Skip to content

Commit 084b86a

Browse files
committed
Improve binary wave form in Ascii trace render
1 parent 20a2a2e commit 084b86a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

pyrtl/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ class AsciiWaveRenderer(_WaveRendererBase):
958958
_tick = '-'
959959
_up, _down = '/', '\\'
960960
_x, _low, _high = 'x', '_', '-'
961-
_revstart, _revstop = ' ', ' '
961+
_revstart, _revstop = '', ''
962962

963963

964964
def default_renderer():

tests/test_simulation.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,50 +132,56 @@ def test_reg_to_reg_simulation(self):
132132
class RenderTraceBase(unittest.TestCase):
133133
def setUp(self):
134134
pyrtl.reset_working_block()
135-
a, b = pyrtl.input_list('a/8 b/8')
135+
a, b, c = pyrtl.input_list('a/8 b/8 c/1')
136136
o = pyrtl.Output()
137-
o <<= a + b
137+
o <<= a + b - c
138138

139139
def check_rendered_trace(self, expected, **kwargs):
140140
sim = pyrtl.Simulation()
141141
sim.step_multiple({
142142
'a': [1, 4, 9, 11, 12],
143143
'b': [2, 23, 43, 120, 0],
144+
'c': [0, 1, 1, 0, 1]
144145
})
145146
buff = io.StringIO()
146147
sim.tracer.render_trace(file=buff, render_cls=pyrtl.simulation.AsciiWaveRenderer,
147148
extra_line=False, **kwargs)
148149
self.assertEqual(buff.getvalue(), expected)
149150

151+
# TODO replace 'x' with something else (a little confusing since hex repr also uses it)
150152
def test_hex_trace(self):
151153
expected = (
152154
" -0 \n"
153-
"a 0x1 x0x4 x0x9 x0xb x0xc \n"
154-
"b 0x2 x0x17 x0x2b x0x78 x0x0 \n"
155+
"a 0x1 x0x4 x0x9 x0xb x0xc \n"
156+
"b 0x2 x0x17x0x2bx0x78x0x0 \n"
157+
"c _____/---------\____/----\n"
155158
)
156159
self.check_rendered_trace(expected)
157160

158-
def test_hex_trace(self):
161+
def test_oct_trace(self):
159162
expected = (
160163
" -0 \n"
161-
"a 0o1 x0o4 x0o11 x0o13 x0o14 \n"
162-
"b 0o2 x0o27 x0o53 x0o170 x0o0 \n"
164+
"a 0o1 x0o4 x0o11 x0o13 x0o14 \n"
165+
"b 0o2 x0o27 x0o53 x0o170x0o0 \n"
166+
"c ______/-----------\_____/-----\n"
163167
)
164168
self.check_rendered_trace(expected, repr_func=oct, symbol_len=None)
165169

166170
def test_bin_trace(self):
167171
expected = (
168172
" -0 \n"
169-
"a 0b1 x0b100 x0b1001 x0b1011 x0b1100 \n"
170-
"b 0b10 x0b10111 x0b101011 x0b1111000 x0b0 \n"
173+
"a 0b1 x0b100 x0b1001 x0b1011 x0b1100 \n"
174+
"b 0b10 x0b10111 x0b101011 x0b1111000x0b0 \n"
175+
"c __________/-------------------\_________/---------\n"
171176
)
172177
self.check_rendered_trace(expected, repr_func=bin, symbol_len=None)
173178

174179
def test_decimal_trace(self):
175180
expected = (
176181
" -0 \n"
177-
"a 1 x4 x9 x11 x12 \n"
178-
"b 2 x23 x43 x120 x0 \n"
182+
"a 1 x4 x9 x11 x12 \n"
183+
"b 2 x23 x43 x120x0 \n"
184+
"c ____/-------\___/---\n"
179185
)
180186
self.check_rendered_trace(expected, repr_func=str, symbol_len=None)
181187

@@ -217,9 +223,9 @@ class Foo(IntEnum):
217223
extra_line=None, repr_per_name={'state': Foo}, symbol_len=None)
218224
expected = (
219225
" -0 \n"
220-
" i 0x1 x0x2 x0x4 x0x8 x0x0 \n"
221-
" o 0x0 x0x1 x0x2 x0x3 \n"
222-
"state Foo.A xFoo.B xFoo.C xFoo.D \n"
226+
" i 0x1 x0x2 x0x4 x0x8 x0x0 \n"
227+
" o 0x0 x0x1 x0x2 x0x3 \n"
228+
"state Foo.A xFoo.BxFoo.CxFoo.D\n"
223229
)
224230
self.assertEqual(buff.getvalue(), expected)
225231

0 commit comments

Comments
 (0)