ROSE  0.11.57.0
Config.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Config_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Config_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/FileSystem.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/Function.h>
8 #include <Sawyer/Map.h>
9 #include <Sawyer/Optional.h>
10 #include <Rose/SourceLocation.h>
11 #include <set>
12 #include <string>
13 
14 namespace Rose {
15 namespace BinaryAnalysis {
16 namespace Partitioner2 {
17 
20  rose_addr_t address_ = 0;
21  std::string comment_;
22  Sawyer::Optional<rose_addr_t> finalInsnVa_;
23  std::set<rose_addr_t> successorVas_;
24  SourceLocation sourceLocation_;
25 
26 public:
27  // default constructor needed by some STL containers
28  BasicBlockConfig() {}
29 
31  explicit BasicBlockConfig(rose_addr_t va): address_(va) {}
32 
36  rose_addr_t address() const { return address_; }
37 
43  const std::string& comment() const { return comment_; }
44  BasicBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
50  const SourceLocation& sourceLocation() const { return sourceLocation_; }
51  BasicBlockConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
61  Sawyer::Optional<rose_addr_t> finalInstructionVa() const { return finalInsnVa_; }
62  BasicBlockConfig& finalInstructionVa(const Sawyer::Optional<rose_addr_t> &va) { finalInsnVa_ = va; return *this; }
72  const std::set<rose_addr_t>& successorVas() const { return successorVas_; }
73  std::set<rose_addr_t>& successorVas() { return successorVas_; }
74  BasicBlockConfig& successorVas(const std::set<rose_addr_t> &vas) { successorVas_ = vas; return *this; }
75  BasicBlockConfig& insertSuccessorVa(rose_addr_t va) { successorVas_.insert(va); return *this; }
76  BasicBlockConfig& clearSuccessorVas() { successorVas_.clear(); return *this; }
78 };
79 
80 
83  rose_addr_t address_;
84  std::string name_;
85  std::string comment_;
86  SourceLocation sourceLocation_;
87 
88 public:
89  // Default constructor needed by some STL containers
90  DataBlockConfig(): address_(0) {}
91 
93  explicit DataBlockConfig(rose_addr_t va): address_(va) {}
94 
98  rose_addr_t address() const { return address_; }
99 
105  const std::string &name() const { return name_; }
106  DataBlockConfig& name(const std::string &s) { name_ = s; return *this; }
114  const std::string& comment() const { return comment_; }
115  DataBlockConfig& comment(const std::string &s) { comment_ = s; return *this; }
121  const SourceLocation& sourceLocation() const { return sourceLocation_; }
122  DataBlockConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
124 };
125 
126 
130  std::string name_, defaultName_, comment_;
131  Sawyer::Optional<int64_t> stackDelta_;
132  Sawyer::Optional<bool> mayReturn_;
133  SourceLocation sourceLocation_;
134 
135 public:
136  // default constructor needed by some STL containers
137  FunctionConfig() {}
138 
142  explicit FunctionConfig(rose_addr_t va, const std::string &name=""): address_(va), name_(name) {}
143  explicit FunctionConfig(const std::string &name): name_(name) {}
144  FunctionConfig(const Sawyer::Optional<rose_addr_t> &va, const std::string &name): address_(va), name_(name) {}
162  Sawyer::Optional<rose_addr_t> address() const { return address_; }
163 
172  const std::string& name() const { return name_; }
173  FunctionConfig& name(const std::string &s);
181  const std::string& defaultName() const { return defaultName_; }
182  FunctionConfig& defaultName(const std::string &s) { defaultName_ = s; return *this; }
190  const std::string& comment() const { return comment_; }
191  FunctionConfig& comment(const std::string &s) { comment_ = s; return *this; }
197  const SourceLocation& sourceLocation() const { return sourceLocation_; }
198  FunctionConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
216  Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
217  FunctionConfig& stackDelta(const Sawyer::Optional<int64_t> &n) { stackDelta_ = n; return *this; }
231  Sawyer::Optional<bool> mayReturn() const { return mayReturn_; }
232  FunctionConfig& mayReturn(const Sawyer::Optional<bool> &b) { mayReturn_ = b; return *this; }
234 };
235 
240  rose_addr_t address_ = 0;
241  std::string name_;
242  std::string comment_;
243  SourceLocation sourceLocation_;
244 
245 public:
246  // Default constructor needed by STL containers
247  AddressConfig() {}
248 
250  explicit AddressConfig(rose_addr_t va)
251  : address_(va) {}
252 
256  rose_addr_t address() const { return address_; }
257 
261  const std::string &name() const { return name_; }
262  AddressConfig& name(const std::string &s) { name_ = s; return *this; }
268  const std::string &comment() const { return comment_; }
269  AddressConfig& comment(const std::string &s) { comment_ = s; return *this; }
275  const SourceLocation& sourceLocation() const { return sourceLocation_; }
276  AddressConfig& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
278 };
279 
282 public:
288 
289 private:
290  BasicBlockConfigs bblockConfigs_;
291  DataBlockConfigs dblockConfigs_;
292  FunctionConfigsByAddress functionConfigsByAddress_;
293  FunctionConfigsByName functionConfigsByName_;
294  AddressConfigs addressConfigs_;
295 
296 public:
298  static std::string fileFormatDoc();
299 
301  void loadFromFile(const FileSystem::Path &fileName);
302 
306  const BasicBlockConfigs& basicBlocks() const { return bblockConfigs_; }
307  BasicBlockConfigs& basicBlocks() { return bblockConfigs_; }
314  const BasicBlockConfig& basicBlock(rose_addr_t) const;
315 
319  const DataBlockConfigs& dataBlocks() const { return dblockConfigs_; }
320  DataBlockConfigs& dataBlocks() { return dblockConfigs_; }
327  const DataBlockConfig& dataBlock(rose_addr_t) const;
328 
332  const FunctionConfigsByAddress& functionConfigsByAddress() const { return functionConfigsByAddress_; }
333  FunctionConfigsByAddress& functionConfigsByAddress() { return functionConfigsByAddress_; }
339  const FunctionConfigsByName& functionConfigsByName() const { return functionConfigsByName_; }
340  FunctionConfigsByName& functionConfigsByName() { return functionConfigsByName_; }
349  const FunctionConfig& function(rose_addr_t) const;
350  const FunctionConfig& function(const std::string &name) const;
356  const AddressConfigs& addresses() const { return addressConfigs_; }
357  AddressConfigs& addresses() { return addressConfigs_; }
363  const AddressConfig& address(rose_addr_t) const;
364 
368  BasicBlockConfig& insertMaybeBasicBlock(rose_addr_t va);
369 
373  DataBlockConfig& insertMaybeDataBlock(rose_addr_t va);
374 
380  FunctionConfig& insertMaybeFunction(rose_addr_t va, const std::string &name="");
381  FunctionConfig& insertMaybeFunction(const std::string &name);
387  AddressConfig& insertMaybeAddress(rose_addr_t va);
388 
394 
400 
405  bool insertConfiguration(const FunctionConfig&);
406 
411  bool insertConfiguration(const AddressConfig&);
412 
418  std::string basicBlockComment(rose_addr_t bblockVa) const;
419 
425 
430  std::set<rose_addr_t> basicBlockSuccessorVas(rose_addr_t bblockVa) const;
431 
435  std::string dataBlockName(rose_addr_t dblockVa) const;
436 
442  std::string dataBlockComment(rose_addr_t dblockVa) const;
443 
449  std::string functionName(rose_addr_t functionVa) const;
450 
456  std::string functionDefaultName(rose_addr_t functionVa) const;
457 
467  std::string functionComment(rose_addr_t functionVa) const;
468  std::string functionComment(const std::string &functionName) const;
469  std::string functionComment(const Function::Ptr&) const;
479  Sawyer::Optional<int64_t> functionStackDelta(rose_addr_t functionVa) const;
495  Sawyer::Optional<bool> functionMayReturn(rose_addr_t functionVa) const;
496  Sawyer::Optional<bool> functionMayReturn(const std::string &functionName) const;
505  std::string addressComment(rose_addr_t va) const;
506 
512  std::string comment(rose_addr_t va) const;
513 
515  void print(std::ostream&) const;
516 };
517 
518 } // namespace
519 } // namespace
520 } // namespace
521 
522 std::ostream& operator<<(std::ostream&, const Rose::BinaryAnalysis::Partitioner2::Configuration&);
523 
524 #endif
525 #endif
FunctionConfig(const std::string &name)
Configuration information for a function.
Definition: Config.h:143
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:62
DataBlockConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:115
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:122
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:73
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.
static std::string fileFormatDoc()
Documentation string describing the file format.
Configuration information for a basic block.
Definition: Config.h:19
DataBlockConfig(rose_addr_t va)
Configuration information for a data block.
Definition: Config.h:93
const std::set< rose_addr_t > & successorVas() const
Property: control flow successors.
Definition: Config.h:72
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:320
FunctionConfig & sourceLocation(const SourceLocation &loc)
Property: Location of function in source code.
Definition: Config.h:198
BasicBlockConfig & insertSuccessorVa(rose_addr_t va)
Property: control flow successors.
Definition: Config.h:75
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:256
BasicBlockConfig & clearSuccessorVas()
Property: control flow successors.
Definition: Config.h:76
Sawyer::Optional< int64_t > stackDelta() const
Property: stack delta.
Definition: Config.h:216
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:268
const std::string & defaultName() const
Property: default name.
Definition: Config.h:181
FunctionConfig(rose_addr_t va, const std::string &name="")
Configuration information for a function.
Definition: Config.h:142
const std::string & comment() const
Property: comment.
Definition: Config.h:114
const FunctionConfigsByAddress & functionConfigsByAddress() const
All function configuration details for function configs that have addresses.
Definition: Config.h:332
bool insertConfiguration(const BasicBlockConfig &)
Insert basic block configuration information.
AddressConfig(rose_addr_t va)
Construct a new address configuration object.
Definition: Config.h:250
DataBlockConfig & name(const std::string &s)
Property: name.
Definition: Config.h:106
BasicBlockConfig & successorVas(const std::set< rose_addr_t > &vas)
Property: control flow successors.
Definition: Config.h:74
const SourceLocation & sourceLocation() const
Property: location of basic block in source code.
Definition: Config.h:50
std::string dataBlockName(rose_addr_t dblockVa) const
Data block name.
Sawyer::Optional< bool > mayReturn() const
Property: may-return.
Definition: Config.h:231
const AddressConfigs & addresses() const
All address configuration details.
Definition: Config.h:356
const SourceLocation & sourceLocation() const
Property: Location of address within source code.
Definition: Config.h:275
const std::string & comment() const
Property: comment.
Definition: Config.h:43
AddressConfigs & addresses()
All address configuration details.
Definition: Config.h:357
FunctionConfig & stackDelta(const Sawyer::Optional< int64_t > &n)
Property: stack delta.
Definition: Config.h:217
const BasicBlockConfigs & basicBlocks() const
All basic block configuration details.
Definition: Config.h:306
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:44
FunctionConfigsByAddress & functionConfigsByAddress()
All function configuration details for function configs that have addresses.
Definition: Config.h:333
Sawyer::Optional< rose_addr_t > finalInstructionVa() const
Property: last instruction.
Definition: Config.h:61
const std::string & name() const
Property: name.
Definition: Config.h:172
const std::string & comment() const
Property: comment.
Definition: Config.h:190
void print(std::ostream &) const
Generate a YAML file.
Sawyer::Optional< rose_addr_t > address() const
Property: address.
Definition: Config.h:162
FunctionConfig(const Sawyer::Optional< rose_addr_t > &va, const std::string &name)
Configuration information for a function.
Definition: Config.h:144
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:339
BasicBlockConfigs & basicBlocks()
All basic block configuration details.
Definition: Config.h:307
AddressConfig & sourceLocation(const SourceLocation &loc)
Property: Location of address within source code.
Definition: Config.h:276
const SourceLocation & sourceLocation() const
Property: Location of function in source code.
Definition: Config.h:197
const std::string & name() const
Property: name.
Definition: Config.h:105
BasicBlockConfig & sourceLocation(const SourceLocation &loc)
Property: location of basic block in source code.
Definition: Config.h:51
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:121
AddressConfig & comment(const std::string &s)
Property: comment string.
Definition: Config.h:269
rose_addr_t address() const
Property: starting address.
Definition: Config.h:98
Configuration for individual addresses.
Definition: Config.h:239
std::string functionDefaultName(rose_addr_t functionVa) const
Function default name.
FunctionConfig & mayReturn(const Sawyer::Optional< bool > &b)
Property: may-return.
Definition: Config.h:232
FunctionConfigsByName & functionConfigsByName()
All function configuration details for configs that have no address.
Definition: Config.h:340
Configuration information for a function.
Definition: Config.h:128
AddressConfig & name(const std::string &s)
Property: name.
Definition: Config.h:262
FunctionConfig & comment(const std::string &s)
Property: comment.
Definition: Config.h:191
std::set< rose_addr_t > basicBlockSuccessorVas(rose_addr_t bblockVa) const
Basic block successor addresses.
Configuration information for a data block.
Definition: Config.h:82
BasicBlockConfig(rose_addr_t va)
Configuration information for a basic block.
Definition: Config.h:31
FunctionConfig & defaultName(const std::string &s)
Property: default name.
Definition: Config.h:182
const std::string & name() const
Property: name.
Definition: Config.h:261
rose_addr_t address() const
Property: starting address.
Definition: Config.h:36
Holds configuration information.
Definition: Config.h:281
const DataBlockConfigs & dataBlocks() const
All data block configuration details.
Definition: Config.h:319