xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp (revision 5fb307d29b364982acbde82cbf77db3cae486f8c)
1 //===-- SystemZMCExpr.cpp - SystemZ specific MC expression classes --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "SystemZMCExpr.h"
10 #include "llvm/MC/MCContext.h"
11 using namespace llvm;
12 
13 #define DEBUG_TYPE "systemzmcexpr"
14 
15 const SystemZMCExpr *SystemZMCExpr::create(VariantKind Kind, const MCExpr *Expr,
16                                            MCContext &Ctx) {
17   return new (Ctx) SystemZMCExpr(Kind, Expr);
18 }
19 
20 StringRef SystemZMCExpr::getVariantKindName() const {
21   switch (static_cast<uint32_t>(getKind())) {
22   case VK_SystemZ_None:
23     return "A";
24   case VK_SystemZ_RCon:
25     return "R";
26   case VK_SystemZ_VCon:
27     return "V";
28   default:
29     llvm_unreachable("Invalid kind");
30   }
31 }
32 
33 void SystemZMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
34   OS << getVariantKindName() << '(';
35   Expr->print(OS, MAI);
36   OS << ')';
37 }
38 
39 bool SystemZMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
40                                               const MCAsmLayout *Layout,
41                                               const MCFixup *Fixup) const {
42   if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
43     return false;
44 
45   Res =
46       MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
47 
48   return true;
49 }
50