1 | //===-- HexagonMCExpr.cpp - Hexagon specific MC expression classes |
2 | //----------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #include "HexagonMCExpr.h" |
11 | #include "llvm/BinaryFormat/ELF.h" |
12 | #include "llvm/MC/MCContext.h" |
13 | #include "llvm/MC/MCStreamer.h" |
14 | #include "llvm/MC/MCSymbolELF.h" |
15 | #include "llvm/MC/MCValue.h" |
16 | #include "llvm/Support/Casting.h" |
17 | #include "llvm/Support/raw_ostream.h" |
18 | |
19 | using namespace llvm; |
20 | |
21 | #define DEBUG_TYPE "hexagon-mcexpr" |
22 | |
23 | HexagonMCExpr *HexagonMCExpr::create(MCExpr const *Expr, MCContext &Ctx) { |
24 | return new (Ctx) HexagonMCExpr(Expr); |
25 | } |
26 | |
27 | bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res, |
28 | const MCAssembler *Asm, |
29 | MCFixup const *Fixup) const { |
30 | return Expr->evaluateAsRelocatable(Res, Asm, Fixup); |
31 | } |
32 | |
33 | void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const { |
34 | Streamer.visitUsedExpr(Expr: *Expr); |
35 | } |
36 | |
37 | MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const { |
38 | return Expr->findAssociatedFragment(); |
39 | } |
40 | |
41 | static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { |
42 | switch (Expr->getKind()) { |
43 | case MCExpr::Target: |
44 | llvm_unreachable("Cannot handle nested target MCExpr" ); |
45 | break; |
46 | case MCExpr::Constant: |
47 | break; |
48 | |
49 | case MCExpr::Binary: { |
50 | const MCBinaryExpr *be = cast<MCBinaryExpr>(Val: Expr); |
51 | fixELFSymbolsInTLSFixupsImpl(Expr: be->getLHS(), Asm); |
52 | fixELFSymbolsInTLSFixupsImpl(Expr: be->getRHS(), Asm); |
53 | break; |
54 | } |
55 | case MCExpr::SymbolRef: { |
56 | const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Val: Expr); |
57 | switch (symRef.getKind()) { |
58 | default: |
59 | return; |
60 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
61 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
62 | case MCSymbolRefExpr::VK_Hexagon_GD_PLT: |
63 | case MCSymbolRefExpr::VK_Hexagon_LD_PLT: |
64 | case MCSymbolRefExpr::VK_Hexagon_IE: |
65 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
66 | case MCSymbolRefExpr::VK_TPREL: |
67 | break; |
68 | } |
69 | cast<MCSymbolELF>(Val: symRef.getSymbol()).setType(ELF::STT_TLS); |
70 | break; |
71 | } |
72 | case MCExpr::Unary: |
73 | fixELFSymbolsInTLSFixupsImpl(Expr: cast<MCUnaryExpr>(Val: Expr)->getSubExpr(), Asm); |
74 | break; |
75 | } |
76 | } |
77 | |
78 | void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const { |
79 | auto expr = getExpr(); |
80 | fixELFSymbolsInTLSFixupsImpl(Expr: expr, Asm); |
81 | } |
82 | |
83 | MCExpr const *HexagonMCExpr::getExpr() const { return Expr; } |
84 | |
85 | void HexagonMCExpr::setMustExtend(bool Val) { |
86 | assert((!Val || !MustNotExtend) && "Extension contradiction" ); |
87 | MustExtend = Val; |
88 | } |
89 | |
90 | bool HexagonMCExpr::mustExtend() const { return MustExtend; } |
91 | void HexagonMCExpr::setMustNotExtend(bool Val) { |
92 | assert((!Val || !MustExtend) && "Extension contradiction" ); |
93 | MustNotExtend = Val; |
94 | } |
95 | bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; } |
96 | |
97 | bool HexagonMCExpr::s27_2_reloc() const { return S27_2_reloc; } |
98 | void HexagonMCExpr::setS27_2_reloc(bool Val) { |
99 | S27_2_reloc = Val; |
100 | } |
101 | |
102 | HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr) |
103 | : Expr(Expr), MustNotExtend(false), MustExtend(false), S27_2_reloc(false), |
104 | SignMismatch(false) {} |
105 | |
106 | void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { |
107 | Expr->print(OS, MAI); |
108 | } |
109 | |
110 | void HexagonMCExpr::setSignMismatch(bool Val) { |
111 | SignMismatch = Val; |
112 | } |
113 | |
114 | bool HexagonMCExpr::signMismatch() const { |
115 | return SignMismatch; |
116 | } |
117 | |