1 //===-- XtensaMCExpr.cpp - Xtensa specific MC expression classes ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This file contains the implementation of the assembly expression modifiers
12 // accepted by the Xtensa architecture
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "XtensaMCExpr.h"
17 #include "llvm/MC/MCAssembler.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSymbolELF.h"
21 #include "llvm/MC/MCValue.h"
22 #include "llvm/Object/ELF.h"
23 #include "llvm/Support/ErrorHandling.h"
24
25 using namespace llvm;
26
27 #define DEBUG_TYPE "xtensamcexpr"
28
create(const MCExpr * Expr,VariantKind Kind,MCContext & Ctx)29 const XtensaMCExpr *XtensaMCExpr::create(const MCExpr *Expr, VariantKind Kind,
30 MCContext &Ctx) {
31 return new (Ctx) XtensaMCExpr(Expr, Kind);
32 }
33
printImpl(raw_ostream & OS,const MCAsmInfo * MAI) const34 void XtensaMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
35 bool HasVariant = getKind() != VK_Xtensa_None;
36 if (HasVariant)
37 OS << '%' << getVariantKindName(getKind()) << '(';
38 Expr->print(OS, MAI);
39 if (HasVariant)
40 OS << ')';
41 }
42
evaluateAsRelocatableImpl(MCValue & Res,const MCAssembler * Asm,const MCFixup * Fixup) const43 bool XtensaMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
44 const MCAssembler *Asm,
45 const MCFixup *Fixup) const {
46 return getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup);
47 }
48
visitUsedExpr(MCStreamer & Streamer) const49 void XtensaMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
50 Streamer.visitUsedExpr(*getSubExpr());
51 }
52
getVariantKindForName(StringRef name)53 XtensaMCExpr::VariantKind XtensaMCExpr::getVariantKindForName(StringRef name) {
54 return StringSwitch<XtensaMCExpr::VariantKind>(name).Default(
55 VK_Xtensa_Invalid);
56 }
57
getVariantKindName(VariantKind Kind)58 StringRef XtensaMCExpr::getVariantKindName(VariantKind Kind) {
59 switch (Kind) {
60 default:
61 llvm_unreachable("Invalid ELF symbol kind");
62 }
63 }
64