---
 software/include/fpvm/fpvm.h   |    2 +
 software/libfpvm/Makefile      |    7 +++-
 software/libfpvm/fpvm-export.c |   67 ++++++++++++++++++++++++++++++++++++++++
 software/libfpvm/fpvm.c        |   33 ++++++-------------
 software/libfpvm/subdir.mak    |    2 +-
 5 files changed, 86 insertions(+), 25 deletions(-)
 create mode 100644 software/libfpvm/fpvm-export.c

diff --git a/software/include/fpvm/fpvm.h b/software/include/fpvm/fpvm.h
index 2b0ed48..7bc843a 100644
--- a/software/include/fpvm/fpvm.h
+++ b/software/include/fpvm/fpvm.h
@@ -101,6 +101,8 @@ struct fpvm_fragment {
        int vector_mode;
 };
 
+extern const char *_Xi, *_Yi, *_Xo, *_Yo;
+
 const char *fpvm_version();
 
 void fpvm_init(struct fpvm_fragment *fragment, int vector_mode);
diff --git a/software/libfpvm/Makefile b/software/libfpvm/Makefile
index 1539fcc..1ba0afd 100644
--- a/software/libfpvm/Makefile
+++ b/software/libfpvm/Makefile
@@ -3,7 +3,7 @@ INCLUDES_NOLIBC=-DPRINTF_FLOAT
 include $(MMDIR)/software/include.mak
 
 OBJECTS=fpvm.o parser_helper.o scanner.o parser.o gfpus.o lnfpus.o pfpu.o \
-       unique.o
+       unique.o fpvm-export.o
 
 .PHONY: all clean depend install
 
@@ -42,9 +42,12 @@ clean:
 
 # DO NOT DELETE
 
+fpvm-emigree.o: ../../software/include/fpvm/fpvm.h
+fpvm-emigree.o: ../../software/include/fpvm/is.h ast.h unique.h
+fpvm-emigree.o: parser_helper.h
 fpvm.o: ../../software/include/base/version.h
 fpvm.o: ../../software/include/fpvm/is.h ../../software/include/fpvm/fpvm.h
-fpvm.o: ast.h unique.h parser_helper.h parser.h
+fpvm.o: ast.h
 gfpus.o: ../../software/include/fpvm/is.h ../../software/include/fpvm/fpvm.h
 gfpus.o: ../../software/include/fpvm/pfpu.h
 gfpus.o: ../../software/include/fpvm/schedulers.h
diff --git a/software/libfpvm/fpvm-export.c b/software/libfpvm/fpvm-export.c
new file mode 100644
index 0000000..be9af09
--- /dev/null
+++ b/software/libfpvm/fpvm-export.c
@@ -0,0 +1,67 @@
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include <fpvm/fpvm.h>
+
+#include "ast.h"
+#include "unique.h"
+#include "parser_helper.h"
+
+
+/* @@@ move later */
+int fpvm_do_assign(struct fpvm_fragment *fragment, const char *dest,
+    struct ast_node *n);
+void fpvm_do_init(struct fpvm_fragment *fragment, int vector_mode);
+
+
+void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
+{
+       /*
+        * We need to pass these through unique() because fpvm_assign does
+        * the same. Once things are in Flickernoise, we can get rid of these
+        * calls to unique().
+        */
+
+       _Xi = unique("_Xi");
+       _Xo = unique("_Xo");
+       _Yi = unique("_Yi");
+       _Yo = unique("_Yo");
+       fpvm_do_init(fragment, vector_mode);
+}
+
+
+int fpvm_assign(struct fpvm_fragment *fragment, const char *dest,
+    const char *expr)
+{
+       struct ast_node *n;
+       int res;
+
+       n = fpvm_parse(expr);
+       if(n == NULL) {
+               snprintf(fragment->last_error, FPVM_MAXERRLEN, "Parse error");
+               return 0;
+       }
+
+       dest = unique(dest);
+
+       res = fpvm_do_assign(fragment, dest, n);
+       fpvm_parse_free(n);
+
+       return res;
+}
diff --git a/software/libfpvm/fpvm.c b/software/libfpvm/fpvm.c
index c97e73c..decaf68 100644
--- a/software/libfpvm/fpvm.c
+++ b/software/libfpvm/fpvm.c
@@ -22,15 +22,17 @@
 #include <fpvm/fpvm.h>
 
 #include "ast.h"
