Skip to content

Commit 1a3c1a5

Browse files
authored
Reflect instruction renaming in code (WebAssembly#2128)
- Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
1 parent d78be9a commit 1a3c1a5

File tree

181 files changed

+1531
-1532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+1531
-1532
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
- Removed APIs related to deprecated instruction names in Binaryen.js:
19+
- `get_local` / `getLocal`
20+
- `set_local` / `setLocal`
21+
- `tee_local` / `teeLocal`
22+
- `get_global` / `getGlobal`
23+
- `set_global` / `setGlobal`
24+
- `current_memory` / `currentMemory`
25+
- `grow_memory` / `growMemory`
26+
They are now available as their new instruction names:
27+
`local.get`, `local.set`, `local.tee`, `global.get`, `global.set`,
28+
`memory.size`, and `memory.grow`.
1829
- Add feature handling to the C/JS API with no feature enabled by default.
1930

2031
v84

build-js.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ export_function "_BinaryenBreakId"
195195
export_function "_BinaryenSwitchId"
196196
export_function "_BinaryenCallId"
197197
export_function "_BinaryenCallIndirectId"
198-
export_function "_BinaryenGetLocalId"
199-
export_function "_BinaryenSetLocalId"
200-
export_function "_BinaryenGetGlobalId"
201-
export_function "_BinaryenSetGlobalId"
198+
export_function "_BinaryenLocalGetId"
199+
export_function "_BinaryenLocalSetId"
200+
export_function "_BinaryenGlobalGetId"
201+
export_function "_BinaryenGlobalSetId"
202202
export_function "_BinaryenLoadId"
203203
export_function "_BinaryenStoreId"
204204
export_function "_BinaryenConstId"
@@ -385,8 +385,8 @@ export_function "_BinaryenLtFloat64"
385385
export_function "_BinaryenLeFloat64"
386386
export_function "_BinaryenGtFloat64"
387387
export_function "_BinaryenGeFloat64"
388-
export_function "_BinaryenCurrentMemory"
389-
export_function "_BinaryenGrowMemory"
388+
export_function "_BinaryenMemorySize"
389+
export_function "_BinaryenMemoryGrow"
390390
export_function "_BinaryenAtomicRMWAdd"
391391
export_function "_BinaryenAtomicRMWSub"
392392
export_function "_BinaryenAtomicRMWAnd"
@@ -537,11 +537,11 @@ export_function "_BinaryenBreak"
537537
export_function "_BinaryenSwitch"
538538
export_function "_BinaryenCall"
539539
export_function "_BinaryenCallIndirect"
540-
export_function "_BinaryenGetLocal"
541-
export_function "_BinaryenSetLocal"
542-
export_function "_BinaryenTeeLocal"
543-
export_function "_BinaryenGetGlobal"
544-
export_function "_BinaryenSetGlobal"
540+
export_function "_BinaryenLocalGet"
541+
export_function "_BinaryenLocalSet"
542+
export_function "_BinaryenLocalTee"
543+
export_function "_BinaryenGlobalGet"
544+
export_function "_BinaryenGlobalSet"
545545
export_function "_BinaryenLoad"
546546
export_function "_BinaryenStore"
547547
export_function "_BinaryenConst"
@@ -610,20 +610,20 @@ export_function "_BinaryenCallIndirectGetTarget"
610610
export_function "_BinaryenCallIndirectGetNumOperands"
611611
export_function "_BinaryenCallIndirectGetOperand"
612612

613-
# 'GetLocal' expression operations
614-
export_function "_BinaryenGetLocalGetIndex"
613+
# 'LocalGet' expression operations
614+
export_function "_BinaryenLocalGetGetIndex"
615615

616-
# 'SetLocal' expression operations
617-
export_function "_BinaryenSetLocalIsTee"
618-
export_function "_BinaryenSetLocalGetIndex"
619-
export_function "_BinaryenSetLocalGetValue"
616+
# 'LocalSet' expression operations
617+
export_function "_BinaryenLocalSetIsTee"
618+
export_function "_BinaryenLocalSetGetIndex"
619+
export_function "_BinaryenLocalSetGetValue"
620620

621-
# 'GetGlobal' expression operations
622-
export_function "_BinaryenGetGlobalGetName"
621+
# 'GlobalGet' expression operations
622+
export_function "_BinaryenGlobalGetGetName"
623623

624-
# 'SetGlobal' expression operations
625-
export_function "_BinaryenSetGlobalGetName"
626-
export_function "_BinaryenSetGlobalGetValue"
624+
# 'GlobalSet' expression operations
625+
export_function "_BinaryenGlobalSetGetName"
626+
export_function "_BinaryenGlobalSetGetValue"
627627

628628
# 'Host' expression operations
629629
export_function "_BinaryenHostGetOp"
@@ -767,8 +767,8 @@ export_function "_BinaryenRemoveExport"
767767
export_function "_BinaryenSetFunctionTable"
768768
export_function "_BinaryenSetMemory"
769769
export_function "_BinaryenSetStart"
770-
export_function "_BinaryenGetFeatures"
771-
export_function "_BinaryenSetFeatures"
770+
export_function "_BinaryenModuleGetFeatures"
771+
export_function "_BinaryenModuleSetFeatures"
772772
export_function "_BinaryenModuleParse"
773773
export_function "_BinaryenModulePrint"
774774
export_function "_BinaryenModulePrintAsmjs"

scripts/fuzz_relooper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def get_phi(j):
216216
};
217217
BinaryenExpressionRef list[] = {
218218
BinaryenCall(module, "print", args, 1, BinaryenTypeNone()),
219-
BinaryenSetLocal(module, 0, BinaryenCall(module, "check", NULL, 0,
219+
BinaryenLocalSet(module, 0, BinaryenCall(module, "check", NULL, 0,
220220
BinaryenTypeInt32()))
221221
};
222222
''' % (i, printed_ids[i])
@@ -226,7 +226,7 @@ def get_phi(j):
226226
BinaryenBlock(module, NULL, list, 2, BinaryenTypeNone()),
227227
BinaryenBinary(module,
228228
BinaryenRemUInt32(),
229-
BinaryenGetLocal(module, 0, BinaryenTypeInt32()),
229+
BinaryenLocalGet(module, 0, BinaryenTypeInt32()),
230230
BinaryenConst(module, BinaryenLiteralInt32(%d))
231231
)
232232
);
@@ -279,7 +279,7 @@ def get_phi(j):
279279
BinaryenEqInt32(),
280280
BinaryenBinary(module,
281281
BinaryenRemUInt32(),
282-
BinaryenGetLocal(module, 0, BinaryenTypeInt32()),
282+
BinaryenLocalGet(module, 0, BinaryenTypeInt32()),
283283
BinaryenConst(module, BinaryenLiteralInt32(%d))
284284
),
285285
BinaryenConst(module, BinaryenLiteralInt32(%d))

scripts/gen-s-parser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
("call_indirect", "makeCallIndirect(s)"),
3333
("drop", "makeDrop(s)"),
3434
("select", "makeSelect(s)"),
35-
("local.get", "makeGetLocal(s)"),
36-
("local.set", "makeSetLocal(s)"),
37-
("local.tee", "makeTeeLocal(s)"),
38-
("global.get", "makeGetGlobal(s)"),
39-
("global.set", "makeSetGlobal(s)"),
35+
("local.get", "makeLocalGet(s)"),
36+
("local.set", "makeLocalSet(s)"),
37+
("local.tee", "makeLocalTee(s)"),
38+
("global.get", "makeGlobalGet(s)"),
39+
("global.set", "makeGlobalSet(s)"),
4040
("memory.init", "makeMemoryInit(s)"),
4141
("data.drop", "makeDataDrop(s)"),
4242
("memory.copy", "makeMemoryCopy(s)"),
@@ -64,8 +64,8 @@
6464
("i64.store8", "makeStore(s, i64, /*isAtomic=*/false)"),
6565
("i64.store16", "makeStore(s, i64, /*isAtomic=*/false)"),
6666
("i64.store32", "makeStore(s, i64, /*isAtomic=*/false)"),
67-
("current_memory", "makeHost(s, HostOp::CurrentMemory)"),
68-
("grow_memory", "makeHost(s, HostOp::GrowMemory)"),
67+
("memory.size", "makeHost(s, HostOp::MemorySize)"),
68+
("memory.grow", "makeHost(s, HostOp::MemoryGrow)"),
6969
("i32.const", "makeConst(s, i32)"),
7070
("i64.const", "makeConst(s, i64)"),
7171
("f32.const", "makeConst(s, f32)"),

src/abi/stack.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
5050
// TODO: find existing stack usage, and add on top of that - carefully
5151
Builder builder(wasm);
5252
auto* block = builder.makeBlock();
53-
block->list.push_back(builder.makeSetLocal(
54-
local, builder.makeGetGlobal(stackPointer->name, PointerType)));
53+
block->list.push_back(builder.makeLocalSet(
54+
local, builder.makeGlobalGet(stackPointer->name, PointerType)));
5555
// TODO: add stack max check
5656
Expression* added;
5757
if (PointerType == i32) {
5858
added = builder.makeBinary(AddInt32,
59-
builder.makeGetLocal(local, PointerType),
59+
builder.makeLocalGet(local, PointerType),
6060
builder.makeConst(Literal(int32_t(size))));
6161
} else {
6262
WASM_UNREACHABLE();
6363
}
64-
block->list.push_back(builder.makeSetGlobal(stackPointer->name, added));
64+
block->list.push_back(builder.makeGlobalSet(stackPointer->name, added));
6565
auto makeStackRestore = [&]() {
66-
return builder.makeSetGlobal(stackPointer->name,
67-
builder.makeGetLocal(local, PointerType));
66+
return builder.makeGlobalSet(stackPointer->name,
67+
builder.makeLocalGet(local, PointerType));
6868
};
6969
// add stack restores to the returns
7070
FindAllPointers<Return> finder(func->body);
@@ -74,10 +74,10 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
7474
// handle the returned value
7575
auto* block = builder.makeBlock();
7676
auto temp = builder.addVar(func, ret->value->type);
77-
block->list.push_back(builder.makeSetLocal(temp, ret->value));
77+
block->list.push_back(builder.makeLocalSet(temp, ret->value));
7878
block->list.push_back(makeStackRestore());
7979
block->list.push_back(
80-
builder.makeReturn(builder.makeGetLocal(temp, ret->value->type)));
80+
builder.makeReturn(builder.makeLocalGet(temp, ret->value->type)));
8181
block->finalize();
8282
*ptr = block;
8383
} else {
@@ -95,9 +95,9 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
9595
} else {
9696
// save the return value
9797
auto temp = builder.addVar(func, func->result);
98-
block->list.push_back(builder.makeSetLocal(temp, func->body));
98+
block->list.push_back(builder.makeLocalSet(temp, func->body));
9999
block->list.push_back(makeStackRestore());
100-
block->list.push_back(builder.makeGetLocal(temp, func->result));
100+
block->list.push_back(builder.makeLocalGet(temp, func->result));
101101
}
102102
block->finalize();
103103
func->body = block;

src/asm2wasm.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
10251025
wasm.addGlobal(
10261026
builder.makeGlobal(name,
10271027
type,
1028-
builder.makeGetGlobal(import->name, type),
1028+
builder.makeGlobalGet(import->name, type),
10291029
Builder::Mutable));
10301030
}
10311031
}
@@ -1262,7 +1262,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
12621262
// when function pointer casts are emulated.
12631263
if (wasm.table.segments.size() == 0) {
12641264
wasm.table.segments.emplace_back(
1265-
builder.makeGetGlobal(Name(TABLE_BASE), i32));
1265+
builder.makeGlobalGet(Name(TABLE_BASE), i32));
12661266
}
12671267
auto& segment = wasm.table.segments[0];
12681268
functionTableStarts[name] =
@@ -1290,7 +1290,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
12901290
IString value = pair[1]->getIString();
12911291
if (key == Name("_emscripten_replace_memory")) {
12921292
// asm.js memory growth provides this special non-asm function,
1293-
// which we don't need (we use grow_memory)
1293+
// which we don't need (we use memory.grow)
12941294
assert(!wasm.getFunctionOrNull(value));
12951295
continue;
12961296
} else if (key == UDIVMODDI4) {
@@ -1732,7 +1732,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
17321732
if (curr->is<Return>()) {
17331733
curr = curr->cast<Return>()->value;
17341734
}
1735-
auto* get = curr->cast<GetGlobal>();
1735+
auto* get = curr->cast<GlobalGet>();
17361736
tempRet0 = get->name;
17371737
}
17381738
// udivmoddi4 receives xl, xh, yl, yl, r, and
@@ -1750,26 +1750,26 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
17501750
y64 = Builder::addVar(func, "y64", i64);
17511751
auto* body = allocator.alloc<Block>();
17521752
body->list.push_back(
1753-
builder.makeSetLocal(x64, I64Utilities::recreateI64(builder, xl, xh)));
1753+
builder.makeLocalSet(x64, I64Utilities::recreateI64(builder, xl, xh)));
17541754
body->list.push_back(
1755-
builder.makeSetLocal(y64, I64Utilities::recreateI64(builder, yl, yh)));
1755+
builder.makeLocalSet(y64, I64Utilities::recreateI64(builder, yl, yh)));
17561756
body->list.push_back(builder.makeIf(
1757-
builder.makeGetLocal(r, i32),
1757+
builder.makeLocalGet(r, i32),
17581758
builder.makeStore(8,
17591759
0,
17601760
8,
1761-
builder.makeGetLocal(r, i32),
1761+
builder.makeLocalGet(r, i32),
17621762
builder.makeBinary(RemUInt64,
1763-
builder.makeGetLocal(x64, i64),
1764-
builder.makeGetLocal(y64, i64)),
1763+
builder.makeLocalGet(x64, i64),
1764+
builder.makeLocalGet(y64, i64)),
17651765
i64)));
17661766
body->list.push_back(
1767-
builder.makeSetLocal(x64,
1767+
builder.makeLocalSet(x64,
17681768
builder.makeBinary(DivUInt64,
1769-
builder.makeGetLocal(x64, i64),
1770-
builder.makeGetLocal(y64, i64))));
1769+
builder.makeLocalGet(x64, i64),
1770+
builder.makeLocalGet(y64, i64))));
17711771
body->list.push_back(
1772-
builder.makeSetGlobal(tempRet0, I64Utilities::getI64High(builder, x64)));
1772+
builder.makeGlobalSet(tempRet0, I64Utilities::getI64High(builder, x64)));
17731773
body->list.push_back(I64Utilities::getI64Low(builder, x64));
17741774
body->finalize();
17751775
func->body = body;
@@ -1855,7 +1855,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
18551855
IString name = ast->getIString();
18561856
if (functionVariables.has(name)) {
18571857
// var in scope
1858-
auto ret = allocator.alloc<GetLocal>();
1858+
auto ret = allocator.alloc<LocalGet>();
18591859
ret->index = function->getLocalIndex(name);
18601860
ret->type = asmToWasmType(asmData.getType(name));
18611861
return ret;
@@ -1883,7 +1883,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
18831883
? true
18841884
: (std::cerr << name.str << '\n', false));
18851885
MappedGlobal& global = mappedGlobals[name];
1886-
return builder.makeGetGlobal(name, global.type);
1886+
return builder.makeGlobalGet(name, global.type);
18871887
}
18881888
if (ast->isNumber()) {
18891889
auto ret = allocator.alloc<Const>();
@@ -1902,7 +1902,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
19021902
auto* assign = ast->asAssignName();
19031903
IString name = assign->target();
19041904
if (functionVariables.has(name)) {
1905-
auto ret = allocator.alloc<SetLocal>();
1905+
auto ret = allocator.alloc<LocalSet>();
19061906
ret->index = function->getLocalIndex(assign->target());
19071907
ret->value = process(assign->value());
19081908
ret->setTee(false);
@@ -1913,15 +1913,15 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
19131913
if (mappedGlobals.find(name) == mappedGlobals.end()) {
19141914
Fatal() << "error: access of a non-existent global var " << name.str;
19151915
}
1916-
auto* ret = builder.makeSetGlobal(name, process(assign->value()));
1916+
auto* ret = builder.makeGlobalSet(name, process(assign->value()));
19171917
// global.set does not return; if our value is trivially not used, don't
19181918
// emit a load (if nontrivially not used, opts get it later)
19191919
auto parent = astStackHelper.getParent();
19201920
if (!parent || parent->isArray(BLOCK) || parent->isArray(IF)) {
19211921
return ret;
19221922
}
19231923
return builder.makeSequence(
1924-
ret, builder.makeGetGlobal(name, ret->value->type));
1924+
ret, builder.makeGlobalGet(name, ret->value->type));
19251925
}
19261926
if (ast->isAssign()) {
19271927
auto* assign = ast->asAssign();
@@ -2155,13 +2155,13 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
21552155
if (value->type == i32) {
21562156
// No wasm support, so use a temp local
21572157
ensureI32Temp();
2158-
auto set = allocator.alloc<SetLocal>();
2158+
auto set = allocator.alloc<LocalSet>();
21592159
set->index = function->getLocalIndex(I32_TEMP);
21602160
set->value = value;
21612161
set->setTee(false);
21622162
set->finalize();
21632163
auto get = [&]() {
2164-
auto ret = allocator.alloc<GetLocal>();
2164+
auto ret = allocator.alloc<LocalGet>();
21652165
ret->index = function->getLocalIndex(I32_TEMP);
21662166
ret->type = i32;
21672167
return ret;
@@ -2264,9 +2264,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
22642264
view.bytes,
22652265
0,
22662266
processUnshifted(ast[2][1], view.bytes),
2267-
builder.makeTeeLocal(temp, process(ast[2][2])),
2267+
builder.makeLocalTee(temp, process(ast[2][2])),
22682268
type),
2269-
builder.makeGetLocal(temp, type));
2269+
builder.makeLocalGet(temp, type));
22702270
} else if (name == Atomics_exchange) {
22712271
return builder.makeAtomicRMW(
22722272
AtomicRMWOp::Xchg,
@@ -3092,7 +3092,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
30923092
// bits, then we can just look at the lower 32 bits
30933093
auto temp = Builder::addVar(function, i64);
30943094
auto* block = builder.makeBlock();
3095-
block->list.push_back(builder.makeSetLocal(temp, offsetor));
3095+
block->list.push_back(builder.makeLocalSet(temp, offsetor));
30963096
// if high bits, we can break to the default (we'll fill in the name
30973097
// later)
30983098
breakWhenNotMatching = builder.makeBreak(
@@ -3101,10 +3101,10 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
31013101
builder.makeUnary(
31023102
UnaryOp::WrapInt64,
31033103
builder.makeBinary(BinaryOp::ShrUInt64,
3104-
builder.makeGetLocal(temp, i64),
3104+
builder.makeLocalGet(temp, i64),
31053105
builder.makeConst(Literal(int64_t(32))))));
31063106
block->list.push_back(breakWhenNotMatching);
3107-
block->list.push_back(builder.makeGetLocal(temp, i64));
3107+
block->list.push_back(builder.makeLocalGet(temp, i64));
31083108
block->finalize();
31093109
br->condition = builder.makeUnary(UnaryOp::WrapInt64, block);
31103110
}
@@ -3158,7 +3158,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
31583158
} else {
31593159
// we can't switch, make an if-chain instead of br_table
31603160
auto var = Builder::addVar(function, br->condition->type);
3161-
top->list.push_back(builder.makeSetLocal(var, br->condition));
3161+
top->list.push_back(builder.makeLocalSet(var, br->condition));
31623162
auto* brHolder = top;
31633163
If* chain = nullptr;
31643164
If* first = nullptr;
@@ -3175,7 +3175,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
31753175
name = nameMapper.pushLabelName("switch-case");
31763176
auto* iff = builder.makeIf(
31773177
builder.makeBinary(br->condition->type == i32 ? EqInt32 : EqInt64,
3178-
builder.makeGetLocal(var, br->condition->type),
3178+
builder.makeLocalGet(var, br->condition->type),
31793179
builder.makeConst(getLiteral(condition))),
31803180
builder.makeBreak(name),
31813181
chain);

0 commit comments

Comments
 (0)