author  Ryan C. Gordon <icculus@icculus.org> 
Mon, 20 Jul 2020 14:54:14 0400  
changeset 1285  1952246ec6cd 
parent 1284  0ed38e8899a3 
child 1287  c5a53296dbd5 
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 

695  10 
// !!! FIXME: this should probably use a formal grammar and not a handwritten 
11 
// !!! FIXME: pile of C code. 

12 

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

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

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

15 

801
6f9625737d41
asm needs bytecode profile
Aras Pranckevicius <aras@unity3d.com>
parents:
798
diff
changeset

16 
#if !SUPPORT_PROFILE_BYTECODE 
6f9625737d41
asm needs bytecode profile
Aras Pranckevicius <aras@unity3d.com>
parents:
798
diff
changeset

17 
#error Shader assembler needs bytecode profile. Fix your build. 
6f9625737d41
asm needs bytecode profile
Aras Pranckevicius <aras@unity3d.com>
parents:
798
diff
changeset

18 
#endif 
6f9625737d41
asm needs bytecode profile
Aras Pranckevicius <aras@unity3d.com>
parents:
798
diff
changeset

19 

716
94a804b54078
Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents:
696
diff
changeset

20 
#if DEBUG_ASSEMBLER_PARSER 
587
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

21 
#define print_debug_token(token, len, val) \ 
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

22 
MOJOSHADER_print_debug_token("ASSEMBLER", token, len, val) 
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

23 
#else 
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

24 
#define print_debug_token(token, len, val) 
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

25 
#endif 
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

26 

566
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset

27 

536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

28 
typedef struct SourcePos 
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

29 
{ 
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

30 
const char *filename; 
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

31 
uint32 line; 
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

32 
} SourcePos; 
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

33 

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

34 

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

35 
// Context...this is state that changes as we assemble a shader... 
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

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

37 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

38 
int isfail; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

42 
void *malloc_data; 
947
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

43 
const char *current_file; 
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

44 
int current_position; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

45 
ErrorList *errors; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

49 
uint8 minor_ver; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

50 
int pushedback; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

51 
const char *token; // assembler token! 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

52 
unsigned int tokenlen; // assembler token! 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

53 
Token tokenval; // assembler token! 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

54 
uint32 version_token; // bytecode token! 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

55 
uint32 tokenbuf[16]; // bytecode tokens! 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

56 
int tokenbufpos; // bytecode tokens! 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

57 
DestArgInfo dest_arg; 
946
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

58 
Buffer *output; 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

59 
Buffer *token_to_source; 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

60 
Buffer *ctab; 
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

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

62 

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

63 

940
bc2a5efade5e
Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents:
939
diff
changeset

64 
// !!! FIXME: cut and paste between every damned source file follows... 
bc2a5efade5e
Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents:
939
diff
changeset

65 
// !!! FIXME: We need to make some sort of ContextBase that applies to all 
bc2a5efade5e
Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents:
939
diff
changeset

66 
// !!! FIXME: files and move this stuff to mojoshader_common.c ... 
bc2a5efade5e
Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents:
939
diff
changeset

67 

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

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

69 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

71 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

