Skip to content

Commit

Permalink
Update binaryen (AssemblyScript#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey authored Jul 4, 2021
1 parent f4091b8 commit b95886d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 69 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues"
},
"dependencies": {
"binaryen": "101.0.0-nightly.20210604",
"binaryen": "101.0.0-nightly.20210703",
"long": "^4.0.0",
"source-map-support": "^0.5.19",
"ts-node": "^6.2.0"
Expand Down
39 changes: 19 additions & 20 deletions src/glue/binaryen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type FunctionRef = Ref;
export type ImportRef = Ref;
export type ExportRef = Ref;
export type GlobalRef = Ref;
export type EventRef = Ref;
export type TagRef = Ref;
export type TableRef = Ref;
export type ElementSegmentRef = Ref;
export type RelooperRef = Ref;
Expand Down Expand Up @@ -410,18 +410,18 @@ export declare function _BinaryenRefEqSetLeft(expr: ExpressionRef, leftExpr: Exp
export declare function _BinaryenRefEqGetRight(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenRefEqSetRight(expr: ExpressionRef, rightExpr: ExpressionRef): void;

export declare function _BinaryenTry(module: ModuleRef, name: StringRef, bodyExpr: ExpressionRef, catchEvents: ArrayRef<StringRef>, numCatchEvents: Index, catchBodies: ArrayRef<ExpressionRef>, numCatchBodies: Index, delegateTarget: StringRef): ExpressionRef;
export declare function _BinaryenTry(module: ModuleRef, name: StringRef, bodyExpr: ExpressionRef, catchTags: ArrayRef<StringRef>, numCatchTags: Index, catchBodies: ArrayRef<ExpressionRef>, numCatchBodies: Index, delegateTarget: StringRef): ExpressionRef;
export declare function _BinaryenTryGetName(expr: ExpressionRef): StringRef;
export declare function _BinaryenTrySetName(expr: ExpressionRef, name: StringRef): void;
export declare function _BinaryenTryGetBody(expr: ExpressionRef): ExpressionRef;
export declare function _BinaryenTrySetBody(expr: ExpressionRef, bodyExpr: ExpressionRef): void;
export declare function _BinaryenTryGetNumCatchEvents(expr: ExpressionRef): Index;
export declare function _BinaryenTryGetNumCatchTags(expr: ExpressionRef): Index;
export declare function _BinaryenTryGetNumCatchBodies(expr: ExpressionRef): Index;
export declare function _BinaryenTryGetCatchEventAt(expr: ExpressionRef, index: Index): StringRef;
export declare function _BinaryenTrySetCatchEventAt(expr: ExpressionRef, index: Index, catchEvent: StringRef): void;
export declare function _BinaryenTryAppendCatchEvent(expr: ExpressionRef, catchEvent: StringRef): Index;
export declare function _BinaryenTryInsertCatchEventAt(expr: ExpressionRef, index: Index, catchEvent: StringRef): void;
export declare function _BinaryenTryRemoveCatchEventAt(expr: ExpressionRef, index: Index): StringRef;
export declare function _BinaryenTryGetCatchTagAt(expr: ExpressionRef, index: Index): StringRef;
export declare function _BinaryenTrySetCatchTagAt(expr: ExpressionRef, index: Index, catchTag: StringRef): void;
export declare function _BinaryenTryAppendCatchTag(expr: ExpressionRef, catchTag: StringRef): Index;
export declare function _BinaryenTryInsertCatchTagAt(expr: ExpressionRef, index: Index, catchTag: StringRef): void;
export declare function _BinaryenTryRemoveCatchTagAt(expr: ExpressionRef, index: Index): StringRef;
export declare function _BinaryenTryGetCatchBodyAt(expr: ExpressionRef, index: Index): ExpressionRef;
export declare function _BinaryenTrySetCatchBodyAt(expr: ExpressionRef, index: Index, catchExpr: ExpressionRef): void;
export declare function _BinaryenTryAppendCatchBody(expr: ExpressionRef, catchExpr: ExpressionRef): Index;
Expand All @@ -432,9 +432,9 @@ export declare function _BinaryenTryGetDelegateTarget(expr: ExpressionRef): Stri
export declare function _BinaryenTrySetDelegateTarget(expr: ExpressionRef, delegateTarget: StringRef): void;
export declare function _BinaryenTryIsDelegate(expr: ExpressionRef): bool;

export declare function _BinaryenThrow(module: ModuleRef, eventName: StringRef, operands: ArrayRef<ExpressionRef>, numOperands: Index): ExpressionRef;
export declare function _BinaryenThrowGetEvent(expr: ExpressionRef): StringRef;
export declare function _BinaryenThrowSetEvent(expr: ExpressionRef, eventName: StringRef): void;
export declare function _BinaryenThrow(module: ModuleRef, tagName: StringRef, operands: ArrayRef<ExpressionRef>, numOperands: Index): ExpressionRef;
export declare function _BinaryenThrowGetTag(expr: ExpressionRef): StringRef;
export declare function _BinaryenThrowSetTag(expr: ExpressionRef, tagName: StringRef): void;
export declare function _BinaryenThrowGetNumOperands(expr: ExpressionRef): Index;
export declare function _BinaryenThrowGetOperandAt(expr: ExpressionRef, index: Index): ExpressionRef;
export declare function _BinaryenThrowSetOperandAt(expr: ExpressionRef, index: Index, operandExpr: ExpressionRef): void;
Expand Down Expand Up @@ -497,13 +497,13 @@ export declare function _BinaryenAddFunctionImport(module: ModuleRef, internalNa
export declare function _BinaryenAddTableImport(module: ModuleRef, internalName: StringRef, externalModuleName: StringRef, externalBaseName: StringRef): void;
export declare function _BinaryenAddMemoryImport(module: ModuleRef, internalName: StringRef, externalModuleName: StringRef, externalBaseName: StringRef, shared:bool): void;
export declare function _BinaryenAddGlobalImport(module: ModuleRef, internalName: StringRef, externalModuleName: StringRef, externalBaseName: StringRef, globalType: TypeRef, mutable: bool): void;
export declare function _BinaryenAddEventImport(module: ModuleRef, internalName: StringRef, externalModuleName: StringRef, externalBaseName: StringRef, attribute: u32, params: TypeRef, results: TypeRef): void;
export declare function _BinaryenAddTagImport(module: ModuleRef, internalName: StringRef, externalModuleName: StringRef, externalBaseName: StringRef, params: TypeRef, results: TypeRef): void;

export declare function _BinaryenAddFunctionExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenAddTableExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenAddMemoryExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenAddGlobalExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenAddEventExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenAddTagExport(module: ModuleRef, internalName: StringRef, externalName: StringRef): ExportRef;
export declare function _BinaryenGetExport(module: ModuleRef, externalName: StringRef): ExportRef;
export declare function _BinaryenRemoveExport(module: ModuleRef, externalName: StringRef): void;
export declare function _BinaryenGetNumExports(module: ModuleRef): Index;
Expand All @@ -523,14 +523,13 @@ export declare function _BinaryenGlobalGetType(global: GlobalRef): TypeRef;
export declare function _BinaryenGlobalIsMutable(global: GlobalRef): bool;
export declare function _BinaryenGlobalGetInitExpr(global: GlobalRef): ExpressionRef;

export declare function _BinaryenAddEvent(module: ModuleRef, name: StringRef, attribute: u32, params: TypeRef, results: TypeRef): EventRef;
export declare function _BinaryenGetEvent(module: ModuleRef, name: StringRef): EventRef;
export declare function _BinaryenRemoveEvent(module: ModuleRef, name: StringRef): void;
export declare function _BinaryenAddTag(module: ModuleRef, name: StringRef, params: TypeRef, results: TypeRef): TagRef;
export declare function _BinaryenGetTag(module: ModuleRef, name: StringRef): TagRef;
export declare function _BinaryenRemoveTag(module: ModuleRef, name: StringRef): void;

export declare function _BinaryenEventGetName(event: EventRef): StringRef;
export declare function _BinaryenEventGetAttribute(event: EventRef): u32;
export declare function _BinaryenEventGetParams(event: EventRef): TypeRef;
export declare function _BinaryenEventGetResults(event: EventRef): TypeRef;
export declare function _BinaryenTagGetName(tag: TagRef): StringRef;
export declare function _BinaryenTagGetParams(tag: TagRef): TypeRef;
export declare function _BinaryenTagGetResults(tag: TagRef): TypeRef;

export declare function _BinaryenAddTable(module: ModuleRef, name: StringRef, initial: Index, maximum: Index): TableRef;
export declare function _BinaryenRemoveTable(module: ModuleRef, table: StringRef): void;
Expand Down
70 changes: 32 additions & 38 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export type FunctionRef = binaryen.FunctionRef;
export type ExpressionRef = binaryen.ExpressionRef;
/** Reference to a Binaryen global. */
export type GlobalRef = binaryen.GlobalRef;
/** Reference to a Binaryen event. */
export type EventRef = binaryen.EventRef;
/** Reference to a Binaryen tag. */
export type TagRef = binaryen.TagRef;
/** Reference to a Binaryen import. */
export type ImportRef = binaryen.ImportRef;
/** Reference to a Binaryen export. */
Expand Down Expand Up @@ -155,7 +155,7 @@ export enum ExternalKind {
Table = 1 /* _BinaryenExternalTable */,
Memory = 2 /* _BinaryenExternalMemory */,
Global = 3 /* _BinaryenExternalGlobal */,
Event = 4 /* _BinaryenExternalEvent */
Tag = 4 /* _BinaryenExternalTag */
}

/** Binaryen unary operation constants. */
Expand Down Expand Up @@ -1584,27 +1584,27 @@ export class Module {

// try(
// body: ExpressionRef,
// catchEvents: string[],
// catchTags: string[],
// catchBodies: ExpressionRef[]
// ): ExpressionRef {
// var numCatchEvents = catchEvents.length;
// var strs = new Array<EventRef>(numCatchEvents);
// for (let i = 0; i < numCatchEvents; ++i) {
// strs[i] = this.allocStringCached(catchEvents[i]);
// var numCatchTags = catchTags.length;
// var strs = new Array<TagRef>(numCatchTags);
// for (let i = 0; i < numCatchTags; ++i) {
// strs[i] = this.allocStringCached(catchTags[i]);
// }
// var cArr1 = allocPtrArray(strs);
// var cArr2 = allocPtrArray(catchBodies);
// var ret = binaryen._BinaryenTry(this.ref, body, cArr1, numCatchEvents, cArr2, catchBodies.length);
// var ret = binaryen._BinaryenTry(this.ref, body, cArr1, numCatchTags, cArr2, catchBodies.length);
// binaryen._free(cArr2);
// binaryen._free(cArr1);
// return ret;
// }

throw(
eventName: string,
tagName: string,
operands: ExpressionRef[]
): ExpressionRef {
var cStr = this.allocStringCached(eventName);
var cStr = this.allocStringCached(tagName);
var cArr = allocPtrArray(operands);
var ret = binaryen._BinaryenThrow(this.ref, cStr, cArr, operands.length);
binaryen._free(cArr);
Expand Down Expand Up @@ -1768,30 +1768,29 @@ export class Module {
binaryen._BinaryenRemoveGlobal(this.ref, cStr);
}

// events
// tags

addEvent(
addTag(
name: string,
attribute: u32,
params: TypeRef,
results: TypeRef
): EventRef {
): TagRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenAddEvent(this.ref, cStr, attribute, params, results);
return binaryen._BinaryenAddTag(this.ref, cStr, params, results);
}

getEvent(
getTag(
name: string
): EventRef {
): TagRef {
var cStr = this.allocStringCached(name);
return binaryen._BinaryenGetEvent(this.ref, cStr);
return binaryen._BinaryenGetTag(this.ref, cStr);
}

removeEvent(
removeTag(
name: string
): void {
var cStr = this.allocStringCached(name);
binaryen._BinaryenRemoveEvent(this.ref, cStr);
binaryen._BinaryenRemoveTag(this.ref, cStr);
}

// functions
Expand Down Expand Up @@ -1904,13 +1903,13 @@ export class Module {
return binaryen._BinaryenAddGlobalExport(this.ref, cStr1, cStr2);
}

addEventExport(
addTagExport(
internalName: string,
externalName: string
): ExportRef {
var cStr1 = this.allocStringCached(internalName);
var cStr2 = this.allocStringCached(externalName);
return binaryen._BinaryenAddEventExport(this.ref, cStr1, cStr2);
return binaryen._BinaryenAddTagExport(this.ref, cStr1, cStr2);
}

removeExport(externalName: string): void {
Expand Down Expand Up @@ -1974,19 +1973,18 @@ export class Module {
binaryen._BinaryenAddGlobalImport(this.ref, cStr1, cStr2, cStr3, globalType, mutable);
}

addEventImport(
addTagImport(
internalName: string,
externalModuleName: string,
externalBaseName: string,
attribute: u32,
params: TypeRef,
results: TypeRef
): void {
var cStr1 = this.allocStringCached(internalName);
var cStr2 = this.allocStringCached(externalModuleName);
var cStr3 = this.allocStringCached(externalBaseName);
binaryen._BinaryenAddEventImport(
this.ref, cStr1, cStr2, cStr3, attribute, params, results
binaryen._BinaryenAddTagImport(
this.ref, cStr1, cStr2, cStr3, params, results
);
}

Expand Down Expand Up @@ -2897,22 +2895,18 @@ export function getGlobalInit(global: GlobalRef): ExpressionRef {
return binaryen._BinaryenGlobalGetInitExpr(global);
}

// events
// tags

export function getEventName(event: EventRef): string | null {
return readString(binaryen._BinaryenEventGetName(event));
export function getTagName(tag: TagRef): string | null {
return readString(binaryen._BinaryenTagGetName(tag));
}

export function getEventAttribute(event: EventRef): u32 {
return binaryen._BinaryenEventGetAttribute(event);
export function getTagParams(tag: TagRef): TypeRef {
return binaryen._BinaryenTagGetParams(tag);
}

export function getEventParams(event: EventRef): TypeRef {
return binaryen._BinaryenEventGetParams(event);
}

export function getEventResults(event: EventRef): TypeRef {
return binaryen._BinaryenEventGetResults(event);
export function getTagResults(tag: TagRef): TypeRef {
return binaryen._BinaryenTagGetResults(tag);
}

export class Relooper {
Expand Down
6 changes: 3 additions & 3 deletions src/passes/pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ import {
_BinaryenAtomicNotifyGetNotifyCount,
_BinaryenAtomicNotifySetNotifyCount,
_BinaryenRefFuncGetFunc,
_BinaryenThrowGetEvent,
_BinaryenThrowGetTag,
_BinaryenTupleExtractGetTuple,
_BinaryenTupleExtractSetTuple,
_BinaryenRefEqGetLeft,
Expand Down Expand Up @@ -484,7 +484,7 @@ export abstract class Visitor {
// unimp
}

visitEvent(name: StringRef): void {
visitTag(name: StringRef): void {
// unimp
}

Expand Down Expand Up @@ -850,7 +850,7 @@ export abstract class Visitor {
}
case ExpressionId.Throw: {
this.stack.push(expr);
this.visitEvent(_BinaryenThrowGetEvent(expr));
this.visitTag(_BinaryenThrowGetTag(expr));
let numOperands = _BinaryenThrowGetNumOperands(expr);
for (let i: Index = 0; i < numOperands; ++i) {
this.visit(_BinaryenThrowGetOperandAt(expr, i));
Expand Down

0 comments on commit b95886d

Please sign in to comment.