From dcafbbcf9004577aec4a02efd0a9fe899a1ec657 Mon Sep 17 00:00:00 2001 From: Brian Taylor Date: Mon, 30 Jan 2023 14:41:49 -0800 Subject: [PATCH] Add port directions when logicexp or pindly are present. --- src/frontend/logicexp.c | 9 +++++++++ src/frontend/udevices.c | 20 ++++++++++++++++++-- src/include/ngspice/udevices.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/frontend/logicexp.c b/src/frontend/logicexp.c index 7b239e2d5..ec4d95d08 100644 --- a/src/frontend/logicexp.c +++ b/src/frontend/logicexp.c @@ -340,6 +340,7 @@ static int lex_gate_op(int c) static int lex_ident(int c) { + /* Pspice and MicroCap are vague about what defines an identifier */ if (isalnum(c) || c == '_' || c == '/' || c == '-') return c; else @@ -1614,6 +1615,7 @@ BOOL f_logicexp(char *line) if (!expect_token(t, LEX_ID, NULL, TRUE, 10)) goto error_return; (void) add_sym_tab_entry(parse_lexer->lexer_buf, SYM_INPUT, &parse_lexer->lexer_sym_tab); + u_remember_pin(parse_lexer->lexer_buf, 1); } /* num_outs output ids */ for (i = 0; i < num_outs; i++) { @@ -1621,6 +1623,7 @@ BOOL f_logicexp(char *line) if (!expect_token(t, LEX_ID, NULL, TRUE, 11)) goto error_return; (void) add_sym_tab_entry(parse_lexer->lexer_buf, SYM_OUTPUT, &parse_lexer->lexer_sym_tab); + u_remember_pin(parse_lexer->lexer_buf, 2); } /* timing model */ t = lex_scan(); @@ -2154,6 +2157,7 @@ static BOOL new_gen_output_models(LEXER lx) if (pline) { pline_arr[idx++] = pline; (void) set_ena_name(ds_get_buf(&enable_name), pline); + u_remember_pin(lx->lexer_buf, 3); } else { goto err_return; } @@ -2247,6 +2251,7 @@ BOOL f_pindly(char *line) if (!expect_token(t, LEX_ID, NULL, TRUE, 61)) goto error_return; pline = add_new_pindly_line(pindly_tab); (void) set_in_name(lxr->lexer_buf, pline); + u_remember_pin(lxr->lexer_buf, 1); } /* num_ena enable nodes which are ignored */ @@ -2254,6 +2259,9 @@ BOOL f_pindly(char *line) for (i = 0; i < num_ena + num_refs; i++) { t = lexer_scan(lxr); if (!expect_token(t, LEX_ID, NULL, TRUE, 62)) goto error_return; + if (i < num_ena) { + u_remember_pin(lxr->lexer_buf, 1); + } } /* num_ios output ids */ pline = NULL; @@ -2265,6 +2273,7 @@ BOOL f_pindly(char *line) else pline = pline->next; (void) set_out_name(lxr->lexer_buf, pline); + u_remember_pin(lxr->lexer_buf, 2); } if (!new_gen_output_models(lxr)) { diff --git a/src/frontend/udevices.c b/src/frontend/udevices.c index 634853f45..6ef3b11b5 100644 --- a/src/frontend/udevices.c +++ b/src/frontend/udevices.c @@ -389,6 +389,22 @@ static void add_port_name(char *name) add_pin_name(name, &port_names_list); } +void u_remember_pin(char *name, int type) +{ + switch (type) { + case 1: add_input_pin(name); + break; + case 2: add_output_pin(name); + break; + case 3: add_tristate_pin(name); + break; + case 4: add_port_name(name); + break; + default: + break; + } +} + static void add_all_port_names(char *subckt_line) { char *copy_line, *tok, *pos; @@ -398,7 +414,7 @@ static void add_all_port_names(char *subckt_line) } if (ps_port_directions & 4) { printf("TRANS_IN %s\n", subckt_line); - } else if (ps_port_directions) { + } else if (ps_port_directions & 1) { printf("%s\n", subckt_line); } copy_line = tprintf("%s", subckt_line); @@ -921,7 +937,7 @@ static void determine_port_type(void) port_type = "IN"; } } - if (ps_port_directions) { + if (ps_port_directions & 1) { printf("port: %s %s\n", x->name, port_type); } } diff --git a/src/include/ngspice/udevices.h b/src/include/ngspice/udevices.h index 0c4ec37e3..5ee5a5fb1 100644 --- a/src/include/ngspice/udevices.h +++ b/src/include/ngspice/udevices.h @@ -9,5 +9,6 @@ struct card *replacement_udevice_cards(void); void cleanup_udevice(void); void u_add_instance(char *str); void u_add_logicexp_model(char *tmodel, char *xspice_gate, char *model_name); +void u_remember_pin(char *name, int type); #endif