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/serene.h"
|
||||||
|
|
||||||
#include "serene/context.h"
|
#include "serene/context.h"
|
||||||
|
#include "serene/jit.h"
|
||||||
#include "serene/namespace.h"
|
#include "serene/namespace.h"
|
||||||
#include "serene/reader/reader.h"
|
#include "serene/reader/reader.h"
|
||||||
#include "serene/reader/semantics.h"
|
#include "serene/reader/semantics.h"
|
||||||
|
@ -68,7 +69,7 @@ enum Action {
|
||||||
CompileToObject,
|
CompileToObject,
|
||||||
Compile,
|
Compile,
|
||||||
// TODO: Remove this option and replace it by a subcommand
|
// 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.")),
|
"Compile to object file.")),
|
||||||
cl::values(clEnumValN(Compile, "target",
|
cl::values(clEnumValN(Compile, "target",
|
||||||
"Compile to target code. (Default)")),
|
"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) {
|
switch (emitAction) {
|
||||||
|
|
||||||
case Action::JIT: {
|
case Action::RunJIT: {
|
||||||
|
// TODO: Replace it by a proper jit configuration
|
||||||
|
ctx->setOperationPhase(CompilationPhase::NoOptimization);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -328,6 +332,18 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
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::Compile:
|
||||||
case Action::CompileToObject: {
|
case Action::CompileToObject: {
|
||||||
return dumpAsObject(*ns);
|
return dumpAsObject(*ns);
|
||||||
|
|
|
@ -144,8 +144,7 @@ public:
|
||||||
/// result(result));
|
/// result(result));
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
llvm::Error invoke(llvm::StringRef funcName, Args... args) {
|
llvm::Error invoke(llvm::StringRef funcName, Args... args) {
|
||||||
const std::string adapterName =
|
const std::string adapterName = std::string("") + funcName.str();
|
||||||
std::string("_mlir_ciface_") + funcName.str();
|
|
||||||
llvm::SmallVector<void *> argsArray;
|
llvm::SmallVector<void *> argsArray;
|
||||||
// Pack every arguments in an array of pointers. Delegate the packing to a
|
// Pack every arguments in an array of pointers. Delegate the packing to a
|
||||||
// trait so that it can be overridden per argument type.
|
// 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();
|
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
|
} // namespace serene
|
||||||
|
|
Loading…
Reference in New Issue