Kaleidoscope-Orc: Extract IRGen work into a utility function.

llvm-svn: 228539
This commit is contained in:
David Blaikie 2015-02-08 20:29:28 +00:00
parent 93ad6b31ec
commit 1803dc2639
1 changed files with 15 additions and 7 deletions

View File

@ -1180,16 +1180,24 @@ private:
CompileLayerT CompileLayer;
};
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
fprintf(stderr, "Read function definition:");
LF->dump();
#endif
return C.takeM();
}
static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
if (auto F = ParseDefinition()) {
IRGenContext C(S);
if (auto LF = F->IRGen(C)) {
#ifndef MINIMAL_STDERR_OUTPUT
std::cerr << "Read function definition:\n";
LF->dump();
#endif
J.addModule(C.takeM());
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.