-#include "unique.h"
-#include "parser_helper.h"
+
+
+const char *_Xi, *_Yi, *_Xo, *_Yo; /* unique, provided by user of libfpvm */
+
 
 const char *fpvm_version()
 {
        return VERSION;
 }
 
-void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
+void fpvm_do_init(struct fpvm_fragment *fragment, int vector_mode)
 {
        fragment->last_error[0] = 0;
        fragment->bind_callback = NULL;
@@ -38,18 +40,18 @@ void fpvm_init(struct fpvm_fragment *fragment, int 
vector_mode)
 
        fragment->nbindings = 3;
        fragment->bindings[0].isvar = 1;
-       fragment->bindings[0].b.v = unique("_Xi");
+       fragment->bindings[0].b.v = _Xi;
        fragment->bindings[1].isvar = 1;
-       fragment->bindings[1].b.v = unique("_Yi");
+       fragment->bindings[1].b.v = _Yi;
        /* Prevent binding of R2 (we need it for "if") */
        fragment->bindings[2].isvar = 1;
        fragment->bindings[2].b.v = "";
 
        fragment->ntbindings = 2;
        fragment->tbindings[0].reg = -1;
-       fragment->tbindings[0].sym = unique("_Xo");
+       fragment->tbindings[0].sym = _Xo;
        fragment->tbindings[1].reg = -2;
-       fragment->tbindings[1].sym = unique("_Yo");
+       fragment->tbindings[1].sym = _Yo;
 
        fragment->nrenamings = 0;
 
@@ -554,25 +556,16 @@ static void fragment_restore(struct fpvm_fragment 
*fragment,
        fragment->ninstructions = backup->ninstructions;
 }
 
-int fpvm_assign(struct fpvm_fragment *fragment, const char *dest,
-    const char *expr)
+int fpvm_do_assign(struct fpvm_fragment *fragment, const char *dest,
+    struct ast_node *n)
 {
-       struct ast_node *n;
        int dest_reg;
        struct fpvm_backup backup;
        int created;
        int use_renaming;
 
-       n = fpvm_parse(expr);
-       if(n == NULL) {
-               snprintf(fragment->last_error, FPVM_MAXERRLEN, "Parse error");
-               return 0;
-       }
-
        fragment_backup(fragment, &backup);
 
-       dest = unique(dest);
-
        /* do not rename output X and Y */
        use_renaming = fragment->vector_mode
                && (dest != fragment->tbindings[0].sym)
@@ -586,7 +579,6 @@ int fpvm_assign(struct fpvm_fragment *fragment, const char 
*dest,
        if(dest_reg == FPVM_INVALID_REG) {
                snprintf(fragment->last_error, FPVM_MAXERRLEN,
                    "Failed to allocate register for destination");
-               fpvm_parse_free(n);
                fragment_restore(fragment, &backup);
                return 0;
        }
@@ -596,19 +588,16 @@ int fpvm_assign(struct fpvm_fragment *fragment, const 
char *dest,
        else
                fragment->final_dest = FPVM_INVALID_REG;
        if(compile(fragment, dest_reg, n) == FPVM_INVALID_REG) {
-               fpvm_parse_free(n);
                fragment_restore(fragment, &backup);
                return 0;
        }
        if(use_renaming) {
                if(!rename_reg(fragment, dest, dest_reg)) {
-                       fpvm_parse_free(n);
                        fragment_restore(fragment, &backup);
                        return 0;
                }
        }
 
-       fpvm_parse_free(n);
        return 1;
 }
 
diff --git a/software/libfpvm/subdir.mak b/software/libfpvm/subdir.mak
index 95beeb6..af97ffc 100644
--- a/software/libfpvm/subdir.mak
+++ b/software/libfpvm/subdir.mak
@@ -1,5 +1,5 @@
 OBJECTS=fpvm.o parser_helper.o scanner.o parser.o gfpus.o lnfpus.o pfpu.o \
-       unique.o
+       unique.o fpvm-export.o
 
 all: libfpvm.a
 
-- 
1.7.1

_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode

Reply via email to