Exemple #1
0
 internal override GFunction ToGFunction()
 {
     return(GFunctionInterpreted.Add(cfi));
 }
Exemple #2
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);
        }
    }