1313
1414#include " RISCVMCExpr.h"
1515#include " MCTargetDesc/RISCVAsmBackend.h"
16+ #include " MCTargetDesc/RISCVMCAsmInfo.h"
1617#include " RISCVFixupKinds.h"
1718#include " llvm/BinaryFormat/ELF.h"
1819#include " llvm/MC/MCAssembler.h"
@@ -31,65 +32,8 @@ const RISCVMCExpr *RISCVMCExpr::create(const MCExpr *Expr, Specifier S,
3132 return new (Ctx) RISCVMCExpr (Expr, S);
3233}
3334
34- void RISCVMCExpr::printImpl (raw_ostream &OS, const MCAsmInfo *MAI) const {
35- Specifier S = getSpecifier ();
36- bool HasVariant = S != RISCV::S_None && S != ELF::R_RISCV_CALL_PLT;
37-
38- if (HasVariant)
39- OS << ' %' << getSpecifierName (S) << ' (' ;
40- Expr->print (OS, MAI);
41- if (HasVariant)
42- OS << ' )' ;
43- }
44-
45- const MCFixup *RISCVMCExpr::getPCRelHiFixup (const MCFragment **DFOut) const {
46- MCValue AUIPCLoc;
47- if (!getSubExpr ()->evaluateAsRelocatable (AUIPCLoc, nullptr ))
48- return nullptr ;
49-
50- const MCSymbol *AUIPCSymbol = AUIPCLoc.getAddSym ();
51- if (!AUIPCSymbol)
52- return nullptr ;
53- const auto *DF = dyn_cast_or_null<MCDataFragment>(AUIPCSymbol->getFragment ());
54-
55- if (!DF)
56- return nullptr ;
57-
58- uint64_t Offset = AUIPCSymbol->getOffset ();
59- if (DF->getContents ().size () == Offset) {
60- DF = dyn_cast_or_null<MCDataFragment>(DF->getNext ());
61- if (!DF)
62- return nullptr ;
63- Offset = 0 ;
64- }
65-
66- for (const MCFixup &F : DF->getFixups ()) {
67- if (F.getOffset () != Offset)
68- continue ;
69- auto Kind = F.getTargetKind ();
70- if (!mc::isRelocation (F.getKind ())) {
71- if (Kind == RISCV::fixup_riscv_pcrel_hi20) {
72- *DFOut = DF;
73- return &F;
74- }
75- break ;
76- }
77- switch (Kind) {
78- case ELF::R_RISCV_GOT_HI20:
79- case ELF::R_RISCV_TLS_GOT_HI20:
80- case ELF::R_RISCV_TLS_GD_HI20:
81- case ELF::R_RISCV_TLSDESC_HI20:
82- *DFOut = DF;
83- return &F;
84- }
85- }
86-
87- return nullptr ;
88- }
89-
90- std::optional<RISCVMCExpr::Specifier>
91- RISCVMCExpr::getSpecifierForName (StringRef name) {
92- return StringSwitch<std::optional<RISCVMCExpr::Specifier>>(name)
35+ RISCV::Specifier RISCV::parseSpecifierName (StringRef name) {
36+ return StringSwitch<RISCV::Specifier>(name)
9337 .Case (" lo" , RISCV::S_LO)
9438 .Case (" hi" , ELF::R_RISCV_HI20)
9539 .Case (" pcrel_lo" , RISCV::S_PCREL_LO)
@@ -108,10 +52,10 @@ RISCVMCExpr::getSpecifierForName(StringRef name) {
10852 // Used in data directives
10953 .Case (" pltpcrel" , ELF::R_RISCV_PLT32)
11054 .Case (" gotpcrel" , ELF::R_RISCV_GOT32_PCREL)
111- .Default (std:: nullopt );
55+ .Default (0 );
11256}
11357
114- StringRef RISCVMCExpr ::getSpecifierName (Specifier S) {
58+ StringRef RISCV ::getSpecifierName (Specifier S) {
11559 switch (S) {
11660 case RISCV::S_None:
11761 llvm_unreachable (" not used as %specifier()" );
0 commit comments