Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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_COMPILER_SEA_IR_TYPES_TYPES_H_ |
| 18 | #define ART_COMPILER_SEA_IR_TYPES_TYPES_H_ |
| 19 | |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 20 | #include "safe_map.h" |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 21 | #include "verifier/reg_type.h" |
| 22 | #include "verifier/reg_type_cache.h" |
| 23 | |
| 24 | namespace sea_ir { |
| 25 | |
| 26 | // TODO: Replace typedef with an actual class implementation when we have more types. |
| 27 | typedef art::verifier::RegType Type; |
| 28 | |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 29 | // Stores information about the result type of each instruction. |
| 30 | // Note: Main purpose is to encapsulate the map<instruction id, type*>, |
| 31 | // so that we can replace the underlying storage at any time. |
| 32 | class TypeData { |
| 33 | public: |
| 34 | art::SafeMap<int, const Type*>* GetTypeMap() { |
| 35 | return &type_map_; |
| 36 | } |
| 37 | // Returns the type associated with instruction with @instruction_id. |
| 38 | const Type* FindTypeOf(int instruction_id) { |
| 39 | art::SafeMap<int, const Type*>::const_iterator result_it = type_map_.find(instruction_id); |
| 40 | if (type_map_.end() != result_it) { |
| 41 | return result_it->second; |
| 42 | } |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | // Saves the fact that instruction @instruction_id produces a value of type @type. |
| 47 | void SetTypeOf(int instruction_id, const Type* type) { |
| 48 | type_map_.Overwrite(instruction_id, type); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | art::SafeMap<int, const Type*> type_map_; |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 57 | } // namespace sea_ir |
| 58 | #endif // ART_COMPILER_SEA_IR_TYPES_TYPES_H_ |