Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 13 files changed
  • 0 comments
  • 1 contributor
79  src/Makefile
... ...
@@ -1,27 +1,42 @@
1  
-RTEMS_VERSION?=4.11
2  
-RTEMS_MAKEFILE_PATH?=/opt/rtems-$(RTEMS_VERSION)/lm32-rtems$(RTEMS_VERSION)/milkymist/
3  
-WITH_PDF?=0
4  
-
5  
-CC=lm32-rtems$(RTEMS_VERSION)-gcc
6  
-LD=lm32-rtems$(RTEMS_VERSION)-gcc
7  
-OBJCOPY=lm32-rtems$(RTEMS_VERSION)-objcopy
8  
-
9  
-CFLAGS=-O9 -Wall -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled -msign-extend-enabled -fsingle-precision-constant -I$(RTEMS_MAKEFILE_PATH)/lib/include -g
10  
-LDFLAGS=-mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled -msign-extend-enabled -B$(RTEMS_MAKEFILE_PATH)/lib -specs bsp_specs -qrtems
11  
-LIBS=-lnfs -lftpd -ltelnetd -lyaffs2 -lmtk -llop -lfpvm -lpng -ljpeg -lcurl -lexpat -lz -lm
12  
-OBJDIR=obj
13  
-BINDIR=bin
14  
-
15  
-OBJS=yaffs.o version.o shellext.o sysconfig.o config.o fb.o input.o keymap.o fbgrab.o shortcuts.o osc.o pngwrite.o patchpool.o flashvalid.o main.o
16  
-OBJS+=$(addprefix pixbuf/,dither.o loaderjpeg.o loaderpng.o manager.o)
17  
-OBJS+=$(addprefix gui/,messagebox.o filedialog.o resmgr.o guirender.o performance.o cp.o keyboard.o ir.o audio.o midi.o oscsettings.o dmxspy.o dmxdesk.o dmx.o videoin.o rsswall.o patcheditor.o monitor.o firstpatch.o filemanager.o sysettings.o about.o flash.o shutdown.o)
  1
+RTEMS_VERSION ?= 4.11
  2
+RTEMS_MAKEFILE_PATH ?= \
  3
+    /opt/rtems-$(RTEMS_VERSION)/lm32-rtems$(RTEMS_VERSION)/milkymist/
  4
+WITH_PDF ?= 0
  5
+
  6
+CC = lm32-rtems$(RTEMS_VERSION)-gcc
  7
+LD = lm32-rtems$(RTEMS_VERSION)-gcc
  8
+OBJCOPY = lm32-rtems$(RTEMS_VERSION)-objcopy
  9
+
  10
+CFLAGS = -O9 -Wall -mbarrel-shift-enabled -mmultiply-enabled \
  11
+	 -mdivide-enabled -msign-extend-enabled -fsingle-precision-constant \
  12
+	 -I$(RTEMS_MAKEFILE_PATH)/lib/include -g
  13
+LDFLAGS = -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled \
  14
+	  -msign-extend-enabled -B$(RTEMS_MAKEFILE_PATH)/lib \
  15
+	  -specs bsp_specs -qrtems
  16
+LIBS = -lnfs -lftpd -ltelnetd -lyaffs2 -lmtk -llop -lfpvm -lpng -ljpeg \
  17
+      -lcurl -lexpat -lz -lm
  18
+OBJDIR = obj
  19
+BINDIR = bin
  20
+
  21
+OBJS = yaffs.o version.o shellext.o sysconfig.o config.o fb.o input.o \
  22
+       keymap.o fbgrab.o shortcuts.o osc.o pngwrite.o patchpool.o \
  23
+       flashvalid.o main.o
  24
+OBJS += $(addprefix pixbuf/,dither.o loaderjpeg.o loaderpng.o manager.o)
  25
+OBJS += $(addprefix gui/,messagebox.o filedialog.o resmgr.o guirender.o \
  26
+	performance.o cp.o keyboard.o ir.o audio.o midi.o oscsettings.o \
  27
+	dmxspy.o dmxdesk.o dmx.o videoin.o rsswall.o patcheditor.o monitor.o \
  28
+	firstpatch.o filemanager.o sysettings.o about.o flash.o shutdown.o)
18 29
 ifeq ($(WITH_PDF),1)
19  
-	OBJS+=$(addprefix gui/,pdfreader.o)
20  
-	CFLAGS+=-DWITH_PDF
21  
-	LIBS:=-lmupdf -lfreetype -ljbig2dec -lopenjpeg $(LIBS)
  30
+	OBJS += $(addprefix gui/,pdfreader.o)
  31
+	CFLAGS += -DWITH_PDF
  32
+	LIBS := -lmupdf -lfreetype -ljbig2dec -lopenjpeg $(LIBS)
22 33
 endif
23  
-OBJS+=$(addprefix translations/,french.o german.o)
24  
-OBJS+=$(addprefix renderer/,framedescriptor.o analyzer.o sampler.o compiler.o eval.o line.o wave.o font.o osd.o raster.o renderer.o videoinreconf.o)
  34
+OBJS += $(addprefix translations/,french.o german.o)
  35
+OBJS += $(addprefix renderer/,framedescriptor.o analyzer.o sampler.o \
  36
+	compiler.o eval.o line.o wave.o font.o osd.o raster.o renderer.o \
  37
+	videoinreconf.o)
  38
+OBJS += $(addprefix compiler/,fpvm.o parser_helper.o scanner.o parser.o \
  39
+	unique.o)
25 40
 
26 41
 POBJS=$(addprefix $(OBJDIR)/,$(OBJS))
27 42
 
@@ -41,6 +56,20 @@ $(BINDIR)/flickernoise: $(POBJS)
41 56
 bandfilters.h: bandfilters.sce
42 57
 	scilab -nw -nwni -nogui -nb -f bandfilters.sce
43 58
 
  59
+%.c: %.re
  60
+	re2c -o $@ $<
  61
+
  62
+%.c: %.y
  63
+	lemon $<
  64
+
  65
+%.h %.inc: %.ids
  66
+	cd compiler && ./idgen `basename $<`
  67
+
  68
+compiler/parser.h: compiler/parser.c
  69
+obj/compiler/scanner.o: compiler/parser.h
  70
+obj/compiler/parser_helper.o: compiler/parser.h
  71
+obj/compiler/unique.o: compiler/fnp.inc
  72
+
44 73
 # boot images for Milkymist One
45 74
 $(BINDIR)/flickernoise.bin: $(BINDIR)/flickernoise
46 75
 	$(OBJCOPY) -O binary $< $@
@@ -64,7 +93,11 @@ flash:
64 93
 
65 94
 clean:
66 95
 	rm -f $(BINDIR)/flickernoise $(BINDIR)/flickernoise.bin 
67  
-	rm -f $(BINDIR)/flickernoise.lzma $(BINDIR)/flickernoise.fbi $(BINDIR)/flickernoise.fbiz 
  96
+	rm -f $(BINDIR)/flickernoise.lzma $(BINDIR)/flickernoise.fbi \
  97
+	    $(BINDIR)/flickernoise.fbiz 
68 98
 	rm -f $(POBJS)
  99
+	rm -f compiler/scanner.c
  100
+	rm -f compiler/parser.c compiler/parser.h compiler/parser.out
  101
+	rm -f compiler/fnp.h compiler/fnp.inc
69 102
 
70 103
 .PHONY: clean load flash
284  src/compiler/fnp.ids
... ...
@@ -0,0 +1,284 @@
  1
+#
  2
+# fnp.ids - Identifiers we already know Flickernoise will use
  3
+#
  4
+# We sort this list at compile time and can then perform a quick O(M*log N)
  5
+# search on it, with M being the average length of an identifier and N the
  6
+# number of identifiers in this list.
  7
+#
  8
+# User-defined identifiers and identifiers omitted from fnp.ids for any
  9
+# other reason currently go to a linear list where they're searched in
  10
+# O(M*N) time.
  11
+#
  12
+
  13
+#
  14
+# Built-in functions
  15
+#
  16
+
  17
+above
  18
+abs
  19
+below
  20
+cos
  21
+equal
  22
+f2i
  23
+icos
  24
+i2f
  25
+if
  26
+int
  27
+invsqrt
  28
+isin
  29
+max
  30
+min
  31
+quake
  32
+sin
  33
+sqr
  34
+sqrt
  35
+tsign
  36
+
  37
+#
  38
+#
  39
+# Per-Frame Variables
  40
+#
  41
+
  42
+sx
  43
+sy
  44
+cx
  45
+cy
  46
+rot
  47
+dx
  48
+dy
  49
+zoom
  50
+decay
  51
+wave_mode
  52
+wave_scale
  53
+wave_additive
  54
+wave_usedots
  55
+wave_brighten
  56
+wave_thick
  57
+wave_x
  58
+wave_y
  59
+wave_r
  60
+wave_g
  61
+wave_b
  62
+wave_a
  63
+
  64
+ob_size
  65
+ob_r
  66
+ob_g
  67
+ob_b
  68
+ob_a
  69
+ib_size
  70
+ib_r
  71
+ib_g
  72
+ib_b
  73
+ib_a
  74
+
  75
+nMotionVectorsY
  76
+mv_dx
  77
+mv_dy
  78
+mv_l
  79
+mv_r
  80
+mv_g
  81
+mv_b
  82
+mv_a
  83
+
  84
+bTexWrap
  85
+
  86
+time
  87
+bass
  88
+mid
  89
+treb
  90
+bass_att
  91
+mid_att
  92
