Skip to content

[WebAssembly] add ability to intialize globals #172732

@daxpedda

Description

@daxpedda

Its currently not possible to define Wasm globals with a non-default value.
E.g.:

.globaltype foo, i32, immutable

produces:

global i32 i32.const 0

Unfortunately simply adding a parameter to .globaltype wouldn't be enough because in reality Wasm potentially supports a whole instruction sequence here.

Instead I would propose the following:

.globaltype foo, i32, immutable
.globalinit foo
  i32.const -1
end_function // or some other more appropriate directive

would produce:

global i32 i32.const -1

Happy to do the implementation on a design sign-off.

Pinging @sbc100 as a target maintainer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions