libTriton  version 1.0 build 1549
basicBlock.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
10
11
12
13namespace triton {
14 namespace arch {
15
17 }
18
19
20 BasicBlock::BasicBlock(const std::vector<triton::arch::Instruction>& instructions) {
21 this->instructions = instructions;
22 }
23
24
26 this->instructions = other.instructions;
27 }
28
29
31 this->instructions = other.instructions;
32 return *this;
33 }
34
35
37 this->instructions.clear();
38 }
39
40
41 void BasicBlock::add(const Instruction& instruction) {
42 Instruction copy = instruction;
43 if (this->instructions.size()) {
44 copy.setAddress(this->instructions.back().getNextAddress());
45 }
46 this->instructions.push_back(copy);
47 }
48
49
51 if (this->instructions.size() <= position)
52 return false;
53 this->instructions.erase(this->instructions.begin() + position);
54 return true;
55 }
56
57
58 std::vector<triton::arch::Instruction>& BasicBlock::getInstructions(void) {
59 return this->instructions;
60 }
61
62
64 return this->instructions.size();
65 }
66
67
69 if (this->instructions.size() == 0)
70 throw triton::exceptions::BasicBlock("BasicBlock::getFirstAddress(): No instruction in the block.");
71 return this->instructions.front().getAddress();
72 }
73
74
76 if (this->instructions.size() == 0)
77 throw triton::exceptions::BasicBlock("BasicBlock::getLastAddress(): No instruction in the block.");
78 return this->instructions.back().getAddress();
79 }
80
81
82 std::ostream& operator<<(std::ostream& stream, BasicBlock& block) {
83 triton::usize size = block.getSize();
84 for (const auto& inst : block.getInstructions()) {
85 stream << inst;
86 if (--size) {
87 stream << std::endl;
88 }
89 }
90 return stream;
91 }
92
93
94 std::ostream& operator<<(std::ostream& stream, BasicBlock* block) {
95 stream << *block;
96 return stream;
97 }
98
99 };
100};
This class is used to represent a basic block.
Definition: basicBlock.hpp:38
TRITON_EXPORT triton::usize getSize(void) const
Returns the number of instructions in the block.
Definition: basicBlock.cpp:63
TRITON_EXPORT bool remove(triton::uint32 position)
Remove an instruction from the block at the given position. Returns true if success.
Definition: basicBlock.cpp:50
TRITON_EXPORT triton::uint64 getFirstAddress(void) const
Returns the first instruction's address.
Definition: basicBlock.cpp:68
TRITON_EXPORT BasicBlock & operator=(const BasicBlock &other)
Copies an BasicBlock.
Definition: basicBlock.cpp:30
TRITON_EXPORT void add(const Instruction &instruction)
Add an instruction to the block.
Definition: basicBlock.cpp:41
TRITON_EXPORT BasicBlock()
Constructor.
Definition: basicBlock.cpp:16
TRITON_EXPORT triton::uint64 getLastAddress(void) const
Returns the last instruction's address.
Definition: basicBlock.cpp:75
TRITON_EXPORT std::vector< triton::arch::Instruction > & getInstructions(void)
Gets all instructions of the block.
Definition: basicBlock.cpp:58
TRITON_EXPORT ~BasicBlock()
Destructor.
Definition: basicBlock.cpp:36
This class is used to represent an instruction.
Definition: instruction.hpp:48
TRITON_EXPORT void setAddress(triton::uint64 addr)
Sets the address of the instruction.
The exception class used by a basic block.
Definition: exceptions.hpp:305
std::ostream & operator<<(std::ostream &stream, BasicBlock &block)
Displays an BasicBlock.
Definition: basicBlock.cpp:82
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
Definition: tritonTypes.hpp:42
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:39
The Triton namespace.