-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbytecode.cpp
More file actions
87 lines (82 loc) · 2.34 KB
/
Copy pathbytecode.cpp
File metadata and controls
87 lines (82 loc) · 2.34 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
80
81
82
83
84
85
86
87
/*
* bytecode.cpp
* openc2e
*
* Created by Bryan Donlan on Wed 07 Dec 2005.
* Copyright (c) 2005 Bryan Donlan. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
*/
#include "bytecode.h"
#include "dialect.h"
#include "cmddata.h"
#include <boost/format.hpp>
using boost::format;
using boost::str;
const char *cnams[] = {
NULL,
"EQ",
"LT",
"LE",
"GT",
"GE",
"NE",
NULL
};
static std::string try_lookup(const Dialect *d, int idx) {
if (d)
return std::string(d->getcmd(idx)->fullname);
return str(format("%d") % idx);
}
std::string dumpOp(const Dialect *d, caosOp op) {
int arg = op.argument; // weird C++ issues
switch (op.opcode) {
case CAOS_NOP:
return std::string("NOP");
case CAOS_DIE:
return str(format("DIE %d") % arg);
case CAOS_STOP:
return std::string("STOP");
case CAOS_CMD:
return str(format("CMD %s") % try_lookup(d, arg));
case CAOS_COND:
return str(format("COND %s %s") % (arg & CAND ? "AND" : "OR") % cnams[arg & CMASK]);
case CAOS_CONST:
return str(format("CONST %d") % arg);
case CAOS_CONSTINT:
return str(format("CONSTINT %d") % arg);
case CAOS_BYTESTR:
return str(format("BYTESTR %d") % arg);
case CAOS_PUSH_AUX:
return str(format("PUSH AUX %d") % arg);
case CAOS_RESTORE_AUX:
return str(format("RESTORE AUX %d") % arg);
case CAOS_SAVE_CMD:
return str(format("CMD SAVE %s") % try_lookup(d, arg));
case CAOS_YIELD:
return str(format("YIELD %d") % arg);
case CAOS_STACK_ROT:
return str(format("STACK ROT %d") % arg);
case CAOS_CJMP:
return str(format("CJMP %08d") % arg);
case CAOS_JMP:
return str(format("JMP %08d") % arg);
case CAOS_DECJNZ:
return str(format("DECJNZ %08d") % arg);
case CAOS_GSUB:
return str(format("GSUB %08d") % arg);
case CAOS_ENUMPOP:
return str(format("ENUMPOP %08d") % arg);
default:
return str(format("UNKNOWN %02x %06x") % arg);
}
}