+treb_att
  93
+
  94
+warp
  95
+fWarpAnimSpeed
  96
+fWarpScale
  97
+
  98
+q1
  99
+q2
  100
+q3
  101
+q4
  102
+q5
  103
+q6
  104
+q7
  105
+q8
  106
+
  107
+fVideoEchoAlpha
  108
+fVideoEchoZoom
  109
+nVideoEchoOrientation
  110
+
  111
+dmx1
  112
+dmx2
  113
+dmx3
  114
+dmx4
  115
+dmx5
  116
+dmx6
  117
+dmx7
  118
+dmx8
  119
+
  120
+idmx1
  121
+idmx2
  122
+idmx3
  123
+idmx4
  124
+idmx5
  125
+idmx6
  126
+idmx7
  127
+idmx8
  128
+
  129
+osc1
  130
+osc2
  131
+osc3
  132
+osc4
  133
+
  134
+midi1
  135
+midi2
  136
+midi3
  137
+midi4
  138
+midi5
  139
+midi6
  140
+midi7
  141
+midi8
  142
+
  143
+video_a
  144
+
  145
+image1_a
  146
+image1_x
  147
+image1_y
  148
+image1_zoom
  149
+image2_a
  150
+image2_x
  151
+image2_y
  152
+image2_zoom
  153
+
  154
+#
  155
+# Aliases
  156
+#
  157
+
  158
+fDecay
  159
+nWaveMode
  160
+fWaveScale
  161
+bAdditiveWaves
  162
+bWaveDots
  163
+bMaximizeWaveColor
  164
+bWaveThick
  165
+fWaveAlpha
  166
+
  167
+#
  168
+# Per-Vertex Variables
  169
+#
  170
+
  171
+# System
  172
+
  173
+_texsize
  174
+_hmeshsize
  175
+_vmeshsize
  176
+
  177
+# MilkDrop
  178
+
  179
+sx
  180
+sy
  181
+cx
  182
+cy
  183
+rot
  184
+dx
  185
+dy
  186
+zoom
  187
+
  188
+time
  189
+bass
  190
+mid
  191
+treb
  192
+bass_att
  193
+mid_att
  194
+treb_att
  195
+
  196
+warp
  197
+fWarpAnimSpeed
  198
+fWarpScale
  199
+
  200
+q1
  201
+q2
  202
+q3
  203
+q4
  204
+q5
  205
+q6
  206
+q7
  207
+q8
  208
+
  209
+idmx1
  210
+idmx2
  211
+idmx3
  212
+idmx4
  213
+idmx5
  214
+idmx6
  215
+idmx7
  216
+idmx8
  217
+
  218
+osc1
  219
+osc2
  220
+osc3
  221
+osc4
  222
+
  223
+midi1
  224
+midi2
  225
+midi3
  226
+midi4
  227
+midi5
  228
+midi6
  229
+midi7
  230
+midi8
  231
+
  232
+#
  233
+# FPVM internal variables
  234
+#
  235
+
  236
+_Xo
  237
+_Yo
  238
+_Xi
  239
+_Yi
  240
+
  241
+#
  242
+# PVV internal variables
  243
+#
  244
+
  245
+# Initialization
  246
+
  247
+x
  248
+y
  249
+rad
  250
+
  251
+# Zoom
  252
+
  253
+_invzoom
  254
+_xy
  255
+_yz
  256
+
  257
+# Scale
  258
+
  259
+_xs
  260
+_ys
  261
+
  262
+# Warp
  263
+
  264
+_warptime
  265
+_invwarpscale
  266
+_f0
  267
+_f1
  268
+_f2
  269
+_f3
  270
+_ox2
  271
+_oy2
  272
+_xw
  273
+_yw
  274
+
  275
+# Rotate
  276
+
  277
+_cosr
  278
+_sinr
  279
+_u
  280
+_v
  281
+_xr
  282
+_yr
  283
+_xd
  284
+_yd
67  src/compiler/fpvm.c
... ...
@@ -0,0 +1,67 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010, 2011 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <stdio.h>
  19
+
  20
+#include <fpvm/fpvm.h>
  21
+#include <fpvm/ast.h>
  22
+
  23
+#include "unique.h"
  24
+#include "parser_helper.h"
  25
+
  26
+
  27
+/* @@@ move later */
  28
+int fpvm_do_assign(struct fpvm_fragment *fragment, const char *dest,
  29
+    struct ast_node *n);
  30
+void fpvm_do_init(struct fpvm_fragment *fragment, int vector_mode);
  31
+
  32
+
  33
+void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
  34
+{
  35
+	/*
  36
+	 * We need to pass these through unique() because fpvm_assign does
  37
+	 * the same. Once things are in Flickernoise, we can get rid of these
  38
+	 * calls to unique().
  39
+	 */
  40
+
  41
+	_Xi = unique("_Xi");
  42
+	_Xo = unique("_Xo");
  43
+	_Yi = unique("_Yi");
  44
+	_Yo = unique("_Yo");
  45
+	fpvm_do_init(fragment, vector_mode);
  46
+}
  47
