CACAO
Instruction.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Instruction.cpp - Instruction
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
27 
28 #include "toolbox/logging.hpp"
29 
30 #define DEBUG_NAME "compiler2/Instruction"
31 
32 namespace cacao {
33 namespace jit {
34 namespace compiler2 {
35 
37 
39  if (!I)
40  return OS << "Instruction is NULL";
41  return OS << *I;
42 }
44  return OS << "[" << get_id() << ": " << get_name() << " ("
45  << get_type() << ")]";
46 }
47 
49  LOG("deleting instruction: " << this << nl);
50  #if 1
51  // remove from users
52  for( OperandListTy::iterator i = op_list.begin(), e = op_list.end(); i != e ; ++i) {
53  Value *v = *i;
54  //assert(v != (Value*)this);
55  // might be a NULL operand
56  //if (v) {
57  v->user_remove(this);
58  //}
59  }
60  for( DepListTy::iterator i = dep_list.begin(), e = dep_list.end(); i != e ; ++i) {
61  Instruction *I = *i;
62  I->reverse_dep_list.remove(this);
63  }
64  #endif
65 }
66 void Instruction::replace_op(Value* v_old, Value* v_new) {
67  LOG("Instruction:::replace_op(this=" << this << ",v_old=" << v_old << ",v_new=" << v_new << ")" << nl );
69  std::replace(op_list.begin(),op_list.end(),v_old,v_new);
71  v_old->user_remove(this);
72  if (v_new)
73  v_new->append_user(this);
74 }
76  OS << "Operands of " << this << " (" << get_name() << ")" << nl ;
77  for(OperandListTy::iterator i = op_list.begin(), e = op_list.end(); i != e; ++i) {
78  OS << "OP: " << *i << nl;
79  }
80  return OS;
81 }
82 bool Instruction::verify() const {
83  if (is_homogeneous()) {
84  for(OperandListTy::const_iterator i = op_list.begin(), e = op_list.end(); i != e; ++i) {
85  Value *V = *i;
86  if (V->get_type() != get_type()) {
87  ERROR_MSG("Instruction verification error","This type " << *this
88  << " is not equal to operand (" << V << ") type " << V->get_type() << nl );
89  return false;
90  }
91  }
92  }
93  return true;
94 }
95 
96 
97 } // end namespace compiler2
98 } // end namespace jit
99 } // end namespace cacao
100 
101 
102 /*
103  * These are local overrides for various environment variables in Emacs.
104  * Please do not remove this and leave it at the end of the file, where
105  * Emacs will automagically detect them.
106  * ---------------------------------------------------------------------
107  * Local variables:
108  * mode: c++
109  * indent-tabs-mode: t
110  * c-basic-offset: 4
111  * tab-width: 4
112  * End:
113  * vim:noexpandtab:sw=4:ts=4:
114  */
virtual OStream & print(OStream &OS) const
print
Definition: Instruction.cpp:43
void append_user(Instruction *I)
Definition: Value.hpp:54
Type::TypeID get_type() const
get the value type of the instruction
Definition: Value.hpp:68
#define DEBUG(STMT)
Execute debug statements in your current module.
Definition: Debug.hpp:125
const char * get_name() const
#define ERROR_MSG(EXPR_SHORT, EXPR_LONG)
Definition: logging.hpp:124
OStream & print_operands(OStream &OS)
Definition: Instruction.cpp:75
virtual bool verify() const
check if the instruction is in a correct state
Definition: Instruction.cpp:82
int get_id() const
return a unique identifier for this instruction
Simple stream class for formatted output.
Definition: OStream.hpp:141
Instruction super class.
Definition: Instruction.hpp:73
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
void replace_op(Value *v_old, Value *v_new)
Definition: Instruction.cpp:66
virtual bool is_homogeneous() const
True if the instruction has a homogeneous signature.
MIIterator i
void user_remove(Instruction *I)
Definition: Value.hpp:60
OStream & OS
MIIterator e
#define LOG(STMT)
Analogous to DEBUG.
Definition: logging.hpp:91
#define I(value)
Definition: codegen.c:279
Nl nl
Definition: OStream.cpp:56
OStream & dbg()
The default destination for logging messages.