LCOV - code coverage report
Current view: top level - lib/MC - MCSectionCOFF.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 50 53 94.3 %
Date: 2018-10-20 13:21:21 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
       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/MCSectionCOFF.h"
      11             : #include "llvm/BinaryFormat/COFF.h"
      12             : #include "llvm/MC/MCSymbol.h"
      13             : #include "llvm/Support/raw_ostream.h"
      14             : #include <cassert>
      15             : 
      16             : using namespace llvm;
      17             : 
      18             : MCSectionCOFF::~MCSectionCOFF() = default; // anchor.
      19             : 
      20             : // ShouldOmitSectionDirective - Decides whether a '.section' directive
      21             : // should be printed before the section name
      22        2050 : bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
      23             :                                                const MCAsmInfo &MAI) const {
      24        2050 :   if (COMDATSymbol)
      25             :     return false;
      26             : 
      27             :   // FIXME: Does .section .bss/.data/.text work everywhere??
      28             :   if (Name == ".text" || Name == ".data" || Name == ".bss")
      29        1292 :     return true;
      30             : 
      31             :   return false;
      32             : }
      33             : 
      34          28 : void MCSectionCOFF::setSelection(int Selection) const {
      35             :   assert(Selection != 0 && "invalid COMDAT selection type");
      36          28 :   this->Selection = Selection;
      37          28 :   Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
      38          28 : }
      39             : 
      40        2050 : void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
      41             :                                          raw_ostream &OS,
      42             :                                          const MCExpr *Subsection) const {
      43             :   // standard sections don't require the '.section'
      44        2050 :   if (ShouldOmitSectionDirective(SectionName, MAI)) {
      45        1292 :     OS << '\t' << getSectionName() << '\n';
      46        1292 :     return;
      47             :   }
      48             : 
      49         758 :   OS << "\t.section\t" << getSectionName() << ",\"";
      50         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
      51             :     OS << 'd';
      52         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
      53             :     OS << 'b';
      54         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
      55             :     OS << 'x';
      56         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
      57             :     OS << 'w';
      58         697 :   else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
      59             :     OS << 'r';
      60             :   else
      61             :     OS << 'y';
      62         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
      63             :     OS << 'n';
      64         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
      65             :     OS << 's';
      66         758 :   if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
      67             :       !isImplicitlyDiscardable(SectionName))
      68             :     OS << 'D';
      69             :   OS << '"';
      70             : 
      71         758 :   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
      72         229 :     if (COMDATSymbol)
      73         228 :       OS << ",";
      74             :     else
      75           1 :       OS << "\n\t.linkonce\t";
      76         229 :     switch (Selection) {
      77          26 :       case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
      78          26 :         OS << "one_only";
      79          26 :         break;
      80         160 :       case COFF::IMAGE_COMDAT_SELECT_ANY:
      81         160 :         OS << "discard";
      82         160 :         break;
      83           2 :       case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
      84           2 :         OS << "same_size";
      85           2 :         break;
      86           1 :       case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
      87           1 :         OS << "same_contents";
      88           1 :         break;
      89          32 :       case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
      90          32 :         OS << "associative";
      91          32 :         break;
      92           8 :       case COFF::IMAGE_COMDAT_SELECT_LARGEST:
      93           8 :         OS << "largest";
      94           8 :         break;
      95           0 :       case COFF::IMAGE_COMDAT_SELECT_NEWEST:
      96           0 :         OS << "newest";
      97           0 :         break;
      98             :       default:
      99             :         assert(false && "unsupported COFF selection type");
     100             :         break;
     101             :     }
     102         229 :     if (COMDATSymbol) {
     103         228 :       OS << ",";
     104         228 :       COMDATSymbol->print(OS, &MAI);
     105             :     }
     106             :   }
     107             :   OS << '\n';
     108             : }
     109             : 
     110         286 : bool MCSectionCOFF::UseCodeAlign() const {
     111         286 :   return getKind().isText();
     112             : }
     113             : 
     114        6904 : bool MCSectionCOFF::isVirtualSection() const {
     115        6904 :   return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
     116             : }

Generated by: LCOV version 1.13