+
  48
+
  49
+int fpvm_assign(struct fpvm_fragment *fragment, const char *dest,
  50
+    const char *expr)
  51
+{
  52
+	struct ast_node *n;
  53
+	int res;
  54
+
  55
+	n = fpvm_parse(expr);
  56
+	if(n == NULL) {
  57
+		snprintf(fragment->last_error, FPVM_MAXERRLEN, "Parse error");
  58
+		return 0;
  59
+	}
  60
+
  61
+	dest = unique(dest);
  62
+
  63
+	res = fpvm_do_assign(fragment, dest, n);
  64
+	fpvm_parse_free(n);
  65
+
  66
+	return res;
  67
+}
57  src/compiler/idgen
... ...
@@ -0,0 +1,57 @@
  1
+#!/bin/sh -e
  2
+#
  3
+# idgen - Identifier table generator
  4
+#
  5
+# Copyright 2011 by Werner Almesberger
  6
+#
  7
+# This program is free software: you can redistribute it and/or modify
  8
+# it under the terms of the GNU General Public License as published by
  9
+# the Free Software Foundation, version 3 of the License.
  10
+#
  11
+
  12
+
  13
+usage()
  14
+{
  15
+	echo "usage: $0 file" 1>&2
  16
+	exit 1
  17
+}
  18
+
  19
+
  20
+[ "$1" ] || usage
  21
+[ "$2" ] && usage
  22
+[ -r "$1" ] || { echo "$1: not found" 1&2; exit 1; }
  23
+
  24
+trap "echo $1.h $1.inc" 0
  25
+
  26
+f=`basename "$1" .ids`
  27
+
  28
+cat <<EOF >$f.h
  29
+/* MACHINE-GENERATED. DO NOT EDIT ! */
  30
+
  31
+#ifndef	IDS_H
  32
+#define	IDS_H
  33
+
  34
+extern const char *well_known[];
  35
+
  36
+EOF
  37
+
  38
+cat <<EOF >$f.inc
  39
+/* MACHINE-GENERATED. DO NOT EDIT ! */
  40
+
  41
+EOF
  42
+
  43
+sed 's/#.*//;s/ //g;/^$/d' $1 | sort | uniq | {
  44
+	i=0
  45
+	while read n; do
  46
+		echo "#define ID_$n (well_known[$i])" >>$f.h
  47
+		echo "\"$n\"," >>$f.inc
  48
+		i=`expr $i + 1`
  49
+	done
  50
+}
  51
+
  52
+cat <<EOF >>$f.h
  53
+
  54
+#endif /* !IDS_H */
  55
+EOF
  56
+
  57
+trap 0
169  src/compiler/parser.y
... ...
@@ -0,0 +1,169 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+%include {
  19
+	#include <assert.h>
  20
+	#include <string.h>
  21
+	#include <stdlib.h>
  22
+	#include <malloc.h>
  23
+	#include <math.h>
  24
+	#include "fpvm/ast.h"
  25
+	#include "parser_itf.h"
  26
+	#include "parser.h"
  27
+
  28
+
  29
+	const enum ast_op tok2op[] = {
  30
+		[TOK_IDENT]	= op_ident,
  31
+		[TOK_CONSTANT]	= op_constant,
  32
+		[TOK_PLUS]	= op_plus,
  33
+		[TOK_MINUS]	= op_minus,
  34
+		[TOK_MULTIPLY]	= op_multiply,
  35
+		[TOK_DIVIDE]	= op_divide,
  36
+		[TOK_PERCENT]	= op_percent,
  37
+		[TOK_ABS]	= op_abs,
  38
+		[TOK_ISIN]	= op_isin,
  39
+		[TOK_ICOS]	= op_icos,
  40
+		[TOK_SIN]	= op_sin,
  41
+		[TOK_COS]	= op_cos,
  42
+		[TOK_ABOVE]	= op_above,
  43
+		[TOK_BELOW]	= op_below,
  44
+		[TOK_EQUAL]	= op_equal,
  45
+		[TOK_I2F]	= op_i2f,
  46
+		[TOK_F2I]	= op_f2i,
  47
+		[TOK_IF]	= op_if,
  48
+		[TOK_TSIGN]	= op_tsign,
  49
+		[TOK_QUAKE]	= op_quake,
  50
+		[TOK_NOT]	= op_not,
  51
+		[TOK_SQR]	= op_sqr,
  52
+		[TOK_SQRT]	= op_sqrt,
  53
+		[TOK_INVSQRT]	= op_invsqrt,
  54
+		[TOK_MIN]	= op_min,
  55
+		[TOK_MAX]	= op_max,
  56
+		[TOK_INT]	= op_int,
  57
+		
  58
+	};
  59
+
  60
+	struct ast_node *node(int token, const char *id, struct ast_node *a,
  61
+	     struct ast_node *b, struct ast_node *c)
  62
+	{
  63
+		struct ast_node *n;
  64
+
  65
+		n = malloc(sizeof(struct ast_node));
  66
+		n->op = tok2op[token];
  67
+		n->label = id;
  68
+		n->contents.branches.a = a;
  69
+		n->contents.branches.b = b;
  70
+		n->contents.branches.c = c;
  71
+		return n;
  72
+	}
  73
+}
  74
