diff --git a/src/IR.cpp b/src/IR.cpp index 913aac5..63d26d8 100644 --- a/src/IR.cpp +++ b/src/IR.cpp @@ -541,7 +541,8 @@ namespace sysy void Module::print(std::ostream &os) const { for (auto &value : children) - os << *value << '\n'; + if (value->getName() != "getint" && value->getName() != "putint") + os << *value << '\n'; } // ArrayValue *ArrayValue::get(Type *type, const vector &values) { diff --git a/src/SysYIRGenerator.cpp b/src/SysYIRGenerator.cpp index 454ac5f..df28589 100644 --- a/src/SysYIRGenerator.cpp +++ b/src/SysYIRGenerator.cpp @@ -18,6 +18,14 @@ 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); // generates globals and functions visitChildren(ctx); // return the IR module