예제 #1
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        public LGSPActions(LGSPGraph lgspgraph)
        {
            graph = lgspgraph;
            matcherGenerator = new LGSPMatcherGenerator(graph.Model);

            modelAssemblyName = Assembly.GetAssembly(graph.Model.GetType()).Location;
            actionsAssemblyName = Assembly.GetAssembly(this.GetType()).Location;

#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
예제 #2
0
        /// <summary>
        /// Does action-backend dependent stuff.
        /// </summary>
        /// <param name="args">Any kind of parameters for the stuff to do</param>
        public override void Custom(params object[] args)
        {
            if(args.Length == 0) goto invalidCommand;

            switch((String) args[0])
            {
                case "gen_searchplan":
                {
                    if(graph.statistics.edgeCounts == null)
                        throw new ArgumentException("Graph not analyzed yet!\nPlease execute 'custom graph analyze'!");
                    LGSPAction[] oldActions;
                    if(args.Length == 1)
                    {
                        oldActions = new LGSPAction[actions.Count];
                        int i = 0;
                        foreach(LGSPAction action in actions.Values)
                        {
                            oldActions[i] = action;
                            ++i;
                        }
                    }
                    else
                    {
                        oldActions = new LGSPAction[args.Length - 1];
                        for(int i = 0; i < oldActions.Length; i++)
                        {
                            oldActions[i] = (LGSPAction)GetAction((String)args[i + 1]);
                            if(oldActions[i] == null)
                                throw new ArgumentException("'" + (String)args[i + 1] + "' is not the name of an action!\n"
                                    + "Please use 'show actions' to get a list of the available names.");
                        }
                    }

                    int startticks = Environment.TickCount;
                    matcherGenerator.LazyNegativeIndependentConditionEvaluation = LazyNIC;
                    matcherGenerator.InlineIndependents = InlineIndependents;
                    matcherGenerator.Profile = Profile;
                    LGSPAction[] newActions = matcherGenerator.GenerateActions(graph, modelAssemblyName,
                        actionsAssemblyName, oldActions);
                    int stopticks = Environment.TickCount;
                    Console.Write("Searchplans for actions ");
                    for(int i = 0; i < oldActions.Length; i++)
                    {
                        actions[oldActions[i].Name] = newActions[i];
                        if(i != 0) Console.Write(", ");
                        Console.Write("'" + oldActions[i].Name + "'");
                    }
                    Console.WriteLine(" generated in " + (stopticks - startticks) + " ms.");
                    return;
                }

                case "dump_sourcecode":
                    if(args.Length != 2)
                        throw new ArgumentException("Usage: dump_sourcecode <bool>\n"
                                + "If <bool> == true, C# files will be dumped for new searchplans.");

                    if(!bool.TryParse((String) args[1], out matcherGenerator.DumpDynSourceCode))
                        throw new ArgumentException("Illegal bool value specified: \"" + (String) args[1] + "\"");
                    return;

                case "dump_searchplan":
                    if(args.Length != 2)
                        throw new ArgumentException("Usage: dump_searchplan <bool>\n"
                                + "If <bool> == true, VCG and TXT files will be dumped for new searchplans.");

                    if(!bool.TryParse((String) args[1], out matcherGenerator.DumpSearchPlan))
                        throw new ArgumentException("Illegal bool value specified: \"" + (String) args[1] + "\"");
                    return;

                case "explain":
                {
                    if(args.Length != 2)
                        throw new ArgumentException("Usage: explain <name>\n"
                                + "Explains the searchplan of the given action.");

                    LGSPAction action = (LGSPAction)GetAction((String)args[1]);
                    if(action == null)
                        throw new ArgumentException("'" + (String)args[1] + "' is not the name of an action!\n"
                            + "Please use 'show actions' to get a list of the available names.");

                    if(action.patternGraph.schedules[0] == null)
                    {
                        LGSPGraphStatistics graphStatistics = null;
                        if(StatisticsPath != null)
                        {
                            Console.WriteLine("static search plans from " + StatisticsPath);
                            graphStatistics = new LGSPGraphStatistics(graph.Model);
                            graphStatistics.Parse(StatisticsPath);
                        }
                        else
                            Console.WriteLine("static search plans");
                        LGSPMatcherGenerator matcherGen = new LGSPMatcherGenerator(graph.Model);
                        matcherGen.FillInStaticSearchPlans(graphStatistics, InlineIndependents, action);
                    }
                    SourceBuilder sb = new SourceBuilder();
                    foreach(KeyValuePair<LGSPMatchingPattern, LGSPMatchingPattern> usedSubpattern
                        in action.rulePattern.patternGraph.usedSubpatterns)
                    {
                        usedSubpattern.Key.patternGraph.Explain(sb, graph.Model);
                    }
                    action.patternGraph.Explain(sb, graph.Model);
                    Console.WriteLine(sb.ToString());
                    return;
                }
            }

invalidCommand:
            throw new ArgumentException("Possible commands:\n"
                + "- gen_searchplan:  Generates a new searchplan for a given action\n"
                + "     depending on a previous graph analysis\n"
                + "- explain: explains the searchplan in use for a given action\n"
                + "- dump_sourcecode: Sets dumping of C# files for new searchplans\n"
                + "- dump_searchplan: Sets dumping of VCG and TXT files of new\n"
                + "     searchplans (with some intermediate steps)");
        }
예제 #3
0
        /// <summary>
        /// Constructs a new LGSPActions instance.
        /// This constructor is deprecated.
        /// </summary>
        /// <param name="lgspgraph">The associated graph.</param>
        /// <param name="modelAsmName">The name of the model assembly.</param>
        /// <param name="actionsAsmName">The name of the actions assembly.</param>
        public LGSPActions(LGSPGraph lgspgraph, String modelAsmName, String actionsAsmName)
        {
            graph = lgspgraph;
            modelAssemblyName = modelAsmName;
            actionsAssemblyName = actionsAsmName;
            matcherGenerator = new LGSPMatcherGenerator(graph.Model);
#if ASSERT_ALL_UNMAPPED_AFTER_MATCH
            OnMatched += new AfterMatchHandler(AssertAllUnmappedAfterMatch);
#endif
        }
예제 #4
0
        /// <summary>
        /// Generates scheduled search plans needed for matcher code generation for action compilation
        /// out of static schedule information given by rulePattern elements, 
        /// or out of statistics stemming from loading previously serialized statistics 
        /// utilizing code of the lgsp matcher generator.
        /// The scheduled search plans are added to the main and the nested pattern graphs.
        /// </summary>
        internal static void GenerateScheduledSearchPlans(PatternGraph patternGraph, LGSPGraphStatistics graphStatistics, 
            LGSPMatcherGenerator matcherGen,
            bool isSubpatternLike, bool isNegativeOrIndependent,
            ScheduledSearchPlan nestingScheduledSearchPlan)
        {
            for(int i=0; i<patternGraph.schedules.Length; ++i)
            {
                patternGraph.AdaptToMaybeNull(i);
                if(matcherGen.Profile)
                    LGSPMatcherGenerator.SetNeedForProfiling(patternGraph);
                PlanGraph planGraph;
                if(graphStatistics != null)
                    planGraph = matcherGen.GeneratePlanGraph(graphStatistics, patternGraph, 
                        isNegativeOrIndependent, isSubpatternLike,
                        LGSPMatcherGenerator.ExtractOwnElements(nestingScheduledSearchPlan, patternGraph));
                else
                    planGraph = GenerateStaticPlanGraph(patternGraph,
                        isNegativeOrIndependent, isSubpatternLike, matcherGen.InlineIndependents,
                        LGSPMatcherGenerator.ExtractOwnElements(nestingScheduledSearchPlan, patternGraph));
                matcherGen.MarkMinimumSpanningArborescence(planGraph, patternGraph.name);
                SearchPlanGraph searchPlanGraph = matcherGen.GenerateSearchPlanGraph(planGraph);
                ScheduledSearchPlan scheduledSearchPlan = matcherGen.ScheduleSearchPlan(
                    searchPlanGraph, patternGraph, isNegativeOrIndependent);
                matcherGen.AppendHomomorphyInformation(scheduledSearchPlan);
                patternGraph.schedules[i] = scheduledSearchPlan;
                patternGraph.RevertMaybeNullAdaption(i);

                foreach(PatternGraph neg in patternGraph.negativePatternGraphsPlusInlined)
                {
                    GenerateScheduledSearchPlans(neg, graphStatistics, matcherGen, 
                        isSubpatternLike, true, null);
                }

                foreach(PatternGraph idpt in patternGraph.independentPatternGraphsPlusInlined)
                {
                    GenerateScheduledSearchPlans(idpt, graphStatistics, matcherGen,
                        isSubpatternLike, true, patternGraph.schedules[i]);
                }

                foreach(Alternative alt in patternGraph.alternativesPlusInlined)
                {
                    foreach(PatternGraph altCase in alt.alternativeCases)
                    {
                        GenerateScheduledSearchPlans(altCase, graphStatistics, matcherGen, 
                            true, false, null);
                    }
                }

                foreach(Iterated iter in patternGraph.iteratedsPlusInlined)
                {
                    GenerateScheduledSearchPlans(iter.iteratedPattern, graphStatistics, matcherGen, 
                        true, false, null);
                }
            }
        }
예제 #5
0
        private void GenerateAndInsertMatcherSourceCode(IGraphModel model, String actionsName, String unitName,
            string externalActionsExtensionFilename, LGSPRuleAndMatchingPatterns ruleAndMatchingPatterns, 
            LGSPSequenceGenerator seqGen, bool isAutoGeneratedFilterExisting, bool isExternalFilterFunctionExisting,
            LGSPGraphStatistics graphStatistics, string statisticsPath,
            SourceBuilder externalSource, SourceBuilder source)
        {
            // analyze the matching patterns, inline the subpatterns when expected to be benefitial
            // the analyzer must be run before the matcher generation
            AnalyzeAndInlineMatchingPatterns((flags & ProcessSpecFlags.Noinline) == 0, ruleAndMatchingPatterns);

            LGSPMatcherGenerator matcherGen = new LGSPMatcherGenerator(model);
            if((flags & ProcessSpecFlags.KeepGeneratedFiles) != 0) matcherGen.CommentSourceCode = true;
            if((flags & ProcessSpecFlags.LazyNIC) != 0) matcherGen.LazyNegativeIndependentConditionEvaluation = true;
            if((flags & ProcessSpecFlags.Noinline) != 0) matcherGen.InlineIndependents = false;
            if((flags & ProcessSpecFlags.Profile) != 0) matcherGen.Profile = true;

            foreach(LGSPMatchingPattern matchingPattern in ruleAndMatchingPatterns.RulesAndSubpatterns)
            {
                GenerateScheduledSearchPlans(matchingPattern.patternGraph, graphStatistics, 
                    matcherGen, !(matchingPattern is LGSPRulePattern), false, null);

                matcherGen.MergeNegativeAndIndependentSchedulesIntoEnclosingSchedules(matchingPattern.patternGraph);

                matcherGen.ParallelizeAsNeeded(matchingPattern);

                matcherGen.GenerateActionAndMatcher(source, matchingPattern, true);
            }

            GenerateDefinedSequencesAndFiltersAndFilterStubs(externalActionsExtensionFilename, 
                isAutoGeneratedFilterExisting, isExternalFilterFunctionExisting,
                ruleAndMatchingPatterns, seqGen, externalSource, source);

            // the actions class referencing the generated stuff is generated now into 
            // a source builder which is appended at the end of the other generated stuff
            SourceBuilder endSource = GenerateActionsClass(model, actionsName, unitName,
                statisticsPath, ruleAndMatchingPatterns, 
                matcherGen.LazyNegativeIndependentConditionEvaluation,
                matcherGen.InlineIndependents,
                matcherGen.Profile);
            source.Append(endSource.ToString());
            source.Append("}");
        }
예제 #6
0
        private static void BuildInterpretationPlan(LGSPGraph graph)
        {
            LGSPMatcherGenerator matcherGen = new LGSPMatcherGenerator(graph.Model);
            graph.matchingState.patternGraph = matcherGen.BuildPatternGraph(graph);
            PlanGraph planGraph = matcherGen.GeneratePlanGraph(graph.statistics, graph.matchingState.patternGraph, 
                false, false, new Dictionary<PatternElement, SetValueType>());
            matcherGen.MarkMinimumSpanningArborescence(planGraph, graph.matchingState.patternGraph.name);
            SearchPlanGraph searchPlanGraph = matcherGen.GenerateSearchPlanGraph(planGraph);
            ScheduledSearchPlan scheduledSearchPlan = matcherGen.ScheduleSearchPlan(
                searchPlanGraph, graph.matchingState.patternGraph, false);
            InterpretationPlanBuilder builder = new InterpretationPlanBuilder(scheduledSearchPlan, searchPlanGraph, graph.Model);
            graph.matchingState.interpretationPlan = builder.BuildInterpretationPlan("ComparisonMatcher_" + graph.graphID);
            ++GraphMatchingState.numInterpretationPlans;
            graph.matchingState.changesCounterAtInterpretationPlanBuilding = graph.changesCounterAtLastAnalyze;
            Debug.Assert(graph.changesCounterAtLastAnalyze == graph.ChangesCounter);

#if LOG_ISOMORPHY_CHECKING
            SourceBuilder sb = new SourceBuilder();
            graph.matchingState.interpretationPlan.Dump(sb);
            writer.WriteLine();
            writer.WriteLine(sb.ToString());
            writer.WriteLine();
            writer.Flush();
#endif
        }