2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_SRCKEY_H_
17 #define incl_HPHP_SRCKEY_H_
20 #include <boost/operators.hpp>
22 #include "hphp/runtime/vm/func.h"
23 #include "hphp/runtime/vm/core_types.h"
27 //////////////////////////////////////////////////////////////////////
30 * A SrcKey is a logical source instruction---it's enough to identify
31 * these using a (Func id, hhbc instruction) pair.
33 struct SrcKey
: private boost::totally_ordered
<SrcKey
> {
34 typedef uint64_t AtomicInt
;
38 : m_funcId(InvalidFuncId
)
42 SrcKey(const Func
* f
, Offset off
)
43 : m_funcId(f
->getFuncId())
47 SrcKey(const Func
* f
, const Opcode
* i
)
48 : m_funcId(f
->getFuncId())
49 , m_offset(f
->unit()->offsetOf(i
))
52 SrcKey(FuncId funcId
, Offset off
)
57 // Packed representation of SrcKeys for use in contexts where we
58 // want atomicity. (SrcDB.)
59 AtomicInt
toAtomicInt() const {
60 return uint64_t(getFuncId()) << 32 | uint64_t(offset());
62 static SrcKey
fromAtomicInt(AtomicInt in
) {
63 return SrcKey
{ uint32_t(in
>> 32), (Offset
) int32_t(in
& 0xffffffff) };
66 void setFuncId(FuncId id
) {
67 assert(id
!= InvalidFuncId
);
71 FuncId
getFuncId() const {
72 assert(m_funcId
!= InvalidFuncId
);
81 * Advance the SrcKey to the next instruction.
83 * If the SrcKey points to the last instruction in a function, this
84 * will advance past the end of the function, and potentially
85 * contain an invalid bytecode offset.
87 void advance(const Unit
* u
) {
88 m_offset
+= instrLen(u
->at(offset()));
92 * Return a SrcKey representing the next instruction, without
93 * mutating this SrcKey.
95 SrcKey
advanced(const Unit
* u
) const {
101 bool operator==(const SrcKey
& r
) const {
102 return offset() == r
.offset() &&
103 getFuncId() == r
.getFuncId();
106 bool operator<(const SrcKey
& r
) const {
107 return std::make_tuple(offset(), getFuncId()) <
108 std::make_tuple(r
.offset(), r
.getFuncId());
116 struct SrcKey::Hasher
{
117 size_t operator()(SrcKey sk
) const {
118 return hash_int64_pair(sk
.getFuncId(), uint64_t(sk
.offset()));
122 //////////////////////////////////////////////////////////////////////