author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 14 Feb 2009 01:33:18 -0500 | |
changeset 616 | 9f087be64555 |
parent 612 | 72ccfe69eaf1 |
child 658 | 22695d3d6b98 |
permissions | -rw-r--r-- |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/** |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* MojoShader; generate shader programs from bytecode of compiled |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* Direct3D shaders. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* Please see the file LICENSE.txt in the source's root directory. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* This file written by Ryan C. Gordon. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
*/ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
#define __MOJOSHADER_INTERNAL__ 1 |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include "mojoshader_internal.h" |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
|
587
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
13 |
#if DEBUG_ASSEMBLY_PARSER |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
14 |
#define print_debug_token(token, len, val) \ |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
15 |
MOJOSHADER_print_debug_token("ASSEMBLER", token, len, val) |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
16 |
#else |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
17 |
#define print_debug_token(token, len, val) |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
18 |
#endif |
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
19 |
|
566
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset
|
20 |
|
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
21 |
typedef struct SourcePos |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
22 |
{ |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
23 |
const char *filename; |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
24 |
uint32 line; |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
25 |
} SourcePos; |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
26 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
// Context...this is state that changes as we assemble a shader... |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
29 |
typedef struct Context |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
31 |
int isfail; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
32 |
int out_of_memory; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
MOJOSHADER_malloc malloc; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
MOJOSHADER_free free; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
void *malloc_data; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
36 |
int error_count; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
37 |
ErrorList *errors; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
38 |
Preprocessor *preprocessor; |
523
699696afd731
Allow errors to specify post-processing problems.
Ryan C. Gordon <icculus@icculus.org>
parents:
522
diff
changeset
|
39 |
MOJOSHADER_parsePhase parse_phase; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
MOJOSHADER_shaderType shader_type; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
uint8 major_ver; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
uint8 minor_ver; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
43 |
int pushedback; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
44 |
const char *token; // assembler token! |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
45 |
unsigned int tokenlen; // assembler token! |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
46 |
Token tokenval; // assembler token! |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
47 |
uint32 version_token; // bytecode token! |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
48 |
uint32 tokenbuf[16]; // bytecode tokens! |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
49 |
int tokenbufpos; // bytecode tokens! |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
DestArgInfo dest_arg; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
51 |
uint32 *output; |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
52 |
SourcePos *token_to_source; |
524
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset
|
53 |
uint8 *ctab; |
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset
|
54 |
uint32 ctab_len; |
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset
|
55 |
uint32 ctab_allocation; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
56 |
size_t output_len; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
57 |
size_t output_allocation; |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
58 |
} Context; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
// Convenience functions for allocators... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
63 |
static inline void out_of_memory(Context *ctx) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
65 |
ctx->isfail = ctx->out_of_memory = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
} // out_of_memory |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
static inline void *Malloc(Context *ctx, const size_t len) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
void *retval = ctx->malloc((int) len, ctx->malloc_data); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
if (retval == NULL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
out_of_memory(ctx); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
return retval; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
} // Malloc |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
76 |
static inline char *StrDup(Context *ctx, const char *str) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
77 |
{ |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
78 |
char *retval = (char *) Malloc(ctx, strlen(str) + 1); |
554 | 79 |
if (retval != NULL) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
80 |
strcpy(retval, str); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
81 |
return retval; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
82 |
} // StrDup |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
83 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
static inline void Free(Context *ctx, void *ptr) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
if (ptr != NULL) // check for NULL in case of dumb free() impl. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
ctx->free(ptr, ctx->malloc_data); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
} // Free |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
90 |
static void failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
91 |
static void failf(Context *ctx, const char *fmt, ...) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
93 |
const char *fname = NULL; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
94 |
unsigned int linenum = 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
95 |
int error_position = 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
96 |
|
550
2f977a75d2b5
Fixed error reporting in assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
549
diff
changeset
|
97 |
ctx->isfail = 1; |
2f977a75d2b5
Fixed error reporting in assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
549
diff
changeset
|
98 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
99 |
switch (ctx->parse_phase) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
101 |
case MOJOSHADER_PARSEPHASE_NOTSTARTED: |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
102 |
error_position = -2; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
103 |
break; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
104 |
case MOJOSHADER_PARSEPHASE_WORKING: |
567
1a61d0cf86ba
Fixed assembler error line numbers.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
105 |
fname = preprocessor_sourcepos(ctx->preprocessor, &linenum); |
1a61d0cf86ba
Fixed assembler error line numbers.
Ryan C. Gordon <icculus@icculus.org>
parents:
566
diff
changeset
|
106 |
error_position = (int) linenum; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
107 |
break; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
108 |
case MOJOSHADER_PARSEPHASE_DONE: |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
109 |
error_position = -1; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
110 |
break; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
111 |
default: |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
112 |
assert(0 && "Unexpected value"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
113 |
return; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
114 |
} // switch |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
115 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
116 |
ErrorList *error = (ErrorList *) Malloc(ctx, sizeof (ErrorList)); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
117 |
if (error == NULL) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
118 |
return; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
119 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
120 |
char scratch = 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
121 |
va_list ap; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
122 |
va_start(ap, fmt); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
123 |
const int len = vsnprintf(&scratch, sizeof (scratch), fmt, ap); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
124 |
va_end(ap); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
125 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
126 |
char *failstr = (char *) Malloc(ctx, len + 1); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
127 |
if (failstr == NULL) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
128 |
Free(ctx, error); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
129 |
else |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
130 |
{ |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
131 |
va_start(ap, fmt); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
132 |
vsnprintf(failstr, len + 1, fmt, ap); // rebuild it. |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
133 |
va_end(ap); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
135 |
error->error.error = failstr; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
136 |
error->error.filename = fname ? StrDup(ctx, fname) : NULL; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
137 |
error->error.error_position = error_position; |
544
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
138 |
error->next = NULL; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
139 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
140 |
ErrorList *prev = NULL; |
544
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
141 |
ErrorList *item = ctx->errors; |
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
142 |
while (item != NULL) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
143 |
{ |
544
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
144 |
prev = item; |
558
314c86ff14dd
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
554
diff
changeset
|
145 |
item = item->next; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
146 |
} // while |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 |
|
544
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
148 |
if (prev == NULL) |
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
149 |
ctx->errors = error; |
f829f48e5214
Fixed stupid linked list bug.
Ryan C. Gordon <icculus@icculus.org>
parents:
543
diff
changeset
|
150 |
else |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
151 |
prev->next = error; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
152 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
153 |
ctx->error_count++; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
154 |
} // else |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 |
} // failf |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
157 |
static inline void fail(Context *ctx, const char *reason) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
159 |
failf(ctx, "%s", reason); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 |
} // fail |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 |
static inline int isfail(const Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
164 |
return ctx->isfail; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 |
} // isfail |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 |
// Shader model version magic... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
static inline uint32 ver_ui32(const uint8 major, const uint8 minor) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
return ( (((uint32) major) << 16) | (((minor) == 0xFF) ? 0 : (minor)) ); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
} // version_ui32 |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 |
static inline int shader_version_atleast(const Context *ctx, const uint8 maj, |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
const uint8 min) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
return (ver_ui32(ctx->major_ver, ctx->minor_ver) >= ver_ui32(maj, min)); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
} // shader_version_atleast |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 |
static inline int shader_is_pixel(const Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 |
return (ctx->shader_type == MOJOSHADER_TYPE_PIXEL); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
} // shader_is_pixel |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 |
static inline int shader_is_vertex(const Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 |
return (ctx->shader_type == MOJOSHADER_TYPE_VERTEX); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
} // shader_is_vertex |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
191 |
static inline void pushback(Context *ctx) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
192 |
{ |
566
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset
|
193 |
#if DEBUG_ASSEMBLY_PARSER |
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset
|
194 |
printf("ASSEMBLER PUSHBACK\n"); |
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset
|
195 |
#endif |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
196 |
assert(!ctx->pushedback); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
197 |
ctx->pushedback = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
198 |
} // pushback |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
200 |
static Token _nexttoken(Context *ctx) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
201 |
{ |
598
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
202 |
while (1) |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
203 |
{ |
598
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
204 |
ctx->token = preprocessor_nexttoken(ctx->preprocessor, &ctx->tokenlen, |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
205 |
&ctx->tokenval); |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
206 |
|
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
207 |
if (preprocessor_outofmemory(ctx->preprocessor)) |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
208 |
{ |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
209 |
out_of_memory(ctx); |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
210 |
ctx->tokenval = TOKEN_EOI; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
211 |
ctx->token = NULL; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
212 |
ctx->tokenlen = 0; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
213 |
break; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
214 |
} // if |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
215 |
|
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
216 |
if (ctx->tokenval == TOKEN_PREPROCESSING_ERROR) |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
217 |
{ |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
218 |
fail(ctx, ctx->token); |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
219 |
continue; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
220 |
} // else |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
221 |
|
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
222 |
break; |
decc32dc03a7
Removed preprocessor_error(). Returns a Token to specify an error state now.
Ryan C. Gordon <icculus@icculus.org>
parents:
587
diff
changeset
|
223 |
} // while |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
224 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
225 |
return ctx->tokenval; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
226 |
} // _nexttoken |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
227 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
228 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
229 |
static Token nexttoken(Context *ctx) |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
230 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
231 |
if (ctx->pushedback) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
232 |
{ |
587
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
233 |
print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
234 |
ctx->pushedback = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
235 |
return ctx->tokenval; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
236 |
} // if |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
237 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
238 |
Token token = _nexttoken(ctx); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
239 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
240 |
while (token == ((Token) '\n')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
241 |
token = _nexttoken(ctx); // skip endlines. |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
242 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
243 |
if (token == ((Token) ';')) // single line comment in assembler. |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
244 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
245 |
do |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
246 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
247 |
token = _nexttoken(ctx); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
248 |
} while ((token != ((Token) '\n')) && (token != TOKEN_EOI)); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
249 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
250 |
while (token == ((Token) '\n')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
251 |
token = _nexttoken(ctx); // skip endlines. |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
252 |
} // if |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
253 |
|
587
202354e004fc
Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset
|
254 |
print_debug_token(ctx->token, ctx->tokenlen, ctx->tokenval); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
255 |
return token; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
256 |
} // nexttoken |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
257 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
258 |
|
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
259 |
static inline void add_token_sourcepos(Context *ctx, const size_t idx) |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
260 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
261 |
unsigned int pos = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
262 |
const char *fname = preprocessor_sourcepos(ctx->preprocessor, &pos); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
263 |
ctx->token_to_source[idx].line = pos; |
612
72ccfe69eaf1
Moved filename caching into the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents:
611
diff
changeset
|
264 |
ctx->token_to_source[idx].filename = fname; // cached in preprocessor! |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
265 |
} // add_token_sourcepos |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
266 |
|
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
267 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
static void output_token_noswap(Context *ctx, const uint32 token) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
if (isfail(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
return; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
273 |
if (ctx->output_len >= ctx->output_allocation) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
274 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
275 |
const size_t output_alloc_bump = 1024; // that's tokens, not bytes. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
276 |
const size_t newsize = ctx->output_allocation + output_alloc_bump; |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
277 |
void *ptr; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
278 |
|
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
279 |
ptr = Malloc(ctx, newsize * sizeof (uint32)); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
280 |
if (ptr == NULL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
281 |
return; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
282 |
if (ctx->output_len > 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
283 |
memcpy(ptr, ctx->output, ctx->output_len * sizeof (uint32)); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
284 |
Free(ctx, ctx->output); |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
285 |
ctx->output = (uint32 *) ptr; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
286 |
|
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
287 |
ptr = Malloc(ctx, newsize * sizeof (SourcePos)); |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
288 |
if (ptr == NULL) |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
289 |
return; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
290 |
if (ctx->output_len > 0) |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
291 |
memcpy(ptr, ctx->token_to_source, ctx->output_len * sizeof (SourcePos)); |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
292 |
Free(ctx, ctx->token_to_source); |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
293 |
ctx->token_to_source = (SourcePos *) ptr; |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
294 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
295 |
ctx->output_allocation = newsize; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
296 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
297 |
|
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
298 |
ctx->output[ctx->output_len] = token; |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset
|
299 |
add_token_sourcepos(ctx, ctx->output_len); |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
300 |
ctx->output_len++; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
} // output_token_noswap |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
static inline void output_token(Context *ctx, const uint32 token) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
306 |
output_token_noswap(ctx, SWAP32(token)); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
} // output_token |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
static void output_comment_bytes(Context *ctx, const uint8 *buf, size_t len) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
if (len > (0xFFFF * 4)) // length is stored as token count, in 16 bits. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
fail(ctx, "Comment field is too big"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
else if (!isfail(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
const uint32 tokencount = (len / 4) + ((len % 4) ? 1 : 0); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
output_token(ctx, 0xFFFE | (tokencount << 16)); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
while (len >= 4) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
output_token_noswap(ctx, *((const uint32 *) buf)); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
len -= 4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
buf += 4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
324 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
325 |
if (len > 0) // handle spillover... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
union { uint8 ui8[4]; uint32 ui32; } overflow; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
overflow.ui32 = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
memcpy(overflow.ui8, buf, len); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
output_token_noswap(ctx, overflow.ui32); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
} // output_comment_bytes |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
static inline void output_comment_string(Context *ctx, const char *str) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
output_comment_bytes(ctx, (const uint8 *) str, strlen(str)); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
} // output_comment_string |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
340 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
342 |
static int require_comma(Context *ctx) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
344 |
const Token token = nexttoken(ctx); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
345 |
if (token != ((Token) ',')) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
346 |
{ |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
347 |
fail(ctx, "Comma expected"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
348 |
return 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
349 |
} // if |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
350 |
return 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
351 |
} // require_comma |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
353 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
354 |
static int check_token_segment(Context *ctx, const char *str) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
355 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
356 |
// !!! FIXME: these are case-insensitive, right? |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
357 |
const size_t len = strlen(str); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
358 |
if ( (ctx->tokenlen < len) || (strncasecmp(ctx->token, str, len) != 0) ) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
359 |
return 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
360 |
ctx->token += len; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
361 |
ctx->tokenlen -= len; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
362 |
return 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
363 |
} // check_token_segment |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
364 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
365 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
366 |
static int check_token(Context *ctx, const char *str) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
367 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
368 |
const size_t len = strlen(str); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
369 |
if ( (ctx->tokenlen != len) || (strncasecmp(ctx->token, str, len) != 0) ) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
370 |
return 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
371 |
ctx->token += len; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
372 |
ctx->tokenlen = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
373 |
return 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
374 |
} // check_token |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
375 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
376 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
377 |
static int ui32fromtoken(Context *ctx, uint32 *_val) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
378 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
379 |
int i; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
380 |
for (i = 0; i < ctx->tokenlen; i++) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
381 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
382 |
if ((ctx->token[i] < '0') || (ctx->token[i] > '9')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
383 |
break; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
384 |
} // for |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
385 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
386 |
if (i == 0) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
387 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
388 |
*_val = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
389 |
return 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
390 |
} // if |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
391 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
392 |
const int len = i; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
393 |
uint32 val = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
394 |
uint32 mult = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
395 |
while (i--) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
396 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
397 |
val += ((uint32) (ctx->token[i] - '0')) * mult; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
398 |
mult *= 10; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
399 |
} // while |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
400 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
401 |
ctx->token += len; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
402 |
ctx->tokenlen -= len; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
403 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
404 |
*_val = val; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
405 |
return 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
406 |
} // ui32fromtoken |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
407 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
408 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
static int parse_register_name(Context *ctx, RegisterType *rtype, int *rnum) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
411 |
if (nexttoken(ctx) != TOKEN_IDENTIFIER) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
412 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
413 |
fail(ctx, "Expected register"); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
414 |
return 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
415 |
} // if |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
416 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
417 |
int neednum = 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
int regnum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
RegisterType regtype = REG_TYPE_TEMP; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
420 |
|
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
421 |
// Watch out for substrings! oDepth must be checked before oD, since |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
422 |
// the latter will match either case. |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
423 |
if (check_token_segment(ctx, "oDepth")) |
513
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset
|
424 |
{ |
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset
|
425 |
regtype = REG_TYPE_DEPTHOUT; |
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset
|
426 |
neednum = 0; |
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset
|
427 |
} // else if |
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
428 |
else if (check_token_segment(ctx, "vFace")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 |
{ |
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
430 |
regtype = REG_TYPE_MISCTYPE; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
431 |
regnum = (int) MISCTYPE_TYPE_FACE; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
432 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
433 |
} // else if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
434 |
else if (check_token_segment(ctx, "vPos")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
436 |
regtype = REG_TYPE_MISCTYPE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
regnum = (int) MISCTYPE_TYPE_POSITION; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
} // else if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
440 |
else if (check_token_segment(ctx, "oPos")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 |
regnum = (int) RASTOUT_TYPE_POSITION; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
} // else if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
446 |
else if (check_token_segment(ctx, "oFog")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
regnum = (int) RASTOUT_TYPE_FOG; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
} // else if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
452 |
else if (check_token_segment(ctx, "oPts")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
453 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |
regnum = (int) RASTOUT_TYPE_POINT_SIZE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
} // else if |
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
458 |
else if (check_token_segment(ctx, "aL")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
459 |
{ |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
460 |
regtype = REG_TYPE_LOOP; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
461 |
neednum = 0; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
462 |
} // else if |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
463 |
else if (check_token_segment(ctx, "oC")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
464 |
regtype = REG_TYPE_COLOROUT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
465 |
else if (check_token_segment(ctx, "oT")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
466 |
regtype = REG_TYPE_OUTPUT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
467 |
else if (check_token_segment(ctx, "oD")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
468 |
regtype = REG_TYPE_ATTROUT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
469 |
else if (check_token_segment(ctx, "r")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
470 |
regtype = REG_TYPE_TEMP; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
471 |
else if (check_token_segment(ctx, "v")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
472 |
regtype = REG_TYPE_INPUT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
473 |
else if (check_token_segment(ctx, "c")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
474 |
regtype = REG_TYPE_CONST; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
475 |
else if (check_token_segment(ctx, "i")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
476 |
regtype = REG_TYPE_CONSTINT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
477 |
else if (check_token_segment(ctx, "b")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
478 |
regtype = REG_TYPE_CONSTBOOL; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
479 |
else if (check_token_segment(ctx, "s")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
480 |
regtype = REG_TYPE_SAMPLER; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
481 |
else if (check_token_segment(ctx, "l")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
482 |
regtype = REG_TYPE_LABEL; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
483 |
else if (check_token_segment(ctx, "p")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
484 |
regtype = REG_TYPE_PREDICATE; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
485 |
else if (check_token_segment(ctx, "o")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
486 |
regtype = REG_TYPE_OUTPUT; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
487 |
else if (check_token_segment(ctx, "a")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
488 |
regtype = REG_TYPE_ADDRESS; |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
489 |
else if (check_token_segment(ctx, "t")) |
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset
|
490 |
regtype = REG_TYPE_ADDRESS; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
491 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
//case REG_TYPE_TEMPFLOAT16: // !!! FIXME: don't know this asm string |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
494 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
496 |
fail(ctx, "expected register type"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
497 |
regtype = REG_TYPE_CONST; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
498 |
regnum = 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
499 |
neednum = 0; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
500 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
501 |
|
570
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset
|
502 |
// "c[5]" is the same as "c5", so if the token is done, see if next is '['. |
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset
|
503 |
if ((neednum) && (ctx->tokenlen == 0)) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
505 |
if (nexttoken(ctx) == ((Token) '[')) |
570
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset
|
506 |
neednum = 0; // don't need a number on register name itself. |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
507 |
pushback(ctx); |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
508 |
} // if |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
509 |
|
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
510 |
if (neednum) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
511 |
{ |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
512 |
uint32 ui32 = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
513 |
if (!ui32fromtoken(ctx, &ui32)) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
514 |
fail(ctx, "Invalid register index"); |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
515 |
regnum = (int) ui32; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
516 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
518 |
// split up REG_TYPE_CONST |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
519 |
if (regtype == REG_TYPE_CONST) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
if (regnum < 2048) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
522 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
523 |
regtype = REG_TYPE_CONST; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
524 |
regnum -= 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
526 |
else if (regnum < 4096) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
527 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
528 |
regtype = REG_TYPE_CONST2; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
529 |
regnum -= 2048; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
530 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 |
else if (regnum < 6144) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
532 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 |
regtype = REG_TYPE_CONST3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 |
regnum -= 4096; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
535 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 |
else if (regnum < 8192) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 |
regtype = REG_TYPE_CONST4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
regnum -= 6144; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
540 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
542 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
543 |
fail(ctx, "Invalid const register index"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
544 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
545 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
546 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
547 |
*rtype = regtype; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
548 |
*rnum = regnum; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
549 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
550 |
return 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
551 |
} // parse_register_name |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
552 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
553 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
554 |
static void set_result_shift(Context *ctx, DestArgInfo *info, const int val) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
555 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
556 |
if (info->result_shift != 0) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
557 |
fail(ctx, "Multiple result shift modifiers"); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
558 |
info->result_shift = val; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
559 |
} // set_result_shift |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
560 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
561 |
|
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
562 |
static int parse_destination_token(Context *ctx) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
563 |
{ |
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
564 |
DestArgInfo *info = &ctx->dest_arg; |
510
f4433db86f6e
Fixed wrong sizeof for a memset() call.
Ryan C. Gordon <icculus@icculus.org>
parents:
508
diff
changeset
|
565 |
memset(info, '\0', sizeof (DestArgInfo)); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
566 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
567 |
// parse_instruction_token() sets ctx->token to the end of the instruction |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
568 |
// so we can see if there are destination modifiers on the instruction |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
569 |
// itself... |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
570 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
571 |
int invalid_modifier = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
572 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
573 |
while ((ctx->tokenlen > 0) && (!invalid_modifier)) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
574 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
575 |
if (check_token_segment(ctx, "_x2")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
576 |
set_result_shift(ctx, info, 0x1); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
577 |
else if (check_token_segment(ctx, "_x4")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
578 |
set_result_shift(ctx, info, 0x2); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
579 |
else if (check_token_segment(ctx, "_x8")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
580 |
set_result_shift(ctx, info, 0x3); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
581 |
else if (check_token_segment(ctx, "_d8")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
582 |
set_result_shift(ctx, info, 0xD); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
583 |
else if (check_token_segment(ctx, "_d4")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
584 |
set_result_shift(ctx, info, 0xE); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
585 |
else if (check_token_segment(ctx, "_d2")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
586 |
set_result_shift(ctx, info, 0xF); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
587 |
else if (check_token_segment(ctx, "_sat")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
info->result_mod |= MOD_SATURATE; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
589 |
else if (check_token_segment(ctx, "_pp")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
590 |
info->result_mod |= MOD_PP; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
591 |
else if (check_token_segment(ctx, "_centroid")) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
592 |
info->result_mod |= MOD_CENTROID; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
593 |
else |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
594 |
invalid_modifier = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
595 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
596 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
597 |
if (invalid_modifier) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
598 |
fail(ctx, "Invalid destination modifier"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
599 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
600 |
// !!! FIXME: predicates. |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
601 |
if (nexttoken(ctx) == ((Token) '(')) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
602 |
fail(ctx, "Predicates unsupported at this time"); // !!! FIXME: ... |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
603 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
604 |
pushback(ctx); // parse_register_name calls nexttoken(). |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
605 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
606 |
parse_register_name(ctx, &info->regtype, &info->regnum); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
607 |
// parse_register_name() can't check this: dest regs might have modifiers. |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
608 |
if (ctx->tokenlen > 0) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
609 |
fail(ctx, "invalid register name"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
610 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
611 |
// !!! FIXME: can dest registers do relative addressing? |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
612 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
613 |
int invalid_writemask = 0; |
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
614 |
int implicit_writemask = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
615 |
if (nexttoken(ctx) != ((Token) '.')) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
616 |
{ |
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
617 |
implicit_writemask = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
618 |
info->writemask = 0xF; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
619 |
info->writemask0 = info->writemask1 = info->writemask2 = info->writemask3 = 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
620 |
pushback(ctx); // no explicit writemask; do full mask. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
621 |
} // if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
622 |
|
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
623 |
// !!! FIXME: Cg generates code with oDepth.z ... this is a bug, I think. |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
624 |
//else if (scalar_register(ctx->shader_type, info->regtype, info->regnum)) |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
625 |
else if ( (scalar_register(ctx->shader_type, info->regtype, info->regnum)) && (info->regtype != REG_TYPE_DEPTHOUT) ) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
626 |
fail(ctx, "Writemask specified for scalar register"); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
627 |
else if (nexttoken(ctx) != TOKEN_IDENTIFIER) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
628 |
invalid_writemask = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
629 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
630 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
631 |
// !!! FIXME: is out-of-order okay (yxzw instead of xyzw?) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
632 |
char tokenbytes[5] = { '\0', '\0', '\0', '\0', '\0' }; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
633 |
const unsigned int tokenlen = ctx->tokenlen; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
634 |
memcpy(tokenbytes, ctx->token, ((tokenlen < 4) ? tokenlen : 4)); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
635 |
char *ptr = tokenbytes; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
636 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
637 |
info->writemask0 = info->writemask1 = info->writemask2 = info->writemask3 = 0; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
638 |
if (*ptr == 'x') { info->writemask0 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
639 |
if (*ptr == 'y') { info->writemask1 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
640 |
if (*ptr == 'z') { info->writemask2 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
641 |
if (*ptr == 'w') { info->writemask3 = 1; ptr++; } |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
642 |
if ((ptr == ctx->token) && (shader_is_pixel(ctx))) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
644 |
if (*ptr == 'r') { info->writemask0 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
645 |
if (*ptr == 'g') { info->writemask1 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
646 |
if (*ptr == 'b') { info->writemask2 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
647 |
if (*ptr == 'a') { info->writemask3 = 1; ptr++; } |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
650 |
if (*ptr != '\0') |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
651 |
invalid_writemask = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
652 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
653 |
info->writemask = ( ((info->writemask0 & 0x1) << 0) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
654 |
((info->writemask1 & 0x1) << 1) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
655 |
((info->writemask2 & 0x1) << 2) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
656 |
((info->writemask3 & 0x1) << 3) ); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
657 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
658 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
659 |
if (invalid_writemask) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
660 |
fail(ctx, "Invalid writemask"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
661 |
|
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
662 |
// !!! FIXME: Cg generates code with oDepth.z ... this is a bug, I think. |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
663 |
if (info->regtype == REG_TYPE_DEPTHOUT) |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
664 |
{ |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
665 |
if ( (!implicit_writemask) && ((info->writemask0 + info->writemask1 + |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
666 |
info->writemask2 + info->writemask3) > 1) ) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
667 |
fail(ctx, "Writemask specified for scalar register"); |
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
668 |
} // if |
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset
|
669 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
670 |
info->orig_writemask = info->writemask; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
671 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
672 |
if (ctx->tokenbufpos >= STATICARRAYLEN(ctx->tokenbuf)) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
673 |
{ |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
674 |
fail(ctx, "Too many tokens"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
675 |
return 1; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
676 |
} // if |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
ctx->tokenbuf[ctx->tokenbufpos++] = |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
679 |
( ((((uint32) 1)) << 31) | |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
680 |
((((uint32) info->regnum) & 0x7ff) << 0) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
((((uint32) info->relative) & 0x1) << 13) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
682 |
((((uint32) info->result_mod) & 0xF) << 20) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
683 |
((((uint32) info->result_shift) & 0xF) << 24) | |
500
38ce929323c2
Fixed writemask bits in assembled bytecode.
Ryan C. Gordon <icculus@icculus.org>
parents:
499
diff
changeset
|
684 |
((((uint32) info->writemask) & 0xF) << 16) | |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
685 |
((((uint32) info->regtype) & 0x7) << 28) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
686 |
((((uint32) info->regtype) & 0x18) << 8) ); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
687 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
688 |
return 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
689 |
} // parse_destination_token |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
690 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
691 |
|
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
692 |
static void set_source_mod(Context *ctx, const int negate, |
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
693 |
const SourceMod norm, const SourceMod negated, |
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
694 |
SourceMod *srcmod) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
695 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
696 |
if ( (*srcmod != SRCMOD_NONE) || (negate && (negated == SRCMOD_NONE)) ) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
697 |
fail(ctx, "Incompatible source modifiers"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
698 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
699 |
*srcmod = ((negate) ? negated : norm); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
700 |
} // set_source_mod |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
701 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
702 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
703 |
static int parse_source_token_maybe_relative(Context *ctx, const int relok) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
704 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
705 |
int retval = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
706 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
707 |
if (ctx->tokenbufpos >= STATICARRAYLEN(ctx->tokenbuf)) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
708 |
{ |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
709 |
fail(ctx, "Too many tokens"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
710 |
return 0; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
711 |
} // if |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
712 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
713 |
// mark this now, so optional relative addressing token is placed second. |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
714 |
uint32 *outtoken = &ctx->tokenbuf[ctx->tokenbufpos++]; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
715 |
*outtoken = 0; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
716 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
717 |
SourceMod srcmod = SRCMOD_NONE; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
718 |
int negate = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
719 |
Token token = nexttoken(ctx); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
720 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
721 |
if (token == ((Token) '!')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
722 |
srcmod = SRCMOD_NOT; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
723 |
else if (token == ((Token) '-')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
724 |
negate = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
725 |
else if ( (token == TOKEN_INT_LITERAL) && (check_token(ctx, "1")) ) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
726 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
727 |
if (nexttoken(ctx) != ((Token) '-')) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
728 |
fail(ctx, "Unexpected token"); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
729 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
730 |
srcmod = SRCMOD_COMPLEMENT; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
731 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
732 |
else |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
733 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
734 |
pushback(ctx); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
735 |
} // else |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
736 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
737 |
RegisterType regtype; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
738 |
int regnum; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
739 |
parse_register_name(ctx, ®type, ®num); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
740 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
741 |
if (ctx->tokenlen > 0) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
742 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
743 |
if (check_token_segment(ctx, "_bias")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
744 |
set_source_mod(ctx, negate, SRCMOD_BIAS, SRCMOD_BIASNEGATE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
745 |
else if (check_token_segment(ctx, "_bx2")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
746 |
set_source_mod(ctx, negate, SRCMOD_SIGN, SRCMOD_SIGNNEGATE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
747 |
else if (check_token_segment(ctx, "_x2")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
748 |
set_source_mod(ctx, negate, SRCMOD_X2, SRCMOD_X2NEGATE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
749 |
else if (check_token_segment(ctx, "_dz")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
750 |
set_source_mod(ctx, negate, SRCMOD_DZ, SRCMOD_NONE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
751 |
else if (check_token_segment(ctx, "_dw")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
752 |
set_source_mod(ctx, negate, SRCMOD_DW, SRCMOD_NONE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
753 |
else if (check_token_segment(ctx, "_abs")) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
754 |
set_source_mod(ctx, negate, SRCMOD_ABS, SRCMOD_ABSNEGATE, &srcmod); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
755 |
else |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
756 |
fail(ctx, "Invalid source modifier"); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
757 |
} // if |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
758 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
759 |
uint32 relative = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
760 |
if (nexttoken(ctx) != ((Token) '[')) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
761 |
pushback(ctx); // not relative addressing? |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
762 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
763 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
764 |
if (!relok) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
765 |
fail(ctx, "Relative addressing not permitted here."); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
766 |
else |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
767 |
retval++; |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
768 |
|
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
769 |
parse_source_token_maybe_relative(ctx, 0); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
770 |
relative = 1; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
771 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
772 |
if (nexttoken(ctx) != ((Token) '+')) |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
773 |
pushback(ctx); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
774 |
else |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
775 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
776 |
// !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ? |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
777 |
if (regnum != 0) |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
778 |
fail(ctx, "Relative addressing with explicit register number."); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
779 |
|
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
780 |
uint32 ui32 = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
781 |
if ( (nexttoken(ctx) != TOKEN_INT_LITERAL) || |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
782 |
(!ui32fromtoken(ctx, &ui32)) || |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
783 |
(ctx->tokenlen != 0) ) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
784 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
785 |
fail(ctx, "Invalid relative addressing offset"); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
786 |
} // if |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
787 |
regnum += (int) ui32; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
788 |
} // else |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
789 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
790 |
if (nexttoken(ctx) != ((Token) ']')) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
791 |
fail(ctx, "Expected ']'"); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
792 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
793 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
794 |
int invalid_swizzle = 0; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
795 |
uint32 swizzle = 0; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
796 |
if (nexttoken(ctx) != ((Token) '.')) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
797 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
798 |
swizzle = 0xE4; // 0xE4 == 11100100 ... 0 1 2 3. No swizzle. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
799 |
pushback(ctx); // no explicit writemask; do full mask. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
800 |
} // if |
491
bcc3c215807a
Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents:
490
diff
changeset
|
801 |
else if (scalar_register(ctx->shader_type, regtype, regnum)) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
802 |
fail(ctx, "Swizzle specified for scalar register"); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
803 |
else if (nexttoken(ctx) != TOKEN_IDENTIFIER) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
804 |
invalid_swizzle = 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
805 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
806 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
807 |
char tokenbytes[5] = { '\0', '\0', '\0', '\0', '\0' }; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
808 |
const unsigned int tokenlen = ctx->tokenlen; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
809 |
memcpy(tokenbytes, ctx->token, ((tokenlen < 4) ? tokenlen : 4)); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
810 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
811 |
// deal with shortened form (.x = .xxxx, etc). |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
812 |
if (tokenlen == 1) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
813 |
tokenbytes[1] = tokenbytes[2] = tokenbytes[3] = tokenbytes[0]; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
814 |
else if (tokenlen == 2) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
815 |
tokenbytes[2] = tokenbytes[3] = tokenbytes[1]; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
816 |
else if (tokenlen == 3) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
817 |
tokenbytes[3] = tokenbytes[2]; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
818 |
else if (tokenlen != 4) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
819 |
invalid_swizzle = 1; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
820 |
tokenbytes[4] = '\0'; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
821 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
822 |
uint32 val = 0; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
823 |
int saw_xyzw = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
824 |
int saw_rgba = 0; |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
825 |
int i; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
826 |
for (i = 0; i < 4; i++) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
827 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
828 |
const int component = (int) tokenbytes[i]; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
829 |
switch (component) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
830 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
831 |
case 'x': val = 0; saw_xyzw = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
832 |
case 'y': val = 1; saw_xyzw = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
833 |
case 'z': val = 2; saw_xyzw = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
834 |
case 'w': val = 3; saw_xyzw = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
835 |
case 'r': val = 0; saw_rgba = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
836 |
case 'g': val = 1; saw_rgba = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
837 |
case 'b': val = 2; saw_rgba = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
838 |
case 'a': val = 3; saw_rgba = 1; break; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
839 |
default: invalid_swizzle = 1; break; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
840 |
} // switch |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
841 |
swizzle |= (val << (i * 2)); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
842 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
843 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
844 |
if (saw_xyzw && saw_rgba) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
845 |
invalid_swizzle = 1; |
548
b37cdacb50d5
Fixed parsing details of swizzles.
Ryan C. Gordon <icculus@icculus.org>
parents:
544
diff
changeset
|
846 |
else if (saw_rgba && !shader_is_pixel(ctx)) |
b37cdacb50d5
Fixed parsing details of swizzles.
Ryan C. Gordon <icculus@icculus.org>
parents:
544
diff
changeset
|
847 |
invalid_swizzle = 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
848 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
849 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
850 |
if (invalid_swizzle) |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
851 |
fail(ctx, "Invalid swizzle"); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
852 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
853 |
*outtoken = ( ((((uint32) 1)) << 31) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
854 |
((((uint32) regnum) & 0x7ff) << 0) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
855 |
((((uint32) relative) & 0x1) << 13) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
856 |
((((uint32) swizzle) & 0xFF) << 16) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
857 |
((((uint32) srcmod) & 0xF) << 24) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
858 |
((((uint32) regtype) & 0x7) << 28) | |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
859 |
((((uint32) regtype) & 0x18) << 8) ); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
860 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
861 |
return retval; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
862 |
} // parse_source_token_maybe_relative |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
863 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
864 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
865 |
static inline int parse_source_token(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
866 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
867 |
return parse_source_token_maybe_relative(ctx, 1); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
868 |
} // parse_source_token |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
869 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
870 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
871 |
static int parse_args_NULL(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
872 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
873 |
return 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
874 |
} // parse_args_NULL |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
875 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
876 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
877 |
static int parse_num(Context *ctx, const int floatok, uint32 *value) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
878 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
879 |
union { float f; int32 si32; uint32 ui32; } cvt; |
572 | 880 |
int negative = 0; |
881 |
Token token = nexttoken(ctx); |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
882 |
|
572 | 883 |
if (token == ((Token) '-')) |
884 |
{ |
|
885 |
negative = 1; |
|
886 |
token = nexttoken(ctx); |
|
887 |
} // if |
|
888 |
||
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
889 |
if (token == TOKEN_INT_LITERAL) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
890 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
891 |
int d = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
892 |
sscanf(ctx->token, "%d", &d); |
572 | 893 |
if (floatok) |
894 |
cvt.f = (float) ((negative) ? -d : d); |
|
895 |
else |
|
896 |
cvt.si32 = (int32) ((negative) ? -d : d); |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
897 |
} // if |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
898 |
else if (token == TOKEN_FLOAT_LITERAL) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
899 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
900 |
if (!floatok) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
901 |
{ |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
902 |
fail(ctx, "Expected whole number"); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
903 |
*value = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
904 |
return 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
905 |
} // if |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
906 |
sscanf(ctx->token, "%f", &cvt.f); |
572 | 907 |
if (negative) |
908 |
cvt.f = -cvt.f; |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
909 |
} // if |
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
910 |
else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
911 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
912 |
fail(ctx, "Expected number"); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
913 |
*value = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
914 |
return 0; |
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
915 |
} // else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
916 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
917 |
*value = cvt.ui32; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
918 |
return 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
919 |
} // parse_num |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
920 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
921 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
922 |
static int parse_args_DEFx(Context *ctx, const int isflt) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
923 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
924 |
parse_destination_token(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
925 |
require_comma(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
926 |
parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
927 |
require_comma(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
928 |
parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
929 |
require_comma(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
930 |
parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
931 |
require_comma(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
932 |
parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
933 |
return 6; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
934 |
} // parse_args_DEFx |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
935 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
936 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
937 |
static int parse_args_DEF(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
938 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
939 |
return parse_args_DEFx(ctx, 1); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
940 |
} // parse_args_DEF |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
941 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
942 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
943 |
static int parse_args_DEFI(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
944 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
945 |
return parse_args_DEFx(ctx, 0); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
946 |
} // parse_args_DEFI |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
947 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
948 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
949 |
static int parse_args_DEFB(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
950 |
{ |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
951 |
parse_destination_token(ctx); |
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
952 |
require_comma(ctx); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
953 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
954 |
// !!! FIXME: do a TOKEN_TRUE and TOKEN_FALSE? Is this case-sensitive? |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
955 |
const Token token = nexttoken(ctx); |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
956 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
957 |
int bad = 0; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
958 |
if (token != TOKEN_IDENTIFIER) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
959 |
bad = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
960 |
else if (check_token_segment(ctx, "true")) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
961 |
ctx->tokenbuf[ctx->tokenbufpos++] = 1; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
962 |
else if (check_token_segment(ctx, "false")) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
963 |
ctx->tokenbuf[ctx->tokenbufpos++] = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
964 |
else |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
965 |
bad = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
966 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
967 |
if (ctx->tokenlen != 0) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
968 |
bad = 1; |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
969 |
|
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
970 |
if (bad) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
971 |
fail(ctx, "Expected 'true' or 'false'"); |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
972 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
973 |
return 3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
974 |
} // parse_args_DEFB |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
975 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
976 |
|
504 | 977 |
static int parse_dcl_usage(Context *ctx, uint32 *val, int *issampler) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
978 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
979 |
int i; |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
980 |
static const char *samplerusagestrs[] = { "_2d", "_cube", "_volume" }; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
981 |
static const char *usagestrs[] = { |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
982 |
"_position", "_blendweight", "_blendindices", "_normal", "_psize", |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
983 |
"_texcoord", "_tangent", "_binormal", "_tessfactor", "_positiont", |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
984 |
"_color", "_fog", "_depth", "_sample" |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
985 |
}; |
504 | 986 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
987 |
for (i = 0; i < STATICARRAYLEN(usagestrs); i++) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
988 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
989 |
if (check_token_segment(ctx, usagestrs[i])) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
990 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
991 |
*issampler = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
992 |
*val = i; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
993 |
return 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
994 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
995 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
996 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
997 |
for (i = 0; i < STATICARRAYLEN(samplerusagestrs); i++) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
998 |
{ |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
999 |
if (check_token_segment(ctx, samplerusagestrs[i])) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1000 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1001 |
*issampler = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1002 |
*val = i + 2; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1003 |
return 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1004 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1005 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1006 |
|
514
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset
|
1007 |
*issampler = 0; |
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset
|
1008 |
*val = 0; |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1009 |
return 0; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1010 |
} // parse_dcl_usage |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1011 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1012 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1013 |
static int parse_args_DCL(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1014 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1015 |
int issampler = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1016 |
uint32 usage = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1017 |
uint32 index = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1018 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1019 |
ctx->tokenbufpos++; // save a spot for the usage/index token. |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1020 |
ctx->tokenbuf[0] = 0; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1021 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1022 |
// parse_instruction_token() sets ctx->token to the end of the instruction |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1023 |
// so we can see if there are destination modifiers on the instruction |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1024 |
// itself... |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1025 |
|
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1026 |
if (parse_dcl_usage(ctx, &usage, &issampler)) |
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1027 |
{ |
575
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset
|
1028 |
if ((ctx->tokenlen > 0) && (*ctx->token != '_')) |
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset
|
1029 |
{ |
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset
|
1030 |
if (!ui32fromtoken(ctx, &index)) |
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset
|
1031 |
fail(ctx, "Expected usage index"); |
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset
|
1032 |
} // if |
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset
|
1033 |
} // if |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1034 |
|
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1035 |
parse_destination_token(ctx); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1036 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1037 |
const int samplerreg = (ctx->dest_arg.regtype == REG_TYPE_SAMPLER); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1038 |
if (issampler != samplerreg) |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1039 |
fail(ctx, "Invalid usage"); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1040 |
else if (samplerreg) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1041 |
ctx->tokenbuf[0] = (usage << 27) | 0x80000000; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1042 |
else |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1043 |
ctx->tokenbuf[0] = usage | (index << 16) | 0x80000000; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1044 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1045 |
return 3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1046 |
} // parse_args_DCL |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1047 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1048 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1049 |
static int parse_args_D(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1050 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1051 |
int retval = 1; |
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
1052 |
retval += parse_destination_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1053 |
return retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1054 |
} // parse_args_D |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1055 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1056 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1057 |
static int parse_args_S(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1058 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1059 |
int retval = 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1060 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1061 |
return retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1062 |
} // parse_args_S |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1063 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1064 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1065 |
static int parse_args_SS(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1066 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1067 |
int retval = 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1068 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1069 |
require_comma(ctx); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1070 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1071 |
return retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1072 |
} // parse_args_SS |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1073 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1074 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1075 |
static int parse_args_DS(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1076 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1077 |
int retval = 1; |
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
1078 |
retval += parse_destination_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1079 |
require_comma(ctx); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1080 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1081 |
return retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1082 |
} // parse_args_DS |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1083 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1084 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1085 |
static int parse_args_DSS(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1086 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1087 |
int retval = 1; |
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
1088 |
retval += parse_destination_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1089 |
require_comma(ctx); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1090 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1091 |
require_comma(ctx); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1092 |
retval += parse_source_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset
|
1093 |
return retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1094 |
} // parse_args_DSS |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1095 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1096 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1097 |
static int parse_args_DSSS(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1098 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1099 |
int retval = 1; |
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset
|
1100 |
retval += parse_destination_token(ctx); |
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@iccu& |