GTIRB
v2.2.0
GrammaTech Intermediate Representation for Binaries: C++ API
|
Go to the documentation of this file.
24 #include <gtirb/proto/CodeBlock.pb.h>
25 #include <boost/range/iterator_range.hpp>
37 template <
class T>
class ErrorOr;
89 uint64_t getOffset()
const;
94 std::optional<Addr> getAddress()
const;
105 Observer->sizeChange(
this,
S, Size);
107 "recovering from rejected size change is not implemented yet");
121 Observer->decodeModeChange(
this, DM,
DecodeMode);
124 "recovering from rejected decode mode change is not implemented yet");
144 template <
typename T>
150 template <
typename T>
161 assert(Parent &&
"Block has no byte interval!");
162 return bytes_begin<T>(Parent->getBoostEndianOrder());
175 template <
typename T>
178 boost::endian::order OutputOrder = boost::endian::order::native) {
179 assert(Parent &&
"Block has no byte interval!");
180 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
191 assert(Parent &&
"Block has no byte interval!");
192 return bytes_end<T>(Parent->getBoostEndianOrder());
205 template <
typename T>
208 boost::endian::order OutputOrder = boost::endian::order::native) {
209 assert(Parent &&
"Block has no byte interval!");
210 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
221 assert(Parent &&
"Block has no byte interval!");
222 return bytes<T>(Parent->getBoostEndianOrder());
235 template <
typename T>
237 bytes(boost::endian::order InputOrder,
238 boost::endian::order OutputOrder = boost::endian::order::native) {
239 assert(Parent &&
"Block has no byte interval!");
241 bytes_end<T>(InputOrder, OutputOrder));
252 assert(Parent &&
"Block has no byte interval!");
253 return bytes_begin<T>(Parent->getBoostEndianOrder());
266 template <
typename T>
268 boost::endian::order InputOrder,
269 boost::endian::order OutputOrder = boost::endian::order::native)
const {
270 assert(Parent &&
"Block has no byte interval!");
271 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
282 assert(Parent &&
"Block has no byte interval!");
283 return bytes_end<T>(Parent->getBoostEndianOrder());
296 template <
typename T>
298 boost::endian::order InputOrder,
299 boost::endian::order OutputOrder = boost::endian::order::native)
const {
300 assert(Parent &&
"Block has no byte interval!");
301 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
312 assert(Parent &&
"Block has no byte interval!");
313 return bytes<T>(Parent->getBoostEndianOrder());
326 template <
typename T>
328 bytes(boost::endian::order InputOrder,
329 boost::endian::order OutputOrder = boost::endian::order::native)
const {
330 assert(Parent &&
"Block has no byte interval!");
332 bytes_end<T>(InputOrder, OutputOrder));
351 assert(Parent &&
"Block has no byte interval!");
352 return reinterpret_cast<T*
>(Parent->rawBytes<uint8_t>() + getOffset());
371 assert(Parent &&
"Block has no byte interval!");
372 return reinterpret_cast<const T*
>(Parent->rawBytes<uint8_t>() +
377 static bool classof(
const Node* N) {
return N->getKind() == Kind::CodeBlock; }
381 CodeBlock(Context& C) : CfgNode(C, Kind::CodeBlock) {}
383 : CfgNode(C, Kind::CodeBlock), Size(
S),
DecodeMode(DMode) {}
385 : CfgNode(C, Kind::CodeBlock, U), Size(
S),
DecodeMode(DMode) {}
387 void setParent(ByteInterval* BI, CodeBlockObserver* O) {
394 return C.Create<CodeBlock>(C, Size, DMode, U);
398 using MessageType = proto::CodeBlock;
405 void toProtobuf(MessageType* Message)
const;
413 static ErrorOr<CodeBlock*> fromProtobuf(Context& C,
414 const MessageType& Message);
417 void save(std::ostream& Out)
const;
420 static CodeBlock* load(Context& C, std::istream& In);
422 ByteInterval* Parent{
nullptr};
423 CodeBlockObserver* Observer{
nullptr};
429 friend class SerializationTestHarness;
434 #endif // GTIRB_BLOCK_H
ByteInterval::const_bytes_iterator< T > const_bytes_iterator
Const iterator over bytes in this block.
Definition: CodeBlock.hpp:145
BytesBaseIterator< ByteInterval, T > bytes_iterator
Iterator over bytes.
Definition: ByteInterval.hpp:1769
A basic block.
Definition: CodeBlock.hpp:47
bytes_iterator< T > bytes_begin()
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:160
NodeTy * Create(Args &&... TheArgs)
Create an object of type T.
Definition: Context.hpp:126
const_bytes_iterator< T > bytes_end() const
Get an iterator past the last byte in this block.
Definition: CodeBlock.hpp:281
Represents the base of the Node class hierarchy.
Definition: Node.hpp:39
gtirb::DecodeMode getDecodeMode() const
Get the decode mode from a CodeBlock.
Definition: CodeBlock.hpp:85
Represents the base of types that can be inserted into the CFG.
Definition: CfgNode.hpp:30
ByteInterval::const_bytes_range< T > const_bytes_range
Const range over bytes in this block.
Definition: CodeBlock.hpp:151
boost::uuids::uuid UUID
Represents a universally unique identifier used to identify Node objects across serialization boundar...
Definition: Context.hpp:36
void setDecodeMode(gtirb::DecodeMode DM)
Set the decode mode of this block.
Definition: CodeBlock.hpp:117
The context under which GTIRB operations occur.
Definition: Context.hpp:63
bytes_range< T > bytes(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:237
uint64_t getSize() const
Get the size from a CodeBlock.
Definition: CodeBlock.hpp:77
ByteInterval::bytes_iterator< T > bytes_iterator
Iterator over bytes in this block.
Definition: CodeBlock.hpp:134
boost::iterator_range< bytes_iterator< T > > bytes_range
Range over bytes.
Definition: ByteInterval.hpp:1775
const_bytes_iterator< T > bytes_begin() const
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:251
T * rawBytes()
Return the raw data underlying this block's byte vector.
Definition: CodeBlock.hpp:350
#define GTIRB_EXPORT_API
This macro controls the visibility of exported symbols (i.e. classes) in shared libraries....
Definition: Export.hpp:52
static CodeBlock * Create(Context &C)
Create an unitialized CodeBlock object.
Definition: CodeBlock.hpp:52
bytes_range< T > bytes()
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:220
Main namespace for the GTIRB API.
Definition: Addr.hpp:28
static CodeBlock * Create(Context &C, uint64_t Size, gtirb::DecodeMode DMode=DecodeMode::Default)
Create a CodeBlock object.
Definition: CodeBlock.hpp:61
bytes_iterator< T > bytes_begin(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:177
Class gtirb::ByteInterval.
ByteInterval::bytes_range< T > bytes_range
Range over bytes in this block.
Definition: CodeBlock.hpp:139
ByteInterval * getByteInterval()
Get the ByteInterval this block belongs to.
Definition: CodeBlock.hpp:67
Base class for nodes of the CFG.
BytesBaseIterator< const ByteInterval, T > const_bytes_iterator
Const iterator over bytes.
Definition: ByteInterval.hpp:1781
const ByteInterval * getByteInterval() const
Get the ByteInterval this block belongs to.
Definition: CodeBlock.hpp:69
DecodeMode
Variations on decoding a particular ISA.
Definition: DecodeMode.hpp:26
bytes_iterator< T > bytes_end(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native)
Get an iterator past the last byte in this block.
Definition: CodeBlock.hpp:207
bytes_iterator< T > bytes_end()
Get an iterator past the last byte in this block.
Definition: CodeBlock.hpp:190
const_bytes_iterator< T > bytes_begin(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:267
@ Default
Default decode mode for all ISAs.
const_bytes_range< T > bytes(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:328
A contiguous region of bytes in a binary.
Definition: ByteInterval.hpp:124
const_bytes_iterator< T > bytes_end(boost::endian::order InputOrder, boost::endian::order OutputOrder=boost::endian::order::native) const
Get an iterator past the last byte in this block.
Definition: CodeBlock.hpp:297
void setSize(uint64_t S)
Set the size of this block.
Definition: CodeBlock.hpp:101
boost::iterator_range< const_bytes_iterator< T > > const_bytes_range
Const range over bytes.
Definition: ByteInterval.hpp:1787
const T * rawBytes() const
Return the raw data underlying this block's byte vector.
Definition: CodeBlock.hpp:370
Class gtirb::Addr and related functions.
const_bytes_range< T > bytes() const
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:311
ChangeStatus
Definition: Observer.hpp:19