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
|
/*
Copyright (c) 2006-2010 Trevor Williams
This program is free software; you can redistribute it and/or modify
it 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*!
\file vsignal.c
\author Trevor Williams (phase1geo@gmail.com)
\date 12/1/2001
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "defines.h"
#include "expr.h"
#include "func_unit.h"
#include "link.h"
#include "obfuscate.h"
#include "sim.h"
#include "util.h"
#include "vector.h"
#include "vsignal.h"
extern char user_msg[USER_MSG_LENGTH];
extern bool debug_mode;
/*!
Initializes the specified vsignal with the values of name, value and lsb. This
function is called by the vsignal_create routine and is also useful for
creating temporary vsignals (reduces the need for dynamic memory allocation).
for performance enhancing purposes.
*/
static void vsignal_init(
vsignal* sig, /*!< Pointer to vsignal to initialize */
char* name, /*!< Pointer to vsignal name string */
unsigned int type, /*!< Type of signal to create */
vector* value, /*!< Pointer to vsignal value */
unsigned int line, /*!< Line number that this signal is declared on */
unsigned int col /*!< Starting column that this signal is declared on */
) { PROFILE(VSIGNAL_INIT);
sig->id = 0;
sig->name = name;
sig->pdim_num = 0;
sig->udim_num = 0;
sig->dim = NULL;
sig->suppl.all = 0;
sig->suppl.part.type = type;
sig->suppl.part.col = col;
sig->value = value;
sig->line = line;
sig->exp_head = NULL;
sig->exp_tail = NULL;
PROFILE_END;
}
/*!
\returns Pointer to newly created vsignal.
This function should be called by the Verilog parser or the
database reading function. It initializes all of the necessary
values for a vsignal and returns a pointer to this newly created
vsignal.
*/
vsignal* vsignal_create(
const char* name, /*!< Full hierarchical name of this vsignal */
unsigned int type, /*!< Type of signal to create */
unsigned int width, /*!< Bit width of this vsignal */
unsigned int line, /*!< Line number that this signal is declared on */
unsigned int col /*!< Starting column that this signal is declared on */
) { PROFILE(VSIGNAL_CREATE);
vsignal* new_sig; /* Pointer to newly created vsignal */
unsigned int vtype;
new_sig = (vsignal*)malloc_safe( sizeof( vsignal ) );
/* Calculate the type */
switch( type ) {
case SSUPPL_TYPE_DECL_REAL :
case SSUPPL_TYPE_PARAM_REAL :
case SSUPPL_TYPE_IMPLICIT_REAL : vtype = VDATA_R64; break;
case SSUPPL_TYPE_DECL_SREAL :
case SSUPPL_TYPE_IMPLICIT_SREAL : vtype = VDATA_R32; break;
default : vtype = VDATA_UL; break;
}
vsignal_init( new_sig, ((name != NULL) ? strdup_safe( name ) : NULL),
type, vector_create( width, ((type == SSUPPL_TYPE_MEM) ? VTYPE_MEM : VTYPE_SIG), vtype, TRUE ), line, col );
PROFILE_END;
return( new_sig );
}
/*!
\throws anonymous expression_set_value
Calculates the signal width and creates a vector value that is
sized to match this width. This function is called during race condition checking and
functional unit element sizing function and needs to be called before expression resizing is performed.
*/
void vsignal_create_vec(
vsignal* sig /*!< Pointer to signal to create vector for */
) { PROFILE(VSIGNAL_CREATE_VEC);
unsigned int i; /* Loop iterator */
vector* vec; /* Temporary vector used for getting a vector value */
exp_link* expl; /* Pointer to current expression in signal expression list */
assert( sig != NULL );
assert( sig->value != NULL );
/* If this signal has been previously simulated, don't create a new vector */
if( !sig->value->suppl.part.set ) {
unsigned int vtype;
/* Deallocate the old memory */
vector_dealloc_value( sig->value );
/* Set the initial signal width to 1 */
sig->value->width = 1;
/* Calculate the width of the given signal */
for( i=0; i<(sig->pdim_num + sig->udim_num); i++ ) {
if( sig->dim[i].msb > sig->dim[i].lsb ) {
sig->value->width *= ((sig->dim[i].msb - sig->dim[i].lsb) + 1);
} else {
sig->value->width *= ((sig->dim[i].lsb - sig->dim[i].msb) + 1);
}
}
/* Set the endianness */
if( (sig->pdim_num + sig->udim_num) > 0 ) {
sig->suppl.part.big_endian = (sig->dim[(sig->pdim_num + sig->udim_num)-1].msb < sig->dim[(sig->pdim_num + sig->udim_num)-1].lsb) ? 1 : 0;
}
/* Figure out the vector data type to create */
switch( sig->suppl.part.type ) {
case SSUPPL_TYPE_DECL_REAL :
case SSUPPL_TYPE_PARAM_REAL :
case SSUPPL_TYPE_IMPLICIT_REAL : vtype = VDATA_R64; break;
case SSUPPL_TYPE_DECL_SREAL :
case SSUPPL_TYPE_IMPLICIT_SREAL : vtype = VDATA_R32; break;
default : vtype = VDATA_UL; break;
}
/* Create the vector and assign it to the signal */
vec = vector_create( sig->value->width, ((sig->suppl.part.type == SSUPPL_TYPE_MEM) ? VTYPE_MEM : VTYPE_SIG), vtype, TRUE );
sig->value->value.ul = vec->value.ul;
free_safe( vec, sizeof( vector ) );
/* Iterate through expression list, setting the expression to this signal */
expl = sig->exp_head;
while( expl != NULL ) {
if( (expl->exp->op != EXP_OP_FUNC_CALL) && (expl->exp->op != EXP_OP_PASSIGN) ) {
expression_set_value( expl->exp, sig, NULL );
}
expl = expl->next;
}
}
PROFILE_END;
}
/*!
\return Returns a newly allocated and initialized copy of the given signal
Duplicates the contents of the given signal with the exception of the expression list.
*/
vsignal* vsignal_duplicate(
vsignal* sig /*!< Pointer to signal to duplicate */
) { PROFILE(VSIGNAL_DUPLICATE);
vsignal* new_sig; /* Pointer to newly created vsignal */
exp_link* expl; /* Pointer to current expression link */
unsigned int i; /* Loop iterator */
assert( sig != NULL );
new_sig = (vsignal*)malloc_safe( sizeof( vsignal ) );
new_sig->name = strdup_safe( sig->name );
new_sig->suppl.all = sig->suppl.all;
new_sig->pdim_num = sig->pdim_num;
new_sig->udim_num = sig->udim_num;
new_sig->dim = NULL;
new_sig->line = sig->line;
new_sig->exp_head = NULL;
new_sig->exp_tail = NULL;
/* Copy the dimension information */
if( (sig->pdim_num + sig->udim_num) > 0 ) {
new_sig->dim = (dim_range*)malloc_safe( sizeof( dim_range ) * (sig->pdim_num + sig->udim_num) );
for( i=0; i<(sig->pdim_num + sig->udim_num); i++ ) {
new_sig->dim[i].msb = sig->dim[i].msb;
new_sig->dim[i].lsb = sig->dim[i].lsb;
}
}
/* Copy the vector value */
vector_clone( sig->value, &(new_sig->value) );
/* Copy the expression pointers */
expl = sig->exp_head;
while( expl != NULL ) {
exp_link_add( expl->exp, &(new_sig->exp_head), &(new_sig->exp_tail) );
expl = expl->next;
}
PROFILE_END;
return( new_sig );
}
/*!
Prints the vsignal information for the specified vsignal to the
specified file. This file will be the database coverage file
for this design.
*/
void vsignal_db_write(
vsignal* sig, /*!< Signal to write to file */
FILE* file /*!< Name of file to display vsignal contents to */
) { PROFILE(VSIGNAL_DB_WRITE);
unsigned int i; /* Loop iterator */
/* Don't write this vsignal if it isn't usable by Covered */
if( (sig->suppl.part.not_handled == 0) &&
(sig->value->width != 0) &&
(sig->value->width <= MAX_BIT_WIDTH) &&
(sig->suppl.part.type != SSUPPL_TYPE_GENVAR) ) {
/* Display identification and value information first */
fprintf( file, "%d %s %d %d %x %u %u",
DB_TYPE_SIGNAL,
sig->name,
sig->id,
sig->line,
sig->suppl.all,
sig->pdim_num,
sig->udim_num
);
/* Display dimension information */
for( i=0; i<(sig->pdim_num + sig->udim_num); i++ ) {
fprintf( file, " %d %d", sig->dim[i].msb, sig->dim[i].lsb );
}
fprintf( file, " " );
vector_db_write( sig->value, file, ((sig->suppl.part.type == SSUPPL_TYPE_PARAM) || (sig->suppl.part.type == SSUPPL_TYPE_PARAM_REAL) || (sig->suppl.part.type == SSUPPL_TYPE_ENUM)), SIGNAL_IS_NET( sig ) );
fprintf( file, "\n" );
}
PROFILE_END;
}
/*!
\throws anonymous Throw Throw Throw vector_db_read
Creates a new vsignal structure, parses current file line for vsignal
information and stores it to the specified vsignal. If there are any problems
in reading in the current line, returns FALSE; otherwise, returns TRUE.
*/
void vsignal_db_read(
char** line, /*!< Pointer to current line from database file to parse */
func_unit* curr_funit /*!< Pointer to current functional unit instantiating this vsignal */
) { PROFILE(VSIGNAL_DB_READ);
char name[256]; /* Name of current vsignal */
vsignal* sig; /* Pointer to the newly created vsignal */
vector* vec; /* Vector value for this vsignal */
int id; /* Signal ID */
int sline; /* Declared line number */
unsigned int pdim_num; /* Packed dimension number */
unsigned int udim_num; /* Unpacked dimension number */
dim_range* dim = NULL; /* Dimensional information */
ssuppl suppl; /* Supplemental field */
int chars_read; /* Number of characters read from line */
unsigned int i; /* Loop iterator */
/* Get name values. */
if( sscanf( *line, "%s %d %d %x %u %u%n", name, &id, &sline, &(suppl.all), &pdim_num, &udim_num, &chars_read ) == 6 ) {
*line = *line + chars_read;
/* Allocate dimensional information */
dim = (dim_range*)malloc_safe( sizeof( dim_range ) * (pdim_num + udim_num) );
Try {
/* Read in dimensional information */
i = 0;
while( i < (pdim_num + udim_num) ) {
if( sscanf( *line, " %d %d%n", &(dim[i].msb), &(dim[i].lsb), &chars_read ) == 2 ) {
*line = *line + chars_read;
} else {
print_output( "Unable to parse signal line in database file. Unable to read.", FATAL, __FILE__, __LINE__ );
Throw 0;
}
i++;
}
/* Read in vector information */
vector_db_read( &vec, line );
} Catch_anonymous {
free_safe( dim, sizeof( dim_range ) );
Throw 0;
}
/* Create new vsignal */
sig = vsignal_create( name, suppl.part.type, vec->width, sline, suppl.part.col );
sig->id = id;
sig->suppl.part.assigned = suppl.part.assigned;
sig->suppl.part.mba = suppl.part.mba;
sig->suppl.part.big_endian = suppl.part.big_endian;
sig->suppl.part.excluded = suppl.part.excluded;
sig->pdim_num = pdim_num;
sig->udim_num = udim_num;
sig->dim = dim;
/* Copy over vector value */
vector_dealloc( sig->value );
sig->value = vec;
/* Add vsignal to vsignal list */
if( curr_funit == NULL ) {
print_output( "Internal error: vsignal in database written before its functional unit", FATAL, __FILE__, __LINE__ );
Throw 0;
} else {
sig_link_add( sig, &(curr_funit->sig_head), &(curr_funit->sig_tail) );
}
} else {
print_output( "Unable to parse signal line in database file. Unable to read.", FATAL, __FILE__, __LINE__ );
Throw 0;
}
PROFILE_END;
}
/*!
\throws anonymous vector_db_merge Throw Throw
Parses specified line for vsignal information and performs merge
of the base and in vsignals, placing the resulting merged vsignal
into the base vsignal. If the vsignals are found to be unalike
(names are different), an error message is displayed to the user.
If both vsignals are the same, perform the merge on the vsignal's
vectors.
*/
void vsignal_db_merge(
vsignal* base, /*!< Signal to store result of merge into */
char** line, /*!< Pointer to line of CDD file to parse */
bool same /*!< Specifies if vsignal to merge needs to be exactly the same as the existing vsignal */
) { PROFILE(VSIGNAL_DB_MERGE);
char name[256]; /* Name of current vsignal */
int id; /* Unique ID of current signal */
int sline; /* Declared line number */
unsigned int pdim_num; /* Number of packed dimensions */
unsigned int udim_num; /* Number of unpacked dimensions */
int msb; /* MSB of current dimension being read */
int lsb; /* LSB of current dimension being read */
ssuppl suppl; /* Supplemental signal information */
int chars_read; /* Number of characters read from line */
unsigned int i; /* Loop iterator */
assert( base != NULL );
assert( base->name != NULL );
if( sscanf( *line, "%s %d %d %x %u %u%n", name, &id, &sline, &(suppl.all), &pdim_num, &udim_num, &chars_read ) == 6 ) {
*line = *line + chars_read;
if( !scope_compare( base->name, name ) || (base->pdim_num != pdim_num) || (base->udim_num != udim_num) ) {
print_output( "Attempting to merge two databases derived from different designs. Unable to merge",
FATAL, __FILE__, __LINE__ );
Throw 0;
} else {
/* Make sure that the exclude bit is merged */
base->suppl.part.excluded |= suppl.part.excluded;
i = 0;
while( (i < (pdim_num + udim_num)) && (sscanf( *line, " %d %d%n", &msb, &lsb, &chars_read ) == 2) ) {
*line = *line + chars_read;
i++;
}
if( i == (pdim_num + udim_num) ) {
/* Read in vector information */
vector_db_merge( base->value, line, same );
}
}
} else {
print_output( "Unable to parse vsignal in database file. Unable to merge.", FATAL, __FILE__, __LINE__ );
Throw 0;
}
PROFILE_END;
}
/*!
Merges two vsignals, placing the result into the base vsignal. This function is used to calculate
module coverage for the GUI.
*/
void vsignal_merge(
vsignal* base, /*!< Base vsignal that will contain the merged results */
vsignal* other /*!< Other vsignal that will be merged into the base vsignal */
) { PROFILE(VSIGNAL_MERGE);
assert( base != NULL );
assert( base->name != NULL );
assert( scope_compare( base->name, other->name ) );
//assert( base->id == other->id );
assert( base->pdim_num == other->pdim_num );
assert( base->udim_num == other->udim_num );
/* Merge the exclusion information */
base->suppl.part.excluded |= other->suppl.part.excluded;
/* Read in vector information */
vector_merge( base->value, other->value );
PROFILE_END;
}
/*!
When the specified signal in the parameter list has changed values, this function
is called to propagate the value change to the simulator to cause any statements
waiting on this value change to be resimulated.
*/
void vsignal_propagate(
vsignal* sig, /*!< Pointer to signal to propagate change information from */
const sim_time* time /*!< Current simulation time when signal changed */
) { PROFILE(VSIGNAL_PROPAGATE);
exp_link* curr_expr; /* Pointer to current expression in signal list */
/* Iterate through vsignal's expression list */
curr_expr = sig->exp_head;
while( curr_expr != NULL ) {
/* Add to simulation queue if expression is a RHS, not a function call and not a port assignment */
if( (curr_expr->exp->op != EXP_OP_FUNC_CALL) &&
(curr_expr->exp->op != EXP_OP_PASSIGN) ) {
sim_expr_changed( curr_expr->exp, time );
}
curr_expr = curr_expr->next;
}
PROFILE_END;
}
/*!
\throws anonymous vector_vcd_assign vector_vcd_assign
Assigns the associated value to the specified vsignal's vector. After this, it
iterates through its expression list, setting the TRUE and FALSE bits accordingly.
Finally, calls the simulator expr_changed function for each expression.
*/
void vsignal_vcd_assign(
vsignal* sig, /*!< Pointer to vsignal to assign VCD value to */
const char* value, /*!< String version of VCD value */
unsigned int msb, /*!< Most significant bit to assign to */
unsigned int lsb, /*!< Least significant bit to assign to */
const sim_time* time /*!< Current simulation time signal is being assigned */
) { PROFILE(VSIGNAL_VCD_ASSIGN);
bool vec_changed; /* Specifies if assigned value differed from original value */
assert( sig != NULL );
assert( sig->value != NULL );
/*
Since this signal is coming from the dumpfile, we don't expect to see values for multi-dimensional
arrays.
*/
assert( sig->udim_num == 0 );
/*
VCS seems to create funny MSB values for packed arrays, so if the pdim_num is more than 1, adjust
the MSB accordingly.
*/
if( (sig->pdim_num > 1) && (msb >= sig->value->width) ) {
msb = sig->value->width - 1;
}
#ifdef DEBUG_MODE
if( debug_mode ) {
unsigned int rv = snprintf( user_msg, USER_MSG_LENGTH, "Assigning vsignal %s[%d:%d] (lsb=%d) to value %s",
obf_sig( sig->name ), msb, lsb, sig->dim[0].lsb, value );
assert( rv < USER_MSG_LENGTH );
print_output( user_msg, DEBUG, __FILE__, __LINE__ );
}
#endif
/* Set vsignal value to specified value */
if( lsb > 0 ) {
vec_changed = vector_vcd_assign( sig->value, value, (msb - sig->dim[0].lsb), (lsb - sig->dim[0].lsb) );
} else {
vec_changed = vector_vcd_assign( sig->value, value, msb, lsb );
}
/* Don't go through the hassle of updating expressions if value hasn't changed */
if( vec_changed ) {
/* Propagate signal changes to rest of design */
vsignal_propagate( sig, time );
}
PROFILE_END;
}
/*!
Adds the specified expression to the end of this vsignal's expression
list.
*/
void vsignal_add_expression(
vsignal* sig, /*!< Pointer to vsignal to add expression to */
expression* expr /*!< Expression to add to list */
) { PROFILE(VSIGNAL_ADD_EXPRESSION);
exp_link_add( expr, &(sig->exp_head), &(sig->exp_tail) );
PROFILE_END;
}
/*!
Displays vsignal's name, dimensional info, width and value vector to the standard output.
*/
void vsignal_display(
vsignal* sig /*!< Pointer to vsignal to display to standard output */
) {
unsigned int i; /* Loop iterator */
assert( sig != NULL );
printf( " Signal => name: %s, ", obf_sig( sig->name ) );
if( sig->pdim_num > 0 ) {
printf( "packed: " );
for( i=sig->udim_num; i<(sig->pdim_num + sig->udim_num); i++ ) {
printf( "[%d:%d]", sig->dim[i].msb, sig->dim[i].lsb );
}
printf( ", " );
}
if( sig->udim_num > 0 ) {
printf( "unpacked: " );
for( i=0; i<sig->udim_num; i++ ) {
printf( "[%d:%d]", sig->dim[i].msb, sig->dim[i].lsb );
}
printf( ", " );
}
switch( sig->value->suppl.part.data_type ) {
case VDATA_UL : vector_display_value_ulong( sig->value->value.ul, sig->value->width ); break;
case VDATA_R64 : printf( "%.16lf", sig->value->value.r64->val ); break;
case VDATA_R32 : printf( "%.16f", sig->value->value.r32->val ); break;
default : assert( 0 ); break;
}
printf( "\n" );
}
/*!
\param str String version of vsignal.
\return Returns pointer to newly created vsignal structure, or returns
NULL is specified string does not properly describe a vsignal.
Converts the specified string describing a Verilog design vsignal. The
vsignal may be a standard vsignal name, a single bit select vsignal or a
multi-bit select vsignal.
*/
vsignal* vsignal_from_string(
char** str
) { PROFILE(VSIGNAL_FROM_STRING);
vsignal* sig; /* Pointer to newly created vsignal */
char name[4096]; /* Signal name */
int left; /* Left selection value of the signal */
int right; /* Right selection value of the signal */
int width; /* Width of the signal */
int big_endian = 0; /* Endianness of the signal */
int chars_read; /* Number of characters read from string */
if( sscanf( *str, "%[a-zA-Z0-9_]\[%d:%d]%n", name, &left, &right, &chars_read ) == 3 ) {
if( right > left ) {
width = (right - left) + 1;
big_endian = 1;
} else {
width = (left - right) + 1;
big_endian = 0;
}
sig = vsignal_create( name, SSUPPL_TYPE_IMPLICIT, width, 0, 0 );
sig->pdim_num = 1;
sig->dim = (dim_range*)malloc_safe( sizeof( dim_range ) * 1 );
sig->dim[0].msb = left;
sig->dim[0].lsb = right;
sig->suppl.part.big_endian = big_endian;
*str += chars_read;
} else if( sscanf( *str, "%[a-zA-Z0-9_]\[%d+:%d]%n", name, &left, &right, &chars_read ) == 3 ) {
sig = vsignal_create( name, SSUPPL_TYPE_IMPLICIT_POS, right, 0, 0 );
sig->pdim_num = 1;
sig->dim = (dim_range*)malloc_safe( sizeof( dim_range ) * 1 );
sig->dim[0].msb = left + right;
sig->dim[0].lsb = left;
*str += chars_read;
} else if( sscanf( *str, "%[a-zA-Z0-9_]\[%d-:%d]%n", name, &left, &right, &chars_read ) == 3 ) {
sig = vsignal_create( name, SSUPPL_TYPE_IMPLICIT_NEG, right, 0, 0 );
sig->pdim_num = 1;
sig->dim = (dim_range*)malloc_safe( sizeof( dim_range ) * 1 );
sig->dim[0].msb = left - right;
sig->dim[0].lsb = left;
*str += chars_read;
} else if( sscanf( *str, "%[a-zA-Z0-9_]\[%d]%n", name, &right, &chars_read ) == 2 ) {
sig = vsignal_create( name, SSUPPL_TYPE_IMPLICIT, 1, 0, 0 );
sig->pdim_num = 1;
sig->dim = (dim_range*)malloc_safe( sizeof( dim_range ) * 1 );
sig->dim[0].msb = right;
sig->dim[0].lsb = right;
*str += chars_read;
} else if( sscanf( *str, "%[a-zA-Z0-9_]%n", name, &chars_read ) == 1 ) {
sig = vsignal_create( name, SSUPPL_TYPE_IMPLICIT, 1, 0, 0 );
/* Specify that this width is unknown */
vector_dealloc_value( sig->value );
sig->value->width = 0;
sig->value->value.ul = NULL;
*str += chars_read;
} else {
sig = NULL;
}
PROFILE_END;
return( sig );
}
/*!
\param expr Pointer to expression to get width for
\param sig Pointer to signal to get width for
\return Returns width of the given expression that is bound to the given signal.
*/
int vsignal_calc_width_for_expr(
expression* expr,
vsignal* sig
) { PROFILE(VSIGNAL_CALC_WIDTH_FOR_EXPR);
int exp_dim; /* Expression dimension number */
int width = 1; /* Return value for this function */
unsigned int i; /* Loop iterator */
assert( expr != NULL );
assert( sig != NULL );
/* Get expression dimension value */
exp_dim = expression_get_curr_dimension( expr );
/* Calculate width */
for( i=(exp_dim + 1); i < (sig->pdim_num + sig->udim_num); i++ ) {
if( sig->dim[i].msb > sig->dim[i].lsb ) {
width *= (sig->dim[i].msb - sig->dim[i].lsb) + 1;
} else {
width *= (sig->dim[i].lsb - sig->dim[i].msb) + 1;
}
}
PROFILE_END;
return( width );
}
/*!
\return Returns the LSB of the given signal for the given expression.
*/
int vsignal_calc_lsb_for_expr(
expression* expr, /*!< Pointer to expression to get LSB for */
vsignal* sig, /*!< Pointer to signal to get LSB for */
int lsb_val /*!< Calculated LSB value from this expression */
) { PROFILE(VSIGNAL_CALC_LSB_FOR_EXPR);
int width = vsignal_calc_width_for_expr( expr, sig ) * lsb_val;
PROFILE_END;
return( width );
}
/*!
\param sig Pointer to vsignal to deallocate.
Deallocates all malloc'ed memory back to the heap for the specified
vsignal.
*/
void vsignal_dealloc(
/*@only@*/ vsignal* sig
) { PROFILE(VSIGNAL_DEALLOC);
exp_link* curr_expl; /* Pointer to current expression link to set to NULL */
if( sig != NULL ) {
/* Free the signal name */
free_safe( sig->name, (strlen( sig->name ) + 1) );
sig->name = NULL;
/* Free the dimension information */
free_safe( sig->dim, (sizeof( dim_range ) * (sig->pdim_num + sig->udim_num)) );
/* Free up memory for value */
vector_dealloc( sig->value );
sig->value = NULL;
/* Free up memory for expression list */
curr_expl = sig->exp_head;
while( curr_expl != NULL ) {
curr_expl->exp->sig = NULL;
curr_expl = curr_expl->next;
}
exp_link_delete_list( sig->exp_head, FALSE );
sig->exp_head = NULL;
/* Finally free up the memory for this vsignal */
free_safe( sig, sizeof( vsignal ) );
}
PROFILE_END;
}
|