-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTreeDump.cpp
More file actions
77 lines (66 loc) · 2.39 KB
/
TreeDump.cpp
File metadata and controls
77 lines (66 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//===- TreeDump.cpp - Dump IncludeTree to stdout --*- C++ -*-===//
//
// This project is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
/// \file
/// Entrypoint of the IncludeTree dump tool.
//
//===----------------------------------------------------------------------===//
/* Author: Giuliano Belinassi */
#include "ArgvParser.hh"
#include "Passes.hh"
#include "Error.hh"
#include <iostream>
#include <stdio.h>
using namespace llvm;
using namespace clang;
void print_usage_message(void)
{
llvm::outs() <<
"OVERVIEW: Tool to show the tree of includes of a C/C++ file.\n"
" It should be invoked as a C/C++ compiler.\n"
"\n"
"USAGE: ce-includetree [options] file...\n"
"\n"
"CLANG-EXTRACT OPTIONS:\n"
" <clang-switch> A clang switch, as specified by calling clang --help.\n"
" -D__KERNEL__ Indicate that we are processing a Linux sourcefile.\n"
" -DCE_KEEP_INCLUDES Keep all possible #include<file> directives.\n"
" -DCE_KEEP_INCLUDES=<policy>\n"
" Keep all possible #include<file> directives, but using the\n"
" specified include expansion <policy>. Valid values are\n"
" nothing, everything, kernel, system and compiler.\n"
" -DCE_EXPAND_INCLUDES=<args>\n"
" Force expansion of the headers provided in <args>.\n"
" -DCE_NOT_EXPAND_INCLUDES=<args>\n"
" Force the following headers to NOT be expanded.\n"
"\n";
}
int main(int argc, char **argv)
{
ArgvParser args(argc, argv);
PassManager::Context ctx(args);
if (argc <= 1) {
print_usage_message();
return 0;
}
/* Cleverly silence any error from clang. */
fclose(stderr);
if (Build_ASTUnit(&ctx) == false){
llvm::outs() << "Unable to create ASTUnit of " << ctx.InputPath << '\n';
return 1;
}
const DiagnosticsEngine &de = ctx.AST->getDiagnostics();
if (de.hasErrorOccurred()) {
llvm::outs() << "ASTUnit of " << ctx.InputPath << " contain errors. Aborting.\n";
return 1;
}
IncludeTree IT(ctx.AST.get(), ctx.IncExpansionPolicy, ctx.HeadersToExpand,
ctx.HeadersToNotExpand);
IT.Dump(llvm::outs());
return 0;
}