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 "base/command_line.h"
19 : #include "base/files/file_path.h"
20 : #include "base/memory/scoped_ptr.h"
21 : #include "base/strings/string_piece.h"
22 : #include "base/time/time.h"
23 : #include "syzygy/application/application.h"
24 : #include "syzygy/pe/image_layout.h"
25 : #include "syzygy/pe/pe_file.h"
26 : #include "syzygy/reorder/reorderer.h"
27 :
28 m : namespace reorder {
29 :
30 : // This class implements the command-line reorder utility.
31 m : class ReorderApp : public application::AppImplBase {
32 m : public:
33 m : ReorderApp();
34 :
35 : // @name Implementation of the AppImplBase interface.
36 : // @{
37 m : bool ParseCommandLine(const base::CommandLine* command_line);
38 m : bool SetUp();
39 m : int Run();
40 : // @}
41 :
42 m : protected:
43 m : typedef std::vector<base::FilePath> FilePathVector;
44 :
45 m : enum Mode {
46 m : kInvalidMode,
47 m : kLinearOrderMode,
48 m : kRandomOrderMode,
49 m : kDeadCodeFinderMode
50 m : };
51 : // @name Utility members.
52 : // @{
53 m : bool Usage(const base::CommandLine* command_line,
54 m : const base::StringPiece& message) const;
55 m : bool OptimizeBasicBlocks(const pe::PEFile::Signature& signature,
56 m : const pe::ImageLayout& image_layout,
57 m : Reorderer::Order* order);
58 : // @}
59 :
60 m : Mode mode_;
61 m : scoped_ptr<Reorderer::OrderGenerator> order_generator_;
62 :
63 : // @name Command-line parameters.
64 : // @{
65 m : base::FilePath instrumented_image_path_;
66 m : base::FilePath input_image_path_;
67 m : base::FilePath output_file_path_;
68 m : base::FilePath bb_entry_count_file_path_;
69 m : FilePathVector trace_file_paths_;
70 m : uint32 seed_;
71 m : bool pretty_print_;
72 m : Reorderer::Flags flags_;
73 : // @}
74 :
75 : // Command-line parameter names. Exposed as protected for unit-testing.
76 : // @{
77 m : static const char kInstrumentedImage[];
78 m : static const char kOutputFile[];
79 m : static const char kInputImage[];
80 m : static const char kBasicBlockEntryCounts[];
81 m : static const char kSeed[];
82 m : static const char kListDeadCode[];
83 m : static const char kPrettyPrint[];
84 m : static const char kReordererFlags[];
85 m : static const char kInstrumentedDll[];
86 m : static const char kInputDll[];
87 : // @}
88 m : private:
89 m : DISALLOW_COPY_AND_ASSIGN(ReorderApp);
90 m : };
91 :
92 m : } // namespace reorder
93 :
94 : #endif // SYZYGY_REORDER_REORDER_APP_H_
|