@@ -321,6 +321,7 @@ let parse_annots (m : module_) : Custom.section list =
321321% token VEC_SHUFFLE
322322% token< Ast. laneidx -> Ast. instr'> VEC_EXTRACT VEC_REPLACE
323323% token FUNC START TYPE PARAM RESULT LOCAL GLOBAL
324+ % token PAGESIZE
324325% token TABLE ELEM MEMORY TAG DATA DECLARE OFFSET ITEM IMPORT EXPORT
325326% token MODULE BIN QUOTE DEFINITION INSTANCE
326327% token SCRIPT REGISTER INVOKE GET
@@ -465,8 +466,16 @@ subtype :
465466tabletype :
466467 | addrtype limits reftype { fun c -> TableT ($1, $2, $3 c) }
467468
469+ % inline pagetype :
470+ | LPAR PAGESIZE NAT RPAR
471+ { let n = (nat32 $ 3 $ loc($ 3 )) in
472+ if not (Lib.Int32. is_power_of_two_unsigned n) then
473+ error (at $ sloc) " invalid custom page size: must be power of two" ;
474+ PageT (Int32. to_int (Lib.Int32. log2_unsigned n)) }
475+ | /* empty */ { PageT 16 } /* Sugar */
476+
468477memorytype :
469- | addrtype limits { fun c -> MemoryT ($1, $2, PageT 16 ) }
478+ | addrtype limits pagetype { fun c -> MemoryT ($1, $2, $3 ) }
470479
471480limits :
472481 | NAT { {min = nat64 $ 1 $ loc($ 1 ); max = None } }
@@ -1126,12 +1135,14 @@ memory_fields :
11261135 | inline_export memory_fields /* Sugar */
11271136 { fun c x loc -> let mems, data, ims, exs = $ 2 c x loc in
11281137 mems, data, ims, $ 1 (MemoryX x) c :: exs }
1129- | addrtype LPAR DATA string_list RPAR /* Sugar */
1138+ | addrtype pagetype LPAR DATA string_list RPAR /* Sugar */
11301139 { fun c x loc ->
1131- let size = Int64. (div (add (of_int (String. length $ 4 )) 65535L ) 65536L ) in
1140+ let PageT ps = $ 2 in
1141+ let page_size = Int64. shift_left 1L ps in
1142+ let size = Int64. (div (add (of_int (String. length $ 5 )) (sub page_size 1L )) page_size) in
11321143 let offset = [at_const $ 1 (0L @@ loc) @@ loc] @@ loc in
1133- [Memory (MemoryT ($ 1 , {min = size; max = Some size}, PageT 16 )) @@ loc],
1134- [Data ($ 4 , Active (x, offset) @@ loc) @@ loc],
1144+ [Memory (MemoryT ($ 1 , {min = size; max = Some size}, $ 2 )) @@ loc],
1145+ [Data ($ 5 , Active (x, offset) @@ loc) @@ loc],
11351146 [] , [] }
11361147
11371148
0 commit comments