MCPcopy Create free account
hub / github.com/EarlGray/language-incubator / codegenFunDef

Function codegenFunDef

llvm/kldscp/codegen.cpp:278–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278Function *codegenFunDef(codegen_t &cg, ast_t *ast) {
279 assert(ast->type == AST_FUNDEF);
280 cg.variables.clear();
281
282 Function *func = codegenProto(cg, ast);
283 if (!func)
284 return (Function *)errorVal("codegenFunDef: codegenProto() failed\n");
285
286 ast_t *astbody = ast->as_fundef.body;
287 if (!astbody)
288 return func; // prototype
289
290 BasicBlock *bb = BasicBlock::Create(getGlobalContext(), "entry", func);
291 cg.ir_builder.SetInsertPoint(bb);
292
293 Value *bodyval = codegen(cg, astbody);
294 if (! bodyval) {
295 func->eraseFromParent();
296 return (Function *)errorVal("codegenFunDef: codegen(body) failed\n");
297 }
298
299 cg.ir_builder.CreateRet(bodyval);
300 verifyFunction(*func);
301
302 if (cg.fpm)
303 cg.fpm->run(*func);
304
305 return func;
306}
307
308inline Value *codegenNum(codegen_t &cg, ast_t *ast) {
309 assert(ast->type == AST_NUM);

Callers 3

codegenImportFunction · 0.85
test_codegenFunction · 0.85
test_interpFunction · 0.85

Calls 4

codegenProtoFunction · 0.85
errorValFunction · 0.85
codegenFunction · 0.85
runMethod · 0.80

Tested by 2

test_codegenFunction · 0.68
test_interpFunction · 0.68