libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
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
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.
TRITON_EXPORT triton::usize getSize(void) const
Returns the number of instructions in the block.
TRITON_EXPORT bool remove(triton::uint32 position)
Remove an instruction from the block at the given position. Returns true if success.
TRITON_EXPORT triton::uint64 getFirstAddress(void) const
Returns the first instruction's address.
TRITON_EXPORT BasicBlock & operator=(const BasicBlock &other)
Copies an BasicBlock.
TRITON_EXPORT void add(const Instruction &instruction)
Add an instruction to the block.
TRITON_EXPORT BasicBlock()
Constructor.
TRITON_EXPORT triton::uint64 getLastAddress(void) const
Returns the last instruction's address.
TRITON_EXPORT std::vector< triton::arch::Instruction > & getInstructions(void)
Gets all instructions of the block.
TRITON_EXPORT ~BasicBlock()
Destructor.
This class is used to represent an instruction.
TRITON_EXPORT void setAddress(triton::uint64 addr)
Sets the address of the instruction.
The exception class used by a basic block.
std::ostream & operator<<(std::ostream &stream, BasicBlock &block)
Displays an BasicBlock.
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
The Triton namespace.