Began removal of platform/. The Monitor:: namespace is completely converted.
[aesalon.git] / src / monitor / asm / Operand.cpp
blob4926d27df140d72fa64f27528004d63475ba6842
1 #include <iostream>
2 #include "Operand.h"
3 #include "misc/String.h"
5 namespace Aesalon {
6 namespace Monitor {
7 namespace ASM {
9 Operand::Operand(std::string operand_string) {
10 Register reg = Register::from_string(operand_string);
11 if(reg != Register::INVALID) {
12 operand_type = REGISTER;
13 this->reg = reg;
14 data_size = reg.get_register_size();
15 return;
17 if(std::isdigit(operand_string[0])) {
18 Misc::String::to<Word>(operand_string, address);
19 operand_type = MEMORY_ADDRESS;
20 return;
22 operand_type = REGISTER_OFFSET;
23 /* Some examples:
24 DWORD PTR [rbp-0x14]
25 QWORD PTR [rip+0x200541]
27 if(Misc::String::begins_with(operand_string, "QWORD")) data_size = Register::SIZE_QWORD;
28 else if(Misc::String::begins_with(operand_string, "DWORD")) data_size = Register::SIZE_DWORD;
29 else if(Misc::String::begins_with(operand_string, "WORD")) data_size = Register::SIZE_WORD;
30 else if(Misc::String::begins_with(operand_string, "BYTE")) data_size = Register::SIZE_BYTE;
31 operand_string.erase(0, operand_string.find("[")+1);
32 std::string offset;
33 if(operand_string.find("+") != std::string::npos) {
34 offset = operand_string.substr(operand_string.find("+"));
35 operand_string.erase(operand_string.find("+"));
37 else if(operand_string.find("-") != std::string::npos) {
38 offset = operand_string.substr(operand_string.find("-"));
39 operand_string.erase(operand_string.find("-"));
41 Misc::String::to<SWord>(offset, this->offset);
42 this->reg = Register::from_string(operand_string);
45 } // namespace ASM
46 } // namespace Monitor
47 } // namespace Aesalon