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

Unified Diff: courgette/disassembler_elf_32.h

Issue 2462993003: [Courgette] Refactor: Add and use Instruction*Receptor classes; call ParseFile() in 2 passes. (Closed)
Patch Set: Fix comments. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/assembly_program.cc ('k') | courgette/disassembler_elf_32.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/disassembler_elf_32.h
diff --git a/courgette/disassembler_elf_32.h b/courgette/disassembler_elf_32.h
index f0961c0c7ab2e9e9c9e4e7c5ee3a22e315333e39..395f571e0bf1929ad76584c5f31e94dd64114111 100644
--- a/courgette/disassembler_elf_32.h
+++ b/courgette/disassembler_elf_32.h
@@ -21,6 +21,7 @@
namespace courgette {
class AssemblyProgram;
+class InstructionReceptor;
// A Courgette disassembler for 32-bit ELF files. This is only a partial
// implementation that admits subclasses for the architecture-specific parts of
@@ -53,8 +54,8 @@ class DisassemblerElf32 : public Disassembler {
virtual CheckBool ComputeRelativeTarget(const uint8_t* op_pointer) = 0;
// Emits the assembly instruction corresponding to |label|.
- virtual CheckBool EmitInstruction(AssemblyProgram* program,
- Label* label) = 0;
+ virtual CheckBool EmitInstruction(Label* label,
+ InstructionReceptor* receptor) = 0;
// Returns the size of the instruction containing the RVA.
virtual uint16_t op_size() const = 0;
@@ -71,7 +72,7 @@ class DisassemblerElf32 : public Disassembler {
return a->file_offset() < b->file_offset();
}
- private:
+ private:
const RVA rva_;
RVA relative_target_ = kNoRVA;
FileOffset file_offset_ = kNoFileOffset;
@@ -102,7 +103,7 @@ class DisassemblerElf32 : public Disassembler {
RVA FileOffsetToRVA(FileOffset file_offset) const override;
FileOffset RVAToFileOffset(RVA rva) const override;
RVA PointerToTargetRVA(const uint8_t* p) const override;
- virtual ExecutableType kind() const override = 0;
+ ExecutableType kind() const override = 0;
bool ParseHeader() override;
bool Disassemble(AssemblyProgram* target) override;
@@ -163,15 +164,15 @@ class DisassemblerElf32 : public Disassembler {
// Misc address space helpers
CheckBool RVAsToFileOffsets(const std::vector<RVA>& rvas,
- std::vector<FileOffset>* file_offsets);
+ std::vector<FileOffset>* file_offsets) const;
CheckBool RVAsToFileOffsets(
- std::vector<std::unique_ptr<TypedRVA>>* typed_rvas);
+ std::vector<std::unique_ptr<TypedRVA>>* typed_rvas) const;
// Parsing code for Disassemble().
virtual CheckBool ParseRelocationSection(const Elf32_Shdr* section_header,
- AssemblyProgram* program)
+ InstructionReceptor* receptor) const
WARN_UNUSED_RESULT = 0;
virtual CheckBool ParseRel32RelocsFromSection(const Elf32_Shdr* section)
@@ -182,7 +183,8 @@ class DisassemblerElf32 : public Disassembler {
RvaVisitor* CreateRel32TargetRvaVisitor() override;
void RemoveUnusedRel32Locations(AssemblyProgram* program) override;
- CheckBool ParseFile(AssemblyProgram* target) WARN_UNUSED_RESULT;
+ CheckBool ParseFile(AssemblyProgram* target,
+ InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
CheckBool ParseProgbitsSection(
const Elf32_Shdr* section_header,
@@ -190,11 +192,13 @@ class DisassemblerElf32 : public Disassembler {
std::vector<FileOffset>::iterator end_abs_offset,
std::vector<std::unique_ptr<TypedRVA>>::iterator* current_rel,
std::vector<std::unique_ptr<TypedRVA>>::iterator end_rel,
- AssemblyProgram* program) WARN_UNUSED_RESULT;
+ AssemblyProgram* program,
+ InstructionReceptor* receptor) const WARN_UNUSED_RESULT;
CheckBool ParseSimpleRegion(FileOffset start_file_offset,
FileOffset end_file_offset,
- AssemblyProgram* program) WARN_UNUSED_RESULT;
+ InstructionReceptor* receptor) const
+ WARN_UNUSED_RESULT;
CheckBool ParseAbs32Relocs() WARN_UNUSED_RESULT;
@@ -220,9 +224,12 @@ class DisassemblerElf32 : public Disassembler {
const char* default_string_section_;
size_t default_string_section_size_;
- std::vector<RVA> abs32_locations_;
- std::vector<std::unique_ptr<TypedRVA>> rel32_locations_;
+ // Sorted abs32 and reel32 RVAs. These are mutable because ParseFile() needs
+ // to sort these by file offsets.
+ mutable std::vector<RVA> abs32_locations_;
+ mutable std::vector<std::unique_ptr<TypedRVA>> rel32_locations_;
+ private:
DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32);
};
« no previous file with comments | « courgette/assembly_program.cc ('k') | courgette/disassembler_elf_32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698