From f267077e99f388a73ecbf1f967b8b511cbc8e06b Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Fri, 14 Jun 2024 08:21:43 +0200 Subject: [PATCH] allow @symname , @param (param defined in symbol template string) translation in instance or symbol spice_sym_def attributes --- scconfig/src/gui/find_gl.c | 29 +++++++++++++++++++++++++---- src/actions.c | 6 +++--- src/spice_netlist.c | 19 +++++++++++++++---- src/token.c | 15 ++++++++++++++- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/scconfig/src/gui/find_gl.c b/scconfig/src/gui/find_gl.c index 0d77086b..dc041d44 100644 --- a/scconfig/src/gui/find_gl.c +++ b/scconfig/src/gui/find_gl.c @@ -94,16 +94,19 @@ int find_gl(const char *name, int logdepth, int fatal) int find_gl_vao(const char *name, int logdepth, int fatal) { - const char *test_c = + const char *test_c_templ = NL "#include " + NL "#include <%s/gl.h>" NL "int main()" NL "{" NL " glBindVertexArray(0);" NL " return 0;" NL "}" NL; + const char *incs_templ = "#define GL_GLEXT_PROTOTYPES\n%s\n#include <%s/gl.h>\n#include <%s/glext.h>"; + char test_c[512], incs2[512]; const char *node = "libs/gui/gl/vao"; - const char *cflags, *ldflags, *incs; + const char *cflags, *ldflags, *incs, *ip; if (require("cc/cc", logdepth, fatal)) return try_fail(logdepth, node); @@ -114,14 +117,24 @@ int find_gl_vao(const char *name, int logdepth, int fatal) cflags = get("libs/gui/gl/cflags"); ldflags = get("libs/gui/gl/ldflags"); incs = get("libs/gui/gl/includes"); + ip = get("libs/gui/gl/include_prefix"); report("Checking for gl vao... "); logprintf(logdepth, "find_gl_vao...\n"); logdepth++; + sprintf(test_c, test_c_templ, ip); + logprintf(logdepth, "trying vao with includes '%s'\n", incs); if (try_icl_norun(logdepth, node, test_c, incs, cflags, ldflags) != 0) return 0; + if (strlen(ip) + strlen(incs)+ strlen(incs_templ) + 8 < sizeof(incs2)) { + sprintf(incs2, incs_templ, incs, ip, ip); + logprintf(logdepth, "trying vao with includes2 '%s'\n", incs2); + if (try_icl_norun(logdepth, node, test_c, incs2, cflags, ldflags) != 0) + return 0; + } + return try_fail(logdepth, node); } @@ -137,7 +150,8 @@ int find_gl_fb_attachment(const char *name, int logdepth, int fatal) NL " return 0;" NL "}" NL; - char test_c[512]; + const char *incs_templ = "#define GL_GLEXT_PROTOTYPES\n%s\n#include <%s/gl.h>\n#include <%s/glext.h>"; + char test_c[512], incs2[512]; const char *node = "libs/gui/gl/fb_attachment"; const char *cflags, *ldflags, *incs, *ip; @@ -157,10 +171,17 @@ int find_gl_fb_attachment(const char *name, int logdepth, int fatal) logdepth++; sprintf(test_c, test_c_templ, ip); - + logprintf(logdepth, "trying fb_att* with includes '%s'\n", incs); if (try_icl_norun(logdepth, node, test_c, incs, cflags, ldflags) != 0) return 0; + if (strlen(ip) + strlen(incs)+ strlen(incs_templ) + 8 < sizeof(incs2)) { + sprintf(incs2, incs_templ, incs, ip, ip); + logprintf(logdepth, "trying fb_att* with includes2 '%s'\n", incs2); + if (try_icl_norun(logdepth, node, test_c, incs2, cflags, ldflags) != 0) + return 0; + } + return try_fail(logdepth, node); } diff --git a/src/actions.c b/src/actions.c index 30c4a5a3..f1ffde79 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1942,9 +1942,9 @@ void get_additional_symbols(int what) char symbol_base_sch[PATH_MAX] = ""; /* copy instance based *_sym_def attributes to symbol */ - my_strdup(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"spice_sym_def",0)); - my_strdup(_ALLOC_ID_, &verilog_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"verilog_sym_def",0)); - my_strdup(_ALLOC_ID_, &vhdl_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"vhdl_sym_def",0)); + my_strdup(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"spice_sym_def",4)); + my_strdup(_ALLOC_ID_, &verilog_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"verilog_sym_def",4)); + my_strdup(_ALLOC_ID_, &vhdl_sym_def, get_tok_value(xctx->inst[i].prop_ptr,"vhdl_sym_def",4)); my_strdup2(_ALLOC_ID_, &sch, tcl_hook2( str_replace( get_tok_value(xctx->inst[i].prop_ptr,"schematic",2), "@symname", get_cell(xctx->inst[i].name, 0), '\\'))); diff --git a/src/spice_netlist.c b/src/spice_netlist.c index 63f4b1a1..11322071 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -605,7 +605,7 @@ int spice_block_netlist(FILE *fd, int i) /* int multip; */ char *extra=NULL; int split_f; - const char *sym_def; + char *sym_def = NULL; char *name = NULL; const char *default_schematic; @@ -636,9 +636,20 @@ int spice_block_netlist(FILE *fd, int i) fprintf(fd, "\n* expanding symbol: %s # of pins=%d\n", name,xctx->sym[i].rects[PINLAYER] ); if(xctx->sym[i].base_name) fprintf(fd, "** sym_path: %s\n", abs_sym_path(xctx->sym[i].base_name, "")); else fprintf(fd, "** sym_path: %s\n", sanitized_abs_sym_path(name, "")); - sym_def = get_tok_value(xctx->sym[i].prop_ptr,"spice_sym_def",0); - if(sym_def[0]) { - fprintf(fd, "%s\n", sym_def); + my_strdup(_ALLOC_ID_, &sym_def, get_tok_value(xctx->sym[i].prop_ptr,"spice_sym_def",0)); + if(sym_def) { + char *symname_attr = NULL; + char *templ = NULL; + const char *translated_sym_def; + my_strdup2(_ALLOC_ID_, &templ, get_tok_value(xctx->sym[i].prop_ptr, "template", 0)); + my_mstrcat(_ALLOC_ID_, &symname_attr, "symname=", get_cell(name, 0), NULL); + translated_sym_def = translate3(sym_def, 1, "", + templ, + symname_attr); + my_free(_ALLOC_ID_, &templ); + my_free(_ALLOC_ID_, &symname_attr); + fprintf(fd, "%s\n", translated_sym_def); + my_free(_ALLOC_ID_, &sym_def); } else { const char *s = sanitize(get_cell(name, 0)); fprintf(fd, "** sch_path: %s\n", sanitized_abs_sym_path(filename, "")); diff --git a/src/token.c b/src/token.c index 500ebdf0..63e5839f 100644 --- a/src/token.c +++ b/src/token.c @@ -1822,14 +1822,21 @@ void print_tedax_subckt(FILE *fd, int symbol) static int has_included_subcircuit(int inst, int symbol, char **result) { char *spice_sym_def = NULL; + const char *translated_sym_def; int ret = 0; + my_strdup2(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->inst[inst].prop_ptr, "spice_sym_def", 0)); if(!spice_sym_def[0]) { my_strdup2(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->sym[symbol].prop_ptr, "spice_sym_def", 0)); } + if(xctx->tok_size) { char *symname = NULL; + char *templ = NULL; + char *symname_attr = NULL; + + my_strdup2(_ALLOC_ID_, &templ, get_tok_value(xctx->sym[symbol].prop_ptr, "template", 0)); my_strdup2(_ALLOC_ID_, &symname, get_tok_value(xctx->inst[inst].prop_ptr, "schematic", 0)); if(!symname[0]) { my_strdup2(_ALLOC_ID_, &symname, get_tok_value(xctx->sym[symbol].prop_ptr, "schematic", 0)); @@ -1837,10 +1844,16 @@ static int has_included_subcircuit(int inst, int symbol, char **result) if(!symname[0]) { my_strdup2(_ALLOC_ID_, &symname, xctx->sym[symbol].name); } + my_mstrcat(_ALLOC_ID_, &symname_attr, "symname=", get_cell(symname, 0), NULL); + translated_sym_def = translate3(spice_sym_def, 1, "", + templ, + symname_attr); strtolower(symname); tclvareval("has_included_subcircuit {", get_cell(symname, 0), "} {", - spice_sym_def, "}", NULL); + translated_sym_def, "}", NULL); + my_free(_ALLOC_ID_, &templ); my_free(_ALLOC_ID_, &symname); + my_free(_ALLOC_ID_, &symname_attr); if(tclresult()[0]) { char *subckt_pin, *pin_save; char *net, *net_save;