NVPTXMCExpr.cpp revision 259698
1//===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#define DEBUG_TYPE "nvptx-mcexpr" 11#include "NVPTXMCExpr.h" 12#include "llvm/ADT/StringExtras.h" 13#include "llvm/MC/MCAssembler.h" 14#include "llvm/MC/MCContext.h" 15using namespace llvm; 16 17const NVPTXFloatMCExpr* 18NVPTXFloatMCExpr::Create(VariantKind Kind, APFloat Flt, MCContext &Ctx) { 19 return new (Ctx) NVPTXFloatMCExpr(Kind, Flt); 20} 21 22void NVPTXFloatMCExpr::PrintImpl(raw_ostream &OS) const { 23 bool Ignored; 24 unsigned NumHex; 25 APFloat APF = getAPFloat(); 26 27 switch (Kind) { 28 default: llvm_unreachable("Invalid kind!"); 29 case VK_NVPTX_SINGLE_PREC_FLOAT: 30 OS << "0f"; 31 NumHex = 8; 32 APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored); 33 break; 34 case VK_NVPTX_DOUBLE_PREC_FLOAT: 35 OS << "0d"; 36 NumHex = 16; 37 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored); 38 break; 39 } 40 41 APInt API = APF.bitcastToAPInt(); 42 std::string HexStr(utohexstr(API.getZExtValue())); 43 if (HexStr.length() < NumHex) 44 OS << std::string(NumHex - HexStr.length(), '0'); 45 OS << utohexstr(API.getZExtValue()); 46} 47