blob: 1a3daf0eaa90f3346f85e49277d6d0ab6c2ebb04 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by James M. Laskey and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
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"
16#include <cctype>
17#include <cstring>
18
19using namespace llvm;
20
21TargetAsmInfo::TargetAsmInfo() :
22 TextSection("\t.text"),
23 DataSection("\t.data"),
24 BSSSection("\t.bss"),
25 TLSDataSection("\t.section .tdata,\"awT\",@progbits"),
26 TLSBSSSection("\t.section .tbss,\"awT\",@nobits"),
27 ZeroFillDirective(0),
28 AddressSize(4),
29 NeedsSet(false),
30 MaxInstLength(4),
31 PCSymbol("$"),
32 SeparatorChar(';'),
33 CommentString("#"),
34 GlobalPrefix(""),
35 PrivateGlobalPrefix("."),
36 JumpTableSpecialLabelPrefix(0),
37 GlobalVarAddrPrefix(""),
38 GlobalVarAddrSuffix(""),
39 FunctionAddrPrefix(""),
40 FunctionAddrSuffix(""),
Bill Wendlingd1bda4f2007-09-11 08:27:17 +000041 PersonalityPrefix(""),
42 PersonalitySuffix(""),
Bill Wendling2d369922007-09-11 17:20:55 +000043 NeedsIndirectEncoding(false),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 InlineAsmStart("#APP"),
45 InlineAsmEnd("#NO_APP"),
46 AssemblerDialect(0),
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),
61 ConstantPoolSection("\t.section .rodata"),
62 JumpTableDataSection("\t.section .rodata"),
63 JumpTableDirective(0),
64 CStringSection(0),
65 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
66 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
67 FourByteConstantSection(0),
68 EightByteConstantSection(0),
69 SixteenByteConstantSection(0),
70 ReadOnlySection(0),
71 GlobalDirective(0),
72 SetDirective(0),
73 LCOMMDirective(0),
74 COMMDirective("\t.comm\t"),
75 COMMDirectiveTakesAlignment(true),
76 HasDotTypeDotSizeDirective(true),
77 UsedDirective(0),
78 WeakRefDirective(0),
79 HiddenDirective("\t.hidden\t"),
80 ProtectedDirective("\t.protected\t"),
81 AbsoluteDebugSectionOffsets(false),
82 AbsoluteEHSectionOffsets(false),
83 HasLEB128(false),
84 HasDotLoc(false),
85 HasDotFile(false),
86 SupportsDebugInformation(false),
87 SupportsExceptionHandling(false),
88 DwarfRequiresFrameSection(true),
89 DwarfSectionOffsetDirective(0),
90 DwarfAbbrevSection(".debug_abbrev"),
91 DwarfInfoSection(".debug_info"),
92 DwarfLineSection(".debug_line"),
93 DwarfFrameSection(".debug_frame"),
94 DwarfPubNamesSection(".debug_pubnames"),
95 DwarfPubTypesSection(".debug_pubtypes"),
96 DwarfStrSection(".debug_str"),
97 DwarfLocSection(".debug_loc"),
98 DwarfARangesSection(".debug_aranges"),
99 DwarfRangesSection(".debug_ranges"),
100 DwarfMacInfoSection(".debug_macinfo"),
101 DwarfEHFrameSection(".eh_frame"),
102 DwarfExceptionSection(".gcc_except_table"),
103 AsmTransCBE(0) {
104}
105
106TargetAsmInfo::~TargetAsmInfo() {
107}
108
109/// Measure the specified inline asm to determine an approximation of its
110/// length.
111/// Comments (which run till the next SeparatorChar or newline) do not
112/// count as an instruction.
113/// Any other non-whitespace text is considered an instruction, with
114/// multiple instructions separated by SeparatorChar or newlines.
115/// Variable-length instructions are not handled here; this function
116/// may be overloaded in the target code to do that.
117unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
118 // Count the number of instructions in the asm.
119 bool atInsnStart = true;
120 unsigned Length = 0;
121 for (; *Str; ++Str) {
122 if (*Str == '\n' || *Str == SeparatorChar)
123 atInsnStart = true;
124 if (atInsnStart && !isspace(*Str)) {
125 Length += MaxInstLength;
126 atInsnStart = false;
127 }
128 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
129 atInsnStart = false;
130 }
131
132 return Length;
133}
134