LLVM API Documentation

NVPTXMCExpr.cpp
Go to the documentation of this file.
00001 //===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "NVPTXMCExpr.h"
00011 #include "llvm/ADT/StringExtras.h"
00012 #include "llvm/MC/MCAssembler.h"
00013 #include "llvm/MC/MCContext.h"
00014 using namespace llvm;
00015 
00016 #define DEBUG_TYPE "nvptx-mcexpr"
00017 
00018 const NVPTXFloatMCExpr*
00019 NVPTXFloatMCExpr::Create(VariantKind Kind, APFloat Flt, MCContext &Ctx) {
00020   return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
00021 }
00022 
00023 void NVPTXFloatMCExpr::PrintImpl(raw_ostream &OS) const {
00024   bool Ignored;
00025   unsigned NumHex;
00026   APFloat APF = getAPFloat();
00027 
00028   switch (Kind) {
00029   default: llvm_unreachable("Invalid kind!");
00030   case VK_NVPTX_SINGLE_PREC_FLOAT:
00031     OS << "0f";
00032     NumHex = 8;
00033     APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored);
00034     break;
00035   case VK_NVPTX_DOUBLE_PREC_FLOAT:
00036     OS << "0d";
00037     NumHex = 16;
00038     APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored);
00039     break;
00040   }
00041 
00042   APInt API = APF.bitcastToAPInt();
00043   std::string HexStr(utohexstr(API.getZExtValue()));
00044   if (HexStr.length() < NumHex)
00045     OS << std::string(NumHex - HexStr.length(), '0');
00046   OS << utohexstr(API.getZExtValue());
00047 }