diff --git a/BitcodeEmitter.cpp b/BitcodeEmitter.cpp index e43fa83..45b6832 100644 --- a/BitcodeEmitter.cpp +++ b/BitcodeEmitter.cpp @@ -438,9 +438,7 @@ bool BitcodeEmitter::emit(Branch const& node) { return true; } -bool BitcodeEmitter::emit(Function const& node) { - d->scope.enter(); - +bool BitcodeEmitter::emitFunctionPrototype(Function const& node, llvm::Function **proto) { std::vector argTypes; for (FunArg const* arg: node.getArgs()) { @@ -492,6 +490,17 @@ bool BitcodeEmitter::emit(Function const& node) { ++argToEmit; } + *proto = func; + + return true; +} + +bool BitcodeEmitter::emit(Function const& node) { + llvm::Function *func = nullptr; + GUARDED(emitFunctionPrototype(node, &func)); + + d->scope.enter(); + llvm::BasicBlock *bb = llvm::BasicBlock::Create( getGlobalContext(), "entry", func ); diff --git a/BitcodeEmitter.hpp b/BitcodeEmitter.hpp index b8b427f..49823cb 100644 --- a/BitcodeEmitter.hpp +++ b/BitcodeEmitter.hpp @@ -26,6 +26,7 @@ namespace llvm { class Module; + class Function; } namespace monicelli { @@ -65,6 +66,7 @@ public: private: bool emitSemiExpression(Id const& left, SemiExpression const& right); + bool emitFunctionPrototype(Function const& node, llvm::Function **proto); std::unique_ptr module; Private *d;