mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-04 23:05:21 +02:00
b2/: add "print VAR" command in substitutions (for debugging/tracing)
This commit is contained in:
parent
3f4a06843a
commit
ee0a2a41fa
14
b2/lang.y
14
b2/lang.y
@ -627,9 +627,16 @@ block:
|
||||
free((void *) $3);
|
||||
$$->next = $5;
|
||||
}
|
||||
| WORD WORD
|
||||
| WORD WORD block
|
||||
{
|
||||
$$ = parse_jump($1, $2);
|
||||
if (!strcmp($1, "print")) {
|
||||
$$ = subst_print($2);
|
||||
$$->next = $3;
|
||||
} else {
|
||||
$$ = parse_jump($1, $2);
|
||||
if ($3)
|
||||
yyerror("unreachable code");
|
||||
}
|
||||
}
|
||||
| WORD '$'
|
||||
{
|
||||
@ -644,6 +651,9 @@ block:
|
||||
else
|
||||
$$ = parse_jump($1, NULL);
|
||||
}
|
||||
| WORD PATTERN
|
||||
{
|
||||
}
|
||||
;
|
||||
|
||||
word_or_dollar:
|
||||
|
24
b2/subex.c
24
b2/subex.c
@ -180,6 +180,24 @@ static int do_match(const char **var, const regex_t *re,
|
||||
}
|
||||
|
||||
|
||||
static void do_print(const char *var,
|
||||
const struct param *in, const struct param *out)
|
||||
{
|
||||
const char *list = "out";
|
||||
const char *val;
|
||||
|
||||
val = var_lookup(out, var);
|
||||
if (!val) {
|
||||
val = var_lookup(in, var);
|
||||
list = "in";
|
||||
}
|
||||
if (val)
|
||||
printf("%s(%s) = \"%s\"\n", var, list, val);
|
||||
else
|
||||
printf("%s = ?\n", var);
|
||||
}
|
||||
|
||||
|
||||
static const struct subst *recurse_sub(const struct subst *sub,
|
||||
const struct param *in, const char *matched_var, const char *matched_val,
|
||||
const regmatch_t *match, const char *units, struct param **out,
|
||||
@ -216,6 +234,12 @@ static const struct subst *recurse_sub(const struct subst *sub,
|
||||
var = matched_var;
|
||||
do_assign(var, out, sub->u.assign.op, tmp);
|
||||
break;
|
||||
case st_print:
|
||||
var = sub->u.print;
|
||||
if (var == dollar)
|
||||
var = matched_var;
|
||||
do_print(var, in, *out);
|
||||
break;
|
||||
case st_end:
|
||||
return &jump_end;
|
||||
case st_ignore:
|
||||
|
15
b2/subst.c
15
b2/subst.c
@ -248,6 +248,16 @@ struct subst *subst_assign(const char *dst, enum relop op, const char *pat)
|
||||
}
|
||||
|
||||
|
||||
struct subst *subst_print(const char *var)
|
||||
{
|
||||
struct subst *sub;
|
||||
|
||||
sub = alloc_subst(st_print);
|
||||
sub->u.print = var;
|
||||
return sub;
|
||||
}
|
||||
|
||||
|
||||
struct subst *subst_end(void)
|
||||
{
|
||||
return alloc_subst(st_end);
|
||||
@ -376,6 +386,8 @@ static void recurse_fin(struct subst *sub, const struct parent *parent)
|
||||
yyerror("$ without match");
|
||||
check_chunks(sub->u.assign.pat, parent, prev);
|
||||
break;
|
||||
case st_print:
|
||||
break;
|
||||
case st_end:
|
||||
break;
|
||||
case st_ignore:
|
||||
@ -446,6 +458,9 @@ static void recurse_dump(FILE *file, const struct subst *sub, int level)
|
||||
dump_chunks(file, sub->u.assign.pat);
|
||||
fprintf(file, "\n");
|
||||
break;
|
||||
case st_print:
|
||||
fprintf(file, "print %s\n", sub->u.print);
|
||||
break;
|
||||
case st_end:
|
||||
fprintf(file, "end\n");
|
||||
break;
|
||||
|
@ -46,6 +46,7 @@ enum subst_type {
|
||||
st_ignore, /* ignore the part */
|
||||
st_break, /* jump to an outer block */
|
||||
st_continue, /* repeat an outer block */
|
||||
st_print, /* print a variable, for debugging */
|
||||
};
|
||||
|
||||
struct subst {
|
||||
@ -62,6 +63,7 @@ struct subst {
|
||||
enum relop op;
|
||||
struct chunk *pat;
|
||||
} assign;
|
||||
const char *print;
|
||||
const struct subst *jump;
|
||||
const char *tmp; /* jump target name; for subst_finalize */
|
||||
} u;
|
||||
@ -78,6 +80,7 @@ extern const char *fn;
|
||||
|
||||
struct subst *subst_match(const char *src, const char *re, char **res);
|
||||
struct subst *subst_assign(const char *dst, enum relop op, const char *pat);
|
||||
struct subst *subst_print(const char *var);
|
||||
struct subst *subst_end(void);
|
||||
struct subst *subst_ignore(void);
|
||||
struct subst *subst_break(const char *block);
|
||||
|
78
b2/test/subprint
Executable file
78
b2/test/subprint
Executable file
@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
. ./Common
|
||||
|
||||
###############################################################################
|
||||
|
||||
tst "substitutions: print input variable" -ds -q foo=bar <<EOF
|
||||
!-s
|
||||
print foo
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
print foo
|
||||
foo(in) = "bar"
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: print output variable" -q <<EOF
|
||||
!-s
|
||||
foo = x
|
||||
print foo
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
foo(out) = "x"
|
||||
foo=x
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: print output variable overriding input" -q x=y <<EOF
|
||||
!-s
|
||||
x = z
|
||||
print x
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x(out) = "z"
|
||||
x=z
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: print unknown variable" -q <<EOF
|
||||
!-s
|
||||
print x
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
x = ?
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: print conditionally defined variable" -q x=y <<EOF
|
||||
!-s
|
||||
x=y { z=1 }
|
||||
print z
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
z(out) = "1"
|
||||
z=1
|
||||
EOF
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
tst "substitutions: print conditionally undefined variable" -q x=z <<EOF
|
||||
!-s
|
||||
x=y { z=1 }
|
||||
print z
|
||||
EOF
|
||||
|
||||
expect <<EOF
|
||||
z = ?
|
||||
EOF
|
||||
|
||||
###############################################################################
|
Loading…
Reference in New Issue
Block a user