tgsi_parse.h revision c398f1544ea113279e5f038f4a643005743cab62
1ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com/**************************************************************************
2ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com *
3ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * All Rights Reserved.
5ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com *
6ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * Permission is hereby granted, free of charge, to any person obtaining a
7ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * copy of this software and associated documentation files (the
8ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * "Software"), to deal in the Software without restriction, including
9ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * without limitation the rights to use, copy, modify, merge, publish,
10ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * distribute, sub license, and/or sell copies of the Software, and to
11ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * permit persons to whom the Software is furnished to do so, subject to
12e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com * the following conditions:
13e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com *
14607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * The above copyright notice and this permission notice (including the
15607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * next paragraph) shall be included in all copies or substantial portions
162d537a18f49cb492358c2b051f4786075dd9406cchudy@google.com * of the Software.
172d537a18f49cb492358c2b051f4786075dd9406cchudy@google.com *
182d537a18f49cb492358c2b051f4786075dd9406cchudy@google.com * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19830b8793bb1646bb76817bdc228dd8e2a92bef7dchudy@google.com * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com *
26830b8793bb1646bb76817bdc228dd8e2a92bef7dchudy@google.com **************************************************************************/
27ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com
28ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com#ifndef TGSI_PARSE_H
29fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org#define TGSI_PARSE_H
30fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org
31fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org#include "pipe/p_compiler.h"
32fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org#include "pipe/p_shader_tokens.h"
33fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org
34fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org#if defined __cplusplus
35fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.orgextern "C" {
36fde1e7ccb4524aa2e0c42872e529ee25d09e7f34commit-bot@chromium.org#endif
37ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com
38ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comstruct tgsi_full_header
390b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com{
400b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_header      Header;
410b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_processor   Processor;
42fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org};
43fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org
44fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.orgstruct tgsi_full_dst_register
45fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org{
4616e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com   struct tgsi_dst_register               Register;
4716e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com   struct tgsi_src_register               Indirect;
486577cd37c73bd6e3bbdb7b7af2fc625a2cd69b39robertphillips@google.com   struct tgsi_dimension                  Dimension;
4916e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com   struct tgsi_src_register               DimIndirect;
50ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com};
51830b8793bb1646bb76817bdc228dd8e2a92bef7dchudy@google.com
52ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comstruct tgsi_full_src_register
53ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com{
54ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_src_register         Register;
55ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_src_register         Indirect;
560b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_dimension            Dimension;
57fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org   struct tgsi_src_register         DimIndirect;
58fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org};
59fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org
60fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.orgstruct tgsi_immediate_array_data
61fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org{
62fae599b4a642aae776966b0f2ea67e2fdf4d6a65commit-bot@chromium.org   union tgsi_immediate_data *u;
630b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com};
640b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com
650b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.comstruct tgsi_full_declaration
660b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com{
670b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_declaration Declaration;
680b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_declaration_range Range;
690b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_declaration_dimension Dim;
700b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_declaration_semantic Semantic;
71607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com   struct tgsi_immediate_array_data ImmediateData;
72607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com};
73ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com
74ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comstruct tgsi_full_immediate
75ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com{
760b4d6b289c89f0b6c6891e2fb812fa3614cb55a2bungeman@google.com   struct tgsi_immediate   Immediate;
77607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com   union tgsi_immediate_data u[4];
78607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com};
79607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
80607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.comstruct tgsi_full_property
81607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com{
82ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_property   Property;
83ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_property_data u[8];
8416e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com};
8516e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com
86e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com#define TGSI_FULL_MAX_DST_REGISTERS 2
87e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com#define TGSI_FULL_MAX_SRC_REGISTERS 4 /* TXD has 4 */
88fec0bc3fc13481f5bcb341ab2d2d695911f39bd4bsalomon@google.com
89ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comstruct tgsi_full_instruction
90ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com{
91ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_instruction             Instruction;
92ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_instruction_predicate   Predicate;
93ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_instruction_label       Label;
94ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_instruction_texture     Texture;
95ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_full_dst_register       Dst[TGSI_FULL_MAX_DST_REGISTERS];
96ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com   struct tgsi_full_src_register       Src[TGSI_FULL_MAX_SRC_REGISTERS];
97e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com};
98e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com
99union tgsi_full_token
100{
101   struct tgsi_token             Token;
102   struct tgsi_full_declaration  FullDeclaration;
103   struct tgsi_full_immediate    FullImmediate;
104   struct tgsi_full_instruction  FullInstruction;
105   struct tgsi_full_property     FullProperty;
106};
107
108struct tgsi_parse_context
109{
110   const struct tgsi_token    *Tokens;
111   unsigned                   Position;
112   struct tgsi_full_header    FullHeader;
113   union tgsi_full_token      FullToken;
114};
115
116#define TGSI_PARSE_OK      0
117#define TGSI_PARSE_ERROR   1
118
119unsigned
120tgsi_parse_init(
121   struct tgsi_parse_context *ctx,
122   const struct tgsi_token *tokens );
123
124void
125tgsi_parse_free(
126   struct tgsi_parse_context *ctx );
127
128boolean
129tgsi_parse_end_of_tokens(
130   struct tgsi_parse_context *ctx );
131
132void
133tgsi_parse_token(
134   struct tgsi_parse_context *ctx );
135
136static INLINE unsigned
137tgsi_num_tokens(const struct tgsi_token *tokens)
138{
139   struct tgsi_header header;
140   memcpy(&header, tokens, sizeof(header));
141   return header.HeaderSize + header.BodySize;
142}
143
144void
145tgsi_dump_tokens(const struct tgsi_token *tokens);
146
147struct tgsi_token *
148tgsi_dup_tokens(const struct tgsi_token *tokens);
149
150struct tgsi_token *
151tgsi_alloc_tokens(unsigned num_tokens);
152
153
154#if defined __cplusplus
155}
156#endif
157
158#endif /* TGSI_PARSE_H */
159
160