Add memoryBase compiler option

This allows having fixed-size application-specific memory in front, followed by compiler-generated static memory and the heap.
This commit is contained in:
dcodeIO 2018-02-17 00:16:08 +01:00
parent 48cbbbbd68
commit 6b459259f9
7 changed files with 17 additions and 5 deletions

View File

@ -277,6 +277,7 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setNoTreeShaking(compilerOptions, !!args.noTreeShaking);
assemblyscript.setNoAssert(compilerOptions, !!args.noAssert);
assemblyscript.setNoMemory(compilerOptions, !!args.noMemory);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
var module;

View File

@ -89,6 +89,10 @@
"desc": "Does not set up a memory. Useful for low-level WebAssembly.",
"type": "boolean"
},
"memoryBase": {
"desc": "Sets the start offset of compiler-generated static memory.",
"type": "number"
},
"noLib": {
"desc": "Does not include the shipped standard library.",
"type": "boolean"

4
dist/asc.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -141,6 +141,8 @@ export class Options {
noAssert: bool = false;
/** If true, does not set up a memory. */
noMemory: bool = false;
/** Static memory start offset. */
memoryBase: u32 = 0;
/** Memory allocation implementation to use. */
allocateImpl: string = "allocate_memory";
/** Memory freeing implementation to use. */
@ -210,7 +212,7 @@ export class Compiler extends DiagnosticEmitter {
super(program.diagnostics);
this.program = program;
this.options = options ? options : new Options();
this.memoryOffset = i64_new(this.options.usizeType.byteSize, 0); // leave space for `null`
this.memoryOffset = i64_new(max(this.options.memoryBase, this.options.usizeType.byteSize), 0); // leave space for `null`
this.module = Module.create();
}

View File

@ -97,6 +97,11 @@ export function setSourceMap(options: Options, sourceMap: bool): void {
options.sourceMap = sourceMap;
}
/** Sets the `memoryBase` option. */
export function setMemoryBase(options: Options, memoryBase: u32): void {
options.memoryBase = memoryBase;
}
/** Compiles the sources computed by the parser to a module. */
export function compile(parser: Parser, options: Options | null = null): Module {
var program = parser.finish();