Home | History | Annotate | Download | only in esan
      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 namespace __esan {
     21 
     22 static const char EsanOptsEnv[] = "ESAN_OPTIONS";
     23 
     24 Flags EsanFlagsDontUseDirectly;
     25 
     26 void Flags::setDefaults() {
     27 #define ESAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
     28 #include "esan_flags.inc"
     29 #undef ESAN_FLAG
     30 }
     31 
     32 static void registerEsanFlags(FlagParser *Parser, Flags *F) {
     33 #define ESAN_FLAG(Type, Name, DefaultValue, Description) \
     34   RegisterFlag(Parser, #Name, Description, &F->Name);
     35 #include "esan_flags.inc"
     36 #undef ESAN_FLAG
     37 }
     38 
     39 void initializeFlags() {
     40   SetCommonFlagsDefaults();
     41   Flags *F = getFlags();
     42   F->setDefaults();
     43 
     44   FlagParser Parser;
     45   registerEsanFlags(&Parser, F);
     46   RegisterCommonFlags(&Parser);
     47   Parser.ParseString(GetEnv(EsanOptsEnv));
     48 
     49   InitializeCommonFlags();
     50   if (Verbosity())
     51     ReportUnrecognizedFlags();
     52   if (common_flags()->help)
     53     Parser.PrintFlagDescriptions();
     54 
     55   __sanitizer_set_report_path(common_flags()->log_path);
     56 }
     57 
     58 } // namespace __esan
     59