Commit bf6b633
MoritzScherer
[ImportVerilog][Moore] Add support for %t format specifier, introduce
This PR adds support for using the %t format specifier in format strings
by mapping them to the newly introduced `moore.fmt.time` /
`moore::TimeFormatOp` in the ImportVerilog string formatter.
According to the system verilog spec IEEE 1800-2023 § 20.4.3
"$timeformat", the exact formatting for any time value is dictated by
the last $timeformat system task invoked within the scope or parent
scopes of the format string, or alternatively, by a mix of constant
default values and
The smallest time precision argument of all the timescale compiler
directives in the source description. Because of the formatting relying
on context (who came up with this anyway? seems like a bad idea), and
use of $timeformat is permitted in conditional settings, meaning it
can't always be determined statically, I decided to not add a format
attribute to moore::FormatTimeOp. I only added the width attribute,
which may be defined in the formatter expression, e.g. %4t. Instead the
semantics for implementing moore.fmt.time should rely on querying some
global state that models the configuration set by the latest
$timeformat system call within the scope.
What's not fully clear to me is whether the System Verilog spec allows
non-"time typed" values to be formatted with %t; I didn't find an
explicit description of allowed values, but all examples in the spec I
could find explicitly use the return value of a time-typed system task
(e.g. $time) or a time-type parameter (e.g. parameter time _time =
100ns;). While it seems reasonable to suppose that also integer values
are allowed (per the spec $time returns a 64-bit integer representing
time), some examples in the doc also allow the use of $realtime
(which returns a real value) with %t, so potentially any numeric value
is allowed? In either case I didn't add this in the current
implementation and instead only allow TimeType values, which in the
context of Moore looked like the sanest option to me. Maybe someone has
a clearer view on this.moore.fmt.time (llvm#8979)1 parent 6e3b6ad commit bf6b633
File tree
3 files changed
+76
-0
lines changed- include/circt/Dialect/Moore
- lib/Conversion/ImportVerilog
- test/Conversion/ImportVerilog
3 files changed
+76
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1734 | 1734 | | |
1735 | 1735 | | |
1736 | 1736 | | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
1737 | 1758 | | |
1738 | 1759 | | |
1739 | 1760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
138 | 141 | | |
139 | 142 | | |
140 | 143 | | |
| |||
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
210 | 243 | | |
211 | 244 | | |
212 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3174 | 3174 | | |
3175 | 3175 | | |
3176 | 3176 | | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
0 commit comments