1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
|
/*
* Copyright (c) 2006-2021 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
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* round() is ISO C99 from math.h. This define should enable it. */
# define _ISOC99_SOURCE 1
# define _SVID_SOURCE 1
# define _DEFAULT_SOURCE 1
# include "sys_priv.h"
# include <ctype.h>
# include <errno.h>
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <limits.h>
# include <assert.h>
# include "ivl_alloc.h"
/*
* The wrapper routines below get a value from either a string or a file.
* This structure is used to determine which one is used. The unused one
* must be assigned a zero value.
*/
struct byte_source {
const char *str;
FILE *fd;
};
/*
* Wrapper routine to get a byte from either a string or a file descriptor.
*/
static int byte_getc(struct byte_source *src)
{
if (src->str) {
assert(! src->fd);
if (src->str[0] == 0) return EOF;
return *(src->str)++;
}
assert(src->fd);
return fgetc(src->fd);
}
/*
* Wrapper routine to unget a byte to either a string or a file descriptor.
*/
static void byte_ungetc(struct byte_source *src, int ch)
{
if (ch == EOF) return;
if (src->str) {
assert(! src->fd);
src->str -= 1;
return;
}
assert(src->fd);
ungetc(ch, src->fd);
}
/*
* This function matches the input characters of a floating point
* number and generates a floating point (double) from that string.
*
* Do we need support for +-Inf and NaN? It's not in the standard.
*
* The match variable is set to 1 for a match or 0 for no match.
*/
static double get_float(struct byte_source *src, unsigned width, int *match)
{
char *endptr;
char *strval = malloc(1);
unsigned len = 0;
double result;
int ch;
/* Skip any leading space. */
ch = byte_getc(src);
while (isspace(ch)) ch = byte_getc(src);
/* If we are being asked for no digits then return a match fail. */
if (width == 0) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
/* Look for the optional sign. */
if ((ch == '+') || (ch == '-')) {
/* If we have a sign then the width must not be
* one since we need a sign and a digit. */
if (width == 1) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
/* Get any digits before the optional decimal point, but no more
* than width. */
while (isdigit(ch) && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
/* Get the optional decimal point and any following digits, but
* no more than width total characters are copied. */
if ((ch == '.') && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
/* Get any trailing digits. */
while (isdigit(ch) && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
}
/* No leading digits were matched. */
if ((len == 0) ||
((len == 1) && ((strval[0] == '+') || (strval[0] == '-')))) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
/* Match an exponent. */
if (((ch == 'e') || (ch == 'E')) && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
/* We must have enough space for at least one digit after
* the exponent. */
if (len == width) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
/* Check to see if the exponent has a sign. */
if ((ch == '-') || (ch == '+')) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
/* We must have enough space for at least one digit
* after the exponent sign. */
if (len == width) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
}
/* We must have at least one digit after the exponent/sign. */
if (! isdigit(ch)) {
byte_ungetc(src, ch);
free(strval);
*match = 0;
return 0.0;
}
/* Get the exponent digits, but no more than width total
* characters are copied. */
while (isdigit(ch) && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
}
strval[len] = 0;
/* Put the last character back. */
byte_ungetc(src, ch);
/* Calculate and return the result. */
result = strtod(strval, &endptr);
/* If this asserts then there is a bug in the code above.*/
assert(*endptr == 0);
free(strval);
*match = 1;
return result;
}
/*
* Routine to return a floating point value (implements %e, %f and %g).
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_float(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name,
char code)
{
vpiHandle arg;
int match;
s_vpi_value val;
double result;
/* Get the real value. */
result = get_float(src, width, &match);
/* Nothing was matched. */
if (match == 0) return 0;
/* If this match is being suppressed then return after consuming
* the digits and report that no arguments were used. */
if (suppress_flag) return -1;
/* We must have a variable to put the double value into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%%c format code.",
name, code);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Put the value into the variable. */
val.format = vpiRealVal;
val.value.real = result;
vpi_put_value(arg, &val, 0, vpiNoDelay);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a floating point value scaled and rounded to the
* current time scale and precision (implements %t).
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_float_time(vpiHandle callh, vpiHandle argv,
struct byte_source*src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle scope = vpi_handle(vpiScope, callh);
int time_units = vpi_get(vpiTimeUnit, scope);
vpiHandle arg;
int match;
s_vpi_value val;
double result;
double scale;
/* Get the raw real value. */
result = get_float(src, width, &match);
/* Nothing was matched. */
if (match == 0) return 0;
/* If this match is being suppressed then return after consuming
* the digits and report that no arguments were used. */
if (suppress_flag) return -1;
/* Round the raw value to the specified precision. Handle this
by shifting the decimal point to the precision where we want
to round, do the rounding, then shift the decimal point back */
scale = pow(10.0, timeformat_info.prec);
result = round(result*scale) / scale;
/* Scale the value from the timeformat units to the current
* timescale units. To minimize the error keep the scale an
* integer value. */
if (timeformat_info.units >= time_units) {
scale = pow(10.0, timeformat_info.units - time_units);
result *= scale;
} else {
scale = pow(10.0, time_units - timeformat_info.units);
result /= scale;
}
/* We must have a variable to put the double value into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%t format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Put the value into the variable. */
val.format = vpiRealVal;
val.value.real = result;
vpi_put_value(arg, &val, 0, vpiNoDelay);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Base routine for getting binary, octal and hex values.
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_base(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name,
const char *match, char code,
PLI_INT32 type)
{
vpiHandle arg;
char *strval = malloc(1);
unsigned len = 0;
s_vpi_value val;
int ch;
/* Skip any leading space. */
ch = byte_getc(src);
while (isspace(ch)) ch = byte_getc(src);
/* If we are being asked for no digits or the first character is
* an underscore then return a match fail. */
if ((width == 0) || (ch == '_')) {
byte_ungetc(src, ch);
free(strval);
return 0;
}
/* Get all the digits, but no more than width. */
while (strchr(match , ch) && (len < width)) {
if (ch == '?') ch = 'x';
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
strval[len] = 0;
/* Put the last character back. */
byte_ungetc(src, ch);
/* Nothing was matched. */
if (len == 0) {
free(strval);
return 0;
}
/* If this match is being suppressed then return after consuming
* the digits and report that no arguments were used. */
if (suppress_flag) {
free(strval);
return -1;
}
/* We must have a variable to put the binary value into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%%c format code.",
name, code);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
free(strval);
return 0;
}
/* Put the value into the variable. */
val.format = type;
val.value.str = strval;
vpi_put_value(arg, &val, 0, vpiNoDelay);
free(strval);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a binary value (implements %b).
*/
static int scan_format_binary(vpiHandle callh, vpiHandle argv,
struct byte_source *src, int width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
return scan_format_base(callh, argv, src, width, suppress_flag, name,
"01xzXZ?_", 'b', vpiBinStrVal);
}
/*
* Routine to return a character value (implements %c).
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_char(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle arg;
s_vpi_value val;
int ch;
/* If we are being asked for no digits then return a match fail. */
if (width == 0) return 0;
/* Get the character to return. */
ch = byte_getc(src);
/* Nothing was matched. */
if (ch == EOF) return 0;
/* If this match is being suppressed then return after consuming
* the character and report that no arguments were used. */
if (suppress_flag) return -1;
/* We must have a variable to put the character value into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%c format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Put the character into the variable. */
val.format = vpiIntVal;
val.value.integer = ch;
vpi_put_value(arg, &val, 0, vpiNoDelay);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a decimal value (implements %d).
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_decimal(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle arg;
char *strval = malloc(1);
s_vpi_value val;
int ch;
/* Skip any leading space. */
ch = byte_getc(src);
while (isspace(ch)) ch = byte_getc(src);
/* If we are being asked for no digits or the first character is
* an underscore then return a match fail. */
if ((width == 0) || (ch == '_')) {
byte_ungetc(src, ch);
free(strval);
return 0;
}
/* A decimal can match a single x/X, ? or z/Z character. */
if (strchr("xX?", ch)) {
strval = realloc(strval, 2);
strval[0] = 'x';
strval[1] = 0;
} else if (strchr("zZ", ch)) {
strval = realloc(strval, 2);
strval[0] = 'z';
strval[1] = 0;
} else {
unsigned len = 0;
/* To match a + or - we must have a digit after it. */
if (ch == '+') {
/* If we have a '+' sign then the width must not be
* one since we need a sign and a digit. */
if (width == 1) {
free(strval);
return 0;
}
ch = byte_getc(src);
if (! isdigit(ch)) {
byte_ungetc(src, ch);
free(strval);
return 0;
}
/* The '+' used up a character. */
width -= 1;
} else if (ch == '-') {
/* If we have a '-' sign then the width must not be
* one since we need a sign and a digit. */
if (width == 1) {
free(strval);
return 0;
}
ch = byte_getc(src);
if (isdigit(ch)) {
strval = realloc(strval, len+2);
strval[len++] = '-';
} else {
byte_ungetc(src, ch);
free(strval);
return 0;
}
}
/* Get all the characters, but no more than width. */
while ((isdigit(ch) || ch == '_') && (len < width)) {
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
strval[len] = 0;
/* Put the last character back. */
byte_ungetc(src, ch);
/* Nothing was matched. */
if (len == 0) {
free(strval);
return 0;
}
}
/* If this match is being suppressed then return after consuming
* the digits and report that no arguments were used. */
if (suppress_flag) {
free(strval);
return -1;
}
/* We must have a variable to put the decimal value into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%d format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
free(strval);
return 0;
}
/* Put the decimal value into the variable. */
val.format = vpiDecStrVal;
val.value.str = strval;
vpi_put_value(arg, &val, 0, vpiNoDelay);
free(strval);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a hex value (implements %h).
*/
static int scan_format_hex(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
return scan_format_base(callh, argv, src, width, suppress_flag, name,
"0123456789abcdefxzABCDEFXZ?_", 'h',
vpiHexStrVal);
}
/*
* Routine to return an octal value (implements %o).
*/
static int scan_format_octal(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
return scan_format_base(callh, argv, src, width, suppress_flag, name,
"01234567xzXZ?_", 'o', vpiOctStrVal);
}
/*
* Routine to return the current hierarchical path (implements %m).
*/
static int scan_format_module_path(vpiHandle callh, vpiHandle argv,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle scope, arg;
char *module_path;
s_vpi_value val;
/* If this format code is being suppressed then just return that no
* arguments were used. */
if (suppress_flag) return -1;
/* We must have a variable to put the hierarchical path into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%m format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Get the current hierarchical path. */
scope = vpi_handle(vpiScope, callh);
assert(scope);
module_path = vpi_get_str(vpiFullName, scope);
/* Put the hierarchical path into the variable. */
val.format = vpiStringVal;
val.value.str = module_path;
vpi_put_value(arg, &val, 0, vpiNoDelay);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a string value (implements %s).
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_string(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle arg;
char *strval = malloc(1);
unsigned len = 0;
s_vpi_value val;
int ch;
/* Skip any leading space. */
ch = byte_getc(src);
while (isspace(ch)) ch = byte_getc(src);
/* If we are being asked for no digits then return a match fail. */
if (width == 0) {
byte_ungetc(src, ch);
free(strval);
return 0;
}
/* Get all the non-space characters, but no more than width. */
while (! isspace(ch) && (len < width)) {
if (ch == EOF) break;
strval = realloc(strval, len+2);
strval[len++] = ch;
ch = byte_getc(src);
}
strval[len] = 0;
/* Nothing was matched (this can only happen at EOF). */
if (len == 0) {
assert(ch == EOF);
free(strval);
return 0;
}
/* Put the last character back. */
byte_ungetc(src, ch);
/* If this match is being suppressed then return after consuming
* the string and report that no arguments were used. */
if (suppress_flag) {
free(strval);
return -1;
}
/* We must have a variable to put the string into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%s format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
free(strval);
return 0;
}
/* Put the string into the variable. */
val.format = vpiStringVal;
val.value.str = strval;
vpi_put_value(arg, &val, 0, vpiNoDelay);
free(strval);
/* We always consume one variable if it is available. */
return 1;
}
/*
* Routine to return a two state value (implements %u).
*
* Note: Since this is a binary routine it also does not check for leading
* space characters or use space as a boundary character.
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_two_state(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle arg;
p_vpi_vecval val_ptr;
s_vpi_value val;
unsigned words, word;
PLI_INT32 varlen;
/* If we are being asked for no data then return a match fail. */
if (width == 0) return 0;
/* Since this is a binary format we do not have an ending sequence.
* Consequently we need to use the width to determine how many word
* pairs to remove from the input stream. */
if (suppress_flag) {
/* If no width was given then just remove one word pair. */
if (width == UINT_MAX) words = 1;
else words = (width+31)/32;
for (word = 0; word < words; word += 1) {
unsigned byte;
/* For a suppression we do not care about the endian order
* of the bytes. */
for (byte = 0; byte < 4; byte += 1) {
int ch = byte_getc(src);
/* See the EOF comments below for more details. */
if (ch == EOF) {
vpi_printf("WARNING: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() only found %u of %u bytes "
"needed by %%u format code.\n", name,
word*4U + byte, words*4U);
return 0;
}
}
}
return -1;
}
/* We must have a variable to put the bits into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%u format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Extract either the given number of word pairs or enough to fill
* the variable. */
varlen = (vpi_get(vpiSize, arg)+31)/32;
assert(varlen > 0);
val_ptr = (p_vpi_vecval) malloc(varlen*sizeof(s_vpi_vecval));
if (width == UINT_MAX) words = (unsigned)varlen;
else words = (width+31)/32;
for (word = 0; word < words; word += 1) {
int byte;
PLI_INT32 bits = 0;
#ifdef WORDS_BIGENDIAN
for (byte = 3; byte >= 0; byte -= 1) {
#else
for (byte = 0; byte <= 3; byte += 1) {
#endif
int ch = byte_getc(src);
/* If there is an EOF while reading the bytes then treat
* that as a non-match. It could be argued that the bytes
* should be put back, but that is not practical and since
* a binary read should be treated as an atomic operation
* it's not helpful either. An EOF while reading is an
* error in the data stream so print a message to help the
* user debug what is going wrong. The calling routine has
* already verified that there is at least one byte
* available so this message is not printed when an EOF
* occurs at a format code boundary. Which may not be an
* error in the data stream. */
if (ch == EOF) {
vpi_printf("WARNING: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() only found %d of %u bytes needed by "
"%%u format code.\n", name, word*4 +
#ifdef WORDS_BIGENDIAN
(3-byte),
#else
byte,
#endif
words*4U);
free(val_ptr);
return 0;
}
bits |= (ch & 0xff) << byte*8;
}
/* Only save the words that are in range. */
assert(varlen>=0);
if (word < (unsigned)varlen) {
val_ptr[word].aval = bits;
val_ptr[word].bval = 0;
}
}
/* Mask the upper bits to match the specified width when required. */
if (width != UINT_MAX) {
PLI_INT32 mask = UINT32_MAX >> (32U - ((width - 1U) % 32U + 1U));
val_ptr[words-1].aval &= mask;
}
/* Not enough words were read to fill the variable so zero fill the
* upper words. */
assert(varlen>=0);
if (words < (unsigned)varlen) {
for (word = words; word < (unsigned)varlen ; word += 1) {
val_ptr[word].aval = 0;
val_ptr[word].bval = 0;
}
}
/* Put the two-state value into the variable. */
val.format = vpiVectorVal;
val.value.vector = val_ptr;
vpi_put_value(arg, &val, 0, vpiNoDelay);
free(val_ptr);
/* One variable was consumed. */
return 1;
}
/*
* Routine to return a four state value (implements %z).
*
* Note: Since this is a binary routine it also does not check for leading
* space characters or use space as a boundary character.
*
* Return: 1 for a match, 0 for no match/variable and -1 for a
* suppressed match. No variable is fatal.
*/
static int scan_format_four_state(vpiHandle callh, vpiHandle argv,
struct byte_source *src, unsigned width,
unsigned suppress_flag, ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle arg;
p_vpi_vecval val_ptr;
s_vpi_value val;
unsigned words, word;
PLI_INT32 varlen;
/* If we are being asked for no data then return a match fail. */
if (width == 0) return 0;
/* Since this is a binary format we do not have an ending sequence.
* Consequently we need to use the width to determine how many word
* pairs to remove from the input stream. */
if (suppress_flag) {
/* If no width was given then just remove one word pair. */
if (width == UINT_MAX) words = 1;
else words = (width+31)/32;
for (word = 0; word < words; word += 1) {
unsigned byte;
/* For a suppression we do not care about the endian order
* of the bytes. */
for (byte = 0; byte < 8; byte += 1) {
int ch = byte_getc(src);
/* See the EOF comments below for more details. */
if (ch == EOF) {
vpi_printf("WARNING: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() only found %u of %u bytes "
"needed by %%z format code.\n", name,
word*8U + byte, words*8U);
return 0;
}
}
}
return -1;
}
/* We must have a variable to put the bits into. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() ran out of variables for %%z format code.", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* Extract either the given number of word pairs or enough to fill
* the variable. */
varlen = (vpi_get(vpiSize, arg)+31)/32;
assert(varlen > 0);
val_ptr = (p_vpi_vecval) malloc(varlen*sizeof(s_vpi_vecval));
if (width == UINT_MAX) words = (unsigned)varlen;
else words = (width+31)/32;
for (word = 0; word < words; word += 1) {
unsigned elem;
for (elem = 0; elem < 2; elem += 1) {
int byte;
PLI_INT32 bits = 0;
#ifdef WORDS_BIGENDIAN
for (byte = 3; byte >= 0; byte -= 1) {
#else
for (byte = 0; byte <= 3; byte += 1) {
#endif
int ch = byte_getc(src);
/* If there is an EOF while reading the bytes then
* treat that as a non-match. It could be argued that
* the bytes should be put back, but that is not
* practical and since a binary read should be
* treated as an atomic operation it's not helpful
* either. An EOF while reading is an error in the
* data stream so print a message to help the user
* debug what is going wrong. The calling routine has
* already verified that there is at least one byte
* available so this message is not printed when an
* EOF occurs at a format code boundary. Which may
* not be an error in the data stream. */
if (ch == EOF) {
vpi_printf("WARNING: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() only found %d of %u bytes "
"needed by %%z format code.\n", name,
word*8 + elem*4 +
#ifdef WORDS_BIGENDIAN
(3-byte),
#else
byte,
#endif
words*8U);
free(val_ptr);
return 0;
}
bits |= (ch & 0xff) << byte*8;
}
/* Only save the words that are in range. */
if (word < (unsigned)varlen) {
*(&val_ptr[word].aval+elem) = bits;
}
}
}
/* Mask the upper bits to match the specified width when required. */
if (width != UINT_MAX) {
PLI_INT32 mask = UINT32_MAX >> (32U - ((width - 1U) % 32U + 1U));
val_ptr[words-1].aval &= mask;
val_ptr[words-1].bval &= mask;
}
/* Not enough words were read to fill the variable so zero fill the
* upper words. */
assert(varlen>=0);
if (words < (unsigned)varlen) {
for (word = words; word < (unsigned)varlen ; word += 1) {
val_ptr[word].aval = 0;
val_ptr[word].bval = 0;
}
}
/* Put the four-state value into the variable. */
val.format = vpiVectorVal;
val.value.vector = val_ptr;
vpi_put_value(arg, &val, 0, vpiNoDelay);
free(val_ptr);
/* One variable was consumed. */
return 1;
}
/*
* The $fscanf and $sscanf functions are the same except for the first
* argument, which is the source. The wrapper functions below peel off
* the first argument and make a byte_source object that then gets
* passed to this function, which processes the rest of the function.
*/
static int scan_format(vpiHandle callh, struct byte_source*src, vpiHandle argv,
ICARUS_VPI_CONST PLI_BYTE8 *name)
{
s_vpi_value val;
vpiHandle item;
PLI_INT32 len, words, idx, mask;
char *fmt, *fmtp;
int rc = 0;
int ch;
int match = 1;
/* Get the format string. */
item = vpi_scan(argv);
assert(item);
/* Look for an undefined bit (X/Z) in the format string. If one is
* found just return EOF. */
len = vpi_get(vpiSize, item);
words = ((len + 31) / 32) - 1;
val.format = vpiVectorVal;
vpi_get_value(item, &val);
/* Check the full words for an undefined bit. */
for (idx = 0; idx < words; idx += 1) {
if (val.value.vector[idx].bval) {
match = 0;
rc = EOF;
break;
}
}
/* The mask is defined to be 32 bits. */
mask = UINT32_MAX >> (32U - ((len - 1U) % 32U + 1U));
/* Check the top word for an undefined bit. */
if (match && (val.value.vector[words].bval & mask)) {
match = 0;
rc = EOF;
}
/* Now get the format as a string. */
val.format = vpiStringVal;
vpi_get_value(item, &val);
fmtp = fmt = strdup(val.value.str);
/* See if we are at EOF before we even start. */
ch = byte_getc(src);
if (ch == EOF) {
rc = EOF;
match = 0;
}
byte_ungetc(src, ch);
while ( fmtp && *fmtp != 0 && match) {
if (isspace((int)*fmtp)) {
/* White space matches a string of white space in the
* input. The number of spaces is not relevant, and
* the match may be 0 or more spaces. */
while (*fmtp && isspace((int)*fmtp)) fmtp += 1;
ch = byte_getc(src);
while (isspace(ch)) ch = byte_getc(src);
byte_ungetc(src, ch);
} else if (*fmtp != '%') {
/* Characters other than % match themselves. */
ch = byte_getc(src);
if (ch != *fmtp) {
byte_ungetc(src, ch);
break;
}
fmtp += 1;
} else {
/* We are at a pattern character. The pattern has
* the format %<N>x no matter what the x code, so
* parse it generically first. */
unsigned suppress_flag = 0;
unsigned max_width = UINT_MAX;
int code = 0;
/* Look for the suppression character '*'. */
fmtp += 1;
if (*fmtp == '*') {
suppress_flag = 1;
fmtp += 1;
}
/* Look for the maximum match width. */
if (isdigit((int)*fmtp)) {
max_width = 0;
while (isdigit((int)*fmtp)) {
max_width *= 10;
max_width += *fmtp - '0';
fmtp += 1;
}
}
/* Get the format character. */
code = *fmtp;
fmtp += 1;
/* The format string is parsed:
* - max_width is the width,
* - code is the format code character,
* - suppress_flag is true if the match is to be ignored.
* Now interpret the code. */
switch (code) {
/* Read a '%' character from the input. */
case '%':
assert(max_width == -1U);
assert(suppress_flag == 0);
ch = byte_getc(src);
if (ch != '%') {
byte_ungetc(src, ch);
match = 0;
}
break;
case 'b':
match = scan_format_binary(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'c':
match = scan_format_char(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'd':
match = scan_format_decimal(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'e':
case 'f':
case 'g':
match = scan_format_float(callh, argv, src, max_width,
suppress_flag, name, code);
if (match == 1) rc += 1;
break;
case 'h':
case 'x':
match = scan_format_hex(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'm':
/* Since this code does not consume any characters
* the width makes no difference. */
match = scan_format_module_path(callh, argv,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'o':
match = scan_format_octal(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 's':
match = scan_format_string(callh, argv, src, max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 't':
match = scan_format_float_time(callh, argv, src,
max_width,
suppress_flag, name);
if (match == 1) rc += 1;
break;
case 'u':
match = scan_format_two_state(callh, argv, src,
max_width,
suppress_flag, name);
/* If a binary match fails and it is the first item
* matched then treat that as an EOF. */
if ((match == 0) && (rc == 0)) rc = EOF;
if (match == 1) rc += 1;
break;
case 'v':
vpi_printf("SORRY: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() format code '%%%c' is not "
"currently supported.\n", name, code);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
break;
case 'z':
match = scan_format_four_state(callh, argv, src,
max_width,
suppress_flag, name);
/* If a binary match fails and it is the first item
* matched then treat that as an EOF. */
if ((match == 0) && (rc == 0)) rc = EOF;
if (match == 1) rc += 1;
break;
default:
vpi_printf("ERROR: %s:%d: ",
vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s() was given an invalid format code: "
"%%%c\n", name, code);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
break;
}
}
}
/* Clean up the allocated memory. */
free(fmt);
vpi_free_object(argv);
/* Return the number of successful matches. */
val.format = vpiIntVal;
val.value.integer = rc;
vpi_put_value(callh, &val, 0, vpiNoDelay);
return 0;
}
/*
* Is the object a variable/register or a piece of one.
*/
static int is_assignable_obj(vpiHandle obj)
{
unsigned rtn = 0;
assert(obj);
switch(vpi_get(vpiType, obj)) {
/* We can not assign to a vpiNetArray. */
case vpiMemoryWord:
if (vpi_get(vpiType, vpi_handle(vpiParent, obj)) == vpiMemory) {
rtn = 1;
}
break;
case vpiPartSelect:
if (! is_assignable_obj(vpi_handle(vpiParent, obj))) break;
// fallthrough
case vpiIntegerVar:
case vpiBitVar:
case vpiByteVar:
case vpiShortIntVar:
case vpiIntVar:
case vpiLongIntVar:
case vpiRealVar:
case vpiReg:
case vpiTimeVar:
case vpiStringVar:
rtn = 1;
break;
}
return rtn;
}
static int sys_check_args(vpiHandle callh, vpiHandle argv, const PLI_BYTE8 *name)
{
vpiHandle arg;
int cnt = 3, rtn = 0;
/* The format (2nd) argument must be a string. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s requires at least three argument.\n", name);
return 1;
}
if(! is_string_obj(arg)) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s format argument must be a string.\n", name);
rtn = 1;
}
/* The rest of the arguments must be assignable. */
arg = vpi_scan(argv);
if (! arg) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s requires at least three argument.\n", name);
return 1;
}
do {
if (! is_assignable_obj(arg)) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s argument %d (a %s) is not assignable.\n",
name, cnt, vpi_get_str(vpiType, arg));
rtn = 1;
}
arg = vpi_scan(argv);
cnt += 1;
} while (arg);
return rtn;
}
static PLI_INT32 sys_fscanf_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
/* Check that there are arguments. */
if (argv == 0) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s requires at least three argument.\n", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* The first argument must be a file descriptor. */
if (! is_numeric_obj(vpi_scan(argv))) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s's first argument (fd) must be numeric.\n", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
vpi_free_object(argv);
return 0;
}
if (sys_check_args(callh, argv, name)) {
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
}
return 0;
}
static PLI_INT32 sys_fscanf_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
s_vpi_value val;
struct byte_source src;
FILE *fd;
errno = 0;
val.format = vpiIntVal;
vpi_get_value(vpi_scan(argv), &val);
fd = vpi_get_file(val.value.integer);
if (!fd) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("invalid file descriptor (0x%x) given to %s.\n",
(int)val.value.integer, name);
errno = EBADF;
val.format = vpiIntVal;
val.value.integer = EOF;
vpi_put_value(callh, &val, 0, vpiNoDelay);
vpi_free_object(argv);
return 0;
}
src.str = 0;
src.fd = fd;
scan_format(callh, &src, argv, name);
return 0;
}
static PLI_INT32 sys_sscanf_compiletf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
vpiHandle reg;
/* Check that there are arguments. */
if (argv == 0) {
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s requires at least three argument.\n", name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
return 0;
}
/* The first argument must be a register or a string. */
reg = vpi_scan(argv); /* This should never be zero. */
switch(vpi_get(vpiType, reg)) {
case vpiReg:
case vpiStringVar:
break;
case vpiConstant:
case vpiParameter:
if (vpi_get(vpiConstType, reg) == vpiStringConst) break;
// fallthrough
default:
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
(int)vpi_get(vpiLineNo, callh));
vpi_printf("%s's first argument must be a register or a string.\n",
name);
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
vpi_free_object(argv);
return 0;
}
if (sys_check_args(callh, argv, name)) {
vpip_set_return_value(1);
vpi_control(vpiFinish, 1);
}
return 0;
}
static PLI_INT32 sys_sscanf_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
s_vpi_value val;
struct byte_source src;
char *str;
val.format = vpiStringVal;
vpi_get_value(vpi_scan(argv), &val);
str = strdup(val.value.str);
src.str = str;
src.fd = 0;
scan_format(callh, &src, argv, name);
free(str);
return 0;
}
void sys_scanf_register(void)
{
s_vpi_systf_data tf_data;
vpiHandle res;
/*============================== fscanf */
tf_data.type = vpiSysFunc;
tf_data.sysfunctype = vpiIntFunc;
tf_data.tfname = "$fscanf";
tf_data.calltf = sys_fscanf_calltf;
tf_data.compiletf = sys_fscanf_compiletf;
tf_data.sizetf = 0;
tf_data.user_data = "$fscanf";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
/*============================== sscanf */
tf_data.type = vpiSysFunc;
tf_data.sysfunctype = vpiIntFunc;
tf_data.tfname = "$sscanf";
tf_data.calltf = sys_sscanf_calltf;
tf_data.compiletf = sys_sscanf_compiletf;
tf_data.sizetf = 0;
tf_data.user_data = "$sscanf";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
}
|