make #includes consistent
[hiphop-php.git] / hphp / runtime / vm / translator / immstack.cpp
blobcae3e94cdd79b890f00c9cd6d274272713ce363b
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- 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/translator/immstack.h"
19 namespace HPHP {
20 ///////////////////////////////////////////////////////////////////////////////
22 void ImmStack::processOpcode(const Opcode* opcode) {
23 StackTransInfo sti = instrStackTransInfo(opcode);
24 if (sti.kind == StackTransInfo::PushPop) {
25 for (int i = 0; i < sti.numPops; i++) {
26 pop();
28 for (int i = 0; i < sti.numPushes; i++) {
29 pushUnknown();
31 } else if (sti.kind == StackTransInfo::InsertMid) {
32 insUnknown(sti.pos);
33 } else {
34 assert(false);
38 void ImmStack::pushUnknown() {
39 StackItem item;
41 item.type = StackItem::StackType_Unknown;
42 m_stack.push_back(item);
45 void ImmStack::insUnknown(int pos) {
46 int k = m_stack.size() - 1 - pos;
47 if (k >= 0 && k < (int)m_stack.size()) {
48 StackItem item;
49 item.type = StackItem::StackType_Unknown;
50 m_stack.insert(m_stack.begin() + k, item);
54 void ImmStack::pop() {
55 // Since we only process on the basic block level, we obviously can pop
56 // locations that we don't track. We treat all these locations as unknowns.
58 if (!m_stack.empty()) {
59 m_stack.pop_back();
63 void ImmStack::pushInt(int64_t value) {
64 StackItem item;
66 item.type = StackItem::StackType_Int;
67 item.i64a = value;
69 m_stack.push_back(item);
72 void ImmStack::pushLitstr(Id value) {
73 StackItem item;
75 item.type = StackItem::StackType_Litstr;
76 item.sa = value;
78 m_stack.push_back(item);
81 ImmStack::StackItem &ImmStack::get(int above) {
82 always_assert(above >= 0 && (size_t)above < m_stack.size());
84 return m_stack[m_stack.size() - above - 1];
87 bool ImmStack::isInt(int above) {
88 if (above >= (int)m_stack.size()) {
89 return false;
92 return get(above).type == StackItem::StackType_Int;
95 bool ImmStack::isLitstr(int above) {
96 if (above >= (int)m_stack.size()) {
97 return false;
100 return get(above).type == StackItem::StackType_Litstr;