1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "../pp/sl_pp_public.h"
33 #include "../cl/sl_cl_parse.h"
43 struct sl_pp_purify_options options
;
45 char errmsg
[100] = "";
46 unsigned int errline
= 0;
47 struct sl_pp_context
*context
;
48 struct sl_pp_token_info
*tokens
;
50 unsigned int tokens_eaten
;
51 struct sl_pp_token_info
*outtokens
;
54 unsigned char *outbytes
;
55 unsigned int cboutbytes
;
56 unsigned int shader_type
;
62 if (!strcmp(argv
[1], "fragment")) {
64 } else if (!strcmp(argv
[1], "vertex")) {
70 in
= fopen(argv
[2], "rb");
75 fseek(in
, 0, SEEK_END
);
77 fseek(in
, 0, SEEK_SET
);
79 out
= fopen(argv
[3], "w");
85 inbuf
= malloc(size
+ 1);
87 fprintf(out
, "$OOMERROR\n");
94 if (fread(inbuf
, 1, size
, in
) != size
) {
95 fprintf(out
, "$READERROR\n");
106 memset(&options
, 0, sizeof(options
));
108 if (sl_pp_purify(inbuf
, &options
, &outbuf
, errmsg
, sizeof(errmsg
), &errline
)) {
109 fprintf(out
, "$PURIFYERROR %s\n", errmsg
);
118 context
= sl_pp_context_create();
120 fprintf(out
, "$CONTEXERROR\n");
127 if (sl_pp_tokenise(context
, outbuf
, &tokens
)) {
128 fprintf(out
, "$ERROR: `%s'\n", sl_pp_context_error_message(context
));
130 sl_pp_context_destroy(context
);
138 if (sl_pp_version(context
, tokens
, &version
, &tokens_eaten
)) {
139 fprintf(out
, "$ERROR: `%s'\n", sl_pp_context_error_message(context
));
141 sl_pp_context_destroy(context
);
147 if (sl_pp_process(context
, &tokens
[tokens_eaten
], &outtokens
)) {
148 fprintf(out
, "$ERROR: `%s'\n", sl_pp_context_error_message(context
));
150 sl_pp_context_destroy(context
);
158 for (i
= j
= 0; outtokens
[i
].token
!= SL_PP_EOF
; i
++) {
159 switch (outtokens
[i
].token
) {
161 case SL_PP_EXTENSION_REQUIRE
:
162 case SL_PP_EXTENSION_ENABLE
:
163 case SL_PP_EXTENSION_WARN
:
164 case SL_PP_EXTENSION_DISABLE
:
168 outtokens
[j
++] = outtokens
[i
];
171 outtokens
[j
] = outtokens
[i
];
173 if (sl_cl_compile(context
, outtokens
, shader_type
, &outbytes
, &cboutbytes
) == 0) {
175 unsigned int line
= 0;
177 fprintf(out
, "\n/* DO NOT EDIT - THIS FILE IS AUTOMATICALLY GENERATED FROM THE FOLLOWING FILE: */");
178 fprintf(out
, "\n/* %s */", argv
[2]);
179 fprintf(out
, "\n\n");
181 for (i
= 0; i
< cboutbytes
; i
++) {
184 if (outbytes
[i
] < 10) {
186 } else if (outbytes
[i
] < 100) {
191 if (i
< cboutbytes
- 1) {
194 if (line
+ a
>= 100) {
199 fprintf (out
, "%u", outbytes
[i
]);
200 if (i
< cboutbytes
- 1) {
208 sl_pp_context_destroy(context
);