summaryrefslogtreecommitdiffstats
path: root/courgette/assembly_program.cc
diff options
context:
space:
mode:
Diffstat (limited to 'courgette/assembly_program.cc')
-rw-r--r--courgette/assembly_program.cc50
1 files changed, 28 insertions, 22 deletions
diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc
index de843f1..20eee96 100644
--- a/courgette/assembly_program.cc
+++ b/courgette/assembly_program.cc
@@ -7,12 +7,16 @@
#include <memory.h>
#include <stddef.h>
#include <stdint.h>
-
-#include <utility>
+#include <algorithm>
+#include <map>
+#include <set>
+#include <sstream>
#include <vector>
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
#include "courgette/courgette.h"
#include "courgette/encoded_program.h"
@@ -361,13 +365,13 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) {
<< " infill " << fill_infill_count;
}
-scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
+EncodedProgram* AssemblyProgram::Encode() const {
scoped_ptr<EncodedProgram> encoded(new EncodedProgram());
encoded->set_image_base(image_base_);
if (!encoded->DefineLabels(abs32_labels_, rel32_labels_))
- return nullptr;
+ return NULL;
for (size_t i = 0; i < instructions_.size(); ++i) {
Instruction* instruction = instructions_[i];
@@ -376,13 +380,13 @@ scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
case ORIGIN: {
OriginInstruction* org = static_cast<OriginInstruction*>(instruction);
if (!encoded->AddOrigin(org->origin_rva()))
- return nullptr;
+ return NULL;
break;
}
case DEFBYTE: {
uint8_t b = static_cast<ByteInstruction*>(instruction)->byte_value();
if (!encoded->AddCopy(1, &b))
- return nullptr;
+ return NULL;
break;
}
case DEFBYTES: {
@@ -391,13 +395,13 @@ scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
size_t len = static_cast<BytesInstruction*>(instruction)->len();
if (!encoded->AddCopy(len, byte_values))
- return nullptr;
+ return NULL;
break;
}
case REL32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddRel32(label->index_))
- return nullptr;
+ return NULL;
break;
}
case REL32ARM: {
@@ -406,34 +410,34 @@ scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
uint16_t compressed_op =
static_cast<InstructionWithLabelARM*>(instruction)->compressed_op();
if (!encoded->AddRel32ARM(compressed_op, label->index_))
- return nullptr;
+ return NULL;
break;
}
case ABS32: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddAbs32(label->index_))
- return nullptr;
+ return NULL;
break;
}
case ABS64: {
Label* label = static_cast<InstructionWithLabel*>(instruction)->label();
if (!encoded->AddAbs64(label->index_))
- return nullptr;
+ return NULL;
break;
}
case MAKEPERELOCS: {
if (!encoded->AddPeMakeRelocs(kind_))
- return nullptr;
+ return NULL;
break;
}
case MAKEELFRELOCS: {
if (!encoded->AddElfMakeRelocs())
- return nullptr;
+ return NULL;
break;
}
case MAKEELFARMRELOCS: {
if (!encoded->AddElfARMMakeRelocs())
- return nullptr;
+ return NULL;
break;
}
default: {
@@ -442,7 +446,7 @@ scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const {
}
}
- return encoded;
+ return encoded.release();
}
Instruction* AssemblyProgram::GetByteInstruction(uint8_t byte) {
@@ -526,13 +530,15 @@ CheckBool AssemblyProgram::TrimLabels() {
////////////////////////////////////////////////////////////////////////////////
-Status Encode(const AssemblyProgram& program,
- scoped_ptr<EncodedProgram>* output) {
- // Explicitly release any memory associated with the output before encoding.
- output->reset();
-
- *output = program.Encode();
- return (*output) ? C_OK : C_GENERAL_ERROR;
+Status Encode(AssemblyProgram* program, EncodedProgram** output) {
+ *output = NULL;
+ EncodedProgram *encoded = program->Encode();
+ if (encoded) {
+ *output = encoded;
+ return C_OK;
+ } else {
+ return C_GENERAL_ERROR;
+ }
}
} // namespace courgette