Add a HHIR-level peephole optimization to reorder CheckTypes
[hiphop-php.git] / hphp / util / eh-frame-inl.h
blob0106de6b08a6889f6e14c88e1e8af6d20029f73d
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 namespace HPHP {
19 ///////////////////////////////////////////////////////////////////////////////
21 inline const uint8_t* EHFrameDesc::Entry::get() const {
22 return &m_vec[m_idx];
25 inline uint32_t EHFrameDesc::Entry::length() const {
26 return *(uint32_t*)(&m_vec[m_idx]);
29 inline uint32_t EHFrameDesc::Entry::cie_off() const {
30 return *(uint32_t*)(&m_vec[m_idx + sizeof(uint32_t)]);
33 inline CodeAddress EHFrameDesc::FDE::start() const {
34 auto constexpr off = sizeof(uint32_t) + sizeof(uint32_t);
35 return *(CodeAddress*)(&m_vec[m_idx + off]);
38 inline size_t EHFrameDesc::FDE::range() const {
39 auto constexpr off = sizeof(uint32_t) + sizeof(uint32_t) +
40 sizeof(CodeAddress);
41 return *(size_t*)(&m_vec[m_idx + off]);
44 ///////////////////////////////////////////////////////////////////////////////
46 inline EHFrameDesc::CIE EHFrameDesc::cie() const {
47 assertx(m_buf != nullptr);
48 return CIE(*m_buf, 0);
51 template <class F>
52 inline void EHFrameDesc::for_each_fde(F f) const {
53 assertx(m_buf != nullptr);
55 auto const cie_len = cie().length();
56 auto idx = sizeof(cie_len) + cie_len;
58 while (idx < m_buf->size()) {
59 auto fde = FDE(*m_buf, idx);
60 auto const fde_len = fde.length();
62 if (fde_len != 0) f(fde); // skip the null-terminating FDE
64 idx += sizeof(fde_len) + fde_len;
65 assertx(fde_len != 0 || idx == m_buf->size());
69 ///////////////////////////////////////////////////////////////////////////////