CompileLayerT CompileLayer;
};
-static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
- if (auto F = ParseDefinition()) {
- IRGenContext C(S);
- if (auto LF = F->IRGen(C)) {
+static std::unique_ptr<llvm::Module>
+IRGen(KaleidoscopeJIT &J, SessionContext &S, const FunctionAST &F) {
+ IRGenContext C(S);
+ auto LF = F.IRGen(C);
+ if (!LF)
+ return nullptr;
#ifndef MINIMAL_STDERR_OUTPUT
- std::cerr << "Read function definition:\n";
- LF->dump();
+ fprintf(stderr, "Read function definition:");
+ LF->dump();
#endif
- J.addModule(C.takeM());
+ return C.takeM();
+}
+
+static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
+ if (auto F = ParseDefinition()) {
+ if (auto M = IRGen(J, S, *F)) {
S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
+ J.addModule(std::move(M));
}
} else {
// Skip token for error recovery.