1 using System;
2 using System.IO;
3
4 namespace cmsx.intermediate
5 {
6 public void Compile(const string& intermediateCodeFileName)
7 {
8 try
9 {
10 Context context;
11 IntermediateCodeLexer lexer(ToUtf32(File.ReadAllText(intermediateCodeFileName)), intermediateCodeFileName, 0);
12 IntermediateCodeFileParser.Parse(lexer, &context);
13 context.compileUnit.MapInstructions();
14 context.compileUnit.Validate();
15 context.compileUnit.CombineBasicBlocks();
16
17 if (Flags.Get(Flag.stages))
18 {
19 context.compileUnit.Print(0);
20 }
21 MachineCode machineCode(context);
22 context.compileUnit.GenerateCode(machineCode);
23 if (Flags.Get(Flag.stages))
24 {
25 context.compileUnit.Print(printMachineCodeStage);
26 }
27 machineCode.Print(Path.ChangeExtension(context.compileUnit.fileName, ".s"));
28 }
29 catch (const Exception& ex)
30 {
31 throw Exception(ex.Message() + " in file '" + intermediateCodeFileName + "'");
32 }
33 }
34 }