NVPTXMCExpr.cpp revision 259698
1259698Sdim//===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===// 2259698Sdim// 3259698Sdim// The LLVM Compiler Infrastructure 4259698Sdim// 5259698Sdim// This file is distributed under the University of Illinois Open Source 6259698Sdim// License. See LICENSE.TXT for details. 7259698Sdim// 8259698Sdim//===----------------------------------------------------------------------===// 9259698Sdim 10259698Sdim#define DEBUG_TYPE "nvptx-mcexpr" 11259698Sdim#include "NVPTXMCExpr.h" 12259698Sdim#include "llvm/ADT/StringExtras.h" 13259698Sdim#include "llvm/MC/MCAssembler.h" 14259698Sdim#include "llvm/MC/MCContext.h" 15259698Sdimusing namespace llvm; 16259698Sdim 17259698Sdimconst NVPTXFloatMCExpr* 18259698SdimNVPTXFloatMCExpr::Create(VariantKind Kind, APFloat Flt, MCContext &Ctx) { 19259698Sdim return new (Ctx) NVPTXFloatMCExpr(Kind, Flt); 20259698Sdim} 21259698Sdim 22259698Sdimvoid NVPTXFloatMCExpr::PrintImpl(raw_ostream &OS) const { 23259698Sdim bool Ignored; 24259698Sdim unsigned NumHex; 25259698Sdim APFloat APF = getAPFloat(); 26259698Sdim 27259698Sdim switch (Kind) { 28259698Sdim default: llvm_unreachable("Invalid kind!"); 29259698Sdim case VK_NVPTX_SINGLE_PREC_FLOAT: 30259698Sdim OS << "0f"; 31259698Sdim NumHex = 8; 32259698Sdim APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored); 33259698Sdim break; 34259698Sdim case VK_NVPTX_DOUBLE_PREC_FLOAT: 35259698Sdim OS << "0d"; 36259698Sdim NumHex = 16; 37259698Sdim APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored); 38259698Sdim break; 39259698Sdim } 40259698Sdim 41259698Sdim APInt API = APF.bitcastToAPInt(); 42259698Sdim std::string HexStr(utohexstr(API.getZExtValue())); 43259698Sdim if (HexStr.length() < NumHex) 44259698Sdim OS << std::string(NumHex - HexStr.length(), '0'); 45259698Sdim OS << utohexstr(API.getZExtValue()); 46259698Sdim} 47