tgsi_parse.h revision bdbe77f9c6f06cfaa155f27c2ade3c523d7fbea7
1/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef TGSI_PARSE_H
29#define TGSI_PARSE_H
30
31#include "pipe/p_compiler.h"
32#include "pipe/p_shader_tokens.h"
33
34#if defined __cplusplus
35extern "C" {
36#endif
37
38struct tgsi_full_header
39{
40   struct tgsi_header      Header;
41   struct tgsi_processor   Processor;
42};
43
44struct tgsi_full_dst_register
45{
46   struct tgsi_dst_register               Register;
47   struct tgsi_src_register               Indirect;
48   struct tgsi_dimension                  Dimension;
49   struct tgsi_src_register               DimIndirect;
50};
51
52struct tgsi_full_src_register
53{
54   struct tgsi_src_register         Register;
55   struct tgsi_src_register         Indirect;
56   struct tgsi_dimension            Dimension;
57   struct tgsi_src_register         DimIndirect;
58};
59
60struct tgsi_immediate_array_data
61{
62   union tgsi_immediate_data *u;
63};
64
65struct tgsi_full_declaration
66{
67   struct tgsi_declaration Declaration;
68   struct tgsi_declaration_range Range;
69   struct tgsi_declaration_dimension Dim;
70   struct tgsi_declaration_semantic Semantic;
71   struct tgsi_immediate_array_data ImmediateData;
72   struct tgsi_declaration_resource Resource;
73};
74
75struct tgsi_full_immediate
76{
77   struct tgsi_immediate   Immediate;
78   union tgsi_immediate_data u[4];
79};
80
81struct tgsi_full_property
82{
83   struct tgsi_property   Property;
84   struct tgsi_property_data u[8];
85};
86
87#define TGSI_FULL_MAX_DST_REGISTERS 2
88#define TGSI_FULL_MAX_SRC_REGISTERS 5 /* SAMPLE_D has 5 */
89
90struct tgsi_full_instruction
91{
92   struct tgsi_instruction             Instruction;
93   struct tgsi_instruction_predicate   Predicate;
94   struct tgsi_instruction_label       Label;
95   struct tgsi_instruction_texture     Texture;
96   struct tgsi_full_dst_register       Dst[TGSI_FULL_MAX_DST_REGISTERS];
97   struct tgsi_full_src_register       Src[TGSI_FULL_MAX_SRC_REGISTERS];
98};
99
100union tgsi_full_token
101{
102   struct tgsi_token             Token;
103   struct tgsi_full_declaration  FullDeclaration;
104   struct tgsi_full_immediate    FullImmediate;
105   struct tgsi_full_instruction  FullInstruction;
106   struct tgsi_full_property     FullProperty;
107};
108
109struct tgsi_parse_context
110{
111   const struct tgsi_token    *Tokens;
112   unsigned                   Position;
113   struct tgsi_full_header    FullHeader;
114   union tgsi_full_token      FullToken;
115};
116
117#define TGSI_PARSE_OK      0
118#define TGSI_PARSE_ERROR   1
119
120unsigned
121tgsi_parse_init(
122   struct tgsi_parse_context *ctx,
123   const struct tgsi_token *tokens );
124
125void
126tgsi_parse_free(
127   struct tgsi_parse_context *ctx );
128
129boolean
130tgsi_parse_end_of_tokens(
131   struct tgsi_parse_context *ctx );
132
133void
134tgsi_parse_token(
135   struct tgsi_parse_context *ctx );
136
137static INLINE unsigned
138tgsi_num_tokens(const struct tgsi_token *tokens)
139{
140   struct tgsi_header header;
141   memcpy(&header, tokens, sizeof(header));
142   return header.HeaderSize + header.BodySize;
143}
144
145void
146tgsi_dump_tokens(const struct tgsi_token *tokens);
147
148struct tgsi_token *
149tgsi_dup_tokens(const struct tgsi_token *tokens);
150
151struct tgsi_token *
152tgsi_alloc_tokens(unsigned num_tokens);
153
154
155#if defined __cplusplus
156}
157#endif
158
159#endif /* TGSI_PARSE_H */
160
161