16#include <llvm/IR/LegacyPassManager.h>
17#include <llvm/IR/Module.h>
18#include <llvm/MC/TargetRegistry.h>
19#include <llvm/Target/TargetMachine.h>
28 llvm::raw_ostream &stderrOS,
bool exitEarly,
bool disableOutput);
37 llvm::orc::ThreadSafeContext &TSC)
41 std::string ErrorString;
43 const llvm::Target *
Target = llvm::TargetRegistry::lookupTarget(
44 PTU.
TheModule->getTargetTriple(), ErrorString);
46 return llvm::make_error<llvm::StringError>(
"Failed to create Wasm Target: ",
47 llvm::inconvertibleErrorCode());
50 llvm::TargetOptions TO = llvm::TargetOptions();
51 llvm::TargetMachine *TargetMachine =
Target->createTargetMachine(
52 PTU.
TheModule->getTargetTriple(),
"",
"", TO, llvm::Reloc::Model::PIC_);
53 PTU.
TheModule->setDataLayout(TargetMachine->createDataLayout());
54 std::string OutputFileName = PTU.
TheModule->getName().str() +
".wasm";
56 std::error_code Error;
57 llvm::raw_fd_ostream OutputFile(llvm::StringRef(OutputFileName), Error);
59 llvm::legacy::PassManager PM;
60 if (TargetMachine->addPassesToEmitFile(PM, OutputFile,
nullptr,
61 llvm::CodeGenFileType::ObjectFile)) {
62 return llvm::make_error<llvm::StringError>(
63 "Wasm backend cannot produce object.", llvm::inconvertibleErrorCode());
68 return llvm::make_error<llvm::StringError>(
"Failed to emit Wasm object.",
69 llvm::inconvertibleErrorCode());
74 std::vector<const char *> LinkerArgs = {
"wasm-ld",
80 "--no-export-dynamic",
82 OutputFileName.c_str(),
84 OutputFileName.c_str()};
88 return llvm::make_error<llvm::StringError>(
89 "Failed to link incremental module", llvm::inconvertibleErrorCode());
91 void *LoadedLibModule =
92 dlopen(OutputFileName.c_str(), RTLD_NOW | RTLD_GLOBAL);
93 if (LoadedLibModule ==
nullptr) {
94 llvm::errs() << dlerror() <<
'\n';
95 return llvm::make_error<llvm::StringError>(
96 "Failed to load incremental module", llvm::inconvertibleErrorCode());
99 return llvm::Error::success();
103 return llvm::make_error<llvm::StringError>(
"Not implemented yet",
104 llvm::inconvertibleErrorCode());
109 return llvm::Error::success();
llvm::MachO::Target Target
llvm::Error addModule(PartialTranslationUnit &PTU) override
llvm::Error runCtors() const override
~WasmIncrementalExecutor() override
llvm::Error removeModule(PartialTranslationUnit &PTU) override
WasmIncrementalExecutor(llvm::orc::ThreadSafeContext &TSC)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
bool link(llvm::ArrayRef< const char * > args, llvm::raw_ostream &stdoutOS, llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput)
The class keeps track of various objects created as part of processing incremental inputs.
std::unique_ptr< llvm::Module > TheModule
The llvm IR produced for the input.