+
  75
+%start_symbol start
  76
+%extra_argument {struct ast_node **parseout}
  77
+%token_type {struct id *}
  78
+
  79
+%token_destructor { free($$); }
  80
+
  81
+%type start {struct ast_node *}
  82
+%type node {struct ast_node *}
  83
+%destructor node { free($$); }
  84
+
  85
+start(S) ::= node(N). {
  86
+	S = N;
  87
+	*parseout = S;
  88
+}
  89
+
  90
+node(N) ::= TOK_CONSTANT(C). {
  91
+	N = node(TOK_CONSTANT, "", NULL, NULL, NULL);
  92
+	N->contents.constant = C->constant;
  93
+}
  94
+
  95
+node(N) ::= ident(I). {
  96
+	N = node(I->token, I->label, NULL, NULL, NULL);
  97
+}
  98
+
  99
+%left TOK_PLUS TOK_MINUS.
  100
+%left TOK_MULTIPLY TOK_DIVIDE TOK_PERCENT.
  101
+%left TOK_NOT.
  102
+
  103
+node(N) ::= node(A) TOK_PLUS node(B). {
  104
+	N = node(TOK_PLUS, "+", A, B, NULL);
  105
+}
  106
+
  107
+node(N) ::= node(A) TOK_MINUS node(B). {
  108
+	N = node(TOK_MINUS, "-", A, B, NULL);
  109
+}
  110
+
  111
+node(N) ::= node(A) TOK_MULTIPLY node(B). {
  112
+	N = node(TOK_MULTIPLY, "*", A, B, NULL);
  113
+}
  114
+
  115
+node(N) ::= node(A) TOK_DIVIDE node(B). {
  116
+	N = node(TOK_DIVIDE, "/", A, B, NULL);
  117
+}
  118
+
  119
+node(N) ::= node(A) TOK_PERCENT node(B). {
  120
+	N = node(TOK_PERCENT, "%", A, B, NULL);
  121
+}
  122
+
  123
+node(N) ::= TOK_MINUS node(A). [TOK_NOT] {
  124
+	N = node(TOK_NOT, "!", A, NULL, NULL);
  125
+}
  126
+
  127
+node(N) ::= unary(I) TOK_LPAREN node(A) TOK_RPAREN. {
  128
+	N = node(I->token, I->label, A, NULL, NULL);
  129
+}
  130
+
  131
+node(N) ::= binary(I) TOK_LPAREN node(A) TOK_COMMA node(B) TOK_RPAREN. {
  132
+	N = node(I->token, I->label, A, B, NULL);
  133
+}
  134
+
  135
+node(N) ::= ternary(I) TOK_LPAREN node(A) TOK_COMMA node(B) TOK_COMMA node(C)
  136
+    TOK_RPAREN. {
  137
+	N = node(I->token, I->label, A, B, C);
  138
+}
  139
+
  140
+node(N) ::= TOK_LPAREN node(A) TOK_RPAREN. {
  141
+	N = A;
  142
+}
  143
+
  144
+ident(O) ::= TOK_IDENT(I).	{ O = I; }
  145
+ident(O) ::= unary(I).		{ O = I; }
  146
+ident(O) ::= binary(I).		{ O = I; }
  147
+ident(O) ::= ternary(I).	{ O = I; }
  148
+
  149
+unary(O) ::= TOK_ABS(I).	{ O = I; }
  150
+unary(O) ::= TOK_COS(I).	{ O = I; }
  151
+unary(O) ::= TOK_F2I(I).	{ O = I; }
  152
+unary(O) ::= TOK_ICOS(I).	{ O = I; }
  153
+unary(O) ::= TOK_I2F(I).	{ O = I; }
  154
+unary(O) ::= TOK_INT(I).	{ O = I; }
  155
+unary(O) ::= TOK_INVSQRT(I).	{ O = I; }
  156
+unary(O) ::= TOK_ISIN(I).	{ O = I; }
  157
+unary(O) ::= TOK_QUAKE(I).	{ O = I; }
  158
+unary(O) ::= TOK_SIN(I).	{ O = I; }
  159
+unary(O) ::= TOK_SQR(I).	{ O = I; }
  160
