-
Notifications
You must be signed in to change notification settings - Fork 15
Module Naming Resolution
WebAssembly does not provide a standard way of naming modules. The closest it has is the optional custom name section, which may or may not be present, and doesn't necessarily include a module name. This custom name section roughly translates to the optional name you can give to modules in the .wat
textual representation, but it's still optional.
Despite the fact that a module is not required to provide it's own name, module names are required to resolve WebAssembly imports. As a result, inNative must guarantee the uniqueness of module names, while also respecting the name section if it exists. Once inNative has resolved a module's name, it is always stored in the module->name
byte array, which is the definitive name of the module as far as inNative is concerned, and should be what you query to figure out what name ended up being used.
The steps inNative follows to resolve the module name are as follows:
- If a module name is included in the custom name section, use it.
- Otherwise, if a suggested name has been passed into
AddModule()
, use the suggested name. - If there is no suggested name, use the name
m##
, where##
is the index number of the module (e.g.m0
).
Various tools and compilation situations rely on generating unique suggested names. This is usually to preserve as much information as possible.
The command line will always use the suggested name that is the file name without an extension.
When compiling a .wast file, each module is compiled with the suggested name of wast_m##
, where ##
is the index number of the module.