fix(ast): 删掉ast结构
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
// 语句翻译模块:
|
||||
// - 处理 if/while/return 等控制流构造
|
||||
// - 负责基本块创建、分支跳转与控制流收束
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
#include "SysYParser.h"
|
||||
#include "ir/IR.h"
|
||||
|
||||
void IRGenImpl::GenStmt(const ast::Stmt& stmt) {
|
||||
if (auto ret = dynamic_cast<const ast::ReturnStmt*>(&stmt)) {
|
||||
ir::Value* v = GenExpr(*ret->value);
|
||||
builder_.CreateRet(v);
|
||||
void IRGenImpl::GenStmt(SysYParser::StmtContext& stmt) {
|
||||
if (stmt.varDecl()) {
|
||||
GenVarDecl(*stmt.varDecl());
|
||||
return;
|
||||
}
|
||||
if (stmt.returnStmt()) {
|
||||
GenReturnStmt(*stmt.returnStmt());
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user