From a2bf4904c4bce7f5380f130d3d6f3323b6e64114 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 29 Aug 2009 08:53:44 -0700 Subject: [PATCH] Handle nets driven by C8<> constants. --- vvp/compile.cc | 36 ++---------------------------------- vvp/schedule.cc | 9 +++++++++ vvp/schedule.h | 1 + vvp/vvp_net.cc | 36 ++++++++++++++++++++++++++++++++++++ vvp/words.cc | 2 +- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/vvp/compile.cc b/vvp/compile.cc index 394fd834b..676ea5db7 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -786,7 +786,6 @@ double crstring_to_double(const char*label) void input_connect(vvp_net_t*fdx, unsigned port, char*label) { vvp_net_ptr_t ifdx = vvp_net_ptr_t(fdx, port); - char*tp; /* Is this a vvp_vector4_t constant value? */ if (c4string_test(label)) { @@ -807,40 +806,9 @@ void input_connect(vvp_net_t*fdx, unsigned port, char*label) } /* Is this a vvp_vector8_t constant value? */ - if ((strncmp(label, "C8<", 3) == 0) - && ((tp = strchr(label,'>'))) - && (tp[1] == 0) - && (strspn(label+3, "01234567xz")+3 == (unsigned)(tp-label))) { - - size_t vsize = tp-label-3; - assert(vsize%3 == 0); - vsize /= 3; - - vvp_vector8_t tmp (vsize); - - for (unsigned idx = 0 ; idx < vsize ; idx += 1) { - vvp_bit4_t bit = BIT4_Z; - unsigned dr0 = label[3+idx*3+0] - '0'; - unsigned dr1 = label[3+idx*3+1] - '0'; - - switch (label[3+idx*3+2]) { - case '0': - bit = BIT4_0; - break; - case '1': - bit = BIT4_1; - break; - case 'x': - bit = BIT4_X; - break; - case 'z': - bit = BIT4_Z; - break; - } - - tmp.set_bit(vsize-idx-1, vvp_scalar_t(bit, dr0, dr1)); - } + if (c8string_test(label)) { + vvp_vector8_t tmp = c8string_to_vector8(label); schedule_set_vector(ifdx, tmp); free(label); diff --git a/vvp/schedule.cc b/vvp/schedule.cc index 0c9f7b63a..a0b2890c8 100644 --- a/vvp/schedule.cc +++ b/vvp/schedule.cc @@ -676,6 +676,15 @@ void schedule_init_vector(vvp_net_ptr_t ptr, vvp_vector4_t bit) schedule_init_list = cur; } +void schedule_init_vector(vvp_net_ptr_t ptr, vvp_vector8_t bit) +{ + struct assign_vector8_event_s*cur = new struct assign_vector8_event_s; + cur->ptr = ptr; + cur->val = bit; + cur->next = schedule_init_list; + schedule_init_list = cur; +} + void schedule_init_vector(vvp_net_ptr_t ptr, double bit) { struct assign_real_event_s*cur = new struct assign_real_event_s; diff --git a/vvp/schedule.h b/vvp/schedule.h index 30f7bc5b5..f1c688572 100644 --- a/vvp/schedule.h +++ b/vvp/schedule.h @@ -87,6 +87,7 @@ extern void schedule_set_vector(vvp_net_ptr_t ptr, double val); * (propagated as events) through the rest of the net. */ extern void schedule_init_vector(vvp_net_ptr_t ptr, vvp_vector4_t val); +extern void schedule_init_vector(vvp_net_ptr_t ptr, vvp_vector8_t val); extern void schedule_init_vector(vvp_net_ptr_t ptr, double val); /* diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index f5d11d7ee..a15e55b77 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -2549,6 +2549,42 @@ bool c8string_test(const char*str) } return false; } +/* + * The format of a C8<> string is: + * C8 + * where aaa... is a 3 character bit descriptor. + */ +vvp_vector8_t c8string_to_vector8(const char*str) +{ + size_t vsize = strlen(str)-4; + assert(vsize%3 == 0); + vsize /= 3; + vvp_vector8_t tmp (vsize); + + for (size_t idx = 0 ; idx < vsize ; idx += 1) { + const char*cp = str+3+3*idx; + vvp_bit4_t bit = BIT4_X; + unsigned dr0 = cp[0]-'0'; + unsigned dr1 = cp[1]-'0'; + switch (cp[2]) { + case '0': + bit = BIT4_0; + break; + case '1': + bit = BIT4_1; + break; + case 'x': + bit = BIT4_X; + break; + case 'z': + bit = BIT4_Z; + break; + } + tmp.set_bit(vsize-idx-1, vvp_scalar_t(bit, dr0, dr1)); + } + + return tmp; +} ostream& operator<<(ostream&out, const vvp_vector8_t&that) { diff --git a/vvp/words.cc b/vvp/words.cc index 725031dd0..7be7dfec3 100644 --- a/vvp/words.cc +++ b/vvp/words.cc @@ -160,7 +160,7 @@ vvp_net_t* create_constant_node(const char*label, const char*val_str) if (c8string_test(val_str)) { vvp_net_t*net = new vvp_net_t; net->fun = new vvp_fun_bufz; - assert(0); // XXXX Don't know how to init a vvp_vector8_t? */ + schedule_init_vector(vvp_net_ptr_t(net,0), c8string_to_vector8(val_str)); return net; }