blob: 7f0d24041b6f77ad861e58a74155a58680cbcbfd [file] [log] [blame]
Ian Rogers7b3ddd22013-02-21 15:19:52 -08001/*
2 * Copyright (C) 2011 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_VERIFIER_METHOD_INSTRUCTION_FLAGS_H_
18#define ART_SRC_VERIFIER_METHOD_INSTRUCTION_FLAGS_H_
19
20#include "base/logging.h"
21
22#include <stdint.h>
23#include <string>
24
25namespace art {
26namespace verifier {
27
28class InstructionFlags {
29 public:
30 InstructionFlags() : length_(0), flags_(0) {}
31
32 void SetLengthInCodeUnits(size_t length) {
33 DCHECK_LT(length, 65536u);
34 length_ = length;
35 }
36 size_t GetLengthInCodeUnits() {
37 return length_;
38 }
39 bool IsOpcode() const {
40 return length_ != 0;
41 }
42
43 void SetInTry() {
44 flags_ |= 1 << kInTry;
45 }
46 void ClearInTry() {
47 flags_ &= ~(1 << kInTry);
48 }
49 bool IsInTry() const {
50 return (flags_ & (1 << kInTry)) != 0;
51 }
52
53 void SetBranchTarget() {
54 flags_ |= 1 << kBranchTarget;
55 }
56 void ClearBranchTarget() {
57 flags_ &= ~(1 << kBranchTarget);
58 }
59 bool IsBranchTarget() const {
60 return (flags_ & (1 << kBranchTarget)) != 0;
61 }
62
63 void SetGcPoint() {
64 flags_ |= 1 << kGcPoint;
65 }
66 void ClearGcPoint() {
67 flags_ &= ~(1 << kGcPoint);
68 }
69 bool IsGcPoint() const {
70 return (flags_ & (1 << kGcPoint)) != 0;
71 }
72
73 void SetVisited() {
74 flags_ |= 1 << kVisited;
75 }
76 void ClearVisited() {
77 flags_ &= ~(1 << kVisited);
78 }
79 bool IsVisited() const {
80 return (flags_ & (1 << kVisited)) != 0;
81 }
82
83 void SetChanged() {
84 flags_ |= 1 << kChanged;
85 }
86 void ClearChanged() {
87 flags_ &= ~(1 << kChanged);
88 }
89 bool IsChanged() const {
90 return (flags_ & (1 << kChanged)) != 0;
91 }
92
93 bool IsVisitedOrChanged() const {
94 return IsVisited() || IsChanged();
95 }
96
97 std::string ToString() const;
98
99 private:
100 enum {
101 kInTry,
102 kBranchTarget,
103 kGcPoint,
104 kVisited,
105 kChanged,
106 };
107
108 // Size of instruction in code units.
109 uint16_t length_;
110 uint8_t flags_;
111};
112
113} // namespace verifier
114} // namespace art
115
116#endif // ART_SRC_VERIFIER_METHOD_INSTRUCTION_FLAGS_H_