Ejemplo n.º 1
0
 public vhdlAbstractVisitor(VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager)
 {
     this.settings            = settings;
     this.rootScope           = rootScope;
     this.libraryScope        = libraryScope;
     this.libraryScope.Parent = rootScope;
     fileName            = string.Empty;
     this.libraryManager = libraryManager;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        public static void VHDLSample()
        {
            Console.WriteLine("Hello World!");

            // TODO: Implement Functionality Here
            string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");

            VHDL_Library_Manager libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);

            libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
            libraryManager.LoadData(@"Libraries");
            VhdlParserSettings       settings       = VhdlParserWrapper.DEFAULT_SETTINGS;
            RootDeclarativeRegion    rootScope      = new RootDeclarativeRegion();
            LibraryDeclarativeRegion currentLibrary = new LibraryDeclarativeRegion("work");

            rootScope.Libraries.Add(currentLibrary);
            rootScope.Libraries.Add(libraryManager.GetLibrary("STD"));

            bool success = true;

            try
            {
                Console.WriteLine("Parsing code");
                VhdlFile file = VhdlParserWrapper.parseFile("sample.vhdl", settings, rootScope, currentLibrary, libraryManager);
            }
            catch (vhdlParseException ex)
            {
                Console.WriteLine(string.Format("{0} {1}:{2} {3} {4} {5}", ex.FilePath, ex.Line, ex.CharPositionInLine, ex.OffendingSymbol.Text, ex.Message, ex.InnerException));
                Console.WriteLine("Parsing failed");
                success = false;
            }
            catch (vhdlSemanticException ex)
            {
                Console.WriteLine(ex.GetConsoleMessageTest());
                Console.WriteLine("Parsing failed");
                success = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("{0} {1} {2} \n {3}", ex.Message, ex.InnerException, ex.Source, ex.StackTrace));
                Console.WriteLine("Parsing failed");
                success = false;
            }
            if (success)
            {
                Console.WriteLine("Parsing complete");
            }



            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public VHDLCompiler(string ProgramPath)
        {
            string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");

            libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);
            libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
            libraryManager.LoadData(@"Libraries");

            settings = VhdlParserWrapper.DEFAULT_SETTINGS;
            settings.AddPositionInformation = true;
            rootScope      = new RootDeclarativeRegion();
            currentLibrary = new LibraryDeclarativeRegion("work");
            rootScope.Libraries.Add(currentLibrary);
            rootScope.Libraries.Add(libraryManager.GetLibrary("STD"));
        }
Ejemplo n.º 6
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));
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            try
            {
                string appBase = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                VHDL.parser.Logger loggercompile = VHDL.parser.Logger.CreateLogger(appBase, "compiler");
                VHDLRuntime.Logger loggerrun     = VHDLRuntime.Logger.CreateLogger(appBase, "run");

                VHDL_Library_Manager libraryManager = new VHDL_Library_Manager("", @"Libraries\LibraryRepository.xml", loggercompile);
                libraryManager.Logger.OnWriteEvent += new VHDL.parser.Logger.OnWriteDeleagte(Logger_OnWriteEvent);
                libraryManager.LoadData(@"Libraries");
                VhdlParserSettings       settings       = VhdlParserWrapper.DEFAULT_SETTINGS;
                RootDeclarativeRegion    rootScope      = new RootDeclarativeRegion();
                LibraryDeclarativeRegion currentLibrary = new LibraryDeclarativeRegion("work");
                rootScope.Libraries.Add(currentLibrary);
                //rootScope.getLibraries().Add(VHDL_Library_Manager.GetLibrary("STD"));

                Console.WriteLine("Parsing code");
                VhdlFile file = VhdlParserWrapper.parseFile("vhdl_tests\\simple_simulation.vhd", settings, rootScope, currentLibrary, libraryManager);
                Console.WriteLine("Parsing complete");

                foreach (LibraryUnit unit in file.Elements)
                {
                    if (unit is Architecture)
                    {
                        Architecture arch = unit as Architecture;
                        if (arch.Identifier.Equals("some_test_bench"))
                        {
                            string fileName = string.Format("{0}\\{1}.dll", appBase, arch.Identifier);
                            string vcdFile  = string.Format("{0}\\dump.vcd", appBase, arch.Identifier);


                            VHDLCompilerInterface compiler = new VHDLCompilerInterface(arch, loggercompile);
                            compiler.Compile(appBase);

                            TestRunner.LoadMyAssemblyAndRun(fileName, arch.Identifier, arch.Identifier, loggerrun, vcdFile);

                            Process proc = new Process();
                            proc.StartInfo.Arguments        = "run.log";
                            proc.StartInfo.FileName         = "notepad.exe";
                            proc.StartInfo.WorkingDirectory = Process.GetCurrentProcess().StartInfo.WorkingDirectory;
                            proc.Start();
                        }
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
            catch { }
            Console.ReadKey();
        }
Ejemplo n.º 10
0
 public vhdlAbstractVisitor(VhdlParserSettings settings, RootDeclarativeRegion rootScope, LibraryDeclarativeRegion libraryScope, VHDL_Library_Manager libraryManager, string fileName)
     : this(settings, rootScope, libraryScope, libraryManager)
 {
     this.fileName = fileName;
 }