LLVM API Documentation

MCSectionMachO.h
Go to the documentation of this file.
00001 //===- MCSectionMachO.h - MachO Machine Code Sections -----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the MCSectionMachO class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_MC_MCSECTIONMACHO_H
00015 #define LLVM_MC_MCSECTIONMACHO_H
00016 
00017 #include "llvm/ADT/StringRef.h"
00018 #include "llvm/MC/MCSection.h"
00019 #include "llvm/Support/MachO.h"
00020 
00021 namespace llvm {
00022 
00023 /// MCSectionMachO - This represents a section on a Mach-O system (used by
00024 /// Mac OS X).  On a Mac system, these are also described in
00025 /// /usr/include/mach-o/loader.h.
00026 class MCSectionMachO : public MCSection {
00027   char SegmentName[16];  // Not necessarily null terminated!
00028   char SectionName[16];  // Not necessarily null terminated!
00029 
00030   /// TypeAndAttributes - This is the SECTION_TYPE and SECTION_ATTRIBUTES
00031   /// field of a section, drawn from the enums below.
00032   unsigned TypeAndAttributes;
00033 
00034   /// Reserved2 - The 'reserved2' field of a section, used to represent the
00035   /// size of stubs, for example.
00036   unsigned Reserved2;
00037 
00038   MCSectionMachO(StringRef Segment, StringRef Section,
00039                  unsigned TAA, unsigned reserved2, SectionKind K);
00040   friend class MCContext;
00041 public:
00042 
00043   StringRef getSegmentName() const {
00044     // SegmentName is not necessarily null terminated!
00045     if (SegmentName[15])
00046       return StringRef(SegmentName, 16);
00047     return StringRef(SegmentName);
00048   }
00049   StringRef getSectionName() const {
00050     // SectionName is not necessarily null terminated!
00051     if (SectionName[15])
00052       return StringRef(SectionName, 16);
00053     return StringRef(SectionName);
00054   }
00055 
00056   std::string getLabelBeginName() const override {
00057     return StringRef(getSegmentName().str() + getSectionName().str() + "_begin");
00058   }
00059 
00060   std::string getLabelEndName() const override {
00061     return StringRef(getSegmentName().str() + getSectionName().str() + "_end");
00062   }
00063 
00064   unsigned getTypeAndAttributes() const { return TypeAndAttributes; }
00065   unsigned getStubSize() const { return Reserved2; }
00066 
00067   MachO::SectionType getType() const {
00068     return static_cast<MachO::SectionType>(TypeAndAttributes &
00069                                            MachO::SECTION_TYPE);
00070   }
00071   bool hasAttribute(unsigned Value) const {
00072     return (TypeAndAttributes & Value) != 0;
00073   }
00074 
00075   /// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
00076   /// This is a string that can appear after a .section directive in a mach-o
00077   /// flavored .s file.  If successful, this fills in the specified Out
00078   /// parameters and returns an empty string.  When an invalid section
00079   /// specifier is present, this returns a string indicating the problem.
00080   /// If no TAA was parsed, TAA is not altered, and TAAWasSet becomes false.
00081   static std::string ParseSectionSpecifier(StringRef Spec,       // In.
00082                                            StringRef &Segment,   // Out.
00083                                            StringRef &Section,   // Out.
00084                                            unsigned  &TAA,       // Out.
00085                                            bool      &TAAParsed, // Out.
00086                                            unsigned  &StubSize); // Out.
00087 
00088   void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
00089                             const MCExpr *Subsection) const override;
00090   bool UseCodeAlign() const override;
00091   bool isVirtualSection() const override;
00092 
00093   static bool classof(const MCSection *S) {
00094     return S->getVariant() == SV_MachO;
00095   }
00096 };
00097 
00098 } // end namespace llvm
00099 
00100 #endif