Synchronize lxt_write.c and lxt2_write.c with Tony Bybell

cvs -z3 -d:pserver:anonymous@gtkwave.cvs.sourceforge.net:/cvsroot/gtkwave co -P gtkwave3
delete CVS logs embedded in files
had to add #define wave_alloca alloca to lxt2_write.h

differences remain relative to upstream .h files:
 whitespace
 value chosen for LXT*_WR_SYMPRIME

Regarding the latter, Tony writes "Don't worry about the .h file.
The only difference is a considerably larger initial hash size.
If this isn't a problem with Icarus now, it certainly doesn't
need to be bumped up."
This commit is contained in:
Larry Doolittle 2008-01-04 12:09:14 -08:00 committed by Stephen Williams
parent 25ad1c174a
commit 6c5773c0e3
3 changed files with 308 additions and 214 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2004 Tony Bybell.
* Copyright (c) 2003-2007 Tony Bybell.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -20,23 +20,28 @@
* DEALINGS IN THE SOFTWARE.
*/
#ifdef _AIX
#pragma alloca
#endif
#include <config.h>
#include "lxt2_write.h"
static char *lxt2_wr_vcd_truncate_bitvec(char *s)
{
char l, r;
char l, r;
r=*s;
if(r=='1')
if(r=='1')
{
return s;
}
}
else
{
s++;
}
for(;;s++)
{
l=r; r=*s;
@ -45,11 +50,60 @@ for(;;s++)
if(l!=r)
{
return(((l=='0')&&(r=='1'))?s:s-1);
}
}
}
}
/*
* in-place sort to keep chained facs from migrating...
*/
static void wave_mergesort(struct lxt2_wr_symbol **a, struct lxt2_wr_symbol **b, int lo, int hi)
{
int i, j, k;
if (lo<hi)
{
int mid=(lo+hi)/2;
wave_mergesort(a, b, lo, mid);
wave_mergesort(a, b, mid+1, hi);
i=0; j=lo;
while (j<=mid)
{
b[i++]=a[j++];
}
i=0; k=lo;
while ((k<j)&&(j<=hi))
{
if (strcmp(b[i]->name, a[j]->name) <= 0)
{
a[k++]=b[i++];
}
else
{
a[k++]=a[j++];
}
}
while (k<j)
{
a[k++]=b[i++];
}
}
}
static void wave_msort(struct lxt2_wr_symbol **a, int num)
{
struct lxt2_wr_symbol **b = malloc(((num/2)+1) * sizeof(struct lxt2_wr_symbol *));
wave_mergesort(a, b, 0, num-1);
free(b);
}
/************************ splay ************************/
static lxt2_wr_ds_Tree * lxt2_wr_ds_splay (granmsk_t i, lxt2_wr_ds_Tree * t) {
@ -101,7 +155,7 @@ static lxt2_wr_ds_Tree * lxt2_wr_ds_insert(granmsk_t i, lxt2_wr_ds_Tree * t, int
/* Insert i into the tree t, unless it's already there. */
/* Return a pointer to the resulting tree. */
lxt2_wr_ds_Tree * n;
n = (lxt2_wr_ds_Tree *) calloc (1, sizeof (lxt2_wr_ds_Tree));
if (n == NULL) {
fprintf(stderr, "ds_insert: ran out of memory, exiting.\n");
@ -191,7 +245,7 @@ static lxt2_wr_dslxt_Tree * lxt2_wr_dslxt_insert(char *i, lxt2_wr_dslxt_Tree * t
/* Return a pointer to the resulting tree. */
lxt2_wr_dslxt_Tree * n;
int dir;
n = (lxt2_wr_dslxt_Tree *) calloc (1, sizeof (lxt2_wr_dslxt_Tree));
if (n == NULL) {
fprintf(stderr, "dslxt_insert: ran out of memory, exiting.\n");
@ -227,7 +281,7 @@ static lxt2_wr_dslxt_Tree * lxt2_wr_dslxt_insert(char *i, lxt2_wr_dslxt_Tree * t
/*
* functions which emit various big endian
* data to a file
*/
*/
static int lxt2_wr_emit_u8(struct lxt2_wr_trace *lt, int value)
{
unsigned char buf[1];
@ -286,7 +340,7 @@ return(rc);
* data to a file. (lt->position needs to be
* fixed up on gzclose so the tables don't
* get out of sync!)
*/
*/
static int gzwrite_buffered(struct lxt2_wr_trace *lt)
{
int rc = 1;
@ -392,7 +446,7 @@ return(rc);
static int lxt2_wr_emit_stringz(struct lxt2_wr_trace *lt, char *value)
{
int rc=1;
do
do
{
rc&=lxt2_wr_emit_u8z(lt, *value);
} while(*(value++));
@ -419,7 +473,7 @@ for(p=s;*p;p++)
{
h=h^(g>>24);
h=h^g;
}
}
}
h^=h2; /* combine the two hashes */
@ -446,17 +500,17 @@ struct lxt2_wr_symbol *temp;
hv=lxt2_wr_hash(s);
if(!(temp=lt->sym[hv])) return(NULL); /* no hash entry, add here wanted to add */
while(temp)
{
if(!strcmp(temp->name,s))
{
return(temp); /* in table already */
return(temp); /* in table already */
}
if(!temp->next) break;
temp=temp->next;
}
return(NULL); /* not found, add here if you want to add*/
}
@ -481,13 +535,13 @@ if(lt->compress_fac_str)
lxt2_wr_emit_u16z(lt, i);
lxt2_wr_emit_stringz(lt, str+i);
free(lt->compress_fac_str);
}
}
else
{
lxt2_wr_emit_u16z(lt, 0);
lxt2_wr_emit_stringz(lt, str);
}
lt->compress_fac_str = (char *) malloc((lt->compress_fac_len=len)+1);
strcpy(lt->compress_fac_str, str);
}
@ -497,21 +551,6 @@ strcpy(lt->compress_fac_str, str);
* emit facs in sorted order along with geometry
* and sync table info
*/
static int lxt2_wr_compare(const void *v1, const void *v2)
{
struct lxt2_wr_symbol *s1 = *(struct lxt2_wr_symbol **)v1;
struct lxt2_wr_symbol *s2 = *(struct lxt2_wr_symbol **)v2;
int rc = strcmp(s1->name, s2->name);
if(rc)
{
return(rc);
}
else
{
return(s1->msb - s2->msb);
}
}
static void strip_brack(struct lxt2_wr_symbol *s)
{
@ -521,12 +560,17 @@ if(s->namlen<3) return;
lastch--;
while(lastch!=s->name)
{
if(*lastch=='.')
{
return; /* MTI SV [0.3] notation for implicit vars */
}
if(*lastch=='[')
{
*lastch=0x00;
*lastch=0x00;
return;
}
lastch--;
lastch--;
}
return;
}
@ -539,7 +583,7 @@ int i;
if((lt)&&(lt->numfacs))
{
struct lxt2_wr_symbol *s = lt->symchain;
struct lxt2_wr_symbol **aliascache = calloc(lt->numalias, sizeof(struct lxt2_wr_symbol *));
struct lxt2_wr_symbol **aliascache = calloc(lt->numalias ? lt->numalias : 1, sizeof(struct lxt2_wr_symbol *));
int aliases_encountered, facs_encountered;
lt->sorted_facs = (struct lxt2_wr_symbol **)calloc(lt->numfacs, sizeof(struct lxt2_wr_symbol *));
@ -549,23 +593,23 @@ if((lt)&&(lt->numfacs))
if(lt->do_strip_brackets)
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
strip_brack(s);
s=s->symchain;
}
else
else
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
s=s->symchain;
}
qsort((void *)lt->sorted_facs, lt->numfacs, sizeof(struct lxt2_wr_symbol *), lxt2_wr_compare);
}
wave_msort(lt->sorted_facs, lt->numfacs);
if(lt->partial_preference)
{
/* move preferenced facs up */
struct lxt2_wr_symbol **prefcache = aliascache;
int prefs_encountered = 0;
int prefs_encountered = 0;
facs_encountered = 0;
for(i=0;i<lt->numfacs;i++)
@ -643,7 +687,7 @@ if((lt)&&(lt->numfacs))
free(lt->compress_fac_str); lt->compress_fac_str=NULL;
lt->compress_fac_len=0;
lt->zfacname_predec_size = lt->zpackcount;
gzflush_buffered(lt, 1);
fseeko(lt->handle, 0L, SEEK_END);
lt->position=ftello(lt->handle);
@ -689,8 +733,8 @@ if((lt)&&(lt->numfacs))
}
/*
* initialize the trace and get back and lt context
/*
* initialize the trace and get back an lt context
*/
struct lxt2_wr_trace *lxt2_wr_init(const char *name)
{
@ -748,15 +792,15 @@ if(lt)
{
lt->partial = 1;
lt->partial_zip = (zipmode != 0);
lt->partial_iter = LXT2_WR_PARTIAL_SIZE;
lt->partial_iter = LXT2_WR_PARTIAL_SIZE;
}
}
void lxt2_wr_set_partial_preference(struct lxt2_wr_trace *lt, const char *name)
{
struct lxt2_wr_symbol *s;
if((lt)&&(name)&&(!lt->sorted_facs))
if((lt)&&(name)&&(!lt->sorted_facs))
{
s=lxt2_wr_symfind(lt, name);
if(s)
@ -795,8 +839,8 @@ if(lt)
/*
* set initial value of trace (0, 1, x, z) only legal vals
*/
void lxt2_wr_set_initial_value(struct lxt2_wr_trace *lt, char value)
{
void lxt2_wr_set_initial_value(struct lxt2_wr_trace *lt, char value)
{
if(lt)
{
switch(value)
@ -934,7 +978,7 @@ return(sa);
}
/*
/*
* set current time/granule updating
*/
int lxt2_wr_inc_time_by_delta(struct lxt2_wr_trace *lt, unsigned int timeval)
@ -1005,8 +1049,10 @@ for(cnt = 0; cnt < lt->break_header_size; cnt += sizeof(buf))
seg = sizeof(buf);
}
fread(buf, seg, 1, clone);
fwrite(buf, seg, 1, f2);
if(fread(buf, seg, 1, clone))
{
if(!fwrite(buf, seg, 1, f2)) break; /* write error! */
}
}
fclose(clone);
@ -1162,7 +1208,7 @@ if(using_partial)
lxt2_wr_emit_u32(lt, partial_length+9); /* size of this section (uncompressed) */
lxt2_wr_emit_u32(lt, iter); /* begin iter of section */
fflush(lt->handle);
lt->zhandle = gzdopen(dup(fileno(lt->handle)), lt->zmode);
lt->zpackcount = 0;
}
@ -1272,7 +1318,7 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
lxt2_wr_emit_u32(lt, 0); /* size of this section (uncompressed) */
lxt2_wr_emit_u32(lt, ~0); /* control section */
fflush(lt->handle);
lt->zhandle = gzdopen(dup(fileno(lt->handle)), lt->zmode);
lt->zpackcount = 0;
}
@ -1295,9 +1341,9 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
exit(255);
}
lxt2_wr_emit_stringz(lt, ds->item);
lxt2_wr_emit_stringz(lt, ds->item);
ds2 = ds->next;
free(ds->item);
free(ds->item);
free(ds);
ds = ds2;
}
@ -1323,7 +1369,7 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
#endif
dt2 = dt->next;
free(dt);
free(dt);
dt = dt2;
}
lt->mapdict_head = lt->mapdict_curr = lt->mapdict = NULL;
@ -1340,11 +1386,11 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
if(using_partial_zip)
{
off_t clen;
gzflush_buffered(lt, 1);
fseeko(lt->handle, 0L, SEEK_END);
lt->position=ftello(lt->handle);
clen = lt->position - current_iter_pos - 12;
fseeko(lt->handle, current_iter_pos, SEEK_SET);
@ -1380,7 +1426,7 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
lxt2_wr_emit_u64(lt, (lt->firsttime>>32)&0xffffffff, lt->firsttime&0xffffffff);
lxt2_wr_emit_u64(lt, (lt->lasttime>>32)&0xffffffff, lt->lasttime&0xffffffff);
/* fprintf(stderr, "start: %Ld, end %Ld\n", lt->firsttime, lt->lasttime); */
/* fprintf(stderr, "start: %lld, end %lld\n", lt->firsttime, lt->lasttime); */
lt->timegranule=0;
lt->numblock++;
@ -1408,7 +1454,7 @@ if(lt)
{
lt->bumptime = 0;
if(!lt->flush_valid)
if(!lt->flush_valid)
{
lt->timepos++;
}
@ -1416,7 +1462,7 @@ if(lt)
{
lt->flush_valid = 0;
}
if(lt->timepos == LXT2_WR_GRANULE_SIZE)
{
/* fprintf(stderr, "flushing granule to disk at time %d\n", (unsigned int)timeval); */
@ -1425,7 +1471,7 @@ if(lt)
}
/* fprintf(stderr, "updating time to %d (%d dict entries/%d bytes)\n", (unsigned int)timeval, lt->num_dict_entries, lt->dict_string_mem_required); */
lt->timetable[lt->timepos] = timeval;
lt->timetable[lt->timepos] = timeval;
lt->lasttime = timeval;
}
}
@ -1434,7 +1480,7 @@ if(lt)
lt->timeset = 1;
lt->mintime = lt->maxtime = timeval;
lt->timetable[lt->timepos] = timeval;
lt->timetable[lt->timepos] = timeval;
}
if( (!lt->timepos) && (!lt->timegranule) )
@ -1466,9 +1512,10 @@ if(lt)
}
else if (s->flags&LXT2_WR_SYM_F_DOUBLE)
{
double value;
double value = 0;
sscanf(s->value, "%lg", &value);
errno = 0;
lxt2_wr_emit_value_double(lt, s, 0, value);
}
else if (s->flags&LXT2_WR_SYM_F_STRING)
@ -1567,7 +1614,7 @@ int rc=0;
if((!lt)||(lt->blackout)||(!s)||(row)) return(rc);
if(!lt->emitted)
if(!lt->emitted)
{
lxt2_wr_emitfacs(lt);
lt->emitted = 1;
@ -1608,7 +1655,7 @@ if(s->flags&LXT2_WR_SYM_F_DOUBLE)
if(lt->dict_curr)
{
lt->dict_curr->next = lt->dict;
lt->dict_curr->next = lt->dict;
lt->dict_curr = lt->dict;
}
else
@ -1649,7 +1696,7 @@ int rc=0;
if((!lt)||(lt->blackout)||(!s)||(!value)||(row)) return(rc);
if(!lt->emitted)
if(!lt->emitted)
{
lxt2_wr_emitfacs(lt);
lt->emitted = 1;
@ -1688,7 +1735,7 @@ if(s->flags&LXT2_WR_SYM_F_STRING)
if(lt->dict_curr)
{
lt->dict_curr->next = lt->dict;
lt->dict_curr->next = lt->dict;
lt->dict_curr = lt->dict;
}
else
@ -1733,7 +1780,7 @@ int i;
if((!lt)||(lt->blackout)||(!s)||(!value)||(!*value)||(row)) return(rc);
if(!lt->emitted)
if(!lt->emitted)
{
lxt2_wr_emitfacs(lt);
lt->emitted = 1;
@ -1752,13 +1799,13 @@ while(s->aliased_to) /* find root alias if exists */
valuelen = strlen(value); /* ensure string is proper length */
if(valuelen == s->len)
{
vfix = alloca(s->len+1);
vfix = wave_alloca(s->len+1);
strcpy(vfix, value);
value = vfix;
}
else
{
vfix = alloca(s->len+1);
vfix = wave_alloca(s->len+1);
if(valuelen < s->len)
{
@ -1798,12 +1845,12 @@ if(!(s->flags&(LXT2_WR_SYM_F_DOUBLE|LXT2_WR_SYM_F_STRING)))
prevch = *vpnt;
while(*vpnt)
{
if(prevch == *vpnt)
if(prevch == *vpnt)
{
vpnt++;
}
else
{
{
prevch = 0;
break;
}
@ -1910,7 +1957,7 @@ idxchk: if(idx<0)
if(lt->dict_curr)
{
lt->dict_curr->next = lt->dict;
lt->dict_curr->next = lt->dict;
lt->dict_curr = lt->dict;
}
else
@ -1958,30 +2005,33 @@ struct lxt2_wr_symbol *s;
if((lt)&&(!lt->blackout))
{
if(!lt->emitted)
if(!lt->emitted)
{
lxt2_wr_emitfacs(lt);
lt->emitted = 1;
if(!lt->timeset)
{
lxt2_wr_set_time(lt, 0);
}
}
}
s = lt->symchain;
while(s)
{
if((s->msk & (LXT2_WR_GRAN_1VAL<<lt->timepos)) == LXT2_WR_GRAN_0VAL)
if(!(s->flags&LXT2_WR_SYM_F_ALIAS))
{
s->msk |= (LXT2_WR_GRAN_1VAL<<lt->timepos);
s->chg[s->chgpos] = LXT2_WR_ENC_BLACKOUT;
s->chgpos++;
}
else
{
s->chg[s->chgpos-1] = LXT2_WR_ENC_BLACKOUT;
if((s->msk & (LXT2_WR_GRAN_1VAL<<lt->timepos)) == LXT2_WR_GRAN_0VAL)
{
s->msk |= (LXT2_WR_GRAN_1VAL<<lt->timepos);
s->chg[s->chgpos] = LXT2_WR_ENC_BLACKOUT;
s->chgpos++;
}
else
{
s->chg[s->chgpos-1] = LXT2_WR_ENC_BLACKOUT;
}
}
s=s->symchain;
@ -2006,26 +2056,29 @@ if((lt)&&(lt->blackout))
s = lt->symchain;
while(s)
{
if(s->flags&LXT2_WR_SYM_F_DOUBLE)
{
free(s->value);
s->value = strdup("0"); /* will cause mismatch then flush */
}
else
{
if(!(s->flags&LXT2_WR_SYM_F_STRING))
{
s->value[0] = '-'; /* will cause mismatch then flush */
for(i=1;i<s->len;i++)
{
s->value[i] = 'x'; /* initial value */
}
s->value[i]=0;
}
else
{
if(!(s->flags&LXT2_WR_SYM_F_ALIAS))
{
if(s->flags&LXT2_WR_SYM_F_DOUBLE)
{
free(s->value);
s->value = calloc(1, 1*sizeof(char));
s->value = strdup("0"); /* will cause mismatch then flush */
}
else
{
if(!(s->flags&LXT2_WR_SYM_F_STRING))
{
s->value[0] = '-'; /* will cause mismatch then flush */
for(i=1;i<s->len;i++)
{
s->value[i] = 'x'; /* initial value */
}
s->value[i]=0;
}
else
{
free(s->value);
s->value = calloc(1, 1*sizeof(char));
}
}
}
@ -2094,7 +2147,7 @@ if(lt)
{
struct lxt2_wr_symbol *s = lt->symchain;
struct lxt2_wr_symbol *s2;
while(s)
{
if(s->name) { free(s->name); }
@ -2106,7 +2159,8 @@ if(lt)
lt->symchain=NULL;
}
free(lt->lxtname);
free(lt->sorted_facs);
fclose(lt->handle);
free(lt);

View File

@ -37,6 +37,7 @@
#define ftello ftell
#endif
#define wave_alloca alloca
#define LXT2_WR_HDRID (0x1380)
#define LXT2_WR_VERSION (0x0001)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-3 Tony Bybell.
* Copyright (c) 2001-7 Tony Bybell.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -20,8 +20,58 @@
* DEALINGS IN THE SOFTWARE.
*/
#include <config.h>
#include "lxt_write.h"
/*
* in-place sort to keep chained facs from migrating...
*/
static void wave_mergesort(struct lt_symbol **a, struct lt_symbol **b, int lo, int hi)
{
int i, j, k;
if (lo<hi)
{
int mid=(lo+hi)/2;
wave_mergesort(a, b, lo, mid);
wave_mergesort(a, b, mid+1, hi);
i=0; j=lo;
while (j<=mid)
{
b[i++]=a[j++];
}
i=0; k=lo;
while ((k<j)&&(j<=hi))
{
if (strcmp(b[i]->name, a[j]->name) <= 0)
{
a[k++]=b[i++];
}
else
{
a[k++]=a[j++];
}
}
while (k<j)
{
a[k++]=b[i++];
}
}
}
static void wave_msort(struct lt_symbol **a, int num)
{
struct lt_symbol **b = malloc(((num/2)+1) * sizeof(struct lt_symbol *));
wave_mergesort(a, b, 0, num-1);
free(b);
}
/************************ splay ************************/
static int dslxt_success;
@ -82,7 +132,7 @@ static dslxt_Tree * dslxt_insert(char *i, dslxt_Tree * t, unsigned int val) {
/* Return a pointer to the resulting tree. */
dslxt_Tree * n;
int dir;
n = (dslxt_Tree *) calloc (1, sizeof (dslxt_Tree));
if (n == NULL) {
fprintf(stderr, "dslxt_insert: ran out of memory, exiting.\n");
@ -140,7 +190,7 @@ static dslxt_Tree * dslxt_delete(char *i, dslxt_Tree * t) {
/*
* functions which emit various big endian
* data to a file
*/
*/
static int lt_emit_u8(struct lt_trace *lt, int value)
{
unsigned char buf[1];
@ -221,7 +271,7 @@ return(nmemb);
static int lt_emit_string(struct lt_trace *lt, char *value)
{
int rc=1;
do
do
{
rc&=lt_emit_u8(lt, *value);
} while(*(value++));
@ -234,7 +284,7 @@ return(rc);
* data to a file. (lt->position needs to be
* fixed up on gzclose so the tables don't
* get out of sync!)
*/
*/
static int lt_emit_u8z(struct lt_trace *lt, int value)
{
unsigned char buf[1];
@ -321,7 +371,7 @@ return(nmemb);
static int lt_emit_stringz(struct lt_trace *lt, char *value)
{
int rc=1;
do
do
{
rc&=lt_emit_u8z(lt, *value);
} while(*(value++));
@ -333,7 +383,7 @@ return(rc);
* data to a file. (lt->position needs to be
* fixed up on BZ2_bzclose so the tables don't
* get out of sync!)
*/
*/
static int lt_emit_u8bz(struct lt_trace *lt, int value)
{
unsigned char buf[1];
@ -420,7 +470,7 @@ return(nmemb);
static int lt_emit_stringbz(struct lt_trace *lt, char *value)
{
int rc=1;
do
do
{
rc&=lt_emit_u8bz(lt, *value);
} while(*(value++));
@ -487,7 +537,7 @@ for(p=s;*p;p++)
{
h=h^(g>>24);
h=h^g;
}
}
}
h^=h2; /* combine the two hashes */
@ -514,17 +564,17 @@ struct lt_symbol *temp;
hv=lt_hash(s);
if(!(temp=lt->sym[hv])) return(NULL); /* no hash entry, add here wanted to add */
while(temp)
{
if(!strcmp(temp->name,s))
{
return(temp); /* in table already */
return(temp); /* in table already */
}
if(!temp->next) break;
temp=temp->next;
}
return(NULL); /* not found, add here if you want to add*/
}
@ -549,38 +599,18 @@ if(lt->compress_fac_str)
lt_emit_u16z(lt, i);
lt_emit_stringz(lt, str+i);
free(lt->compress_fac_str);
}
}
else
{
lt_emit_u16z(lt, 0);
lt_emit_stringz(lt, str);
}
lt->compress_fac_str = (char *) malloc((lt->compress_fac_len=len)+1);
strcpy(lt->compress_fac_str, str);
}
/*
* emit facs in sorted order along with geometry
* and sync table info
*/
static int lt_compare(const void *v1, const void *v2)
{
struct lt_symbol *s1 = *(struct lt_symbol **)v1;
struct lt_symbol *s2 = *(struct lt_symbol **)v2;
int rc = strcmp(s1->name, s2->name);
if(rc)
{
return(rc);
}
else
{
return(s1->msb - s2->msb);
}
}
static void strip_brack(struct lt_symbol *s)
{
char *lastch = s->name+s->namlen - 1;
@ -589,12 +619,17 @@ if(s->namlen<3) return;
lastch--;
while(lastch!=s->name)
{
if(*lastch=='.')
{
return; /* MTI SV [0.3] notation for implicit vars */
}
if(*lastch=='[')
{
*lastch=0x00;
*lastch=0x00;
return;
}
lastch--;
lastch--;
}
return;
}
@ -616,17 +651,17 @@ if((lt)&&(lt->numfacs))
if(lt->do_strip_brackets)
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
strip_brack(s);
s=s->symchain;
}
else
else
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing*/
s=s->symchain;
}
qsort((void *)lt->sorted_facs, lt->numfacs, sizeof(struct lt_symbol *), lt_compare);
}
wave_msort(lt->sorted_facs, lt->numfacs);
for(i=0;i<lt->numfacs;i++)
{
@ -653,7 +688,7 @@ if((lt)&&(lt->numfacs))
free(lt->compress_fac_str); lt->compress_fac_str=NULL;
lt->compress_fac_len=0;
lt->zfacname_predec_size = lt->zpackcount;
gzclose(lt->zhandle);
fseeko(lt->handle, 0L, SEEK_END);
lt->position=ftello(lt->handle);
@ -688,13 +723,13 @@ if((lt)&&(lt->numfacs))
if(is_interlaced_trace)
{
lt->zhandle = gzdopen(dup(fileno(lt->handle)), "wb9");
lt->sync_table_offset = lt->position;
for(i=0;i<lt->numfacs;i++)
{
lt_emit_u32z(lt, lt->sorted_facs[i]->last_change);
}
gzclose(lt->zhandle); lt->zhandle = NULL;
fseeko(lt->handle, 0L, SEEK_END);
lt->position=ftello(lt->handle);
@ -705,7 +740,7 @@ if((lt)&&(lt->numfacs))
}
/*
/*
* initialize the trace and get back an lt context
*/
struct lt_trace *lt_init(const char *name)
@ -831,7 +866,7 @@ switch(numbytes_trans&3)
case 3: lt->lt_emit_u32(lt, numtrans); break;
}
/* printf("Clock finish for '%s' at %Ld ending with '%c' for %d repeats over a switch delta of %d\n",
/* printf("Clock finish for '%s' at %lld ending with '%c' for %d repeats over a switch delta of %d\n",
s->name, lt->timeval, s->clk_prevval, s->clk_numtrans - LT_CLKPACK, s->clk_delta); */
s->clk_prevtrans = ULLDescriptor(~0);
s->clk_numtrans = 0;
@ -932,7 +967,7 @@ switch(numbytes_trans&3)
case 3: lt->lt_emit_u32(lt, numtrans); break;
}
/* printf("Clock finish for '%s' at %Ld ending with '%08x' for %d repeats over a switch delta of %Ld\n",
/* printf("Clock finish for '%s' at %lld ending with '%08x' for %d repeats over a switch delta of %lld\n",
s->name, lt->timeval, s->clk_prevval, s->clk_numtrans - LT_CLKPACK_M, s->clk_delta); */
s->clk_prevtrans = ULLDescriptor(~0);
s->clk_numtrans = 0;
@ -1000,7 +1035,7 @@ for(i=0;i<lt->num_dict_entries;i++)
/* fprintf(stderr, "%8d) '%s'\n", ds->val, ds->item); */
lt_emit_stringz(lt, ds->item+1);
}
gzclose(lt->zhandle);
fseeko(lt->handle, 0L, SEEK_END);
lt->position=ftello(lt->handle);
@ -1037,13 +1072,13 @@ if(lt)
if(s->clk_numtrans > LT_CLKPACK_M) lt_flushclock_m(lt, s);
}
else
{
{
if(s->clk_numtrans > LT_CLKPACK) lt_flushclock(lt, s);
}
}
s=s->symchain;
}
}
lt_set_dumpon(lt); /* in case it was turned off */
@ -1101,7 +1136,7 @@ if(lt)
while(t)
{
lt_emit_u32z(lt, t->position - lastposition); lastposition = t->position;
t=t->next;
t=t->next;
}
t=lt->timehead;
@ -1111,9 +1146,9 @@ if(lt)
{
lxttime_t delta = t->timeval - lasttime;
lt_emit_u64z(lt, (int)(delta>>32), (int)delta); lasttime = t->timeval;
t2=t->next;
free(t);
free(t);
t=t2;
}
}
@ -1122,12 +1157,12 @@ if(lt)
while(t)
{
lt_emit_u32z(lt, (int)(t->timeval - lasttime)); lasttime = t->timeval;
t2=t->next;
free(t);
free(t);
t=t2;
}
lt->timehead = lt->timecurr = NULL;
}
@ -1137,7 +1172,7 @@ if(lt)
lt->ztime_table_size = lt->position - lt->ztime_table_size;
}
if(lt->initial_value>=0)
if(lt->initial_value>=0)
{
lt->initial_value_offset = lt->position;
lt_emit_u8(lt, lt->initial_value);
@ -1152,7 +1187,7 @@ if(lt)
if(lt->double_used)
{
lt->double_test_offset = lt->position;
lt_emit_double(lt, 3.14159);
lt_emit_double(lt, 3.14159);
}
if(lt->dumpoffcount)
@ -1168,7 +1203,7 @@ if(lt)
lt_emit_u64(lt, (int)((ltt->timeval)>>32), (int)ltt->timeval);
ltt2 = ltt;
ltt=ltt->next;
free(ltt2);
free(ltt2);
}
lt->dumpoffhead = lt->dumpoffcurr = NULL;
@ -1211,7 +1246,7 @@ if(lt)
{
struct lt_symbol *s = lt->symchain;
struct lt_symbol *s2;
while(s)
{
free(s->name);
@ -1220,7 +1255,7 @@ if(lt)
s=s2;
}
}
free(lt->sorted_facs);
fclose(lt->handle);
free(lt);
@ -1326,7 +1361,7 @@ return(sa);
}
/*
/*
* set current time
*/
int lt_inc_time_by_delta(struct lt_trace *lt, unsigned int timeval)
@ -1365,7 +1400,7 @@ if(lt)
else
{
free(trl);
goto bail;
goto bail;
}
}
else
@ -1446,7 +1481,7 @@ if((lt)&&(!lt->emitted))
}
/*
* sets change interlace
* sets change interlace
*/
void lt_set_no_interlace(struct lt_trace *lt)
{
@ -1467,17 +1502,17 @@ if((lt)&&(!lt->emitted)&&(!lt->sorted_facs))
if(lt->do_strip_brackets)
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
strip_brack(s);
s=s->symchain;
}
else
else
for(i=0;i<lt->numfacs;i++)
{
lt->sorted_facs[i] = s;
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
s=s->symchain;
}
qsort((void *)lt->sorted_facs, lt->numfacs, sizeof(struct lt_symbol *), lt_compare);
}
wave_msort(lt->sorted_facs, lt->numfacs);
for(i=0;i<lt->numfacs;i++)
{
@ -1516,12 +1551,12 @@ if(lt)
{
int tag;
switch(value)
{
{
case '0': tag = 0; break;
case '1': tag = 1; break;
case 'Z':
case 'Z':
case 'z': tag = 2; break;
case 'X':
case 'X':
case 'x': tag = 3; break;
case 'H':
case 'h': tag = 4; break;
@ -1639,6 +1674,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
unsigned int last_change_delta;
if((lt->clock_compress)&&(s->rows==0))
{
if((len>1)&&(len<=32))
{
int ivalue = value;
@ -1678,7 +1714,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
s->clk_prevval1 = s->clk_prevval;
s->clk_prevval = ivalue;
/* printf("Clock value '%08x' for '%s' at %Ld (#%d)\n", ivalue, s->name, lt->timeval, s->clk_numtrans); */
/* printf("Clock value '%08x' for '%s' at %lld (#%d)\n", ivalue, s->name, lt->timeval, s->clk_numtrans); */
return(1);
}
}
@ -1779,6 +1815,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
s->clk_prevval = ivalue + '0';
}
}
/* normal trace handling */
@ -1821,7 +1858,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
{
tag = (numbytes<<4);
}
lt->lt_emit_u8(lt, tag);
switch(numbytes&3)
{
@ -1842,7 +1879,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
}
lt->lt_emit_u8(lt, optimized ? (3+optimized1) : 0);
}
s->last_change = start_position;
if(s->rows>0)
@ -1908,7 +1945,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
{
if(lt->num_dict_entries==(256*65536)) lt->dict32_offset = lt->position;
}
lt->num_dict_entries++;
}
@ -1953,14 +1990,14 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
value <<= (24-len);
rc=lt->lt_emit_u24(lt, value);
}
else
else
{
value <<= (32-len);
rc=lt->lt_emit_u32(lt, value);
}
}
}
}
if(lt->timebuff)
{
lt->timechangecount++;
@ -2022,7 +2059,7 @@ if((s->flags)&LT_SYM_F_DOUBLE)
{
numbytes = 0;
}
start_position = lt->position;
s->last_change = start_position;
@ -2078,7 +2115,7 @@ if((s->flags)&LT_SYM_F_DOUBLE)
}
rc=lt->lt_emit_double(lt, value);
if(lt->timebuff)
{
lt->timechangecount++;
@ -2120,7 +2157,7 @@ if((s->flags)&LT_SYM_F_STRING)
int numbytes; /* number of bytes to store value minus one */
unsigned int last_change_delta = lt->position - s->last_change - 2;
if(lt->numfacs_bytes)
if(!lt->numfacs_bytes)
{
if(last_change_delta >= 256*65536)
{
@ -2140,7 +2177,7 @@ if((s->flags)&LT_SYM_F_STRING)
{
numbytes = 0;
}
start_position = lt->position;
s->last_change = start_position;
@ -2196,7 +2233,7 @@ if((s->flags)&LT_SYM_F_STRING)
}
rc=lt->lt_emit_string(lt, value);
if(lt->timebuff)
{
lt->timechangecount++;
@ -2245,6 +2282,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
int len = ((s->flags)&LT_SYM_F_INTEGER) ? 32 : s->len;
if((lt->clock_compress)&&(s->rows==0))
{
if((len>1)&&(len<=32))
{
int legal = 0;
@ -2308,7 +2346,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
s->clk_prevval1 = s->clk_prevval;
s->clk_prevval = ivalue;
/* printf("Clock value '%08x' for '%s' [len=%d] at %Ld (#%d)\n",
/* printf("Clock value '%08x' for '%s' [len=%d] at %lld (#%d)\n",
ivalue, s->name, len, lt->timeval, s->clk_numtrans); */
return(1);
}
@ -2374,7 +2412,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
{
s->clk_prevval = value[0];
/* printf("Clock value '%c' for '%s' at %Ld (#%d)\n", value[0], s->name, lt->timeval, s->clk_numtrans); */
/* printf("Clock value '%c' for '%s' at %lld (#%d)\n", value[0], s->name, lt->timeval, s->clk_numtrans); */
return(1);
}
}
@ -2408,6 +2446,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
s->clk_prevval = value[0];
}
}
/* normal trace handling */
@ -2437,12 +2476,12 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
while((ch=*(pnt++)))
{
switch(ch)
{
{
case '0':
case '1': mvl|=LT_MVL_2; break;
case 'Z':
case 'z':
case 'X':
case 'Z':
case 'z':
case 'X':
case 'x': mvl|=LT_MVL_4; break;
default: mvl|=LT_MVL_9; break;
}
@ -2451,13 +2490,13 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
}
switch(prevch)
{
{
case 0x00: tagadd = 0; break;
case '0': tagadd = 3; break;
case '1': tagadd = 4; break;
case 'Z':
case 'Z':
case 'z': tagadd = 5; break;
case 'X':
case 'X':
case 'x': tagadd = 6; break;
case 'H':
case 'h': tagadd = 7; break;
@ -2554,7 +2593,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
int outval = 0;
int thisval= 0;
pnt = value;
pnt = value;
if((lt->dictmode)&&(len>lt->mindictwidth))
{
@ -2585,7 +2624,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
{
if(lt->num_dict_entries==(256*65536)) lt->dict32_offset = lt->position;
}
lt->num_dict_entries++;
}
@ -2623,8 +2662,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
outval |= (thisval<<bitpos);
bitpos--;
if((bitpos==-1)||(i==len-1))
{
lt->lt_emit_u8(lt, outval);
{
lt->lt_emit_u8(lt, outval);
outval = 0;
bitpos = 7;
}
@ -2638,7 +2677,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
int outval = 0;
int thisval= 0;
pnt = value;
pnt = value;
for(i=0;i<len;i++)
{
@ -2657,8 +2696,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
outval |= (thisval<<bitpos);
bitpos-=2;
if((bitpos==-2)||(i==len-1))
{
lt->lt_emit_u8(lt, outval);
{
lt->lt_emit_u8(lt, outval);
outval = 0;
bitpos = 6;
}
@ -2672,7 +2711,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
int outval = 0;
int thisval= 0;
pnt = value;
pnt = value;
for(i=0;i<len;i++)
{
@ -2701,8 +2740,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
outval |= (thisval<<bitpos);
bitpos-=4;
if((bitpos==-4)||(i==len-1))
{
lt->lt_emit_u8(lt, outval);
{
lt->lt_emit_u8(lt, outval);
outval = 0;
bitpos = 4;
}
@ -2712,7 +2751,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
rc=1;
}
if(lt->timebuff)
{
lt->timechangecount++;