16 #ifndef PSTORE_MCREPO_COMPILATION_HPP 17 #define PSTORE_MCREPO_COMPILATION_HPP 21 #include "pstore/core/index_types.hpp" 23 #include "pstore/mcrepo/repo_error.hpp" 30 #define PSTORE_REPO_LINKAGES \ 34 X (internal_no_symbol) \ 42 enum class linkage : std::uint8_t { PSTORE_REPO_LINKAGES };
45 std::ostream & operator<< (std::ostream & os, linkage l);
47 #define PSTORE_REPO_VISIBILITIES \ 53 enum class visibility : std::uint8_t { PSTORE_REPO_VISIBILITIES };
72 linkage l, visibility v = repo::visibility::default_vis) noexcept;
84 std::uint8_t bf = UINT8_C (0);
88 std::uint8_t padding1 = 0;
89 std::uint16_t padding2 = 0;
90 std::uint32_t padding3 = 0;
92 auto linkage ()
const noexcept ->
enum linkage {
93 return static_cast<enum linkage
> (linkage_.value ());
95 auto visibility ()
const noexcept ->
enum visibility {
96 return static_cast<enum visibility
> (visibility_.value ());
105 -> std::shared_ptr<definition const>;
117 -> std::shared_ptr<definition const> {
118 return db.getro (addr);
132 using size_type = std::uint32_t;
134 void operator delete (
void * p);
150 template <
typename TransactionType,
typename Iterator>
153 Iterator first_member, Iterator last_member);
160 static std::shared_ptr<compilation const> load (
database const & db,
166 definition const & operator[] (std::size_t
const i)
const {
167 PSTORE_ASSERT (i < size_);
175 const_iterator
begin ()
const {
return members_; }
176 const_iterator cbegin ()
const {
return this->
begin (); }
178 iterator end () {
return members_ + size_; }
179 const_iterator end ()
const {
return members_ + size_; }
180 const_iterator cend ()
const {
return this->end (); }
187 bool empty () const noexcept {
return size_ == 0; }
189 size_type
size () const noexcept {
return size_; }
198 size = std::max (size, size_type{1});
199 return sizeof (
compilation) -
sizeof (compilation::members_) +
200 sizeof (compilation::members_[0]) * size;
225 template <
typename Iterator>
227 Iterator first_member, Iterator last_member) noexcept;
234 void *
operator new (std::size_t s, nmembers size);
236 void *
operator new (std::size_t s,
void * ptr);
237 void operator delete (
void * p, nmembers size);
238 void operator delete (
void * p,
void * ptr);
240 static constexpr std::array<char, 8> compilation_signature_ = {
241 {
'C',
'm',
'p',
'l',
'8',
'i',
'o',
'n'}};
243 std::array<char, 8> signature_ = compilation_signature_;
248 std::uint32_t padding1_ = 0;
252 PSTORE_STATIC_ASSERT (std::is_standard_layout<compilation>::value);
254 PSTORE_STATIC_ASSERT (
alignof (
compilation) == 16);
256 template <
typename Iterator>
258 Iterator
const first_member, Iterator
const last_member) noexcept
263 PSTORE_STATIC_ASSERT (offsetof (
compilation, signature_) == 0);
264 PSTORE_STATIC_ASSERT (offsetof (
compilation, triple_) == 8);
265 PSTORE_STATIC_ASSERT (offsetof (
compilation, size_) == 16);
266 PSTORE_STATIC_ASSERT (offsetof (
compilation, padding1_) == 20);
267 PSTORE_STATIC_ASSERT (offsetof (
compilation, members_) == 32);
271 PSTORE_ASSERT (unsigned_cast (std::distance (first_member, last_member)) == size);
273 std::copy (first_member, last_member, this->
begin ());
278 template <
typename TransactionType,
typename Iterator>
283 auto const dist = std::distance (first_member, last_member);
284 PSTORE_ASSERT (dist >= 0);
286 if (dist > std::numeric_limits<size_type>::max ()) {
287 raise (error_code::too_many_members_in_compilation);
290 auto const num_members =
static_cast<size_type
> (dist);
291 auto const size = size_bytes (num_members);
294 auto const addr = transaction.allocate (size,
alignof (
compilation));
295 auto ptr = std::static_pointer_cast<
compilation> (transaction.getrw (addr, size));
298 new (ptr.get ())
compilation{triple, num_members, first_member, last_member};
305 #endif // PSTORE_MCREPO_COMPILATION_HPP Definition: uint128.hpp:85
A portable bit-field type.
size_type size() const noexcept
Returns the number of elements.
Definition: compilation.hpp:189
An extent is a contiguous area of storage reserved for a data BLOB, represented as a range...
Definition: address.hpp:441
std::size_t size_bytes() const noexcept
Definition: compilation.hpp:204
extent< fragment > fext
The extent of the fragment referenced by this compilation symbol.
Definition: compilation.hpp:76
static extent< compilation > alloc(TransactionType &transaction, typed_address< indirect_string > triple, Iterator first_member, Iterator last_member)
Allocates a new compilation in-store and copy the ticket file path and the contents of a vector of de...
typed_address< indirect_string > triple() const noexcept
Returns the target triple.
Definition: compilation.hpp:210
unsigned_cast() (and its runtime-checked version) allow for simple integral unsigned casts...
transaction< transaction_lock > begin(database &db, transaction_lock &lock)
Creates a new transaction. Every operation performed on a transaction instance can be potentially und...
Definition: transaction.hpp:311
static std::size_t size_bytes(size_type size) noexcept
Returns the number of bytes of storage required for a compilation with 'size' members.
Definition: compilation.hpp:197
The data store transaction class.
Definition: transaction.hpp:191
Definition: address.hpp:231
static auto load(database const &db, typed_address< definition > addr) -> std::shared_ptr< definition const >
Returns a pointer to an in-store definition instance.
Definition: compilation.hpp:116
A compilation is a holder for zero or more definitions.
Definition: compilation.hpp:128
Definition: nonpod2.cpp:40
Definition: database.hpp:40
bool empty() const noexcept
Checks whether the container is empty.
Definition: compilation.hpp:187
static constexpr typed_address< definition > index_address(typed_address< compilation > const c, size_type const index) noexcept
Compute the address of the definition given by index within compilation c.
Definition: compilation.hpp:218
Represents an individual symbol in a compilation.
Definition: compilation.hpp:65
index::digest digest
The digest of the fragment referenced by this compilation symbol.
Definition: compilation.hpp:74