776dee87257f1051c5c11e25544c367563060ab2
[mesa.git] / src / gallium / state_trackers / clover / core / module.hpp
1 //
2 // Copyright 2012 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 _CORE_MODULE_HPP_
24 #define _CORE_MODULE_HPP_
25
26 #include "core/compat.hpp"
27
28 namespace clover {
29 struct module {
30 class noent_error {
31 public:
32 virtual ~noent_error() {}
33 };
34
35 typedef uint32_t resource_id;
36 typedef uint32_t size_t;
37
38 struct section {
39 enum type {
40 text,
41 data_constant,
42 data_global,
43 data_local,
44 data_private
45 };
46
47 section(resource_id id, enum type type, size_t size,
48 const clover::compat::vector<char> &data) :
49 id(id), type(type), size(size), data(data) { }
50 section() : id(0), type(text), size(0), data() { }
51
52 resource_id id;
53 type type;
54 size_t size;
55 clover::compat::vector<char> data;
56 };
57
58 struct argument {
59 enum type {
60 scalar,
61 constant,
62 global,
63 local,
64 image2d_rd,
65 image2d_wr,
66 image3d_rd,
67 image3d_wr,
68 sampler
69 };
70
71 enum ext_type {
72 zero_ext,
73 sign_ext
74 };
75
76 argument(enum type type, size_t size,
77 size_t target_size, size_t target_align,
78 enum ext_type ext_type) :
79 type(type), size(size),
80 target_size(target_size), target_align(target_align),
81 ext_type(ext_type) { }
82
83 argument(enum type type, size_t size) :
84 type(type), size(size),
85 target_size(size), target_align(1),
86 ext_type(zero_ext) { }
87
88 argument() : type(scalar), size(0),
89 target_size(0), target_align(1),
90 ext_type(zero_ext) { }
91
92 type type;
93 size_t size;
94 size_t target_size;
95 size_t target_align;
96 ext_type ext_type;
97 };
98
99 struct symbol {
100 symbol(const clover::compat::vector<char> &name, resource_id section,
101 size_t offset, const clover::compat::vector<argument> &args) :
102 name(name), section(section), offset(offset), args(args) { }
103 symbol() : name(), section(0), offset(0), args() { }
104
105 clover::compat::vector<char> name;
106 resource_id section;
107 size_t offset;
108 clover::compat::vector<argument> args;
109 };
110
111 void serialize(compat::ostream &os) const;
112 static module deserialize(compat::istream &is);
113
114 /// Look up a symbol by name. Throws module::noent_error if not
115 /// found.
116 const symbol &sym(compat::string name) const;
117
118 /// Look up a section by type. Throws module::noent_error if not
119 /// found.
120 const section &sec(typename section::type type) const;
121
122 clover::compat::vector<symbol> syms;
123 clover::compat::vector<section> secs;
124 };
125 }
126
127 #endif