MCPcopy Create free account
hub / github.com/WebAssembly/wabt / ReadModule

Method ReadModule

src/binary-reader.cc:3258–3295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3256}
3257
3258Result BinaryReader::ReadModule(const ReadModuleOptions& options) {
3259 uint32_t magic = 0;
3260 CHECK_RESULT(ReadU32(&magic, "magic"));
3261 ERROR_UNLESS(magic == WABT_BINARY_MAGIC, "bad magic value");
3262
3263 uint16_t version = 0, layer = 0;
3264 CHECK_RESULT(ReadU16(&version, "version"));
3265 CHECK_RESULT(ReadU16(&layer, "layer"));
3266
3267 switch (layer) {
3268 case WABT_BINARY_LAYER_MODULE:
3269 ERROR_UNLESS(version == WABT_BINARY_VERSION,
3270 "bad wasm file version: %#x (expected %#x)", version,
3271 WABT_BINARY_VERSION);
3272 break;
3273 case WABT_BINARY_LAYER_COMPONENT:
3274 ERROR("wasm components are not yet supported in this tool");
3275 break;
3276 default:
3277 ERROR("unsupported wasm layer: %#x", layer);
3278 break;
3279 }
3280
3281 CALLBACK(BeginModule, version);
3282 CHECK_RESULT(ReadSections(ReadSectionsOptions{options.stop_on_first_error}));
3283 // This is checked in ReadCodeSection, but it must be checked at the end too,
3284 // in case the code section was omitted.
3285 ERROR_UNLESS(num_function_signatures_ == num_function_bodies_,
3286 "function signature count != function body count");
3287 // This is checked in ReadDataSection, but it must be checked at the end too,
3288 // in case the data section was omitted.
3289 ERROR_IF(num_data_segments_ == 0 && data_count_ != kInvalidIndex &&
3290 data_count_ != 0,
3291 "Data section missing but DataCount non-zero");
3292 CALLBACK0(EndModule);
3293
3294 return Result::Ok;
3295}
3296
3297} // end anonymous namespace
3298

Callers 1

ReadBinaryFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected