diff options
[IPL/T] Implemented Float type and added basic function structure as well as added addition function for two arguments
1 files changed, 20 insertions, 0 deletions
| -rw-r--r-- | Year 2/Implementation of Programming Languages/Transpiler/src/LLVMVisitor/LLVMVisitor.cpp | 20 |
diff --git a/Year 2/Implementation of Programming Languages/Transpiler/src/LLVMVisitor/LLVMVisitor.cpp b/Year 2/Implementation of Programming Languages/Transpiler/src/LLVMVisitor/LLVMVisitor.cpp index f68b80d..d3eea2d 100644 --- a/Year 2/Implementation of Programming Languages/Transpiler/src/LLVMVisitor/LLVMVisitor.cpp +++ b/Year 2/Implementation of Programming Languages/Transpiler/src/LLVMVisitor/LLVMVisitor.cpp @@ -10,3 +10,23 @@ std::string LLVMVisitor::Visit(const Integer& vint) { outFile << valRegister + " = " + std::to_string(vint.get_value()) + "\n"; return valRegister; } + +std::string LLVMVisitor::Visit(const Float& vfloat) { + std::string valRegister = *(reg++); + outFile << valRegister + " = " + std::to_string(vfloat.get_value()) + "\n"; + return valRegister; +} + +std::string LLVMVisitor::f_add(const BuiltInFunction& bfun) { + std::string leftArg = bfun.get_args()[0]->Visit(*this); + std::string rightArg = bfun.get_args()[1]->Visit(*this); + std::string valRegister = *(reg++); + outFile << valRegister << " = add i32 " << leftArg << ", " << rightArg << "\n"; + return valRegister; +} + +std::string LLVMVisitor::Visit(const BuiltInFunction& bfun) { + if (bfun.get_name() == "+") + return f_add(bfun); + return ""; +} |
