xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- LanaiMCExpr.cpp - Lanai specific MC expression classes ------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "LanaiMCExpr.h"
100b57cec5SDimitry Andric #include "llvm/MC/MCAssembler.h"
110b57cec5SDimitry Andric #include "llvm/MC/MCContext.h"
120b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
130b57cec5SDimitry Andric using namespace llvm;
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #define DEBUG_TYPE "lanaimcexpr"
160b57cec5SDimitry Andric 
create(VariantKind Kind,const MCExpr * Expr,MCContext & Ctx)170b57cec5SDimitry Andric const LanaiMCExpr *LanaiMCExpr::create(VariantKind Kind, const MCExpr *Expr,
180b57cec5SDimitry Andric                                        MCContext &Ctx) {
190b57cec5SDimitry Andric   return new (Ctx) LanaiMCExpr(Kind, Expr);
200b57cec5SDimitry Andric }
210b57cec5SDimitry Andric 
printImpl(raw_ostream & OS,const MCAsmInfo * MAI) const220b57cec5SDimitry Andric void LanaiMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
230b57cec5SDimitry Andric   if (Kind == VK_Lanai_None) {
240b57cec5SDimitry Andric     Expr->print(OS, MAI);
250b57cec5SDimitry Andric     return;
260b57cec5SDimitry Andric   }
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric   switch (Kind) {
290b57cec5SDimitry Andric   default:
300b57cec5SDimitry Andric     llvm_unreachable("Invalid kind!");
310b57cec5SDimitry Andric   case VK_Lanai_ABS_HI:
320b57cec5SDimitry Andric     OS << "hi";
330b57cec5SDimitry Andric     break;
340b57cec5SDimitry Andric   case VK_Lanai_ABS_LO:
350b57cec5SDimitry Andric     OS << "lo";
360b57cec5SDimitry Andric     break;
370b57cec5SDimitry Andric   }
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric   OS << '(';
400b57cec5SDimitry Andric   const MCExpr *Expr = getSubExpr();
410b57cec5SDimitry Andric   Expr->print(OS, MAI);
420b57cec5SDimitry Andric   OS << ')';
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric 
visitUsedExpr(MCStreamer & Streamer) const450b57cec5SDimitry Andric void LanaiMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
460b57cec5SDimitry Andric   Streamer.visitUsedExpr(*getSubExpr());
470b57cec5SDimitry Andric }
480b57cec5SDimitry Andric 
evaluateAsRelocatableImpl(MCValue & Res,const MCAssembler * Asm,const MCFixup * Fixup) const490b57cec5SDimitry Andric bool LanaiMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
50*0fca6ea1SDimitry Andric                                             const MCAssembler *Asm,
510b57cec5SDimitry Andric                                             const MCFixup *Fixup) const {
52*0fca6ea1SDimitry Andric   if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
530b57cec5SDimitry Andric     return false;
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   Res =
560b57cec5SDimitry Andric       MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   return true;
590b57cec5SDimitry Andric }
60