1 //===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "NVPTXMCExpr.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
16 #define DEBUG_TYPE "nvptx-mcexpr"
18 const NVPTXFloatMCExpr *
19 NVPTXFloatMCExpr::create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx) {
20 return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
23 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
26 APFloat APF = getAPFloat();
29 default: llvm_unreachable("Invalid kind!");
30 case VK_NVPTX_SINGLE_PREC_FLOAT:
33 APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored);
35 case VK_NVPTX_DOUBLE_PREC_FLOAT:
38 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored);
42 APInt API = APF.bitcastToAPInt();
43 std::string HexStr(utohexstr(API.getZExtValue()));
44 if (HexStr.length() < NumHex)
45 OS << std::string(NumHex - HexStr.length(), '0');
46 OS << utohexstr(API.getZExtValue());
49 const NVPTXGenericMCSymbolRefExpr*
50 NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr *SymExpr,
52 return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
55 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS,
56 const MCAsmInfo *MAI) const {
58 SymExpr->print(OS, MAI);