Skip to content

Commit

Permalink
[minor] Add radix-encoded int literals alt syntax
Browse files Browse the repository at this point in the history
Add radix-encoded integer literals as alternative syntax for
string-encoded integer literals.

Signed-off-by: Schuyler Eldridge <[email protected]>
  • Loading branch information
seldridge committed Jun 13, 2023
1 parent c1aa738 commit b25fcb5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions revision-history.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ revisionHistory:
# populated using the "version" that the Makefile grabs from git. Notable
# additions to the specification should append entries here.
thisVersion:
- Add radix-encoded integer literals as alternative syntax for
string-encoded integer literals.
- Add missing deprecation notice for "reg with" syntax.
# Information about the old versions. This should be static.
oldVersions:
Expand Down
48 changes: 46 additions & 2 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,43 @@ The following string-encoded integer literals all have the value `-42`:
String-encoded integer literals are usable in any place where an integer would
be unless explicitly disallowed.

### Alternative Syntax

A _radix-specified integer literal_ is a special integer literal with one of the
following leading character sequences to indicate the numerical encoding:

- `0b`{.firrtl} -- for representing binary numbers
- `0o`{.firrtl} -- for representing octal numbers
- `0d`{.firrtl} -- for representing decimal numbers
- `0h`{.firrtl} -- for representing hexadecimal numbers

Signed radix-specified integer literals have their sign _before_ the leading
character sequence.

The following radix-encoded integer literals all have the value `42`:

``` firrtl
0b101010
0o52
0d42
0h2a
```

The following radix-encoded integer literals all have the value `-42`:

``` firrtl
-0b101010
-0o52
-0d42
-0h2a
```

Radix-encoded integer literals are usable in any place where an integer would be
unless explicitly disallowed.

Radix-specified integer literals will replace string-encoded integer literals in
the 3.0.0 FIRRTL specification.

# Types

FIRRTL has three classes of types: _ground_ types, _aggregate_ types, and
Expand Down Expand Up @@ -1703,7 +1740,7 @@ by the following parameters.
written to while a read to that location is in progress.

Integer literals for the number of elements and the read/write latencies _may
not be string-encoded integer literals_.
not be string-encoded integer literals or radix-encoded integer literals_.

The following example demonstrates instantiating a memory containing 256 complex
numbers, each with 16-bit signed integer fields for its real and imaginary
Expand Down Expand Up @@ -3585,8 +3622,15 @@ int_se =
| '"' , "o" , [ "-" ] , digit_oct , { digit_oct } , '"'
| '"' , "h" , [ "-" ] , digit_hex , { digit_hex } , '"' ;
(* Radix-specified Integer Literals *)
rint =
[ "-" ] , "0b" , digit_bin , { digit_bin }
| [ "-" ] , "0o" , digit_oct , { digit_oct }
| [ "-" ] , "0d" , digit_oct , { digit_dec }
| [ "-" ] , "0h" , digit_hex , { digit_hex } ;
(* An Integer or String-encoded Integer Literal *)
int_any = int | int_se ;
int_any = int | int_se | rint ;
(* String Literals *)
string = ? a string ? ;
Expand Down

0 comments on commit b25fcb5

Please sign in to comment.