Beispiel #1
0
        /// <summary>
        /// Should generate the code according to the specification of the algebra.
        /// </summary>
        /// <param name="S">The specification of the algebra. The specification also lists the names of the files
        /// to be generated, or at least the base path.</param>
        /// <param name="plugins">The plugins which Gaigen found that support the same language as this code generator.</param>
        /// <returns>a list of filenames; the names of the files that were generated. This may be used
        /// for post processing.</returns>
        public List<string> GenerateCode(Specification S, List<CodeGeneratorPlugin> plugins)
        {
            // disable all inlining since the Java language does not support this:
            S.SetInlineNone();

            CreatePackageDirectory(S);

            CoGsharp.CoG cog = InitCog(S);

            CG.Shared.CGdata cgd = new G25.CG.Shared.CGdata(plugins, cog);
            cgd.SetDependencyPrefix("missing_function_"); // this makes sure that the user sees the function call is a missing dependency
            G25.CG.Shared.FunctionGeneratorInfo FGI = (S.m_generateTestSuite) ? new G25.CG.Shared.FunctionGeneratorInfo() : null; // the fields in this variable are set by Functions.WriteFunctions() and reused by TestSuite.GenerateCode()

            { // pregenerated code that will go into main source
                // generate code for parts of the geometric product, dual, etc (works in parallel internally)
                try
                {
                    bool declOnly = false;
                    G25.CG.Shared.PartsCode.GeneratePartsCode(S, cgd, declOnly);
                }
                catch (G25.UserException E) { cgd.AddError(E); }


                // write function (works in parallel internally)
               G25.CG.Shared.Functions.WriteFunctions(S, cgd, FGI, Functions.GetFunctionGeneratorPlugins(cgd));
            }

            List<string> generatedFiles = new List<string>();

            // generate Doxyfile
            generatedFiles.Add(G25.CG.Shared.Util.GenerateDoxyfile(S, cgd));
            // generate source files / classes for all GMV, SMV, GOM, SOM types
            generatedFiles.AddRange(GenerateClasses(S, cgd));
            // generate source
            generatedFiles.AddRange(Source.GenerateCode(S, cgd));
            // generate smv type enum
            generatedFiles.AddRange(SmvType.GenerateCode(S, cgd));
            // generate GroupBitmap class
            generatedFiles.AddRange(GroupBitmap.GenerateCode(S, cgd));
            // generate multivector interfaces
            generatedFiles.AddRange(MvInterface.GenerateCode(S, cgd));
            // generate parser
            generatedFiles.AddRange(Parser.GenerateCode(S, cgd));
            // generate report usage code
            generatedFiles.AddRange(ReportUsage.GenerateCode(S, cgd));

            // report errors and missing deps to user
            cgd.PrintErrors(S);
            cgd.PrintMissingDependencies(S);
            if ((cgd.GetNbErrors() == 0) && (cgd.GetNbMissingDependencies() == 0) && S.m_generateTestSuite)
            {
                // generate test suite
                generatedFiles.AddRange(TestSuite.GenerateCode(S, cgd, FGI));
            }



            return generatedFiles;
        }
