1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | #include "clang/Basic/XRayLists.h" |
13 | |
14 | using namespace clang; |
15 | |
16 | XRayFunctionFilter::XRayFunctionFilter( |
17 | ArrayRef<std::string> AlwaysInstrumentPaths, |
18 | ArrayRef<std::string> NeverInstrumentPaths, |
19 | ArrayRef<std::string> AttrListPaths, SourceManager &SM) |
20 | : AlwaysInstrument( |
21 | llvm::SpecialCaseList::createOrDie(AlwaysInstrumentPaths)), |
22 | NeverInstrument(llvm::SpecialCaseList::createOrDie(NeverInstrumentPaths)), |
23 | AttrList(llvm::SpecialCaseList::createOrDie(AttrListPaths)), SM(SM) {} |
24 | |
25 | XRayFunctionFilter::ImbueAttribute |
26 | XRayFunctionFilter::shouldImbueFunction(StringRef FunctionName) const { |
27 | |
28 | |
29 | |
30 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", FunctionName, |
31 | "arg1") || |
32 | AttrList->inSection("always", "fun", FunctionName, "arg1")) |
33 | return ImbueAttribute::ALWAYS_ARG1; |
34 | if (AlwaysInstrument->inSection("xray_always_instrument", "fun", |
35 | FunctionName) || |
36 | AttrList->inSection("always", "fun", FunctionName)) |
37 | return ImbueAttribute::ALWAYS; |
38 | |
39 | if (NeverInstrument->inSection("xray_never_instrument", "fun", |
40 | FunctionName) || |
41 | AttrList->inSection("never", "fun", FunctionName)) |
42 | return ImbueAttribute::NEVER; |
43 | |
44 | return ImbueAttribute::NONE; |
45 | } |
46 | |
47 | XRayFunctionFilter::ImbueAttribute |
48 | XRayFunctionFilter::shouldImbueFunctionsInFile(StringRef Filename, |
49 | StringRef Category) const { |
50 | if (AlwaysInstrument->inSection("xray_always_instrument", "src", Filename, |
51 | Category) || |
52 | AttrList->inSection("always", "src", Filename, Category)) |
53 | return ImbueAttribute::ALWAYS; |
54 | if (NeverInstrument->inSection("xray_never_instrument", "src", Filename, |
55 | Category) || |
56 | AttrList->inSection("never", "src", Filename, Category)) |
57 | return ImbueAttribute::NEVER; |
58 | return ImbueAttribute::NONE; |
59 | } |
60 | |
61 | XRayFunctionFilter::ImbueAttribute |
62 | XRayFunctionFilter::shouldImbueLocation(SourceLocation Loc, |
63 | StringRef Category) const { |
64 | if (!Loc.isValid()) |
65 | return ImbueAttribute::NONE; |
66 | return this->shouldImbueFunctionsInFile(SM.getFilename(SM.getFileLoc(Loc)), |
67 | Category); |
68 | } |
69 | |