 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
67.4% |
31 / 46 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
87.0% |
40 / 46 |
| |
|
Line Coverage: |
100.0% |
37 / 37 |
| |
 |
|
 |
1 : //===--- Builtins.cpp - Builtin function implementation -------------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file implements various things for builtin functions.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "clang/Basic/Builtins.h"
15 : #include "clang/Basic/IdentifierTable.h"
16 : #include "clang/Basic/TargetInfo.h"
17 : using namespace clang;
18 :
19 : static const Builtin::Info BuiltinInfo[] = {
20 : { "not a builtin function", 0, 0, 0, false },
21 : #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
22 : #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
23 : #include "clang/Basic/Builtins.def"
24 : };
25 :
26 22284: const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const {
10816: branch 0 taken
11468: branch 1 taken
27 22284: if (ID < Builtin::FirstTSBuiltin)
28 10816: return BuiltinInfo[ID];
0: branch 0 not taken
11468: branch 1 taken
29 11468: assert(ID - Builtin::FirstTSBuiltin < NumTSRecords && "Invalid builtin ID!");
30 11468: return TSRecords[ID - Builtin::FirstTSBuiltin];
31 : }
32 :
33 2533: Builtin::Context::Context(const TargetInfo &Target) {
34 : // Get the target specific builtins from the target.
35 2533: TSRecords = 0;
36 2533: NumTSRecords = 0;
37 2533: Target.getTargetBuiltins(TSRecords, NumTSRecords);
38 2533: }
39 :
40 : /// InitializeBuiltins - Mark the identifiers for all the builtins with their
41 : /// appropriate builtin ID # and mark any non-portable builtin identifiers as
42 : /// such.
43 : void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
44 2484: bool NoBuiltins) {
45 : // Step #1: mark all target-independent builtins with their ID's.
1001052: branch 0 taken
2484: branch 1 taken
46 1003536: for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
1001052: branch 0 taken
0: branch 1 not taken
11687: branch 2 taken
989365: branch 3 taken
10034: branch 5 taken
1653: branch 6 taken
47 1001052: if (!BuiltinInfo[i].Suppressed &&
48 : (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
49 999399: Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
50 :
51 : // Step #2: Register target-specific builtins.
622465: branch 0 taken
2484: branch 1 taken
52 624949: for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
622465: branch 0 taken
0: branch 1 not taken
2809: branch 2 taken
619656: branch 3 taken
2809: branch 4 taken
0: branch 5 not taken
2809: branch 7 taken
0: branch 8 not taken
53 622465: if (!TSRecords[i].Suppressed &&
54 : (!NoBuiltins ||
55 : (TSRecords[i].Attributes &&
56 : !strchr(TSRecords[i].Attributes, 'f'))))
57 622465: Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);
58 2484: }
59 :
60 : void
61 : Builtin::Context::GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,
62 44: bool NoBuiltins) {
63 : // Final all target-independent names
17732: branch 0 taken
44: branch 1 taken
64 17776: for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
17732: branch 0 taken
0: branch 1 not taken
0: branch 2 not taken
17732: branch 3 taken
0: branch 5 not taken
0: branch 6 not taken
65 17732: if (!BuiltinInfo[i].Suppressed &&
66 : (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
67 17732: Names.push_back(BuiltinInfo[i].Name);
68 :
69 : // Find target-specific names.
11220: branch 0 taken
44: branch 1 taken
70 11264: for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
11220: branch 0 taken
0: branch 1 not taken
0: branch 2 not taken
11220: branch 3 taken
11220: branch 4 taken
11220: branch 5 taken
0: branch 7 not taken
0: branch 8 not taken
71 11220: if (!TSRecords[i].Suppressed &&
72 : (!NoBuiltins ||
73 : (TSRecords[i].Attributes &&
74 : !strchr(TSRecords[i].Attributes, 'f'))))
75 11220: Names.push_back(TSRecords[i].Name);
76 44: }
77 :
78 : bool
79 : Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx,
80 1582: bool &HasVAListArg) {
81 1582: const char *Printf = strpbrk(GetRecord(ID).Attributes, "pP");
1397: branch 0 taken
185: branch 1 taken
82 1582: if (!Printf)
83 1397: return false;
84 :
85 185: HasVAListArg = (*Printf == 'P');
86 :
87 185: ++Printf;
0: branch 0 not taken
185: branch 1 taken
88 185: assert(*Printf == ':' && "p or P specifier must have be followed by a ':'");
89 185: ++Printf;
90 :
0: branch 1 not taken
185: branch 2 taken
91 185: assert(strchr(Printf, ':') && "printf specifier must end with a ':'");
92 185: FormatIdx = strtol(Printf, 0, 10);
93 185: return true;
94 : }
95 :
Generated: 2010-02-10 01:31 by zcov