llvm_unreachable->llvm_unreachable(0), LLVM_UNREACHABLE->llvm_unreachable.
[oota-llvm.git] / lib / Target / ARM / ARMTargetAsmInfo.cpp
index 47abcc6f40776bd9d9501591034c8b3e2353ec72..34c187492fdb5415725fc70b1444920fe6135de6 100644 (file)
 #include <cctype>
 using namespace llvm;
 
-static const char *const arm_asm_table[] = {
-                                      "{r0}", "r0",
-                                      "{r1}", "r1",
-                                      "{r2}", "r2",
-                                      "{r3}", "r3",
-                                      "{r4}", "r4",
-                                      "{r5}", "r5",
-                                      "{r6}", "r6",
-                                      "{r7}", "r7",
-                                      "{r8}", "r8",
-                                      "{r9}", "r9",
-                                      "{r10}", "r10",
-                                      "{r11}", "r11",
-                                      "{r12}", "r12",
-                                      "{r13}", "r13",
-                                      "{r14}", "r14",
-                                      "{lr}", "lr",
-                                      "{sp}", "sp",
-                                      "{ip}", "ip",
-                                      "{fp}", "fp",
-                                      "{sl}", "sl",
-                                      "{memory}", "memory",
-                                      "{cc}", "cc",
-                                      0,0};
+const char *const llvm::arm_asm_table[] = {
+  "{r0}", "r0",
+  "{r1}", "r1",
+  "{r2}", "r2",
+  "{r3}", "r3",
+  "{r4}", "r4",
+  "{r5}", "r5",
+  "{r6}", "r6",
+  "{r7}", "r7",
+  "{r8}", "r8",
+  "{r9}", "r9",
+  "{r10}", "r10",
+  "{r11}", "r11",
+  "{r12}", "r12",
+  "{r13}", "r13",
+  "{r14}", "r14",
+  "{lr}", "lr",
+  "{sp}", "sp",
+  "{ip}", "ip",
+  "{fp}", "fp",
+  "{sl}", "sl",
+  "{memory}", "memory",
+  "{cc}", "cc",
+  0,0
+};
 
-ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
+ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMBaseTargetMachine &TM):
+  ARMTargetAsmInfo<DarwinTargetAsmInfo>(TM) {
   Subtarget = &TM.getSubtarget<ARMSubtarget>();
-  AsmTransCBE = arm_asm_table;
-  if (Subtarget->isTargetDarwin()) {
-    GlobalPrefix = "_";
-    PrivateGlobalPrefix = "L";
-    StringConstantPrefix = "\1LC";
-    BSSSection = 0;                       // no BSS section.
-    ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
-    SetDirective = "\t.set\t";
-    WeakRefDirective = "\t.weak_reference\t";
-    HiddenDirective = "\t.private_extern\t";
-    ProtectedDirective = NULL;
-    JumpTableDataSection = ".const";
-    CStringSection = "\t.cstring";
-    FourByteConstantSection = "\t.literal4\n";
-    EightByteConstantSection = "\t.literal8\n";
-    ReadOnlySection = "\t.const\n";
-    HasDotTypeDotSizeDirective = false;
-    NeedsIndirectEncoding = true;
-    if (TM.getRelocationModel() == Reloc::Static) {
-      StaticCtorsSection = ".constructor";
-      StaticDtorsSection = ".destructor";
-    } else {
-      StaticCtorsSection = ".mod_init_func";
-      StaticDtorsSection = ".mod_term_func";
-    }
-    
-    // In non-PIC modes, emit a special label before jump tables so that the
-    // linker can perform more accurate dead code stripping.
-    if (TM.getRelocationModel() != Reloc::PIC_) {
-      // Emit a local label that is preserved until the linker runs.
-      JumpTableSpecialLabelPrefix = "l";
-    }
-    
-    NeedsSet = true;
-    DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
-    DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
-    DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
-    DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
-    DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
-    DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
-    DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
-    DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
-    DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
-    DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
-    DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
-  } else {
-    NeedsSet = false;
-    HasLEB128 = true;
-    AbsoluteDebugSectionOffsets = true;
-    ReadOnlySection = "\t.section\t.rodata\n";
-    PrivateGlobalPrefix = ".L";
-    WeakRefDirective = "\t.weak\t";
-    SetDirective = "\t.set\t";
-    DwarfRequiresFrameSection = false;
-    DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",%progbits";
-    DwarfInfoSection =    "\t.section\t.debug_info,\"\",%progbits";
-    DwarfLineSection =    "\t.section\t.debug_line,\"\",%progbits";
-    DwarfFrameSection =   "\t.section\t.debug_frame,\"\",%progbits";
-    DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
-    DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
-    DwarfStrSection =     "\t.section\t.debug_str,\"\",%progbits";
-    DwarfLocSection =     "\t.section\t.debug_loc,\"\",%progbits";
-    DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
-    DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",%progbits";
-    DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
-
-    if (Subtarget->isAAPCS_ABI()) {
-      StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
-      StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
-    } else {
-      StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
-      StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
-    }
-    TLSDataSection = "\t.section .tdata,\"awT\",%progbits";
-    TLSBSSSection = "\t.section .tbss,\"awT\",%nobits";
-  }
 
   ZeroDirective = "\t.space\t";
-  AlignmentIsInBytes = false;
-  Data64bitsDirective = 0;
-  CommentString = "@";
-  DataSection = "\t.data";
-  ConstantPoolSection = "\t.text\n";
-  COMMDirectiveTakesAlignment = false;
-  InlineAsmStart = "@ InlineAsm Start";
-  InlineAsmEnd = "@ InlineAsm End";
-  LCOMMDirective = "\t.lcomm\t";
+  ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
+  SetDirective = "\t.set\t";
+  ProtectedDirective = NULL;
+  HasDotTypeDotSizeDirective = false;
+  SupportsDebugInformation = true;
+}
+
+ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMBaseTargetMachine &TM):
+  ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
+  Subtarget = &TM.getSubtarget<ARMSubtarget>();
+
+  NeedsSet = false;
+  HasLEB128 = true;
+  AbsoluteDebugSectionOffsets = true;
+  CStringSection = ".rodata.str";
+  PrivateGlobalPrefix = ".L";
+  WeakRefDirective = "\t.weak\t";
+  SetDirective = "\t.set\t";
+  DwarfRequiresFrameSection = false;
+  DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",%progbits";
+  DwarfInfoSection =    "\t.section\t.debug_info,\"\",%progbits";
+  DwarfLineSection =    "\t.section\t.debug_line,\"\",%progbits";
+  DwarfFrameSection =   "\t.section\t.debug_frame,\"\",%progbits";
+  DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits";
+  DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits";
+  DwarfStrSection =     "\t.section\t.debug_str,\"\",%progbits";
+  DwarfLocSection =     "\t.section\t.debug_loc,\"\",%progbits";
+  DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits";
+  DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",%progbits";
+  DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits";
+
+  if (Subtarget->isAAPCS_ABI()) {
+    StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array";
+    StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array";
+  } else {
+    StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits";
+    StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits";
+  }
+  SupportsDebugInformation = true;
 }
 
 /// Count the number of comma-separated arguments.
 /// Do not try to detect errors.
