Shih-wei Liao | e94d9b2 | 2012-05-22 09:01:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_SRC_GREENLAND_LIR_OPERAND_H_ |
| 18 | #define ART_SRC_GREENLAND_LIR_OPERAND_H_ |
| 19 | |
| 20 | #include "logging.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class ConstantFP; |
| 24 | } |
| 25 | |
| 26 | namespace art { |
| 27 | namespace greenland { |
| 28 | |
| 29 | class LIR; |
| 30 | |
| 31 | class LIROperand { |
| 32 | public: |
| 33 | enum Type { |
| 34 | UnknownType, |
| 35 | RegisterType, |
| 36 | ImmediateType, |
| 37 | FPImmediateType, |
| 38 | LabelType, |
| 39 | }; |
| 40 | |
| 41 | private: |
| 42 | Type type_; |
| 43 | |
| 44 | union { |
| 45 | // RegisterType |
| 46 | unsigned reg_no_; |
| 47 | |
| 48 | // ImmediateType |
| 49 | int64_t imm_val_; |
| 50 | |
| 51 | // FPImmediateType |
| 52 | const llvm::ConstantFP *fp_imm_val_; |
| 53 | |
| 54 | // LabelType |
| 55 | const LIR* target_; |
| 56 | } contents_; |
| 57 | |
| 58 | friend class LIR; |
| 59 | LIROperand() : type_(UnknownType) { } |
| 60 | |
| 61 | void SetType(enum Type type) { |
| 62 | type_ = type; |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | public: |
| 67 | enum Type GetType() const { |
| 68 | return type_; |
| 69 | } |
| 70 | |
| 71 | bool IsReg() const { |
| 72 | return (type_ == RegisterType); |
| 73 | } |
| 74 | bool IsImm() const { |
| 75 | return (type_ == ImmediateType); |
| 76 | } |
| 77 | bool IsFPImm() const { |
| 78 | return (type_ == FPImmediateType); |
| 79 | } |
| 80 | bool IsLabel() const { |
| 81 | return (type_ == LabelType); |
| 82 | } |
| 83 | |
| 84 | //---------------------------------------------------------------------------- |
| 85 | // Accessors |
| 86 | //---------------------------------------------------------------------------- |
| 87 | unsigned GetReg() const { |
| 88 | CHECK(IsReg()) << "This is not a register operand!"; |
| 89 | return contents_.reg_no_; |
| 90 | } |
| 91 | |
| 92 | int64_t GetImm() const { |
| 93 | CHECK(IsImm()) << "This is not a immediate operand!"; |
| 94 | return contents_.imm_val_; |
| 95 | } |
| 96 | |
| 97 | const llvm::ConstantFP* GetFPImm() const { |
| 98 | CHECK(IsFPImm()) << "This is not a FP immediate operand!"; |
| 99 | return contents_.fp_imm_val_; |
| 100 | } |
| 101 | |
| 102 | const LIR* GetLabelTarget() const { |
| 103 | CHECK(IsFPImm()) << "This is not a label operand!"; |
| 104 | return contents_.target_; |
| 105 | } |
| 106 | |
| 107 | //---------------------------------------------------------------------------- |
| 108 | // Mutators |
| 109 | //---------------------------------------------------------------------------- |
| 110 | void SetReg(unsigned reg_no) { |
| 111 | if (type_ == UnknownType) { |
| 112 | type_ = RegisterType; |
| 113 | } |
| 114 | CHECK(IsReg()) << "This is not a register operand!"; |
| 115 | contents_.reg_no_ = reg_no; |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | void SetImm(int64_t imm_val) { |
| 120 | if (type_ == UnknownType) { |
| 121 | type_ = ImmediateType; |
| 122 | } |
| 123 | CHECK(IsImm()) << "This is not a immediate operand!"; |
| 124 | contents_.imm_val_ = imm_val; |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | void SetFPImm(const llvm::ConstantFP* fp_imm_val) { |
| 129 | if (type_ == UnknownType) { |
| 130 | type_ = FPImmediateType; |
| 131 | } |
| 132 | CHECK(IsFPImm()) << "This is not a FP immediate operand!"; |
| 133 | contents_.fp_imm_val_ = fp_imm_val; |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | void SetLabelTarget(LIR* target) { |
| 138 | if (type_ == UnknownType) { |
| 139 | type_ = LabelType; |
| 140 | } |
| 141 | CHECK(IsLabel()) << "This is not a label operand!"; |
| 142 | contents_.target_ = target; |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | }; |
| 147 | |
| 148 | } // namespace greenland |
| 149 | } // namespace art |
| 150 | |
| 151 | #endif // ART_SRC_GREENLAND_LIR_OPERAND_H_ |