2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 #include "hphp/runtime/vm/jit/normalized-instruction.h"
19 #include "hphp/runtime/base/repo-auth-type-codec.h"
20 #include "hphp/runtime/vm/jit/translator.h"
22 namespace HPHP
{ namespace jit
{
23 ///////////////////////////////////////////////////////////////////////////////
26 * Populates `imm' on `inst'.
28 * Assumes that inst.source and inst.unit have been properly set.
30 static void populateImmediates(NormalizedInstruction
& inst
) {
32 for (int i
= 0; i
< numImmediates(inst
.op()); ++i
) {
33 if (immType(inst
.op(), i
) == RATA
) {
34 auto rataPc
= inst
.pc() + offset
;
35 inst
.imm
[i
].u_RATA
= decodeRAT(inst
.unit(), rataPc
);
37 inst
.imm
[i
] = getImm(reinterpret_cast<const Op
*>(inst
.pc()), i
);
39 offset
+= immSize(reinterpret_cast<const Op
*>(inst
.pc()), i
);
41 if (hasImmVector(*reinterpret_cast<const Op
*>(inst
.pc()))) {
42 inst
.immVec
= getImmVector(reinterpret_cast<const Op
*>(inst
.pc()));
44 if (inst
.op() == OpFCallArray
) {
45 inst
.imm
[0].u_IVA
= 1;
49 ///////////////////////////////////////////////////////////////////////////////
51 NormalizedInstruction::NormalizedInstruction(SrcKey sk
, const Unit
* u
)
59 , ignoreInnerType(false)
62 memset(imm
, 0, sizeof(imm
));
63 populateImmediates(*this);
66 NormalizedInstruction::NormalizedInstruction() { }
68 NormalizedInstruction::~NormalizedInstruction() { }
71 * Helpers for recovering context of this instruction.
73 Op
NormalizedInstruction::op() const {
74 return *reinterpret_cast<const Op
*>(pc());
77 Op
NormalizedInstruction::mInstrOp() const {
78 auto const opcode
= op();
79 #define MII(instr, a, b, i, v, d) case Op##instr##M: return opcode;
83 return preppedByRef
? Op::VGetM
: Op::CGetM
;
90 PC
NormalizedInstruction::pc() const {
91 return unit()->at(source
.offset());
94 const Unit
* NormalizedInstruction::unit() const {
98 const Func
* NormalizedInstruction::func() const {
102 Offset
NormalizedInstruction::offset() const {
103 return source
.offset();
106 std::string
NormalizedInstruction::toString() const {
107 return instrToString((Op
*)pc(), unit());
110 SrcKey
NormalizedInstruction::nextSk() const {
111 return source
.advanced(m_unit
);
114 ///////////////////////////////////////////////////////////////////////////////