2020-08-08 15:47:34 +02:00
|
|
|
/* File: token.c
|
2020-10-12 13:13:31 +02:00
|
|
|
*
|
2020-08-08 15:47:34 +02:00
|
|
|
* This file is part of XSCHEM,
|
2020-10-12 13:13:31 +02:00
|
|
|
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
|
2020-08-08 15:47:34 +02:00
|
|
|
* simulation.
|
|
|
|
|
* Copyright (C) 1998-2020 Stefan Frederik Schippers
|
|
|
|
|
*
|
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "xschem.h"
|
2020-10-14 01:38:51 +02:00
|
|
|
#define SPACE(c) ( c=='\n' || c==' ' || c=='\t' || c=='\0' || c==';' )
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* instance name (refdes) hash table, for unique name checking */
|
|
|
|
|
struct inst_hashentry {
|
|
|
|
|
struct inst_hashentry *next;
|
|
|
|
|
unsigned int hash;
|
|
|
|
|
char *token;
|
|
|
|
|
int value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct inst_hashentry *table[HASHSIZE];
|
|
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
enum status {TOK_BEGIN, TOK_TOKEN, TOK_SEP, TOK_VALUE, TOK_END, TOK_ENDTOK};
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* calculate the hash function relative to string s */
|
|
|
|
|
static unsigned int hash(char *tok)
|
|
|
|
|
{
|
|
|
|
|
unsigned int hash = 0;
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
while ( (c = *tok++) )
|
|
|
|
|
hash = c + (hash << 6) + (hash << 16) - hash;
|
|
|
|
|
return hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int name_strcmp(char *s, char *d) /* compare strings up to '\0' or'[' */
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
if(d[i]=='\0' || d[i]=='[')
|
|
|
|
|
{
|
|
|
|
|
if(s[i]!='\0' && s[i]!='[') return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if(s[i]=='\0' || s[i]=='[')
|
|
|
|
|
{
|
|
|
|
|
if(d[i]!='\0' && d[i]!='[') return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if(s[i]!=d[i]) return 1;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 20180926 added token_size */
|
|
|
|
|
/* remove:
|
|
|
|
|
* 0,XINSERT : lookup and insert in hash table (return NULL if token was not found)
|
|
|
|
|
* if token was found update value
|
2020-09-23 00:58:39 +02:00
|
|
|
3,XINSERT_NOREPLACE : same as XINSERT but do not replace existing value if token found.
|
2020-08-08 15:47:34 +02:00
|
|
|
* 1,XDELETE : delete token entry, return NULL
|
2020-10-12 13:13:31 +02:00
|
|
|
* 2,XLOOKUP : lookup only
|
2020-08-08 15:47:34 +02:00
|
|
|
*/
|
2020-09-30 23:55:07 +02:00
|
|
|
static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, char *token,
|
|
|
|
|
int value, int remove, size_t token_size)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
unsigned int hashcode;
|
2020-08-08 15:47:34 +02:00
|
|
|
unsigned int index;
|
|
|
|
|
struct inst_hashentry *entry, *saveptr, **preventry;
|
|
|
|
|
int s;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token==NULL) return NULL;
|
2020-10-12 13:13:31 +02:00
|
|
|
hashcode=hash(token);
|
|
|
|
|
index=hashcode % HASHSIZE;
|
2020-08-08 15:47:34 +02:00
|
|
|
entry=table[index];
|
|
|
|
|
preventry=&table[index];
|
|
|
|
|
while(1) {
|
|
|
|
|
if( !entry ) { /* empty slot */
|
2020-09-23 00:58:39 +02:00
|
|
|
if(remove == XINSERT || remove == XINSERT_NOREPLACE) { /* insert data */
|
2020-08-08 15:47:34 +02:00
|
|
|
s=sizeof( struct inst_hashentry );
|
|
|
|
|
entry=(struct inst_hashentry *) my_malloc(425, s);
|
|
|
|
|
*preventry=entry;
|
|
|
|
|
entry->next=NULL;
|
|
|
|
|
entry->hash=hashcode;
|
|
|
|
|
entry->token=NULL;
|
|
|
|
|
entry->token = my_malloc(426, token_size + 1);
|
|
|
|
|
memcpy(entry->token,token, token_size + 1);
|
|
|
|
|
entry->value = value;
|
|
|
|
|
}
|
|
|
|
|
return NULL; /* token was not in hash */
|
|
|
|
|
}
|
|
|
|
|
if( entry->hash==hashcode && !strcmp(token,entry->token) ) { /* found a matching token */
|
|
|
|
|
if(remove == XDELETE) { /* remove token from the hash table ... */
|
|
|
|
|
saveptr=entry->next;
|
|
|
|
|
my_free(968, &entry->token);
|
|
|
|
|
my_free(969, &entry);
|
|
|
|
|
*preventry=saveptr;
|
|
|
|
|
return NULL;
|
|
|
|
|
} else if(remove == XINSERT) {
|
|
|
|
|
entry->value = value;
|
|
|
|
|
}
|
2020-11-16 02:25:43 +01:00
|
|
|
/* dbg(1, "inst_hash_lookup(): returning: %s , %d\n", entry->token, entry->value); */
|
2020-08-08 15:47:34 +02:00
|
|
|
return entry; /* found matching entry, return the address */
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
preventry=&entry->next; /* descend into the list. */
|
|
|
|
|
entry = entry->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct inst_hashentry *inst_free_hash_entry(struct inst_hashentry *entry)
|
|
|
|
|
{
|
|
|
|
|
struct inst_hashentry *tmp;
|
|
|
|
|
while( entry ) {
|
|
|
|
|
tmp = entry -> next;
|
|
|
|
|
my_free(970, &(entry->token));
|
|
|
|
|
dbg(3, "inst_free_hash_entry(): removing entry %lu\n", (unsigned long)entry);
|
|
|
|
|
my_free(971, &entry);
|
|
|
|
|
entry = tmp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void inst_free_hash(struct inst_hashentry **table) /* remove the whole hash table */
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "inst_free_hash(): removing hash table\n");
|
|
|
|
|
for(i=0;i<HASHSIZE;i++)
|
|
|
|
|
{
|
|
|
|
|
table[i] = inst_free_hash_entry( table[i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void hash_all_names(int n)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
inst_free_hash(table);
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0; i<xctx->instances; i++) {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* if(i == n) continue; */
|
2020-10-15 17:39:21 +02:00
|
|
|
inst_hash_lookup(table, xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname));
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 04:12:34 +02:00
|
|
|
|
2020-10-14 23:44:53 +02:00
|
|
|
void tcl_hook(char **res)
|
2020-10-14 04:12:34 +02:00
|
|
|
{
|
|
|
|
|
char * result = *res;
|
|
|
|
|
if(result && strstr(result, "tcleval(")== result) {
|
2020-10-14 23:44:53 +02:00
|
|
|
Tcl_VarEval(interp, "tclpropeval2 {", result, "}" , NULL);
|
2020-10-14 04:12:34 +02:00
|
|
|
my_strdup2(1198, res, tclresult());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
void clear_instance_hash()
|
|
|
|
|
{
|
|
|
|
|
inst_free_hash(table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_unique_names(int rename)
|
|
|
|
|
{
|
|
|
|
|
int i, j, first = 1;
|
|
|
|
|
char *tmp = NULL;
|
|
|
|
|
int newpropcnt = 0;
|
|
|
|
|
int mult;
|
|
|
|
|
char *start;
|
|
|
|
|
char *comma_pos;
|
|
|
|
|
char *expanded_instname = NULL;
|
|
|
|
|
struct inst_hashentry *entry;
|
2020-10-18 13:53:58 +02:00
|
|
|
int big = xctx->wires> 2000 || xctx->instances > 2000;
|
2020-08-08 15:47:34 +02:00
|
|
|
/* int save_draw; */
|
|
|
|
|
|
|
|
|
|
if(hilight_nets) {
|
2020-10-12 13:13:31 +02:00
|
|
|
xRect boundbox;
|
2020-10-18 13:53:58 +02:00
|
|
|
if(!big) calc_drawing_bbox(&boundbox, 2);
|
2020-08-08 15:47:34 +02:00
|
|
|
enable_drill=0;
|
|
|
|
|
delete_hilight_net();
|
|
|
|
|
/* undraw_hilight_net(1); */
|
2020-10-18 13:53:58 +02:00
|
|
|
if(!big) {
|
2020-11-03 12:10:55 +01:00
|
|
|
bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
|
2020-10-18 13:53:58 +02:00
|
|
|
bbox(ADD, boundbox.x1, boundbox.y1, boundbox.x2, boundbox.y2);
|
|
|
|
|
bbox(SET , 0.0 , 0.0 , 0.0 , 0.0);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
draw();
|
2020-10-18 13:53:58 +02:00
|
|
|
if(!big) bbox(END , 0.0 , 0.0 , 0.0 , 0.0);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
inst_free_hash(table);
|
|
|
|
|
first = 1;
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0;i<xctx->instances;i++) {
|
|
|
|
|
if(xctx->inst[i].instname && xctx->inst[i].instname[0]) {
|
|
|
|
|
my_strdup(118, &expanded_instname, expandlabel(xctx->inst[i].instname, &mult));
|
2020-08-08 15:47:34 +02:00
|
|
|
comma_pos = 0;
|
|
|
|
|
for(j =0; j< mult; j++) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if(j == 0) start = expanded_instname;
|
2020-08-08 15:47:34 +02:00
|
|
|
else start = comma_pos;
|
|
|
|
|
comma_pos = strchr(start, ',');
|
|
|
|
|
if(comma_pos) *comma_pos = '\0';
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "check_unique_names(): checking %s\n", start);
|
2020-09-23 00:58:39 +02:00
|
|
|
if( (entry = inst_hash_lookup(table, start, i, XINSERT_NOREPLACE, strlen(start)) ) && entry->value != i) {
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->inst[i].flags |=4;
|
2020-08-08 15:47:34 +02:00
|
|
|
hilight_nets=1;
|
|
|
|
|
if(rename == 1) {
|
|
|
|
|
if(first) {
|
2020-11-03 12:10:55 +01:00
|
|
|
bbox(START,0.0,0.0,0.0,0.0);
|
2020-08-08 15:47:34 +02:00
|
|
|
set_modify(1); push_undo();
|
|
|
|
|
prepared_hash_instances=0;
|
|
|
|
|
prepared_netlist_structs=0;
|
|
|
|
|
prepared_hilight_structs=0;
|
|
|
|
|
first = 0;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(comma_pos) {
|
|
|
|
|
*comma_pos=',';
|
|
|
|
|
comma_pos++;
|
|
|
|
|
}
|
|
|
|
|
} /* for(j...) */
|
2020-10-15 17:39:21 +02:00
|
|
|
if( (xctx->inst[i].flags & 4) && rename) {
|
|
|
|
|
my_strdup(511, &tmp, xctx->inst[i].prop_ptr);
|
2020-08-08 15:47:34 +02:00
|
|
|
new_prop_string(i, tmp, newpropcnt++, !rename);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup2(512, &xctx->inst[i].instname, get_tok_value(xctx->inst[i].prop_ptr, "name", 0));
|
|
|
|
|
inst_hash_lookup(table, xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname));
|
|
|
|
|
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2);
|
|
|
|
|
bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(972, &tmp);
|
|
|
|
|
}
|
|
|
|
|
my_free(973, &expanded_instname);
|
|
|
|
|
}
|
|
|
|
|
} /* for(i...) */
|
|
|
|
|
if(rename == 1 && hilight_nets) {
|
|
|
|
|
bbox(SET,0.0,0.0,0.0,0.0);
|
|
|
|
|
draw();
|
|
|
|
|
bbox(END,0.0,0.0,0.0,0.0);
|
|
|
|
|
}
|
|
|
|
|
/* draw_hilight_net(1); */
|
|
|
|
|
redraw_hilights();
|
|
|
|
|
/* draw_window = save_draw; */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int match_symbol(const char *name) /* never returns -1, if symbol not found load systemlib/missing.sym */
|
|
|
|
|
{
|
|
|
|
|
int i,found;
|
|
|
|
|
|
|
|
|
|
found=0;
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0;i<xctx->symbols;i++)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
/* dbg(1, "match_symbol(): name=%s, sym[i].name=%s\n",name, xctx->sym[i].name);*/
|
|
|
|
|
if(strcmp(name, xctx->sym[i].name) == 0)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-11 02:55:24 +02:00
|
|
|
dbg(1, "match_symbol(): found matching symbol:%s\n",name);
|
2020-08-08 15:47:34 +02:00
|
|
|
found=1;break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!found)
|
|
|
|
|
{
|
|
|
|
|
dbg(1, "match_symbol(): matching symbol not found:%s, loading\n",name);
|
2020-10-15 17:39:21 +02:00
|
|
|
load_sym_def(name, NULL); /* append another symbol to the xctx->sym[] array */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-11 02:55:24 +02:00
|
|
|
dbg(1, "match_symbol(): returning %d\n",i);
|
2020-08-08 15:47:34 +02:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update **s modifying only the token values that are */
|
|
|
|
|
/* different between *new and *old */
|
|
|
|
|
/* return 1 if s modified 20081221 */
|
2020-08-19 10:25:11 +02:00
|
|
|
int set_different_token(char **s,const char *new, const char *old, int object, int n)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *token=NULL, *value=NULL;
|
|
|
|
|
int sizetok=0, sizeval=0;
|
|
|
|
|
int token_pos=0, value_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
|
|
|
|
int mod;
|
2020-08-19 10:25:11 +02:00
|
|
|
const char *my_new;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
mod=0;
|
|
|
|
|
my_new = new;
|
|
|
|
|
dbg(1, "set_different_token(): *s=%s, new=%s, old=%s n=%d\n",*s, new, old, n);
|
|
|
|
|
if(new==NULL) return 0;
|
2020-08-18 01:39:44 +02:00
|
|
|
|
|
|
|
|
sizeval = sizetok = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(427, &token, sizetok);
|
|
|
|
|
my_realloc(429, &value, sizeval);
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* parse new string and add / change attributes that are missing / different from old */
|
|
|
|
|
while(1) {
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*my_new++;
|
2020-08-08 15:47:34 +02:00
|
|
|
space=SPACE(c) ;
|
2020-08-19 10:25:11 +02:00
|
|
|
if(c=='"' && !escape) quote=!quote;
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote && !escape) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
|
|
|
|
if(strcmp(value, get_tok_value(old,token,1))) {
|
|
|
|
|
mod=1;
|
|
|
|
|
my_strdup(433, s, subst_token(*s, token, value) );
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-19 10:25:11 +02:00
|
|
|
escape = (c=='\\' && !escape);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\0') break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
state = TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
escape = quote = token_pos = value_pos = 0;
|
|
|
|
|
/* parse old string and remove attributes that are not present in new */
|
|
|
|
|
while(old) {
|
|
|
|
|
c=*old++;
|
|
|
|
|
space=SPACE(c) ;
|
2020-08-19 10:25:11 +02:00
|
|
|
if(c=='"' && !escape) quote=!quote;
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote && !escape) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
|
|
|
|
get_tok_value(new,token,1);
|
|
|
|
|
if(get_tok_size == 0 ) {
|
|
|
|
|
mod=1;
|
|
|
|
|
my_strdup(443, s, subst_token(*s, token, NULL) );
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
2020-08-16 15:08:17 +02:00
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-19 10:25:11 +02:00
|
|
|
escape = (c=='\\' && !escape);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\0') break;
|
|
|
|
|
}
|
|
|
|
|
my_free(974, &token);
|
|
|
|
|
my_free(975, &value);
|
|
|
|
|
return mod;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 10:48:26 +02:00
|
|
|
/* return a string containing the list of all tokens in s */
|
|
|
|
|
/* with_quotes: */
|
|
|
|
|
/* 0: eat non escaped quotes (") */
|
|
|
|
|
/* 1: return unescaped quotes as part of the token value if they are present */
|
|
|
|
|
/* 2: eat backslashes */
|
|
|
|
|
const char *list_tokens(const char *s, int with_quotes)
|
|
|
|
|
{
|
|
|
|
|
static char *token=NULL;
|
2020-08-18 01:39:44 +02:00
|
|
|
int sizetok=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-15 10:48:26 +02:00
|
|
|
register int token_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-15 10:48:26 +02:00
|
|
|
if(s==NULL) {
|
|
|
|
|
my_free(435, &token);
|
|
|
|
|
sizetok = 0;
|
2020-08-18 09:39:29 +02:00
|
|
|
return "";
|
2020-08-15 10:48:26 +02:00
|
|
|
}
|
2020-08-18 01:39:44 +02:00
|
|
|
sizetok = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(451, &token, sizetok);
|
2020-11-23 02:15:34 +01:00
|
|
|
token[0] = '\0';
|
2020-08-15 10:48:26 +02:00
|
|
|
while(1) {
|
|
|
|
|
c=*s++;
|
|
|
|
|
space=SPACE(c) ;
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space && !quote && !escape) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote && !escape ) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-08-15 10:48:26 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if(!escape) quote=!quote;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-08-15 10:48:26 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if((with_quotes & 1) || escape) token[token_pos++]=c;
|
|
|
|
|
}
|
|
|
|
|
else if( !(c == '\\' && (with_quotes & 2)) ) token[token_pos++]=c;
|
|
|
|
|
else if(escape && c == '\\') token[token_pos++]=c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_VALUE) {
|
2020-08-15 10:48:26 +02:00
|
|
|
/* do nothing */
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-15 10:48:26 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos++]= ' ';
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
|
|
|
|
state=TOK_BEGIN;
|
2020-08-15 10:48:26 +02:00
|
|
|
}
|
|
|
|
|
escape = (c=='\\' && !escape);
|
|
|
|
|
if(c=='\0') {
|
|
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos-1]= (c != '\0' ) ? ' ' : '\0';
|
|
|
|
|
}
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* state machine that parses a string made up of <token>=<value> ... */
|
|
|
|
|
/* couples and returns the value of the given token */
|
|
|
|
|
/* if s==NULL or no match return empty string */
|
|
|
|
|
/* NULL tok NOT ALLOWED !!!!!!!! */
|
|
|
|
|
/* never returns NULL... */
|
|
|
|
|
/* with_quotes: */
|
2020-11-29 01:59:17 +01:00
|
|
|
/* 0: eat unescaped backslashes and unescaped double quotes (") */
|
|
|
|
|
/* 1: return backslashes and quotes as part of the token value if they are present */
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *get_tok_value(const char *s,const char *tok, int with_quotes)
|
|
|
|
|
{
|
|
|
|
|
static char *result=NULL;
|
|
|
|
|
static char *token=NULL;
|
2020-11-11 19:01:22 +01:00
|
|
|
static int size=0;
|
|
|
|
|
static int sizetok=0;
|
2020-10-16 18:24:06 +02:00
|
|
|
register int c, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
register int token_pos=0, value_pos=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
int quote=0, state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
int escape=0;
|
2020-08-17 01:08:13 +02:00
|
|
|
int cmp = 1;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(s==NULL) {
|
|
|
|
|
my_free(976, &result);
|
|
|
|
|
my_free(977, &token);
|
2020-11-11 19:01:22 +01:00
|
|
|
size = sizetok = 0;
|
2020-08-18 01:39:44 +02:00
|
|
|
get_tok_value_size = get_tok_size = 0;
|
2020-08-08 15:47:34 +02:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
get_tok_value_size = get_tok_size = 0;
|
|
|
|
|
dbg(2, "get_tok_value(): looking for <%s> in <%s>\n",tok,s);
|
2020-11-11 19:01:22 +01:00
|
|
|
if( size == 0 ) {
|
|
|
|
|
sizetok = size = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(454, &result, size);
|
|
|
|
|
my_realloc(457, &token, sizetok);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
while(1) {
|
|
|
|
|
c=*s++;
|
|
|
|
|
space=SPACE(c) ;
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space && !quote && !escape) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote && !escape ) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
/* don't use STR_ALLOC() for efficiency reasons */
|
|
|
|
|
if(value_pos>=size) {
|
|
|
|
|
size+=CADCHUNKALLOC;
|
|
|
|
|
my_realloc(436, &result,size);
|
|
|
|
|
}
|
|
|
|
|
if(token_pos>=sizetok) {
|
|
|
|
|
sizetok+=CADCHUNKALLOC;
|
|
|
|
|
my_realloc(437, &token,sizetok);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if(!escape) quote=!quote;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-08-17 01:08:13 +02:00
|
|
|
if(!cmp) { /* previous token matched search and was without value, return get_tok_size */
|
|
|
|
|
result[0] = '\0';
|
|
|
|
|
get_tok_value_size = 0;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if((with_quotes & 1) || escape) token[token_pos++]=c;
|
|
|
|
|
}
|
2020-11-29 01:59:17 +01:00
|
|
|
/* skip unescaped backslashes */
|
|
|
|
|
else if( escape || c != '\\' ) token[token_pos++]=c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_VALUE) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if((with_quotes & 1) || escape) result[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-17 01:29:47 +01:00
|
|
|
/* skip unescaped backslashes */
|
2020-11-29 01:59:17 +01:00
|
|
|
else if( escape || c != '\\' ) result[value_pos++]=c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
2020-08-17 01:08:13 +02:00
|
|
|
if( !(cmp = strcmp(token,tok)) ) {
|
2020-11-17 01:29:47 +01:00
|
|
|
/* report back also token size, useful to check if requested token exists */
|
|
|
|
|
get_tok_size = token_pos;
|
2020-08-17 01:08:13 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "get_tok_value(): token=%s\n", token);
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
2020-08-08 15:47:34 +02:00
|
|
|
result[value_pos]='\0';
|
2020-08-17 01:08:13 +02:00
|
|
|
if( !cmp ) {
|
2020-11-17 01:29:47 +01:00
|
|
|
get_tok_value_size = value_pos; /* return also size so to avoid using strlen */
|
2020-08-08 15:47:34 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
value_pos=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
escape = (c=='\\' && !escape);
|
|
|
|
|
if(c=='\0') {
|
|
|
|
|
result[0]='\0';
|
|
|
|
|
get_tok_size = 0;
|
2020-11-17 01:29:47 +01:00
|
|
|
get_tok_value_size = 0; /* return also size so to avoid using strlen */
|
2020-08-08 15:47:34 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return template string excluding name=... and token=value where token listed in extra */
|
|
|
|
|
const char *get_sym_template(char *s,char *extra)
|
|
|
|
|
{
|
|
|
|
|
static char *result=NULL;
|
2020-08-18 01:39:44 +02:00
|
|
|
int sizeres=0;
|
|
|
|
|
int sizetok=0;
|
|
|
|
|
int sizeval=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *value=NULL;
|
|
|
|
|
char *token=NULL;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
register int token_pos=0, value_pos=0, result_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
|
|
|
|
int with_quotes=0;
|
|
|
|
|
int l;
|
|
|
|
|
/* with_quotes: */
|
|
|
|
|
/* 0: eat non escaped quotes (") */
|
|
|
|
|
/* 1: return unescaped quotes as part of the token value if they are present */
|
|
|
|
|
/* 2: eat backslashes */
|
|
|
|
|
/* 3: 1+2 :) */
|
|
|
|
|
|
|
|
|
|
if(s==NULL) {
|
|
|
|
|
my_free(978, &result);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
l = strlen(s);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, l+1, &sizeres);
|
2020-08-18 01:39:44 +02:00
|
|
|
sizetok = sizeval = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(438, &value,sizeval);
|
|
|
|
|
my_realloc(439, &token,sizetok);
|
2020-08-08 15:47:34 +02:00
|
|
|
while(1) {
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
space=SPACE(c) ;
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_BEGIN) {
|
2020-08-08 15:47:34 +02:00
|
|
|
result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_TOKEN) {
|
2020-08-08 15:47:34 +02:00
|
|
|
token[token_pos++]=c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_VALUE) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='"') {
|
|
|
|
|
if(!escape) quote=!quote;
|
|
|
|
|
if((with_quotes & 1) || escape) value[value_pos++]=c;
|
|
|
|
|
}
|
|
|
|
|
else if( (c=='\\') && (with_quotes & 2) ) ; /* dont store backslash */
|
|
|
|
|
else value[value_pos++]=c;
|
2020-08-18 01:39:44 +02:00
|
|
|
escape = (c=='\\' && !escape);
|
|
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value[value_pos]='\0';
|
|
|
|
|
if((!extra || !strstr(extra, token)) && strcmp(token,"name")) {
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, value, value_pos+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=value_pos;
|
|
|
|
|
}
|
|
|
|
|
result[result_pos++] = c;
|
|
|
|
|
value_pos=0;
|
|
|
|
|
token_pos=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
|
|
|
|
} else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
if((!extra || !strstr(extra, token)) && strcmp(token,"name")) {
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, token, token_pos+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=token_pos;
|
|
|
|
|
result[result_pos++] = c;
|
|
|
|
|
}
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(c=='\0') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(979, &value);
|
|
|
|
|
my_free(980, &token);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *find_bracket(const char *s)
|
|
|
|
|
{
|
|
|
|
|
while(*s!='['&& *s!='\0') s++;
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 01:04:57 +02:00
|
|
|
/* caller is responsible for freeing up storage for return value
|
|
|
|
|
* return NULL if no matching token found */
|
2020-08-08 15:47:34 +02:00
|
|
|
char *get_pin_attr_from_inst(int inst, int pin, const char *attr)
|
2020-10-12 13:13:31 +02:00
|
|
|
{
|
2020-08-08 15:47:34 +02:00
|
|
|
int attr_size;
|
2020-10-03 01:04:57 +02:00
|
|
|
char *pinname = NULL, *pname = NULL, *pin_attr_value = NULL;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *pnumber = NULL;
|
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "get_pin_attr_from_inst(): inst=%d pin=%d attr=%s\n", inst, pin, attr);
|
2020-10-03 01:04:57 +02:00
|
|
|
pin_attr_value = NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
str = get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][pin].prop_ptr,"name",0);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(str[0]) {
|
|
|
|
|
attr_size = strlen(attr);
|
|
|
|
|
my_strdup(498, &pinname, str);
|
|
|
|
|
pname =my_malloc(49, get_tok_value_size + attr_size + 30);
|
|
|
|
|
my_snprintf(pname, get_tok_value_size + attr_size + 30, "%s(%s)", attr, pinname);
|
|
|
|
|
my_free(981, &pinname);
|
2020-10-15 17:39:21 +02:00
|
|
|
str = get_tok_value(xctx->inst[inst].prop_ptr, pname, 0);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(982, &pname);
|
2020-10-03 01:04:57 +02:00
|
|
|
if(get_tok_size) my_strdup2(51, &pin_attr_value, str);
|
2020-08-08 15:47:34 +02:00
|
|
|
else {
|
|
|
|
|
pnumber = my_malloc(52, attr_size + 100);
|
|
|
|
|
my_snprintf(pnumber, attr_size + 100, "%s(%d)", attr, pin);
|
2020-10-15 17:39:21 +02:00
|
|
|
str = get_tok_value(xctx->inst[inst].prop_ptr, pnumber, 0);
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "get_pin_attr_from_inst(): pnumber=%s\n", pnumber);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(983, &pnumber);
|
2020-10-03 01:04:57 +02:00
|
|
|
if(get_tok_size) my_strdup2(40, &pin_attr_value, str);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-03 01:04:57 +02:00
|
|
|
return pin_attr_value; /* caller is responsible for freeing up storage for pin_attr_value */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-04 23:55:43 +02:00
|
|
|
void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
/* given a old_prop property string, return a new */
|
2020-10-15 17:39:21 +02:00
|
|
|
/* property string in xctx->inst[i].prop_ptr such that the element name is */
|
2020-08-08 15:47:34 +02:00
|
|
|
/* unique in current design (that is, element name is changed */
|
|
|
|
|
/* if necessary) */
|
|
|
|
|
/* if old_prop=NULL return NULL */
|
|
|
|
|
/* if old_prop does not contain a valid "name" or empty return old_prop */
|
|
|
|
|
static char prefix;
|
|
|
|
|
char *old_name=NULL, *new_name=NULL;
|
|
|
|
|
const char *tmp;
|
|
|
|
|
const char *tmp2;
|
|
|
|
|
int q,qq;
|
|
|
|
|
static int last[256];
|
2020-10-12 13:13:31 +02:00
|
|
|
int old_name_len;
|
2020-08-08 15:47:34 +02:00
|
|
|
int new_name_len;
|
|
|
|
|
int n;
|
|
|
|
|
char *old_name_base = NULL;
|
|
|
|
|
struct inst_hashentry *entry;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(1, "new_prop_string(): i=%d, old_prop=%s, fast=%d\n", i, old_prop, fast);
|
|
|
|
|
if(!fast) { /* on 1st invocation of new_prop_string */
|
|
|
|
|
for(q=1;q<=255;q++) last[q]=1;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
if(old_prop==NULL)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
my_free(984, &xctx->inst[i].prop_ptr);
|
2020-08-08 15:47:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
old_name_len = my_strdup(444, &old_name,get_tok_value(old_prop,"name",0) ); /* added old_name_len */
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
if(old_name==NULL)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(446, &xctx->inst[i].prop_ptr, old_prop); /* changed to copy old props if no name */
|
2020-08-08 15:47:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
prefix=old_name[0];
|
|
|
|
|
/* don't change old_prop if name does not conflict. */
|
2020-10-12 13:13:31 +02:00
|
|
|
if(dis_uniq_names || (entry = inst_hash_lookup(table, old_name, i, XLOOKUP, old_name_len))==NULL ||
|
|
|
|
|
entry->value == i)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
inst_hash_lookup(table, old_name, i, XINSERT, old_name_len);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(447, &xctx->inst[i].prop_ptr, old_prop);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(985, &old_name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
old_name_base = my_malloc(64, old_name_len+1);
|
|
|
|
|
n = sscanf(old_name, "%[^[0-9]",old_name_base);
|
|
|
|
|
tmp=find_bracket(old_name);
|
2020-10-12 13:13:31 +02:00
|
|
|
my_realloc(448, &new_name, old_name_len + 40); /* strlen(old_name)+40); */
|
|
|
|
|
qq=fast ? last[(int)prefix] : 1;
|
2020-08-08 15:47:34 +02:00
|
|
|
for(q=qq;;q++)
|
|
|
|
|
{
|
|
|
|
|
if(n >= 1 ) {
|
|
|
|
|
new_name_len = my_snprintf(new_name, old_name_len + 40, "%s%d%s", old_name_base, q, tmp);
|
|
|
|
|
} else {
|
2020-10-12 13:13:31 +02:00
|
|
|
new_name_len = my_snprintf(new_name, old_name_len + 40, "%c%d%s", prefix,q, tmp); /* added new_name_len */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
if((entry = inst_hash_lookup(table, new_name, i, XLOOKUP, new_name_len)) == NULL || entry->value == i)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
last[(int)prefix]=q+1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(986, &old_name_base);
|
2020-10-12 13:13:31 +02:00
|
|
|
tmp2 = subst_token(old_prop, "name", new_name);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(strcmp(tmp2, old_prop) ) {
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(449, &xctx->inst[i].prop_ptr, tmp2);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
inst_hash_lookup(table, new_name, i, XINSERT, new_name_len); /* reinsert in hash */
|
|
|
|
|
my_free(987, &old_name);
|
|
|
|
|
my_free(988, &new_name);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 02:25:41 +02:00
|
|
|
const char *subst_token(const char *s, const char *tok, const char *new_val)
|
2020-08-08 15:47:34 +02:00
|
|
|
/* given a string <s> with multiple "token=value ..." assignments */
|
|
|
|
|
/* substitute <tok>'s value with <new_val> */
|
2020-08-19 09:00:44 +02:00
|
|
|
/* if tok not found in s and new_val!=NULL add tok=new_val at end.*/
|
2020-08-08 15:47:34 +02:00
|
|
|
/* if new_val is empty ('\0') set token value to "" (token="") */
|
2020-08-19 09:00:44 +02:00
|
|
|
/* if new_val is NULL *remove* 'token (and =val if any)' from s */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-18 01:39:44 +02:00
|
|
|
static char *result=NULL;
|
|
|
|
|
int size=0;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-18 01:39:44 +02:00
|
|
|
int sizetok=0;
|
|
|
|
|
char *token=NULL;
|
|
|
|
|
int token_pos=0, result_pos=0, result_save_pos = 0;
|
|
|
|
|
int quote=0, tmp;
|
|
|
|
|
int done_subst=0;
|
|
|
|
|
int escape=0, matched_tok=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-21 10:50:27 +02:00
|
|
|
if(s==NULL && tok == NULL){
|
2020-08-18 01:39:44 +02:00
|
|
|
my_free(989, &result);
|
|
|
|
|
return "";
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-21 10:50:27 +02:00
|
|
|
if((tok == NULL || tok[0]=='\0') && s ){
|
|
|
|
|
my_strdup2(458, &result, s);
|
2020-08-18 01:39:44 +02:00
|
|
|
return result;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "subst_token(): %s, %s, %s\n", s, tok, new_val);
|
2020-08-18 01:39:44 +02:00
|
|
|
sizetok = size = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(1152, &result, size);
|
|
|
|
|
my_realloc(1153, &token, sizetok);
|
2020-08-21 10:50:27 +02:00
|
|
|
result[0] = '\0';
|
2020-08-18 01:39:44 +02:00
|
|
|
while( s ) {
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-08-18 01:39:44 +02:00
|
|
|
space=SPACE(c);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c == '"' && !escape) quote=!quote;
|
2020-08-18 01:39:44 +02:00
|
|
|
/* alloc data */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, result_pos, &size);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-18 01:39:44 +02:00
|
|
|
/* parsing state machine */
|
|
|
|
|
/* states: */
|
2020-11-21 01:23:00 +01:00
|
|
|
/* TOK_BEGIN TOK_TOKEN TOK_ENDTOK TOK_SEP TOK_VALUE */
|
2020-08-18 01:39:44 +02:00
|
|
|
/* */
|
|
|
|
|
/* */
|
2020-11-03 12:10:55 +01:00
|
|
|
/* TOK_BEGIN */
|
2020-11-21 01:23:00 +01:00
|
|
|
/* | TOK_TOKEN */
|
|
|
|
|
/* | | TOK_ENDTOK */
|
|
|
|
|
/* | | | TOK_SEP */
|
|
|
|
|
/* | | | | TOK_VALUE */
|
2020-11-03 12:10:55 +01:00
|
|
|
/* | | | | | TOK_BEGIN */
|
2020-11-21 01:23:00 +01:00
|
|
|
/* | | | | | | TOK_TOKEN */
|
|
|
|
|
/* | | | | | | | TOK_ENDTOK */
|
|
|
|
|
/* | | | | | | | | TOK_TOKEN */
|
2020-08-18 01:39:44 +02:00
|
|
|
/* | | | | | | | | | */
|
|
|
|
|
/* .......name...=.x1....format...type..=..subcircuit.... */
|
|
|
|
|
/* . : space */
|
|
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state == TOK_BEGIN && !space && c != '=' ) {
|
2020-08-18 01:39:44 +02:00
|
|
|
result_save_pos = result_pos;
|
|
|
|
|
token_pos = 0;
|
2020-11-03 12:10:55 +01:00
|
|
|
state = TOK_TOKEN;
|
|
|
|
|
} else if(state == TOK_ENDTOK && (!space || c == '\0') && c != '=' ) {
|
2020-08-18 01:39:44 +02:00
|
|
|
if(!done_subst && matched_tok) {
|
|
|
|
|
if(new_val) { /* add new_val to matching token with no value */
|
|
|
|
|
if(new_val[0]) {
|
|
|
|
|
tmp = strlen(new_val);
|
|
|
|
|
} else {
|
|
|
|
|
new_val = "\"\"";
|
|
|
|
|
tmp = 2;
|
|
|
|
|
}
|
2020-10-14 01:38:51 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp+2 + result_pos, &size);
|
2020-08-19 09:00:44 +02:00
|
|
|
memcpy(result + result_pos, "=", 1);
|
|
|
|
|
memcpy(result + result_pos+1, new_val, tmp);
|
|
|
|
|
memcpy(result + result_pos+1+tmp, " ", 1);
|
|
|
|
|
result_pos += tmp + 2;
|
2020-08-18 01:39:44 +02:00
|
|
|
done_subst = 1;
|
|
|
|
|
} else { /* remove token (and value if any) */
|
|
|
|
|
result_pos = result_save_pos;
|
|
|
|
|
done_subst = 1;
|
2020-08-17 13:37:27 +02:00
|
|
|
}
|
2020-08-18 01:39:44 +02:00
|
|
|
}
|
|
|
|
|
result_save_pos = result_pos;
|
2020-11-03 12:10:55 +01:00
|
|
|
if(c != '\0') state = TOK_TOKEN; /* if end of string remain in TOK_ENDTOK state */
|
|
|
|
|
} else if( state == TOK_TOKEN && space) {
|
2020-08-18 01:39:44 +02:00
|
|
|
token[token_pos] = '\0';
|
|
|
|
|
token_pos = 0;
|
2020-08-18 02:33:58 +02:00
|
|
|
matched_tok = !strcmp(token, tok) && !done_subst;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_ENDTOK;
|
2020-08-19 09:00:44 +02:00
|
|
|
if(c == '\0') {
|
2020-11-03 12:10:55 +01:00
|
|
|
s--; /* go to next iteration and process '\0' as TOK_ENDTOK */
|
2020-08-19 09:00:44 +02:00
|
|
|
continue;
|
2020-08-18 23:45:32 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state == TOK_TOKEN && c=='=') {
|
2020-08-18 01:39:44 +02:00
|
|
|
token[token_pos] = '\0';
|
|
|
|
|
token_pos = 0;
|
2020-08-18 02:33:58 +02:00
|
|
|
matched_tok = !strcmp(token, tok) && !done_subst;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_SEP;
|
|
|
|
|
} else if(state == TOK_ENDTOK && c=='=') {
|
|
|
|
|
state=TOK_SEP;
|
|
|
|
|
} else if( state == TOK_SEP && !space) {
|
2020-08-18 01:39:44 +02:00
|
|
|
if(!done_subst && matched_tok) {
|
|
|
|
|
if(new_val) { /* replace token value with new_val */
|
|
|
|
|
if(new_val[0]) {
|
|
|
|
|
tmp = strlen(new_val);
|
|
|
|
|
} else {
|
|
|
|
|
new_val = "\"\"";
|
|
|
|
|
tmp = 2;
|
|
|
|
|
}
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-08-18 01:39:44 +02:00
|
|
|
memcpy(result + result_pos ,new_val, tmp + 1);
|
|
|
|
|
result_pos += tmp;
|
|
|
|
|
done_subst = 1;
|
|
|
|
|
} else { /* remove token (and value if any) */
|
|
|
|
|
result_pos = result_save_pos;
|
|
|
|
|
done_subst = 1;
|
2020-08-17 13:37:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_VALUE;
|
|
|
|
|
} else if( state == TOK_VALUE && space && !quote && !escape) {
|
|
|
|
|
state=TOK_BEGIN;
|
2020-08-18 01:39:44 +02:00
|
|
|
}
|
|
|
|
|
/* state actions */
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state == TOK_BEGIN) {
|
2020-08-18 01:39:44 +02:00
|
|
|
result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state == TOK_TOKEN) {
|
2020-08-18 01:39:44 +02:00
|
|
|
token[token_pos++] = c;
|
|
|
|
|
result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state == TOK_ENDTOK) {
|
2020-08-18 01:39:44 +02:00
|
|
|
result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state == TOK_SEP) {
|
2020-08-18 01:39:44 +02:00
|
|
|
result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_VALUE) {
|
2020-08-18 01:39:44 +02:00
|
|
|
if(!matched_tok) result[result_pos++] = c; /* skip value for matching token */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-18 23:09:40 +02:00
|
|
|
escape = (c=='\\' && !escape);
|
2020-08-18 01:39:44 +02:00
|
|
|
if(c == '\0') break;
|
|
|
|
|
}
|
|
|
|
|
if(!done_subst) { /* if tok not found add tok=new_value at end */
|
2020-08-21 10:50:27 +02:00
|
|
|
if(result_pos == 0 ) result_pos = 1; /* result="" */
|
2020-08-18 01:39:44 +02:00
|
|
|
if(new_val) {
|
|
|
|
|
if(!new_val[0]) new_val = "\"\"";
|
|
|
|
|
tmp = strlen(new_val) + strlen(tok) + 2;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-08-21 10:50:27 +02:00
|
|
|
my_snprintf(result + result_pos - 1, size, " %s=%s", tok, new_val ); /* result_pos guaranteed to be > 0 */
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-18 01:39:44 +02:00
|
|
|
dbg(2, "subst_token(): returning: %s\n",result);
|
|
|
|
|
my_free(990, &token);
|
|
|
|
|
return result;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *get_trailing_path(const char *str, int no_of_dir, int skip_ext)
|
|
|
|
|
{
|
|
|
|
|
static char s[PATH_MAX];
|
|
|
|
|
size_t len;
|
|
|
|
|
int ext_pos, dir_pos, n_ext, n_dir, c, i;
|
|
|
|
|
|
|
|
|
|
my_strncpy(s, str, S(s));
|
|
|
|
|
len = strlen(s);
|
|
|
|
|
|
|
|
|
|
for(ext_pos=len, dir_pos=len, n_ext=0, n_dir=0, i=len; i>=0; i--) {
|
|
|
|
|
c = s[i];
|
|
|
|
|
if(c=='.' && ++n_ext==1) ext_pos = i;
|
|
|
|
|
if(c=='/' && ++n_dir==no_of_dir+1) dir_pos = i;
|
|
|
|
|
}
|
|
|
|
|
if(skip_ext) s[ext_pos] = '\0';
|
|
|
|
|
|
|
|
|
|
if(dir_pos==len) return s;
|
2020-10-12 13:13:31 +02:00
|
|
|
dbg(2, "get_trailing_path(): str=%s, no_of_dir=%d, skip_ext=%d\n",
|
2020-08-08 15:47:34 +02:00
|
|
|
str, no_of_dir, skip_ext);
|
|
|
|
|
dbg(2, "get_trailing_path(): returning: %s\n", s+(dir_pos<len ? dir_pos+1 : 0));
|
|
|
|
|
return s+(dir_pos<len ? dir_pos+1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* skip also extension */
|
|
|
|
|
const char *skip_dir(const char *str)
|
|
|
|
|
{
|
|
|
|
|
return get_trailing_path(str, 0, 1);
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
/* no extension */
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *get_cell(const char *str, int no_of_dir)
|
2020-10-12 13:13:31 +02:00
|
|
|
{
|
2020-08-08 15:47:34 +02:00
|
|
|
return get_trailing_path(str, no_of_dir, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *get_cell_w_ext(const char *str, int no_of_dir)
|
2020-10-12 13:13:31 +02:00
|
|
|
{
|
2020-08-08 15:47:34 +02:00
|
|
|
return get_trailing_path(str, no_of_dir, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-15 10:48:26 +02:00
|
|
|
/* not used? */
|
|
|
|
|
int count_labels(char *s)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-15 10:48:26 +02:00
|
|
|
int i=1;
|
|
|
|
|
int c;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-15 10:48:26 +02:00
|
|
|
if(s==NULL) return 1;
|
|
|
|
|
while( (c=(*s++)) ) {
|
|
|
|
|
if(c==',') i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
void print_vhdl_element(FILE *fd, int inst)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int i=0, mult, tmp, tmp1;
|
|
|
|
|
const char *str_ptr;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *lab;
|
|
|
|
|
char *name=NULL;
|
|
|
|
|
char *generic_value=NULL, *generic_type=NULL;
|
|
|
|
|
char *template=NULL,*s, *value=NULL, *token=NULL;
|
|
|
|
|
int no_of_pins=0, no_of_generics=0;
|
|
|
|
|
int sizetok=0, sizeval=0;
|
|
|
|
|
int token_pos=0, value_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
2020-11-17 01:29:47 +01:00
|
|
|
xRect *pinptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
if(get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"vhdl_format", 0)[0] != '\0') {
|
2020-10-12 13:13:31 +02:00
|
|
|
print_vhdl_primitive(fd, inst);
|
2020-08-08 15:47:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(462, &name,xctx->inst[inst].instname);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!name) my_strdup(58, &name, get_tok_value(template, "name", 0));
|
|
|
|
|
if(name==NULL) {
|
|
|
|
|
my_free(991, &name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(461, &template, (xctx->inst[inst].ptr+ xctx->sym)->templ);
|
|
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
|
|
|
|
no_of_generics= (xctx->inst[inst].ptr+ xctx->sym)->rects[GENERICLAYER];
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
s=xctx->inst[inst].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* print instance name and subckt */
|
|
|
|
|
dbg(2, "print_vhdl_element(): printing inst name & subcircuit name\n");
|
|
|
|
|
if( (lab = expandlabel(name, &tmp)) != NULL)
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf(fd, "%d %s : %s\n", tmp, lab, skip_dir(xctx->inst[inst].name) );
|
2020-08-08 15:47:34 +02:00
|
|
|
else /* name in some strange format, probably an error */
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf(fd, "1 %s : %s\n", name, skip_dir(xctx->inst[inst].name) );
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "print_vhdl_element(): printing generics passed as properties\n");
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* -------- print generics passed as properties */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
tmp=0;
|
|
|
|
|
/* 20080213 use generic_type property to decide if some properties are strings, see later */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(464, &generic_type, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"generic_type", 0));
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
if (s==NULL) break;
|
|
|
|
|
c=*s++;
|
|
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
escape=0;
|
|
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='"' && !escape) quote=!quote;
|
|
|
|
|
else value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
|
|
|
|
get_tok_value(template, token, 0);
|
|
|
|
|
if(get_tok_size) {
|
2020-08-10 14:15:36 +02:00
|
|
|
if(strcmp(token, "name") && value[0] != '\0') /* token has a value */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-10 14:15:36 +02:00
|
|
|
if(tmp == 0) {fprintf(fd, "generic map(\n");tmp++;tmp1=0;}
|
|
|
|
|
if(tmp1) fprintf(fd, " ,\n");
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-10 14:15:36 +02:00
|
|
|
/* 20080213 put "" around string type generics! */
|
2020-11-29 01:59:17 +01:00
|
|
|
if( generic_type && !strcmp(get_tok_value(generic_type,token, 0), "string") ) {
|
2020-08-10 14:15:36 +02:00
|
|
|
fprintf(fd, " %s => \"%s\"", token, value);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fd, " %s => %s", token, value);
|
|
|
|
|
}
|
|
|
|
|
/* /20080213 */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-10 14:15:36 +02:00
|
|
|
tmp1=1;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
if(c=='\0') /* end string */
|
|
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* -------- end print generics passed as properties */
|
|
|
|
|
dbg(2, "print_vhdl_element(): printing generic maps \n");
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
/* print generic map */
|
|
|
|
|
for(i=0;i<no_of_generics;i++)
|
|
|
|
|
{
|
|
|
|
|
my_strdup(467, &generic_type,get_tok_value(
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->rect[GENERICLAYER][i].prop_ptr,"type",0));
|
|
|
|
|
my_strdup(468, &generic_value, xctx->inst[inst].node[no_of_pins+i] );
|
2020-08-08 15:47:34 +02:00
|
|
|
/*my_strdup(469, &generic_value, get_tok_value( */
|
2020-10-15 17:39:21 +02:00
|
|
|
/* (xctx->inst[inst].ptr+ xctx->sym)->rect[GENERICLAYER][i].prop_ptr,"value") ); */
|
2020-08-08 15:47:34 +02:00
|
|
|
str_ptr = get_tok_value(
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->rect[GENERICLAYER][i].prop_ptr,"name",0);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(generic_value) { /*03062002 dont print generics if unassigned */
|
|
|
|
|
if(tmp) fprintf(fd, " ,\n");
|
|
|
|
|
if(!tmp) fprintf(fd, "generic map (\n");
|
|
|
|
|
fprintf(fd," %s => %s",
|
|
|
|
|
str_ptr ? str_ptr : "<NULL>",
|
|
|
|
|
generic_value ? generic_value : "<NULL>" );
|
|
|
|
|
tmp=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(tmp) fprintf(fd, "\n)\n");
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "print_vhdl_element(): printing port maps \n");
|
|
|
|
|
/* print port map */
|
|
|
|
|
fprintf(fd, "port map(\n" );
|
|
|
|
|
tmp=0;
|
2020-11-17 01:29:47 +01:00
|
|
|
pinptr = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-11-17 01:29:47 +01:00
|
|
|
if(strcmp(get_tok_value(pinptr[i].prop_ptr,"vhdl_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
if( (str_ptr = net_name(inst,i, &mult, 0, 1)) )
|
2020-09-02 12:30:52 +02:00
|
|
|
{
|
|
|
|
|
if(tmp) fprintf(fd, " ,\n");
|
|
|
|
|
fprintf(fd, " %s => %s",
|
2020-10-15 17:39:21 +02:00
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr,"name",0),
|
2020-09-02 12:30:52 +02:00
|
|
|
str_ptr);
|
|
|
|
|
tmp=1;
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(fd, "\n);\n\n");
|
|
|
|
|
dbg(2, "print_vhdl_element(): ------- end ------ \n");
|
|
|
|
|
my_free(992, &name);
|
|
|
|
|
my_free(993, &generic_value);
|
|
|
|
|
my_free(994, &generic_type);
|
|
|
|
|
my_free(995, &template);
|
|
|
|
|
my_free(996, &value);
|
|
|
|
|
my_free(997, &token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_generic(FILE *fd, char *ent_or_comp, int symbol)
|
|
|
|
|
{
|
|
|
|
|
int tmp;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-10-11 00:13:52 +02:00
|
|
|
char *template=NULL, *s, *value=NULL, *token=NULL;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *type=NULL, *generic_type=NULL, *generic_value=NULL;
|
|
|
|
|
const char *str_tmp;
|
|
|
|
|
int i, sizetok=0, sizeval=0;
|
|
|
|
|
int token_pos=0, value_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
|
|
|
|
int token_number=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(472, &template, xctx->sym[symbol].templ);
|
2020-08-08 15:47:34 +02:00
|
|
|
if( !template || !(template[0]) ) {
|
|
|
|
|
my_free(998, &template);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(471, &generic_type, get_tok_value(xctx->sym[symbol].prop_ptr,"generic_type",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "print_generic(): symbol=%d template=%s \n", symbol, template);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf(fd, "%s %s ",ent_or_comp, skip_dir(xctx->sym[symbol].name));
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!strcmp(ent_or_comp,"entity"))
|
|
|
|
|
fprintf(fd, "is\n");
|
|
|
|
|
else
|
|
|
|
|
fprintf(fd, "\n");
|
|
|
|
|
s=template;
|
|
|
|
|
tmp=0;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
c=*s++;
|
|
|
|
|
if(c=='\\')
|
|
|
|
|
{
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
escape=0;
|
|
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote) state=TOK_END;
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
if(c=='"' && !escape) quote=!quote;
|
|
|
|
|
else value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
token_number++;
|
|
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
|
|
|
|
my_strdup(475, &type, get_tok_value(generic_type,token,0));
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(value[0] != '\0') /* token has a value */
|
|
|
|
|
{
|
|
|
|
|
if(token_number>1)
|
|
|
|
|
{
|
|
|
|
|
if(!tmp) {fprintf(fd, "generic (\n");}
|
|
|
|
|
if(tmp) fprintf(fd, " ;\n");
|
2020-11-16 12:33:06 +01:00
|
|
|
if(!type || strcmp(type,"string") ) { /* print "" around string values 20080418 check for type==NULL */
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, " %s : %s := %s", token, type? type:"integer", value);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fd, " %s : %s := \"%s\"", token, type? type:"integer", value);
|
|
|
|
|
} /* /20080213 */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
tmp=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
if(c=='\0') /* end string */
|
|
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
for(i=0;i<xctx->sym[symbol].rects[GENERICLAYER];i++)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(476, &generic_type,
|
|
|
|
|
get_tok_value(xctx->sym[symbol].rect[GENERICLAYER][i].prop_ptr,"generic_type",0));
|
|
|
|
|
my_strdup(477, &generic_value,
|
|
|
|
|
get_tok_value(xctx->sym[symbol].rect[GENERICLAYER][i].prop_ptr,"value", 0) );
|
2020-10-15 17:39:21 +02:00
|
|
|
str_tmp = get_tok_value(xctx->sym[symbol].rect[GENERICLAYER][i].prop_ptr,"name",0);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!tmp) fprintf(fd, "generic (\n");
|
|
|
|
|
if(tmp) fprintf(fd, " ;\n");
|
|
|
|
|
fprintf(fd," %s : %s",str_tmp ? str_tmp : "<NULL>",
|
|
|
|
|
generic_type ? generic_type : "<NULL>" );
|
|
|
|
|
if(generic_value &&generic_value[0])
|
|
|
|
|
fprintf(fd," := %s", generic_value);
|
|
|
|
|
tmp=1;
|
|
|
|
|
}
|
|
|
|
|
if(tmp) fprintf(fd, "\n);\n");
|
|
|
|
|
my_free(999, &template);
|
|
|
|
|
my_free(1001, &value);
|
|
|
|
|
my_free(1002, &token);
|
|
|
|
|
my_free(1003, &type);
|
|
|
|
|
my_free(1004, &generic_type);
|
|
|
|
|
my_free(1005, &generic_value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
void print_verilog_param(FILE *fd, int symbol)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *template=NULL, *s, *value=NULL, *generic_type=NULL, *token=NULL;
|
|
|
|
|
int sizetok=0, sizeval=0;
|
|
|
|
|
int token_pos=0, value_pos=0;
|
|
|
|
|
int quote=0;
|
|
|
|
|
int escape=0;
|
|
|
|
|
int token_number=0;
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(479, &template, xctx->sym[symbol].templ); /* 20150409 20171103 */
|
|
|
|
|
my_strdup(480, &generic_type, get_tok_value(xctx->sym[symbol].prop_ptr,"generic_type",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if( !template || !(template[0]) ) {
|
|
|
|
|
my_free(1006, &template);
|
|
|
|
|
my_free(1007, &generic_type);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dbg(2, "print_verilog_param(): symbol=%d template=%s \n", symbol, template);
|
|
|
|
|
|
|
|
|
|
s=template;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
c=*s++;
|
|
|
|
|
if(c=='\\')
|
|
|
|
|
{
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
escape=0;
|
|
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote) state=TOK_END;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
if(c=='"' && !escape) quote=!quote;
|
|
|
|
|
else value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
token_number++;
|
|
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
|
|
|
|
|
|
|
|
|
if(value[0] != '\0') /* token has a value */
|
|
|
|
|
{
|
|
|
|
|
if(token_number>1)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* 20080915 put "" around string params */
|
2020-11-29 01:59:17 +01:00
|
|
|
if( !generic_type || strcmp(get_tok_value(generic_type,token, 0), "time") ) {
|
|
|
|
|
if( generic_type && !strcmp(get_tok_value(generic_type,token, 0), "string") ) {
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, " parameter %s = \"%s\" ;\n", token, value);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fprintf(fd, " parameter %s = %s ;\n", token, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
if(c=='\0') /* end string */
|
|
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(1008, &template);
|
|
|
|
|
my_free(1009, &generic_type);
|
|
|
|
|
my_free(1010, &value);
|
|
|
|
|
my_free(1011, &token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-24 02:54:45 +01:00
|
|
|
void print_tedax_subckt(FILE *fd, int symbol)
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult;
|
|
|
|
|
const char *str_ptr=NULL;
|
|
|
|
|
register int c, state=TOK_BEGIN, space;
|
|
|
|
|
char *format=NULL,*s, *token=NULL;
|
|
|
|
|
int pin_number;
|
|
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
|
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(460, &format, get_tok_value(xctx->sym[symbol].prop_ptr,"format",0));
|
2020-11-24 02:54:45 +01:00
|
|
|
if( (format==NULL) ) {
|
|
|
|
|
my_free(473, &format);
|
|
|
|
|
return; /* no format */
|
|
|
|
|
}
|
|
|
|
|
no_of_pins= xctx->sym[symbol].rects[PINLAYER];
|
|
|
|
|
s=format;
|
|
|
|
|
|
|
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
c=*s++;
|
|
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
|
|
|
|
}
|
|
|
|
|
else escape=0;
|
|
|
|
|
if(c=='\n' && escape ) c=*s++; /* 20171030 eat escaped newlines */
|
|
|
|
|
space=SPACE(c);
|
|
|
|
|
if( state==TOK_BEGIN && (c=='@' || c=='$') && !escape) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
|
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
state = TOK_SEP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
|
|
|
|
if(state==TOK_TOKEN) {
|
|
|
|
|
token[token_pos++]=c;
|
|
|
|
|
}
|
|
|
|
|
else if(state==TOK_SEP) /* got a token */
|
|
|
|
|
{
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
if(!strcmp(token, "@name")) {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token, "@symname")==0) {
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token, "@pinlist")==0) {
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"spice_ignore",0), "true")) {
|
|
|
|
|
str_ptr=
|
|
|
|
|
expandlabel(get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"name",0), &mult);
|
|
|
|
|
fprintf(fd, "%s ", str_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
char *prop=NULL;
|
|
|
|
|
for(i = 0; i<no_of_pins; i++) {
|
|
|
|
|
prop = xctx->sym[symbol].rect[PINLAYER][i].prop_ptr;
|
|
|
|
|
if(!strcmp(get_tok_value(prop, "name",0), token + 2)) break;
|
|
|
|
|
}
|
|
|
|
|
if(i<no_of_pins && strcmp(get_tok_value(prop,"spice_ignore",0), "true")) {
|
|
|
|
|
fprintf(fd, "%s ", expandlabel(token+2, &mult));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name 20180911 */
|
|
|
|
|
else if(token[0]=='@' && token[1]=='#') {
|
|
|
|
|
pin_number = atoi(token+2);
|
|
|
|
|
if(pin_number < no_of_pins) {
|
|
|
|
|
if(strcmp(get_tok_value(xctx->sym[symbol].rect[PINLAYER][pin_number].prop_ptr,"spice_ignore",0), "true")) {
|
|
|
|
|
str_ptr = get_tok_value(xctx->sym[symbol].rect[PINLAYER][pin_number].prop_ptr,"name",0);
|
|
|
|
|
fprintf(fd, "%s ", expandlabel(str_ptr, &mult));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* this will print the other @parameters, usually "extra" nodes so they will be in the order
|
|
|
|
|
* specified by the format string. The 'extra' attribute is no more used to print extra nodes
|
|
|
|
|
* in spice_block_netlist(). */
|
|
|
|
|
else if(token[0] == '@') { /* given previous if() conditions not followed by @ or # */
|
|
|
|
|
fprintf(fd, "%s ", token + 1);
|
|
|
|
|
}
|
|
|
|
|
if(c!='$' && c!='@' && c!='\0' ) fputc(c,fd);
|
|
|
|
|
if(c == '@' || c =='$') s--;
|
|
|
|
|
state=TOK_BEGIN;
|
|
|
|
|
}
|
|
|
|
|
/* 20151028 dont print escaping backslashes */
|
|
|
|
|
else if(state==TOK_BEGIN && c!='\0') {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
if(c=='\0')
|
|
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(474, &format);
|
|
|
|
|
my_free(478, &token);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
void print_spice_subckt(FILE *fd, int symbol)
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult;
|
2020-10-12 13:13:31 +02:00
|
|
|
const char *str_ptr=NULL;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *format=NULL,*s, *token=NULL;
|
2020-10-12 13:13:31 +02:00
|
|
|
int pin_number;
|
2020-08-08 15:47:34 +02:00
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(103, &format, get_tok_value(xctx->sym[symbol].prop_ptr,"format",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if( (format==NULL) ) {
|
|
|
|
|
my_free(1012, &format);
|
|
|
|
|
return; /* no format */
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
no_of_pins= xctx->sym[symbol].rects[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
s=format;
|
|
|
|
|
|
|
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-10-13 16:23:48 +02:00
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-13 16:23:48 +02:00
|
|
|
else escape=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\n' && escape ) c=*s++; /* 20171030 eat escaped newlines */
|
2020-10-13 16:23:48 +02:00
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( state==TOK_BEGIN && (c=='@' || c=='$') && !escape) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
2020-10-13 16:23:48 +02:00
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
) {
|
2020-11-03 12:10:55 +01:00
|
|
|
state = TOK_SEP;
|
2020-10-13 16:23:48 +02:00
|
|
|
}
|
2020-10-14 01:38:51 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-10-13 16:23:48 +02:00
|
|
|
token[token_pos++]=c;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_SEP) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
|
|
|
|
if(!strcmp(token, "@name")) {
|
|
|
|
|
/* do nothing */
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token, "@symname")==0) {
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token, "@pinlist")==0) {
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
if(strcmp(get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"spice_ignore",0), "true")) {
|
2020-09-02 12:30:52 +02:00
|
|
|
str_ptr=
|
2020-10-15 17:39:21 +02:00
|
|
|
expandlabel(get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"name",0), &mult);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "%s ", str_ptr);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
2020-10-13 01:07:28 +02:00
|
|
|
char *prop=NULL;
|
2020-09-02 12:30:52 +02:00
|
|
|
for(i = 0; i<no_of_pins; i++) {
|
2020-10-15 17:39:21 +02:00
|
|
|
prop = xctx->sym[symbol].rect[PINLAYER][i].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!strcmp(get_tok_value(prop, "name",0), token + 2)) break;
|
2020-09-02 12:30:52 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
if(i<no_of_pins && strcmp(get_tok_value(prop,"spice_ignore",0), "true")) {
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "%s ", expandlabel(token+2, &mult));
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name 20180911 */
|
|
|
|
|
else if(token[0]=='@' && token[1]=='#') {
|
2020-10-12 13:13:31 +02:00
|
|
|
pin_number = atoi(token+2);
|
2020-09-02 12:30:52 +02:00
|
|
|
if(pin_number < no_of_pins) {
|
2020-10-15 17:39:21 +02:00
|
|
|
if(strcmp(get_tok_value(xctx->sym[symbol].rect[PINLAYER][pin_number].prop_ptr,"spice_ignore",0), "true")) {
|
|
|
|
|
str_ptr = get_tok_value(xctx->sym[symbol].rect[PINLAYER][pin_number].prop_ptr,"name",0);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "%s ", expandlabel(str_ptr, &mult));
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-09-02 12:30:52 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-21 18:18:53 +02:00
|
|
|
/* this will print the other @parameters, usually "extra" nodes so they will be in the order
|
|
|
|
|
* specified by the format string. The 'extra' attribute is no more used to print extra nodes
|
|
|
|
|
* in spice_block_netlist(). */
|
|
|
|
|
else if(token[0] == '@') { /* given previous if() conditions not followed by @ or # */
|
|
|
|
|
fprintf(fd, "%s ", token + 1);
|
|
|
|
|
}
|
2020-10-13 16:23:48 +02:00
|
|
|
if(c!='$' && c!='@' && c!='\0' ) fputc(c,fd);
|
|
|
|
|
if(c == '@' || c =='$') s--;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
/* 20151028 dont print escaping backslashes */
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN && c!='\0') {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* do nothing */
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(1013, &format);
|
|
|
|
|
my_free(1014, &token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_spice_element(FILE *fd, int inst)
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult, tmp;
|
2020-10-12 13:13:31 +02:00
|
|
|
const char *str_ptr=NULL;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *template=NULL,*format=NULL,*s, *name=NULL, *token=NULL;
|
|
|
|
|
const char *lab, *value = NULL;
|
2020-11-20 18:46:27 +01:00
|
|
|
char *translatedvalue = NULL;
|
2020-10-12 13:13:31 +02:00
|
|
|
int pin_number;
|
2020-08-08 15:47:34 +02:00
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
2020-10-14 01:38:51 +02:00
|
|
|
char *result = NULL;
|
|
|
|
|
int result_pos = 0;
|
|
|
|
|
int size = 0;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-14 01:38:51 +02:00
|
|
|
size = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(1211, &result, size);
|
|
|
|
|
result[0] = '\0';
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(483, &template, (xctx->inst[inst].ptr+ xctx->sym)->templ);
|
|
|
|
|
my_strdup(484, &name,xctx->inst[inst].instname);
|
2020-08-08 15:47:34 +02:00
|
|
|
if (!name) my_strdup(43, &name, get_tok_value(template, "name", 0));
|
|
|
|
|
|
2020-10-11 00:13:52 +02:00
|
|
|
/* allow format string override in instance */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(470, &format, get_tok_value(xctx->inst[inst].prop_ptr,"format",0));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!format || !format[0])
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(486, &format, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"format",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
if ((name==NULL) || (format==NULL)) {
|
2020-10-12 13:13:31 +02:00
|
|
|
my_free(1015, &template);
|
|
|
|
|
my_free(1016, &format);
|
|
|
|
|
my_free(1017, &name);
|
2020-10-14 01:38:51 +02:00
|
|
|
my_free(1193, &result);
|
2020-08-08 15:47:34 +02:00
|
|
|
return; /* do no netlist unwanted insts(no format) */
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
s=format;
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "print_spice_element(): name=%s, format=%s netlist_count=%d\n",name,format, netlist_count);
|
2020-08-08 15:47:34 +02:00
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-14 01:38:51 +02:00
|
|
|
/* always make room for some characters so the single char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, 100 + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-10-13 01:07:28 +02:00
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-13 01:07:28 +02:00
|
|
|
else escape=0;
|
2020-10-14 21:04:45 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if (c=='\n' && escape) c=*s++; /* 20171030 eat escaped newlines */
|
2020-10-13 01:07:28 +02:00
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if ( state==TOK_BEGIN && (c=='@'|| c=='$') && !escape ) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
2020-10-13 02:52:37 +02:00
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
) {
|
2020-11-22 00:51:24 +01:00
|
|
|
dbg(1, "print_spice_element(): c=%c, space=%d, escape=%d token_pos=%d\n", c, space, escape, token_pos);
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_SEP;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-10-13 01:07:28 +02:00
|
|
|
token[token_pos++]=c;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if (state==TOK_SEP) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-11-21 01:23:00 +01:00
|
|
|
int token_exists = 0;
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
|
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
if (!spiceprefix && !strcmp(token, "@spiceprefix")) {
|
2020-08-08 15:47:34 +02:00
|
|
|
value=NULL;
|
|
|
|
|
} else {
|
|
|
|
|
dbg(1, "print_spice_element(): token: |%s|\n", token);
|
2020-11-29 01:59:17 +01:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
|
2020-11-21 01:23:00 +01:00
|
|
|
/* get_tok_size==0 indicates that token(+1) does not exist in instance attributes */
|
|
|
|
|
if (!get_tok_size) value=get_tok_value(template, token+1, 0);
|
|
|
|
|
token_exists = get_tok_size;
|
2020-11-20 18:46:27 +01:00
|
|
|
if (!strncmp(value,"tcleval(", 8)) {
|
2020-11-20 22:02:43 +01:00
|
|
|
dbg(1, "print_spice_element(): value=%s\n", value);
|
2020-11-24 02:54:45 +01:00
|
|
|
my_strdup2(466, &translatedvalue, value);
|
|
|
|
|
my_strdup2(456, &translatedvalue, translate(inst, translatedvalue));
|
2020-11-20 18:46:27 +01:00
|
|
|
value = translatedvalue;
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-21 01:23:00 +01:00
|
|
|
if(!token_exists && token[0] =='$') {
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
tmp = strlen(token + 1) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", token + 1);
|
|
|
|
|
/* fputs(token + 1, fd); */
|
2020-08-08 15:47:34 +02:00
|
|
|
} else if (value && value[0]!='\0') {
|
|
|
|
|
/* instance names (name) and node labels (lab) go thru the expandlabel function. */
|
|
|
|
|
/*if something else must be parsed, put an if here! */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if (!(strcmp(token+1,"name") && strcmp(token+1,"lab")) /* expand name/labels */
|
2020-10-14 01:38:51 +02:00
|
|
|
&& ((lab = expandlabel(value, &tmp)) != NULL)) {
|
|
|
|
|
|
|
|
|
|
tmp = strlen(lab) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", lab);
|
|
|
|
|
/* fputs(lab,fd); */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
tmp = strlen(value) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", value);
|
|
|
|
|
/* fputs(value,fd); */
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if (strcmp(token,"@symname")==0) /* of course symname must not be present */
|
2020-10-14 01:38:51 +02:00
|
|
|
/* in hash table */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
const char *s = skip_dir(xctx->inst[inst].name);
|
2020-10-14 01:38:51 +02:00
|
|
|
tmp = strlen(s) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", s);
|
|
|
|
|
/* fputs(s,fd); */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-14 21:04:45 +02:00
|
|
|
else if (strcmp(token,"@symname_ext")==0) /* of course symname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
const char *s = get_cell_w_ext(xctx->inst[inst].name, 0);
|
2020-10-14 21:04:45 +02:00
|
|
|
tmp = strlen(s) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 21:04:45 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", s);
|
|
|
|
|
/* fputs(s,fd); */
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
else if(strcmp(token,"@schname")==0) /* of course schname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp = strlen(xctx->current_name) +100 ; /* always make room for some extra chars
|
2020-10-14 01:38:51 +02:00
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", xctx->current_name);
|
|
|
|
|
/* fputs(xctx->current_name, fd); */
|
2020-10-14 01:38:51 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present */
|
|
|
|
|
/* in hash table. print multiplicity */
|
|
|
|
|
{ /* and node number: m1 n1 m2 n2 .... */
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
2020-10-11 13:08:32 +02:00
|
|
|
if(strcmp(get_tok_value(prop, "spice_ignore", 0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 23:15:05 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr);
|
2020-09-02 12:30:52 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
for(i=0;i<no_of_pins;i++) {
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if (!strcmp( get_tok_value(prop,"name",0), token+2)) {
|
|
|
|
|
if(strcmp(get_tok_value(prop,"spice_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 23:15:05 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr);
|
2020-09-02 12:30:52 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
break;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name 20180911 */
|
|
|
|
|
else if (token[0]=='@' && token[1]=='#') {
|
2020-10-12 13:13:31 +02:00
|
|
|
pin_number = atoi(token+2);
|
2020-08-08 15:47:34 +02:00
|
|
|
if (pin_number < no_of_pins) {
|
2020-09-30 23:55:07 +02:00
|
|
|
const char *si;
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][pin_number].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
si = get_tok_value(prop, "spice_ignore",0);
|
2020-09-30 23:55:07 +02:00
|
|
|
if(strcmp(si, "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,pin_number, &mult, 0, 1);
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 23:15:05 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", mult, str_ptr);
|
2020-09-02 12:30:52 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else if (!strncmp(token,"@tcleval", 8)) {
|
2020-08-08 15:47:34 +02:00
|
|
|
size_t s;
|
|
|
|
|
char *tclcmd=NULL;
|
2020-10-14 01:38:51 +02:00
|
|
|
const char *res;
|
2020-10-15 17:39:21 +02:00
|
|
|
s = token_pos + strlen(name) + strlen(xctx->inst[inst].name) + 100;
|
2020-08-08 15:47:34 +02:00
|
|
|
tclcmd = my_malloc(488, s);
|
|
|
|
|
Tcl_ResetResult(interp);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(tclcmd, s, "tclpropeval {%s} {%s} {%s}", token, name, xctx->inst[inst].name);
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "print_spice_element(): tclpropeval {%s} {%s} {%s}", token, name, xctx->inst[inst].name);
|
2020-10-14 01:38:51 +02:00
|
|
|
res = tcleval(tclcmd);
|
|
|
|
|
|
|
|
|
|
tmp = strlen(res) + 100; /* always make room for some extra chars
|
|
|
|
|
* so 1-char writes to result do not need reallocs */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", res);
|
|
|
|
|
/* fprintf(fd, "%s", tclresult()); */
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1018, &tclcmd);
|
|
|
|
|
} /* /20171029 */
|
2020-10-14 01:38:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if(c != '$' && c != '@' && c!='\0' ) {
|
|
|
|
|
result_pos += my_snprintf(result + result_pos, 2, "%c", c); /* no realloc needed */
|
|
|
|
|
/* fputc(c,fd); */
|
|
|
|
|
}
|
2020-10-13 01:07:28 +02:00
|
|
|
if(c == '@' || c == '$' ) s--;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN && c!='\0') {
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, 2, "%c", c); /* no realloc needed */
|
|
|
|
|
/* fputc(c,fd); */
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-14 01:38:51 +02:00
|
|
|
result_pos += my_snprintf(result + result_pos, 2, "%c", '\n'); /* no realloc needed */
|
|
|
|
|
/* fputc('\n',fd); */
|
2020-08-08 15:47:34 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2020-10-14 01:38:51 +02:00
|
|
|
} /* while(1) */
|
|
|
|
|
|
2020-10-14 04:12:34 +02:00
|
|
|
|
|
|
|
|
/* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions
|
|
|
|
|
* can be calculated */
|
2020-10-14 21:04:45 +02:00
|
|
|
|
|
|
|
|
/* do one level of substitutions to resolve @params and equations*/
|
2020-10-14 23:15:05 +02:00
|
|
|
if(result && strstr(result, "tcleval(")== result) {
|
2020-10-21 18:18:53 +02:00
|
|
|
dbg(1, "print_spice_element(): before translate()result=%s\n", result);
|
2020-10-14 23:15:05 +02:00
|
|
|
my_strdup(22, &result, translate(inst, result));
|
2020-10-21 18:18:53 +02:00
|
|
|
dbg(1, "print_spice_element(): after translate()result=%s\n", result);
|
2020-10-14 23:15:05 +02:00
|
|
|
}
|
2020-11-20 18:46:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* can't remember what the f**k this is supposed to do.
|
|
|
|
|
why eval( and not tcleval( ?
|
|
|
|
|
disable until some regression pops out
|
|
|
|
|
*/
|
|
|
|
|
#if 0
|
2020-10-23 23:17:55 +02:00
|
|
|
/* do a second round of substitutions, but without calling tcl */
|
|
|
|
|
if(result && strstr(result, "eval(") == result) {
|
2020-10-24 03:15:08 +02:00
|
|
|
char *c = strrchr(result, ')');
|
2020-10-25 03:03:23 +01:00
|
|
|
if(c) while(1) { /* shift following characters back 1 char */
|
|
|
|
|
*c = c[1];
|
|
|
|
|
c++;
|
|
|
|
|
if(!*c) break;
|
|
|
|
|
}
|
2020-10-23 23:17:55 +02:00
|
|
|
my_strdup2(88, &result, translate(inst, result+5));
|
|
|
|
|
}
|
2020-11-20 18:46:27 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2020-10-14 01:38:51 +02:00
|
|
|
fprintf(fd, "%s", result);
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1019, &template);
|
|
|
|
|
my_free(1020, &format);
|
|
|
|
|
my_free(1021, &name);
|
|
|
|
|
my_free(1022, &token);
|
2020-10-14 01:38:51 +02:00
|
|
|
my_free(1194, &result);
|
2020-11-20 22:02:43 +01:00
|
|
|
my_free(455, &translatedvalue);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_tedax_element(FILE *fd, int inst)
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult;
|
2020-10-12 13:13:31 +02:00
|
|
|
const char *str_ptr=NULL;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *template=NULL,*format=NULL,*s, *name=NULL, *token=NULL;
|
|
|
|
|
const char *value;
|
|
|
|
|
char *extra=NULL, *extra_pinnumber=NULL;
|
|
|
|
|
char *numslots=NULL;
|
2020-10-12 13:13:31 +02:00
|
|
|
int pin_number;
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *extra_token, *extra_token_val;
|
|
|
|
|
char *extra_ptr;
|
|
|
|
|
char *extra_pinnumber_token, *extra_pinnumber_ptr;
|
|
|
|
|
char *saveptr1, *saveptr2;
|
|
|
|
|
const char *tmp;
|
|
|
|
|
int instance_based=0;
|
|
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
2020-11-24 02:54:45 +01:00
|
|
|
int subcircuit = 0;
|
2020-08-08 15:47:34 +02:00
|
|
|
/* struct inst_hashentry *ptr; */
|
|
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(489, &extra, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"extra",0));
|
|
|
|
|
my_strdup(41, &extra_pinnumber, get_tok_value(xctx->inst[inst].prop_ptr,"extra_pinnumber",0));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!extra_pinnumber) my_strdup(490, &extra_pinnumber,
|
2020-11-29 01:59:17 +01:00
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"extra_pinnumber",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
my_strdup(491, &template,
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->templ);
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(492, &numslots, get_tok_value(xctx->inst[inst].prop_ptr,"numslots",0));
|
|
|
|
|
if(!numslots) my_strdup(493, &numslots, get_tok_value(template,"numslots",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!numslots) my_strdup(494, &numslots, "1");
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(495, &name,xctx->inst[inst].instname);
|
|
|
|
|
/* my_strdup(496, &name,get_tok_value(xctx->inst[inst].prop_ptr,"name",0)); */
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!name) my_strdup(2, &name, get_tok_value(template, "name", 0));
|
|
|
|
|
|
2020-10-11 00:13:52 +02:00
|
|
|
/* allow format string override in instance */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(1185, &format, get_tok_value(xctx->inst[inst].prop_ptr,"tedax_format",0));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!format || !format[0])
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(497, &format, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"tedax_format",0));
|
2020-11-24 02:54:45 +01:00
|
|
|
|
|
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
|
|
|
|
if( !format && !strcmp((xctx->inst[inst].ptr+ xctx->sym)->type, "subcircuit") ) {
|
2020-11-28 16:41:35 +01:00
|
|
|
char *net = NULL;
|
|
|
|
|
char *pinname = NULL;
|
|
|
|
|
char *pin = NULL;
|
|
|
|
|
char *netbit=NULL;
|
|
|
|
|
char *pinbit = NULL;
|
|
|
|
|
int net_mult;
|
|
|
|
|
int pin_mult;
|
|
|
|
|
int n;
|
|
|
|
|
subcircuit = 1;
|
|
|
|
|
fprintf(fd, "__subcircuit__ %s %s\n", skip_dir(xctx->inst[inst].name), xctx->inst[inst].instname);
|
|
|
|
|
for(i=0;i<no_of_pins; i++) {
|
|
|
|
|
my_strdup2(531, &net, net_name(inst,i, &net_mult, 0, 1));
|
|
|
|
|
my_strdup2(1196, &pinname,
|
|
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr,"name",0));
|
|
|
|
|
my_strdup2(1197, &pin, expandlabel(pinname, &pin_mult));
|
|
|
|
|
dbg(1, "#net=%s pinname=%s pin=%s net_mult=%d pin_mult=%d\n", net, pinname, pin, net_mult, pin_mult);
|
|
|
|
|
for(n = 0; n < net_mult; n++) {
|
|
|
|
|
my_strdup(1204, &netbit, find_nth(net, ',', n+1));
|
|
|
|
|
my_strdup(1205, &pinbit, find_nth(pin, ',', n+1));
|
|
|
|
|
fprintf(fd, "__map__ %s -> %s\n",
|
|
|
|
|
pinbit ? pinbit : "__UNCONNECTED_PIN__",
|
|
|
|
|
netbit ? netbit : "__UNCONNECTED_PIN__");
|
2020-11-24 02:54:45 +01:00
|
|
|
}
|
2020-11-28 16:41:35 +01:00
|
|
|
}
|
|
|
|
|
my_free(1199, &net);
|
|
|
|
|
my_free(1200, &pin);
|
|
|
|
|
my_free(1201, &pinname);
|
|
|
|
|
my_free(1206, &pinbit);
|
|
|
|
|
my_free(1207, &netbit);
|
|
|
|
|
fprintf(fd, "\n");
|
2020-11-24 02:54:45 +01:00
|
|
|
}
|
|
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(name==NULL || !format || !format[0]) {
|
|
|
|
|
my_free(1023, &extra);
|
|
|
|
|
my_free(1024, &extra_pinnumber);
|
|
|
|
|
my_free(1025, &template);
|
|
|
|
|
my_free(1026, &numslots);
|
|
|
|
|
my_free(1027, &format);
|
|
|
|
|
my_free(1028, &name);
|
2020-10-12 13:13:31 +02:00
|
|
|
return;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-24 02:54:45 +01:00
|
|
|
if(!subcircuit) {
|
|
|
|
|
fprintf(fd, "begin_inst %s numslots %s\n", name, numslots);
|
|
|
|
|
for(i=0;i<no_of_pins; i++) {
|
|
|
|
|
char *pinnumber;
|
|
|
|
|
pinnumber = get_pin_attr_from_inst(inst, i, "pinnumber");
|
|
|
|
|
if(!pinnumber) {
|
|
|
|
|
my_strdup2(500, &pinnumber,
|
|
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr,"pinnumber",0));
|
|
|
|
|
}
|
|
|
|
|
if(!get_tok_size) my_strdup(501, &pinnumber, "--UNDEF--");
|
|
|
|
|
tmp = net_name(inst,i, &mult, 0, 1);
|
|
|
|
|
if(tmp && strcmp(tmp, "__UNCONNECTED_PIN__")) {
|
|
|
|
|
fprintf(fd, "conn %s %s %s %s %d\n",
|
|
|
|
|
name,
|
|
|
|
|
tmp,
|
|
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr,"name",0),
|
|
|
|
|
pinnumber,
|
|
|
|
|
i+1);
|
|
|
|
|
}
|
|
|
|
|
my_free(1029, &pinnumber);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-24 02:54:45 +01:00
|
|
|
|
|
|
|
|
if(extra){
|
|
|
|
|
char netstring[40];
|
|
|
|
|
/* fprintf(errfp, "extra_pinnumber: |%s|\n", extra_pinnumber); */
|
|
|
|
|
/* fprintf(errfp, "extra: |%s|\n", extra); */
|
|
|
|
|
for(extra_ptr = extra, extra_pinnumber_ptr = extra_pinnumber; ; extra_ptr=NULL, extra_pinnumber_ptr=NULL) {
|
|
|
|
|
extra_pinnumber_token=my_strtok_r(extra_pinnumber_ptr, " ", &saveptr1);
|
|
|
|
|
extra_token=my_strtok_r(extra_ptr, " ", &saveptr2);
|
|
|
|
|
if(!extra_token) break;
|
|
|
|
|
/* fprintf(errfp, "extra_pinnumber_token: |%s|\n", extra_pinnumber_token); */
|
|
|
|
|
/* fprintf(errfp, "extra_token: |%s|\n", extra_token); */
|
|
|
|
|
instance_based=0;
|
|
|
|
|
|
|
|
|
|
/* alternate instance based extra net naming: net:<pinumber>=netname */
|
|
|
|
|
my_snprintf(netstring, S(netstring), "net:%s", extra_pinnumber_token);
|
|
|
|
|
dbg(1, "print_tedax_element(): netstring=%s\n", netstring);
|
|
|
|
|
extra_token_val=get_tok_value(xctx->inst[inst].prop_ptr, extra_token, 0);
|
|
|
|
|
if(!extra_token_val[0]) extra_token_val=get_tok_value(xctx->inst[inst].prop_ptr, netstring, 0);
|
|
|
|
|
if(!extra_token_val[0]) extra_token_val=get_tok_value(template, extra_token, 0);
|
|
|
|
|
else instance_based=1;
|
|
|
|
|
if(!extra_token_val[0]) extra_token_val="--UNDEF--";
|
|
|
|
|
|
|
|
|
|
fprintf(fd, "conn %s %s %s %s %d", name, extra_token_val, extra_token, extra_pinnumber_token, i+1);
|
|
|
|
|
i++;
|
|
|
|
|
if(instance_based) fprintf(fd, " # instance_based");
|
|
|
|
|
fprintf(fd,"\n");
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(format) {
|
|
|
|
|
s=format;
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "print_tedax_element(): name=%s, tedax_format=%s netlist_count=%d\n",name,format, netlist_count);
|
2020-08-08 15:47:34 +02:00
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-13 02:52:37 +02:00
|
|
|
else escape=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\n' && escape ) c=*s++; /* 20171030 eat escaped newlines */
|
2020-10-14 01:38:51 +02:00
|
|
|
space=SPACE(c);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
if( state==TOK_BEGIN && (c=='$' || c=='@') && !escape) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
2020-10-13 02:52:37 +02:00
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
) {
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_SEP;
|
2020-10-13 02:52:37 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-10-13 02:52:37 +02:00
|
|
|
token[token_pos++]=c; /* 20171029 remove escaping backslashes */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_SEP) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
|
2020-11-21 01:23:00 +01:00
|
|
|
/* get_tok_size==0 indicates that token(+1) does not exist in instance attributes */
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!get_tok_size) value=get_tok_value(template, token+1, 0);
|
|
|
|
|
if(!get_tok_size && token[0] =='$') {
|
|
|
|
|
fputs(token + 1, fd);
|
|
|
|
|
} else if(value[0]!='\0')
|
|
|
|
|
{
|
|
|
|
|
fputs(value,fd);
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@symname")==0) /* of course symname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fputs(skip_dir(xctx->inst[inst].name),fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-14 21:04:45 +02:00
|
|
|
else if (strcmp(token,"@symname_ext")==0)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fputs(get_cell_w_ext(xctx->inst[inst].name, 0), fd);
|
2020-10-14 21:04:45 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
else if(strcmp(token,"@schname")==0) /* of course schname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
/* fputs(xctx->sch[xctx->currsch],fd); */
|
|
|
|
|
fputs(xctx->current_name, fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present */
|
|
|
|
|
/* in hash table. print multiplicity */
|
|
|
|
|
{ /* and node number: m1 n1 m2 n2 .... */
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-08-08 15:47:34 +02:00
|
|
|
/* fprintf(errfp, "inst: %s --> %s\n", name, str_ptr); */
|
2020-10-14 23:15:05 +02:00
|
|
|
fprintf(fd, "?%d %s ", mult, str_ptr);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
for(i=0;i<no_of_pins;i++) {
|
|
|
|
|
if(!strcmp(
|
2020-10-15 17:39:21 +02:00
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr,"name",0),
|
2020-08-08 15:47:34 +02:00
|
|
|
token+2
|
|
|
|
|
)
|
|
|
|
|
) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", str_ptr);
|
2020-10-12 13:13:31 +02:00
|
|
|
break;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this allow to print in netlist any properties defined for pins.
|
2020-10-12 13:13:31 +02:00
|
|
|
* @#n:property, where 'n' is the pin index (starting from 0) and
|
|
|
|
|
* 'property' the property defined for that pin (property=value)
|
2020-08-08 15:47:34 +02:00
|
|
|
* in case this property is found the value for it is printed.
|
|
|
|
|
* if device is slotted (U1:m) and property value for pin
|
|
|
|
|
* is also slotted ('a:b:c:d') then print the m-th substring.
|
|
|
|
|
* if property value is not slotted print entire value regardless of device slot.
|
|
|
|
|
* slot numbers start from 1
|
|
|
|
|
*/
|
2020-10-12 13:13:31 +02:00
|
|
|
} else if(token[0]=='@' && token[1]=='#') {
|
2020-08-08 15:47:34 +02:00
|
|
|
if( strchr(token, ':') ) {
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
char *subtok = my_malloc(503, sizetok * sizeof(char));
|
|
|
|
|
char *subtok2 = my_malloc(42, sizetok * sizeof(char)+20);
|
|
|
|
|
subtok[0]='\0';
|
|
|
|
|
n=-1;
|
|
|
|
|
sscanf(token+2, "%d:%s", &n, subtok);
|
|
|
|
|
if(n!=-1 && subtok[0]) {
|
|
|
|
|
my_snprintf(subtok2, sizetok * sizeof(char)+20, "%s(%d)", subtok, n);
|
2020-10-15 17:39:21 +02:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr,subtok2,0);
|
|
|
|
|
if( n>=0 && n < (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER]) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!value[0])
|
2020-10-15 17:39:21 +02:00
|
|
|
value = get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][n].prop_ptr,subtok,0);
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
if(value[0]) {
|
|
|
|
|
char *ss;
|
|
|
|
|
int slot;
|
2020-10-15 17:39:21 +02:00
|
|
|
if( (ss=strchr(xctx->inst[inst].instname, ':')) ) {
|
2020-08-08 15:47:34 +02:00
|
|
|
sscanf(ss+1, "%d", &slot);
|
|
|
|
|
if(strstr(value, ":")) value = find_nth(value, ':', slot);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(1030, &subtok);
|
|
|
|
|
my_free(1031, &subtok2);
|
|
|
|
|
} else {
|
2020-10-12 13:13:31 +02:00
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name */
|
2020-08-08 15:47:34 +02:00
|
|
|
/* @#n --> return net name attached to pin of index 'n' */
|
|
|
|
|
pin_number = atoi(token+2);
|
|
|
|
|
if(pin_number < no_of_pins) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,pin_number, &mult, 0, 1);
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", str_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else if(!strncmp(token,"@tcleval", 8)) {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* char tclcmd[strlen(token)+100] ; */
|
|
|
|
|
size_t s;
|
|
|
|
|
char *tclcmd=NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
s = token_pos + strlen(name) + strlen(xctx->inst[inst].name) + 100;
|
2020-08-08 15:47:34 +02:00
|
|
|
tclcmd = my_malloc(504, s);
|
|
|
|
|
Tcl_ResetResult(interp);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(tclcmd, s, "tclpropeval {%s} {%s} {%s}", token, name, xctx->inst[inst].name);
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(tclcmd);
|
2020-08-16 03:34:45 +02:00
|
|
|
fprintf(fd, "%s", tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1032, &tclcmd);
|
|
|
|
|
/* fprintf(errfp, "%s\n", tclcmd); */
|
|
|
|
|
} /* /20171029 */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
|
|
|
|
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c!='$' && c!='@' && c!='\0') fputc(c,fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c == '@' || c == '$' ) s--;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN && c!='\0') fputc(c,fd);
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
fputc('\n',fd);
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* if(format) */
|
2020-11-24 02:54:45 +01:00
|
|
|
if(!subcircuit) fprintf(fd,"end_inst\n");
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1033, &extra);
|
|
|
|
|
my_free(1034, &extra_pinnumber);
|
|
|
|
|
my_free(1035, &template);
|
|
|
|
|
my_free(1036, &numslots);
|
|
|
|
|
my_free(1037, &format);
|
|
|
|
|
my_free(1038, &name);
|
|
|
|
|
my_free(1039, &token);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 14:15:36 +02:00
|
|
|
/* verilog module instantiation:
|
|
|
|
|
cmos_inv
|
|
|
|
|
#(
|
|
|
|
|
.WN ( 1.5e-05 ) ,
|
|
|
|
|
.WP ( 4.5e-05 ) ,
|
|
|
|
|
.LLN ( 3e-06 ) ,
|
|
|
|
|
.LLP ( 3e-06 )
|
|
|
|
|
)
|
2020-10-12 13:13:31 +02:00
|
|
|
Xinv (
|
2020-08-10 14:15:36 +02:00
|
|
|
.A( AA ),
|
|
|
|
|
.Z( Z )
|
|
|
|
|
);
|
|
|
|
|
*/
|
2020-08-08 15:47:34 +02:00
|
|
|
void print_verilog_element(FILE *fd, int inst)
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult, tmp;
|
|
|
|
|
const char *str_ptr;
|
|
|
|
|
const char *lab;
|
|
|
|
|
char *name=NULL;
|
|
|
|
|
char *generic_type=NULL;
|
|
|
|
|
char *template=NULL,*s;
|
|
|
|
|
int no_of_pins=0;
|
|
|
|
|
int tmp1 = 0;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *value=NULL, *token=NULL;
|
|
|
|
|
int sizetok=0, sizeval=0;
|
|
|
|
|
int token_pos=0, value_pos=0;
|
|
|
|
|
int quote=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
if(get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"verilog_format",0)[0] != '\0') {
|
2020-10-11 00:13:52 +02:00
|
|
|
print_verilog_primitive(fd, inst);
|
2020-08-08 15:47:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
my_strdup(506, &template,
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->templ);
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(507, &name,xctx->inst[inst].instname);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!name) my_strdup(3, &name, get_tok_value(template, "name", 0));
|
|
|
|
|
if(name==NULL) {
|
|
|
|
|
my_free(1040, &template);
|
|
|
|
|
my_free(1041, &name);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* 20080915 use generic_type property to decide if some properties are strings, see later */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(505, &generic_type, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"generic_type",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
s=xctx->inst[inst].prop_ptr;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* print instance subckt */
|
|
|
|
|
dbg(2, "print_verilog_element(): printing inst name & subcircuit name\n");
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf(fd, "%s\n", skip_dir(xctx->inst[inst].name) );
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
/* -------- print generics passed as properties */
|
|
|
|
|
tmp=0;
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
if (s==NULL) break;
|
|
|
|
|
c=*s++;
|
|
|
|
|
if(c=='\\')
|
|
|
|
|
{
|
|
|
|
|
c=*s++;
|
|
|
|
|
}
|
|
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( (state==TOK_BEGIN || state==TOK_ENDTOK) && !space && c != '=') state=TOK_TOKEN;
|
|
|
|
|
else if( state==TOK_TOKEN && space) state=TOK_ENDTOK;
|
|
|
|
|
else if( (state==TOK_TOKEN || state==TOK_ENDTOK) && c=='=') state=TOK_SEP;
|
|
|
|
|
else if( state==TOK_SEP && !space) state=TOK_VALUE;
|
|
|
|
|
else if( state==TOK_VALUE && space && !quote) state=TOK_END;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&value, value_pos, &sizeval);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_VALUE)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
value[value_pos++]=c;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_ENDTOK || state==TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
if(token_pos) {
|
|
|
|
|
token[token_pos]='\0';
|
|
|
|
|
token_pos=0;
|
|
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
} else if(state==TOK_END)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
value[value_pos]='\0';
|
|
|
|
|
value_pos=0;
|
2020-08-10 14:15:36 +02:00
|
|
|
get_tok_value(template, token, 0);
|
|
|
|
|
if(strcmp(token, "name") && get_tok_size) {
|
|
|
|
|
if(value[0] != '\0') /* token has a value */
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(token,"spice_ignore") && strcmp(token,"vhdl_ignore") && strcmp(token,"tedax_ignore")) {
|
|
|
|
|
if(tmp == 0) {fprintf(fd, "#(\n---- start parameters\n");tmp++;tmp1=0;}
|
|
|
|
|
if(tmp1) fprintf(fd, " ,\n");
|
2020-11-29 01:59:17 +01:00
|
|
|
if( !generic_type || strcmp(get_tok_value(generic_type,token, 0), "time") ) {
|
|
|
|
|
if( generic_type && !strcmp(get_tok_value(generic_type,token, 0), "string") ) {
|
2020-08-10 14:15:36 +02:00
|
|
|
fprintf(fd, " .%s ( \"%s\" )", token, value);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(fd, " .%s ( %s )", token, value);
|
|
|
|
|
}
|
|
|
|
|
tmp1=1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
if(c=='\0') /* end string */
|
|
|
|
|
{
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(tmp) fprintf(fd, "\n---- end parameters\n)\n");
|
|
|
|
|
|
|
|
|
|
/* -------- end print generics passed as properties */
|
|
|
|
|
|
|
|
|
|
/* print instance name */
|
|
|
|
|
if( (lab = expandlabel(name, &tmp)) != NULL)
|
|
|
|
|
fprintf(fd, "---- instance %s (\n", lab );
|
|
|
|
|
else /* name in some strange format, probably an error */
|
|
|
|
|
fprintf(fd, "---- instance %s (\n", name );
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "print_verilog_element(): printing port maps \n");
|
|
|
|
|
/* print port map */
|
|
|
|
|
tmp=0;
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
xSymbol *ptr = xctx->inst[inst].ptr+ xctx->sym;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(strcmp(get_tok_value(ptr->rect[PINLAYER][i].prop_ptr,"verilog_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
if( (str_ptr = net_name(inst,i, &mult, 0, 1)) )
|
2020-09-02 12:30:52 +02:00
|
|
|
{
|
|
|
|
|
if(tmp) fprintf(fd,"\n");
|
2020-10-14 23:15:05 +02:00
|
|
|
fprintf(fd, " ?%d %s %s ", mult,
|
2020-10-12 13:13:31 +02:00
|
|
|
get_tok_value(ptr->rect[PINLAYER][i].prop_ptr,"name",0),
|
2020-09-02 12:30:52 +02:00
|
|
|
str_ptr);
|
|
|
|
|
tmp=1;
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fprintf(fd, "\n);\n\n");
|
|
|
|
|
dbg(2, "print_verilog_element(): ------- end ------ \n");
|
|
|
|
|
my_free(1042, &name);
|
|
|
|
|
my_free(1043, &generic_type);
|
|
|
|
|
my_free(1044, &template);
|
|
|
|
|
my_free(1045, &value);
|
|
|
|
|
my_free(1046, &token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-11-16 15:44:51 +01:00
|
|
|
const char *net_name(int i, int j, int *mult, int hash_prefix_unnamed_net, int erc)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
int tmp;
|
|
|
|
|
char errstr[2048];
|
2020-10-15 02:16:57 +02:00
|
|
|
static const char unconn[]="__UNCONNECTED_PIN__";
|
2020-08-08 15:47:34 +02:00
|
|
|
char str_node[40]; /* 20161122 overflow safe */
|
2020-10-15 17:39:21 +02:00
|
|
|
if(xctx->inst[i].node && xctx->inst[i].node[j]!=NULL)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
if((xctx->inst[i].node[j])[0] == '#') /* unnamed net */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
/* get unnamed node multiplicity ( minimum mult found in circuit) */
|
2020-10-15 17:39:21 +02:00
|
|
|
*mult = get_unnamed_node(3, 0, atoi((xctx->inst[i].node[j])+4) );
|
2020-09-30 00:30:48 +02:00
|
|
|
dbg(2, "net_name(): node = %s n=%d mult=%d\n",
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->inst[i].node[j], atoi(xctx->inst[i].node[j]), *mult);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(hash_prefix_unnamed_net) {
|
|
|
|
|
if(*mult>1) /* unnamed is a bus */
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(str_node, S(str_node), "%s[%d:0]", (xctx->inst[i].node[j]), *mult-1);
|
2020-08-08 15:47:34 +02:00
|
|
|
else
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(str_node, S(str_node), "%s", (xctx->inst[i].node[j]) );
|
2020-08-08 15:47:34 +02:00
|
|
|
} else {
|
|
|
|
|
if(*mult>1) /* unnamed is a bus */
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(str_node, S(str_node), "%s[%d:0]", (xctx->inst[i].node[j])+1, *mult-1);
|
2020-08-08 15:47:34 +02:00
|
|
|
else
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(str_node, S(str_node), "%s", (xctx->inst[i].node[j])+1 );
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-28 16:41:35 +01:00
|
|
|
expandlabel(get_tok_value( /* remove quotes --. */
|
|
|
|
|
(xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0), mult);
|
2020-08-08 15:47:34 +02:00
|
|
|
return expandlabel(str_node, &tmp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-28 16:41:35 +01:00
|
|
|
expandlabel(get_tok_value( /* remove quotes --. */
|
|
|
|
|
(xctx->inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr,"name",0), mult);
|
2020-10-15 17:39:21 +02:00
|
|
|
return expandlabel(xctx->inst[i].node[j], &tmp);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*mult=1;
|
|
|
|
|
|
2020-11-16 15:44:51 +01:00
|
|
|
if(erc) {
|
|
|
|
|
my_snprintf(errstr, S(errstr), "Warning: unconnected pin, Inst idx: %d, Pin idx: %d Inst:%s\n",
|
|
|
|
|
i, j, xctx->inst[i].instname ) ;
|
|
|
|
|
statusmsg(errstr,2);
|
|
|
|
|
if(!netlist_count) {
|
|
|
|
|
xctx->inst[i].flags |=4;
|
|
|
|
|
hilight_nets=1;
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
return unconn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 20071217 */
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult, tmp;
|
|
|
|
|
const char *str_ptr;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *lab;
|
|
|
|
|
char *template=NULL,*format=NULL,*s, *name=NULL, *token=NULL;
|
|
|
|
|
const char *value;
|
2020-10-12 13:13:31 +02:00
|
|
|
int pin_number;
|
2020-08-08 15:47:34 +02:00
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
|
|
|
|
/* struct inst_hashentry *ptr; */
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(513, &template, (xctx->inst[inst].ptr+ xctx->sym)->templ);
|
|
|
|
|
my_strdup(514, &name, xctx->inst[inst].instname);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!name) my_strdup(50, &name, get_tok_value(template, "name", 0));
|
|
|
|
|
|
2020-10-11 00:13:52 +02:00
|
|
|
/* allow format string override in instance */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(1000, &format, get_tok_value(xctx->inst[inst].prop_ptr,"vhdl_format",0));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!format || !format[0])
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(516, &format, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"vhdl_format",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if((name==NULL) || (format==NULL) ) {
|
|
|
|
|
my_free(1047, &template);
|
|
|
|
|
my_free(1048, &name);
|
2020-08-10 23:43:20 +02:00
|
|
|
my_free(1151, &format);
|
2020-08-08 15:47:34 +02:00
|
|
|
return; /*do no netlist unwanted insts(no format) */
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
s=format;
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "print_vhdl_primitive(): name=%s, format=%s netlist_count=%d\n",name,format, netlist_count);
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
fprintf(fd, "---- start primitive ");
|
|
|
|
|
lab=expandlabel(name, &tmp);
|
|
|
|
|
fprintf(fd, "%d\n",tmp);
|
|
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-13 02:52:37 +02:00
|
|
|
else escape=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\n' && escape ) c=*s++; /* 20171030 eat escaped newlines */
|
|
|
|
|
space=SPACE(c);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-03 12:10:55 +01:00
|
|
|
if( state==TOK_BEGIN && (c=='@' || c=='$') && !escape ) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
2020-10-13 02:52:37 +02:00
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
) {
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_SEP;
|
2020-10-04 23:55:43 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-10-13 02:52:37 +02:00
|
|
|
token[token_pos++]=c; /* 20171029 remove escaping backslashes */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_SEP) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
|
2020-11-21 01:23:00 +01:00
|
|
|
/* get_tok_size==0 indicates that token(+1) does not exist in instance attributes */
|
|
|
|
|
if(!get_tok_size)
|
2020-08-08 15:47:34 +02:00
|
|
|
value=get_tok_value(template, token+1, 0);
|
|
|
|
|
if(!get_tok_size && token[0] =='$') {
|
|
|
|
|
fputs(token + 1, fd);
|
2020-10-13 02:52:37 +02:00
|
|
|
} else if(value && value[0]!='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{ /* instance names (name) and node labels (lab) go thru the expandlabel function. */
|
|
|
|
|
/*if something else must be parsed, put an if here! */
|
|
|
|
|
|
|
|
|
|
if(!(strcmp(token+1,"name"))) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if( (lab=expandlabel(value, &tmp)) != NULL)
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "----name(%s)", lab);
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else if(!(strcmp(token+1,"lab"))) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if( (lab=expandlabel(value, &tmp)) != NULL)
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "----pin(%s)", lab);
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@symname")==0) /* of course symname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf( fd, "%s",skip_dir(xctx->inst[inst].name) );
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-14 21:04:45 +02:00
|
|
|
else if (strcmp(token,"@symname_ext")==0)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fputs(get_cell_w_ext(xctx->inst[inst].name, 0), fd);
|
2020-10-14 21:04:45 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
else if(strcmp(token,"@schname")==0) /* of course schname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
/* fputs(xctx->sch[xctx->currsch],fd); */
|
|
|
|
|
fputs(xctx->current_name, fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present */
|
|
|
|
|
/* in hash table. print multiplicity */
|
|
|
|
|
{ /* and node number: m1 n1 m2 n2 .... */
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(strcmp(get_tok_value(prop,"vhdl_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
for(i=0;i<no_of_pins;i++) {
|
2020-10-15 17:39:21 +02:00
|
|
|
xSymbol *ptr = xctx->inst[inst].ptr+ xctx->sym;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!strcmp( get_tok_value(ptr->rect[PINLAYER][i].prop_ptr,"name",0), token+2)) {
|
|
|
|
|
if(strcmp(get_tok_value(ptr->rect[PINLAYER][i].prop_ptr,"vhdl_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
break;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name 20180911 */
|
|
|
|
|
else if(token[0]=='@' && token[1]=='#') {
|
|
|
|
|
pin_number = atoi(token+2);
|
|
|
|
|
if(pin_number < no_of_pins) {
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][pin_number].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(strcmp(get_tok_value(prop,"vhdl_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,pin_number, &mult, 0, 1);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else if(!strncmp(token,"@tcleval", 8)) {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* char tclcmd[strlen(token)+100] ; */
|
|
|
|
|
size_t s;
|
|
|
|
|
char *tclcmd=NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
s = token_pos + strlen(name) + strlen(xctx->inst[inst].name) + 100;
|
2020-08-08 15:47:34 +02:00
|
|
|
tclcmd = my_malloc(518, s);
|
|
|
|
|
Tcl_ResetResult(interp);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(tclcmd, s, "tclpropeval {%s} {%s} {%s}", token, name, xctx->inst[inst].name);
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(tclcmd);
|
2020-08-16 03:34:45 +02:00
|
|
|
fprintf(fd, "%s", tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1049, &tclcmd);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c!='$' && c!='@' && c!='\0' ) fputc(c,fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c == '@' || c == '$') s--;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN && c!='\0') fputc(c,fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
fputc('\n',fd);
|
|
|
|
|
fprintf(fd, "---- end primitive\n");
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(1050, &template);
|
|
|
|
|
my_free(1051, &format);
|
|
|
|
|
my_free(1052, &name);
|
|
|
|
|
my_free(1053, &token);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 14:15:36 +02:00
|
|
|
/* print verilog element if verilog_format is specified */
|
2020-08-08 15:47:34 +02:00
|
|
|
void print_verilog_primitive(FILE *fd, int inst) /* netlist switch level primitives, 15112003 */
|
|
|
|
|
{
|
|
|
|
|
int i=0, mult, tmp;
|
|
|
|
|
const char *str_ptr;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *lab;
|
|
|
|
|
char *template=NULL,*format=NULL,*s=NULL, *name=NULL, *token=NULL;
|
|
|
|
|
const char *value;
|
|
|
|
|
int sizetok=0;
|
|
|
|
|
int token_pos=0, escape=0;
|
|
|
|
|
int no_of_pins=0;
|
|
|
|
|
/* struct inst_hashentry *ptr; */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
my_strdup(519, &template,
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->templ);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strdup(520, &name,xctx->inst[inst].instname);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!name) my_strdup(4, &name, get_tok_value(template, "name", 0));
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-11 00:13:52 +02:00
|
|
|
/* allow format string override in instance */
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(1186, &format, get_tok_value(xctx->inst[inst].prop_ptr,"verilog_format",0));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!format || !format[0])
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup(522, &format, get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->prop_ptr,"verilog_format",0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if((name==NULL) || (format==NULL) ) {
|
|
|
|
|
my_free(1054, &template);
|
|
|
|
|
my_free(1055, &name);
|
|
|
|
|
my_free(1056, &format);
|
|
|
|
|
return; /*do no netlist unwanted insts(no format) */
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
2020-08-08 15:47:34 +02:00
|
|
|
s=format;
|
2020-11-16 02:25:43 +01:00
|
|
|
dbg(1, "print_verilog_primitive(): name=%s, format=%s netlist_count=%d\n",name,format, netlist_count);
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "---- start primitive ");
|
|
|
|
|
lab=expandlabel(name, &tmp);
|
|
|
|
|
fprintf(fd, "%d\n",tmp);
|
|
|
|
|
/* begin parsing format string */
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c=='\\') {
|
|
|
|
|
escape=1;
|
|
|
|
|
c=*s++;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-13 02:52:37 +02:00
|
|
|
else escape=0;
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c=='\n' && escape ) c=*s++; /* 20171030 eat escaped newlines */
|
2020-10-12 13:13:31 +02:00
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( state==TOK_BEGIN && (c=='@' || c=='$') && !escape ) state=TOK_TOKEN;
|
|
|
|
|
else if(state==TOK_TOKEN && token_pos > 1 &&
|
2020-10-13 02:52:37 +02:00
|
|
|
(
|
|
|
|
|
( (space || c == '$' || c == '@') && !escape ) ||
|
|
|
|
|
( (!space && c != '$' && c != '@') && escape )
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
) {
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_SEP;
|
2020-10-04 23:55:43 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) {
|
2020-10-13 02:52:37 +02:00
|
|
|
token[token_pos++]=c;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_SEP) /* got a token */
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
token_pos=0;
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-11-29 01:59:17 +01:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
|
2020-11-21 01:23:00 +01:00
|
|
|
/* get_tok_size==0 indicates that token(+1) does not exist in instance attributes */
|
|
|
|
|
if(!get_tok_size)
|
2020-08-08 15:47:34 +02:00
|
|
|
value=get_tok_value(template, token+1, 0);
|
|
|
|
|
if(!get_tok_size && token[0] =='$') {
|
|
|
|
|
fputs(token + 1, fd);
|
2020-10-13 02:52:37 +02:00
|
|
|
} else if(value && value[0]!='\0') {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* instance names (name) and node labels (lab) go thru the expandlabel function. */
|
|
|
|
|
/*if something else must be parsed, put an if here! */
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!(strcmp(token+1,"name"))) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if( (lab=expandlabel(value, &tmp)) != NULL)
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "----name(%s)", lab);
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else if(!(strcmp(token+1,"lab"))) {
|
2020-10-12 13:13:31 +02:00
|
|
|
if( (lab=expandlabel(value, &tmp)) != NULL)
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "----pin(%s)", lab);
|
2020-10-12 13:13:31 +02:00
|
|
|
else
|
2020-08-08 15:47:34 +02:00
|
|
|
fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else fprintf(fd, "%s", value);
|
|
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@symname")==0) /* of course symname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fprintf( fd, "%s",skip_dir(xctx->inst[inst]. name) );
|
2020-10-14 21:04:45 +02:00
|
|
|
}
|
|
|
|
|
else if (strcmp(token,"@symname_ext")==0)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
fputs(get_cell_w_ext(xctx->inst[inst].name, 0), fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@schname")==0) /* of course schname must not be present */
|
|
|
|
|
/* in hash table */
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
/* fputs(xctx->sch[xctx->currsch],fd); */
|
|
|
|
|
fputs(xctx->current_name, fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present */
|
|
|
|
|
/* in hash table. print multiplicity */
|
|
|
|
|
{ /* and node number: m1 n1 m2 n2 .... */
|
|
|
|
|
for(i=0;i<no_of_pins;i++)
|
|
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(strcmp(get_tok_value(prop, "verilog_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
for(i=0;i<no_of_pins;i++) {
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
2020-10-11 13:08:32 +02:00
|
|
|
if(!strcmp( get_tok_value(prop,"name",0), token+2)) {
|
|
|
|
|
if(strcmp(get_tok_value(prop, "verilog_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,i, &mult, 0, 1);
|
2020-09-02 12:30:52 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
break;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* reference by pin number instead of pin name, allows faster lookup of the attached net name 20180911 */
|
|
|
|
|
else if(token[0]=='@' && token[1]=='#') {
|
2020-10-11 13:08:32 +02:00
|
|
|
int pin_number = atoi(token+2);
|
|
|
|
|
if(pin_number < no_of_pins) {
|
|
|
|
|
const char *vi;
|
2020-10-15 17:39:21 +02:00
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][pin_number].prop_ptr;
|
2020-10-11 13:08:32 +02:00
|
|
|
vi = get_tok_value(prop,"verilog_ignore",0);
|
|
|
|
|
if(strcmp(vi, "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
str_ptr = net_name(inst,pin_number, &mult, 0, 1);
|
2020-10-11 13:08:32 +02:00
|
|
|
fprintf(fd, "----pin(%s) ", str_ptr);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-11 13:08:32 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
else if(!strncmp(token,"@tcleval", 8)) {
|
2020-08-08 15:47:34 +02:00
|
|
|
/* char tclcmd[strlen(token)+100] ; */
|
|
|
|
|
size_t s;
|
|
|
|
|
char *tclcmd=NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
s = token_pos + strlen(name) + strlen(xctx->inst[inst].name) + 100;
|
2020-08-08 15:47:34 +02:00
|
|
|
tclcmd = my_malloc(524, s);
|
|
|
|
|
Tcl_ResetResult(interp);
|
2020-10-15 17:39:21 +02:00
|
|
|
my_snprintf(tclcmd, s, "tclpropeval {%s} {%s} {%s}", token, name, xctx->inst[inst].name);
|
2020-08-08 15:47:34 +02:00
|
|
|
tcleval(tclcmd);
|
2020-08-16 03:34:45 +02:00
|
|
|
fprintf(fd, "%s", tclresult());
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1057, &tclcmd);
|
|
|
|
|
}
|
2020-10-13 02:52:37 +02:00
|
|
|
if(c!='$' && c!='@' && c!='\0') fputc(c,fd);
|
2020-08-08 15:47:34 +02:00
|
|
|
if(c == '@' || c == '$') s--;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN && c!='\0') fputc(c,fd);
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
fputc('\n',fd);
|
|
|
|
|
fprintf(fd, "---- end primitive\n");
|
|
|
|
|
break ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my_free(1058, &template);
|
|
|
|
|
my_free(1059, &format);
|
|
|
|
|
my_free(1060, &name);
|
|
|
|
|
my_free(1061, &token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int isonlydigit(const char *s)
|
|
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
if(s == NULL || *s == '\0') return 0;
|
|
|
|
|
while( (c = *s) ) {
|
|
|
|
|
if(c < '0' || c > '9') return 0;
|
|
|
|
|
s++;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
const char *find_nth(const char *str, char sep, int n)
|
|
|
|
|
{
|
|
|
|
|
static char *result=NULL;
|
|
|
|
|
static char empty[]="";
|
|
|
|
|
int i;
|
|
|
|
|
char *ptr;
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
if(!str) {
|
|
|
|
|
my_free(1062, &result);
|
|
|
|
|
return empty;
|
|
|
|
|
}
|
|
|
|
|
my_strdup(525, &result, str);
|
|
|
|
|
if(!result) return empty;
|
|
|
|
|
for(i=0, count=1, ptr=result; result[i] != 0; i++) {
|
|
|
|
|
if(result[i]==sep) {
|
|
|
|
|
result[i]=0;
|
|
|
|
|
if(count==n) {
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
ptr=result+i+1;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(count==n) return ptr;
|
|
|
|
|
else return empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* substitute given tokens in a string with their corresponding values */
|
|
|
|
|
/* ex.: name=@name w=@w l=@l ---> name=m112 w=3e-6 l=0.8e-6 */
|
|
|
|
|
/* if s==NULL return emty string */
|
2020-10-14 04:12:34 +02:00
|
|
|
const char *translate(int inst, const char* s)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-31 02:25:41 +02:00
|
|
|
static char empty[]="";
|
2020-08-08 15:47:34 +02:00
|
|
|
static char *result=NULL;
|
|
|
|
|
int size=0, tmp;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state=TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *token=NULL;
|
|
|
|
|
const char *tmp_sym_name;
|
|
|
|
|
int sizetok=0;
|
|
|
|
|
int result_pos=0, token_pos=0;
|
|
|
|
|
/* struct inst_hashentry *ptr; */
|
|
|
|
|
struct stat time_buf;
|
|
|
|
|
struct tm *tm;
|
|
|
|
|
char file_name[PATH_MAX];
|
|
|
|
|
const char *value;
|
|
|
|
|
int escape=0;
|
|
|
|
|
char date[200];
|
|
|
|
|
|
|
|
|
|
if(!s) {
|
|
|
|
|
my_free(1063, &result);
|
2020-08-31 02:25:41 +02:00
|
|
|
return empty;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
size=CADCHUNKALLOC;
|
|
|
|
|
my_realloc(527, &result,size);
|
|
|
|
|
result[0]='\0';
|
|
|
|
|
|
2020-10-14 21:04:45 +02:00
|
|
|
dbg(1, "translate(): substituting props in <%s>, instance <%s>\n",
|
2020-10-15 17:39:21 +02:00
|
|
|
s?s:"NULL",xctx->inst[inst].instname?xctx->inst[inst].instname:"NULL");
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
c=*s++;
|
2020-08-18 01:39:44 +02:00
|
|
|
if(c=='\\') {
|
2020-08-08 15:47:34 +02:00
|
|
|
escape=1;
|
2020-11-24 15:25:37 +01:00
|
|
|
c=*s++; /* do not remove: breaks translation of format strings in netlists (escaping $) */
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-08-18 01:39:44 +02:00
|
|
|
else escape=0;
|
2020-10-14 01:38:51 +02:00
|
|
|
space=SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if( state==TOK_BEGIN && (c=='@' || c=='$' ) && !escape ) state=TOK_TOKEN; /* 20161210 escape */
|
|
|
|
|
else if( state==TOK_TOKEN && (
|
2020-10-12 13:13:31 +02:00
|
|
|
(space && !escape) ||
|
2020-08-08 15:47:34 +02:00
|
|
|
(c =='@' || c == '$') ||
|
|
|
|
|
(!space && escape)
|
2020-10-12 13:13:31 +02:00
|
|
|
)
|
2020-11-03 12:10:55 +01:00
|
|
|
&& token_pos > 1 ) state=TOK_SEP;
|
2020-08-08 15:47:34 +02:00
|
|
|
|
|
|
|
|
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, result_pos, &size);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if(state==TOK_TOKEN) token[token_pos++]=c;
|
|
|
|
|
else if(state==TOK_SEP)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-12 13:13:31 +02:00
|
|
|
token[token_pos]='\0';
|
2020-08-08 15:47:34 +02:00
|
|
|
dbg(2, "translate(): token=%s\n", token);
|
|
|
|
|
|
|
|
|
|
if(!spiceprefix && !strcmp(token, "@spiceprefix")) {
|
|
|
|
|
value = NULL;
|
|
|
|
|
get_tok_size = 0;
|
|
|
|
|
} else {
|
2020-11-29 01:59:17 +01:00
|
|
|
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
|
|
|
|
|
if(!get_tok_size) value=get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->templ, token+1, 0);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!get_tok_size && token[0] =='$') {
|
2020-10-23 23:17:55 +02:00
|
|
|
char *env = getenv(token + 1);
|
|
|
|
|
if(env) { /* do environment var substitution if no xschem definition for $token */
|
|
|
|
|
tmp = strlen(env);
|
|
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
|
|
|
|
memcpy(result+result_pos, env, tmp+1);
|
|
|
|
|
} else { /* no definition found -> subst with token without leading $ */
|
|
|
|
|
tmp=token_pos -1 ; /* we need token_pos -1 chars, ( strlen(token+1) ) , excluding leading '$' */
|
|
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
|
|
|
|
dbg(2, "translate(): token=%s, token_pos = %d\n", token, token_pos);
|
|
|
|
|
memcpy(result+result_pos, token + 1, tmp+1);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
token_pos = 0;
|
|
|
|
|
if(get_tok_size) {
|
2020-10-12 13:13:31 +02:00
|
|
|
tmp=get_tok_value_size; /* strlen(value); */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, value, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
} else if(strcmp(token,"@symname")==0) {
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp_sym_name=xctx->inst[inst].name ? get_cell(xctx->inst[inst].name, 0) : "";
|
2020-08-08 15:47:34 +02:00
|
|
|
tmp=strlen(tmp_sym_name);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos,tmp_sym_name, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
2020-08-12 11:31:42 +02:00
|
|
|
} else if(strcmp(token,"@symname_ext")==0) {
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp_sym_name=xctx->inst[inst].name ? get_cell_w_ext(xctx->inst[inst].name, 0) : "";
|
2020-08-12 11:31:42 +02:00
|
|
|
tmp=strlen(tmp_sym_name);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos,tmp_sym_name, tmp+1);
|
2020-08-12 11:31:42 +02:00
|
|
|
result_pos+=tmp;
|
2020-10-20 01:05:40 +02:00
|
|
|
} else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
|
|
|
|
|
int i, mult;
|
|
|
|
|
int no_of_pins= (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER];
|
|
|
|
|
prepare_netlist_structs(0);
|
|
|
|
|
for(i=0;i<no_of_pins;i++) {
|
|
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][i].prop_ptr;
|
|
|
|
|
if (!strcmp( get_tok_value(prop,"name",0), token+2)) {
|
|
|
|
|
if(strcmp(get_tok_value(prop,"spice_ignore",0), "true")) {
|
2020-11-16 15:44:51 +01:00
|
|
|
const char *str_ptr = net_name(inst,i, &mult, 0, 0);
|
2020-10-20 01:05:40 +02:00
|
|
|
tmp = strlen(str_ptr) +100 ;
|
|
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
|
|
|
|
result_pos += my_snprintf(result + result_pos, tmp, "%s", str_ptr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
} else if(token[0]=='@' && token[1]=='#') {
|
2020-08-08 15:47:34 +02:00
|
|
|
int n;
|
|
|
|
|
char *pin_attr = my_malloc(532, sizetok * sizeof(char));
|
|
|
|
|
char *pin_num_or_name = my_malloc(55, sizetok * sizeof(char));
|
|
|
|
|
|
|
|
|
|
pin_num_or_name[0]='\0';
|
|
|
|
|
pin_attr[0]='\0';
|
|
|
|
|
n=-1;
|
|
|
|
|
sscanf(token+2, "%[^:]:%[^:]", pin_num_or_name, pin_attr);
|
|
|
|
|
if(isonlydigit(pin_num_or_name)) {
|
|
|
|
|
n = atoi(pin_num_or_name);
|
|
|
|
|
}
|
|
|
|
|
else if(pin_num_or_name[0]) {
|
2020-10-15 17:39:21 +02:00
|
|
|
for(n = 0 ; n < (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER]; n++) {
|
|
|
|
|
char *prop = (xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][n].prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!strcmp(get_tok_value(prop,"name",0), pin_num_or_name)) break;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
if(n>=0 && pin_attr[0] && n < (xctx->inst[inst].ptr+ xctx->sym)->rects[PINLAYER]) {
|
2020-10-03 01:04:57 +02:00
|
|
|
char *pin_attr_value = NULL;
|
|
|
|
|
|
|
|
|
|
/* get pin_attr value from instance: "pinnumber(ENABLE)=5" --> return 5, attr "pinnumber" of pin "ENABLE"
|
|
|
|
|
* "pinnumber(3)=6 --> return 6, attr "pinnumber" of 4th pin */
|
|
|
|
|
if(!pin_attr_value) pin_attr_value = get_pin_attr_from_inst(inst, n, pin_attr);
|
|
|
|
|
/* get pin_attr from instance pin attribute string */
|
|
|
|
|
if(!pin_attr_value) {
|
2020-10-12 13:13:31 +02:00
|
|
|
my_strdup(499, &pin_attr_value,
|
2020-11-29 01:59:17 +01:00
|
|
|
get_tok_value((xctx->inst[inst].ptr+ xctx->sym)->rect[PINLAYER][n].prop_ptr, pin_attr, 0));
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-03 01:04:57 +02:00
|
|
|
|
2020-09-30 00:30:48 +02:00
|
|
|
/* @#n:net_name attribute (n = pin number or name) will translate to net name attached to pin
|
|
|
|
|
* if 'net_name=true' attribute is set in instance or symbol */
|
2020-10-03 01:04:57 +02:00
|
|
|
if( !pin_attr_value && !strcmp(pin_attr, "net_name")) {
|
2020-10-15 17:39:21 +02:00
|
|
|
char *instprop = xctx->inst[inst].prop_ptr;
|
|
|
|
|
char *symprop = (xctx->inst[inst].ptr + xctx->sym)->prop_ptr;
|
2020-10-12 13:13:31 +02:00
|
|
|
if( show_pin_net_names && (!strcmp(get_tok_value(instprop, "net_name", 0), "true") ||
|
2020-10-04 23:55:43 +02:00
|
|
|
!strcmp(get_tok_value(symprop, "net_name", 0), "true"))) {
|
2020-10-03 01:04:57 +02:00
|
|
|
prepare_netlist_structs(0);
|
2020-10-12 13:13:31 +02:00
|
|
|
my_strdup2(1175, &pin_attr_value,
|
2020-10-15 17:39:21 +02:00
|
|
|
xctx->inst[inst].node && xctx->inst[inst].node[n] ? xctx->inst[inst].node[n] : "?");
|
2020-10-03 01:04:57 +02:00
|
|
|
/* do not show net_name: set to empty string */
|
|
|
|
|
} else {
|
|
|
|
|
my_strdup2(1178, &pin_attr_value, "");
|
2020-09-30 00:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-03 01:04:57 +02:00
|
|
|
if(!pin_attr_value ) my_strdup(379, &pin_attr_value, "--UNDEF--");
|
|
|
|
|
value = pin_attr_value;
|
|
|
|
|
/* recognize slotted devices: instname = "U3:3", value = "a:b:c:d" --> value = "c" */
|
|
|
|
|
if(value && value[0] != 0 && !strcmp(pin_attr, "pinnumber") ) {
|
2020-08-08 15:47:34 +02:00
|
|
|
char *ss;
|
|
|
|
|
int slot;
|
2020-10-03 01:04:57 +02:00
|
|
|
char *tmpstr = NULL;
|
2020-10-15 17:39:21 +02:00
|
|
|
tmpstr = my_malloc(1176, sizeof(xctx->inst[inst].instname));
|
|
|
|
|
if( (ss=strchr(xctx->inst[inst].instname, ':')) ) {
|
2020-10-03 01:04:57 +02:00
|
|
|
sscanf(ss+1, "%s", tmpstr);
|
|
|
|
|
if(isonlydigit(tmpstr)) {
|
|
|
|
|
slot = atoi(tmpstr);
|
|
|
|
|
if(strstr(value,":")) value = find_nth(value, ':', slot);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-05 13:29:57 +02:00
|
|
|
my_free(1177, &tmpstr);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-10-03 01:04:57 +02:00
|
|
|
tmp=strlen(value);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, value, tmp+1);
|
2020-10-03 01:04:57 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
my_free(1064, &pin_attr_value);
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
my_free(1065, &pin_attr);
|
|
|
|
|
my_free(1066, &pin_num_or_name);
|
|
|
|
|
} else if(strcmp(token,"@sch_last_modified")==0) {
|
|
|
|
|
|
|
|
|
|
my_strncpy(file_name, abs_sym_path(get_tok_value(
|
2020-10-15 17:39:21 +02:00
|
|
|
(xctx->inst[inst].ptr+ xctx->sym)->prop_ptr, "schematic",0 ), "")
|
2020-08-08 15:47:34 +02:00
|
|
|
, S(file_name));
|
|
|
|
|
if(!file_name[0]) {
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strncpy(file_name, add_ext(abs_sym_path(xctx->inst[inst].name, ""), ".sch"), S(file_name));
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
if(!stat(file_name , &time_buf)) {
|
|
|
|
|
tm=localtime(&(time_buf.st_mtime) );
|
|
|
|
|
tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, date, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
2020-10-12 13:13:31 +02:00
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
} else if(strcmp(token,"@sym_last_modified")==0) {
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strncpy(file_name, abs_sym_path(xctx->inst[inst].name, ""), S(file_name));
|
2020-08-08 15:47:34 +02:00
|
|
|
if(!stat(file_name , &time_buf)) {
|
|
|
|
|
tm=localtime(&(time_buf.st_mtime) );
|
|
|
|
|
tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, date, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
} else if(strcmp(token,"@time_last_modified")==0) {
|
2020-10-15 17:39:21 +02:00
|
|
|
my_strncpy(file_name, abs_sym_path(xctx->sch[xctx->currsch], ""), S(file_name));
|
2020-10-12 13:13:31 +02:00
|
|
|
if(!stat(file_name , &time_buf)) {
|
2020-08-08 15:47:34 +02:00
|
|
|
tm=localtime(&(time_buf.st_mtime) );
|
|
|
|
|
tmp=strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", tm);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-12 13:13:31 +02:00
|
|
|
memcpy(result+result_pos, date, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
} else if(strcmp(token,"@schname")==0) {
|
2020-10-15 17:39:21 +02:00
|
|
|
/* tmp=strlen(xctx->sch[xctx->currsch]);*/
|
|
|
|
|
tmp = strlen(xctx->current_name);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
/* memcpy(result+result_pos,xctx->sch[xctx->currsch], tmp+1); */
|
|
|
|
|
memcpy(result+result_pos, xctx->current_name, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
2020-10-15 17:39:21 +02:00
|
|
|
} else if(strcmp(token,"@prop_ptr")==0 && xctx->inst[inst].prop_ptr) {
|
|
|
|
|
tmp=strlen(xctx->inst[inst].prop_ptr);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->inst[inst].prop_ptr, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
else if(strcmp(token,"@schvhdlprop")==0 && xctx->schvhdlprop)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp=strlen(xctx->schvhdlprop);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->schvhdlprop, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
2020-10-12 13:13:31 +02:00
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
else if(strcmp(token,"@schprop")==0 && xctx->schprop)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp=strlen(xctx->schprop);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->schprop, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
/* /20100217 */
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
else if(strcmp(token,"@schsymbolprop")==0 && xctx->schsymbolprop)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp=strlen(xctx->schsymbolprop);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->schsymbolprop, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
2020-10-15 17:39:21 +02:00
|
|
|
else if(strcmp(token,"@schtedaxprop")==0 && xctx->schtedaxprop)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp=strlen(xctx->schtedaxprop);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->schtedaxprop, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
/* /20100217 */
|
|
|
|
|
|
2020-10-15 17:39:21 +02:00
|
|
|
else if(strcmp(token,"@schverilogprop")==0 && xctx->schverilogprop)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-10-15 17:39:21 +02:00
|
|
|
tmp=strlen(xctx->schverilogprop);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-10-15 17:39:21 +02:00
|
|
|
memcpy(result+result_pos,xctx->schverilogprop, tmp+1);
|
2020-08-08 15:47:34 +02:00
|
|
|
result_pos+=tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(c == '@' || c == '$') s--;
|
|
|
|
|
else result[result_pos++]=c;
|
2020-11-03 12:10:55 +01:00
|
|
|
state=TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if(state==TOK_BEGIN) result[result_pos++]=c;
|
2020-10-12 13:13:31 +02:00
|
|
|
if(c=='\0')
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
|
|
|
|
result[result_pos]='\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dbg(2, "translate(): returning %s\n", result);
|
|
|
|
|
my_free(1067, &token);
|
2020-10-12 17:25:57 +02:00
|
|
|
|
2020-10-14 04:12:34 +02:00
|
|
|
/* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions
|
|
|
|
|
* can be calculated */
|
2020-10-14 23:44:53 +02:00
|
|
|
tcl_hook(&result);
|
2020-08-08 15:47:34 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 02:25:41 +02:00
|
|
|
const char *translate2(struct Lcc *lcc, int level, char* s)
|
2020-08-08 15:47:34 +02:00
|
|
|
{
|
2020-08-31 02:25:41 +02:00
|
|
|
static char empty[]="";
|
2020-08-08 15:47:34 +02:00
|
|
|
static char *result = NULL;
|
|
|
|
|
int i, size = 0, tmp, save_tok_size, save_value_size;
|
2020-11-03 12:10:55 +01:00
|
|
|
register int c, state = TOK_BEGIN, space;
|
2020-08-08 15:47:34 +02:00
|
|
|
char *token = NULL;
|
|
|
|
|
const char *tmp_sym_name;
|
|
|
|
|
int sizetok = 0;
|
|
|
|
|
int result_pos = 0, token_pos = 0;
|
|
|
|
|
char *value1 = NULL;
|
|
|
|
|
char *value2 = NULL;
|
|
|
|
|
char *value = NULL;
|
|
|
|
|
int escape = 0;
|
|
|
|
|
|
|
|
|
|
if(!s) {
|
|
|
|
|
my_free(1068, &result);
|
2020-08-31 02:25:41 +02:00
|
|
|
return empty;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
size = CADCHUNKALLOC;
|
|
|
|
|
my_realloc(661, &result, size);
|
|
|
|
|
result[0] = '\0';
|
|
|
|
|
while (1) {
|
|
|
|
|
c = *s++;
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
escape = 1;
|
|
|
|
|
/* we keep backslashes as they should mark end of tokens as for example in: @token1\xxxx@token2
|
|
|
|
|
these backslashes will be 'eaten' at drawing time by translate() */
|
|
|
|
|
/* c = *s++; */
|
|
|
|
|
}
|
|
|
|
|
else escape = 0;
|
2020-10-14 01:38:51 +02:00
|
|
|
space = SPACE(c);
|
2020-11-03 12:10:55 +01:00
|
|
|
if (state == TOK_BEGIN && c == '@' && !escape) state = TOK_TOKEN;
|
|
|
|
|
else if (state == TOK_TOKEN && ( (space && !escape) || c == '@' || (!space && escape)) && token_pos > 1) {
|
|
|
|
|
state = TOK_SEP;
|
2020-10-04 23:55:43 +02:00
|
|
|
}
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, result_pos, &size);
|
|
|
|
|
STR_ALLOC(&token, token_pos, &sizetok);
|
2020-11-03 12:10:55 +01:00
|
|
|
if (state == TOK_TOKEN) token[token_pos++] = c;
|
|
|
|
|
else if (state == TOK_SEP) {
|
2020-08-08 15:47:34 +02:00
|
|
|
token[token_pos] = '\0';
|
|
|
|
|
token_pos = 0;
|
|
|
|
|
|
|
|
|
|
if(!spiceprefix && !strcmp(token, "@spiceprefix")) {
|
|
|
|
|
my_free(1069, &value1);
|
|
|
|
|
get_tok_size = 0;
|
|
|
|
|
} else {
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup2(332, &value1, get_tok_value(lcc[level].prop_ptr, token + 1, 0));
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
|
|
|
|
value = "";
|
|
|
|
|
if(get_tok_size) {
|
|
|
|
|
value = value1;
|
|
|
|
|
i = level;
|
|
|
|
|
/* recursive substitution of value using parent level prop_str attributes */
|
|
|
|
|
while(i > 1) {
|
|
|
|
|
save_tok_size = get_tok_size;
|
|
|
|
|
save_value_size = get_tok_value_size;
|
2020-11-29 01:59:17 +01:00
|
|
|
my_strdup2(440, &value2, get_tok_value(lcc[i-1].prop_ptr, value, 0));
|
2020-08-08 15:47:34 +02:00
|
|
|
if(get_tok_size && value2[0]) {
|
|
|
|
|
value = value2;
|
|
|
|
|
} else {
|
|
|
|
|
/* restore last successful get_tok_value() size parameters */
|
|
|
|
|
get_tok_size = save_tok_size;
|
|
|
|
|
get_tok_value_size = save_value_size;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
}
|
|
|
|
|
tmp = get_tok_value_size; /* strlen(value); */
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + 1 + result_pos, &size); /* +1 to add leading '$' */
|
2020-11-17 01:29:47 +01:00
|
|
|
/* prefix substituted token with a '$' so it will be recognized by translate()
|
|
|
|
|
* for last level translation with instance placement prop_ptr attributes at
|
|
|
|
|
* drawing/netlisting time. */
|
2020-08-08 15:47:34 +02:00
|
|
|
memcpy(result + result_pos , "$", 1);
|
|
|
|
|
memcpy(result + result_pos + 1 , value, tmp + 1);
|
|
|
|
|
result_pos += tmp + 1;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(token, "@symname") == 0) {
|
2020-08-12 11:31:42 +02:00
|
|
|
tmp_sym_name = lcc[level].symname ? get_cell(lcc[level].symname, 0) : "";
|
|
|
|
|
tmp = strlen(tmp_sym_name);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-08-12 11:31:42 +02:00
|
|
|
memcpy(result + result_pos, tmp_sym_name, tmp + 1);
|
|
|
|
|
result_pos += tmp;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(token, "@symname_ext") == 0) {
|
2020-08-08 15:47:34 +02:00
|
|
|
tmp_sym_name = lcc[level].symname ? get_cell_w_ext(lcc[level].symname, 0) : "";
|
|
|
|
|
tmp = strlen(tmp_sym_name);
|
2020-10-16 16:34:15 +02:00
|
|
|
STR_ALLOC(&result, tmp + result_pos, &size);
|
2020-08-08 15:47:34 +02:00
|
|
|
memcpy(result + result_pos, tmp_sym_name, tmp + 1);
|
|
|
|
|
result_pos += tmp;
|
|
|
|
|
}
|
2020-08-12 11:31:42 +02:00
|
|
|
|
2020-08-08 15:47:34 +02:00
|
|
|
if (c == '@') s--;
|
|
|
|
|
else result[result_pos++] = c;
|
2020-11-03 12:10:55 +01:00
|
|
|
state = TOK_BEGIN;
|
2020-08-08 15:47:34 +02:00
|
|
|
}
|
2020-11-03 12:10:55 +01:00
|
|
|
else if (state == TOK_BEGIN) result[result_pos++] = c;
|
2020-08-08 15:47:34 +02:00
|
|
|
if (c == '\0') {
|
|
|
|
|
result[result_pos] = '\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-14 23:44:53 +02:00
|
|
|
if(result && strstr(result, "tcleval(")== result) {
|
|
|
|
|
tcl_hook(&result);
|
|
|
|
|
}
|
2020-08-08 15:47:34 +02:00
|
|
|
my_free(1070, &token);
|
|
|
|
|
my_free(1071, &value1);
|
|
|
|
|
my_free(1072, &value2);
|
|
|
|
|
return result;
|
|
|
|
|
}
|