Home | History | Annotate | Download | only in NVPTX
      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 #include "NVPTXMCExpr.h"
     11 #include "llvm/ADT/StringExtras.h"
     12 #include "llvm/MC/MCAssembler.h"
     13 #include "llvm/MC/MCContext.h"
     14 using namespace llvm;
     15 
     16 #define DEBUG_TYPE "nvptx-mcexpr"
     17 
     18 const NVPTXFloatMCExpr*
     19 NVPTXFloatMCExpr::create(VariantKind Kind, APFloat Flt, MCContext &Ctx) {
     20   return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
     21 }
     22 
     23 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
     24   bool Ignored;
     25   unsigned NumHex;
     26   APFloat APF = getAPFloat();
     27 
     28   switch (Kind) {
     29   default: llvm_unreachable("Invalid kind!");
     30   case VK_NVPTX_SINGLE_PREC_FLOAT:
     31     OS << "0f";
     32     NumHex = 8;
     33     APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored);
     34     break;
     35   case VK_NVPTX_DOUBLE_PREC_FLOAT:
     36     OS << "0d";
     37     NumHex = 16;
     38     APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored);
     39     break;
     40   }
     41 
     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());
     47 }
     48 
     49 const NVPTXGenericMCSymbolRefExpr*
     50 NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr *SymExpr,
     51                                     MCContext &Ctx) {
     52   return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
     53 }
     54 
     55 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS,
     56                                             const MCAsmInfo *MAI) const {
     57   OS << "generic(";
     58   SymExpr->print(OS, MAI);
     59   OS << ")";
     60 }
     61