Provide direct function to switch to Section
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 24 Sep 2008 22:12:10 +0000 (22:12 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 24 Sep 2008 22:12:10 +0000 (22:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56571 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp

index 6ccef8ca59b9cb76576273fb79dbb5450a567183..45ea5d8977402609934dd2c8a86ad1fc0a815b85 100644 (file)
@@ -32,6 +32,7 @@ namespace llvm {
   class MachineConstantPoolValue;
   class MachineModuleInfo;
   class Mangler;
+  class Section;
   class TargetAsmInfo;
   class Type;
   class raw_ostream;
@@ -127,7 +128,11 @@ namespace llvm {
     /// are the same.
     ///
     void SwitchToDataSection(const char *NewSection, const GlobalValue *GV = NULL);
-    
+
+    /// SwitchToSection - Switch to the specified section of the executable if
+    /// we are not already in it!
+    void SwitchToSection(const Section* NS);
+
     /// getGlobalLinkName - Returns the asm/link name of of the specified
     /// global variable.  Should be overridden by each target asm printer to
     /// generate the appropriate value.
index 589c9a6efc9b052f04be92297cd9a6f1c5522dea..8305e54f9e8ddc12dfd77e503e625a07c2af89fa 100644 (file)
@@ -114,6 +114,7 @@ namespace llvm {
     bool isNamed() const { return Flags & SectionFlags::Named; }
     unsigned getEntitySize() const { return (Flags >> 24) & 0xFF; }
     const std::string& getName() const { return Name; }
+    unsigned getFlags() const { return Flags; }
   };
 
   /// TargetAsmInfo - This class is intended to be used as a base class for asm
index de856c165af48d8818d43ca6b6756f02b8d90290..6e9d935e0c009b2222d89480a08123af30fd469d 100644 (file)
@@ -105,6 +105,26 @@ void AsmPrinter::SwitchToDataSection(const char *NewSection,
   IsInTextSection = false;
 }
 
+/// SwitchToSection - Switch to the specified section of the executable if we
+/// are not already in it!
+void AsmPrinter::SwitchToSection(const Section* NS) {
+  const std::string& NewSection = NS->getName();
+
+  // If we're already in this section, we're done.
+  if (CurrentSection == NewSection) return;
+
+  // Close the current section, if applicable.
+  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
+    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
+
+  // FIXME: Make CurrentSection a Section* in the future
+  CurrentSection = NewSection;
+
+  if (!CurrentSection.empty())
+    O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
+
+  IsInTextSection = (NS->getFlags() & SectionFlags::Code);
+}
 
 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
   MachineFunctionPass::getAnalysisUsage(AU);