tgt-vvp: inform vvp about undriven constant values.

This causes tgt-vvp to use a lower case 'c' instead of an upper case
'C' as the prefix for constant values used to initialise undriven nets.

For use by the following commit.
This commit is contained in:
Martin Whitaker 2024-01-06 20:45:15 +00:00
parent af92bef64f
commit 94b443a7fe
4 changed files with 50 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2022 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2024 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -651,18 +651,20 @@ static void draw_net_input_x(ivl_nexus_t nex,
nex_data->flags |= nex_flags;
/* If the nexus has no drivers, then send a constant HiZ or
0.0 into the net. */
0.0 into the net. Use a lower case 'c' prefix for the
constant to inform vvp that this is an undriven value. */
if (ndrivers == 0) {
unsigned wid = width_of_nexus(nex);
int pull = (res == IVL_SIT_TRI0) || (res == IVL_SIT_TRI1);
/* For real nets put 0.0. */
if (signal_data_type_of_nexus(nex) == IVL_VT_REAL) {
nex_private = draw_Cr_to_string(0.0);
nex_private[0] = 'c';
} else {
unsigned jdx;
char*tmp = malloc((pull ? 3 : 1) * wid + 5);
nex_private = tmp;
strcpy(tmp, pull ? "C8<" : "C4<");
strcpy(tmp, pull ? "c8<" : "c4<");
tmp += strlen(tmp);
switch (res) {
case IVL_SIT_TRI:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2024 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -891,9 +891,20 @@ void compile_vpi_time_precision(long pre)
*
* The real value is sign * (mant ** exp).
*/
static bool crstring_header_test(const char*str)
{
if ((str[0] != 'C') && (str[0] != 'c'))
return false;
if ((str[1] != 'r') || (str[2] != '<'))
return false;
return true;
}
bool crstring_test(const char*str)
{
if (strncmp(str, "Cr<", 3) != 0) return false;
if (!crstring_header_test(str))
return false;
const char*tp = strchr(str, '>');
if (tp == 0) return false;
if (tp[1] != 0) return false;
@ -906,6 +917,8 @@ bool crstring_test(const char*str)
double crstring_to_double(const char*label)
{
assert(crstring_header_test(label));
const char*cp = label+3;
assert(*cp == 'm');
cp += 1;

View File

@ -4,7 +4,7 @@
%{
/*
* Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2024 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -263,17 +263,17 @@ static char* strdupnew(char const *str)
/* Handle some specialized constant/literals as symbols. */
"C4<"[01xz]*">" {
[Cc]"4<"[01xz]*">" {
yylval.text = strdup(yytext);
assert(yylval.text);
return T_SYMBOL; }
"C8<"[01234567xz]*">" {
[Cc]"8<"[01234567xz]*">" {
yylval.text = strdup(yytext);
assert(yylval.text);
return T_SYMBOL; }
"Cr<m"[a-f0-9]*"g"[a-f0-9]*">" {
[Cc]"r<m"[a-f0-9]*"g"[a-f0-9]*">" {
yylval.text = strdup(yytext);
assert(yylval.text);
return T_SYMBOL; }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2023 Stephen Williams (steve@icarus.com)
* Copyright (c) 2004-2024 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -2999,9 +2999,18 @@ vvp_vector4_t vector2_to_vector4(const vvp_vector2_t&that, unsigned wid)
return res;
}
static bool c4string_header_test(const char*str)
{
if ((str[0] != 'C') && (str[0] != 'c'))
return false;
if ((str[1] != '4') || (str[2] != '<'))
return false;
return true;
}
bool c4string_test(const char*str)
{
if (strncmp(str, "C4<", 3) != 0)
if (!c4string_header_test(str))
return false;
size_t value_size = strspn(str+3, "01xz");
if (str[3+value_size] != '>')
@ -3014,7 +3023,7 @@ bool c4string_test(const char*str)
vvp_vector4_t c4string_to_vector4(const char*str)
{
assert((str[0]=='C') && (str[1]=='4') && (str[2]=='<'));
assert(c4string_header_test(str));
str += 3;
const char*tp = str + strspn(str,"01xz");
@ -3186,14 +3195,21 @@ vvp_vector8_t part_expand(const vvp_vector8_t&that, unsigned wid, unsigned off)
return tmp;
}
static bool c8string_header_test(const char*str)
{
if ((str[0] != 'C') && (str[0] != 'c'))
return false;
if ((str[1] != '8') || (str[2] != '<'))
return false;
return true;
}
bool c8string_test(const char*str)
{
const char*cp;
if (str[0] != 'C') return false;
if (str[1] != '8') return false;
if (str[2] != '<') return false;
if (!c8string_header_test(str))
return false;
cp = str+3;
const char*cp = str+3;
for (;; cp += 1) {
if (cp[0] == '>' && cp[1] == 0) return true;
if (cp[0] >= '0' && cp[0] <= '9') continue;
@ -3210,6 +3226,8 @@ bool c8string_test(const char*str)
*/
vvp_vector8_t c8string_to_vector8(const char*str)
{
assert(c8string_header_test(str));
size_t vsize = strlen(str)-4;
assert(vsize%3 == 0);
vsize /= 3;