clover: Move back to using build_error to signal compilation failure.
[mesa.git] / src / gallium / state_trackers / clover / core / error.hpp
1 //
2 // Copyright 2013 Francisco Jerez
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 shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22
23 #ifndef CLOVER_CORE_ERROR_HPP
24 #define CLOVER_CORE_ERROR_HPP
25
26 #include "CL/cl.h"
27
28 #include <stdexcept>
29 #include <string>
30
31 namespace clover {
32 class command_queue;
33 class context;
34 class device;
35 class event;
36 class hard_event;
37 class soft_event;
38 class kernel;
39 class memory_obj;
40 class buffer;
41 class root_buffer;
42 class sub_buffer;
43 class image;
44 class image2d;
45 class image3d;
46 class platform;
47 class program;
48 class sampler;
49
50 ///
51 /// Class that represents an error that can be converted to an
52 /// OpenCL status code.
53 ///
54 class error : public std::runtime_error {
55 public:
56 error(cl_int code, std::string what = "") :
57 std::runtime_error(what), code(code) {
58 }
59
60 cl_int get() const {
61 return code;
62 }
63
64 protected:
65 cl_int code;
66 };
67
68 class build_error : public error {
69 public:
70 build_error(const std::string &what = "") :
71 error(CL_BUILD_PROGRAM_FAILURE, what) {}
72 };
73
74 template<typename O>
75 class invalid_object_error;
76
77 template<>
78 class invalid_object_error<command_queue> : public error {
79 public:
80 invalid_object_error(std::string what = "") :
81 error(CL_INVALID_COMMAND_QUEUE, what) {}
82 };
83
84 template<>
85 class invalid_object_error<context> : public error {
86 public:
87 invalid_object_error(std::string what = "") :
88 error(CL_INVALID_CONTEXT, what) {}
89 };
90
91 template<>
92 class invalid_object_error<device> : public error {
93 public:
94 invalid_object_error(std::string what = "") :
95 error(CL_INVALID_DEVICE, what) {}
96 };
97
98 template<>
99 class invalid_object_error<event> : public error {
100 public:
101 invalid_object_error(std::string what = "") :
102 error(CL_INVALID_EVENT, what) {}
103 };
104
105 template<>
106 class invalid_object_error<soft_event> : public error {
107 public:
108 invalid_object_error(std::string what = "") :
109 error(CL_INVALID_EVENT, what) {}
110 };
111
112 template<>
113 class invalid_object_error<kernel> : public error {
114 public:
115 invalid_object_error(std::string what = "") :
116 error(CL_INVALID_KERNEL, what) {}
117 };
118
119 template<>
120 class invalid_object_error<memory_obj> : public error {
121 public:
122 invalid_object_error(std::string what = "") :
123 error(CL_INVALID_MEM_OBJECT, what) {}
124 };
125
126 template<>
127 class invalid_object_error<buffer> : public error {
128 public:
129 invalid_object_error(std::string what = "") :
130 error(CL_INVALID_MEM_OBJECT, what) {}
131 };
132
133 template<>
134 class invalid_object_error<root_buffer> : public error {
135 public:
136 invalid_object_error(std::string what = "") :
137 error(CL_INVALID_MEM_OBJECT, what) {}
138 };
139
140 template<>
141 class invalid_object_error<sub_buffer> : public error {
142 public:
143 invalid_object_error(std::string what = "") :
144 error(CL_INVALID_MEM_OBJECT, what) {}
145 };
146
147 template<>
148 class invalid_object_error<image> : public error {
149 public:
150 invalid_object_error(std::string what = "") :
151 error(CL_INVALID_MEM_OBJECT, what) {}
152 };
153
154 template<>
155 class invalid_object_error<image2d> : public error {
156 public:
157 invalid_object_error(std::string what = "") :
158 error(CL_INVALID_MEM_OBJECT, what) {}
159 };
160
161 template<>
162 class invalid_object_error<image3d> : public error {
163 public:
164 invalid_object_error(std::string what = "") :
165 error(CL_INVALID_MEM_OBJECT, what) {}
166 };
167
168 template<>
169 class invalid_object_error<platform> : public error {
170 public:
171 invalid_object_error(std::string what = "") :
172 error(CL_INVALID_PLATFORM, what) {}
173 };
174
175 template<>
176 class invalid_object_error<program> : public error {
177 public:
178 invalid_object_error(std::string what = "") :
179 error(CL_INVALID_PROGRAM, what) {}
180 };
181
182 template<>
183 class invalid_object_error<sampler> : public error {
184 public:
185 invalid_object_error(std::string what = "") :
186 error(CL_INVALID_SAMPLER, what) {}
187 };
188
189 class invalid_wait_list_error : public error {
190 public:
191 invalid_wait_list_error(std::string what = "") :
192 error(CL_INVALID_EVENT_WAIT_LIST, what) {}
193 };
194 }
195
196 #endif