+unary(O) ::= TOK_SQRT(I).	{ O = I; }
  161
+
  162
+binary(O) ::= TOK_ABOVE(I).	{ O = I; }
  163
+binary(O) ::= TOK_BELOW(I).	{ O = I; }
  164
+binary(O) ::= TOK_EQUAL(I).	{ O = I; }
  165
+binary(O) ::= TOK_MAX(I).	{ O = I; }
  166
+binary(O) ::= TOK_MIN(I).	{ O = I; }
  167
+binary(O) ::= TOK_TSIGN(I).	{ O = I; }
  168
+
  169
+ternary(O) ::= TOK_IF(I).	{ O = I; }
77  src/compiler/parser_helper.c
... ...
@@ -0,0 +1,77 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <stdio.h>
  19
+#include <malloc.h>
  20
+#include <fpvm/ast.h>
  21
+
  22
+#include "scanner.h"
  23
+#include "parser_itf.h"
  24
+#include "parser_helper.h"
  25
+
  26
+struct ast_node *fpvm_parse(const char *expr)
  27
+{
  28
+	struct scanner *s;
  29
+	int tok;
  30
+	struct id *identifier;
  31
+	void *p;
  32
+	struct ast_node *ast;
  33
+	
  34
+	s = new_scanner((unsigned char *)expr);
  35
+	ast = NULL;
  36
+	p = ParseAlloc(malloc);
  37
+	tok = scan(s);
  38
+	while(tok != TOK_EOF) {
  39
+		identifier = malloc(sizeof(struct id));
  40
+		identifier->token = tok;
  41
+		if(tok == TOK_CONSTANT) {
  42
+			identifier->constant = get_constant(s);
  43
+			identifier->label = "";
  44
+		} else {
  45
+			identifier->label = get_token(s);
  46
+		}
  47
+		Parse(p, tok, identifier, &ast);
  48
+		if(tok == TOK_ERROR) {
  49
+			printf("FPVM: scan error\n");
  50
+			ParseFree(p, free);
  51
+			delete_scanner(s);
  52
+			return NULL;
  53
+		}
  54
+		tok = scan(s);
  55
+	}
  56
+	Parse(p, TOK_EOF, NULL, &ast);
  57
+	ParseFree(p, free);
  58
+	delete_scanner(s);
  59
+
  60
+	if(ast == NULL) {
  61
+		printf("FPVM: parse error\n");
  62
+		return NULL;
  63
+	}
  64
+
  65
+	return ast;
  66
+}
  67
+
  68
+void fpvm_parse_free(struct ast_node *node)
  69
+{
  70
+	if(node == NULL) return;
  71
+	if(node->label[0] != 0) {
  72
+		fpvm_parse_free(node->contents.branches.a);
  73
+		fpvm_parse_free(node->contents.branches.b);
  74
+		fpvm_parse_free(node->contents.branches.c);
  75
+	}
  76
+	free(node);
  77
+}
26  src/compiler/parser_helper.h
... ...
@@ -0,0 +1,26 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __PARSER_HELPER_H
  19
+#define __PARSER_HELPER_H
  20
+
  21
+#include <fpvm/ast.h>
  22
+
  23
+struct ast_node *fpvm_parse(const char *expr);
  24
+void fpvm_parse_free(struct ast_node *node);
  25
+
  26
+#endif /* __PARSER_HELPER_H */
33  src/compiler/parser_itf.h
... ...
@@ -0,0 +1,33 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __PARSER_ITF_H
  19
+#define __PARSER_ITF_H
  20
+
  21
+#define NDEBUG
  22
+
  23
+struct id {
  24
+	int token;
  25
+	const char *label;
  26
+	float constant;
  27
+};
  28
+
  29
+void *ParseAlloc(void *(*mallocProc)(size_t));
  30
+void ParseFree(void *p, void (*freeProc)(void*));
  31
+void Parse(void *yyp, int yymajor, struct id *yyminor, struct ast_node **p);
  32
+
  33
+#endif /* __PARSER_ITF_H */
46  src/compiler/scanner.h
... ...
@@ -0,0 +1,46 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __SCANNER_H
  19
+#define __SCANNER_H
  20
+
  21
+#define TOK_ERROR	(-1)
  22
+#define TOK_EOF		0
  23
+
  24
+#include "parser.h"
  25
+
  26
+struct scanner {
  27
+	unsigned char *marker;
  28
+	unsigned char *old_cursor;
  29
+	unsigned char *cursor;
  30
+	unsigned char *limit;
  31
+};
  32
+
  33
+struct scanner *new_scanner(unsigned char *input);
  34
+void delete_scanner(struct scanner *s);
  35
+
  36
+/* get to the next token and return its type */
  37
+int scan(struct scanner *s);
  38
+
  39
+/* get the unique string comprising the current token
  40
+ */
  41