76 
{ 
1188
25000edc0176
Move zeromalloc trickery to internal malloc/free functions
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1182
diff
changeset

77 
void *retval = ctx>malloc((int) len, ctx>malloc_data); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

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

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

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

82 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

83 
static inline char *StrDup(Context *ctx, const char *str) 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

84 
{ 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

85 
char *retval = (char *) Malloc(ctx, strlen(str) + 1); 
554  86 
if (retval != NULL) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

87 
strcpy(retval, str); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

88 
return retval; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

89 
} // StrDup 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

90 

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

91 
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

92 
{ 
1188
25000edc0176
Move zeromalloc trickery to internal malloc/free functions
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents:
1182
diff
changeset

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

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

95 

939
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

96 
static void *MallocBridge(int bytes, void *data) 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

97 
{ 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

98 
return Malloc((Context *) data, (size_t) bytes); 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

99 
} // MallocBridge 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

100 

64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

101 
static void FreeBridge(void *ptr, void *data) 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

102 
{ 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

103 
Free((Context *) data, ptr); 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

104 
} // FreeBridge 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

105 

940
bc2a5efade5e
Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents:
939
diff
changeset

106 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

107 
static void failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

108 
static void failf(Context *ctx, const char *fmt, ...) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

109 
{ 
550
2f977a75d2b5
Fixed error reporting in assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
549
diff
changeset

110 
ctx>isfail = 1; 
939
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

111 
if (ctx>out_of_memory) 
64cc93ee5a56
Cutandpaste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents:
840
diff
changeset

112 
return; 
550
2f977a75d2b5
Fixed error reporting in assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
549
diff
changeset

113 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

114 
va_list ap; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

115 
va_start(ap, fmt); 
947
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

116 
errorlist_add_va(ctx>errors, ctx>current_file, ctx>current_position, fmt, ap); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

119 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

120 
static inline void fail(Context *ctx, const char *reason) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

121 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

124 

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

125 
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

126 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

128 
} // isfail 
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 

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

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

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

135 
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

136 
} // version_ui32 
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_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

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

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

141 
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

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

143 

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

144 
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

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

146 
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

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

148 

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

149 
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

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

151 
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

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

153 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

154 
static inline void pushback(Context *ctx) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

155 
{ 
716
94a804b54078
Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents:
696
diff
changeset

156 
#if DEBUG_ASSEMBLER_PARSER 
566
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset

157 
printf("ASSEMBLER PUSHBACK\n"); 
6bd82a5acf62
Added more debug output.
Ryan C. Gordon <icculus@icculus.org>
parents:
562
diff
changeset

158 
#endif 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

159 
assert(!ctx>pushedback); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

160 
ctx>pushedback = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

162 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

163 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

164 
static Token nexttoken(Context *ctx) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

165 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

166 
if (ctx>pushedback) 
690
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

167 
ctx>pushedback = 0; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

168 
else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

169 
{ 
690
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

170 
while (1) 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

171 
{ 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

172 
ctx>token = preprocessor_nexttoken(ctx>preprocessor, 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

173 
&ctx>tokenlen, 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

174 
&ctx>tokenval); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

175 

690
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

176 
if (preprocessor_outofmemory(ctx>preprocessor)) 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

177 
{ 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

178 
ctx>tokenval = TOKEN_EOI; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

179 
ctx>token = NULL; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

180 
ctx>tokenlen = 0; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

181 
break; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

182 
} // if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

183 

947
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

184 
unsigned int line; 
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

185 
ctx>current_file = preprocessor_sourcepos(ctx>preprocessor,&line); 
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

186 
ctx>current_position = (int) line; 
16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

187 

16af6e2b2ada
Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents:
946
diff
changeset

188 
if (ctx>tokenval == TOKEN_BAD_CHARS) 
840
84a0c6807aa8
Report bad characters in the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
801
diff
changeset

189 
{ 
84a0c6807aa8
Report bad characters in the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
801
diff
changeset

190 
fail(ctx, "Bad characters in source file"); 
84a0c6807aa8
Report bad characters in the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
801
diff
changeset

191 
continue; 
84a0c6807aa8
Report bad characters in the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
801
diff
changeset

192 
} // else if 
84a0c6807aa8
Report bad characters in the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
801
diff
changeset

193 

690
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

194 
else if (ctx>tokenval == TOKEN_PREPROCESSING_ERROR) 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

195 
{ 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

196 
fail(ctx, ctx>token); 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

197 
continue; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

198 
} // else if 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

199 

4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

200 
break; 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

201 
} // while 
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

202 
} // else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

203 

587
202354e004fc
Unified some cutandpaste code.
Ryan C. Gordon <icculus@icculus.org>
parents:
586
diff
changeset

204 
print_debug_token(ctx>token, ctx>tokenlen, ctx>tokenval); 
690
4710df464f13
Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
658
diff
changeset

205 
return ctx>tokenval; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

206 
} // nexttoken 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

207 

536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
532
diff
changeset

208 

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

209 
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

210 
{ 
946
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

211 
if (!isfail(ctx)) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

212 
{ 
946
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

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

214 

946
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

215 
// We only need a list of these that grows throughout processing, and 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

216 
// is flattened for reference at the end of the run, so we use a 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

217 
// Buffer. It's sneaky! 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

218 
unsigned int pos = 0; 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

219 
const char *fname = preprocessor_sourcepos(ctx>preprocessor, &pos); 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

220 
SourcePos srcpos; 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

221 
memset(&srcpos, '\0', sizeof (SourcePos)); 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

222 
srcpos.line = pos; 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

223 
srcpos.filename = fname; // cached in preprocessor! 
16fec3a3f687
Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents:
945
diff
changeset

224 
buffer_append(ctx>token_to_source, &srcpos, sizeof (SourcePos)); 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

227 

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

228 

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

229 
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

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

231 
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

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

233 

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

234 

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

235 
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

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

237 
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

238 
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

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

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

241 
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

242 
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

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

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

245 
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

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

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

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

249 

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

250 
if (len > 0) // handle spillover... 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

252 
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

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

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

255 
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

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

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

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

259 

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

260 

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

261 
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

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

263 
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

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

265 

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

266 

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

267 
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

268 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

269 
const Token token = nexttoken(ctx); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

270 
if (token != ((Token) ',')) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

271 
{ 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

272 
fail(ctx, "Comma expected"); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

273 
return 0; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

274 
} // if 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

277 

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

278 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

279 
static int check_token_segment(Context *ctx, const char *str) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

280 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

281 
// !!! FIXME: these are caseinsensitive, right? 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

282 
const size_t len = strlen(str); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

283 
if ( (ctx>tokenlen < len)  (strncasecmp(ctx>token, str, len) != 0) ) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

284 
return 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

285 
ctx>token += len; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

286 
ctx>tokenlen = len; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

287 
return 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

288 
} // check_token_segment 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

289 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

290 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

291 
static int check_token(Context *ctx, const char *str) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

292 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

293 
const size_t len = strlen(str); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

294 
if ( (ctx>tokenlen != len)  (strncasecmp(ctx>token, str, len) != 0) ) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

295 
return 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

296 
ctx>token += len; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

297 
ctx>tokenlen = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

298 
return 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

299 
} // check_token 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

300 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

301 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

302 
static int ui32fromtoken(Context *ctx, uint32 *_val) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

303 
{ 
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

304 
unsigned int i; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

305 
for (i = 0; i < ctx>tokenlen; i++) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

306 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

307 
if ((ctx>token[i] < '0')  (ctx>token[i] > '9')) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

308 
break; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

309 
} // for 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

310 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

311 
if (i == 0) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

312 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

313 
*_val = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

314 
return 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

315 
} // if 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

