Automatic replacement of .param by .func

.param xxx1(x,y) = '2*x+y'  --->  .func xxx1(x,y) '2*x+y'
This commit is contained in:
Holger Vogt 2025-03-01 16:14:00 +01:00
parent 83d3890490
commit d3de6b0f3f
1 changed files with 75 additions and 1 deletions

View File

@ -134,6 +134,7 @@ static void expand_section_references(struct card *deck,
static void inp_grab_func(struct function_env *, struct card *deck);
static void inp_fix_inst_calls_for_numparam(
struct names *subckt_w_params, struct card *deck);
static void inp_replace_param_by_func(struct card* deck);
static void inp_expand_macros_in_func(struct function_env *);
static struct card *inp_expand_macros_in_deck(
struct function_env *, struct card *deck);
@ -1124,7 +1125,7 @@ struct card *inp_readall(FILE *fp, const char *dir_name, const char* file_name,
subckt_params_to_param(working);
rv.line_number = inp_split_multi_param_lines(working, rv.line_number);
inp_replace_param_by_func(working);
inp_fix_macro_param_func_paren_io(working);
static char *statfcn[] = {
@ -5674,6 +5675,12 @@ static int inp_split_multi_param_lines(struct card *card, int line_num)
int paren_depth = 0;
beg_param = skip_back_ws(equal_ptr, curr_line);
/* Special treatment if .param is a .func:
move back to opening '(' */
if (*(beg_param - 1) == ')') {
while (beg_param > curr_line && *beg_param != '(')
beg_param--;
}
beg_param = skip_back_non_ws(beg_param, curr_line);
end_param = skip_ws(equal_ptr + 1);
while (*end_param && !isspace_c(*end_param)) {
@ -7981,6 +7988,73 @@ static void inp_fix_temper_in_param(struct card *deck)
inp_delete_funcs(funcs);
}
/* Convert .param lines containing user defined functions
* into .func lines:
* .param xxx1(x,y) = '2*x+y' ---> .func xxx1(x,y) ''2*x+y''
*/
static void inp_replace_param_by_func(struct card* deck)
{
int skip_control = 0;
struct card* card;
for (card = deck; card; card = card->nextcard) {
char* curr_line = card->line;
if (*curr_line == '*')
continue;
/* exclude any command inside .control ... .endc */
if (ciprefix(".control", curr_line)) {
skip_control++;
continue;
}
else if (ciprefix(".endc", curr_line)) {
skip_control--;
continue;
}
else if (skip_control > 0) {
continue;
}
if (ciprefix(".para", curr_line)) {
char *fcn, *equal_ptr, *tmpstr;
bool found = FALSE;
fcn = nexttok(curr_line); // skip .param
if (!fcn)
continue;
equal_ptr = find_assignment(curr_line);
if (!equal_ptr)
continue;
tmpstr = equal_ptr;
while (tmpstr > curr_line) {
tmpstr--;
if (*tmpstr == ')') {
found = TRUE;
break;
}
}
if (!found)
continue;
*equal_ptr = ' ';
curr_line[0] = ' ';
curr_line[1] = '.';
curr_line[2] = 'f';
curr_line[3] = 'u';
curr_line[4] = 'n';
curr_line[5] = 'c';
fprintf(stdout, "%s\n", curr_line);
}
}
}
/* Convert .param lines containing function 'agauss' and others
* (function name handed over by *fcn), into .func lines: