author  Ryan C. Gordon <icculus@icculus.org> 
Sat, 20 Dec 2008 05:48:38 0500  
changeset 524  03eea2f0762c 
parent 523  699696afd731 
child 526  ba7df2cd0371 
permissions  rwrr 
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 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

17 
typedef struct TokenizerContext 
514
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

18 
{ 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

19 
const char *source; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

20 
int on_endline; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

21 
unsigned int linenum; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

22 
char prevchar; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

23 
char token[64]; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

24 
char pushedback; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

25 
} TokenizerContext; 
514
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

26 

ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

27 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

28 
typedef struct Context Context; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

29 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

30 
// 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

31 
struct Context 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

32 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

33 
MOJOSHADER_malloc malloc; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

34 
MOJOSHADER_free free; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

35 
void *malloc_data; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

36 
const char *failstr; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

37 
TokenizerContext tctx; 
523
699696afd731
Allow errors to specify postprocessing problems.
Ryan C. Gordon <icculus@icculus.org>
parents:
522
diff
changeset

38 
MOJOSHADER_parsePhase parse_phase; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

39 
MOJOSHADER_shaderType shader_type; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

40 
uint8 major_ver; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

41 
uint8 minor_ver; 
524
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset

42 
uint32 version_token; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

43 
uint32 tokenbuf[16]; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

44 
int tokenbufpos; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

45 
DestArgInfo dest_arg; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

46 
uint32 *output; 
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

47 
uint32 *token_to_line; 
524
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset

48 
uint8 *ctab; 
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset

49 
uint32 ctab_len; 
03eea2f0762c
First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents:
523
diff
changeset

50 
uint32 ctab_allocation; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

51 
size_t output_len; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

52 
size_t output_allocation; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

53 
}; 
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 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

56 
// Convenience functions for allocators... 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

57 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

58 
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

59 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

60 
if (ctx>failstr == NULL) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

61 
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

62 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

63 
} // out_of_memory 
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 
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

66 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

67 
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

68 
if (retval == NULL) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

69 
out_of_memory(ctx); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

70 
return retval; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

71 
} // Malloc 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

72 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

73 
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

74 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

75 
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

76 
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

77 
} // Free 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

78 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

79 
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

80 
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

81 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

82 
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

83 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

84 
char scratch = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

85 
va_list ap; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

86 
va_start(ap, fmt); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

87 
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

88 
va_end(ap); 
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 
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

91 
if (failstr != NULL) 
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 
va_start(ap, fmt); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

94 
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

95 
va_end(ap); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

96 
ctx>failstr = failstr; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

97 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

98 
} // if 
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 FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

101 
} // failf 
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 
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

104 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

105 
return failf(ctx, "%s", reason); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

106 
} // fail 
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 
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

109 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

110 
return (ctx>failstr != NULL); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

111 
} // isfail 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

112 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

113 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

114 
static inline int tokeq(const TokenizerContext *tctx, const char *token) 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

115 
{ 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

116 
return (strcasecmp(tctx>token, token) == 0); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

117 
} // tokeq 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

118 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

119 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

120 
// Shader model version magic... 
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 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

123 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

124 
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

125 
} // version_ui32 
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 
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

128 
const uint8 min) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

129 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

130 
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

131 
} // shader_version_atleast 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

132 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

133 
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

134 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

135 
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

136 
} // shader_is_pixel 
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 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

139 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

140 
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

141 
} // shader_is_vertex 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

142 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

143 

482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

144 
static int ui32fromstr(const char *str, uint32 *ui32) 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

145 
{ 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

146 
//*ui32 = (uint32) atoi(minstr); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

147 
char *endptr = NULL; 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

148 
const long val = strtol(str, &endptr, 10); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

149 
*ui32 = (uint32) val; 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

150 
return ((val >= 0) && (*str != '\0') && (*endptr == '\0')); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

151 
} // ui32fromstr 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

152 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

153 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

154 
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

155 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

156 
if (isfail(ctx)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

157 
return; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

158 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

159 
if (ctx>output_len >= ctx>output_allocation) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

160 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

161 
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

162 
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

163 
void *ptr; 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

164 

45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

165 
ptr = Malloc(ctx, newsize * sizeof (uint32)); 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

166 
if (ptr == NULL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

167 
return; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

168 
if (ctx>output_len > 0) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

169 
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

170 
Free(ctx, ctx>output); 
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

171 
ctx>output = (uint32 *) ptr; 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

172 

45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

173 
ptr = Malloc(ctx, newsize * sizeof (uint32)); 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

174 
if (ptr == NULL) 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

175 
return; 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

176 
if (ctx>output_len > 0) 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

177 
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

178 
Free(ctx, ctx>token_to_line); 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

179 
ctx>token_to_line = (uint32 *) ptr; 
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

180 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

181 
ctx>output_allocation = newsize; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

182 
} // if 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

183 

486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

184 
ctx>output[ctx>output_len] = token; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

185 
ctx>token_to_line[ctx>output_len] = ctx>tctx.linenum; 
486
45efac751027
Added error_position to assembly results.
Ryan C. Gordon <icculus@icculus.org>
parents:
485
diff
changeset

186 
ctx>output_len++; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

187 
} // output_token_noswap 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

