author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 28 Oct 2010 03:42:12 -0400 | |
changeset 931 | 4aa1f68d8292 |
parent 892 | c45dec9f8906 |
child 933 | f2367f48f3e2 |
permissions | -rw-r--r-- |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/** |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* MojoShader; generate shader programs from bytecode of compiled |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* Direct3D shaders. |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* Please see the file LICENSE.txt in the source's root directory. |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* This file written by Ryan C. Gordon. |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
*/ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
#include <stdio.h> |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include <stdlib.h> |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
12 |
#include <string.h> |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
13 |
#include <assert.h> |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
14 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
#include "mojoshader.h" |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
17 |
#ifndef _WIN32 |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
18 |
#define stricmp(a,b) strcasecmp(a,b) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
19 |
#endif |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
20 |
|
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
21 |
static const char **include_paths = NULL; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
22 |
static unsigned int include_path_count = 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
23 |
|
673
4b14154df11b
Turn off allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
671
diff
changeset
|
24 |
#define MOJOSHADER_DEBUG_MALLOC 0 |
671
af7b7bfdfc2a
Fixed allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
670
diff
changeset
|
25 |
|
665
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
26 |
#if MOJOSHADER_DEBUG_MALLOC |
671
af7b7bfdfc2a
Fixed allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
670
diff
changeset
|
27 |
static void *Malloc(int len, void *d) |
665
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
28 |
{ |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
29 |
void *ptr = malloc(len + sizeof (int)); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
30 |
int *store = (int *) ptr; |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
31 |
printf("malloc() %d bytes (%p)\n", len, ptr); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
32 |
if (ptr == NULL) return NULL; |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
33 |
*store = len; |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
34 |
return (void *) (store + 1); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
35 |
} // Malloc |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
36 |
|
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
37 |
|
671
af7b7bfdfc2a
Fixed allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
670
diff
changeset
|
38 |
static void Free(void *_ptr, void *d) |
665
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
39 |
{ |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
40 |
int *ptr = (((int *) _ptr) - 1); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
41 |
int len = *ptr; |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
42 |
printf("free() %d bytes (%p)\n", len, ptr); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
43 |
free(ptr); |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
44 |
} // Free |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
45 |
#else |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
46 |
#define Malloc NULL |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
47 |
#define Free NULL |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
48 |
#endif |
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
49 |
|
668 | 50 |
|
51 |
static void fail(const char *err) |
|
52 |
{ |
|
53 |
printf("%s.\n", err); |
|
54 |
exit(1); |
|
55 |
} // fail |
|
56 |
||
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
57 |
static void print_unroll_attr(const int unroll) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
58 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
59 |
if (unroll == 0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
60 |
printf("[loop] "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
61 |
else if (unroll < 0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
62 |
printf("[unroll] "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
63 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
64 |
printf("[unroll(%d)] ", unroll); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
65 |
} // print_unroll_attr |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
66 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
67 |
// !!! FIXME: this screws up on order of operations. |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
68 |
static void print_ast(const int substmt, const void *_ast) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
69 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
70 |
const MOJOSHADER_astNode *ast = (const MOJOSHADER_astNode *) _ast; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
71 |
const char *nl = substmt ? "" : "\n"; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
72 |
int typeint = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
73 |
static int indent = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
74 |
int isblock = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
75 |
int i; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
76 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
77 |
// These _HAVE_ to be in the same order as MOJOSHADER_astNodeType! |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
78 |
static const char *binary[] = |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
79 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
80 |
",", "*", "/", "%", "+", "-", "<<", ">>", "<", ">", "<=", ">=", "==", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
81 |
"!=", "&", "^", "|", "&&", "||", "=", "*=", "/=", "%=", "+=", "-=", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
82 |
"<<=", ">>=", "&=", "^=", "|=" |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
83 |
}; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
84 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
85 |
static const char *pre_unary[] = { "++", "--", "-", "~", "!" }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
86 |
static const char *post_unary[] = { "++", "--" }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
87 |
static const char *simple_stmt[] = { "", "break", "continue", "discard" }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
88 |
static const char *inpmod[] = { "", "in ", "out ", "in out ", "uniform " }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
89 |
static const char *fnstorage[] = { "", "inline " }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
90 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
91 |
static const char *interpmod[] = { |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
92 |
"", " linear", " centroid", " nointerpolation", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
93 |
" noperspective", " sample" |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
94 |
}; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
95 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
96 |
if (!ast) return; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
97 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
98 |
typeint = (int) ast->ast.type; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
99 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
100 |
#define DO_INDENT do { \ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
101 |
if (!substmt) { for (i = 0; i < indent; i++) printf(" "); } \ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
102 |
} while (0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
103 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
104 |
switch (ast->ast.type) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
105 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
106 |
case MOJOSHADER_AST_OP_PREINCREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
107 |
case MOJOSHADER_AST_OP_PREDECREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
108 |
case MOJOSHADER_AST_OP_NEGATE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
109 |
case MOJOSHADER_AST_OP_COMPLEMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
110 |
case MOJOSHADER_AST_OP_NOT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
111 |
printf("%s", pre_unary[(typeint-MOJOSHADER_AST_OP_START_RANGE_UNARY)-1]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
112 |
print_ast(0, ast->unary.operand); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
113 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
114 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
115 |
case MOJOSHADER_AST_OP_POSTINCREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
116 |
case MOJOSHADER_AST_OP_POSTDECREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
117 |
print_ast(0, ast->unary.operand); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
118 |
printf("%s", post_unary[typeint-MOJOSHADER_AST_OP_POSTINCREMENT]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
119 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
120 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
121 |
case MOJOSHADER_AST_OP_MULTIPLY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
122 |
case MOJOSHADER_AST_OP_DIVIDE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
123 |
case MOJOSHADER_AST_OP_MODULO: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
124 |
case MOJOSHADER_AST_OP_ADD: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
125 |
case MOJOSHADER_AST_OP_SUBTRACT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
126 |
case MOJOSHADER_AST_OP_LSHIFT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
127 |
case MOJOSHADER_AST_OP_RSHIFT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
128 |
case MOJOSHADER_AST_OP_LESSTHAN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
129 |
case MOJOSHADER_AST_OP_GREATERTHAN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
130 |
case MOJOSHADER_AST_OP_LESSTHANOREQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
131 |
case MOJOSHADER_AST_OP_GREATERTHANOREQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
132 |
case MOJOSHADER_AST_OP_EQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
133 |
case MOJOSHADER_AST_OP_NOTEQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
134 |
case MOJOSHADER_AST_OP_BINARYAND: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
135 |
case MOJOSHADER_AST_OP_BINARYXOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
136 |
case MOJOSHADER_AST_OP_BINARYOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
137 |
case MOJOSHADER_AST_OP_LOGICALAND: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
138 |
case MOJOSHADER_AST_OP_LOGICALOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
139 |
case MOJOSHADER_AST_OP_ASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
140 |
case MOJOSHADER_AST_OP_MULASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
141 |
case MOJOSHADER_AST_OP_DIVASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
142 |
case MOJOSHADER_AST_OP_MODASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
143 |
case MOJOSHADER_AST_OP_ADDASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
144 |
case MOJOSHADER_AST_OP_SUBASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
145 |
case MOJOSHADER_AST_OP_LSHIFTASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
146 |
case MOJOSHADER_AST_OP_RSHIFTASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
147 |
case MOJOSHADER_AST_OP_ANDASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
148 |
case MOJOSHADER_AST_OP_XORASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
149 |
case MOJOSHADER_AST_OP_ORASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
150 |
printf(" "); // then fall through! (no space before the comma). |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
151 |
case MOJOSHADER_AST_OP_COMMA: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
152 |
print_ast(0, ast->binary.left); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
153 |
printf("%s ", binary[ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
154 |
(typeint - MOJOSHADER_AST_OP_START_RANGE_BINARY) - 1]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
155 |
print_ast(0, ast->binary.right); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
156 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
157 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
158 |
case MOJOSHADER_AST_OP_DEREF_ARRAY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
159 |
print_ast(0, ast->binary.left); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
160 |
printf("["); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
161 |
print_ast(0, ast->binary.right); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
162 |
printf("]"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
163 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
164 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
165 |
case MOJOSHADER_AST_OP_DEREF_STRUCT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
166 |
print_ast(0, ast->derefstruct.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
167 |
printf("."); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
168 |
printf("%s", ast->derefstruct.member); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
169 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
170 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
171 |
case MOJOSHADER_AST_OP_CONDITIONAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
172 |
print_ast(0, ast->ternary.left); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
173 |
printf(" ? "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
174 |
print_ast(0, ast->ternary.center); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
175 |
printf(" : "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
176 |
print_ast(0, ast->ternary.right); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
177 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
178 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
179 |
case MOJOSHADER_AST_OP_IDENTIFIER: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
180 |
printf("%s", ast->identifier.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
181 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
182 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
183 |
case MOJOSHADER_AST_OP_INT_LITERAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
184 |
printf("%d", ast->intliteral.value); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
185 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
186 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
187 |
case MOJOSHADER_AST_OP_FLOAT_LITERAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
188 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
189 |
const float f = ast->floatliteral.value; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
190 |
const long long flr = (long long) f; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
191 |
if (((float) flr) == f) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
192 |
printf("%lld.0", flr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
193 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
194 |
printf("%.16g", f); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
195 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
196 |
} // case |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
197 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
198 |
case MOJOSHADER_AST_OP_STRING_LITERAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
199 |
printf("\"%s\"", ast->stringliteral.string); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
200 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
201 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
202 |
case MOJOSHADER_AST_OP_BOOLEAN_LITERAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
203 |
printf("%s", ast->boolliteral.value ? "true" : "false"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
204 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
205 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
206 |
case MOJOSHADER_AST_ARGUMENTS: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
207 |
print_ast(0, ast->arguments.argument); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
208 |
if (ast->arguments.next != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
209 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
210 |
printf(", "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
211 |
print_ast(0, ast->arguments.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
212 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
213 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
214 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
215 |
case MOJOSHADER_AST_OP_CALLFUNC: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
216 |
print_ast(0, ast->callfunc.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
217 |
printf("("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
218 |
print_ast(0, ast->callfunc.args); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
219 |
printf(")"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
220 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
221 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
222 |
case MOJOSHADER_AST_OP_CONSTRUCTOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
223 |
printf("%s(", ast->constructor.datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
224 |
print_ast(0, ast->constructor.args); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
225 |
printf(")"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
226 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
227 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
228 |
case MOJOSHADER_AST_OP_CAST: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
229 |
printf("(%s) (", ast->cast.datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
230 |
print_ast(0, ast->cast.operand); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
231 |
printf(")"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
232 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
233 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
234 |
case MOJOSHADER_AST_STATEMENT_EXPRESSION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
235 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
236 |
print_ast(0, ast->exprstmt.expr); // !!! FIXME: This is named badly... |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
237 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
238 |
print_ast(0, ast->exprstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
239 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
240 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
241 |
case MOJOSHADER_AST_STATEMENT_IF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
242 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
243 |
printf("if ("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
244 |
print_ast(0, ast->ifstmt.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
245 |
printf(")\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
246 |
isblock = ast->ifstmt.statement->ast.type == MOJOSHADER_AST_STATEMENT_BLOCK; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
247 |
if (!isblock) indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
248 |
print_ast(0, ast->ifstmt.statement); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
249 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
250 |
print_ast(0, ast->ifstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
251 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
252 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
253 |
case MOJOSHADER_AST_STATEMENT_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
254 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
255 |
print_ast(1, ast->typedefstmt.type_info); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
256 |
printf("%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
257 |
print_ast(0, ast->typedefstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
258 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
259 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
260 |
case MOJOSHADER_AST_STATEMENT_SWITCH: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
261 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
262 |
switch ( ast->switchstmt.attributes ) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
263 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
264 |
case MOJOSHADER_AST_SWITCHATTR_NONE: break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
265 |
case MOJOSHADER_AST_SWITCHATTR_FLATTEN: printf("[flatten] "); break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
266 |
case MOJOSHADER_AST_SWITCHATTR_BRANCH: printf("[branch] "); break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
267 |
case MOJOSHADER_AST_SWITCHATTR_FORCECASE: printf("[forcecase] "); break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
268 |
case MOJOSHADER_AST_SWITCHATTR_CALL: printf("[call] "); break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
269 |
} // switch |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
270 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
271 |
printf("switch ("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
272 |
print_ast(0, ast->switchstmt.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
273 |
printf(")\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
274 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
275 |
printf("{\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
276 |
indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
277 |
print_ast(0, ast->switchstmt.cases); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
278 |
indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
279 |
printf("\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
280 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
281 |
printf("}\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
282 |
print_ast(0, ast->switchstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
283 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
284 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
285 |
case MOJOSHADER_AST_SWITCH_CASE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
286 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
287 |
printf("case "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
288 |
print_ast(0, ast->cases.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
289 |
printf(":\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
290 |
isblock = ast->cases.statement->ast.type == MOJOSHADER_AST_STATEMENT_BLOCK; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
291 |
if (!isblock) indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
292 |
print_ast(0, ast->cases.statement); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
293 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
294 |
print_ast(0, ast->cases.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
295 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
296 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
297 |
case MOJOSHADER_AST_STATEMENT_STRUCT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
298 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
299 |
print_ast(0, ast->structstmt.struct_info); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
300 |
printf(";%s%s", nl, nl); // always space these out. |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
301 |
print_ast(0, ast->structstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
302 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
303 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
304 |
case MOJOSHADER_AST_STATEMENT_VARDECL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
305 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
306 |
print_ast(1, ast->vardeclstmt.declaration); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
307 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
308 |
print_ast(0, ast->vardeclstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
309 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
310 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
311 |
case MOJOSHADER_AST_STATEMENT_BLOCK: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
312 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
313 |
printf("{\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
314 |
indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
315 |
print_ast(0, ast->blockstmt.statements); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
316 |
indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
317 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
318 |
printf("}\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
319 |
print_ast(0, ast->blockstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
320 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
321 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
322 |
case MOJOSHADER_AST_STATEMENT_FOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
323 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
324 |
print_unroll_attr(ast->forstmt.unroll); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
325 |
printf("for ("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
326 |
print_ast(1, ast->forstmt.var_decl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
327 |
if (ast->forstmt.initializer != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
328 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
329 |
printf(" = "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
330 |
print_ast(1, ast->forstmt.initializer); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
331 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
332 |
printf("; "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
333 |
print_ast(1, ast->forstmt.looptest); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
334 |
printf("; "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
335 |
print_ast(1, ast->forstmt.counter); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
336 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
337 |
printf(")\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
338 |
isblock = ast->forstmt.statement->ast.type == MOJOSHADER_AST_STATEMENT_BLOCK; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
339 |
if (!isblock) indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
340 |
print_ast(0, ast->forstmt.statement); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
341 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
342 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
343 |
print_ast(0, ast->forstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
344 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
345 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
346 |
case MOJOSHADER_AST_STATEMENT_DO: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
347 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
348 |
print_unroll_attr(ast->dostmt.unroll); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
349 |
printf("do\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
350 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
351 |
isblock = ast->dostmt.statement->ast.type == MOJOSHADER_AST_STATEMENT_BLOCK; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
352 |
if (!isblock) indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
353 |
print_ast(0, ast->dostmt.statement); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
354 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
355 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
356 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
357 |
printf("while ("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
358 |
print_ast(0, ast->dostmt.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
359 |
printf(");\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
360 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
361 |
print_ast(0, ast->dostmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
362 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
363 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
364 |
case MOJOSHADER_AST_STATEMENT_WHILE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
365 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
366 |
print_unroll_attr(ast->whilestmt.unroll); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
367 |
printf("while ("); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
368 |
print_ast(0, ast->whilestmt.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
369 |
printf(")\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
370 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
371 |
isblock = ast->whilestmt.statement->ast.type == MOJOSHADER_AST_STATEMENT_BLOCK; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
372 |
if (!isblock) indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
373 |
print_ast(0, ast->whilestmt.statement); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
374 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
375 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
376 |
print_ast(0, ast->whilestmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
377 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
378 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
379 |
case MOJOSHADER_AST_STATEMENT_RETURN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
380 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
381 |
printf("return"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
382 |
if (ast->returnstmt.expr) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
383 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
384 |
printf(" "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
385 |
print_ast(0, ast->returnstmt.expr); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
386 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
387 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
388 |
print_ast(0, ast->returnstmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
389 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
390 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
391 |
case MOJOSHADER_AST_STATEMENT_EMPTY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
392 |
case MOJOSHADER_AST_STATEMENT_BREAK: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
393 |
case MOJOSHADER_AST_STATEMENT_CONTINUE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
394 |
case MOJOSHADER_AST_STATEMENT_DISCARD: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
395 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
396 |
printf("%s;%s", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
397 |
simple_stmt[(typeint-MOJOSHADER_AST_STATEMENT_START_RANGE)-1], |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
398 |
nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
399 |
print_ast(0, ast->stmt.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
400 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
401 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
402 |
case MOJOSHADER_AST_COMPUNIT_FUNCTION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
403 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
404 |
print_ast(0, ast->funcunit.declaration); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
405 |
if (ast->funcunit.definition == NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
406 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
407 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
408 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
409 |
printf("%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
410 |
print_ast(0, ast->funcunit.definition); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
411 |
printf("%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
412 |
} // else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
413 |
print_ast(0, ast->funcunit.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
414 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
415 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
416 |
case MOJOSHADER_AST_COMPUNIT_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
417 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
418 |
print_ast(0, ast->typedefunit.type_info); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
419 |
printf("%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
420 |
print_ast(0, ast->typedefunit.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
421 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
422 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
423 |
case MOJOSHADER_AST_COMPUNIT_STRUCT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
424 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
425 |
print_ast(0, ast->structunit.struct_info); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
426 |
printf(";%s%s", nl, nl); // always space these out. |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
427 |
print_ast(0, ast->structunit.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
428 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
429 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
430 |
case MOJOSHADER_AST_COMPUNIT_VARIABLE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
431 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
432 |
print_ast(1, ast->varunit.declaration); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
433 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
434 |
if (ast->varunit.next && |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
435 |
ast->varunit.next->ast.type!=MOJOSHADER_AST_COMPUNIT_VARIABLE) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
436 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
437 |
printf("%s", nl); // group vars together, and space out other things. |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
438 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
439 |
print_ast(0, ast->varunit.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
440 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
441 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
442 |
case MOJOSHADER_AST_SCALAR_OR_ARRAY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
443 |
printf("%s", ast->soa.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
444 |
if (ast->soa.isarray) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
445 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
446 |
printf("["); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
447 |
print_ast(0, ast->soa.dimension); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
448 |
printf("]"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
449 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
450 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
451 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
452 |
case MOJOSHADER_AST_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
453 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
454 |
printf("typedef %s%s ", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
455 |
ast->typdef.isconst ? "const " : "", ast->typdef.datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
456 |
print_ast(0, ast->typdef.details); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
457 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
458 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
459 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
460 |
case MOJOSHADER_AST_FUNCTION_PARAMS: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
461 |
printf("%s", inpmod[(int) ast->params.input_modifier]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
462 |
printf("%s %s", ast->params.datatype, ast->params.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
463 |
if (ast->params.semantic) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
464 |
printf(" : %s", ast->params.semantic); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
465 |
printf("%s", interpmod[(int) ast->params.interpolation_modifier]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
466 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
467 |
if (ast->params.initializer) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
468 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
469 |
printf(" = "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
470 |
print_ast(0, ast->params.initializer); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
471 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
472 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
473 |
if (ast->params.next) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
474 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
475 |
printf(", "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
476 |
print_ast(0, ast->params.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
477 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
478 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
479 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
480 |
case MOJOSHADER_AST_FUNCTION_SIGNATURE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
481 |
printf("%s", fnstorage[(int) ast->funcsig.storage_class]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
482 |
printf("%s %s(", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
483 |
ast->funcsig.datatype ? ast->funcsig.datatype : "void", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
484 |
ast->funcsig.identifier); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
485 |
print_ast(0, ast->funcsig.params); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
486 |
printf(")"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
487 |
if (ast->funcsig.semantic) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
488 |
printf(" : %s", ast->funcsig.semantic); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
489 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
490 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
491 |
case MOJOSHADER_AST_STRUCT_DECLARATION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
492 |
printf("struct %s\n", ast->structdecl.name); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
493 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
494 |
printf("{\n"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
495 |
indent++; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
496 |
print_ast(0, ast->structdecl.members); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
497 |
indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
498 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
499 |
printf("}"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
500 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
501 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
502 |
case MOJOSHADER_AST_STRUCT_MEMBER: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
503 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
504 |
printf("%s", interpmod[(int)ast->structmembers.interpolation_mod]); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
505 |
printf("%s ", ast->structmembers.datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
506 |
print_ast(0, ast->structmembers.details); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
507 |
if (ast->structmembers.semantic) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
508 |
printf(" : %s", ast->structmembers.semantic); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
509 |
printf(";%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
510 |
print_ast(0, ast->structmembers.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
511 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
512 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
513 |
case MOJOSHADER_AST_VARIABLE_DECLARATION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
514 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
515 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_EXTERN) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
516 |
printf("extern "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
517 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_NOINTERPOLATION) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
518 |
printf("nointerpolation "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
519 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_SHARED) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
520 |
printf("shared"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
521 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_STATIC) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
522 |
printf("static "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
523 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_UNIFORM) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
524 |
printf("uniform "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
525 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_VOLATILE) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
526 |
printf("nointerpolation "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
527 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_CONST) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
528 |
printf("const "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
529 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_ROWMAJOR) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
530 |
printf("rowmajor "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
531 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_COLUMNMAJOR) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
532 |
printf("columnmajor "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
533 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
534 |
if (ast->vardecl.datatype) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
535 |
printf("%s", ast->vardecl.datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
536 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
537 |
print_ast(0, ast->vardecl.anonymous_datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
538 |
printf(" "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
539 |
print_ast(0, ast->vardecl.details); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
540 |
if (ast->vardecl.semantic) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
541 |
printf(" : %s", ast->vardecl.semantic); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
542 |
if (ast->vardecl.annotations) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
543 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
544 |
printf(" "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
545 |
print_ast(0, ast->vardecl.annotations); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
546 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
547 |
if (ast->vardecl.initializer != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
548 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
549 |
printf(" = "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
550 |
print_ast(0, ast->vardecl.initializer); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
551 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
552 |
print_ast(0, ast->vardecl.lowlevel); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
553 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
554 |
if (ast->vardecl.next == NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
555 |
printf("%s", nl); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
556 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
557 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
558 |
const int attr = ast->vardecl.next->attributes; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
559 |
printf(", "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
560 |
ast->vardecl.next->attributes = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
561 |
print_ast(1, ast->vardecl.next); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
562 |
ast->vardecl.next->attributes = attr; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
563 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
564 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
565 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
566 |
case MOJOSHADER_AST_PACK_OFFSET: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
567 |
printf(" : packoffset(%s%s%s)", ast->packoffset.ident1, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
568 |
ast->packoffset.ident2 ? "." : "", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
569 |
ast->packoffset.ident2 ? ast->packoffset.ident2 : ""); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
570 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
571 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
572 |
case MOJOSHADER_AST_VARIABLE_LOWLEVEL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
573 |
print_ast(0, ast->varlowlevel.packoffset); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
574 |
if (ast->varlowlevel.register_name) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
575 |
printf(" : register(%s)", ast->varlowlevel.register_name); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
576 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
577 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
578 |
case MOJOSHADER_AST_ANNOTATION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
579 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
580 |
const MOJOSHADER_astAnnotations *a = &ast->annotations; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
581 |
printf("<"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
582 |
while (a) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
583 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
584 |
printf(" %s ", a->datatype); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
585 |
if (a->initializer != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
586 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
587 |
printf(" = "); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
588 |
print_ast(0, a->initializer); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
589 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
590 |
if (a->next) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
591 |
printf(","); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
592 |
a = a->next; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
593 |
} // while |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
594 |
printf(" >"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
595 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
596 |
} // case |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
597 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
598 |
default: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
599 |
assert(0 && "unexpected type"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
600 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
601 |
} // switch |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
602 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
603 |
#undef DO_INDENT |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
604 |
} // print_ast |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
605 |
|
668 | 606 |
|
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
607 |
static int open_include(MOJOSHADER_includeType inctype, const char *fname, |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
608 |
const char *parent, const char **outdata, |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
609 |
unsigned int *outbytes, MOJOSHADER_malloc m, |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
610 |
MOJOSHADER_free f, void *d) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
611 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
612 |
int i; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
613 |
for (i = 0; i < include_path_count; i++) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
614 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
615 |
const char *path = include_paths[i]; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
616 |
const size_t len = strlen(path) + strlen(fname) + 2; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
617 |
char *buf = (char *) m(len, d); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
618 |
if (buf == NULL) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
619 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
620 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
621 |
snprintf(buf, len, "%s/%s", path, fname); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
622 |
FILE *io = fopen(buf, "rb"); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
623 |
f(buf, d); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
624 |
if (io == NULL) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
625 |
continue; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
626 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
627 |
if (fseek(io, 0, SEEK_END) != -1) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
628 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
629 |
const long fsize = ftell(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
630 |
if ((fsize == -1) || (fseek(io, 0, SEEK_SET) == -1)) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
631 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
632 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
633 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
634 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
635 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
636 |
char *data = (char *) m(fsize, d); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
637 |
if (data == NULL) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
638 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
639 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
640 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
641 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
642 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
643 |
if (fread(data, fsize, 1, io) != 1) |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
644 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
645 |
f(data, d); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
646 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
647 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
648 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
649 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
650 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
651 |
*outdata = data; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
652 |
*outbytes = (unsigned int) fsize; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
653 |
return 1; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
654 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
655 |
} // for |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
656 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
657 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
658 |
} // open_include |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
659 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
660 |
|
663 | 661 |
static void close_include(const char *data, MOJOSHADER_malloc m, |
662 |
MOJOSHADER_free f, void *d) |
|
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
663 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
664 |
f((void *) data, d); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
665 |
} // close_include |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
666 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
667 |
|
578
6c8f73c845e7
Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
577
diff
changeset
|
668 |
static int preprocess(const char *fname, const char *buf, int len, |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
669 |
const char *outfile, |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
670 |
const MOJOSHADER_preprocessorDefine *defs, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
671 |
unsigned int defcount, FILE *io) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
672 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
const MOJOSHADER_preprocessData *pd; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
674 |
int retval = 0; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
|
665
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
676 |
pd = MOJOSHADER_preprocess(fname, buf, len, defs, defcount, open_include, |
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
677 |
close_include, Malloc, Free, NULL); |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
679 |
if (pd->error_count > 0) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
680 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
int i; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
682 |
for (i = 0; i < pd->error_count; i++) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
683 |
{ |
885
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
793
diff
changeset
|
684 |
fprintf(stderr, "%s:%d: ERROR: %s\n", |
577
bec531dd448e
Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
556
diff
changeset
|
685 |
pd->errors[i].filename ? pd->errors[i].filename : "???", |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
686 |
pd->errors[i].error_position, |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
687 |
pd->errors[i].error); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
688 |
} // for |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
689 |
} // if |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
690 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
691 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
692 |
if (pd->output != NULL) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
693 |
{ |
747
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
694 |
const int len = pd->output_len; |
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
695 |
if ((len) && (fwrite(pd->output, len, 1, io) != 1)) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 |
printf(" ... fwrite('%s') failed.\n", outfile); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
697 |
else if ((outfile != NULL) && (fclose(io) == EOF)) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
698 |
printf(" ... fclose('%s') failed.\n", outfile); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
699 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
700 |
retval = 1; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
701 |
} // if |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
702 |
} // else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
703 |
MOJOSHADER_freePreprocessData(pd); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
704 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
705 |
return retval; |
556
04282775cc2c
Fixed cut-and-pasted comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
706 |
} // preprocess |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
707 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
708 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
709 |
static int assemble(const char *fname, const char *buf, int len, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
710 |
const char *outfile, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
711 |
const MOJOSHADER_preprocessorDefine *defs, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
712 |
unsigned int defcount, FILE *io) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
713 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
714 |
const MOJOSHADER_parseData *pd; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
715 |
int retval = 0; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
716 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
717 |
pd = MOJOSHADER_assemble(fname, buf, len, NULL, 0, NULL, 0, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
718 |
defs, defcount, open_include, close_include, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
719 |
Malloc, Free, NULL); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
720 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
721 |
if (pd->error_count > 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
722 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
723 |
int i; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
724 |
for (i = 0; i < pd->error_count; i++) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
725 |
{ |
885
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
793
diff
changeset
|
726 |
fprintf(stderr, "%s:%d: ERROR: %s\n", |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
727 |
pd->errors[i].filename ? pd->errors[i].filename : "???", |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
728 |
pd->errors[i].error_position, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
729 |
pd->errors[i].error); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
730 |
} // for |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
731 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
732 |
else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
733 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
734 |
if (pd->output != NULL) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
735 |
{ |
747
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
736 |
const int len = pd->output_len; |
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
737 |
if ((len) && (fwrite(pd->output, len, 1, io) != 1)) |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
738 |
printf(" ... fwrite('%s') failed.\n", outfile); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
739 |
else if ((outfile != NULL) && (fclose(io) == EOF)) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
740 |
printf(" ... fclose('%s') failed.\n", outfile); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
741 |
else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
742 |
retval = 1; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
743 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
744 |
} // else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
745 |
MOJOSHADER_freeParseData(pd); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
746 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
747 |
return retval; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
748 |
} // assemble |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
749 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
750 |
static int ast(const char *fname, const char *buf, int len, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
751 |
const char *outfile, const MOJOSHADER_preprocessorDefine *defs, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
752 |
unsigned int defcount, FILE *io) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
753 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
754 |
// !!! FIXME: write me. |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
755 |
//const MOJOSHADER_parseData *pd; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
756 |
//int retval = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
757 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
758 |
MOJOSHADER_parseAst(MOJOSHADER_SRC_PROFILE_HLSL_PS_1_1, // !!! FIXME |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
759 |
fname, buf, len, defs, defcount, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
760 |
open_include, close_include, Malloc, Free, NULL); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
761 |
return 1; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
762 |
} // ast |
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
763 |
|
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
764 |
static int compile(const char *fname, const char *buf, int len, |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
765 |
const char *outfile, |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
766 |
const MOJOSHADER_preprocessorDefine *defs, |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
767 |
unsigned int defcount, FILE *io) |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
768 |
{ |
793
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
769 |
// !!! FIXME: write me. |
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
770 |
//const MOJOSHADER_parseData *pd; |
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
771 |
//int retval = 0; |
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
772 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
773 |
MOJOSHADER_compile(MOJOSHADER_SRC_PROFILE_HLSL_PS_1_1, // !!! FIXME |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
774 |
fname, buf, len, defs, defcount, |
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
775 |
open_include, close_include, |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
776 |
Malloc, Free, NULL); |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
777 |
return 1; |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
778 |
} // compile |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
779 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
780 |
typedef enum |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
781 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
782 |
ACTION_UNKNOWN, |
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
783 |
ACTION_VERSION, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
784 |
ACTION_PREPROCESS, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
785 |
ACTION_ASSEMBLE, |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
786 |
ACTION_AST, |
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
787 |
ACTION_COMPILE, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
788 |
} Action; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
789 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
790 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
791 |
int main(int argc, char **argv) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
792 |
{ |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
793 |
Action action = ACTION_UNKNOWN; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
794 |
int retval = 1; |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
795 |
const char *infile = NULL; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
796 |
const char *outfile = NULL; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
797 |
int i; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
798 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
799 |
MOJOSHADER_preprocessorDefine *defs = NULL; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
800 |
unsigned int defcount = 0; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
801 |
|
686
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
802 |
include_paths = (const char **) malloc(sizeof (char *)); |
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
803 |
include_paths[0] = "."; |
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
804 |
include_path_count = 1; |
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
805 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
806 |
// !!! FIXME: clean this up. |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
807 |
for (i = 1; i < argc; i++) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
808 |
{ |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
809 |
const char *arg = argv[i]; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
810 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
811 |
if (strcmp(arg, "-P") == 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
812 |
{ |
688
29ee34e66161
No reason you can't specify the same option twice.
Ryan C. Gordon <icculus@icculus.org>
parents:
686
diff
changeset
|
813 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_PREPROCESS)) |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
814 |
fail("Multiple actions specified"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
815 |
action = ACTION_PREPROCESS; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
816 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
817 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
818 |
else if (strcmp(arg, "-A") == 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
819 |
{ |
688
29ee34e66161
No reason you can't specify the same option twice.
Ryan C. Gordon <icculus@icculus.org>
parents:
686
diff
changeset
|
820 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_ASSEMBLE)) |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
821 |
fail("Multiple actions specified"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
822 |
action = ACTION_ASSEMBLE; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
823 |
} // else if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
824 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
825 |
else if (strcmp(arg, "-T") == 0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
826 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
827 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_AST)) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
828 |
fail("Multiple actions specified"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
829 |
action = ACTION_AST; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
830 |
} // else if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
831 |
|
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
832 |
else if (strcmp(arg, "-C") == 0) |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
833 |
{ |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
834 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_COMPILE)) |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
835 |
fail("Multiple actions specified"); |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
836 |
action = ACTION_COMPILE; |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
837 |
} // else if |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
838 |
|
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
839 |
else if ((strcmp(arg, "-V") == 0) || (strcmp(arg, "--version") == 0)) |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
840 |
{ |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
841 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_VERSION)) |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
842 |
fail("Multiple actions specified"); |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
843 |
action = ACTION_VERSION; |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
844 |
} // else if |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
845 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
846 |
else if (strcmp(arg, "-o") == 0) |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
847 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
848 |
if (outfile != NULL) |
668 | 849 |
fail("multiple output files specified"); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
850 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
851 |
arg = argv[++i]; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
852 |
if (arg == NULL) |
668 | 853 |
fail("no filename after '-o'"); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
854 |
outfile = arg; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
855 |
} // if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
856 |
|
667
8efc63f4ab9b
That should be an "else if", not an "if" ...
Ryan C. Gordon <icculus@icculus.org>
parents:
666
diff
changeset
|
857 |
else if (strcmp(arg, "-I") == 0) |
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
858 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
859 |
arg = argv[++i]; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
860 |
if (arg == NULL) |
668 | 861 |
fail("no path after '-I'"); |
862 |
||
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
863 |
include_paths = (const char **) realloc(include_paths, |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
864 |
(include_path_count+1) * sizeof (char *)); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
865 |
include_paths[include_path_count] = arg; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
866 |
include_path_count++; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
867 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
868 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
869 |
else if (strncmp(arg, "-D", 2) == 0) |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
870 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
871 |
arg += 2; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
872 |
char *ident = strdup(arg); |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
873 |
char *ptr = strchr(ident, '='); |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
874 |
const char *val = ""; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
875 |
if (ptr) |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
876 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
877 |
*ptr = '\0'; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
878 |
val = ptr+1; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
879 |
} // if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
880 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
881 |
defs = (MOJOSHADER_preprocessorDefine *) realloc(defs, |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
882 |
(defcount+1) * sizeof (MOJOSHADER_preprocessorDefine)); |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
883 |
defs[defcount].identifier = ident; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
884 |
defs[defcount].definition = val; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
885 |
defcount++; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
886 |
} // else if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
887 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
888 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
889 |
{ |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
890 |
if (infile != NULL) |
670 | 891 |
fail("multiple input files specified"); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
892 |
infile = arg; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
893 |
} // else |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
894 |
} // for |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
895 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
896 |
if (action == ACTION_UNKNOWN) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
897 |
action = ACTION_ASSEMBLE; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
898 |
|
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
899 |
if (action == ACTION_VERSION) |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
900 |
{ |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
901 |
printf("mojoshader-compiler, changeset %s\n", MOJOSHADER_CHANGESET); |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
902 |
return 0; |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
903 |
} // if |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
904 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
905 |
if (infile == NULL) |
670 | 906 |
fail("no input file specified"); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
907 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
908 |
FILE *io = fopen(infile, "rb"); |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
909 |
if (io == NULL) |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
910 |
fail("failed to open input file"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
911 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
912 |
fseek(io, 0, SEEK_END); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
913 |
long fsize = ftell(io); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
914 |
fseek(io, 0, SEEK_SET); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
915 |
if (fsize == -1) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
916 |
fsize = 1000000; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
917 |
char *buf = (char *) malloc(fsize); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
918 |
const int rc = fread(buf, 1, fsize, io); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
919 |
fclose(io); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
920 |
if (rc == EOF) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
921 |
fail("failed to read input file"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
922 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
923 |
FILE *outio = outfile ? fopen(outfile, "wb") : stdout; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
924 |
if (outio == NULL) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
925 |
fail("failed to open output file"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
926 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
927 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
928 |
if (action == ACTION_PREPROCESS) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
929 |
retval = (!preprocess(infile, buf, rc, outfile, defs, defcount, outio)); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
930 |
else if (action == ACTION_ASSEMBLE) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
931 |
retval = (!assemble(infile, buf, rc, outfile, defs, defcount, outio)); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
932 |
else if (action == ACTION_AST) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
933 |
retval = (!ast(infile, buf, rc, outfile, defs, defcount, outio)); |
706
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
934 |
else if (action == ACTION_COMPILE) |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
935 |
retval = (!compile(infile, buf, rc, outfile, defs, defcount, outio)); |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
936 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
937 |
if ((retval != 0) && (outfile != NULL)) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
938 |
remove(outfile); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
939 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
940 |
free(buf); |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
941 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
942 |
for (i = 0; i < defcount; i++) |
661
a502c4999238
Fixed logic bug: used wrong variable.
Ryan C. Gordon <icculus@icculus.org>
parents:
660
diff
changeset
|
943 |
free((void *) defs[i].identifier); |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
944 |
free(defs); |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
945 |
|
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
946 |
free(include_paths); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
947 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
948 |
return retval; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
949 |
} // main |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
950 |
|
666 | 951 |
// end of mojoshader-compiler.c ... |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
952 |