1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23import sys
24from genutil import *
25
26# Templates
27
28reservedOperatorCaseTemplate = """
29case operator_${{NAME}}
30	expect compile_fail
31	values {}
32
33	both ""
34		precision mediump float;
35		precision mediump int;
36
37		${DECLARATIONS}
38
39		void main()
40		{
41			${SETUP}
42			int value = 100;
43			${{OP}}
44			${OUTPUT}
45		}
46	""
47end
48"""[1:-1]
49
50# Classes
51
52class ReservedOperatorCase(ShaderCase):
53	def __init__(self, op):
54		self.name		= op.name
55		if op.operator == "~":
56			self.operation = 'value = ~value;'
57		else:
58			self.operation	= 'value ' + op.operator + ' 1;'
59
60	def __str__(self):
61		params = {
62			"NAME": self.name,
63			"OP"  : self.operation
64		}
65		return fillTemplate(reservedOperatorCaseTemplate, params)
66
67
68class Operator():
69	def __init__(self, operator, name):
70		self.operator	= operator
71		self.name		= name
72
73# Declarations
74
75RESERVED_OPERATORS = [
76	Operator("%",	"modulo"),
77	Operator("~",	"bitwise_not"),
78	Operator("<<",	"bitwise_shift_left"),
79	Operator(">>",	"bitwise_shift_right"),
80	Operator("&",	"bitwise_and"),
81	Operator("^",	"bitwise_xor"),
82	Operator("|",	"bitwise_or"),
83	Operator("%=",	"assign_modulo"),
84	Operator("<<=",	"assign_shift_left"),
85	Operator(">>=", "assign_shift_right"),
86	Operator("&=",	"assign_and"),
87	Operator("^=",	"assign_xor"),
88	Operator("|=",	"assign_or")
89]
90
91# Reserved operator usage cases
92
93reservedOperatorCases = []
94
95for operator in RESERVED_OPERATORS:
96	reservedOperatorCases.append(ReservedOperatorCase(operator))		# Reserved operators
97
98# Main program
99
100if __name__ == "__main__":
101	print("Generating shader case files.")
102	writeAllCases("reserved_operators.test",	reservedOperatorCases)
103