tinysnail 3 years ago
commit c74943c7c6

@ -0,0 +1,13 @@
#include "Value.h"
#include "Module.h"
#include "Function.h"
#include "GlobalVariable.h"
#include "Constant.h"
#include "BasicBlock.h"
#include "Instruction.h"
#include "User.h"
#include "Type.h"
std::string print_as_op( Value *v, bool print_ty );
std::string print_cmp_type( CmpInst::CmpOp op);
std::string print_fcmp_type( FCmpInst::CmpOp op);

@ -0,0 +1,86 @@
#include "IRPrinter.h"
std::string print_as_op( Value *v, bool print_ty )
{
std::string op_ir;
if( print_ty )
{
op_ir += v->get_type()->print();
op_ir += " ";
}
if (dynamic_cast<GlobalVariable *>(v))
{
op_ir += "@"+v->get_name();
}
else if ( dynamic_cast<Function *>(v) )
{
op_ir += "@"+v->get_name();
}
else if ( dynamic_cast<Constant *>(v))
{
op_ir += v->print();
}
else
{
op_ir += "%"+v->get_name();
}
return op_ir;
}
std::string print_cmp_type( CmpInst::CmpOp op )
{
switch (op)
{
case CmpInst::GE:
return "sge";
break;
case CmpInst::GT:
return "sgt";
break;
case CmpInst::LE:
return "sle";
break;
case CmpInst::LT:
return "slt";
break;
case CmpInst::EQ:
return "eq";
break;
case CmpInst::NE:
return "ne";
break;
default:
break;
}
return "wrong cmpop";
}
std::string print_fcmp_type( FCmpInst::CmpOp op )
{
switch (op)
{
case FCmpInst::GE:
return "uge";
break;
case FCmpInst::GT:
return "ugt";
break;
case FCmpInst::LE:
return "ule";
break;
case FCmpInst::LT:
return "ult";
break;
case FCmpInst::EQ:
return "ueq";
break;
case FCmpInst::NE:
return "une";
break;
default:
break;
}
return "wrong fcmpop";
}
Loading…
Cancel
Save