From 1a898f63ef68cc5286325dc416244f6e76cec0f6 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 9 Sep 2025 11:24:39 +0200 Subject: [PATCH] proc is_xschem_file: if symbol contains instances of "logo" or "launcher" type do not consider it as a schematic. add "xschem get_sym_type" command --- doc/xschem_man/developer_info.html | 4 ++++ src/save.c | 2 +- src/scheduler.c | 16 ++++++++++++++++ src/xschem.h | 2 ++ src/xschem.tcl | 12 ++++++++++-- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index 67059a17..024575ac 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -899,6 +899,10 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
  • get_sch_from_sym inst [symbol]
  •     get schematic associated with instance 'inst'
        if inst==-1 and a 'symbol' name is given get sch associated with symbol 
    +
  • get_sym_type symname
  • +   get "type" value from global attributes of symbol,
    +   looking frst in loaded symbols, then looking in symbol file
    +   symbols that are not already loaded in the design will not be loaded 
  • get_tok str tok [with_quotes]
  •     get value of token 'tok' in string 'str'
        'with_quotes' (default:0) is an integer passed to get_tok_value() 
    diff --git a/src/save.c b/src/save.c index e972b7a6..9c938e80 100644 --- a/src/save.c +++ b/src/save.c @@ -3909,7 +3909,7 @@ void pop_undo(int redo, int set_modify_status) * return symbol type in type pointer or "" if no type or no symbol found * if pintable given (!=NULL) hash all symbol pins * if embed_fd is not NULL read symbol from embedded '[...]' tags using embed_fd file pointer */ -static void get_sym_type(const char *symname, char **type, +void get_sym_type(const char *symname, char **type, Int_hashtable *pintable, FILE *embed_fd, int *sym_n_pins) { int i, c, n = 0; diff --git a/src/scheduler.c b/src/scheduler.c index b6c09405..5122520b 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -2066,6 +2066,22 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg Tcl_SetResult(interp, filename, TCL_VOLATILE); } + /* get_sym_type symname + * get "type" value from global attributes of symbol, + * looking frst in loaded symbols, then looking in symbol file + * symbols that are not already loaded in the design will not be loaded */ + else if(!strcmp(argv[1], "get_sym_type") ) + { + char *s=NULL; + if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;} + + if(argc < 3) {Tcl_SetResult(interp, "Missing arguments", TCL_STATIC);return TCL_ERROR;} + get_sym_type(argv[2], &s, NULL, NULL, NULL); + + Tcl_SetResult(interp, s, TCL_VOLATILE); + my_free(_ALLOC_ID_, &s); + } + /* get_tok str tok [with_quotes] * get value of token 'tok' in string 'str' * 'with_quotes' (default:0) is an integer passed to get_tok_value() */ diff --git a/src/xschem.h b/src/xschem.h index c99b23c3..587b51db 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1512,6 +1512,8 @@ extern int spectre_block_netlist(FILE *fd, int i, int alert); extern void remove_symbols(void); extern void remove_symbol(int i); extern void clear_drawing(void); +extern void get_sym_type(const char *symname, char **type, + Int_hashtable *pintable, FILE *embed_fd, int *sym_n_pins); extern int is_from_web(const char *f); extern int load_sym_def(const char name[], FILE *embed_fd); extern int descend_symbol(void); diff --git a/src/xschem.tcl b/src/xschem.tcl index cd038356..cc33acce 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -4069,10 +4069,18 @@ proc is_xschem_file {f} { set generator 1 # continue } - if { [regexp {^[TKGVSE] \{} $line] } { incr score } + if { [regexp {^[TKFGVSE] \{} $line] } { incr score } if { [regexp {^[BL] +[0-9]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +\{} $line] } {incr score} if { [regexp {^N +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +[-0-9.eE]+ +\{} $line] } {incr score} - if { [regexp {^C +\{[^{}]+\} +[-0-9.eE]+ +[-0-9.eE]+ +[0-3]+ +[0-3]+ +\{} $line] } {incr instances; incr score} + if { [regexp {^C +\{[^{}]+\} +[-0-9.eE]+ +[-0-9.eE]+ +[0-3]+ +[0-3]+ +\{} $line] } { + set symname [regsub {([^{]+{)([^}]+)(}.*)} $line {\2}] + set type [xschem get_sym_type $symname] + # title/launcher instances in symbols are allowed, do not indicate it is a schematic. + if {![regexp "^(logo|launcher)$" $type]} { + incr instances + incr score + } + } if { [regexp "^v\[ \t\]+\{xschem\[ \t\]+version\[ \t\]*=.*\[ \t\]+file_version\[ \t\]*=" $line] } { set ret 1 }