public static void ReadObjectFile(FileInfo file, Linker linker) { FileInfo objectFile = new FileInfo(file.FullName + ".obj"); try { BinaryReader dataInputStream = new BinaryReader(File.OpenRead(objectFile.FullName)); int linkerSetSize = dataInputStream.ReadInt32(); for (int count = 0; count < linkerSetSize; ++count) { StaticSymbolWindows staticSymbol = new StaticSymbolWindows(); staticSymbol.Read(dataInputStream); linker.Add(staticSymbol); } dataInputStream.Close(); } catch (Exception exception) { Console.Out.WriteLine(exception.StackTrace); Assert.Error(exception.Message); } }
public static void Main(string[] args) { Windows = !Linux; if (Start.Windows) { ObjectCodeTable.Initializer(); } System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (args.Length == 0) { Assert.Error("usage: compiler <filename>"); } List <string> argList = new List <string>(args); bool rebuild = argList.Remove("-rebuild"), print = argList.Remove("-print"); try { if (Start.Linux) { foreach (string arg in argList) { FileInfo file = new FileInfo(SourcePath + arg); if (rebuild || !IsGeneratedFileUpToDate(file, ".asm")) { if (print) { Console.Out.WriteLine("Compiling \"" + file.FullName + ".c\"."); } CompileSourceFile(file); } } GenerateMakeFile(argList); } if (Start.Windows) { bool doLink = false; foreach (string arg in argList) { FileInfo file = new FileInfo(SourcePath + arg); if (rebuild || !IsGeneratedFileUpToDate(file, ".obj")) { if (print) { Console.Out.WriteLine("Compiling \"" + file.FullName + ".c\"."); } CompileSourceFile(file); doLink = true; } } if (doLink) { FileInfo targetFile = new FileInfo(TargetPath + argList[0] + ".com"); Linker linker = new Linker(); CCompiler_Main.Scanner.Path = null; foreach (string arg in argList) { FileInfo file = new FileInfo(SourcePath + arg); if (print) { Console.Out.WriteLine("Loading \"" + file.FullName + ".obj\"."); } ReadObjectFile(file, linker); } linker.Generate(targetFile); } else if (print) { Console.Out.WriteLine(SourcePath + argList[0] + ".com is up-to-date."); } } } catch (Exception exception) { Console.Out.WriteLine(exception.StackTrace); Assert.Error(exception.Message, Message.Parse_error); } }