Less prose; Update i64 example; More options for asc

This commit is contained in:
dcodeIO
2017-12-25 12:08:51 +01:00
parent 4baff99125
commit 5c4bf1af76
14 changed files with 322 additions and 82 deletions

View File

@ -134,6 +134,8 @@ export class Options {
noTreeShaking: bool = false;
/** If true, replaces assertions with nops. */
noAssert: bool = false;
/** If true, does not set up a memory. */
noMemory: bool = false;
}
/** Indicates the desired kind of a conversion. */
@ -227,22 +229,23 @@ export class Compiler extends DiagnosticEmitter {
}
// set up memory
const initial: U64 = this.memoryOffset.clone();
if (this.options.target == Target.WASM64)
this.module.addGlobal("HEAP_BASE", NativeType.I64, false, this.module.createI64(initial.lo, initial.hi));
else
this.module.addGlobal("HEAP_BASE", NativeType.I32, false, this.module.createI32(initial.lo));
if (!this.options.noMemory) {
const initial: U64 = this.memoryOffset.clone();
if (this.options.target == Target.WASM64)
this.module.addGlobal("HEAP_BASE", NativeType.I64, false, this.module.createI64(initial.lo, initial.hi));
else
this.module.addGlobal("HEAP_BASE", NativeType.I32, false, this.module.createI32(initial.lo));
// determine initial page size
const initialOverlaps: U64 = initial.clone();
initialOverlaps.and32(0xffff);
if (!initialOverlaps.isZero) {
initial.or32(0xffff);
initial.add32(1);
// determine initial page size
const initialOverlaps: U64 = initial.clone();
initialOverlaps.and32(0xffff);
if (!initialOverlaps.isZero) {
initial.or32(0xffff);
initial.add32(1);
}
initial.shru32(16); // now is initial size in 64k pages
this.module.setMemory(initial.toI32(), Module.MAX_MEMORY_WASM32 /* TODO: not WASM64 compatible yet */, this.memorySegments, this.options.target, "memory");
}
initial.shru32(16); // now is initial size in 64k pages
this.module.setMemory(initial.toI32(), Module.MAX_MEMORY_WASM32 /* TODO: not WASM64 compatible yet */, this.memorySegments, this.options.target, "memory");
return this.module;
}

View File

@ -113,6 +113,11 @@ export function setNoAssert(options: Options, noAssert: bool): void {
options.noAssert = noAssert;
}
/** Sets the `noMemory` option. */
export function setNoMemory(options: Options, noMemory: bool): void {
options.noMemory = noMemory;
}
/** Compiles the sources computed by the parser to a module. */
export function compile(parser: Parser, options: Options | null = null): Module {
const program: Program = parser.finish();

View File

@ -137,15 +137,11 @@ export class Type {
/** Converts this type to its respective native type. */
toNativeType(): NativeType {
return this.kind == TypeKind.F32
? NativeType.F32
: this.kind == TypeKind.F64
? NativeType.F64
: this.isLongInteger
? NativeType.I64
: this.isAnyInteger || this.kind == TypeKind.BOOL
? NativeType.I32
: NativeType.None;
return this.kind == TypeKind.F32 ? NativeType.F32
: this.kind == TypeKind.F64 ? NativeType.F64
: this.isLongInteger ? NativeType.I64
: this.isAnyInteger ? NativeType.I32
: NativeType.None;
}
/** Converts this type to its native `0` value. */