+const char *get_token(struct scanner *s);
  42
+
  43
+float get_constant(struct scanner *s);
  44
+
  45
+#endif /* __SCANNER_H */
  46
+
122  src/compiler/scanner.re
... ...
@@ -0,0 +1,122 @@
  1
+/*
  2
+ * Milkymist SoC (Software)
  3
+ * Copyright (C) 2007, 2008, 2009, 2010 Sebastien Bourdeauducq
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <stdio.h>
  19
+#include <string.h>
  20
+#include <malloc.h>
  21
+
  22
+#include "unique.h"
  23
+#include "scanner.h"
  24
+
  25
+#define YYCTYPE     unsigned char
  26
+#define YYCURSOR    s->cursor
  27
+#define YYLIMIT     s->limit
  28
+
  29
+/* refilling not supported */
  30
+#define YYMARKER s->marker
  31
+#define YYFILL(n)
  32
+
  33
+struct scanner *new_scanner(unsigned char *input)
  34
+{
  35
+	struct scanner *s;
  36
+	
  37
+	s = malloc(sizeof(struct scanner));
  38
+	if(s == NULL) return NULL;
  39
+	
  40
+	s->marker = input;
  41
+	s->old_cursor = input;
  42
+	s->cursor = input;
  43
+	s->limit = input + strlen((char *)input);
  44
+	
  45
+	return s;
  46
+}
  47
+
  48
+void delete_scanner(struct scanner *s)
  49
+{
  50
+	free(s);
  51
+}
  52
+
  53
+int scan(struct scanner *s)
  54
+{
  55
+	std:
  56
+	if(s->cursor == s->limit) return TOK_EOF;
  57
+	s->old_cursor = s->cursor;
  58
+	
  59
+	/*!re2c
  60
+		[\x20\r\t]		{ goto std; }
  61
+		[0-9]+			{ return TOK_CONSTANT; }
  62
+		[0-9]* "." [0-9]*	{ return TOK_CONSTANT; }
  63
+
  64
+		"above"			{ return TOK_ABOVE; }
  65
+		"abs"			{ return TOK_ABS; }
  66
+		"below"			{ return TOK_BELOW; }
  67
+		"cos"			{ return TOK_COS; }
  68
+		"equal"			{ return TOK_EQUAL; }
  69
+		"f2i"			{ return TOK_F2I; }
  70
+		"icos"			{ return TOK_ICOS; }
  71
+		"i2f"			{ return TOK_I2F; }
  72
+		"if"			{ return TOK_IF; }
  73
+		"int"			{ return TOK_INT; }
  74
+		"invsqrt"		{ return TOK_INVSQRT; }
  75
+		"isin"			{ return TOK_ISIN; }
  76
+		"max"			{ return TOK_MAX; }
  77
+		"min"			{ return TOK_MIN; }
  78
+		"quake"			{ return TOK_QUAKE; }
  79
+		"sin"			{ return TOK_SIN; }
  80
+		"sqr"			{ return TOK_SQR; }
  81
+		"sqrt"			{ return TOK_SQRT; }
  82
+		"tsign"			{ return TOK_TSIGN; }
  83
+
  84
+		[a-zA-Z_0-9]+		{ return TOK_IDENT; }
  85
+		"+"			{ return TOK_PLUS; }
  86
+		"-"			{ return TOK_MINUS; }
  87
+		"*"			{ return TOK_MULTIPLY; }
  88
+		"/"			{ return TOK_DIVIDE; }
  89
+		"%"			{ return TOK_PERCENT; }
  90
+		"("			{ return TOK_LPAREN; }
  91
+		")"			{ return TOK_RPAREN; }
  92
+		","			{ return TOK_COMMA; }
  93
+		[\x00-\xff]		{ return TOK_ERROR; }
  94
+	*/
  95
+}
  96
+
  97
+const char *get_token(struct scanner *s)
  98
+{
  99
+	return unique_n((const char *) s->old_cursor,
  100
+	    s->cursor - s->old_cursor);
  101
+}
  102
+
  103
+float get_constant(struct scanner *s)
  104
+{
  105
+	const unsigned char *p;
  106
+	float v = 0;
  107
+	float m = 1;
  108
+
  109
+	for(p = s->old_cursor; p != s->cursor; p++) {
  110
+		if(*p == '.')
  111
+			goto dot;
  112
+		v = v*10+(*p-'0');
  113
+	}
  114
+	return v;
  115
+
  116
+dot:
  117
+	for(p++; p != s->cursor; p++) {
  118
+		m /= 10;
  119
+		v += m*(*p-'0');
  120
+	}
  121
+	return v;
  122
+}
137  src/compiler/unique.c
... ...
@@ -0,0 +1,137 @@
  1
+/*
  2
+ * unique.c - Unique string store
  3
+ *
  4
+ * Copyright 2011 by Werner Almesberger
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ */
  10
