2021-01-27 08:29:44 -08:00
|
|
|
/*
|
|
|
|
* HLSL parser
|
|
|
|
*
|
|
|
|
* Copyright 2008 Stefan Dösinger
|
|
|
|
* Copyright 2012 Matteo Bruni for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
%{
|
|
|
|
#define YY_NO_UNISTD_H
|
|
|
|
#include "hlsl.h"
|
|
|
|
#include "hlsl.tab.h"
|
|
|
|
|
2021-02-12 08:48:53 -08:00
|
|
|
#define YYSTYPE HLSL_YYSTYPE
|
|
|
|
#define YYLTYPE HLSL_YYLTYPE
|
2021-02-04 14:33:52 -08:00
|
|
|
|
2021-02-12 08:48:53 -08:00
|
|
|
static void update_location(struct hlsl_ctx *ctx, YYLTYPE *loc);
|
2021-02-04 14:33:53 -08:00
|
|
|
|
2024-07-17 08:22:44 -07:00
|
|
|
static void apply_escape_sequences(char *str);
|
|
|
|
|
2021-02-04 14:33:53 -08:00
|
|
|
#define YY_USER_ACTION update_location(yyget_extra(yyscanner), yyget_lloc(yyscanner));
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
2021-02-04 14:33:53 -08:00
|
|
|
%option bison-bridge
|
|
|
|
%option bison-locations
|
|
|
|
%option extra-type="struct hlsl_ctx *"
|
2021-01-27 08:29:44 -08:00
|
|
|
%option never-interactive
|
2023-05-08 10:57:14 -07:00
|
|
|
%option nodefault
|
2021-01-27 08:29:44 -08:00
|
|
|
%option noinput
|
|
|
|
%option nounput
|
|
|
|
%option noyywrap
|
2021-02-12 08:48:53 -08:00
|
|
|
%option prefix="hlsl_yy"
|
2021-02-04 14:33:53 -08:00
|
|
|
%option reentrant
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
%x pp pp_line pp_pragma pp_ignore
|
|
|
|
|
2023-10-11 04:51:51 -07:00
|
|
|
RESERVED1 auto|catch|char|class|const_cast|delete|dynamic_cast|enum
|
2021-01-27 08:29:44 -08:00
|
|
|
RESERVED2 explicit|friend|goto|long|mutable|new|operator|private|protected|public
|
|
|
|
RESERVED3 reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
|
2024-05-18 14:29:58 -07:00
|
|
|
RESERVED4 typename|union|using|virtual
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
WS [ \t]
|
|
|
|
NEWLINE (\n)|(\r\n)
|
2024-07-17 08:22:44 -07:00
|
|
|
STRING \"([^\"\\]|\\.)*\"
|
2021-01-27 08:29:44 -08:00
|
|
|
IDENTIFIER [A-Za-z_][A-Za-z0-9_]*
|
|
|
|
|
|
|
|
ANY (.)
|
|
|
|
|
|
|
|
%%
|
2021-02-04 14:33:53 -08:00
|
|
|
{RESERVED1} |
|
|
|
|
{RESERVED2} |
|
|
|
|
{RESERVED3} |
|
2021-01-27 08:29:44 -08:00
|
|
|
{RESERVED4} {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-12-01 08:14:57 -08:00
|
|
|
hlsl_error(ctx, yylloc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX,
|
2021-02-21 20:04:36 -08:00
|
|
|
"Reserved keyword \"%s\" used.", yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
BlendState {return KW_BLENDSTATE; }
|
|
|
|
break {return KW_BREAK; }
|
|
|
|
Buffer {return KW_BUFFER; }
|
2023-10-11 04:51:51 -07:00
|
|
|
case {return KW_CASE; }
|
2021-01-27 08:29:44 -08:00
|
|
|
cbuffer {return KW_CBUFFER; }
|
2023-09-21 06:11:26 -07:00
|
|
|
centroid {return KW_CENTROID; }
|
2023-07-29 17:08:48 -07:00
|
|
|
column_major {return KW_COLUMN_MAJOR; }
|
2024-02-22 15:51:20 -08:00
|
|
|
ComputeShader {return KW_COMPUTESHADER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
compile {return KW_COMPILE; }
|
2024-06-24 14:43:41 -07:00
|
|
|
CompileShader {return KW_COMPILESHADER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
const {return KW_CONST; }
|
2024-06-24 16:22:22 -07:00
|
|
|
ConstructGSWithSO {return KW_CONSTRUCTGSWITHSO; }
|
2021-01-27 08:29:44 -08:00
|
|
|
continue {return KW_CONTINUE; }
|
|
|
|
DepthStencilState {return KW_DEPTHSTENCILSTATE; }
|
|
|
|
DepthStencilView {return KW_DEPTHSTENCILVIEW; }
|
2023-10-11 04:51:51 -07:00
|
|
|
default {return KW_DEFAULT; }
|
2021-01-27 08:29:44 -08:00
|
|
|
discard {return KW_DISCARD; }
|
2024-02-22 15:51:20 -08:00
|
|
|
DomainShader {return KW_DOMAINSHADER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
do {return KW_DO; }
|
|
|
|
else {return KW_ELSE; }
|
2024-03-31 06:36:00 -07:00
|
|
|
export {return KW_EXPORT; }
|
2021-01-27 08:29:44 -08:00
|
|
|
extern {return KW_EXTERN; }
|
|
|
|
false {return KW_FALSE; }
|
|
|
|
for {return KW_FOR; }
|
2023-11-02 07:37:01 -07:00
|
|
|
fxgroup {return KW_FXGROUP; }
|
2021-01-27 08:29:44 -08:00
|
|
|
GeometryShader {return KW_GEOMETRYSHADER; }
|
|
|
|
groupshared {return KW_GROUPSHARED; }
|
2024-02-22 15:51:20 -08:00
|
|
|
HullShader {return KW_HULLSHADER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
if {return KW_IF; }
|
|
|
|
in {return KW_IN; }
|
|
|
|
inline {return KW_INLINE; }
|
|
|
|
inout {return KW_INOUT; }
|
2023-11-26 11:36:29 -08:00
|
|
|
linear {return KW_LINEAR; }
|
2021-01-27 08:29:44 -08:00
|
|
|
matrix {return KW_MATRIX; }
|
|
|
|
namespace {return KW_NAMESPACE; }
|
|
|
|
nointerpolation {return KW_NOINTERPOLATION; }
|
2023-09-21 06:11:26 -07:00
|
|
|
noperspective {return KW_NOPERSPECTIVE; }
|
2024-07-23 06:30:27 -07:00
|
|
|
NULL {return KW_NULL; }
|
2021-01-27 08:29:44 -08:00
|
|
|
out {return KW_OUT; }
|
2023-02-22 09:53:17 -08:00
|
|
|
packoffset {return KW_PACKOFFSET; }
|
2021-01-27 08:29:44 -08:00
|
|
|
pass {return KW_PASS; }
|
|
|
|
PixelShader {return KW_PIXELSHADER; }
|
2024-02-23 06:50:39 -08:00
|
|
|
pixelshader {return KW_PIXELSHADER; }
|
2023-10-12 10:32:02 -07:00
|
|
|
RasterizerOrderedBuffer {return KW_RASTERIZERORDEREDBUFFER; }
|
|
|
|
RasterizerOrderedStructuredBuffer {return KW_RASTERIZERORDEREDSTRUCTUREDBUFFER; }
|
|
|
|
RasterizerOrderedTexture1D {return KW_RASTERIZERORDEREDTEXTURE1D; }
|
|
|
|
RasterizerOrderedTexture1DArray {return KW_RASTERIZERORDEREDTEXTURE1DARRAY; }
|
|
|
|
RasterizerOrderedTexture2D {return KW_RASTERIZERORDEREDTEXTURE2D; }
|
|
|
|
RasterizerOrderedTexture2DArray {return KW_RASTERIZERORDEREDTEXTURE2DARRAY; }
|
|
|
|
RasterizerOrderedTexture3D {return KW_RASTERIZERORDEREDTEXTURE3D; }
|
2021-01-27 08:29:44 -08:00
|
|
|
RasterizerState {return KW_RASTERIZERSTATE; }
|
2023-07-29 17:08:48 -07:00
|
|
|
register {return KW_REGISTER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
RenderTargetView {return KW_RENDERTARGETVIEW; }
|
|
|
|
return {return KW_RETURN; }
|
2023-07-29 17:08:48 -07:00
|
|
|
row_major {return KW_ROW_MAJOR; }
|
2023-05-02 18:47:05 -07:00
|
|
|
RWBuffer {return KW_RWBUFFER; }
|
2024-10-24 23:39:49 -07:00
|
|
|
RWByteAddressBuffer {return KW_RWBYTEADDRESSBUFFER; }
|
2023-05-16 03:55:31 -07:00
|
|
|
RWStructuredBuffer {return KW_RWSTRUCTUREDBUFFER; }
|
2021-08-12 19:03:26 -07:00
|
|
|
RWTexture1D {return KW_RWTEXTURE1D; }
|
2023-10-18 13:49:18 -07:00
|
|
|
RWTexture1DArray {return KW_RWTEXTURE1DARRAY; }
|
2021-08-12 19:03:26 -07:00
|
|
|
RWTexture2D {return KW_RWTEXTURE2D; }
|
2023-10-18 13:56:52 -07:00
|
|
|
RWTexture2DArray {return KW_RWTEXTURE2DARRAY; }
|
2021-08-12 19:03:26 -07:00
|
|
|
RWTexture3D {return KW_RWTEXTURE3D; }
|
2021-01-27 08:29:44 -08:00
|
|
|
sampler {return KW_SAMPLER; }
|
|
|
|
sampler1D {return KW_SAMPLER1D; }
|
|
|
|
sampler2D {return KW_SAMPLER2D; }
|
|
|
|
sampler3D {return KW_SAMPLER3D; }
|
|
|
|
SamplerComparisonState {return KW_SAMPLERCOMPARISONSTATE;}
|
2023-07-29 17:08:48 -07:00
|
|
|
samplerCUBE {return KW_SAMPLERCUBE; }
|
2021-11-05 11:35:51 -07:00
|
|
|
SamplerState {return KW_SAMPLER; }
|
2023-07-29 17:08:48 -07:00
|
|
|
sampler_state {return KW_SAMPLER_STATE; }
|
2021-01-27 08:29:44 -08:00
|
|
|
shared {return KW_SHARED; }
|
2024-10-15 04:20:15 -07:00
|
|
|
snorm {return KW_SNORM; }
|
2021-01-27 08:29:44 -08:00
|
|
|
stateblock {return KW_STATEBLOCK; }
|
|
|
|
stateblock_state {return KW_STATEBLOCK_STATE; }
|
|
|
|
static {return KW_STATIC; }
|
|
|
|
string {return KW_STRING; }
|
2024-08-13 12:20:03 -07:00
|
|
|
String {return KW_STRING; }
|
2021-01-27 08:29:44 -08:00
|
|
|
struct {return KW_STRUCT; }
|
|
|
|
switch {return KW_SWITCH; }
|
|
|
|
tbuffer {return KW_TBUFFER; }
|
2023-11-01 14:16:47 -07:00
|
|
|
(?i:technique) {return KW_TECHNIQUE; }
|
2021-01-27 08:29:44 -08:00
|
|
|
technique10 {return KW_TECHNIQUE10; }
|
2023-11-01 13:54:17 -07:00
|
|
|
technique11 {return KW_TECHNIQUE11; }
|
2021-01-27 08:29:44 -08:00
|
|
|
texture {return KW_TEXTURE; }
|
2021-10-07 19:58:54 -07:00
|
|
|
Texture1D {return KW_TEXTURE1D; }
|
2023-07-29 17:08:48 -07:00
|
|
|
texture1D {return KW_TEXTURE1D; }
|
2021-01-27 08:29:44 -08:00
|
|
|
Texture1DArray {return KW_TEXTURE1DARRAY; }
|
2021-10-07 19:58:54 -07:00
|
|
|
Texture2D {return KW_TEXTURE2D; }
|
2023-07-29 17:08:48 -07:00
|
|
|
texture2D {return KW_TEXTURE2D; }
|
2021-01-27 08:29:44 -08:00
|
|
|
Texture2DArray {return KW_TEXTURE2DARRAY; }
|
|
|
|
Texture2DMS {return KW_TEXTURE2DMS; }
|
|
|
|
Texture2DMSArray {return KW_TEXTURE2DMSARRAY; }
|
2021-10-07 19:58:54 -07:00
|
|
|
Texture3D {return KW_TEXTURE3D; }
|
2023-07-29 17:08:48 -07:00
|
|
|
texture3D {return KW_TEXTURE3D; }
|
2021-10-07 19:58:54 -07:00
|
|
|
TextureCube {return KW_TEXTURECUBE; }
|
2023-07-29 17:08:48 -07:00
|
|
|
textureCUBE {return KW_TEXTURECUBE; }
|
2022-01-27 10:31:26 -08:00
|
|
|
TextureCubeArray {return KW_TEXTURECUBEARRAY; }
|
2021-01-27 08:29:44 -08:00
|
|
|
true {return KW_TRUE; }
|
|
|
|
typedef {return KW_TYPEDEF; }
|
2024-05-18 14:29:58 -07:00
|
|
|
unsigned {return KW_UNSIGNED; }
|
2021-01-27 08:29:44 -08:00
|
|
|
uniform {return KW_UNIFORM; }
|
2024-10-15 04:20:15 -07:00
|
|
|
unorm {return KW_UNORM; }
|
2021-01-27 08:29:44 -08:00
|
|
|
vector {return KW_VECTOR; }
|
|
|
|
VertexShader {return KW_VERTEXSHADER; }
|
2024-02-23 06:50:39 -08:00
|
|
|
vertexshader {return KW_VERTEXSHADER; }
|
2021-01-27 08:29:44 -08:00
|
|
|
void {return KW_VOID; }
|
|
|
|
volatile {return KW_VOLATILE; }
|
|
|
|
while {return KW_WHILE; }
|
|
|
|
|
|
|
|
\+\+ {return OP_INC; }
|
|
|
|
\-\- {return OP_DEC; }
|
|
|
|
&& {return OP_AND; }
|
|
|
|
\|\| {return OP_OR; }
|
|
|
|
== {return OP_EQ; }
|
|
|
|
\<\< {return OP_LEFTSHIFT; }
|
|
|
|
\<\<= {return OP_LEFTSHIFTASSIGN; }
|
|
|
|
\>\> {return OP_RIGHTSHIFT; }
|
|
|
|
\>\>= {return OP_RIGHTSHIFTASSIGN; }
|
|
|
|
\<= {return OP_LE; }
|
|
|
|
\>= {return OP_GE; }
|
|
|
|
!= {return OP_NE; }
|
|
|
|
\+= {return OP_ADDASSIGN; }
|
|
|
|
\-= {return OP_SUBASSIGN; }
|
|
|
|
\*= {return OP_MULASSIGN; }
|
|
|
|
\/= {return OP_DIVASSIGN; }
|
|
|
|
%= {return OP_MODASSIGN; }
|
|
|
|
&= {return OP_ANDASSIGN; }
|
|
|
|
\|= {return OP_ORASSIGN; }
|
2024-05-20 10:18:04 -07:00
|
|
|
\^= {return OP_XORASSIGN; }
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
{IDENTIFIER} {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-05-20 22:32:20 -07:00
|
|
|
yylval->name = hlsl_strdup(ctx, yytext);
|
2024-05-27 15:31:51 -07:00
|
|
|
if (hlsl_version_ge(ctx, 5, 1) && !strcmp(yytext, "ConstantBuffer"))
|
|
|
|
return KW_CONSTANTBUFFER;
|
|
|
|
else if (hlsl_get_var(ctx->cur_scope, yytext) || hlsl_get_function(ctx, yytext))
|
2021-01-27 08:29:44 -08:00
|
|
|
return VAR_IDENTIFIER;
|
2023-02-18 16:44:20 -08:00
|
|
|
else if (hlsl_get_type(ctx->cur_scope, yytext, true, true))
|
2021-01-27 08:29:44 -08:00
|
|
|
return TYPE_IDENTIFIER;
|
|
|
|
else
|
|
|
|
return NEW_IDENTIFIER;
|
|
|
|
}
|
|
|
|
|
2024-06-14 16:59:21 -07:00
|
|
|
{STRING} {
|
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
char *string = hlsl_strdup(ctx, yytext + 1);
|
|
|
|
|
|
|
|
string[strlen(string) - 1] = 0;
|
2024-07-17 08:22:44 -07:00
|
|
|
apply_escape_sequences(string);
|
2024-06-14 16:59:21 -07:00
|
|
|
yylval->name = string;
|
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
[0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[h|H|f|F]? {
|
2021-02-04 14:33:53 -08:00
|
|
|
yylval->floatval = atof(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_FLOAT;
|
|
|
|
}
|
|
|
|
[0-9]+\.([eE][+-]?[0-9]+)?[h|H|f|F]? {
|
2021-02-04 14:33:53 -08:00
|
|
|
yylval->floatval = atof(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_FLOAT;
|
|
|
|
}
|
2022-02-07 22:52:15 -08:00
|
|
|
[0-9]+[eE][+-]?[0-9]+[h|H|f|F]? {
|
2021-02-04 14:33:53 -08:00
|
|
|
yylval->floatval = atof(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_FLOAT;
|
|
|
|
}
|
2023-11-16 10:32:16 -08:00
|
|
|
0x[0-9a-fA-F]+[lL]? {
|
2022-05-11 07:39:08 -07:00
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_INTEGER;
|
|
|
|
}
|
2023-11-16 10:32:16 -08:00
|
|
|
0[0-7]+[lL]? {
|
2022-05-11 07:39:08 -07:00
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_INTEGER;
|
|
|
|
}
|
2023-11-16 10:32:16 -08:00
|
|
|
[0-9]+[lL]? {
|
2022-05-11 07:39:08 -07:00
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
2021-01-27 08:29:44 -08:00
|
|
|
return C_INTEGER;
|
|
|
|
}
|
2023-11-16 10:32:16 -08:00
|
|
|
0x[0-9a-fA-F]+([uU]|[uU][lL]|[lL][uU]) {
|
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
|
|
|
return C_UNSIGNED;
|
|
|
|
}
|
|
|
|
0[0-7]+([uU]|[uU][lL]|[lL][uU]) {
|
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
|
|
|
return C_UNSIGNED;
|
|
|
|
}
|
|
|
|
[0-9]+([uU]|[uU][lL]|[lL][uU]) {
|
|
|
|
yylval->intval = vkd3d_parse_integer(yytext);
|
|
|
|
return C_UNSIGNED;
|
|
|
|
}
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
{WS}+ {}
|
|
|
|
{NEWLINE} {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-02-12 08:48:56 -08:00
|
|
|
++ctx->location.line;
|
|
|
|
ctx->location.column = 1;
|
2021-01-27 08:29:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
^# {
|
|
|
|
BEGIN(pp);
|
|
|
|
}
|
|
|
|
|
|
|
|
<pp>pragma{WS}+ {
|
|
|
|
BEGIN(pp_pragma);
|
|
|
|
}
|
|
|
|
<pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
TRACE("#pragma setting row_major mode.\n");
|
2022-03-29 16:49:10 -07:00
|
|
|
ctx->matrix_majority = HLSL_MODIFIER_ROW_MAJOR;
|
2021-01-27 08:29:44 -08:00
|
|
|
BEGIN(pp_ignore);
|
|
|
|
}
|
|
|
|
<pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-01-27 08:29:44 -08:00
|
|
|
TRACE("#pragma setting column_major mode.\n");
|
2022-03-29 16:49:10 -07:00
|
|
|
ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR;
|
2021-01-27 08:29:44 -08:00
|
|
|
BEGIN(pp_ignore);
|
|
|
|
}
|
|
|
|
<pp_pragma>{NEWLINE} {
|
2021-02-04 14:33:53 -08:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
|
2021-02-12 08:48:56 -08:00
|
|
|
FIXME("Unsupported preprocessor #pragma directive at line %u.\n", ctx->location.line);
|
2021-01-27 08:29:44 -08:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
|
|
|
<pp_pragma>{ANY} {}
|
|
|
|
<pp>[0-9]+ {
|
|
|
|
BEGIN(pp_line);
|
2021-02-04 14:33:53 -08:00
|
|
|
yylval->intval = (atoi(yytext));
|
2021-01-27 08:29:44 -08:00
|
|
|
return PRE_LINE;
|
|
|
|
}
|
|
|
|
<pp_line>{STRING} {
|
2021-05-20 22:32:20 -07:00
|
|
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
|
|
|
char *string = hlsl_strdup(ctx, yytext + 1);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
BEGIN(pp_ignore);
|
|
|
|
string[strlen(string) - 1] = 0;
|
2024-07-17 08:22:44 -07:00
|
|
|
apply_escape_sequences(string);
|
2021-02-04 14:33:53 -08:00
|
|
|
yylval->name = string;
|
2021-01-27 08:29:44 -08:00
|
|
|
return STRING;
|
|
|
|
}
|
|
|
|
<pp_line>{WS}+ {}
|
2023-05-08 10:56:36 -07:00
|
|
|
<pp_line>{ANY} {
|
|
|
|
FIXME("Malformed preprocessor line directive?\n");
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
2021-01-27 08:29:44 -08:00
|
|
|
<pp_line>{NEWLINE} {
|
|
|
|
FIXME("Malformed preprocessor line directive?\n");
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
|
|
|
<pp_ignore>{NEWLINE} {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
|
|
|
<pp_ignore>{ANY} {}
|
|
|
|
<pp>{NEWLINE} {
|
|
|
|
FIXME("Unexpected preprocessor directive.\n");
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
|
|
|
<pp>{ANY} {}
|
|
|
|
|
|
|
|
{ANY} {
|
|
|
|
return yytext[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2021-02-12 08:48:53 -08:00
|
|
|
static void update_location(struct hlsl_ctx *ctx, YYLTYPE *lloc)
|
2021-02-04 14:33:52 -08:00
|
|
|
{
|
2021-02-12 08:48:56 -08:00
|
|
|
*lloc = ctx->location;
|
|
|
|
ctx->location.column += yyget_leng(ctx->scanner);
|
2021-02-04 14:33:52 -08:00
|
|
|
}
|
|
|
|
|
2021-03-04 15:33:28 -08:00
|
|
|
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const struct vkd3d_shader_code *hlsl)
|
2021-01-27 08:29:44 -08:00
|
|
|
{
|
|
|
|
YY_BUFFER_STATE buffer;
|
|
|
|
int ret;
|
|
|
|
|
2021-02-04 14:33:53 -08:00
|
|
|
yylex_init_extra(ctx, &ctx->scanner);
|
2021-03-04 15:33:28 -08:00
|
|
|
buffer = yy_scan_bytes(hlsl->code, hlsl->size, ctx->scanner);
|
2021-02-12 08:48:53 -08:00
|
|
|
yy_switch_to_buffer(buffer, ctx->scanner);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2021-03-04 15:33:24 -08:00
|
|
|
ret = hlsl_yyparse(ctx->scanner, ctx);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
2021-02-12 08:48:53 -08:00
|
|
|
yy_delete_buffer(buffer, ctx->scanner);
|
2021-02-04 14:33:53 -08:00
|
|
|
yylex_destroy(ctx->scanner);
|
2021-01-27 08:29:44 -08:00
|
|
|
return ret;
|
|
|
|
}
|
2024-07-17 08:22:44 -07:00
|
|
|
|
|
|
|
static void apply_escape_sequences(char *str)
|
|
|
|
{
|
|
|
|
unsigned int i = 0, k = 0, r;
|
|
|
|
|
|
|
|
while (str[i])
|
|
|
|
{
|
|
|
|
unsigned char v = 0;
|
|
|
|
|
|
|
|
if (str[i] != '\\')
|
|
|
|
{
|
|
|
|
str[k++] = str[i];
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
VKD3D_ASSERT(str[i]);
|
|
|
|
|
|
|
|
if ('0' <= str[i] && str[i] <= '7')
|
|
|
|
{
|
|
|
|
/* octal, up to 3 digits. */
|
|
|
|
for (r = 0; r < 3; ++r)
|
|
|
|
{
|
|
|
|
char c = str[i];
|
|
|
|
|
|
|
|
if ('0' <= c && c <= '7')
|
|
|
|
{
|
|
|
|
v = v << 3;
|
|
|
|
v += c - '0';
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str[k++] = v;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[i] == 'x')
|
|
|
|
{
|
|
|
|
bool number = false;
|
|
|
|
|
|
|
|
/* hexadecimal */
|
|
|
|
++i;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
char c = str[i];
|
|
|
|
|
|
|
|
if ('0' <= c && c <= '9')
|
|
|
|
{
|
|
|
|
v = v << 4;
|
|
|
|
v += c - '0';
|
|
|
|
number = true;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else if ('a' <= c && c <= 'f')
|
|
|
|
{
|
|
|
|
v = v << 4;
|
|
|
|
v += c - 'a' + 10;
|
|
|
|
number = true;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else if ('A' <= c && c <= 'F')
|
|
|
|
{
|
|
|
|
v = v << 4;
|
|
|
|
v += c - 'A' + 10;
|
|
|
|
number = true;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (number)
|
|
|
|
str[k++] = v;
|
|
|
|
else
|
|
|
|
str[k++] = 'x';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (str[i])
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
str[k++] = '\a';
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
str[k++] = '\b';
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
str[k++] = '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
str[k++] = '\n';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
str[k++] = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
str[k++] = '\t';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
str[k++] = '\v';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
str[k++] = str[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
str[k++] = '\0';
|
|
|
|
}
|