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