1/*
2 * Copyright © Microsoft Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifndef MESA_CLC_HELPERS_H
25#define MESA_CLC_HELPERS_H
26
27#include "nir_types.h"
28
29#include "clc.h"
30#include "util/u_string.h"
31
32#include <assert.h>
33#include <stddef.h>
34#include <stdio.h>
35#include <stdint.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41bool
42clc_spirv_get_kernels_info(const struct clc_binary *spvbin,
43                           const struct clc_kernel_info **kernels,
44                           unsigned *num_kernels,
45                           const struct clc_parsed_spec_constant **spec_constants,
46                           unsigned *num_spec_constants,
47                           const struct clc_logger *logger);
48
49void
50clc_free_kernels_info(const struct clc_kernel_info *kernels,
51                      unsigned num_kernels);
52
53int
54clc_c_to_spir(const struct clc_compile_args *args,
55              const struct clc_logger *logger,
56              struct clc_binary *out_spir);
57
58int
59clc_spir_to_spirv(const struct clc_binary *in_spir,
60                  const struct clc_logger *logger,
61                  struct clc_binary *out_spirv);
62
63int
64clc_c_to_spirv(const struct clc_compile_args *args,
65               const struct clc_logger *logger,
66               struct clc_binary *out_spirv);
67
68int
69clc_link_spirv_binaries(const struct clc_linker_args *args,
70                        const struct clc_logger *logger,
71                        struct clc_binary *out_spirv);
72
73int
74clc_spirv_specialize(const struct clc_binary *in_spirv,
75                     const struct clc_parsed_spirv *parsed_data,
76                     const struct clc_spirv_specialization_consts *consts,
77                     struct clc_binary *out_spirv);
78
79void
80clc_dump_spirv(const struct clc_binary *spvbin, FILE *f);
81
82void
83clc_free_spir_binary(struct clc_binary *spir);
84
85void
86clc_free_spirv_binary(struct clc_binary *spvbin);
87
88#define clc_log(logger, level, fmt, ...) do {        \
89      if (!logger || !logger->level) break;          \
90      char *_msg = NULL;                             \
91      asprintf(&_msg, fmt, ##__VA_ARGS__);           \
92      assert(_msg);                                  \
93      logger->level(logger->priv, _msg);             \
94      free(_msg);                                    \
95   } while (0)
96
97#define clc_error(logger, fmt, ...) clc_log(logger, error, fmt, ##__VA_ARGS__)
98#define clc_warning(logger, fmt, ...) clc_log(logger, warning, fmt, ##__VA_ARGS__)
99
100#ifdef __cplusplus
101}
102#endif
103
104#endif /* MESA_CLC_HELPERS_H */
105