From e803d993bbeaacfbb5f5038ac455ca57db381ce7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Mon, 15 Dec 2025 14:57:02 +0100 Subject: [PATCH] Enable creating a netlist with only the linear instances --- src/frontend/subckt.c | 55 +++++++++++++++++++++++++++++++++++++++++++ src/frontend/subckt.h | 1 + 2 files changed, 56 insertions(+) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index a0fed2696..c81f28750 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -943,6 +943,61 @@ struct card* inp_deckcopy_ln(struct card* deck) return nd; } /* end of function inp_deckcopy_ln */ +/* + * Copy a deck, without the ->actualLine lines, without comment lines, and + * without .control section(s), without dot commands, copy only linear instances. + * Keep the line numbers. + */ +struct card* inp_deckcopy_linear(struct card* deck) +{ + struct card* d = NULL, * nd = NULL; + int skip_control = 0; + + while (deck) { + /* exclude any command inside .control ... .endc */ + if (ciprefix(".control", deck->line)) { + skip_control++; + deck = deck->nextcard; + continue; + } + else if (ciprefix(".endc", deck->line)) { + skip_control--; + deck = deck->nextcard; + continue; + } + else if (skip_control > 0) { + deck = deck->nextcard; + continue; + } + /* linear instances only */ + else if (!strchr("ehfgvirlck", *(deck->line)) || strchr(deck->line, '=')) { + deck = deck->nextcard; + continue; + } + if (nd) { /* First card already found */ + /* d is the card at the end of the deck */ + d = d->nextcard = TMALLOC(struct card, 1); + } + else { /* This is the first card */ + nd = d = TMALLOC(struct card, 1); + } + d->w = deck->w; + d->l = deck->l; + d->nf = deck->nf; + d->linenum_orig = deck->linenum_orig; + d->linesource = deck->linesource; + d->linenum = deck->linenum; + d->compmod = deck->compmod; + d->line = copy(deck->line); + if (deck->error) { + d->error = copy(deck->error); + } + d->actualLine = NULL; + deck = deck->nextcard; + } /* end of loop over cards in the source deck */ + + return nd; +} /* end of function inp_deckcopy_linear */ /*------------------------------------------------------------------- * struct bxx_buffer, diff --git a/src/frontend/subckt.h b/src/frontend/subckt.h index 3d93bf36f..05bcd1df9 100644 --- a/src/frontend/subckt.h +++ b/src/frontend/subckt.h @@ -10,5 +10,6 @@ struct card *inp_subcktexpand(struct card *deck); struct card *inp_deckcopy(struct card *deck); struct card *inp_deckcopy_oc(struct card *deck); struct card *inp_deckcopy_ln(struct card *deck); +struct card *inp_deckcopy_linear(struct card *deck); #endif