summaryrefslogtreecommitdiff
path: root/src/glsl/pp
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl/pp')
-rw-r--r--src/glsl/pp/sl_pp_context.c3
-rw-r--r--src/glsl/pp/sl_pp_context.h3
-rw-r--r--src/glsl/pp/sl_pp_define.c1
-rw-r--r--src/glsl/pp/sl_pp_error.c1
-rw-r--r--src/glsl/pp/sl_pp_extension.c1
-rw-r--r--src/glsl/pp/sl_pp_line.c1
-rw-r--r--src/glsl/pp/sl_pp_macro.c1
-rw-r--r--src/glsl/pp/sl_pp_pragma.c1
-rw-r--r--src/glsl/pp/sl_pp_process.c116
-rw-r--r--src/glsl/pp/sl_pp_process.h3
-rw-r--r--src/glsl/pp/sl_pp_public.h4
11 files changed, 95 insertions, 40 deletions
diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c
index c1cef41bce..74a9bdddfd 100644
--- a/src/glsl/pp/sl_pp_context.c
+++ b/src/glsl/pp/sl_pp_context.c
@@ -69,6 +69,8 @@ sl_pp_context_create(const char *input,
sl_pp_purify_state_init(&context->pure, input, options);
+ memset(&context->process_state, 0, sizeof(context->process_state));
+
return context;
}
@@ -80,6 +82,7 @@ sl_pp_context_destroy(struct sl_pp_context *context)
sl_pp_macro_free(context->macro);
free(context->getc_buf);
sl_pp_token_buffer_destroy(&context->tokens);
+ free(context->process_state.out);
free(context);
}
}
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index 5e1c563048..3eada380cd 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -30,6 +30,7 @@
#include "sl_pp_dict.h"
#include "sl_pp_macro.h"
+#include "sl_pp_process.h"
#include "sl_pp_purify.h"
#include "sl_pp_token_util.h"
@@ -84,6 +85,8 @@ struct sl_pp_context {
unsigned int getc_buf_capacity;
struct sl_pp_token_buffer tokens;
+
+ struct sl_pp_process_state process_state;
};
#endif /* SL_PP_CONTEXT_H */
diff --git a/src/glsl/pp/sl_pp_define.c b/src/glsl/pp/sl_pp_define.c
index e004c9f95b..808a6a0d4f 100644
--- a/src/glsl/pp/sl_pp_define.c
+++ b/src/glsl/pp/sl_pp_define.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_process.h"
#include "sl_pp_public.h"
diff --git a/src/glsl/pp/sl_pp_error.c b/src/glsl/pp/sl_pp_error.c
index a9eeff98ba..b628e37ce8 100644
--- a/src/glsl/pp/sl_pp_error.c
+++ b/src/glsl/pp/sl_pp_error.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_process.h"
#include "sl_pp_public.h"
diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c
index 67b24404d4..8af5731e84 100644
--- a/src/glsl/pp/sl_pp_extension.c
+++ b/src/glsl/pp/sl_pp_extension.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_process.h"
#include "sl_pp_public.h"
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index 87987fc2ba..6f7e9eb562 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_public.h"
#include "sl_pp_process.h"
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index c98ab6559a..9f520b8fc5 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_public.h"
#include "sl_pp_macro.h"
#include "sl_pp_process.h"
diff --git a/src/glsl/pp/sl_pp_pragma.c b/src/glsl/pp/sl_pp_pragma.c
index 489eb17b8e..caf4c63f65 100644
--- a/src/glsl/pp/sl_pp_pragma.c
+++ b/src/glsl/pp/sl_pp_pragma.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_process.h"
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index 6dcd0ab401..563ea948e7 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include "sl_pp_context.h"
#include "sl_pp_process.h"
#include "sl_pp_public.h"
@@ -58,34 +59,47 @@ sl_pp_process_out(struct sl_pp_process_state *state,
}
int
-sl_pp_process(struct sl_pp_context *context,
- struct sl_pp_token_info **output)
+sl_pp_process_get(struct sl_pp_context *context,
+ struct sl_pp_token_info *output)
{
- struct sl_pp_process_state state;
- int found_eof = 0;
-
- memset(&state, 0, sizeof(state));
-
- if (context->line > 1) {
- struct sl_pp_token_info ti;
-
- ti.token = SL_PP_LINE;
- ti.data.line.lineno = context->line - 1;
- ti.data.line.fileno = context->file;
- if (sl_pp_process_out(&state, &ti)) {
- strcpy(context->error_msg, "out of memory");
- return -1;
- }
+ if (!context->process_state.out) {
+ if (context->line > 1) {
+ struct sl_pp_token_info ti;
+
+ ti.token = SL_PP_LINE;
+ ti.data.line.lineno = context->line - 1;
+ ti.data.line.fileno = context->file;
+ if (sl_pp_process_out(&context->process_state, &ti)) {
+ strcpy(context->error_msg, "out of memory");
+ return -1;
+ }
- ti.token = SL_PP_NEWLINE;
- if (sl_pp_process_out(&state, &ti)) {
- strcpy(context->error_msg, "out of memory");
- return -1;
+ ti.token = SL_PP_NEWLINE;
+ if (sl_pp_process_out(&context->process_state, &ti)) {
+ strcpy(context->error_msg, "out of memory");
+ return -1;
+ }
}
}
- while (!found_eof) {
+ for (;;) {
struct sl_pp_token_info input;
+ int found_eof = 0;
+
+ if (context->process_state.out_len) {
+ *output = context->process_state.out[0];
+
+ if (context->process_state.out_len > 1) {
+ unsigned int i;
+
+ for (i = 1; i < context->process_state.out_len; i++) {
+ context->process_state.out[i - 1] = context->process_state.out[i];
+ }
+ }
+ context->process_state.out_len--;
+
+ return 0;
+ }
if (sl_pp_token_buffer_skip_white(&context->tokens, &input)) {
return -1;
@@ -101,7 +115,7 @@ sl_pp_process(struct sl_pp_context *context,
int found_eol = 0;
struct sl_pp_token_info endof;
struct sl_pp_token_peek peek;
- int result;
+ int result = 0;
/* Directive name. */
name = input.data.identifier;
@@ -166,17 +180,17 @@ sl_pp_process(struct sl_pp_context *context,
sl_pp_process_error(context, peek.tokens, 0, peek.size - 1);
result = -1;
} else if (name == context->dict.extension) {
- result = sl_pp_process_extension(context, peek.tokens, 0, peek.size - 1, &state);
+ result = sl_pp_process_extension(context, peek.tokens, 0, peek.size - 1, &context->process_state);
} else if (name == context->dict.line) {
struct sl_pp_token_buffer buffer;
result = sl_pp_token_peek_to_buffer(&peek, &buffer);
if (result == 0) {
- result = sl_pp_process_line(context, &buffer, &state);
+ result = sl_pp_process_line(context, &buffer, &context->process_state);
sl_pp_token_buffer_destroy(&buffer);
}
} else if (name == context->dict.pragma) {
- result = sl_pp_process_pragma(context, peek.tokens, 0, peek.size - 1, &state);
+ result = sl_pp_process_pragma(context, peek.tokens, 0, peek.size - 1, &context->process_state);
} else if (name == context->dict.undef) {
result = sl_pp_process_undef(context, peek.tokens, 0, peek.size - 1);
} else {
@@ -192,7 +206,7 @@ sl_pp_process(struct sl_pp_context *context,
return result;
}
- if (sl_pp_process_out(&state, &endof)) {
+ if (sl_pp_process_out(&context->process_state, &endof)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -202,7 +216,7 @@ sl_pp_process(struct sl_pp_context *context,
case SL_PP_NEWLINE:
/* Empty directive. */
- if (sl_pp_process_out(&state, &input)) {
+ if (sl_pp_process_out(&context->process_state, &input)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -211,7 +225,7 @@ sl_pp_process(struct sl_pp_context *context,
case SL_PP_EOF:
/* Empty directive. */
- if (sl_pp_process_out(&state, &input)) {
+ if (sl_pp_process_out(&context->process_state, &input)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -239,7 +253,7 @@ sl_pp_process(struct sl_pp_context *context,
case SL_PP_NEWLINE:
/* Preserve newline just for the sake of line numbering. */
- if (sl_pp_process_out(&state, &input)) {
+ if (sl_pp_process_out(&context->process_state, &input)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -248,7 +262,7 @@ sl_pp_process(struct sl_pp_context *context,
break;
case SL_PP_EOF:
- if (sl_pp_process_out(&state, &input)) {
+ if (sl_pp_process_out(&context->process_state, &input)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -258,7 +272,7 @@ sl_pp_process(struct sl_pp_context *context,
case SL_PP_IDENTIFIER:
sl_pp_token_buffer_unget(&context->tokens, &input);
- if (sl_pp_macro_expand(context, &context->tokens, NULL, &state,
+ if (sl_pp_macro_expand(context, &context->tokens, NULL, &context->process_state,
context->if_value ? sl_pp_macro_expand_normal : sl_pp_macro_expand_mute)) {
return -1;
}
@@ -266,7 +280,7 @@ sl_pp_process(struct sl_pp_context *context,
default:
if (context->if_value) {
- if (sl_pp_process_out(&state, &input)) {
+ if (sl_pp_process_out(&context->process_state, &input)) {
strcpy(context->error_msg, "out of memory");
return -1;
}
@@ -274,13 +288,37 @@ sl_pp_process(struct sl_pp_context *context,
}
}
}
- }
- if (context->if_ptr != SL_PP_MAX_IF_NESTING) {
- strcpy(context->error_msg, "expected `#endif' directive");
- return -1;
+ if (found_eof) {
+ if (context->if_ptr != SL_PP_MAX_IF_NESTING) {
+ strcpy(context->error_msg, "expected `#endif' directive");
+ return -1;
+ }
+ }
}
+}
- *output = state.out;
- return 0;
+int
+sl_pp_process(struct sl_pp_context *context,
+ struct sl_pp_token_info **output)
+{
+ struct sl_pp_process_state state;
+
+ memset(&state, 0, sizeof(state));
+ for (;;) {
+ struct sl_pp_token_info input;
+
+ if (sl_pp_process_get(context, &input)) {
+ free(state.out);
+ return -1;
+ }
+ if (sl_pp_process_out(&state, &input)) {
+ free(state.out);
+ return -1;
+ }
+ if (input.token == SL_PP_EOF) {
+ *output = state.out;
+ return 0;
+ }
+ }
}
diff --git a/src/glsl/pp/sl_pp_process.h b/src/glsl/pp/sl_pp_process.h
index 31defd911a..fe6ff0d464 100644
--- a/src/glsl/pp/sl_pp_process.h
+++ b/src/glsl/pp/sl_pp_process.h
@@ -28,11 +28,12 @@
#ifndef SL_PP_PROCESS_H
#define SL_PP_PROCESS_H
-#include "sl_pp_context.h"
#include "sl_pp_macro.h"
#include "sl_pp_token.h"
+struct sl_pp_context;
+
struct sl_pp_process_state {
struct sl_pp_token_info *out;
unsigned int out_len;
diff --git a/src/glsl/pp/sl_pp_public.h b/src/glsl/pp/sl_pp_public.h
index 309a70c07f..12528d6f8d 100644
--- a/src/glsl/pp/sl_pp_public.h
+++ b/src/glsl/pp/sl_pp_public.h
@@ -74,6 +74,10 @@ sl_pp_version(struct sl_pp_context *context,
unsigned int *version);
int
+sl_pp_process_get(struct sl_pp_context *context,
+ struct sl_pp_token_info *output);
+
+int
sl_pp_process(struct sl_pp_context *context,
struct sl_pp_token_info **output);