You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
578 B
24 lines
578 B
#include "irgen/IRGen.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "SysYParser.h"
|
|
#include "ir/IR.h"
|
|
#include "utils/Log.h"
|
|
|
|
bool IRGenImpl::GenStmt(SysYParser::StmtContext& stmt) {
|
|
if (stmt.returnStmt()) {
|
|
GenReturnStmt(*stmt.returnStmt());
|
|
return true;
|
|
}
|
|
throw std::runtime_error(FormatError("irgen", "暂不支持的语句类型"));
|
|
}
|
|
|
|
void IRGenImpl::GenReturnStmt(SysYParser::ReturnStmtContext& ret) {
|
|
if (!ret.exp()) {
|
|
throw std::runtime_error(FormatError("irgen", "return 缺少表达式"));
|
|
}
|
|
ir::Value* v = GenExpr(*ret.exp());
|
|
builder_.CreateRet(v);
|
|
}
|