From ba32e91aca044141c6e26ee068ea7766054fe8a4 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 14 Jan 2021 14:47:49 -0600 Subject: [PATCH] vkd3d-shader: Implement #pragma. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/preproc.l | 13 +++++++++++++ libs/vkd3d-shader/preproc.y | 1 + tests/hlsl_d3d12.c | 3 +-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 80ac7d03..f7aee198 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -129,6 +129,8 @@ IDENTIFIER [A-Za-z_][A-Za-z0-9_]* return T_IFDEF; if (!strcmp(p, "ifndef")) return T_IFNDEF; + if (!strcmp(p, "pragma")) + return T_PRAGMA; if (!strcmp(p, "undef")) return T_UNDEF; @@ -352,6 +354,7 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner) case T_IFDEF: case T_IFNDEF: case T_INCLUDE: + case T_PRAGMA: case T_UNDEF: ctx->current_directive = token; break; @@ -387,6 +390,16 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner) continue; } + if (ctx->current_directive == T_PRAGMA) + { + /* Print all tokens verbatim. */ + if (token == T_PRAGMA) + vkd3d_string_buffer_printf(&ctx->buffer, "#pragma "); + else + vkd3d_string_buffer_printf(&ctx->buffer, "%s", text); + continue; + } + switch (func_state->state) { case STATE_NONE: diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y index 72d6486e..4b276a95 100644 --- a/libs/vkd3d-shader/preproc.y +++ b/libs/vkd3d-shader/preproc.y @@ -326,6 +326,7 @@ static void free_parse_arg_names(struct parse_arg_names *args) %token T_IFDEF "#ifdef" %token T_IFNDEF "#ifndef" %token T_INCLUDE "#include" +%token T_PRAGMA "#pragma" %token T_UNDEF "#undef" %token T_CONCAT "##" diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index 03169716..837476d1 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -350,8 +350,7 @@ static void test_preprocess(void) for (i = 0; i < ARRAY_SIZE(tests); ++i) { vkd3d_test_set_context("Source \"%s\"", tests[i].source); - todo_if (i == 9) - check_preprocess(tests[i].source, NULL, NULL, tests[i].present, tests[i].absent); + check_preprocess(tests[i].source, NULL, NULL, tests[i].present, tests[i].absent); } vkd3d_test_set_context(NULL);