private string EmitCloseStatement(CloseStatement closeStatement) { string r = ""; string className = "__CobolProgram"; //Console.WriteLine("Emitting Close Statement"); foreach (string fd in closeStatement.Files) { FileAndSortDescriptionEntry fsde = GetFSDE(fd); //Work out if it's read or write mode r += " " + ILAddress(1) + "ldarg.0\n"; r += " " + ILAddress(5); r += "ldfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(fd) + "\n"; r += " " + ILAddress(1) + "ldnull\n"; r += " " + ILAddress(5) + "bne.un "; //Read mode... string r2 = ""; r2 += " " + ILAddress(1) + "ldarg.0\n"; r2 += " " + ILAddress(5); r2 += "ldfld class [mscorlib]System.IO.StreamReader " + className + "::_reader_" + ILIdentifier(fd) + "\n"; r2 += " " + ILAddress(5); r2 += "callvirt instance void class [mscorlib]System.IO.StreamReader::Close()\n"; r2 += " " + ILAddress(1) + "ldarg.0\n"; r2 += " " + ILAddress(1) + "ldnull\n"; r2 += " " + ILAddress(5); r2 += "stfld class [mscorlib]System.IO.StreamReader " + className + "::_reader_" + ILIdentifier(fd) + "\n"; r2 += " " + ILAddress(5) + "br "; //Write mode... r += ILAddress() + "\n"; string r3 = ""; r3 += " " + ILAddress(1) + "ldarg.0\n"; r3 += " " + ILAddress(5); r3 += "ldfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(fd) + "\n"; r3 += " " + ILAddress(5); r3 += "callvirt instance void class [mscorlib]System.IO.StreamWriter::Close()\n"; r3 += " " + ILAddress(1) + "ldarg.0\n"; r3 += " " + ILAddress(1) + "ldnull\n"; r3 += " " + ILAddress(5); r3 += "stfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(fd) + "\n"; r2 += ILAddress() + "\n"; r += r2; r += r3; } return(r); }
private string EmitOpenStatement(OpenStatement openStatement) { string r = ""; string className = "__CobolProgram"; //Console.WriteLine("Emitting Open Statement"); //fsde.FileControlEntry; foreach (string fd in openStatement.Files) { FileAndSortDescriptionEntry fsde = GetFSDE(fd); //Console.WriteLine("FD = "+fd); //Pointer to this... r += " " + ILAddress(1) + "ldarg.0\n"; //TODO: Load filename r += EmitLoadSource(fsde.FileControlEntry.Assign.Source, false, false); if (openStatement.IsInput) { //Open for read... r += " " + ILAddress(5); r += "newobj instance void class [mscorlib]System.IO.StreamReader::.ctor(string)\n"; r += " " + ILAddress(5); r += "stfld class [mscorlib]System.IO.StreamReader " + className + "::_reader_" + ILIdentifier(fd) + "\n"; } else { //Open for write... r += " " + ILAddress(5); r += "newobj instance void class [mscorlib]System.IO.StreamWriter::.ctor(string)\n"; r += " " + ILAddress(5); r += "stfld class [mscorlib]System.IO.StreamWriter " + className + "::_writer_" + ILIdentifier(fd) + "\n"; } } return(r); }
private string EmitReadStatement(ReadStatement readStatement) { string r = "\n //Begin read statement...\n"; string className = "__CobolProgram"; FileAndSortDescriptionEntry fsde = GetFSDE(readStatement.Filename.Name); //fsde.DataDescriptions is a list of items that the data should be read into //Check for End of Stream... r += " " + ILAddress(1) + "ldarg.0\n"; r += " " + ILAddress(5); r += "ldfld class [mscorlib]System.IO.StreamReader " + className + "::_reader_" + ILIdentifier(readStatement.Filename.Name) + "\n"; r += " " + ILAddress(5); r += "callvirt instance bool class [mscorlib]System.IO.StreamReader::get_EndOfStream()\n"; r += " " + ILAddress(5); r += "brtrue "; //Jump to IsAtEndOfStream string r2 = ""; //Execute NotEndStatements... if (readStatement.NotEndStatements.Count > 0) { foreach (Sentence sentence in readStatement.NotEndStatements) { r2 += EmitSentence(sentence); } } //Read from file... r2 += " " + ILAddress(1) + "ldarg.0\n"; r2 += " " + ILAddress(5); r2 += "ldfld class [mscorlib]System.IO.StreamReader " + className + "::_reader_" + ILIdentifier(readStatement.Filename.Name) + "\n"; r2 += " " + ILAddress(5); r2 += "callvirt instance string class [mscorlib]System.IO.StreamReader::ReadLine()\n"; Identifier id = new Identifier(); id.Definition = fsde.DataDescriptions[0] as DataDescription; r2 += EmitStore(id, null); //EmitStore calls EmitStoreGroup which needs to loop through the elements of a record. //This should be changed to call ListElements like DISPLAY does. //Jump to EndRead r2 += " " + ILAddress(5); r2 += "br "; //If we're at the end of the stream, the first branch jumps to here r += ILAddress() + "\n"; //Execute NotEndStatements... string r3 = ""; if (readStatement.EndStatements.Count > 0) { foreach (Sentence sentence in readStatement.EndStatements) { r3 += EmitSentence(sentence); } } //End Read //The branch after reading data jumps to here r2 += ILAddress() + "\n"; r += r2; r += r3; r += " //End of read statement\n"; return(r); }