LCOV - code coverage report
Current view: top level - lib/MC - MCInstPrinter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 38 56 67.9 %
Date: 2017-09-14 15:23:50 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCInstPrinter.cpp - Convert an MCInst to target assembly syntax ----===//
       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 "llvm/MC/MCInstPrinter.h"
      11             : #include "llvm/ADT/ArrayRef.h"
      12             : #include "llvm/ADT/StringRef.h"
      13             : #include "llvm/MC/MCAsmInfo.h"
      14             : #include "llvm/MC/MCInstrInfo.h"
      15             : #include "llvm/Support/ErrorHandling.h"
      16             : #include "llvm/Support/Format.h"
      17             : #include "llvm/Support/raw_ostream.h"
      18             : #include <cinttypes>
      19             : #include <cstdint>
      20             : 
      21             : using namespace llvm;
      22             : 
      23      221975 : void llvm::dumpBytes(ArrayRef<uint8_t> bytes, raw_ostream &OS) {
      24             :   static const char hex_rep[] = "0123456789abcdef";
      25     1246018 :   for (char i: bytes) {
      26     1604136 :     OS << hex_rep[(i & 0xF0) >> 4];
      27     1604136 :     OS << hex_rep[i & 0xF];
      28      802068 :     OS << ' ';
      29             :   }
      30      221975 : }
      31             : 
      32             : MCInstPrinter::~MCInstPrinter() = default;
      33             : 
      34             : /// getOpcodeName - Return the name of the specified opcode enum (e.g.
      35             : /// "MOV32ri") or empty if we can't resolve it.
      36        1135 : StringRef MCInstPrinter::getOpcodeName(unsigned Opcode) const {
      37        2270 :   return MII.getName(Opcode);
      38             : }
      39             : 
      40           0 : void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
      41           0 :   llvm_unreachable("Target should implement this");
      42             : }
      43             : 
      44     1825435 : void MCInstPrinter::printAnnotation(raw_ostream &OS, StringRef Annot) {
      45     1825435 :   if (!Annot.empty()) {
      46          68 :     if (CommentStream) {
      47           0 :       (*CommentStream) << Annot;
      48             :       // By definition (see MCInstPrinter.h), CommentStream must end with
      49             :       // a newline after each comment.
      50           0 :       if (Annot.back() != '\n')
      51           0 :         (*CommentStream) << '\n';
      52             :     } else
      53          68 :       OS << " " << MAI.getCommentString() << " " << Annot;
      54             :   }
      55     1825435 : }
      56             : 
      57             : /// Utility functions to make adding mark ups simpler.
      58     3362590 : StringRef MCInstPrinter::markup(StringRef s) const {
      59     3362590 :   if (getUseMarkup())
      60          26 :     return s;
      61             :   else
      62     3362564 :     return "";
      63             : }
      64           0 : StringRef MCInstPrinter::markup(StringRef a, StringRef b) const {
      65           0 :   if (getUseMarkup())
      66           0 :     return a;
      67             :   else
      68           0 :     return b;
      69             : }
      70             : 
      71             : // For asm-style hex (e.g. 0ffh) the first digit always has to be a number.
      72             : static bool needsLeadingZero(uint64_t Value)
      73             : {
      74          60 :   while (Value)
      75             :   {
      76          60 :     uint64_t digit = (Value >> 60) & 0xf;
      77          60 :     if (digit != 0)
      78           4 :       return (digit >= 0xa);
      79          56 :     Value <<= 4;
      80             :   }
      81             :   return false;
      82             : }
      83             : 
      84      472924 : format_object<int64_t> MCInstPrinter::formatDec(int64_t Value) const {
      85      945848 :   return format("%" PRId64, Value);
      86             : }
      87             : 
      88       54538 : format_object<int64_t> MCInstPrinter::formatHex(int64_t Value) const {
      89       54538 :   switch(PrintHexStyle) {
      90       54534 :   case HexStyle::C:
      91       54534 :     if (Value < 0)
      92        1270 :       return format("-0x%" PRIx64, -Value);
      93             :     else
      94       53899 :       return format("0x%" PRIx64, Value);
      95           4 :   case HexStyle::Asm:
      96           4 :     if (Value < 0) {
      97           0 :       if (needsLeadingZero((uint64_t)(-Value)))
      98           0 :         return format("-0%" PRIx64 "h", -Value);
      99             :       else
     100           0 :         return format("-%" PRIx64 "h", -Value);
     101             :     } else {
     102           8 :       if (needsLeadingZero((uint64_t)(Value)))
     103           0 :         return format("0%" PRIx64 "h", Value);
     104             :       else
     105           4 :         return format("%" PRIx64 "h", Value);
     106             :     }
     107             :   }
     108           0 :   llvm_unreachable("unsupported print style");
     109             : }
     110             : 
     111       28744 : format_object<uint64_t> MCInstPrinter::formatHex(uint64_t Value) const {
     112       28744 :   switch(PrintHexStyle) {
     113       28744 :   case HexStyle::C:
     114       28744 :      return format("0x%" PRIx64, Value);
     115             :   case HexStyle::Asm:
     116           0 :     if (needsLeadingZero(Value))
     117           0 :       return format("0%" PRIx64 "h", Value);
     118             :     else
     119           0 :       return format("%" PRIx64 "h", Value);
     120             :   }
     121           0 :   llvm_unreachable("unsupported print style");
     122             : }

Generated by: LCOV version 1.13