ROSE  0.11.109.0
Configuration.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Configuration_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Configuration_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
29 
31  explicit BasicBlockConfiguration(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  BasicBlockConfiguration& comment(const std::string &s) { comment_ = s; return *this; }
50  const SourceLocation& sourceLocation() const { return sourceLocation_; }
51  BasicBlockConfiguration& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
61  Sawyer::Optional<rose_addr_t> finalInstructionVa() const { return finalInsnVa_; }
62  BasicBlockConfiguration& 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  BasicBlockConfiguration& successorVas(const std::set<rose_addr_t> &vas) { successorVas_ = vas; return *this; }
75  BasicBlockConfiguration& insertSuccessorVa(rose_addr_t va) { successorVas_.insert(va); return *this; }
76  BasicBlockConfiguration& 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  DataBlockConfiguration(): address_(0) {}
91 
93  explicit DataBlockConfiguration(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  DataBlockConfiguration& name(const std::string &s) { name_ = s; return *this; }
114  const std::string& comment() const { return comment_; }
115  DataBlockConfiguration& comment(const std::string &s) { comment_ = s; return *this; }
121  const SourceLocation& sourceLocation() const { return sourceLocation_; }
122  DataBlockConfiguration& 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
138 
142  explicit FunctionConfiguration(rose_addr_t va, const std::string &name=""): address_(va), name_(name) {}
143  explicit FunctionConfiguration(const std::string &name): name_(name) {}
144  FunctionConfiguration(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  FunctionConfiguration& name(const std::string &s);
181  const std::string& defaultName() const { return defaultName_; }
182  FunctionConfiguration& defaultName(const std::string &s) { defaultName_ = s; return *this; }
190  const std::string& comment() const { return comment_; }
191  FunctionConfiguration& comment(const std::string &s) { comment_ = s; return *this; }
197  const SourceLocation& sourceLocation() const { return sourceLocation_; }
198  FunctionConfiguration& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
216  Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
217  FunctionConfiguration& stackDelta(const Sawyer::Optional<int64_t> &n) { stackDelta_ = n; return *this; }
231  Sawyer::Optional<bool> mayReturn() const { return mayReturn_; }
232  FunctionConfiguration& 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
248 
250  explicit AddressConfiguration(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  AddressConfiguration& name(const std::string &s) { name_ = s; return *this; }
268  const std::string &comment() const { return comment_; }
269  AddressConfiguration& comment(const std::string &s) { comment_ = s; return *this; }
275  const SourceLocation& sourceLocation() const { return sourceLocation_; }
276  AddressConfiguration& sourceLocation(const SourceLocation &loc) { sourceLocation_ = loc; return *this; }
278 };
279 
282 public:
288 
289 private:
290  BasicBlockConfigurations bblockConfigurations_;
291  DataBlockConfigurations dblockConfigurations_;
292  FunctionConfigurationsByAddress functionConfigurationsByAddress_;
293  FunctionConfigurationsByName functionConfigurationsByName_;
294  AddressConfigurations addressConfigurations_;
295 
296 public:
298  static std::string fileFormatDoc();
299 
301  void loadFromFile(const FileSystem::Path &fileName);
302 
306  const BasicBlockConfigurations& basicBlocks() const { return bblockConfigurations_; }
307  BasicBlockConfigurations& basicBlocks() { return bblockConfigurations_; }
314  const BasicBlockConfiguration& basicBlock(rose_addr_t) const;
315 
319  const DataBlockConfigurations& dataBlocks() const { return dblockConfigurations_; }
320  DataBlockConfigurations& dataBlocks() { return dblockConfigurations_; }
327  const DataBlockConfiguration& dataBlock(rose_addr_t) const;
328 
332  const FunctionConfigurationsByAddress& functionConfigurationsByAddress() const { return functionConfigurationsByAddress_; }
333  FunctionConfigurationsByAddress& functionConfigurationsByAddress() { return functionConfigurationsByAddress_; }
339  const FunctionConfigurationsByName& functionConfigurationsByName() const { return functionConfigurationsByName_; }
340  FunctionConfigurationsByName& functionConfigurationsByName() { return functionConfigurationsByName_; }
349  const FunctionConfiguration& function(rose_addr_t) const;
350  const FunctionConfiguration& function(const std::string &name) const;
356  const AddressConfigurations& addresses() const { return addressConfigurations_; }
357  AddressConfigurations& addresses() { return addressConfigurations_; }
363  const AddressConfiguration& address(rose_addr_t) const;
364 
369 
374 
380  FunctionConfiguration& insertMaybeFunction(rose_addr_t va, const std::string &name="");
381  FunctionConfiguration& insertMaybeFunction(const std::string &name);
387  AddressConfiguration& insertMaybeAddress(rose_addr_t va);
388 
394 
400 
406 
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
bool insertConfiguration(const BasicBlockConfiguration &)
Insert basic block configuration information.
const std::string & comment() const
Property: comment.
Definition: Configuration.h:43
Sawyer::Optional< rose_addr_t > finalInstructionVa() const
Property: last instruction.
Definition: Configuration.h:61
FunctionConfiguration & stackDelta(const Sawyer::Optional< int64_t > &n)
Property: stack delta.
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.
std::string functionComment(rose_addr_t functionVa) const
Function comment.
Configuration information for a function.
FunctionConfigurationsByAddress & functionConfigurationsByAddress()
All function configuration details for function configs that have addresses.
const std::string & defaultName() const
Property: default name.
Sawyer::Optional< rose_addr_t > basicBlockFinalInstructionVa(rose_addr_t bblockVa) const
Basic block final instruction address.
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.
DataBlockConfiguration(rose_addr_t va)
Configuration information for a data block.
Definition: Configuration.h:93
void loadFromFile(const FileSystem::Path &fileName)
Loads configuration from a file.
AddressConfiguration(rose_addr_t va)
Construct a new address configuration object.
FunctionConfiguration & defaultName(const std::string &s)
Property: default name.
const std::string & comment() const
Property: comment string.
Sawyer::Optional< rose_addr_t > address() const
Property: address.
std::string dataBlockComment(rose_addr_t dblockVa) const
Data block comment.
FunctionConfiguration & sourceLocation(const SourceLocation &loc)
Property: Location of function in source code.
std::string comment(rose_addr_t va) const
Address comment.
BasicBlockConfigurations & basicBlocks()
All basic block configuration details.
DataBlockConfigurations & dataBlocks()
All data block configuration details.
rose_addr_t address() const
Property: address.
const FunctionConfigurationsByName & functionConfigurationsByName() const
All function configuration details for configs that have no address.
BasicBlockConfiguration & insertSuccessorVa(rose_addr_t va)
Property: control flow successors.
Definition: Configuration.h:75
Main namespace for the ROSE library.
const AddressConfiguration & address(rose_addr_t) const
Configuration for a particular address.
const SourceLocation & sourceLocation() const
Property: Location of data block in source code.
const std::string & name() const
Property: name.
const std::string & name() const
Property: name.
BasicBlockConfiguration & successorVas(const std::set< rose_addr_t > &vas)
Property: control flow successors.
Definition: Configuration.h:74
std::string dataBlockName(rose_addr_t dblockVa) const
Data block name.
const BasicBlockConfiguration & basicBlock(rose_addr_t) const
Configuration for a particular basic block.
DataBlockConfiguration & sourceLocation(const SourceLocation &loc)
Property: Location of data block in source code.
FunctionConfiguration(const std::string &name)
Configuration information for a function.
BasicBlockConfiguration & insertMaybeBasicBlock(rose_addr_t va)
Lookup or insert a basic block.
Sawyer::Optional< int64_t > stackDelta() const
Property: stack delta.
Configuration for individual addresses.
const DataBlockConfiguration & dataBlock(rose_addr_t) const
Configuration for a particular data block.
FunctionConfiguration & insertMaybeFunction(rose_addr_t va, const std::string &name="")
Lookup or insert a function.
std::string functionName(rose_addr_t functionVa) const
Function name.
Sawyer::Optional< bool > mayReturn() const
Property: may-return.
AddressConfiguration & comment(const std::string &s)
Property: comment string.
const FunctionConfigurationsByAddress & functionConfigurationsByAddress() const
All function configuration details for function configs that have addresses.
AddressConfiguration & insertMaybeAddress(rose_addr_t va)
Lookup or insert address details.
AddressConfiguration & sourceLocation(const SourceLocation &loc)
Property: Location of address within source code.
AddressConfiguration & name(const std::string &s)
Property: name.
void print(std::ostream &) const
Generate a YAML file.
FunctionConfiguration(rose_addr_t va, const std::string &name="")
Configuration information for a function.
BasicBlockConfiguration & finalInstructionVa(const Sawyer::Optional< rose_addr_t > &va)
Property: last instruction.
Definition: Configuration.h:62
Configuration information for a data block.
Definition: Configuration.h:82
DataBlockConfiguration & name(const std::string &s)
Property: name.
const std::string & comment() const
Property: comment.
FunctionConfigurationsByName & functionConfigurationsByName()
All function configuration details for configs that have no address.
DataBlockConfiguration & insertMaybeDataBlock(rose_addr_t va)
Lookup or insert a data block.
FunctionConfiguration & comment(const std::string &s)
Property: comment.
const BasicBlockConfigurations & basicBlocks() const
All basic block configuration details.
BasicBlockConfiguration & clearSuccessorVas()
Property: control flow successors.
Definition: Configuration.h:76
std::string functionDefaultName(rose_addr_t functionVa) const
Function default name.
std::set< rose_addr_t > & successorVas()
Property: control flow successors.
Definition: Configuration.h:73
const std::set< rose_addr_t > & successorVas() const
Property: control flow successors.
Definition: Configuration.h:72
DataBlockConfiguration & comment(const std::string &s)
Property: comment.
const SourceLocation & sourceLocation() const
Property: Location of function in source code.
const SourceLocation & sourceLocation() const
Property: location of basic block in source code.
Definition: Configuration.h:50
const DataBlockConfigurations & dataBlocks() const
All data block configuration details.
AddressConfigurations & addresses()
All address configuration details.
FunctionConfiguration & mayReturn(const Sawyer::Optional< bool > &b)
Property: may-return.
const std::string & name() const
Property: name.
const std::string & comment() const
Property: comment.
rose_addr_t address() const
Property: starting address.
Definition: Configuration.h:36
BasicBlockConfiguration & comment(const std::string &s)
Property: comment.
Definition: Configuration.h:44
std::set< rose_addr_t > basicBlockSuccessorVas(rose_addr_t bblockVa) const
Basic block successor addresses.
const SourceLocation & sourceLocation() const
Property: Location of address within source code.
Configuration information for a basic block.
Definition: Configuration.h:19
BasicBlockConfiguration & sourceLocation(const SourceLocation &loc)
Property: location of basic block in source code.
Definition: Configuration.h:51
BasicBlockConfiguration(rose_addr_t va)
Configuration information for a basic block.
Definition: Configuration.h:31
rose_addr_t address() const
Property: starting address.
Definition: Configuration.h:98
const AddressConfigurations & addresses() const
All address configuration details.
FunctionConfiguration(const Sawyer::Optional< rose_addr_t > &va, const std::string &name)
Configuration information for a function.