print_spice_element(): when expanding format @variables, if substituted value contains @var do another round of translate() to replace @var with instance assigned var=xxx value

This commit is contained in:
stefan schippers 2024-01-21 00:00:01 +01:00
parent 289a979c61
commit 9ceb274b5e
2 changed files with 10 additions and 4 deletions

View File

@ -211,18 +211,22 @@ static int spice_netlist(FILE *fd, int spice_stop )
print_spice_element(fd, i) ; /* this is the element line */
fprintf(fd,"**** end user architecture code\n");
} else {
char *val = NULL;
const char *m;
if(print_spice_element(fd, i)) {
fprintf(fd, "**** end_element\n");
}
/* hash device_model attribute if any */
m = translate(i, get_tok_value(xctx->inst[i].prop_ptr, "device_model", 2));
my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->inst[i].prop_ptr, "device_model", 2));
m = val;
if(strchr(val, '@')) m = translate(i, val);
if(m[0]) str_hash_lookup(&model_table, model_name(m), m, XINSERT);
else {
m = get_tok_value( (xctx->inst[i].ptr+ xctx->sym)->prop_ptr, "device_model", 0);
if(m[0]) str_hash_lookup(&model_table, model_name(m), m, XINSERT);
}
my_free(_ALLOC_ID_, &model_name_result);
my_free(_ALLOC_ID_, &val);
}
}
}

View File

@ -2138,6 +2138,7 @@ int print_spice_element(FILE *fd, int inst)
}
else if (state==TOK_SEP) /* got a token */
{
char *val = NULL;
size_t token_exists = 0;
token[token_pos]='\0';
token_pos=0;
@ -2147,11 +2148,11 @@ int print_spice_element(FILE *fd, int inst)
value=NULL;
} else {
size_t tok_val_len;
dbg(1, "print_spice_element(): token: |%s|\n", token);
value = get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0);
my_strdup2(_ALLOC_ID_, &val, get_tok_value(xctx->inst[inst].prop_ptr, token+1, 0));
value = val;
if(strchr(value, '@')) value = translate(inst, val);
tok_val_len = strlen(value);
if(!strcmp(token, "@spiceprefix")) {
my_realloc(_ALLOC_ID_, &spiceprefixtag, tok_val_len+22);
my_snprintf(spiceprefixtag, tok_val_len+22, "**** spice_prefix %s\n", value);
@ -2386,6 +2387,7 @@ int print_spice_element(FILE *fd, int inst)
}
if(c == '@' || c == '%' ) s--;
state=TOK_BEGIN;
my_free(_ALLOC_ID_, &val);
}
else if(state==TOK_BEGIN && c!='\0') {
char str[2];