2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ART_RUNTIME_DEX_INSTRUCTION_VISITOR_H_
18 #define ART_RUNTIME_DEX_INSTRUCTION_VISITOR_H_
20 #include "base/macros.h"
21 #include "dex_instruction.h"
26 class DexInstructionVisitor {
28 void Visit(const uint16_t* code, size_t size_in_bytes) {
29 T* derived = static_cast<T*>(this);
30 size_t size_in_code_units = size_in_bytes / sizeof(uint16_t);
32 while (i < size_in_code_units) {
33 const Instruction* inst = Instruction::At(&code[i]);
34 switch (inst->Opcode()) {
35 #define INSTRUCTION_CASE(o, cname, p, f, r, i, a, v) \
36 case Instruction::cname: { \
37 derived->Do_ ## cname(inst); \
40 #include "dex_instruction_list.h"
41 DEX_INSTRUCTION_LIST(INSTRUCTION_CASE)
42 #undef DEX_INSTRUCTION_LIST
43 #undef INSTRUCTION_CASE
47 i += inst->SizeInCodeUnits();
52 // Specific handlers for each instruction.
53 #define INSTRUCTION_VISITOR(o, cname, p, f, r, i, a, v) \
54 void Do_ ## cname(const Instruction* inst) { \
55 T* derived = static_cast<T*>(this); \
56 derived->Do_Default(inst); \
58 #include "dex_instruction_list.h"
59 DEX_INSTRUCTION_LIST(INSTRUCTION_VISITOR)
60 #undef DEX_INSTRUCTION_LIST
61 #undef INSTRUCTION_VISITOR
63 // The default instruction handler.
64 void Do_Default(const Instruction*) {
72 #endif // ART_RUNTIME_DEX_INSTRUCTION_VISITOR_H_