• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CLOVER_CORE_MODULE_HPP
24 #define CLOVER_CORE_MODULE_HPP
25 
26 #include <vector>
27 #include <string>
28 
29 namespace clover {
30    struct module {
31       typedef uint32_t resource_id;
32       typedef uint32_t size_t;
33 
34       struct section {
35          enum type {
36             text_intermediate,
37             text_library,
38             text_executable,
39             data_constant,
40             data_global,
41             data_local,
42             data_private
43          };
44 
sectionclover::module::section45          section(resource_id id, enum type type, size_t size,
46                  const std::vector<char> &data) :
47                  id(id), type(type), size(size), data(data) { }
sectionclover::module::section48          section() : id(0), type(text_intermediate), size(0), data() { }
49 
50          resource_id id;
51          type type;
52          size_t size;
53          std::vector<char> data;
54       };
55 
56       struct argument {
57          enum type {
58             scalar,
59             constant,
60             global,
61             local,
62             image2d_rd,
63             image2d_wr,
64             image3d_rd,
65             image3d_wr,
66             sampler
67          };
68 
69          enum ext_type {
70             zero_ext,
71             sign_ext
72          };
73 
74          enum semantic {
75             general,
76             grid_dimension,
77             grid_offset,
78             image_size,
79             image_format
80          };
81 
argumentclover::module::argument82          argument(enum type type, size_t size,
83                   size_t target_size, size_t target_align,
84                   enum ext_type ext_type,
85                   enum semantic semantic = general) :
86             type(type), size(size),
87             target_size(target_size), target_align(target_align),
88             ext_type(ext_type), semantic(semantic) { }
89 
argumentclover::module::argument90          argument(enum type type, size_t size) :
91             type(type), size(size),
92             target_size(size), target_align(1),
93             ext_type(zero_ext), semantic(general) { }
94 
argumentclover::module::argument95          argument() : type(scalar), size(0),
96                       target_size(0), target_align(1),
97                       ext_type(zero_ext), semantic(general) { }
98 
99          type type;
100          size_t size;
101          size_t target_size;
102          size_t target_align;
103          ext_type ext_type;
104          semantic semantic;
105       };
106 
107       struct symbol {
symbolclover::module::symbol108          symbol(const std::string &name, resource_id section,
109                 size_t offset, const std::vector<argument> &args) :
110                 name(name), section(section), offset(offset), args(args) { }
symbolclover::module::symbol111          symbol() : name(), section(0), offset(0), args() { }
112 
113          std::string name;
114          resource_id section;
115          size_t offset;
116          std::vector<argument> args;
117       };
118 
119       void serialize(std::ostream &os) const;
120       static module deserialize(std::istream &is);
121       size_t size() const;
122 
123       std::vector<symbol> syms;
124       std::vector<section> secs;
125    };
126 }
127 
128 #endif
129