aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Parse.ml
diff options
context:
space:
mode:
authorFrançois Pottier <francois.pottier@inria.fr>2015-10-16 17:56:06 +0200
committerFrançois Pottier <francois.pottier@inria.fr>2015-10-23 11:32:28 +0200
commit03f39523094fd41c8aad5ee7a8169ffc448cfd4a (patch)
treef59f6951f244261d8ef38a77860f6feff33a4880 /cparser/Parse.ml
parente036d68cb41de1ddac47d7686d25904281405ffe (diff)
downloadcompcert-kvx-03f39523094fd41c8aad5ee7a8169ffc448cfd4a.tar.gz
compcert-kvx-03f39523094fd41c8aad5ee7a8169ffc448cfd4a.zip
Read the whole source C file into memory instad of reading it on demand.
Having the file in memory will help build an error message. Also, this may be slightly faster.
Diffstat (limited to 'cparser/Parse.ml')
-rw-r--r--cparser/Parse.ml18
1 files changed, 15 insertions, 3 deletions
diff --git a/cparser/Parse.ml b/cparser/Parse.ml
index cfa95688..1d92d5a5 100644
--- a/cparser/Parse.ml
+++ b/cparser/Parse.ml
@@ -38,9 +38,22 @@ let parse_transformations s =
s;
!t
+let read_file sourcefile =
+ let ic = open_in sourcefile in
+ let n = in_channel_length ic in
+ let text = really_input_string ic n in
+ close_in ic;
+ text
+
let preprocessed_file transfs name sourcefile =
Cerrors.reset();
- let ic = open_in sourcefile in
+ (* Reading the whole file at once may seem costly, but seems to be
+ the simplest / most robust way of accessing the text underlying
+ a range of positions. This is used when printing an error message.
+ Plus, I note that reading the whole file into memory leads to a
+ speed increase: "make -C test" speeds up by 3 seconds out of 40
+ on my machine. *)
+ let text = read_file sourcefile in
let p =
try
let t = parse_transformations transfs in
@@ -52,7 +65,7 @@ let preprocessed_file transfs name sourcefile =
parsing of the entire file. This is non-negligeabe,
so we cannot use Timing.time2 *)
(fun () ->
- Parser.translation_unit_file inf (Lexer.tokens_stream name ic)) ()
+ Parser.translation_unit_file inf (Lexer.tokens_stream name text)) ()
with
| Parser.Parser.Inter.Fail_pr ->
(* Theoretically impossible : implies inconsistencies
@@ -65,5 +78,4 @@ let preprocessed_file transfs name sourcefile =
with
| Cerrors.Abort ->
[] in
- close_in ic;
if Cerrors.check_errors() then None else Some p