Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a4b3833
Choose a base ref
...
head repository: m-labs/flickernoise
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a5468c2
Choose a head ref
  • 5 commits
  • 9 files changed
  • 1 contributor

Commits on Jan 28, 2012

  1. ptest: -c -c compiles into FPVM code and dumps the result

    Also changed compiler.c to export init_fpvm, for sharing with ptest.
    wpwrak committed Jan 28, 2012
    Copy the full SHA
    ed83089 View commit details
  2. tests: new command "pvm" to generate and pretty-print FPVM code

    The prettification is done by ptest/prvm.pl
    wpwrak committed Jan 28, 2012
    Copy the full SHA
    1a05965 View commit details
  3. compiler: completed boolean "and" and "or"

    This commit:
    
    - fixes a bug in the parser that made it not recognize && and ||
      (it did accept band and bor),
    - adds op_band and op_bor to ptest.c, and
    - adds test cases "and" and "or"
    wpwrak committed Jan 28, 2012
    Copy the full SHA
    6e741aa View commit details
  4. test/Common: don't require argument of equiv1 and equiv2 to be a file…

    … name
    
    This changes the use from  equiv1 FILE  to  equiv1 <FILE
    With the change, we can also pass simpler expressions directly
    on the command line, with  equiv1 "EXPRESSION"
    
    Also updated test/rewrite
    wpwrak committed Jan 28, 2012
    Copy the full SHA
    933ac8f View commit details
  5. Copy the full SHA
    a5468c2 View commit details
Showing with 318 additions and 38 deletions.
  1. +1 −1 src/compiler/compiler.c
  2. +1 −0 src/compiler/compiler.h
  3. +1 −1 src/compiler/parser.y
  4. +29 −0 src/compiler/ptest/prvm.pl
  5. +72 −28 src/compiler/ptest/ptest.c
  6. +13 −6 src/compiler/test/Common
  7. +79 −0 src/compiler/test/and
  8. +79 −0 src/compiler/test/or
  9. +43 −2 src/compiler/test/rewrite
2 changes: 1 addition & 1 deletion src/compiler/compiler.c
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ static void comp_report(struct compiler_sc *sc, const char *format, ...)
sc->rmc(outbuf);
}

