Skip to content

Commit 7acff76

Browse files
authored
Update Binaryen (#1009)
1 parent 4e00fa3 commit 7acff76

File tree

277 files changed

+7704
-7699
lines changed

Some content is hidden

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

277 files changed

+7704
-7699
lines changed

package-lock.json

Lines changed: 108 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
2222
},
2323
"dependencies": {
24-
"binaryen": "89.0.0-nightly.20191204",
24+
"binaryen": "89.0.0-nightly.20191215",
2525
"long": "^4.0.0",
2626
"source-map-support": "^0.5.16",
27-
"ts-node": "^6.2.0",
28-
"typescript": "^3.7.2"
27+
"ts-node": "^6.2.0"
2928
},
3029
"devDependencies": {
31-
"@types/node": "^12.12.7",
30+
"@types/node": "^12.12.17",
3231
"browser-process-hrtime": "^1.0.0",
3332
"diff": "^4.0.1",
3433
"glob": "^7.1.6",
@@ -38,8 +37,8 @@
3837
"ts-node": "^6.2.0",
3938
"tslint": "^5.20.1",
4039
"typedoc-plugin-external-module-name": "^2.1.0",
41-
"typescript": "^3.7.2",
42-
"webpack": "^4.41.2",
40+
"typescript": "^3.7.3",
41+
"webpack": "^4.41.3",
4342
"webpack-cli": "^3.3.10"
4443
},
4544
"main": "index.js",

src/builtins.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ import {
5555
RelooperBlockRef,
5656
SIMDLoadOp,
5757
getLocalGetIndex,
58-
hasSideEffects
58+
hasSideEffects,
59+
createType
5960
} from "./module";
6061

