LLVM  4.0.0
NVPTXMCExpr.cpp
Go to the documentation of this file.
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 *
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!");
31  OS << "0f";
32  NumHex = 8;
34  break;
36  OS << "0d";
37  NumHex = 16;
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 
51  MCContext &Ctx) {
52  return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
53 }
54 
56  const MCAsmInfo *MAI) const {
57  OS << "generic(";
58  SymExpr->print(OS, MAI);
59  OS << ")";
60 }
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1309
APInt bitcastToAPInt() const
Definition: APFloat.h:1012
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:161
Context object for machine code objects.
Definition: MCContext.h:51
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4139
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:50
static const fltSemantics & IEEEsingle()
Definition: APFloat.cpp:100
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:19
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:61
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:55
Class for arbitrary precision integers.
Definition: APInt.h:77
static const fltSemantics & IEEEdouble()
Definition: APFloat.cpp:103
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:23
static std::string utohexstr(uint64_t X, bool LowerCase=false)
Definition: StringExtras.h:48
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:33
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:84