ROSE  0.11.2.0
Config.h
1 #ifndef ROSE_Partitioner2_Config_H
2 #define ROSE_Partitioner2_Config_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <FileSystem.h>
8 #include <Partitioner2/Function.h>
9 #include <Sawyer/Map.h>
10 #include <Sawyer/Optional.h>
11 #include <SourceLocation.h>
12 #include <set>
13 #include <string>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace Partitioner2 {
18 
21  rose_addr_t address_;
22  std::string comment_;
23  Sawyer::Optional<rose_addr_t> finalInsnVa_;
24  std::set<rose_addr_t> successorVas_;
25  SourceLocation sourceLocation_;
26 
27 public:
28  // default constructor needed by some STL containers
29  BasicBlockConfig(): address_(0) {}
30 
32  explicit BasicBlockConfig(rose_addr_t va): address_(va) {}
33 
37  rose_addr_t address() const { return address_; }
38 
44  const std::string& comment() const { return comment_; }
45  BasicBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
51  const SourceLocation& sourceLocation() const { return sourceLocation_; }
52  BasicBlockConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
62  Sawyer::Optional<rose_addr_t> finalInstructionVa() const { return finalInsnVa_; }
63  BasicBlockConfig& finalInstructionVa(const Sawyer::Optional<rose_addr_t> &va) { finalInsnVa_ = va; return *this; }
73  const std::set<rose_addr_t>& successorVas() const { return successorVas_; }
74  std::set<rose_addr_t>& successorVas() { return successorVas_; }
75  BasicBlockConfig& successorVas(const std::set<rose_addr_t> &vas) { successorVas_ = vas; return *this; }
76  BasicBlockConfig& insertSuccessorVa(rose_addr_t va) { successorVas_.insert(va); return *this; }
77  BasicBlockConfig& clearSuccessorVas() { successorVas_.clear(); return *this; }
79 };
80 
81 
84  rose_addr_t address_;
85  std::string name_;
86  std::string comment_;
87  SourceLocation sourceLocation_;
88 
89 public:
90  // Default constructor needed by some STL containers
91  DataBlockConfig(): address_(0) {}
92 
94  explicit DataBlockConfig(rose_addr_t va): address_(va) {}
95 
99  rose_addr_t address() const { return address_; }
100 
106  const std::string &name() const { return name_; }
107  DataBlockConfig& name(const std::string &s) { name_ = s; return *this; }
115  const std::string& comment() const { return comment_; }
116  DataBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
122  const SourceLocation& sourceLocation() const { return sourceLocation_; }
123  DataBlockConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
125 };
126 
127 
131  std::string name_, defaultName_, comment_;
132  Sawyer::Optional<int64_t> stackDelta_;
133  Sawyer::Optional<bool> mayReturn_;
134  SourceLocation sourceLocation_;
135 
136 public:
137  // default constructor needed by some STL containers
138  FunctionConfig() {}
139 
143  explicit FunctionConfig(rose_addr_t va, const std::string &name=""): address_(va), name_(name) {}
144  explicit FunctionConfig(const std::string &name): name_(name) {}
145  FunctionConfig(const Sawyer::Optional<rose_addr_t> &va, const std::string &name): address_(va), name_(name) {}
163  Sawyer::Optional<rose_addr_t> address() const { return address_; }
164 
173  const std::string& name() const { return name_; }
174  FunctionConfig& name(const std::string &s);
182  const std::string& defaultName() const { return defaultName_; }
183  FunctionConfig& defaultName(const std::string &s) { defaultName_ = s; return *this; }
191  const std::string& comment() const { return comment_; }
192  FunctionConfig& comment(const std::string &s) { comment_ = s; return *this; }
198  const SourceLocation& sourceLocation() const { return sourceLocation_; }
199  FunctionConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
217  Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
218  FunctionConfig& stackDelta(const Sawyer::Optional<int64_t> &n) { stackDelta_ = n; return *this; }
232  Sawyer::Optional<bool> mayReturn() const { return mayReturn_; }
233  FunctionConfig& mayReturn(const Sawyer::Optional<bool> &b) { mayReturn_ = b; return *this; }
235 };
236 
241  rose_addr_t address_;
242  std::string name_;
243  std::string comment_;
244  SourceLocation sourceLocation_;
245 
246 public:
247  // Default constructor needed by STL containers
248  AddressConfig() {}
249 
251  explicit AddressConfig(rose_addr_t va)
252  : address_(va) {}
253 
257  rose_addr_t address() const { return address_; }
258 
262  const std::string &name() const { return name_; }
263  AddressConfig& name(const std::string &s) { name_ = s; return *this; }
269  const std::string &comment() const { return comment_; }
270  AddressConfig& comment(const std::string &s) { comment_ = s; return *this; }
276  const SourceLocation& sourceLocation() const { return sourceLocation_; }
277  AddressConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
279 };
280 
283 public:
289 
290 private:
291  BasicBlockConfigs bblockConfigs_;
292  DataBlockConfigs dblockConfigs_;
293  FunctionConfigsByAddress functionConfigsByAddress_;
294  FunctionConfigsByName functionConfigsByName_;
295  AddressConfigs addressConfigs_;
296 
297 public:
299  static std::string fileFormatDoc();
300 
302  void loadFromFile(const FileSystem::Path &fileName);
303 
307  const BasicBlockConfigs& basicBlocks() const { return bblockConfigs_; }
308  BasicBlockConfigs& basicBlocks() { return bblockConfigs_; }
315  const BasicBlockConfig& basicBlock(rose_addr_t) const;
316 
320  const DataBlockConfigs& dataBlocks() const { return dblockConfigs_; }
321  DataBlockConfigs& dataBlocks() { return dblockConfigs_; }
328  const DataBlockConfig& dataBlock(rose_addr_t) const;
329 
333  const FunctionConfigsByAddress& functionConfigsByAddress() const { return functionConfigsByAddress_; }
334  FunctionConfigsByAddress& functionConfigsByAddress() { return functionConfigsByAddress_; }
340  const FunctionConfigsByName& functionConfigsByName() const { return functionConfigsByName_; }
341  FunctionConfigsByName& functionConfigsByName() { return functionConfigsByName_; }
350  const FunctionConfig& function(rose_addr_t) const;
351  const FunctionConfig& function(const std::string &name) const;
357  const AddressConfigs& addresses() const { return addressConfigs_; }
358  AddressConfigs& addresses() { return addressConfigs_; }
364  const AddressConfig& address(rose_addr_t) const;
365 
369  BasicBlockConfig& insertMaybeBasicBlock(rose_addr_t va);
370 
374  DataBlockConfig& insertMaybeDataBlock(rose_addr_t va);
375 
381  FunctionConfig& insertMaybeFunction(rose_addr_t va, const std::string &name="");
382  FunctionConfig& insertMaybeFunction(const std::string &name);
388  AddressConfig& insertMaybeAddress(rose_addr_t va);
389 
395 
401 
406  bool insertConfiguration(const FunctionConfig&);
407 
412  bool insertConfiguration(const AddressConfig&);
413 
419  std::string basicBlockComment(rose_addr_t bblockVa) const;
420 
426 
431  std::set<rose_addr_t> basicBlockSuccessorVas(rose_addr_t bblockVa) const;
432 
436  std::string dataBlockName(rose_addr_t dblockVa) const;
437 
443  std::string dataBlockComment(rose_addr_t dblockVa) const;
444 
450  std::string functionName(rose_addr_t functionVa) const;
451 
457  std::string functionDefaultName(rose_addr_t functionVa) const;
458 
468  std::string functionComment(rose_addr_t functionVa) const;
469  std::string functionComment(const std::string &functionName) const;
470  std::string functionComment(const Function::Ptr&) const;
480  Sawyer::Optional<int64_t> functionStackDelta(rose_addr_t functionVa) const;
496  Sawyer::Optional<bool> functionMayReturn(rose_addr_t functionVa) const;
497  Sawyer::Optional<bool> functionMayReturn(const std::string &functionName) const;
506  std::string addressComment(rose_addr_t va) const;
507 
513  std::string comment(rose_addr_t va) const;
514 
516  void print(std::ostream&) const;
517 };
518 
519 } // namespace
520 } // namespace
521 } // namespace
522 
523 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::Partitioner2::Configuration&);
524 
525 #endif
526 #endif
FunctionConfig(const std::string &name)
Configuration information for a function.
Definition: Config.h:144
const DataBlockConfig & dataBlock(rose_addr_t) const
Configuration for a particular data block.
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:63
DataBlockConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:116
std::string functionComment(rose_addr_t functionVa) const
Function comment.
DataBlockConfig & sourceLocation(const SourceLocation &loc)
Property: Location of data block in source code.
Definition: Config.h:123
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:74
DataBlockConfig & insertMaybeDataBlock(rose_addr_t va)
Lookup or insert a data block.
std::string addressComment(rose_addr_t va) const
Address comment.
Information about a source location.
boost::filesystem::path Path
Name of entities in a filesystem.
Definition: FileSystem.h:18
static std::string fileFormatDoc()
Documentation string describing the file format.
Configuration information for a basic block.
Definition: Config.h:20
DataBlockConfig(rose_addr_t va)
Configuration information for a data block.
Definition: Config.h:94
const std::set< rose_addr_t > & successorVas() const
Property: control flow successors.
Definition: Config.h:73
const BasicBlockConfig & basicBlock(rose_addr_t) const
Configuration for a particular basic block.
void loadFromFile(const FileSystem::Path &fileName)
Loads configuration from a file.
DataBlockConfigs & dataBlocks()
All data block configuration details.
Definition: Config.h:321
FunctionConfig & sourceLocation(const SourceLocation &loc)
Property: Location of function in source code.
Definition: Config.h:199
BasicBlockConfig & insertSuccessorVa(rose_addr_t va)
Property: control flow successors.
Definition: Config.h:76
std::string dataBlockComment(rose_addr_t dblockVa) const
Data block comment.
std::string comment(rose_addr_t va) const
Address comment.
rose_addr_t address() const
Property: address.
Definition: Config.h:257
BasicBlockConfig & clearSuccessorVas()
Property: control flow successors.
Definition: Config.h:77
Sawyer::Optional< int64_t > stackDelta() const
Property: stack delta.
Definition: Config.h:217
Main namespace for the ROSE library.
FunctionConfig & insertMaybeFunction(rose_addr_t va, const std::string &name="")
Lookup or insert a function.
const std::string & comment() const
Property: comment string.
Definition: Config.h:269
const std::string & defaultName() const
Property: default name.
Definition: Config.h:182
FunctionConfig(rose_addr_t va, const std::string &name="")
Configuration information for a function.
Definition: Config.h:143
const std::string & comment() const
Property: comment.
Definition: Config.h:115
const FunctionConfigsByAddress & functionConfigsByAddress() const
All function configuration details for function configs that have addresses.
Definition: Config.h:333
bool insertConfiguration(const BasicBlockConfig &)
Insert basic block configuration information.
AddressConfig(rose_addr_t va)
Construct a new address configuration object.
Definition: Config.h:251
DataBlockConfig & name(const std::string &s)
Property: name.
Definition: Config.h:107
BasicBlockConfig & successorVas(const std::set< rose_addr_t > &vas)
Property: control flow successors.
Definition: Config.h:75
const SourceLocation & sourceLocation() const
Property: location of basic block in source code.
Definition: Config.h:51
std::string dataBlockName(rose_addr_t dblockVa) const
Data block name.
Sawyer::Optional< bool > mayReturn() const
Property: may-return.
Definition: Config.h:232
const AddressConfigs & addresses() const
All address configuration details.
Definition: Config.h:357
const SourceLocation & sourceLocation() const
Property: Location of address within source code.
Definition: Config.h:276
const std::string & comment() const
Property: comment.
Definition: Config.h:44
AddressConfigs & addresses()
All address configuration details.
Definition: Config.h:358
FunctionConfig & stackDelta(const Sawyer::Optional< int64_t > &n)
Property: stack delta.
Definition: Config.h:218
const BasicBlockConfigs & basicBlocks() const
All basic block configuration details.
Definition: Config.h:307
std::string functionName(rose_addr_t functionVa) const
Function name.
const AddressConfig & address(rose_addr_t) const
Configuration for a particular address.
BasicBlockConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:45
FunctionConfigsByAddress & functionConfigsByAddress()
All function configuration details for function configs that have addresses.
Definition: Config.h:334
Sawyer::Optional< rose_addr_t > finalInstructionVa() const
Property: last instruction.
Definition: Config.h:62
const std::string & name() const
Property: name.
Definition: Config.h:173
const std::string & comment() const
Property: comment.
Definition: Config.h:191
void print(std::ostream &) const
Generate a YAML file.
Sawyer::Optional< rose_addr_t > address() const
Property: address.
Definition: Config.h:163
FunctionConfig(const Sawyer::Optional< rose_addr_t > &va, const std::string &name)
Configuration information for a function.
Definition: Config.h:145
AddressConfig & insertMaybeAddress(rose_addr_t va)
Lookup or insert address details.
const FunctionConfigsByName & functionConfigsByName() const
All function configuration details for configs that have no address.
Definition: Config.h:340
BasicBlockConfigs & basicBlocks()
All basic block configuration details.
Definition: Config.h:308
AddressConfig & sourceLocation(const SourceLocation &loc)
Property: Location of address within source code.
Definition: Config.h:277
const SourceLocation & sourceLocation() const
Property: Location of function in source code.
Definition: Config.h:198
const std::string & name() const
Property: name.
Definition: Config.h:106
BasicBlockConfig & sourceLocation(const SourceLocation &loc)
Property: location of basic block in source code.
Definition: Config.h:52
BasicBlockConfig & insertMaybeBasicBlock(rose_addr_t va)
Lookup or insert a basic block.
const SourceLocation & sourceLocation() const
Property: Location of data block in source code.
Definition: Config.h:122
AddressConfig & comment(const std::string &s)
Property: comment string.
Definition: Config.h:270
rose_addr_t address() const
Property: starting address.
Definition: Config.h:99
Configuration for individual addresses.
Definition: Config.h:240
std::string functionDefaultName(rose_addr_t functionVa) const
Function default name.
FunctionConfig & mayReturn(const Sawyer::Optional< bool > &b)
Property: may-return.
Definition: Config.h:233
FunctionConfigsByName & functionConfigsByName()
All function configuration details for configs that have no address.
Definition: Config.h:341
Configuration information for a function.
Definition: Config.h:129
AddressConfig & name(const std::string &s)
Property: name.
Definition: Config.h:263
FunctionConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:192
std::set< rose_addr_t > basicBlockSuccessorVas(rose_addr_t bblockVa) const
Basic block successor addresses.
Configuration information for a data block.
Definition: Config.h:83
BasicBlockConfig(rose_addr_t va)
Configuration information for a basic block.
Definition: Config.h:32
FunctionConfig & defaultName(const std::string &s)
Property: default name.
Definition: Config.h:183
const std::string & name() const
Property: name.
Definition: Config.h:262
rose_addr_t address() const
Property: starting address.
Definition: Config.h:37
Holds configuration information.
Definition: Config.h:282
const DataBlockConfigs & dataBlocks() const
All data block configuration details.
Definition: Config.h:320