• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_FLAGS_FLAGS_H_
6 #define V8_FLAGS_FLAGS_H_
7 
8 #include <vector>
9 
10 #include "src/common/globals.h"
11 #include "src/wasm/wasm-limits.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // Declare all of our flags.
17 #define FLAG_MODE_DECLARE
18 #include "src/flags/flag-definitions.h"  // NOLINT
19 
20 // The global list of all flags.
21 class V8_EXPORT_PRIVATE FlagList {
22  public:
23   // The list of all flags with a value different from the default
24   // and their values. The format of the list is like the format of the
25   // argv array passed to the main function, e.g.
26   // ("--prof", "--log-file", "v8.prof", "--nolazy").
27   //
28   // The caller is responsible for disposing the list, as well
29   // as every element of it.
30   static std::vector<const char*>* argv();
31 
32   class HelpOptions {
33    public:
34     enum ExitBehavior : bool { kExit = true, kDontExit = false };
35 
36     explicit HelpOptions(ExitBehavior exit_behavior = kExit,
37                          const char* usage = nullptr)
exit_behavior_(exit_behavior)38         : exit_behavior_(exit_behavior), usage_(usage) {}
39 
ShouldExit()40     bool ShouldExit() { return exit_behavior_ == kExit; }
HasUsage()41     bool HasUsage() { return usage_ != nullptr; }
usage()42     const char* usage() { return usage_; }
43 
44    private:
45     ExitBehavior exit_behavior_;
46     const char* usage_;
47   };
48 
49   // Set the flag values by parsing the command line. If remove_flags is
50   // set, the recognized flags and associated values are removed from (argc,
51   // argv) and only unknown arguments remain. Returns 0 if no error occurred.
52   // Otherwise, returns the argv index > 0 for the argument where an error
53   // occurred. In that case, (argc, argv) will remain unchanged independent of
54   // the remove_flags value, and no assumptions about flag settings should be
55   // made. If exit_behavior is set to Exit and --help has been specified on the
56   // command line, then the usage string will be printed, if it was specified,
57   // followed by the help flag and then the process will exit. Otherwise the
58   // flag help will be displayed but execution will continue.
59   //
60   // The following syntax for flags is accepted (both '-' and '--' are ok):
61   //
62   //   --flag        (bool flags only)
63   //   --no-flag     (bool flags only)
64   //   --flag=value  (non-bool flags only, no spaces around '=')
65   //   --flag value  (non-bool flags only)
66   //   --            (capture all remaining args in JavaScript)
67   static int SetFlagsFromCommandLine(
68       int* argc, char** argv, bool remove_flags,
69       FlagList::HelpOptions help_options = FlagList::HelpOptions());
70 
71   // Set the flag values by parsing the string str. Splits string into argc
72   // substrings argv[], each of which consisting of non-white-space chars,
73   // and then calls SetFlagsFromCommandLine() and returns its result.
74   static int SetFlagsFromString(const char* str, size_t len);
75 
76   // Reset all flags to their default value.
77   static void ResetAllFlags();
78 
79   // Print help to stdout with flags, types, and default values.
80   static void PrintHelp();
81 
82   // Set flags as consequence of being implied by another flag.
83   static void EnforceFlagImplications();
84 
85   // Hash of flags (to quickly determine mismatching flag expectations).
86   // This hash is calculated during V8::Initialize and cached.
87   static uint32_t Hash();
88 };
89 
90 }  // namespace internal
91 }  // namespace v8
92 
93 #endif  // V8_FLAGS_FLAGS_H_
94