static void DumpIntermidiateFile(string filePath, List <ExpresionLine> expresionLines, Globals.DataStructures dataStructures) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".tmp")) { Chronicler.HoldOutput(); int curLinNum = 0; foreach (ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { curLinNum = expLine.lineNumber; file.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { file.Write(expLine.locationCounter.ToString("X6") + "\t"); } file.Write(expLine.OriginalLine); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { Chronicler.Write(expLine.locationCounter.ToString("X6") + "\t"); } Chronicler.WriteLine(expLine.OriginalLine); } } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { curLinNum++; file.Write(curLinNum.ToString() + "\t"); file.Write(lv.address.ToString("X6") + "\t"); file.Write("*" + "\t"); file.Write(lv.label); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); Chronicler.Write(lv.address.ToString("X6") + "\t"); Chronicler.Write("*" + "\t"); Chronicler.WriteLine(lv.label); } } Chronicler.HoldOutput(); dataStructures.symbolTable.Print(); Chronicler.HoldOutput(); dataStructures.literalTable.PrintTable(); }
//************************************************************************* //*** FUNCTION Main //*** ********************************************************************* //*** DESCRIPTION : This is the main program driver //*** INPUT ARGS : string[] args //*** OUTPUT ARGS : N/A //*** IN/OUT ARGS : N/A //*** RETURN : N/A //************************************************************************* static void Main(string[] args) { Chronicler.WriteLine("Loading symbols..."); Globals.DataStructures dataStructures = new Globals.DataStructures(); string filePath; if (args.Length == 0) { Chronicler.WriteLine("Please enter the search file name: "); filePath = Console.ReadLine(); } else { filePath = args[0]; } Chronicler.HoldOutput(); Chronicler.NewLine(); Chronicler.NewLine(); PassOne.Execute(dataStructures, out System.Collections.Generic.List <PassOne.ExpresionLine> expresionLines, "../../../" + filePath); //symbolTable.SearchSymbols("../../../" + filePath); Chronicler.HoldOutput(); PassTwo.Execute(dataStructures, expresionLines, "../../../" + filePath); }
static void DumpObjFile(string filePath, List <PassOne.ExpresionLine> expresionLines, Globals.DataStructures dataStructures) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".txt")) { Chronicler.HoldOutput(); int curLinNum = 0; foreach (PassOne.ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { curLinNum = expLine.lineNumber; file.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { file.Write(expLine.locationCounter.ToString("X6") + "\t"); } file.Write(expLine.OriginalLine + "\t"); file.Write(expLine.Opcode); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { Chronicler.Write(expLine.locationCounter.ToString("X6") + "\t"); } Chronicler.Write(expLine.OriginalLine + "\t"); Chronicler.WriteLine(expLine.Opcode); } } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { curLinNum++; file.Write(curLinNum.ToString() + "\t"); file.Write(lv.address.ToString("X6") + "\t"); file.Write("*" + "\t"); file.Write(lv.label); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); Chronicler.Write(lv.address.ToString("X6") + "\t"); Chronicler.Write("*" + "\t"); Chronicler.WriteLine(lv.label); } } Chronicler.HoldOutput(); dataStructures.symbolTable.Print(); Chronicler.HoldOutput(); dataStructures.literalTable.PrintTable(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".obj")) { Chronicler.HoldOutput(); string buffer = ""; string prevOpCode = "start"; int sl = 0; if (expresionLines.Count > 0) { sl = expresionLines[0].locationCounter; } Chronicler.WriteLine("Object code:"); foreach (PassOne.ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { if ((buffer.Length + expLine.Opcode.Length) > 60 || (prevOpCode == "" && buffer != "")) { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); sl = expLine.locationCounter; //clear buffer buffer = ""; } prevOpCode = expLine.Opcode; //check continuity buffer += expLine.Opcode; //add curr line to buffer } } if (buffer != "") { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { if (buffer != "" && (buffer.Length + lv.hexValue.Length) > 60) { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } buffer += lv.hexValue;//add curr line to buffer } if (buffer != "") { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } dataStructures.symbolTable.PrintFile(file); dataStructures.symbolTable.Print(); } }