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

Side by Side Diff: courgette/courgette_flow.h

Issue 2854113002: [Courgette] Reduce AssemblyProgram to reduce Courgette-apply RAM floor and disk churn. (Closed)
Patch Set: Update courgette_fuzzer in libfuzzer. Created 3 years, 7 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
« no previous file with comments | « courgette/assembly_program.cc ('k') | courgette/courgette_flow.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_COURGETTE_FLOW_H_ 5 #ifndef COURGETTE_COURGETTE_FLOW_H_
6 #define COURGETTE_COURGETTE_FLOW_H_ 6 #define COURGETTE_COURGETTE_FLOW_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "courgette/courgette.h" 12 #include "courgette/courgette.h"
13 #include "courgette/region.h" 13 #include "courgette/region.h"
14 #include "courgette/streams.h" 14 #include "courgette/streams.h"
15 15
16 namespace courgette { 16 namespace courgette {
17 17
18 class AssemblyProgram; 18 class AssemblyProgram;
19 class Disassembler;
19 class EncodedProgram; 20 class EncodedProgram;
20 21
21 // An adaptor for Region as BasicBuffer. 22 // An adaptor for Region as BasicBuffer.
22 class RegionBuffer : public BasicBuffer { 23 class RegionBuffer : public BasicBuffer {
23 public: 24 public:
24 explicit RegionBuffer(const Region& region) : region_(region) {} 25 explicit RegionBuffer(const Region& region) : region_(region) {}
25 ~RegionBuffer() override {} 26 ~RegionBuffer() override {}
26 27
27 // BasicBuffer: 28 // BasicBuffer:
28 const uint8_t* data() const override { return region_.start(); } 29 const uint8_t* data() const override { return region_.start(); }
(...skipping 11 matching lines...) Expand all
40 // and all subsequent commands become no-op. This allows callers to concisely 41 // and all subsequent commands become no-op. This allows callers to concisely
41 // specify high-level logic with minimal code for error handling. 42 // specify high-level logic with minimal code for error handling.
42 class CourgetteFlow { 43 class CourgetteFlow {
43 public: 44 public:
44 // A group of Courgette data, for a single executable. Takes negligible space 45 // A group of Courgette data, for a single executable. Takes negligible space
45 // when unused. 46 // when unused.
46 struct Data { 47 struct Data {
47 Data(); 48 Data();
48 ~Data(); 49 ~Data();
49 50
51 std::unique_ptr<Disassembler> disassembler;
50 std::unique_ptr<AssemblyProgram> program; 52 std::unique_ptr<AssemblyProgram> program;
51 std::unique_ptr<EncodedProgram> encoded; 53 std::unique_ptr<EncodedProgram> encoded;
52 SinkStreamSet sinks; 54 SinkStreamSet sinks;
53 SourceStreamSet sources; 55 SourceStreamSet sources;
54 }; 56 };
55 57
56 // Group enumeration into |data_*_| fields. 58 // Group enumeration into |data_*_| fields.
57 enum Group { 59 enum Group {
58 ONLY, // The only file processed. 60 ONLY, // The only file processed.
59 OLD, // The "old" file during patching. 61 OLD, // The "old" file during patching.
(...skipping 11 matching lines...) Expand all
71 const std::string& message(); 73 const std::string& message();
72 74
73 // Commands that perform no-op on error. This allows caller to concisely 75 // Commands that perform no-op on error. This allows caller to concisely
74 // specify high-level logic, and perform a single error check at the end. Care 76 // specify high-level logic, and perform a single error check at the end. Care
75 // must be taken w.r.t. error handling if |data()| is harvested between 77 // must be taken w.r.t. error handling if |data()| is harvested between
76 // commands. 78 // commands.
77 79
78 // Reads |buffer| to initialize |data(group)->sources|. 80 // Reads |buffer| to initialize |data(group)->sources|.
79 void ReadSourceStreamSetFromBuffer(Group group, const BasicBuffer& buffer); 81 void ReadSourceStreamSetFromBuffer(Group group, const BasicBuffer& buffer);
80 82
81 // Reads |buffer| to initialize |data(group)->program|, passing |annotate| as 83 // Reads |buffer| to initialize |data(group)->disassembler|.
82 // initialization parameter (true if AdjustNewAssemblyProgramToMatchOld() gets 84 void ReadDisassemblerFromBuffer(Group group, const BasicBuffer& buffer);
83 // called later).
84 void ReadAssemblyProgramFromBuffer(Group group,
85 const BasicBuffer& buffer,
86 bool annotate);
87 85
88 // Reads |opt_sources| if given, or else |data(group)->sources| to initialize 86 // Reads |opt_sources| if given, or else |data(group)->sources| to initialize
89 // |data(group).encoded|. 87 // |data(group).encoded|.
90 void ReadEncodedProgramFromSourceStreamSet( 88 void ReadEncodedProgramFromSourceStreamSet(
91 Group group, 89 Group group,
92 SourceStreamSet* opt_sources = nullptr); 90 SourceStreamSet* opt_sources = nullptr);
93 91
94 // Uses |data(group)->program| to initialize |data(group)->encoded|. 92 // Uses |data(group)->disassembler| to initialize |data(group)->program|,
95 void CreateEncodedProgramFromAssemblyProgram(Group group); 93 // passing |annotate| as initialization parameter (should be true if
94 // AdjustNewAssemblyProgramToMatchOld() gets called later).
95 void CreateAssemblyProgramFromDisassembler(Group group, bool annotate);
96
97 // Uses |data(group)->disassembler| and |data(group)->program| to initialize
98 // |data(group)->encoded|.
99 void CreateEncodedProgramFromDisassemblerAndAssemblyProgram(Group group);
96 100
97 // Serializese |data(group)->sinks| to |sink|. 101 // Serializese |data(group)->sinks| to |sink|.
98 void WriteSinkStreamFromSinkStreamSet(Group group, SinkStream* sink); 102 void WriteSinkStreamFromSinkStreamSet(Group group, SinkStream* sink);
99 103
100 // Serializes |data(group)->encoded| to |opt_sinks| if given, or else to 104 // Serializes |data(group)->encoded| to |opt_sinks| if given, or else to
101 // |data(group)->sinks|. 105 // |data(group)->sinks|.
102 void WriteSinkStreamSetFromEncodedProgram(Group group, 106 void WriteSinkStreamSetFromEncodedProgram(Group group,
103 SinkStreamSet* opt_sinks = nullptr); 107 SinkStreamSet* opt_sinks = nullptr);
104 108
105 // Converts |data(group)->encoded| to an exectuable and writes the result to 109 // Converts |data(group)->encoded| to an exectuable and writes the result to
106 // |sink|. 110 // |sink|.
107 void WriteExecutableFromEncodedProgram(Group group, SinkStream* sink); 111 void WriteExecutableFromEncodedProgram(Group group, SinkStream* sink);
108 112
109 // Adjusts |data(NEW)->program| Labels to match |data(OLD)->program| Labels. 113 // Adjusts |data(NEW)->program| Labels to match |data(OLD)->program| Labels.
110 void AdjustNewAssemblyProgramToMatchOld(); 114 void AdjustNewAssemblyProgramToMatchOld();
111 115
112 // Destructor commands to reduce memory usage. 116 // Destructor commands to reduce memory usage.
113 117
118 void DestroyDisassembler(Group group);
119
114 void DestroyAssemblyProgram(Group group); 120 void DestroyAssemblyProgram(Group group);
115 121
116 void DestroyEncodedProgram(Group group); 122 void DestroyEncodedProgram(Group group);
117 123
118 private: 124 private:
119 // Utilities to process return values from Courgette functions, and assign 125 // Utilities to process return values from Courgette functions, and assign
120 // |status_| and |message_|. Usage: 126 // |status_| and |message_|. Usage:
121 // if (!check(some_courgette_function(param1, ...))) 127 // if (!check(some_courgette_function(param1, ...)))
122 // setMessage("format string %s...", value1, ...); 128 // setMessage("format string %s...", value1, ...);
123 129
(...skipping 11 matching lines...) Expand all
135 Data data_only_; 141 Data data_only_;
136 Data data_old_; 142 Data data_old_;
137 Data data_new_; 143 Data data_new_;
138 144
139 DISALLOW_COPY_AND_ASSIGN(CourgetteFlow); 145 DISALLOW_COPY_AND_ASSIGN(CourgetteFlow);
140 }; 146 };
141 147
142 } // namespace courgette 148 } // namespace courgette
143 149
144 #endif // COURGETTE_COURGETTE_FLOW_H_ 150 #endif // COURGETTE_COURGETTE_FLOW_H_
OLDNEW
« no previous file with comments | « courgette/assembly_program.cc ('k') | courgette/courgette_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698