diff --git a/Student/task3/test_stu/.gitkeep b/Student/task3/test_stu/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include/SysYFIR/IRPrinter.h b/include/SysYFIR/IRPrinter.h new file mode 100644 index 0000000..1f7b082 --- /dev/null +++ b/include/SysYFIR/IRPrinter.h @@ -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); \ No newline at end of file diff --git a/src/SysYFIR/IRPrinter.cpp b/src/SysYFIR/IRPrinter.cpp new file mode 100644 index 0000000..b2a6b1e --- /dev/null +++ b/src/SysYFIR/IRPrinter.cpp @@ -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(v)) + { + op_ir += "@"+v->get_name(); + } + else if ( dynamic_cast(v) ) + { + op_ir += "@"+v->get_name(); + } + else if ( dynamic_cast(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"; +}