1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include <stddef.h>
25
26 #include "compiler/glsl_types.h"
27 #include "rogue_compiler.h"
28 #include "util/ralloc.h"
29
30 /**
31 * \file rogue_compiler.c
32 *
33 * \brief Contains the Rogue compiler interface.
34 */
35
36 /**
37 * \brief Creates and sets up a Rogue compiler context.
38 *
39 * \param[in] dev_info Device info pointer.
40 * \return A pointer to the new compiler context, or NULL on failure.
41 */
42 struct rogue_compiler *
rogue_compiler_create(const struct pvr_device_info * dev_info)43 rogue_compiler_create(const struct pvr_device_info *dev_info)
44 {
45 struct rogue_compiler *compiler;
46
47 compiler = rzalloc_size(NULL, sizeof(*compiler));
48 if (!compiler)
49 return NULL;
50
51 compiler->dev_info = dev_info;
52
53 /* TODO: Additional compiler setup (allocators? error message output
54 * location?).
55 */
56
57 glsl_type_singleton_init_or_ref();
58
59 return compiler;
60 }
61
62 /**
63 * \brief Destroys and frees a compiler context.
64 *
65 * \param[in] compiler The compiler context.
66 */
rogue_compiler_destroy(struct rogue_compiler * compiler)67 void rogue_compiler_destroy(struct rogue_compiler *compiler)
68 {
69 glsl_type_singleton_decref();
70
71 ralloc_free(compiler);
72 }
73