author | Ryan C. Gordon <icculus@icculus.org> |
Mon, 20 Jul 2020 20:06:34 -0400 | |
changeset 1295 | f592791e062e |
parent 1006 | 0f65599179f9 |
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 |
|
956
7888858a6777
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
938
diff
changeset
|
17 |
#ifdef _WIN32 |
7888858a6777
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
938
diff
changeset
|
18 |
#define snprintf _snprintf // !!! FIXME: not a safe replacement! |
931
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 |
||
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
57 |
static void print_unroll_attr(FILE *io, const int unroll) |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
58 |
{ |
992
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
59 |
// -1 means "unroll at compiler's discretion", |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
60 |
// -2 means user didn't specify the attribute. |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
61 |
switch (unroll) |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
62 |
{ |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
63 |
case 0: |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
64 |
fprintf(io, "[loop] "); |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
65 |
break; |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
66 |
case -1: |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
67 |
fprintf(io, "[unroll] "); |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
68 |
break; |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
69 |
case -2: |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
70 |
/* no-op. */ |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
71 |
break; |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
72 |
default: |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
73 |
assert(unroll > 0); |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
74 |
fprintf(io, "[unroll(%d)] ", unroll); |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
75 |
break; |
a951ce8bf2ec
Don't print loop attributes if user didn't explicitly specify one.
Ryan C. Gordon <icculus@icculus.org>
parents:
964
diff
changeset
|
76 |
} // case |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
77 |
} // print_unroll_attr |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
78 |
|
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
79 |
static void print_ast_datatype(FILE *io, const MOJOSHADER_astDataType *dt) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
80 |
{ |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
81 |
int i; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
82 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
83 |
if (dt == NULL) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
84 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
85 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
86 |
switch (dt->type) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
87 |
{ |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
88 |
case MOJOSHADER_AST_DATATYPE_BOOL: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
89 |
fprintf(io, "bool"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
90 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
91 |
case MOJOSHADER_AST_DATATYPE_INT: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
92 |
fprintf(io, "int"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
93 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
94 |
case MOJOSHADER_AST_DATATYPE_UINT: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
95 |
fprintf(io, "uint"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
96 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
97 |
case MOJOSHADER_AST_DATATYPE_FLOAT: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
98 |
fprintf(io, "float"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
99 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
100 |
case MOJOSHADER_AST_DATATYPE_FLOAT_SNORM: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
101 |
fprintf(io, "snorm float"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
102 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
103 |
case MOJOSHADER_AST_DATATYPE_FLOAT_UNORM: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
104 |
fprintf(io, "unorm float"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
105 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
106 |
case MOJOSHADER_AST_DATATYPE_HALF: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
107 |
fprintf(io, "half"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
108 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
109 |
case MOJOSHADER_AST_DATATYPE_DOUBLE: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
110 |
fprintf(io, "double"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
111 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
112 |
case MOJOSHADER_AST_DATATYPE_STRING: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
113 |
fprintf(io, "string"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
114 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
115 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_1D: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
116 |
fprintf(io, "sampler1D"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
117 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
118 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_2D: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
119 |
fprintf(io, "sampler2D"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
120 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
121 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_3D: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
122 |
fprintf(io, "sampler3D"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
123 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
124 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_CUBE: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
125 |
fprintf(io, "samplerCUBE"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
126 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
127 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_STATE: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
128 |
fprintf(io, "sampler_state"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
129 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
130 |
case MOJOSHADER_AST_DATATYPE_SAMPLER_COMPARISON_STATE: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
131 |
fprintf(io, "SamplerComparisonState"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
132 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
133 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
134 |
case MOJOSHADER_AST_DATATYPE_STRUCT: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
135 |
fprintf(io, "struct { "); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
136 |
for (i = 0; i < dt->structure.member_count; i++) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
137 |
{ |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
138 |
print_ast_datatype(io, dt->structure.members[i].datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
139 |
fprintf(io, " %s; ", dt->structure.members[i].identifier); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
140 |
} // for |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
141 |
fprintf(io, "}"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
142 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
143 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
144 |
case MOJOSHADER_AST_DATATYPE_ARRAY: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
145 |
print_ast_datatype(io, dt->array.base); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
146 |
if (dt->array.elements < 0) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
147 |
fprintf(io, "[]"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
148 |
else |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
149 |
fprintf(io, "[%d]", dt->array.elements); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
150 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
151 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
152 |
case MOJOSHADER_AST_DATATYPE_VECTOR: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
153 |
fprintf(io, "vector<"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
154 |
print_ast_datatype(io, dt->vector.base); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
155 |
fprintf(io, ",%d>", dt->vector.elements); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
156 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
157 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
158 |
case MOJOSHADER_AST_DATATYPE_MATRIX: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
159 |
fprintf(io, "matrix<"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
160 |
print_ast_datatype(io, dt->matrix.base); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
161 |
fprintf(io, ",%d,%d>", dt->matrix.rows, dt->matrix.columns); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
162 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
163 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
164 |
case MOJOSHADER_AST_DATATYPE_BUFFER: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
165 |
fprintf(io, "buffer<"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
166 |
print_ast_datatype(io, dt->buffer.base); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
167 |
fprintf(io, ">"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
168 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
169 |
|
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
170 |
case MOJOSHADER_AST_DATATYPE_USER: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
171 |
fprintf(io, "%s", dt->user.name); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
172 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
173 |
|
1001
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
174 |
// this should only appear if we did semantic analysis on the AST, |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
175 |
// so we only print the return value here. |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
176 |
case MOJOSHADER_AST_DATATYPE_FUNCTION: |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
177 |
if (!dt->function.retval) |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
178 |
fprintf(io, "void"); |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
179 |
else |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
180 |
print_ast_datatype(io, dt->function.retval); |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
181 |
return; |
61991d334619
Minor tweaks in case I expose semantic analysis phase to the public API later.
Ryan C. Gordon <icculus@icculus.org>
parents:
992
diff
changeset
|
182 |
|
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
183 |
//case MOJOSHADER_AST_DATATYPE_NONE: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
184 |
default: |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
185 |
assert(0 && "Unexpected datatype."); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
186 |
return; |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
187 |
} // switch |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
188 |
} // print_ast_datatype |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
189 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
190 |
// !!! FIXME: this screws up on order of operations. |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
191 |
static void print_ast(FILE *io, const int substmt, const void *_ast) |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
192 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
193 |
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
|
194 |
const char *nl = substmt ? "" : "\n"; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
195 |
int typeint = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
196 |
static int indent = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
197 |
int isblock = 0; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
198 |
int i; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
199 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
200 |
// 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
|
201 |
static const char *binary[] = |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
202 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
203 |
",", "*", "/", "%", "+", "-", "<<", ">>", "<", ">", "<=", ">=", "==", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
204 |
"!=", "&", "^", "|", "&&", "||", "=", "*=", "/=", "%=", "+=", "-=", |
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 |
}; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
207 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
208 |
static const char *pre_unary[] = { "++", "--", "-", "~", "!" }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
209 |
static const char *post_unary[] = { "++", "--" }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
210 |
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
|
211 |
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
|
212 |
static const char *fnstorage[] = { "", "inline " }; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
213 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
214 |
static const char *interpmod[] = { |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
215 |
"", " linear", " centroid", " nointerpolation", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
216 |
" noperspective", " sample" |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
217 |
}; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
218 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
219 |
if (!ast) return; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
220 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
221 |
typeint = (int) ast->ast.type; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
222 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
223 |
#define DO_INDENT do { \ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
224 |
if (!substmt) { for (i = 0; i < indent; i++) fprintf(io, " "); } \ |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
225 |
} while (0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
226 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
227 |
switch (ast->ast.type) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
228 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
229 |
case MOJOSHADER_AST_OP_PREINCREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
230 |
case MOJOSHADER_AST_OP_PREDECREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
231 |
case MOJOSHADER_AST_OP_NEGATE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
232 |
case MOJOSHADER_AST_OP_COMPLEMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
233 |
case MOJOSHADER_AST_OP_NOT: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
234 |
fprintf(io, "%s", pre_unary[(typeint-MOJOSHADER_AST_OP_START_RANGE_UNARY)-1]); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
235 |
print_ast(io, 0, ast->unary.operand); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
236 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
237 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
238 |
case MOJOSHADER_AST_OP_POSTINCREMENT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
239 |
case MOJOSHADER_AST_OP_POSTDECREMENT: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
240 |
print_ast(io, 0, ast->unary.operand); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
241 |
fprintf(io, "%s", post_unary[typeint-MOJOSHADER_AST_OP_POSTINCREMENT]); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
242 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
243 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
244 |
case MOJOSHADER_AST_OP_MULTIPLY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
245 |
case MOJOSHADER_AST_OP_DIVIDE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
246 |
case MOJOSHADER_AST_OP_MODULO: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
247 |
case MOJOSHADER_AST_OP_ADD: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
248 |
case MOJOSHADER_AST_OP_SUBTRACT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
249 |
case MOJOSHADER_AST_OP_LSHIFT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
250 |
case MOJOSHADER_AST_OP_RSHIFT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
251 |
case MOJOSHADER_AST_OP_LESSTHAN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
252 |
case MOJOSHADER_AST_OP_GREATERTHAN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
253 |
case MOJOSHADER_AST_OP_LESSTHANOREQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
254 |
case MOJOSHADER_AST_OP_GREATERTHANOREQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
255 |
case MOJOSHADER_AST_OP_EQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
256 |
case MOJOSHADER_AST_OP_NOTEQUAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
257 |
case MOJOSHADER_AST_OP_BINARYAND: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
258 |
case MOJOSHADER_AST_OP_BINARYXOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
259 |
case MOJOSHADER_AST_OP_BINARYOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
260 |
case MOJOSHADER_AST_OP_LOGICALAND: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
261 |
case MOJOSHADER_AST_OP_LOGICALOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
262 |
case MOJOSHADER_AST_OP_ASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
263 |
case MOJOSHADER_AST_OP_MULASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
264 |
case MOJOSHADER_AST_OP_DIVASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
265 |
case MOJOSHADER_AST_OP_MODASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
266 |
case MOJOSHADER_AST_OP_ADDASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
267 |
case MOJOSHADER_AST_OP_SUBASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
268 |
case MOJOSHADER_AST_OP_LSHIFTASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
269 |
case MOJOSHADER_AST_OP_RSHIFTASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
270 |
case MOJOSHADER_AST_OP_ANDASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
271 |
case MOJOSHADER_AST_OP_XORASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
272 |
case MOJOSHADER_AST_OP_ORASSIGN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
273 |
case MOJOSHADER_AST_OP_COMMA: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
274 |
print_ast(io, 0, ast->binary.left); |
938
fc5240c4f197
Fixed spacing for binary operators in print_ast().
Ryan C. Gordon <icculus@icculus.org>
parents:
934
diff
changeset
|
275 |
if (ast->ast.type != MOJOSHADER_AST_OP_COMMA) |
fc5240c4f197
Fixed spacing for binary operators in print_ast().
Ryan C. Gordon <icculus@icculus.org>
parents:
934
diff
changeset
|
276 |
fprintf(io, " "); // no space before the comma. |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
277 |
fprintf(io, "%s ", binary[ |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
278 |
(typeint - MOJOSHADER_AST_OP_START_RANGE_BINARY) - 1]); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
279 |
print_ast(io, 0, ast->binary.right); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
280 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
281 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
282 |
case MOJOSHADER_AST_OP_DEREF_ARRAY: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
283 |
print_ast(io, 0, ast->binary.left); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
284 |
fprintf(io, "["); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
285 |
print_ast(io, 0, ast->binary.right); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
286 |
fprintf(io, "]"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
287 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
288 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
289 |
case MOJOSHADER_AST_OP_DEREF_STRUCT: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
290 |
print_ast(io, 0, ast->derefstruct.identifier); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
291 |
fprintf(io, "."); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
292 |
fprintf(io, "%s", ast->derefstruct.member); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
293 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
294 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
295 |
case MOJOSHADER_AST_OP_CONDITIONAL: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
296 |
print_ast(io, 0, ast->ternary.left); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
297 |
fprintf(io, " ? "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
298 |
print_ast(io, 0, ast->ternary.center); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
299 |
fprintf(io, " : "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
300 |
print_ast(io, 0, ast->ternary.right); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
301 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
302 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
303 |
case MOJOSHADER_AST_OP_IDENTIFIER: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
304 |
fprintf(io, "%s", ast->identifier.identifier); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
305 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
306 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
307 |
case MOJOSHADER_AST_OP_INT_LITERAL: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
308 |
fprintf(io, "%d", ast->intliteral.value); |
931
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_OP_FLOAT_LITERAL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
312 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
313 |
const float f = ast->floatliteral.value; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
314 |
const long long flr = (long long) f; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
315 |
if (((float) flr) == f) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
316 |
fprintf(io, "%lld.0", flr); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
317 |
else |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
318 |
fprintf(io, "%.16g", f); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
319 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
320 |
} // case |
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_OP_STRING_LITERAL: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
323 |
fprintf(io, "\"%s\"", ast->stringliteral.string); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
324 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
325 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
326 |
case MOJOSHADER_AST_OP_BOOLEAN_LITERAL: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
327 |
fprintf(io, "%s", ast->boolliteral.value ? "true" : "false"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
328 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
329 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
330 |
case MOJOSHADER_AST_ARGUMENTS: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
331 |
print_ast(io, 0, ast->arguments.argument); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
332 |
if (ast->arguments.next != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
333 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
334 |
fprintf(io, ", "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
335 |
print_ast(io, 0, ast->arguments.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
336 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
337 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
338 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
339 |
case MOJOSHADER_AST_OP_CALLFUNC: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
340 |
print_ast(io, 0, ast->callfunc.identifier); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
341 |
fprintf(io, "("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
342 |
print_ast(io, 0, ast->callfunc.args); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
343 |
fprintf(io, ")"); |
931
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_OP_CONSTRUCTOR: |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
347 |
print_ast_datatype(io, ast->constructor.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
348 |
fprintf(io, "("); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
349 |
print_ast(io, 0, ast->constructor.args); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
350 |
fprintf(io, ")"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
351 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
352 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
353 |
case MOJOSHADER_AST_OP_CAST: |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
354 |
fprintf(io, "("); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
355 |
print_ast_datatype(io, ast->cast.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
356 |
fprintf(io, ") ("); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
357 |
print_ast(io, 0, ast->cast.operand); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
358 |
fprintf(io, ")"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
359 |
break; |
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 |
case MOJOSHADER_AST_STATEMENT_EXPRESSION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
362 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
363 |
print_ast(io, 0, ast->exprstmt.expr); // !!! FIXME: This is named badly... |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
364 |
fprintf(io, ";%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
365 |
print_ast(io, 0, ast->exprstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
366 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
367 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
368 |
case MOJOSHADER_AST_STATEMENT_IF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
369 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
370 |
fprintf(io, "if ("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
371 |
print_ast(io, 0, ast->ifstmt.expr); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
372 |
fprintf(io, ")\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
373 |
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
|
374 |
if (!isblock) indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
375 |
print_ast(io, 0, ast->ifstmt.statement); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
376 |
if (!isblock) indent--; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
377 |
print_ast(io, 0, ast->ifstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
378 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
379 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
380 |
case MOJOSHADER_AST_STATEMENT_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
381 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
382 |
print_ast(io, 1, ast->typedefstmt.type_info); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
383 |
fprintf(io, "%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
384 |
print_ast(io, 0, ast->typedefstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
385 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
386 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
387 |
case MOJOSHADER_AST_STATEMENT_SWITCH: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
388 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
389 |
switch ( ast->switchstmt.attributes ) |
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_SWITCHATTR_NONE: break; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
392 |
case MOJOSHADER_AST_SWITCHATTR_FLATTEN: fprintf(io, "[flatten] "); break; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
393 |
case MOJOSHADER_AST_SWITCHATTR_BRANCH: fprintf(io, "[branch] "); break; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
394 |
case MOJOSHADER_AST_SWITCHATTR_FORCECASE: fprintf(io, "[forcecase] "); break; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
395 |
case MOJOSHADER_AST_SWITCHATTR_CALL: fprintf(io, "[call] "); break; |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
396 |
} // switch |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
397 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
398 |
fprintf(io, "switch ("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
399 |
print_ast(io, 0, ast->switchstmt.expr); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
400 |
fprintf(io, ")\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
401 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
402 |
fprintf(io, "{\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
403 |
indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
404 |
print_ast(io, 0, ast->switchstmt.cases); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
405 |
indent--; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
406 |
fprintf(io, "\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
407 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
408 |
fprintf(io, "}\n"); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
409 |
print_ast(io, 0, ast->switchstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
410 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
411 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
412 |
case MOJOSHADER_AST_SWITCH_CASE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
413 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
414 |
fprintf(io, "case "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
415 |
print_ast(io, 0, ast->cases.expr); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
416 |
fprintf(io, ":\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
417 |
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
|
418 |
if (!isblock) indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
419 |
print_ast(io, 0, ast->cases.statement); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
420 |
if (!isblock) indent--; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
421 |
print_ast(io, 0, ast->cases.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
422 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
423 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
424 |
case MOJOSHADER_AST_STATEMENT_STRUCT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
425 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
426 |
print_ast(io, 0, ast->structstmt.struct_info); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
427 |
fprintf(io, ";%s%s", nl, nl); // always space these out. |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
428 |
print_ast(io, 0, ast->structstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
429 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
430 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
431 |
case MOJOSHADER_AST_STATEMENT_VARDECL: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
432 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
433 |
print_ast(io, 1, ast->vardeclstmt.declaration); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
434 |
fprintf(io, ";%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
435 |
print_ast(io, 0, ast->vardeclstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
436 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
437 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
438 |
case MOJOSHADER_AST_STATEMENT_BLOCK: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
439 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
440 |
fprintf(io, "{\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
441 |
indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
442 |
print_ast(io, 0, ast->blockstmt.statements); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
443 |
indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
444 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
445 |
fprintf(io, "}\n"); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
446 |
print_ast(io, 0, ast->blockstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
447 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
448 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
449 |
case MOJOSHADER_AST_STATEMENT_FOR: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
450 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
451 |
print_unroll_attr(io, ast->forstmt.unroll); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
452 |
fprintf(io, "for ("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
453 |
print_ast(io, 1, ast->forstmt.var_decl); |
1006
0f65599179f9
Fixed a misunderstanding about how the AST of a for-loop initializer works.
Ryan C. Gordon <icculus@icculus.org>
parents:
1001
diff
changeset
|
454 |
print_ast(io, 1, ast->forstmt.initializer); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
455 |
fprintf(io, "; "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
456 |
print_ast(io, 1, ast->forstmt.looptest); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
457 |
fprintf(io, "; "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
458 |
print_ast(io, 1, ast->forstmt.counter); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
459 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
460 |
fprintf(io, ")\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
461 |
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
|
462 |
if (!isblock) indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
463 |
print_ast(io, 0, ast->forstmt.statement); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
464 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
465 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
466 |
print_ast(io, 0, ast->forstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
467 |
break; |
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 |
case MOJOSHADER_AST_STATEMENT_DO: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
470 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
471 |
print_unroll_attr(io, ast->dostmt.unroll); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
472 |
fprintf(io, "do\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
473 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
474 |
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
|
475 |
if (!isblock) indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
476 |
print_ast(io, 0, ast->dostmt.statement); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
477 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
478 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
479 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
480 |
fprintf(io, "while ("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
481 |
print_ast(io, 0, ast->dostmt.expr); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
482 |
fprintf(io, ");\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
483 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
484 |
print_ast(io, 0, ast->dostmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
485 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
486 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
487 |
case MOJOSHADER_AST_STATEMENT_WHILE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
488 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
489 |
print_unroll_attr(io, ast->whilestmt.unroll); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
490 |
fprintf(io, "while ("); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
491 |
print_ast(io, 0, ast->whilestmt.expr); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
492 |
fprintf(io, ")\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
493 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
494 |
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
|
495 |
if (!isblock) indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
496 |
print_ast(io, 0, ast->whilestmt.statement); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
497 |
if (!isblock) indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
498 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
499 |
print_ast(io, 0, ast->whilestmt.next); |
931
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_STATEMENT_RETURN: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
503 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
504 |
fprintf(io, "return"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
505 |
if (ast->returnstmt.expr) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
506 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
507 |
fprintf(io, " "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
508 |
print_ast(io, 0, ast->returnstmt.expr); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
509 |
} // if |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
510 |
fprintf(io, ";%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
511 |
print_ast(io, 0, ast->returnstmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
512 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
513 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
514 |
case MOJOSHADER_AST_STATEMENT_EMPTY: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
515 |
case MOJOSHADER_AST_STATEMENT_BREAK: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
516 |
case MOJOSHADER_AST_STATEMENT_CONTINUE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
517 |
case MOJOSHADER_AST_STATEMENT_DISCARD: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
518 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
519 |
fprintf(io, "%s;%s", |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
520 |
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
|
521 |
nl); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
522 |
print_ast(io, 0, ast->stmt.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
523 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
524 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
525 |
case MOJOSHADER_AST_COMPUNIT_FUNCTION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
526 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
527 |
print_ast(io, 0, ast->funcunit.declaration); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
528 |
if (ast->funcunit.definition == NULL) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
529 |
fprintf(io, ";%s", nl); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
530 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
531 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
532 |
fprintf(io, "%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
533 |
print_ast(io, 0, ast->funcunit.definition); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
534 |
fprintf(io, "%s", nl); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
535 |
} // else |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
536 |
print_ast(io, 0, ast->funcunit.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
537 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
538 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
539 |
case MOJOSHADER_AST_COMPUNIT_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
540 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
541 |
print_ast(io, 0, ast->typedefunit.type_info); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
542 |
fprintf(io, "%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
543 |
print_ast(io, 0, ast->typedefunit.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
544 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
545 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
546 |
case MOJOSHADER_AST_COMPUNIT_STRUCT: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
547 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
548 |
print_ast(io, 0, ast->structunit.struct_info); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
549 |
fprintf(io, ";%s%s", nl, nl); // always space these out. |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
550 |
print_ast(io, 0, ast->structunit.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
551 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
552 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
553 |
case MOJOSHADER_AST_COMPUNIT_VARIABLE: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
554 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
555 |
print_ast(io, 1, ast->varunit.declaration); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
556 |
fprintf(io, ";%s", nl); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
557 |
if (ast->varunit.next && |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
558 |
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
|
559 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
560 |
fprintf(io, "%s", nl); // group vars together, and space out other things. |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
561 |
} // if |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
562 |
print_ast(io, 0, ast->varunit.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
563 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
564 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
565 |
case MOJOSHADER_AST_SCALAR_OR_ARRAY: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
566 |
fprintf(io, "%s", ast->soa.identifier); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
567 |
if (ast->soa.isarray) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
568 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
569 |
fprintf(io, "["); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
570 |
print_ast(io, 0, ast->soa.dimension); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
571 |
fprintf(io, "]"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
572 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
573 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
574 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
575 |
case MOJOSHADER_AST_TYPEDEF: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
576 |
DO_INDENT; |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
577 |
fprintf(io, "typedef %s", ast->typdef.isconst ? "const " : ""); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
578 |
print_ast_datatype(io, ast->typdef.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
579 |
fprintf(io, " "); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
580 |
print_ast(io, 0, ast->typdef.details); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
581 |
fprintf(io, ";%s", nl); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
582 |
break; |
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 |
case MOJOSHADER_AST_FUNCTION_PARAMS: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
585 |
fprintf(io, "%s", inpmod[(int) ast->params.input_modifier]); |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
586 |
print_ast_datatype(io, ast->params.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
587 |
fprintf(io, " %s", ast->params.identifier); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
588 |
if (ast->params.semantic) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
589 |
fprintf(io, " : %s", ast->params.semantic); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
590 |
fprintf(io, "%s", interpmod[(int) ast->params.interpolation_modifier]); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
591 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
592 |
if (ast->params.initializer) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
593 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
594 |
fprintf(io, " = "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
595 |
print_ast(io, 0, ast->params.initializer); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
596 |
} // if |
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 |
if (ast->params.next) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
599 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
600 |
fprintf(io, ", "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
601 |
print_ast(io, 0, ast->params.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
602 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
603 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
604 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
605 |
case MOJOSHADER_AST_FUNCTION_SIGNATURE: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
606 |
fprintf(io, "%s", fnstorage[(int) ast->funcsig.storage_class]); |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
607 |
if (ast->funcsig.datatype) |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
608 |
print_ast_datatype(io, ast->funcsig.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
609 |
else |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
610 |
fprintf(io, "void"); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
611 |
fprintf(io, " %s(", ast->funcsig.identifier); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
612 |
print_ast(io, 0, ast->funcsig.params); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
613 |
fprintf(io, ")"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
614 |
if (ast->funcsig.semantic) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
615 |
fprintf(io, " : %s", ast->funcsig.semantic); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
616 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
617 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
618 |
case MOJOSHADER_AST_STRUCT_DECLARATION: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
619 |
fprintf(io, "struct %s\n", ast->structdecl.name); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
620 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
621 |
fprintf(io, "{\n"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
622 |
indent++; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
623 |
print_ast(io, 0, ast->structdecl.members); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
624 |
indent--; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
625 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
626 |
fprintf(io, "}"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
627 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
628 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
629 |
case MOJOSHADER_AST_STRUCT_MEMBER: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
630 |
DO_INDENT; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
631 |
fprintf(io, "%s", interpmod[(int)ast->structmembers.interpolation_mod]); |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
632 |
print_ast_datatype(io, ast->structmembers.datatype); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
633 |
fprintf(io, " "); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
634 |
print_ast(io, 0, ast->structmembers.details); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
635 |
if (ast->structmembers.semantic) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
636 |
fprintf(io, " : %s", ast->structmembers.semantic); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
637 |
fprintf(io, ";%s", nl); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
638 |
print_ast(io, 0, ast->structmembers.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
639 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
640 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
641 |
case MOJOSHADER_AST_VARIABLE_DECLARATION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
642 |
DO_INDENT; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
643 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_EXTERN) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
644 |
fprintf(io, "extern "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
645 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_NOINTERPOLATION) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
646 |
fprintf(io, "nointerpolation "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
647 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_SHARED) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
648 |
fprintf(io, "shared"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
649 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_STATIC) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
650 |
fprintf(io, "static "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
651 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_UNIFORM) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
652 |
fprintf(io, "uniform "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
653 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_VOLATILE) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
654 |
fprintf(io, "nointerpolation "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
655 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_CONST) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
656 |
fprintf(io, "const "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
657 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_ROWMAJOR) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
658 |
fprintf(io, "rowmajor "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
659 |
if (ast->vardecl.attributes & MOJOSHADER_AST_VARATTR_COLUMNMAJOR) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
660 |
fprintf(io, "columnmajor "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
661 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
662 |
if (ast->vardecl.datatype) |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
663 |
print_ast_datatype(io, ast->vardecl.datatype); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
664 |
else |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
665 |
print_ast(io, 0, ast->vardecl.anonymous_datatype); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
666 |
fprintf(io, " "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
667 |
print_ast(io, 0, ast->vardecl.details); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
668 |
if (ast->vardecl.semantic) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
669 |
fprintf(io, " : %s", ast->vardecl.semantic); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
670 |
if (ast->vardecl.annotations) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
671 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
672 |
fprintf(io, " "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
673 |
print_ast(io, 0, ast->vardecl.annotations); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
674 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
675 |
if (ast->vardecl.initializer != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
676 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
677 |
fprintf(io, " = "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
678 |
print_ast(io, 0, ast->vardecl.initializer); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
679 |
} // if |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
680 |
print_ast(io, 0, ast->vardecl.lowlevel); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
681 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
682 |
if (ast->vardecl.next == NULL) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
683 |
fprintf(io, "%s", nl); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
684 |
else |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
685 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
686 |
const int attr = ast->vardecl.next->attributes; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
687 |
fprintf(io, ", "); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
688 |
ast->vardecl.next->attributes = 0; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
689 |
print_ast(io, 1, ast->vardecl.next); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
690 |
ast->vardecl.next->attributes = attr; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
691 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
692 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
693 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
694 |
case MOJOSHADER_AST_PACK_OFFSET: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
695 |
fprintf(io, " : packoffset(%s%s%s)", ast->packoffset.ident1, |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
696 |
ast->packoffset.ident2 ? "." : "", |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
697 |
ast->packoffset.ident2 ? ast->packoffset.ident2 : ""); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
698 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
699 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
700 |
case MOJOSHADER_AST_VARIABLE_LOWLEVEL: |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
701 |
print_ast(io, 0, ast->varlowlevel.packoffset); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
702 |
if (ast->varlowlevel.register_name) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
703 |
fprintf(io, " : register(%s)", ast->varlowlevel.register_name); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
704 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
705 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
706 |
case MOJOSHADER_AST_ANNOTATION: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
707 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
708 |
const MOJOSHADER_astAnnotations *a = &ast->annotations; |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
709 |
fprintf(io, "<"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
710 |
while (a) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
711 |
{ |
964
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
712 |
fprintf(io, " "); |
e8c09c28162e
Reworked datatype processing in the compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
956
diff
changeset
|
713 |
print_ast_datatype(io, a->datatype); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
714 |
if (a->initializer != NULL) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
715 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
716 |
fprintf(io, " = "); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
717 |
print_ast(io, 0, a->initializer); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
718 |
} // if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
719 |
if (a->next) |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
720 |
fprintf(io, ","); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
721 |
a = a->next; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
722 |
} // while |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
723 |
fprintf(io, " >"); |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
724 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
725 |
} // case |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
726 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
727 |
default: |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
728 |
assert(0 && "unexpected type"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
729 |
break; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
730 |
} // switch |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
731 |
|
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
732 |
#undef DO_INDENT |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
733 |
} // print_ast |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
734 |
|
668 | 735 |
|
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
736 |
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
|
737 |
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
|
738 |
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
|
739 |
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
|
740 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
741 |
int i; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
742 |
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
|
743 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
744 |
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
|
745 |
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
|
746 |
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
|
747 |
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
|
748 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
749 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
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
|
754 |
continue; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
755 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
756 |
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
|
757 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
758 |
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
|
759 |
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
|
760 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
761 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
762 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
763 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
764 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
765 |
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
|
766 |
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
|
767 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
768 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
769 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
770 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
771 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
772 |
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
|
773 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
774 |
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
|
775 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
776 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
777 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
778 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
779 |
fclose(io); |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
780 |
*outdata = data; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
781 |
*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
|
782 |
return 1; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
783 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
784 |
} // for |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
785 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
786 |
return 0; |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
787 |
} // open_include |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
788 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
789 |
|
663 | 790 |
static void close_include(const char *data, MOJOSHADER_malloc m, |
791 |
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
|
792 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
793 |
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
|
794 |
} // close_include |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
795 |
|
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
796 |
|
578
6c8f73c845e7
Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
577
diff
changeset
|
797 |
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
|
798 |
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
|
799 |
const MOJOSHADER_preprocessorDefine *defs, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
800 |
unsigned int defcount, FILE *io) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
801 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
802 |
const MOJOSHADER_preprocessData *pd; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
803 |
int retval = 0; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
804 |
|
665
521d24646891
Added allocator debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
664
diff
changeset
|
805 |
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
|
806 |
close_include, Malloc, Free, NULL); |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
807 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
808 |
if (pd->error_count > 0) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
809 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
810 |
int i; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
811 |
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
|
812 |
{ |
885
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
793
diff
changeset
|
813 |
fprintf(stderr, "%s:%d: ERROR: %s\n", |
577
bec531dd448e
Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
556
diff
changeset
|
814 |
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
|
815 |
pd->errors[i].error_position, |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
816 |
pd->errors[i].error); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
817 |
} // for |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
818 |
} // if |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
819 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
820 |
{ |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
821 |
if (pd->output != NULL) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
822 |
{ |
747
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
823 |
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
|
824 |
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
|
825 |
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
|
826 |
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
|
827 |
printf(" ... fclose('%s') failed.\n", outfile); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
828 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
829 |
retval = 1; |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
830 |
} // if |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
831 |
} // else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
832 |
MOJOSHADER_freePreprocessData(pd); |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
833 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
834 |
return retval; |
556
04282775cc2c
Fixed cut-and-pasted comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
555
diff
changeset
|
835 |
} // preprocess |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
836 |
|
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
837 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
838 |
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
|
839 |
const char *outfile, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
840 |
const MOJOSHADER_preprocessorDefine *defs, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
841 |
unsigned int defcount, FILE *io) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
842 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
843 |
const MOJOSHADER_parseData *pd; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
844 |
int retval = 0; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
845 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
846 |
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
|
847 |
defs, defcount, open_include, close_include, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
848 |
Malloc, Free, NULL); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
849 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
850 |
if (pd->error_count > 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
851 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
852 |
int i; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
853 |
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
|
854 |
{ |
885
29b6d4c4a7a2
Implemented error output unit test harness.
Ryan C. Gordon <icculus@icculus.org>
parents:
793
diff
changeset
|
855 |
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
|
856 |
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
|
857 |
pd->errors[i].error_position, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
858 |
pd->errors[i].error); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
859 |
} // for |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
860 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
861 |
else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
862 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
863 |
if (pd->output != NULL) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
864 |
{ |
747
0d1dbadcb387
Don't report false error when writing a zero-byte file.
Ryan C. Gordon <icculus@icculus.org>
parents:
706
diff
changeset
|
865 |
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
|
866 |
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
|
867 |
printf(" ... fwrite('%s') failed.\n", outfile); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
868 |
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
|
869 |
printf(" ... fclose('%s') failed.\n", outfile); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
870 |
else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
871 |
retval = 1; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
872 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
873 |
} // else |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
874 |
MOJOSHADER_freeParseData(pd); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
875 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
876 |
return retval; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
877 |
} // assemble |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
878 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
879 |
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
|
880 |
const char *outfile, const MOJOSHADER_preprocessorDefine *defs, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
881 |
unsigned int defcount, FILE *io) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
882 |
{ |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
883 |
const MOJOSHADER_astData *ad; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
884 |
int retval = 0; |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
885 |
|
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
886 |
ad = MOJOSHADER_parseAst(MOJOSHADER_SRC_PROFILE_HLSL_PS_1_1, // !!! FIXME |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
887 |
fname, buf, len, defs, defcount, |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
888 |
open_include, close_include, Malloc, Free, NULL); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
889 |
|
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
890 |
if (ad->error_count > 0) |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
891 |
{ |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
892 |
int i; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
893 |
for (i = 0; i < ad->error_count; i++) |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
894 |
{ |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
895 |
fprintf(stderr, "%s:%d: ERROR: %s\n", |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
896 |
ad->errors[i].filename ? ad->errors[i].filename : "???", |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
897 |
ad->errors[i].error_position, |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
898 |
ad->errors[i].error); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
899 |
} // for |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
900 |
} // if |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
901 |
else |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
902 |
{ |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
903 |
print_ast(io, 0, ad->ast); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
904 |
if ((outfile != NULL) && (fclose(io) == EOF)) |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
905 |
printf(" ... fclose('%s') failed.\n", outfile); |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
906 |
else |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
907 |
retval = 1; |
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
908 |
} // else |
934
f6ecea50c607
Whoops, forgot to free return value when finished with it.
Ryan C. Gordon <icculus@icculus.org>
parents:
933
diff
changeset
|
909 |
MOJOSHADER_freeAstData(ad); |
933
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
910 |
|
f2367f48f3e2
Finished cleaning up AST tools and moving them into application level.
Ryan C. Gordon <icculus@icculus.org>
parents:
931
diff
changeset
|
911 |
return retval; |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
912 |
} // 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
|
913 |
|
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
914 |
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
|
915 |
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
|
916 |
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
|
917 |
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
|
918 |
{ |
793
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
919 |
// !!! FIXME: write me. |
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
920 |
//const MOJOSHADER_parseData *pd; |
616980fb00bb
Fixed a compiler warning, for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
747
diff
changeset
|
921 |
//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
|
922 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
923 |
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
|
924 |
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
|
925 |
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
|
926 |
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
|
927 |
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
|
928 |
} // compile |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
929 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
930 |
typedef enum |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
931 |
{ |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
932 |
ACTION_UNKNOWN, |
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
933 |
ACTION_VERSION, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
934 |
ACTION_PREPROCESS, |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
935 |
ACTION_ASSEMBLE, |
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
936 |
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
|
937 |
ACTION_COMPILE, |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
938 |
} Action; |
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 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
941 |
int main(int argc, char **argv) |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
942 |
{ |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
943 |
Action action = ACTION_UNKNOWN; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
944 |
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
|
945 |
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
|
946 |
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
|
947 |
int i; |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
948 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
949 |
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
|
950 |
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
|
951 |
|
686
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
952 |
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
|
953 |
include_paths[0] = "."; |
021241f2a237
Current working directory should always be in the include path.
Ryan C. Gordon <icculus@icculus.org>
parents:
673
diff
changeset
|
954 |
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
|
955 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
956 |
// !!! 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
|
957 |
for (i = 1; i < argc; i++) |
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
958 |
{ |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
959 |
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
|
960 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
961 |
if (strcmp(arg, "-P") == 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
962 |
{ |
688
29ee34e66161
No reason you can't specify the same option twice.
Ryan C. Gordon <icculus@icculus.org>
parents:
686
diff
changeset
|
963 |
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
|
964 |
fail("Multiple actions specified"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
965 |
action = ACTION_PREPROCESS; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
966 |
} // if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
967 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
968 |
else if (strcmp(arg, "-A") == 0) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
969 |
{ |
688
29ee34e66161
No reason you can't specify the same option twice.
Ryan C. Gordon <icculus@icculus.org>
parents:
686
diff
changeset
|
970 |
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
|
971 |
fail("Multiple actions specified"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
972 |
action = ACTION_ASSEMBLE; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
973 |
} // else if |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
974 |
|
931
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
975 |
else if (strcmp(arg, "-T") == 0) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
976 |
{ |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
977 |
if ((action != ACTION_UNKNOWN) && (action != ACTION_AST)) |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
978 |
fail("Multiple actions specified"); |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
979 |
action = ACTION_AST; |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
980 |
} // else if |
4aa1f68d8292
Heavy rework of the AST code.
Ryan C. Gordon <icculus@icculus.org>
parents:
892
diff
changeset
|
981 |
|
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
|
982 |
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
|
983 |
{ |
01a92f30b84f
Added some basic compiler stub stuff, just to get this building at all.
Ryan C. Gordon <icculus@icculus.org>
parents:
688
diff
changeset
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
} // 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
|
988 |
|
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
989 |
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
|
990 |
{ |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
991 |
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
|
992 |
fail("Multiple actions specified"); |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
993 |
action = ACTION_VERSION; |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
994 |
} // else if |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
995 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
996 |
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
|
997 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
998 |
if (outfile != NULL) |
668 | 999 |
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
|
1000 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1001 |
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
|
1002 |
if (arg == NULL) |
668 | 1003 |
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
|
1004 |
outfile = arg; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1005 |
} // if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1006 |
|
667
8efc63f4ab9b
That should be an "else if", not an "if" ...
Ryan C. Gordon <icculus@icculus.org>
parents:
666
diff
changeset
|
1007 |
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
|
1008 |
{ |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
1009 |
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
|
1010 |
if (arg == NULL) |
668 | 1011 |
fail("no path after '-I'"); |
1012 |
||
660
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
1013 |
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
|
1014 |
(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
|
1015 |
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
|
1016 |
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
|
1017 |
} // if |
d82a22c8ab3d
Allow preprocess.c to specify include paths on the command line.
Ryan C. Gordon <icculus@icculus.org>
parents:
659
diff
changeset
|
1018 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1019 |
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
|
1020 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1021 |
arg += 2; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1022 |
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
|
1023 |
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
|
1024 |
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
|
1025 |
if (ptr) |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1026 |
{ |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1027 |
*ptr = '\0'; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1028 |
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
|
1029 |
} // if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1030 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1031 |
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
|
1032 |
(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
|
1033 |
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
|
1034 |
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
|
1035 |
defcount++; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1036 |
} // else if |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1037 |
|
555
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1038 |
else |
940821555fda
Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1039 |
{ |
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1040 |
if (infile != NULL) |
670 | 1041 |
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
|
1042 |
infile = arg; |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1043 |
} // else |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1044 |
} // for |
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1045 |
|
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1046 |
if (action == ACTION_UNKNOWN) |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1047 |
action = ACTION_ASSEMBLE; |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1048 |
|
892
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
1049 |
if (action == ACTION_VERSION) |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
1050 |
{ |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
1051 |
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
|
1052 |
return 0; |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
1053 |
} // if |
c45dec9f8906
Added a --version command line to mojoshader-compiler.
Ryan C. Gordon <icculus@icculus.org>
parents:
885
diff
changeset
|
1054 |
|
659
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1055 |
if (infile == NULL) |
670 | 1056 |
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
|
1057 |
|
e77acde263cc
Added command line stuff to preprocess.c, including predefined macro support.
Ryan C. Gordon <icculus@icculus.org>
parents:
588
diff
changeset
|
1058 |
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
|
1059 |
if (io == NULL) |
669
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1060 |
fail("failed to open input file"); |
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1061 |
|
fd14a7278a95
Merged assemble.c into mojoshader-compiler.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
668
diff
changeset
|
1062 |
fseek(io, 0, SEEK_END); |