Skip to content

feat: store local name in debug mode binary #2437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 21, 2022
Merged
Prev Previous commit
Next Next commit
refactory
  • Loading branch information
HerrCai0907 committed Aug 16, 2022
commit a5e022a6e6fec154b9c1efb87eda769c1b86ce23
4 changes: 0 additions & 4 deletions src/builtins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10198,7 +10198,6 @@ export function compileVisitGlobals(compiler: Compiler): void {
TypeRef.I32, // cookie
TypeRef.None, // => void
[ sizeTypeRef ],
null,
exprs.length
? module.block(null, exprs)
: module.nop()
Expand Down Expand Up @@ -10305,7 +10304,6 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void {
createType([sizeTypeRef, TypeRef.I32]),
TypeRef.None,
needsTempValue ? [ sizeTypeRef ] : null,
null,
module.flatten(body, TypeRef.None)
);

Expand Down Expand Up @@ -10388,7 +10386,6 @@ export function compileVisitMembers(compiler: Compiler): void {
createType([ sizeTypeRef, TypeRef.I32 ]), // this, cookie
TypeRef.None, // => void
null,
null,
module.flatten([
current,
module.unreachable()
Expand Down Expand Up @@ -10525,7 +10522,6 @@ export function compileClassInstanceOf(compiler: Compiler, prototype: ClassProto
sizeTypeRef,
TypeRef.I32,
null,
null,
module.flatten(stmts)
);
}
Expand Down
25 changes: 8 additions & 17 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ export class Compiler extends DiagnosticEmitter {

// expose the arguments length helper if there are varargs exports
if (this.runtimeFeatures & RuntimeFeatures.setArgumentsLength) {
module.addFunction(BuiltinNames.setArgumentsLength, TypeRef.I32, TypeRef.None, null, null,
module.addFunction(BuiltinNames.setArgumentsLength, TypeRef.I32, TypeRef.None, null,
module.global_set(this.ensureArgumentsLength(), module.local_get(0, TypeRef.I32))
);
module.addFunctionExport(BuiltinNames.setArgumentsLength, ExportNames.setArgumentsLength);
Expand Down Expand Up @@ -784,9 +784,9 @@ export class Compiler extends DiagnosticEmitter {
signature.paramRefs,
signature.resultRefs,
typesToRefs(startFunctionInstance.additionalLocals),
startFunctionInstance.localsByIndex.map<string>(local => local.name),
module.flatten(startFunctionBody)
);
module.setLocalNames(funcRef, startFunctionInstance.localsByIndex.map<string>(local => local.name));
startFunctionInstance.finalize(module, funcRef);
if (exportStart == null) module.setStart(funcRef);
else {
Expand Down Expand Up @@ -1020,14 +1020,14 @@ export class Compiler extends DiagnosticEmitter {
let numLocals = locals.length;
let varTypes = new Array<TypeRef>(numLocals);
for (let i = 0; i < numLocals; ++i) varTypes[i] = locals[i].type.toRef();
module.addFunction(
const funcRef = module.addFunction(
startFunction.internalName,
startSignature.paramRefs,
startSignature.resultRefs,
varTypes,
startFunction.localsByIndex.map<string>(locals => locals.name),
module.flatten(startFunctionBody)
);
module.setLocalNames(funcRef, startFunction.localsByIndex.map<string>(local => local.name));
previousBody.push(
module.call(startFunction.internalName, null, TypeRef.None)
);
Expand Down Expand Up @@ -1477,9 +1477,9 @@ export class Compiler extends DiagnosticEmitter {
signature.paramRefs,
signature.resultRefs,
typesToRefs(instance.additionalLocals),
instance.localsByIndex.map<string>(local => local.name),
module.flatten(stmts, instance.signature.returnType.toRef())
);
module.setLocalNames(funcRef, instance.localsByIndex.map<string>(local => local.name));

// imported function
} else if (instance.is(CommonFlags.AMBIENT)) {
Expand Down Expand Up @@ -1518,7 +1518,6 @@ export class Compiler extends DiagnosticEmitter {
signature.paramRefs,
signature.resultRefs,
null,
null,
module.unreachable()
);
} else {
Expand Down Expand Up @@ -1684,7 +1683,7 @@ export class Compiler extends DiagnosticEmitter {
var valueTypeRef = valueType.toRef();
var thisTypeRef = this.options.sizeTypeRef;
// return this.field
instance.getterRef = module.addFunction(instance.internalGetterName, thisTypeRef, valueTypeRef, null, null,
instance.getterRef = module.addFunction(instance.internalGetterName, thisTypeRef, valueTypeRef, null,
module.load(valueType.byteSize, valueType.isSignedIntegerValue,
module.local_get(0, thisTypeRef),
valueTypeRef, instance.memoryOffset
Expand Down Expand Up @@ -1728,12 +1727,7 @@ export class Compiler extends DiagnosticEmitter {
], TypeRef.None);
}
}
instance.setterRef = module.addFunction(
instance.internalSetterName,
createType([ thisTypeRef, valueTypeRef ]),
TypeRef.None,
null,
null,
instance.setterRef = module.addFunction(instance.internalSetterName, createType([ thisTypeRef, valueTypeRef ]), TypeRef.None, null,
bodyExpr
);
if (instance.getterRef) {
Expand Down Expand Up @@ -6574,7 +6568,6 @@ export class Compiler extends DiagnosticEmitter {
stub.signature.paramRefs,
stub.signature.resultRefs,
typesToRefs(stub.additionalLocals),
null,
module.flatten(stmts, returnType.toRef())
);
stub.set(CommonFlags.COMPILED);
Expand All @@ -6599,7 +6592,6 @@ export class Compiler extends DiagnosticEmitter {
stub.signature.paramRefs,
stub.signature.resultRefs,
null,
null,
module.unreachable()
);
this.virtualStubs.add(original);
Expand Down Expand Up @@ -6724,7 +6716,6 @@ export class Compiler extends DiagnosticEmitter {
stub.signature.paramRefs,
stub.signature.resultRefs,
[ TypeRef.I32 ],
null,
module.block(null, [
builder.render(tempIndex),
body
Expand Down Expand Up @@ -8622,9 +8613,9 @@ export class Compiler extends DiagnosticEmitter {
signature.paramRefs,
signature.resultRefs,
varTypes,
instance.localsByIndex.map<string>(local => local.name),
module.flatten(stmts, sizeTypeRef)
);
module.setLocalNames(funcRef, instance.localsByIndex.map<string>(local => local.name));
instance.finalize(module, funcRef);
}

Expand Down
2 changes: 0 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,6 @@ export class Module {
params: TypeRef,
results: TypeRef,
varTypes: TypeRef[] | null,
localNames: string[] | null,
body: ExpressionRef
): FunctionRef {
var cStr = this.allocStringCached(name);
Expand All @@ -1911,7 +1910,6 @@ export class Module {
body
);
binaryen._free(cArr);
this.setLocalNames(ret, localNames);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/passes/ministack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class MiniStack extends Pass {
module.local_get(numParams, results)
);
}
module.addFunction(wrapperName, params, results, vars, null,
module.addFunction(wrapperName, params, results, vars,
module.block(null, stmts, results)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/passes/shadowstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class ShadowStackPass extends Pass {
var module = this.module;
if (!this.hasStackCheckFunction) {
this.hasStackCheckFunction = true;
module.addFunction("~stack_check", TypeRef.None, TypeRef.None, null, null,
module.addFunction("~stack_check", TypeRef.None, TypeRef.None, null,
module.if(
module.binary(BinaryOp.LtI32,
module.global_get(BuiltinNames.stack_pointer, this.ptrType),
Expand Down