GTIRB
v2.1.0
GrammaTech Intermediate Representation for Binaries: C++ API
|
Go to the documentation of this file.
23 #include <gtirb/proto/CodeBlock.pb.h>
24 #include <boost/range/iterator_range.hpp>
36 template <
class T>
class ErrorOr;
47 Thumb = proto::ARM_Thumb,
96 uint64_t getOffset()
const;
101 std::optional<Addr> getAddress()
const;
112 Observer->sizeChange(
this,
S, Size);
114 "recovering from rejected size change is not implemented yet");
140 template <
typename T>
146 template <
typename T>
157 assert(Parent &&
"Block has no byte interval!");
158 return bytes_begin<T>(Parent->getBoostEndianOrder());
171 template <
typename T>
174 boost::endian::order OutputOrder = boost::endian::order::native) {
175 assert(Parent &&
"Block has no byte interval!");
176 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
187 assert(Parent &&
"Block has no byte interval!");
188 return bytes_end<T>(Parent->getBoostEndianOrder());
201 template <
typename T>
204 boost::endian::order OutputOrder = boost::endian::order::native) {
205 assert(Parent &&
"Block has no byte interval!");
206 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
217 assert(Parent &&
"Block has no byte interval!");
218 return bytes<T>(Parent->getBoostEndianOrder());
231 template <
typename T>
233 bytes(boost::endian::order InputOrder,
234 boost::endian::order OutputOrder = boost::endian::order::native) {
235 assert(Parent &&
"Block has no byte interval!");
237 bytes_end<T>(InputOrder, OutputOrder));
248 assert(Parent &&
"Block has no byte interval!");
249 return bytes_begin<T>(Parent->getBoostEndianOrder());
262 template <
typename T>
264 boost::endian::order InputOrder,
265 boost::endian::order OutputOrder = boost::endian::order::native)
const {
266 assert(Parent &&
"Block has no byte interval!");
267 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset();
278 assert(Parent &&
"Block has no byte interval!");
279 return bytes_end<T>(Parent->getBoostEndianOrder());
292 template <
typename T>
294 boost::endian::order InputOrder,
295 boost::endian::order OutputOrder = boost::endian::order::native)
const {
296 assert(Parent &&
"Block has no byte interval!");
297 return Parent->bytes_begin<T>(InputOrder, OutputOrder) + getOffset() + Size;
308 assert(Parent &&
"Block has no byte interval!");
309 return bytes<T>(Parent->getBoostEndianOrder());
322 template <
typename T>
324 bytes(boost::endian::order InputOrder,
325 boost::endian::order OutputOrder = boost::endian::order::native)
const {
326 assert(Parent &&
"Block has no byte interval!");
328 bytes_end<T>(InputOrder, OutputOrder));
347 assert(Parent &&
"Block has no byte interval!");
348 return reinterpret_cast<T*
>(Parent->rawBytes<uint8_t>() + getOffset());
367 assert(Parent &&
"Block has no byte interval!");
368 return reinterpret_cast<const T*
>(Parent->rawBytes<uint8_t>() +
373 static bool classof(
const Node* N) {
return N->getKind() == Kind::CodeBlock; }
377 CodeBlock(Context& C) : CfgNode(C, Kind::CodeBlock) {}
379 : CfgNode(C, Kind::CodeBlock), Size(
S),
DecodeMode(DMode) {}
381 : CfgNode(C, Kind::CodeBlock, U), Size(
S),
DecodeMode(DMode) {}
383 void setParent(ByteInterval* BI, CodeBlockObserver* O) {
390 return C.Create<CodeBlock>(C, Size, DMode, U);
394 using MessageType = proto::CodeBlock;
401 void toProtobuf(MessageType* Message)
const;
409 static ErrorOr<CodeBlock*> fromProtobuf(Context& C,
410 const MessageType& Message);
413 void save(std::ostream& Out)
const;
416 static CodeBlock* load(Context& C, std::istream& In);
418 ByteInterval* Parent{
nullptr};
419 CodeBlockObserver* Observer{
nullptr};
425 friend class SerializationTestHarness;
430 #endif // GTIRB_BLOCK_H
ByteInterval::const_bytes_iterator< T > const_bytes_iterator
Const iterator over bytes in this block.
Definition: CodeBlock.hpp:141
BytesBaseIterator< ByteInterval, T > bytes_iterator
Iterator over bytes.
Definition: ByteInterval.hpp:1721
A basic block.
Definition: CodeBlock.hpp:54
bytes_iterator< T > bytes_begin()
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:156
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:277
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:92
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:147
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:124
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:233
uint64_t getSize() const
Get the size from a CodeBlock.
Definition: CodeBlock.hpp:84
ByteInterval::bytes_iterator< T > bytes_iterator
Iterator over bytes in this block.
Definition: CodeBlock.hpp:130
boost::iterator_range< bytes_iterator< T > > bytes_range
Range over bytes.
Definition: ByteInterval.hpp:1727
const_bytes_iterator< T > bytes_begin() const
Get an iterator to the first byte in this block.
Definition: CodeBlock.hpp:247
T * rawBytes()
Return the raw data underlying this block's byte vector.
Definition: CodeBlock.hpp:346
#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:59
bytes_range< T > bytes()
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:216
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:68
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:173
Class gtirb::ByteInterval.
@ Thumb
Thumb decode mode for ARM32.
ByteInterval::bytes_range< T > bytes_range
Range over bytes in this block.
Definition: CodeBlock.hpp:135
ByteInterval * getByteInterval()
Get the ByteInterval this block belongs to.
Definition: CodeBlock.hpp:74
Base class for nodes of the CFG.
BytesBaseIterator< const ByteInterval, T > const_bytes_iterator
Const iterator over bytes.
Definition: ByteInterval.hpp:1733
const ByteInterval * getByteInterval() const
Get the ByteInterval this block belongs to.
Definition: CodeBlock.hpp:76
DecodeMode
Variations on decoding a particular ISA.
Definition: CodeBlock.hpp:45
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:203
bytes_iterator< T > bytes_end()
Get an iterator past the last byte in this block.
Definition: CodeBlock.hpp:186
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:263
@ 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:324
A contiguous region of bytes in a binary.
Definition: ByteInterval.hpp:116
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:293
void setSize(uint64_t S)
Set the size of this block.
Definition: CodeBlock.hpp:108
boost::iterator_range< const_bytes_iterator< T > > const_bytes_range
Const range over bytes.
Definition: ByteInterval.hpp:1739
const T * rawBytes() const
Return the raw data underlying this block's byte vector.
Definition: CodeBlock.hpp:366
Class gtirb::Addr and related functions.
const_bytes_range< T > bytes() const
Get a range of the bytes in this block.
Definition: CodeBlock.hpp:307
ChangeStatus
Definition: Observer.hpp:19