This patch adds the infrastructure to optionally perform code generation
in ptest and the command-line option -c to enable this feature. Only
small changes were needed in the rest of the system.
This patch needs an up to date version of /opt/milkymist/milkymist.git/
---
src/compiler/compiler.c | 6 +++
src/compiler/compiler.h | 4 ++
src/compiler/ptest/Makefile | 19 ++++++++-
src/compiler/ptest/ptest.c | 84 ++++++++++++++++++++++++++++-----------
src/compiler/ptest/standalone.h | 12 ++++++
src/renderer/framedescriptor.h | 4 ++
6 files changed, 103 insertions(+), 26 deletions(-)
create mode 100644 src/compiler/ptest/standalone.h
diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c
index 1b8146c..8ee534b 100644
--- a/src/compiler/compiler.c
+++ b/src/compiler/compiler.c
@@ -549,6 +549,7 @@ static const char *assign_per_vertex(struct parser_comm
*comm,
static const char *assign_image_name(struct parser_comm *comm,
int number, const char *name)
{
+#ifndef STANDALONE
struct compiler_sc *sc = comm->u.sc;
char *totalname;
@@ -568,6 +569,7 @@ static const char *assign_image_name(struct parser_comm
*comm,
pixbuf_dec_ref(sc->p->images[number]);
sc->p->images[number] = pixbuf_get(totalname);
free(totalname);
+#endif /* STANDALONE */
return NULL;
}
@@ -660,6 +662,8 @@ struct patch *patch_compile_filename(const char *filename,
return p;
}
+#ifndef STANDALONE
+
struct patch *patch_copy(struct patch *p)
{
struct patch *new_patch;
@@ -683,3 +687,5 @@ void patch_free(struct patch *p)
pixbuf_dec_ref(p->images[i]);
free(p);
}
+
+#endif
diff --git a/src/compiler/compiler.h b/src/compiler/compiler.h
index 55bb854..5f6be43 100644
--- a/src/compiler/compiler.h
+++ b/src/compiler/compiler.h
@@ -18,8 +18,12 @@
#ifndef __COMPILER_H
#define __COMPILER_H
+#ifndef STANDALONE
#include <rtems.h>
#include <bsp/milkymist_pfpu.h>
+#else
+#include STANDALONE
+#endif /* STANDALONE */
#include "../renderer/framedescriptor.h"
#include "../pixbuf/pixbuf.h"
diff --git a/src/compiler/ptest/Makefile b/src/compiler/ptest/Makefile
index 1ad5692..19901ef 100644
--- a/src/compiler/ptest/Makefile
+++ b/src/compiler/ptest/Makefile
@@ -3,8 +3,13 @@ RTEMS_MAKEFILE_PATH ?= \
/opt/rtems-$(RTEMS_VERSION)/lm32-rtems$(RTEMS_VERSION)/milkymist/
RTEMS_FPVM_H = $(RTEMS_MAKEFILE_PATH)/lib/include/fpvm
-CFLAGS = -Wall -g -I.. -I.
-OBJS = ptest.o scanner.o parser.o parser_helper.o unique.o
+MMDIR ?= /opt/milkymist/milkymist.git
+LIBFPVM_X86 = $(MMDIR)/software/libfpvm/x86-linux
+
+CFLAGS_STANDALONE = -DSTANDALONE=\"standalone.h\"
+CFLAGS = -Wall -g -I.. -I. $(CFLAGS_STANDALONE)
+OBJS = ptest.o scanner.o parser.o parser_helper.o unique.o compiler.o fpvm.o \
+ libfpvm.a
# ----- Verbosity control -----------------------------------------------------
@@ -45,6 +50,13 @@ ptest: $(OBJS)
%.h %.inc: %.ids
$(GEN) cd .. && ./idgen `basename $<`
+../infra-fnp.h: ../finish-pfv.fnp ../init-pvv.fnp ../finish-pvv.fnp
+ $(GEN) ../file2h $^ >$@ || { rm -f $@; }
+
+libfpvm.a:
+ $(MAKE) -C $(LIBFPVM_X86)
+ cp $(LIBFPVM_X86)/$@ .
+
# ----- Dependencies ----------------------------------------------------------
../parser.h: ../parser.c
@@ -52,12 +64,15 @@ scanner.o: ../parser.h
parser_helper.o: ../parser.h
ptest.o: ../parser.h
unique.o: ../fnp.inc
+compiler.o: ../infra-fnp.h
# ----- Cleanup ---------------------------------------------------------------
clean:
+ $(MAKE) -C $(LIBFPVM_X86) clean
rm -f $(OBJS)
rm -f ../scanner.c
rm -f ../parser.c ../parser.h ../parser.out
rm -f ../fnp.h ../fnp.inc
+ rm -f ../infra-fnp.h libfpvm.a
rm -f fpvm
diff --git a/src/compiler/ptest/ptest.c b/src/compiler/ptest/ptest.c
index 330c68f..6ef9b60 100644
--- a/src/compiler/ptest/ptest.c
+++ b/src/compiler/ptest/ptest.c
@@ -14,9 +14,12 @@
#include <unistd.h>
#include <string.h>
+#include "fpvm/pfpu.h"
+
#include "../fpvm.h"
#include "../parser_helper.h"
#include "../parser.h"
+#include "../compiler.h"
static int quiet = 0;
@@ -135,12 +138,6 @@ static void dump_ast(const struct ast_node *ast)
}
-const char *fpvm_get_last_error(struct fpvm_fragment *fragment)
-{
- return fragment->last_error;
-}
-
-
static const char *assign_default(struct parser_comm *comm,
const char *label, struct ast_node *node)
{
@@ -187,6 +184,14 @@ static const char *assign_image_name(struct parser_comm
*comm,
return NULL;
}
+
+static void report(const char *s)
+{
+ fprintf(stderr, "%s\n", s);
+ exit(1);
+}
+
+
static const char *read_stdin(void)
{
char *buf = NULL;
@@ -217,17 +222,8 @@ static const char *read_stdin(void)
}
-static void usage(const char *name)
+static void parse_only(const char *pgm)
{
- fprintf(stderr, "usage: %s [-f error] [-q] [expr]\n", name);
- exit(1);
-}
-
-
-int main(int argc, char **argv)
-{
- int c;
- const char *buf;
struct fpvm_fragment fragment;
struct parser_comm comm = {
.u.fragment = &fragment,
@@ -238,8 +234,50 @@ int main(int argc, char **argv)
};
const char *error;
- while ((c = getopt(argc, argv, "f:q")) != EOF)
+ error = fpvm_parse(pgm, TOK_START_ASSIGN, &comm);
+ if (!error)
+ return;
+ fflush(stdout);
+ fprintf(stderr, "%s\n", error);
+ free((void *) error);
+ exit(1);
+}
+
+
+static void compile(const char *pgm)
+{
+ struct patch *patch;
+
+ patch = patch_compile("/", pgm, report);
+ if (!patch)
+ exit(1);
+ if (quiet)
+ return;
+ printf("per-frame PFPU fragment:\n");
+ pfpu_dump(patch->perframe_prog, patch->perframe_prog_length);
+ printf("per-vertex PFPU fragment:\n");
+ pfpu_dump(patch->pervertex_prog, patch->pervertex_prog_length);
+}
+
+
+static void usage(const char *name)
+{
+ fprintf(stderr, "usage: %s [-c] [-f error] [-q] [expr]\n", name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ int c;
+ const char *buf;
+ int codegen = 0;
+
+ while ((c = getopt(argc, argv, "cf:q")) != EOF)
switch (c) {
+ case 'c':
+ codegen = 1;
+ break;
case 'f':
fail = optarg;
break;
@@ -260,11 +298,9 @@ int main(int argc, char **argv)
usage(*argv);
}
- error = fpvm_parse(buf, TOK_START_ASSIGN, &comm);
- if (!error)
- return 0;
- fflush(stdout);
- fprintf(stderr, "%s\n", error);
- free((void *)error);
- return 1;
+ if (codegen)
+ compile(buf);
+ else
+ parse_only(buf);
+ return 0;
}
diff --git a/src/compiler/ptest/standalone.h b/src/compiler/ptest/standalone.h
new file mode 100644
index 0000000..d56aea4
--- /dev/null
+++ b/src/compiler/ptest/standalone.h
@@ -0,0 +1,12 @@
+#ifndef STANDALONE_H
+#define STANDALONE_H
+
+/*
+ * From
+ * /opt/rtems-4.11/lm32-rtems4.11/milkymist/lib/include/bsp/milkymist_pfpu.h
+ */
+
+#define PFPU_PROGSIZE 2048
+#define PFPU_REG_COUNT 128
+
+#endif /* !STANDALONE_H */
diff --git a/src/renderer/framedescriptor.h b/src/renderer/framedescriptor.h
index 030c870..3bbd10c 100644
--- a/src/renderer/framedescriptor.h
+++ b/src/renderer/framedescriptor.h
@@ -18,8 +18,12 @@
#ifndef __FRAMEDESCRIPTOR_H
#define __FRAMEDESCRIPTOR_H
+#ifndef STANDALONE
#include <rtems.h>
#include <bsp/milkymist_ac97.h>
+#else
+#include STANDALONE
+#endif /* STANDALONE */
#include "../pixbuf/pixbuf.h"
--
1.7.1
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode