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 <stdarg.h> | 5 #include <stdarg.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <initializer_list> | 9 #include <initializer_list> |
10 #include <memory> | 10 #include <memory> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 148 } |
149 | 149 |
150 printf("%s Executable\n", format.c_str()); | 150 printf("%s Executable\n", format.c_str()); |
151 return result; | 151 return result; |
152 } | 152 } |
153 | 153 |
154 void Disassemble(const base::FilePath& input_file, | 154 void Disassemble(const base::FilePath& input_file, |
155 const base::FilePath& output_file) { | 155 const base::FilePath& output_file) { |
156 CourgetteFlow flow; | 156 CourgetteFlow flow; |
157 BufferedFileReader input_buffer(input_file, flow.name(flow.ONLY)); | 157 BufferedFileReader input_buffer(input_file, flow.name(flow.ONLY)); |
158 flow.ReadAssemblyProgramFromBuffer(flow.ONLY, input_buffer, false); | 158 flow.ReadDisassemblerFromBuffer(flow.ONLY, input_buffer); |
159 flow.CreateEncodedProgramFromAssemblyProgram(flow.ONLY); | 159 flow.CreateAssemblyProgramFromDisassembler(flow.ONLY, false); |
160 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.ONLY); | |
161 flow.DestroyDisassembler(flow.ONLY); | |
160 flow.DestroyAssemblyProgram(flow.ONLY); | 162 flow.DestroyAssemblyProgram(flow.ONLY); |
161 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY); | 163 flow.WriteSinkStreamSetFromEncodedProgram(flow.ONLY); |
162 flow.DestroyEncodedProgram(flow.ONLY); | 164 flow.DestroyEncodedProgram(flow.ONLY); |
163 courgette::SinkStream sink; | 165 courgette::SinkStream sink; |
164 flow.WriteSinkStreamFromSinkStreamSet(flow.ONLY, &sink); | 166 flow.WriteSinkStreamFromSinkStreamSet(flow.ONLY, &sink); |
165 if (flow.failed()) | 167 if (flow.failed()) |
166 Problem(flow.message().c_str()); | 168 Problem(flow.message().c_str()); |
167 | 169 |
168 WriteSinkToFile(&sink, output_file); | 170 WriteSinkToFile(&sink, output_file); |
169 } | 171 } |
170 | 172 |
171 void DisassembleAndAdjust(const base::FilePath& old_file, | 173 void DisassembleAndAdjust(const base::FilePath& old_file, |
172 const base::FilePath& new_file, | 174 const base::FilePath& new_file, |
173 const base::FilePath& output_file) { | 175 const base::FilePath& output_file) { |
176 // Flow graph and process sequence (DA = Disassembler, AP = AssemblyProgram, | |
177 // EP = EncodedProgram, Adj = Adjusted): | |
178 // [1 Old DA] --> [2 Old AP] [4 New AP] <-- [3 New DA] | |
179 // | | | | |
180 // | v (move) v | |
181 // +---> [5 Adj New AP] --> [6 New EP] | |
182 // (7 Write) | |
174 CourgetteFlow flow; | 183 CourgetteFlow flow; |
175 BufferedFileReader old_buffer(old_file, flow.name(flow.OLD)); | 184 BufferedFileReader old_buffer(old_file, flow.name(flow.OLD)); |
176 BufferedFileReader new_buffer(new_file, flow.name(flow.NEW)); | 185 BufferedFileReader new_buffer(new_file, flow.name(flow.NEW)); |
177 flow.ReadAssemblyProgramFromBuffer(flow.OLD, old_buffer, true); | 186 flow.ReadDisassemblerFromBuffer(flow.OLD, old_buffer); // 1 |
178 flow.ReadAssemblyProgramFromBuffer(flow.NEW, new_buffer, true); | 187 flow.CreateAssemblyProgramFromDisassembler(flow.OLD, true); // 2 |
179 flow.AdjustNewAssemblyProgramToMatchOld(); | 188 flow.DestroyDisassembler(flow.OLD); |
Will Harris
2017/05/05 22:26:22
can these create and destroys be managed with smar
huangs
2017/05/14 04:27:55
Yes, then we won't need the flow.Destroy*() functi
| |
189 flow.ReadDisassemblerFromBuffer(flow.NEW, new_buffer); // 3 | |
190 flow.CreateAssemblyProgramFromDisassembler(flow.NEW, true); // 4 | |
191 flow.AdjustNewAssemblyProgramToMatchOld(); // 5 | |
180 flow.DestroyAssemblyProgram(flow.OLD); | 192 flow.DestroyAssemblyProgram(flow.OLD); |
181 flow.CreateEncodedProgramFromAssemblyProgram(flow.NEW); | 193 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.NEW); // 6 |
182 flow.DestroyAssemblyProgram(flow.NEW); | 194 flow.DestroyAssemblyProgram(flow.NEW); |
183 flow.WriteSinkStreamSetFromEncodedProgram(flow.NEW); | 195 flow.DestroyDisassembler(flow.NEW); |
196 flow.WriteSinkStreamSetFromEncodedProgram(flow.NEW); // 7 | |
184 flow.DestroyEncodedProgram(flow.NEW); | 197 flow.DestroyEncodedProgram(flow.NEW); |
185 courgette::SinkStream sink; | 198 courgette::SinkStream sink; |
186 flow.WriteSinkStreamFromSinkStreamSet(flow.NEW, &sink); | 199 flow.WriteSinkStreamFromSinkStreamSet(flow.NEW, &sink); |
187 if (flow.failed()) | 200 if (flow.failed()) |
188 Problem(flow.message().c_str()); | 201 Problem(flow.message().c_str()); |
189 | 202 |
190 WriteSinkToFile(&sink, output_file); | 203 WriteSinkToFile(&sink, output_file); |
191 } | 204 } |
192 | 205 |
193 // Diffs two executable files, write a set of files for the diff, one file per | 206 // Diffs two executable files, write a set of files for the diff, one file per |
194 // stream of the EncodedProgram format. Each file is the bsdiff between the | 207 // stream of the EncodedProgram format. Each file is the bsdiff between the |
195 // original file's stream and the new file's stream. This is completely | 208 // original file's stream and the new file's stream. This is completely |
196 // uninteresting to users, but it is handy for seeing how much each which | 209 // uninteresting to users, but it is handy for seeing how much each which |
197 // streams are contributing to the final file size. Adjustment is optional. | 210 // streams are contributing to the final file size. Adjustment is optional. |
198 void DisassembleAdjustDiff(const base::FilePath& old_file, | 211 void DisassembleAdjustDiff(const base::FilePath& old_file, |
199 const base::FilePath& new_file, | 212 const base::FilePath& new_file, |
200 const base::FilePath& output_file_root, | 213 const base::FilePath& output_file_root, |
201 bool adjust) { | 214 bool adjust) { |
215 // Same as PatchGeneratorX86_32::Transform(), except Adjust is optional, and | |
216 // |flow|'s internal SinkStreamSet get used. | |
217 // Flow graph and process sequence (DA = Disassembler, AP = AssemblyProgram, | |
218 // EP = EncodedProgram, Adj = Adjusted): | |
219 // [1 Old DA] --> [2 Old AP] [6 New AP] <-- [5 New DA] | |
220 // | | | | | | |
221 // v | | v (move) v | |
222 // [3 Old EP] <-----+ +->[7 Adj New AP] --> [8 New EP] | |
223 // (4 Write) (9 Write) | |
202 CourgetteFlow flow; | 224 CourgetteFlow flow; |
203 BufferedFileReader old_buffer(old_file, flow.name(flow.OLD)); | 225 BufferedFileReader old_buffer(old_file, flow.name(flow.OLD)); |
204 BufferedFileReader new_buffer(new_file, flow.name(flow.NEW)); | 226 BufferedFileReader new_buffer(new_file, flow.name(flow.NEW)); |
205 flow.ReadAssemblyProgramFromBuffer(flow.OLD, old_buffer, adjust); | 227 flow.ReadDisassemblerFromBuffer(flow.OLD, old_buffer); // 1 |
206 flow.ReadAssemblyProgramFromBuffer(flow.NEW, new_buffer, adjust); | 228 flow.CreateAssemblyProgramFromDisassembler(flow.OLD, adjust); // 2 |
229 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.OLD); // 3 | |
230 flow.DestroyDisassembler(flow.OLD); | |
231 flow.WriteSinkStreamSetFromEncodedProgram(flow.OLD); // 4 | |
232 flow.DestroyEncodedProgram(flow.OLD); | |
233 flow.ReadDisassemblerFromBuffer(flow.NEW, new_buffer); // 5 | |
234 flow.CreateAssemblyProgramFromDisassembler(flow.NEW, adjust); // 6 | |
207 if (adjust) | 235 if (adjust) |
208 flow.AdjustNewAssemblyProgramToMatchOld(); | 236 flow.AdjustNewAssemblyProgramToMatchOld(); // 7, optional |
209 flow.CreateEncodedProgramFromAssemblyProgram(flow.OLD); | |
210 flow.DestroyAssemblyProgram(flow.OLD); | 237 flow.DestroyAssemblyProgram(flow.OLD); |
211 flow.CreateEncodedProgramFromAssemblyProgram(flow.NEW); | 238 flow.CreateEncodedProgramFromDisassemblerAndAssemblyProgram(flow.NEW); // 8 |
212 flow.DestroyAssemblyProgram(flow.NEW); | 239 flow.DestroyAssemblyProgram(flow.NEW); |
213 flow.WriteSinkStreamSetFromEncodedProgram(flow.OLD); | 240 flow.DestroyDisassembler(flow.NEW); |
214 flow.DestroyEncodedProgram(flow.OLD); | 241 flow.WriteSinkStreamSetFromEncodedProgram(flow.NEW); // 9 |
215 flow.WriteSinkStreamSetFromEncodedProgram(flow.NEW); | |
216 flow.DestroyEncodedProgram(flow.NEW); | 242 flow.DestroyEncodedProgram(flow.NEW); |
217 if (flow.failed()) | 243 if (flow.failed()) |
218 Problem(flow.message().c_str()); | 244 Problem(flow.message().c_str()); |
219 | 245 |
220 courgette::SinkStream empty_sink; | 246 courgette::SinkStream empty_sink; |
221 for (int i = 0; ; ++i) { | 247 for (int i = 0; ; ++i) { |
222 courgette::SinkStream* old_stream = flow.data(flow.OLD)->sinks.stream(i); | 248 courgette::SinkStream* old_stream = flow.data(flow.OLD)->sinks.stream(i); |
223 courgette::SinkStream* new_stream = flow.data(flow.NEW)->sinks.stream(i); | 249 courgette::SinkStream* new_stream = flow.data(flow.NEW)->sinks.stream(i); |
224 if (old_stream == NULL && new_stream == NULL) | 250 if (old_stream == NULL && new_stream == NULL) |
225 break; | 251 break; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 UsageProblem(kUsageGen1); | 485 UsageProblem(kUsageGen1); |
460 DisassembleAdjustDiff(values[0], values[1], values[2], | 486 DisassembleAdjustDiff(values[0], values[1], values[2], |
461 cmd_spread_1_adjusted); | 487 cmd_spread_1_adjusted); |
462 } else { | 488 } else { |
463 UsageProblem("No operation specified"); | 489 UsageProblem("No operation specified"); |
464 } | 490 } |
465 } | 491 } |
466 | 492 |
467 return 0; | 493 return 0; |
468 } | 494 } |
OLD | NEW |