Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +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 | b4f658c | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
asl | 4eeee01 | 2009-01-27 22:29:24 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Anton Korobeynikov | b4f658c | 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" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetAsmInfo.h" |
Chris Lattner | 2a7dd7d | 2009-07-26 06:11:33 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetData.h" |
Anton Korobeynikov | 1dc008a | 2009-03-29 17:13:49 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
Anton Korobeynikov | b4f658c | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | 65c0d87 | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Dwarf.h" |
Edwin Török | 675d562 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 27 | #include <cctype> |
| 28 | #include <cstring> |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Chris Lattner | 224957e | 2009-07-24 20:14:10 +0000 | [diff] [blame] | 31 | TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) { |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 32 | ZeroFillDirective = 0; |
| 33 | NonexecutableStackDirective = 0; |
| 34 | NeedsSet = false; |
| 35 | MaxInstLength = 4; |
| 36 | PCSymbol = "$"; |
| 37 | SeparatorChar = ';'; |
David Greene | 6348612 | 2009-07-13 20:25:48 +0000 | [diff] [blame] | 38 | CommentColumn = 60; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 39 | CommentString = "#"; |
David Greene | 47974bf | 2009-07-20 22:02:59 +0000 | [diff] [blame] | 40 | FirstOperandColumn = 0; |
| 41 | MaxOperandLength = 0; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 42 | GlobalPrefix = ""; |
| 43 | PrivateGlobalPrefix = "."; |
Chris Lattner | c889b3b | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 44 | LinkerPrivateGlobalPrefix = ""; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 45 | JumpTableSpecialLabelPrefix = 0; |
| 46 | GlobalVarAddrPrefix = ""; |
| 47 | GlobalVarAddrSuffix = ""; |
| 48 | FunctionAddrPrefix = ""; |
| 49 | FunctionAddrSuffix = ""; |
| 50 | PersonalityPrefix = ""; |
| 51 | PersonalitySuffix = ""; |
| 52 | NeedsIndirectEncoding = false; |
| 53 | InlineAsmStart = "#APP"; |
| 54 | InlineAsmEnd = "#NO_APP"; |
| 55 | AssemblerDialect = 0; |
Chris Lattner | 690b02c | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 56 | AllowQuotesInName = false; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 57 | ZeroDirective = "\t.zero\t"; |
| 58 | ZeroDirectiveSuffix = 0; |
| 59 | AsciiDirective = "\t.ascii\t"; |
| 60 | AscizDirective = "\t.asciz\t"; |
| 61 | Data8bitsDirective = "\t.byte\t"; |
| 62 | Data16bitsDirective = "\t.short\t"; |
| 63 | Data32bitsDirective = "\t.long\t"; |
| 64 | Data64bitsDirective = "\t.quad\t"; |
| 65 | AlignDirective = "\t.align\t"; |
| 66 | AlignmentIsInBytes = true; |
| 67 | TextAlignFillValue = 0; |
| 68 | SwitchToSectionDirective = "\t.section\t"; |
| 69 | TextSectionStartSuffix = ""; |
| 70 | DataSectionStartSuffix = ""; |
| 71 | SectionEndDirectiveSuffix = 0; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 72 | JumpTableDirective = 0; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 73 | GlobalDirective = "\t.globl\t"; |
| 74 | SetDirective = 0; |
| 75 | LCOMMDirective = 0; |
| 76 | COMMDirective = "\t.comm\t"; |
| 77 | COMMDirectiveTakesAlignment = true; |
| 78 | HasDotTypeDotSizeDirective = true; |
Rafael Espindola | 5cf2e55 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 79 | HasSingleParameterDotFile = true; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 80 | UsedDirective = 0; |
| 81 | WeakRefDirective = 0; |
| 82 | WeakDefDirective = 0; |
| 83 | // FIXME: These are ELFish - move to ELFTAI. |
| 84 | HiddenDirective = "\t.hidden\t"; |
| 85 | ProtectedDirective = "\t.protected\t"; |
| 86 | AbsoluteDebugSectionOffsets = false; |
| 87 | AbsoluteEHSectionOffsets = false; |
| 88 | HasLEB128 = false; |
| 89 | HasDotLocAndDotFile = false; |
| 90 | SupportsDebugInformation = false; |
| 91 | SupportsExceptionHandling = false; |
| 92 | DwarfRequiresFrameSection = true; |
Devang Patel | 88bf96e | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 93 | DwarfUsesInlineInfoSection = false; |
Chris Lattner | 5c3475e | 2009-07-17 20:46:40 +0000 | [diff] [blame] | 94 | Is_EHSymbolPrivate = true; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 95 | GlobalEHDirective = 0; |
| 96 | SupportsWeakOmittedEHFrame = true; |
| 97 | DwarfSectionOffsetDirective = 0; |
| 98 | DwarfAbbrevSection = ".debug_abbrev"; |
| 99 | DwarfInfoSection = ".debug_info"; |
| 100 | DwarfLineSection = ".debug_line"; |
| 101 | DwarfFrameSection = ".debug_frame"; |
| 102 | DwarfPubNamesSection = ".debug_pubnames"; |
| 103 | DwarfPubTypesSection = ".debug_pubtypes"; |
Devang Patel | 88bf96e | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 104 | DwarfDebugInlineSection = ".debug_inlined"; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 105 | DwarfStrSection = ".debug_str"; |
| 106 | DwarfLocSection = ".debug_loc"; |
| 107 | DwarfARangesSection = ".debug_aranges"; |
| 108 | DwarfRangesSection = ".debug_ranges"; |
Chris Lattner | ecbf73b | 2009-06-18 23:31:37 +0000 | [diff] [blame] | 109 | DwarfMacroInfoSection = ".debug_macinfo"; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 110 | DwarfEHFrameSection = ".eh_frame"; |
Anton Korobeynikov | 3829e8a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 111 | AsmTransCBE = 0; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | TargetAsmInfo::~TargetAsmInfo() { |
| 115 | } |
| 116 | |
| 117 | /// Measure the specified inline asm to determine an approximation of its |
| 118 | /// length. |
| 119 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 120 | /// count as an instruction. |
| 121 | /// Any other non-whitespace text is considered an instruction, with |
| 122 | /// multiple instructions separated by SeparatorChar or newlines. |
| 123 | /// Variable-length instructions are not handled here; this function |
| 124 | /// may be overloaded in the target code to do that. |
| 125 | unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 126 | // Count the number of instructions in the asm. |
| 127 | bool atInsnStart = true; |
| 128 | unsigned Length = 0; |
| 129 | for (; *Str; ++Str) { |
| 130 | if (*Str == '\n' || *Str == SeparatorChar) |
| 131 | atInsnStart = true; |
| 132 | if (atInsnStart && !isspace(*Str)) { |
| 133 | Length += MaxInstLength; |
| 134 | atInsnStart = false; |
| 135 | } |
| 136 | if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0) |
| 137 | atInsnStart = false; |
| 138 | } |
| 139 | |
| 140 | return Length; |
| 141 | } |
| 142 | |
Chris Lattner | 8b0bb37 | 2009-07-31 21:39:55 +0000 | [diff] [blame] | 143 | unsigned TargetAsmInfo::PreferredEHDataFormat() const { |
Anton Korobeynikov | 65c0d87 | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 144 | return dwarf::DW_EH_PE_absptr; |
| 145 | } |
| 146 | |
asl | c200b11 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 147 | unsigned TargetAsmInfo::getULEB128Size(unsigned Value) { |
| 148 | unsigned Size = 0; |
| 149 | do { |
| 150 | Value >>= 7; |
| 151 | Size += sizeof(int8_t); |
| 152 | } while (Value); |
| 153 | return Size; |
| 154 | } |
| 155 | |
| 156 | unsigned TargetAsmInfo::getSLEB128Size(int Value) { |
| 157 | unsigned Size = 0; |
| 158 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 159 | bool IsMore; |
| 160 | |
| 161 | do { |
| 162 | unsigned Byte = Value & 0x7f; |
| 163 | Value >>= 7; |
| 164 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 165 | Size += sizeof(int8_t); |
| 166 | } while (IsMore); |
| 167 | return Size; |
| 168 | } |