1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_REORDER_REORDER_APP_H_
16 : #define SYZYGY_REORDER_REORDER_APP_H_
17 :
18 : #include <memory>
19 :
20 : #include "base/command_line.h"
21 : #include "base/files/file_path.h"
22 : #include "base/strings/string_piece.h"
23 : #include "base/time/time.h"
24 : #include "syzygy/application/application.h"
25 : #include "syzygy/pe/image_layout.h"
26 : #include "syzygy/pe/pe_file.h"
27 : #include "syzygy/reorder/reorderer.h"
28 :
29 m : namespace reorder {
30 :
31 : // This class implements the command-line reorder utility.
32 m : class ReorderApp : public application::AppImplBase {
33 m : public:
34 m : ReorderApp();
35 :
36 : // @name Implementation of the AppImplBase interface.
37 : // @{
38 m : bool ParseCommandLine(const base::CommandLine* command_line);
39 m : bool SetUp();
40 m : int Run();
41 : // @}
42 :
43 m : protected:
44 m : typedef std::vector<base::FilePath> FilePathVector;
45 :
46 m : enum Mode {
47 m : kInvalidMode,
48 m : kLinearOrderMode,
49 m : kRandomOrderMode,
50 m : kDeadCodeFinderMode
51 m : };
52 : // @name Utility members.
53 : // @{
54 m : bool Usage(const base::CommandLine* command_line,
55 m : const base::StringPiece& message) const;
56 m : bool OptimizeBasicBlocks(const pe::PEFile::Signature& signature,
57 m : const pe::ImageLayout& image_layout,
58 m : Reorderer::Order* order);
59 : // @}
60 :
61 m : Mode mode_;
62 m : std::unique_ptr<Reorderer::OrderGenerator> order_generator_;
63 :
64 : // @name Command-line parameters.
65 : // @{
66 m : base::FilePath instrumented_image_path_;
67 m : base::FilePath input_image_path_;
68 m : base::FilePath output_file_path_;
69 m : base::FilePath bb_entry_count_file_path_;
70 m : FilePathVector trace_file_paths_;
71 m : uint32_t seed_;
72 m : bool pretty_print_;
73 m : Reorderer::Flags flags_;
74 : // @}
75 :
76 : // Command-line parameter names. Exposed as protected for unit-testing.
77 : // @{
78 m : static const char kInstrumentedImage[];
79 m : static const char kOutputFile[];
80 m : static const char kInputImage[];
81 m : static const char kBasicBlockEntryCounts[];
82 m : static const char kSeed[];
83 m : static const char kListDeadCode[];
84 m : static const char kPrettyPrint[];
85 m : static const char kReordererFlags[];
86 m : static const char kInstrumentedDll[];
87 m : static const char kInputDll[];
88 : // @}
89 m : private:
90 m : DISALLOW_COPY_AND_ASSIGN(ReorderApp);
91 m : };
92 :
93 m : } // namespace reorder
94 :
95 : #endif // SYZYGY_REORDER_REORDER_APP_H_
|