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> | |
14 #include <vector> | 13 #include <vector> |
15 | 14 |
16 #include "base/environment.h" | 15 #include "base/environment.h" |
17 #include "base/logging.h" | 16 #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" |
25 | 26 |
26 namespace courgette { | 27 namespace courgette { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Serializes a vector of integral values using Varint32 coding. | 31 // Serializes a vector of integral values using Varint32 coding. |
31 template<typename V> | 32 template<typename V> |
32 CheckBool WriteVector(const V& items, SinkStream* buffer) { | 33 CheckBool WriteVector(const V& items, SinkStream* buffer) { |
33 size_t count = items.size(); | 34 size_t count = items.size(); |
34 bool ok = buffer->WriteSizeVarint32(count); | 35 bool ok = buffer->WriteSizeVarint32(count); |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 return ok; | 774 return ok; |
774 } | 775 } |
775 //////////////////////////////////////////////////////////////////////////////// | 776 //////////////////////////////////////////////////////////////////////////////// |
776 | 777 |
777 Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink) { | 778 Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink) { |
778 if (!encoded->WriteTo(sink)) | 779 if (!encoded->WriteTo(sink)) |
779 return C_STREAM_ERROR; | 780 return C_STREAM_ERROR; |
780 return C_OK; | 781 return C_OK; |
781 } | 782 } |
782 | 783 |
783 Status ReadEncodedProgram(SourceStreamSet* streams, | 784 Status ReadEncodedProgram(SourceStreamSet* streams, EncodedProgram** output) { |
784 scoped_ptr<EncodedProgram>* output) { | 785 EncodedProgram* encoded = new EncodedProgram(); |
785 output->reset(); | 786 if (encoded->ReadFrom(streams)) { |
786 scoped_ptr<EncodedProgram> encoded(new EncodedProgram()); | 787 *output = encoded; |
787 if (!encoded->ReadFrom(streams)) | 788 return C_OK; |
788 return C_DESERIALIZATION_FAILED; | 789 } |
789 | 790 delete encoded; |
790 *output = std::move(encoded); | 791 return C_DESERIALIZATION_FAILED; |
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 |
801 } // namespace courgette | 805 } // namespace courgette |
OLD | NEW |