1 //===-- esan_flags.cc -------------------------------------------*- C++ -*-===//
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 is a part of EfficiencySanitizer, a family of performance tuners.
11 //
12 // Esan flag parsing logic.
13 //===----------------------------------------------------------------------===//
14
15 #include "esan_flags.h"
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_flag_parser.h"
18 #include "sanitizer_common/sanitizer_flags.h"
19
20 using namespace __sanitizer;
21
22 namespace __esan {
23
24 static const char EsanOptsEnv[] = "ESAN_OPTIONS";
25
26 Flags EsanFlagsDontUseDirectly;
27
setDefaults()28 void Flags::setDefaults() {
29 #define ESAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
30 #include "esan_flags.inc"
31 #undef ESAN_FLAG
32 }
33
registerEsanFlags(FlagParser * Parser,Flags * F)34 static void registerEsanFlags(FlagParser *Parser, Flags *F) {
35 #define ESAN_FLAG(Type, Name, DefaultValue, Description) \
36 RegisterFlag(Parser, #Name, Description, &F->Name);
37 #include "esan_flags.inc"
38 #undef ESAN_FLAG
39 }
40
initializeFlags()41 void initializeFlags() {
42 SetCommonFlagsDefaults();
43 Flags *F = getFlags();
44 F->setDefaults();
45
46 FlagParser Parser;
47 registerEsanFlags(&Parser, F);
48 RegisterCommonFlags(&Parser);
49 Parser.ParseString(GetEnv(EsanOptsEnv));
50
51 InitializeCommonFlags();
52 if (Verbosity())
53 ReportUnrecognizedFlags();
54 if (common_flags()->help)
55 Parser.PrintFlagDescriptions();
56
57 __sanitizer_set_report_path(common_flags()->log_path);
58 }
59
60 } // namespace __esan
61