blob: 76506f160444dea1b5c04f37ba2009f7b7d1a739 [file] [log] [blame]
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01001#include <libspirv/libspirv.h>
2
3#include <string.h>
4
5static const spv_ext_inst_desc_t glslStd450Entries[] = {
6 {
Lei Zhang884c8332015-08-14 14:42:30 -04007 "round", GLSLstd450::GLSLstd450Round, {SPV_OPERAND_TYPE_ID},
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01008 },
9 // TODO: Add remaining GLSL.std.450 instructions
10};
11
12static const spv_ext_inst_desc_t openclStd12Entries[] = {
13 {"placeholder", 0, {}},
14 // TODO: Add remaining OpenCL.std.12 instructions
15};
16
17static const spv_ext_inst_desc_t openclStd20Entries[] = {
18 {"placeholder", 0, {}},
19 // TODO: Add remaining OpenCL.std.20 instructions
20};
21
22static const spv_ext_inst_desc_t openclStd21Entries[] = {
23 {"placeholder", 0, {}},
24 // TODO: Add remaining OpenCL.std.21 instructions
25};
26
27spv_result_t spvExtInstTableGet(spv_ext_inst_table *pExtInstTable) {
28 spvCheck(!pExtInstTable, return SPV_ERROR_INVALID_POINTER);
29
30 static const spv_ext_inst_group_t groups[] = {
31 {SPV_EXT_INST_TYPE_GLSL_STD_450,
32 sizeof(glslStd450Entries) / sizeof(spv_ext_inst_desc_t),
33 glslStd450Entries},
34 {SPV_EXT_INST_TYPE_OPENCL_STD_12,
35 sizeof(openclStd12Entries) / sizeof(spv_ext_inst_desc_t),
36 openclStd12Entries},
37 {SPV_EXT_INST_TYPE_OPENCL_STD_20,
38 sizeof(openclStd20Entries) / sizeof(spv_ext_inst_desc_t),
39 openclStd20Entries},
40 {SPV_EXT_INST_TYPE_OPENCL_STD_21,
41 sizeof(openclStd21Entries) / sizeof(spv_ext_inst_desc_t),
42 openclStd21Entries},
43 };
44
45 static const spv_ext_inst_table_t table = {
46 sizeof(groups) / sizeof(spv_ext_inst_group_t), groups};
47
48 *pExtInstTable = &table;
49
50 return SPV_SUCCESS;
51}
52
53spv_ext_inst_type_t spvExtInstImportTypeGet(const char *name) {
54 if (!strcmp("GLSL.std.450", name)) {
55 return SPV_EXT_INST_TYPE_GLSL_STD_450;
56 }
57 if (!strcmp("OpenCL.std.12", name)) {
58 return SPV_EXT_INST_TYPE_OPENCL_STD_12;
59 }
60 if (!strcmp("OpenCL.std.20", name)) {
61 return SPV_EXT_INST_TYPE_OPENCL_STD_20;
62 }
63 if (!strcmp("OpenCL.std.21", name)) {
64 return SPV_EXT_INST_TYPE_OPENCL_STD_21;
65 }
66 return SPV_EXT_INST_TYPE_NONE;
67}
68
69spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table,
70 const spv_ext_inst_type_t type,
71 const char *name,
72 spv_ext_inst_desc *pEntry) {
73 spvCheck(!table, return SPV_ERROR_INVALID_TABLE);
74 spvCheck(!pEntry, return SPV_ERROR_INVALID_POINTER);
75
76 for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) {
77 auto &group = table->groups[groupIndex];
78 if (type == group.type) {
79 for (uint32_t index = 0; index < group.count; index++) {
80 auto &entry = group.entries[index];
81 if (!strcmp(name, entry.name)) {
82 *pEntry = &table->groups[groupIndex].entries[index];
83 return SPV_SUCCESS;
84 }
85 }
86 }
87 }
88
89 return SPV_ERROR_INVALID_LOOKUP;
90}
91
92spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table,
93 const spv_ext_inst_type_t type,
94 const uint32_t value,
95 spv_ext_inst_desc *pEntry) {
96 spvCheck(!table, return SPV_ERROR_INVALID_TABLE);
97 spvCheck(!pEntry, return SPV_ERROR_INVALID_POINTER);
98
99 for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) {
100 auto &group = table->groups[groupIndex];
101 if (type == group.type) {
102 for (uint32_t index = 0; index < group.count; index++) {
103 auto &entry = group.entries[index];
104 if (value == entry.ext_inst) {
105 *pEntry = &table->groups[groupIndex].entries[index];
106 return SPV_SUCCESS;
107 }
108 }
109 }
110 }
111
112 return SPV_ERROR_INVALID_LOOKUP;
113}