Expose method and ivars for measuring inline asm length properly.
[oota-llvm.git] / lib / Target / TargetAsmInfo.cpp
1 //===-- 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
17 using namespace llvm;
18
19 TargetAsmInfo::TargetAsmInfo() :
20   TextSection(".text"),
21   DataSection(".data"),
22   AddressSize(4),
23   NeedsSet(false),
24   MaxInstLength(4),
25   SeparatorChar(';'),
26   CommentString("#"),
27   GlobalPrefix(""),
28   PrivateGlobalPrefix("."),
29   GlobalVarAddrPrefix(""),
30   GlobalVarAddrSuffix(""),
31   FunctionAddrPrefix(""),
32   FunctionAddrSuffix(""),
33   InlineAsmStart("#APP"),
34   InlineAsmEnd("#NO_APP"),
35   ZeroDirective("\t.zero\t"),
36   ZeroDirectiveSuffix(0),
37   AsciiDirective("\t.ascii\t"),
38   AscizDirective("\t.asciz\t"),
39   Data8bitsDirective("\t.byte\t"),
40   Data16bitsDirective("\t.short\t"),
41   Data32bitsDirective("\t.long\t"),
42   Data64bitsDirective("\t.quad\t"),
43   AlignDirective("\t.align\t"),
44   AlignmentIsInBytes(true),
45   SwitchToSectionDirective("\t.section\t"),
46   TextSectionStartSuffix(""),
47   DataSectionStartSuffix(""),
48   SectionEndDirectiveSuffix(0),
49   ConstantPoolSection("\t.section .rodata\n"),
50   JumpTableDataSection("\t.section .rodata\n"),
51   JumpTableDirective(0),
52   StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
53   StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
54   FourByteConstantSection(0),
55   EightByteConstantSection(0),
56   SixteenByteConstantSection(0),
57   SetDirective(0),
58   LCOMMDirective(0),
59   COMMDirective("\t.comm\t"),
60   COMMDirectiveTakesAlignment(true),
61   HasDotTypeDotSizeDirective(true),
62   UsedDirective(0),
63   HasLEB128(false),
64   HasDotLoc(false),
65   HasDotFile(false),
66   DwarfAbbrevSection(".debug_abbrev"),
67   DwarfInfoSection(".debug_info"),
68   DwarfLineSection(".debug_line"),
69   DwarfFrameSection(".debug_frame"),
70   DwarfPubNamesSection(".debug_pubnames"),
71   DwarfPubTypesSection(".debug_pubtypes"),
72   DwarfStrSection(".debug_str"),
73   DwarfLocSection(".debug_loc"),
74   DwarfARangesSection(".debug_aranges"),
75   DwarfRangesSection(".debug_ranges"),
76   DwarfMacInfoSection(".debug_macinfo") {
77 }
78
79 TargetAsmInfo::~TargetAsmInfo() {
80 }
81
82 /// Measure the specified inline asm to determine an approximation of its
83 /// length.
84 unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
85   // Count the number of instructions in the asm.
86   unsigned NumInsts = 0;
87   for (; *Str; ++Str) {
88     if (*Str == '\n' || *Str == SeparatorChar)
89       ++NumInsts;
90   }
91
92   // Multiply by the worst-case length for each instruction.
93   return NumInsts * MaxInstLength;
94 }