diff --git a/src/SysYIRGenerator.cpp b/src/SysYIRGenerator.cpp index 29201ac..c05f191 100644 --- a/src/SysYIRGenerator.cpp +++ b/src/SysYIRGenerator.cpp @@ -18,14 +18,18 @@ namespace sysy auto pModule = new Module(); assert(pModule); module.reset(pModule); - // // create function:getint - // auto getint_type = Type::getFunctionType(Type::getIntType()); - // auto f_getint = pModule->createFunction("getint", getint_type); - // symbols.insert("getint", f_getint); - // // create function:putint - // auto putint_type = Type::getFunctionType(Type::getVoidType(), vector({Type::getIntType()})); - // auto f_putint = pModule->createFunction("putint", putint_type); - // symbols.insert("putint", f_putint); + // create function:getint + auto getint_type = Type::getFunctionType(Type::getIntType()); + auto f_getint = pModule->createFunction("getint", getint_type); + symbols.insert("getint", f_getint); + auto getint_entry = f_getint->addBasicBlock("getint_entry"); + // create function:putint + auto putint_type = Type::getFunctionType(Type::getVoidType(), vector({Type::getIntType()})); + auto f_putint = pModule->createFunction("putint", putint_type); + symbols.insert("putint", f_putint); + // SymbolTable::FunctionScope putint_scope(symbols); + auto putint_entry = f_putint->addBasicBlock("putint_entry"); + auto putint_arg = putint_entry->createArgument(Type::getPointerType(Type::getIntType())); // generates globals and functions visitChildren(ctx); // return the IR module @@ -116,7 +120,7 @@ namespace sysy symbols.insert(name, function); // create the function scope SymbolTable::FunctionScope scope(symbols); - // create the entry block with the same parameters as the function, + // create the entry block with the same parameters of the function, // and update the symbol table auto entry = function->addBasicBlock(entry_name); // auto entry = function->getEntryBlock(); diff --git a/src/backend/codegen.cpp b/src/backend/codegen.cpp index b9fd846..dd0b06f 100644 --- a/src/backend/codegen.cpp +++ b/src/backend/codegen.cpp @@ -183,6 +183,9 @@ namespace backend string CodeGen::function_gen(Function *func) { + string code; + if (libfunc.find(func->getName()) != libfunc.end()) + return code; curFunc = func; clearFunctionRecord(func); string bbCode; @@ -196,7 +199,6 @@ namespace backend auto bb = iter->get(); bbCode += basicBlock_gen(bb); } - string code; string funcHead = functionHead_gen(func); string prologueCode = prologueCode_gen(func); string epilogueCode = epilogueCode_gen(func); diff --git a/src/backend/codegen.hpp b/src/backend/codegen.hpp index 6b6808d..26e01b7 100644 --- a/src/backend/codegen.hpp +++ b/src/backend/codegen.hpp @@ -188,6 +188,7 @@ namespace backend int max_param = 0; // record arguments need to be backpatched vector backpatch; + set libfunc = {"getint", "putint"}; public: CodeGen(Module *module) : module(module) {}