LCOV - code coverage report
Current view: top level - lib/MC - MCSectionCOFF.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 46 49 93.9 %
Date: 2017-09-14 15:23:50 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        1520 : bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
      23             :                                                const MCAsmInfo &MAI) const {
      24        1520 :   if (COMDATSymbol)
      25             :     return false;
      26             : 
      27             :   // FIXME: Does .section .bss/.data/.text work everywhere??
      28        2307 :   if (Name == ".text" || Name == ".data" || Name == ".bss")
      29             :     return true;
      30             : 
      31             :   return false;
      32             : }
      33             : 
      34          19 : void MCSectionCOFF::setSelection(int Selection) const {
      35             :   assert(Selection != 0 && "invalid COMDAT selection type");
      36          19 :   this->Selection = Selection;
      37          19 :   Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
      38          19 : }
      39             : 
      40        1520 : 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        1520 :   if (ShouldOmitSectionDirective(SectionName, MAI)) {
      45         983 :     OS << '\t' << getSectionName() << '\n';
      46             :     return;
      47             :   }
      48             : 
      49         537 :   OS << "\t.section\t" << getSectionName() << ",\"";
      50         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
      51             :     OS << 'd';
      52         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
      53             :     OS << 'b';
      54         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
      55             :     OS << 'x';
      56         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
      57             :     OS << 'w';
      58         491 :   else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
      59             :     OS << 'r';
      60             :   else
      61             :     OS << 'y';
      62         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
      63             :     OS << 'n';
      64         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
      65             :     OS << 's';
      66         537 :   if ((getCharacteristics() & COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
      67             :       !isImplicitlyDiscardable(SectionName))
      68             :     OS << 'D';
      69         537 :   OS << '"';
      70             : 
      71         537 :   if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
      72         128 :     OS << ",";
      73         128 :     switch (Selection) {
      74          25 :       case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
      75          25 :         OS << "one_only,";
      76          25 :         break;
      77          79 :       case COFF::IMAGE_COMDAT_SELECT_ANY:
      78          79 :         OS << "discard,";
      79          79 :         break;
      80           2 :       case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
      81           2 :         OS << "same_size,";
      82           2 :         break;
      83           1 :       case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
      84           1 :         OS << "same_contents,";
      85           1 :         break;
      86          19 :       case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
      87          19 :         OS << "associative,";
      88          19 :         break;
      89           2 :       case COFF::IMAGE_COMDAT_SELECT_LARGEST:
      90           2 :         OS << "largest,";
      91           2 :         break;
      92           0 :       case COFF::IMAGE_COMDAT_SELECT_NEWEST:
      93           0 :         OS << "newest,";
      94           0 :         break;
      95             :       default:
      96             :         assert(false && "unsupported COFF selection type");
      97             :         break;
      98             :     }
      99             :     assert(COMDATSymbol);
     100         128 :     COMDATSymbol->print(OS, &MAI);
     101             :   }
     102             :   OS << '\n';
     103             : }
     104             : 
     105         158 : bool MCSectionCOFF::UseCodeAlign() const {
     106         316 :   return getKind().isText();
     107             : }
     108             : 
     109        4180 : bool MCSectionCOFF::isVirtualSection() const {
     110        4180 :   return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
     111             : }

Generated by: LCOV version 1.13