Skip to content

Commit 0e6fdae

Browse files
authored
Merge pull request #397 from pllab/ascii-waveform
Improve binary wave form in Ascii trace render
2 parents 20a2a2e + 6a927a0 commit 0e6fdae

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-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: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ 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,
@@ -150,32 +151,36 @@ def check_rendered_trace(self, expected, **kwargs):
150151
def test_hex_trace(self):
151152
expected = (
152153
" -0 \n"
153-
"a 0x1 x0x4 x0x9 x0xb x0xc \n"
154-
"b 0x2 x0x17 x0x2b x0x78 x0x0 \n"
154+
"a 0x1 x0x4 x0x9 x0xb x0xc \n"
155+
"b 0x2 x0x17x0x2bx0x78x0x0 \n"
156+
"c _____/---------\\____/----\n" # escaped backslash
155157
)
156158
self.check_rendered_trace(expected)
157159

158-
def test_hex_trace(self):
160+
def test_oct_trace(self):
159161
expected = (
160162
" -0 \n"
161-
"a 0o1 x0o4 x0o11 x0o13 x0o14 \n"
162-
"b 0o2 x0o27 x0o53 x0o170 x0o0 \n"
163+
"a 0o1 x0o4 x0o11 x0o13 x0o14 \n"
164+
"b 0o2 x0o27 x0o53 x0o170x0o0 \n"
165+
"c ______/-----------\\_____/-----\n" # escaped backslash
163166
)
164167
self.check_rendered_trace(expected, repr_func=oct, symbol_len=None)
165168

166169
def test_bin_trace(self):
167170
expected = (
168171
" -0 \n"
169-
"a 0b1 x0b100 x0b1001 x0b1011 x0b1100 \n"
170-
"b 0b10 x0b10111 x0b101011 x0b1111000 x0b0 \n"
172+
"a 0b1 x0b100 x0b1001 x0b1011 x0b1100 \n"
173+
"b 0b10 x0b10111 x0b101011 x0b1111000x0b0 \n"
174+
"c __________/-------------------\\_________/---------\n" # escaped backslash
171175
)
172176
self.check_rendered_trace(expected, repr_func=bin, symbol_len=None)
173177

174178
def test_decimal_trace(self):
175179
expected = (
176180
" -0 \n"
177-
"a 1 x4 x9 x11 x12 \n"
178-
"b 2 x23 x43 x120 x0 \n"
181+
"a 1 x4 x9 x11 x12 \n"
182+
"b 2 x23 x43 x120x0 \n"
183+
"c ____/-------\\___/---\n" # escaped backslash
179184
)
180185
self.check_rendered_trace(expected, repr_func=str, symbol_len=None)
181186

@@ -217,9 +222,9 @@ class Foo(IntEnum):
217222
extra_line=None, repr_per_name={'state': Foo}, symbol_len=None)
218223
expected = (
219224
" -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"
225+
" i 0x1 x0x2 x0x4 x0x8 x0x0 \n"
226+
" o 0x0 x0x1 x0x2 x0x3 \n"
227+
"state Foo.A xFoo.BxFoo.CxFoo.D\n"
223228
)
224229
self.assertEqual(buff.getvalue(), expected)
225230

0 commit comments

Comments
 (0)