@@ -108,6 +108,88 @@ def withRegisterResult : WithDifferentResult<"ToStack", "ToReg">;
108
108
109
109
include "EraVMOpcodes.td"
110
110
111
+ //===----------------------------------------------------------------------===//
112
+ // EraVM Operand Definitions.
113
+ //===----------------------------------------------------------------------===//
114
+
115
+ def UImm16Operand : AsmOperandClass {
116
+ let Name = "UImm16";
117
+ let ParserMethod = "tryParseUImm16Operand";
118
+ let PredicateMethod = "isImm";
119
+ let RenderMethod = "addImmOperands";
120
+ }
121
+
122
+ def imm16 : Operand<i256>, IntImmLeaf<i256, [{
123
+ return Imm.isIntN(16);
124
+ }]> {
125
+ let ParserMatchClass = UImm16Operand;
126
+ }
127
+
128
+ def neg_imm16 : Operand<i256>, IntImmLeaf<i256, [{
129
+ return Imm.isNegative() && Imm.abs().isIntN(16);
130
+ }]> {}
131
+
132
+ def large_imm : Operand<i256>, IntImmLeaf<i256, [{
133
+ return !Imm.abs().isIntN(16);
134
+ }]> {}
135
+
136
+ // This operand class represents those jump targets described
137
+ // as imm_in operand in the spec.
138
+ def JumpTargetOperand : AsmOperandClass {
139
+ let Name = "JumpTarget";
140
+ let ParserMethod = "tryParseJumpTargetOperand";
141
+ let PredicateMethod = "isImm";
142
+ let RenderMethod = "addImmOperands";
143
+ }
144
+
145
+ def jmptarget : Operand<OtherVT> {
146
+ let ParserMatchClass = JumpTargetOperand;
147
+ let EncoderMethod = "getJumpTargetValue";
148
+ }
149
+
150
+ // Address operands
151
+
152
+ def CodeOperand : AsmOperandClass {
153
+ let Name = "CodeReference";
154
+ let ParserMethod = "tryParseCodeOperand";
155
+ }
156
+
157
+ def memop : Operand<i256> {
158
+ let PrintMethod = "printMemOperand";
159
+ let EncoderMethod = "getMemOpValue";
160
+ let ParserMatchClass = CodeOperand;
161
+ let DecoderMethod = "DecodeCodeOperand";
162
+ let MIOperandInfo = (ops GR256, i16imm);
163
+ }
164
+
165
+ let ParserMethod = "tryParseStackOperand",
166
+ RenderMethod = "addStackReferenceOperands" in {
167
+ def StackInOperand : AsmOperandClass {
168
+ let Name = "StackInReference";
169
+ let PredicateMethod = "isStackReference<true>";
170
+ }
171
+ def StackOutOperand : AsmOperandClass {
172
+ let Name = "StackOutReference";
173
+ let PredicateMethod = "isStackReference<false>";
174
+ }
175
+ }
176
+
177
+ def stackin : Operand<i256> {
178
+ let PrintMethod = "printStackOperand<true>";
179
+ let EncoderMethod = "getStackOpValue<true>";
180
+ let ParserMatchClass = StackInOperand;
181
+ let DecoderMethod = "DecodeStackOperand";
182
+ let MIOperandInfo = (ops GRStackRefMarker, GR256, i16imm);
183
+ }
184
+
185
+ def stackout : Operand<i256> {
186
+ let PrintMethod = "printStackOperand<false>";
187
+ let EncoderMethod = "getStackOpValue<false>";
188
+ let ParserMatchClass = StackOutOperand;
189
+ let DecoderMethod = "DecodeStackOperand";
190
+ let MIOperandInfo = (ops GRStackRefMarker, GR256, i16imm);
191
+ }
192
+
111
193
//===----------------------------------------------------------------------===//
112
194
// EraVM Instructions
113
195
//===----------------------------------------------------------------------===//
@@ -346,21 +428,59 @@ class IBinaryS<EraVMOpcode opcode,
346
428
let Imm1 = dst0{19-4};
347
429
}
348
430
349
- class Irr_r<EraVMOpcode opcode,
350
- mod_swap swap_operands, mod_set_flags silent,
351
- dag outs, dag ins,
352
- string asmstr,
353
- list<dag> pattern>
354
- : IBinaryR<opcode, SrcReg, swap_operands, silent, outs, ins, asmstr, pattern> {
431
+ // Mix-in classes to hook standard fields for different combinations
432
+ // of input operands.
433
+
434
+ class SrcOperandsRR {
435
+ SrcOperandMode OperandAddrMode = OpndRR;
436
+
355
437
bits<4> rs0;
356
438
bits<4> rs1;
357
439
358
- let OperandAddrMode = OpndRR;
440
+ bits<4> Src0 = rs0;
441
+ bits<4> Src1 = rs1;
442
+ }
443
+
444
+ class SrcOperandsIR {
445
+ SrcOperandMode OperandAddrMode = OpndIR;
359
446
360
- let Src0 = rs0;
361
- let Src1 = rs1;
447
+ bits<16> imm;
448
+ bits<4> rs1;
449
+
450
+ bits<16> Imm0 = imm;
451
+ bits<4> Src1 = rs1;
452
+ }
453
+
454
+ class SrcOperandsMR {
455
+ SrcOperandMode OperandAddrMode = OpndCR;
456
+
457
+ bits<20> src0;
458
+ bits<4> rs1;
459
+
460
+ bits<4> Src0 = src0{3-0};
461
+ bits<16> Imm0 = src0{19-4};
462
+ bits<4> Src1 = rs1;
463
+ }
464
+
465
+ class SrcOperandsSR {
466
+ SrcOperandMode OperandAddrMode = OpndSR;
467
+
468
+ bits<20> src0;
469
+ bits<4> rs1;
470
+
471
+ bits<4> Src0 = src0{3-0};
472
+ bits<16> Imm0 = src0{19-4};
473
+ bits<4> Src1 = rs1;
362
474
}
363
475
476
+ class Irr_r<EraVMOpcode opcode,
477
+ mod_swap swap_operands, mod_set_flags silent,
478
+ dag outs, dag ins,
479
+ string asmstr,
480
+ list<dag> pattern>
481
+ : IBinaryR<opcode, SrcReg, swap_operands, silent, outs, ins, asmstr, pattern>,
482
+ SrcOperandsRR;
483
+
364
484
class Irr_rr<EraVMOpcode opcode,
365
485
mod_swap swap_operands, mod_set_flags silent,
366
486
dag outs, dag ins,
@@ -377,15 +497,8 @@ class Iir_r<EraVMOpcode opcode,
377
497
dag outs, dag ins,
378
498
string asmstr,
379
499
list<dag> pattern>
380
- : IBinaryR<opcode, SrcImm, swap_operands, silent, outs, ins, asmstr, pattern> {
381
- bits<4> rs1;
382
- bits<16> imm;
383
-
384
- let OperandAddrMode = OpndIR;
385
-
386
- let Src1 = rs1;
387
- let Imm0 = imm;
388
- }
500
+ : IBinaryR<opcode, SrcImm, swap_operands, silent, outs, ins, asmstr, pattern>,
501
+ SrcOperandsIR;
389
502
390
503
class Iir_rr<EraVMOpcode opcode,
391
504
mod_swap swap_operands, mod_set_flags silent,
@@ -403,32 +516,16 @@ class Imr_r<EraVMOpcode opcode,
403
516
dag outs, dag ins,
404
517
string asmstr,
405
518
list<dag> pattern>
406
- : IBinaryR<opcode, SrcCodeAddr, swap_operands, silent, outs, ins, asmstr, pattern> {
407
- bits<20> src0;
408
- bits<4> rs1;
409
-
410
- let OperandAddrMode = OpndCR;
411
-
412
- let Src0 = src0{3-0};
413
- let Imm0 = src0{19-4};
414
- let Src1 = rs1;
415
- }
519
+ : IBinaryR<opcode, SrcCodeAddr, swap_operands, silent, outs, ins, asmstr, pattern>,
520
+ SrcOperandsMR;
416
521
417
522
class Isr_r<EraVMOpcode opcode,
418
523
mod_swap swap_operands, mod_set_flags silent,
419
524
dag outs, dag ins,
420
525
string asmstr,
421
526
list<dag> pattern>
422
- : IBinaryR<opcode, SrcStackAbsolute, swap_operands, silent, outs, ins, asmstr, pattern> {
423
- bits<20> src0;
424
- bits<4> rs1;
425
-
426
- let OperandAddrMode = OpndSR;
427
-
428
- let Src0 = src0{3-0};
429
- let Src1 = rs1;
430
- let Imm0 = src0{19-4};
431
- }
527
+ : IBinaryR<opcode, SrcStackAbsolute, swap_operands, silent, outs, ins, asmstr, pattern>,
528
+ SrcOperandsSR;
432
529
433
530
class Imr_rr<EraVMOpcode opcode,
434
531
mod_swap swap_operands, mod_set_flags silent,
@@ -457,15 +554,8 @@ class Irr_s<EraVMOpcode opcode,
457
554
dag outs, dag ins,
458
555
string asmstr,
459
556
list<dag> pattern>
460
- : IBinaryS<opcode, SrcReg, swap_operands, silent, outs, ins, asmstr, pattern> {
461
- bits<4> rs0;
462
- bits<4> rs1;
463
-
464
- let OperandAddrMode = OpndRR;
465
-
466
- let Src0 = rs0;
467
- let Src1 = rs1;
468
- }
557
+ : IBinaryS<opcode, SrcReg, swap_operands, silent, outs, ins, asmstr, pattern>,
558
+ SrcOperandsRR;
469
559
470
560
class Irr_sr<EraVMOpcode opcode,
471
561
mod_swap swap_operands, mod_set_flags silent,
@@ -483,15 +573,8 @@ class Iir_s<EraVMOpcode opcode,
483
573
dag outs, dag ins,
484
574
string asmstr,
485
575
list<dag> pattern>
486
- : IBinaryS<opcode, SrcImm, swap_operands, silent, outs, ins, asmstr, pattern> {
487
- bits<16> imm;
488
- bits<4> rs1;
489
-
490
- let OperandAddrMode = OpndIR;
491
-
492
- let Imm0 = imm;
493
- let Src1 = rs1;
494
- }
576
+ : IBinaryS<opcode, SrcImm, swap_operands, silent, outs, ins, asmstr, pattern>,
577
+ SrcOperandsIR;
495
578
496
579
class Iir_sr<EraVMOpcode opcode,
497
580
mod_swap swap_operands, mod_set_flags silent,
@@ -509,32 +592,16 @@ class Imr_s<EraVMOpcode opcode,
509
592
dag outs, dag ins,
510
593
string asmstr,
511
594
list<dag> pattern>
512
- : IBinaryS<opcode, SrcCodeAddr, swap_operands, silent, outs, ins, asmstr, pattern> {
513
- bits<20> src0;
514
- bits<4> rs1;
515
-
516
- let OperandAddrMode = OpndCR;
517
-
518
- let Src0 = src0{3-0};
519
- let Imm0 = src0{19-4};
520
- let Src1 = rs1;
521
- }
595
+ : IBinaryS<opcode, SrcCodeAddr, swap_operands, silent, outs, ins, asmstr, pattern>,
596
+ SrcOperandsMR;
522
597
523
598
class Isr_s<EraVMOpcode opcode,
524
599
mod_swap swap_operands, mod_set_flags silent,
525
600
dag outs, dag ins,
526
601
string asmstr,
527
602
list<dag> pattern>
528
- : IBinaryS<opcode, SrcStackAbsolute, swap_operands, silent, outs, ins, asmstr, pattern> {
529
- bits<20> src0;
530
- bits<4> rs1;
531
-
532
- let OperandAddrMode = OpndSR;
533
-
534
- let Src0 = src0{3-0};
535
- let Src1 = rs1;
536
- let Imm0 = src0{19-4};
537
- }
603
+ : IBinaryS<opcode, SrcStackAbsolute, swap_operands, silent, outs, ins, asmstr, pattern>,
604
+ SrcOperandsSR;
538
605
539
606
class Imr_sr<EraVMOpcode opcode,
540
607
mod_swap swap_operands, mod_set_flags silent,
0 commit comments