CACAO
MachineOperand.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/MachineOperand.cpp - MachineOperand
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 
28 #include "toolbox/logging.hpp"
29 
30 namespace cacao {
31 namespace jit {
32 namespace compiler2 {
33 
34 std::size_t MachineOperand::id_counter = 0;
35 
37 
39 #if 0
40 OStream& operator<<(OStream &OS, const MachineOperandType &MO) {
41  OS << "MachineOperandType [ ";
42  if (MO.takes(MachineOperandType::REGISTER_VALUE))
43  OS << "RV ";
44  if (MO.takes(MachineOperandType::REGISTER_MEM))
45  OS << "RM ";
46  if (MO.takes(MachineOperandType::IMMEDIATE))
47  OS << "IM ";
48  if (MO.takes(MachineOperandType::ABSOLUTE_ADDR))
49  OS << "AA ";
50  if (MO.takes(MachineOperandType::PIC_ADDR))
51  OS << "PA ";
52  if (MO.takes(MachineOperandType::PC_REL_ADDR))
53  OS << "RA ";
54  return OS << ']';
55 }
56 #endif
57 
59  return parent->get_StackSlot(this);
60 }
61 
63  : MachineOperand(ImmediateID,I->get_type()) {
64  switch (get_type()) {
65  case Type::IntTypeID:
66  value.i = I->get_Int();
67  break;
68  case Type::LongTypeID:
69  value.l = I->get_Long();
70  break;
71  case Type::FloatTypeID:
72  value.f = I->get_Float();
73  break;
74  case Type::DoubleTypeID:
75  value.d = I->get_Double();
76  break;
77  default:
78  assert(0);
79  break;
80  }
81 }
82 template<>
84  switch (get_type()) {
85  case Type::ShortTypeID: return (s8)value.i;
86  case Type::IntTypeID: return (s8)value.i;
87  case Type::LongTypeID: return (s8)value.l;
88  default: break;
89  }
90  ABORT_MSG("TypeNotSupported: Immediate::get_value<s8>",
91  "type " << get_type());
92  return 0;
93 }
94 
95 template<>
97  switch (get_type()) {
98  case Type::ShortTypeID: return (s4)value.i;
99  case Type::IntTypeID: return (s4)value.i;
100  case Type::LongTypeID:
101  if (fits_into<s4>(value.l)) {
102  return (s4)value.l;
103  }
104  break;
105  default: break;
106  }
107  ABORT_MSG("TypeNotSupported: Immediate::get_value<s8>",
108  "type " << get_type());
109  return 0;
110 }
111 
112 template<>
114  switch (get_type()) {
115  case Type::ShortTypeID: return (s2)value.i;
116  case Type::IntTypeID:
117  if (fits_into<s2>(value.i)) {
118  return (s2)value.i;
119  }
120  break;
121  case Type::LongTypeID:
122  if (fits_into<s2>(value.l)) {
123  return (s2)value.l;
124  }
125  break;
126  default: break;
127  }
128  ABORT_MSG("TypeNotSupported: Immediate::get_value<s8>",
129  "type " << get_type());
130  return 0;
131 }
132 
133 template<>
135  switch (get_type()) {
136  case Type::IntTypeID:
137  if (fits_into<s1>(value.i)) {
138  return (s1)value.i;
139  }
140  break;
141  case Type::LongTypeID:
142  if (fits_into<s1>(value.l)) {
143  return (s1)value.l;
144  }
145  break;
146  default: break;
147  }
148  ABORT_MSG("TypeNotSupported: Immediate::get_value<s8>",
149  "type " << get_type());
150  return 0;
151 }
152 
153 
154 } // end namespace compiler2
155 } // end namespace jit
156 } // end namespace cacao
157 
158 /*
159  * These are local overrides for various environment variables in Emacs.
160  * Please do not remove this and leave it at the end of the file, where
161  * Emacs will automagically detect them.
162  * ---------------------------------------------------------------------
163  * Local variables:
164  * mode: c++
165  * indent-tabs-mode: t
166  * c-basic-offset: 4
167  * tab-width: 4
168  * End:
169  * vim:noexpandtab:sw=4:ts=4:
170  */
virtual StackSlot * to_StackSlot()
FIXME this should be managed.
int64_t s8
Definition: types.hpp:48
Simple stream class for formatted output.
Definition: OStream.hpp:141
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
int32_t s4
Definition: types.hpp:45
OStream & OS
StackSlot * get_StackSlot(ManagedStackSlot *MSS)
get a stack slot from a managed stack slot
#define I(value)
Definition: codegen.c:279
Operands that can be directly used by the machine (register, memory, stackslot)
int8_t s1
Definition: types.hpp:39
int16_t s2
Definition: types.hpp:42
#define ABORT_MSG(EXPR_SHORT, EXPR_LONG)
Definition: logging.hpp:133