Skip to content

Commit decdb30

Browse files
vouillonhhugo
authored andcommitted
WAT output: fix import/export name quoting
1 parent f7f9f51 commit decdb30

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

compiler/lib-wasm/wat_output.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ let rec format_sexp f s =
147147
Format.pp_print_string f ";;";
148148
Format.pp_print_string f s
149149

150+
let escape_string s =
151+
let b = Buffer.create (String.length s + 2) in
152+
for i = 0 to String.length s - 1 do
153+
let c = s.[i] in
154+
if Char.(c >= ' ' && c <= '~' && c <> '"' && c <> '\\')
155+
then Buffer.add_char b c
156+
else Printf.bprintf b "\\%02x" (Char.code c)
157+
done;
158+
Buffer.contents b
159+
150160
let index tbl x = Atom ("$" ^ Code.Var.Hashtbl.find tbl x)
151161

152162
let heap_type st (ty : heap_type) =
@@ -215,7 +225,7 @@ let str_type st typ =
215225

216226
let block_type = func_type
217227

218-
let quoted_name name = Atom ("\"" ^ name ^ "\"")
228+
let quoted_name name = Atom ("\"" ^ escape_string name ^ "\"")
219229

220230
let export name =
221231
match name with
@@ -613,16 +623,6 @@ let import st f =
613623
]
614624
]
615625

616-
let escape_string s =
617-
let b = Buffer.create (String.length s + 2) in
618-
for i = 0 to String.length s - 1 do
619-
let c = s.[i] in
620-
if Char.(c >= ' ' && c <= '~' && c <> '"' && c <> '\\')
621-
then Buffer.add_char b c
622-
else Printf.bprintf b "\\%02x" (Char.code c)
623-
done;
624-
Buffer.contents b
625-
626626
let type_field st { name; typ; supertype; final } =
627627
if final && Option.is_none supertype
628628
then List [ Atom "type"; index st.type_names name; str_type st typ ]

0 commit comments

Comments
 (0)