| 111 | } |
| 112 | |
| 113 | llvm::Expected<std::unique_ptr<WasmModule>> WasmModule::CreateFromFile( |
| 114 | llvm::StringRef path) { |
| 115 | if (!llvm::sys::fs::exists(path)) { |
| 116 | return llvm::createStringError(llvm::inconvertibleErrorCode(), |
| 117 | "Module file '%s' not found\n.", |
| 118 | path.str().c_str()); |
| 119 | } |
| 120 | LLVM_DEBUG(llvm::dbgs() << "Loading module from '" << path << "'\n"); |
| 121 | |
| 122 | auto instance = GetTarget(); |
| 123 | if (!instance) { |
| 124 | return instance.takeError(); |
| 125 | } |
| 126 | auto [debugger, target] = *instance; |
| 127 | auto module = target->GetOrCreateModule( |
| 128 | {lldb_private::FileSpec(path), |
| 129 | lldb_private::ArchSpec("wasm32-unknown-unknown-wasm")}, |
| 130 | false); |
| 131 | |
| 132 | return std::unique_ptr<WasmModule>(new WasmModule(target, module)); |
| 133 | } |
| 134 | |
| 135 | bool WasmModule::Valid() const { |
| 136 | return module_ && module_->GetNumCompileUnits() > 0; |