Finish up the wiring of the very basic JIT implementation.
This commit is contained in:
parent
aba81bfcae
commit
a1d3ae8c9c
|
@ -25,6 +25,7 @@
|
|||
#include "serene/serene.h"
|
||||
|
||||
#include "serene/context.h"
|
||||
#include "serene/jit.h"
|
||||
#include "serene/namespace.h"
|
||||
#include "serene/reader/reader.h"
|
||||
#include "serene/reader/semantics.h"
|
||||
|
@ -68,7 +69,7 @@ enum Action {
|
|||
CompileToObject,
|
||||
Compile,
|
||||
// TODO: Remove this option and replace it by a subcommand
|
||||
JIT,
|
||||
RunJIT,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,8 @@ static cl::opt<enum Action> emitAction(
|
|||
"Compile to object file.")),
|
||||
cl::values(clEnumValN(Compile, "target",
|
||||
"Compile to target code. (Default)")),
|
||||
cl::values(clEnumValN(JIT, "jit", "Run the give input file with the JIT."))
|
||||
cl::values(clEnumValN(RunJIT, "jit",
|
||||
"Run the give input file with the JIT."))
|
||||
|
||||
);
|
||||
|
||||
|
@ -251,7 +253,9 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
switch (emitAction) {
|
||||
|
||||
case Action::JIT: {
|
||||
case Action::RunJIT: {
|
||||
// TODO: Replace it by a proper jit configuration
|
||||
ctx->setOperationPhase(CompilationPhase::NoOptimization);
|
||||
break;
|
||||
};
|
||||
|
||||
|
@ -328,6 +332,18 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
};
|
||||
|
||||
case Action::RunJIT: {
|
||||
auto maybeJIT = JIT::make(*ns.get());
|
||||
auto jit = std::move(maybeJIT.getValueOrFail("Couldn't creat the JIT!"));
|
||||
|
||||
if (jit->invoke("main")) {
|
||||
llvm::errs() << "Faild to invoke the 'main' function.\n";
|
||||
return 1;
|
||||
}
|
||||
llvm::outs() << "Done!";
|
||||
break;
|
||||
};
|
||||
|
||||
case Action::Compile:
|
||||
case Action::CompileToObject: {
|
||||
return dumpAsObject(*ns);
|
||||
|
|
|
@ -144,8 +144,7 @@ public:
|
|||
/// result(result));
|
||||
template <typename... Args>
|
||||
llvm::Error invoke(llvm::StringRef funcName, Args... args) {
|
||||
const std::string adapterName =
|
||||
std::string("_mlir_ciface_") + funcName.str();
|
||||
const std::string adapterName = std::string("") + funcName.str();
|
||||
llvm::SmallVector<void *> argsArray;
|
||||
// Pack every arguments in an array of pointers. Delegate the packing to a
|
||||
// trait so that it can be overridden per argument type.
|
||||
|
|
|
@ -321,4 +321,13 @@ llvm::Error JIT::invokePacked(llvm::StringRef name,
|
|||
return llvm::Error::success();
|
||||
}
|
||||
|
||||
void JIT::registerSymbols(
|
||||
llvm::function_ref<llvm::orc::SymbolMap(llvm::orc::MangleAndInterner)>
|
||||
symbolMap) {
|
||||
auto &mainJitDylib = engine->getMainJITDylib();
|
||||
cantFail(mainJitDylib.define(
|
||||
absoluteSymbols(symbolMap(llvm::orc::MangleAndInterner(
|
||||
mainJitDylib.getExecutionSession(), engine->getDataLayout())))));
|
||||
}
|
||||
|
||||
} // namespace serene
|
||||
|
|
Loading…
Reference in New Issue