This commit is contained in:
dcode
2019-05-20 23:10:06 +02:00
parent f73d807d5a
commit 3e480d9423
108 changed files with 123377 additions and 48800 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -146,32 +146,32 @@ export enum LocalFlags {
READFROM = 1 << 2,
/** Local is written to. */
WRITTENTO = 1 << 3,
/** Local must be autoreleased. */
AUTORELEASE = 1 << 4,
/** Local is retained. */
RETAINED = 1 << 4,
/** Local is conditionally read from. */
CONDITIONALLY_READFROM = 1 << 5,
/** Local is conditionally written to. */
CONDITIONALLY_WRITTENTO = 1 << 6,
/** Local must be conditionally autoreleased. */
CONDITIONALLY_AUTORELEASE = 1 << 7,
/** Local must be conditionally retained. */
CONDITIONALLY_RETAINED = 1 << 7,
/** Any categorical flag. */
ANY_CATEGORICAL = WRAPPED
| NONNULL
| READFROM
| WRITTENTO
| AUTORELEASE,
| RETAINED,
/** Any conditional flag. */
ANY_CONDITIONAL = AUTORELEASE
ANY_CONDITIONAL = RETAINED
| CONDITIONALLY_READFROM
| CONDITIONALLY_WRITTENTO
| CONDITIONALLY_AUTORELEASE,
| CONDITIONALLY_RETAINED,
/** Any autorelease flag. */
ANY_AUTORELEASE = AUTORELEASE
| CONDITIONALLY_AUTORELEASE
/** Any retained flag. */
ANY_RETAINED = RETAINED
| CONDITIONALLY_RETAINED
}
export namespace LocalFlags {
export function join(left: LocalFlags, right: LocalFlags): LocalFlags {
@ -324,7 +324,7 @@ export class Flow {
var scopedLocals = this.scopedLocals;
if (!scopedLocals) this.scopedLocals = scopedLocals = new Map();
scopedLocals.set("~auto" + (this.parentFunction.nextAutoreleaseId++), local);
this.setLocalFlag(local.index, LocalFlags.AUTORELEASE);
this.setLocalFlag(local.index, LocalFlags.RETAINED);
return local;
}
@ -585,7 +585,7 @@ export class Flow {
var localFlags = other.localFlags;
for (let i = 0, k = localFlags.length; i < k; ++i) {
let flags = localFlags[i];
if (flags & LocalFlags.AUTORELEASE) this.setLocalFlag(i, LocalFlags.CONDITIONALLY_AUTORELEASE);
if (flags & LocalFlags.RETAINED) this.setLocalFlag(i, LocalFlags.CONDITIONALLY_RETAINED);
if (flags & LocalFlags.READFROM) this.setLocalFlag(i, LocalFlags.CONDITIONALLY_READFROM);
if (flags & LocalFlags.WRITTENTO) this.setLocalFlag(i, LocalFlags.CONDITIONALLY_WRITTENTO);
}

View File

@ -22,6 +22,16 @@ declare function _BinaryenTypeVec128(): BinaryenType;
declare function _BinaryenTypeUnreachable(): BinaryenType;
declare function _BinaryenTypeAuto(): BinaryenType;
declare type BinaryenFeatureFlags = u32;
declare function _BinaryenFeatureAtomics(): BinaryenFeatureFlags;
declare function _BinaryenFeatureMutableGlobals(): BinaryenFeatureFlags;
declare function _BinaryenFeatureNontrappingFPToInt(): BinaryenFeatureFlags;
declare function _BinaryenFeatureSIMD128(): BinaryenFeatureFlags;
declare function _BinaryenFeatureBulkMemory(): BinaryenFeatureFlags;
declare function _BinaryenFeatureSignExt(): BinaryenFeatureFlags;
declare function _BinaryenFeatureExceptionHandling(): BinaryenFeatureFlags;
declare type BinaryenExpressionId = i32;
declare function _BinaryenInvalidId(): BinaryenExpressionId;
@ -612,6 +622,8 @@ declare function _BinaryenModuleRead(input: usize, inputSize: usize): BinaryenMo
declare function _BinaryenModuleInterpret(module: BinaryenModuleRef): void;
declare function _BinaryenModuleAddDebugInfoFileName(module: BinaryenModuleRef, filename: usize): BinaryenIndex;
declare function _BinaryenModuleGetDebugInfoFileName(module: BinaryenModuleRef, index: BinaryenIndex): usize;
declare function _BinaryenGetFeatures(module: BinaryenModuleRef): BinaryenFeatureFlags;
declare function _BinaryenSetFeatures(module: BinaryenModuleRef, featureFlags: BinaryenFeatureFlags): void;
declare type BinaryenRelooperRef = usize;
declare type BinaryenRelooperBlockRef = usize;

View File

@ -27,6 +27,16 @@ export enum NativeType {
Auto = _BinaryenTypeAuto()
}
export enum FeatureFlags {
Atomics = _BinaryenFeatureAtomics(),
MutableGloabls = _BinaryenFeatureMutableGlobals(),
NontrappingFPToInt = _BinaryenFeatureNontrappingFPToInt(),
SIMD128 = _BinaryenFeatureSIMD128(),
BulkMemory = _BinaryenFeatureBulkMemory(),
SignExt = _BinaryenFeatureSignExt(),
ExceptionHandling = _BinaryenFeatureExceptionHandling()
}
export enum ExpressionId {
Invalid = _BinaryenInvalidId(),
Block = _BinaryenBlockId(),
@ -553,6 +563,7 @@ export class Module {
offset: Index = 0,
align: Index = bytes // naturally aligned by default
): ExpressionRef {
if (type < NativeType.None || type > NativeType.V128) throw new Error("here: " + type);
return _BinaryenStore(this.ref, bytes, offset, align, ptr, value, type);
}
@ -1044,6 +1055,14 @@ export class Module {
_BinaryenSetDebugInfo(on);
}
getFeatures(): BinaryenFeatureFlags {
return _BinaryenGetFeatures(this.ref);
}
setFeatures(featureFlags: BinaryenFeatureFlags): void {
_BinaryenSetFeatures(this.ref, featureFlags);
}
optimize(func: FunctionRef = 0): void {
if (func) {
_BinaryenFunctionOptimize(func, this.ref);

View File

@ -309,13 +309,6 @@ function operatorKindFromDecorator(decoratorKind: DecoratorKind, arg: string): O
return OperatorKind.INVALID;
}
/** Garbage collector kind present. */
export enum CollectorKind {
NONE,
TRACING,
COUNTING
}
/** Represents an AssemblyScript program. */
export class Program extends DiagnosticEmitter {
@ -794,13 +787,18 @@ export class Program extends DiagnosticEmitter {
if (globalAliases) {
for (let [alias, name] of globalAliases) {
if (!name.length) continue; // explicitly disabled
let elementsByName = this.elementsByName;
let element = elementsByName.get(name);
if (element) {
if (elementsByName.has(alias)) throw new Error("duplicate global element: " + name);
elementsByName.set(alias, element);
let firstChar = name.charCodeAt(0);
if (firstChar >= CharCode._0 && firstChar <= CharCode._9) {
this.registerConstantInteger(alias, Type.i32, i64_new(parseI32(name, 10)));
} else {
let elementsByName = this.elementsByName;
let element = elementsByName.get(name);
if (element) {
if (elementsByName.has(alias)) throw new Error("duplicate global element: " + name);
elementsByName.set(alias, element);
}
else throw new Error("no such global element: " + name);
}
else throw new Error("no such global element: " + name);
}
}
}

View File

@ -7,8 +7,7 @@ import {
Class,
FunctionTarget,
Program,
DecoratorFlags,
CollectorKind
DecoratorFlags
} from "./program";
import {