Arquivos
hhvm/hphp/runtime/vm/srckey.h
T
Drew Paroski 9edc07112b Merge ObjectData and Instance together, part 1
When object support was first added to HHVM, a class named "Instance"
was introduced (deriving from ObjectData) to represent instances of user
defined classes. Since then, things have evolved and HPHPc and HPHPi have
been retired, and now there really is no needed to have ObjectData and
Instance be separate classes anymore.

As a first step towards merging ObjectData and Instance together, this diff
puts their definitions in the same .h file and puts their implementations
in the same .cpp file. A few small changes were necessary to fix issues
with cyclical includes: (1) Repo/emitter related parts of class.cpp and
class.h were moved to class-emit.cpp and class-emit.h; (2) the contents of
"vm/core_types.h" was moved to "base/types.h"; and (3) a few functions that
didn't appear to be hot were moved from .h files and the corresponding .cpp
files.
2013-07-06 11:12:29 -07:00

135 linhas
3.6 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_SRCKEY_H_
#define incl_HPHP_SRCKEY_H_
#include <tuple>
#include <boost/operators.hpp>
#include "hphp/runtime/vm/func.h"
#include "hphp/runtime/base/complex_types.h"
namespace HPHP {
//////////////////////////////////////////////////////////////////////
/*
* A SrcKey is a logical source instruction---it's enough to identify
* these using a (Func id, hhbc instruction) pair.
*/
struct SrcKey : private boost::totally_ordered<SrcKey> {
typedef uint64_t AtomicInt;
struct Hasher;
SrcKey()
: m_funcId(InvalidFuncId)
, m_offset(0)
{}
SrcKey(const Func* f, Offset off)
: m_funcId(f->getFuncId())
, m_offset(off)
{}
SrcKey(const Func* f, const Opcode* i)
: m_funcId(f->getFuncId())
, m_offset(f->unit()->offsetOf(i))
{}
SrcKey(FuncId funcId, Offset off)
: m_funcId{funcId}
, m_offset{off}
{}
// Packed representation of SrcKeys for use in contexts where we
// want atomicity. (SrcDB.)
AtomicInt toAtomicInt() const {
return uint64_t(getFuncId()) << 32 | uint64_t(offset());
}
static SrcKey fromAtomicInt(AtomicInt in) {
return SrcKey { uint32_t(in >> 32), (Offset) int32_t(in & 0xffffffff) };
}
void setFuncId(FuncId id) {
assert(id != InvalidFuncId);
m_funcId = id;
}
FuncId getFuncId() const {
assert(m_funcId != InvalidFuncId);
return m_funcId;
}
void setOffset(Offset o) {
m_offset = o;
}
int offset() const {
return m_offset;
}
/*
* Advance the SrcKey to the next instruction.
*
* If the SrcKey points to the last instruction in a function, this
* will advance past the end of the function, and potentially
* contain an invalid bytecode offset.
*/
void advance(const Unit* u) {
m_offset += instrLen((Op*)u->at(offset()));
}
/*
* Return a SrcKey representing the next instruction, without
* mutating this SrcKey.
*/
SrcKey advanced(const Unit* u) const {
auto tmp = *this;
tmp.advance(u);
return tmp;
}
bool operator==(const SrcKey& r) const {
return offset() == r.offset() &&
getFuncId() == r.getFuncId();
}
bool operator<(const SrcKey& r) const {
return std::make_tuple(offset(), getFuncId()) <
std::make_tuple(r.offset(), r.getFuncId());
}
private:
FuncId m_funcId;
Offset m_offset;
};
struct SrcKey::Hasher {
size_t operator()(SrcKey sk) const {
return hash_int64_pair(sk.getFuncId(), uint64_t(sk.offset()));
}
};
//////////////////////////////////////////////////////////////////////
inline std::string show(SrcKey sk) {
return folly::format("{}@{}", sk.getFuncId(), sk.offset()).str();
}
}
#endif