9
9
#include " LanaiAluCode.h"
10
10
#include " LanaiCondCode.h"
11
11
#include " LanaiInstrInfo.h"
12
- #include " MCTargetDesc/LanaiMCExpr .h"
12
+ #include " MCTargetDesc/LanaiMCAsmInfo .h"
13
13
#include " TargetInfo/LanaiTargetInfo.h"
14
14
#include " llvm/ADT/StringRef.h"
15
15
#include " llvm/ADT/StringSwitch.h"
@@ -231,14 +231,14 @@ struct LanaiOperand : public MCParsedAsmOperand {
231
231
}
232
232
233
233
// Symbolic reference expression
234
- if (const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr >(Imm.Value ))
235
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_HI ;
234
+ if (const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr >(Imm.Value ))
235
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_HI ;
236
236
237
237
// Binary expression
238
238
if (const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(Imm.Value ))
239
- if (const LanaiMCExpr *SymbolRefExpr =
240
- dyn_cast<LanaiMCExpr >(BinaryExpr->getLHS ()))
241
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_HI ;
239
+ if (const auto *SymbolRefExpr =
240
+ dyn_cast<MCSpecifierExpr >(BinaryExpr->getLHS ()))
241
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_HI ;
242
242
243
243
return false ;
244
244
}
@@ -268,14 +268,14 @@ struct LanaiOperand : public MCParsedAsmOperand {
268
268
}
269
269
270
270
// Symbolic reference expression
271
- if (const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr >(Imm.Value ))
272
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_LO ;
271
+ if (const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr >(Imm.Value ))
272
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_LO ;
273
273
274
274
// Binary expression
275
275
if (const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(Imm.Value ))
276
- if (const LanaiMCExpr *SymbolRefExpr =
277
- dyn_cast<LanaiMCExpr >(BinaryExpr->getLHS ()))
278
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_LO ;
276
+ if (const auto *SymbolRefExpr =
277
+ dyn_cast<MCSpecifierExpr >(BinaryExpr->getLHS ()))
278
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_LO ;
279
279
280
280
return false ;
281
281
}
@@ -292,14 +292,14 @@ struct LanaiOperand : public MCParsedAsmOperand {
292
292
}
293
293
294
294
// Symbolic reference expression
295
- if (const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr >(Imm.Value ))
296
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_LO ;
295
+ if (const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr >(Imm.Value ))
296
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_LO ;
297
297
298
298
// Binary expression
299
299
if (const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(Imm.Value ))
300
- if (const LanaiMCExpr *SymbolRefExpr =
301
- dyn_cast<LanaiMCExpr >(BinaryExpr->getLHS ()))
302
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_LO ;
300
+ if (const auto *SymbolRefExpr =
301
+ dyn_cast<MCSpecifierExpr >(BinaryExpr->getLHS ()))
302
+ return SymbolRefExpr->getSpecifier () == Lanai::S_ABS_LO ;
303
303
304
304
return false ;
305
305
}
@@ -339,18 +339,18 @@ struct LanaiOperand : public MCParsedAsmOperand {
339
339
}
340
340
341
341
// Symbolic reference expression
342
- if (const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr >(Imm.Value ))
343
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_None ;
342
+ if (const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr >(Imm.Value ))
343
+ return SymbolRefExpr->getSpecifier () == Lanai::S_None ;
344
344
if (const MCSymbolRefExpr *SymbolRefExpr =
345
345
dyn_cast<MCSymbolRefExpr>(Imm.Value )) {
346
346
return SymbolRefExpr->getKind () == MCSymbolRefExpr::VK_None;
347
347
}
348
348
349
349
// Binary expression
350
350
if (const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(Imm.Value )) {
351
- if (const LanaiMCExpr *SymbolRefExpr =
352
- dyn_cast<LanaiMCExpr >(BinaryExpr->getLHS ()))
353
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_None ;
351
+ if (const auto *SymbolRefExpr =
352
+ dyn_cast<MCSpecifierExpr >(BinaryExpr->getLHS ()))
353
+ return SymbolRefExpr->getSpecifier () == Lanai::S_None ;
354
354
if (const MCSymbolRefExpr *SymbolRefExpr =
355
355
dyn_cast<MCSymbolRefExpr>(BinaryExpr->getLHS ()))
356
356
return SymbolRefExpr->getKind () == MCSymbolRefExpr::VK_None;
@@ -464,19 +464,18 @@ struct LanaiOperand : public MCParsedAsmOperand {
464
464
if (const MCConstantExpr *ConstExpr = dyn_cast<MCConstantExpr>(getImm ()))
465
465
Inst.addOperand (
466
466
MCOperand::createImm (static_cast <int32_t >(ConstExpr->getValue ())));
467
- else if (isa<LanaiMCExpr >(getImm ())) {
467
+ else if (isa<MCSpecifierExpr >(getImm ())) {
468
468
#ifndef NDEBUG
469
- const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr>(getImm ());
470
- assert (SymbolRefExpr &&
471
- SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_LO);
469
+ const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr>(getImm ());
470
+ assert (SymbolRefExpr && SymbolRefExpr->getSpecifier () == Lanai::S_ABS_LO);
472
471
#endif
473
472
Inst.addOperand (MCOperand::createExpr (getImm ()));
474
473
} else if (isa<MCBinaryExpr>(getImm ())) {
475
474
#ifndef NDEBUG
476
475
const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(getImm ());
477
- assert (BinaryExpr && isa<LanaiMCExpr >(BinaryExpr->getLHS ()) &&
478
- cast<LanaiMCExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
479
- LanaiMCExpr::VK_Lanai_ABS_LO );
476
+ assert (BinaryExpr && isa<MCSpecifierExpr >(BinaryExpr->getLHS ()) &&
477
+ cast<MCSpecifierExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
478
+ Lanai::S_ABS_LO );
480
479
#endif
481
480
Inst.addOperand (MCOperand::createExpr (getImm ()));
482
481
} else
@@ -495,19 +494,18 @@ struct LanaiOperand : public MCParsedAsmOperand {
495
494
assert (N == 1 && " Invalid number of operands!" );
496
495
if (const MCConstantExpr *ConstExpr = dyn_cast<MCConstantExpr>(getImm ()))
497
496
Inst.addOperand (MCOperand::createImm (ConstExpr->getValue () >> 16 ));
498
- else if (isa<LanaiMCExpr >(getImm ())) {
497
+ else if (isa<MCSpecifierExpr >(getImm ())) {
499
498
#ifndef NDEBUG
500
- const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr>(getImm ());
501
- assert (SymbolRefExpr &&
502
- SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_ABS_HI);
499
+ const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr>(getImm ());
500
+ assert (SymbolRefExpr && SymbolRefExpr->getSpecifier () == Lanai::S_ABS_HI);
503
501
#endif
504
502
Inst.addOperand (MCOperand::createExpr (getImm ()));
505
503
} else if (isa<MCBinaryExpr>(getImm ())) {
506
504
#ifndef NDEBUG
507
505
const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(getImm ());
508
- assert (BinaryExpr && isa<LanaiMCExpr >(BinaryExpr->getLHS ()) &&
509
- cast<LanaiMCExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
510
- LanaiMCExpr::VK_Lanai_ABS_HI );
506
+ assert (BinaryExpr && isa<MCSpecifierExpr >(BinaryExpr->getLHS ()) &&
507
+ cast<MCSpecifierExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
508
+ Lanai::S_ABS_HI );
511
509
#endif
512
510
Inst.addOperand (MCOperand::createExpr (getImm ()));
513
511
} else
@@ -526,11 +524,10 @@ struct LanaiOperand : public MCParsedAsmOperand {
526
524
assert (N == 1 && " Invalid number of operands!" );
527
525
if (const MCConstantExpr *ConstExpr = dyn_cast<MCConstantExpr>(getImm ()))
528
526
Inst.addOperand (MCOperand::createImm (ConstExpr->getValue () & 0x1fffff ));
529
- else if (isa<LanaiMCExpr >(getImm ())) {
527
+ else if (isa<MCSpecifierExpr >(getImm ())) {
530
528
#ifndef NDEBUG
531
- const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr>(getImm ());
532
- assert (SymbolRefExpr &&
533
- SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_None);
529
+ const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr>(getImm ());
530
+ assert (SymbolRefExpr && SymbolRefExpr->getSpecifier () == Lanai::S_None);
534
531
#endif
535
532
Inst.addOperand (MCOperand::createExpr (getImm ()));
536
533
} else if (isa<MCSymbolRefExpr>(getImm ())) {
@@ -544,9 +541,9 @@ struct LanaiOperand : public MCParsedAsmOperand {
544
541
} else if (isa<MCBinaryExpr>(getImm ())) {
545
542
#ifndef NDEBUG
546
543
const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(getImm ());
547
- assert (BinaryExpr && isa<LanaiMCExpr >(BinaryExpr->getLHS ()) &&
548
- cast<LanaiMCExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
549
- LanaiMCExpr::VK_Lanai_None );
544
+ assert (BinaryExpr && isa<MCSpecifierExpr >(BinaryExpr->getLHS ()) &&
545
+ cast<MCSpecifierExpr >(BinaryExpr->getLHS ())->getSpecifier () ==
546
+ Lanai::S_None );
550
547
#endif
551
548
Inst.addOperand (MCOperand::createExpr (getImm ()));
552
549
} else
@@ -737,7 +734,7 @@ std::unique_ptr<LanaiOperand> LanaiAsmParser::parseIdentifier() {
737
734
SMLoc Start = Parser.getTok ().getLoc ();
738
735
SMLoc End = SMLoc::getFromPointer (Parser.getTok ().getLoc ().getPointer () - 1 );
739
736
const MCExpr *Res, *RHS = nullptr ;
740
- LanaiMCExpr::Spec Kind = LanaiMCExpr::VK_Lanai_None ;
737
+ auto Kind = Lanai::S_None ;
741
738
742
739
if (Lexer.getKind () != AsmToken::Identifier)
743
740
return nullptr ;
@@ -748,13 +745,13 @@ std::unique_ptr<LanaiOperand> LanaiAsmParser::parseIdentifier() {
748
745
749
746
// Check if identifier has a modifier
750
747
if (Identifier.equals_insensitive (" hi" ))
751
- Kind = LanaiMCExpr::VK_Lanai_ABS_HI ;
748
+ Kind = Lanai::S_ABS_HI ;
752
749
else if (Identifier.equals_insensitive (" lo" ))
753
- Kind = LanaiMCExpr::VK_Lanai_ABS_LO ;
750
+ Kind = Lanai::S_ABS_LO ;
754
751
755
752
// If the identifier corresponds to a variant then extract the real
756
753
// identifier.
757
- if (Kind != LanaiMCExpr::VK_Lanai_None ) {
754
+ if (Kind != Lanai::S_None ) {
758
755
if (Lexer.getKind () != AsmToken::LParen) {
759
756
Error (Lexer.getLoc (), " Expected '('" );
760
757
return nullptr ;
@@ -771,7 +768,7 @@ std::unique_ptr<LanaiOperand> LanaiAsmParser::parseIdentifier() {
771
768
return nullptr ;
772
769
773
770
// For variants parse the final ')'
774
- if (Kind != LanaiMCExpr::VK_Lanai_None ) {
771
+ if (Kind != Lanai::S_None ) {
775
772
if (Lexer.getKind () != AsmToken::RParen) {
776
773
Error (Lexer.getLoc (), " Expected ')'" );
777
774
return nullptr ;
@@ -781,8 +778,7 @@ std::unique_ptr<LanaiOperand> LanaiAsmParser::parseIdentifier() {
781
778
782
779
End = SMLoc::getFromPointer (Parser.getTok ().getLoc ().getPointer () - 1 );
783
780
MCSymbol *Sym = getContext ().getOrCreateSymbol (Identifier);
784
- const MCExpr *Expr = MCSymbolRefExpr::create (Sym, getContext ());
785
- Res = LanaiMCExpr::create (Kind, Expr, getContext ());
781
+ Res = MCSpecifierExpr::create (Sym, Kind, getContext ());
786
782
787
783
// Nest if this was an addition
788
784
if (RHS)
@@ -865,16 +861,16 @@ bool shouldBeSls(const LanaiOperand &Op) {
865
861
}
866
862
// The instruction should be encoded as an SLS if the operand is a symbolic
867
863
// reference with no variant.
868
- if (const LanaiMCExpr *SymbolRefExpr = dyn_cast<LanaiMCExpr >(Op.getImm ()))
869
- return SymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_None ;
864
+ if (const auto *SymbolRefExpr = dyn_cast<MCSpecifierExpr >(Op.getImm ()))
865
+ return SymbolRefExpr->getSpecifier () == Lanai::S_None ;
870
866
// The instruction should be encoded as an SLS if the operand is a binary
871
867
// expression with the left-hand side being a symbolic reference with no
872
868
// variant.
873
869
if (const MCBinaryExpr *BinaryExpr = dyn_cast<MCBinaryExpr>(Op.getImm ())) {
874
- const LanaiMCExpr *LHSSymbolRefExpr =
875
- dyn_cast<LanaiMCExpr >(BinaryExpr->getLHS ());
870
+ const auto *LHSSymbolRefExpr =
871
+ dyn_cast<MCSpecifierExpr >(BinaryExpr->getLHS ());
876
872
return (LHSSymbolRefExpr &&
877
- LHSSymbolRefExpr->getSpecifier () == LanaiMCExpr::VK_Lanai_None );
873
+ LHSSymbolRefExpr->getSpecifier () == Lanai::S_None );
878
874
}
879
875
return false ;
880
876
}
0 commit comments