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

Side by Side Diff: courgette/encoded_program.h

Issue 6677141: Switch out use of std::string and std::vector for large allocations for a buffer class that doesn... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: fix linux build error. remove unnecessary call Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « courgette/encode_decode_unittest.cc ('k') | courgette/encoded_program.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 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 #ifndef COURGETTE_ENCODED_PROGRAM_H_ 5 #ifndef COURGETTE_ENCODED_PROGRAM_H_
6 #define COURGETTE_ENCODED_PROGRAM_H_ 6 #define COURGETTE_ENCODED_PROGRAM_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "courgette/image_info.h" 11 #include "courgette/image_info.h"
(...skipping 13 matching lines...) Expand all
25 public: 25 public:
26 EncodedProgram(); 26 EncodedProgram();
27 ~EncodedProgram(); 27 ~EncodedProgram();
28 28
29 // Generating an EncodedProgram: 29 // Generating an EncodedProgram:
30 // 30 //
31 // (1) The image base can be specified at any time. 31 // (1) The image base can be specified at any time.
32 void set_image_base(uint64 base) { image_base_ = base; } 32 void set_image_base(uint64 base) { image_base_ = base; }
33 33
34 // (2) Address tables and indexes defined first. 34 // (2) Address tables and indexes defined first.
35 CheckBool DefineRel32Label(int index, RVA address); 35 CheckBool DefineRel32Label(int index, RVA address) WARN_UNUSED_RESULT;
36 CheckBool DefineAbs32Label(int index, RVA address); 36 CheckBool DefineAbs32Label(int index, RVA address) WARN_UNUSED_RESULT;
37 void EndLabels(); 37 void EndLabels();
38 38
39 // (3) Add instructions in the order needed to generate bytes of file. 39 // (3) Add instructions in the order needed to generate bytes of file.
40 CheckBool AddOrigin(RVA rva); 40 // NOTE: If any of these methods ever fail, the EncodedProgram instance
41 CheckBool AddCopy(uint32 count, const void* bytes); 41 // has failed and should be discarded.
42 CheckBool AddRel32(int label_index); 42 CheckBool AddOrigin(RVA rva) WARN_UNUSED_RESULT;
43 CheckBool AddAbs32(int label_index); 43 CheckBool AddCopy(uint32 count, const void* bytes) WARN_UNUSED_RESULT;
44 CheckBool AddMakeRelocs(); 44 CheckBool AddRel32(int label_index) WARN_UNUSED_RESULT;
45 CheckBool AddAbs32(int label_index) WARN_UNUSED_RESULT;
46 CheckBool AddMakeRelocs() WARN_UNUSED_RESULT;
45 47
46 // (3) Serialize binary assembly language tables to a set of streams. 48 // (3) Serialize binary assembly language tables to a set of streams.
47 CheckBool WriteTo(SinkStreamSet* streams); 49 CheckBool WriteTo(SinkStreamSet* streams) WARN_UNUSED_RESULT;
48 50
49 // Using an EncodedProgram to generate a byte stream: 51 // Using an EncodedProgram to generate a byte stream:
50 // 52 //
51 // (4) Deserializes a fresh EncodedProgram from a set of streams. 53 // (4) Deserializes a fresh EncodedProgram from a set of streams.
52 bool ReadFrom(SourceStreamSet* streams); 54 bool ReadFrom(SourceStreamSet* streams);
53 55
54 // (5) Assembles the 'binary assembly language' into final file. 56 // (5) Assembles the 'binary assembly language' into final file.
55 CheckBool AssembleTo(SinkStream* buffer); 57 CheckBool AssembleTo(SinkStream* buffer) WARN_UNUSED_RESULT;
56 58
57 private: 59 private:
58 // Binary assembly language operations. 60 // Binary assembly language operations.
59 enum OP { 61 enum OP {
60 ORIGIN, // ORIGIN <rva> - set address for subsequent assembly. 62 ORIGIN, // ORIGIN <rva> - set address for subsequent assembly.
61 COPY, // COPY <count> <bytes> - copy bytes to output. 63 COPY, // COPY <count> <bytes> - copy bytes to output.
62 COPY1, // COPY1 <byte> - same as COPY 1 <byte>. 64 COPY1, // COPY1 <byte> - same as COPY 1 <byte>.
63 REL32, // REL32 <index> - emit rel32 encoded reference to address at 65 REL32, // REL32 <index> - emit rel32 encoded reference to address at
64 // address table offset <index> 66 // address table offset <index>
65 ABS32, // ABS32 <index> - emit abs32 encoded reference to address at 67 ABS32, // ABS32 <index> - emit abs32 encoded reference to address at
66 // address table offset <index> 68 // address table offset <index>
67 MAKE_BASE_RELOCATION_TABLE, // Emit base relocation table blocks. 69 MAKE_BASE_RELOCATION_TABLE, // Emit base relocation table blocks.
68 OP_LAST 70 OP_LAST
69 }; 71 };
70 72
71 typedef std::vector<RVA, MemoryAllocator<RVA> > RvaVector; 73 typedef NoThrowBuffer<RVA> RvaVector;
72 typedef std::vector<uint32, MemoryAllocator<uint32> > UInt32Vector; 74 typedef NoThrowBuffer<uint32> UInt32Vector;
73 typedef std::vector<uint8, MemoryAllocator<uint8> > UInt8Vector; 75 typedef NoThrowBuffer<uint8> UInt8Vector;
74 typedef std::vector<OP, MemoryAllocator<OP> > OPVector; 76 typedef NoThrowBuffer<OP> OPVector;
75 77
76 void DebuggingSummary(); 78 void DebuggingSummary();
77 CheckBool GenerateBaseRelocations(SinkStream *buffer); 79 CheckBool GenerateBaseRelocations(SinkStream *buffer) WARN_UNUSED_RESULT;
78 CheckBool DefineLabelCommon(RvaVector*, int, RVA); 80 CheckBool DefineLabelCommon(RvaVector*, int, RVA) WARN_UNUSED_RESULT;
79 void FinishLabelsCommon(RvaVector* addresses); 81 void FinishLabelsCommon(RvaVector* addresses);
80 82
81 // Binary assembly language tables. 83 // Binary assembly language tables.
82 uint64 image_base_; 84 uint64 image_base_;
83 RvaVector rel32_rva_; 85 RvaVector rel32_rva_;
84 RvaVector abs32_rva_; 86 RvaVector abs32_rva_;
85 OPVector ops_; 87 OPVector ops_;
86 RvaVector origins_; 88 RvaVector origins_;
87 UInt32Vector copy_counts_; 89 UInt32Vector copy_counts_;
88 UInt8Vector copy_bytes_; 90 UInt8Vector copy_bytes_;
89 UInt32Vector rel32_ix_; 91 UInt32Vector rel32_ix_;
90 UInt32Vector abs32_ix_; 92 UInt32Vector abs32_ix_;
91 93
92 // Table of the addresses containing abs32 relocations; computed during 94 // Table of the addresses containing abs32 relocations; computed during
93 // assembly, used to generate base relocation table. 95 // assembly, used to generate base relocation table.
94 UInt32Vector abs32_relocs_; 96 UInt32Vector abs32_relocs_;
95 97
96 DISALLOW_COPY_AND_ASSIGN(EncodedProgram); 98 DISALLOW_COPY_AND_ASSIGN(EncodedProgram);
97 }; 99 };
98 100
99 } // namespace courgette 101 } // namespace courgette
100 #endif // COURGETTE_ENCODED_PROGRAM_H_ 102 #endif // COURGETTE_ENCODED_PROGRAM_H_
OLDNEW
« no previous file with comments | « courgette/encode_decode_unittest.cc ('k') | courgette/encoded_program.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698