Beispiel #2
0
        /// <summary>
        /// Generate all code according to the specification of the algebra.
        /// </summary>
        /// <param name="S">The specification of the algebra. The specification also lists the names of the files
        /// to be generated, or at least the base path.</param>
        /// <param name="plugins">The plugins which Gaigen found that support the same language as this code generator.</param>
        /// <returns>a list of filenames; the names of the files that were generated. This may be used
        /// for post processing.</returns>
        public List <string> GenerateCode(Specification S, List <CodeGeneratorPlugin> plugins)
        {
            // disable all inlining since the C language does not support this:
            S.SetInlineNone();

            CoGsharp.CoG cog = InitCog(S);

            CG.Shared.CGdata cgd = new G25.CG.Shared.CGdata(plugins, cog);
            cgd.SetDependencyPrefix("missing_function_");                                                                         // this makes sure that the user sees the function call is a missing dependency
            G25.CG.Shared.FunctionGeneratorInfo FGI = (S.m_generateTestSuite) ? new G25.CG.Shared.FunctionGeneratorInfo() : null; // the fields in this variable are set by Functions.WriteFunctions() and reused by TestSuite.GenerateCode()


            { // pregenerated code that will go into header, source
                // generate code for parts of the geometric product, dual, etc (works in parallel internally)
                try {
                    bool declOnly = false;
                    G25.CG.Shared.PartsCode.GeneratePartsCode(S, cgd, declOnly);
                } catch (G25.UserException E) { cgd.AddError(E); }

                // write set zero, set, copy, copy between float types, extract coordinate, largest coordinate, etc (works in parallel internally)
                try {
                    GenerateSetFunctions(S, plugins, cgd);
                } catch (G25.UserException E) { cgd.AddError(E); }


                // write function (works in parallel internally)
                G25.CG.Shared.Functions.WriteFunctions(S, cgd, FGI, Functions.GetFunctionGeneratorPlugins(cgd));
            }

            List <string> generatedFiles = new List <string>();

            // generate Doxyfile
            generatedFiles.Add(G25.CG.Shared.Util.GenerateDoxyfile(S, cgd));
            // generate header
            generatedFiles.AddRange(Header.GenerateCode(S, cgd));
            // generate source
            generatedFiles.AddRange(Source.GenerateCode(S, cgd));
            // generate parser
            generatedFiles.AddRange(Parser.GenerateCode(S, cgd));

            // report errors and missing deps to user
            cgd.PrintErrors(S);
            cgd.PrintMissingDependencies(S);
            if ((cgd.GetNbErrors() == 0) && (cgd.GetNbMissingDependencies() == 0) && S.m_generateTestSuite)
            {
                // if no errors, then generate testing code
                TestSuite.GenerateCode(S, cgd, FGI);
            }

            // Generate random number generator source code (Mersenne Twister).
            // This must be done last since the testing code may require it!
            if (cgd.GetFeedback(G25.CG.C.MainGenerator.MERSENNE_TWISTER) == "true")
            {
                generatedFiles.AddRange(RandomMT.GenerateCode(S, cgd));
            }

            return(generatedFiles);
        }
Beispiel #3
0
        /// <summary>
        /// Loads all templates for the 'CPP' language into 'cog'. Also loads
        /// shared templates by calling G25.CG.Shared.Util.LoadTemplates(cog);
        /// </summary>
        /// <param name="cog">Templates are loaded into this variable.</param>
        /// <param name="S">Specification. Used to know whether testing code will be generated.</param>
        public override void LoadTemplates(Specification S, CoGsharp.CoG cog)
        {
            // also load shared templates:
            G25.CG.Shared.Util.LoadTemplates(cog);
            G25.CG.Shared.Util.LoadCTemplates(cog);

            cog.LoadTemplates(g25_cg_cpp.Properties.Resources.cg_cpp_templates, "cg_cpp_templates.txt");
            if (S.m_generateTestSuite) // only load when testing code is required
            {
                cog.LoadTemplates(g25_cg_cpp.Properties.Resources.cg_cpp_test_templates, "cg_cpp_test_templates.txt");
            }
        }
Beispiel #4
0
        public CoGsharp.CoG InitCog(Specification S)
        {
            // get cog, add references, load templates
            CoGsharp.CoG cog = new CoGsharp.CoG();
            cog.AddReference(S.GetType().Assembly.Location);                          // add reference for libg25
            cog.AddReference(RefGA.BasisBlade.ZERO.GetType().Assembly.Location);      // add reference for RefGA
            cog.AddReference(this.GetType().Assembly.Location);                       // add reference for this assembly
            cog.AddReference((new G25.CG.Shared.Util()).GetType().Assembly.Location); // add reference for g25_cg_shared

            LoadTemplates(S, cog);
            return(cog);
        }
