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

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: Make AssemblyProgram::CreateInstruction*Receptor() return CheckBool. 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
Index: courgette/disassembler_elf_32.h
diff --git a/courgette/disassembler_elf_32.h b/courgette/disassembler_elf_32.h
index f0961c0c7ab2e9e9c9e4e7c5ee3a22e315333e39..5a99b189cabad62bc3363cd4ca85aa200251b894 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;
@@ -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,8 +224,10 @@ 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_;
DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32);
};

Powered by Google App Engine
This is Rietveld 408576698