1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-12-22 12:53:19 +02:00

add %iprint, to track variables during instantiation

This commit is contained in:
Werner Almesberger 2012-05-27 14:09:40 -03:00
parent 91154440a3
commit 3c39600c1c
8 changed files with 148 additions and 12 deletions

11
README
View File

@ -684,6 +684,7 @@ most of which mimick the effect of GUI operations:
%move <identifier> [<number>] <identifier>
%frame <identifier> <qualified-base>
%print <expression>
%iprint <expression>
%meas <identifier>
%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.

View File

@ -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();
}

6
fpd.h
View File

@ -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);

2
fpd.l
View File

@ -136,6 +136,8 @@ SP [\t ]*
return TOK_DBG_FRAME; }
<INITIAL>"%print" { BEGIN(NOKEYWORD);
return TOK_DBG_PRINT; }
<INITIAL>"%iprint" { BEGIN(NOKEYWORD);
return TOK_DBG_IPRINT; }
<INITIAL>"%meas" { BEGIN(NOKEYWORD);
return TOK_DBG_MEAS; }
<INITIAL>"%dump" { BEGIN(NOKEYWORD);

17
fpd.y
View File

@ -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 = $<num>3.n;
}
| TOK_DBG_IPRINT expr
{
$$ = new_obj(ot_iprint);
$$->base = NULL;
$$->u.iprint.expr = $2;
}
;
pad_type:

4
obj.c
View File

@ -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();
}

10
obj.h
View File

@ -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;

101
test/iprint Executable file
View File

@ -0,0 +1,101 @@
#!/bin/sh
. ./Common
###############################################################################
fped "iprint: loop" <<EOF
loop x = 1, 3
%iprint x
EOF
expect <<EOF
1
2
3
EOF
#------------------------------------------------------------------------------
fped "iprint: two tables (independent)" <<EOF
table { a } { 1 } { 2 }
table { b } { 3 } { 4 }
%iprint a*10+b
EOF
expect <<EOF
13
14
23
24
EOF
#------------------------------------------------------------------------------
fped "iprint: two tables (2nd references 1st)" <<EOF
table { a } { 1 } { 2 }
table { b } { 3+a } { 4+a }
%iprint a*10+b
EOF
expect <<EOF
14
15
25
26
EOF
#------------------------------------------------------------------------------
fped "iprint: two tables (1st references 2nd)" <<EOF
table { a } { 1+b } { 2+b }
table { b } { 3 } { 4 }
%iprint a*10+b
EOF
expect <<EOF
43
54
53
64
EOF
#------------------------------------------------------------------------------
fped "iprint: inside frame (global variable)" <<EOF
frame foo {
%iprint n
}
loop n = 1, 2
frame foo @
EOF
expect <<EOF
1
2
EOF
#------------------------------------------------------------------------------
fped "iprint: inside frame (local variable) " <<EOF
frame foo {
set n1 = n+1
%iprint n1
}
loop n = 1, 2
frame foo @
EOF
expect <<EOF
2
3
EOF
#------------------------------------------------------------------------------
fped_fail "iprint: undefined variable" <<EOF
%iprint foo
EOF
expect <<EOF
undefined variable "foo"
EOF
###############################################################################