#pragma once #include #include #include #include "WAVM/IR/Types.h" #include "WAVM/Inline/BasicTypes.h" #include "WAVM/Inline/HashMap.h" #include "WAVM/RuntimeABI/RuntimeABI.h" // Forward declarations namespace WAVM { namespace IR { struct Module; struct UntaggedValue; struct FeatureSpec; enum class CallingConvention; }} namespace WAVM { namespace Runtime { struct ContextRuntimeData; struct ExceptionType; struct Function; struct Instance; }} namespace WAVM { namespace LLVMJIT { struct TargetSpec { std::string triple; std::string cpu; }; enum class TargetValidationResult { valid, invalidTargetSpec, unsupportedArchitecture, x86CPUDoesNotSupportSSE41, wavmDoesNotSupportSIMDOnArch }; WAVM_API TargetSpec getHostTargetSpec(); WAVM_API TargetValidationResult validateTarget(const TargetSpec& targetSpec, const IR::FeatureSpec& featureSpec); struct Version { Uptr llvmMajor; Uptr llvmMinor; Uptr llvmPatch; Uptr llvmjitVersion; }; WAVM_API Version getVersion(); // Compile a module to object code with the host target spec. // Cannot fail if validateTarget(targetSpec, irModule.featureSpec) == valid. WAVM_API std::vector compileModule(const IR::Module& irModule, const TargetSpec& targetSpec); WAVM_API std::string emitLLVMIR(const IR::Module& irModule, const TargetSpec& targetSpec, bool optimize); WAVM_API std::string disassembleObject(const TargetSpec& targetSpec, const std::vector& objectBytes); // An opaque type that can be used to reference a loaded JIT module. struct Module; // // Structs that are passed to loadModule to bind undefined symbols in object code to values. // struct InstanceBinding { Uptr id; }; struct FunctionBinding { const void* code; }; struct TableBinding { Uptr id; }; struct MemoryBinding { Uptr id; }; struct GlobalBinding { IR::GlobalType type; union { const IR::UntaggedValue* immutableValuePointer; Uptr mutableGlobalIndex; }; }; struct ExceptionTypeBinding { Uptr id; }; // Loads a module from object code, and binds its undefined symbols to the provided bindings. WAVM_API std::shared_ptr loadModule( const std::vector& objectFileBytes, HashMap&& wavmIntrinsicsExportMap, std::vector&& types, std::vector&& functionImports, std::vector&& tables, std::vector&& memories, std::vector&& globals, std::vector&& exceptionTypes, InstanceBinding instance, Uptr tableReferenceBias, const std::vector& functionDefMutableDatas); struct InstructionSource { Runtime::Function* function; Uptr instructionIndex; }; // Finds the JIT function and instruction index at the given address. If no JIT function // contains the given address, returns an InstructionSourceInfo with function==nullptr. WAVM_API bool getInstructionSourceByAddress(Uptr address, InstructionSource& outSource); // Generates an invoke thunk for a specific function type. WAVM_API Runtime::InvokeThunkPointer getInvokeThunk(IR::FunctionType functionType); }}