-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand.cc
More file actions
79 lines (71 loc) · 2.2 KB
/
Copy pathCommand.cc
File metadata and controls
79 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Asm stat tool for reading objdumps
* Copyright © 2016 gluk47@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The code in this file is fully authored by Egor Kochetov <gluk47@gmail.com>
* Feel free to contact him if you need this file with GPL restrictions waived.
*/
#include "Command.h"
#include "Switch.h"
#include "tools.h"
using namespace std;
namespace cmd_basenames {
set <string> jumps = { "j", "jmp" };
}
Command::Command(string fullname)
: m_fullname(move (fullname)) {
parse_fullname();
}
void Command::parse_fullname() {
if (m_fullname.empty())
return;
if (m_fullname[0] == 'j') {
if (m_fullname.substr(0, 3) == "jmp")
m_basename = "jmp";
else
m_basename = "j";
}
}
void Command::parse_args() {
if (cmd_basenames::jumps.count (m_basename) > 0) {
if (m_arguments.size() < 1) {
cerr << "Invalid jump command: not found a required argument to " << m_fullname
<< "\n";
return;
}
stringstream ss (m_arguments[0]);
ss >> hex >> jump_address;
}
}
istream& operator>>(istream& str, Command& cmd) {
string opname;
str >> opname;
cmd.set_fullname(opname);
str >> ws;
getline(str, opname, '\n');
auto args = split<vector>(opname, ',');
cmd.set_args(args);
return str;
}
ostream& operator<<(ostream& str, const Command& cmd) {
str << cmd.fullname();
if (cmd.jump_address == 0)
for (const auto& arg : cmd.args())
str << " " << arg;
else
str << " to 0x" << hex << cmd.jump_address;
return str;
}