Load module or component unit. See "include/loader/loader.h".
| 185 | |
| 186 | // Load module or component unit. See "include/loader/loader.h". |
| 187 | Expect<std::variant<std::unique_ptr<AST::Component::Component>, |
| 188 | std::unique_ptr<AST::Module>>> |
| 189 | Loader::loadUnit() { |
| 190 | EXPECTED_TRY(auto Preamble, loadPreamble()); |
| 191 | auto &[WasmMagic, Ver] = Preamble; |
| 192 | if (Ver == ModuleVersion) { |
| 193 | auto Mod = std::make_unique<AST::Module>(); |
| 194 | Mod->getMagic() = WasmMagic; |
| 195 | Mod->getVersion() = Ver; |
| 196 | if (Conf.getRuntimeConfigure().getRunMode() == RunMode::AOT) { |
| 197 | EXPECTED_TRY(loadModuleAOT(Mod->getAOTSection())); |
| 198 | } |
| 199 | // Seek to the position after the binary header. |
| 200 | FMgr.seek(8); |
| 201 | EXPECTED_TRY(loadModule(*Mod)); |
| 202 | |
| 203 | // Load library from AOT Section for the universal WASM case only when the |
| 204 | // configured run mode is AOT. |
| 205 | if (Conf.getRuntimeConfigure().getRunMode() == RunMode::AOT) { |
| 206 | if (WASMType == InputType::UniversalWASM) { |
| 207 | EXPECTED_TRY(loadUniversalWASM(*Mod)); |
| 208 | } else if (WASMType == InputType::WASM) { |
| 209 | // AOT requested on a plain .wasm with no AOT artifact. |
| 210 | spdlog::warn("AOT was requested but the input has no AOT artifact, " |
| 211 | "falling back to interpreter."sv); |
| 212 | } |
| 213 | } |
| 214 | return Mod; |
| 215 | } else if (Ver == ComponentVersion) { |
| 216 | if (!Conf.hasProposal(Proposal::Component)) { |
| 217 | return logNeedProposal(ErrCode::Value::MalformedVersion, |
| 218 | Proposal::Component, FMgr.getLastOffset(), |
| 219 | ASTNodeAttr::Component); |
| 220 | } |
| 221 | spdlog::warn("component model is an experimental proposal"sv); |
| 222 | auto Comp = std::make_unique<AST::Component::Component>(); |
| 223 | Comp->getMagic() = WasmMagic; |
| 224 | Comp->getVersion() = {Ver[0], Ver[1]}; |
| 225 | Comp->getLayer() = {Ver[2], Ver[3]}; |
| 226 | EXPECTED_TRY(loadComponent(*Comp)); |
| 227 | return Comp; |
| 228 | } else { |
| 229 | return logLoadError(ErrCode::Value::MalformedVersion, FMgr.getLastOffset(), |
| 230 | ASTNodeAttr::Component); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // Serialize module into byte code. See "include/loader/loader.h". |
| 235 | Expect<std::vector<Byte>> Loader::serializeModule(const AST::Module &Mod) { |
nothing calls this directly
no test coverage detected