-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinst.h
1231 lines (1176 loc) · 36.5 KB
/
inst.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <variant>
#include "common.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/raw_ostream.h"
template<typename... Ts>
struct overload : Ts...
{
using Ts::operator()...;
};
template<typename... Ts>
overload(Ts...) -> overload<Ts...>;
namespace cpu0 {
class LD;
class ST;
class LDB;
class STB;
class LDR;
class STR;
class LBR;
class SBR;
class LDI;
class CMP;
class MOV;
class ADD;
class SUB;
class MUL;
class DIV;
class AND;
class OR;
class XOR;
class ADDI;
class ROL;
class ROR;
class SHL;
class SHR;
class JEQ;
class JNE;
class JLT;
class JGT;
class JLE;
class JGE;
class JMP;
class SWI;
class CALL;
class RET;
class IRET;
class PUSH;
class POP;
class PUSHB;
class POPB;
class RESW;
class RESB;
class WORD;
class BYTE;
class Visitor {
public:
virtual ~Visitor() {}
virtual void VisitLD(LD *t) = 0;
virtual void VisitST(ST *t) = 0;
virtual void VisitLDB(LDB *t) = 0;
virtual void VisitSTB(STB *t) = 0;
virtual void VisitLDR(LDR *t) = 0;
virtual void VisitSTR(STR *t) = 0;
virtual void VisitLBR(LBR *t) = 0;
virtual void VisitSBR(SBR *t) = 0;
virtual void VisitLDI(LDI *t) = 0;
virtual void VisitCMP(CMP *t) = 0;
virtual void VisitMOV(MOV *t) = 0;
virtual void VisitADD(ADD *t) = 0;
virtual void VisitSUB(SUB *t) = 0;
virtual void VisitMUL(MUL *t) = 0;
virtual void VisitDIV(DIV *t) = 0;
virtual void VisitAND(AND *t) = 0;
virtual void VisitOR(OR *t) = 0;
virtual void VisitXOR(XOR *t) = 0;
virtual void VisitADDI(ADDI *t) = 0;
virtual void VisitROL(ROL *t) = 0;
virtual void VisitROR(ROR *t) = 0;
virtual void VisitSHL(SHL *t) = 0;
virtual void VisitSHR(SHR *t) = 0;
virtual void VisitJEQ(JEQ *t) = 0;
virtual void VisitJNE(JNE *t) = 0;
virtual void VisitJLT(JLT *t) = 0;
virtual void VisitJGT(JGT *t) = 0;
virtual void VisitJLE(JLE *t) = 0;
virtual void VisitJGE(JGE *t) = 0;
virtual void VisitJMP(JMP *t) = 0;
virtual void VisitSWI(SWI *t) = 0;
virtual void VisitCALL(CALL *t) = 0;
virtual void VisitRET(RET *t) = 0;
virtual void VisitIRET(IRET *t) = 0;
virtual void VisitPUSH(PUSH *t) = 0;
virtual void VisitPOP(POP *t) = 0;
virtual void VisitPUSHB(PUSHB *t) = 0;
virtual void VisitPOPB(POPB *t) = 0;
virtual void VisitRESW(RESW *t) = 0;
virtual void VisitRESB(RESB *t) = 0;
virtual void VisitWORD(WORD *t) = 0;
virtual void VisitBYTE(BYTE *t) = 0;
};
class Inst {
public:
enum Kind {
Inst_LD, // L | 0x00 | load word | LD Ra,[Rb+Cx] | Ra = [Rb + Cx]
Inst_ST, // L | 0x01 | store word | ST Ra,[Rb+Cx] | [Rb+Cx] = Ra;
Inst_LDB, // L | 0x02 | load byte | LDB Ra,[Rb+Cx] | Ra =(byte)[Rb+Cx]
Inst_STB, // L | 0x03 | store byte | STB Ra,[Rb+Cx] | [Rb+Cx] = (byte)Ra
Inst_LDR, // L | 0x04 | LD的寄存器版本 | LDR Ra,[Rb+Rc] | Ra = [Rb+Rc]
Inst_STR, // L | 0x05 | ST的寄存器版本 | STR Ra,[Rb+Rc] | [Rb+Rc] = Ra
Inst_LBR, // L | 0x06 | LDB的寄存器版本 | LBR Ra,[Rb+Rc] | Ra = (byte)[Rb+Rc]
Inst_SBR, // L | 0x07 | SBR的寄存器版本 | SBR Ra,[Rb+Rc] | [Rb+Rc] = (byte)Ra
Inst_LDI, // L | 0x08 | 载入常数 | LDI Ra, Cx | Ra = Cx
Inst_CMP, // A | 0x10 | 比较 | CMP Ra, Rb | SW = Ra >=< Rb
Inst_MOV, // A | 0x12 | 移动 | MOV Ra, Rb | Ra = Rb
Inst_ADD, // A | 0x13 | 加法 | ADD Ra, Rb, Rc | Ra = Rb + Rc
Inst_SUB, // A | 0x14 | 减法 | SUB Ra, Rb, Rc | Ra = Rb - Rc
Inst_MUL, // A | 0x15 | 乘法 | MUL Ra, Rb, Rc | Ra = Rb * Rc
Inst_DIV, // A | 0x16 | 除法 | DIV Ra, Rb, Rc | Ra = Rb / Rc
Inst_AND, // A | 0x18 | 按位与 | AND Ra, Rb, Rc | Ra = Rb & Rc
Inst_OR, // A | 0x19 | 按位或 | OR Ra, Rb, Rc | Ra = Rb | Rc
Inst_XOR, // A | 0x1A | 按位异或 | XOR Ra,Rb,Rc | Ra = Rb ^ Rc
Inst_ADDI, // A | 0x1B | 常数加法 | ADDI Ra,Rb,Cx | Ra = Rb+Cx
Inst_ROL, // A | 0x1C | 循环左移 | ROL Ra,Rb,Cx | Ra = Rb rol Cx
Inst_ROR, // A | 0x1D | 循环右移 | ROR Ra,Rb,Cx | Ra = Rb ror Cx
Inst_SHL, // A | 0x1E | 向左移位 | SHL Ra,Rb,Cx | Ra = Rb << Cx
Inst_SHR, // A | 0x1F | 向右移位 | SHR Ra,Rb,Cx | Ra = Rb >> Cx
Inst_JEQ, // J | 0x20 | 相等跳转 | JEQ Cx | if SW(=) PC = PC+Cx
Inst_JNE, // J | 0x21 | 不等跳转 | JNE Cx | if SW(!=) PC=PC+Cx
Inst_JLT, // J | 0x22 | 小于跳转 | JLT Cx | if SW(<) PC= PC+Cx
Inst_JGT, // J | 0x23 | 大于跳转 | JGT Cx | if SW(>) PC=PC+Cx
Inst_JLE, // J | 0x24 | 小于等于跳转 | JLE Cx | if SW(<=) PC=PC+Cx
Inst_JGE, // J | 0x25 | 大于等于跳转 | JGE Cx | if SW(>=) PC=PC+Cx
Inst_JMP, // J | 0x26 | 无条件跳转 | JMP Cx | PC=PC+Cx
Inst_SWI, // J | 0x2A | 软件中断 | SWI Cx | LR=PC; PC=Cx; INT=1
Inst_CALL, // J | 0x2B | 调用 | CALL Cx | LR=PC; PC=PC+Cx
Inst_RET, // J | 0x2C | 返回 | RET | PC=LR
Inst_IRET, // J | 0x2D | 中断返回 | IRET | PC=LR; INT=0
Inst_PUSH, // A | 0x30 | push word | PUSH Ra | SP-=4;[SP]=Ra
Inst_POP, // A | 0x31 | pop word | POP Ra | Ra=[SP]; SP+=4
Inst_PUSHB, // A | 0x32 | push byte | PUSH Ra | SP--;[SP]=(byte)Ra
Inst_POPB, // A | 0x33 | pop byte | POP Ra | Ra=(byte)[SP]; SP++
Inst_RESW, // D | 0xF0 | 保留n个word
Inst_RESB, // D | 0xF1 | 保留n个byte
Inst_WORD, // D | 0xF2 | 定义有初值的整数变量
Inst_BYTE, // D | 0xf3 | 定义有初值的字节变量或者字符串
};
Inst(Kind kind): kind(kind) {}
virtual ~Inst(){};
const Kind GetKind() const {return kind;}
void SetAddr(uint32_t addr) {addr_ = addr;}
uint32_t Addr() const {return addr_;}
void SetLable(llvm::StringRef label) {label_ = label;}
llvm::StringRef Label() const {return label_;}
void SetSize(uint32_t size) {size_ = size;}
uint32_t Size() const { return size_; }
void SetObjCode(const std::string &objCode) {objCode_ = objCode;}
const std::string &ObjCode() const {
return objCode_;
}
virtual void Accept(Visitor *v) {}
virtual void Dump() {}
private:
const Kind kind;
uint32_t addr_;
llvm::StringRef label_;
uint32_t size_{4};
std::string objCode_;
};
class LD : public Inst{
public:
int op{0x00};
int reg1;
int reg2;
std::variant<llvm::StringRef, int> cx;
LD() : Inst(Inst_LD) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_LD;
}
void Accept(Visitor *v) override {
return v->VisitLD(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "LD \t" << "R" << reg1 << ", R" << reg2 << ", ";
std::visit([&](auto &&v) {
llvm::outs() << v;
}, cx);
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class ST : public Inst{
public:
int op{0x01};
int reg1;
int reg2;
std::variant<llvm::StringRef, int> cx;
ST() : Inst(Inst_ST) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_ST;
}
void Accept(Visitor *v) override {
return v->VisitST(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "ST \t" << "R" << reg1 << ", R" << reg2 << ", ";
std::visit([&](auto &&v) {
llvm::outs() << v;
}, cx);
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class LDB : public Inst{
public:
int op{0x02};
int reg1;
int reg2;
std::variant<llvm::StringRef, int> cx;
LDB() : Inst(Inst_LDB) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_LDB;
}
void Accept(Visitor *v) override {
return v->VisitLDB(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "LDB \t" << "R" << reg1 << ", R" << reg2 << ", ";
std::visit([&](auto &&v) {
llvm::outs() << v;
}, cx);
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class STB : public Inst{
public:
int op{0x03};
int reg1;
int reg2;
std::variant<llvm::StringRef, int> cx;
STB() : Inst(Inst_STB) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_STB;
}
void Accept(Visitor *v) override {
return v->VisitSTB(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "STB \t" << "R" << reg1 << ", R" << reg2 << ", ";
std::visit([&](auto &&v) {
llvm::outs() << v << "\n";
}, cx);
}
};
class LDR : public Inst{
public:
int op{0x04};
int reg1;
int reg2;
int reg3;
LDR() : Inst(Inst_LDR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_LDR;
}
void Accept(Visitor *v) override {
return v->VisitLDR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "LDR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class STR : public Inst{
public:
int op{0x05};
int reg1;
int reg2;
int reg3;
STR() : Inst(Inst_STR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_STR;
}
void Accept(Visitor *v) override {
return v->VisitSTR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "STR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class LBR : public Inst{
public:
int op{0x06};
int reg1;
int reg2;
int reg3;
LBR() : Inst(Inst_LBR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_LBR;
}
void Accept(Visitor *v) override {
return v->VisitLBR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "LBR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class SBR : public Inst{
public:
int op{0x07};
int reg1;
int reg2;
int reg3;
SBR() : Inst(Inst_SBR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_SBR;
}
void Accept(Visitor *v) override {
return v->VisitSBR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "SBR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class LDI : public Inst{
public:
int op{0x08};
int reg1;
int num;
LDI() : Inst(Inst_LDI) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_LDI;
}
void Accept(Visitor *v) override {
return v->VisitLDI(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "LDI \t" << "R" << reg1 << ", " << num;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class CMP : public Inst{
public:
int op{0x10};
int reg1;
int reg2;
CMP() : Inst(Inst_CMP) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_CMP;
}
void Accept(Visitor *v) override {
return v->VisitCMP(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "CMP \t" << "R" << reg1 << ", R" << reg2;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class MOV : public Inst{
public:
int op{0x12};
int reg1;
int reg2;
MOV() : Inst(Inst_MOV) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_MOV;
}
void Accept(Visitor *v) override {
return v->VisitMOV(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "MOV \t" << "R" << reg1 << ", R" << reg2;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class ADD : public Inst{
public:
int op{0x13};
int reg1;
int reg2;
int reg3;
ADD() : Inst(Inst_ADD) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_ADD;
}
void Accept(Visitor *v) override {
return v->VisitADD(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "ADD \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class SUB : public Inst{
public:
int op{0x14};
int reg1;
int reg2;
int reg3;
SUB() : Inst(Inst_SUB) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_SUB;
}
void Accept(Visitor *v) override {
return v->VisitSUB(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "SUB \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class MUL : public Inst{
public:
int op{0x15};
int reg1;
int reg2;
int reg3;
MUL() : Inst(Inst_MUL) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_MUL;
}
void Accept(Visitor *v) override {
return v->VisitMUL(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "MUL \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class DIV : public Inst{
public:
int op{0x16};
int reg1;
int reg2;
int reg3;
DIV() : Inst(Inst_DIV) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_DIV;
}
void Accept(Visitor *v) override {
return v->VisitDIV(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "DIV \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class AND : public Inst{
public:
int op{0x18};
int reg1;
int reg2;
int reg3;
AND() : Inst(Inst_AND) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_AND;
}
void Accept(Visitor *v) override {
return v->VisitAND(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "AND \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class OR : public Inst{
public:
int op{0x19};
int reg1;
int reg2;
int reg3;
OR() : Inst(Inst_OR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_OR;
}
void Accept(Visitor *v) override {
return v->VisitOR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "OR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class XOR : public Inst{
public:
int op{0x1A};
int reg1;
int reg2;
int reg3;
XOR() : Inst(Inst_XOR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_XOR;
}
void Accept(Visitor *v) override {
return v->VisitXOR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "XOR \t" << "R" << reg1 << ", R" << reg2 << ", R" << reg3;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class ADDI : public Inst{
public:
int op{0x1B};
int reg1;
int reg2;
int cx;
ADDI() : Inst(Inst_ADDI) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_ADDI;
}
void Accept(Visitor *v) override {
return v->VisitADDI(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "ADDI \t" << "R" << reg1 << ", R" << reg2 << ", " << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class ROL : public Inst{
public:
int op{0x1C};
int reg1;
int reg2;
int cx;
ROL() : Inst(Inst_ROL) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_ROL;
}
void Accept(Visitor *v) override {
return v->VisitROL(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "ROL \t" << "R" << reg1 << ", R" << reg2 << ", " << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class ROR : public Inst{
public:
int op{0x1D};
int reg1;
int reg2;
int cx;
ROR() : Inst(Inst_ROR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_ROR;
}
void Accept(Visitor *v) override {
return v->VisitROR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "ROR \t" << "R" << reg1 << ", R" << reg2 << ", " << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class SHL : public Inst{
public:
int op{0x1E};
int reg1;
int reg2;
int cx;
SHL() : Inst(Inst_SHL) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_SHL;
}
void Accept(Visitor *v) override {
return v->VisitSHL(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "SHL \t" << "R" << reg1 << ", R" << reg2 << ", " << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class SHR : public Inst{
public:
int op{0x1F};
int reg1;
int reg2;
int cx;
SHR() : Inst(Inst_SHR) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_SHR;
}
void Accept(Visitor *v) override {
return v->VisitSHR(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "SHR \t" << "R" << reg1 << ", R" << reg2 << ", " << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JEQ : public Inst{
public:
int op{0x20};
llvm::StringRef cx;
JEQ() : Inst(Inst_JEQ) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JEQ;
}
void Accept(Visitor *v) override {
return v->VisitJEQ(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JEQ \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JNE : public Inst{
public:
int op{0x21};
llvm::StringRef cx;
JNE() : Inst(Inst_JNE) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JNE;
}
void Accept(Visitor *v) override {
return v->VisitJNE(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JNE \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JLT : public Inst{
public:
int op{0x22};
llvm::StringRef cx;
JLT() : Inst(Inst_JLT) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JLT;
}
void Accept(Visitor *v) override {
return v->VisitJLT(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JLT \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JGT : public Inst{
public:
int op{0x23};
llvm::StringRef cx;
JGT() : Inst(Inst_JGT) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JGT;
}
void Accept(Visitor *v) override {
return v->VisitJGT(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JGT \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JLE : public Inst{
public:
int op{0x24};
llvm::StringRef cx;
JLE() : Inst(Inst_JLE) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JLE;
}
void Accept(Visitor *v) override {
return v->VisitJLE(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JLE \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JGE : public Inst{
public:
int op{0x25};
llvm::StringRef cx;
JGE() : Inst(Inst_JGE) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JGE;
}
void Accept(Visitor *v) override {
return v->VisitJGE(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JGE \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class JMP : public Inst{
public:
int op{0x26};
llvm::StringRef cx;
JMP() : Inst(Inst_JMP) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_JMP;
}
void Accept(Visitor *v) override {
return v->VisitJMP(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "JMP \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class SWI : public Inst{
public:
int op{0x2A};
int cx;
SWI() : Inst(Inst_SWI) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_SWI;
}
void Accept(Visitor *v) override {
return v->VisitSWI(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "SWI \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class CALL : public Inst{
public:
int op{0x2B};
llvm::StringRef cx;
CALL() : Inst(Inst_CALL) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_CALL;
}
void Accept(Visitor *v) override {
return v->VisitCALL(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "CALL \t" << cx;
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class RET : public Inst{
public:
int op{0x2C};
RET() : Inst(Inst_RET) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_RET;
}
void Accept(Visitor *v) override {
return v->VisitRET(this);
}
void Dump() override {
llvm::outs() << hex(Addr(), 8) << ": ";
Label().size() > 0 ? (llvm::outs() << Label() << ": \t") : llvm::outs() << "\t";
llvm::outs() << "RET ";
if (ObjCode().size() > 0) {
llvm::outs() << "\t\t=> " << ObjCode() << "\n";
}else {
llvm::outs() << "\n";
}
}
};
class IRET : public Inst{
public:
int op{0x2D};
IRET() : Inst(Inst_IRET) {}
static bool classof(const Inst *st) {
return st->GetKind() == Inst_IRET;
}
void Accept(Visitor *v) override {
return v->VisitIRET(this);
}