Ejemplo n.º 1
0
        public void Emit(string fnName, EmitFlags f, Formatter fmt, CodeFormatter w, TypeReferenceFormatter t)
        {
            bool emitStorage = (f & EmitFlags.ArgumentKind) == EmitFlags.ArgumentKind;

            if (ParametersValid)
            {
                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.WriteDeclaration(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(")");
            }
            else
            {
                fmt.WriteKeyword("define");
                fmt.Write(" ");
                fmt.Write(fnName);
            }

            if ((f & EmitFlags.LowLevelInfo) == EmitFlags.LowLevelInfo)
            {
                fmt.WriteLine();
                fmt.Write("// stackDelta: {0}; fpuStackDelta: {1}; fpuMaxParam: {2}", StackDelta, FpuStackDelta, FpuStackArgumentMax);
                fmt.WriteLine();
            }
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            var sw  = new StringWriter();
            var fmt = new TextFormatter(sw);
            var cf  = new CodeFormatter(fmt);
            var tf  = new TypeReferenceFormatter(fmt);

            Signature.Emit(Name, FunctionType.EmitFlags.ArgumentKind, fmt, cf, tf);
            return(sw.ToString());
        }
Ejemplo n.º 3
0
        public string ToString(string name, EmitFlags flags = EmitFlags.ArgumentKind)
        {
            var sw = new StringWriter();
            var f  = new TextFormatter(sw);
            var cf = new CodeFormatter(f);
            var tf = new TypeReferenceFormatter(f);

            Emit(name, flags, f, cf, tf);
            return(sw.ToString());
        }
Ejemplo n.º 4
0
        public void Tyreffmt_ptr_TypeReference()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    new TypeReference("LONG", PrimitiveType.Int32), 32),
                "l0");
            Assert.AreEqual("LONG * l0", sw.ToString());
        }
Ejemplo n.º 5
0
        public void Tyreffmt_ptr_function()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    FunctionType.Action(new [] { Arg("arg0", 0) }),
                    32),
                "pfn");
            Assert.AreEqual("void (* pfn)(word32 arg0)", sw.ToString());
        }
Ejemplo n.º 6
0
        public void TypeReference()
        {
            tyreffo = new TypeReferenceFormatter(new TextFormatter(sw));
            EquivalenceClass b = new EquivalenceClass(new TypeVariable(1));

            b.DataType = new StructureType("b", 0)
            {
                Fields = { { 4, PrimitiveType.Word32 } }
            };

            tyfo.Write(new Pointer(b, 16), "pb");
            Assert.AreEqual("b * pb", sw.ToString());
        }
        public void Tyreffmt_ptr_function_with_eq_class()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    new EquivalenceClass(
                        new TypeVariable(3),
                        FunctionType.Action(new[] { Arg("arg0", 0) })),
                    4),
                "pfn");
            Assert.AreEqual("void (* pfn)(word32 arg0)", sw.ToString());
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
            sw = new StringWriter();
            var tf = new TextFormatter(sw)
            {
                Indentation = 0
            };

            tyfo = new TypeFormatter(tf);
            tf   = new TextFormatter(sw)
            {
                Indentation = 0
            };
            tyreffo = new TypeReferenceFormatter(tf);
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            sw = new StringWriter();
            var tf = new TextFormatter(sw)
            {
                Indentation = 0
            };

            tyfo = new TypeFormatter(tf);
            tf   = new TextFormatter(sw)
            {
                Indentation = 0
            };
            tyreffo = new TypeReferenceFormatter(tf);
            arch    = new Mock <IProcessorArchitecture>();
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            sw = new StringWriter();
            var tf = new TextFormatter(sw)
            {
                Indentation = 0
            };

            tyfo = new TypeFormatter(tf);
            tf   = new TextFormatter(sw)
            {
                Indentation = 0
            };
            tyreffo = new TypeReferenceFormatter(tf);
            arch    = MockRepository.GenerateStub <IProcessorArchitecture>();
            arch.Replay();
        }
Ejemplo n.º 11
0
        public void Write(TextWriter writer)
        {
            TextFormatter f = new TextFormatter(writer);

            foreach (var de in Signatures.OrderBy(d => d.Key, StringComparer.InvariantCulture))
            {
                string name = de.Key;
                de.Value.Emit(de.Key, FunctionType.EmitFlags.ArgumentKind, f);
                writer.WriteLine();
            }

            var tf = new TypeReferenceFormatter(f);

            foreach (var de in Globals.OrderBy(d => d.Key, StringComparer.InvariantCulture))
            {
                tf.WriteDeclaration(de.Value, de.Key);
            }
        }
Ejemplo n.º 12
0
        private string DecorateGenericName()
        {
            var sw = new StringWriter();

            sw.Write(Name);
            if (this.IsGeneric)
            {
                var fm  = new TextFormatter(sw);
                var tw  = new TypeReferenceFormatter(fm);
                var sep = '<';
                foreach (var arg in this.genericArguments)
                {
                    sw.Write(sep);
                    sep = ',';
                    tw.WriteTypeReference(arg);
                }
                sw.Write('>');
            }
            return(sw.ToString());
        }
Ejemplo n.º 13
0
 public void SetUp()
 {
     sw      = new StringWriter();
     tyfo    = new TypeFormatter(new TextFormatter(sw), false);
     tyreffo = new TypeReferenceFormatter(new TextFormatter(sw), false);
 }