Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
Jan 12, 2012
Werner Almesberger ptest.c: restored dump_regs, using new forall_syms
It's now reasonably easy to look up identifiers, so we can have code
dumps again.
47c5068
Werner Almesberger compiler: remove "virtual ops" concept and use op_not from libfpvm
Also updated the regression test for algorithmic use of boolean not,
since this is now a valid use.
7ec58a4
Werner Almesberger compiler: also support equation numbers after per_vertex/per_pixel
Added regression test.
4bf4e79
Werner Almesberger compiler: disallow equation numbers and per_pixel keyword in new style a1adbc3
15  src/compiler/parser.y
@@ -322,20 +322,23 @@ assignment ::= context(C). {
322 322
 	state->comm->assign_default = C;
323 323
 }
324 324
 
325  
-context(C) ::= TOK_PER_FRAME TOK_ASSIGN. {
  325
+context(C) ::= old_per_frame TOK_ASSIGN. {
326 326
 	IS_STYLE(old_style);
327 327
 	C = state->comm->assign_per_frame;
328 328
 }
329 329
 
330  
-context(C) ::= TOK_PER_VERTEX TOK_ASSIGN. {
  330
+context(C) ::= old_per_vertex TOK_ASSIGN. {
331 331
 	IS_STYLE(old_style);
332 332
 	C = state->comm->assign_per_vertex;
333 333
 }
334 334
 
335  
-context(C) ::= TOK_PER_PIXEL TOK_ASSIGN. {
336  
-	IS_STYLE(old_style);
337  
-	C = state->comm->assign_per_vertex;
338  
-}
  335
+old_per_frame ::= TOK_PER_FRAME.
  336
+old_per_frame ::= TOK_PER_FRAME_UGLY.
  337
+
  338
+old_per_vertex ::= TOK_PER_VERTEX.
  339
+old_per_vertex ::= TOK_PER_VERTEX_UGLY.
  340
+old_per_vertex ::= TOK_PER_PIXEL.
  341
+old_per_vertex ::= TOK_PER_PIXEL_UGLY.
339 342
 
340 343
 opt_semi ::= opt_semi TOK_SEMI.
341 344
 
3  src/compiler/parser_helper.h
@@ -24,9 +24,6 @@
24 24
 #include "symtab.h"
25 25
 
26 26
 
27  
-/* virtual operation - for use inside the parser only */
28  
-#define	op_not	(op_vops+1)
29  
-
30 27
 struct compiler_sc;
31 28
 
32 29
 struct parser_comm {
41  src/compiler/ptest/ptest.c
@@ -256,7 +256,27 @@ static void parse_only(const char *pgm)
256 256
 }
257 257
 
258 258
 
259  
-static void dump_regs(const int *alloc, const char (*names)[FPVM_MAXSYMLEN],
  259
+/*
  260
+ * "sym" and "field" are used to access a field chosen by the caller in the
  261
+ * "struct sym". For this, the caller provides a buffer (sym) and a pointer to
  262
+ * the respective field inside the buffer. This way, it's perfectly type-safe
  263
+ * and we don't need offsetof acrobatics.
  264
+ */
  265
+
  266
+static const char *lookup_name(int idx, struct sym *sym, const int *field)
  267
+{
  268
+	const struct sym *walk;
  269
+
  270
+	forall_syms(walk) {
  271
+		*sym = *walk;
  272
+		if (*field == idx)
  273
+			return walk->fpvm_sym.name;
  274
+	}
  275
+	return NULL;
  276
+}
  277
+
  278
+
  279
+static void dump_regs(const int *alloc, struct sym *sym, const int *field,
260 280
     const float *values, int n)
261 281
 {
262 282
 	const char *mapped[n];
@@ -266,7 +286,7 @@ static void dump_regs(const int *alloc, const char (*names)[FPVM_MAXSYMLEN],
266 286
 		mapped[i] = NULL;
267 287
 	for (i = 0; i != n; i++)
268 288
 		if (alloc[i] != -1)
269  
-			mapped[alloc[i]] = names[i];
  289
+			mapped[alloc[i]] = lookup_name(i, sym, field);
270 290
 	for (i = 0; i != n; i++) {
271 291
 		if (!values[i] && !mapped[i])
272 292
 			continue;
@@ -280,27 +300,22 @@ static void dump_regs(const int *alloc, const char (*names)[FPVM_MAXSYMLEN],
280 300
 
281 301
 static void show_patch(const struct patch *patch)
282 302
 {
283  
-/*
284  
- * @@@ Disable for now since we have no good way to get the names and the
285  
- * mapping archtecture is still in flux.
286  
- */
287  
-#if 0
288 303
 	int i;
  304
+	struct sym sym;
289 305
 
290 306
 	printf("global:\n");
291 307
 	for (i = 0; i != COMP_PFV_COUNT; i++)
292 308
 		if (patch->pfv_initial[i])
293 309
 			printf("R%03d = %f %s\n", i, patch->pfv_initial[i],
294  
-			    pfv_names[i]);
  310
+			    lookup_name(i, &sym, &sym.pfv_idx));
295 311
 	printf("per-frame PFPU fragment:\n");
296  
-	dump_regs(patch->pfv_allocation, pfv_names, patch->perframe_regs,
297  
-	    COMP_PFV_COUNT);
  312
+	dump_regs(patch->pfv_allocation, &sym, &sym.pfv_idx,
  313
+	    patch->perframe_regs, COMP_PFV_COUNT);
298 314
 	pfpu_dump(patch->perframe_prog, patch->perframe_prog_length);
299 315
 	printf("per-vertex PFPU fragment:\n");
300  
-	dump_regs(patch->pvv_allocation, pvv_names, patch->pervertex_regs,
301  
-	    COMP_PVV_COUNT);
  316
+	dump_regs(patch->pvv_allocation, &sym, &sym.pvv_idx,
  317
+	     patch->pervertex_regs, COMP_PVV_COUNT);
302 318
 	pfpu_dump(patch->pervertex_prog, patch->pervertex_prog_length);
303  
-#endif
304 319
 }
305 320
 
306 321
 
10  src/compiler/scanner.re
@@ -118,10 +118,14 @@ int scan(struct scanner *s)
118 118
 		<N>"sqrt"		{ return TOK_SQRT; }
119 119
 		<N>"tsign"		{ return TOK_TSIGN; }
120 120
 
121  
-		<N>"per_frame"[a-z_0-9]*
122  
-					{ return TOK_PER_FRAME; }
  121
+		<N>"per_frame"		{ return TOK_PER_FRAME; }
123 122
 		<N>"per_vertex"		{ return TOK_PER_VERTEX; }
124  
-		<N>"per_pixel"		{ return TOK_PER_PIXEL; }
  123
+		<N>"per_frame"[a-z_0-9]+
  124
+					{ return TOK_PER_FRAME_UGLY; }
  125
+		<N>"per_vertex"[a-z_0-9]+
  126
+					{ return TOK_PER_VERTEX_UGLY; }
  127
+		<N>"per_pixel"[a-z_0-9]*
  128
+					{ return TOK_PER_PIXEL_UGLY; }
125 129
 
126 130
 		<N>"imagefile"[1-9]	{ YYSETCONDITION(yycFNAME1);
127 131
 					  return TOK_IMAGEFILE; }
51  src/compiler/test/eqnum
... ...
@@ -0,0 +1,51 @@
  1
+#!/bin/sh
  2
+. ./Common
  3
+
  4
+###############################################################################
  5
+
  6
+ptest "equation numbers: old-style per_frame" <<EOF
  7
+per_frame_0 = foo = 1
  8
+EOF
  9
+expect <<EOF
  10
+per_frame = foo = 1
  11
+EOF
  12
+
  13
+#------------------------------------------------------------------------------
  14
+
  15
+ptest "equation numbers: old-style per_vertex" <<EOF
  16
+per_vertex_20 = foo = 2
  17
+EOF
  18
+expect <<EOF
  19
+per_vertex = foo = 2
  20
+EOF
  21
+
  22
+#------------------------------------------------------------------------------
  23
+
  24
+ptest "equation numbers: old-style per_pixel" <<EOF
  25
+per_pixel_n0 = foo = 3
  26
+EOF
  27
+expect <<EOF
  28
+per_vertex = foo = 3
  29
+EOF
  30
+
  31
+#------------------------------------------------------------------------------
  32
+
  33
+ptest_fail "equation numbers: new-style per_frame" <<EOF
  34
+per_frame_0:
  35
+	foo = 1
  36
+EOF
  37
+expect <<EOF
  38
+FPVM, line 1: parse error near ':'
  39
+EOF
  40
+
  41
+#------------------------------------------------------------------------------
  42
+
  43
+ptest_fail "equation numbers: new-style per_vertex" <<EOF
  44
+per_vertex_2:
  45
+	foo = 2
  46
+EOF
  47
+expect <<EOF
  48
+FPVM, line 1: parse error near ':'
  49
+EOF
  50
+
  51
+###############################################################################
28  src/compiler/test/not
@@ -12,15 +12,6 @@ EOF
12 12
 
13 13
 #------------------------------------------------------------------------------
14 14
 
15  
-ptest_fail "not: !a (try to generate code)" -c << EOF
16  
-per_frame: wave_a = !a
17  
-EOF
18  
-expect <<EOF
19  
-FPVM, line 2: Operation not supported: 29 near 'EOF'
20  
-EOF
21  
-
22  
-#------------------------------------------------------------------------------
23  
-
24 15
 ptest "not: !0" << EOF
25 16
 sx = !0
26 17
 EOF
@@ -100,4 +91,23 @@ expect <<EOF
100 91
 sx = c
101 92
 EOF
102 93
 
  94
+#------------------------------------------------------------------------------
  95
+
  96
+ptest "not: !sx (generate code)" -c << EOF
  97
+per_frame: wave_a = !sx
  98
+EOF
  99
+sedit '/^per-frame/,/^Eff/p;d'
  100
+expect <<EOF
  101
+per-frame PFPU fragment:
  102
+R003 = 1.000000 fWaveAlpha
  103
+R004 = 1.000000 sx
  104
+0000: EQUAL   R004,R005 <L=2 E=0002> 
  105
+0001: COPY    R000      <L=2 E=0003> 
  106
+0002: COPY    R001      <L=2 E=0004> -> R003
  107
+0003: NOP                            -> R002
  108
+0004: NOP                            -> R006
  109
+0005: VECTOUT R000,R000 <L=0 E=0005> 
  110
+Efficiency: 50%
  111
+EOF
  112
+
103 113
 ###############################################################################
10  src/compiler/test/sections
@@ -145,4 +145,14 @@ per_vertex = a = b
145 145
 FPVM, line 3: parse error near 'c'
146 146
 EOF
147 147
 
  148
+#------------------------------------------------------------------------------
  149
+
  150
+ptest_fail "sections: new style has no per_pixel" <<EOF
  151
+per_pixel:
  152
+	no = junk
  153
+EOF
  154
+expect <<EOF
  155
+FPVM, line 1: parse error near ':'
  156
+EOF
  157
+
148 158
 ###############################################################################

No commit comments for this range

Something went wrong with that request. Please try again.