OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "courgette/encoded_program.h" | 5 #include "courgette/encoded_program.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
| 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/environment.h" | 16 #include "base/environment.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
19 #include "base/numerics/safe_math.h" | 19 #include "base/numerics/safe_math.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "courgette/courgette.h" | 22 #include "courgette/courgette.h" |
23 #include "courgette/disassembler_elf_32_arm.h" | 23 #include "courgette/disassembler_elf_32_arm.h" |
24 #include "courgette/streams.h" | 24 #include "courgette/streams.h" |
25 #include "courgette/types_elf.h" | |
26 | 25 |
27 namespace courgette { | 26 namespace courgette { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // Serializes a vector of integral values using Varint32 coding. | 30 // Serializes a vector of integral values using Varint32 coding. |
32 template<typename V> | 31 template<typename V> |
33 CheckBool WriteVector(const V& items, SinkStream* buffer) { | 32 CheckBool WriteVector(const V& items, SinkStream* buffer) { |
34 size_t count = items.size(); | 33 size_t count = items.size(); |
35 bool ok = buffer->WriteSizeVarint32(count); | 34 bool ok = buffer->WriteSizeVarint32(count); |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 return ok; | 773 return ok; |
775 } | 774 } |
776 //////////////////////////////////////////////////////////////////////////////// | 775 //////////////////////////////////////////////////////////////////////////////// |
777 | 776 |
778 Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink) { | 777 Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink) { |
779 if (!encoded->WriteTo(sink)) | 778 if (!encoded->WriteTo(sink)) |
780 return C_STREAM_ERROR; | 779 return C_STREAM_ERROR; |
781 return C_OK; | 780 return C_OK; |
782 } | 781 } |
783 | 782 |
784 Status ReadEncodedProgram(SourceStreamSet* streams, EncodedProgram** output) { | 783 Status ReadEncodedProgram(SourceStreamSet* streams, |
785 EncodedProgram* encoded = new EncodedProgram(); | 784 scoped_ptr<EncodedProgram>* output) { |
786 if (encoded->ReadFrom(streams)) { | 785 output->reset(nullptr); |
787 *output = encoded; | 786 scoped_ptr<EncodedProgram> encoded(new EncodedProgram()); |
788 return C_OK; | 787 if (!encoded->ReadFrom(streams)) |
789 } | 788 return C_DESERIALIZATION_FAILED; |
790 delete encoded; | 789 |
791 return C_DESERIALIZATION_FAILED; | 790 *output = std::move(encoded); |
| 791 return C_OK; |
792 } | 792 } |
793 | 793 |
794 Status Assemble(EncodedProgram* encoded, SinkStream* buffer) { | 794 Status Assemble(EncodedProgram* encoded, SinkStream* buffer) { |
795 bool assembled = encoded->AssembleTo(buffer); | 795 bool assembled = encoded->AssembleTo(buffer); |
796 if (assembled) | 796 if (assembled) |
797 return C_OK; | 797 return C_OK; |
798 return C_ASSEMBLY_FAILED; | 798 return C_ASSEMBLY_FAILED; |
799 } | 799 } |
800 | 800 |
801 void DeleteEncodedProgram(EncodedProgram* encoded) { | |
802 delete encoded; | |
803 } | |
804 | |
805 } // namespace courgette | 801 } // namespace courgette |
OLD | NEW |