6162
import {
@@ -4757,7 +4758,6 @@ export function compileAbort(
47574758
export function compileVisitGlobals(compiler: Compiler): void {
47584759
var module = compiler.module;
47594760
var exprs = new Array<ExpressionRef>();
4760-
var typeRef = compiler.ensureFunctionType([ Type.u32 ], Type.void); // cookie
47614761
var nativeSizeType = compiler.options.nativeSizeType;
47624762
var visitInstance = assert(compiler.program.visitInstance);
47634763

@@ -4800,7 +4800,10 @@ export function compileVisitGlobals(compiler: Compiler): void {
48004800
}
48014801
}
48024802
}
4803-
module.addFunction(BuiltinSymbols.visit_globals, typeRef, [ nativeSizeType ],
4803+
module.addFunction(BuiltinSymbols.visit_globals,
4804+
NativeType.I32, // cookie
4805+
NativeType.None, // => void
4806+
[ nativeSizeType ],
48044807
exprs.length
48054808
? module.block(null, exprs)
48064809
: module.nop()
@@ -4814,7 +4817,6 @@ export function compileVisitMembers(compiler: Compiler): void {
48144817
var usizeType = program.options.usizeType;
48154818
var nativeSizeType = usizeType.toNativeType();
48164819
var nativeSizeSize = usizeType.byteSize;
4817-
var ftype = compiler.ensureFunctionType([ usizeType, Type.i32 ], Type.void); // ref, cookie
48184820
var managedClasses = program.managedClasses;
48194821
var visitInstance = assert(program.visitInstance);
48204822
var blocks = new Array<RelooperBlockRef>();
@@ -4921,7 +4923,12 @@ export function compileVisitMembers(compiler: Compiler): void {
49214923
);
49224924
relooper.addBranchForSwitch(outer, blocks[blocks.length - 1], []); // default
49234925
compiler.compileFunction(visitInstance);
4924-
module.addFunction(BuiltinSymbols.visit_members, ftype, [ nativeSizeType ], relooper.renderAndDispose(outer, 2));
4926+
module.addFunction(BuiltinSymbols.visit_members,
4927+
createType([ usizeType.toNativeType(), NativeType.I32 ]), // ref, cookie
4928+
NativeType.None, // => void
4929+
[ nativeSizeType ],
4930+
relooper.renderAndDispose(outer, 2)
4931+
);
49254932
}
49264933

49274934
function typeToRuntimeFlags(type: Type): TypeinfoFlags {

src/compiler.ts

Lines changed: 24 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
NativeType,
2727
FunctionRef,
2828
ExpressionId,
29-
FunctionTypeRef,
3029
GlobalRef,
3130
EventRef,
3231
FeatureFlags,
@@ -46,7 +45,8 @@ import {
4645
needsExplicitUnreachable,
4746
getLocalSetValue,
4847
getGlobalGetName,
49-
isGlobalMutable
48+
isGlobalMutable,
49+
createType
5050
} from "./module";
5151

5252
import {
@@ -395,11 +395,8 @@ export class Compiler extends DiagnosticEmitter {
395395
}
396396
let funcRef = module.addFunction(
397397
startFunctionInstance.internalName,
398-
this.ensureFunctionType(
399-
signature.parameterTypes,
400-
signature.returnType,
401-
signature.thisType
402-
),
398+
signature.nativeParams,
399+
signature.nativeResults,
403400
typesToNativeTypes(startFunctionInstance.additionalLocals),
404401
module.block(null, startFunctionBody)
405402
);
@@ -456,7 +453,7 @@ export class Compiler extends DiagnosticEmitter {
456453
// set up function table
457454
var functionTable = this.functionTable;
458455
module.setFunctionTable(functionTable.length, Module.UNLIMITED_TABLE, functionTable, module.i32(0));
459-
module.addFunction("null", this.ensureFunctionType(null, Type.void), null, module.unreachable());
456+
module.addFunction("null", NativeType.None, NativeType.None, null, module.unreachable());
460457

461458
// import table if requested (default table is named '0' by Binaryen)
462459
if (options.importTable) module.addTableImport("0", "env", "table");
@@ -628,7 +625,8 @@ export class Compiler extends DiagnosticEmitter {
628625
if (type.isManaged) loadExpr = this.makeRetain(loadExpr);
629626
module.addFunction(
630627
name,
631-
this.ensureFunctionType(null, type, usizeType),
628+
usizeType.toNativeType(),
629+
type.toNativeType(),
632630
null,
633631
loadExpr
634632
);
@@ -654,7 +652,8 @@ export class Compiler extends DiagnosticEmitter {
654652
}
655653
module.addFunction(
656654
name,
657-
this.ensureFunctionType([ type ], Type.void, usizeType),
655+
createType([ usizeType.toNativeType(), type.toNativeType() ]),
656+
NativeType.None,
658657
null,
659658
module.store(
660659
type.byteSize,
@@ -759,6 +758,7 @@ export class Compiler extends DiagnosticEmitter {
759758

760759
// compile top-level statements within the file's start function
761760
var startFunction = file.startFunction;
761+
var startSignature = startFunction.signature;
762762
var previousBody = this.currentBody;
763763
var startFunctionBody = new Array<ExpressionRef>();
764764
this.currentBody = startFunctionBody;
@@ -781,9 +781,11 @@ export class Compiler extends DiagnosticEmitter {
781781
let numLocals = locals.length;
782782
let varTypes = new Array<NativeType>(numLocals);
783783
for (let i = 0; i < numLocals; ++i) varTypes[i] = locals[i].type.toNativeType();
784+
784785
module.addFunction(
785786
startFunction.internalName,
786-
this.ensureFunctionType(startFunction.signature.parameterTypes, startFunction.signature.returnType),
787+
startSignature.nativeParams,
788+
startSignature.nativeResults,
787789
varTypes,
788790
startFunctionBody.length > 1
789791
? module.block(null, startFunctionBody)
@@ -1112,51 +1114,6 @@ export class Compiler extends DiagnosticEmitter {
11121114
return instance;
11131115
}
11141116

1115-
/** Either reuses or creates the function type matching the specified signature. */
1116-
ensureFunctionType(
1117-
parameterTypes: Type[] | null,
1118-
returnType: Type,
1119-
thisType: Type | null = null
1120-
): FunctionTypeRef {
1121-
var numParameters = parameterTypes ? parameterTypes.length : 0;
1122-
var paramTypes: NativeType[];
1123-
var index = 0;
1124-
if (thisType) {
1125-
paramTypes = new Array(1 + numParameters);
1126-
paramTypes[0] = thisType.toNativeType();
1127-
index = 1;
1128-
} else {
1129-
paramTypes = new Array(numParameters);
1130-
}
1131-
if (parameterTypes) {
1132-
for (let i = 0; i < numParameters; ++i, ++index) {
1133-
paramTypes[index] = parameterTypes[i].toNativeType();
1134-
}
1135-
}
1136-
var resultType = returnType.toNativeType();
1137-
var module = this.module;
1138-
var typeRef = module.getFunctionTypeBySignature(resultType, paramTypes);
1139-
if (!typeRef) {
1140-
let name = Signature.makeSignatureString(parameterTypes, returnType, thisType);
1141-
typeRef = module.addFunctionType(name, resultType, paramTypes);
1142-
}
1143-
return typeRef;
1144-
}
1145-
1146-
/** Either reuses or creates the event type matching the specified name. */
1147-
ensureEventType(
1148-
name: string,
1149-
parameterTypes: Type[] | null
1150-
): EventRef {
1151-
var events = this.events;
1152-
if (events.has(name)) return events.get(name)!;
1153-
var module = this.module;
1154-
var funcType = this.ensureFunctionType(parameterTypes, Type.void);
1155-
var eventType = module.addEvent(name, 0, funcType);
1156-
events.set(name, eventType);
1157-
return eventType;
1158-
}
1159-
11601117
/** Compiles the body of a function within the specified flow. */
11611118
compileFunctionBody(
11621119
/** Function to compile. */
@@ -1274,7 +1231,6 @@ export class Compiler extends DiagnosticEmitter {
12741231
var signature = instance.signature;
12751232
var bodyNode = instance.prototype.bodyNode;
12761233

1277-
var typeRef = this.ensureFunctionType(signature.parameterTypes, signature.returnType, signature.thisType);
12781234
var funcRef: FunctionRef;
12791235

12801236
// concrete function
@@ -1336,7 +1292,8 @@ export class Compiler extends DiagnosticEmitter {
13361292
// create the function
13371293
funcRef = module.addFunction(
13381294
instance.internalName,
1339-
typeRef,
1295+
signature.nativeParams,
1296+
signature.nativeResults,
13401297
typesToNativeTypes(instance.additionalLocals),
13411298
flatten(module, stmts, instance.signature.returnType.toNativeType())
13421299
);
@@ -1358,7 +1315,8 @@ export class Compiler extends DiagnosticEmitter {
13581315
instance.internalName,
13591316
mangleImportName_moduleName,
13601317
mangleImportName_elementName,
1361-
typeRef
1318+
signature.nativeParams,
1319+
signature.nativeResults
13621320
);
13631321
funcRef = module.getFunction(instance.internalName);
13641322
}
@@ -6404,11 +6362,8 @@ export class Compiler extends DiagnosticEmitter {
64046362

64056363
var funcRef = module.addFunction(
64066364
trampoline.internalName,
6407-
this.ensureFunctionType(
6408-
trampolineSignature.parameterTypes,
6409-
returnType,
6410-
thisType
6411-
),
6365+
trampolineSignature.nativeParams,
6366+
trampolineSignature.nativeResults,
64126367
typesToNativeTypes(trampoline.additionalLocals),
64136368
module.block(null, stmts, returnType.toNativeType())
64146369
);
@@ -6435,7 +6390,8 @@ export class Compiler extends DiagnosticEmitter {
64356390
if (!this.argcSet) {
64366391
let module = this.module;
64376392
this.argcSet = module.addFunction(BuiltinSymbols.setargc,
6438-
this.ensureFunctionType([ Type.u32 ], Type.void),
6393+
NativeType.I32,
6394+
NativeType.None,
64396395
null,
64406396
module.global_set(this.ensureArgcVar(),
64416397
module.local_get(0, NativeType.I32)
@@ -6906,7 +6862,6 @@ export class Compiler extends DiagnosticEmitter {
69066862
}
69076863
assert(numOperands >= minOperands);
69086864

6909-
this.ensureFunctionType(signature.parameterTypes, signature.returnType, signature.thisType);
69106865
var module = this.module;
69116866

69126867
// fill up omitted arguments with zeroes
@@ -6931,7 +6886,8 @@ export class Compiler extends DiagnosticEmitter {
69316886
? module.unary(UnaryOp.WrapI64, indexArg)
69326887
: indexArg,
69336888
operands,
6934-
signature.toSignatureString()
6889+
signature.nativeParams,
6890+
signature.nativeResults
69356891
)
69366892
], returnType.toNativeType());
69376893
this.currentType = returnType;
@@ -7951,15 +7907,14 @@ export class Compiler extends DiagnosticEmitter {
79517907
this.currentFlow = previousFlow;
79527908

79537909
// make the function
7954-
var typeRef = this.ensureFunctionType(signature.parameterTypes, signature.returnType, signature.thisType);
79557910
var locals = instance.localsByIndex;
79567911
var varTypes = new Array<NativeType>(); // of temp. vars added while compiling initializers
79577912
var numOperands = 1 + signature.parameterTypes.length;
79587913
var numLocals = locals.length;
79597914
if (numLocals > numOperands) {
79607915
for (let i = numOperands; i < numLocals; ++i) varTypes.push(locals[i].type.toNativeType());
79617916
}
7962-
var funcRef = module.addFunction(instance.internalName, typeRef, varTypes, body);
7917+
var funcRef = module.addFunction(instance.internalName, signature.nativeParams, signature.nativeResults, varTypes, body);
79637918
instance.finalize(module, funcRef);
79647919
return instance;
79657920
}

src/decompiler.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import {
1515
Index,
1616
getFunctionName,
1717
getFunctionBody,
18-
getFunctionParamCount,
19-
getFunctionParamType,
20-
getFunctionResultType,
18+
getFunctionParams,
19+
getFunctionResults,
2120
getExpressionId,
2221
getExpressionType,
2322
getBlockName,
@@ -54,7 +53,8 @@ import {
5453
getDropValue,
5554
getReturnValue,
5655
getHostOp,
57-
getHostOperand
56+
getHostOperand,
57+
expandType
5858
} from "./module";
5959

6060
// TODO :-)
@@ -83,15 +83,27 @@ export class Decompiler {
8383
this.push("function ");
8484
this.push(name);
8585
this.push("(");
86-
for (let i: Index = 0, k: Index = getFunctionParamCount(func); i < k; ++i) {
86+
var params = expandType(getFunctionParams(func));
87+
for (let i = 0, k = params.length; i < k; ++i) {
8788
if (i > 0) this.push(", ");
8889
this.push("$");
8990
this.push(i.toString(10));
9091
this.push(": ");
91-
this.push(nativeTypeToType(getFunctionParamType(func, i)));
92+
this.push(nativeTypeToType(params[i]));
9293
}
9394
this.push("): ");
94-
this.push(nativeTypeToType(getFunctionResultType(func)));
95+
var results = expandType(getFunctionResults(func));
96+
switch (results.length) {
97+
case 0: {
98+
this.push("void");
99+
break;
100+
}
101+
default: assert(false); // TODO: multi-value
102+
case 1: {
103+
this.push(nativeTypeToType(results[0]));
104+
break;
105+
}
106+
}
95107
this.push(" ");
96108
if (getExpressionId(body) != ExpressionId.Block) {
97109
this.push("{\n");

0 commit comments

Comments
 (0)