mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-22 03:01:55 +00:00
Update binaryen
This commit is contained in:
@ -352,7 +352,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
} else {
|
||||
this.module.addGlobal(internalName, nativeType, element.isMutable, initializer);
|
||||
if (!element.isMutable) {
|
||||
// TODO: check export, requires updated binaryen.js with Module#addGlobalExport
|
||||
// TODO: check export
|
||||
}
|
||||
}
|
||||
return element.isCompiled = true;
|
||||
@ -416,7 +416,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (!instance)
|
||||
return;
|
||||
if (declaration.range.source.isEntry && declaration.parent == declaration.range.source && hasModifier(ModifierKind.EXPORT, declaration.modifiers))
|
||||
this.module.addExport(instance.internalName, declaration.identifier.name);
|
||||
this.module.addFunctionExport(instance.internalName, declaration.identifier.name);
|
||||
}
|
||||
|
||||
compileFunctionUsingTypeArguments(prototype: FunctionPrototype, typeArguments: TypeNode[], contextualTypeArguments: Map<string,Type> | null = null, alternativeReportNode: Node | null = null): Function | null {
|
||||
@ -473,7 +473,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
// create the function
|
||||
const internalName: string = instance.internalName;
|
||||
if (instance.isDeclare) {
|
||||
this.module.addImport(internalName, "env", declaration.identifier.name, typeRef);
|
||||
this.module.addFunctionImport(internalName, "env", declaration.identifier.name, typeRef);
|
||||
} else {
|
||||
this.module.addFunction(internalName, typeRef, typesToNativeTypes(instance.additionalLocals), this.module.createBlock(null, <ExpressionRef[]>stmts, NativeType.None));
|
||||
}
|
||||
@ -577,7 +577,7 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (!(<FunctionPrototype>element).isGeneric) {
|
||||
const functionInstance: Function | null = this.compileFunctionUsingTypeArguments(<FunctionPrototype>element, []);
|
||||
if (functionInstance && statement.range.source.isEntry)
|
||||
this.module.addExport(functionInstance.internalName, member.externalIdentifier.name);
|
||||
this.module.addFunctionExport(functionInstance.internalName, member.externalIdentifier.name);
|
||||
}
|
||||
break;
|
||||
|
||||
|
10
src/glue/binaryen.d.ts
vendored
10
src/glue/binaryen.d.ts
vendored
@ -274,12 +274,18 @@ declare function _BinaryenFunctionRunPasses(func: BinaryenFunctionRef, module: B
|
||||
|
||||
declare type BinaryenImportRef = usize;
|
||||
|
||||
declare function _BinaryenAddImport(module: BinaryenModuleRef, internalName: CString, externalModuleName: CString, externalBaseName: CString, type: BinaryenFunctionTypeRef): BinaryenImportRef;
|
||||
declare function _BinaryenAddFunctionImport(module: BinaryenModuleRef, internalName: CString, externalModuleName: CString, externalBaseName: CString, functionType: BinaryenFunctionTypeRef): BinaryenImportRef;
|
||||
declare function _BinaryenAddTableImport(module: BinaryenModuleRef, internalName: CString, externalModuleName: CString, externalBaseName: CString): BinaryenImportRef;
|
||||
declare function _BinaryenAddMemoryImport(module: BinaryenModuleRef, internalName: CString, externalModuleName: CString, externalBaseName: CString): BinaryenImportRef;
|
||||
declare function _BinaryenAddGlobalImport(module: BinaryenModuleRef, internalName: CString, externalModuleName: CString, externalBaseName: CString, globalType: BinaryenType): BinaryenImportRef;
|
||||
declare function _BinaryenRemoveImport(module: BinaryenModuleRef, internalName: CString): void;
|
||||
|
||||
declare type BinaryenExportRef = usize;
|
||||
|
||||
declare function _BinaryenAddExport(module: BinaryenModuleRef, internalName: CString, externalName: CString): BinaryenExportRef;
|
||||
declare function _BinaryenAddFunctionExport(module: BinaryenModuleRef, internalName: CString, externalName: CString): BinaryenExportRef;
|
||||
declare function _BinaryenAddTableExport(module: BinaryenModuleRef, internalName: CString, externalName: CString): BinaryenExportRef;
|
||||
declare function _BinaryenAddMemoryExport(module: BinaryenModuleRef, internalName: CString, externalName: CString): BinaryenExportRef;
|
||||
declare function _BinaryenAddGlobalExport(module: BinaryenModuleRef, internalName: CString, externalName: CString): BinaryenExportRef;
|
||||
declare function _BinaryenRemoveExport(module: BinaryenModuleRef, externalName: CString): void;
|
||||
|
||||
declare type BinaryenGlobalRef = usize;
|
||||
|
@ -522,12 +522,48 @@ export class Module {
|
||||
}
|
||||
}
|
||||
|
||||
addExport(internalName: string, externalName: string): ExportRef {
|
||||
addFunctionExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddExport(this.ref, cStr1, cStr2);
|
||||
return _BinaryenAddFunctionExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addTableExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddTableExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addMemoryExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddMemoryExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addGlobalExport(internalName: string, externalName: string): ExportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalName);
|
||||
try {
|
||||
return _BinaryenAddGlobalExport(this.ref, cStr1, cStr2);
|
||||
} finally {
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
@ -544,13 +580,55 @@ export class Module {
|
||||
}
|
||||
}
|
||||
|
||||
addImport(internalName: string, externalModuleName: string, externalBaseName: string, type: FunctionTypeRef): ImportRef {
|
||||
addFunctionImport(internalName: string, externalModuleName: string, externalBaseName: string, functionType: FunctionTypeRef): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalModuleName);
|
||||
const cStr3: CString = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddImport(this.ref, cStr1, cStr2, cStr3, type);
|
||||
return _BinaryenAddFunctionImport(this.ref, cStr1, cStr2, cStr3, functionType);
|
||||
} finally {
|
||||
_free(cStr3);
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addTableImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalModuleName);
|
||||
const cStr3: CString = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddTableImport(this.ref, cStr1, cStr2, cStr3);
|
||||
} finally {
|
||||
_free(cStr3);
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addMemoryImport(internalName: string, externalModuleName: string, externalBaseName: string): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalModuleName);
|
||||
const cStr3: CString = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddMemoryImport(this.ref, cStr1, cStr2, cStr3);
|
||||
} finally {
|
||||
_free(cStr3);
|
||||
_free(cStr2);
|
||||
_free(cStr1);
|
||||
}
|
||||
}
|
||||
|
||||
addGlobalImport(internalName: string, externalModuleName: string, externalBaseName: string, globalType: NativeType): ImportRef {
|
||||
if (this.noEmit) return 0;
|
||||
const cStr1: CString = allocString(internalName);
|
||||
const cStr2: CString = allocString(externalModuleName);
|
||||
const cStr3: CString = allocString(externalBaseName);
|
||||
try {
|
||||
return _BinaryenAddGlobalImport(this.ref, cStr1, cStr2, cStr3, globalType);
|
||||
} finally {
|
||||
_free(cStr3);
|
||||
_free(cStr2);
|
||||
@ -598,6 +676,16 @@ export class Module {
|
||||
}
|
||||
}
|
||||
|
||||
setFunctionTable(funcs: BinaryenFunctionRef[]): void {
|
||||
if (this.noEmit) return;
|
||||
const cArr: CArray<i32> = allocI32Array(funcs);
|
||||
try {
|
||||
_BinaryenSetFunctionTable(this.ref, cArr, funcs.length);
|
||||
} finally {
|
||||
_free(cArr);
|
||||
}
|
||||
}
|
||||
|
||||
setStart(func: FunctionRef): void {
|
||||
if (this.noEmit) return;
|
||||
_BinaryenSetStart(this.ref, func);
|
||||
|
Reference in New Issue
Block a user