Skip to content

Commit

Permalink
fix(Gen): 修复了函数嵌套没有复位的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wangziwenhk committed Jul 29, 2024
1 parent 0d445c9 commit 906f185
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Visitors/GenVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace Riddle {
return DefineArgsType{types, names};
}
std::any GenVisitor::visitFuncDefine(RiddleParser::FuncDefineContext *ctx) {
//fixme 这个问题
auto args = any_cast<DefineArgsType>(visit(ctx->args));
llvm::Type *resultType;
if(ctx->returnType == nullptr) {
Expand All @@ -85,6 +84,7 @@ namespace Riddle {
llvm::FunctionType *funcType = llvm::FunctionType::get(resultType, args.types, false);
llvm::Function *func = llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, ctx->funcName->getText(), *module);
llvm::BasicBlock *entry = llvm::BasicBlock::Create(globalContext, "entry", func);
llvm::BasicBlock *oldBlock = Builder.GetInsertBlock();
Builder.SetInsertPoint(entry);
FuncCalls[ctx->funcName->getText()] = module->getOrInsertFunction(ctx->funcName->getText(), funcType);
FuncStack.push(func);
Expand All @@ -101,6 +101,7 @@ namespace Riddle {
visit(ctx->funcBody());
varManager.pop();
FuncStack.pop();
Builder.SetInsertPoint(oldBlock);
return nullptr;
}
std::any GenVisitor::visitReturnStatement(RiddleParser::ReturnStatementContext *ctx) {
Expand Down

0 comments on commit 906f185

Please sign in to comment.