Ejemplo n.º 1
0
        public void TyfoMem()
        {
            StructureType m = new StructureType("foo", 0);

            m.Fields.Add(4, PrimitiveType.UInt16);
            m.Fields.Add(8, new Pointer(PrimitiveType.UInt32, 32));
            tyfo.Write(m, "bar");
            Assert.AreEqual(
                @"struct foo {
	uint16 w0004;	// 4
	uint32 * ptr0008;	// 8
} bar",
                sw.ToString());
        }
Ejemplo n.º 2
0
        public void Emit(string fnName, EmitFlags f, Formatter fmt, CodeFormatter w, TypeFormatter t)
        {
            bool emitStorage = (f & EmitFlags.ArgumentKind) == EmitFlags.ArgumentKind;

            if (emitStorage)
            {
                if (HasVoidReturn)
                {
                    fmt.Write("void ");
                }
                else
                {
                    w.WriteFormalArgumentType(ReturnValue, emitStorage);
                    fmt.Write(" ");
                }
                fmt.Write("{0}(", fnName);
            }
            else
            {
                if (HasVoidReturn)
                {
                    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)
            {
                IEnumerable <Identifier> parms = this.IsInstanceMetod
                    ? Parameters.Skip(1)
                    : Parameters;
                foreach (var p in parms)
                {
                    fmt.Write(sep);
                    sep = ", ";
                    w.WriteFormalArgument(p, 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();
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        public void WriteDecompiledTypes(Program program, TextWriter w)
        {
            WriteHeaderComment(Path.GetFileName(program.TypesFilename), program, w);
            w.WriteLine("/*"); program.TypeStore.Write(w); w.WriteLine("*/");
            TypeFormatter fmt = new TypeFormatter(new TextFormatter(w), false);

            foreach (EquivalenceClass eq in program.TypeStore.UsedEquivalenceClasses)
            {
                if (eq.DataType != null)
                {
                    w.Write("typedef ");
                    fmt.Write(eq.DataType, eq.Name);
                    w.WriteLine(";");
                    w.WriteLine();
                }
            }
        }
Ejemplo n.º 5
0
        public void WriteDecompiledTypes(Program program, string headerFilename, TextWriter w)
        {
            WriteHeaderComment(headerFilename, program, w);
            w.WriteLine("/*"); program.TypeStore.Write(w); w.WriteLine("*/");
            var tf = new TextFormatter(w)
            {
                Indentation = 0,
            };
            var fmt = new TypeFormatter(tf);

            foreach (EquivalenceClass eq in program.TypeStore.UsedEquivalenceClasses)
            {
                if (eq.DataType != null)
                {
                    tf.WriteKeyword("typedef");     //$REVIEW: C/C++-specific
                    tf.Write(" ");
                    fmt.Write(eq.DataType, eq.Name);
                    w.WriteLine(";");
                    w.WriteLine();
                }
            }
        }
Ejemplo n.º 6
0
 public void WriteFormalArgument(Identifier arg, bool writeStorage, TypeFormatter t)
 {
     if (writeStorage)
     {
         WriteFormalArgumentType(arg, writeStorage);
         writer.Write(" ");
         writer.Write(arg.Name);
     }
     else
     {
         t.Write(arg.DataType, arg.Name);
     }
 }
Ejemplo n.º 7
0
		public void VisitDeclaration(AbsynDeclaration decl)
		{
			writer.Indent();
			if (decl.Identifier.DataType != null)
			{
                TypeFormatter tf = new TypeFormatter(writer, true);
                tf.Write(decl.Identifier.DataType, decl.Identifier.Name);
			}
			else
			{
                writer.Write("?unknown?");
                writer.Write(" ");
                decl.Identifier.Accept(this);
            }
			if (decl.Expression != null)
			{
				writer.Write(" = ");
				decl.Expression.Accept(this);
			}
			writer.Terminate(";");
		}
Ejemplo n.º 8
0
		public void VisitDeclaration(Declaration decl)
		{
			writer.Indent();
            Debug.Assert(decl.Identifier.DataType != null, "The DataType property can't ever be null");

            TypeFormatter tf = new TypeFormatter(writer, true);
            tf.Write(decl.Identifier.DataType, decl.Identifier.Name);
			if (decl.Expression != null)
			{
				writer.Write(" = ");
				decl.Expression.Accept(this);
			}
			writer.Terminate();
		}
Ejemplo n.º 9
0
 public void WriteDecompiledTypes(Program program, TextWriter w)
 {
     WriteHeaderComment(Path.GetFileName(program.TypesFilename), program, w);
     w.WriteLine("/*"); program.TypeStore.Write(w); w.WriteLine("*/");
     var tf = new TextFormatter(w)
     {
         Indentation = 0,
     };
     TypeFormatter fmt = new TypeFormatter(tf, false);
     foreach (EquivalenceClass eq in program.TypeStore.UsedEquivalenceClasses)
     {
         if (eq.DataType != null)
         {
             w.Write("typedef ");
             fmt.Write(eq.DataType, eq.Name);
             w.WriteLine(";");
             w.WriteLine();
         }
     }
 }
Ejemplo n.º 10
0
 public void WriteFormalArgument(Identifier arg, bool writeStorage, TypeFormatter t)
 {
     if (writeStorage)
     {
         WriteFormalArgumentType(arg, writeStorage);
         writer.Write(" ");
         writer.Write(arg.Name);
     }
     else
     {
         if (arg.Storage is OutArgumentStorage)
         {
             t.Write(new ReferenceTo(arg.DataType), arg.Name);
         }
         else
         {
             t.Write(arg.DataType, arg.Name);
         }
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 12
0
 private void SetTextView(DataType dt)
 {
     var tsf = new TextSpanFormatter() { Indentation = 0 };
     var fmt = new TypeFormatter(tsf, false);
     tsf.UseTabs = false;
     fmt.Write(dt, "");
     this.TextView.Model = tsf.GetModel();
 }