-unsigned ARMTargetAsmInfo::countArguments(const char* p) const {
+template <class BaseTAI>
+unsigned ARMTargetAsmInfo<BaseTAI>::countArguments(const char* p) const {
   unsigned count = 0;
   while (*p && isspace(*p) && *p != '\n')
     p++;
   count++;
-  while (*p && *p!='\n' && 
-         strncmp(p, CommentString, strlen(CommentString))!=0) {
+  while (*p && *p!='\n' &&
+         strncmp(p, BaseTAI::CommentString,
+                 strlen(BaseTAI::CommentString))!=0) {
     if (*p==',')
       count++;
     p++;
@@ -151,7 +109,8 @@ unsigned ARMTargetAsmInfo::countArguments(const char* p) const {
 
 /// Count the length of a string enclosed in quote characters.
 /// Do not try to detect errors.
-unsigned ARMTargetAsmInfo::countString(const char* p) const {
+template <class BaseTAI>
+unsigned ARMTargetAsmInfo<BaseTAI>::countString(const char* p) const {
   unsigned count = 0;
   while (*p && isspace(*p) && *p!='\n')
     p++;
@@ -163,7 +122,8 @@ unsigned ARMTargetAsmInfo::countString(const char* p) const {
 }
 
 /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
-unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
+template <class BaseTAI>
+unsigned ARMTargetAsmInfo<BaseTAI>::getInlineAsmLength(const char *s) const {
   // Make a lowercase-folded version of s for counting purposes.
   char *q, *s_copy = (char *)malloc(strlen(s) + 1);
   strcpy(s_copy, s);
@@ -188,8 +148,12 @@ unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
             Str++;
           break;
         }
+      
+      if (*Str == 0) break;
+      
       // Ignore everything from comment char(s) to EOL
-      if (strncmp(Str, CommentString, strlen(CommentString))==-0)
+      if (strncmp(Str, BaseTAI::CommentString,
+                  strlen(BaseTAI::CommentString)) == 0)
         atInsnStart = false;
       // FIXME do something like the following for non-Darwin
       else if (*Str == '.' && Subtarget->isTargetDarwin()) {
@@ -260,7 +224,7 @@ unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
       } else if (inTextSection) {
         // An instruction
         atInsnStart = false;
-        if (Subtarget->isThumb()) {
+        if (Subtarget->isThumb()) {  // FIXME thumb2
           // BL and BLX <non-reg> are 4 bytes, all others 2.
           if (strncmp(Str, "blx", strlen("blx"))==0) {
             const char* p = Str+3;
@@ -279,9 +243,12 @@ unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
           Length += 4;    // ARM
       }
     }
-    if (*Str == '\n' || *Str == SeparatorChar)
+    if (*Str == '\n' || *Str == BaseTAI::SeparatorChar)
       atInsnStart = true;
   }
   free(s_copy);
   return Length;
 }
+
+// Instantiate default implementation.
+TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>);