author | Ryan C. Gordon <icculus@icculus.org> |
Fri, 12 Dec 2008 04:47:21 -0500 | |
changeset 510 | f4433db86f6e |
parent 508 | f45abd96ad7b |
child 511 | 67d7efa9206b |
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 |
|
497
5b2465d40b57
Disabled tokenizer debug output for now.
Ryan C. Gordon <icculus@icculus.org>
parents:
495
diff
changeset
|
13 |
#define DEBUG_TOKENIZER 0 |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
|
498 | 15 |
// !!! FIXME: no #define support yet. |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
typedef struct Context Context; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 |
// Context...this is state that changes as we assemble a shader... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
struct Context |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 |
MOJOSHADER_malloc malloc; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
MOJOSHADER_free free; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 |
void *malloc_data; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 |
const char *failstr; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
const char *source; |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
27 |
int started_parsing; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
MOJOSHADER_shaderType shader_type; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
uint8 major_ver; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
uint8 minor_ver; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
31 |
int on_endline; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
unsigned int linenum; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
char prevchar; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
char token[64]; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
char pushedback; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
uint32 tokenbuf[16]; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
int tokenbufpos; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
DestArgInfo dest_arg; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
39 |
uint32 *output; |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
40 |
uint32 *token_to_line; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
41 |
size_t output_len; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
42 |
size_t output_allocation; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
}; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
// Convenience functions for allocators... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
static inline int out_of_memory(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
if (ctx->failstr == NULL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
ctx->failstr = out_of_mem_str; // fail() would call malloc(). |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
} // out_of_memory |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
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
|
56 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
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
|
58 |
if (retval == NULL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
out_of_memory(ctx); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
return retval; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
} // Malloc |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
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
|
64 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
} // Free |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
static int failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
static int failf(Context *ctx, const char *fmt, ...) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
if (ctx->failstr == NULL) // don't change existing error. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
char scratch = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
va_list ap; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
va_start(ap, fmt); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
const int len = vsnprintf(&scratch, sizeof (scratch), fmt, ap); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
va_end(ap); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |
char *failstr = (char *) Malloc(ctx, len + 1); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 |
if (failstr != NULL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 |
va_start(ap, fmt); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 |
vsnprintf(failstr, len + 1, fmt, ap); // rebuild it. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
va_end(ap); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 |
ctx->failstr = failstr; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
87 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 |
} // failf |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 |
static inline int fail(Context *ctx, const char *reason) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
return failf(ctx, "%s", reason); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 |
} // fail |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 |
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
|
99 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
return (ctx->failstr != NULL); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 |
} // isfail |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 |
// Shader model version magic... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 |
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
|
107 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 |
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
|
109 |
} // version_ui32 |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 |
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
|
112 |
const uint8 min) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 |
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
|
115 |
} // shader_version_atleast |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 |
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
|
118 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
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
|
120 |
} // shader_is_pixel |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 |
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
|
123 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
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
|
125 |
} // shader_is_vertex |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
|
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
128 |
static int ui32fromstr(const char *str, uint32 *ui32) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
129 |
{ |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
130 |
//*ui32 = (uint32) atoi(minstr); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
131 |
char *endptr = NULL; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
132 |
const long val = strtol(str, &endptr, 10); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
133 |
*ui32 = (uint32) val; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
134 |
return ((val >= 0) && (*str != '\0') && (*endptr == '\0')); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
135 |
} // ui32fromstr |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
136 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
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
|
139 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 |
if (isfail(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
return; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
143 |
if (ctx->output_len >= ctx->output_allocation) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
144 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
145 |
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
|
146 |
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
|
147 |
void *ptr; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
148 |
|
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
149 |
ptr = Malloc(ctx, newsize * sizeof (uint32)); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
150 |
if (ptr == NULL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
151 |
return; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
152 |
if (ctx->output_len > 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
153 |
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
|
154 |
Free(ctx, ctx->output); |
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
155 |
ctx->output = (uint32 *) ptr; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
156 |
|
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
157 |
ptr = Malloc(ctx, newsize * sizeof (uint32)); |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
158 |
if (ptr == NULL) |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
159 |
return; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
160 |
if (ctx->output_len > 0) |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
161 |
memcpy(ptr, ctx->token_to_line, ctx->output_len * sizeof (uint32)); |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
162 |
Free(ctx, ctx->token_to_line); |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
163 |
ctx->token_to_line = (uint32 *) ptr; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
164 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
165 |
ctx->output_allocation = newsize; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
166 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
167 |
|
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
168 |
ctx->output[ctx->output_len] = token; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
169 |
ctx->token_to_line[ctx->output_len] = ctx->linenum; |
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset
|
170 |
ctx->output_len++; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 |
} // output_token_noswap |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 |
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
|
175 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
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
|
177 |
} // output_token |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
179 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 |
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
|
181 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
else if (!isfail(ctx)) |
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 |
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
|
187 |
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
|
188 |
while (len >= 4) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 |
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
|
191 |
len -= 4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
buf += 4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
if (len > 0) // handle spillover... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 |
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
|
198 |
overflow.ui32 = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
memcpy(overflow.ui8, buf, len); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 |
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
|
201 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 |
} // output_comment_bytes |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
206 |
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
|
207 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 |
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
|
209 |
} // output_comment_string |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 |
static int _tokenize(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 |
int idx = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
if (isfail(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
if (ctx->pushedback) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 |
ctx->pushedback = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
225 |
if (ctx->on_endline) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
226 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
227 |
ctx->on_endline = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
228 |
ctx->linenum++; // passed a newline, update. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
229 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
230 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 |
while (1) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
232 |
{ |
477 | 233 |
// !!! FIXME: carefully crafted (but legal) comments can trigger this. |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 |
if (idx >= sizeof (ctx->token)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 |
return fail(ctx, "buffer overflow"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 |
char ch = *ctx->source; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 |
if (ch == '\t') |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 |
ch = ' '; // collapse tabs into single spaces. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 |
else if (ch == '\r') |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
if (ctx->source[1] == '\n') |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 |
continue; // ignore '\r' if this is "\r\n" ... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
ch = '\n'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 |
|
478
af4bfa5d615c
Some basic tokenizer logic fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
477
diff
changeset
|
247 |
if ((ch >= '0') && (ch <= '9')) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 |
// starting a number, but rest of current token was not number. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
if ((idx > 0) && ((ctx->prevchar < '0') || (ctx->prevchar > '9'))) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
ctx->token[idx++] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 |
// starting a non-number, but rest of current token was numbers. |
478
af4bfa5d615c
Some basic tokenizer logic fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
477
diff
changeset
|
259 |
if ((idx > 0) && ((ctx->prevchar >= '0') && (ctx->prevchar <= '9'))) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
ctx->token[idx++] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 |
switch (ch) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 |
case '/': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 |
case ';': // !!! FIXME: comment, right? |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
if (idx != 0) // finish off existing token. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 |
ctx->token[idx] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 |
ctx->token[idx++] = ch; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
ctx->source++; |
478
af4bfa5d615c
Some basic tokenizer logic fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
477
diff
changeset
|
276 |
if ((ch == '/') && (*ctx->source == '/')) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 |
ctx->token[idx++] = '/'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 |
ctx->source++; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 |
ctx->token[idx++] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 |
case ' ': |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
286 |
if (ctx->prevchar == ' ') |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 |
break; // multiple whitespace collapses into one. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 |
// intentional fall-through... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
case '_': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
291 |
case '[': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
292 |
case ']': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
293 |
case '(': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
294 |
case ')': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
295 |
case '!': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
296 |
case '+': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
297 |
case '-': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
298 |
case ',': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
299 |
case '.': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
300 |
case '\n': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
301 |
if (idx != 0) // finish off existing token. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 |
ctx->token[idx] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
303 |
else // this is a token in itself. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
304 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
305 |
if (ch == '\n') |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
306 |
ctx->on_endline = 1; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
307 |
ctx->source++; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 |
ctx->token[idx++] = ch; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
309 |
ctx->token[idx++] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
310 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
313 |
case '\0': |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 |
ctx->token[idx] = '\0'; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
315 |
if (idx != 0) // had any chars? It's a token. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
316 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
317 |
return END_OF_STREAM; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
318 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
319 |
default: |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
320 |
ctx->source++; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
321 |
ctx->token[idx++] = ch; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 |
break; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
323 |
} // switch |
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 |
ctx->prevchar = ch; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
326 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
327 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
328 |
return fail(ctx, "???"); // shouldn't hit this. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
329 |
} // _tokenize |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
330 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
332 |
static inline int tokenize(Context *ctx) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
333 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
334 |
const int rc = _tokenize(ctx); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
335 |
#if DEBUG_TOKENIZER |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 |
printf("TOKENIZE: %s '%s'\n", |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
(rc == END_OF_STREAM) ? "END_OF_STREAM" : |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 |
(rc == FAIL) ? "FAIL" : |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
339 |
(rc == NOFAIL) ? "NOFAIL" : "???", |
495
93ede2fba3c6
Made debug output more readable.
Ryan C. Gordon <icculus@icculus.org>
parents:
492
diff
changeset
|
340 |
(ctx->token[0] == '\n') ? "\\n" : ctx->token); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
341 |
#endif |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
342 |
return rc; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
343 |
} // tokenize |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
344 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 |
|
490
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
346 |
static inline int pushback(Context *ctx) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
347 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
348 |
#if DEBUG_TOKENIZER |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
349 |
printf("PUSHBACK\n"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
350 |
#endif |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
352 |
if (ctx->pushedback) |
490
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
353 |
return fail(ctx, "BUG: Double pushback in parser"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 |
ctx->pushedback = 1; |
490
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
356 |
|
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
357 |
return NOFAIL; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 |
} // pushback |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
360 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
361 |
static int nexttoken(Context *ctx, const int ignoreeol, |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
362 |
const int ignorewhitespace, const int eolok, |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 |
const int eosok) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
364 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
365 |
int rc = NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
366 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
while ((rc = tokenize(ctx)) == NOFAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
369 |
if (strcmp(ctx->token, "\n") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 |
if (ignoreeol) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
372 |
continue; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
373 |
else if (!eolok) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
return fail(ctx, "Unexpected EOL"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
375 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
376 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
377 |
else if (strcmp(ctx->token, " ") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
378 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
379 |
if (ignorewhitespace) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 |
continue; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
381 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
382 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 |
// skip comments... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
384 |
else if ((strcmp(ctx->token, "//") == 0) || (strcmp(ctx->token, ";") == 0)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
386 |
while ((rc = tokenize(ctx)) == NOFAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
387 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
388 |
if (strcmp(ctx->token, "\n") == 0) |
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
389 |
{ |
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
390 |
pushback(ctx); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
391 |
break; |
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
392 |
} // if |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 |
} // while |
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset
|
394 |
continue; // pick up from newline, go again. |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
396 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
397 |
break; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
399 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
400 |
#if DEBUG_TOKENIZER |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
401 |
printf("NEXTTOKEN: %s '%s'\n", |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
402 |
(rc == END_OF_STREAM) ? "END_OF_STREAM" : |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
403 |
(rc == FAIL) ? "FAIL" : |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
404 |
(rc == NOFAIL) ? "NOFAIL" : "???", |
495
93ede2fba3c6
Made debug output more readable.
Ryan C. Gordon <icculus@icculus.org>
parents:
492
diff
changeset
|
405 |
(ctx->token[0] == '\n') ? "\\n" : ctx->token); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
406 |
#endif |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
407 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
408 |
if ((rc == END_OF_STREAM) && (!eosok)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 |
return fail(ctx, "Unexpected EOF"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
410 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
411 |
return rc; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 |
} // nexttoken |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
414 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
415 |
static int require_endline(Context *ctx) |
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 |
const int rc = nexttoken(ctx, 0, 1, 1, 1); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
418 |
if (rc == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
419 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 |
else if (rc == END_OF_STREAM) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
421 |
return NOFAIL; // we'll call this an EOL. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 |
else if (strcmp(ctx->token, "\n") != 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
423 |
return fail(ctx, "Endline expected"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
424 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
425 |
} // require_endline |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
426 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
428 |
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
|
429 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
430 |
const int rc = nexttoken(ctx, 0, 1, 0, 0); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
431 |
if (rc == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
432 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
433 |
else if (strcmp(ctx->token, ",") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
434 |
return fail(ctx, "Comma expected"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
435 |
return NOFAIL; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
436 |
} // require_comma |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
439 |
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
|
440 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
444 |
// !!! FIXME: some of these registers are only valid for some shader types. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
445 |
int neednum = 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
446 |
int regnum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
447 |
const char *t = ctx->token; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
448 |
RegisterType regtype = REG_TYPE_TEMP; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
449 |
if (strcasecmp(t, "r") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
450 |
regtype = REG_TYPE_TEMP; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 |
else if (strcasecmp(t, "v") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
452 |
regtype = REG_TYPE_INPUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
453 |
else if (strcasecmp(t, "c") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
454 |
regtype = REG_TYPE_CONST; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
455 |
else if (strcasecmp(t, "i") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
456 |
regtype = REG_TYPE_CONSTINT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
else if (strcasecmp(t, "b") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 |
regtype = REG_TYPE_CONSTBOOL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
459 |
else if (strcasecmp(t, "oC") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
460 |
regtype = REG_TYPE_COLOROUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
461 |
else if (strcasecmp(t, "oDepth") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 |
regtype = REG_TYPE_DEPTHOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
463 |
else if (strcasecmp(t, "s") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
464 |
regtype = REG_TYPE_SAMPLER; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
465 |
else if (strcasecmp(t, "oD") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 |
regtype = REG_TYPE_ATTROUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 |
else if (strcasecmp(t, "l") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 |
regtype = REG_TYPE_LABEL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
469 |
else if (strcasecmp(t, "p") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 |
regtype = REG_TYPE_PREDICATE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
471 |
else if (strcasecmp(t, "aL") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
472 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
473 |
regtype = REG_TYPE_LOOP; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
474 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
475 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
476 |
else if (strcasecmp(t, "o") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
477 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
478 |
if (!shader_is_vertex(ctx) || !shader_version_atleast(ctx, 3, 0)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 |
return fail(ctx, "Output register not valid in this shader type"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
480 |
regtype = REG_TYPE_OUTPUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
481 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
482 |
else if (strcasecmp(t, "oT") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
483 |
{ |
502
3cb501248990
Fixed logic error in assembler, to decide if oTx registers are available.
Ryan C. Gordon <icculus@icculus.org>
parents:
500
diff
changeset
|
484 |
if (shader_is_vertex(ctx) && shader_version_atleast(ctx, 3, 0)) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
485 |
return fail(ctx, "Output register not valid in this shader type"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
486 |
regtype = REG_TYPE_OUTPUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
487 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
488 |
else if (strcasecmp(t, "a") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
489 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 |
if (!shader_is_vertex(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
491 |
return fail(ctx, "Address register only valid in vertex shaders."); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
regtype = REG_TYPE_ADDRESS; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
494 |
else if (strcasecmp(t, "t") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
if (!shader_is_pixel(ctx)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
497 |
return fail(ctx, "Address register only valid in pixel shaders."); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
498 |
regtype = REG_TYPE_ADDRESS; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
499 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
500 |
else if (strcasecmp(t, "vPos") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
501 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
502 |
regtype = REG_TYPE_MISCTYPE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
503 |
regnum = (int) MISCTYPE_TYPE_POSITION; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
505 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
else if (strcasecmp(t, "vFace") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
507 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 |
regtype = REG_TYPE_MISCTYPE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
509 |
regnum = (int) MISCTYPE_TYPE_FACE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
510 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
512 |
else if (strcasecmp(t, "oPos") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
513 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
514 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
515 |
regnum = (int) RASTOUT_TYPE_POSITION; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
516 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
518 |
else if (strcasecmp(t, "oFog") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
519 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
regnum = (int) RASTOUT_TYPE_FOG; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
522 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
523 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
524 |
else if (strcasecmp(t, "oPts") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
526 |
regtype = REG_TYPE_RASTOUT; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
527 |
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
|
528 |
neednum = 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
529 |
} // else if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
530 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 |
//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
|
532 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
535 |
return fail(ctx, "expected register type"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
536 |
} // else |
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 |
if (neednum) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
539 |
{ |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
540 |
// cheat the pushback. |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
541 |
const char *origsrc = ctx->source; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
542 |
const int origonendline = ctx->on_endline; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
543 |
const int origlinenum = ctx->linenum; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
544 |
const int origprevchar = ctx->prevchar; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
545 |
|
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
546 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
547 |
return FAIL; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
548 |
else if (strcmp(ctx->token, "[") == 0) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
549 |
neednum = 0; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
550 |
|
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
551 |
ctx->source = origsrc; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
552 |
ctx->on_endline = origonendline; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
553 |
ctx->linenum = origlinenum; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
554 |
ctx->prevchar = origprevchar; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
555 |
} // if |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
556 |
|
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
557 |
if (neednum) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
558 |
{ |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 |
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
560 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
561 |
|
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
562 |
uint32 ui32 = 0; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
563 |
if (!ui32fromstr(ctx->token, &ui32)) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
564 |
return fail(ctx, "Invalid register index"); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
565 |
regnum = (int) ui32; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
566 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
568 |
// split up REG_TYPE_CONST |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
569 |
if (regtype == REG_TYPE_CONST) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
570 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
571 |
if (regnum < 2048) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
572 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
573 |
regtype = REG_TYPE_CONST; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
574 |
regnum -= 0; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
575 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
576 |
else if (regnum < 4096) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
577 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
578 |
regtype = REG_TYPE_CONST2; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 |
regnum -= 2048; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
581 |
else if (regnum < 6144) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 |
regtype = REG_TYPE_CONST3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 |
regnum -= 4096; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
else if (regnum < 8192) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
587 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
regtype = REG_TYPE_CONST4; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
589 |
regnum -= 6144; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
590 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
592 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
593 |
return fail(ctx, "Invalid const register index"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
594 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
595 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
596 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
597 |
*rtype = regtype; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
598 |
*rnum = regnum; |
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 |
return NOFAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
601 |
} // parse_register_name |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
602 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
603 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
604 |
static int set_result_shift(Context *ctx, DestArgInfo *info, const int val) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
605 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
606 |
if (info->result_shift != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
607 |
return fail(ctx, "Multiple result shift modifiers"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
608 |
info->result_shift = val; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
609 |
return NOFAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
610 |
} // set_result_shift |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
611 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
612 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
613 |
static int parse_destination_token(Context *ctx, DestArgInfo *info) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
614 |
{ |
510
f4433db86f6e
Fixed wrong sizeof for a memset() call.
Ryan C. Gordon <icculus@icculus.org>
parents:
508
diff
changeset
|
615 |
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
|
616 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
617 |
// See if there are destination modifiers on the instruction itself... |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
618 |
while (1) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
619 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
620 |
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
621 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
622 |
else if (strcmp(ctx->token, " ") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
623 |
break; // done with modifiers. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
624 |
else if (strcmp(ctx->token, "_") != 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
625 |
return fail(ctx, "Expected modifier or whitespace"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
626 |
else if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
627 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
628 |
else if (strcasecmp(ctx->token, "x2") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
629 |
set_result_shift(ctx, info, 0x1); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
630 |
else if (strcasecmp(ctx->token, "x4") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
631 |
set_result_shift(ctx, info, 0x2); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
632 |
else if (strcasecmp(ctx->token, "x8") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
633 |
set_result_shift(ctx, info, 0x3); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
634 |
else if (strcasecmp(ctx->token, "d8") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
635 |
set_result_shift(ctx, info, 0xD); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
636 |
else if (strcasecmp(ctx->token, "d4") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
637 |
set_result_shift(ctx, info, 0xE); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
638 |
else if (strcasecmp(ctx->token, "d2") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
639 |
set_result_shift(ctx, info, 0xF); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
640 |
else if (strcasecmp(ctx->token, "sat") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
641 |
info->result_mod |= MOD_SATURATE; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
642 |
else if (strcasecmp(ctx->token, "pp") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
643 |
info->result_mod |= MOD_PP; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
644 |
else if (strcasecmp(ctx->token, "centroid") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
645 |
info->result_mod |= MOD_CENTROID; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
646 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 |
return fail(ctx, "Expected modifier"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 |
} // while |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
650 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
651 |
return FAIL; |
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 |
// !!! FIXME: predicates. |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
654 |
if (strcmp(ctx->token, "(") == 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
655 |
return fail(ctx, "Predicates unsupported at this time"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
656 |
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
|
657 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
658 |
if (parse_register_name(ctx, &info->regtype, &info->regnum) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
659 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
660 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
661 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
662 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
663 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
664 |
// !!! 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
|
665 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
666 |
if (strcmp(ctx->token, ".") != 0) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
667 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
668 |
info->writemask = 0xF; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
669 |
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
|
670 |
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
|
671 |
} // if |
491
bcc3c215807a
Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents:
490
diff
changeset
|
672 |
else if (scalar_register(ctx->shader_type, info->regtype, info->regnum)) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
673 |
return fail(ctx, "Writemask specified for scalar register"); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
674 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
675 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
676 |
else if (ctx->token[0] == '\0') |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
677 |
return fail(ctx, "Invalid writemask"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
678 |
else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
679 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
680 |
char *ptr = ctx->token; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
681 |
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
|
682 |
if (*ptr == 'x') { info->writemask0 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
683 |
if (*ptr == 'y') { info->writemask1 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
684 |
if (*ptr == 'z') { info->writemask2 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
685 |
if (*ptr == 'w') { info->writemask3 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
686 |
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
|
687 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
688 |
if (*ptr == 'r') { info->writemask0 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
689 |
if (*ptr == 'g') { info->writemask1 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
690 |
if (*ptr == 'b') { info->writemask2 = 1; ptr++; } |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
691 |
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
|
692 |
} // if |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
693 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
694 |
if (*ptr != '\0') |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
return fail(ctx, "Invalid writemask"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
696 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |
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
|
698 |
((info->writemask1 & 0x1) << 1) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
699 |
((info->writemask2 & 0x1) << 2) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
700 |
((info->writemask3 & 0x1) << 3) ); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
701 |
} // else |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
702 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
703 |
info->orig_writemask = info->writemask; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
704 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
705 |
if (ctx->tokenbufpos >= STATICARRAYLEN(ctx->tokenbuf)) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
706 |
return fail(ctx, "Too many tokens"); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
707 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
708 |
ctx->tokenbuf[ctx->tokenbufpos++] = |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
709 |
( ((((uint32) 1)) << 31) | |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
710 |
((((uint32) info->regnum) & 0x7ff) << 0) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
711 |
((((uint32) info->relative) & 0x1) << 13) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
712 |
((((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
|
713 |
((((uint32) info->result_shift) & 0xF) << 24) | |
500
38ce929323c2
Fixed writemask bits in assembled bytecode.
Ryan C. Gordon <icculus@icculus.org>
parents:
499
diff
changeset
|
714 |
((((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
|
715 |
((((uint32) info->regtype) & 0x7) << 28) | |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
716 |
((((uint32) info->regtype) & 0x18) << 8) ); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
717 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
718 |
return 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
719 |
} // parse_destination_token |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
720 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
721 |
|
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
722 |
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
|
723 |
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
|
724 |
SourceMod *srcmod) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
725 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
726 |
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
|
727 |
fail(ctx, "Incompatible source modifiers"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
728 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
729 |
*srcmod = ((negate) ? negated : norm); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
730 |
} // set_source_mod |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
731 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
732 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
733 |
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
|
734 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
735 |
int retval = 1; |
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 |
if (ctx->tokenbufpos >= STATICARRAYLEN(ctx->tokenbuf)) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
738 |
return fail(ctx, "Too many tokens"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
739 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
740 |
// mark this now, so optional relative addressing token is placed second. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
741 |
uint32 *token = &ctx->tokenbuf[ctx->tokenbufpos++]; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
742 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
743 |
SourceMod srcmod = SRCMOD_NONE; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
744 |
int negate = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
745 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
746 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
747 |
else if (strcmp(ctx->token, "1") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
748 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
749 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
750 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
751 |
else if (strcmp(ctx->token, "-") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
752 |
return fail(ctx, "Unexpected value"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
753 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
754 |
srcmod = SRCMOD_COMPLEMENT; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
755 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
756 |
else if (strcmp(ctx->token, "!") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
757 |
srcmod = SRCMOD_NOT; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
758 |
else if (strcmp(ctx->token, "-") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
759 |
negate = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
760 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
761 |
pushback(ctx); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
762 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
763 |
RegisterType regtype; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
764 |
int regnum; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
765 |
if (parse_register_name(ctx, ®type, ®num) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
766 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
767 |
else if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
768 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
769 |
else if (strcmp(ctx->token, "_") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
770 |
pushback(ctx); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
771 |
else if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
772 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
773 |
else if (strcasecmp(ctx->token, "bias") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
774 |
set_source_mod(ctx, negate, SRCMOD_BIAS, SRCMOD_BIASNEGATE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
775 |
else if (strcasecmp(ctx->token, "bx2") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
776 |
set_source_mod(ctx, negate, SRCMOD_SIGN, SRCMOD_SIGNNEGATE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
777 |
else if (strcasecmp(ctx->token, "x2") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
778 |
set_source_mod(ctx, negate, SRCMOD_X2, SRCMOD_X2NEGATE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
779 |
else if (strcasecmp(ctx->token, "dz") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
780 |
set_source_mod(ctx, negate, SRCMOD_DZ, SRCMOD_NONE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
781 |
else if (strcasecmp(ctx->token, "dw") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
782 |
set_source_mod(ctx, negate, SRCMOD_DW, SRCMOD_NONE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
783 |
else if (strcasecmp(ctx->token, "abs") == 0) |
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset
|
784 |
set_source_mod(ctx, negate, SRCMOD_ABS, SRCMOD_ABSNEGATE, &srcmod); |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
785 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
786 |
return fail(ctx, "Invalid source modifier"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
787 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
788 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
789 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
790 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
791 |
uint32 relative = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
792 |
if (strcmp(ctx->token, "[") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
793 |
pushback(ctx); // not relative addressing? |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
794 |
else if (!relok) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
795 |
return fail(ctx, "Relative addressing not permitted here."); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
796 |
else |
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 |
const int rc = parse_source_token_maybe_relative(ctx, 0); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
799 |
if (rc == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
800 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
801 |
retval += rc; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
802 |
relative = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
803 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
804 |
return FAIL; |
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
805 |
else if (strcmp(ctx->token, "+") != 0) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
806 |
pushback(ctx); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
807 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
808 |
return FAIL; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
809 |
else |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
810 |
{ |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
811 |
if (regnum != 0) // !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ? |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
812 |
fail(ctx, "Relative addressing with explicit register number."); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
813 |
uint32 ui32 = 0; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
814 |
if (!ui32fromstr(ctx->token, &ui32)) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
815 |
return fail(ctx, "Invalid relative addressing offset"); |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
816 |
regnum += (int) ui32; |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
817 |
} // else |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
818 |
|
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
819 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset
|
820 |
return FAIL; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
821 |
else if (strcmp(ctx->token, "]") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
822 |
return fail(ctx, "Expected ']'"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
823 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
824 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
825 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
826 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
827 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
828 |
uint32 swizzle = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
829 |
if (strcmp(ctx->token, ".") != 0) |
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 |
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
|
832 |
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
|
833 |
} // if |
491
bcc3c215807a
Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents:
490
diff
changeset
|
834 |
else if (scalar_register(ctx->shader_type, regtype, regnum)) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
835 |
return fail(ctx, "Swizzle specified for scalar register"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
836 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
837 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
838 |
else if (ctx->token[0] == '\0') |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
839 |
return fail(ctx, "Invalid swizzle"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
840 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
841 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
842 |
// deal with shortened form (.x = .xxxx, etc). |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
843 |
if (ctx->token[1] == '\0') |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
844 |
ctx->token[1] = ctx->token[2] = ctx->token[3] = ctx->token[0]; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
845 |
else if (ctx->token[2] == '\0') |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
846 |
ctx->token[2] = ctx->token[3] = ctx->token[1]; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
847 |
else if (ctx->token[3] == '\0') |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
848 |
ctx->token[3] = ctx->token[2]; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
849 |
else if (ctx->token[4] != '\0') |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
850 |
return fail(ctx, "Invalid swizzle"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
851 |
ctx->token[4] = '\0'; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
852 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
853 |
uint32 val; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
854 |
int saw_xyzw = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
855 |
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
|
856 |
int i; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
857 |
for (i = 0; i < 4; i++) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
858 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
859 |
const int component = (int) ctx->token[i]; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
860 |
switch (component) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
861 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
862 |
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
|
863 |
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
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
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
|
868 |
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
|
869 |
case 'a': val = 3; saw_rgba = 1; break; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
870 |
default: return fail(ctx, "Invalid swizzle"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
871 |
} // switch |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
872 |
swizzle |= (val << (i * 2)); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
873 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
874 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
875 |
if (saw_xyzw && saw_rgba) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
876 |
return fail(ctx, "Invalid swizzle"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
877 |
} // else |
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 |
*token = ( ((((uint32) 1)) << 31) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
880 |
((((uint32) regnum) & 0x7ff) << 0) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
881 |
((((uint32) relative) & 0x1) << 13) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
882 |
((((uint32) swizzle) & 0xFF) << 16) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
883 |
((((uint32) srcmod) & 0xF) << 24) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
884 |
((((uint32) regtype) & 0x7) << 28) | |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
885 |
((((uint32) regtype) & 0x18) << 8) ); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
886 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
887 |
return retval; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
888 |
} // parse_source_token_maybe_relative |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
889 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
890 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
891 |
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
|
892 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
893 |
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
|
894 |
} // parse_source_token |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
895 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
896 |
|
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
897 |
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
|
898 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
899 |
return (isfail(ctx) ? FAIL : 1); |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
900 |
} // parse_args_NULL |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
901 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
902 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
903 |
static int parse_num(Context *ctx, const int floatok, uint32 *token) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
904 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
905 |
int32 negative = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
906 |
union { float f; int32 si32; uint32 ui32; } cvt; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
907 |
cvt.si32 = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
908 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
909 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
910 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
911 |
else if (strcmp(ctx->token, "-") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
912 |
negative = -1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
913 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
914 |
pushback(ctx); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
915 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
916 |
uint32 val = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
917 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
918 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
919 |
else if (!ui32fromstr(ctx->token, &val)) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
920 |
return fail(ctx, "Expected number"); |
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 |
uint32 fraction = 0; |
488
1a318d011c00
Handle endlines on DEF statements.
Ryan C. Gordon <icculus@icculus.org>
parents:
487
diff
changeset
|
923 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
924 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
925 |
else if (strcmp(ctx->token, ".") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
926 |
pushback(ctx); // whole number |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
927 |
else if (!floatok) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
928 |
return fail(ctx, "Expected whole number"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
929 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
930 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
931 |
else if (!ui32fromstr(ctx->token, &fraction)) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
932 |
return fail(ctx, "Expected number"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
933 |
|
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
934 |
uint32 exponent = 0; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
935 |
int negexp = 0; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
936 |
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
937 |
return FAIL; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
938 |
else if (strcmp(ctx->token, "e") != 0) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
939 |
pushback(ctx); |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
940 |
else if (!floatok) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
941 |
return fail(ctx, "Exponent on whole number"); // !!! FIXME: illegal? |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
942 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
943 |
return FAIL; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
944 |
else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
945 |
{ |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
946 |
if (strcmp(ctx->token, "-") != 0) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
947 |
pushback(ctx); |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
948 |
else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
949 |
negexp = 1; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
950 |
|
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
951 |
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
952 |
return FAIL; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
953 |
else if (!ui32fromstr(ctx->token, &exponent)) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
954 |
return fail(ctx, "Expected exponent"); |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
955 |
} // else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
956 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
957 |
if (!floatok) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
958 |
cvt.si32 = ((int32) val) * negative; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
959 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
960 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
961 |
// !!! FIXME: this is lame. |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
962 |
char buf[128]; |
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
963 |
snprintf(buf, sizeof (buf), "%s%u.%u", (negative < 0) ? "-" : "", |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
964 |
(uint) val, (uint) fraction); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
965 |
sscanf(buf, "%f", &cvt.f); |
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
966 |
cvt.f *= (float) negative; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
967 |
|
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
968 |
if (exponent) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
969 |
{ |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
970 |
int i; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
971 |
if (negexp) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
972 |
{ |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
973 |
for (i = 0; i > exponent; i--) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
974 |
cvt.f /= 10.0f; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
975 |
} // if |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
976 |
else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
977 |
{ |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
978 |
for (i = 0; i < exponent; i++) |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
979 |
cvt.f *= 10.0f; |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
980 |
} // else |
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset
|
981 |
} // if |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
982 |
} // else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
983 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
984 |
*token = cvt.ui32; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
985 |
return NOFAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
986 |
} // parse_num |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
987 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
988 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
989 |
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
|
990 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
991 |
if (parse_destination_token(ctx, &ctx->dest_arg) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
992 |
return FAIL; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
993 |
else if (require_comma(ctx) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
994 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
995 |
else if (parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
996 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
997 |
else if (require_comma(ctx) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
998 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
999 |
else if (parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1000 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1001 |
else if (require_comma(ctx) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1002 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1003 |
else if (parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1004 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1005 |
else if (require_comma(ctx) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1006 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1007 |
else if (parse_num(ctx, isflt, &ctx->tokenbuf[ctx->tokenbufpos++]) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1008 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1009 |
return 6; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1010 |
} // parse_args_DEFx |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1011 |
|
470
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_DEF(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 |
return parse_args_DEFx(ctx, 1); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1016 |
} // parse_args_DEF |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1017 |
|
470
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 |
static int parse_args_DEFI(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1020 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1021 |
return parse_args_DEFx(ctx, 0); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1022 |
} // parse_args_DEFI |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1023 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1024 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1025 |
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
|
1026 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1027 |
if (parse_destination_token(ctx, &ctx->dest_arg) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1028 |
return FAIL; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1029 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1030 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1031 |
else if (strcmp(ctx->token, ",") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1032 |
return fail(ctx, "Expected ','"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1033 |
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1034 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1035 |
else if (strcasecmp(ctx->token, "true") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1036 |
ctx->tokenbuf[ctx->tokenbufpos++] = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1037 |
else if (strcasecmp(ctx->token, "false") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1038 |
ctx->tokenbuf[ctx->tokenbufpos++] = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1039 |
else |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1040 |
return fail(ctx, "Expected 'true' or 'false'"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1041 |
return 3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1042 |
} // parse_args_DEFB |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1043 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1044 |
|
504 | 1045 |
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
|
1046 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1047 |
int i; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1048 |
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
|
1049 |
static const char *usagestrs[] = { |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1050 |
"position", "blendweight", "blendindices", "normal", "psize", |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1051 |
"texcoord", "tangent", "binormal", "tessfactor", "positiont", |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1052 |
"color", "fog", "depth", "sample" |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1053 |
}; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1054 |
|
504 | 1055 |
// !!! FIXME: we need to clean this out in the tokenizer. |
1056 |
char token[sizeof (ctx->token)]; |
|
1057 |
strcpy(token, ctx->token); |
|
1058 |
if (strcmp(token, "2") == 0) // "2d" is two tokens. |
|
1059 |
{ |
|
1060 |
if (nexttoken(ctx, 0, 0, 1, 1) == FAIL) |
|
1061 |
return FAIL; |
|
1062 |
else if (strcasecmp(ctx->token, "d") != 0) |
|
1063 |
pushback(ctx); |
|
1064 |
else |
|
1065 |
strcpy(token, "2d"); |
|
1066 |
} // if |
|
1067 |
||
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1068 |
for (i = 0; i < STATICARRAYLEN(usagestrs); i++) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1069 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1070 |
if (strcasecmp(usagestrs[i], token) == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1071 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1072 |
*issampler = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1073 |
*val = i; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1074 |
return NOFAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1075 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1076 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1077 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1078 |
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
|
1079 |
{ |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1080 |
if (strcasecmp(samplerusagestrs[i], token) == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1081 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1082 |
*issampler = 1; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1083 |
*val = i + 2; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1084 |
return NOFAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1085 |
} // if |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1086 |
} // for |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1087 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1088 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1089 |
} // parse_dcl_usage |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1090 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1091 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1092 |
static int parse_args_DCL(Context *ctx) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1093 |
{ |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1094 |
int issampler = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1095 |
uint32 usage = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1096 |
uint32 index = 0; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1097 |
|
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1098 |
ctx->tokenbufpos++; // save a spot for the usage/index token. |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1099 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1100 |
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1101 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1102 |
else if (strcmp(ctx->token, " ") == 0) |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1103 |
pushback(ctx); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1104 |
else if (strcmp(ctx->token, "_") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1105 |
return fail(ctx, "Expected register or usage"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1106 |
else if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1107 |
return FAIL; |
504 | 1108 |
else if (parse_dcl_usage(ctx, &usage, &issampler) == FAIL) |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1109 |
return FAIL; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1110 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1111 |
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1112 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1113 |
else if (strcmp(ctx->token, " ") == 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1114 |
pushback(ctx); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1115 |
else if (!ui32fromstr(ctx->token, &index)) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1116 |
return fail(ctx, "Expected usage index or register"); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1117 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1118 |
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1119 |
return FAIL; |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1120 |
else if (strcmp(ctx->token, " ") != 0) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1121 |
return fail(ctx, "Expected register"); |
490
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
1122 |
else if (pushback(ctx) == FAIL) // parse_destination_token() wants the ' ' |
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset
|
1123 |
return FAIL; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1124 |
else if (parse_destination_token(ctx, &ctx->dest_arg) == FAIL) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1125 |
return FAIL; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1126 |
|
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1127 |
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
|
1128 |
if (issampler != samplerreg) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1129 |
return fail(ctx, "Invalid usage"); |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1130 |
else if (samplerreg) |
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1131 |
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
|
1132 |
else |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1133 |
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
|
1134 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1135 |
return 3; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1136 |
} // parse_args_DCL |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1137 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1138 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1139 |
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
|
1140 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1141 |
int retval = 1; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1142 |
retval += parse_destination_token(ctx, &ctx->dest_arg); |
480
e7a7822fb38b
Logic error due to second-guessing design.
Ryan C. Gordon <icculus@icculus.org>
parents:
479
diff
changeset
|
1143 |
return isfail(ctx) ? FAIL : retval; |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1144 |
} // parse_args_D |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1145 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1146 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1147 |
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
|
1148 |
{ |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1149 |
int retval = 1; |
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset
|
1150 |
retval += parse_source_token(ctx); |
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1151 |
return isfail(ctx) ? FAIL : retval; |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1152 |
} // parse_args_S |
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1153 |
|
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1154 |
|