Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
5bc4d9a2
Commit
5bc4d9a2
authored
Jun 20, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSL: Airplane work: break/continue/discard grammar, and decls for for/if/while.
parent
a4a4d5e2
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
519 additions
and
36 deletions
+519
-36
hlsl.discard.frag.out
Test/baseResults/hlsl.discard.frag.out
+149
-0
hlsl.forLoop.frag.out
Test/baseResults/hlsl.forLoop.frag.out
+188
-3
hlsl.if.frag.out
Test/baseResults/hlsl.if.frag.out
+55
-3
hlsl.discard.frag
Test/hlsl.discard.frag
+14
-0
hlsl.forLoop.frag
Test/hlsl.forLoop.frag
+5
-0
hlsl.if.frag
Test/hlsl.if.frag
+5
-0
Hlsl.FromFile.cpp
gtests/Hlsl.FromFile.cpp
+1
-0
hlslGrammar.cpp
hlsl/hlslGrammar.cpp
+101
-30
hlslGrammar.h
hlsl/hlslGrammar.h
+1
-0
No files found.
Test/baseResults/hlsl.discard.frag.out
0 → 100755
View file @
5bc4d9a2
hlsl.discard.frag
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
0:7 Function Definition: foo(f1; (temp void)
0:2 Function Parameters:
0:2 'f' (in float)
0:? Sequence
0:3 Test condition and select (temp void)
0:3 Condition
0:3 Compare Less Than (temp bool)
0:3 'f' (in float)
0:3 Constant:
0:3 1.000000
0:3 true case
0:4 Branch: Kill
0:15 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:8 Function Parameters:
0:8 'input' (in 4-component vector of float)
0:? Sequence
0:9 Function Call: foo(f1; (temp void)
0:9 direct index (temp float)
0:9 'input' (in 4-component vector of float)
0:9 Constant:
0:9 2 (const int)
0:10 Test condition and select (temp void)
0:10 Condition
0:10 direct index (temp float)
0:10 'input' (in 4-component vector of float)
0:10 Constant:
0:10 0 (const int)
0:10 true case
0:11 Branch: Kill
0:12 move second child to first child (temp float)
0:12 'f' (temp float)
0:12 direct index (temp float)
0:12 'input' (in 4-component vector of float)
0:12 Constant:
0:12 0 (const int)
0:13 Branch: Kill
0:? Linker Objects
Linked fragment stage:
Shader version: 450
gl_FragCoord origin is upper left
0:? Sequence
0:7 Function Definition: foo(f1; (temp void)
0:2 Function Parameters:
0:2 'f' (in float)
0:? Sequence
0:3 Test condition and select (temp void)
0:3 Condition
0:3 Compare Less Than (temp bool)
0:3 'f' (in float)
0:3 Constant:
0:3 1.000000
0:3 true case
0:4 Branch: Kill
0:15 Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:8 Function Parameters:
0:8 'input' (in 4-component vector of float)
0:? Sequence
0:9 Function Call: foo(f1; (temp void)
0:9 direct index (temp float)
0:9 'input' (in 4-component vector of float)
0:9 Constant:
0:9 2 (const int)
0:10 Test condition and select (temp void)
0:10 Condition
0:10 direct index (temp float)
0:10 'input' (in 4-component vector of float)
0:10 Constant:
0:10 0 (const int)
0:10 true case
0:11 Branch: Kill
0:12 move second child to first child (temp float)
0:12 'f' (temp float)
0:12 direct index (temp float)
0:12 'input' (in 4-component vector of float)
0:12 Constant:
0:12 0 (const int)
0:13 Branch: Kill
0:? Linker Objects
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 39
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 21
ExecutionMode 4 OriginUpperLeft
Source HLSL 450
Name 4 "PixelShaderFunction"
Name 10 "foo(f1;"
Name 9 "f"
Name 21 "input"
Name 22 "param"
Name 35 "f"
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypePointer Function 6(float)
8: TypeFunction 2 7(ptr)
13: 6(float) Constant 1065353216
14: TypeBool
19: TypeVector 6(float) 4
20: TypePointer Input 19(fvec4)
21(input): 20(ptr) Variable Input
23: TypeInt 32 0
24: 23(int) Constant 2
25: TypePointer Input 6(float)
29: 23(int) Constant 0
4(PixelShaderFunction): 2 Function None 3
5: Label
22(param): 7(ptr) Variable Function
35(f): 7(ptr) Variable Function
26: 25(ptr) AccessChain 21(input) 24
27: 6(float) Load 26
Store 22(param) 27
28: 2 FunctionCall 10(foo(f1;) 22(param)
30: 25(ptr) AccessChain 21(input) 29
31: 6(float) Load 30
SelectionMerge 33 None
BranchConditional 31 32 33
32: Label
Kill
33: Label
36: 25(ptr) AccessChain 21(input) 29
37: 6(float) Load 36
Store 35(f) 37
Kill
FunctionEnd
10(foo(f1;): 2 Function None 8
9(f): 7(ptr) FunctionParameter
11: Label
12: 6(float) Load 9(f)
15: 14(bool) FOrdLessThan 12 13
SelectionMerge 17 None
BranchConditional 15 16 17
16: Label
Kill
17: Label
Return
FunctionEnd
Test/baseResults/hlsl.forLoop.frag.out
View file @
5bc4d9a2
...
@@ -2,7 +2,7 @@ hlsl.forLoop.frag
...
@@ -2,7 +2,7 @@ hlsl.forLoop.frag
Shader version: 450
Shader version: 450
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:
9
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:
14
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:2 Function Parameters:
0:2 Function Parameters:
0:2 'input' (in 4-component vector of float)
0:2 'input' (in 4-component vector of float)
0:? Sequence
0:? Sequence
...
@@ -52,6 +52,61 @@ gl_FragCoord origin is upper left
...
@@ -52,6 +52,61 @@ gl_FragCoord origin is upper left
0:7 'input' (in 4-component vector of float)
0:7 'input' (in 4-component vector of float)
0:7 Constant:
0:7 Constant:
0:7 2.000000
0:7 2.000000
0:? Sequence
0:8 Loop with condition tested first
0:8 No loop condition
0:8 Loop Body
0:8 Test condition and select (temp void)
0:8 Condition
0:8 Compare Greater Than (temp bool)
0:8 direct index (temp float)
0:8 'input' (in 4-component vector of float)
0:8 Constant:
0:8 0 (const int)
0:8 Constant:
0:8 2.000000
0:8 true case
0:8 Branch: Break
0:? Sequence
0:9 Loop with condition tested first
0:9 No loop condition
0:9 Loop Body
0:9 Test condition and select (temp void)
0:9 Condition
0:9 Compare Greater Than (temp bool)
0:9 direct index (temp float)
0:9 'input' (in 4-component vector of float)
0:9 Constant:
0:9 0 (const int)
0:9 Constant:
0:9 2.000000
0:9 true case
0:9 Branch: Continue
0:11 Sequence
0:11 move second child to first child (temp int)
0:11 'ii' (temp int)
0:11 Constant:
0:11 -1 (const int)
0:11 Loop with condition tested first
0:11 Loop Condition
0:11 Compare Less Than (temp bool)
0:11 'ii' (temp int)
0:11 Constant:
0:11 3 (const int)
0:11 Loop Body
0:11 Test condition and select (temp void)
0:11 Condition
0:11 Compare Equal (temp bool)
0:11 'ii' (temp int)
0:11 Constant:
0:11 2 (const int)
0:11 true case
0:11 Branch: Continue
0:11 Loop Terminal Expression
0:11 Pre-Increment (temp int)
0:11 'ii' (temp int)
0:12 Pre-Decrement (temp float)
0:12 'ii' (temp float)
0:? Linker Objects
0:? Linker Objects
...
@@ -61,7 +116,7 @@ Linked fragment stage:
...
@@ -61,7 +116,7 @@ Linked fragment stage:
Shader version: 450
Shader version: 450
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:
9
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:
14
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:2 Function Parameters:
0:2 Function Parameters:
0:2 'input' (in 4-component vector of float)
0:2 'input' (in 4-component vector of float)
0:? Sequence
0:? Sequence
...
@@ -111,11 +166,66 @@ gl_FragCoord origin is upper left
...
@@ -111,11 +166,66 @@ gl_FragCoord origin is upper left
0:7 'input' (in 4-component vector of float)
0:7 'input' (in 4-component vector of float)
0:7 Constant:
0:7 Constant:
0:7 2.000000
0:7 2.000000
0:? Sequence
0:8 Loop with condition tested first
0:8 No loop condition
0:8 Loop Body
0:8 Test condition and select (temp void)
0:8 Condition
0:8 Compare Greater Than (temp bool)
0:8 direct index (temp float)
0:8 'input' (in 4-component vector of float)
0:8 Constant:
0:8 0 (const int)
0:8 Constant:
0:8 2.000000
0:8 true case
0:8 Branch: Break
0:? Sequence
0:9 Loop with condition tested first
0:9 No loop condition
0:9 Loop Body
0:9 Test condition and select (temp void)
0:9 Condition
0:9 Compare Greater Than (temp bool)
0:9 direct index (temp float)
0:9 'input' (in 4-component vector of float)
0:9 Constant:
0:9 0 (const int)
0:9 Constant:
0:9 2.000000
0:9 true case
0:9 Branch: Continue
0:11 Sequence
0:11 move second child to first child (temp int)
0:11 'ii' (temp int)
0:11 Constant:
0:11 -1 (const int)
0:11 Loop with condition tested first
0:11 Loop Condition
0:11 Compare Less Than (temp bool)
0:11 'ii' (temp int)
0:11 Constant:
0:11 3 (const int)
0:11 Loop Body
0:11 Test condition and select (temp void)
0:11 Condition
0:11 Compare Equal (temp bool)
0:11 'ii' (temp int)
0:11 Constant:
0:11 2 (const int)
0:11 true case
0:11 Branch: Continue
0:11 Loop Terminal Expression
0:11 Pre-Increment (temp int)
0:11 'ii' (temp int)
0:12 Pre-Decrement (temp float)
0:12 'ii' (temp float)
0:? Linker Objects
0:? Linker Objects
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by
64
// Id's are bound by
112
Capability Shader
Capability Shader
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
...
@@ -125,6 +235,8 @@ gl_FragCoord origin is upper left
...
@@ -125,6 +235,8 @@ gl_FragCoord origin is upper left
Source HLSL 450
Source HLSL 450
Name 4 "PixelShaderFunction"
Name 4 "PixelShaderFunction"
Name 13 "input"
Name 13 "input"
Name 89 "ii"
Name 109 "ii"
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
10: TypeFloat 32
10: TypeFloat 32
...
@@ -135,8 +247,20 @@ gl_FragCoord origin is upper left
...
@@ -135,8 +247,20 @@ gl_FragCoord origin is upper left
29: TypeBool
29: TypeBool
30: TypeVector 29(bool) 4
30: TypeVector 29(bool) 4
60: 10(float) Constant 1073741824
60: 10(float) Constant 1073741824
68: TypeInt 32 0
69: 68(int) Constant 0
70: TypePointer Input 10(float)
87: TypeInt 32 1
88: TypePointer Function 87(int)
90: 87(int) Constant 4294967295
97: 87(int) Constant 3
100: 87(int) Constant 2
106: 87(int) Constant 1
108: TypePointer Function 10(float)
4(PixelShaderFunction): 2 Function None 3
4(PixelShaderFunction): 2 Function None 3
5: Label
5: Label
89(ii): 88(ptr) Variable Function
109(ii): 108(ptr) Variable Function
Branch 6
Branch 6
6: Label
6: Label
LoopMerge 8 9 None
LoopMerge 8 9 None
...
@@ -216,5 +340,66 @@ gl_FragCoord origin is upper left
...
@@ -216,5 +340,66 @@ gl_FragCoord origin is upper left
Store 13(input) 63
Store 13(input) 63
Branch 48
Branch 48
50: Label
50: Label
Branch 64
64: Label
LoopMerge 66 67 None
Branch 65
65: Label
71: 70(ptr) AccessChain 13(input) 69
72: 10(float) Load 71
73: 29(bool) FOrdGreaterThan 72 60
SelectionMerge 75 None
BranchConditional 73 74 75
74: Label
Branch 66
75: Label
Branch 67
67: Label
Branch 64
66: Label
Branch 77
77: Label
LoopMerge 79 80 None
Branch 78
78: Label
81: 70(ptr) AccessChain 13(input) 69
82: 10(float) Load 81
83: 29(bool) FOrdGreaterThan 82 60
SelectionMerge 85 None
BranchConditional 83 84 85
84: Label
Branch 80
85: Label
Branch 80
80: Label
Branch 77
79: Label
Store 89(ii) 90
Branch 91
91: Label
LoopMerge 93 94 None
Branch 95
95: Label
96: 87(int) Load 89(ii)
98: 29(bool) SLessThan 96 97
BranchConditional 98 92 93
92: Label
99: 87(int) Load 89(ii)
101: 29(bool) IEqual 99 100
SelectionMerge 103 None
BranchConditional 101 102 103
102: Label
Branch 94
103: Label
Branch 94
94: Label
105: 87(int) Load 89(ii)
107: 87(int) IAdd 105 106
Store 89(ii) 107
Branch 91
93: Label
110: 10(float) Load 109(ii)
111: 10(float) FSub 110 15
Store 109(ii) 111
Return
Return
FunctionEnd
FunctionEnd
Test/baseResults/hlsl.if.frag.out
View file @
5bc4d9a2
...
@@ -2,7 +2,7 @@ hlsl.if.frag
...
@@ -2,7 +2,7 @@ hlsl.if.frag
Shader version: 450
Shader version: 450
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:
29
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:
34
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:2 Function Parameters:
0:2 Function Parameters:
0:2 'input' (in 4-component vector of float)
0:2 'input' (in 4-component vector of float)
0:? Sequence
0:? Sequence
...
@@ -61,6 +61,19 @@ gl_FragCoord origin is upper left
...
@@ -61,6 +61,19 @@ gl_FragCoord origin is upper left
0:26 Branch: Return with expression
0:26 Branch: Return with expression
0:26 Negate value (temp 4-component vector of float)
0:26 Negate value (temp 4-component vector of float)
0:26 'input' (in 4-component vector of float)
0:26 'input' (in 4-component vector of float)
0:30 Test condition and select (temp void)
0:30 Condition
0:30 move second child to first child (temp float)
0:30 'ii' (temp float)
0:30 direct index (temp float)
0:30 'input' (in 4-component vector of float)
0:30 Constant:
0:30 2 (const int)
0:30 true case
0:31 Pre-Increment (temp float)
0:31 'ii' (temp float)
0:32 Pre-Increment (temp int)
0:32 'ii' (temp int)
0:? Linker Objects
0:? Linker Objects
...
@@ -70,7 +83,7 @@ Linked fragment stage:
...
@@ -70,7 +83,7 @@ Linked fragment stage:
Shader version: 450
Shader version: 450
gl_FragCoord origin is upper left
gl_FragCoord origin is upper left
0:? Sequence
0:? Sequence
0:
29
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:
34
Function Definition: PixelShaderFunction(vf4; (temp 4-component vector of float)
0:2 Function Parameters:
0:2 Function Parameters:
0:2 'input' (in 4-component vector of float)
0:2 'input' (in 4-component vector of float)
0:? Sequence
0:? Sequence
...
@@ -129,11 +142,24 @@ gl_FragCoord origin is upper left
...
@@ -129,11 +142,24 @@ gl_FragCoord origin is upper left
0:26 Branch: Return with expression
0:26 Branch: Return with expression
0:26 Negate value (temp 4-component vector of float)
0:26 Negate value (temp 4-component vector of float)
0:26 'input' (in 4-component vector of float)
0:26 'input' (in 4-component vector of float)
0:30 Test condition and select (temp void)
0:30 Condition
0:30 move second child to first child (temp float)
0:30 'ii' (temp float)
0:30 direct index (temp float)
0:30 'input' (in 4-component vector of float)
0:30 Constant:
0:30 2 (const int)
0:30 true case
0:31 Pre-Increment (temp float)
0:31 'ii' (temp float)
0:32 Pre-Increment (temp int)
0:32 'ii' (temp int)
0:? Linker Objects
0:? Linker Objects
// Module Version 10000
// Module Version 10000
// Generated by (magic number): 80001
// Generated by (magic number): 80001
// Id's are bound by
64
// Id's are bound by
82
Capability Shader
Capability Shader
1: ExtInstImport "GLSL.std.450"
1: ExtInstImport "GLSL.std.450"
...
@@ -143,6 +169,8 @@ gl_FragCoord origin is upper left
...
@@ -143,6 +169,8 @@ gl_FragCoord origin is upper left
Source HLSL 450
Source HLSL 450
Name 4 "PixelShaderFunction"
Name 4 "PixelShaderFunction"
Name 9 "input"
Name 9 "input"
Name 65 "ii"
Name 78 "ii"
2: TypeVoid
2: TypeVoid
3: TypeFunction 2
3: TypeFunction 2
6: TypeFloat 32
6: TypeFloat 32
...
@@ -151,8 +179,18 @@ gl_FragCoord origin is upper left
...
@@ -151,8 +179,18 @@ gl_FragCoord origin is upper left
9(input): 8(ptr) Variable Input
9(input): 8(ptr) Variable Input
12: TypeBool
12: TypeBool
13: TypeVector 12(bool) 4
13: TypeVector 12(bool) 4
64: TypePointer Function 6(float)
66: TypeInt 32 0
67: 66(int) Constant 2
68: TypePointer Input 6(float)
74: 6(float) Constant 1065353216
76: TypeInt 32 1
77: TypePointer Function 76(int)
80: 76(int) Constant 1
4(PixelShaderFunction): 2 Function None 3
4(PixelShaderFunction): 2 Function None 3
5: Label
5: Label
65(ii): 64(ptr) Variable Function
78(ii): 77(ptr) Variable Function
10: 7(fvec4) Load 9(input)
10: 7(fvec4) Load 9(input)
11: 7(fvec4) Load 9(input)
11: 7(fvec4) Load 9(input)
14: 13(bvec4) FOrdEqual 10 11
14: 13(bvec4) FOrdEqual 10 11
...
@@ -219,5 +257,19 @@ gl_FragCoord origin is upper left
...
@@ -219,5 +257,19 @@ gl_FragCoord origin is upper left
62: 7(fvec4) FNegate 61
62: 7(fvec4) FNegate 61
ReturnValue 62
ReturnValue 62
57: Label
57: Label
69: 68(ptr) AccessChain 9(input) 67
70: 6(float) Load 69
Store 65(ii) 70
SelectionMerge 72 None
BranchConditional 70 71 72
71: Label
73: 6(float) Load 65(ii)
75: 6(float) FAdd 73 74
Store 65(ii) 75
Branch 72
72: Label
79: 76(int) Load 78(ii)
81: 76(int) IAdd 79 80
Store 78(ii) 81
Return
Return
FunctionEnd
FunctionEnd
Test/hlsl.discard.frag
0 → 100644
View file @
5bc4d9a2
void
foo
(
float
f
)
{
if
(
f
<
1
.
0
)
discard
;
}
float4
PixelShaderFunction
(
float4
input
)
:
COLOR0
{
foo
(
input
.
z
);
if
(
input
.
x
)
discard
;
float
f
=
input
.
x
;
discard
;
}
Test/hlsl.forLoop.frag
View file @
5bc4d9a2
...
@@ -5,4 +5,9 @@ float4 PixelShaderFunction(float4 input) : COLOR0
...
@@ -5,4 +5,9 @@ float4 PixelShaderFunction(float4 input) : COLOR0
[
unroll
]
for
(;
input
!=
input
;
)
{}
[
unroll
]
for
(;
input
!=
input
;
)
{}
for
(;
input
!=
input
;
)
{
return
-
input
;
}
for
(;
input
!=
input
;
)
{
return
-
input
;
}
for
(
--
input
;
input
!=
input
;
input
+=
2
)
{
return
-
input
;
}
for
(
--
input
;
input
!=
input
;
input
+=
2
)
{
return
-
input
;
}
for
(;;)
if
(
input
.
x
>
2
.
0
)
break
;
for
(;;)
if
(
input
.
x
>
2
.
0
)
continue
;
float
ii
;
for
(
int
ii
=
-
1
;
ii
<
3
;
++
ii
)
if
(
ii
==
2
)
continue
;
--
ii
;
}
}
Test/hlsl.if.frag
View file @
5bc4d9a2
...
@@ -25,4 +25,9 @@ float4 PixelShaderFunction(float4 input) : COLOR0
...
@@ -25,4 +25,9 @@ float4 PixelShaderFunction(float4 input) : COLOR0
}
else
{
}
else
{
return
-
input
;
return
-
input
;
}
}
int
ii
;
if
(
float
ii
=
input
.
z
)
++
ii
;
++
ii
;
}
}
gtests/Hlsl.FromFile.cpp
View file @
5bc4d9a2
...
@@ -76,6 +76,7 @@ INSTANTIATE_TEST_CASE_P(
...
@@ -76,6 +76,7 @@ INSTANTIATE_TEST_CASE_P(
{
"hlsl.assoc.frag"
,
"PixelShaderFunction"
},
{
"hlsl.assoc.frag"
,
"PixelShaderFunction"
},
{
"hlsl.attribute.frag"
,
"PixelShaderFunction"
},
{
"hlsl.attribute.frag"
,
"PixelShaderFunction"
},
{
"hlsl.cast.frag"
,
"PixelShaderFunction"
},
{
"hlsl.cast.frag"
,
"PixelShaderFunction"
},
{
"hlsl.discard.frag"
,
"PixelShaderFunction"
},
{
"hlsl.doLoop.frag"
,
"PixelShaderFunction"
},
{
"hlsl.doLoop.frag"
,
"PixelShaderFunction"
},
{
"hlsl.float1.frag"
,
"PixelShaderFunction"
},
{
"hlsl.float1.frag"
,
"PixelShaderFunction"
},
{
"hlsl.float4.frag"
,
"PixelShaderFunction"
},
{
"hlsl.float4.frag"
,
"PixelShaderFunction"
},
...
...
hlsl/hlslGrammar.cpp
View file @
5bc4d9a2
...
@@ -106,7 +106,7 @@ bool HlslGrammar::acceptCompilationUnit()
...
@@ -106,7 +106,7 @@ bool HlslGrammar::acceptCompilationUnit()
// declaration
// declaration
// : SEMICOLON
// : SEMICOLON
//
:
fully_specified_type SEMICOLON
//
|
fully_specified_type SEMICOLON
// | fully_specified_type identifier array_specifier post_decls (EQUAL expression)opt SEMICOLON
// | fully_specified_type identifier array_specifier post_decls (EQUAL expression)opt SEMICOLON
// | fully_specified_type identifier function_parameters post_decls SEMICOLON // function prototype
// | fully_specified_type identifier function_parameters post_decls SEMICOLON // function prototype
// | fully_specified_type identifier function_parameters post_decls compound_statement // function definition
// | fully_specified_type identifier function_parameters post_decls compound_statement // function definition
...
@@ -173,6 +173,43 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
...
@@ -173,6 +173,43 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
return
true
;
return
true
;
}
}
// control_declaration
// : fully_specified_type identifier EQUAL expression
//
bool
HlslGrammar
::
acceptControlDeclaration
(
TIntermNode
*&
node
)
{
node
=
nullptr
;
// fully_specified_type
TType
type
;
if
(
!
acceptFullySpecifiedType
(
type
))
return
false
;
// identifier
HlslToken
idToken
;
if
(
!
acceptIdentifier
(
idToken
))
{
expected
(
"identifier"
);
return
false
;
}
// EQUAL
TIntermTyped
*
expressionNode
=
nullptr
;
if
(
!
acceptTokenClass
(
EHTokAssign
))
{
expected
(
"="
);
return
false
;
}
// expression
if
(
!
acceptExpression
(
expressionNode
))
{
expected
(
"initializer"
);
return
false
;
}
node
=
parseContext
.
declareVariable
(
idToken
.
loc
,
*
idToken
.
string
,
type
,
0
,
expressionNode
);
return
true
;
}
// fully_specified_type
// fully_specified_type
// : type_specifier
// : type_specifier
// | type_qualifier type_specifier
// | type_qualifier type_specifier
...
@@ -833,7 +870,9 @@ bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& no
...
@@ -833,7 +870,9 @@ bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& no
// Accept an expression with parenthesis around it, where
// Accept an expression with parenthesis around it, where
// the parenthesis ARE NOT expression parenthesis, but the
// the parenthesis ARE NOT expression parenthesis, but the
// syntactically required ones like in "if ( expression )"
// syntactically required ones like in "if ( expression )".
//
// Also accepts a declaration expression; "if (int a = expression)".
//
//
// Note this one is not set up to be speculative; as it gives
// Note this one is not set up to be speculative; as it gives
// errors if not found.
// errors if not found.
...
@@ -844,9 +883,21 @@ bool HlslGrammar::acceptParenExpression(TIntermTyped*& expression)
...
@@ -844,9 +883,21 @@ bool HlslGrammar::acceptParenExpression(TIntermTyped*& expression)
if
(
!
acceptTokenClass
(
EHTokLeftParen
))
if
(
!
acceptTokenClass
(
EHTokLeftParen
))
expected
(
"("
);
expected
(
"("
);
if
(
!
acceptExpression
(
expression
))
{
bool
decl
=
false
;
expected
(
"expression"
);
TIntermNode
*
declNode
=
nullptr
;
return
false
;
decl
=
acceptControlDeclaration
(
declNode
);
if
(
decl
)
{
if
(
declNode
==
nullptr
||
declNode
->
getAsTyped
()
==
nullptr
)
{
expected
(
"initialized declaration"
);
return
false
;
}
else
expression
=
declNode
->
getAsTyped
();
}
else
{
// no declaration
if
(
!
acceptExpression
(
expression
))
{
expected
(
"expression"
);
return
false
;
}
}
}
// RIGHT_PAREN
// RIGHT_PAREN
...
@@ -1567,9 +1618,14 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
...
@@ -1567,9 +1618,14 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
// of the for sub-statement
// of the for sub-statement
parseContext
.
pushScope
();
parseContext
.
pushScope
();
// initializer SEMI_COLON
// initializer
TIntermTyped
*
initializer
=
nullptr
;
// TODO, "for (initializer" needs to support decl. statement
TIntermNode
*
initNode
=
nullptr
;
acceptExpression
(
initializer
);
if
(
!
acceptControlDeclaration
(
initNode
))
{
TIntermTyped
*
initExpr
=
nullptr
;
acceptExpression
(
initExpr
);
initNode
=
initExpr
;
}
// SEMI_COLON
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
expected
(
";"
);
expected
(
";"
);
...
@@ -1592,7 +1648,7 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
...
@@ -1592,7 +1648,7 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
return
false
;
return
false
;
}
}
statement
=
intermediate
.
addForLoop
(
statement
,
init
ializer
,
condition
,
iterator
,
true
,
loc
);
statement
=
intermediate
.
addForLoop
(
statement
,
init
Node
,
condition
,
iterator
,
true
,
loc
);
parseContext
.
popScope
();
parseContext
.
popScope
();
parseContext
.
unnestLooping
();
parseContext
.
unnestLooping
();
...
@@ -1614,38 +1670,53 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
...
@@ -1614,38 +1670,53 @@ bool HlslGrammar::acceptIterationStatement(TIntermNode*& statement)
//
//
bool
HlslGrammar
::
acceptJumpStatement
(
TIntermNode
*&
statement
)
bool
HlslGrammar
::
acceptJumpStatement
(
TIntermNode
*&
statement
)
{
{
switch
(
peek
())
{
EHlslTokenClass
jump
=
peek
();
switch
(
jump
)
{
case
EHTokContinue
:
case
EHTokContinue
:
case
EHTokBreak
:
case
EHTokBreak
:
case
EHTokDiscard
:
case
EHTokDiscard
:
// TODO
return
false
;
case
EHTokReturn
:
case
EHTokReturn
:
// return
advanceToken
();
if
(
acceptTokenClass
(
EHTokReturn
))
{
break
;
// expression
default
:
TIntermTyped
*
node
;
// not something we handle in this function
if
(
acceptExpression
(
node
))
{
return
false
;
// hook it up
}
statement
=
intermediate
.
addBranch
(
EOpReturn
,
node
,
token
.
loc
);
}
else
statement
=
intermediate
.
addBranch
(
EOpReturn
,
token
.
loc
);
// SEMICOLON
switch
(
jump
)
{
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
{
case
EHTokContinue
:
expected
(
";"
);
statement
=
intermediate
.
addBranch
(
EOpContinue
,
token
.
loc
);
return
false
;
break
;
}
case
EHTokBreak
:
statement
=
intermediate
.
addBranch
(
EOpBreak
,
token
.
loc
);
break
;
case
EHTokDiscard
:
statement
=
intermediate
.
addBranch
(
EOpKill
,
token
.
loc
);
break
;
return
true
;
case
EHTokReturn
:
}
{
// expression
TIntermTyped
*
node
;
if
(
acceptExpression
(
node
))
{
// hook it up
statement
=
intermediate
.
addBranch
(
EOpReturn
,
node
,
token
.
loc
);
}
else
statement
=
intermediate
.
addBranch
(
EOpReturn
,
token
.
loc
);
break
;
}
default
:
default
:
assert
(
0
);
return
false
;
return
false
;
}
}
}
// SEMICOLON
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
expected
(
";"
);
return
true
;
}
bool
HlslGrammar
::
acceptCaseLabel
(
TIntermNode
*&
statement
)
bool
HlslGrammar
::
acceptCaseLabel
(
TIntermNode
*&
statement
)
{
{
...
...
hlsl/hlslGrammar.h
View file @
5bc4d9a2
...
@@ -58,6 +58,7 @@ namespace glslang {
...
@@ -58,6 +58,7 @@ namespace glslang {
bool
acceptIdentifier
(
HlslToken
&
);
bool
acceptIdentifier
(
HlslToken
&
);
bool
acceptCompilationUnit
();
bool
acceptCompilationUnit
();
bool
acceptDeclaration
(
TIntermNode
*&
node
);
bool
acceptDeclaration
(
TIntermNode
*&
node
);
bool
acceptControlDeclaration
(
TIntermNode
*&
node
);
bool
acceptFullySpecifiedType
(
TType
&
);
bool
acceptFullySpecifiedType
(
TType
&
);
void
acceptQualifier
(
TQualifier
&
);
void
acceptQualifier
(
TQualifier
&
);
bool
acceptType
(
TType
&
);
bool
acceptType
(
TType
&
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment