Change the year on all our generated files
[hiphop-php.git] / hphp / vixl / a64 / decoder-a64.h
blobde51022e6e6160bc65eef65bcfc87cc923905cbb
1 // Copyright 2013, ARM Limited
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
12 // * Neither the name of ARM Limited nor the names of its contributors may be
13 // used to endorse or promote products derived from this software without
14 // specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef VIXL_A64_DECODER_A64_H_
28 #define VIXL_A64_DECODER_A64_H_
30 #include <list>
32 #include "hphp/vixl/globals.h"
33 #include "hphp/vixl/a64/instructions-a64.h"
36 // List macro containing all visitors needed by the decoder class.
38 #define VISITOR_LIST(V) \
39 V(PCRelAddressing) \
40 V(AddSubImmediate) \
41 V(LogicalImmediate) \
42 V(MoveWideImmediate) \
43 V(Bitfield) \
44 V(Extract) \
45 V(UnconditionalBranch) \
46 V(UnconditionalBranchToRegister) \
47 V(CompareBranch) \
48 V(TestBranch) \
49 V(ConditionalBranch) \
50 V(System) \
51 V(Exception) \
52 V(LoadStorePairPostIndex) \
53 V(LoadStorePairOffset) \
54 V(LoadStorePairPreIndex) \
55 V(LoadStorePairNonTemporal) \
56 V(LoadLiteral) \
57 V(LoadStoreUnscaledOffset) \
58 V(LoadStorePostIndex) \
59 V(LoadStorePreIndex) \
60 V(LoadStoreRegisterOffset) \
61 V(LoadStoreUnsignedOffset) \
62 V(LoadStoreExclusive) \
63 V(LogicalShifted) \
64 V(LseLdOp) \
65 V(AddSubShifted) \
66 V(AddSubExtended) \
67 V(AddSubWithCarry) \
68 V(ConditionalCompareRegister) \
69 V(ConditionalCompareImmediate) \
70 V(ConditionalSelect) \
71 V(DataProcessing1Source) \
72 V(DataProcessing2Source) \
73 V(DataProcessing3Source) \
74 V(FPCompare) \
75 V(FPConditionalCompare) \
76 V(FPConditionalSelect) \
77 V(FPImmediate) \
78 V(FPDataProcessing1Source) \
79 V(FPDataProcessing2Source) \
80 V(FPDataProcessing3Source) \
81 V(FPIntegerConvert) \
82 V(FPFixedPointConvert) \
83 V(Unallocated) \
84 V(Unimplemented)
86 namespace vixl {
88 // The Visitor interface. Disassembler and simulator (and other tools)
89 // must provide implementations for all of these functions.
90 class DecoderVisitor {
91 public:
92 #define DECLARE(A) virtual void Visit##A(Instruction* instr) = 0;
93 VISITOR_LIST(DECLARE)
94 #undef DECLARE
96 virtual ~DecoderVisitor() {}
98 private:
99 // Visitors are registered in a list.
100 std::list<DecoderVisitor*> visitors_;
102 friend class Decoder;
106 class Decoder: public DecoderVisitor {
107 public:
108 Decoder() {}
110 // Top-level instruction decoder function. Decodes an instruction and calls
111 // the visitor functions registered with the Decoder class.
112 void Decode(Instruction *instr);
114 // Register a new visitor class with the decoder.
115 // Decode() will call the corresponding visitor method from all registered
116 // visitor classes when decoding reaches the leaf node of the instruction
117 // decode tree.
118 // Visitors are called in the order.
119 // A visitor can only be registered once.
120 // Registering an already registered visitor will update its position.
122 // d.AppendVisitor(V1);
123 // d.AppendVisitor(V2);
124 // d.PrependVisitor(V2); // Move V2 at the start of the list.
125 // d.InsertVisitorBefore(V3, V2);
126 // d.AppendVisitor(V4);
127 // d.AppendVisitor(V4); // No effect.
129 // d.Decode(i);
131 // will call in order visitor methods in V3, V2, V1, V4.
132 void AppendVisitor(DecoderVisitor* visitor);
133 void PrependVisitor(DecoderVisitor* visitor);
134 void InsertVisitorBefore(DecoderVisitor* new_visitor,
135 DecoderVisitor* registered_visitor);
136 void InsertVisitorAfter(DecoderVisitor* new_visitor,
137 DecoderVisitor* registered_visitor);
139 // Remove a previously registered visitor class from the list of visitors
140 // stored by the decoder.
141 void RemoveVisitor(DecoderVisitor* visitor);
143 #define DECLARE(A) void Visit##A(Instruction* instr);
144 VISITOR_LIST(DECLARE)
145 #undef DECLARE
147 private:
148 // Decode the PC relative addressing instruction, and call the corresponding
149 // visitors.
150 // On entry, instruction bits 27:24 = 0x0.
151 void DecodePCRelAddressing(Instruction* instr);
153 // Decode the add/subtract immediate instruction, and call the corresponding
154 // visitors.
155 // On entry, instruction bits 27:24 = 0x1.
156 void DecodeAddSubImmediate(Instruction* instr);
158 // Decode the branch, system command, and exception generation parts of
159 // the instruction tree, and call the corresponding visitors.
160 // On entry, instruction bits 27:24 = {0x4, 0x5, 0x6, 0x7}.
161 void DecodeBranchSystemException(Instruction* instr);
163 // Decode the load and store parts of the instruction tree, and call
164 // the corresponding visitors.
165 // On entry, instruction bits 27:24 = {0x8, 0x9, 0xC, 0xD}.
166 void DecodeLoadStore(Instruction* instr);
168 // Decode the logical immediate and move wide immediate parts of the
169 // instruction tree, and call the corresponding visitors.
170 // On entry, instruction bits 27:24 = 0x2.
171 void DecodeLogical(Instruction* instr);
173 // Decode the bitfield and extraction parts of the instruction tree,
174 // and call the corresponding visitors.
175 // On entry, instruction bits 27:24 = 0x3.
176 void DecodeBitfieldExtract(Instruction* instr);
178 // Decode the data processing parts of the instruction tree, and call the
179 // corresponding visitors.
180 // On entry, instruction bits 27:24 = {0x1, 0xA, 0xB}.
181 void DecodeDataProcessing(Instruction* instr);
183 // Decode the floating point parts of the instruction tree, and call the
184 // corresponding visitors.
185 // On entry, instruction bits 27:24 = {0xE, 0xF}.
186 void DecodeFP(Instruction* instr);
188 // Decode the Advanced SIMD (NEON) load/store part of the instruction tree,
189 // and call the corresponding visitors.
190 // On entry, instruction bits 29:25 = 0x6.
191 void DecodeAdvSIMDLoadStore(Instruction* instr);
193 // Decode the Advanced SIMD (NEON) data processing part of the instruction
194 // tree, and call the corresponding visitors.
195 // On entry, instruction bits 27:25 = 0x7.
196 void DecodeAdvSIMDDataProcessing(Instruction* instr);
198 } // namespace vixl
200 #endif // VIXL_A64_DECODER_A64_H_