This removes comments and redundant whitespace at build time, speeding
up run-time parsing.
---
 src/Makefile                |    2 +-
 src/compiler/file2h         |   30 +++++++++++++++++++++++++++++-
 src/compiler/ptest/Makefile |    2 +-
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 79de657..bb5d48f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -94,7 +94,7 @@ bandfilters.h: bandfilters.sce
 
 compiler/infra-fnp.h: \
          compiler/finish-pfv.fnp compiler/init-pvv.fnp compiler/finish-pvv.fnp
-       $(GEN) compiler/file2h $^ >$@ || { rm -f $@; }
+       $(GEN) compiler/file2h -c $^ >$@ || { rm -f $@; }
 
 compiler/parser.h: compiler/parser.c
 obj/compiler/scanner.o: compiler/parser.h
diff --git a/src/compiler/file2h b/src/compiler/file2h
index c145e0a..0ba2ccf 100755
--- a/src/compiler/file2h
+++ b/src/compiler/file2h
@@ -1,9 +1,37 @@
 #!/bin/sh -e
+#
+# file2h - Embed file content in #define expanding to a string
+#
+# Copyright 2011 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.
+#
+
+
+usage()
+{
+       echo "usage: $0 [-c] file ..." 1>&2
+       exit 1
+}
+
+
+filter=cat
+while [ "$1" ]; do
+       case "$1" in
+       -c)     filter="cpp -P";;
+       -*)     usage;;
+       *)      break;
+       esac
+       shift
+done
+
 while [ "$1" ]; do
        echo -n "#define "
        basename $1 | sed 's/[^a-zA-Z0-9]/_/g' | tr a-z A-Z | tr -d '\n'
        echo ' "" \'
-       sed 's/\\/\\\\/g;s/"/\\"/g;s/.*/    "&\\n" \\/' <$1
+       cat $1 | $filter | sed 's/\\/\\\\/g;s/"/\\"/g;s/.*/    "&\\n" \\/'
        echo
        shift
 done
diff --git a/src/compiler/ptest/Makefile b/src/compiler/ptest/Makefile
index 7d3fca6..7617a50 100644
--- a/src/compiler/ptest/Makefile
+++ b/src/compiler/ptest/Makefile
@@ -47,7 +47,7 @@ ptest:                $(OBJS)
                $(GEN) cd .. && ./idgen `basename $<`
 
 ../infra-fnp.h:        ../finish-pfv.fnp ../init-pvv.fnp ../finish-pvv.fnp
-               $(GEN) ../file2h $^ >$@ || { rm -f $@; }
+               $(GEN) ../file2h -c $^ >$@ || { rm -f $@; }
 
 libfpvm.a:
                $(MAKE) -C $(LIBFPVM_X86)
-- 
1.7.1

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

Reply via email to