188 

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 
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

191 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

192 
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

193 
} // output_token 
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 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

196 
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

197 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

198 
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

199 
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

200 
else if (!isfail(ctx)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

201 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

202 
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

203 
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

204 
while (len >= 4) 
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 
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

207 
len = 4; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

208 
buf += 4; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

209 
} // while 
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 
if (len > 0) // handle spillover... 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

212 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

213 
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

214 
overflow.ui32 = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

215 
memcpy(overflow.ui8, buf, len); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

216 
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

217 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

218 
} // else if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

219 
} // output_comment_bytes 
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 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

222 
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

223 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

224 
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

225 
} // output_comment_string 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

226 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

227 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

228 
static int tokenize_ctx(Context *ctx, TokenizerContext *tctx) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

229 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

230 
int idx = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

231 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

232 
if (isfail(ctx)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

233 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

234 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

235 
if (tctx>pushedback) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

236 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

237 
tctx>pushedback = 0; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

238 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

239 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

240 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

241 
if (tctx>on_endline) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

242 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

243 
tctx>on_endline = 0; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

244 
tctx>linenum++; // passed a newline, update. 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

245 
} // if 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

246 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

247 
while (1) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

248 
{ 
477  249 
// !!! FIXME: carefully crafted (but legal) comments can trigger this. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

250 
if (idx >= sizeof (tctx>token)) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

251 
return fail(ctx, "buffer overflow"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

252 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

253 
char ch = *tctx>source; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

254 
if (ch == '\t') 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

255 
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

256 
else if (ch == '\r') 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

257 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

258 
if (tctx>source[1] == '\n') 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

259 
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

260 
ch = '\n'; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

261 
} // else if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

262 

478
af4bfa5d615c
Some basic tokenizer logic fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
477
diff
changeset

263 
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

264 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

265 
// starting a number, but rest of current token was not number. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

266 
if ((idx > 0) && ((tctx>prevchar < '0')  (tctx>prevchar > '9'))) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

267 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

268 
tctx>token[idx++] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

269 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

270 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

271 
} // if 
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 
// starting a nonnumber, but rest of current token was numbers. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

275 
if ((idx > 0) && ((tctx>prevchar >= '0') && (tctx>prevchar <= '9'))) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

276 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

277 
tctx>token[idx++] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

278 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

279 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

280 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

281 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

282 
switch (ch) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

283 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

284 
case '/': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

285 
case ';': // !!! FIXME: comment, right? 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

286 
if (idx != 0) // finish off existing token. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

287 
tctx>token[idx] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

288 
else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

289 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

290 
tctx>token[idx++] = ch; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

291 
tctx>source++; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

292 
if ((ch == '/') && (*tctx>source == '/')) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

293 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

294 
tctx>token[idx++] = '/'; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

295 
tctx>source++; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

296 
} // if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

297 
tctx>token[idx++] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

298 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

299 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

300 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

301 
case ' ': 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

302 
if (tctx>prevchar == ' ') 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

303 
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

304 
// intentional fallthrough... 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

305 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

306 
case '_': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

307 
case '[': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

308 
case ']': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

309 
case '(': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

310 
case ')': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

311 
case '!': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

312 
case '+': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

313 
case '': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

314 
case ',': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

315 
case '.': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

316 
case '\n': 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

317 
if (idx != 0) // finish off existing token. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

318 
tctx>token[idx] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

319 
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

320 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

321 
if (ch == '\n') 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

322 
tctx>on_endline = 1; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

323 
tctx>source++; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

324 
tctx>token[idx++] = ch; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

325 
tctx>token[idx++] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

326 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

327 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

328 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

329 
case '\0': 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

330 
tctx>token[idx] = '\0'; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

331 
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

332 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

333 
return END_OF_STREAM; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

334 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

335 
default: 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

336 
tctx>source++; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

337 
tctx>token[idx++] = ch; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

338 
break; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

339 
} // switch 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

340 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

341 
tctx>prevchar = ch; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

342 
} // while 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

343 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

344 
return fail(ctx, "???"); // shouldn't hit this. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

345 
} // tokenize_ctx 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

346 

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 
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

349 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

