MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / compile

Method compile

lib/llvm/compiler.cpp:5897–6037  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5895}
5896
5897Expect<Data> Compiler::compile(const AST::Module &Module) noexcept {
5898 // Check that the module is validated.
5899 if (unlikely(!Module.getIsValidated())) {
5900 spdlog::error(ErrCode::Value::NotValidated);
5901 return Unexpect(ErrCode::Value::NotValidated);
5902 }
5903
5904 std::unique_lock Lock(Mutex);
5905 spdlog::info("compile start"sv);
5906
5907 LLVM::Data D;
5908 auto LLContext = D.extract().getLLContext();
5909 LLVM::Core::init(LLContext.unwrap());
5910 auto &LLModule = D.extract().LLModule;
5911 LLModule.setTarget(LLVM::getDefaultTargetTriple().unwrap());
5912 LLModule.addFlag(LLVMModuleFlagBehaviorError, "PIC Level"sv, 2);
5913
5914 CompileContext NewContext(LLContext, LLModule,
5915 Conf.getCompilerConfigure().isGenericBinary());
5916 struct RAIICleanup {
5917 RAIICleanup(CompileContext *&Context, CompileContext &NewContext)
5918 : Context(Context) {
5919 Context = &NewContext;
5920 }
5921 ~RAIICleanup() { Context = nullptr; }
5922 CompileContext *&Context;
5923 };
5924 RAIICleanup Cleanup(Context, NewContext);
5925
5926 // Compile Function Types
5927 compile(Module.getTypeSection());
5928 // Compile ImportSection
5929 compile(Module.getImportSection());
5930 // Compile GlobalSection
5931 compile(Module.getGlobalSection());
5932 // Compile MemorySection (MemorySec, DataSec)
5933 compile(Module.getMemorySection(), Module.getDataSection());
5934 // Compile TableSection (TableSec, ElemSec)
5935 compile(Module.getTableSection(), Module.getElementSection());
5936 // Compile functions in the module. (FunctionSec, CodeSec)
5937 EXPECTED_TRY(compile(Module.getFunctionSection(), Module.getCodeSection()));
5938 // Compile ExportSection.
5939 compile(Module.getExportSection());
5940 // StartSection is not required for compilation.
5941
5942 spdlog::info("verify start"sv);
5943 LLModule.verify(LLVMPrintMessageAction);
5944
5945 spdlog::info("optimize start"sv);
5946 auto &TM = D.extract().TM;
5947 {
5948 auto Triple = LLModule.getTarget();
5949 auto [TheTarget, ErrorMessage] = LLVM::Target::getFromTriple(Triple);
5950 if (ErrorMessage) {
5951 spdlog::error("getFromTriple failed:{}"sv, ErrorMessage.string_view());
5952 return Unexpect(ErrCode::Value::IllegalPath);
5953 } else {
5954 std::string CPUName;

Callers 5

FuzzToolFunction · 0.45
CompilerFunction · 0.45
unsafeInstantiateMethod · 0.45

Calls 15

unlikelyFunction · 0.85
UnexpectFunction · 0.85
getDefaultTargetTripleFunction · 0.85
getHostCPUNameFunction · 0.85
getHostCPUFeaturesFunction · 0.85
toLLVMCodeGenLevelFunction · 0.85
toLLVMLevelFunction · 0.85
toLLVMTypeFunction · 0.85
unpackStructFunction · 0.85
getLLContextMethod · 0.80
setTargetMethod · 0.80
addFlagMethod · 0.80

Tested by

no test coverage detected