2 // Copyright 2012 Francisco Jerez
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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.
23 #ifndef _CORE_MODULE_HPP_
24 #define _CORE_MODULE_HPP_
26 #include "core/compat.hpp"
32 virtual ~noent_error() {}
35 typedef uint32_t resource_id;
36 typedef uint32_t size_t;
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() { }
55 clover::compat::vector<char> data;
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) { }
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) { }
88 argument() : type(scalar), size(0),
89 target_size(0), target_align(1),
90 ext_type(zero_ext) { }
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() { }
105 clover::compat::vector<char> name;
108 clover::compat::vector<argument> args;
111 void serialize(compat::ostream &os) const;
112 static module deserialize(compat::istream &is);
114 /// Look up a symbol by name. Throws module::noent_error if not
116 const symbol &sym(compat::string name) const;
118 /// Look up a section by type. Throws module::noent_error if not
120 const section &sec(typename section::type type) const;
122 clover::compat::vector<symbol> syms;
123 clover::compat::vector<section> secs;