From 22fd5c5bb8683c686a68ea59d2e0961f6da074c1 Mon Sep 17 00:00:00 2001 From: wqz <1197460504@qq.com> Date: Wed, 26 Apr 2023 10:29:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=86=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E7=A9=BA=E5=87=BD=E6=95=B0getint,putint,=E4=BD=86=E4=B8=8D?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=85=B6=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/IR.cpp | 3 ++- src/SysYIRGenerator.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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