ROSE  0.9.9.139
Config.h
1 #ifndef ROSE_Partitioner2_Config_H
2 #define ROSE_Partitioner2_Config_H
3 
4 #include <FileSystem.h>
5 #include <Partitioner2/Function.h>
6 #include <Sawyer/Map.h>
7 #include <Sawyer/Optional.h>
8 #include <set>
9 #include <string>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 namespace Partitioner2 {
14 
17  rose_addr_t address_;
18  std::string comment_;
19  Sawyer::Optional<rose_addr_t> finalInsnVa_;
20  std::set<rose_addr_t> successorVas_;
21 
22 public:
23  // default constructor needed by some STL containers
24  BasicBlockConfig(): address_(0) {}
25 
27  explicit BasicBlockConfig(rose_addr_t va): address_(va) {}
28 
32  rose_addr_t address() const { return address_; }
33 
39  const std::string& comment() const { return comment_; }
40  BasicBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
50  Sawyer::Optional<rose_addr_t> finalInstructionVa() const { return finalInsnVa_; }
51  BasicBlockConfig& finalInstructionVa(const Sawyer::Optional<rose_addr_t> &va) { finalInsnVa_ = va; return *this; }
61  const std::set<rose_addr_t>& successorVas() const { return successorVas_; }
62  std::set<rose_addr_t>& successorVas() { return successorVas_; }
63  BasicBlockConfig& successorVas(const std::set<rose_addr_t> &vas) { successorVas_ = vas; return *this; }
64  BasicBlockConfig& insertSuccessorVa(rose_addr_t va) { successorVas_.insert(va); return *this; }
65  BasicBlockConfig& clearSuccessorVas() { successorVas_.clear(); return *this; }
67 };
68 
69 
72  rose_addr_t address_;
73  std::string name_;
74  std::string comment_;
75 
76 public:
77  // Default constructor needed by some STL containers
78  DataBlockConfig(): address_(0) {}
79 
81  explicit DataBlockConfig(rose_addr_t va): address_(va) {}
82 
86  rose_addr_t address() const { return address_; }
87 
93  const std::string &name() const { return name_; }
94  DataBlockConfig& name(const std::string &s) { name_ = s; return *this; }
102  const std::string& comment() const { return comment_; }
103  DataBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
105 };
106 
107 
111  std::string name_, defaultName_, comment_;
112  Sawyer::Optional<int64_t> stackDelta_;
113  Sawyer::Optional<bool> mayReturn_;
114 
115 public:
116  // default constructor needed by some STL containers
117  FunctionConfig() {}
118 
122  explicit FunctionConfig(rose_addr_t va, const std::string &name=""): address_(va), name_(name) {}
123  explicit FunctionConfig(const std::string &name): name_(name) {}
124  FunctionConfig(const Sawyer::Optional<rose_addr_t> &va, const std::string &name): address_(va), name_(name) {}
142  Sawyer::Optional<rose_addr_t> address() const { return address_; }
143 
152  const std::string& name() const { return name_; }
153  FunctionConfig& name(const std::string &s);
161  const std::string& defaultName() const { return defaultName_; }
162  FunctionConfig& defaultName(const std::string &s) { defaultName_ = s; return *this; }
170  const std::string& comment() const { return comment_; }
171  FunctionConfig& comment(const std::string &s) { comment_ = s; return *this; }
189  Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
190  FunctionConfig& stackDelta(const Sawyer::Optional<int64_t> &n) { stackDelta_ = n; return *this; }
204  Sawyer::Optional<bool> mayReturn() const { return mayReturn_; }
205  FunctionConfig& mayReturn(const Sawyer::Optional<bool> &b) { mayReturn_ = b; return *this; }
207 };
208 
211 public:
216 
217 private:
218  BasicBlockConfigs bblockConfigs_;
219  DataBlockConfigs dblockConfigs_;
220  FunctionConfigsByAddress functionConfigsByAddress_;
221  FunctionConfigsByName functionConfigsByName_;
222 
223 public:
225  void loadFromFile(const FileSystem::Path &fileName);
226 
230  const BasicBlockConfigs& basicBlocks() const { return bblockConfigs_; }
231  BasicBlockConfigs& basicBlocks() { return bblockConfigs_; }
237  const DataBlockConfigs& dataBlocks() const { return dblockConfigs_; }
238  DataBlockConfigs& dataBlocks() { return dblockConfigs_; }
244  const FunctionConfigsByAddress& functionConfigsByAddress() const { return functionConfigsByAddress_; }
245  FunctionConfigsByAddress& functionConfigsByAddress() { return functionConfigsByAddress_; }
251  const FunctionConfigsByName& functionConfigsByName() const { return functionConfigsByName_; }
252  FunctionConfigsByName& functionConfigsByName() { return functionConfigsByName_; }
258  BasicBlockConfig& insertMaybeBasicBlock(rose_addr_t va);
259 
263  DataBlockConfig& insertMaybeDataBlock(rose_addr_t va);
264 
270  FunctionConfig& insertMaybeFunction(rose_addr_t va, const std::string &name="");
271  FunctionConfig& insertMaybeFunction(const std::string &name);
279 
285 
290  bool insertConfiguration(const FunctionConfig&);
291 
295  std::string basicBlockComment(rose_addr_t bblockVa) const;
296 
302 
307  std::set<rose_addr_t> basicBlockSuccessorVas(rose_addr_t bblockVa) const;
308 
312  std::string dataBlockName(rose_addr_t dblockVa) const;
313 
317  std::string dataBlockComment(rose_addr_t dblockVa) const;
318 
324  std::string functionName(rose_addr_t functionVa) const;
325 
331  std::string functionDefaultName(rose_addr_t functionVa) const;
332 
340  std::string functionComment(rose_addr_t functionVa) const;
341  std::string functionComment(const std::string &functionName) const;
342  std::string functionComment(const Function::Ptr&) const;
352  Sawyer::Optional<int64_t> functionStackDelta(rose_addr_t functionVa) const;
368  Sawyer::Optional<bool> functionMayReturn(rose_addr_t functionVa) const;
369  Sawyer::Optional<bool> functionMayReturn(const std::string &functionName) const;
374  void print(std::ostream&) const;
375 };
376 
377 } // namespace
378 } // namespace
379 } // namespace
380 
381 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::Partitioner2::Configuration&);
382 
383 #endif
FunctionConfig(const std::string &name)
Configuration information for a function.
Definition: Config.h:123
std::string basicBlockComment(rose_addr_t bblockVa) const
Basic block comment.
Sawyer::Optional< int64_t > functionStackDelta(rose_addr_t functionVa) const
Function stack delta.
Sawyer::Optional< bool > functionMayReturn(rose_addr_t functionVa) const
Function may-return status.
BasicBlockConfig & finalInstructionVa(const Sawyer::Optional< rose_addr_t > &va)
Property: last instruction.
Definition: Config.h:51
DataBlockConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:103
std::string functionComment(rose_addr_t functionVa) const
Function comment.
Sawyer::Optional< rose_addr_t > basicBlockFinalInstructionVa(rose_addr_t bblockVa) const
Basic block final instruction address.
std::set< rose_addr_t > & successorVas()
Property: control flow successors.
Definition: Config.h:62
DataBlockConfig & insertMaybeDataBlock(rose_addr_t va)
Lookup or insert a data block.
boost::filesystem::path Path
Name of entities in a filesystem.
Definition: FileSystem.h:18
Configuration information for a basic block.
Definition: Config.h:16
DataBlockConfig(rose_addr_t va)
Configuration information for a data block.
Definition: Config.h:81
const std::set< rose_addr_t > & successorVas() const
Property: control flow successors.
Definition: Config.h:61
void loadFromFile(const FileSystem::Path &fileName)
Loads configuration from a file.
DataBlockConfigs & dataBlocks()
All data block configuration details.
Definition: Config.h:238
BasicBlockConfig & insertSuccessorVa(rose_addr_t va)
Property: control flow successors.
Definition: Config.h:64
std::string dataBlockComment(rose_addr_t dblockVa) const
Data block comment.
BasicBlockConfig & clearSuccessorVas()
Property: control flow successors.
Definition: Config.h:65
Sawyer::Optional< int64_t > stackDelta() const
Property: stack delta.
Definition: Config.h:189
Main namespace for the ROSE library.
FunctionConfig & insertMaybeFunction(rose_addr_t va, const std::string &name="")
Lookup or insert a function.
const std::string & defaultName() const
Property: default name.
Definition: Config.h:161
FunctionConfig(rose_addr_t va, const std::string &name="")
Configuration information for a function.
Definition: Config.h:122
const std::string & comment() const
Property: comment.
Definition: Config.h:102
const FunctionConfigsByAddress & functionConfigsByAddress() const
All function configuration details for function configs that have addresses.
Definition: Config.h:244
bool insertConfiguration(const BasicBlockConfig &)
Insert basic block configuration information.
DataBlockConfig & name(const std::string &s)
Property: name.
Definition: Config.h:94
BasicBlockConfig & successorVas(const std::set< rose_addr_t > &vas)
Property: control flow successors.
Definition: Config.h:63
std::string dataBlockName(rose_addr_t dblockVa) const
Data block name.
Sawyer::Optional< bool > mayReturn() const
Property may-return.
Definition: Config.h:204
const std::string & comment() const
Property: comment.
Definition: Config.h:39
FunctionConfig & stackDelta(const Sawyer::Optional< int64_t > &n)
Property: stack delta.
Definition: Config.h:190
const BasicBlockConfigs & basicBlocks() const
All basic block configuration details.
Definition: Config.h:230
std::string functionName(rose_addr_t functionVa) const
Function name.
BasicBlockConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:40
FunctionConfigsByAddress & functionConfigsByAddress()
All function configuration details for function configs that have addresses.
Definition: Config.h:245
Sawyer::Optional< rose_addr_t > finalInstructionVa() const
Property: last instruction.
Definition: Config.h:50
const std::string & name() const
Property: name.
Definition: Config.h:152
const std::string & comment() const
Property: comment.
Definition: Config.h:170
void print(std::ostream &) const
Generate a YAML file.
Sawyer::Optional< rose_addr_t > address() const
Property: address.
Definition: Config.h:142
FunctionConfig(const Sawyer::Optional< rose_addr_t > &va, const std::string &name)
Configuration information for a function.
Definition: Config.h:124
const FunctionConfigsByName & functionConfigsByName() const
All function configuration details for configs that have no address.
Definition: Config.h:251
BasicBlockConfigs & basicBlocks()
All basic block configuration details.
Definition: Config.h:231
const std::string & name() const
Property: name.
Definition: Config.h:93
BasicBlockConfig & insertMaybeBasicBlock(rose_addr_t va)
Lookup or insert a basic block.
rose_addr_t address() const
Property: starting address.
Definition: Config.h:86
std::string functionDefaultName(rose_addr_t functionVa) const
Function default name.
FunctionConfig & mayReturn(const Sawyer::Optional< bool > &b)
Property may-return.
Definition: Config.h:205
FunctionConfigsByName & functionConfigsByName()
All function configuration details for configs that have no address.
Definition: Config.h:252
Configuration information for a function.
Definition: Config.h:109
FunctionConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:171
std::set< rose_addr_t > basicBlockSuccessorVas(rose_addr_t bblockVa) const
Basic block successor addresses.
Configuration information for a data block.
Definition: Config.h:71
BasicBlockConfig(rose_addr_t va)
Configuration information for a basic block.
Definition: Config.h:27
FunctionConfig & defaultName(const std::string &s)
Property: default name.
Definition: Config.h:162
rose_addr_t address() const
Property: starting address.
Definition: Config.h:32
Holds configuration information.
Definition: Config.h:210
const DataBlockConfigs & dataBlocks() const
All data block configuration details.
Definition: Config.h:237