@@ -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