nx_wasm_layout_wat_lib.nx source
↩ module page · 30 lines · 1108 B
1// Compiler-attached layout evidence. WAT comments preserve executable semantics.
2import "nx_wasm_layout_lib.nx"
3
4func wl_wat_record(m: *Module,arena_pages: i64,shared: i64,o: *OutBuf) -> i64 {
5 if m==(0 as *Module) || o==(0 as *OutBuf) { return 0 }
6 if o.pos<0 || o.cap<o.pos || m.n_globals<0 { return 0 }
7 let prefix: *u8=";; nishi-layout-v1 " as *u8
8 var prefix_n: i64=0
9 while prefix[prefix_n]!=(0 as u8) { prefix_n=prefix_n+1 }
10 let available: i64=o.cap-o.pos-prefix_n-1
11 if available<WL_HEADER*2 { return 0 }
12 let capacity: i64=available/2
13 if m.n_globals>(capacity-WL_HEADER)/WL_ROW { return 0 }
14 let extent: i64=WL_HEADER+m.n_globals*WL_ROW
15 let record: *u8=sys_mmap(extent)
16 if (record as i64)<=0 { return 0 }
17 let n: i64=wl_record(m,arena_pages,shared,record,extent)
18 if n!=extent { return 0 }
19 let hex: *u8="0123456789abcdef" as *u8
20 out_str(o,prefix)
21 var k: i64=0
22 while k<n {
23 let b: i64=record[k] as i64
24 out_char(o,hex[b>>4] as i64)
25 out_char(o,hex[b&15] as i64)
26 k=k+1
27 }
28 out_char(o,10)
29 return n
30}