diff options
| author | Graydon Hoare <[email protected]> | 2010-06-24 10:34:47 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-06-24 10:34:47 -0700 |
| commit | 25eb1fd3c9d997e460dff3e03d87e398e616c726 (patch) | |
| tree | fb8919376fe8a1f180f69bf4704bb71668881aab /src/boot/util | |
| parent | Merge timer loop functions, fix win32 build broken by logger change. (diff) | |
| download | rust-25eb1fd3c9d997e460dff3e03d87e398e616c726.tar.xz rust-25eb1fd3c9d997e460dff3e03d87e398e616c726.zip | |
Add fmt module, move out some common format helpers, add instruction-selection tracing and make selection use queues rather than list refs.
Diffstat (limited to 'src/boot/util')
| -rw-r--r-- | src/boot/util/fmt.ml | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/boot/util/fmt.ml b/src/boot/util/fmt.ml new file mode 100644 index 00000000..650224ba --- /dev/null +++ b/src/boot/util/fmt.ml @@ -0,0 +1,83 @@ +(* + * Common formatting helpers. + *) + +let fmt = Format.fprintf +;; + +let fmt_str ff = fmt ff "%s" +;; + +let fmt_obox ff = Format.pp_open_box ff 4;; +let fmt_obox_3 ff = Format.pp_open_box ff 3;; +let fmt_cbox ff = Format.pp_close_box ff ();; +let fmt_obr ff = fmt ff "{";; +let fmt_cbr ff = fmt ff "@\n}";; +let fmt_cbb ff = (fmt_cbox ff; fmt_cbr ff);; + +let fmt_bracketed + (bra:string) + (ket:string) + (inner:Format.formatter -> 'a -> unit) + (ff:Format.formatter) + (a:'a) + : unit = + fmt_str ff bra; + inner ff a; + fmt_str ff ket +;; + +let fmt_arr_sep + (sep:string) + (inner:Format.formatter -> 'a -> unit) + (ff:Format.formatter) + (az:'a array) + : unit = + Array.iteri + begin + fun i a -> + if i <> 0 + then fmt_str ff sep; + inner ff a + end + az +;; + +let fmt_bracketed_arr_sep + (bra:string) + (ket:string) + (sep:string) + (inner:Format.formatter -> 'a -> unit) + (ff:Format.formatter) + (az:'a array) + : unit = + fmt_bracketed bra ket + (fmt_arr_sep sep inner) + ff az +;; + +let fmt_to_str (f:Format.formatter -> 'a -> unit) (v:'a) : string = + let buf = Buffer.create 16 in + let bf = Format.formatter_of_buffer buf in + begin + f bf v; + Format.pp_print_flush bf (); + Buffer.contents buf + end +;; + +let sprintf_fmt + (f:Format.formatter -> 'a -> unit) + : (unit -> 'a -> string) = + (fun _ -> fmt_to_str f) +;; + + +(* + * Local Variables: + * fill-column: 78; + * indent-tabs-mode: nil + * buffer-file-coding-system: utf-8-unix + * compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; + * End: + *) |