Exemple #1
0
        public static CSTMethod Translate(MethodEnvironment methEnv, JST.NameSupply nameSupply, CSTWriter trace)
        {
            // Infer machine states for each control point
            var machineStateInference = new MachineStateInference(methEnv, trace);

            machineStateInference.Infer();

            if (trace != null)
            {
                trace.Trace
                    ("After machine state inference",
                    w =>
                {
                    methEnv.Method.AppendDefinition(w);
                    w.EndLine();
                });
            }

            // Translate to basic-blocks which use structural control flow where possible
            var controlFlowRecovery = new ControlFlowRecovery(methEnv, nameSupply.GenSym, -1, trace);
            var root = controlFlowRecovery.Root();

            if (trace != null)
            {
                trace.Trace
                    ("After control flow recovery",
                    w =>
                {
                    root.AppendAll(w);
                    w.EndLine();
                });
            }

            var initState = root.Targets[0].Block.BeforeState;
            var compEnv   = methEnv.AddVariables(nameSupply, i => initState.ArgLocalIsAlive(ArgLocal.Local, i));

            // Translate to intermediate statements/expressions/cells language
            var translator = new Translator
                                 (compEnv, nameSupply, controlFlowRecovery.NextInstructionId, trace);
            var body = translator.Translate(root);

            var res = new CSTMethod(compEnv, body);

            if (trace != null)
            {
                trace.Trace("After translation to intermediate representation", res.Append);
            }

            return(res);
        }
Exemple #2
0
        public static CSTMethod Translate(MethodEnvironment methEnv, JST.NameSupply nameSupply, CSTWriter trace)
        {
            // Infer machine states for each control point
            var machineStateInference = new MachineStateInference(methEnv, trace);
            machineStateInference.Infer();

            if (trace != null)
                trace.Trace
                    ("After machine state inference",
                     w =>
                         {
                             methEnv.Method.AppendDefinition(w);
                             w.EndLine();
                         });

            // Translate to basic-blocks which use structural control flow where possible
            var controlFlowRecovery = new ControlFlowRecovery(methEnv, nameSupply.GenSym, -1, trace);
            var root = controlFlowRecovery.Root();

            if (trace != null)
                trace.Trace
                    ("After control flow recovery",
                     w =>
                         {
                             root.AppendAll(w);
                             w.EndLine();
                         });

            var initState = root.Targets[0].Block.BeforeState;
            var compEnv = methEnv.AddVariables(nameSupply, i => initState.ArgLocalIsAlive(ArgLocal.Local, i));

            // Translate to intermediate statements/expressions/cells language
            var translator = new Translator
                (compEnv, nameSupply, controlFlowRecovery.NextInstructionId, trace);
            var body = translator.Translate(root);

            var res = new CSTMethod(compEnv, body);

            if (trace != null)
                trace.Trace("After translation to intermediate representation", res.Append);

            return res;
        }