Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for VHDL time units #1937

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Added TTL 74541: Octal buffers with three-state outputs
* Added TTL 74670: 4-by-4 register file with three-state outputs
* Added 16 bit floating point support for floating point arithmetic
* Added partial support for VHDL time units
* Fixed the problem of keys getting assigned to focusing on the cell of the table in "properties" section along with its actual intent

* v3.8.0 (2022-10-02)
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/com/cburch/logisim/vhdl/base/VhdlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private static Pattern regex(String pattern) {
private static final Pattern GENERICS = regex("generic");
private static final Pattern GENERIC = regex("(\\w+(?: , \\w+)*) : (\\w+)");
private static final Pattern DVALUE = regex(":= (\\w+)");
private static final Pattern UNIT = regex("(\\w+)");

private final List<PortDescription> inputs;
private final List<PortDescription> outputs;
Expand Down Expand Up @@ -287,7 +288,7 @@ private boolean parsePorts(Scanner input) throws IllegalVhdlContentException {
if (!input.next(OPENLIST)) throw new IllegalVhdlContentException(S.get("portDeclarationException"));
parsePort(input);
while (input.next(SEMICOLON)) parsePort(input);
if (!input.next(DONELIST)) throw new IllegalVhdlContentException(S.get("portDeclarationException"));
if (!input.next(DONELIST)) throw new IllegalVhdlContentException(S.get("portDeclarationException") + " before " + input.remaining());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This additional error output was very helpful in identifying the problem.

return true;
}

Expand All @@ -301,7 +302,9 @@ private void parseGeneric(Scanner input) throws IllegalVhdlContentException {
var type = input.match().group(2).trim();
if (!type.equalsIgnoreCase("integer")
&& !type.equalsIgnoreCase("natural")
&& !type.equalsIgnoreCase("positive")) {
&& !type.equalsIgnoreCase("positive")
&& !type.equalsIgnoreCase("time")
) {
throw new IllegalVhdlContentException(S.get("genericTypeException") + ": " + type);
}
type = type.toLowerCase();
Expand All @@ -319,6 +322,39 @@ private void parseGeneric(Scanner input) throws IllegalVhdlContentException {
if (type.equals("natural") && dval < 0 || type.equals("positive") && dval < 1)
throw new IllegalVhdlContentException(S.get("genericValueException") + ": " + dval);
}
if (type.equalsIgnoreCase("time")) {
if (input.next(UNIT)) {
String s = input.match().group(1);
if (s.equals("fs")) {
// default base unit, femtoseconds
}
else if (s.equals("ps")) {
dval *= 1000;
}
else if (s.equals("ns")) {
dval *= 1000000;
}
else if (s.equals("us")) {
dval *= 1000000000;
}
// these will overflow unless dval type is changed from int to long or larger
// else if (s.equals("ms")) {
// dval *= 1000000000000;
// }
// else if (s.equals("sec")) {
// dval *= 1000000000000000;
// }
// else if (s.equals("min")) {
// dval *= 60000000000000000;
// }
// else if (s.equals("hr")) {
// dval *= 3600000000000000000;
// }
else {
throw new IllegalVhdlContentException("Unrecognized time unit: " + dval);
}
}
}

for (final var name : names.split("\\s*,\\s*")) {
generics.add(new GenericDescription(name, type, dval));
Expand Down
Loading