mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-21 02:31:41 +00:00
Use Binaryen's function signature naming scheme (#522)
This commit is contained in:
@ -27,7 +27,8 @@ import {
|
||||
import {
|
||||
Type,
|
||||
TypeKind,
|
||||
TypeFlags
|
||||
TypeFlags,
|
||||
Signature
|
||||
} from "./types";
|
||||
|
||||
import {
|
||||
@ -3236,17 +3237,16 @@ export function compileCall(
|
||||
}
|
||||
let numOperands = operands.length - 1;
|
||||
let operandExprs = new Array<ExpressionRef>(numOperands);
|
||||
let signatureParts = new Array<string>(numOperands + 1);
|
||||
let nativeReturnType = returnType.toNativeType();
|
||||
let parameterTypes = new Array<Type>(numOperands);
|
||||
let nativeParamTypes = new Array<NativeType>(numOperands);
|
||||
for (let i = 0; i < numOperands; ++i) {
|
||||
operandExprs[i] = compiler.compileExpressionRetainType(operands[1 + i], Type.i32, WrapMode.NONE);
|
||||
let operandType = compiler.currentType;
|
||||
signatureParts[i] = operandType.toSignatureString();
|
||||
parameterTypes[i] = operandType;
|
||||
nativeParamTypes[i] = operandType.toNativeType();
|
||||
}
|
||||
signatureParts[numOperands] = returnType.toSignatureString();
|
||||
let typeName = signatureParts.join("");
|
||||
let typeName = Signature.makeSignatureString(parameterTypes, returnType);
|
||||
let typeRef = module.getFunctionTypeBySignature(nativeReturnType, nativeParamTypes);
|
||||
if (!typeRef) typeRef = module.addFunctionType(typeName, nativeReturnType, nativeParamTypes);
|
||||
compiler.currentType = returnType;
|
||||
@ -5952,7 +5952,7 @@ export function compileIterateRoots(compiler: Compiler): void {
|
||||
? module.createI64(i64_low(value), i64_high(value))
|
||||
: module.createI32(i64_low(value))
|
||||
],
|
||||
"i_"
|
||||
"FUNCSIG$vi"
|
||||
)
|
||||
);
|
||||
} else {
|
||||
@ -5965,7 +5965,7 @@ export function compileIterateRoots(compiler: Compiler): void {
|
||||
compiler.options.nativeSizeType
|
||||
)
|
||||
],
|
||||
"i_"
|
||||
"FUNCSIG$vi"
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -6049,7 +6049,7 @@ export function ensureGCHook(
|
||||
[
|
||||
module.createGetLocal(0, nativeSizeType)
|
||||
],
|
||||
nativeSizeType == NativeType.I64 ? "I_" : "i_"
|
||||
"FUNCSIG$" + (nativeSizeType == NativeType.I64 ? "vj" : "vi")
|
||||
)
|
||||
);
|
||||
|
||||
|
25
src/types.ts
25
src/types.ts
@ -368,16 +368,25 @@ export class Type {
|
||||
/** Converts this type to its signature string. */
|
||||
toSignatureString(): string {
|
||||
switch (this.kind) {
|
||||
default: return "i";
|
||||
// same naming scheme as Binaryen
|
||||
case TypeKind.I8:
|
||||
case TypeKind.U8:
|
||||
case TypeKind.I16:
|
||||
case TypeKind.U16:
|
||||
case TypeKind.I32:
|
||||
case TypeKind.U32:
|
||||
case TypeKind.BOOL: return "i";
|
||||
case TypeKind.I64:
|
||||
case TypeKind.U64: return "I";
|
||||
case TypeKind.U64: return "j";
|
||||
case TypeKind.ISIZE:
|
||||
case TypeKind.USIZE: return this.size == 64 ? "I" : "i";
|
||||
case TypeKind.USIZE: return this.size == 64 ? "j" : "i";
|
||||
case TypeKind.F32: return "f";
|
||||
case TypeKind.F64: return "F";
|
||||
case TypeKind.V128: return "v";
|
||||
case TypeKind.VOID: return "_";
|
||||
case TypeKind.F64: return "d";
|
||||
case TypeKind.V128: return "V";
|
||||
case TypeKind.VOID: return "v";
|
||||
default: assert(false);
|
||||
}
|
||||
return "i";
|
||||
}
|
||||
|
||||
// Types
|
||||
@ -614,12 +623,12 @@ export class Signature {
|
||||
/** Converts a signature to a function type string. */
|
||||
static makeSignatureString(parameterTypes: Type[] | null, returnType: Type, thisType: Type | null = null): string {
|
||||
var sb = [];
|
||||
sb.push(returnType.toSignatureString());
|
||||
if (thisType) sb.push(thisType.toSignatureString());
|
||||
if (parameterTypes) {
|
||||
for (let i = 0, k = parameterTypes.length; i < k; ++i) sb.push(parameterTypes[i].toSignatureString());
|
||||
}
|
||||
sb.push(returnType.toSignatureString());
|
||||
return sb.join("");
|
||||
return "FUNCSIG$" + sb.join("");
|
||||
}
|
||||
|
||||
/** Converts this signature to a function type string. */
|
||||
|
Reference in New Issue
Block a user