LLVM  3.7.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:1327
static const fltSemantics IEEEdouble
Definition: APFloat.h:133
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:159
Context object for machine code objects.
Definition: MCContext.h:48
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:50
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
Definition: MCExpr.cpp:33
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
Definition: APFloat.cpp:1972
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:60
static const NVPTXFloatMCExpr * create(VariantKind Kind, APFloat Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:19
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:55
Class for arbitrary precision integers.
Definition: APInt.h:73
APInt bitcastToAPInt() const
Definition: APFloat.cpp:3084
static const fltSemantics IEEEsingle
Definition: APFloat.h:132
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:72
const ARM::ArchExtKind Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:83