@@ -202,10 +202,16 @@ export class Options {
202
202
target : Target = Target . WASM32 ;
203
203
/** If true, replaces assertions with nops. */
204
204
noAssert : bool = false ;
205
+ /** It true, exports the memory to the embedder. */
206
+ exportMemory : bool = true ;
205
207
/** If true, imports the memory provided by the embedder. */
206
208
importMemory : bool = false ;
207
- /** If greater than zero, declare memory as shared by setting max memory to sharedMemory. */
208
- sharedMemory : i32 = 0 ;
209
+ /** Initial memory size, in pages. */
210
+ initialMemory : u32 = 0 ;
211
+ /** Maximum memory size, in pages. */
212
+ maximumMemory : u32 = 0 ;
213
+ /** If true, memory is declared as shared. */
214
+ sharedMemory : bool = false ;
209
215
/** If true, imports the function table provided by the embedder. */
210
216
importTable : bool = false ;
211
217
/** If true, exports the function table. */
@@ -215,9 +221,9 @@ export class Options {
215
221
/** If true, generates an explicit start function. */
216
222
explicitStart : bool = false ;
217
223
/** Static memory start offset. */
218
- memoryBase : i32 = 0 ;
224
+ memoryBase : u32 = 0 ;
219
225
/** Static table start offset. */
220
- tableBase : i32 = 0 ;
226
+ tableBase : u32 = 0 ;
221
227
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
222
228
globalAliases : Map < string , string > | null = null ;
223
229
/** Features to activate by default. These are the finished proposals. */
@@ -227,7 +233,7 @@ export class Options {
227
233
/** If true, enables pedantic diagnostics. */
228
234
pedantic : bool = false ;
229
235
/** Indicates a very low (<64k) memory limit. */
230
- lowMemoryLimit : i32 = 0 ;
236
+ lowMemoryLimit : u32 = 0 ;
231
237
232
238
/** Hinted optimize level. Not applied by the compiler itself. */
233
239
optimizeLevelHint : i32 = 0 ;
@@ -554,15 +560,57 @@ export class Compiler extends DiagnosticEmitter {
554
560
}
555
561
556
562
// set up memory
557
- var isSharedMemory = options . hasFeature ( Feature . THREADS ) && options . sharedMemory > 0 ;
563
+ var initialPages : u32 = 0 ;
564
+ if ( this . options . memoryBase /* is specified */ || this . memorySegments . length ) {
565
+ initialPages = u32 ( i64_low ( i64_shr_u ( i64_align ( memoryOffset , 0x10000 ) , i64_new ( 16 ) ) ) ) ;
566
+ }
567
+ if ( options . initialMemory ) {
568
+ if ( options . initialMemory < initialPages ) {
569
+ this . error (
570
+ DiagnosticCode . Module_requires_at_least_0_pages_of_initial_memory ,
571
+ null ,
572
+ initialPages . toString ( )
573
+ ) ;
574
+ } else {
575
+ initialPages = options . initialMemory ;
576
+ }
577
+ }
578
+ var maximumPages = Module . UNLIMITED_MEMORY ;
579
+ if ( options . maximumMemory ) {
580
+ if ( options . maximumMemory < initialPages ) {
581
+ this . error (
582
+ DiagnosticCode . Module_requires_at_least_0_pages_of_maximum_memory ,
583
+ null ,
584
+ initialPages . toString ( )
585
+ ) ;
586
+ } else {
587
+ maximumPages = options . maximumMemory ;
588
+ }
589
+ }
590
+ var isSharedMemory = false ;
591
+ if ( options . sharedMemory ) {
592
+ isSharedMemory = true ;
593
+ if ( ! options . maximumMemory ) {
594
+ this . error (
595
+ DiagnosticCode . Shared_memory_requires_maximum_memory_to_be_defined ,
596
+ null
597
+ ) ;
598
+ isSharedMemory = false ;
599
+ }
600
+ if ( ! options . hasFeature ( Feature . THREADS ) ) {
601
+ this . error (
602
+ DiagnosticCode . Shared_memory_requires_feature_threads_to_be_enabled ,
603
+ null
604
+ ) ;
605
+ isSharedMemory = false ;
606
+ }
607
+ }
558
608
module . setMemory (
559
- this . options . memoryBase /* is specified */ || this . memorySegments . length
560
- ? i64_low ( i64_shr_u ( i64_align ( memoryOffset , 0x10000 ) , i64_new ( 16 ) ) )
561
- : 0 ,
562
- isSharedMemory ? options . sharedMemory : Module . UNLIMITED_MEMORY ,
609
+ initialPages ,
610
+ maximumPages ,
563
611
this . memorySegments ,
564
612
options . target ,
565
- ExportNames . memory ,
613
+ options . exportMemory ? ExportNames . memory : null ,
566
614
isSharedMemory
567
615
) ;
568
616
0 commit comments