Академический Документы
Профессиональный Документы
Культура Документы
ECE 4899
Table of Contents
Abstract ...................................................................................................................................................... 2
Introduction ................................................................................................................................................ 3
Details of Procedure: .................................................................................................................................. 6
Results ........................................................................................................................................................ 8
Discussion and Conclusion .......................................................................................................................... 9
Appendix ................................................................................................................................................... 12
User Interface ....................................................................................................................................... 12
Description of the Linting Tool Parsers Class Hierarchy ....................................................................... 15
User Guide For Running the Linting Tool for the First Time .................................................................. 19
Guide For Running the JNLP Creator ..................................................................................................... 23
Linting Tool Code Files .......................................................................................................................... 28
ECE 4899
Abstract
The ECE 4242 Advanced Digital Design Methodologies course as well as several other courses at
University of Colorado at Colorado Springs teach students about digital design techniques and place
emphasis on the Verilog hardware description language. The students learn syntax needed to code in
Verilog, as well as methods to simulate their code. They also learn how to synthesize their Verilog code
designs to gate level schematics for FPGA devices. However, because simulation and synthesis are
separate processes, a student may find that his or her correctly simulating design may not be
synthesizable into gate level logic.
In an attempt to help prevent this problem from occurring and to improve the quality of student
Verilog code the instructor for these Verilog courses and sponsor for the project Dr. Greg Tumbush
requested the design of a Verilog Linting Tool that is capable of checking a students Verilog code for
errors that would prevent it from being synthesizable.
The Verilog Linting Tool was designed and built using the java programming language and the
java runtime environment in order to be able to continue to add new Errors after the tools initial
publication, and to allow easy building and running of the executable jar file after setup. The solution
linting tool that has been built is able to detect and report to the user the presence of up to 17 different
code errors that would prevent the Verilog code from being synthesizable. The tool is also able to be
run on several different operating system platforms, and was tested and verified to work on Mac OSX,
Windows 7, Windows 8, and Windows XP.
ECE 4899
Introduction
The University of Colorado at Colorado Springs offers several courses that require students to
write behavior-modeled digital design code using the Verilog hardware description language.
Consequently students also need a way to check for synthesis errors in their Verilog Hardware
Description Files. A linting tool that is capable of checking these files for synthesis error was requested
for students to use in these classes. UCCS students do have access to a professional linting tool, but this
professional tool requires a remote service to be started, students are inconvenienced by the necessity
of logging into a linux virtual machine, and then subsequently spending time setting up the tool. This is
a very time consuming, and inconvenient process for the students to check their Verilog files for
synthesiazability.
The request for making a new Linting Tool that will remedy these issues was made by the
project sponsor and advisor Dr. Tumbush for the improvement of the classes that he teaches. The new
tool needed to be able to be more easily accessable to all students regardless of their preferred
operating system and access to a remote connection client. The tool itself must be able to be updated
easily and as hassle free as possible for both the project sponsor hosting the tool as well as the students
of UCCS using the tool. The solution tool needs to stay up to date with the current errors and updates
that were incorporated into the tool at any given time. Next, the tools GUI must be as easy and
straightforward as possible because the tool was going to be used by students with various
technological skills. After assessing these requirements our team made the decision for developing the
new linting tool in the Java programming language.
Two of the main reasons Java was chosen was that some of the services it offered such as Java
Web Start and the Java Virtual Machine. Java Web Start is a program built into the Java Runtime
Environment that allows web-hosted programs to be downloaded and run on the users local machine.
ECE 4899
It also monitors the download location where the tool was received from and checks for updates every
time the program is run again. If an updated version of the program is found it is automatically
downloaded to the users local machine, therefore keeping the tool up to date. The Java Virtual
Machine then takes care of the requirement that the program must be able to be run on multiple
operating systems. Because java is an interpreted language that is run on the virtual Java Runtime
Environment it effectively has a Middle-man interpreting any specific instructions for the users
specific operating system and computer hardware. This eliminates any hardware and Operating Systemspecific dependencies that would prevent the Linting Tool from running on a users machine. Because
both team members have experience in java, and seeing that Java handles interpretation of code
between operating systems inherently, the Java programming language was chosen for accomplishing
the tasks that needed to be met for the tools design.
The way the group approached creating the tool was to have four main pieces to the too (All are
detailed in the appendix):
1. The Verilog code parser: this element of the design takes a users input Verilog code file and
uses it to create a virtual structure of the codes behavioral blocks, variable declarations,
assignment statements, and conditional statements. This virtual structure is saved in memory
and used to identify the errors in the file.
2. The Error Searcher: this element of the design uses the virtual structure of the code created and
passed to it from the parser in order to identify the specific errors present in the users Verilog
code.
3. The User Interface: As can be seen in Figure 1, Figure 2, and Figure 3 the user interface provides
a simple layout for the tool that hides all of the background work done during the Parsing and
Error Searching sections described above.
ECE 4899
4. Using Java Web Start: Java web start was used for hosting the tool in a way that could provide
user updates without the need for the user to continue to download the tool (though they can if
they prefer to). The details for updating the tool using Java Web Start provided to the sponsor
are detailed in the corresponding appendix section, but updating the tool using Java Web Start
happens seamlessly as far as the user is concerned.
Each of these pieces were written separately from each other, and were made over the courses of the
project by taking smalls steps at a time by incrementally adding structure items to parse and slowly
building what the parser could handle to a point where it is able to identify major code blocks and
behavior constructs in the Verilog Language. Then using this parsed structure, the first several synthesis
error checking classes could be coded in order to look through the identified structures for known
synthesis errors. As new types of behavioral code constructs and aspects of the Verilog laguage were
added to the parser the errors that need to be checked from those structures were then also added. For
example, classes that searched for errors present in always blocks were written only after the parser
was able to identify and parse always blocks into the virtual code structure. New Verilog test case files
were then written to verify the tools functionality and assure the errors are identified correctly.
ECE 4899
Details of Procedure:
After the initial planning of the project between the two team members and the project advisor
the Team members separated into two distinct roles. First, both team members would build the initial
files for storage class code. Then when the initial stages of the Linting Tool were done, one team
member would work on the Verilog code parser, while the other would work on writing the functions
that would search for errors, as well as developing the user interface and Java Web Start updater for the
tool.
The first step that needed to be done during parsing was to design a way of storing all the
constructs that could show up in the Users code. A Java class hierarchy was used for the storage and
parsing of items in the Verilog code file. Then using some very basic structure files and the existing class
hierarchy a group of class files were created to parse the basic behavior blocks, variable signal types,
and assignment statement types possible in the Verilog code. As development continued subsequent
types of behavioral blocks and code constructs were added, as well as the ability to detect new errors.
The final tool includes the ability to parse the following (Each of these pieces are discussed more
thoroughly in the corresponding section of the appendix discussing the parser):
1. Behavioral Code All behavioral blocks inherit from a generic Block class:
a. Module Block
b. Always Blocks
c. Case Blocks
d. For Loops
e. Functions
f.
If-Else Blocks
ECE 4899
Task Blocks
j.
2. Variable Type Code Constructs: All Variable types inherit from a generic Variable class:
a. Reg variable
b. Wire variable
c. Task Call Instance variable
d. Function Call Instance variable
3. Assignment Statement Type Code Constructs:
a. Assignment Statements
b. Continuous assignments
c. Conditional Statements
When delays occurred or structures that werent identified were needed to be added to the
parser before the detection of more errors could take place, time from the second team member would
go into developing the GUI for the user interface as well as the JNLP file for the Java Web Start Service.
During this work automation files for building the packaged application and the JNLP Files were also
created.
Testing was done at every stage of the main engine and error searching functions. Testing
would be done by custom written Verilog test files, several that would pass and several that would fail,
to identify proper detection and structuring done by the parser and error searching functions. Also, at
the same time, backups were made of the code every three day to insure any functionality or integrity
of file problems could be rolled back to a previous date if necessary.
ECE 4899
Results
The Final Build of the tool was done on May 9, 2013 for presentation and student use. The final
tool is able to detect 17 errors as well as several parsing errors that will also be reported to the user.
The Java Web Start JNLP File is successfully built for every build of the tool, and a version number based
on the date and time ensures the version number of subsequent builds is always newer than the
previous build so that the tool will always remain up to date. A GUI was added and successfully displays
the errors that were detected, the file currently selected, and the files code with line numbers. With
interactivity, the GUI Supplies more information to the user about an error the tool has identified as well
as highlight which lines the errors are referring to.
It should be noted that the Linting Tool does not support the following aspects of Verilog code:
1. Trying to run the tool with code that does not compile correctly, the tool will give an error and
stop parsing
2. Analysis of parsed Sub-Module Instantiations
3. Analysis of parsed For loops
4. Analysis of parsed While loops:
5. Analysis of parsed Tasks
6. Analysis of parsed Functions
7. Analysis of Processor Directives
8. Parsing of Multi-Dimensional Arrays
9. Parsing of Named-Blocks
10. Parsing of ternary operators
11. Parsing of Pre-parsing parameters
ECE 4899
The team feels that this project has been a success. While the final linting tool may not handle
the same level of Verilog code analysis as other professional tools, our linting tool successfully does
what it was intended to do by providing undergraduate UCCS students who are just starting to learn
Verilog a solid resource that they can go to in order to check the synthesizability of their Verilog code.
ECE 4899
8. Providing the sponsor with information on how to update the tool to include new errors, this
aspect was planned for in advance so the linting tool also provides:
a. A Java class template for writing new errors
b. Information on how to integrate the new error into the linting tool after it is written
i. This was made as simple as possible, the sponsor should only need to include
the new class file into the project, and then add a single line to the
ErrorSearcher class calling an instance of that class, and passing it the parsed
virtual Verilog structure.
c. Information on how to build the new executable JAR file, and load it to the host website
Not every aspect of the Verilog Hardware Description Language is capable of begin run through
the tool (as evidence by the list of unsupported Verilog code constructs provided in the Results section
of this document), however the Verilog omissions that were made to the tool are relatively few and
furthermore several of them are more advanced Verilog concepts that fall outside of the scope the
tools intended use for students just beginning to learn the Verilog Hardware Description Language.
As for the Schedule, the originally planned schedule was not followed completely, but instead
the problems with bugs in the parser or unsupported constructs pushed some errors out while others
were done on time. The final schedule, in figure 4, below shows the final outcome of delays and bug
10
ECE 4899
fixes.
This final schedule show where delays were and how the errors were mainly programmed in at the end
of the allotted time. If more knowledge was known about what to expect about the files that the users
were going to run through the machine then there may not have been as many bugs or changes to the
parser. This would have been a better outcome, but as it stands the parser and GUI came out in a
respectable format for the user.
11
ECE 4899
Appendix
User Interface
The User Interface: As can be seen in Figure 1, Figure 2, and Figure 3 the user interface provides a simple
layout for the tool that hides all of the background work done during the Parsing and Error Searching
sections described above. The user is provided with:
a. Three windows detailing information:
i. Files Open: Shows all of the Verilog code files that have been linted, if multiple
files have been loaded the user can click on the names of the files presented in
this window in order to change which Verilog code file data is displayed in the
File Data and Error Messages windows
ii. File Data: Displays the users code:
1.
2. It highlights lines with errors in red when the user left-clicks on an error
in the Error Messages window
iii. Error Messages: Displays a list of the errors found in the Verilog file
1. If no errors are present then this window displays No Errors Detected
2. If the user Left-Clicks on an error the line numbers causing the error are
highlighted in the File Data window (As shown in Figure 2)
3. If the user Right-Clicks on an error then more detailed information
about the error is displayed for the user (An example of this is shown in
Figure 3)
b.
Two buttons:
12
ECE 4899
13
ECE 4899
14
ECE 4899
Figure 3: An example of the user documentation giving an in-depth description of the error in question,
a code example of the error, and a description of what can be done to fix the error.
15
ECE 4899
2. Behavioral Code blocks (note that a hierarchical diagram of these Block classes can be
seen in appendix Figure 2): All behavioral blocks inherit from a generic Block class that
includes the following functional pieces:
a. The data members responsible for identifying:
i.
16
ECE 4899
3. Variable Type Code Constructs: All Variable types inherit from a generic Variable class with
the following functional pieces:
a. Data members responsible for storing
i. Variable Name
ii. Variable type
iii. Variable Attributes
iv. Line Number of Declaration
v. Array Size
17
ECE 4899
4. Assignment Statement Type Code Constructs: Generic assignment statements are handled
by the AssignmentStatement class, with conditional statements and continuous
assignment statements inheriting from the AssignmentStatement class.
a. The AssignmentStatement class has data members responsible for the following:
i. Variables present on the Left Hand Side of the assignment statement
ii. Variables present on the Right Hand Side of the assignment statement
iii. A reference to the parent block that contains the assignment stamen
iv. The Line Number that the assignment statement occurs on
b. The AssignmentStatement class has methods responsible for the following:
i. Identifying variables on the Left Hand Side of the assignment statement
ii. Identifying variables on the Right Hand Side of the assignment statement
iii. Returning information about the assignment statement
18
ECE 4899
User Guide For Running the Linting Tool for the First Time
(Note: These instructions have been made available by the sponsor on his web page for the linting tool,
it is presented here as the user will see it, any changes in the formatting of this document that may be
seen is for this reason.)
2. Make sure "Open with Java(TM) Web Start Launcher" is selected then press the "OK" button
19
ECE 4899
20
ECE 4899
4. You will see this Loading Screen if Java has Launched correctly
5. When the Security Warning pops up make sure to check the "I accept the risk and want to run this
application" check box, then click on the "Show Options" button
6. On the expanded window check the "Do not show this again for apps from the publisher and location
above" check box, then click on the "Run" button
21
ECE 4899
22
ECE 4899
23
ECE 4899
i.
ii. Make Note of the password you used.
b. Follow the on screen instructions
4. Edit Sign Jar.bat
a. Change the *Insert Your Password Here* with your password in part 3
5. Try Running Command Line Variable Add
a. If you see the prompt information below
24
ECE 4899
i.
ii. Go to Step 6.
b. Else
i. You need to get the default java installation path
1. Usually found at C:\Program Files\Java
2. Verify a Java Development Kit Is installed.
a. Folder Usually call jdk1.7.0_xx
b. If not installed
i. Install a Java JDK
ii. Start step 5 over
3. If it is there then environmental variables will need to be manually set
a. Take note of the Java JDK Folder Location
b. In start menu search Enviro
c. You should see the picture below
d.
e. Click the Edit enviroment variables for your account
25
ECE 4899
26
ECE 4899
Optional Move where the default location of the LintingTool.jar and LintingTool_WebStart.jnlp is placed
1. Edit Create Jar and Sign.bat
a. Locate the lines that contain move instructions.
b. Replace the second argument in quotes with the location you want it to copy to.
c. Example
i. Original
1. "%cdir%\Compiled\LintingTool.jar"
2. "%cdir%\Compiled\LintingTool_WebStart.jnlp"
ii. Changed
1. C:\Program Files\LintingTool.jar"
2. C:\Program Files\LintingTool_WebStart.jnlp"
Note: For Security Reasons make sure the bats are not accessible from the web.
JNLP Syntax Availible From Here:
http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/synta
x.html
27
ECE 4899
import java.util.ArrayList;
public class Always extends Block{
private ArrayList<Variable> sensitivityList;
/*"alwaysBlockOrder" preserves the structureal order of statements and
* subBlocks in and always block.
* 0 - indicates an assignment statement,
* 1- indicates the presence of another subBlock
*/
28
ECE 4899
parent = comesFrom;
LineNumber = Parser.currentLineNumber;
}
&&
!temp.equals("##END_OF_MODULE_CODE");
&&
!temp.equals("##END_OF_MODULE_CODE");
29
temp
ECE 4899
}
else{
if(!temp.equals("always")){
parser.checkForNewBlock(always, temp);
if(!temp.equals("$#")) //this one
always.alwaysBlockOrder.add(new Integer(1));
}
else{
String errorText = "Error: nested always blocks not allowed";
parser.addErrorToParserErrorList(new
Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
}
}else{
if(temp.equals("$#")){
parser.checkForNewBlock(always, temp);
30
ECE 4899
temp = parser.getNextPiece();
}
if(!parser.pieceIsKeyword(temp) && parser.checkTaskOrFunctionName(temp)==0){
for(;
!temp.equals(";")
parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
temp
ECE 4899
}
else{
String errorText = "Error: nested always blocks not allowed";
parser.addErrorToParserErrorList(new Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
}
return temp;
}
private void parseAlwaysHead(Parser parser){
statementText = "always";
String temp = parser.getNextPiece(); //temp will equal "@"
if(!temp.equals("@")){
parser.stopParsing();
return;
}
statementText += (" "+temp);
Variable tempVar; Reg tempReg; Wire tempWire;
temp = parser.getNextPiece(); //temp will equal "(" or "*"
statementText += (" "+temp);
if(temp.equals("*")){ //if the sensitivities are not explicitely specified
//
sensitivityList.add(new Variable("*",""));
BlockType = "levelSensitive";
}else if(temp.equals("(")){ //if temp == "("
temp = parser.getNextPiece(); //temp will equal the first item of interrest
statementText += (" "+temp);
32
ECE 4899
sensitivityList.add(new Variable("*",""));
BlockType = "levelSensitive";
}
else if(temp.equals("posedge")){
if(!(BlockType.equals("") || BlockType.equals("edgeSensitive")) ){
addError12MixedSensitivityInAlwaysBlock(parser);
//
return;
}
BlockType = "edgeSensitive";
temp = parser.getNextPiece(); statementText+=(" "+temp);
tempVar = this.findVariableInParentBlockHierarchy(temp);
if(tempVar != null){
if(tempVar.arraySize > 1){ // if the variable in question is an array
addError10VectorOrArrayInSensList(temp, parser);
}
else
if(!tempVar.getEdgeSensitivity().equals("negedge")
!tempVar.getEdgeSensitivity().equals("levelSensitive")){
tempVar.setEdgeSensitivity("posedge");
sensitivityList.add(tempVar);
}else{
addError17MixedSensitivityOfAVariable(parser, tempVar.name);
}
33
&&
ECE 4899
vector
addError10VectorOrArrayInSensList(temp, parser);
}
else{
parser.addInstanceOfError8UndeclaredSignal(temp);
}
}
else if(temp.equals("negedge")){
if(!(BlockType.equals("") || BlockType.equals("edgeSensitive")) ){
addError12MixedSensitivityInAlwaysBlock(parser);
//
return;
}
BlockType = "edgeSensitive";
temp = parser.getNextPiece(); statementText+=(" "+temp);
tempVar = this.findVariableInParentBlockHierarchy(temp);
if(tempVar != null){
if(tempVar.arraySize > 1){ // if the variable in question is an array
addError10VectorOrArrayInSensList(temp, parser);
}
else
if(!tempVar.getEdgeSensitivity().equals("posedge")
!tempVar.getEdgeSensitivity().equals("levelSensitive")){
tempVar.setEdgeSensitivity("posedge");
sensitivityList.add(tempVar);
}else{
addError17MixedSensitivityOfAVariable(parser, tempVar.name);
}
34
&&
ECE 4899
vector
addError10VectorOrArrayInSensList(temp, parser);
}
else{
parser.addInstanceOfError8UndeclaredSignal(temp);
}
}
else if(temp.equals("or") || temp.equals(","));
else{
if(!(BlockType.equals("") || BlockType.equals("levelSensitive")) ){
addError12MixedSensitivityInAlwaysBlock(parser);
//
return;
}
BlockType = "levelSensitive";
tempVar = this.findVariableInParentBlockHierarchy(temp);
if(tempVar != null){
if(tempVar.arraySize > 1){ // if the variable in question is an array
addError10VectorOrArrayInSensList(temp, parser);
}
else
if(!tempVar.getEdgeSensitivity().equals("posedge")
!tempVar.getEdgeSensitivity().equals("negedge")){
tempVar.setEdgeSensitivity("levelSensitive");
sensitivityList.add(tempVar);
}else{
addError17MixedSensitivityOfAVariable(parser, tempVar.name);
}
35
&&
ECE 4899
vector
//addErrorVectorArrayInSensList(temp, parser);
Variable.safelyParseVariableFromLine(parser, this, temp,
sensitivityList,sensitivityList);
}
else{
parser.addInstanceOfError8UndeclaredSignal(temp);
}
}
}
}else {
parser.addInstanceOfError18UnexpectedToken(temp);
parser.stopParsing();
return;
}
}
public void addToAlwaysBlockOrder(int num){
this.alwaysBlockOrder.add(num);
}
public int getFromAlwaysBlockOrder(int index){
if(index< alwaysBlockOrder.size() && index>=0){
return this.alwaysBlockOrder.get(index);
}else{
return this.alwaysBlockOrder.get(0);
}
}
public String getAlwaysStatement(){
36
ECE 4899
return statementText;
}
public ArrayList<Variable> getSensitivityList()
{
return sensitivityList;
}
private void addError10VectorOrArrayInSensList(String varName, Parser parser){
String errorOutput = "Error: Vector or Array detected in Edge-Sensitive Always Block sensitivity
list,\n"
+ "\tor an Array variable was detected in a Level-Sensitive Always Block sensitivity list:\n";
errorOutput += "\t Variable ( "+varName+" ) in always on line : "+this.LineNumber+" Variable Name:
";
parser.addErrorToParserErrorList(new Error("10",errorOutput,this.LineNumber));
}
private void addError12MixedSensitivityInAlwaysBlock(Parser parser){
String errorOutput = "Error: Mixing of Level and Edge Sensitivity detected in Always Block :\n";
errorOutput += "\tin always on line : "+this.LineNumber+"\n";
parser.addErrorToParserErrorList(new Error("12",errorOutput,this.LineNumber));
}
private void addError17MixedSensitivityOfAVariable(Parser parser, String var){
String errorOutput = "Error: Mixing of Level and Edge Sensitivity detected:\n";
errorOutput += "\t variable ( "+var+" ) is used in both edge-sensitive and level-sensitive always
blocks"
+ "\n first use of mixed type occued in always on line: "+this.LineNumber;
parser.addErrorToParserErrorList(new Error("17",errorOutput,this.LineNumber));
}
@Override
public String toString(){
int i = 0; int subBlockCount=0; int assignmentStatementCount=0; int taskCallCount=0;
37
ECE 4899
ECE 4899
}
}
temp += "end //end always\n";
return temp;
}
39
ECE 4899
AssignmentStatement.java
package TestMain;
import java.util.ArrayList;
identifyLHSvariables(parser);
}
AssignmentStatement(String rawText, Block blockSource, Parser parser){
40
ECE 4899
assignmentText = rawText;
LHSvars = new ArrayList();
RHSvars = new ArrayList();
parent = blockSource;
LineNumber = Parser.currentLineNumber;
System.out.println(LineNumber);
identifyLHSvariables(parser);
identifyRHSvariables(parser);
}
LHSvars.add(tempVar);
temp = Variable.safelyParseVariableForAssignmentStatement(
parser, parent, this,temp, LHSvars,RHSvars);
41
ECE 4899
}else if(parent.findVectorNameInParentBlockHierarchy(temp).size()>0){
//
LHSvars.addAll(parent.findVectorNameInParentBlockHierarchy(temp));
temp=Variable.safelyParseVariableForAssignmentStatement(
parser, parent, this,temp, LHSvars,RHSvars);
}else{
}
}
if(!temp.equals("=")){
temp=getNextPiece();
}
}
assignmentText = preserve;
}
protected void identifyRHSvariables(Parser parser){
String preserve = assignmentText;
assignmentText = assignmentText.substring(assignmentText.indexOf("="));
String temp = getNextPiece();
Variable tempVar=null;
for(temp=getNextPiece(); !temp.equals("##END_OF_STATEMENT"); ){
if(temp.equals("$#")){
temp=getNextPiece();
parser.setLineNumber(Integer.parseInt(temp));
}
else {
tempVar = parent.findVariableInParentBlockHierarchy(temp);
if(tempVar != null){
42
ECE 4899
//
LHSvars.add(tempVar);
Variable.safelyParseVariableForAssignmentStatement(
parser, parent, this,temp, RHSvars,RHSvars);
}else if(parent.findVectorNameInParentBlockHierarchy(temp).size()>0){
//
LHSvars.addAll(parent.findVectorNameInParentBlockHierarchy(temp));
Variable.safelyParseVariableForAssignmentStatement(
parser, parent, this,temp, RHSvars,RHSvars);
}else{
}
}
if(!temp.equals("$#")){
temp=getNextPiece();
}
}
assignmentText = preserve;
}
ECE 4899
piece[0] = "##END_OF_STATEMENT";
}
}
return piece[0];
}
ECE 4899
}else if(piece.equals("^")){
return true;
}else if(piece.equals("%")){
return true;
}else if(piece.equals("*")){
return true;
}else if(piece.equals("+")){
return true;
}else if(piece.equals("-")){
return true;
}else if(piece.equals("/")){
return true;
}else if(piece.equals("(")){
return true;
}else if(piece.equals(")")){
return true;
}else if(piece.equals("[")){
return true;
}else if(piece.equals("]")){
return true;
}else if(piece.equals("<")){
return true;
}else if(piece.equals(">")){
return true;
}else{
return false;
}
}
45
ECE 4899
@Override
public String toString(){
String text = "";
text += assignmentText + ";\\\\ ";
text += "LHSvars: "+LHSvars.toString();
text += ", RHSvars: "+RHSvars.toString()+" LINE: "+LineNumber+"\n";
return text;
}
}
46
ECE 4899
Block.java
package TestMain;
import java.util.ArrayList;
Block(){
BlockType = "";
BlockName = "";
vars = new ArrayList();
subBlocks = new ArrayList();
assignments = new ArrayList();
LineNumber = Parser.currentLineNumber;
}
Block(String type, Block comesFrom){
BlockType = type;
BlockName = "";
vars = new ArrayList();
47
ECE 4899
sortVariables();
}
public void addSubBlock(Block newSubBlock){
subBlocks.add(newSubBlock);
}
public void addAssignment(AssignmentStatement newAssignment){
assignments.add(newAssignment);
}
ECE 4899
&&
ECE 4899
ECE 4899
@Override
51
ECE 4899
return retVar;
}
}
52
ECE 4899
Case.java
package TestMain;
import java.util.ArrayList;
Block(){
BlockType = "";
BlockName = "";
vars = new ArrayList();
subBlocks = new ArrayList();
assignments = new ArrayList();
LineNumber = Parser.currentLineNumber;
}
Block(String type, Block comesFrom){
BlockType = type;
BlockName = "";
vars = new ArrayList();
subBlocks = new ArrayList();
53
ECE 4899
sortVariables();
}
public void addSubBlock(Block newSubBlock){
subBlocks.add(newSubBlock);
}
public void addAssignment(AssignmentStatement newAssignment){
assignments.add(newAssignment);
}
ECE 4899
&&
ECE 4899
56
ECE 4899
@Override
public String toString(){
57
ECE 4899
int i=0;
String retVar = BlockType + " " + BlockName + " ";
return retVar;
}
}
58
ECE 4899
ConditionStatement.java
package TestMain;
import java.util.ArrayList;
identifyConditionVariables(parser);
}
ECE 4899
//
temp = Variable.safelyParseVariableForAssignmentStatement(
parser, parent, this,temp, conditionVars,conditionVars);
}else {
//
conditionVars.addAll(parent.findVectorNameInParentBlockHierarchy(temp));
//
temp = Variable.safelyParseVariableForAssignmentStatement(
//
@Override
public String toString(){
return assignmentText + "";
}
60
ECE 4899
ContinuousAssignment.java
package TestMain;
import java.util.ArrayList;
identifyLHSvariables(parser);
identifyRHSvariables(parser);
}
/*
@Override
protected void identifyLHSvariables(Parser parser){
String preserve = assignmentText;
String temp = super.getNextPiece();
Variable tempVar=null;
for(; !temp.equals("="); temp=super.getNextPiece()){
if( !super.expressionPiece(temp) ){
tempVar = parent.findVariableInParentBlockHierarchy(temp);
if(tempVar != null){
LHSvars.add(tempVar);
}
61
ECE 4899
}
}
assignmentText = preserve;
}
@Override
protected void identifyRHSvariables(Parser parser){
String preserve = assignmentText;
assignmentText = assignmentText.substring(assignmentText.indexOf("="));
String temp;
for(temp=getNextPiece(); !temp.equals("##END_OF_STATEMENT"); temp=getNextPiece()){
if( parent.findVariableInParentBlockHierarchy(temp) != null){
RHSvars.add(parent.findVariableInParentBlockHierarchy(temp));
}else {
RHSvars.addAll(parent.findVectorNameInParentBlockHierarchy(temp));
}
}
assignmentText = preserve;
}
*/
@Override
public String toString(){
String text = "";
text += "assign " + assignmentText + ";\\\\ ";
text += "LHSvars: "+LHSvars.toString();
text += ", RHSvars: "+RHSvars.toString()+" LINE: "+LineNumber+"\n";
return text;
}
}
62
ECE 4899
DocumentationGUI.java
package TestMain;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.text.DefaultEditorKit;
import sun.security.krb5.internal.crypto.Des;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deathwarror
*/
public class DocumentationGui extends javax.swing.JDialog {
63
ECE 4899
/**
* Creates new form DocumentationGui
*/
public DocumentationGui(java.awt.Frame parent, boolean modal,String ErrorNumber ,String
DURL,String DType,String DDType) {
super(parent, modal);
initComponents();
ECE 4899
this.setSize(new Dimension(ScreenWidth,ScreenHeight));
this.setLocation((int)((dim.width-ScreenWidth)/2),(int)((dim.height-ScreenHeight)/2));
this.setSize(new Dimension((int)(ScreenWidth*.9-200),(int)(ScreenHeight*.9-30)));
this.setVisible(true);
}
//try loading the txt version of he description
catch(Exception e)
{
e.printStackTrace();
Description = EDL2.load(ErrorNumber);
JOptionPane.showMessageDialog(new
JFrame(),
ErrorNumber),JOptionPane.INFORMATION_MESSAGE );
Description,("Error:
this.dispose();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
65
"+
ECE 4899
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
CloseButton.setText("OK");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
JSP.setViewportView(DocumentationField);
ErrorName.setText("jLabel1");
ECE 4899
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(ErrorName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(JSP, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CloseButton)
.addGap(7, 7, 7))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
67
ECE 4899
68
ECE 4899
Error.java
package TestMain;
* Status: UPDATE
* Updated by Danny on 2/24/2013
*/
import java.util.ArrayList;
Error()
{
ErrorMsg = "";
ErrorNumber = "";
LineNumbers = new ArrayList();
69
ECE 4899
ECE 4899
return LineNumbers;
}
//Returns the Error Number;
public String getErrorNum()
{
return ErrorNumber;
}
ECE 4899
{
ErrorNumber = e;
}
//allows the error message to be set afterwards
public void setErrorMsg(String msg)
{
ErrorMsg = msg;
}
72
ECE 4899
Error01_05_07IdentifyClockErrors.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.100
* Function:
*
detects any always blocks that a for flip flops and searches to see if they
then detect to see if there is an unused signal for the clock and then
checks to see if there is more than one unused signal making the block
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
ECE 4899
Variable currentVar;
Block currentBlock;
ConditionStatement currentStatement;
ArrayList<Variable> Clocks = new ArrayList();
ArrayList<Variable> SensList;
ArrayList<Integer> LineNumbers = new ArrayList();
ECE 4899
ECE 4899
//if there was more than one unused signal in the sensitivity list
else if(SensList.size()>1)
{
Error e = new Error();
e.setErrorNum("07");
errorOutput = "Multiple Clocks or unused signals detected in always block:\n";
errorOutput += "\tin always on line : "+currentBlock.LineNumber;
e.addLineNumber(currentBlock.LineNumber);
e.setErrorMsg(errorOutput);
System.out.println(errorOutput + "\n");
ErrorList.add(e);
76
ECE 4899
}
}
}
"\tFirst
Clock:
e.setErrorMsg(errorOutput);
e.addLineNumber(LineNumbers.get(0));
77
"+currentVar.getName()+"\n\tSecond
Clock:
ECE 4899
e.addLineNumber(LineNumbers.get(i));
System.out.println(errorOutput + "\n");
ErrorList.add(e);
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No Problems with clock or reset detected in ClockErrors\n");
}
return ErrorList;
}
}
78
ECE 4899
Error03IdentifyAssignmentVsSensType.java
/**
* @Author:
* @Date:
Kenneth Hassey
1/7/2013
* @Version: 1.000
* Function:
*
This File is for verification of correct blocking and non blocking statements
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
ECE 4899
String SensType;
//Go through the list of blocks
for(int i = 0;i<blocks.size();i++)
{
//get the current block
currentBlock = blocks.get(i);
ECE 4899
"\n\tLine
}
//if a nonblocking in a combination block was detected
if(error == 2)
{
errorOutput = "Detected a Combinational Always Block with a NonBlocking Statement:\n";
errorOutput += "\tin always on line "+currentBlock.LineNumber+":";
errorOutput
+=
"+statements.get(j).LineNumber+":\t"+statements.get(j).assignmentText+";\n";
81
"\n\tLine
ECE 4899
if(errorOutput.equals("NE"))
{
System.out.println("No improper use of blocking and non blocking detected!\n");
return ErrorList;
}
else
{
return ErrorList;
}
}
}
82
ECE 4899
Error06IdientifyMultiplyDrivenSignals.java
package TestMain;
import java.util.ArrayList;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deathwarror
*/
public class Error06IdentifyMultiplyDrivenSignals {
public static ArrayList<Error> getErrors(Parser parser){
ArrayList<Error> ErrorList = new ArrayList();
String errorOutput="Error: Multiply Driven Signals were detected in the following lines of code:\n";
ArrayList<String> tempString;
ArrayList<Variable> vars = parser.getVariableList();
ArrayList<Block> blocks = parser.getBlockList();
ArrayList<AssignmentStatement> statements;
ArrayList<Integer> lineNumbers = new ArrayList();
ArrayList<Integer> tempLineNumbers = new ArrayList();
Variable currentVar = null;
Block currentBlock = null;
AssignmentStatement currentStatement = null;
83
ECE 4899
";
(line:
);
tempLineNumbers.add(currentStatement.getAssignmentStatementLineNumber());
break;
}
84
ECE 4899
}
}
j<blocks.size();
j++,
tempString=new
ArrayList(),
currentBlock=blocks.get(j);
if(currentBlock.getClass() == Module.class){
//Should retrive all assignment statements in the module
//but not in module subBlocks
statements = currentBlock.getBlockAssignmentStatements();
for(k=0; k<statements.size(); k++){
currentStatement=statements.get(k);
if(currentStatement.getLHSvars().indexOf( currentVar) != -1 ){
tempString.add(
"Continuous Assignment: assign"
+currentStatement.assignmentText
+ "; (line: "+ currentStatement.getAssignmentStatementLineNumber() +")\n"
);
tempLineNumbers.add(currentStatement.getAssignmentStatementLineNumber());
85
ECE 4899
}
}
}
}
86
ECE 4899
Error09a_09bIdentifyIncompleteSensList.java
package TestMain;
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.000
* Function:
*
Finds sensitivity lists that have unused variables or ports and also
*
* Status: Tested Working;
*/
import java.util.ArrayList;
ECE 4899
Block currentBlock;
AssignmentStatement currentStatement;
ArrayList<Variable> SensList;
ArrayList<Variable> OrigSensList;
ArrayList<Variable> UsedVars;
statements=currentBlock.getAllAssignmentStatements();
//
ECE 4899
ECE 4899
ArrayList<Variable> vl;
vl = ((Case)(caseBlock.get(j))).getCondition().conditionVars;
for(int l = 0; l <vl.size(); l++)
{
currentVar = vl.get(l);
ECE 4899
ECE 4899
are not:\n";
errorOutput += "\tin always on line : "+currentBlock.LineNumber +"\n\tUsed Variable(s)
not present in sensitivity list: ";
e.addLineNumber(currentBlock.LineNumber);
//add the unused Vars
for(int varCount = 0;varCount <(UsedVars.size()-1);varCount++)
{
errorOutput+= UsedVars.get(varCount).getName()+", ";
}
errorOutput+=UsedVars.get(UsedVars.size()-1).getName();
System.out.println(errorOutput+"\n");
e.setErrorMsg(errorOutput);
ErrorList.add(e);
}
92
ECE 4899
errorOutput = "Signal(s) present in sensitivity list that are not used as inputs to
combinatorial logic modeled in always block:\n";
errorOutput += "\tin always on line : "+currentBlock.LineNumber +"\n\tUnused Variable(s)
in sensitivity list: ";
e.addLineNumber(currentBlock.LineNumber);
for(int varCount = 0;varCount <(SensList.size()-1);varCount++)
{
errorOutput+= SensList.get(varCount).getName()+", ";
}
errorOutput+=SensList.get(SensList.size()-1).getName();
System.out.println(errorOutput+"\n");
e.setErrorMsg(errorOutput);
ErrorList.add(e);
}
}
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No Error Detected in Incomplete Sensitivity List\n");
}
return ErrorList;
}
}
93
ECE 4899
Error10vectorArrayInSensList.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.000
* Function:
*
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Deathwarror
*/
public class Error10VectorArrayInSensList {
public static ArrayList<Error> getErrors(Parser parser)
{
ArrayList<Error> ErrorList = new ArrayList();
ECE 4899
for(int i = 0;i<Variables.size();i++)
{
//get go through the list and find variables that have a vector parent
if(!(Variables.get(i).vectorParentName.equals("")))
{
int add = 1;
for(int j = 0; j<VectorNames.size();j++)
{
//if the vector name is in the list flag the add variable to don't add
if((VectorNames.get(j).equals(Variables.get(i).vectorParentName)))
{
add = 0;
}
}
//if the vector name wasn't found in the list
if(add == 1)
{
//add it to the list of VectorNames
VectorNames.add(Variables.get(i).vectorParentName);
}
}
}
//go through the list of blocks
95
ECE 4899
if(currentBlock.BlockType.equals("edgeSensitive"))
{
int ignore = 0;
for(int j = 0; j < VectorNames.size();j++)
{
currentVar = VectorNames.get(j);
ECE 4899
";
errorOutput += currentVar;
e.addLineNumber(currentBlock.LineNumber);
System.out.println(errorOutput+"\n");
e.setErrorMsg(errorOutput);
ErrorList.add(e);
}
}
}
}//end of level sensitive check
}
}
if(errorOutput.equals("No Error"))
{
97
ECE 4899
return ErrorList;
}
}
98
ECE 4899
Error11LogicalNotWithVector.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.001
* Function:
*
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
ECE 4899
for(int i = 0;i<Variables.size();i++)
{
//get go through the list and find variables that have a vector parent
if(!(Variables.get(i).vectorParentName.equals("")))
{
int add = 1;
for(int j = 0; j<VectorNames.size();j++)
{
//if the vector name is in the list flag the add variable to don't add
if((VectorNames.get(j).equals(Variables.get(i).vectorParentName)))
{
add = 0;
}
}
//if the vector name wasn't found in the list
if(add == 1)
{
//add it to the list of VectorNames
VectorNames.add(Variables.get(i).vectorParentName);
}
}
}
if(blocks.size()>0)
{
//get the top block
currentBlock = blocks.get(0);
100
ECE 4899
//get the assignment text and add a space for missing end character
currentStatement = As.get(j).assignmentText+" ";
for(int k = 0; k<VectorNames.size();k++)
{
ECE 4899
102
ECE 4899
operator:\n";
errorOutput += "\tin always on line : "+As.get(j).LineNumber+"\n\tVariable
Name: ";
errorOutput += currentVar;
e.addLineNumber(As.get(j).LineNumber);
System.out.println(errorOutput+"\n");
e.setErrorMsg(errorOutput);
ErrorList.add(e);
}
}
}
}
}
}
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No Errors Detected In LogicaNotWithVector\n");
}
return ErrorList;
}
}
103
ECE 4899
Error13IdentifyOperatorInSensList.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.010
* Function:
*
always block
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
ECE 4899
for(int i = 0;i<blocks.size();i++)
{
//get the current block
currentBlock = blocks.get(i);
ECE 4899
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "&";
else
CharactersIdentified += ", &";
}
if(AlwaysStatement.contains("*"))
{
if(((Always)currentBlock).getSensitivityList().size()>0)
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "*";
else
CharactersIdentified += ", *";
}
}
if(AlwaysStatement.contains("/"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "/";
else
CharactersIdentified += ", /";
}
if(AlwaysStatement.contains("+"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "+";
else
106
ECE 4899
}
if(AlwaysStatement.contains("-"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "-";
else
CharactersIdentified += ", -";
}
if(AlwaysStatement.contains("%"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "%";
else
CharactersIdentified += ", %";
}
if(AlwaysStatement.contains("!"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "!";
else
CharactersIdentified += ", ";
}
if(AlwaysStatement.contains("<"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "<";
else
107
ECE 4899
}
if(AlwaysStatement.contains(">"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += ">";
else
CharactersIdentified += ", >";
}
if(AlwaysStatement.contains("^"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "^";
else
CharactersIdentified += ", ^";
}
if(AlwaysStatement.contains("~"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "~";
else
CharactersIdentified += ", ~";
}
if(AlwaysStatement.contains("?"))
{
if(CharactersIdentified.equals(""))
CharactersIdentified += "?";
else
108
ECE 4899
if(!(CharactersIdentified.equals("")))
{
errorOutput = "Detected Mathametical or Logical operator in the Sensitivity List:\n";
errorOutput += "\tin always on line "+currentBlock.LineNumber+": \n\t Character List:
"+CharactersIdentified;
errorOutput
+=
"+currentBlock.LineNumber+":\t"+((Always)currentBlock).getAlwaysStatement()+";\n";
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No Operators In Sensitivity List!\n");
109
"\n\tLine
ECE 4899
return ErrorList;
}
else
{
return ErrorList;
}
}
110
ECE 4899
Error14IdentifyBackwardDrivenPortDirection.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.010
* Function:
*
this flags for any calculations that are using output ports and
*
* Status: Tested Working;
*
*/
package TestMain;
import java.util.ArrayList;
111
ECE 4899
if(!blocks.isEmpty()){
//get the top block
currentBlock = blocks.get(0);
ECE 4899
errorOutput
+=
"+statements.get(j).LineNumber+":\t"+statements.get(j).assignmentText+";\n";
"\n\tLine
//label the input side as already been flagged so that multiply errors arent listed
lineFlagged = 1;
}
}
lineFlagged = 0;
//Look For an output being used in a calculation or right side of assignment
RHSVList = statements.get(j).getRHSvars();
for(int k = 0; k < RHSVList.size();k++)
{
outputVar = RHSVList.get(k);
if(outputVar.variableAttribute.equals("output") &&lineFlagged ==0
&& outputVar.getClass()!= Reg.class)
{
errorOutput = "Detected output being being used in Right Side of equation:\n";
errorOutput += "\tin always on line "+currentBlock.LineNumber+": \n\t Variable:
"+RHSVList.get(k).name;
113
ECE 4899
errorOutput
+=
"+statements.get(j).LineNumber+":\t"+statements.get(j).assignmentText+";\n";
"\n\tLine
//label the operation side as already been flagged so that multiply errors arent listed
lineFlagged = 1;
}
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No Improper used ports!\n");
return ErrorList;
}
else
{
return ErrorList;
}
}
114
ECE 4899
return ErrorList;
}
}
115
ECE 4899
Error15IdentifyBlockingNonBlocking.java
/**
* @Author:
* @Date:
Kenneth Hassey
5/8/2013
* @Version: 1.001
* Function:
*
This File is for detection of blocking and non blocking statements used
*
* Status: Tested Working;
*/
package TestMain;
import java.util.ArrayList;
ECE 4899
ECE 4899
//verify that it is a blocking line by making sure there is not a non blocking symbol at
the start
if (currentStatement.assignmentText.charAt(index-2) != '<'&&blockFlagged == 0)
{
+=
errorOutput
"\t"+statements.get(k).LineNumber+":\t"+statements.get(k).assignmentText+";\n";
+=
//label the block as already been flagged so that multiply errors arent listed
blockFlagged = 1;
}
}
118
ECE 4899
}
}
}
if(errorOutput.equals("No Error"))
{
System.out.println("No NonBlocking with Blocking assignments Detected!\n");
return ErrorList;
}
else
{
return ErrorList;
}
}
119
ECE 4899
Error16IdentifyLatches.java
package TestMain;
import java.util.ArrayList;
assignments
ECE 4899
ArrayList<Variable>tempVars=LHSvars;
LHSvars = new ArrayList();
//This loop makes sure that each unique variable in the always block
// is only checked once
for(int j=0; j<tempVars.size();j++){
if(!LHSvars.contains(tempVars.get(j)) ){
LHSvars.add(tempVars.get(j) );
}
}
checkIfStatements(alwaysBlocks.get(i),errorList);
for(int j=0;j<LHSvars.size();j++){
ArrayList<Error> blockErrors = new ArrayList();
checkSubBlocks(LHSvars.get(j),alwaysBlocks.get(i), blockErrors);
if(!blockErrors.isEmpty()){
String text = "\tError: "+
"variable
("+LHSvars.get(j).name+")
("+alwaysBlocks.get(i).LineNumber+") is a latch,\n"
in
always
block
on
line
return errorList;
}
121
ECE 4899
ECE 4899
}
}
}
if(ifFlag != 0){
list.add(error16MissingElse(block));
}
for(int i=0; i<block.subBlocks.size(); i++){
checkIfStatements(block.subBlocks.get(i), list);
}
return;
}
private static Error error16MissingAssignments(Variable var, Block block){
String text = "\tSub-Error:\n"+
"variable ("+var.name+") not assigned in block on line ("+block.LineNumber+")";
Error err = new Error("16",text, block.LineNumber);
return err;
}
private static Error error16MissingElse(Block block){
String text = "\tError: Laches present\n"+
"\"if\" without corresponding \"else\" in block on line ("+block.LineNumber+")";
Error err = new Error("16",text, block.LineNumber);
return err;
}
}
123
ECE 4899
ErrorDocumentationLoader.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
/*
* @author: Kenenth Hassey
* @date: 1/23/2013
* @Version: 1.000;
* Function: Reads in the database from the git hub url
* Status: Tested Will need to be tested again
*/
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
ECE 4899
{
baseURL = burl;
Format = format;
try{
DocumentationURL = new URL(baseURL);
inStream = new InputStreamReader(DocumentationURL.openStream());
in = new BufferedReader(inStream);
}
catch(Exception e)
{
System.out.println("Documentation Url Streams failed to open.");
}
}
public String getURL(String Number)
{
return baseURL+Number+Format;
}
//trys reading in the database
public String load(String Number)
{
String ed = "";
String ReadLine;
try{
DocumentationURL = new URL(baseURL+Number+Format);
//open the error file
inStream = new InputStreamReader(DocumentationURL.openStream());
in = new BufferedReader(inStream);
}
125
ECE 4899
catch(Exception E)
{
return "Could not get the Documentation for error "
+ Number + ":\nThe page failed to load\n"
+ "\tThis could be caused by no internet connection or \n"
+ "\tthe webpage that holds the information is down.\n"
+ "Documentation Web Address: \n\t"+baseURL+Number+Format+"\n";
}
try{
ReadLine = in.readLine();
while(ReadLine!= null)
{
ed +=ReadLine+"\n";
ReadLine = in.readLine();
}
}
catch(Exception E)
{
return "Something Went wrong while reading the file of error "
+ Number +":\n The reading of the file was unsuccessful.\n"
+ "\tThis could be caused by an unstable internet connection.\n"
+ "Documentation Web Address: \n\t"+baseURL+Number+Format+"\n";
}
return ed;
}
}
126
ECE 4899
ErrorSearcher.java
package TestMain;
import java.util.ArrayList;
*/
public class ErrorSearcher {
ArrayList<Error> EL;
ErrorSearcher()
{
EL = new ArrayList();
}
public ArrayList<Error> Start(Parser parser)
{
ClearErrorList();
merge(parser.getParserErrorList());
if(EL.isEmpty()){
merge(Error06IdentifyMultiplyDrivenSignals.getErrors(parser));
merge(Error15IdentifyBlockingNonBlocking.getErrors(parser));
merge(Error14IdentifyBackwardPortDirection.getErrors(parser));
merge(Error13IdentifyOperatorsInSensList.getErrors(parser));
merge(Error03IdentifyAssignmentVsSensType.getErrors(parser));
127
ECE 4899
merge(Error01_05_07IdentifyClockErrors.getErrors(parser));
merge(Error09a_09bIdentifyIncompleteSensList.getErrors(parser));
merge(Error10VectorArrayInSensList.getErrors(parser));
merge(Error11LogicalNotWithVector.getErrors(parser));
merge(Error16IdentifyLatches.getErrors(parser));
}
return EL;
}
private void ClearErrorList()
{
EL = new ArrayList();
}
private void merge(ArrayList<Error> ErrorList)
{
EL.addAll(ErrorList);
}
}
128
ECE 4899
FileRead.java
package TestMain;
/**
* @Author:
* @Date:
Kenneth Hassey
1/7/2013
* @Version: 1.000
* Function:
*
Basic Steps are prompt the user for a file and convert it to an
*
* Status: Tested Working;
*/
import javax.swing.JFileChooser;
import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
*
*/
public class FileRead {
ECE 4899
ECE 4899
FileType = file.getName();
}
catch(Exception e)
{
System.out.println("File Read Error");
}
}
//This function is Responsible for the opening of the file and to convert it
//into strings for return. This function does not return the
//String ArrayList.
private void readFile()
{
code = new ArrayList();
Scanner inputFile;
//
try
{
inputFile = new Scanner(file);
//this block is responsible for converting the file to a arraylist
//of strings.
try{
while (inputFile.hasNext())
{
//adds line of code to the Arraylist.
131
ECE 4899
}
}
//catches exception dealing with array out of bounds for file
//should never trigger.
catch(Exception e )
{
System.out.println("File Has Filed to transfer to ArrayList\n"
+ "Location: FileReader.readFile()");
}
}
//catch an exception most likely dealing with the input file being null
catch(Exception e)
{
System.out.println("File Has Failed to Read\n"
+ "Location: FileReader.readFile()");
}
//used to get a new file from the user and to convert it to a Arraylist of
//Strings. Call this instead of a New Constructor.
public void newFile()
{
getFile();
readFile();
}
132
ECE 4899
@Override
public String toString()
{
String comp="";
//@Override
//prints out the file name
//
System.out.println(FileName+":");
System.out.println("\t"+code.get(i));
133
ECE 4899
comp += code.get(i);
}
//
return ("Successful");
return comp;
}
134
ECE 4899
ForLoop.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class ForLoop extends Block{
private ArrayList<String> forLoopBody;
private ArrayList<String> whileLoopHead;
ECE 4899
&&
!temp.equals("##END_OF_MODULE_CODE");
forLoop.whileLoopHead.add(temp);
}
forLoop.whileLoopHead.add(temp);
temp = parser.getNextPiece();
forLoop.forLoopBody.add(temp);
if(temp.equals("begin")){
temp = parser.getNextPiece();
for(
int
endCount=0;
(!temp.equals("end")
||
!temp.equals("##END_OF_MODULE_CODE"); temp=parser.getNextPiece()){
forLoop.forLoopBody.add(temp);
if(temp.equals("begin")){
endCount++;
}
else if(temp.equals("end")){
endCount--;
}
}
forLoop.forLoopBody.add(temp);
}else {
136
endCount!=0)
&&
ECE 4899
temp = parser.getNextPiece();
//if the for loop is not wrapped in begin/end it is assumed the loop contains
// only a single assignment statement, and not sub-blocks, this will need to
// be changed in the future if for loops are going to be legitimately used
for(;
!temp.equals(";")
temp=parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
forLoop.forLoopBody.add(temp);
}
forLoop.forLoopBody.add(";");
}
}
@Override
public String toString(){
ArrayList<String> forLoopText = whileLoopHead;
forLoopText.addAll(forLoopBody);
String exit="for( ";
for(int i=0; i<forLoopText.size(); i++){
exit += forLoopText.get(i) + " ";
if(forLoopText.get(i).equals("begin")
|| forLoopText.get(i).equals("end")
|| forLoopText.get(i).equals(";") ){
exit += "\n";
}
}
return exit+"\n";
}
}
137
ECE 4899
Function.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class Function extends Block{
private ArrayList<String> functionText;
ECE 4899
String lastType="DEFAULT_NET_TYPE";
String lastAttribute = "";
Function function = new Function("function",current, temp);
current.addSubBlock(function);
for(;
!temp.equals("endfunction")
temp=parser.getNextPiece()){
&&
function.functionText.add(temp);
}
}
@Override
public String toString(){
String exit="function ";
for(int i=0; i<functionText.size(); i++){
exit += functionText.get(i) + " ";
if(functionText.get(i).equals("begin")
|| functionText.get(i).equals("end")
|| functionText.get(i).equals(";") ){
exit += "\n";
}
}
return exit+"endfunction\n";
}
}
139
!temp.equals("##END_OF_MODULE_CODE");
ECE 4899
FunctionCall.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class FunctionCall extends Variable{
String functionCallText;
ArrayList<String> functionCallElements;
ArrayList<Variable> parameterVars;
FunctionCall(){
functionCallText = "";
functionCallElements = new ArrayList();
parameterVars = new ArrayList();
LineNumber = Parser.currentLineNumber;
}
FunctionCall(String text, ArrayList<String> elements){
functionCallText = text;
functionCallElements = elements;
parameterVars = new ArrayList();
LineNumber = Parser.currentLineNumber;
140
ECE 4899
@Override
public String toString(){
return functionCallText +" //Function Call LINE: "+LineNumber+"\n";
}
}
141
ECE 4899
IfElse.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Hell-o
*/
public class IfElse extends Block {
private ConditionStatement condition;
/*"ifElseBlockOrder" preserves the structureal order of statements and
* subBlocks in and always block.
* 0 - indicates an assignment statement,
* 1- indicates the presence of another subBlock
*/
private ArrayList<Integer> ifElseBlockOrder;
private int ifElseType; //0="if", 1="else if", 2="else"
ECE 4899
parent = comesFrom;
LineNumber = Parser.currentLineNumber;
}
ECE 4899
}else {
ifConditionStatementBreak = -1;
}
}else {
statementText += temp+ " ";
temp = parser.getNextPiece();
}
}
ie.condition =
new ConditionStatement(statementText, ie, parser);
temp = parser.getNextPiece();
// if there will be multiple sublocks or assginments
if(temp.equals("$#")){
parser.updateLineNumber();
temp = parser.getNextPiece();
}
if(temp.equals("begin")){
for(temp=parser.getNextPiece();
!temp.equals("end")
!temp.equals("##END_OF_MODULE_CODE"); temp=parser.getNextPiece() ){
if(parser.pieceIsKeyword(temp)){
if(!temp.equals("always")){
parser.checkForNewBlock(ie, temp);
if(!temp.equals("$#"))
ie.ifElseBlockOrder.add(new Integer(1));
}
else{
144
&&
ECE 4899
parser.addErrorToParserErrorList(new
Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
else if(parser.checkTaskOrFunctionName(temp)!=0){
String taskCallText = "";
ArrayList<String> taskCallElements = new ArrayList();
for(; !temp.equals(";") &&
!temp.equals("##END_OF_MODULE_CODE");
temp=parser.getNextPiece()){
taskCallText += temp+" ";
taskCallElements.add(temp);
}
ie.addVariable(new TaskCall(taskCallText,taskCallElements));
ie.ifElseBlockOrder.add(new Integer(2));
}
else if( ie.findVariableInParentBlockHierarchy(temp)!=null ||
!ie.findVectorNameInParentBlockHierarchy(temp).isEmpty()){
for(statementText=""; !temp.equals(";") && !temp.equals("##END_OF_MODULE_CODE");
temp = parser.getNextPiece()){
statementText+=temp+" ";
}
ie.addAssignment(new AssignmentStatement(statementText,ie,parser));
ie.ifElseBlockOrder.add(new Integer(0));
}
else {
145
ECE 4899
}
}
}else {
if(temp.equals("$#")){
parser.checkForNewBlock(ie, temp);
temp = parser.getNextPiece();
}
if(parser.pieceIsKeyword(temp)){
if(!temp.equals("always")){
parser.checkForNewBlock(ie, temp);
if(!temp.equals("$#"))
ie.ifElseBlockOrder.add(new Integer(1));
}
else{
String errorText = "Error: nested always blocks not allowed";
parser.addErrorToParserErrorList(new Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
else if(parser.checkTaskOrFunctionName(temp)!=0){
String taskCallText = "";
ArrayList<String> taskCallElements = new ArrayList();
for(; !temp.equals(";") &&
!temp.equals("##END_OF_MODULE_CODE");
temp=parser.getNextPiece()){
taskCallText += temp+" ";
taskCallElements.add(temp);
146
ECE 4899
}
ie.addVariable(new TaskCall(taskCallText,taskCallElements));
ie.ifElseBlockOrder.add(new Integer(2));
}
else if( ie.findVariableInParentBlockHierarchy(temp)!=null ||
!ie.findVectorNameInParentBlockHierarchy(temp).isEmpty()){
for(statementText=""; !temp.equals(";") && !temp.equals("##END_OF_MODULE_CODE"); temp
= parser.getNextPiece()){
statementText+=temp+" ";
}
ie.addAssignment(new AssignmentStatement(statementText,ie,parser));
ie.ifElseBlockOrder.add(new Integer(0));
}
else {
//add piece identification error here
}
}
return ie;
}
public static String parseElse(Block current, Parser parser){
String temp = parser.getNextPiece();
String statementText = "";
if(temp.equals("$#")){
parser.updateLineNumber();
temp = parser.getNextPiece();
}
//if this "else" statement is really and "else if" then parse it like
147
ECE 4899
&&
ECE 4899
ECE 4899
return temp;
}
public void setIfElseType(int type){
this.ifElseType = type;
150
ECE 4899
}
public ConditionStatement getConditionStatement()
{
return condition;
}
public int getIfElseType(){
return this.ifElseType;
}
@Override
public String toString(){
String temp = "";
int i=0; int subBlockCount=0; int assignmentStatementCount=0; int varsCount=0;
if(this.ifElseType == 0){
temp += "if(";
temp += this.condition.toString();
temp += ") begin \\\\LINE: "+LineNumber+", Vars in Condition: "
+condition.conditionVars.toString()+"\n";
for(i=0, subBlockCount=0, assignmentStatementCount=0, varsCount=0;
i< this.ifElseBlockOrder.size(); i++){
if(ifElseBlockOrder.get(i) == 1){
temp += this.subBlocks.get(subBlockCount).toString();
subBlockCount++;
}else if(!assignments.isEmpty()){
temp += this.assignments.get(assignmentStatementCount);
assignmentStatementCount++;
}else if(!vars.isEmpty()){
temp += this.vars.get(varsCount);
varsCount++;
151
ECE 4899
}
}
temp += "end //ends if()\n";
}else if(this.ifElseType==1){
temp += "else if("; temp += this.condition.toString(); temp += ") begin "
+ "//Vars in Condition: "+condition.conditionVars.toString()+"\n";
for(i=0, subBlockCount=0, assignmentStatementCount=0, varsCount=0;
i< this.ifElseBlockOrder.size(); i++){
if(ifElseBlockOrder.get(i) == 1){
temp += this.subBlocks.get(subBlockCount).toString();
subBlockCount++;
}else if(!assignments.isEmpty()){
temp += this.assignments.get(assignmentStatementCount);
assignmentStatementCount++;
}else if(!vars.isEmpty()){
temp += this.vars.get(varsCount);
varsCount++;
}
}
temp += "end //ends else if()\n";
}else {
temp += "else begin\n";
for(i=0, subBlockCount=0, assignmentStatementCount=0, varsCount=0;
i< this.ifElseBlockOrder.size(); i++){
if(ifElseBlockOrder.get(i) == 1){
temp += this.subBlocks.get(subBlockCount).toString();
subBlockCount++;
}else if(!assignments.isEmpty()){
152
ECE 4899
}else if(!vars.isEmpty()){
temp += this.vars.get(varsCount);
varsCount++;
}
}
temp += "end //ends else\n";
}
return temp;
}
}
153
ECE 4899
IntegerVariable.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class IntegerVariable extends Variable{
protected int startValue;
protected String startValueString;
IntegerVariable(String name_in)
{
name = name_in;
variableType = "IntegerVariable";
variableAttribute = "";
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
startValue = 0;
154
ECE 4899
startValueString = "";
}
IntegerVariable(ArrayList<String> startVals)
{
name = "";
variableType = "IntegerVariable";
variableAttribute = "";
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
startValueString = "";
parseIntegerVariable(startVals);
}
ECE 4899
}
else if(Parser.isANumber(pieces.get(i))==1 && equalsFlag==1){
startValue = Integer.parseInt(Parser.parseNumberFromExpression(pieces.get(i)+" "));
startValueString = Integer.toString(startValue);
}else {
startValue = 0;
startValueString = pieces.get(i);
}
}
@Override
public String toString(){
return variableAttribute + " " + variableType + " " + variableSign + " " +
name + " = "+startValueString+"; LINE: " + LineNumber;
}
}
156
ECE 4899
MainGUI.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import com.sun.corba.se.impl.util.Version;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
/**
*
* @author Deathwarror
*/
public class MainGUI extends javax.swing.JFrame {
ECE 4899
"https://linting-
ECE 4899
ScreenHeight = (int)(dim.height*.8);
ScreenWidth = (int)(dim.width*.8);
VersionNumber.setText(("Version: "+version.version));
this.setSize(new Dimension(ScreenWidth,ScreenHeight));
this.setLocation((int)((dim.width-ScreenWidth)/2),(int)((dim.height-ScreenHeight)/2));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
159
ECE 4899
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Linting Tool");
setBounds(new java.awt.Rectangle(0, 0, 800, 600));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
FileListBox.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
FileListBoxValueChanged(evt);
}
});
FileListPane.setViewportView(FileListBox);
AddButton.setText("Load File");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
RemoveButton.setText("Remove File");
RemoveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RemoveButtonActionPerformed(evt);
}
});
FileListTitle.setText("Files Opened");
160
ECE 4899
CodeListTitle.setText("File data");
ErrorMsgTitle.setText("Error Messages");
ErrorListBox.setToolTipText("Right Click For More Information about the Error (Requires Internet
Connection)");
ErrorListBox.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
ErrorListBoxMouseClicked(evt);
}
});
ErrorListBox.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
ErrorListBoxValueChanged(evt);
}
});
ErrorListPane.setViewportView(ErrorListBox);
CodeListPane.setViewportView(CodeListBox);
VersionNumber.setText("jLabel1");
ECE 4899
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ErrorListPane)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(FileListPane,
javax.swing.GroupLayout.PREFERRED_SIZE)
javax.swing.GroupLayout.PREFERRED_SIZE,
172,
.addComponent(FileListTitle)
.addComponent(ErrorMsgTitle)
.addGroup(layout.createSequentialGroup()
.addComponent(AddButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(RemoveButton,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(CodeListTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(VersionNumber))
.addComponent(CodeListPane))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(FileListTitle,
javax.swing.GroupLayout.PREFERRED_SIZE)
javax.swing.GroupLayout.PREFERRED_SIZE,
162
14,
ECE 4899
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(FileListPane)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(RemoveButton)))
.addComponent(CodeListPane))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ErrorMsgTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ErrorListPane,
javax.swing.GroupLayout.PREFERRED_SIZE))
javax.swing.GroupLayout.PREFERRED_SIZE,
);
pack();
}// </editor-fold>
221,
ECE 4899
if(!FR.getFileName().equals(""))
{
newFile.setCode(FR.getCode());
newFile.setName(FR.getFileName());
System.out.println("enter");
parser = new Parser(newFile.getCode());
System.out.println("exit parser");
newFile.setErrorList(ES.Start(parser));
System.out.println("exit Error list");
FileListModel.addElement(newFile);
FileListBox.setSelectedIndex(FileListModel.size()-1);
FileListBox.ensureIndexIsVisible(FileListModel.size()-1);
}
else
{
JOptionPane.showMessageDialog(new JFrame(), "Error the File Failed to Read");
}
ECE 4899
String FileCode;
for(int i = 0; i<Errors.size();i++)
{
Error e = Errors.get(i);
if(!e.getLineNumbers().isEmpty()){
165
ECE 4899
Error
Temp = convertToHTML(Temp);
ErrorListModel.addElement("<html>"+Temp+"</html>");
}else {
String
Temp
"+e.getErrorMsg()+"\n\n");
ReplaceSpecialCharacterS("Error
Temp = convertToHTML(Temp);
ErrorListModel.addElement("<html>"+Temp+"</html>");
}
}
if(Errors.isEmpty())
{
ErrorListModel.addElement("No Errors Detected");
}
}
}
}
166
"+e.getErrorNum()+":
ECE 4899
ECE 4899
ArrayList<String> Code;
String FileCode;
//if nothing is selected
if(index == -1)
{
}
else
{
if(EL.size() >0)
{
//if Something was selected
CodeListModel.clear();
e = EL.get(index);
ErrorLines = e.getLineNumbers();
sortLineNumbers(ErrorLines);
//fill the cell with
int j = 0;
//rebuilds the HTML code so that the error lines are highlighted
168
ECE 4899
}
}
}
}
new
ErrorDocumentationLoader
EDL2
ErrorDocumentationLoader(DocumentationURL,DefaultDocType);
new
String Description;
SimpleFileStore WorkingStore;
169
ECE 4899
ArrayList<Error> EL;
String ErrorNumber;
JEditorPane ErrorD;
JScrollPane JSP;
if(EL.size()>0)
{
ErrorNumber = EL.get(index).getErrorNum();
//try using the gui based load method
}
}
}
}
ECE 4899
{
s=s.replaceAll("&","&");
s=s.replaceAll("<","<");
s=s.replaceAll("<",">");
return s;
}
private ArrayList<String> ReplaceSpecialCharacter(ArrayList<String>al)
{
ArrayList<String> temp = new ArrayList();
String s;
for(int i = 0; i <al.size();i++)
{
s = al.get(i);
s=s.replaceAll("&","&");
s=s.replaceAll("<","<");
s=s.replaceAll("<",">");
temp.add(s);
}
return temp;
}
//converts the arraylist of numbers to an integer array
private static void sortLineNumbers(ArrayList<Integer> arr){
int i=0, j=0;
Integer temp = new Integer(0);
for(i=0; i<arr.size(); i++){
for(j=0; j<arr.size()-(i+1); j++){
if(arr.get(j).compareTo(arr.get(j+1)) == 1){
171
ECE 4899
}
}
for(int k = 0; k <arr.size()-1;k++)
{
if(arr.get(k).compareTo(arr.get(k+1))==0)
{
arr.remove(k);
k--;
}
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for
(javax.swing.UIManager.LookAndFeelInfo
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
172
info
ECE 4899
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
173
ECE 4899
temp2 = replaceAll(temp2);
ECE 4899
line += line2;
temp2 = line;
ECE 4899
blockComment = true;
}
else if(temp2.contains("/*") && temp2.contains("*/"))
{
temp2 = removePreviousColors(temp2);
int comNum = 0;
boolean lineCom = false;
arr = temp2.toCharArray();
line = "";
for(int j=1; j<arr.length; j++){
if(arr[j]=='*' && arr[j-1]=='/' && !lineCom){
if(line.length()>0){
line = line.substring(0, line.length()-1);
}
line = replaceAll(line);
line += "<font color=#"+CommentColor+">/*";
comNum++;
}
else if(arr[j]=='/' && arr[j-1]=='*' && !lineCom){
line += "/</font>";
comNum--;
lineCom = false;
}
else if(arr[j]=='/' && arr[j-1]=='/'){
if(line.length()>0){
line = line.substring(0, line.length()-1);
}
line = replaceAll(line);
176
ECE 4899
if(lineCom){
line += "</font>/";
}
else if(comNum > 0){
line += "</font>/";
blockComment = true;
}
temp2 = line;
}
else if(temp2.contains("*/"))
{
startIndex = temp2.indexOf("*/");
temp1 = temp2.substring(startIndex);
temp1 = replaceAll(temp1);
temp2 = removePreviousColors(temp2.substring(0,startIndex))+temp1;
temp2 = temp2.replace("*/","*/</font>");
temp2 = "<font color=#"+CommentColor+">"+ temp2;
blockComment = false;
}
else if(temp2.contains("//"))
177
ECE 4899
{
startIndex = temp2.indexOf("//");
temp1 = temp2.substring(0,startIndex);
temp1 = replaceAll(temp1);
temp2 = temp1+removePreviousColors(temp2.substring(startIndex));
temp2 = temp2.replace("//","<font color=#"+CommentColor+">//");
temp2 = temp2+"</font>";
}
newLines.add(temp2);
}
return newLines;
}
private String replaceAll(String S){
//module
S = S.replaceAll(" module "," <font color=#"+KeywordColor+">module</font> ");
S = S.replaceAll(";module ",";<font color=#"+KeywordColor+">module</font> ");
S = S.replaceAll("module ","<font color=#"+KeywordColor+">module</font> ");
//input
S = S.replaceAll(" input "," <font color=#"+KeywordColor+">input</font> ");
S = S.replaceAll(",input ",",<font color=#"+KeywordColor+">input</font> ");
S = S.replaceAll(";input ",";<font color=#"+KeywordColor+">input</font> ");
S = S.replaceAll("\\(input ","\\(<font color=#"+KeywordColor+">input</font> ");
//inout
S = S.replaceAll(" inout "," <font color=#"+KeywordColor+">inout</font> ");
S = S.replaceAll(",inout ",",<font color=#"+KeywordColor+">inout</font> ");
S = S.replaceAll(";inout ",";<font color=#"+KeywordColor+">inout</font> ");
S = S.replaceAll("\\(inout ","\\(<font color=#"+KeywordColor+">inout</font> ");
178
ECE 4899
//output
S = S.replaceAll(" output "," <font color=#"+KeywordColor+">output</font> ");
S = S.replaceAll(",output ",",<font color=#"+KeywordColor+">output</font> ");
S = S.replaceAll(";output ",";<font color=#"+KeywordColor+">output</font> ");
S = S.replaceAll("\\(output ","\\(<font color=#"+KeywordColor+">output</font> ");
//parameter
S = S.replaceAll(" parameter "," <font color=#"+KeywordColor+">parameter</font> ");
S = S.replaceAll(";parameter ",";<font color=#"+KeywordColor+">parameter</font> ");
S = S.replaceAll(" parameter="," <font color=#"+KeywordColor+">parameter</font>=");
S = S.replaceAll(";parameter=",";<font color=#"+KeywordColor+">parameter</font>=");
//localparameter
S = S.replaceAll(" localparam "," <font color=#"+KeywordColor+">localparam</font> ");
S = S.replaceAll(";localparam ",";<font color=#"+KeywordColor+">localparam</font> ");
S = S.replaceAll(" localparam="," <font color=#"+KeywordColor+">localparam</font>=");
S = S.replaceAll(";localparam=",";<font color=#"+KeywordColor+">localparam</font>=");
//register
S = S.replaceAll(" reg ", " <font color=#"+KeywordColor+">reg</font> ");
S = S.replaceAll(";reg ", ";<font color=#"+KeywordColor+">reg</font> ");
//wire
S = S.replaceAll(" wire ", " <font color=#"+KeywordColor+">wire</font> ");
S = S.replaceAll(";wire ", ",<font color=#"+KeywordColor+">wire</font> ");
//always
S = S.replaceAll(" always "," <font color=#"+KeywordColor+">always</font> ");
S = S.replaceAll(";always ",";<font color=#"+KeywordColor+">always</font> ");
S = S.replaceAll(" always@"," <font color=#"+KeywordColor+">always</font>@");
S = S.replaceAll(";always@",";<font color=#"+KeywordColor+">always</font>@");
//if
S = S.replaceAll(" if "," <font color=#"+KeywordColor+">if</font> ");
179
ECE 4899
ECE 4899
//endcase
S = S.replaceAll(";endcase ",";<font color=#"+KeywordColor+">endcase</font> ");
S = S.replaceAll(";endcase;",";<font color=#"+KeywordColor+">endcase</font>;");
S = S.replaceAll(" endcase;"," <font color=#"+KeywordColor+">endcase</font>;");
S = S.replaceAll(" endcase "," <font color=#"+KeywordColor+">endcase</font> ");
S = S.replaceAll(";endcase\\(",";<font color=#"+KeywordColor+">endcase</font>\\(");
S = S.replaceAll(" endcase\\("," <font color=#"+KeywordColor+">endcase</font>\\(");
S = S.replaceAll("\\)endcase ","\\)<font color=#"+KeywordColor+">endcase</font> ");
S = S.replaceAll("\\)endcase;","\\)<font color=#"+KeywordColor+">endcase</font>;");
//default
S = S.replaceAll(";default ",";<font color=#"+KeywordColor+">default</font> ");
S = S.replaceAll(" default "," <font color=#"+KeywordColor+">default</font> ");
//forever
S = S.replaceAll(";forever ",";<font color=#"+KeywordColor+">forever</font> ");
S = S.replaceAll(" forever "," <font color=#"+KeywordColor+">forever</font> ");
//task
S = S.replaceAll(";task ",";<font color=#"+KeywordColor+">task</font> ");
S = S.replaceAll(" task "," <font color=#"+KeywordColor+">task</font> ");
S = S.replaceAll(";task\\(",";<font color=#"+KeywordColor+">task</font>\\(");
S = S.replaceAll(" task\\("," <font color=#"+KeywordColor+">task</font>\\(");
//function
181
ECE 4899
ECE 4899
String ss = "";
int i, last;
boolean dont = false;
for(i=s.indexOf("<font"),last=0; i!=-1;i=s.indexOf("<font")){
ss += s.substring(last, i);
if(!dont){
i = s.indexOf(">")+1;
dont = true;
}else {
i = s.indexOf(">")+1;
s = s.substring(i, s.length());
i = s.indexOf(">")+1;
dont = false;
}
s = s.substring(i, s.length());
}
ss += s.substring(0, s.length());
s = ss; ss= "";
for(i=s.indexOf("</font>"),last=0; i!=-1;last=0,i=s.indexOf("</font>")){
ss += s.substring(last, i);
i = s.indexOf(">")+1;
s = s.substring(i, s.length());
}
ss += s.substring(0, s.length());
return ss;
}
ECE 4899
String Temp = S;
Temp = Temp.replaceAll("\n","<br>");
Temp = Temp.replaceAll("\t"," ");
Temp = Temp.replaceAll(" "," ");
return Temp;
}
// Variables declaration - do not modify
private javax.swing.JButton AddButton;
private javax.swing.JList CodeListBox;
private javax.swing.JScrollPane CodeListPane;
private javax.swing.JLabel CodeListTitle;
private javax.swing.JList ErrorListBox;
private javax.swing.JScrollPane ErrorListPane;
private javax.swing.JLabel ErrorMsgTitle;
private javax.swing.JList FileListBox;
private javax.swing.JScrollPane FileListPane;
private javax.swing.JLabel FileListTitle;
private javax.swing.JButton RemoveButton;
private javax.swing.JLabel VersionNumber;
// End of variables declaration
184
ECE 4899
Module.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Hell-o
*/
public class Module extends Block{
Module(){
BlockType = "";
BlockName = "";
statementText = "";
vars = new ArrayList();
subBlocks = new ArrayList();
185
ECE 4899
ECE 4899
sortVariables();
}
void addVariableToModulePortList(Variable newVar){
portVariables.add(newVar);
addVariableToModule(newVar);
}
void addModuleInstantiation(ModuleInstantiation subModule){
subModules.add(subModule);
}
public Variable findVariableInModule(String searchName){
for(int i=0; i<vars.size(); i++){
if(vars.get(i).name.equals(searchName)){
if(vars.get(i).getClass()!=TaskCall.class && vars.get(i).getClass()!=FunctionCall.class){
return vars.get(i);
}
}
}
return null;
}
public void removeVariableFromModule(String removeName, ArrayList<Variable> rm){
for(int i=0; i<rm.size(); i++){
187
ECE 4899
if(rm.get(i).name.equals(removeName) || rm.get(i).vectorParentName.equals(removeName)){
rm.remove(i);
i--;
}
}
}
public void updatePortVariableInModule(String varName, String newType, ArrayList<Variable>
newVars){
Variable newVar;
/* If a variable by that name exists in both the overall variable list
* "vars" and in the "portVariables" list, then remove it, and add the
* updated variable.
*/
if(findVariableInModule(varName) != null){
removeVariableFromModule(varName, vars);
vars.addAll(newVars);
}
if(findVariableInModulePortList(varName) != null){
removeVariableFromModule(varName, portVariables);
portVariables.addAll(newVars);
}
}
public void sortModuleVariables(){
int i=0, j=0;
Variable temp;
for(i=0; i<vars.size(); i++){
for(j=0; j<vars.size()-(i+1); j++){
if(vars.get(j).compareVariable(vars.get(j+1)) == 1){
188
ECE 4899
}
}
}
}
public Variable findVariableInModulePortList(String searchName){
for(int i=0; i<portVariables.size(); i++){
if(portVariables.get(i).name.equals(searchName)){
return portVariables.get(i);
}
}
for(int i=0; i<portVariables.size(); i++){
if(portVariables.get(i).vectorParentName.equals(searchName)){
return portVariables.get(i);
}
}
return null;
}
public Parameter findParameterInModule(String searchName){
for(int i=0; i<parameters.size(); i++){
if(parameters.get(i).name.equals(searchName)){
return parameters.get(i);
}
}
return null;
}
189
ECE 4899
ECE 4899
if(temp.equals("$#")){
parser.updateLineNumber();
}else if(temp.equals("input") || temp.equals("output") ){
vecStartTemp=""; vecEndTemp="";
vecAttributeTemp = temp;
}else if(temp.equals("reg") || temp.equals("wire")){
vecTypeTemp = temp;
}else if(temp.equals("signed") || temp.equals("unsigned")){
lastSign = temp;
}else if(temp.equals(",")){
//
vecStart.set(i,vecStartTemp);
//
vecEnd.set(i,vecEndTemp);
vecStartTemp=""; vecEndTemp="";
//
vecStart.add("");
//
vecEnd.add("");
i++;
}else if(temp.equals("[")){
for(
temp=parser.getNextPiece();
!temp.equals("##END_OF_MODULE_CODE");
!temp.equals(":")
&&
!temp.equals("]")
}else{
191
&&
ECE 4899
}
}
for(int i=0; i<varNames.size() && !temp.equals("##END_OF_MODULE_CODE"); i++){
ArrayList<Variable> newVars = new ArrayList();
//set up the template
Variable template = findVariableInModulePortList(varNames.get(i));
if(vecTypes.get(i).equals("reg")){
template = new Reg(varNames.get(i), vecAttributes.get(i), lastSign, 0);
192
ECE 4899
}else {
template = new Wire(varNames.get(i), vecAttributes.get(i), lastSign, 0);
}
vecStart.get(i),
ECE 4899
if(temp.equals("$#")){
parser.updateLineNumber();
}else if(temp.equals("input") || temp.equals("output") ){
lastAttribute = temp;
}else if(temp.equals("reg") || temp.equals("wire")){
lastType = temp;
}else if(temp.equals("signed") || temp.equals("unsigned")){
lastSign = temp;
}else if(temp.equals(",")){
arraySize.add(new Integer(0));
}else if(temp.equals("[") && parVector){
for(
temp=parser.getNextPiece();
!temp.equals("##END_OF_MODULE_CODE");
!temp.equals(":")
&&
!temp.equals("]")
&&
!temp.equals(":")
&&
!temp.equals("]")
194
&&
ECE 4899
!temp.equals(";")
temp=parser.getNextPiece()){
if(temp.equals("{")){
breakFlag++;
}
else if(temp.equals("\\")){
escapeChar = true;
}
else if(temp.equals("\"")){
if(escapeChar){
escapeChar = false;
}
else if(inQuote){
inQuote = false;
}
else{
inQuote = true;
}
195
&&
breakFlag!=-1
&&
ECE 4899
}
parser.backOneStep();
}else{
parVector = false;
if(!checkVariableName(temp)){
parser.addInstanceOfError18UnexpectedToken(temp);
parser.stopParsing();
}
varNames.add(temp);
singleArrayParsed = false;
}
}
for(int i=0; i<varNames.size() && !temp.equals("##END_OF_MODULE_CODE"); i++){
ArrayList<Variable> newVars = new ArrayList();
196
ECE 4899
//take the newVars list and either update the existing variable, or add the new variables to the list
if( findVariableInModulePortList(varNames.get(i)) != null ){
updatePortVariableInModule(template.name, lastType, newVars);
}else{
197
ECE 4899
vars.addAll(newVars);
}
module = parseModuleHead(module,parser);
temp = parser.getNextPiece(); //should be a "("
if(temp.equals("(")){
temp = parser.getNextPiece(); //should be a the first intereting piece of the port lists
module.parseVariableInModuleHead(temp, parser);
}
current.addSubBlock(module);
Variable tempVar;
int piecePlaceholder=0; //used for checking vector names
do{
temp = parser.getNextPiece();
if(temp.equals("input") || temp.equals("output") || temp.equals("reg") || temp.equals("wire")){
module.parseVariableInModule(temp, parser);
}
else if(temp.equals("integer")){
198
ECE 4899
&&
integerPieces.add(temp);
}
module.addVariableToModule(new IntegerVariable(integerPieces));
}
//This effectively skips over the parameters, which have already been parsed
else if(temp.equals("parameter") || temp.equals("localparam")){
for(;
!temp.equals(";")
parser.getNextPiece());
&&
!temp.equals("##END_OF_MODULE_CODE");
temp
}
else if(temp.equals("assign")){
for(module.statementText="", temp="";
!temp.equals(";")
parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
temp
199
ECE 4899
ModuleInstantiation(subModuleText,
line));
}else{
parser.addInstanceOfError8UndeclaredSignal(temp);
parser.stopParsing();
}
}
//check for a task call, and ignore it if its present
else if(parser.checkTaskOrFunctionName(temp)!=0){
int type = parser.checkTaskOrFunctionName(temp);
String CallText = "";
ArrayList<String> CallElements = new ArrayList();
for(; !temp.equals(";") &&
!temp.equals("##END_OF_MODULE_CODE");
temp=parser.getNextPiece()){
CallText += temp+" ";
CallElements.add(temp);
200
subModule,
ECE 4899
}
if(type == 1){
module.addVariable(new TaskCall(CallText,CallElements));
}else if(type == 2){
module.addVariable(new FunctionCall(CallText,CallElements));
}
}
else if(!temp.equals("##END_OF_MODULE_CODE") ){
/* If the string temp is a keyword then once it is back in the
* it is checked to see if it is part of a block, and if so
* then it is passed back to the parser to be handled
* to another block type
*/
if(parser.pieceIsKeyword(temp))
parser.checkForNewBlock(module, temp);
else{
parser.addInstanceOfError18UnexpectedToken(temp);
parser.stopParsing();
}
}
}while( !temp.equals("endmodule") && !temp.equals("##END_OF_MODULE_CODE"));
return temp;
}
private static Module parseModuleHead(Module current, Parser parser){
Module module = current;
String piece = parser.getNextPiece();
String lastType="DEFAULT_NET_TYPE";
String lastAttribute = "";
201
ECE 4899
do{
piece = parser.getNextPiece();
if(piece.equals("$#")){
parser.checkForNewBlock(current, piece);
}
else if(piece.equals("input")){
lastAttribute = "input";
lastType = "DEFAULT_NET_TYPE";
piece = parser.getNextPiece();
if(piece.equals("reg")){
lastType = "ERROR";
piece = parser.getNextPiece();
module.addVariableToModulePortList(new Reg(piece,"input"));
}else if(piece.equals("wire")){
lastType = "wire";
piece = parser.getNextPiece();
module.addVariableToModulePortList(new Wire(piece,"input"));
}
else{
module.addVariableToModulePortList(new Variable(piece,lastType,"input"));
}
}
else if(piece.equals("output")){
lastAttribute = "output";
lastType = "DEFAULT_NET_TYPE";
piece = parser.getNextPiece();
if(piece.equals("reg")){
lastType = "reg";
202
ECE 4899
}else if(piece.equals("wire")){
lastType = "wire";
piece = parser.getNextPiece();
module.addVariableToModulePortList(new Wire(piece,"output"));
}
else {
module.addVariableToModulePortList(new Variable(piece,lastType,"input"));
}
}
else if(piece.equals("reg")){
lastType = "ERROR";
piece = parser.getNextPiece();
module.addVariableToModulePortList(new Variable(piece,lastType,lastAttribute));
}
else if(piece.equals("wire")){
lastType = "wire";
piece = parser.getNextPiece();
module.addVariableToModulePortList(new Wire(piece,lastAttribute));
}
else if(!piece.equals(")")){
module.addVariableToModulePortList(new Variable(piece,lastType,lastAttribute));
}
}while(!piece.equals(")") && !piece.equals("##END_OF_MODULE_CODE"));
piece = parser.getNextPiece(); //used to remove the final semicolon from the parse string
return module;
}
203
ECE 4899
&&
!temp.equals("##END_OF_MODULE_CODE");
if(temp.equals("$#")){
parser.updateLineNumber();
}
else if(temp.equals("parameter") || temp.equals("localparam") ){
paramType = temp;
temp = parser.getNextPiece();
if(temp.equals("[")){
for(;
!temp.equals("]")
temp=parser.getNextPiece());
&&
!temp.equals("##END_OF_MODULE_CODE");
204
ECE 4899
}
for(paramAssignmentValue="";
!temp.equals(";")
temp=parser.getNextPiece() ){
&&
!temp.equals("##END_OF_MODULE_CODE");
parser.setLineNumber(1);
parser.setFreshPieceIndex(currentPieceIndex);
}
@Override
public String toString(){
205
ECE 4899
int i=0;
for(i=0; (vars.get(i).getAttribute().equals("input")
//
|| vars.get(i).getAttribute().equals("output"))
//
//
out += vars.get(i).toString();
for(i=0; i<vars.size(); i++){
206
ECE 4899
if(!vars.get(i).getAttribute().equals("input")
&& !vars.get(i).getAttribute().equals("output")
&& vars.get(i).getClass() != Parameter.class){
out += vars.get(i).toString();
out += ";\n";
}
}
}
out += "\n";
for(i=0; i< subModules.size(); i++){
out += subModules.get(i).toString();
}
out += "\n";
for(i=0; i< subBlocks.size(); i++){
out += subBlocks.get(i).toString();
}
out += "\n";
for(i=0; i<assignments.size(); i++){
out += assignments.get(i).toString();
}
out+="\nendmodule\n";
return out;
}
}
207
ECE 4899
ModuleInstantiation.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
ModuleInstantiation(){
name = "";
variableType = "";
moduleText = "";
externalPortVariables = new ArrayList();
internalPortVariables = new ArrayList();
LineNumber = Parser.currentLineNumber;
}
ModuleInstantiation(String moduleTextIn, ArrayList<String> subModule, int line){
name = "";
208
ECE 4899
variableType = "";
moduleText = "";
externalPortVariables = new ArrayList();
internalPortVariables = new ArrayList();
moduleText = moduleTextIn;
LineNumber = line;
parseSubModule(subModule);
}
private void parseSubModule(ArrayList<String> pieces){
}
@Override
public String toString(){
return moduleText+" LINE: "+LineNumber+"\n";
}
209
ECE 4899
New_Error_Template.java
/*
* Template For Sponsor To Write New Error Files
*/
package TestMain;
import java.util.ArrayList;
return errorList;
}
}
210
ECE 4899
Parameter.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
/**
*
* @author cloud9
*/
public class Parameter extends Variable{
determineParameterValue();
}
private void determineParameterValue(){
parameterValue = Parser.parseNumberFromExpression(variableAttribute);
211
ECE 4899
}
public String getParameterValue(){
return parameterValue;
}
@Override
public String toString(){
return variableType + " " + name + " = "+ parameterValue + "; \\\\LINE:"+LineNumber+"\n";
}
}
212
ECE 4899
Parser.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Hell-o
*/
public class Parser {
private Block top;
private ArrayList<Variable> variables; // A complete list of all variables
private ArrayList<Block> Blocks; // A complete list of all Blocks/subBlocks
private String cleanInput;
private ArrayList<String> usedPieces;
private ArrayList<String> freshPieces;
private ArrayList<String> taskOrFunctionNames;
private int freshPieceIndex;
public static int currentLineNumber;
Parser(ArrayList<String> original){
//initializes "Parser" class members
213
ECE 4899
cleanInput = removeComments(original);
cleanInput = spaceEvenly(cleanInput);
makePieceList(freshPieces, cleanInput);
removeBlockNames();
checkForTimingControl();
if(!parserErrorList.isEmpty()){
return;
}
getTaskAndFunctionNames();
ECE 4899
bob = getNextPiece();
checkForNewBlock(top,bob); // this starts actally parsing the module
System.out.println("\n"+top.toString());
variables.addAll(top.getAllVariables());
System.out.println("\nVariables: "+variables.toString());
Blocks.addAll(top.getAllBlocks());
}
private String removeComments(ArrayList<String> original){
int i=0,numChars=0;
String temp="";
for(i =0; i<original.size(); i++){
temp += " $# " + (i+1) + " ";
temp += original.get(i);
temp += " \n";
}
//
System.out.println("\nBefore:\n");
//
System.out.print(temp);
numChars = temp.length();
char[] clean = temp.toCharArray();
for(i=0; i<numChars; i++){
switch(clean[i]){
case '/':
if(clean[i+1] == '/'){
for(;clean[i]!='\n';i++)
215
ECE 4899
case '\n':
clean[i]=' ';
break;
case '\r':
clean[i]=' ';
break;
case '\t':
clean[i]=' ';
break;
default:
break;
}
}
//
System.out.println("\nAfter:\n");
//
System.out.print(String.copyValueOf(clean));
return String.copyValueOf(clean);
}
private String spaceEvenly(String original){
String spacer = original;
216
ECE 4899
spacer = spaceElement("(",spacer);
spacer = spaceElement(")",spacer);
spacer = spaceElement("[",spacer);
spacer = spaceElement("]",spacer);
spacer = spaceElement("@",spacer);
spacer = spaceElement(",",spacer);
spacer = spaceElement("`",spacer);
spacer = spaceElement(";",spacer);
spacer = spaceElement("*",spacer);
spacer = spaceElement(":",spacer);
spacer = spaceElement("+",spacer);
spacer = spaceElement("-",spacer);
spacer = spaceElement("=",spacer);
spacer = spaceElement("<",spacer);
spacer = spaceElement(">",spacer);
spacer = spaceElement("/",spacer);
spacer = spaceElement("%",spacer);
spacer = spaceElement("!",spacer);
spacer = spaceElement("`",spacer);
spacer = spaceElement("^",spacer);
spacer = spaceElement("|",spacer);
spacer = spaceElement("&",spacer);
spacer = spaceElement("#",spacer);
spacer = spaceElement("{",spacer);
spacer = spaceElement("}",spacer);
spacer = spaceElement("\"",spacer);
//
System.out.println("\nEvenly Spaced\n"+spacer+"\n");
217
ECE 4899
return removeRadixSpaces(spacer);
}
private String removeRadixSpaces(String orig){
String unspaced = "" + orig.charAt(0) + orig.charAt(1);
char rad = ' ';
for(int i = 2; i<orig.length(); i++){
rad = orig.charAt(i-1);
if(orig.charAt(i-2)=='\'' &&
(rad=='b' || rad=='B' || rad=='d' || rad=='D' || rad=='o' || rad=='O' || rad=='h' || rad=='H')
&&
(orig.charAt(i)==' ' || orig.charAt(i)=='\n')){
for(;orig.charAt(i)==' ' || orig.charAt(i)=='\n' || orig.charAt(i)=='$'; i++){
if(orig.charAt(i)=='$'){
for(i+=3; orig.charAt(i)!=' '; i++);
}
}
}
unspaced += orig.charAt(i);
}
//
//
ECE 4899
return output;
}
public void checkForNewBlock(Block current, String nextWord){
String piece = nextWord;
if( piece.equals("module") ){
Module.parseModule(current,this);
}else if( piece.equals("`")){
parseCompilerDerective(current);
}else if( piece.equals("always")){
219
ECE 4899
Always.parseAlways(current, this);
}else if( piece.equals("if")){
IfElse.parseIf(current, this);
}else if( piece.equals("else")){
IfElse.parseElse(current, this);
}else if( piece.equals("case")){
Case.parseCase(current, this);
}else if( piece.equals("task")){
Task.parseTask(current, this);
}else if( piece.equals("function")){
Function.parseFunction(current, this);
}else if( piece.equals("for")){
ForLoop.parseForLoop(current, this);
}else if( piece.equals("while")){
WhileLoop.parseWhileLoop(current, this);
}else if( piece.equals("$#")){
updateLineNumber();
}
}
public String getNextPiece(){
if(freshPieceIndex+1 < freshPieces.size()){
freshPieceIndex++;
return freshPieces.get(freshPieceIndex);
}
return "##END_OF_MODULE_CODE";
}
public void replaceCurrentPieceText(String newText){
freshPieces.set(freshPieceIndex, newText);
220
ECE 4899
}
public void reFRESHpieces(){
freshPieceIndex = -1;
}
private void removeBlockNames(){
for(int i=1; i<freshPieces.size()-1; i++){
if(freshPieces.get(i-1).equals("$#")){
currentLineNumber = Integer.parseInt( freshPieces.get(i));
}else if(freshPieces.get(i).equals(":") &&
(freshPieces.get(i-1).equals("begin") || freshPieces.get(i-1).equals("end"))){
freshPieces.remove(i+1);
freshPieces.remove(i);
String errorText="Error: Named Block Detected \n\ton line "+currentLineNumber+" (this is not
supported with this tool)";
System.out.println(errorText);
addErrorToParserErrorList(new Error("20f",errorText,currentLineNumber) );
}
}
}
private void checkForTimingControl(){
for(int i=3; i<freshPieces.size()-1; i++){
if(freshPieces.get(i-1).equals("$#")){
currentLineNumber = Integer.parseInt( freshPieces.get(i));
}else if((freshPieces.get(i).equals("posedge") || freshPieces.get(i).equals("negedge"))
&& freshPieces.get(i-1).equals("(")
&& freshPieces.get(i-2).equals("@")
&& !freshPieces.get(i-3).equals("always") ){
221
ECE 4899
addError2UnsynthesizableControlCodeError("@("+freshPieces.get(i)+"
"+freshPieces.get(i+1)+") ");
}else if(isANumber(freshPieces.get(i)) == 1
&& freshPieces.get(i-1).equals("#") ){
addError2UnsynthesizableControlCodeError("#"+freshPieces.get(i));
}else if( freshPieces.get(i).equals("wait")){
addError2UnsynthesizableControlCodeError("wait");
}else if( freshPieces.get(i).equals("while")){
addError2UnsynthesizableControlCodeError("while");
}
}
}
private void addError2UnsynthesizableControlCodeError(String offendingControl){
String errorOutput = "Timing Control, or unsynthesizable Control code "
+ "( "+offendingControl+" ) present in module";
errorOutput += "\ton line : "+currentLineNumber;
addErrorToParserErrorList(new Error("2",errorOutput,currentLineNumber));
}
private static void makePieceList(ArrayList<String> tempFreshPieces, String inputString){
//
while(tempFreshPieces.lastIndexOf("endmodule") == -1){
while( !inputString.equals("") && !inputString.equals(" ")){
String[] piece = inputString.split(" ",2);
if(piece.length != 1)
inputString = piece[1];
while( piece[0].equals("")){
piece = inputString.split(" ",2);
inputString = piece[1];
222
ECE 4899
}
tempFreshPieces.add(piece[0]);
//
System.out.print(piece[0]+" ");
}
remergeLineNumbers(tempFreshPieces);
}
private static void remergeLineNumbers(ArrayList<String> tempFreshPieces){
for(int i=1; i< tempFreshPieces.size(); i++){
if(tempFreshPieces.get(i).equals("#") && tempFreshPieces.get(i-1).equals("$")){
tempFreshPieces.set(i-1, "$#");
tempFreshPieces.remove(i);
i--;
}
}
}
public String getPreviousPiece(int traceBack){
if(freshPieceIndex-traceBack >= 0 && freshPieceIndex-traceBack < freshPieces.size()){
return freshPieces.get(freshPieceIndex - traceBack);
}else{
return "";
}
}
public void parseCompilerDerective(Block current) {
String piece = getNextPiece();
while(!pieceIsKeyword(piece)){
piece = getNextPiece();
}
223
ECE 4899
checkForNewBlock(current, piece);
}
public boolean pieceIsKeyword(String piece){
if( piece.equals("module"))
return true;
else if(piece.equals("`"))
return true;
else if(piece.equals("input"))
return true;
else if(piece.equals("output"))
return true;
else if(piece.equals("parameter"))
return true;
else if(piece.equals("localparam"))
return true;
else if(piece.equals("reg"))
return true;
else if(piece.equals("wire"))
return true;
else if(piece.equals("always"))
return true;
else if(piece.equals("if"))
return true;
else if(piece.equals("else"))
return true;
else if(piece.equals("end"))
return true;
else if(piece.equals("endmodule"))
224
ECE 4899
return true;
else if(piece.equals("case"))
return true;
else if(piece.equals("endcase"))
return true;
else if(piece.equals("default"))
return true;
else if(piece.equals("forever"))
return true;
else if(piece.equals("task"))
return true;
else if(piece.equals("function"))
return true;
else if(piece.equals("while"))
return true;
else if(piece.equals("for"))
return true;
else if(piece.equals("repeat"))
return true;
else if(piece.equals("initial"))
return true;
else if(piece.equals("$#"))
return true;
else{
return false;
}
}
public ArrayList<Variable> getVariableList(){
225
ECE 4899
return variables;
}
public ArrayList<Block> getBlockList(){
return Blocks;
}
public void setFreshPieceIndex(int newIndex){
if(newIndex > -2 && newIndex+1 < freshPieces.size()){
freshPieceIndex = newIndex;
}
}
public int getFreshPieceIndex(){
return freshPieceIndex;
}
public static String parseNumberFromExpression(String expression){
ArrayList<String> pieces = new ArrayList();
makePieceList(pieces,expression);
int num = 0;//Integer.parseInt(expression, 10);
//Integer.parseInt(expression);
ECE 4899
return Integer.toString(num);
}
public static int parseNumberForParameter(Module module, String expression){
return 0;
}
public static int isANumber(String inputString){
//returns a 1 if the string is a legal verilog number,
//returns a 2 if the string is a don't care "x" or high impedence "z"
//returns a 0 if the string is neither of the two preveious
String maybe = "";
for(int i=0; i<inputString.length(); i++){
227
ECE 4899
ECE 4899
}
}
for(int i=quoteLocation+2; i<maybe.length(); i++){
test = maybe.charAt(i);
if(test=='z' || test=='Z' || test=='x' || test=='X'){
return 2;
}
}
return 1;
}
}
public static String resolveNumberToDecimalRadix(String inputString){
String numText = "";
//This loop clears out the whitespace allowed in the number
for(int i=0; i<inputString.length(); i++){
if(inputString.charAt(i) !=' '){
numText += inputString.charAt(i);
}
}
if( isANumber(numText)==0){
//this probably should never happen!
return "NOT_A_NUMBER";
}else if(isANumber(numText)==2){
return numText;
}else{
int quoteLocation = numText.indexOf("'");
229
ECE 4899
if(quoteLocation == -1){
for(int i=0; i<numText.length(); i++){
if(numText.charAt(i)!='_'){
num += numText.charAt(i);
}
}
return String.valueOf( Integer.parseInt(num, 10));
}
for(int i=quoteLocation+2; i<numText.length(); i++){
num += numText.charAt(i);
}
switch(numText.charAt(quoteLocation+1)){
case('b'): return String.valueOf( Integer.parseInt(num, 2));
case('B'): return String.valueOf( Integer.parseInt(num, 2));
case('o'): return String.valueOf( Integer.parseInt(num, 8));
case('O'): return String.valueOf( Integer.parseInt(num, 8));
case('d'): return String.valueOf( Integer.parseInt(num, 10));
case('D'): return String.valueOf( Integer.parseInt(num, 10));
case('h'): return String.valueOf( Integer.parseInt(num, 16));
case('H'): return String.valueOf( Integer.parseInt(num, 16));
default: return numText;
}
}
}
public void updateLineNumber(){
String number = getNextPiece(); //number should now be equal to the line number
230
ECE 4899
currentLineNumber = Integer.valueOf(number);
}
public void setLineNumber(int num){
currentLineNumber = num;
}
public static int getCurrentLineNumber(){
return currentLineNumber;
}
public void addErrorToParserErrorList(Error e){
parserErrorList.add(e);
}
public ArrayList<Error> getParserErrorList(){
return parserErrorList;
}
public void getTaskAndFunctionNames(){
for(int i=1; i<freshPieces.size(); i++){
if(freshPieces.get(i-1).equals("function")){
taskOrFunctionNames.add("function");
taskOrFunctionNames.add(freshPieces.get(i));
}else if(freshPieces.get(i-1).equals("task")){
taskOrFunctionNames.add("task");
taskOrFunctionNames.add(freshPieces.get(i));
}
}
}
public int checkTaskOrFunctionName(String name){
// 1: indicates "name" is a task
// 2: indicates "name" is a function
231
ECE 4899
ECE 4899
freshPieceIndex = freshPieces.size();
System.out.println("PARSING STOPPED!");
}
public void backOneStep(){
if(freshPieceIndex > 0){
freshPieceIndex--;
}
}
233
ECE 4899
Reg.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
/**
*
* @author Hell-o
*/
public class Reg extends Variable{
// private String edgeSensitivity;
Reg(String name_in)
{
name = name_in;
variableType = "reg";
variableAttribute = "";
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Reg(String name_in, String attributeIn)
{
name = name_in;
234
ECE 4899
variableType = "reg";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Reg(String name_in, String attributeIn, String vectorParent)
{
name = name_in;
variableType = "reg";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = vectorParent;
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Reg(String name_in, String attributeIn, String vectorParent, String signIn, int arraySizeIn)
{
name = name_in;
variableType = "reg";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = vectorParent;
LineNumber = Parser.currentLineNumber;
variableSign = signIn;
235
ECE 4899
arraySize = arraySizeIn;
}
Reg(String name_in, String attributeIn, String signIn, int arraySizeIn)
{
name = name_in;
variableType = "reg";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = signIn;
arraySize = arraySizeIn;
}
//
//
return edgeSensitivity;
//
//
//
if(!edgeSensitivity.equals("")){
//
return false;
//
//
edgeSensitivity = sensitive;
//
return true;
//
//
return false;
//
@Override
public String toString(){
236
ECE 4899
return variableAttribute + " " + variableType + " " + variableSign + " " +
name + "; Array Size: " + arraySize + " LINE: " + LineNumber;
}
}
237
ECE 4899
SimpleFileStore.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Deathwarror
*/
public class SimpleFileStore {
private String Name;
private ArrayList<String> Code;
private ArrayList<Error> ErrorList;
SimpleFileStore()
{
Name = "";
Code = new ArrayList();
ErrorList = new ArrayList();
}
public void setName(String name)
{
Name = name;
}
238
ECE 4899
239
ECE 4899
SubCase.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author Hell-o
*/
public class SubCase extends Block{
private ConditionStatement condition;
/*"caseBlockOrder" preserves the structureal order of statements and
* subBlocks in and always block.
* 0 - indicates an assignment statement,
* 1- indicates the presence of another subBlock
*/
private ArrayList<Integer> subCaseBlockOrder;
ECE 4899
parent = comesFrom;
LineNumber = Parser.currentLineNumber;
}
statementText="";
subCaseConditionStatementBreak!=-1
!temp.equals("##END_OF_MODULE_CODE"); ){
if(temp.equals("$#")){
parser.updateLineNumber();
temp = parser.getNextPiece();
}else if(temp.equals(":")){
if(subCaseConditionStatementBreak == 0){
subCaseConditionStatementBreak = -1;
}else {
statementText += temp+ " ";
temp = parser.getNextPiece();
}
}else if(temp.equals("[")){
241
&&
ECE 4899
subCaseConditionStatementBreak++;
statementText += temp+ " ";
temp = parser.getNextPiece();
}else if(temp.equals("]")){
subCaseConditionStatementBreak--;
statementText += temp+ " ";
temp = parser.getNextPiece();
}else {
statementText += temp+ " ";
temp = parser.getNextPiece();
}
}
sub.condition = new ConditionStatement(statementText, sub, parser);
temp = parser.getNextPiece();
// if there will be multiple sublocks or assginments
if(temp.equals("begin")){
for(temp=parser.getNextPiece();
!temp.equals("end")
!temp.equals("##END_OF_MODULE_CODE"); temp=parser.getNextPiece() ){
if(parser.pieceIsKeyword(temp)){
if(!temp.equals("always")){
parser.checkForNewBlock(sub, temp);
if(!temp.equals("$#"))
sub.subCaseBlockOrder.add(new Integer(1));
}
else{
String errorText = "Error: nested always blocks not allowed";
242
&&
ECE 4899
parser.addErrorToParserErrorList(new
Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
else if(parser.checkTaskOrFunctionName(temp)!=0){
String taskCallText = "";
ArrayList<String> taskCallElements = new ArrayList();
for(; !temp.equals(";") &&
!temp.equals("##END_OF_MODULE_CODE");
temp=parser.getNextPiece()){
taskCallText += temp+" ";
taskCallElements.add(temp);
}
sub.addVariable(new TaskCall(taskCallText,taskCallElements));
sub.subCaseBlockOrder.add(new Integer(2));
}
else if( sub.findVariableInParentBlockHierarchy(temp) !=null ||
!sub.findVectorNameInParentBlockHierarchy(temp).isEmpty()){
for(statementText=""; !temp.equals(";") && !temp.equals("##END_OF_MODULE_CODE");
temp = parser.getNextPiece()){
statementText+=temp+" ";
}
sub.addAssignment(new AssignmentStatement(statementText,sub,parser));
sub.subCaseBlockOrder.add(new Integer(0));
}
else {
parser.addInstanceOfError8UndeclaredSignal(temp);
243
ECE 4899
}
}
}else {
if(temp.equals("$#")){
parser.checkForNewBlock(sub, temp);
temp = parser.getNextPiece();
}
if(parser.pieceIsKeyword(temp)){
if(!temp.equals("always")){
parser.checkForNewBlock(sub, temp);
if(!temp.equals("$#"))
sub.subCaseBlockOrder.add(new Integer(1));
}
else{
String errorText = "Error: nested always blocks not allowed";
parser.addErrorToParserErrorList(new Error("19",errorText,Parser.getCurrentLineNumber()));
parser.stopParsing();
}
}
else if(parser.checkTaskOrFunctionName(temp)!=0){
String taskCallText = "";
ArrayList<String> taskCallElements = new ArrayList();
for(; !temp.equals(";") &&
!temp.equals("##END_OF_MODULE_CODE");
temp=parser.getNextPiece()){
taskCallText += temp+" ";
taskCallElements.add(temp);
244
ECE 4899
}
sub.addVariable(new TaskCall(taskCallText,taskCallElements));
sub.subCaseBlockOrder.add(new Integer(2));
}
else if( sub.findVariableInParentBlockHierarchy(temp)!=null ||
!sub.findVectorNameInParentBlockHierarchy(temp).isEmpty()){
for(statementText=""; !temp.equals(";") && !temp.equals("##END_OF_MODULE_CODE"); temp
= parser.getNextPiece()){
statementText+=temp+" ";
}
sub.addAssignment(new AssignmentStatement(statementText,sub,parser));
sub.subCaseBlockOrder.add(new Integer(0));
}
else {
parser.addInstanceOfError8UndeclaredSignal(temp);
parser.stopParsing();
}
}
return temp;
}
@Override
public String toString(){
String temp="";
int i=0; int subBlockCount=0; int assignmentStatementCount=0; int varsCount=0;
temp += condition.toString()+": begin \\\\LINE: "+LineNumber+
", Vars in Condition: "+condition.conditionVars.toString()+"\n";
245
ECE 4899
temp += "end\n";
return temp;
}
}
246
ECE 4899
Task.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class Task extends Block{
private ArrayList<String> taskText;
ECE 4899
String lastType="DEFAULT_NET_TYPE";
String lastAttribute = "";
Task task = new Task("task",current, temp);
current.addSubBlock(task);
for(;
!temp.equals("endtask")
temp=parser.getNextPiece()){
&&
task.taskText.add(temp);
}
}
@Override
public String toString(){
String exit="task ";
for(int i=0; i<taskText.size(); i++){
exit += taskText.get(i) + " ";
if(taskText.get(i).equals("begin")
|| taskText.get(i).equals("end")
|| taskText.get(i).equals(";") ){
exit += "\n";
}
}
return exit+"endtask\n";
}
}
248
!temp.equals("##END_OF_MODULE_CODE");
ECE 4899
TaskCall.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class TaskCall extends Variable{
String taskCallText;
ArrayList<String> taskCallElements;
ArrayList<Variable> parameterVars;
TaskCall(){
taskCallText = "";
taskCallElements = new ArrayList();
parameterVars = new ArrayList();
LineNumber = Parser.currentLineNumber;
}
TaskCall(String text, ArrayList<String> elements){
taskCallText = text;
taskCallElements = elements;
parameterVars = new ArrayList();
LineNumber = Parser.currentLineNumber;
249
ECE 4899
@Override
public String toString(){
return taskCallText +"; //Task Call LINE: "+LineNumber+"\n";
}
}
250
ECE 4899
TestError.java
package TestMain;
import java.util.Scanner;
import java.util.ArrayList;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deathwarror
*/
public class TestError {
TestError()
{
sc = new Scanner(System.in);
e = new Error();
}
public Error Default()
{
251
ECE 4899
String en = "10";
String em = "Error Msg";
ArrayList<String> ed = new ArrayList();
ed.add("Module");
ed.add("endModule");
return new Error(en,em);
}
public void start()
{
System.out.println("Error Tester:\n");
for(int i = 0;i>-1;)
{
System.out.println("-1\t quit\n"
+ "1\tBuild Error\n"
+ "2\tSet Error Number\n"
+ "3\tSet Error Message\n"
+ "4\tDuplicate Error\n"
+ "5\tCompare Errors\n"
+ "6\tPrint Primary Stored Error\n");
i = sc.nextInt();
switch(i){
case 1:
buildError();
break;
case 2:
setEN();
break;
case 3:
252
ECE 4899
setEM();
break;
case 4:
dupE();
break;
case 5:
compareE();
break;
case 6:
PrintError();
break;
default:
break;
}
}
}
public void buildError()
{
String en="";
String em="";
String read="";
ArrayList<String> ed = new ArrayList();
System.out.println("Enter Error Number");
while(en.equals(""))
{
en = sc.nextLine();
}
253
ECE 4899
ECE 4899
ECE 4899
256
ECE 4899
TestMain.java
/**
* @Author: Kenneth Hassey
* @Date:1/7/2013
* @Version: 1.000
* Function:
*
This file will be responsible for calling and running all functions and
to open, parse files, load database, test rules, and check comments.
*
*
Coders Note: This file will be the one to replace with the GUI Later on.
class functions.
*/
package TestMain;
257
ECE 4899
TestMenu()
{
sc = new Scanner(System.in);
Parser parserTest;
ArrayList<String> stringArray;// = new ArrayList();
stringArray.add( fileReaderTest.toString() );
stringArray = fileReaderTest.getCode();
parserTest = new Parser(stringArray);
error.identifyMultiplyDrivenSignals(parserTest);
258
ECE 4899
//
start();
}
private void start()
{
for(int select = 0;select > -1;)
{
System.out.println("-1\t quit\n"
+ "1\tRun Class Tester");
select = sc.nextInt();
//System.out.println(select);
if(select == 1)
{
ClassTestMenu();
}
}
}
private void ClassTestMenu()
{
TestVariable V = new TestVariable();
TestError E = new TestError();
for(int i = 0; i > -1;)
{
System.out.println("-1\t quit \n"
+ "1\tError Class Tester\n"
+ "2\tVariable Class Tester\n");
i = sc.nextInt();
switch(i)
{
259
ECE 4899
}
}
}
}
260
ECE 4899
TestVariable.java
package TestMain;
import java.util.ArrayList;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deathwarror
*/
public class TestVariable {
private Scanner sc;
private Variable v, v2;
TestVariable()
{
sc = new Scanner(System.in);
v = new Variable();
v2 = new Variable();
}
public void start()
{
System.out.println("Error Tester:\n");
for(int i = 0;i>-1;)
261
ECE 4899
{
System.out.println("-1\t quit\n"
+ "1\tBuild Variable\n"
+ "2\tSet Variable Name\n"
+ "3\tSet Variable Type\n"
+ "4\tSet Variable Edges to pos\n"
+ "5\tDuplicate Variable\n"
+ "6\tCompare Variable \n"
+ "7\tCompare Variable all fields\n"
+ "8\tAdd Edge Neg Sens to Variable\n"
+ "9\tPrint Primary Stored Error\n");
i = sc.nextInt();
switch(i){
case 1:
buildVariable();
break;
case 2:
setVN();
break;
case 3:
setVT();
break;
case 4:
setEdge();
break;
case 5:
dupV();
break;
262
ECE 4899
case 6:
compareV();
break;
case 7:
compareVAll();
break;
case 8:
addNegEdge();
break;
case 9:
PrintVar();
break;
default:
break;
}
}
}
public Variable Default()
{
String vn = "Name";
String Vt = "Reg";
ArrayList<String> el = new ArrayList();
el.add("NegEdge");
el.add("PosEdge");
return new Variable(vn,Vt,el);
}
public void buildVariable()
{
263
ECE 4899
String vn="";
String vt="";
String read="";
ArrayList<String> ed = new ArrayList();
System.out.println("Enter Variable Name");
while(vn.equals(""))
{
vn = sc.nextLine();
}
System.out.println("Enter Variable Type");
while(vt.equals(""))
{
vt = sc.nextLine();
}
for(int i = 0;i>-1; i = sc.nextInt())
{
read = "";
System.out.println("Enter Edge Sensitivity");
while(read.equals(""))
{
read = sc.nextLine();
}
ed.add(read);
System.out.println("-1\t quit\n"
+ "1\tContinue\n");
}
v = new Variable(vn,vt,ed);
}
264
ECE 4899
ECE 4899
ECE 4899
Variable.java
package TestMain;
/**
* @Author: Kenneth Hassey
* @Date: 1/7/2013
* @Version 1.000
* Function:
*
This class is designed to store all the variables that come across in
parsing of the code. This file stores Variable's name, variableType, and any
edge sensitivities.
*
*
Status: Untested.
*/
import java.util.ArrayList;
267
ECE 4899
//Default Constructor
Variable()
{
name = "";
variableType = "";
variableAttribute = "";
EdgeSens = new ArrayList();
vectorParentName = "";
variableSign = "";
arraySize = 0;
LineNumber = Parser.currentLineNumber;
}
//This constructor will most likely be used in conjuntion with the addEdge
//function because the variable variableType may edge may not be registered at first
Variable(String name_in, String type_in)
{
name = name_in;
variableType = type_in;
variableAttribute = "";
vectorParentName = "";
variableSign = "";
arraySize = 0;
LineNumber = Parser.currentLineNumber;
}
ECE 4899
name = name_in;
variableType = type_in;
variableAttribute = attributeIn;
vectorParentName = "";
variableSign = "";
arraySize = 0;
LineNumber = Parser.currentLineNumber;
}
Variable(String name_in, String type_in, String attributeIn, String sign_in, int arraySizeIn)
{
name = name_in;
variableType = type_in;
variableAttribute = attributeIn;
vectorParentName = "";
variableSign = sign_in;
arraySize = arraySizeIn;
LineNumber = Parser.currentLineNumber;
}
//This constructor can be used to allow all three data slots to be filled.
//Recommended defualt use of
//
ECE 4899
EdgeSens = Edge;
vectorParentName = "";
variableSign = "";
arraySize = 0;
LineNumber = Parser.currentLineNumber;
}
ECE 4899
ECE 4899
}
//catch false
return false;
}
272
ECE 4899
ECE 4899
}
}
}
return false;
}
//compares two variable's name and variableType for a lower level compare
public boolean compareTo(Variable V)
{
if(name.equals(V.getName()))
{
if(variableType.equals(V.getType()))
{
return true;
}
274
ECE 4899
}
return false;
}
//the "params" array list is assumed to come from the module that is currently being worked in
public static ArrayList createVariablesFromVector(Variable template, String vecStart, String vecEnd){
ArrayList<Variable> vectorVars = new ArrayList();
String temp; //parser "freshPiece" string value should currently be set to a "["
String number;
int MSB=0;
int LSB=0;
number = Parser.parseNumberFromExpression(vecStart);
if(Parser.isANumber(number)==1){
275
ECE 4899
MSB = Integer.parseInt(number);
}else{
MSB = 0;
}
number = Parser.parseNumberFromExpression(vecEnd);
if(Parser.isANumber(number)==1){
LSB = Integer.parseInt(number);
}else{
LSB = 0;
}
if(MSB < LSB){
int num = MSB; MSB = LSB; LSB = num;
}
template.variableAttribute,
return vectorVars;
}
276
template.variableAttribute,
ECE 4899
String number;
int MSB=0;
int LSB=0;
number = Parser.parseNumberFromExpression(arrayStart);
if(Parser.isANumber(number)==1){
MSB = Integer.parseInt(number);
}else{
return -1;
}
number = Parser.parseNumberFromExpression(arrayEnd);
if(Parser.isANumber(number)==1){
LSB = Integer.parseInt(number);
}else{
return -1;
}
if(MSB==0 && LSB==0)
if(MSB < LSB){
int num = MSB; MSB = LSB; LSB = num;
}
return MSB+1-LSB;
}
ECE 4899
&&
!temp.equals("##END_OF_MODULE_CODE");
pieces.add(temp);
if(temp.equals("$#")){
parser.updateLineNumber();
}
//if there is indexing present, and the signal is an array, handle it differently than a vector
else if(vars.get(0).arraySize > 1 && !arrayIndexParsed){
for(arrayIndexParsed=true, temp=parser.getNextPiece();
!temp.equals("]")
temp=parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
if(temp.equals("$#")){
parser.updateLineNumber();
}
else {
278
ECE 4899
}
arrayIndexParsed = true;
}
//this else parses the vector variables
else {
String expression = "";
for(temp=parser.getNextPiece();
(!temp.equals("]") && !temp.equals(":"))
&& !temp.equals("##END_OF_MODULE_CODE"); temp=parser.getNextPiece()){
if(temp.equals("$#")){
parser.updateLineNumber();
}
else {
pieces.add(temp);
if(Parser.isANumber(temp)==1 || AssignmentStatement.expressionPiece(temp)){
expression += temp+" ";
}
279
ECE 4899
}
startNum = Integer.parseInt(Parser.parseNumberFromExpression(expression));
expression = "";
if(temp.equals(":")){
for(temp=parser.getNextPiece();
!temp.equals("]")
temp=parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
if(temp.equals("$#")){
parser.updateLineNumber();
}
else {
pieces.add(temp);
if(Parser.isANumber(temp)==1 || AssignmentStatement.expressionPiece(temp)){
280
ECE 4899
}
}
pieces.add(temp);
}
ECE 4899
if(startNum != -1){
Variable tempVar;
if(stopNum == -1){
stopNum = startNum;
}
for(int i=stopNum; i<startNum+1; i++){
tempVar = workingBlock.findVariableInParentBlockHierarchy(varName+"_"+i);
if(tempVar != null){
varListToAddTo.add(tempVar);
}
else {
String errorText = "Error: Parser error, index of ("+varName+") might be out of bounds\n";
parser.addInstanceOfError20ParseError("20d",errorText);
parser.stopParsing();
}
}
}
else if(workingBlock.findVariableInParentBlockHierarchy(varName)==null
&& !workingBlock.findVectorNameInParentBlockHierarchy(varName).isEmpty()){
varListToAddTo.addAll(workingBlock.findVectorNameInParentBlockHierarchy(varName));
}
else if(workingBlock.findVariableInParentBlockHierarchy(varName)!=null
&& workingBlock.findVectorNameInParentBlockHierarchy(varName).isEmpty()){
varListToAddTo.add(workingBlock.findVariableInParentBlockHierarchy(varName));
}
else {
parser.addInstanceOfError20ParseError("20e","Error: unknown parser error\n\tMake sure your
design compiles in modelsim.");
282
ECE 4899
parser.stopParsing();
}
parser.setFreshPieceIndex(parser.getFreshPieceIndex()-1);
return temp;
}
public static String safelyParseVariableForAssignmentStatement(Parser parser, Block workingBlock,
AssignmentStatement statement,
String varName, ArrayList<Variable> varListToAddTo,ArrayList<Variable> arrayIndexVars){
ArrayList<Variable> vars = new ArrayList();
ArrayList<String> pieces = new ArrayList();
String temp = statement.getNextPiece();
if(workingBlock.findVariableInParentBlockHierarchy(varName) != null){
vars.add(workingBlock.findVariableInParentBlockHierarchy(varName));
}
else if(!workingBlock.findVectorNameInParentBlockHierarchy(varName).isEmpty()){
vars.addAll(workingBlock.findVectorNameInParentBlockHierarchy(varName));
}
else {
parser.addInstanceOfError8UndeclaredSignal(varName);
parser.stopParsing();
}
boolean arrayIndexParsed = false;
int startNum=-1, stopNum=-1, arrayIndex=-1;
for(; (temp.equals("[") || temp.equals("$#"))
&& !temp.equals("##END_OF_STATEMENT"); temp=statement.getNextPiece()){
pieces.add(temp);
if(temp.equals("$#")){
283
ECE 4899
temp=statement.getNextPiece();
parser.setLineNumber(Integer.parseInt(temp));
}
//if there is indexing present, and the signal is an array, handle it differently than a vector
else if(vars.get(0).arraySize > 1 && !arrayIndexParsed){
for(arrayIndexParsed=true, temp=statement.getNextPiece();
!temp.equals("]") && !temp.equals("##END_OF_STATEMENT"); ){
if(temp.equals("$#")){
temp=statement.getNextPiece();
parser.setLineNumber(Integer.parseInt(temp));
}
else {
pieces.add(temp);
if(workingBlock.findVariableInParentBlockHierarchy(temp)!=null
|| !workingBlock.findVectorNameInParentBlockHierarchy(temp).isEmpty()){
temp = Variable.safelyParseVariableForAssignmentStatement(
parser, workingBlock, statement, temp, arrayIndexVars, arrayIndexVars);
//
temp = statement.getNextPiece();
}
else if(Module.checkVariableName(temp) && Parser.isANumber(temp)==0){
parser.addInstanceOfError8UndeclaredSignal(temp);
parser.stopParsing();
}
}
if(!temp.equals("$#") && !temp.equals("]")){
temp=statement.getNextPiece();
}
}
284
ECE 4899
arrayIndexParsed = true;
}
//this else parses the vector variables
else {
String expression = "";
for(temp=statement.getNextPiece();
(!temp.equals("]") && !temp.equals(":"))
&& !temp.equals("##END_OF_STATEMENT"); temp=statement.getNextPiece()){
if(temp.equals("$#")){
temp=statement.getNextPiece();
parser.setLineNumber(Integer.parseInt(temp));
}
else {
pieces.add(temp);
if(Parser.isANumber(temp)==1 || AssignmentStatement.expressionPiece(temp)){
expression += temp+" ";
}
else if(!temp.equals(":") && !temp.equals("]")){
String errorText; String errorNum;
if(!Module.checkVariableName(temp)){
errorText = "Error: illegal token in vector bounds: ("+temp+")";
errorNum = "20b";
}
else{
errorText = "Warning: variable ("+temp+") in vector bounds:\n"
+ "\tThis will very likely not produce the results you intend.";
errorNum = "20c";
}
285
ECE 4899
}
startNum = Integer.parseInt(Parser.parseNumberFromExpression(expression));
expression = "";
if(temp.equals(":")){
for(temp=statement.getNextPiece();
!temp.equals("]")
temp=statement.getNextPiece()){
&&
!temp.equals("##END_OF_STATEMENT");
if(temp.equals("$#")){
temp=statement.getNextPiece();
parser.setLineNumber(Integer.parseInt(temp));
}
else {
pieces.add(temp);
if(Parser.isANumber(temp)==1 || AssignmentStatement.expressionPiece(temp)){
expression += temp+" ";
}
else if(!temp.equals("]")){
String errorText; String errorNum;
if(!Module.checkVariableName(temp)){
errorText = "Error: illegal token in vector bounds: ("+temp+")";
errorNum = "20b";
}
else{
errorText = "Warning: variable ("+temp+") in vector bounds:\n"
286
ECE 4899
}
}
pieces.add(temp);
}
ECE 4899
}
}
else if(workingBlock.findVariableInParentBlockHierarchy(varName)==null
&& !workingBlock.findVectorNameInParentBlockHierarchy(varName).isEmpty()){
varListToAddTo.addAll(workingBlock.findVectorNameInParentBlockHierarchy(varName));
}
else if(workingBlock.findVariableInParentBlockHierarchy(varName)!=null
&& workingBlock.findVectorNameInParentBlockHierarchy(varName).isEmpty()){
varListToAddTo.add(workingBlock.findVariableInParentBlockHierarchy(varName));
}
else {
parser.addInstanceOfError20ParseError("20e","Error: unknown parser error\n\tMake sure your
design compiles in modelsim.");
parser.stopParsing();
}
return temp;
}
ECE 4899
{
//
//
for(int i = 0; i <EdgeSens.size();i++)
//
//
System.out.println("\t"+EdgeSens.get(i));
//
return variableAttribute + " " + variableType + " " + name + " Array Size: " + arraySize + " LINE: " +
LineNumber;
}
}
289
ECE 4899
WhileLoop.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
import java.util.ArrayList;
/**
*
* @author cloud9
*/
public class WhileLoop extends Block{
private ArrayList<String> whileLoopBody;
private ArrayList<String> whileLoopHead;
ECE 4899
&&
!temp.equals("##END_OF_MODULE_CODE");
whileLoop.whileLoopHead.add(temp);
}
whileLoop.whileLoopHead.add(temp);
temp = parser.getNextPiece();
whileLoop.whileLoopBody.add(temp);
if(temp.equals("begin")){
temp = parser.getNextPiece();
for(
int
endCount=0;
(!temp.equals("end")
||
!temp.equals("##END_OF_MODULE_CODE"); temp=parser.getNextPiece()){
whileLoop.whileLoopBody.add(temp);
if(temp.equals("begin")){
endCount++;
}
else if(temp.equals("end")){
endCount--;
}
}
whileLoop.whileLoopBody.add(temp);
}else {
291
endCount!=0)
&&
ECE 4899
temp = parser.getNextPiece();
//if the while loop is not wrapped in begin/end it is assumed the loop contains
// only a single assignment statement, and not sub-blocks, this will need to
// be changed in the future if for loops are going to be legitimately used
for(;
!temp.equals(";")
temp=parser.getNextPiece()){
&&
!temp.equals("##END_OF_MODULE_CODE");
whileLoop.whileLoopBody.add(temp);
}
whileLoop.whileLoopBody.add(";");
}
}
@Override
public String toString(){
ArrayList<String> whileLoopText = whileLoopHead;
whileLoopText.addAll(whileLoopBody);
String exit="while ";
for(int i=0; i<whileLoopText.size(); i++){
exit += whileLoopText.get(i) + " ";
if(whileLoopText.get(i).equals("begin")
|| whileLoopText.get(i).equals("end")
|| whileLoopText.get(i).equals(";") ){
exit += "\n";
}
}
return exit+"\n";
}
}
292
ECE 4899
Wire.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TestMain;
/**
*
* @author Hell-o
*/
public class Wire extends Variable{
// private String edgeSensitivity;
Wire(String name_in)
{
name = name_in;
variableType = "wire";
variableAttribute = "";
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Wire(String name_in, String attributeIn)
{
name = name_in;
293
ECE 4899
variableType = "wire";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Wire(String name_in, String attributeIn, String vectorParent)
{
name = name_in;
variableType = "wire";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = vectorParent;
LineNumber = Parser.currentLineNumber;
variableSign = "";
arraySize = 0;
}
Wire(String name_in, String attributeIn, String vectorParent, String signIn, int arraySizeIn)
{
name = name_in;
variableType = "wire";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = vectorParent;
LineNumber = Parser.currentLineNumber;
variableSign = signIn;
294
ECE 4899
arraySize = arraySizeIn;
}
Wire(String name_in, String attributeIn, String signIn, int arraySizeIn)
{
name = name_in;
variableType = "wire";
variableAttribute = attributeIn;
edgeSensitivity = "";
vectorParentName = "";
LineNumber = Parser.currentLineNumber;
variableSign = signIn;
arraySize = arraySizeIn;
}
//
//
return edgeSensitivity;
//
//
//
if(!edgeSensitivity.equals("")){
//
return false;
//
//
edgeSensitivity = sensitive;
//
return true;
//
//
return false;
//
@Override
295
ECE 4899
296
ECE 4899
Version.java
//Class contains a changing current build number
//this one is used for testing
//gets remade in jars to last build date
package TestMain;
public class version {
static String version = "Build Version Here";
}
297