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

@ -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();