Skip to content

Commit 7cce427

Browse files
committed
feat: add local variant name
1 parent 256a6b0 commit 7cce427

File tree

142 files changed

+113273
-113242
lines changed

Some content is hidden

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

142 files changed

+113273
-113242
lines changed

src/builtins.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10198,6 +10198,7 @@ export function compileVisitGlobals(compiler: Compiler): void {
1019810198
TypeRef.I32, // cookie
1019910199
TypeRef.None, // => void
1020010200
[ sizeTypeRef ],
10201+
null,
1020110202
exprs.length
1020210203
? module.block(null, exprs)
1020310204
: module.nop()
@@ -10304,6 +10305,7 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void {
1030410305
createType([sizeTypeRef, TypeRef.I32]),
1030510306
TypeRef.None,
1030610307
needsTempValue ? [ sizeTypeRef ] : null,
10308+
null,
1030710309
module.flatten(body, TypeRef.None)
1030810310
);
1030910311

@@ -10386,6 +10388,7 @@ export function compileVisitMembers(compiler: Compiler): void {
1038610388
createType([ sizeTypeRef, TypeRef.I32 ]), // this, cookie
1038710389
TypeRef.None, // => void
1038810390
null,
10391+
null,
1038910392
module.flatten([
1039010393
current,
1039110394
module.unreachable()
@@ -10522,6 +10525,7 @@ export function compileClassInstanceOf(compiler: Compiler, prototype: ClassProto
1052210525
sizeTypeRef,
1052310526
TypeRef.I32,
1052410527
null,
10528+
null,
1052510529
module.flatten(stmts)
1052610530
);
1052710531
}

src/compiler.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ export class Compiler extends DiagnosticEmitter {
749749

750750
// expose the arguments length helper if there are varargs exports
751751
if (this.runtimeFeatures & RuntimeFeatures.setArgumentsLength) {
752-
module.addFunction(BuiltinNames.setArgumentsLength, TypeRef.I32, TypeRef.None, null,
752+
module.addFunction(BuiltinNames.setArgumentsLength, TypeRef.I32, TypeRef.None, null, null,
753753
module.global_set(this.ensureArgumentsLength(), module.local_get(0, TypeRef.I32))
754754
);
755755
module.addFunctionExport(BuiltinNames.setArgumentsLength, ExportNames.setArgumentsLength);
@@ -784,6 +784,7 @@ export class Compiler extends DiagnosticEmitter {
784784
signature.paramRefs,
785785
signature.resultRefs,
786786
typesToRefs(startFunctionInstance.additionalLocals),
787+
startFunctionInstance.localsByIndex.map<string>(local => local.internalName),
787788
module.flatten(startFunctionBody)
788789
);
789790
startFunctionInstance.finalize(module, funcRef);
@@ -1024,6 +1025,7 @@ export class Compiler extends DiagnosticEmitter {
10241025
startSignature.paramRefs,
10251026
startSignature.resultRefs,
10261027
varTypes,
1028+
startFunction.localsByIndex.map<string>(locals => locals.internalName),
10271029
module.flatten(startFunctionBody)
10281030
);
10291031
previousBody.push(
@@ -1475,6 +1477,7 @@ export class Compiler extends DiagnosticEmitter {
14751477
signature.paramRefs,
14761478
signature.resultRefs,
14771479
typesToRefs(instance.additionalLocals),
1480+
instance.localsByIndex.map<string>(local => local.internalName),
14781481
module.flatten(stmts, instance.signature.returnType.toRef())
14791482
);
14801483

@@ -1515,6 +1518,7 @@ export class Compiler extends DiagnosticEmitter {
15151518
signature.paramRefs,
15161519
signature.resultRefs,
15171520
null,
1521+
null,
15181522
module.unreachable()
15191523
);
15201524
} else {
@@ -1680,7 +1684,7 @@ export class Compiler extends DiagnosticEmitter {
16801684
var valueTypeRef = valueType.toRef();
16811685
var thisTypeRef = this.options.sizeTypeRef;
16821686
// return this.field
1683-
instance.getterRef = module.addFunction(instance.internalGetterName, thisTypeRef, valueTypeRef, null,
1687+
instance.getterRef = module.addFunction(instance.internalGetterName, thisTypeRef, valueTypeRef, null, null,
16841688
module.load(valueType.byteSize, valueType.isSignedIntegerValue,
16851689
module.local_get(0, thisTypeRef),
16861690
valueTypeRef, instance.memoryOffset
@@ -1724,7 +1728,10 @@ export class Compiler extends DiagnosticEmitter {
17241728
], TypeRef.None);
17251729
}
17261730
}
1727-
instance.setterRef = module.addFunction(instance.internalSetterName, createType([ thisTypeRef, valueTypeRef ]), TypeRef.None, null,
1731+
instance.setterRef = module.addFunction(
1732+
instance.internalSetterName,
1733+
createType([ thisTypeRef, valueTypeRef ]),
1734+
TypeRef.None, null, null,
17281735
bodyExpr
17291736
);
17301737
if (instance.getterRef) {
@@ -6565,6 +6572,7 @@ export class Compiler extends DiagnosticEmitter {
65656572
stub.signature.paramRefs,
65666573
stub.signature.resultRefs,
65676574
typesToRefs(stub.additionalLocals),
6575+
null,
65686576
module.flatten(stmts, returnType.toRef())
65696577
);
65706578
stub.set(CommonFlags.COMPILED);
@@ -6588,7 +6596,7 @@ export class Compiler extends DiagnosticEmitter {
65886596
stub.internalName,
65896597
stub.signature.paramRefs,
65906598
stub.signature.resultRefs,
6591-
null,
6599+
null, null,
65926600
module.unreachable()
65936601
);
65946602
this.virtualStubs.add(original);
@@ -6713,6 +6721,7 @@ export class Compiler extends DiagnosticEmitter {
67136721
stub.signature.paramRefs,
67146722
stub.signature.resultRefs,
67156723
[ TypeRef.I32 ],
6724+
null,
67166725
module.block(null, [
67176726
builder.render(tempIndex),
67186727
body
@@ -8610,6 +8619,7 @@ export class Compiler extends DiagnosticEmitter {
86108619
signature.paramRefs,
86118620
signature.resultRefs,
86128621
varTypes,
8622+
instance.localsByIndex.map<string>(local => local.internalName),
86138623
module.flatten(stmts, sizeTypeRef)
86148624
);
86158625
instance.finalize(module, funcRef);

src/module.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ export class Module {
18961896
params: TypeRef,
18971897
results: TypeRef,
18981898
varTypes: TypeRef[] | null,
1899+
localNames: string[] | null,
18991900
body: ExpressionRef
19001901
): FunctionRef {
19011902
var cStr = this.allocStringCached(name);
@@ -1910,6 +1911,22 @@ export class Module {
19101911
body
19111912
);
19121913
binaryen._free(cArr);
1914+
if (localNames) {
1915+
let localNameMap = new Set<string>();
1916+
for (let i = 0, k = localNames.length; i < k; i++) {
1917+
let localNameParts = localNames[i].split("~");
1918+
let localName = localNameParts[localNameParts.length - 1];
1919+
if (localNameMap.has(localName)) {
1920+
let repeat = 0;
1921+
while (localNameMap.has(`${localName}_${repeat}`)) {
1922+
repeat++;
1923+
}
1924+
localName = `${localName}_${repeat}`;
1925+
}
1926+
localNameMap.add(localName);
1927+
binaryen._BinaryenFunctionSetLocalName(ret, i, this.allocStringCached(localName));
1928+
}
1929+
}
19131930
return ret;
19141931
}
19151932

src/passes/ministack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class MiniStack extends Pass {
144144
module.local_get(numParams, results)
145145
);
146146
}
147-
module.addFunction(wrapperName, params, results, vars,
147+
module.addFunction(wrapperName, params, results, vars, null,
148148
module.block(null, stmts, results)
149149
);
150150
}

src/passes/shadowstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export class ShadowStackPass extends Pass {
317317
var module = this.module;
318318
if (!this.hasStackCheckFunction) {
319319
this.hasStackCheckFunction = true;
320-
module.addFunction("~stack_check", TypeRef.None, TypeRef.None, null,
320+
module.addFunction("~stack_check", TypeRef.None, TypeRef.None, null, null,
321321
module.if(
322322
module.binary(BinaryOp.LtI32,
323323
module.global_get(BuiltinNames.stack_pointer, this.ptrType),

0 commit comments

Comments
 (0)