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); }
protected VhdlFile parseCode(string code) { return(VhdlParserWrapper.parseString(code, libraryManager)); }
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(); }
public override bool CheckSyntaxOne(string filePath) { string startMessage = "Check syntax of " + filePath; bool success = true; Schematix.Core.UserControls.ProgressWindow.Window.RunProcess( new MyBackgroundWorker( new Action(() => { try { file = VhdlParserWrapper.parseFile(filePath, libraryManager); } catch (vhdlParseException ex) { string message = string.Format("{0} {1}:{2} {3} {4} {5}", ex.FilePath, ex.Line, ex.CharPositionInLine, ex.OffendingSymbol.Text, ex.Message, ex.InnerException); messages.Add(new DiagnosticMessage(message, new SourcePosition(ex.FilePath, ex.Line, ex.CharPositionInLine), MessageWindow.MessageType.Error)); success = false; } catch (vhdlSemanticException ex) { string message = string.Format("{0} {1}:{2} {3} {4} {5}", ex.FileName, ex.Context.Start.Line, ex.Context.Start.Column, ex.Context.GetText(), ex.Message, ex.InnerException); messages.Add(new DiagnosticMessage(message, new SourcePosition(ex.FileName, ex.Context.Start.Line, ex.Context.Start.Column), MessageWindow.MessageType.Error)); Console.WriteLine("Parsing failed"); success = false; } catch (Exception ex) { string message = string.Format("{0} {1} {2} \n {3}", ex.Message, ex.InnerException, ex.Source, ex.StackTrace); messages.Add(new DiagnosticMessage(message, false)); Console.WriteLine("Parsing failed"); success = false; } if (success) { Console.WriteLine("Parsing complete"); } if (file != null) { string compiledFile = Path.ChangeExtension(filePath, "obj"); Stream stream = new FileStream(compiledFile, FileMode.Create); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(stream, file); stream.Close(); } }), new Action(() => { }), string.Format("Check Syntax of {0}", filePath))); if (success) { messages.Add(new DiagnosticMessage(startMessage + " ... Fail")); return(false); } else { messages.Add(new DiagnosticMessage(startMessage + " ... Ok")); } return(base.CheckSyntaxOne(filePath)); }