2002-05-11 06:39:35 +02:00
|
|
|
/*
|
2013-04-15 21:27:30 +02:00
|
|
|
* Copyright (c) 2002-2013 Stephen Williams (steve@icarus.com)
|
2002-05-11 06:39:35 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-05-11 06:39:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
# include "vpi_priv.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstring>
|
|
|
|
|
# include <climits>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cassert>
|
2002-05-11 06:39:35 +02:00
|
|
|
|
|
|
|
|
extern const char oct_digits[64];
|
|
|
|
|
|
2006-02-21 03:39:27 +01:00
|
|
|
void vpip_oct_str_to_vec4(vvp_vector4_t&val, const char*str)
|
2002-05-11 06:39:35 +02:00
|
|
|
{
|
2006-02-21 03:39:27 +01:00
|
|
|
unsigned str_len = strlen(str);
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
unsigned skip_chars = 0;
|
|
|
|
|
const char*tstr = str;
|
|
|
|
|
/* Find the number of non-numeric characters. */
|
2008-11-16 22:10:58 +01:00
|
|
|
while ((tstr = strpbrk(tstr, "-_"))) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
skip_chars += 1;
|
|
|
|
|
tstr += 1;
|
2006-02-21 03:39:27 +01:00
|
|
|
}
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vvp_vector4_t tval(3*(str_len-skip_chars));
|
|
|
|
|
skip_chars = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < tval.size() ; idx += 1) {
|
2006-02-21 03:39:27 +01:00
|
|
|
unsigned tmp;
|
|
|
|
|
unsigned bit_off = idx%3;
|
|
|
|
|
unsigned str_off = idx/3;
|
|
|
|
|
char ch;
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
|
|
|
|
|
assert(str_off+skip_chars < str_len);
|
|
|
|
|
/* Skip any "_" characters in the string. */
|
|
|
|
|
while ((ch = str[str_len-str_off-1-skip_chars]) == '_') {
|
|
|
|
|
skip_chars += 1;
|
|
|
|
|
assert(str_off+skip_chars < str_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we find a "-" it must be at the head of the string. */
|
|
|
|
|
if (ch == '-') assert(0);
|
2006-02-21 03:39:27 +01:00
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case '0':
|
|
|
|
|
case '1':
|
|
|
|
|
case '2':
|
|
|
|
|
case '3':
|
|
|
|
|
case '4':
|
|
|
|
|
case '5':
|
|
|
|
|
case '6':
|
|
|
|
|
case '7':
|
|
|
|
|
tmp = ch - '0';
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
tval.set_bit(idx, ((tmp>>bit_off)&1)? BIT4_1 : BIT4_0);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
|
|
|
|
case 'x':
|
2006-02-21 03:39:27 +01:00
|
|
|
case 'X':
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
tval.set_bit(idx, BIT4_X);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
2006-02-21 03:39:27 +01:00
|
|
|
case 'z':
|
|
|
|
|
case 'Z':
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
tval.set_bit(idx, BIT4_Z);
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
2006-02-21 03:39:27 +01:00
|
|
|
default:
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
/* Return "x" if there are invalid digits in the string. */
|
|
|
|
|
fprintf(stderr, "Warning: Invalid octal digit %c(%d) in "
|
|
|
|
|
"\"%s\".\n", ch, ch, str);
|
2008-12-22 17:18:01 +01:00
|
|
|
for (unsigned jdx = 0 ; jdx < val.size() ; jdx += 1) {
|
|
|
|
|
val.set_bit(jdx, BIT4_X);
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a negative value when needed. */
|
|
|
|
|
if (str[0] == '-') {
|
|
|
|
|
tval.invert();
|
|
|
|
|
tval += (int64_t) 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find the correct padding value. */
|
|
|
|
|
vvp_bit4_t pad;
|
|
|
|
|
switch (tval.value(tval.size()-1)) {
|
|
|
|
|
case BIT4_X: // Pad MSB 'x' with 'x'
|
|
|
|
|
pad = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_Z: // Pad MSB 'z' with 'z'
|
|
|
|
|
pad = BIT4_Z;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1: // If negative pad MSB '1' with '1'
|
|
|
|
|
if (str[0] == '-') {
|
|
|
|
|
pad = BIT4_1;
|
2002-05-11 06:39:35 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
default: // Everything else gets '0' padded.
|
|
|
|
|
pad = BIT4_0;
|
|
|
|
|
break;
|
2002-05-11 06:39:35 +02:00
|
|
|
}
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
|
|
|
|
|
/* Copy the temporary value to the real value, padding if needed. */
|
|
|
|
|
for (unsigned idx = 0 ; idx < val.size() ; idx += 1) {
|
|
|
|
|
if (idx < tval.size()) val.set_bit(idx, tval.value(idx));
|
|
|
|
|
else val.set_bit(idx, pad);
|
|
|
|
|
}
|
2002-05-11 06:39:35 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
void vpip_vec4_to_oct_str(const vvp_vector4_t&bits, char*buf, unsigned nbuf)
|
2005-06-13 02:54:04 +02:00
|
|
|
{
|
|
|
|
|
unsigned slen = (bits.size() + 2) / 3;
|
|
|
|
|
assert(slen < nbuf);
|
|
|
|
|
|
|
|
|
|
buf[slen] = 0;
|
|
|
|
|
|
|
|
|
|
unsigned val = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < bits.size() ; idx += 1) {
|
|
|
|
|
unsigned vs = (idx%3) * 2;
|
|
|
|
|
|
|
|
|
|
switch (bits.value(idx)) {
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
|
|
|
|
val |= 1 << vs;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_X:
|
|
|
|
|
val |= 2 << vs;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_Z:
|
|
|
|
|
val |= 3 << vs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vs == 4) {
|
|
|
|
|
slen -= 1;
|
|
|
|
|
buf[slen] = oct_digits[val];
|
|
|
|
|
val = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-16 19:43:17 +02:00
|
|
|
/* Fill in X or Z if they are the only thing in the value. */
|
|
|
|
|
switch (bits.size() % 3) {
|
|
|
|
|
case 1:
|
|
|
|
|
if (val == 2) val = 42;
|
|
|
|
|
else if (val == 3) val = 63;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (val == 10) val = 42;
|
|
|
|
|
else if (val == 15) val = 63;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-13 02:54:04 +02:00
|
|
|
if (slen > 0) {
|
|
|
|
|
slen -= 1;
|
|
|
|
|
buf[slen] = oct_digits[val];
|
|
|
|
|
}
|
|
|
|
|
}
|