350 
const int rc = tokenize_ctx(ctx, &ctx>tctx); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

351 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

352 
#if DEBUG_TOKENIZER 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

353 
printf("TOKENIZE: %s '%s'\n", 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

354 
(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

355 
(rc == FAIL) ? "FAIL" : 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

356 
(rc == NOFAIL) ? "NOFAIL" : "???", 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

357 
(ctx>tctx.token[0] == '\n') ? "\\n" : ctx>tctx.token); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

358 
#endif 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

359 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

360 
return rc; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

361 
} // tokenize 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

362 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

363 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

364 
static int pushback_ctx(Context *ctx, TokenizerContext *tctx) 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

365 
{ 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

366 
if (tctx>pushedback) 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

367 
return fail(ctx, "BUG: Double pushback in parser"); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

368 
else 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

369 
tctx>pushedback = 1; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

370 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

371 
return NOFAIL; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

372 
} 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

373 

490
14b6586d9c43
Fixed parsing of DCL instructions.
Ryan C. Gordon <icculus@icculus.org>
parents:
489
diff
changeset

374 
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

375 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

376 
const int rc = pushback_ctx(ctx, &ctx>tctx); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

377 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

378 
#if DEBUG_TOKENIZER 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

379 
printf("PUSHBACK: %s\n", 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

380 
(rc == END_OF_STREAM) ? "END_OF_STREAM" : 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

381 
(rc == FAIL) ? "FAIL" : 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

382 
(rc == NOFAIL) ? "NOFAIL" : "???"); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

383 
#endif 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

384 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

385 
return rc; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

386 
} // pushback 
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 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

389 
static int nexttoken_ctx(Context *ctx, TokenizerContext *tctx, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

390 
const int ignoreeol, const int ignorewhitespace, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

391 
const int eolok, const int eosok) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

392 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

393 
int rc = NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

394 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

395 
while ((rc = tokenize_ctx(ctx, tctx)) == NOFAIL) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

396 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

397 
if (tokeq(tctx, "\n")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

398 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

399 
if (ignoreeol) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

400 
continue; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

401 
else if (!eolok) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

402 
return fail(ctx, "Unexpected EOL"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

403 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

404 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

405 
else if (tokeq(tctx, " ")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

406 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

407 
if (ignorewhitespace) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

408 
continue; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

409 
} // else if 
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 
// skip comments... 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

412 
else if (tokeq(tctx, "//")  tokeq(tctx, ";")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

413 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

414 
while ((rc = tokenize_ctx(ctx, tctx)) == NOFAIL) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

415 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

416 
if (tokeq(tctx, "\n")) 
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset

417 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

418 
pushback_ctx(ctx, tctx); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

419 
break; 
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset

420 
} // if 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

421 
} // while 
479
f7beff48de5e
nexttoken() needs to report the ending newline when throwing away comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
478
diff
changeset

422 
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

423 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

424 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

425 
break; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

426 
} // while 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

427 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

428 
if ((rc == END_OF_STREAM) && (!eosok)) 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

429 
return fail(ctx, "Unexpected EOF"); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

430 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

431 
return rc; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

432 
} // nexttoken_ctx 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

433 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

434 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

435 
static inline int nexttoken(Context *ctx, const int ignoreeol, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

436 
const int ignorewhitespace, const int eolok, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

437 
const int eosok) 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

