Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 1 | //===-- MCAsmInfo.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 | |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAsmInfo.h" |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCContext.h" |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCExpr.h" |
| 18 | #include "llvm/MC/MCStreamer.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 19 | #include "llvm/Support/DataTypes.h" |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Dwarf.h" |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 21 | #include <cctype> |
| 22 | #include <cstring> |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Chris Lattner | 8eeba35 | 2010-01-20 06:34:14 +0000 | [diff] [blame] | 25 | MCAsmInfo::MCAsmInfo() { |
Evan Cheng | 1be0e27 | 2011-07-15 02:09:41 +0000 | [diff] [blame] | 26 | PointerSize = 4; |
| 27 | IsLittleEndian = true; |
| 28 | StackGrowsUp = false; |
Chris Lattner | f9f93e4 | 2010-01-23 07:21:06 +0000 | [diff] [blame] | 29 | HasSubsectionsViaSymbols = false; |
Chris Lattner | aac138e | 2010-01-19 02:09:44 +0000 | [diff] [blame] | 30 | HasMachoZeroFillDirective = false; |
Eric Christopher | c1a887d | 2010-05-20 00:49:07 +0000 | [diff] [blame] | 31 | HasMachoTBSSDirective = false; |
Duncan Sands | 147272b | 2011-09-02 18:07:19 +0000 | [diff] [blame] | 32 | StructorOutputOrder = Structors::ReversePriorityOrder; |
Chris Lattner | 71eae71 | 2010-01-19 04:34:02 +0000 | [diff] [blame] | 33 | HasStaticCtorDtorReferenceInStaticMode = false; |
Rafael Espindola | 767b1be | 2010-12-04 00:31:13 +0000 | [diff] [blame] | 34 | LinkerRequiresNonEmptyDwarfLines = false; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 35 | MaxInstLength = 4; |
| 36 | PCSymbol = "$"; |
Jim Grosbach | d31d304 | 2011-03-24 18:46:34 +0000 | [diff] [blame] | 37 | SeparatorString = ";"; |
Daniel Dunbar | 73163f8 | 2010-02-05 07:32:18 +0000 | [diff] [blame] | 38 | CommentColumn = 40; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 39 | CommentString = "#"; |
Chris Lattner | e07b75e | 2010-09-22 22:19:53 +0000 | [diff] [blame] | 40 | LabelSuffix = ":"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 41 | GlobalPrefix = ""; |
| 42 | PrivateGlobalPrefix = "."; |
Chris Lattner | 90f8b70 | 2009-07-21 17:30:51 +0000 | [diff] [blame] | 43 | LinkerPrivateGlobalPrefix = ""; |
Chris Lattner | e2b0601 | 2009-08-11 22:39:40 +0000 | [diff] [blame] | 44 | InlineAsmStart = "APP"; |
| 45 | InlineAsmEnd = "NO_APP"; |
Evan Cheng | bd27f5a | 2011-07-27 00:38:12 +0000 | [diff] [blame] | 46 | Code16Directive = ".code16"; |
| 47 | Code32Directive = ".code32"; |
| 48 | Code64Directive = ".code64"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 49 | AssemblerDialect = 0; |
Chris Lattner | a93ca92 | 2009-06-18 23:41:35 +0000 | [diff] [blame] | 50 | AllowQuotesInName = false; |
Anton Korobeynikov | c6f729e | 2009-09-18 16:57:42 +0000 | [diff] [blame] | 51 | AllowNameToStartWithDigit = false; |
Mon P Wang | b9a01bc | 2010-04-29 04:00:56 +0000 | [diff] [blame] | 52 | AllowPeriodsInName = true; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 53 | ZeroDirective = "\t.zero\t"; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 54 | AsciiDirective = "\t.ascii\t"; |
| 55 | AscizDirective = "\t.asciz\t"; |
| 56 | Data8bitsDirective = "\t.byte\t"; |
| 57 | Data16bitsDirective = "\t.short\t"; |
| 58 | Data32bitsDirective = "\t.long\t"; |
| 59 | Data64bitsDirective = "\t.quad\t"; |
Owen Anderson | 2fec6c5 | 2011-10-04 23:26:17 +0000 | [diff] [blame] | 60 | DataBegin = "$d."; |
| 61 | CodeBegin = "$a."; |
| 62 | JT8Begin = "$d."; |
| 63 | JT16Begin = "$d."; |
| 64 | JT32Begin = "$d."; |
Owen Anderson | 5d6a673 | 2011-10-14 20:28:57 +0000 | [diff] [blame] | 65 | SupportsDataRegions = false; |
Chris Lattner | 5277b22 | 2009-08-08 20:43:12 +0000 | [diff] [blame] | 66 | SunStyleELFSectionSwitchSyntax = false; |
Bruno Cardoso Lopes | fdf229e | 2009-08-13 23:30:21 +0000 | [diff] [blame] | 67 | UsesELFSectionDirectiveForBSS = false; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 68 | AlignDirective = "\t.align\t"; |
| 69 | AlignmentIsInBytes = true; |
| 70 | TextAlignFillValue = 0; |
Chris Lattner | 78f485a | 2010-01-25 21:10:10 +0000 | [diff] [blame] | 71 | GPRel32Directive = 0; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 72 | GlobalDirective = "\t.globl\t"; |
Chris Lattner | cee6332 | 2010-01-26 20:40:54 +0000 | [diff] [blame] | 73 | HasSetDirective = true; |
Rafael Espindola | 90a5a0c | 2010-12-22 21:51:29 +0000 | [diff] [blame] | 74 | HasAggressiveSymbolFolding = true; |
Benjamin Kramer | 36a1601 | 2011-09-01 23:04:27 +0000 | [diff] [blame] | 75 | LCOMMDirectiveType = LCOMM::None; |
Rafael Espindola | 2e2563b | 2010-01-26 20:21:43 +0000 | [diff] [blame] | 76 | COMMDirectiveAlignmentIsInBytes = true; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 77 | HasDotTypeDotSizeDirective = true; |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 78 | HasSingleParameterDotFile = true; |
Chris Lattner | 3a9be0e | 2010-01-23 05:51:36 +0000 | [diff] [blame] | 79 | HasNoDeadStrip = false; |
Kevin Enderby | e8e98d7 | 2010-11-19 18:39:33 +0000 | [diff] [blame] | 80 | HasSymbolResolver = false; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 81 | WeakRefDirective = 0; |
| 82 | WeakDefDirective = 0; |
Chris Lattner | 41eb8b4 | 2010-01-19 05:08:13 +0000 | [diff] [blame] | 83 | LinkOnceDirective = 0; |
Chris Lattner | 152a29b | 2010-01-23 06:53:23 +0000 | [diff] [blame] | 84 | HiddenVisibilityAttr = MCSA_Hidden; |
Stuart Hastings | 5129bde | 2011-02-23 02:27:05 +0000 | [diff] [blame] | 85 | HiddenDeclarationVisibilityAttr = MCSA_Hidden; |
Chris Lattner | 152a29b | 2010-01-23 06:53:23 +0000 | [diff] [blame] | 86 | ProtectedVisibilityAttr = MCSA_Protected; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 87 | HasLEB128 = false; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 88 | SupportsDebugInformation = false; |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 89 | ExceptionsType = ExceptionHandling::None; |
Devang Patel | 0f7fef3 | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 90 | DwarfUsesInlineInfoSection = false; |
Rafael Espindola | dc52ecf | 2011-05-10 20:35:05 +0000 | [diff] [blame] | 91 | DwarfRequiresRelocationForSectionOffset = true; |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 92 | DwarfSectionOffsetDirective = 0; |
Devang Patel | b1fcfbe | 2010-09-02 16:43:44 +0000 | [diff] [blame] | 93 | DwarfUsesLabelOffsetForRanges = true; |
Nick Lewycky | 390c40d | 2011-10-27 06:44:11 +0000 | [diff] [blame] | 94 | DwarfUsesRelocationsForStringPool = true; |
Akira Hatanaka | 3014b2f | 2011-07-07 20:30:33 +0000 | [diff] [blame] | 95 | DwarfRegNumForCFI = false; |
Chris Lattner | 8a29fa6 | 2010-03-12 21:03:47 +0000 | [diff] [blame] | 96 | HasMicrosoftFastStdCallMangling = false; |
Chris Lattner | 18a4c16 | 2009-08-02 07:24:22 +0000 | [diff] [blame] | 97 | |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 98 | AsmTransCBE = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 99 | } |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 100 | |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 101 | MCAsmInfo::~MCAsmInfo() { |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 102 | } |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 103 | |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 104 | |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 105 | unsigned MCAsmInfo::getULEB128Size(unsigned Value) { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 106 | unsigned Size = 0; |
| 107 | do { |
| 108 | Value >>= 7; |
| 109 | Size += sizeof(int8_t); |
| 110 | } while (Value); |
| 111 | return Size; |
| 112 | } |
| 113 | |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 114 | unsigned MCAsmInfo::getSLEB128Size(int Value) { |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 115 | unsigned Size = 0; |
| 116 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 117 | bool IsMore; |
| 118 | |
| 119 | do { |
| 120 | unsigned Byte = Value & 0x7f; |
| 121 | Value >>= 7; |
| 122 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 123 | Size += sizeof(int8_t); |
| 124 | } while (IsMore); |
| 125 | return Size; |
| 126 | } |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 127 | |
| 128 | const MCExpr * |
| 129 | MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 130 | unsigned Encoding, |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 131 | MCStreamer &Streamer) const { |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 132 | return getExprForFDESymbol(Sym, Encoding, Streamer); |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | const MCExpr * |
| 136 | MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym, |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 137 | unsigned Encoding, |
Rafael Espindola | a0057ca | 2011-04-28 21:04:39 +0000 | [diff] [blame] | 138 | MCStreamer &Streamer) const { |
Rafael Espindola | debd7e4 | 2011-05-01 03:50:49 +0000 | [diff] [blame] | 139 | if (!(Encoding & dwarf::DW_EH_PE_pcrel)) |
| 140 | return MCSymbolRefExpr::Create(Sym, Streamer.getContext()); |
| 141 | |
| 142 | MCContext &Context = Streamer.getContext(); |
| 143 | const MCExpr *Res = MCSymbolRefExpr::Create(Sym, Context); |
| 144 | MCSymbol *PCSym = Context.CreateTempSymbol(); |
| 145 | Streamer.EmitLabel(PCSym); |
| 146 | const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, Context); |
| 147 | return MCBinaryExpr::CreateSub(Res, PC, Context); |
Rafael Espindola | bfa27cc | 2011-04-28 16:09:09 +0000 | [diff] [blame] | 148 | } |