Skip to content

Commit

Permalink
fix: init target
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlekcahdp4 committed Dec 12, 2024
1 parent aa5ffd6 commit 833628f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ add_llvm_based_tool(pclc
LLVM_COMPONENTS
executionengine
interpreter
target
AllTargetsInfos
AllTargetsDescs
AllTargetsDisassemblers
AllTargetsAsmParsers
AllTargetsCodeGens
support
SOURCES
src/pclc.cc
)
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ stdenv.mkDerivation {
];
buildInputs = with pkgs; [
boost
llvm_18
llvm_19
];
}
1 change: 0 additions & 1 deletion src/llvm_codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_llvm_based_lib(paracl-llvm
SHARED
LLVM_COMPONENTS
target
core
Expand Down
12 changes: 10 additions & 2 deletions src/pclc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/InitLLVM.h>


#include <boost/program_options.hpp>

Expand Down Expand Up @@ -106,11 +109,17 @@ int main(int argc, char *argv[]) try {
}

if (out_type == output_type::LLVM) {
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
llvm::LLVMContext ctx;
auto m = paracl::llvm_codegen::emit_llvm(drv, ctx);
if (vm.count("emit-llvm")) m->dump();
auto &module_ref = *m;
auto *exec = llvm::EngineBuilder(std::move(m)).create();
std::string err;
auto *exec = llvm::EngineBuilder(std::move(m)).setErrorStr(&err).create();
if (!err.empty())
throw std::runtime_error(err);
assert(exec);
std::unordered_map<std::string, void *> external_functions;
external_functions.try_emplace("__print", reinterpret_cast<void *>(paracl::llvm_codegen::intrinsics::print));
external_functions.try_emplace("__read", reinterpret_cast<void *>(paracl::llvm_codegen::intrinsics::read));
Expand All @@ -129,7 +138,6 @@ int main(int argc, char *argv[]) try {
});

exec->setVerifyModules(true);
exec->DisableLazyCompilation(false);
exec->finalizeObject();
exec->runFunction(module_ref.getFunction("main"), {});

Expand Down

0 comments on commit 833628f

Please sign in to comment.