-
Notifications
You must be signed in to change notification settings - Fork 2
/
ir_instructions.h
3405 lines (2847 loc) · 91.6 KB
/
ir_instructions.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
#ifndef __LANGUMS_IRINSTRUCTIONS_H
#define __LANGUMS_IRINSTRUCTIONS_H
#include <unordered_map>
#include "ir_utility.h"
namespace LangUMS
{
enum class IRInstructionType
{
Nop = 0,
DebugBrk, // puts an automatic debug breakpoint for the debugger
// core
Push, // pushes value on top of the stack and decrements the stack pointer
Pop, // pops a value from the stack and increments the stack pointer
SetReg, // sets a register to a constant value
IncReg, // increments a register by a constant value
DecReg, // decrements a register by a constant value
CopyReg, // copies a register's value to another register
Add, // pops two values off the stack and adds them together, pushes the result on the stack
Sub, // pops two values off the stack, subtracts the second from the first, pushes the result on the stack
Mul, // pops two values off the stack, multiplies them together, pushes the result on the stack
MulConst, // pops a value off the stack and multiplies it with a constant, pushes the result on the stack
Div, // pops two values off the stack, divides the second by the first, pushes the result on the stack
Rnd256, // pushes a random value between 0 and 255 on top of the stack
Jmp, // jumps to an instruction using a relative or an absolute offset
JmpIfEq, // jumps to an instruction if a register is equal to a constant
JmpIfNotEq, // jumps to an instruction if a register is not equal to a constant
JmpIfLess, // jumps to an instruction if a register is less than a constant
JmpIfGrt, // jumps to an instruction if a register is greater than a constant
JmpIfLessOrEq, // jumps to an instruction if a register is less than or equal to a constant
JmpIfGrtOrEq, // jumps to an instruction if a register is greater than or equal to a constant
JmpIfSwNotSet, // jumps to an instruction if a switch is not set
JmpIfSwSet, // jumps to an instruction if a switch is set
SetSw, // sets a switch
ChkPlayers, // runs checks which players are in-game
IsPresent, // pushes 1 or 0 on top of the stack depending on whether given players are in-game or not
// actions
Wait, // waits for an amount of time
DisplayMsg, // displays a text message
Spawn, // spawns a unit
Kill, // kills a unit
Remove, // removes a unit
Move, // moves a unit
Order, // orders a unit to move, attack or patrol
Modify, // modifies a unit's properties such as hp, energy, shields and hangar count
Give, // gives units to another player
MoveLoc, // moves a location
EndGame, // ends the game in a victory or defeat for a given player
CenterView, // centers the camera on a location for a given player
Ping, // Minimap ping at a location
SetResource, // sets the resource count for a given resource for a given player
IncResource, // increments the resource count for a given resource for a given player
DecResource, // decrements the resource count for a given resource for a given player
SetScore, // sets the score for a player
IncScore, // increments the score for a player
DecScore, // decrements the score for a player
SetCountdown, // sets the countdown timer,
AddCountdown, // adds to the countdown timer,
SubCountdown, // subtracts from the countdown timer,
PauseCountdown, // pauses/ unpauses the countdown timer
MuteUnitSpeech, // mutes/ unmutes unit speech
SetDeaths, // sets the death count for a given unit
IncDeaths, // increments the death count for a given unit
DecDeaths, // decrements the death count for a given unit
Talk, // shows the unit talking portrait for an amount of time
SetDoodad, // sets the state of a doodad
SetInvincible, // sets invincibility for units
AIScript, // runs an ai script
SetAlly, // sets alliance status between two players
SetObj, // sets the mission objectives
PauseGame, // pauses the game (singleplayer)
NextScen, // sets the next scenario (singleplayer)
Leaderboard, // shows the leaderboard
LeaderboardCpu, // whether to show cpu players in the leaderboard
PlayWAV, // plays a .wav file
Transmission, // combined display msg, unit portrait and play wav
Event, // conditions
RegCond, // Register value condition
BringCond, // Bring trigger condition
AccumCond, // Accumulate trigger condition
LeastResCond, // Player has the least quantity of a resource
MostResCond, // Player has the most quantity of a resource
ScoreCond, // Score condition
HiScoreCond, // Highest score condition
LowScoreCond, // Lowest score condition
TimeCond, // Elapsed time trigger condition
CmdCond, // Player commands a quantity of units condition
CmdLeastCond, // Player commands the least quantity of units condition
CmdMostCond, // Player commands the most quantity of units condition
KillCond, // Player has killed a quantity of units condition
KillLeastCond, // Player has the least units killed
KillMostCond, // Player hast the most units killed
DeathCond, // Player has lost a quantity of units condition
CountdownCond, // Countdown timer condition
OpponentsCond, // Opponents condition
Unit, // unit properties
UnitProp
};
struct StackFrame
{
std::string m_FunctionName;
std::vector<std::pair<unsigned int, std::string>> m_Variables;
IASTNode* m_ASTNode = nullptr;
};
using namespace CHK;
class IIRInstruction
{
public:
IIRInstruction (IRInstructionType type) : m_Type (type)
{}
virtual ~IIRInstruction ()
{}
IASTNode* GetASTNode() const
{
return m_ASTNode;
}
void SetASTNode(IASTNode* node)
{
m_ASTNode = node;
}
unsigned int GetInstructionId() const
{
return m_Id;
}
void SetInstructionId(unsigned int id)
{
m_Id = id;
}
void SetDebugStackFrames(const std::vector<std::shared_ptr<StackFrame>>& frames)
{
m_DebugStackFrames = frames;
}
const std::vector<std::shared_ptr<StackFrame>>& GetDebugStackFrames() const
{
return m_DebugStackFrames;
}
IRInstructionType GetType () const
{
return m_Type;
}
virtual std::string DebugDump () const = 0;
private:
IASTNode* m_ASTNode = nullptr;
IRInstructionType m_Type = IRInstructionType::Nop;
unsigned int m_Id = 0;
std::vector<std::shared_ptr<StackFrame>> m_DebugStackFrames;
};
class IRNopInstruction : public IIRInstruction
{
public:
IRNopInstruction () : IIRInstruction (IRInstructionType::Nop)
{}
std::string DebugDump () const
{
return "NOP";
}
};
class IRDebugBrkInstruction : public IIRInstruction
{
public:
IRDebugBrkInstruction () : IIRInstruction (IRInstructionType::DebugBrk)
{}
std::string DebugDump () const
{
return "DBGBRK";
}
};
class IRPushInstruction : public IIRInstruction
{
public:
IRPushInstruction (unsigned int regId, bool isLiteral = false) :
m_RegId (regId), m_IsValueLiteral (isLiteral), IIRInstruction (IRInstructionType::Push)
{}
unsigned int GetRegisterId () const
{
return m_RegId;
}
bool IsValueLiteral () const
{
return m_IsValueLiteral;
}
std::string DebugDump () const
{
if (m_IsValueLiteral)
{
return SafePrintf ("PUSH %", m_RegId);
}
else
{
return SafePrintf ("PUSH %", RegisterIdToString (m_RegId));
}
}
private:
unsigned int m_RegId = 0;
bool m_IsValueLiteral = false;
};
class IRPopInstruction : public IIRInstruction
{
public:
IRPopInstruction (int regId = -1) : // if regId == -1 will only increment the stack pointer without copying the value into a register
m_RegId (regId), IIRInstruction (IRInstructionType::Pop)
{}
int GetRegisterId () const
{
return m_RegId;
}
std::string DebugDump () const
{
if (m_RegId != -1)
{
return SafePrintf ("POP %", RegisterIdToString (m_RegId));
}
else
{
return "POP";
}
}
private:
int m_RegId = 0;
};
class IRSetRegInstruction : public IIRInstruction
{
public:
IRSetRegInstruction (unsigned int regId, int value) :
m_RegId (regId), m_Value (value), IIRInstruction (IRInstructionType::SetReg)
{}
unsigned int GetRegisterId () const
{
return m_RegId;
}
int GetValue () const
{
return m_Value;
}
std::string DebugDump () const
{
return SafePrintf ("SET % %", RegisterIdToString (m_RegId), m_Value);
}
private:
unsigned int m_RegId = 0;
int m_Value = 0;
};
class IRIncRegInstruction : public IIRInstruction
{
public:
IRIncRegInstruction (unsigned int regId, int amount) :
m_RegId (regId), m_Amount (amount), IIRInstruction (IRInstructionType::IncReg)
{}
unsigned int GetRegisterId () const
{
return m_RegId;
}
int GetAmount () const
{
return m_Amount;
}
std::string DebugDump () const
{
if (m_Amount > 1)
{
return SafePrintf ("INC % %", RegisterIdToString (m_RegId), m_Amount);
}
return SafePrintf ("INC %", RegisterIdToString (m_RegId));
}
private:
unsigned int m_RegId = 0;
int m_Amount = 0;
};
class IRDecRegInstruction : public IIRInstruction
{
public:
IRDecRegInstruction (unsigned int regId, int amount) :
m_RegId (regId), m_Amount (amount), IIRInstruction (IRInstructionType::DecReg)
{}
unsigned int GetRegisterId () const
{
return m_RegId;
}
int GetAmount () const
{
return m_Amount;
}
std::string DebugDump () const
{
if (m_Amount > 1)
{
return SafePrintf ("DEC % %", RegisterIdToString (m_RegId), m_Amount);
}
return SafePrintf ("DEC %", RegisterIdToString (m_RegId));
}
private:
unsigned int m_RegId = 0;
int m_Amount = 0;
};
class IRCopyRegInstruction : public IIRInstruction
{
public:
IRCopyRegInstruction (unsigned int dstRegId, unsigned int srcRegId) :
m_DstRegId (dstRegId), m_SrcRegId (srcRegId), IIRInstruction (IRInstructionType::CopyReg)
{}
unsigned int GetDestinationRegisterId () const
{
return m_DstRegId;
}
unsigned int GetSourceRegisterId () const
{
return m_SrcRegId;
}
std::string DebugDump () const
{
return SafePrintf ("CPY % %", RegisterIdToString (m_DstRegId), RegisterIdToString (m_SrcRegId));
}
private:
unsigned int m_DstRegId = 0;
unsigned int m_SrcRegId = 0;
};
class IRAddInstruction : public IIRInstruction
{
public:
IRAddInstruction () : IIRInstruction (IRInstructionType::Add)
{}
std::string DebugDump () const
{
return "ADD";
}
};
class IRSubInstruction : public IIRInstruction
{
public:
IRSubInstruction () : IIRInstruction (IRInstructionType::Sub)
{}
std::string DebugDump () const
{
return "SUB";
}
};
class IRMulInstruction : public IIRInstruction
{
public:
IRMulInstruction () : IIRInstruction (IRInstructionType::Mul)
{}
std::string DebugDump () const
{
return "MUL";
}
};
class IRMulConstInstruction : public IIRInstruction
{
public:
IRMulConstInstruction (unsigned int value) : m_Value(value), IIRInstruction (IRInstructionType::MulConst)
{}
std::string DebugDump () const
{
return SafePrintf("MULCONST %", m_Value);
}
unsigned int GetValue() const
{
return m_Value;
}
private:
unsigned int m_Value;
};
class IRDivInstruction : public IIRInstruction
{
public:
IRDivInstruction () : IIRInstruction (IRInstructionType::Div)
{}
std::string DebugDump () const
{
return "DIV";
}
};
class IRRnd256Instruction : public IIRInstruction
{
public:
IRRnd256Instruction () : IIRInstruction (IRInstructionType::Rnd256)
{}
std::string DebugDump () const
{
return "RND256";
}
};
class IRDisplayMsgInstruction : public IIRInstruction
{
public:
IRDisplayMsgInstruction (const std::string& message, int playerId) :
m_Message (message), m_PlayerId (playerId), IIRInstruction (IRInstructionType::DisplayMsg)
{}
const std::string& GetMessage () const
{
return m_Message;
}
int GetPlayerId () const
{
return m_PlayerId;
}
std::string DebugDump () const
{
auto msg = m_Message;
std::replace (msg.begin (), msg.end (), '\n', ' ');
if (m_PlayerId == -1)
{
return SafePrintf ("MSG \"%\" [ALL]", msg);
}
return SafePrintf ("MSG \"%\" %", msg, CHK::PlayersByName[m_PlayerId]);
}
private:
std::string m_Message;
int m_PlayerId;
};
class IRJmpInstruction : public IIRInstruction
{
public:
IRJmpInstruction (int offset, bool absolute = false) :
m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::Jmp)
{}
int GetOffset () const
{
return m_Offset;
}
void SetOffset (int offset)
{
m_Offset = offset;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JMP %", m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JMP +%", m_Offset);
}
else
{
return SafePrintf ("JMP %", m_Offset);
}
}
}
private:
int m_Offset = 0;
bool m_IsAbsolute = false;
};
class IRJmpIfEqInstruction : public IIRInstruction
{
public:
IRJmpIfEqInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Offset (offset), m_IsAbsolute (absolute), m_Value(value), IIRInstruction (IRInstructionType::JmpIfEq)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JEQ % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JEQ % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JEQ % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfNotEqInstruction : public IIRInstruction
{
public:
IRJmpIfNotEqInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Value(value), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfNotEq)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JNE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JNE % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JNE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfLessInstruction : public IIRInstruction
{
public:
IRJmpIfLessInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Value(value), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfLess)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JLT % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JLT % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JLT % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfGrtInstruction : public IIRInstruction
{
public:
IRJmpIfGrtInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Value(value), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfGrt)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JGT % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JGT % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JGT % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfLessOrEqualInstruction : public IIRInstruction
{
public:
IRJmpIfLessOrEqualInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Value(value), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfLessOrEq)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JLE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JLE % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JLE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfGrtOrEqualInstruction : public IIRInstruction
{
public:
IRJmpIfGrtOrEqualInstruction (unsigned int regId, unsigned int value, int offset, bool absolute = false) :
m_RegisterId (regId), m_Value(value), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfGrtOrEq)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetRegisterId () const
{
return m_RegisterId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
unsigned int GetValue() const
{
return m_Value;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JGE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JGE % % +%", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
else
{
return SafePrintf ("JGE % % %", RegisterIdToString (m_RegisterId), m_Value, m_Offset);
}
}
}
private:
unsigned int m_RegisterId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
unsigned int m_Value;
};
class IRJmpIfSwNotSetInstruction : public IIRInstruction
{
public:
IRJmpIfSwNotSetInstruction (unsigned int switchId, int offset, bool absolute = false) :
m_SwitchId (switchId), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfSwNotSet)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetSwitchId () const
{
return m_SwitchId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JSNS % %", SwitchToString (m_SwitchId), m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JSNS % +%", SwitchToString (m_SwitchId), m_Offset);
}
else
{
return SafePrintf ("JSNS % %", SwitchToString (m_SwitchId), m_Offset);
}
}
}
private:
unsigned int m_SwitchId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
};
class IRJmpIfSwSetInstruction : public IIRInstruction
{
public:
IRJmpIfSwSetInstruction (unsigned int switchId, int offset, bool absolute = false) :
m_SwitchId (switchId), m_Offset (offset), m_IsAbsolute (absolute), IIRInstruction (IRInstructionType::JmpIfSwSet)
{}
int GetOffset () const
{
return m_Offset;
}
unsigned int GetSwitchId () const
{
return m_SwitchId;
}
bool IsAbsolute () const
{
return m_IsAbsolute;
}
std::string DebugDump () const
{
if (m_IsAbsolute)
{
return SafePrintf ("JSS % %", SwitchToString (m_SwitchId), m_Offset);
}
else
{
if (m_Offset >= 0)
{
return SafePrintf ("JSS % +%", SwitchToString (m_SwitchId), m_Offset);
}
else
{
return SafePrintf ("JSS % %", SwitchToString (m_SwitchId), m_Offset);
}
}
}
private:
unsigned int m_SwitchId = 0;
int m_Offset = 0;
bool m_IsAbsolute = false;
};
class IRSetSwInstruction : public IIRInstruction
{
public:
IRSetSwInstruction (unsigned int switchId, bool state) :
m_SwitchId (switchId), m_State (state), IIRInstruction (IRInstructionType::SetSw)
{}
unsigned int GetSwitchId () const
{
return m_SwitchId;
}
bool GetState () const
{
return m_State;
}
std::string DebugDump () const
{
return SafePrintf ("SETSW % %", SwitchToString (m_SwitchId), m_State);
}
private:
unsigned int m_SwitchId = 0;
bool m_State;
};
class IRChkPlayers : public IIRInstruction
{
public:
IRChkPlayers () : IIRInstruction (IRInstructionType::ChkPlayers)
{}
std::string DebugDump () const
{
return "CHKPLAYERS";
}
};
class IRIsPresentInstruction : public IIRInstruction
{
public:
IRIsPresentInstruction () : IIRInstruction (IRInstructionType::IsPresent)
{}
std::string DebugDump () const
{
std::string s = "ISPRESENT";
for (auto& playerId : m_PlayerIds)
{
s = SafePrintf("% %", s, CHK::PlayersByName[playerId]);
}
return s;
}