Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: courgette/assembly_program.h

Issue 1543643002: Switch to standard integer types in courgette/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/adjustment_method_2.cc ('k') | courgette/assembly_program.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h>
9 #include <stdint.h>
10
8 #include <map> 11 #include <map>
9 #include <set> 12 #include <set>
10 #include <vector> 13 #include <vector>
11 14
12 #include "base/basictypes.h" 15 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
14
15 #include "courgette/disassembler.h" 17 #include "courgette/disassembler.h"
16 #include "courgette/image_utils.h" 18 #include "courgette/image_utils.h"
17 #include "courgette/memory_allocator.h" 19 #include "courgette/memory_allocator.h"
18 20
19 namespace courgette { 21 namespace courgette {
20 22
21 class EncodedProgram; 23 class EncodedProgram;
22 24
23 typedef std::map<RVA, Label*> RVAToLabel; 25 typedef std::map<RVA, Label*> RVAToLabel;
24 26
(...skipping 15 matching lines...) Expand all
40 // Base class for instructions. Because we have so many instructions we want to 42 // Base class for instructions. Because we have so many instructions we want to
41 // keep them as small as possible. For this reason we avoid virtual functions. 43 // keep them as small as possible. For this reason we avoid virtual functions.
42 class Instruction { 44 class Instruction {
43 public: 45 public:
44 OP op() const { return static_cast<OP>(op_); } 46 OP op() const { return static_cast<OP>(op_); }
45 47
46 protected: 48 protected:
47 explicit Instruction(OP op) : op_(op), info_(0) {} 49 explicit Instruction(OP op) : op_(op), info_(0) {}
48 Instruction(OP op, unsigned int info) : op_(op), info_(info) {} 50 Instruction(OP op, unsigned int info) : op_(op), info_(info) {}
49 51
50 uint32 op_ : 4; // A few bits to store the OP code. 52 uint32_t op_ : 4; // A few bits to store the OP code.
51 uint32 info_ : 28; // Remaining bits in first word available to subclass. 53 uint32_t info_ : 28; // Remaining bits in first word available to subclass.
52 54
53 private: 55 private:
54 DISALLOW_COPY_AND_ASSIGN(Instruction); 56 DISALLOW_COPY_AND_ASSIGN(Instruction);
55 }; 57 };
56 58
57 typedef NoThrowBuffer<Instruction*> InstructionVector; 59 typedef NoThrowBuffer<Instruction*> InstructionVector;
58 60
59 // An AssemblyProgram is the result of disassembling an executable file. 61 // An AssemblyProgram is the result of disassembling an executable file.
60 // 62 //
61 // * The disassembler creates labels in the AssemblyProgram and emits 63 // * The disassembler creates labels in the AssemblyProgram and emits
(...skipping 13 matching lines...) Expand all
75 // its own assignment, and then call AssignRemainingIndexes to ensure all 77 // its own assignment, and then call AssignRemainingIndexes to ensure all
76 // indexes are assigned. 78 // indexes are assigned.
77 // 79 //
78 class AssemblyProgram { 80 class AssemblyProgram {
79 public: 81 public:
80 explicit AssemblyProgram(ExecutableType kind); 82 explicit AssemblyProgram(ExecutableType kind);
81 ~AssemblyProgram(); 83 ~AssemblyProgram();
82 84
83 ExecutableType kind() const { return kind_; } 85 ExecutableType kind() const { return kind_; }
84 86
85 void set_image_base(uint64 image_base) { image_base_ = image_base; } 87 void set_image_base(uint64_t image_base) { image_base_ = image_base; }
86 88
87 // Instructions will be assembled in the order they are emitted. 89 // Instructions will be assembled in the order they are emitted.
88 90
89 // Generates an entire base relocation table. 91 // Generates an entire base relocation table.
90 CheckBool EmitPeRelocsInstruction() WARN_UNUSED_RESULT; 92 CheckBool EmitPeRelocsInstruction() WARN_UNUSED_RESULT;
91 93
92 // Generates an ELF style relocation table for X86. 94 // Generates an ELF style relocation table for X86.
93 CheckBool EmitElfRelocationInstruction() WARN_UNUSED_RESULT; 95 CheckBool EmitElfRelocationInstruction() WARN_UNUSED_RESULT;
94 96
95 // Generates an ELF style relocation table for ARM. 97 // Generates an ELF style relocation table for ARM.
96 CheckBool EmitElfARMRelocationInstruction() WARN_UNUSED_RESULT; 98 CheckBool EmitElfARMRelocationInstruction() WARN_UNUSED_RESULT;
97 99
98 // Following instruction will be assembled at address 'rva'. 100 // Following instruction will be assembled at address 'rva'.
99 CheckBool EmitOriginInstruction(RVA rva) WARN_UNUSED_RESULT; 101 CheckBool EmitOriginInstruction(RVA rva) WARN_UNUSED_RESULT;
100 102
101 // Generates a single byte of data or machine instruction. 103 // Generates a single byte of data or machine instruction.
102 CheckBool EmitByteInstruction(uint8 byte) WARN_UNUSED_RESULT; 104 CheckBool EmitByteInstruction(uint8_t byte) WARN_UNUSED_RESULT;
103 105
104 // Generates multiple bytes of data or machine instructions. 106 // Generates multiple bytes of data or machine instructions.
105 CheckBool EmitBytesInstruction(const uint8* value, size_t len) 107 CheckBool EmitBytesInstruction(const uint8_t* value,
106 WARN_UNUSED_RESULT; 108 size_t len) WARN_UNUSED_RESULT;
107 109
108 // Generates 4-byte relative reference to address of 'label'. 110 // Generates 4-byte relative reference to address of 'label'.
109 CheckBool EmitRel32(Label* label) WARN_UNUSED_RESULT; 111 CheckBool EmitRel32(Label* label) WARN_UNUSED_RESULT;
110 112
111 // Generates 4-byte relative reference to address of 'label' for 113 // Generates 4-byte relative reference to address of 'label' for
112 // ARM. 114 // ARM.
113 CheckBool EmitRel32ARM(uint16 op, Label* label, const uint8* arm_op, 115 CheckBool EmitRel32ARM(uint16_t op,
114 uint16 op_size) WARN_UNUSED_RESULT; 116 Label* label,
117 const uint8_t* arm_op,
118 uint16_t op_size) WARN_UNUSED_RESULT;
115 119
116 // Generates 4-byte absolute reference to address of 'label'. 120 // Generates 4-byte absolute reference to address of 'label'.
117 CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT; 121 CheckBool EmitAbs32(Label* label) WARN_UNUSED_RESULT;
118 122
119 // Generates 8-byte absolute reference to address of 'label'. 123 // Generates 8-byte absolute reference to address of 'label'.
120 CheckBool EmitAbs64(Label* label) WARN_UNUSED_RESULT; 124 CheckBool EmitAbs64(Label* label) WARN_UNUSED_RESULT;
121 125
122 // Looks up a label or creates a new one. Might return NULL. 126 // Looks up a label or creates a new one. Might return NULL.
123 Label* FindOrMakeAbs32Label(RVA rva); 127 Label* FindOrMakeAbs32Label(RVA rva);
124 128
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 168
165 // Looks up a label or creates a new one. Might return NULL. 169 // Looks up a label or creates a new one. Might return NULL.
166 Label* FindLabel(RVA rva, RVAToLabel* labels); 170 Label* FindLabel(RVA rva, RVAToLabel* labels);
167 171
168 // Helper methods for the public versions. 172 // Helper methods for the public versions.
169 static void UnassignIndexes(RVAToLabel* labels); 173 static void UnassignIndexes(RVAToLabel* labels);
170 static void DefaultAssignIndexes(RVAToLabel* labels); 174 static void DefaultAssignIndexes(RVAToLabel* labels);
171 static void AssignRemainingIndexes(RVAToLabel* labels); 175 static void AssignRemainingIndexes(RVAToLabel* labels);
172 176
173 // Sharing instructions that emit a single byte saves a lot of space. 177 // Sharing instructions that emit a single byte saves a lot of space.
174 Instruction* GetByteInstruction(uint8 byte); 178 Instruction* GetByteInstruction(uint8_t byte);
175 scoped_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_; 179 scoped_ptr<Instruction* [], base::FreeDeleter> byte_instruction_cache_;
176 180
177 uint64 image_base_; // Desired or mandated base address of image. 181 uint64_t image_base_; // Desired or mandated base address of image.
178 182
179 InstructionVector instructions_; // All the instructions in program. 183 InstructionVector instructions_; // All the instructions in program.
180 184
181 // These are lookup maps to find the label associated with a given address. 185 // These are lookup maps to find the label associated with a given address.
182 // We have separate label spaces for addresses referenced by rel32 labels and 186 // We have separate label spaces for addresses referenced by rel32 labels and
183 // abs32 labels. This is somewhat arbitrary. 187 // abs32 labels. This is somewhat arbitrary.
184 RVAToLabel rel32_labels_; 188 RVAToLabel rel32_labels_;
185 RVAToLabel abs32_labels_; 189 RVAToLabel abs32_labels_;
186 190
187 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram); 191 DISALLOW_COPY_AND_ASSIGN(AssemblyProgram);
188 }; 192 };
189 193
190 } // namespace courgette 194 } // namespace courgette
191 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_ 195 #endif // COURGETTE_ASSEMBLY_PROGRAM_H_
OLDNEW
« no previous file with comments | « courgette/adjustment_method_2.cc ('k') | courgette/assembly_program.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698