[WebAssembly] add ability to intialize `global`s
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Its currently not possible to define Wasm `global`s with a non-default value.
E.g.:
```gas
.globaltype foo, i32, immutable
```
produces:
```wat
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:
```gas
.globaltype foo, i32, immutable
.globalinit foo
i32.const -1
end_function // or some other more appropriate directive
```
would produce:
```wat
global i32 i32.const -1
```
Happy to do the implementation on a design sign-off.
Pinging @sbc100 as a target maintainer.
Contributor guide
Research direction
The issue names no files or tests; start by locating the WebAssembly assembler handling for `.globaltype` and the emitted WAT shown here. Review the proposed `.globalinit` directive and instruction-sequence semantics, then seek design sign-off; done means an agreed interface and implementation that emits the requested initialized global.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100