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" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame^] | 16 | #include "llvm/Support/Dwarf.h" |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 17 | #include <cctype> |
| 18 | #include <cstring> |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | TargetAsmInfo::TargetAsmInfo() : |
Dan Gohman | 9570165 | 2007-05-03 18:46:30 +0000 | [diff] [blame] | 23 | TextSection("\t.text"), |
| 24 | DataSection("\t.data"), |
| 25 | BSSSection("\t.bss"), |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 26 | TLSDataSection("\t.section .tdata,\"awT\",@progbits"), |
| 27 | TLSBSSSection("\t.section .tbss,\"awT\",@nobits"), |
Chris Lattner | 6f198df | 2007-01-17 17:42:42 +0000 | [diff] [blame] | 28 | ZeroFillDirective(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 29 | NeedsSet(false), |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 30 | MaxInstLength(4), |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 31 | PCSymbol("$"), |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 32 | SeparatorChar(';'), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 33 | CommentString("#"), |
| 34 | GlobalPrefix(""), |
| 35 | PrivateGlobalPrefix("."), |
Chris Lattner | 393a8ee | 2007-01-18 01:12:56 +0000 | [diff] [blame] | 36 | JumpTableSpecialLabelPrefix(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 37 | GlobalVarAddrPrefix(""), |
| 38 | GlobalVarAddrSuffix(""), |
| 39 | FunctionAddrPrefix(""), |
| 40 | FunctionAddrSuffix(""), |
Bill Wendling | d60da49 | 2007-09-11 08:27:17 +0000 | [diff] [blame] | 41 | PersonalityPrefix(""), |
| 42 | PersonalitySuffix(""), |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 43 | NeedsIndirectEncoding(false), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 44 | InlineAsmStart("#APP"), |
| 45 | InlineAsmEnd("#NO_APP"), |
Bill Wendling | eb9a42c | 2007-01-16 03:42:04 +0000 | [diff] [blame] | 46 | AssemblerDialect(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 47 | ZeroDirective("\t.zero\t"), |
| 48 | ZeroDirectiveSuffix(0), |
| 49 | AsciiDirective("\t.ascii\t"), |
| 50 | AscizDirective("\t.asciz\t"), |
| 51 | Data8bitsDirective("\t.byte\t"), |
| 52 | Data16bitsDirective("\t.short\t"), |
| 53 | Data32bitsDirective("\t.long\t"), |
| 54 | Data64bitsDirective("\t.quad\t"), |
| 55 | AlignDirective("\t.align\t"), |
| 56 | AlignmentIsInBytes(true), |
| 57 | SwitchToSectionDirective("\t.section\t"), |
| 58 | TextSectionStartSuffix(""), |
| 59 | DataSectionStartSuffix(""), |
| 60 | SectionEndDirectiveSuffix(0), |
Dan Gohman | af67ea7 | 2007-06-14 15:00:27 +0000 | [diff] [blame] | 61 | ConstantPoolSection("\t.section .rodata"), |
| 62 | JumpTableDataSection("\t.section .rodata"), |
Andrew Lenharth | beec30e | 2006-09-24 19:45:58 +0000 | [diff] [blame] | 63 | JumpTableDirective(0), |
Reid Spencer | c50209b | 2006-10-27 16:14:06 +0000 | [diff] [blame] | 64 | CStringSection(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 65 | StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"), |
| 66 | StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"), |
| 67 | FourByteConstantSection(0), |
| 68 | EightByteConstantSection(0), |
| 69 | SixteenByteConstantSection(0), |
Evan Cheng | be346c9 | 2007-03-08 01:00:38 +0000 | [diff] [blame] | 70 | ReadOnlySection(0), |
Gordon Henriksen | 81361d6 | 2007-12-23 20:58:16 +0000 | [diff] [blame] | 71 | GlobalDirective("\t.globl\t"), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 72 | SetDirective(0), |
| 73 | LCOMMDirective(0), |
| 74 | COMMDirective("\t.comm\t"), |
| 75 | COMMDirectiveTakesAlignment(true), |
| 76 | HasDotTypeDotSizeDirective(true), |
Chris Lattner | cb05af8 | 2006-09-26 03:38:18 +0000 | [diff] [blame] | 77 | UsedDirective(0), |
Evan Cheng | 8752ce6 | 2006-12-01 20:47:11 +0000 | [diff] [blame] | 78 | WeakRefDirective(0), |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 79 | WeakDefDirective(0), |
Chris Lattner | 9784bc7 | 2007-01-14 06:27:21 +0000 | [diff] [blame] | 80 | HiddenDirective("\t.hidden\t"), |
Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 81 | ProtectedDirective("\t.protected\t"), |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 82 | AbsoluteDebugSectionOffsets(false), |
| 83 | AbsoluteEHSectionOffsets(false), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 84 | HasLEB128(false), |
Dan Gohman | 7225273 | 2007-09-24 21:09:53 +0000 | [diff] [blame] | 85 | HasDotLocAndDotFile(false), |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 86 | SupportsDebugInformation(false), |
Jim Laskey | 072200c | 2007-01-29 18:51:14 +0000 | [diff] [blame] | 87 | SupportsExceptionHandling(false), |
Reid Spencer | 02b8511 | 2006-10-30 22:32:30 +0000 | [diff] [blame] | 88 | DwarfRequiresFrameSection(true), |
Dale Johannesen | 9305dcb | 2007-11-21 00:45:00 +0000 | [diff] [blame] | 89 | GlobalEHDirective(0), |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 90 | SupportsWeakOmittedEHFrame(true), |
Dale Johannesen | 0991d0b | 2008-01-15 23:25:27 +0000 | [diff] [blame] | 91 | ShortenEHDataOn64Bit(false), |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 92 | DwarfSectionOffsetDirective(0), |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 93 | DwarfAbbrevSection(".debug_abbrev"), |
| 94 | DwarfInfoSection(".debug_info"), |
| 95 | DwarfLineSection(".debug_line"), |
| 96 | DwarfFrameSection(".debug_frame"), |
| 97 | DwarfPubNamesSection(".debug_pubnames"), |
| 98 | DwarfPubTypesSection(".debug_pubtypes"), |
| 99 | DwarfStrSection(".debug_str"), |
| 100 | DwarfLocSection(".debug_loc"), |
| 101 | DwarfARangesSection(".debug_aranges"), |
| 102 | DwarfRangesSection(".debug_ranges"), |
Andrew Lenharth | 3655de6 | 2006-11-28 19:52:20 +0000 | [diff] [blame] | 103 | DwarfMacInfoSection(".debug_macinfo"), |
Jim Laskey | b82313f | 2007-02-01 16:31:34 +0000 | [diff] [blame] | 104 | DwarfEHFrameSection(".eh_frame"), |
Jim Laskey | a15be8c | 2007-02-21 22:43:40 +0000 | [diff] [blame] | 105 | DwarfExceptionSection(".gcc_except_table"), |
Andrew Lenharth | 3655de6 | 2006-11-28 19:52:20 +0000 | [diff] [blame] | 106 | AsmTransCBE(0) { |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 107 | } |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 108 | |
| 109 | TargetAsmInfo::~TargetAsmInfo() { |
| 110 | } |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 111 | |
| 112 | /// Measure the specified inline asm to determine an approximation of its |
| 113 | /// length. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 114 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 115 | /// count as an instruction. |
| 116 | /// Any other non-whitespace text is considered an instruction, with |
| 117 | /// multiple instructions separated by SeparatorChar or newlines. |
| 118 | /// Variable-length instructions are not handled here; this function |
| 119 | /// may be overloaded in the target code to do that. |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 120 | unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 121 | // Count the number of instructions in the asm. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 122 | bool atInsnStart = true; |
| 123 | unsigned Length = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 124 | for (; *Str; ++Str) { |
| 125 | if (*Str == '\n' || *Str == SeparatorChar) |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 126 | atInsnStart = true; |
| 127 | if (atInsnStart && !isspace(*Str)) { |
| 128 | Length += MaxInstLength; |
| 129 | atInsnStart = false; |
| 130 | } |
| 131 | if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0) |
| 132 | atInsnStart = false; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 135 | return Length; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 136 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 137 | |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame^] | 138 | unsigned TargetAsmInfo::PreferredEHDataFormat(unsigned Reason, |
| 139 | bool Global) const { |
| 140 | return dwarf::DW_EH_PE_absptr; |
| 141 | } |
| 142 | |