#include "LLVMVisitor.h" LLVMVisitor::LLVMVisitor(const char* fileName) : outFile(std::ofstream(fileName)), reg() { if (!outFile.is_open()) throw std::runtime_error("Couldn't open file for writing!"); } std::string LLVMVisitor::Visit(const Integer& vint) { std::string valRegister = *(reg++); 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 ""; }