Exemplo n.º 1
0
        public static string GenerateMakeCommands(CoG cog, string specName, SpecVars SV, string target)
        {
            StringBuilder SB = new StringBuilder();

            SB.AppendLine("");
            SB.AppendLine("cd " + specName);

            if (IsUnix())
            {
                SB.AppendLine("make" + target);
                SB.AppendLine("if [ $? -eq 0 ]; ");
                SB.AppendLine("then");
                SB.AppendLine("echo \"build ok\"");
                SB.AppendLine("else");
                SB.AppendLine("\texit $?");
                SB.AppendLine("fi");
            }
            else
            {
                SB.AppendLine("nmake" + target);
                SB.AppendLine("if not %errorlevel%==0 goto :error");
            }

            SB.AppendLine("cd ..");

            return(SB.ToString());
        }
Exemplo n.º 2
0
        public static string GenerateDoxygenCommands(CoG cog, string specName, SpecVars SV)
        {
            StringBuilder SB = new StringBuilder();

            SB.AppendLine("");
            SB.AppendLine("cd " + specName);
            SB.AppendLine("echo \"Running doxygen for " + specName + " \"");
            SB.AppendLine("doxygen");
            SB.AppendLine("cd ..");

            return(SB.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Varies the random generator (built-in, Mersenne Twister)
        /// </summary>
        /// <param name="mvNames">List of variations on the random generator.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryRandomGenerator(List <string> randomGenerators)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (string g in randomGenerators)
            {
                SpecVars V = this.Clone();
                V.RandomGenerator = g;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Varies the dimension of 'this'.
        /// </summary>
        /// <param name="dimensions">List of variations on the dimension.</param>
        /// <returns>a list of variations.</returns>
        public List <SpecVars> VaryDimension(List <int> dimensions)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (int dim in dimensions)
            {
                SpecVars V = this.Clone();
                V.Dimension = dim;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Varies whether to report usage of converted SMV in GMV functions.
        /// </summary>
        /// <param name="reportUsage">List of variations on inlining.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryReportUsage(List <bool> reportUsage)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool bip in reportUsage)
            {
                SpecVars V = this.Clone();
                V.ReportUsage = bip;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Varies whether to inline code.
        /// </summary>
        /// <param name="doInline">List of variations on inlining.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryInline(List <bool> doInline)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool bip in doInline)
            {
                SpecVars V = this.Clone();
                V.Inline = bip;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Varies the way GMV memory is allocate (pp, full, dynamic)
        /// </summary>
        /// <param name="mvNames">List of variations on the memory allocation for GMVs.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryGmvMemAlloc(List <G25.GMV.MEM_ALLOC_METHOD> gmvMemAlloc)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (G25.GMV.MEM_ALLOC_METHOD a in gmvMemAlloc)
            {
                SpecVars V = this.Clone();
                V.GmvMemAlloc = a;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Varies the scalar name of 'this'.
        /// </summary>
        /// <param name="scalarNames">List of variations on the name of the scalar type.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryScalarNames(List <string> scalarNames)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (string name in scalarNames)
            {
                SpecVars V = this.Clone();
                V.ScalarName = name;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Varies the way GMV code is generated (runtime, or expand).
        /// </summary>
        /// <param name="mvNames">List of variations on the code generation for GMVs.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryGmvCode(List <G25.GMV_CODE> gmvCode)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (G25.GMV_CODE c in gmvCode)
            {
                SpecVars V = this.Clone();
                V.GmvCode = c;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Varies the parser (builtin or ANTLR) of 'this'.
        /// </summary>
        /// <param name="useBuiltinParser">List of variations on the parser.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryBuiltInParser(List <bool> useBuiltinParser)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool bip  in useBuiltinParser)
            {
                SpecVars V = this.Clone();
                V.BuiltInParser = bip;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Varies the whether to a have a GOM or not.
        /// </summary>
        /// <param name="haveGOM">List of variations on the GOM yes/no.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryHaveGom(List <bool> haveGom)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool hg in haveGom)
            {
                SpecVars V = this.Clone();
                V.HaveGom = hg;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Varies the grouping method (regular or 'alternative') of 'this'.
        /// </summary>
        /// <param name="alternativeGrouping">List of variations on the  grouping method.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryGroupAlternative(List <bool> alternativeGrouping)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool ac in alternativeGrouping)
            {
                SpecVars V = this.Clone();
                V.GroupAlternative = ac;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Varies the coordinate storage method of 'this'.
        /// </summary>
        /// <param name="coordStorage">List of variations on the coordinate storage method.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryCoordStorage(List <G25.COORD_STORAGE> coordStorage)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (G25.COORD_STORAGE cs in coordStorage)
            {
                SpecVars V = this.Clone();
                V.CoordStorage = cs;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Varies the whether a scalar type is present.
        /// </summary>
        /// <param name="haveScalar">List of variations on the scalar type.</param>
        /// <returns>a list of variations.</returns>
        public List <SpecVars> VaryHaveScalarType(List <bool> haveScalar)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (bool hs in haveScalar)
            {
                SpecVars V = this.Clone();
                V.HaveScalarType = hs;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Varies the float types.
        /// </summary>
        /// <param name="reportUsage">List of float types.</param>
        /// <returns>Returns a list of variations.</returns>
        public List <SpecVars> VaryFloatTypes(List <List <string> > floatTypes)
        {
            List <SpecVars> list = new List <SpecVars>();

            foreach (List <string> FT in floatTypes)
            {
                SpecVars V = this.Clone();
                V.FloatTypes = FT;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Varies the output language of 'this'.
        /// </summary>
        /// <param name="languages">List of variations on the output language.</param>
        /// <returns>a list of variations.</returns>
        public List <SpecVars> VaryOutputLanguage(List <string> languages)
        {
            List <SpecVars> list = new  List <SpecVars>();

            foreach (string lang in languages)
            {
                SpecVars V = this.Clone();
                V.OutputLanguage = lang;
                list.Add(V);
            }

            return(list);
        }
Exemplo n.º 17
0
        public static string GenerateFromVar(CoG cog,
                                             Dictionary <string, List <string> > commands,
                                             string specTemplateName,
                                             string makefileTemplateName,
                                             string specBaseName,
                                             SpecVars SV)
        {
            GeneratorCount++;

            // get name of specification
            string specName = specBaseName + "_" + SV.GetShortName();

            // get full directory name, create directory
            string dirName = System.IO.Path.Combine(OutputDirectory, specName);

            try
            {
                System.IO.Directory.CreateDirectory(dirName);
            }
            catch (Exception)
            {
                Console.WriteLine("Warning: this directory is not clean: " + dirName);
            }

            // get filename of spec, write it
            string specFilename = System.IO.Path.Combine(dirName, specName + ".xml");

            GenerateSpecFromVar(cog, specTemplateName, specName, specFilename, SV);

            // get filename of makefile, write it
            string makefileFilename = System.IO.Path.Combine(dirName, "Makefile");

            GenerateMakefileFromVar(cog, makefileTemplateName, specName, makefileFilename, specBaseName, SV);

            // if myDouble is used, generate it
            if (SV.FloatTypes.Contains("myDouble"))
            {
                string myDoubleFilename = System.IO.Path.Combine(dirName, "my_double.h");
                GenerateMyDoubleFromVar(cog, myDoubleFilename, SV);
            }


            commands[BUILD_CMD].Add(GenerateMakeCommands(cog, specName, SV, ""));
            commands[TEST_CMD].Add(GenerateRunCommands(cog, specName, SV));
            commands[CLEAN_CMD].Add(GenerateMakeCommands(cog, specName, SV, " clean"));
            commands[XML_TEST_CMD].Add(GenerateXmlTestCommands(cog, specName, SV));
            commands[DOXYGEN_CMD].Add(GenerateDoxygenCommands(cog, specName, SV));

            return(specName);
        }
Exemplo n.º 18
0
        public static void GenerateMyDoubleFromVar(CoG cog, string filename, SpecVars SV)
        {
            // get name of template
            string templateName = "not_set";

            if (SV.OutputLanguage == "cpp")
            {
                templateName = "myDouble_cpp_header";
            }

            // write template to StringBuilder
            StringBuilder SB = new StringBuilder();

            cog.EmitTemplate(SB, templateName);

            // write template to file
            G25.CG.Shared.Util.WriteFile(filename, SB.ToString());
        }
Exemplo n.º 19
0
        public static void GenerateSampleAlgebras(CoG cog, Dictionary <string, List <string> > commands)
        {
            Console.WriteLine("Generating the sample algebras");

            ReduceNbTestsBy = 1;
            Shuffle         = false;

            SpecVars SV = new SpecVars();

            SV.HaveGom           = true;
            SV.Inline            = true;
            SV.ShortNameLangOnly = true;
            List <SpecVars> vars = SV.VaryOutputLanguage(Languages);

            GenerateE2gaVariations(cog, commands, vars);

            GenerateE3gaVariations(cog, commands, vars);

            GenerateP3gaVariations(cog, commands, vars);

            GenerateC3gaVariations(cog, commands, vars);
        }
Exemplo n.º 20
0
        public static string GenerateXmlTestCommands(CoG cog, string specName, SpecVars SV)
        {
            StringBuilder SB             = new StringBuilder();
            string        xmlTestdirName = XML_TEST_CMD;
            string        fileListName   = "g25_file_list.txt";

            SB.AppendLine("");
            SB.AppendLine("cd " + specName);
            SB.AppendLine("g25 -d true -f " + fileListName + " " + specName + ".xml");
            SB.AppendLine("mkdir " + xmlTestdirName);

            SB.AppendLine("g25 -d true -s " + xmlTestdirName + System.IO.Path.DirectorySeparatorChar + specName + ".xml " + specName + ".xml");
            SB.AppendLine("cd " + xmlTestdirName);
            SB.AppendLine("g25 -d true -f " + fileListName + " " + specName + ".xml");

            SB.AppendLine("g25_diff " + fileListName + " .." + System.IO.Path.DirectorySeparatorChar + fileListName);

            if (IsWindows())
            {
                SB.AppendLine("if not %errorlevel%==0 goto :error");
            }
            else
            {
                SB.AppendLine("if [ $? -eq 0 ]; ");
                SB.AppendLine("then");
                SB.AppendLine("echo \"XML test ok\"");
                SB.AppendLine("else");
                SB.AppendLine("\texit $?");
                SB.AppendLine("fi");
            }

            SB.AppendLine("cd .."); // leave xmlTestdirName

            SB.AppendLine("cd .."); // leave algebra dir

            return(SB.ToString());
        }
Exemplo n.º 21
0
        public static string GenerateRunCommands(CoG cog, string specName, SpecVars SV)
        {
            StringBuilder SB = new StringBuilder();

            SB.AppendLine("");
            SB.AppendLine("cd " + specName);
            SB.AppendLine("echo \"Testing " + specName + " \"");
            if (IsUnix())
            {
                if (SV.OutputLanguage == G25.XML.XML_JAVA)
                {
                    SB.AppendLine("sh ./test.sh");
                }
                else if (SV.OutputLanguage == G25.XML.XML_CSHARP)
                {
                    SB.AppendLine("mono ./test.exe");
                }
                else
                {
                    SB.AppendLine("./test");
                }
            }
            else
            {
                if (SV.OutputLanguage == G25.XML.XML_JAVA)
                {
                    SB.AppendLine("call test.bat");
                }
                else
                {
                    SB.AppendLine("test.exe");
                }
            }
            SB.AppendLine("cd ..");

            return(SB.ToString());
        }
Exemplo n.º 22
0
        public static List <SpecVars> GetVariations(int minDim, int maxDim, bool groupAlternative, string alternativeGmvName, string alternativeScalarName, bool varyGmvCode, bool varyInline, bool varyCoordStorage)
        {
            List <SpecVars> returnList = new List <SpecVars>();

            foreach (string lang in Languages)
            {
                List <SpecVars> list = new List <SpecVars>();
                list.Add(new SpecVars());

                // vary output language
                list[0].OutputLanguage = lang;
                int langMaxDim = (lang == G25.XML.XML_JAVA) ? 10 : maxDim; // limit Java to 10-D due to the 64K method-size limit (doh).

                // vary dimension
                List <int> dims = new List <int>();
                for (int d = minDim; d <= Math.Min(langMaxDim, maxDim); d++)
                {
                    dims.Add(d);
                }
                list = SpecVars.VaryDimension(list, dims);

                // vary scalar type
                list = SpecVars.VaryHaveScalarType(list, new List <bool> {
                    false, true
                });

                // vary GMV coordinate storage
                if (varyCoordStorage)
                {
                    list = SpecVars.VaryCoordStorage(list, new List <G25.COORD_STORAGE> {
                        G25.COORD_STORAGE.ARRAY, G25.COORD_STORAGE.VARIABLES
                    });
                }

                // vary grouping of GMV
                if (groupAlternative)
                {
                    list = SpecVars.VaryGroupAlternative(list, new List <bool> {
                        false, true
                    });
                }

                // vary GOM
                list = SpecVars.VaryHaveGom(list, new List <bool> {
                    false, true
                });

                // vary parser
                list = SpecVars.VaryBuiltInParser(list, new List <bool> {
                    false, true
                });

                // vary GMV name
                if ((alternativeGmvName != null) && (alternativeGmvName.Length > 0))
                {
                    list = SpecVars.VaryGmvNames(list, new List <string> {
                        "mv", alternativeGmvName
                    });
                }

                // vary scalar type name
                if ((alternativeScalarName != null) && (alternativeScalarName.Length > 0))
                {
                    list = SpecVars.VaryScalarNames(list, new List <string> {
                        "scalar", alternativeScalarName
                    });
                }

                // vary GMV function coding
                if (varyGmvCode)
                {
                    list = SpecVars.VaryGmvCode(list, new List <G25.GMV_CODE> {
                        G25.GMV_CODE.EXPAND, G25.GMV_CODE.RUNTIME
                    });
                }

                // vary GMV function coding
                if ((lang == G25.XML.XML_CPP) || (lang == G25.XML.XML_C))
                {
                    list = SpecVars.VaryRandomGenerator(list, new List <string> {
                        "libc", "mt"
                    });
                }
                else
                {
                    list = SpecVars.VaryRandomGenerator(list, new List <string> {
                        "libc"
                    });
                }

                // vary inline, report usage
                if ((lang != G25.XML.XML_C) && varyInline)
                {
                    list = SpecVars.VaryInline(list, new List <bool> {
                        false, true
                    });
                    list = SpecVars.VaryReportUsage(list, new List <bool> {
                        false, true
                    });
                }

                // vary GMV memory allocation
                List <G25.GMV.MEM_ALLOC_METHOD> AL = new List <G25.GMV.MEM_ALLOC_METHOD> {
                    G25.GMV.MEM_ALLOC_METHOD.FULL, G25.GMV.MEM_ALLOC_METHOD.PARITY_PURE
                };
                if (lang != G25.XML.XML_C)
                {
                    AL.Add(G25.GMV.MEM_ALLOC_METHOD.DYNAMIC);
                }
                list = SpecVars.VaryGmvMemAlloc(list, AL);

                // vary floating point types
                List <List <string> > FT = null;
                if (lang == G25.XML.XML_CPP)
                {
                    if (minDim < 5)
                    {
                        FT = new List <List <string> > {
                            new List <string> {
                                "float"
                            },
                            new List <string> {
                                "double"
                            },
                            new List <string> {
                                "double", "float", "myDouble"
                            }
                        }
                    }
                    ;
                    else
                    {
                        FT = new List <List <string> > {
                            new List <string> {
                                "float"
                            },
                            new List <string> {
                                "myDouble"
                            },
                            new List <string> {
                                "double", "myDouble"
                            }
                        }
                    };
                }
                else
                {
                    FT = new List <List <string> > {
                        new List <string> {
                            "float"
                        },
                        new List <string> {
                            "double"
                        },
                        new List <string> {
                            "double", "float"
                        }
                    };
                }

                list = SpecVars.VaryFloatTypes(list, FT);

                returnList.AddRange(list);
            }

            return(returnList);
        }
Exemplo n.º 23
0
        public static void GenerateMakefileFromVar(CoG cog, string templateName, string specName, string makefileFilename, string algebraName, SpecVars SV)
        {
            // write template to StringBuilder
            StringBuilder SB = new StringBuilder();

            cog.EmitTemplate(SB, templateName,
                             "SV=", SV,
                             "SPEC_NAME=", specName,
                             "ALGEBRA_NAME=", algebraName,
                             "WINDOWS=", IsWindows(),
                             "MACOSX=", GetPlatformID() == PlatformID.MacOSX,
                             "LINUX=", GetPlatformID() == PlatformID.Unix
                             );

            // write template to file
            G25.CG.Shared.Util.WriteFile(makefileFilename, SB.ToString());
        }
Exemplo n.º 24
0
        public static void GenerateSpecFromVar(CoG cog, string templateName, string specName, string specFilename, SpecVars SV)
        {
            // write template to StringBuilder
            StringBuilder SB = new StringBuilder();

            cog.EmitTemplate(SB, templateName, "SV=", SV);

            // write template to file
            G25.CG.Shared.Util.WriteFile(specFilename, SB.ToString());
        }