CACAO
NumericInstruction.hpp
Go to the documentation of this file.
1 /* src/vm/jit/loop/NumericInstruction.hpp
2 
3  Copyright (C) 1996-2012
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 
25 #ifndef _NUMERIC_INSTRUCTION_HPP
26 #define _NUMERIC_INSTRUCTION_HPP
27 
28 #include <limits>
29 #include <iostream>
30 #include <cassert>
31 
32 #include "vm/types.hpp"
33 
34 
35 /**
36  * Represents a constant numeric instruction.
37  */
39 {
40 public:
41 
42  enum Kind // sorted
43  {
44  ZERO = 0,
47  };
48 
49 private:
50 
53 
54  static s4 lowerBounds[3];
55  static s4 upperBounds[3];
56 
58  : _kind(kind)
59  , _var(variable)
60  {}
61 
62 public:
63 
65  : _kind(other._kind)
66  , _var(other._var)
67  {}
68 
69  static NumericInstruction newZero();
72 
73  Kind kind() const { return _kind; }
74  s4 variable() const { return _var; }
75 
76  /**
77  * The smallest value this instruction can return.
78  */
79  s4 lower() const;
80 
81  /**
82  * The largest value this instruction can return.
83  */
84  s4 upper() const;
85 };
86 
87 
89 {
90  return NumericInstruction(ZERO, 0);
91 }
92 
94 {
95  return NumericInstruction(ARRAY_LENGTH, variable);
96 }
97 
99 {
100  return NumericInstruction(VARIABLE, variable);
101 }
102 
103 inline bool operator==(const NumericInstruction& a, const NumericInstruction& b)
104 {
105  return a.kind() == b.kind() && a.variable() == b.variable();
106 }
107 
108 inline bool operator!=(const NumericInstruction& a, const NumericInstruction& b)
109 {
110  return a.kind() != b.kind() || a.variable() != b.variable();
111 }
112 
114 {
115  return lowerBounds[_kind];
116 }
117 
119 {
120  return upperBounds[_kind];
121 }
122 
123 inline std::ostream& operator<<(std::ostream& out, const NumericInstruction& instruction)
124 {
125  switch (instruction.kind())
126  {
127  case NumericInstruction::ZERO: return out << '0';
128  case NumericInstruction::ARRAY_LENGTH: return out << '(' << instruction.variable() << ").length";
129  case NumericInstruction::VARIABLE: return out << '(' << instruction.variable() << ')';
130  default: assert(false);
131  }
132  return out;
133 }
134 
135 #endif
136 
137 /*
138  * These are local overrides for various environment variables in Emacs.
139  * Please do not remove this and leave it at the end of the file, where
140  * Emacs will automagically detect them.
141  * ---------------------------------------------------------------------
142  * Local variables:
143  * mode: c++
144  * indent-tabs-mode: t
145  * c-basic-offset: 4
146  * tab-width: 4
147  * End:
148  * vim:noexpandtab:sw=4:ts=4:
149  */
150 
Represents a constant numeric instruction.
NumericInstruction(const NumericInstruction &other)
bool operator!=(const ordered_list< T, Allocator > &lhs, const ordered_list< T, Allocator > &rhs)
inequality
s4 lower() const
The smallest value this instruction can return.
NumericInstruction(Kind kind, s4 variable)
static NumericInstruction newArrayLength(s4 variable)
int32_t s4
Definition: types.hpp:45
OStream & operator<<(OStream &OS, const std::string &t)
Definition: OStream.hpp:459
static NumericInstruction newVariable(s4 variable)
bool operator==(const ordered_list< T, Allocator > &lhs, const ordered_list< T, Allocator > &rhs)
equality
s4 upper() const
The largest value this instruction can return.
OStream & out()
Definition: OStream.cpp:39
static NumericInstruction newZero()