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

Unified Diff: courgette/disassembler.cc

Issue 2771753004: [Courgette] Refactor: Unify Disassembler::Disassemble() and instantiate AssemblyProgram there. (Closed)
Patch Set: Fix signed/unsigned comparison issue in test. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/disassembler.h ('k') | courgette/disassembler_elf_32.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/disassembler.cc
diff --git a/courgette/disassembler.cc b/courgette/disassembler.cc
index 9407f6dae6a871e06319b9ac3e0d77e86ba33d99..31c23f1f64020c67c78abccf011103517922b76a 100644
--- a/courgette/disassembler.cc
+++ b/courgette/disassembler.cc
@@ -4,9 +4,8 @@
#include "courgette/disassembler.h"
-#include <memory>
-
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "courgette/assembly_program.h"
namespace courgette {
@@ -38,9 +37,9 @@ Disassembler::Disassembler(const uint8_t* start, size_t length)
start_ = start;
length_ = length;
end_ = start_ + length_;
-};
+}
-Disassembler::~Disassembler() {};
+Disassembler::~Disassembler() {}
const uint8_t* Disassembler::FileOffsetToPointer(FileOffset file_offset) const {
CHECK_LE(file_offset, static_cast<FileOffset>(end_ - start_));
@@ -55,6 +54,23 @@ const uint8_t* Disassembler::RVAToPointer(RVA rva) const {
return FileOffsetToPointer(file_offset);
}
+std::unique_ptr<AssemblyProgram> Disassembler::Disassemble() {
+ if (!ok() || !ExtractAbs32Locations() || !ExtractRel32Locations())
+ return nullptr;
+
+ std::unique_ptr<AssemblyProgram> program =
+ base::MakeUnique<AssemblyProgram>(kind(), image_base());
+
+ PrecomputeLabels(program.get());
+ RemoveUnusedRel32Locations(program.get());
+
+ if (!program->GenerateInstructions(GetInstructionGenerator(program.get())))
+ return nullptr;
+
+ program->DefaultAssignIndexes();
+ return program;
+}
+
bool Disassembler::Good() {
failure_reason_ = nullptr;
return true;
« no previous file with comments | « courgette/disassembler.h ('k') | courgette/disassembler_elf_32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698