Files
nudt-compiler-cpp/src/irgen/IRGenStmt.cpp
2026-03-09 15:37:36 +08:00

27 lines
606 B
C++

#include "irgen/IRGen.h"
#include <stdexcept>
#include "SysYParser.h"
#include "ir/IR.h"
bool IRGenImpl::GenStmt(SysYParser::StmtContext& stmt) {
if (stmt.varDecl()) {
GenVarDecl(*stmt.varDecl());
return false;
}
if (stmt.returnStmt()) {
GenReturnStmt(*stmt.returnStmt());
return true;
}
throw std::runtime_error("[irgen] 暂不支持的语句类型");
}
void IRGenImpl::GenReturnStmt(SysYParser::ReturnStmtContext& ret) {
if (!ret.exp()) {
throw std::runtime_error("[irgen] return 缺少表达式");
}
ir::Value* v = GenExpr(*ret.exp());
builder_.CreateRet(v);
}