Beispiel #5
0
        public CoGsharp.CoG InitCog(Specification S)
        {
            // get cog, add references, load templates
            CoGsharp.CoG cog = new CoGsharp.CoG();
            cog.AddReference(S.GetType().Assembly.Location); // add reference for libg25
            cog.AddReference(RefGA.BasisBlade.ZERO.GetType().Assembly.Location); // add reference for RefGA
            cog.AddReference(this.GetType().Assembly.Location); // add reference for this assembly
            cog.AddReference((new G25.CG.Shared.Util()).GetType().Assembly.Location); // add reference for g25_cg_shared

            LoadTemplates(S, cog);
            return cog;
        }
Beispiel #6
0
        /// <summary>
        /// Loads all templates for the 'Java' language into 'cog'. Also loads
        /// shared templates by calling G25.CG.Shared.Util.LoadTemplates(cog);
        /// </summary>
        /// <param name="cog">Templates are loaded into this variable.</param>
        /// <param name="S">Specification. Used to know whether testing code will be generated.</param>
        public override void LoadTemplates(Specification S, CoGsharp.CoG cog)
        {
            cog.AddReference((new G25.CG.CSJ.GMV()).GetType().Assembly.Location); // add reference for g25_cg_csj

            // also load shared templates:
            G25.CG.Shared.Util.LoadTemplates(cog);

            cog.LoadTemplates(g25_cg_csj_shared.Properties.Resources.cg_csj_shared_templates , "cg_csj_shared_templates.txt");
            cog.LoadTemplates(g25_cg_csj_shared.Properties.Resources.cg_csj_shared_test_templates, "cg_csj_shared_test_templates.txt");

            cog.LoadTemplates(g25_cg_java.Properties.Resources.cg_java_templates, "cg_java_templates.txt");
            if (S.m_generateTestSuite) // only load when testing code is required
                cog.LoadTemplates(g25_cg_java.Properties.Resources.cg_java_test_templates, "cg_java_test_templates.txt");
        }
Beispiel #7
0
 public CGdata(List<CodeGeneratorPlugin> plugins, CoGsharp.CoG cog)
 {
     m_plugins = plugins;
     m_cog = cog;
 }
Beispiel #8
0
 /// <summary>
 /// Loads shared templates for C and C++ for into 'cog'.
 /// Specifically, loads 'cg_shared_c_templates.txt'
 /// which is a project resource of g25_cg_shared.
 /// </summary>
 /// <param name="cog">Templates are loaded into cog.</param>
 public static void LoadCTemplates(CoGsharp.CoG cog)
 {
     cog.LoadTemplates(g25_cg_shared.Properties.Resources.cg_shared_c_templates, "cg_shared_c_templates.txt");
 }
Beispiel #9
0
 /// <summary>
 /// Should load all templates for the language into 'cog'.
 ///
 /// Default implementation does nothing.
 ///
 /// </summary>
 /// <param name="cog">Templates are loaded into this variable.</param>
 /// <param name="S">Specification. Used to know whether testing code will be generated.</param>
 public virtual void LoadTemplates(Specification S, CoGsharp.CoG cog)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="cgd"></param>
 public CGdata(CGdata cgd)
 {
     // copy all from cgd
     m_plugins = cgd.m_plugins;
     m_cog = cgd.m_cog;
     m_gmvGPpartFuncNames = cgd.m_gmvGPpartFuncNames;
     m_gmvDualPartFuncNames = cgd.m_gmvDualPartFuncNames;
     m_gmvGomPartFuncNames = cgd.m_gmvGomPartFuncNames;
     m_missingDependencies = cgd.m_missingDependencies;
     m_errors = cgd.m_errors;
     m_feedback = cgd.m_feedback;
     m_dependencyId = cgd.m_dependencyId;
     m_dependencyPrefix = cgd.m_dependencyPrefix;
 }
Beispiel #11
0
 public CGdata(List<CodeGeneratorPlugin> plugins, CoGsharp.CoG cog)
 {
     m_plugins = plugins;
     m_cog = cog;
 }