public void Setup() { sw = new StringWriter(); formatter = new TextFormatter(sw); cf = new CodeFormatter(formatter); m = new ExpressionEmitter(); }
public override string ToString() { StringWriter sw = new StringWriter(); TextFormatter fmt = new TextFormatter(sw); CodeFormatter cf = new CodeFormatter(fmt); TypeFormatter tf = new TypeFormatter(fmt, false); Signature.Emit(Name, ProcedureSignature.EmitFlags.ArgumentKind, fmt, cf, tf); return sw.ToString(); }
private void GenCode(Procedure proc, StringWriter sb) { sb.WriteLine("{0}()", proc.Name); sb.WriteLine("{"); CodeFormatter cf = new CodeFormatter(new TextFormatter(sb)); cf.WriteStatementList(proc.Body); sb.WriteLine("}"); }
private void RunTest(ProcedureBuilder mock, string outFilename) { Procedure proc = mock.Procedure; using (FileUnitTester fut = new FileUnitTester(outFilename)) { ControlFlowGraphCleaner cfgc = new ControlFlowGraphCleaner(proc); cfgc.Transform(); proc.Write(false, fut.TextWriter); fut.TextWriter.WriteLine(); StructureAnalysis sa = new StructureAnalysis(proc); sa.Structure(); CodeFormatter fmt = new CodeFormatter(new TextFormatter(fut.TextWriter)); fmt.Write(proc); fut.TextWriter.WriteLine("==========================="); fut.AssertFilesEqual(); } }
private void RunTest16(string sourceFilename, string outFilename, Address addrBase) { using (FileUnitTester fut = new FileUnitTester(outFilename)) { RewriteProgramMsdos(sourceFilename, addrBase); foreach (Procedure proc in program.Procedures.Values) { var cfgc = new ControlFlowGraphCleaner(program.Procedures.Values[0]); cfgc.Transform(); proc.Write(false, fut.TextWriter); fut.TextWriter.WriteLine(); var sa = new StructureAnalysis(proc); sa.Structure(); var fmt = new CodeFormatter(new TextFormatter(fut.TextWriter)); fmt.Write(proc); fut.TextWriter.WriteLine("==========================="); } fut.AssertFilesEqual(); } }
public void DisplayProcedure(Procedure proc) { if (codeView == null || proc == null) return; this.proc = proc; var tsf = new TextSpanFormatter(); var fmt = new CodeFormatter(tsf); fmt.InnerFormatter.UseTabs = false; fmt.Write(proc); this.TextView.Model = tsf.GetModel(); }
public void CopyAll() { if (this.proc == null) return; var sw = new StringWriter(); var writer = new TextFormatter(sw); var fmt = new CodeFormatter(writer); fmt.Write(proc); sw.Flush(); Clipboard.SetText(sw.ToString()); }
public void WriteStatements(TextWriter writer) { TextFormatter f = new TextFormatter(writer); f.UseTabs = true; f.TabSize = 4; CodeFormatter cf = new CodeFormatter(f); int i = 0; foreach (Statement s in Statements) { s.Instruction.Accept(cf); ++i; } }
public string ToString(string name) { StringWriter sw = new StringWriter(); TextFormatter f = new TextFormatter(sw); CodeFormatter cf = new CodeFormatter(f); TypeFormatter tf = new TypeFormatter(f, false); Emit(name, EmitFlags.ArgumentKind, f, cf, tf); return sw.ToString(); }
public override string ToString() { StringWriter w = new StringWriter(); TextFormatter f = new TextFormatter(w); CodeFormatter cf = new CodeFormatter(f); TypeFormatter tf = new TypeFormatter(f, false); Emit("()", EmitFlags.ArgumentKind | EmitFlags.LowLevelInfo, f, cf, tf); return w.ToString(); }
public void Emit(string fnName, EmitFlags f, Formatter fmt, CodeFormatter w, TypeFormatter t) { bool emitStorage = (f & EmitFlags.ArgumentKind) == EmitFlags.ArgumentKind; if (emitStorage) { if (ReturnValue != null) { w.WriteFormalArgumentType(ReturnValue, emitStorage); fmt.Write(" "); } else { fmt.Write("void "); } fmt.Write("{0}(", fnName); } else { if (ReturnValue == null) fmt.Write("void {0}", fnName); else { t.Write(ReturnValue.DataType, fnName); //$TODO: won't work with fn's that return pointers to functions or arrays. } fmt.Write("("); } var sep = ""; if (Parameters != null) { for (int i = 0; i < Parameters.Length; ++i) { fmt.Write(sep); sep = ", "; w.WriteFormalArgument(Parameters[i], emitStorage, t); } } fmt.Write(")"); if ((f & EmitFlags.LowLevelInfo) == EmitFlags.LowLevelInfo) { fmt.WriteLine(); fmt.Write("// stackDelta: {0}; fpuStackDelta: {1}; fpuMaxParam: {2}", StackDelta, FpuStackDelta, FpuStackArgumentMax); fmt.WriteLine(); } }
private void WriteBlock(Block block, CodeFormatter writer) { if (!string.IsNullOrEmpty(block.Name)) { writer.InnerFormatter.Write(block.Name); writer.InnerFormatter.Write(":"); writer.InnerFormatter.WriteLine(); } foreach (var stm in block.Statements) stm.Instruction.Accept(writer); }
public ProcedureFormatter(Procedure procedure, BlockDecorator decorator, CodeFormatter formatter) { this.proc = procedure; this.decorator = decorator; this.formatter = formatter; }
public ProcedureFormatter(Procedure procedure, CodeFormatter formatter) { this.proc = procedure; this.decorator = new BlockDecorator(); this.formatter = formatter; }
private void RunTest32(string expected, Program program) { var sw = new StringWriter(); foreach (var proc in program.Procedures.Values) { var cfgc = new ControlFlowGraphCleaner(proc); cfgc.Transform(); var sa = new StructureAnalysis(proc); sa.Structure(); var fmt = new CodeFormatter(new TextFormatter(sw)); fmt.Write(proc); sw.WriteLine("==="); } Console.WriteLine(sw); Assert.AreEqual(expected, sw.ToString()); }