+
  11
+
  12
+#include <stdlib.h>
  13
+#include <string.h>
  14
+#include <ctype.h>
  15
+
  16
+#include "unique.h"
  17
+
  18
+
  19
+#define	INITIAL_ALLOC	64
  20
+
  21
+
  22
+struct key_n {
  23
+	const char *s;
  24
+	int n;
  25
+};
  26
+
  27
+const char *well_known[] = {
  28
+#include "fnp.inc"
  29
+};
  30
+
  31
+static const char **vars = NULL;
  32
+static int num_vars = 0, allocated = 0;
  33
+
  34
+
  35
+/*
  36
+ * "a" is not NUL-terminated and its length "a" is determined by "n".
  37
+ * "b" is NUL-terminated.
  38
+ */
  39
+
  40
+static int strcmp_n(const char *a, const char *b, int n)
  41
+{
  42
+	int diff;
  43
+
  44
+	diff = strncmp(a, b, n);
  45
+	if (diff)
  46
+		return diff;
  47
+	/* handle implicit NUL in string "a" */
  48
+	return -b[n];
  49
+}
  50
+
  51
+
  52
+static char *strdup_n(const char *s, int n)
  53
+{
  54
+	char *new;
  55
+
  56
+	new = malloc(n+1);
  57
+	memcpy(new, s, n);
  58
+	new[n] = 0;
  59
+	return new;
  60
+}
  61
+
  62
+
  63
+static void grow_table(void)
  64
+{
  65
+	if(num_vars != allocated)
  66
+		return;
  67
+
  68
+	allocated = allocated ? allocated*2 : INITIAL_ALLOC;
  69
+	vars = realloc(vars, allocated*sizeof(*vars));
  70
+}
  71
+
  72
+
  73
+static int cmp(const void *a, const void *b)
  74
+{
  75
+	return strcmp(a, *(const char **) b);
  76
+}
  77
+
  78
+
  79
+static int cmp_n(const void *a, const void *b)
  80
+{
  81
+	const struct key_n *key = a;
  82
+
  83
+	return strcmp_n(key->s, *(const char **) b, key->n);
  84
+}
  85
+
  86
+
  87
+const char *unique(const char *s)
  88
+{
  89
+	const char **res;
  90
+	const char **walk;
  91
+
  92
+	if(!isalnum(*s) && *s != '_')
  93
+		return s;
  94
+	res = bsearch(s, well_known, sizeof(well_known)/sizeof(*well_known),
  95
+	    sizeof(s), cmp);
  96
+	if(res)
  97
+		return *res;
  98
+	for(walk = vars; walk != vars+num_vars; walk++)
  99
+		if(!strcmp(*walk, s))
  100
+			return *walk;
  101
+	grow_table();
  102
+	return vars[num_vars++] = strdup(s);
  103
+}
  104
+
  105
+
  106
+const char *unique_n(const char *s, int n)
  107
+{
  108
+	struct key_n key = {
  109
+		.s = s,
  110
+		.n = n,
  111
+	};
  112
+	const char **res;
  113
+	const char **walk;
  114
+
  115
+	if(!isalnum(*s) && *s != '_')
  116
+		return s;
  117
+	res = bsearch(&key, well_known, sizeof(well_known)/sizeof(*well_known),
  118
+	    sizeof(s), cmp_n);
  119
+	if(res)
  120
+		return *res;
  121
+	for(walk = vars; walk != vars+num_vars; walk++)
  122
+		if(!strcmp_n(s, *walk, n))
  123
+			return *walk;
  124
+	grow_table();
  125
+	return vars[num_vars++] = strdup_n(s, n);
  126
+}
  127
+
  128
+
  129
+void unique_free(void)
  130
+{
  131
+	int i;
  132
+
  133
+	for(i = 0; i != num_vars; i++)
  134
+		free((void *) vars[i]);
  135
+	free(vars);
  136
+	num_vars = allocated = 0;
  137
+}
18  src/compiler/unique.h
... ...
@@ -0,0 +1,18 @@
  1
+/*
  2
+ * unique.h - Unique string store
  3
+ *
  4
+ * Copyright 2011 by Werner Almesberger
  5
+ *
  6
+ * This program is free software: you can redistribute it and/or modify
  7
+ * it under the terms of the GNU General Public License as published by
  8
+ * the Free Software Foundation, version 3 of the License.
  9
+ */
  10
+
  11
+#ifndef UNIQUE_H
  12
+#define	UNIQUE_H
  13
+
  14
+const char *unique(const char *s);
  15
+const char *unique_n(const char *s, int n);
  16
+void unique_free(void);
  17
+
  18
+#endif /* !UNIQUE_H */
0  src/obj/compiler/.keep_me
No changes.

No commit comments for this range

Something went wrong with that request. Please try again.