@@ -77,6 +77,10 @@ class SparcAsmParser : public MCTargetAsmParser {
77
77
bool parseDirectiveWord (unsigned Size, SMLoc L);
78
78
79
79
bool is64Bit () const { return STI.getTargetTriple ().startswith (" sparcv9" ); }
80
+
81
+ void expandSET (MCInst &Inst, SMLoc IDLoc,
82
+ SmallVectorImpl<MCInst> &Instructions);
83
+
80
84
public:
81
85
SparcAsmParser (MCSubtargetInfo &sti, MCAsmParser &parser,
82
86
const MCInstrInfo &MII,
@@ -392,6 +396,49 @@ class SparcOperand : public MCParsedAsmOperand {
392
396
393
397
} // end namespace
394
398
399
+ void SparcAsmParser::expandSET (MCInst &Inst, SMLoc IDLoc,
400
+ SmallVectorImpl<MCInst> &Instructions) {
401
+ MCOperand MCRegOp = Inst.getOperand (0 );
402
+ MCOperand MCValOp = Inst.getOperand (1 );
403
+ assert (MCRegOp.isReg ());
404
+ assert (MCValOp.isImm () || MCValOp.isExpr ());
405
+
406
+ // the imm operand can be either an expression or an immediate.
407
+ bool IsImm = Inst.getOperand (1 ).isImm ();
408
+ uint64_t ImmValue = IsImm ? MCValOp.getImm () : 0 ;
409
+ const MCExpr *ValExpr;
410
+ if (IsImm)
411
+ ValExpr = MCConstantExpr::Create (ImmValue, getContext ());
412
+ else
413
+ ValExpr = MCValOp.getExpr ();
414
+
415
+ MCOperand PrevReg = MCOperand::createReg (Sparc::G0);
416
+
417
+ if (!IsImm || (ImmValue & ~0x1fff )) {
418
+ MCInst TmpInst;
419
+ const MCExpr *Expr =
420
+ SparcMCExpr::Create (SparcMCExpr::VK_Sparc_HI, ValExpr, getContext ());
421
+ TmpInst.setLoc (IDLoc);
422
+ TmpInst.setOpcode (SP::SETHIi);
423
+ TmpInst.addOperand (MCRegOp);
424
+ TmpInst.addOperand (MCOperand::createExpr (Expr));
425
+ Instructions.push_back (TmpInst);
426
+ PrevReg = MCRegOp;
427
+ }
428
+
429
+ if (!IsImm || ((ImmValue & 0x1fff ) != 0 || ImmValue == 0 )) {
430
+ MCInst TmpInst;
431
+ const MCExpr *Expr =
432
+ SparcMCExpr::Create (SparcMCExpr::VK_Sparc_LO, ValExpr, getContext ());
433
+ TmpInst.setLoc (IDLoc);
434
+ TmpInst.setOpcode (SP::ORri);
435
+ TmpInst.addOperand (MCRegOp);
436
+ TmpInst.addOperand (PrevReg);
437
+ TmpInst.addOperand (MCOperand::createExpr (Expr));
438
+ Instructions.push_back (TmpInst);
439
+ }
440
+ }
441
+
395
442
bool SparcAsmParser::MatchAndEmitInstruction (SMLoc IDLoc, unsigned &Opcode,
396
443
OperandVector &Operands,
397
444
MCStreamer &Out,
@@ -403,8 +450,19 @@ bool SparcAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
403
450
MatchingInlineAsm);
404
451
switch (MatchResult) {
405
452
case Match_Success: {
406
- Inst.setLoc (IDLoc);
407
- Out.EmitInstruction (Inst, STI);
453
+ switch (Inst.getOpcode ()) {
454
+ default :
455
+ Inst.setLoc (IDLoc);
456
+ Instructions.push_back (Inst);
457
+ break ;
458
+ case SP::SET:
459
+ expandSET (Inst, IDLoc, Instructions);
460
+ break ;
461
+ }
462
+
463
+ for (const MCInst &I : Instructions) {
464
+ Out.EmitInstruction (I, STI);
465
+ }
408
466
return false ;
409
467
}
410
468
0 commit comments