Skip to content

Commit c9cbfda

Browse files
authored
Merge pull request #105 from m-schmidt/master
Fix parsing and handling of CMinor files
2 parents 4c7650c + 2ef43e7 commit c9cbfda

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

backend/CMlexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ rule token = parse
136136
| "]" { RBRACKET }
137137
| "readonly" { READONLY }
138138
| "return" { RETURN }
139+
| "runtime" { RUNTIME }
139140
| ")" { RPAREN }
140141
| ";" { SEMICOLON }
141142
| "/" { SLASH }

backend/CMparser.mly

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ let mkef sg toks =
3838
EF_external(coqstring_of_camlstring s, sg)
3939
| [EFT_tok "builtin"; EFT_string s] ->
4040
EF_builtin(coqstring_of_camlstring s, sg)
41+
| [EFT_tok "runtime"; EFT_string s] ->
42+
EF_runtime(coqstring_of_camlstring s, sg)
4143
| [EFT_tok "volatile"; EFT_tok "load"; EFT_chunk c] ->
4244
EF_vload c
4345
| [EFT_tok "volatile"; EFT_tok "store"; EFT_chunk c] ->
@@ -348,6 +350,7 @@ let mkmatch expr cases =
348350
%token READONLY
349351
%token RETURN
350352
%token RPAREN
353+
%token RUNTIME
351354
%token SEMICOLON
352355
%token SINGLE
353356
%token SINGLEOFINT
@@ -719,6 +722,7 @@ eftok:
719722
| VOLATILE { EFT_tok "volatile" }
720723
| EXTERN { EFT_tok "extern" }
721724
| BUILTIN { EFT_tok "builtin" }
725+
| RUNTIME { EFT_tok "runtime" }
722726
| memory_chunk { EFT_chunk $1 }
723727
;
724728

driver/Driver.ml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,35 @@ let compile_cminor_file ifile ofile =
8686
Sections.initialize();
8787
let ic = open_in ifile in
8888
let lb = Lexing.from_channel ic in
89-
try
90-
match Compiler.transf_cminor_program
91-
(CMtypecheck.type_program
92-
(CMparser.prog CMlexer.token lb)) with
89+
(* Parse cminor *)
90+
let cm =
91+
try CMtypecheck.type_program (CMparser.prog CMlexer.token lb)
92+
with Parsing.Parse_error ->
93+
eprintf "File %s, character %d: Syntax error\n"
94+
ifile (Lexing.lexeme_start lb);
95+
exit 2
96+
| CMlexer.Error msg ->
97+
eprintf "File %s, character %d: %s\n"
98+
ifile (Lexing.lexeme_start lb) msg;
99+
exit 2
100+
| CMtypecheck.Error msg ->
101+
eprintf "File %s, type-checking error:\n%s"
102+
ifile msg;
103+
exit 2 in
104+
(* Convert to Asm *)
105+
let asm =
106+
match Compiler.apply_partial
107+
(Compiler.transf_cminor_program cm)
108+
Asmexpand.expand_program with
109+
| Errors.OK asm ->
110+
asm
93111
| Errors.Error msg ->
94112
eprintf "%s: %a" ifile print_error msg;
95-
exit 2
96-
| Errors.OK p ->
97-
let oc = open_out ofile in
98-
PrintAsm.print_program oc p;
99-
close_out oc
100-
with Parsing.Parse_error ->
101-
eprintf "File %s, character %d: Syntax error\n"
102-
ifile (Lexing.lexeme_start lb);
103-
exit 2
104-
| CMlexer.Error msg ->
105-
eprintf "File %s, character %d: %s\n"
106-
ifile (Lexing.lexeme_start lb) msg;
107-
exit 2
108-
| CMtypecheck.Error msg ->
109-
eprintf "File %s, type-checking error:\n%s"
110-
ifile msg;
111-
exit 2
113+
exit 2 in
114+
(* Print Asm in text form *)
115+
let oc = open_out ofile in
116+
PrintAsm.print_program oc asm;
117+
close_out oc
112118

113119
(* Processing of a .c file *)
114120

0 commit comments

Comments
 (0)