Zebediah Figura : vkd3d-shader: Move the remainder of hlsl_parser_compile() to hlsl_compile_shader().

Alexandre Julliard julliard at winehq.org
Fri Mar 5 15:31:01 CST 2021


Module: vkd3d
Branch: master
Commit: 8ce33da2abef3896c7d3da92191afb13db5c7571
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=8ce33da2abef3896c7d3da92191afb13db5c7571

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Thu Mar  4 17:33:24 2021 -0600

vkd3d-shader: Move the remainder of hlsl_parser_compile() to hlsl_compile_shader().

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 libs/vkd3d-shader/hlsl.h |  4 ++--
 libs/vkd3d-shader/hlsl.l |  4 ++--
 libs/vkd3d-shader/hlsl.y | 47 +----------------------------------------------
 4 files changed, 47 insertions(+), 52 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 0486c95..02fa484 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -188,6 +188,22 @@ bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name)
     return rb_get(&ctx->functions, name) != NULL;
 }
 
+struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name)
+{
+    struct hlsl_ir_function_decl *decl;
+    struct hlsl_ir_function *func;
+    struct rb_entry *entry;
+
+    if ((entry = rb_get(&ctx->functions, name)))
+    {
+        func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
+        RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
+            return decl;
+    }
+
+    return NULL;
+}
+
 unsigned int hlsl_type_component_count(struct hlsl_type *type)
 {
     struct hlsl_struct_field *field;
@@ -1606,7 +1622,9 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
         struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context)
 {
     const struct vkd3d_shader_hlsl_source_info *hlsl_source_info;
+    struct hlsl_ir_function_decl *entry_func;
     const struct hlsl_profile_info *profile;
+    const char *entry_point;
     struct hlsl_ctx ctx;
     int ret;
 
@@ -1615,6 +1633,7 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
         ERR("No HLSL source info given.\n");
         return VKD3D_ERROR_INVALID_ARGUMENT;
     }
+    entry_point = hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main";
 
     if (!(profile = get_target_info(hlsl_source_info->profile)))
     {
@@ -1627,9 +1646,30 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
     if (!hlsl_ctx_init(&ctx, message_context))
         return VKD3D_ERROR_OUT_OF_MEMORY;
 
-    ret = hlsl_lexer_compile(&ctx, text, hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main");
+    hlsl_lexer_compile(&ctx, text);
 
-    hlsl_ctx_cleanup(&ctx);
+    if (ctx.failed)
+    {
+        hlsl_ctx_cleanup(&ctx);
+        return VKD3D_ERROR_INVALID_SHADER;
+    }
+
+    if (!(entry_func = hlsl_get_func_decl(&ctx, entry_point)))
+    {
+        const struct vkd3d_shader_location loc = {.source_name = compile_info->source_name};
 
+        hlsl_error(&ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED,
+                "Entry point \"%s\" is not defined.", entry_point);
+        return VKD3D_ERROR_INVALID_SHADER;
+    }
+
+    if (!hlsl_type_is_void(entry_func->return_type)
+            && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
+        hlsl_error(&ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
+                "Entry point \"%s\" is missing a return value semantic.", entry_point);
+
+    ret = hlsl_emit_dxbc(&ctx, entry_func);
+
+    hlsl_ctx_cleanup(&ctx);
     return ret;
 }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 73ba2be..4af021e 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -518,6 +518,7 @@ void hlsl_free_type(struct hlsl_type *type) DECLSPEC_HIDDEN;
 void hlsl_free_var(struct hlsl_ir_var *decl) DECLSPEC_HIDDEN;
 
 bool hlsl_get_function(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
+struct hlsl_ir_function_decl *hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
 struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive) DECLSPEC_HIDDEN;
 struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DECLSPEC_HIDDEN;
 
@@ -571,7 +572,6 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type) DECLSPEC_HIDDEN;
 bool hlsl_type_is_row_major(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 bool hlsl_type_is_void(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint) DECLSPEC_HIDDEN;
-int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint) DECLSPEC_HIDDEN;
+int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text) DECLSPEC_HIDDEN;
 
 #endif
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l
index 4cc0a3e..da54d57 100644
--- a/libs/vkd3d-shader/hlsl.l
+++ b/libs/vkd3d-shader/hlsl.l
@@ -282,7 +282,7 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc)
     ctx->location.column += yyget_leng(ctx->scanner);
 }
 
-int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entrypoint)
+int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text)
 {
     YY_BUFFER_STATE buffer;
     int ret;
@@ -291,7 +291,7 @@ int hlsl_lexer_compile(struct hlsl_ctx *ctx, const char *text, const char *entry
     buffer = yy_scan_string(text, ctx->scanner);
     yy_switch_to_buffer(buffer, ctx->scanner);
 
-    ret = hlsl_parser_compile(ctx, entrypoint);
+    ret = hlsl_yyparse(ctx->scanner, ctx);
 
     yy_delete_buffer(buffer, ctx->scanner);
     yylex_destroy(ctx->scanner);
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index ae15118..6674774 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -286,22 +286,6 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
     return &cast->node;
 }
 
-static struct hlsl_ir_function_decl *get_func_entry(struct hlsl_ctx *ctx, const char *name)
-{
-    struct hlsl_ir_function_decl *decl;
-    struct hlsl_ir_function *func;
-    struct rb_entry *entry;
-
-    if ((entry = rb_get(&ctx->functions, name)))
-    {
-        func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
-        RB_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
-            return decl;
-    }
-
-    return NULL;
-}
-
 static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local)
 {
     struct hlsl_ir_function_decl *func;
@@ -334,7 +318,7 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo
     }
     else
     {
-        if ((func = get_func_entry(ctx, decl->name)))
+        if ((func = hlsl_get_func_decl(ctx, decl->name)))
         {
             hlsl_error(ctx, decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED,
                     "Variable '%s' is already defined as a function.", decl->name);
@@ -3012,32 +2996,3 @@ expr:
             list_move_tail($$, $3);
             vkd3d_free($3);
         }
-
-%%
-
-int hlsl_parser_compile(struct hlsl_ctx *ctx, const char *entrypoint)
-{
-    struct hlsl_ir_function_decl *entry_func;
-
-    yyparse(ctx->scanner, ctx);
-
-    if (ctx->failed)
-        return VKD3D_ERROR_INVALID_SHADER;
-
-    if (!(entry_func = get_func_entry(ctx, entrypoint)))
-    {
-        const struct vkd3d_shader_location loc = {.source_name = ctx->location.source_name};
-
-        hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Entry point \"%s\" is not defined.", entrypoint);
-        return VKD3D_ERROR_INVALID_SHADER;
-    }
-
-    if (!hlsl_type_is_void(entry_func->return_type)
-            && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->semantic)
-    {
-        hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
-                "Entry point \"%s\" is missing a return value semantic.", entry_func->func->name);
-    }
-
-    return hlsl_emit_dxbc(ctx, entry_func);
-}




More information about the wine-cvs mailing list