static void init_fpvm(struct fpvm_fragment *fragment, int vector_mode)
void init_fpvm(struct fpvm_fragment *fragment, int vector_mode)
{
/*
* We need to pass these through unique() because the parser does
1 change: 1 addition & 0 deletions src/compiler/compiler.h
Original file line number Diff line number Diff line change
@@ -247,6 +247,7 @@ struct patch {

typedef void (*report_message)(const char *);

void init_fpvm(struct fpvm_fragment *fragment, int vector_mode);
struct patch *patch_compile(const char *basedir, const char *patch_code, report_message rmc);
struct patch *patch_compile_filename(const char *filename, const char *patch_code, report_message rmc);
struct patch *patch_copy(struct patch *p);
2 changes: 1 addition & 1 deletion src/compiler/parser.y
Original file line number Diff line number Diff line change
@@ -351,7 +351,7 @@ expr(N) ::= cond_expr(A). {
N = A;
}

cond_expr(N) ::= equal_expr(A). {
cond_expr(N) ::= bool_or_expr(A). {
N = A;
}

29 changes: 29 additions & 0 deletions src/compiler/ptest/prvm.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/perl
#
# prvm.pl - FPVM code dump prettifier
#
# Copyright 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
# the Free Software Foundation, version 3 of the License.
#

$r{"R0002"} = "R2";
while (<>) {
next if /^==/;
if (/^(R\S+)\s(.*)/) {
$r = $1;
$v = $2;
$v = sprintf("%g", $v) if $v =~ /^[-0-9]/;
$r{$r} = $v if $r ne "R0002";
next;
}
for $r (keys %r) {
s/\b$r\b/$r{$r}/g;
}
s/<R2>//;
s/ +/ /g;
s/^\d{4}: //;
print;
}
100 changes: 72 additions & 28 deletions src/compiler/ptest/ptest.c
Original file line number Diff line number Diff line change
@@ -138,6 +138,12 @@ static void dump_ast(const struct ast_node *ast)
case op_bnot:
op("!", ast);
break;
case op_band:
op("&&", ast);
break;
case op_bor:
op("||", ast);
break;
default:
abort();
}
@@ -344,33 +350,62 @@ static void compile(const char *pgm)
}


#if 0
static void compile_raw(const char *pgm)
static const char *assign_raw(struct parser_comm *comm,
struct sym *sym, struct ast_node *node)
{
struct patch patch;
struct compiler_sc sc = {
.p = &patch
};
struct patch *p;
struct fpvm_fragment *frag = comm->u.fragment;

memset(&patch, 0, sizeof(patch));
patch.rmc = report;
if(fpvm_do_assign(frag, &sym->fpvm_sym, node))
return NULL;
else
return strdup(fpvm_get_last_error(frag));
}


static const char *assign_raw_fail(struct parser_comm *comm,
struct sym *sym, struct ast_node *node)
{
return strdup("unsupported assignment mode");
}

if (!parse_patch(&sc, pgm)) {
symtab_free();
exit(1);
}
patch.perframe_prog_length = fpvm_default_schedule(&sc.pfv_fragment,
(unsigned *) patch.perframe_prog,
(unsigned *) patch.perframe_regs);
patch.pervertex_prog_length = fpvm_default_schedule(&sc.pvv_fragment,
(unsigned *) patch.pervertex_prog,
(unsigned *) patch.pervertex_regs);

static const char *assign_image_fail(struct parser_comm *comm,
int number, const char *name)
{
if (!quiet)
show_patch(p);
printf("image %d = \"%s\"\n", number, name);
return NULL;
}


static void compile_vm(const char *pgm)
{
struct fpvm_fragment fragment;
struct parser_comm comm = {
.u.fragment = &fragment,
.assign_default = assign_raw,
.assign_per_frame = assign_raw,
.assign_per_vertex = assign_raw_fail,
.assign_image_name = assign_image_fail,
};
int ok;

init_fpvm(&fragment, 0);
fpvm_set_bind_mode(&fragment, FPVM_BIND_ALL);
symtab_init();
ok = parse(pgm, TOK_START_ASSIGN, &comm);

if (ok)
fpvm_dump(&fragment);
symtab_free();
if (ok)
return;

fflush(stdout);
fprintf(stderr, "%s\n", comm.msg);
free((void *) comm.msg);
exit(1);
}
#endif


static void free_buffer(void)
@@ -382,8 +417,9 @@ static void free_buffer(void)
static void usage(const char *name)
{
fprintf(stderr,
"usage: %s [-c|-f error] [-n runs] [-q] [-s] [-Wwarning...] [expr]\n\n"
"usage: %s [-c [-c]|-f error] [-n runs] [-q] [-s] [-Wwarning...] [expr]\n\n"
" -c generate code and dump generated code (unless -q is set)\n"
" -c -c generate and dump VM code\n"
" -f error fail any assignment with specified error message\n"
" -n runs run compilation repeatedly (default: run only once)\n"
" -q quiet operation\n"
@@ -407,7 +443,7 @@ int main(int argc, char **argv)
while ((c = getopt(argc, argv, "cf:n:qsW:")) != EOF)
switch (c) {
case 'c':
codegen = 1;
codegen++;
break;
case 'f':
fail = optarg;
@@ -450,12 +486,20 @@ int main(int argc, char **argv)
usage(*argv);
}

while (repeat--) {
if (codegen)
compile(buffer);
else
while (repeat--)
switch (codegen) {
case 0:
parse_only(buffer);
}
break;
case 1:
compile(buffer);
break;
case 2:
compile_vm(buffer);
break;
default:
usage(*argv);
}

return 0;
}
19 changes: 13 additions & 6 deletions src/compiler/test/Common
Original file line number Diff line number Diff line change
@@ -67,9 +67,8 @@ sedit()
equiv1()
{
echo -n "$1: " 1>&2
one=$2
shift 2
$VALGRIND ${PTST:-../ptest/ptest} "$@" <"$one" >_out 2>&1 || {
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _out
rm -f _out
@@ -80,9 +79,7 @@ equiv1()

equiv2()
{
two=$1
shift
$VALGRIND ${PTST:-../ptest/ptest} "$@" <"$two" >_two 2>&1 || {
$VALGRIND ${PTST:-../ptest/ptest} "$@" >_two 2>&1 || {
echo FAILED "($SCRIPT)" 1>&2
cat _two
rm -f _out _two
@@ -98,3 +95,13 @@ equiv2()
rm -f _out _two _diff
passed=`expr ${passed:-0} + 1`
}


fpvm()
{
one=$1
shift
ptest "$one" -c -c "$@"
${PRVM:-../ptest/prvm.pl} _out >_tmp || exit 1
mv _tmp _out
}
79 changes: 79 additions & 0 deletions src/compiler/test/and
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh
. ./Common

###############################################################################

ptest "and: band(a, b)" << EOF
sx = band(a, b)
EOF
expect <<EOF
sx = (&& a b)
EOF

#------------------------------------------------------------------------------

ptest "and: a && b" << EOF
sx = a && b
EOF
expect <<EOF
sx = (&& a b)
EOF

#------------------------------------------------------------------------------

ptest "and: 0 && 0" << EOF
sx = 0 && 0
EOF
expect <<EOF
sx = 0
EOF

#------------------------------------------------------------------------------

ptest "and: 1 && 0" << EOF
sx = 1 && 0
EOF
expect <<EOF
sx = 0
EOF

#------------------------------------------------------------------------------

ptest "and: 0 && 1" << EOF
sx = 0 && 1
EOF
expect <<EOF
sx = 0
EOF

#------------------------------------------------------------------------------

ptest "and: 1 && 1" << EOF
sx = 1 && 1
EOF
expect <<EOF
sx = 1
EOF

#------------------------------------------------------------------------------

ptest "and: a && b == c" << EOF
sx = a && b == c
EOF
expect <<EOF
sx = (&& a (equal b c))
EOF

#------------------------------------------------------------------------------

fpvm "and: a && b (generate code)" <<EOF
sx = a && b
EOF
expect <<EOF
COPY a -> R2
IF 1,0 -> R-003
COPY b -> R2
IF R-003,0 -> sx
EOF

###############################################################################
79 changes: 79 additions & 0 deletions src/compiler/test/or
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh
. ./Common

###############################################################################

ptest "or: bor(a, b)" << EOF
sx = bor(a, b)
EOF
expect <<EOF
sx = (|| a b)
EOF

#------------------------------------------------------------------------------

ptest "or: a || b" << EOF
sx = a || b
EOF
expect <<EOF
sx = (|| a b)
EOF

#------------------------------------------------------------------------------

ptest "or: 0 || 0" << EOF
sx = 0 || 0
EOF
expect <<EOF
sx = 0
EOF

#------------------------------------------------------------------------------

ptest "or: 1 || 0" << EOF
sx = 1 || 0
EOF
expect <<EOF
sx = 1
EOF

#------------------------------------------------------------------------------

ptest "or: 0 || 1" << EOF
sx = 0 || 1
EOF
expect <<EOF
sx = 1
EOF

#------------------------------------------------------------------------------

ptest "or: 1 || 1" << EOF
sx = 1 || 1
EOF
expect <<EOF
sx = 1
EOF

#------------------------------------------------------------------------------

ptest "or: a || b && c" << EOF
sx = a || b && c
EOF
expect <<EOF
sx = (|| a (&& b c))
EOF

#------------------------------------------------------------------------------

fpvm "or: a || b (generate code)" <<EOF
sx = a || b
EOF
expect <<EOF
COPY a -> R2
IF 1,0 -> R-003
COPY b -> R2
IF 1,R-003 -> sx
EOF

###############################################################################
Loading