OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COURGETTE_ASSEMBLY_PROGRAM_H_ | 5 #ifndef COURGETTE_ASSEMBLY_PROGRAM_H_ |
6 #define COURGETTE_ASSEMBLY_PROGRAM_H_ | 6 #define COURGETTE_ASSEMBLY_PROGRAM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 | 14 |
15 #include "courgette/disassembler.h" | 15 #include "courgette/disassembler.h" |
| 16 #include "courgette/image_utils.h" |
16 #include "courgette/memory_allocator.h" | 17 #include "courgette/memory_allocator.h" |
17 | 18 |
18 namespace courgette { | 19 namespace courgette { |
19 | 20 |
20 class EncodedProgram; | 21 class EncodedProgram; |
21 | 22 |
22 // A Label is a symbolic reference to an address. Unlike a conventional | |
23 // assembly language, we always know the address. The address will later be | |
24 // stored in a table and the Label will be replaced with the index into the | |
25 // table. | |
26 // | |
27 // TODO(sra): Make fields private and add setters and getters. | |
28 class Label { | |
29 public: | |
30 static const int kNoIndex = -1; | |
31 Label() : rva_(0), index_(kNoIndex), count_(0) {} | |
32 explicit Label(RVA rva) : rva_(rva), index_(kNoIndex), count_(0) {} | |
33 | |
34 RVA rva_; // Address referred to by the label. | |
35 int index_; // Index of address in address table, kNoIndex until assigned. | |
36 int count_; | |
37 }; | |
38 | |
39 typedef std::map<RVA, Label*> RVAToLabel; | 23 typedef std::map<RVA, Label*> RVAToLabel; |
40 | 24 |
41 // Opcodes of simple assembly language | 25 // Opcodes of simple assembly language |
42 enum OP { | 26 enum OP { |
43 ORIGIN, // ORIGIN <rva> - set current address for assembly. | 27 ORIGIN, // ORIGIN <rva> - set current address for assembly. |
44 MAKEPERELOCS, // Generates a base relocation table. | 28 MAKEPERELOCS, // Generates a base relocation table. |
45 MAKEELFRELOCS, // Generates a base relocation table. | 29 MAKEELFRELOCS, // Generates a base relocation table. |
46 DEFBYTE, // DEFBYTE <value> - emit a byte literal. | 30 DEFBYTE, // DEFBYTE <value> - emit a byte literal. |
47 REL32, // REL32 <label> - emit a rel32 encoded reference to 'label'. | 31 REL32, // REL32 <label> - emit a rel32 encoded reference to 'label'. |
48 ABS32, // ABS32 <label> - emit an abs32 encoded reference to 'label'. | 32 ABS32, // ABS32 <label> - emit an abs32 encoded reference to 'label'. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // We have separate label spaces for addresses referenced by rel32 labels and | 182 // We have separate label spaces for addresses referenced by rel32 labels and |
199 // abs32 labels. This is somewhat arbitrary. | 183 // abs32 labels. This is somewhat arbitrary. |
200 RVAToLabel rel32_labels_; | 184 RVAToLabel rel32_labels_; |
201 RVAToLabel abs32_labels_; | 185 RVAToLabel abs32_labels_; |
202 | 186 |
203 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram); | 187 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram); |
204 }; | 188 }; |
205 | 189 |
206 } // namespace courgette | 190 } // namespace courgette |
207 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_ | 191 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_ |
OLD | NEW |