438 
{ 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

439 
const int rc = nexttoken_ctx(ctx, &ctx>tctx, ignoreeol, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

440 
ignorewhitespace, eolok, eosok); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

441 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

442 
#if DEBUG_TOKENIZER 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

443 
printf("NEXTTOKEN: %s '%s'\n", 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

444 
(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

445 
(rc == FAIL) ? "FAIL" : 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

446 
(rc == NOFAIL) ? "NOFAIL" : "???", 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

447 
(ctx>tctx.token[0] == '\n') ? "\\n" : ctx>tctx.token); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

448 
#endif 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

449 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

450 
return rc; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

451 
} // nexttoken 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

452 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

453 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

454 
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

455 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

456 
TokenizerContext *tctx = &ctx>tctx; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

457 
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

458 
if (rc == FAIL) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

459 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

460 
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

461 
return NOFAIL; // we'll call this an EOL. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

462 
else if (!tokeq(tctx, "\n")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

463 
return fail(ctx, "Endline expected"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

464 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

465 
} // require_endline 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

466 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

467 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

468 
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

469 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

470 
TokenizerContext *tctx = &ctx>tctx; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

471 
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

472 
if (rc == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

473 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

474 
else if (!tokeq(tctx, ",")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

475 
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

476 
return NOFAIL; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

477 
} // require_comma 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

478 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

479 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

480 
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

481 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

482 
TokenizerContext *tctx = &ctx>tctx; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

483 
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

484 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

485 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

486 
int neednum = 1; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

487 
int regnum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

488 
RegisterType regtype = REG_TYPE_TEMP; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

489 
if (tokeq(tctx, "r")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

490 
regtype = REG_TYPE_TEMP; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

491 
else if (tokeq(tctx, "v")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

492 
regtype = REG_TYPE_INPUT; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

493 
else if (tokeq(tctx, "c")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

494 
regtype = REG_TYPE_CONST; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

495 
else if (tokeq(tctx, "i")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

496 
regtype = REG_TYPE_CONSTINT; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

497 
else if (tokeq(tctx, "b")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

498 
regtype = REG_TYPE_CONSTBOOL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

499 
else if (tokeq(tctx, "oC")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

500 
regtype = REG_TYPE_COLOROUT; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

501 
else if (tokeq(tctx, "s")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

502 
regtype = REG_TYPE_SAMPLER; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

503 
else if (tokeq(tctx, "oD")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

504 
regtype = REG_TYPE_ATTROUT; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

505 
else if (tokeq(tctx, "l")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

506 
regtype = REG_TYPE_LABEL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

507 
else if (tokeq(tctx, "p")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

508 
regtype = REG_TYPE_PREDICATE; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

509 
else if (tokeq(tctx, "oDepth")) 
513
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset

510 
{ 
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset

511 
regtype = REG_TYPE_DEPTHOUT; 
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset

512 
neednum = 0; 
abd9c85ba168
oDepth register doesn't have an index.
Ryan C. Gordon <icculus@icculus.org>
parents:
512
diff
changeset

513 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

514 
else if (tokeq(tctx, "aL")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

515 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

516 
regtype = REG_TYPE_LOOP; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

517 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

518 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

519 
else if (tokeq(tctx, "o")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

520 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

521 
if (!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

522 
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

523 
regtype = REG_TYPE_OUTPUT; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

524 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

525 
else if (tokeq(tctx, "oT")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

526 
{ 
502
3cb501248990
Fixed logic error in assembler, to decide if oTx registers are available.
Ryan C. Gordon <icculus@icculus.org>
parents:
500
diff
changeset

527 
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

528 
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

529 
regtype = REG_TYPE_OUTPUT; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

530 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

531 
else if (tokeq(tctx, "a")) 
465
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 
if (!shader_is_vertex(ctx)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

534 
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

535 
regtype = REG_TYPE_ADDRESS; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

536 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

537 
else if (tokeq(tctx, "t")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

538 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

539 
if (!shader_is_pixel(ctx)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

540 
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

541 
regtype = REG_TYPE_ADDRESS; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

542 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

543 
else if (tokeq(tctx, "vPos")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

544 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

545 
regtype = REG_TYPE_MISCTYPE; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

546 
regnum = (int) MISCTYPE_TYPE_POSITION; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

547 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

548 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

549 
else if (tokeq(tctx, "vFace")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

550 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

551 
regtype = REG_TYPE_MISCTYPE; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

552 
regnum = (int) MISCTYPE_TYPE_FACE; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

553 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

554 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

555 
else if (tokeq(tctx, "oPos")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

556 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

557 
regtype = REG_TYPE_RASTOUT; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

558 
regnum = (int) RASTOUT_TYPE_POSITION; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

559 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

560 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

561 
else if (tokeq(tctx, "oFog")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

562 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

563 
regtype = REG_TYPE_RASTOUT; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

564 
regnum = (int) RASTOUT_TYPE_FOG; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

565 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

566 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

567 
else if (tokeq(tctx, "oPts")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

568 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

569 
regtype = REG_TYPE_RASTOUT; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

570 
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

571 
neednum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

572 
} // else if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

573 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

574 
//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

575 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

576 
else 
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 
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

579 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

580 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

581 
if (neednum) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

582 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

583 
// Make a temp TokenizerContext, since we need to skip whitespace here, 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

584 
// but if the next nonwhitespace token isn't '[', we'll want to get 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

585 
// that whitespace back. 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

586 
TokenizerContext tmptctx; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

587 
memcpy(&tmptctx, tctx, sizeof (TokenizerContext)); 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

588 
if (nexttoken_ctx(ctx, &tmptctx, 0, 1, 1, 1) == FAIL) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

589 
return FAIL; 
522
3c08f4d2aa2e
Fixed relative addressing parsing, again.
Ryan C. Gordon <icculus@icculus.org>
parents:
521
diff
changeset

590 
else if (tokeq(&tmptctx, "[")) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

591 
neednum = 0; 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

592 
} // if 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

593 

3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

594 
if (neednum) 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

595 
{ 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

596 
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

597 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

598 

482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

599 
uint32 ui32 = 0; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

600 
if (!ui32fromstr(tctx>token, &ui32)) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

601 
return fail(ctx, "Invalid register index"); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

602 
regnum = (int) ui32; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

603 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

604 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

605 
// split up REG_TYPE_CONST 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

606 
if (regtype == REG_TYPE_CONST) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

607 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

608 
if (regnum < 2048) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

609 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

610 
regtype = REG_TYPE_CONST; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

611 
regnum = 0; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

612 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

613 
else if (regnum < 4096) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

614 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

615 
regtype = REG_TYPE_CONST2; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

616 
regnum = 2048; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

617 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

618 
else if (regnum < 6144) 
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 
regtype = REG_TYPE_CONST3; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

621 
regnum = 4096; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

622 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

623 
else if (regnum < 8192) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

624 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

625 
regtype = REG_TYPE_CONST4; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

626 
regnum = 6144; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

627 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

628 
else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

629 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

630 
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

631 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

632 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

633 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

634 
*rtype = regtype; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

635 
*rnum = regnum; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

636 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

637 
return NOFAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

638 
} // parse_register_name 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

639 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

640 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

641 
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

642 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

643 
if (info>result_shift != 0) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

644 
return fail(ctx, "Multiple result shift modifiers"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

645 
info>result_shift = val; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

646 
return NOFAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

647 
} // set_result_shift 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

648 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

649 

515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

650 
static int parse_destination_token(Context *ctx) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

651 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

652 
TokenizerContext *tctx = &ctx>tctx; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

653 

58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

654 
DestArgInfo *info = &ctx>dest_arg; 
510
f4433db86f6e
Fixed wrong sizeof for a memset() call.
Ryan C. Gordon <icculus@icculus.org>
parents:
508
diff
changeset

655 
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

656 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

657 
// 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

658 
while (1) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

659 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

660 
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

661 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

662 
else if (tokeq(tctx, " ")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

663 
break; // done with modifiers. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

664 
else if (!tokeq(tctx, "_")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

665 
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

666 
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

667 
return FAIL; 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

668 
// !!! FIXME: this can be cleaned up when tokenizer is fixed. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

669 
else if (tokeq(tctx, "x")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

670 
{ 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

671 
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

672 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

673 
else if (tokeq(tctx, "2")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

674 
set_result_shift(ctx, info, 0x1); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

675 
else if (tokeq(tctx, "4")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

676 
set_result_shift(ctx, info, 0x2); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

677 
else if (tokeq(tctx, "8")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

678 
set_result_shift(ctx, info, 0x3); 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

679 
else 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

680 
return fail(ctx, "Expected modifier"); 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

681 
} // else if 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

682 
// !!! FIXME: this can be cleaned up when tokenizer is fixed. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

683 
else if (tokeq(tctx, "d")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

684 
{ 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

685 
if (nexttoken(ctx, 0, 0, 0, 0) == FAIL) 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

686 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

687 
else if (tokeq(tctx, "8")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

688 
set_result_shift(ctx, info, 0xD); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

689 
else if (tokeq(tctx, "4")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

690 
set_result_shift(ctx, info, 0xE); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

691 
else if (tokeq(tctx, "2")) 
511
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

692 
set_result_shift(ctx, info, 0xF); 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

693 
else 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

694 
return fail(ctx, "Expected modifier"); 
67d7efa9206b
Corrected parsing of result modifiers for my stupid tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
510
diff
changeset

695 
} // else if 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

696 
else if (tokeq(tctx, "sat")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

697 
info>result_mod = MOD_SATURATE; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

698 
else if (tokeq(tctx, "pp")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

699 
info>result_mod = MOD_PP; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

700 
else if (tokeq(tctx, "centroid")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

701 
info>result_mod = MOD_CENTROID; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

702 
else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

703 
return fail(ctx, "Expected modifier"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

704 
} // while 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

705 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

706 
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

707 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

708 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

709 
// !!! FIXME: predicates. 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

710 
if (tokeq(tctx, "(")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

711 
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

712 
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

713 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

714 
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

715 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

716 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

717 
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

718 
return FAIL; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

719 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

720 
// !!! 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

721 

521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

722 
int implicit_writemask = 0; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

723 
if (!tokeq(tctx, ".")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

724 
{ 
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

725 
implicit_writemask = 1; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

726 
info>writemask = 0xF; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

727 
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

728 
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

729 
} // if 
521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

730 
// !!! FIXME: Cg generates code with oDepth.z ... this is a bug, I think. 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

731 
//else if (scalar_register(ctx>shader_type, info>regtype, info>regnum)) 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

732 
else if ( (scalar_register(ctx>shader_type, info>regtype, info>regnum)) && (info>regtype != REG_TYPE_DEPTHOUT) ) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

733 
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

734 
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

735 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

736 
else if (tokeq(tctx, "")) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

737 
return fail(ctx, "Invalid writemask"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

738 
else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

739 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

740 
char *ptr = tctx>token; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

741 
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

742 
if (*ptr == 'x') { info>writemask0 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

743 
if (*ptr == 'y') { info>writemask1 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

744 
if (*ptr == 'z') { info>writemask2 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

745 
if (*ptr == 'w') { info>writemask3 = 1; ptr++; } 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

746 
if ((ptr == tctx>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

747 
{ 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

748 
if (*ptr == 'r') { info>writemask0 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

749 
if (*ptr == 'g') { info>writemask1 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

750 
if (*ptr == 'b') { info>writemask2 = 1; ptr++; } 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

751 
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

752 
} // if 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

753 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

754 
if (*ptr != '\0') 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

755 
return fail(ctx, "Invalid writemask"); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

756 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

757 
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

758 
((info>writemask1 & 0x1) << 1)  
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

759 
((info>writemask2 & 0x1) << 2)  
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

760 
((info>writemask3 & 0x1) << 3) ); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

761 
} // else 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

762 

521
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

763 
// !!! FIXME: Cg generates code with oDepth.z ... this is a bug, I think. 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

764 
if (info>regtype == REG_TYPE_DEPTHOUT) 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

765 
{ 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

766 
if ( (!implicit_writemask) && ((info>writemask0 + info>writemask1 + 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

767 
info>writemask2 + info>writemask3) > 1) ) 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

768 
return fail(ctx, "Writemask specified for scalar register"); 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

769 
} // if 
57e1945104cb
Workaround for incorrect assembly code generated by Cg.
Ryan C. Gordon <icculus@icculus.org>
parents:
519
diff
changeset

770 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

771 
info>orig_writemask = info>writemask; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

772 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

773 
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

774 
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

775 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

776 
ctx>tokenbuf[ctx>tokenbufpos++] = 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

777 
( ((((uint32) 1)) << 31)  
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

778 
((((uint32) info>regnum) & 0x7ff) << 0)  
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

779 
((((uint32) info>relative) & 0x1) << 13)  
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

780 
((((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

781 
((((uint32) info>result_shift) & 0xF) << 24)  
500
38ce929323c2
Fixed writemask bits in assembled bytecode.
Ryan C. Gordon <icculus@icculus.org>
parents:
499
diff
changeset

782 
((((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

783 
((((uint32) info>regtype) & 0x7) << 28)  
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

784 
((((uint32) info>regtype) & 0x18) << 8) ); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

785 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

786 
return 1; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

787 
} // parse_destination_token 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

788 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

789 

472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

790 
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

791 
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

792 
SourceMod *srcmod) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

793 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

794 
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

795 
fail(ctx, "Incompatible source modifiers"); 
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 
*srcmod = ((negate) ? negated : norm); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

798 
} // set_source_mod 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

799 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

800 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

801 
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

802 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

803 
TokenizerContext *tctx = &ctx>tctx; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

804 
int retval = 1; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

805 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

806 
if (ctx>tokenbufpos >= STATICARRAYLEN(ctx>tokenbuf)) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

807 
return fail(ctx, "Too many tokens"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

808 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

809 
// 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

810 
uint32 *token = &ctx>tokenbuf[ctx>tokenbufpos++]; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

811 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

812 
SourceMod srcmod = SRCMOD_NONE; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

813 
int negate = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

814 
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

815 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

816 
else if (tokeq(tctx, "1")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

817 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

818 
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

819 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

820 
else if (!tokeq(tctx, "")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

821 
return fail(ctx, "Unexpected value"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

822 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

823 
srcmod = SRCMOD_COMPLEMENT; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

824 
} // else 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

825 
else if (tokeq(tctx, "!")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

826 
srcmod = SRCMOD_NOT; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

827 
else if (tokeq(tctx, "")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

828 
negate = 1; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

829 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

830 
pushback(ctx); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

831 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

832 
RegisterType regtype; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

833 
int regnum; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

834 
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

835 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

836 
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

837 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

838 
else if (!tokeq(tctx, "_")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

839 
pushback(ctx); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

840 
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

841 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

842 
else if (tokeq(tctx, "bias")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

843 
set_source_mod(ctx, negate, SRCMOD_BIAS, SRCMOD_BIASNEGATE, &srcmod); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

844 
else if (tokeq(tctx, "bx2")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

845 
set_source_mod(ctx, negate, SRCMOD_SIGN, SRCMOD_SIGNNEGATE, &srcmod); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

846 
else if (tokeq(tctx, "x2")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

847 
set_source_mod(ctx, negate, SRCMOD_X2, SRCMOD_X2NEGATE, &srcmod); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

848 
else if (tokeq(tctx, "dz")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

849 
set_source_mod(ctx, negate, SRCMOD_DZ, SRCMOD_NONE, &srcmod); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

850 
else if (tokeq(tctx, "dw")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

851 
set_source_mod(ctx, negate, SRCMOD_DW, SRCMOD_NONE, &srcmod); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

852 
else if (tokeq(tctx, "abs")) 
472
e52d487e6d91
Bunch More Work on the assembler. Feature complete now?
Ryan C. Gordon <icculus@icculus.org>
parents:
470
diff
changeset

853 
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

854 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

855 
return fail(ctx, "Invalid source modifier"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

856 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

857 
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

858 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

859 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

860 
uint32 relative = 0; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

861 
if (!tokeq(tctx, "[")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

862 
pushback(ctx); // not relative addressing? 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

863 
else if (!relok) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

864 
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

865 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

866 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

867 
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

868 
if (rc == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

869 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

870 
retval += rc; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

871 
relative = 1; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

872 
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

873 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

874 
else if (!tokeq(tctx, "+")) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

875 
pushback(ctx); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

876 
else if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

877 
return FAIL; 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

878 
else 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

879 
{ 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

880 
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

881 
fail(ctx, "Relative addressing with explicit register number."); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

882 
uint32 ui32 = 0; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

883 
if (!ui32fromstr(tctx>token, &ui32)) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

884 
return fail(ctx, "Invalid relative addressing offset"); 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

885 
regnum += (int) ui32; 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

886 
} // else 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

887 

3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

888 
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) 
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

889 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

890 
else if (!tokeq(tctx, "]")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

891 
return fail(ctx, "Expected ']'"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

892 
} // else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

893 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

894 
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

895 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

896 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

897 
uint32 swizzle = 0; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

898 
if (!tokeq(tctx, ".")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

899 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

900 
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

901 
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

902 
} // if 
491
bcc3c215807a
Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents:
490
diff
changeset

903 
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

904 
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

905 
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

906 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

907 
else if (tokeq(tctx, "")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

908 
return fail(ctx, "Invalid swizzle"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

909 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

910 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

911 
// deal with shortened form (.x = .xxxx, etc). 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

912 
if (tctx>token[1] == '\0') 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

913 
tctx>token[1] = tctx>token[2] = tctx>token[3] = tctx>token[0]; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

914 
else if (tctx>token[2] == '\0') 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

915 
tctx>token[2] = tctx>token[3] = tctx>token[1]; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

916 
else if (tctx>token[3] == '\0') 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

917 
tctx>token[3] = tctx>token[2]; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

918 
else if (tctx>token[4] != '\0') 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

919 
return fail(ctx, "Invalid swizzle"); 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

920 
tctx>token[4] = '\0'; 
470
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 val; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

923 
int saw_xyzw = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

924 
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

925 
int i; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

926 
for (i = 0; i < 4; i++) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

927 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

928 
const int component = (int) tctx>token[i]; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

929 
switch (component) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

930 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

931 
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

932 
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

933 
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

934 
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

935 
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

936 
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

937 
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

938 
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

939 
default: return fail(ctx, "Invalid swizzle"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

940 
} // switch 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

941 
swizzle = (val << (i * 2)); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

942 
} // for 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

943 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

944 
if (saw_xyzw && saw_rgba) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

945 
return fail(ctx, "Invalid swizzle"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

946 
} // else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

947 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

948 
*token = ( ((((uint32) 1)) << 31)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

949 
((((uint32) regnum) & 0x7ff) << 0)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

950 
((((uint32) relative) & 0x1) << 13)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

951 
((((uint32) swizzle) & 0xFF) << 16)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

952 
((((uint32) srcmod) & 0xF) << 24)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

953 
((((uint32) regtype) & 0x7) << 28)  
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

954 
((((uint32) regtype) & 0x18) << 8) ); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

955 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

956 
return retval; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

957 
} // parse_source_token_maybe_relative 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

958 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

959 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

960 
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

961 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

962 
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

963 
} // parse_source_token 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

964 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

965 

465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

966 
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

967 
{ 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

968 
return (isfail(ctx) ? FAIL : 1); 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

969 
} // parse_args_NULL 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

970 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

971 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

972 
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

973 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

974 
TokenizerContext *tctx = &ctx>tctx; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

975 
int32 negative = 1; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

976 
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

977 
cvt.si32 = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

978 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

979 
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

980 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

981 
else if (tokeq(tctx, "")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

982 
negative = 1; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

983 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

984 
pushback(ctx); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

985 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

986 
uint32 val = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

987 
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

988 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

989 
else if (!ui32fromstr(tctx>token, &val)) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

990 
return fail(ctx, "Expected number"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

991 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

992 
uint32 fraction = 0; 
488
1a318d011c00
Handle endlines on DEF statements.
Ryan C. Gordon <icculus@icculus.org>
parents:
487
diff
changeset

993 
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

994 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

995 
else if (!tokeq(tctx, ".")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

996 
pushback(ctx); // whole number 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

997 
else if (!floatok) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

998 
return fail(ctx, "Expected whole number"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

999 
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

1000 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1001 
else if (!ui32fromstr(tctx>token, &fraction)) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1002 
return fail(ctx, "Expected number"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1003 

492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1004 
uint32 exponent = 0; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1005 
int negexp = 0; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1006 
if (nexttoken(ctx, 0, 1, 1, 1) == FAIL) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1007 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1008 
else if (!tokeq(tctx, "e")) 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1009 
pushback(ctx); 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1010 
else if (!floatok) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1011 
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

1012 
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

1013 
return FAIL; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1014 
else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1015 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1016 
if (!tokeq(tctx, "")) 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1017 
pushback(ctx); 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1018 
else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1019 
negexp = 1; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1020 

29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1021 
if (nexttoken(ctx, 0, 1, 0, 0) == FAIL) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1022 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1023 
else if (!ui32fromstr(tctx>token, &exponent)) 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1024 
return fail(ctx, "Expected exponent"); 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1025 
} // else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1026 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1027 
if (!floatok) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1028 
cvt.si32 = ((int32) val) * negative; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1029 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1030 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1031 
// !!! FIXME: this is lame. 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1032 
char buf[128]; 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1033 
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

1034 
(uint) val, (uint) fraction); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1035 
sscanf(buf, "%f", &cvt.f); 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1036 
cvt.f *= (float) negative; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1037 

29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1038 
if (exponent) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1039 
{ 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1040 
int i; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1041 
if (negexp) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1042 
{ 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1043 
for (i = 0; i > exponent; i) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1044 
cvt.f /= 10.0f; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1045 
} // if 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1046 
else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1047 
{ 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1048 
for (i = 0; i < exponent; i++) 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1049 
cvt.f *= 10.0f; 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1050 
} // else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

1051 
} // if 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1052 
} // else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1053 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1054 
*token = cvt.ui32; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1055 
return NOFAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1056 
} // parse_num 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1057 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1058 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1059 
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

1060 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1061 
if (parse_destination_token(ctx) == FAIL) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1062 
return FAIL; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1063 
else if (require_comma(ctx) == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1064 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1065 
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

1066 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1067 
else if (require_comma(ctx) == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1068 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1069 
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

1070 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1071 
else if (require_comma(ctx) == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1072 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1073 
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

1074 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1075 
else if (require_comma(ctx) == FAIL) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1076 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1077 
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

1078 
return FAIL; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1079 
return 6; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1080 
} // parse_args_DEFx 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1081 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1082 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1083 
static int parse_args_DEF(Context *ctx) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1084 
{ 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1085 
return parse_args_DEFx(ctx, 1); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1086 
} // parse_args_DEF 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1087 

470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1088 

7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1089 
static int parse_args_DEFI(Context *ctx) 
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 
return parse_args_DEFx(ctx, 0); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1092 
} // parse_args_DEFI 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1093 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1094 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1095 
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

1096 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1097 
TokenizerContext *tctx = &ctx>tctx; 
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1098 
if (parse_destination_token(ctx) == FAIL) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1099 
return FAIL; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1100 
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

1101 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1102 
else if (!tokeq(tctx, ",")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1103 
return fail(ctx, "Expected ','"); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1104 
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

1105 
return FAIL; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1106 
else if (tokeq(tctx, "true")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1107 
ctx>tokenbuf[ctx>tokenbufpos++] = 1; 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1108 
else if (tokeq(tctx, "false")) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1109 
ctx>tokenbuf[ctx>tokenbufpos++] = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1110 
else 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1111 
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

1112 
return 3; 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1113 
} // parse_args_DEFB 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1114 

0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1115 

504  1116 
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

1117 
{ 
515
58c1a7d98176
First steps of reworking tokenizer.
Ryan C. Gordon <icculus@icculus.org>
parents:
514
diff
changeset

1118 
TokenizerContext *tctx = &ctx>tctx; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1119 
int i; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

1120 
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

1121 
static const char *usagestrs[] = { 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1122 
"position", "blendweight", "blendindices", "normal", "psize", 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1123 
"texcoord", "tangent", "binormal", "tessfactor", "positiont", 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1124 
"color", "fog", "depth", "sample" 
