Example #1
0
 internal override void PrintContents(
     TextWriter tw, int indent, XObjectGen xog)
 {
     tw.WriteLine("{");
     for (int i = 0; i < size; i++)
     {
         if (i != 0)
         {
             tw.WriteLine(",");
         }
         Compiler.Indent(tw, indent + 1);
         XObject xo = xog.embeds[off + i];
         if (xo is XObjectGen)
         {
             CCValues.PrintObjectGen(tw, indent + 1,
                                     (XObjectGen)xo);
         }
         else if (xo is XArrayGeneric)
         {
             CCValues.PrintArray(tw, indent + 1,
                                 (XArrayGeneric)xo);
         }
         else
         {
             throw new Exception(string.Format("unsupported embedded type: {0}", xo.GetType()));
         }
     }
     tw.WriteLine();
     Compiler.Indent(tw, indent);
     tw.Write("}");
 }
Example #2
0
    internal void AddLocalInstanceArray(int off, int len, XType ltype)
    {
        CCValues.AddTypeLayout(ltype);
        LocalInstance li;

        if (!instances.TryGetValue(off, out li))
        {
            instances[off] = new LocalInstance(len, ltype);
            return;
        }
        if (len != li.len)
        {
            throw new Exception("length mismatch for local instance array");
        }
    }
Example #3
0
 internal override void PrintContents(
     TextWriter tw, int indent, XObjectGen xog)
 {
     tw.WriteLine("{");
     for (int i = 0; i < size; i++)
     {
         if (i != 0)
         {
             tw.WriteLine(",");
         }
         Compiler.Indent(tw, indent + 1);
         CCValues.PrintRef(tw, xog.fields[off + i]);
     }
     tw.WriteLine();
     Compiler.Indent(tw, indent);
     tw.Write("}");
 }
Example #4
0
        internal override void PrintContents(
            TextWriter tw, int indent, XObjectGen xog)
        {
            XObject xo = xog.embeds[Offset];

            if (xo is XObjectGen)
            {
                CCValues.PrintObjectGen(tw, indent,
                                        (XObjectGen)xo);
            }
            else if (xo is XArrayGeneric)
            {
                CCValues.PrintArray(tw, indent,
                                    (XArrayGeneric)xo);
            }
            else
            {
                throw new Exception(string.Format("unsupported embedded type: {0}", xo.GetType()));
            }
        }
Example #5
0
        internal override void PrintValue(TextWriter tw)
        {
            string eCType = GetEltCType();
            int    n      = ranges.Count;

            for (int i = 0; i < n; i++)
            {
                IndexRange ir = ranges[i];
                tw.WriteLine();
                tw.Write(
                    "static const {0}t1b_{1}_{2}[] = {{",
                    eCType, buf.Serial, i);
                for (int j = ir.Start; j < ir.End; j++)
                {
                    if (j == ir.Start)
                    {
                        tw.WriteLine();
                    }
                    else
                    {
                        tw.WriteLine(",");
                    }
                    Compiler.Indent(tw, 1);
                    XValue xv = buf.Get(j);
                    if (embed)
                    {
                        XObject xo = xv.XObject;
                        PrintValueElementEmbed(tw, xo);
                    }
                    else
                    {
                        CCValues.PrintRef(tw, xv);
                    }
                }
                tw.WriteLine();
                tw.WriteLine("};");
            }
        }
Example #6
0
    internal void DoConst(XValue v)
    {
        /*
         * A constant value will point to a statically allocated
         * instance, hence constant. However, for basic types,
         * the instances are virtual, and we do not want to tag
         * them with the "constant" flag to avoid duplicating
         * the types in the analysis.
         */
        XType  xt = v.VType;
        CCType ct;

        if (xt.IsBasic)
        {
            ct = new CCType(xt);
        }
        else
        {
            ct = new CCType(xt, null, 0, true);
        }
        CCValues.AddValue(v);
        PropagateNext(Stack.Push(new CCTypeSet(ct)));
    }
Example #7
0
    /*
     * Perform compilation.
     */
    internal static void DoCompile()
    {
        string[] eps;
        if (entryPoints.Count == 0)
        {
            eps = new string[] { "def::main" };
        }
        else
        {
            eps = entryPoints.ToArray();
        }

        if (Verbose)
        {
            Console.WriteLine("+++++ Type Analysis +++++");
        }
        List <CCNode> roots = new List <CCNode>();

        foreach (string name in eps)
        {
            if (Verbose)
            {
                Console.WriteLine("--- Entry point: {0}", name);
            }
            Function f = Function.LookupNoArgs(name);
            if (f == null)
            {
                throw new Exception(string.Format("no such entry point: {0}", name));
            }
            roots.Add(CCNode.BuildTree(f));
        }
        if (PrintTrees != null)
        {
            PrintTrees.WriteLine("Call trees:");
            foreach (CCNode node in roots)
            {
                Indent(PrintTrees, 1);
                PrintTrees.WriteLine("*****");
                node.Print(PrintTrees, 2);
            }
        }

        if (Verbose)
        {
            Console.WriteLine("+++++ Code Generation +++++");
        }
        foreach (CCNode root in roots)
        {
            var ne = root as CCNodeEntry;
            if (ne != null)
            {
                GFunctionInterpreted.Add(ne.cfi);
            }
        }
        if (PrintTrees != null)
        {
            PrintTrees.WriteLine("Generated functions:");
            GFunctionInterpreted.PrintAll(PrintTrees);
        }

        using (TextWriter tw = File.CreateText(OutputBase + ".c")) {
            CCValues.PrintAll(tw);
        }
    }
Example #8
0
 internal override void PrintContents(
     TextWriter tw, int indent, XObjectGen xog)
 {
     CCValues.PrintRef(tw, xog.fields[off]);
 }