316 

798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

317 
const unsigned int len = i; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

318 
uint32 val = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

319 
uint32 mult = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

320 
while (i) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

321 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

322 
val += ((uint32) (ctx>token[i]  '0')) * mult; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

323 
mult *= 10; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

324 
} // while 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

325 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

326 
ctx>token += len; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

327 
ctx>tokenlen = len; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

328 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

329 
*_val = val; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

330 
return 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

331 
} // ui32fromtoken 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

332 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

333 

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

334 
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

335 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

336 
if (nexttoken(ctx) != TOKEN_IDENTIFIER) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

337 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

338 
fail(ctx, "Expected register"); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

339 
return 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

341 

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

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

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

344 
RegisterType regtype = REG_TYPE_TEMP; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

345 

573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

346 
// Watch out for substrings! oDepth must be checked before oD, since 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

347 
// the latter will match either case. 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

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

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

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

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

352 
} // else if 
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

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

354 
{ 
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

355 
regtype = REG_TYPE_MISCTYPE; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

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

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

358 
} // else if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

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

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

364 
} // else if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

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

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

370 
} // else if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

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

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

376 
} // else if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

380 
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

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

382 
} // else if 
573
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

383 
else if (check_token_segment(ctx, "aL")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

384 
{ 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

385 
regtype = REG_TYPE_LOOP; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

386 
neednum = 0; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

387 
} // else if 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

388 
else if (check_token_segment(ctx, "oC")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

389 
regtype = REG_TYPE_COLOROUT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

390 
else if (check_token_segment(ctx, "oT")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

391 
regtype = REG_TYPE_OUTPUT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

392 
else if (check_token_segment(ctx, "oD")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

393 
regtype = REG_TYPE_ATTROUT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

394 
else if (check_token_segment(ctx, "r")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

395 
regtype = REG_TYPE_TEMP; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

396 
else if (check_token_segment(ctx, "v")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

397 
regtype = REG_TYPE_INPUT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

398 
else if (check_token_segment(ctx, "c")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

399 
regtype = REG_TYPE_CONST; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

400 
else if (check_token_segment(ctx, "i")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

401 
regtype = REG_TYPE_CONSTINT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

402 
else if (check_token_segment(ctx, "b")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

403 
regtype = REG_TYPE_CONSTBOOL; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

404 
else if (check_token_segment(ctx, "s")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

405 
regtype = REG_TYPE_SAMPLER; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

406 
else if (check_token_segment(ctx, "l")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

407 
regtype = REG_TYPE_LABEL; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

408 
else if (check_token_segment(ctx, "p")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

409 
regtype = REG_TYPE_PREDICATE; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

410 
else if (check_token_segment(ctx, "o")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

411 
regtype = REG_TYPE_OUTPUT; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

412 
else if (check_token_segment(ctx, "a")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

413 
regtype = REG_TYPE_ADDRESS; 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

414 
else if (check_token_segment(ctx, "t")) 
1cd1d99a79cb
Rearrange how we test for register names to avoid substring matches.
Ryan C. Gordon <icculus@icculus.org>
parents:
572
diff
changeset

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

416 

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

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

418 

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

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

420 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

421 
fail(ctx, "expected register type"); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

422 
regtype = REG_TYPE_CONST; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

423 
regnum = 0; 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

426 

570
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset

427 
// "c[5]" is the same as "c5", so if the token is done, see if next is '['. 
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset

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

429 
{ 
1057
4c5cb78c6cdd
Assembler: fixed bug where relative addressing failed parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
994
diff
changeset

430 
const int tlen = ctx>tokenlen; // we need to protect this for later. 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

431 
if (nexttoken(ctx) == ((Token) '[')) 
570
af6bb8728f9e
Fixed register name parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
567
diff
changeset

432 
neednum = 0; // don't need a number on register name itself. 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

433 
pushback(ctx); 
1057
4c5cb78c6cdd
Assembler: fixed bug where relative addressing failed parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
994
diff
changeset

434 
ctx>tokenlen = tlen; 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

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

436 

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

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

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

439 
uint32 ui32 = 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

440 
if (!ui32fromtoken(ctx, &ui32)) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

444 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

469 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

473 

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

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

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

476 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

478 
} // parse_register_name 
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 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

481 
static void set_result_shift(Context *ctx, DestArgInfo *info, const int val) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

483 
if (info>result_shift != 0) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

487 

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

488 

798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

489 
static inline int tokenbuf_overflow(Context *ctx) 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

490 
{ 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

491 
if ( ctx>tokenbufpos >= ((int) (STATICARRAYLEN(ctx>tokenbuf))) ) 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

492 
{ 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

493 
fail(ctx, "Too many tokens"); 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

494 
return 1; 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

495 
} // if 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

496 

5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

497 
return 0; 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

498 
} // tokenbuf_overflow 
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

499 

5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

500 

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

501 
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

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

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

504 
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

505 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

506 
// parse_instruction_token() sets ctx>token to the end of the instruction 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

507 
// so we can see if there are destination modifiers on the instruction 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

508 
// itself... 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

509 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

510 
int invalid_modifier = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

511 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

512 
while ((ctx>tokenlen > 0) && (!invalid_modifier)) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

513 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

514 
if (check_token_segment(ctx, "_x2")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

515 
set_result_shift(ctx, info, 0x1); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

516 
else if (check_token_segment(ctx, "_x4")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

517 
set_result_shift(ctx, info, 0x2); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

518 
else if (check_token_segment(ctx, "_x8")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

519 
set_result_shift(ctx, info, 0x3); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

520 
else if (check_token_segment(ctx, "_d8")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

521 
set_result_shift(ctx, info, 0xD); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

522 
else if (check_token_segment(ctx, "_d4")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

523 
set_result_shift(ctx, info, 0xE); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

524 
else if (check_token_segment(ctx, "_d2")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

525 
set_result_shift(ctx, info, 0xF); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

527 
info>result_mod = MOD_SATURATE; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

529 
info>result_mod = MOD_PP; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

532 
else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

535 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

536 
if (invalid_modifier) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

538 

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

539 
// !!! FIXME: predicates. 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

540 
if (nexttoken(ctx) == ((Token) '(')) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

541 
fail(ctx, "Predicates unsupported at this time"); // !!! FIXME: ... 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

542 

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

543 
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

544 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

545 
parse_register_name(ctx, &info>regtype, &info>regnum); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

546 
// parse_register_name() can't check this: dest regs might have modifiers. 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

547 
if (ctx>tokenlen > 0) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

548 
fail(ctx, "invalid register name"); 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

549 

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

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

551 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

552 
int invalid_writemask = 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

553 
if (nexttoken(ctx) != ((Token) '.')) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

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

556 
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

557 
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

558 
} // if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

559 
else if (nexttoken(ctx) != TOKEN_IDENTIFIER) 
1284
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

560 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

561 
invalid_writemask = 1; 
1284
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

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

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

564 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

565 
char tokenbytes[5] = { '\0', '\0', '\0', '\0', '\0' }; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

566 
const unsigned int tokenlen = ctx>tokenlen; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

567 
memcpy(tokenbytes, ctx>token, ((tokenlen < 4) ? tokenlen : 4)); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

568 
char *ptr = tokenbytes; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

569 

720
7b0bbd985de7
You can mix and match "xyzw" and "rgba" writemasks, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
719
diff
changeset

570 
if ((*ptr == 'r')  (*ptr == 'x')) { info>writemask0 = 1; ptr++; } 
7b0bbd985de7
You can mix and match "xyzw" and "rgba" writemasks, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
719
diff
changeset

571 
if ((*ptr == 'g')  (*ptr == 'y')) { info>writemask1 = 1; ptr++; } 
7b0bbd985de7
You can mix and match "xyzw" and "rgba" writemasks, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
719
diff
changeset

572 
if ((*ptr == 'b')  (*ptr == 'z')) { info>writemask2 = 1; ptr++; } 
7b0bbd985de7
You can mix and match "xyzw" and "rgba" writemasks, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
719
diff
changeset

573 
if ((*ptr == 'a')  (*ptr == 'w')) { info>writemask3 = 1; ptr++; } 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

574 

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

575 
if (*ptr != '\0') 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

576 
invalid_writemask = 1; 
465
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 
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

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

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

581 
((info>writemask3 & 0x1) << 3) ); 
1284
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

582 

0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

583 
// Cg generates code with oDepth.z, and Microsoft's tools accept 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

584 
// oFog.x and probably others. For safety's sake, we'll allow 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

585 
// any single channel to be specified and will just wipe out the 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

586 
// writemask as if it wasn't specified at all. More than one 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

587 
// channel will be a fail, though. 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

588 
if (!invalid_writemask && scalar_register(ctx>shader_type, info>regtype, info>regnum)) 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

589 
{ 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

590 
const int numchans = info>writemask0 + info>writemask1 + info>writemask2 + info>writemask3; 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

591 
if (numchans != 1) 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

592 
fail(ctx, "Nonscalar writemask specified for scalar register"); 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

593 
info>writemask = 0xF; 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

594 
info>writemask0 = info>writemask1 = info>writemask2 = info>writemask3 = 1; 
0ed38e8899a3
Assembler now deals with scalar registers specifying a write mask better.
Ryan C. Gordon <icculus@icculus.org>
parents:
1283
diff
changeset

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

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

597 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

598 
if (invalid_writemask) 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

599 
fail(ctx, "Invalid writemask"); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

600 

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

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

602 

798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

603 
if (tokenbuf_overflow(ctx)) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

605 

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

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

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

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

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

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

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

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

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

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

615 

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

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

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

618 

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

619 

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

620 
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

621 
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

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

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

624 
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

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

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

627 
*srcmod = ((negate) ? negated : norm); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

629 

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

630 

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

631 
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

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

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

634 

798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

635 
if (tokenbuf_overflow(ctx)) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

637 

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

638 
// mark this now, so optional relative addressing token is placed second. 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

639 
uint32 *outtoken = &ctx>tokenbuf[ctx>tokenbufpos++]; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

640 
*outtoken = 0; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

641 

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

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

643 
int negate = 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

644 
Token token = nexttoken(ctx); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

645 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

646 
if (token == ((Token) '!')) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

647 
srcmod = SRCMOD_NOT; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

648 
else if (token == ((Token) '')) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

649 
negate = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

650 
else if ( (token == TOKEN_INT_LITERAL) && (check_token(ctx, "1")) ) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

651 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

652 
if (nexttoken(ctx) != ((Token) '')) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

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

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

657 
else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

659 
pushback(ctx); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

661 

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

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

663 
int regnum; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

664 
parse_register_name(ctx, ®type, ®num); 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

665 

696
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

666 
if (ctx>tokenlen == 0) 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

667 
{ 
696
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

668 
if (negate) 
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

669 
set_source_mod(ctx, negate, SRCMOD_NONE, SRCMOD_NEGATE, &srcmod); 
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

670 
} // if 
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

671 
else 
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

672 
{ 
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

673 
assert(ctx>tokenlen > 0); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

674 
if (check_token_segment(ctx, "_bias")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

675 
set_source_mod(ctx, negate, SRCMOD_BIAS, SRCMOD_BIASNEGATE, &srcmod); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

676 
else if (check_token_segment(ctx, "_bx2")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

677 
set_source_mod(ctx, negate, SRCMOD_SIGN, SRCMOD_SIGNNEGATE, &srcmod); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

678 
else if (check_token_segment(ctx, "_x2")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

679 
set_source_mod(ctx, negate, SRCMOD_X2, SRCMOD_X2NEGATE, &srcmod); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

680 
else if (check_token_segment(ctx, "_dz")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

681 
set_source_mod(ctx, negate, SRCMOD_DZ, SRCMOD_NONE, &srcmod); 
1096
b04fca1befb8
According to MSDN, _db and _da are legit srcmods, identical to _dz and _dw.
Ryan C. Gordon <icculus@icculus.org>
parents:
1057
diff
changeset

682 
else if (check_token_segment(ctx, "_db")) 
b04fca1befb8
According to MSDN, _db and _da are legit srcmods, identical to _dz and _dw.
Ryan C. Gordon <icculus@icculus.org>
parents:
1057
diff
changeset

683 
set_source_mod(ctx, negate, SRCMOD_DZ, SRCMOD_NONE, &srcmod); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

684 
else if (check_token_segment(ctx, "_dw")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

685 
set_source_mod(ctx, negate, SRCMOD_DW, SRCMOD_NONE, &srcmod); 
1096
b04fca1befb8
According to MSDN, _db and _da are legit srcmods, identical to _dz and _dw.
Ryan C. Gordon <icculus@icculus.org>
parents:
1057
diff
changeset

686 
else if (check_token_segment(ctx, "_da")) 
b04fca1befb8
According to MSDN, _db and _da are legit srcmods, identical to _dz and _dw.
Ryan C. Gordon <icculus@icculus.org>
parents:
1057
diff
changeset

687 
set_source_mod(ctx, negate, SRCMOD_DW, SRCMOD_NONE, &srcmod); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

688 
else if (check_token_segment(ctx, "_abs")) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

689 
set_source_mod(ctx, negate, SRCMOD_ABS, SRCMOD_ABSNEGATE, &srcmod); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

690 
else 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

691 
fail(ctx, "Invalid source modifier"); 
696
c9e03dc63eb8
Fixed SRCMOD_NEGATE usage when assembling.
Ryan C. Gordon <icculus@icculus.org>
parents:
695
diff
changeset

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

693 

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

694 
uint32 relative = 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

695 
if (nexttoken(ctx) != ((Token) '[')) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

698 
{ 
1285
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

699 
// quick hack here to make "c[5]" convert to "c5". This will also 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

700 
// work with "c0[5]" but that's possibly illegal...? 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

701 
int skip_relative_parsing = 0; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

702 
if ((regtype == REG_TYPE_CONST) && (regnum == 0)) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

703 
{ 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

704 
uint32 ui32 = 0; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

705 
if (nexttoken(ctx) != TOKEN_INT_LITERAL) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

706 
pushback(ctx); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

707 
else if (!ui32fromtoken(ctx, &ui32)) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

708 
pushback(ctx); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

709 
else 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

710 
{ 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

711 
regnum = ui32; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

712 
skip_relative_parsing = 1; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

713 
} // else 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

714 
} // if 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

715 

1285
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

716 
if (!skip_relative_parsing) 
482
3f740f25bd7e
Fixed relative addressing parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
481
diff
changeset

717 
{ 
1285
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

718 
if (!relok) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

719 
fail(ctx, "Relative addressing not permitted here."); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

720 
else 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

721 
retval++; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

722 

1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

723 
parse_source_token_maybe_relative(ctx, 0); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

724 
relative = 1; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

725 

1285
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

726 
if (nexttoken(ctx) != ((Token) '+')) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

727 
pushback(ctx); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

728 
else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

729 
{ 
1285
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

730 
// !!! FIXME: maybe c3[a0.x + 5] is legal and becomes c[a0.x + 8] ? 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

731 
if (regnum != 0) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

732 
fail(ctx, "Relative addressing with explicit register number."); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

733 

1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

734 
uint32 ui32 = 0; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

735 
if ( (nexttoken(ctx) != TOKEN_INT_LITERAL)  
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

736 
(!ui32fromtoken(ctx, &ui32))  
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

737 
(ctx>tokenlen != 0) ) 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

738 
{ 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

739 
fail(ctx, "Invalid relative addressing offset"); 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

740 
} // if 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

741 
regnum += (int) ui32; 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

742 
} // else 
1952246ec6cd
Assembler now accepts "c[5]" as equivalent to "c5".
Ryan C. Gordon <icculus@icculus.org>
parents:
1284
diff
changeset

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

744 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

745 
if (nexttoken(ctx) != ((Token) ']')) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

748 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

750 
uint32 swizzle = 0; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

751 
if (nexttoken(ctx) != ((Token) '.')) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

753 
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

754 
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

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

756 
else if (scalar_register(ctx>shader_type, regtype, regnum)) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

757 
fail(ctx, "Swizzle specified for scalar register"); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

758 
else if (nexttoken(ctx) != TOKEN_IDENTIFIER) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

761 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

762 
char tokenbytes[5] = { '\0', '\0', '\0', '\0', '\0' }; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

763 
const unsigned int tokenlen = ctx>tokenlen; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

764 
memcpy(tokenbytes, ctx>token, ((tokenlen < 4) ? tokenlen : 4)); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

765 

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

766 
// deal with shortened form (.x = .xxxx, etc). 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

767 
if (tokenlen == 1) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

768 
tokenbytes[1] = tokenbytes[2] = tokenbytes[3] = tokenbytes[0]; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

769 
else if (tokenlen == 2) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

770 
tokenbytes[2] = tokenbytes[3] = tokenbytes[1]; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

771 
else if (tokenlen == 3) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

772 
tokenbytes[3] = tokenbytes[2]; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

773 
else if (tokenlen != 4) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

774 
invalid_swizzle = 1; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

775 
tokenbytes[4] = '\0'; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

776 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

780 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

783 
{ 
718
08e758f9aae3
Apparently you can mix "xyzw" and "rgba" swizzles, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
716
diff
changeset

784 
case 'r': case 'x': val = 0; break; 
08e758f9aae3
Apparently you can mix "xyzw" and "rgba" swizzles, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
716
diff
changeset

785 
case 'g': case 'y': val = 1; break; 
08e758f9aae3
Apparently you can mix "xyzw" and "rgba" swizzles, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
716
diff
changeset

786 
case 'b': case 'z': val = 2; break; 
08e758f9aae3
Apparently you can mix "xyzw" and "rgba" swizzles, even in vertex shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
716
diff
changeset

787 
case 'a': case 'w': val = 3; break; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

788 
default: invalid_swizzle = 1; break; 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

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

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

793 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

794 
if (invalid_swizzle) 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

795 
fail(ctx, "Invalid swizzle"); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

796 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

797 
*outtoken = ( ((((uint32) 1)) << 31)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

798 
((((uint32) regnum) & 0x7ff) << 0)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

799 
((((uint32) relative) & 0x1) << 13)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

800 
((((uint32) swizzle) & 0xFF) << 16)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

801 
((((uint32) srcmod) & 0xF) << 24)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

802 
((((uint32) regtype) & 0x7) << 28)  
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

804 

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

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

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

807 

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

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

811 
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

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

813 

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

814 

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

815 
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

816 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

819 

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

820 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

821 
static int parse_num(Context *ctx, const int floatok, uint32 *value) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

823 
union { float f; int32 si32; uint32 ui32; } cvt; 
572  824 
int negative = 0; 
825 
Token token = nexttoken(ctx); 

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

826 

572  827 
if (token == ((Token) '')) 
828 
{ 

829 
negative = 1; 

830 
token = nexttoken(ctx); 

831 
} // if 

832 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

833 
if (token == TOKEN_INT_LITERAL) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

834 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

835 
int d = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

836 
sscanf(ctx>token, "%d", &d); 
572  837 
if (floatok) 
838 
cvt.f = (float) ((negative) ? d : d); 

839 
else 

840 
cvt.si32 = (int32) ((negative) ? d : d); 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

841 
} // if 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

842 
else if (token == TOKEN_FLOAT_LITERAL) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

843 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

844 
if (!floatok) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

845 
{ 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

846 
fail(ctx, "Expected whole number"); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

847 
*value = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

848 
return 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

849 
} // if 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

850 
sscanf(ctx>token, "%f", &cvt.f); 
572  851 
if (negative) 
852 
cvt.f = cvt.f; 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

853 
} // if 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

854 
else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

855 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

856 
fail(ctx, "Expected number"); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

857 
*value = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

858 
return 0; 
492
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

859 
} // else 
29bfa3448549
Handle exponents in number parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
491
diff
changeset

860 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

861 
*value = cvt.ui32; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

864 

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

865 

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

866 
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

867 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

868 
parse_destination_token(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

869 
require_comma(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

870 
parse_num(ctx, isflt, &ctx>tokenbuf[ctx>tokenbufpos++]); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

871 
require_comma(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

872 
parse_num(ctx, isflt, &ctx>tokenbuf[ctx>tokenbufpos++]); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

873 
require_comma(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

874 
parse_num(ctx, isflt, &ctx>tokenbuf[ctx>tokenbufpos++]); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

875 
require_comma(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

876 
parse_num(ctx, isflt, &ctx>tokenbuf[ctx>tokenbufpos++]); 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

879 

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

880 

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

881 
static int parse_args_DEF(Context *ctx) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

883 
return parse_args_DEFx(ctx, 1); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

885 

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

886 

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

887 
static int parse_args_DEFI(Context *ctx) 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

889 
return parse_args_DEFx(ctx, 0); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

891 

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

892 

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

893 
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

894 
{ 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

895 
parse_destination_token(ctx); 
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

896 
require_comma(ctx); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

897 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

898 
// !!! FIXME: do a TOKEN_TRUE and TOKEN_FALSE? Is this casesensitive? 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

899 
const Token token = nexttoken(ctx); 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

900 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

901 
int bad = 0; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

902 
if (token != TOKEN_IDENTIFIER) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

903 
bad = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

905 
ctx>tokenbuf[ctx>tokenbufpos++] = 1; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

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

908 
else 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

909 
bad = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

910 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

911 
if (ctx>tokenlen != 0) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

912 
bad = 1; 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

913 

c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

914 
if (bad) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

915 
fail(ctx, "Expected 'true' or 'false'"); 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

916 

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

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

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

919 

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

920 

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

922 
{ 
798
5dd67cc04cf9
Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents:
720
diff
changeset

923 
size_t i; 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

924 
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

925 
static const char *usagestrs[] = { 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

926 
"_position", "_blendweight", "_blendindices", "_normal", "_psize", 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

927 
"_texcoord", "_tangent", "_binormal", "_tessfactor", "_positiont", 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

928 
"_color", "_fog", "_depth", "_sample" 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

929 
}; 
504  930 

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

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

932 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

933 
if (check_token_segment(ctx, usagestrs[i])) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

936 
*val = i; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

940 

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

941 
for (i = 0; i < STATICARRAYLEN(samplerusagestrs); i++) 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

942 
{ 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

943 
if (check_token_segment(ctx, samplerusagestrs[i])) 
470
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

946 
*val = i + 2; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

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

950 

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

951 
*issampler = 0; 
ba913834b491
The parse_args_DCL fiasco continues.
Ryan C. Gordon <icculus@icculus.org>
parents:
513
diff
changeset

952 
*val = 0; 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

954 
} // parse_dcl_usage 
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 

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

957 
static int parse_args_DCL(Context *ctx) 
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 
int issampler = 0; 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

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

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

962 

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

963 
ctx>tokenbufpos++; // save a spot for the usage/index token. 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

965 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

966 
// parse_instruction_token() sets ctx>token to the end of the instruction 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

967 
// so we can see if there are destination modifiers on the instruction 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

969 

562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

970 
if (parse_dcl_usage(ctx, &usage, &issampler)) 
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

971 
{ 
575
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset

972 
if ((ctx>tokenlen > 0) && (*ctx>token != '_')) 
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset

973 
{ 
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset

974 
if (!ui32fromtoken(ctx, &index)) 
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset

975 
fail(ctx, "Expected usage index"); 
70bb1ba99a07
Fixed DCL usage index parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
574
diff
changeset

976 
} // if 
562
c9a2bc5129c9
First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents:
558
diff
changeset

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

978 

542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

980 

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

981 
const int samplerreg = (ctx>dest_arg.regtype == REG_TYPE_SAMPLER); 
7d84d3452125
Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents:
465
diff
changeset

982 
if (issampler != samplerreg) 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

985 
ctx>tokenbuf[0] = (usage << 27)  0x80000000; 
1132
b784577caefa
Assembler: Pixel shader DCL opcodes only specify usage for samplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1130
diff
changeset

986 
else if (shader_is_pixel(ctx)) // all other pixel shader types are zero'd. 
b784577caefa
Assembler: Pixel shader DCL opcodes only specify usage for samplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
1130
diff
changeset

987 
ctx>tokenbuf[0] = 0x80000000; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

989 
ctx>tokenbuf[0] = usage  (index << 16)  0x80000000; 
465
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

990 

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

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

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

993 

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

994 

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

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

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

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

998 
retval += parse_destination_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1001 

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

1002 

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

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

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

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

1006 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1009 

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

1010 

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

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

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

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

1014 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1016 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1019 

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

1020 

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

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

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

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

1024 
retval += parse_destination_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1026 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1029 

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

1030 

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

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

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

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

1034 
retval += parse_destination_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1036 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1038 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1041 

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

1042 

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

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

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

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

1046 
retval += parse_destination_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1048 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1050 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1052 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1055 

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

1056 

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

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

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

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

1060 
retval += parse_destination_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1062 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1064 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1066 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

1068 
retval += parse_source_token(ctx); 
542
a56d3bfd2e36
More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents:
539
diff
changeset

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

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

1071 

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

1072 

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

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

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

1075 
// this opcode needs extra registers for sm2 and lower. 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

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

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

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

1080 

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

1081 

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

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

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

1084 
// added extra register in ps_1_4. 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

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

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

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

1089 

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

1090 

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

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

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

1093 
// different registers in px_1_3, ps_1_4, and ps_2_0! 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

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

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

1096 
else if (shader_version_atleast(ctx, 1, 4)) 
0a75f98f785b
Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1097 