From 069017e07ca24565c56590464ac3bbf7a0306c47 Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Mon, 7 Mar 2022 01:42:53 +0100 Subject: [PATCH] recursively resolve parameter passing throughout hierarchy and show resolved value in leaf cells if possible --- XSchemWin/README_WIN | 34 ++++++++++++++++++++++++++++++++++ src/actions.c | 3 ++- src/save.c | 4 ++++ src/token.c | 40 ++++++++++++++++++++++++++++++++++------ src/xinit.c | 10 +++++++++- src/xschem.h | 1 + src/xschem.tcl | 8 ++++++++ 7 files changed, 92 insertions(+), 8 deletions(-) diff --git a/XSchemWin/README_WIN b/XSchemWin/README_WIN index a2ae9d94..5200a9c7 100644 --- a/XSchemWin/README_WIN +++ b/XSchemWin/README_WIN @@ -96,3 +96,37 @@ INSTRUCTIONS TO ADD XSCHEM TO VISUAL STUDIO 2019 4. running from Visual Studio 2019 F5 + +INSTRUCTIONS TO COMPILE CAIRO AND COMPILE XSCHEM WITH IT ON VISUAL STUDIO 2019 + +1. Create a cairo_win directory in XSchemWin +2. cd cairo_win and git clone from "https://github.com/gleb-t/Cairo-VS" (inside the newly cairo_win directory, use command "git clone https://github.com/gleb-t/Cairo-VS .") + Note: Latest source can be downloaded from the following (or alternatively, you can use packed-lib-source.zip provided by gleb-t): + a. cairo: https://www.cairographics.org/releases/ (e.g. cairo-1.16.0.tar.xz) + b. freetype: https://github.com/freetype/freetype + c. libpng: http://www.libpng.org/pub/png/libpng.html (e.g., libpng-1.6.37.tar.gz) + d. pixman: https://www.cairographics.org/releases/ (e.g., pixman-0.40.0.tar.gz) + e. zlib: https://zlib.net/ (e.g., zlib-1.2.11.tar.gz) + Put each source content into the appropriate subdirectory in cairo_win directory. + For example, in cairo_win/cairo folder, you should have the following folders: boilerplate, build, doc, perf, src, test, util, ... +3. Compile freetype (x64, release_static) library in freetype directory: + a. Open builds/windows/vc2010/freetype.sln in VS2019 + b. Select Release_static; x64 and build solution (library file is created in freetype\objs\x64\Release Static\freetype.lib) + c. create a libs folder in cairo_win, and make a copy of Release_Static\freetype.lib into this lib folder +4. Compile cairo: Open VS 2019 solution in projects/cairo.sln + a. Change to Release, x64 build + b. Change cairo > Properties > Librarian > General > freetype271.lib to freetype.lib (Optional: Also do this for Debug,x64 build if needed) + c. Edit cairo > Header Files > cairo-features.h by adding the following line "#define CAIRO_HAS_XLIB_SURFACE 1" at the end + d. Build solution (If VS2019 complaint about missing freetype.lib, redo step (3c) by copying the file over again) + e. cairo.lib and pixman.lib are in cairo_win/projects/x64/Release +5. Setup xschem VS 2019 to compile with cairo library + a. Uncomment "#define HAS_CAIRO 1" and "#define CAIRO_WIN32_STATIC_BUILD" in config.h + Note: Step b and onward is updated in XSchemWin_cairo.vcxproj + For Release, x64 + * Properties > VC++ Directories > Include: ;cairo_win\cairo\src;cairo_win\projects\cairo\src; + Libraries: ;cairo_win\projects\x64\Release;cairo_win\libs + * Properties > Linker > Input > Additional Dependencies: Add ;cairo.lib;pixman.lib;zlib.lib;libpng.lib;freetype.lib; + For Debug, x64 + * Properties > VC++ Directories > Include: ;cairo_win\cairo\src;cairo_win\projects\cairo\src; + Libraries: ;cairo_win\projects\x64\Debug;cairo_win\libs + * Properties > Linker > Input > Additional Dependencies: Add ;cairo.lib;pixman.lib;zlibd.lib;libpngd.lib;freetype.lib; \ No newline at end of file diff --git a/src/actions.c b/src/actions.c index 9e583a46..e4d23ac7 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1270,7 +1270,8 @@ void descend_schematic(int instnumber) } my_strdup(14, &xctx->sch_path[xctx->currsch+1], xctx->sch_path[xctx->currsch]); xctx->sch_path_hash[xctx->currsch+1] =0; - + my_strdup(1516, &xctx->hier_attr[xctx->currsch].prop_ptr, + xctx->inst[xctx->sel_array[0].n].prop_ptr); inst_number = 1; if(inst_mult > 1) { /* on multiple instances ask where to descend, to correctly evaluate the hierarchy path you descend to */ diff --git a/src/save.c b/src/save.c index e063ce6f..68f8e732 100644 --- a/src/save.c +++ b/src/save.c @@ -3213,6 +3213,10 @@ void descend_symbol(void) my_strcat(365, &xctx->sch_path[xctx->currsch+1], str); my_strcat(366, &xctx->sch_path[xctx->currsch+1], "."); xctx->sch_path_hash[xctx->currsch+1] = 0; + + my_strdup(1518, &xctx->hier_attr[xctx->currsch].prop_ptr, + xctx->inst[xctx->sel_array[0].n].prop_ptr); + xctx->sch_inst_number[xctx->currsch+1] = 1; my_free(921, &str); xctx->previous_instance[xctx->currsch]=xctx->sel_array[0].n; diff --git a/src/token.c b/src/token.c index 42bc6dd5..2135ebdf 100644 --- a/src/token.c +++ b/src/token.c @@ -2771,6 +2771,10 @@ const char *translate(int inst, const char* s) char *sch = NULL; int sp_prefix; int s_pnetname; + int level; + Lcc *lcc; + char *value1 = NULL, *value2 = NULL; + s_pnetname = tclgetboolvar("show_pin_net_names"); sp_prefix = tclgetboolvar("spiceprefix"); @@ -2779,6 +2783,8 @@ const char *translate(int inst, const char* s) return empty; } + level = xctx->currsch; + lcc = xctx->hier_attr; size=CADCHUNKALLOC; my_realloc(527, &result,size); result[0]='\0'; @@ -3014,10 +3020,27 @@ const char *translate(int inst, const char* s) result_pos+=tmp; } } else { - tmp=strlen(value); + int i = level; + my_strdup2(1521, &value1, value); + /* recursive substitution of value using parent level prop_str attributes */ + while(i > 0) { + my_strdup2(1522, &value2, get_tok_value(lcc[i-1].prop_ptr, value1, 0)); + if(xctx->tok_size && value2[0]) { + dbg(1, "value2=%s\n", value2); + my_strdup2(1523, &value1, value2); + } + dbg(1, "2 translate(): lcc[%d].prop_ptr=%s, value1=%s\n", i-1, lcc[i-1].prop_ptr, value1); + i--; + } + + + tmp=strlen(value1); STR_ALLOC(&result, tmp + result_pos, &size); - memcpy(result+result_pos, value, tmp+1); + memcpy(result+result_pos, value1, tmp+1); result_pos+=tmp; + my_free(1524, &value1); + my_free(1525, &value2); + } } token_pos = 0; @@ -3060,8 +3083,9 @@ const char *translate2(Lcc *lcc, int level, char* s) return empty; } size = CADCHUNKALLOC; - my_realloc(661, &result, size); + my_realloc(1528, &result, size); result[0] = '\0'; + dbg(1, "translate2(): s=%s\n", s); while (1) { c = *s++; if (c == '\\') { @@ -3083,6 +3107,7 @@ const char *translate2(Lcc *lcc, int level, char* s) token[token_pos] = '\0'; token_pos = 0; + dbg(1, "translate2(): lcc[%d].prop_ptr=%s\n", level, lcc[level].prop_ptr); /* if spiceprefix==0 and token == @spiceprefix then set empty value */ if(!tclgetboolvar("spiceprefix") && !strcmp(token, "@spiceprefix")) { my_free(1069, &value1); @@ -3098,6 +3123,7 @@ const char *translate2(Lcc *lcc, int level, char* s) while(i > 1) { save_tok_size = xctx->tok_size; my_strdup2(440, &value2, get_tok_value(lcc[i-1].prop_ptr, value, 0)); + dbg(1, "translate2(): lcc[%d].prop_ptr=%s\n", i-1, lcc[i-1].prop_ptr); if(xctx->tok_size && value2[0]) { value = value2; } else { @@ -3141,8 +3167,10 @@ const char *translate2(Lcc *lcc, int level, char* s) break; } } - my_free(1070, &token); - my_free(1071, &value1); - my_free(1072, &value2); + my_free(1532, &token); + my_free(1533, &value1); + my_free(1071, &value2); + dbg(1, "translate2(): result=%s\n", result); return tcl_hook2(&result); } + diff --git a/src/xinit.c b/src/xinit.c index d2749320..cb4f17e5 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -358,7 +358,12 @@ static void free_xschem_data() my_free(1132, &xctx->maxa); my_free(1133, &xctx->maxl); my_free(1108, &xctx->sel_array); - for(i=0;isch_path[i]); + for(i=0;isch_path[i]); + my_free(959, &xctx->hier_attr[i].prop_ptr); + my_free(960, &xctx->hier_attr[i].symname); + } + my_free(1099, &xctx->gridpoint); my_free(1214, &xctx->biggridpoint); my_free(1135, &xctx->gc); @@ -529,6 +534,9 @@ static void alloc_xschem_data(const char *top_path, const char *win_path) for(i=0;isch_path[i]=NULL; xctx->sch_path_hash[i]=0; + xctx->hier_attr[i].prop_ptr = NULL; + xctx->hier_attr[i].symname = NULL; + xctx->hier_attr[i].fd = NULL; } my_strdup(1187, &xctx->sch_path[0],"."); xctx->sch_inst_number[0] = 1; diff --git a/src/xschem.h b/src/xschem.h index 3bd3b405..2de01ee8 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -944,6 +944,7 @@ typedef struct { void (*clear_undo)(void); int case_insensitive; /* for case insensitive compare where needed */ int (*x_strcmp)(const char *, const char *); + Lcc hier_attr[CADMAXHIER]; /* hierarchical recursive attribute substitution when descending */ } Xschem_ctx; /* GLOBAL VARIABLES */ diff --git a/src/xschem.tcl b/src/xschem.tcl index 23c91522..ccfe35f5 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -351,6 +351,14 @@ proc sframe {container} { } #### /Scrollable frame +## evaluate expression. if expression has errors or does not evaluate return expression as is +proc ev {s} { + if {![catch {expr $s} res]} { + return [format %.4g $res] + } else { + return $s + } +} proc netlist {source_file show netlist_file} { global XSCHEM_SHAREDIR flat_netlist hspice_netlist netlist_dir global verilog_2001 debug_var OS