コード例 #1
0
        private static VhdlFile parse(VhdlParserSettings settings, ICharStream stream, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager)
        {
            vhdlLexer lexer = new vhdlLexer(stream);

            CommonTokenStream tokens = new CommonTokenStream(lexer);
            vhdlParser        parser = new vhdlParser(tokens);

            //--------------------------------------------
            //Optional - add listener
            //vhdlListener listener = new vhdlListener();
            //parser.AddParseListener(listener);
            //--------------------------------------------
            vhdlSemanticErrorListener vhdlSemanticErrorListener = new vhdlSemanticErrorListener(stream.SourceName);

            parser.AddErrorListener(vhdlSemanticErrorListener);

            IParseTree tree = parser.design_file();
            //Console.WriteLine(tree.ToStringTree(parser));
            vhdlVisitor visitor = new vhdlVisitor(settings, rootScope, libraryScope, libraryManager)
            {
                FileName = stream.SourceName
            };
            VhdlFile res = visitor.Visit(tree) as VhdlFile;

            return(res);
        }
コード例 #2
0
        private static VhdlFile parse(VhdlParserSettings settings, ICharStream stream, VHDL_Library_Manager libraryManager)
        {
            RootDeclarativeRegion    rootScope    = new RootDeclarativeRegion();
            LibraryDeclarativeRegion libraryScope = new LibraryDeclarativeRegion("work");

            rootScope.Libraries.Add(libraryScope);

            return(parse(settings, stream, rootScope, libraryScope, libraryManager));
        }
コード例 #3
0
        /// <summary>
        /// Сам процесс компиляции
        /// </summary>
        private void CompileFiles()
        {
            VhdlParserSettings settings = VhdlParserWrapper.DEFAULT_SETTINGS;

            settings.AddPositionInformation = true;
            RootDeclarativeRegion rootScope = new RootDeclarativeRegion();

            foreach (LibraryFileInfo file in compileQueue)
            {
                logger.WriteLineFormat("Compilation of the file: {0}", file.Path);
                logger.Write(file.PrintInfo());
                CompileFile(file, settings, rootScope);
                logger.WriteLineFormat("Compilation of the file: {0}. success", file.Path);
            }
        }
コード例 #4
0
 public static VhdlFile parseFile(string fileName, VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libray, VHDL_Library_Manager libraryManager)
 {
     return(parse(settings, new CaseInsensitiveFileStream(fileName), rootScope, libray, libraryManager));
 }
コード例 #5
0
 public static VhdlFile parseFile(string fileName, VhdlParserSettings settings, VHDL_Library_Manager libraryManager)
 {
     return(parse(settings, new CaseInsensitiveFileStream(fileName), libraryManager));
 }
コード例 #6
0
 public static VhdlFile parseStream(Stream stream, VhdlParserSettings settings, VHDL_Library_Manager libraryManager)
 {
     return(parse(settings, new CaseInsensitiveInputStream(stream), libraryManager));
 }
コード例 #7
0
        /// <summary>
        /// Компиляция файла
        /// </summary>
        /// <param name="file"></param>
        private void CompileFile(LibraryFileInfo file, VhdlParserSettings settings, RootDeclarativeRegion rootScope)
        {
            LibraryInfo currentLibrary = null;

            foreach (LibraryInfo inf in parsedLibraries)
            {
                if (inf.Name.EqualsIgnoreCase(file.LibraryName))
                {
                    currentLibrary = inf;
                    break;
                }
            }
            if (currentLibrary == null)
            {
                currentLibrary = new LibraryInfo(file.LibraryName);
                parsedLibraries.Add(currentLibrary);
                rootScope.Libraries.Add(currentLibrary.LibraryScope);
            }
            try
            {
                Console.WriteLine("parsing file {0} ", file.Path);
                VhdlFile vhdfile = VhdlParserWrapper.parseFile(file.Path, settings, rootScope, currentLibrary.LibraryScope, libraryManager);
                foreach (LibraryUnit unit in vhdfile.Elements)
                {
                    if (unit is PackageDeclaration)
                    {
                        PackageDeclaration pd = unit as PackageDeclaration;
                        pd.Parent = null;
                        bool foundPackage = false;
                        foreach (PackageInfo inf in currentLibrary.Packages)
                        {
                            if (inf.Name.EqualsIdentifier(pd.Identifier))
                            {
                                inf.DeclarationPath = file.Path;
                                string path = FormCompilePath(file.Path, "decl");
                                inf.DeclarationLibPath = path;
                                inf.Declaration        = pd;
                                foundPackage           = true;
                                break;
                            }
                        }
                        if (foundPackage == false)
                        {
                            PackageInfo pi = new PackageInfo(pd.Identifier, currentLibrary.Name, file.Path);
                            pi.DeclarationPath = file.Path;
                            string path = FormCompilePath(file.Path, "decl");
                            pi.DeclarationLibPath = path;
                            pi.BodyLibPath        = path;
                            pi.Declaration        = pd;
                            currentLibrary.Packages.Add(pi);
                        }
                    }
                    if (unit is PackageBody)
                    {
                        PackageBody pb = unit as PackageBody;
                        pb.Parent = null;
                        bool foundPackage = false;
                        foreach (PackageInfo inf in currentLibrary.Packages)
                        {
                            if (inf.Name.EqualsIdentifier(pb.Package.Identifier))
                            {
                                inf.BodyPath = file.Path;
                                string path = FormCompilePath(file.Path, "body");
                                inf.BodyLibPath = path;
                                inf.Body        = pb;
                                foundPackage    = true;
                                break;
                            }
                        }
                        if (foundPackage == false)
                        {
                            PackageInfo pi = new PackageInfo(pb.Package.Identifier, currentLibrary.Name, file.Path);
                            pi.BodyPath = file.Path;
                            string path = FormCompilePath(file.Path, "body");
                            pi.BodyLibPath = path;
                            pi.Body        = pb;
                            currentLibrary.Packages.Add(pi);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.WriteLineFormat("parsing {0} failed", file.Path);
                logger.WriteLine(ex.Message);
                logger.WriteLine(LoggerMessageVerbosity.Error, ex.Message);
            }
        }