17ec681f3Smrg/*
27ec681f3Smrg * Copyright © Microsoft Corporation
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#ifndef MESA_CLC_HELPERS_H
257ec681f3Smrg#define MESA_CLC_HELPERS_H
267ec681f3Smrg
277ec681f3Smrg#include "nir_types.h"
287ec681f3Smrg
297ec681f3Smrg#include "clc.h"
307ec681f3Smrg#include "util/u_string.h"
317ec681f3Smrg
327ec681f3Smrg#include <assert.h>
337ec681f3Smrg#include <stddef.h>
347ec681f3Smrg#include <stdio.h>
357ec681f3Smrg#include <stdint.h>
367ec681f3Smrg
377ec681f3Smrg#ifdef __cplusplus
387ec681f3Smrgextern "C" {
397ec681f3Smrg#endif
407ec681f3Smrg
417ec681f3Smrgbool
427ec681f3Smrgclc_spirv_get_kernels_info(const struct clc_binary *spvbin,
437ec681f3Smrg                           const struct clc_kernel_info **kernels,
447ec681f3Smrg                           unsigned *num_kernels,
457ec681f3Smrg                           const struct clc_parsed_spec_constant **spec_constants,
467ec681f3Smrg                           unsigned *num_spec_constants,
477ec681f3Smrg                           const struct clc_logger *logger);
487ec681f3Smrg
497ec681f3Smrgvoid
507ec681f3Smrgclc_free_kernels_info(const struct clc_kernel_info *kernels,
517ec681f3Smrg                      unsigned num_kernels);
527ec681f3Smrg
537ec681f3Smrgint
547ec681f3Smrgclc_c_to_spir(const struct clc_compile_args *args,
557ec681f3Smrg              const struct clc_logger *logger,
567ec681f3Smrg              struct clc_binary *out_spir);
577ec681f3Smrg
587ec681f3Smrgint
597ec681f3Smrgclc_spir_to_spirv(const struct clc_binary *in_spir,
607ec681f3Smrg                  const struct clc_logger *logger,
617ec681f3Smrg                  struct clc_binary *out_spirv);
627ec681f3Smrg
637ec681f3Smrgint
647ec681f3Smrgclc_c_to_spirv(const struct clc_compile_args *args,
657ec681f3Smrg               const struct clc_logger *logger,
667ec681f3Smrg               struct clc_binary *out_spirv);
677ec681f3Smrg
687ec681f3Smrgint
697ec681f3Smrgclc_link_spirv_binaries(const struct clc_linker_args *args,
707ec681f3Smrg                        const struct clc_logger *logger,
717ec681f3Smrg                        struct clc_binary *out_spirv);
727ec681f3Smrg
737ec681f3Smrgint
747ec681f3Smrgclc_spirv_specialize(const struct clc_binary *in_spirv,
757ec681f3Smrg                     const struct clc_parsed_spirv *parsed_data,
767ec681f3Smrg                     const struct clc_spirv_specialization_consts *consts,
777ec681f3Smrg                     struct clc_binary *out_spirv);
787ec681f3Smrg
797ec681f3Smrgvoid
807ec681f3Smrgclc_dump_spirv(const struct clc_binary *spvbin, FILE *f);
817ec681f3Smrg
827ec681f3Smrgvoid
837ec681f3Smrgclc_free_spir_binary(struct clc_binary *spir);
847ec681f3Smrg
857ec681f3Smrgvoid
867ec681f3Smrgclc_free_spirv_binary(struct clc_binary *spvbin);
877ec681f3Smrg
887ec681f3Smrg#define clc_log(logger, level, fmt, ...) do {        \
897ec681f3Smrg      if (!logger || !logger->level) break;          \
907ec681f3Smrg      char *_msg = NULL;                             \
917ec681f3Smrg      asprintf(&_msg, fmt, ##__VA_ARGS__);           \
927ec681f3Smrg      assert(_msg);                                  \
937ec681f3Smrg      logger->level(logger->priv, _msg);             \
947ec681f3Smrg      free(_msg);                                    \
957ec681f3Smrg   } while (0)
967ec681f3Smrg
977ec681f3Smrg#define clc_error(logger, fmt, ...) clc_log(logger, error, fmt, ##__VA_ARGS__)
987ec681f3Smrg#define clc_warning(logger, fmt, ...) clc_log(logger, warning, fmt, ##__VA_ARGS__)
997ec681f3Smrg
1007ec681f3Smrg#ifdef __cplusplus
1017ec681f3Smrg}
1027ec681f3Smrg#endif
1037ec681f3Smrg
1047ec681f3Smrg#endif /* MESA_CLC_HELPERS_H */
105