tgt-vvp: Avoid interleaving array ports into mux output

Currently draw_lpm_mux_nest() calls draw_net_input() while printing a
.functor statement. For array word inputs draw_net_input() emits an
.array/port statement as a side effect, which interleaves the .array/port
text into the middle of the .functor line and generates invalid VVP.

draw_lpm_substitute() has the same pattern. Collect the input labels before
starting to print the consuming statement so any side-effect output appears
as a separate statement first.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-06-20 15:29:54 -07:00
parent daadc38f18
commit a5bf5e145f
2 changed files with 13 additions and 4 deletions

View File

@ -83,10 +83,14 @@ static void draw_lpm_mux_nest(ivl_lpm_t net, const char*muxz)
net, select_input);
for (idx = 0 ; idx < ivl_lpm_size(net) ; idx += 2) {
/* draw_net_input() can emit helper statements, for example for
array words. Emit those before starting the .functor line. */
const char*input0 = draw_net_input(ivl_lpm_data(net,idx+0));
const char*input1 = draw_net_input(ivl_lpm_data(net,idx+1));
fprintf(vvp_out, "L_%p/0/%u .functor %s %u",
net, idx/2, muxz, width);
fprintf(vvp_out, ", %s", draw_net_input(ivl_lpm_data(net,idx+0)));
fprintf(vvp_out, ", %s", draw_net_input(ivl_lpm_data(net,idx+1)));
fprintf(vvp_out, ", %s", input0);
fprintf(vvp_out, ", %s", input1);
fprintf(vvp_out, ", L_%p/0s, C4<>;\n", net);
}

View File

@ -25,8 +25,13 @@
void draw_lpm_substitute(ivl_lpm_t net)
{
unsigned swidth = width_of_nexus(ivl_lpm_data(net,1));
/* draw_net_input() can emit helper statements, for example for
array words. Emit those before starting the .substitute line. */
const char*input0 = draw_net_input(ivl_lpm_data(net,0));
const char*input1 = draw_net_input(ivl_lpm_data(net,1));
fprintf(vvp_out, "L_%p .substitute %u, %u %u",
net, ivl_lpm_width(net), ivl_lpm_base(net), swidth);
fprintf(vvp_out, ", %s", draw_net_input(ivl_lpm_data(net,0)));
fprintf(vvp_out, ", %s;\n", draw_net_input(ivl_lpm_data(net,1)));
fprintf(vvp_out, ", %s", input0);
fprintf(vvp_out, ", %s;\n", input1);
}