diff options
-rw-r--r-- | lex/main.ml | 10 | ||||
-rw-r--r-- | lex/output.ml | 11 |
2 files changed, 12 insertions, 9 deletions
diff --git a/lex/main.ml b/lex/main.ml index 3f5a6252e..cd7d02e6c 100644 --- a/lex/main.ml +++ b/lex/main.ml @@ -28,10 +28,9 @@ let main () = Filename.chop_suffix source_name ".mll" ^ ".ml" else source_name ^ ".ml" in - let ic_bin = open_in_bin source_name in - let ic_txt = open_in source_name in + let ic = open_in_bin source_name in let oc = open_out dest_name in - let lexbuf = Lexing.from_channel ic_bin in + let lexbuf = Lexing.from_channel ic in let def = try Parser.lexer_definition Lexer.main lexbuf @@ -54,9 +53,8 @@ let main () = exit 2 in let (entries, transitions) = Lexgen.make_dfa def in let tables = Compact.compact_tables transitions in - Output.output_lexdef ic_txt oc def.header tables entries def.trailer; - close_in ic_bin; - close_in ic_txt; + Output.output_lexdef ic oc def.header tables entries def.trailer; + close_in ic; close_out oc let _ = Printexc.catch main (); exit 0 diff --git a/lex/output.ml b/lex/output.ml index 82e17af83..5ffb3b8c0 100644 --- a/lex/output.ml +++ b/lex/output.ml @@ -20,11 +20,16 @@ open Compact (* To copy the ML code fragments *) +let copy_buffer = String.create 1024 + let copy_chunk ic oc (Location(start,stop)) = seek_in ic start; - let buffer = String.create (stop - start) in - let r = input ic buffer 0 (stop - start) in - output oc buffer 0 r + let n = ref (stop - start) in + while !n > 0 do + let m = input ic copy_buffer 0 (min !n 1024) in + output oc copy_buffer 0 m; + n := !n - m + done (* To output an array of short ints, encoded as a string *) |