private static void WriteXmlInstruction(XmlTextWriter xmltw, AbstractInstruction cinst) { switch (cinst.Name()) { case "call": case "execute": case "bcall": xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("name", cinst.ToString().Split(new char[] { ' ' })[1]); xmltw.WriteEndElement(); break; case "fcall": FCallInstruction fcinst = (FCallInstruction)cinst; xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("assembly", fcinst._assemblyName); xmltw.WriteAttributeString("class", fcinst._classType); xmltw.WriteAttributeString("method", fcinst._methodName); xmltw.WriteAttributeString("predicate", fcinst._predicateName); break; default: WriteXmlInstructionArguments(xmltw, cinst); break; } }
private static void WriteXmlInstructionArguments(XmlTextWriter xmltw, AbstractInstruction cinst) { switch (cinst.NumberOfArguments()) { case 0: xmltw.WriteStartElement(cinst.Name()); xmltw.WriteEndElement(); break; case 1: xmltw.WriteStartElement(cinst.Name()); xmltw.WriteAttributeString("arg1", cinst.ToString().Split(new char[] { ' ' })[1]); xmltw.WriteEndElement(); break; case 2: xmltw.WriteStartElement(cinst.Name()); if (cinst.Name() == "put_structure") { string args = cinst.ToString().Split(new char[] { ' ' })[1]; xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]); xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]); xmltw.WriteEndElement(); } else { if (cinst.ToString().IndexOf('"') != -1) { // put_constant "Hello, World", X0 string instStr = cinst.ToString(); string arg1 = instStr.Substring(instStr.IndexOf('"'), instStr.LastIndexOf('"') - instStr.IndexOf('"') + 1); string arg2 = instStr.Substring(instStr.LastIndexOf('"') + 2); xmltw.WriteAttributeString("arg1", arg1); xmltw.WriteAttributeString("arg2", arg2); xmltw.WriteEndElement(); } else if (cinst.ToString().IndexOf('\'') != -1) { // put_constant 'Hello, World', X0 string instStr = cinst.ToString(); string arg1 = instStr.Substring(instStr.IndexOf('\''), instStr.LastIndexOf('\'') - instStr.IndexOf('\'') + 1); string arg2 = instStr.Substring(instStr.LastIndexOf('\'') + 2); xmltw.WriteAttributeString("arg1", arg1); xmltw.WriteAttributeString("arg2", arg2); xmltw.WriteEndElement(); } else { string args = cinst.ToString().Split(new char[] { ' ' })[1]; xmltw.WriteAttributeString("arg1", args.Split(new char[] { ',' })[0]); xmltw.WriteAttributeString("arg2", args.Split(new char[] { ',' })[1]); xmltw.WriteEndElement(); } } break; } }
private string GetInstructionStatement(AbstractInstruction inst) { string statement = "program.Add(iset.CreateInstruction("; if (inst.Name() == "procedure") { ProcedureInstruction pi = (ProcedureInstruction)inst; statement += "\"procedure\", \"" + pi.ProcedureName + "\", \"" + pi.Arity + "\""; } else { if (inst._arguments == null || inst._arguments.Length == 0) { statement += "\"" + inst.Name() + "\""; } else { statement += "\"" + inst.Name() + "\", "; for (int i = 0; i < inst._arguments.Length; i++) { statement += "\"" + inst._arguments[i] + "\""; if (i != (inst._arguments.Length - 1)) { statement += ", "; } } } } statement += "));"; return statement; }