Jim Laskey | 7c95ad4 | 2006-09-06 19:21:41 +0000 | [diff] [blame] | 1 | //===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==// |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines target asm properties related what form asm statements |
| 11 | // should take. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
Anton Korobeynikov | 72bb402 | 2009-01-27 22:29:24 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 17 | #include "llvm/GlobalVariable.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/Module.h" |
| 20 | #include "llvm/Type.h" |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetAsmInfo.h" |
Chris Lattner | 8ca5209 | 2009-07-26 06:11:33 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetData.h" |
Anton Korobeynikov | db23231 | 2009-03-29 17:13:49 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Dwarf.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 27 | #include <cctype> |
| 28 | #include <cstring> |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Chris Lattner | 0d4960c3 | 2009-07-24 20:14:10 +0000 | [diff] [blame] | 31 | TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) { |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 32 | BSSSection = "\t.bss"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 33 | ZeroFillDirective = 0; |
| 34 | NonexecutableStackDirective = 0; |
| 35 | NeedsSet = false; |
| 36 | MaxInstLength = 4; |
| 37 | PCSymbol = "$"; |
| 38 | SeparatorChar = ';'; |
David Greene | 014700c | 2009-07-13 20:25:48 +0000 | [diff] [blame] | 39 | CommentColumn = 60; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 40 | CommentString = "#"; |
David Greene | 76081c4 | 2009-07-20 22:02:59 +0000 | [diff] [blame] | 41 | FirstOperandColumn = 0; |
| 42 | MaxOperandLength = 0; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 43 | GlobalPrefix = ""; |
| 44 | PrivateGlobalPrefix = "."; |
Chris Lattner | 90f8b70 | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 45 | LinkerPrivateGlobalPrefix = ""; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 46 | JumpTableSpecialLabelPrefix = 0; |
| 47 | GlobalVarAddrPrefix = ""; |
| 48 | GlobalVarAddrSuffix = ""; |
| 49 | FunctionAddrPrefix = ""; |
| 50 | FunctionAddrSuffix = ""; |
| 51 | PersonalityPrefix = ""; |
| 52 | PersonalitySuffix = ""; |
| 53 | NeedsIndirectEncoding = false; |
| 54 | InlineAsmStart = "#APP"; |
| 55 | InlineAsmEnd = "#NO_APP"; |
| 56 | AssemblerDialect = 0; |
Chris Lattner | a93ca92 | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 57 | AllowQuotesInName = false; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 58 | ZeroDirective = "\t.zero\t"; |
| 59 | ZeroDirectiveSuffix = 0; |
| 60 | AsciiDirective = "\t.ascii\t"; |
| 61 | AscizDirective = "\t.asciz\t"; |
| 62 | Data8bitsDirective = "\t.byte\t"; |
| 63 | Data16bitsDirective = "\t.short\t"; |
| 64 | Data32bitsDirective = "\t.long\t"; |
| 65 | Data64bitsDirective = "\t.quad\t"; |
| 66 | AlignDirective = "\t.align\t"; |
| 67 | AlignmentIsInBytes = true; |
| 68 | TextAlignFillValue = 0; |
| 69 | SwitchToSectionDirective = "\t.section\t"; |
| 70 | TextSectionStartSuffix = ""; |
| 71 | DataSectionStartSuffix = ""; |
| 72 | SectionEndDirectiveSuffix = 0; |
| 73 | ConstantPoolSection = "\t.section .rodata"; |
| 74 | JumpTableDataSection = "\t.section .rodata"; |
| 75 | JumpTableDirective = 0; |
| 76 | CStringSection = 0; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 77 | // FIXME: Flags are ELFish - replace with normal section stuff. |
| 78 | StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits"; |
| 79 | StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits"; |
| 80 | GlobalDirective = "\t.globl\t"; |
| 81 | SetDirective = 0; |
| 82 | LCOMMDirective = 0; |
| 83 | COMMDirective = "\t.comm\t"; |
| 84 | COMMDirectiveTakesAlignment = true; |
| 85 | HasDotTypeDotSizeDirective = true; |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 86 | HasSingleParameterDotFile = true; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 87 | UsedDirective = 0; |
| 88 | WeakRefDirective = 0; |
| 89 | WeakDefDirective = 0; |
| 90 | // FIXME: These are ELFish - move to ELFTAI. |
| 91 | HiddenDirective = "\t.hidden\t"; |
| 92 | ProtectedDirective = "\t.protected\t"; |
| 93 | AbsoluteDebugSectionOffsets = false; |
| 94 | AbsoluteEHSectionOffsets = false; |
| 95 | HasLEB128 = false; |
| 96 | HasDotLocAndDotFile = false; |
| 97 | SupportsDebugInformation = false; |
| 98 | SupportsExceptionHandling = false; |
| 99 | DwarfRequiresFrameSection = true; |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 100 | DwarfUsesInlineInfoSection = false; |
Chris Lattner | e2cf37b | 2009-07-17 20:46:40 +0000 | [diff] [blame] | 101 | Is_EHSymbolPrivate = true; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 102 | GlobalEHDirective = 0; |
| 103 | SupportsWeakOmittedEHFrame = true; |
| 104 | DwarfSectionOffsetDirective = 0; |
| 105 | DwarfAbbrevSection = ".debug_abbrev"; |
| 106 | DwarfInfoSection = ".debug_info"; |
| 107 | DwarfLineSection = ".debug_line"; |
| 108 | DwarfFrameSection = ".debug_frame"; |
| 109 | DwarfPubNamesSection = ".debug_pubnames"; |
| 110 | DwarfPubTypesSection = ".debug_pubtypes"; |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 111 | DwarfDebugInlineSection = ".debug_inlined"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 112 | DwarfStrSection = ".debug_str"; |
| 113 | DwarfLocSection = ".debug_loc"; |
| 114 | DwarfARangesSection = ".debug_aranges"; |
| 115 | DwarfRangesSection = ".debug_ranges"; |
Chris Lattner | b839c3f | 2009-06-18 23:31:37 +0000 | [diff] [blame] | 116 | DwarfMacroInfoSection = ".debug_macinfo"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 117 | DwarfEHFrameSection = ".eh_frame"; |
| 118 | DwarfExceptionSection = ".gcc_except_table"; |
| 119 | AsmTransCBE = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 120 | } |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 121 | |
| 122 | TargetAsmInfo::~TargetAsmInfo() { |
| 123 | } |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 124 | |
| 125 | /// Measure the specified inline asm to determine an approximation of its |
| 126 | /// length. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 127 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 128 | /// count as an instruction. |
| 129 | /// Any other non-whitespace text is considered an instruction, with |
| 130 | /// multiple instructions separated by SeparatorChar or newlines. |
| 131 | /// Variable-length instructions are not handled here; this function |
| 132 | /// may be overloaded in the target code to do that. |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 133 | unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 134 | // Count the number of instructions in the asm. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 135 | bool atInsnStart = true; |
| 136 | unsigned Length = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 137 | for (; *Str; ++Str) { |
| 138 | if (*Str == '\n' || *Str == SeparatorChar) |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 139 | atInsnStart = true; |
| 140 | if (atInsnStart && !isspace(*Str)) { |
| 141 | Length += MaxInstLength; |
| 142 | atInsnStart = false; |
| 143 | } |
| 144 | if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0) |
| 145 | atInsnStart = false; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 148 | return Length; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 149 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 150 | |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 151 | unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 152 | bool Global) const { |
| 153 | return dwarf::DW_EH_PE_absptr; |
| 154 | } |
| 155 | |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 156 | unsigned TargetAsmInfo::getULEB128Size(unsigned Value) { |
| 157 | unsigned Size = 0; |
| 158 | do { |
| 159 | Value >>= 7; |
| 160 | Size += sizeof(int8_t); |
| 161 | } while (Value); |
| 162 | return Size; |
| 163 | } |
| 164 | |
| 165 | unsigned TargetAsmInfo::getSLEB128Size(int Value) { |
| 166 | unsigned Size = 0; |
| 167 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 168 | bool IsMore; |
| 169 | |
| 170 | do { |
| 171 | unsigned Byte = Value & 0x7f; |
| 172 | Value >>= 7; |
| 173 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 174 | Size += sizeof(int8_t); |
| 175 | } while (IsMore); |
| 176 | return Size; |
| 177 | } |