summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPrashanth Mundkur2018-06-19 15:18:54 -0700
committerPrashanth Mundkur2018-06-19 15:18:54 -0700
commite63f1441cb17407a4adc696324f71d6c3800a911 (patch)
treefbfe337b6bd9736825d4cabb324d36f98184ac8e /src
parenta03d5dfa7e220b2be9455480672c8b00a2e4fec2 (diff)
Minor optimization in ocaml_backend to use ints instead of strings for Big_int literals.
Improves tests/riscv duration by around 2% and size of riscv.o by 15%.
Diffstat (limited to 'src')
-rw-r--r--src/ocaml_backend.ml5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ocaml_backend.ml b/src/ocaml_backend.ml
index 1feb6513..6de40977 100644
--- a/src/ocaml_backend.ml
+++ b/src/ocaml_backend.ml
@@ -166,7 +166,10 @@ let ocaml_lit (L_aux (lit_aux, _)) =
| L_one -> string "B1"
| L_true -> string "true"
| L_false -> string "false"
- | L_num n -> parens (string "Big_int.of_string" ^^ space ^^ string ("\"" ^ Big_int.to_string n ^ "\""))
+ | L_num n -> if Big_int.equal n Big_int.zero
+ then string "Big_int.zero"
+ else parens (string "Big_int.of_int" ^^ space
+ ^^ string "(" ^^ string (Big_int.to_string n) ^^ string ")")
| L_undef -> failwith "undefined should have been re-written prior to ocaml backend"
| L_string str -> string_lit str
| L_real str -> parens (string "real_of_string" ^^ space ^^ dquotes (string (String.escaped str)))