From 3c39600c1c20b570a3e56586451dc1ef382bc6bc Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 27 May 2012 14:09:40 -0300 Subject: [PATCH] add %iprint, to track variables during instantiation --- README | 11 +++++- delete.c | 9 +++-- fpd.h | 6 ++-- fpd.l | 2 ++ fpd.y | 17 ++++++--- obj.c | 4 +++ obj.h | 10 ++++-- test/iprint | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 148 insertions(+), 12 deletions(-) create mode 100755 test/iprint diff --git a/README b/README index 876ebd7..a634e96 100644 --- a/README +++ b/README @@ -684,6 +684,7 @@ most of which mimick the effect of GUI operations: %move [] %frame %print +%iprint %meas %dump %exit @@ -715,7 +716,15 @@ parent frame's origin can be references as "@". %dump writes the footprint definition in the fped language to standard output. %exit immediately exits fped, without invoking the GUI. -%print evaluates the expression and prints the result to standard output. +%print and %iprint evaluate the expression and print the result to +standard output. The difference between them is that %print runs only +once and without explicit instantiation, while %iprint is treated as +a regular object and is executed as many times as instantiation +demands. + +For example, after loop x = 1, 3 we would obtain just 1 with %print +while %iprint would display, 1, 2, and 3. + %meas performs an instantiation and prints the value of the labeled measurement. diff --git a/delete.c b/delete.c index bb056e3..7128f9e 100644 --- a/delete.c +++ b/delete.c @@ -1,8 +1,8 @@ /* * delete.c - Object deletion * - * Written 2009, 2010 by Werner Almesberger - * Copyright 2009, 2010 by Werner Almesberger + * Written 2009, 2010, 2012 by Werner Almesberger + * Copyright 2009, 2010, 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -143,6 +143,8 @@ static int obj_has_ref(const struct obj *obj, const struct vec *ref) return obj->u.arc.start == ref || obj->u.arc.end == ref; case ot_meas: return obj->u.meas.high == ref; + case ot_iprint: + return 0; default: abort(); } @@ -238,6 +240,9 @@ static void destroy_obj(struct obj *obj) if (obj->u.meas.offset) free_expr(obj->u.meas.offset); break; + case ot_iprint: + free_expr(obj->u.iprint.expr); + break; default: abort(); } diff --git a/fpd.h b/fpd.h index 74f61c7..356c777 100644 --- a/fpd.h +++ b/fpd.h @@ -1,8 +1,8 @@ /* * fpd.c - Things fpd.l and fpd.y export * - * Written 2009 by Werner Almesberger - * Copyright 2009 by Werner Almesberger + * Written 2009, 2012 by Werner Almesberger + * Copyright 2009, 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ extern const char *var_id; extern struct value *var_value_list; +int dbg_print(const struct expr *expr, const struct frame *frame); + void scan_empty(void); void scan_expr(const char *s); void scan_var(const char *s); diff --git a/fpd.l b/fpd.l index d637e3a..ccc2623 100644 --- a/fpd.l +++ b/fpd.l @@ -136,6 +136,8 @@ SP [\t ]* return TOK_DBG_FRAME; } "%print" { BEGIN(NOKEYWORD); return TOK_DBG_PRINT; } +"%iprint" { BEGIN(NOKEYWORD); + return TOK_DBG_IPRINT; } "%meas" { BEGIN(NOKEYWORD); return TOK_DBG_MEAS; } "%dump" { BEGIN(NOKEYWORD); diff --git a/fpd.y b/fpd.y index d1db83c..8e36603 100644 --- a/fpd.y +++ b/fpd.y @@ -365,17 +365,17 @@ static int dbg_link_frame(const char *frame_name, } -static int dbg_print(const struct expr *expr) +int dbg_print(const struct expr *expr, const struct frame *frame) { const char *s; struct num num; - s = eval_str(expr, curr_frame); + s = eval_str(expr, frame); if (s) { printf("%s\n", s); return 1; } - num = eval_num(expr, curr_frame); + num = eval_num(expr, frame); if (is_undef(num)) return 0; printf("%lg%s\n", num.n, str_unit(num)); @@ -457,7 +457,8 @@ static int dbg_meas(const char *name) %token TOK_PAD TOK_RPAD TOK_HOLE TOK_RECT TOK_LINE TOK_CIRC TOK_ARC %token TOK_MEAS TOK_MEASX TOK_MEASY TOK_UNIT %token TOK_NEXT TOK_NEXT_INVERTED TOK_MAX TOK_MAX_INVERTED -%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME TOK_DBG_PRINT +%token TOK_DBG_DEL TOK_DBG_MOVE TOK_DBG_FRAME +%token TOK_DBG_PRINT TOK_DBG_IPRINT %token TOK_DBG_DUMP TOK_DBG_EXIT TOK_DBG_TSORT TOK_DBG_MEAS %token TOK_ALLOW_OVERLAP TOK_ALLOW_TOUCH @@ -666,7 +667,7 @@ debug_item: } | TOK_DBG_PRINT expr { - if (!dbg_print($2)) + if (!dbg_print($2, curr_frame)) YYABORT; } | TOK_DBG_MEAS ID @@ -976,6 +977,12 @@ obj: $$->u.frame.ref->active_ref = $$; $$->u.frame.lineno = $3.n; } + | TOK_DBG_IPRINT expr + { + $$ = new_obj(ot_iprint); + $$->base = NULL; + $$->u.iprint.expr = $2; + } ; pad_type: diff --git a/obj.c b/obj.c index c4f8f14..ff2b328 100644 --- a/obj.c +++ b/obj.c @@ -25,6 +25,7 @@ #include "overlap.h" #include "layer.h" #include "delete.h" +#include "fpd.h" #include "obj.h" @@ -316,6 +317,9 @@ static int generate_objs(struct frame *frame, struct coord base_pos, goto error; inst_meas_hint(obj, offset.n); break; + case ot_iprint: + dbg_print(obj->u.iprint.expr, frame); + break; default: abort(); } diff --git a/obj.h b/obj.h index dd901c1..7e5f81f 100644 --- a/obj.h +++ b/obj.h @@ -1,8 +1,8 @@ /* * obj.h - Object definition model * - * Written 2009-2011 by Werner Almesberger - * Copyright 2009-2011 by Werner Almesberger + * Written 2009-2012 by Werner Almesberger + * Copyright 2009-2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -186,6 +186,7 @@ enum obj_type { ot_line, ot_arc, ot_meas, + ot_iprint, }; struct frame_ref { @@ -215,6 +216,10 @@ struct arc { struct expr *width; }; +struct iprint { + struct expr *expr; +}; + struct obj { enum obj_type type; const char *name; /* NULL if anonymous */ @@ -226,6 +231,7 @@ struct obj { struct hole hole; struct arc arc; struct meas meas; + struct iprint iprint; } u; struct frame *frame; struct vec *base; diff --git a/test/iprint b/test/iprint new file mode 100755 index 0000000..84c1ca2 --- /dev/null +++ b/test/iprint @@ -0,0 +1,101 @@ +#!/bin/sh +. ./Common + +############################################################################### + +fped "iprint: loop" <