コード例 #1
0
 public void Setup()
 {
     sw = new StringWriter();
     formatter = new TextFormatter(sw);
     cf = new CodeFormatter(formatter);
     m = new ExpressionEmitter();
 }
コード例 #2
0
ファイル: ExternalProcedure.cs プロジェクト: killbug2004/reko
		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();
		}
コード例 #3
0
        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("}");
        }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
ファイル: CodeViewerPane.cs プロジェクト: killbug2004/reko
        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();
        }
コード例 #7
0
ファイル: CodeViewerPane.cs プロジェクト: killbug2004/reko
 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());
 }
コード例 #8
0
ファイル: Block.cs プロジェクト: killbug2004/reko
		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;
			}
		}
コード例 #9
0
 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();
 }
コード例 #10
0
 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();
 }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
 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);
 }
コード例 #13
0
 public ProcedureFormatter(Procedure procedure, BlockDecorator decorator, CodeFormatter formatter)
 {
     this.proc = procedure;
     this.decorator = decorator;
     this.formatter = formatter;
 }
コード例 #14
0
 public ProcedureFormatter(Procedure procedure, CodeFormatter formatter)
 {
     this.proc = procedure;
     this.decorator = new BlockDecorator();
     this.formatter = formatter;
 }
コード例 #15
0
 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());
 }