• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1COMMON_COPTS = [
2        "-DSPIRV_CHECK_CONTEXT",
3        "-DSPIRV_COLOR_TERMINAL",
4    ] + select({
5    "@bazel_tools//src/conditions:windows": [""],
6    "//conditions:default": [
7        "-DSPIRV_LINUX",
8        "-DSPIRV_TIMER_ENABLED",
9        "-Wall",
10        "-Wextra",
11        "-Wnon-virtual-dtor",
12        "-Wno-missing-field-initializers",
13        "-Werror",
14        "-std=c++11",
15        "-fvisibility=hidden",
16        "-fno-exceptions",
17        "-fno-rtti",
18        "-Wno-long-long",
19        "-Wshadow",
20        "-Wundef",
21        "-Wconversion",
22        "-Wno-sign-conversion",
23    ],
24})
25
26TEST_COPTS = COMMON_COPTS + select({
27    "@bazel_tools//src/conditions:windows": [
28        # Disable C4503 "decorated name length exceeded" warning,
29        # triggered by some heavily templated types.
30        # We don't care much about that in test code.
31        # Important to do since we have warnings-as-errors.
32        "/wd4503"
33    ],
34    "//conditions:default": [
35        "-Wno-undef",
36        "-Wno-self-assign",
37        "-Wno-shadow",
38        "-Wno-unused-parameter"
39    ],
40})
41
42DEBUGINFO_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_debuginfo_grammar_unified1"
43CLDEBUGINFO100_GRAMMAR_JSON_FILE = "@spirv_headers//:spirv_ext_inst_opencl_debuginfo_100_grammar_unified1"
44VKDEBUGINFO100_GRAMMAR_JSON_FILE = "source/extinst.nonsemantic.vulkan.debuginfo.100.grammar.json"
45
46def generate_core_tables(version = None):
47    if not version:
48        fail("Must specify version", "version")
49    grammars = [
50        "@spirv_headers//:spirv_core_grammar_" + version,
51        DEBUGINFO_GRAMMAR_JSON_FILE,
52        CLDEBUGINFO100_GRAMMAR_JSON_FILE,
53    ]
54    outs = [
55        "core.insts-{}.inc".format(version),
56        "operand.kinds-{}.inc".format(version),
57    ]
58    fmtargs = grammars + outs
59    native.genrule(
60        name = "gen_core_tables_" + version,
61        srcs = grammars,
62        outs = outs,
63        cmd = (
64            "$(location :generate_grammar_tables) " +
65            "--spirv-core-grammar=$(location {0}) " +
66            "--extinst-debuginfo-grammar=$(location {1}) " +
67            "--extinst-cldebuginfo100-grammar=$(location {2}) " +
68            "--core-insts-output=$(location {3}) " +
69            "--operand-kinds-output=$(location {4})"
70        ).format(*fmtargs),
71        tools = [":generate_grammar_tables"],
72        visibility = ["//visibility:private"],
73    )
74
75def generate_enum_string_mapping(version = None):
76    if not version:
77        fail("Must specify version", "version")
78    grammars = [
79        "@spirv_headers//:spirv_core_grammar_" + version,
80        DEBUGINFO_GRAMMAR_JSON_FILE,
81        CLDEBUGINFO100_GRAMMAR_JSON_FILE,
82    ]
83    outs = [
84        "extension_enum.inc",
85        "enum_string_mapping.inc",
86    ]
87    fmtargs = grammars + outs
88    native.genrule(
89        name = "gen_enum_string_mapping",
90        srcs = grammars,
91        outs = outs,
92        cmd = (
93            "$(location :generate_grammar_tables) " +
94            "--spirv-core-grammar=$(location {0}) " +
95            "--extinst-debuginfo-grammar=$(location {1}) " +
96            "--extinst-cldebuginfo100-grammar=$(location {2}) " +
97            "--extension-enum-output=$(location {3}) " +
98            "--enum-string-mapping-output=$(location {4})"
99        ).format(*fmtargs),
100        tools = [":generate_grammar_tables"],
101        visibility = ["//visibility:private"],
102    )
103
104def generate_opencl_tables(version = None):
105    if not version:
106        fail("Must specify version", "version")
107    grammars = [
108        "@spirv_headers//:spirv_opencl_grammar_" + version,
109    ]
110    outs = ["opencl.std.insts.inc"]
111    fmtargs = grammars + outs
112    native.genrule(
113        name = "gen_opencl_tables_" + version,
114        srcs = grammars,
115        outs = outs,
116        cmd = (
117            "$(location :generate_grammar_tables) " +
118            "--extinst-opencl-grammar=$(location {0}) " +
119            "--opencl-insts-output=$(location {1})"
120        ).format(*fmtargs),
121        tools = [":generate_grammar_tables"],
122        visibility = ["//visibility:private"],
123    )
124
125def generate_glsl_tables(version = None):
126    if not version:
127        fail("Must specify version", "version")
128    grammars = [
129        "@spirv_headers//:spirv_glsl_grammar_" + version,
130    ]
131    outs = ["glsl.std.450.insts.inc"]
132    fmtargs = grammars + outs
133    native.genrule(
134        name = "gen_glsl_tables_" + version,
135        srcs = grammars,
136        outs = outs,
137        cmd = (
138            "$(location :generate_grammar_tables) " +
139            "--extinst-glsl-grammar=$(location {0}) " +
140            "--glsl-insts-output=$(location {1})"
141        ).format(*fmtargs),
142        tools = [":generate_grammar_tables"],
143        visibility = ["//visibility:private"],
144    )
145
146def generate_vendor_tables(extension, operand_kind_prefix = ""):
147    if not extension:
148        fail("Must specify extension", "extension")
149    extension_rule = extension.replace("-", "_").replace(".", "_")
150    grammars = ["@spirv_headers//:spirv_ext_inst_{}_grammar_unified1".format(extension_rule)]
151    outs = ["{}.insts.inc".format(extension)]
152    prefices = [operand_kind_prefix]
153    fmtargs = grammars + outs + prefices
154    native.genrule(
155        name = "gen_vendor_tables_" + extension_rule,
156        srcs = grammars,
157        outs = outs,
158        cmd = (
159            "$(location :generate_grammar_tables) " +
160            "--extinst-vendor-grammar=$(location {0}) " +
161            "--vendor-insts-output=$(location {1}) " +
162            "--vendor-operand-kind-prefix={2}"
163        ).format(*fmtargs),
164        tools = [":generate_grammar_tables"],
165        visibility = ["//visibility:private"],
166    )
167
168def generate_vendor_tables_local(extension, operand_kind_prefix = ""):
169    if not extension:
170        fail("Must specify extension", "extension")
171    extension_rule = extension.replace("-", "_").replace(".", "_")
172    grammars = ["source/extinst.{}.grammar.json".format(extension)]
173    outs = ["{}.insts.inc".format(extension)]
174    prefices = [operand_kind_prefix]
175    fmtargs = grammars + outs + prefices
176    native.genrule(
177        name = "gen_vendor_tables_" + extension_rule,
178        srcs = grammars,
179        outs = outs,
180        cmd = (
181            "$(location :generate_grammar_tables) " +
182            "--extinst-vendor-grammar=$(location {0}) " +
183            "--vendor-insts-output=$(location {1}) " +
184            "--vendor-operand-kind-prefix={2}"
185        ).format(*fmtargs),
186        tools = [":generate_grammar_tables"],
187        visibility = ["//visibility:private"],
188    )
189
190def generate_extinst_lang_headers(name, grammar = None):
191    if not grammar:
192        fail("Must specify grammar", "grammar")
193    outs = [name + ".h"]
194    fmtargs = outs
195    native.genrule(
196        name = "gen_extinst_lang_headers_" + name,
197        srcs = [grammar],
198        outs = outs,
199        cmd = (
200            "$(location :generate_language_headers) " +
201            "--extinst-grammar=$< " +
202            "--extinst-output-path=$(location {0})"
203        ).format(*fmtargs),
204        tools = [":generate_language_headers"],
205        visibility = ["//visibility:private"],
206    )
207
208def base_test(name, srcs, deps = []):
209    if srcs == []:
210        return
211    if name[-5:] != "_test":
212        name = name + "_test"
213    native.cc_test(
214        name = "base_" + name,
215        srcs = srcs,
216        compatible_with = [],
217        copts = TEST_COPTS,
218        size = "large",
219        deps = [
220            ":test_common",
221            "@com_google_googletest//:gtest_main",
222            "@com_google_googletest//:gtest",
223            "@com_google_effcee//:effcee",
224        ] + deps,
225    )
226
227def link_test(name, srcs, deps = []):
228    if name[-5:] != "_test":
229        name = name + "_test"
230    native.cc_test(
231        name = "link_" + name,
232        srcs = srcs,
233        compatible_with = [],
234        copts = TEST_COPTS,
235        size = "large",
236        deps = [
237            ":link_test_common",
238            "@com_google_googletest//:gtest_main",
239            "@com_google_googletest//:gtest",
240            "@com_google_effcee//:effcee",
241        ] + deps,
242    )
243
244def opt_test(name, srcs, deps = []):
245    if name[-5:] != "_test":
246        name = name + "_test"
247    native.cc_test(
248        name = "opt_" + name,
249        srcs = srcs,
250        compatible_with = [],
251        copts = TEST_COPTS,
252        size = "large",
253        deps = [
254            ":opt_test_common",
255            "@com_google_googletest//:gtest_main",
256            "@com_google_googletest//:gtest",
257            "@com_google_effcee//:effcee",
258        ] + deps,
259    )
260
261def reduce_test(name, srcs, deps = []):
262    if name[-5:] != "_test":
263        name = name + "_test"
264    native.cc_test(
265        name = "reduce_" + name,
266        srcs = srcs,
267        compatible_with = [],
268        copts = TEST_COPTS,
269        size = "large",
270        deps = [
271            ":reduce_test_common",
272            ":spirv_tools_reduce",
273            "@com_google_googletest//:gtest_main",
274            "@com_google_googletest//:gtest",
275            "@com_google_effcee//:effcee",
276        ] + deps,
277    )
278
279def util_test(name, srcs, deps = []):
280    if name[-5:] != "_test":
281        name = name + "_test"
282    native.cc_test(
283        name = "util_" + name,
284        srcs = srcs,
285        compatible_with = [],
286        copts = TEST_COPTS,
287        size = "large",
288        deps = [
289            ":opt_test_common",
290            "@com_google_googletest//:gtest_main",
291            "@com_google_googletest//:gtest",
292            "@com_google_effcee//:effcee",
293        ] + deps,
294    )
295
296def val_test(name, srcs = [], copts = [], deps = [], **kwargs):
297    if name[-5:] != "_test":
298        name = name + "_test"
299    if name[:4] != "val_":
300        name = "val_" + name
301    native.cc_test(
302        name = name,
303        srcs = srcs,
304        compatible_with = [],
305        copts = TEST_COPTS + copts,
306        size = "large",
307        deps = [
308            ":val_test_common",
309            "@com_google_googletest//:gtest_main",
310            "@com_google_googletest//:gtest",
311            "@com_google_effcee//:effcee",
312        ] + deps,
313        **kwargs
314    )
315