Chromium Code Reviews| Index: courgette/assembly_program.cc |
| diff --git a/courgette/assembly_program.cc b/courgette/assembly_program.cc |
| index 20eee96ff5e04b5e0d1e77642526b6d7c7698a4e..1ffbcb58c855fa50e6b3aae27465b3cb54e88c0f 100644 |
| --- a/courgette/assembly_program.cc |
| +++ b/courgette/assembly_program.cc |
| @@ -7,16 +7,16 @@ |
| #include <memory.h> |
| #include <stddef.h> |
| #include <stdint.h> |
| + |
| #include <algorithm> |
| #include <map> |
| #include <set> |
| #include <sstream> |
| +#include <utility> |
|
grt (UTC plus 2)
2016/01/26 16:39:54
the four includes above this appear to be unused,
huangs
2016/01/26 18:42:24
Done.
|
| #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" |
| @@ -365,13 +365,13 @@ void AssemblyProgram::AssignRemainingIndexes(RVAToLabel* labels) { |
| << " infill " << fill_infill_count; |
| } |
| -EncodedProgram* AssemblyProgram::Encode() const { |
| +scoped_ptr<EncodedProgram> AssemblyProgram::Encode() const { |
| scoped_ptr<EncodedProgram> encoded(new EncodedProgram()); |
| encoded->set_image_base(image_base_); |
| if (!encoded->DefineLabels(abs32_labels_, rel32_labels_)) |
| - return NULL; |
| + return nullptr; |
| for (size_t i = 0; i < instructions_.size(); ++i) { |
| Instruction* instruction = instructions_[i]; |
| @@ -380,13 +380,13 @@ EncodedProgram* AssemblyProgram::Encode() const { |
| case ORIGIN: { |
| OriginInstruction* org = static_cast<OriginInstruction*>(instruction); |
| if (!encoded->AddOrigin(org->origin_rva())) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case DEFBYTE: { |
| uint8_t b = static_cast<ByteInstruction*>(instruction)->byte_value(); |
| if (!encoded->AddCopy(1, &b)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case DEFBYTES: { |
| @@ -395,13 +395,13 @@ EncodedProgram* AssemblyProgram::Encode() const { |
| size_t len = static_cast<BytesInstruction*>(instruction)->len(); |
| if (!encoded->AddCopy(len, byte_values)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case REL32: { |
| Label* label = static_cast<InstructionWithLabel*>(instruction)->label(); |
| if (!encoded->AddRel32(label->index_)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case REL32ARM: { |
| @@ -410,34 +410,34 @@ EncodedProgram* AssemblyProgram::Encode() const { |
| uint16_t compressed_op = |
| static_cast<InstructionWithLabelARM*>(instruction)->compressed_op(); |
| if (!encoded->AddRel32ARM(compressed_op, label->index_)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case ABS32: { |
| Label* label = static_cast<InstructionWithLabel*>(instruction)->label(); |
| if (!encoded->AddAbs32(label->index_)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case ABS64: { |
| Label* label = static_cast<InstructionWithLabel*>(instruction)->label(); |
| if (!encoded->AddAbs64(label->index_)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case MAKEPERELOCS: { |
| if (!encoded->AddPeMakeRelocs(kind_)) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case MAKEELFRELOCS: { |
| if (!encoded->AddElfMakeRelocs()) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| case MAKEELFARMRELOCS: { |
| if (!encoded->AddElfARMMakeRelocs()) |
| - return NULL; |
| + return nullptr; |
| break; |
| } |
| default: { |
| @@ -446,7 +446,7 @@ EncodedProgram* AssemblyProgram::Encode() const { |
| } |
| } |
| - return encoded.release(); |
| + return encoded; |
| } |
| Instruction* AssemblyProgram::GetByteInstruction(uint8_t byte) { |
| @@ -530,15 +530,16 @@ CheckBool AssemblyProgram::TrimLabels() { |
| //////////////////////////////////////////////////////////////////////////////// |
| -Status Encode(AssemblyProgram* program, EncodedProgram** output) { |
| - *output = NULL; |
| - EncodedProgram *encoded = program->Encode(); |
| - if (encoded) { |
| - *output = encoded; |
| - return C_OK; |
| - } else { |
| +Status Encode(const AssemblyProgram& program, |
|
grt (UTC plus 2)
2016/01/26 16:39:54
i don't see the point of this function since the r
huangs
2016/01/26 18:42:24
I think the intention of these weird wrappers is t
|
| + scoped_ptr<EncodedProgram>* output) { |
| + output->reset(nullptr); |
|
grt (UTC plus 2)
2016/01/26 16:39:54
please document this subtlety
// Explicitly rele
huangs
2016/01/26 18:42:24
Done.
|
| + |
| + scoped_ptr<EncodedProgram> encoded = program.Encode(); |
|
grt (UTC plus 2)
2016/01/26 16:39:54
this intermediate variable isn't needed:
*output
huangs
2016/01/26 18:42:24
Done.
|
| + if (!encoded) |
| return C_GENERAL_ERROR; |
| - } |
| + |
| + *output = std::move(encoded); |
| + return C_OK; |
| } |
| } // namespace courgette |