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_H_
6 #define V8_FLAGS_H_
7 
8 #include <vector>
9 
10 #include "src/globals.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // Declare all of our flags.
16 #define FLAG_MODE_DECLARE
17 #include "src/flag-definitions.h"  // NOLINT
18 
19 // The global list of all flags.
20 class V8_EXPORT_PRIVATE FlagList {
21  public:
22   // The list of all flags with a value different from the default
23   // and their values. The format of the list is like the format of the
24   // argv array passed to the main function, e.g.
25   // ("--prof", "--log-file", "v8.prof", "--nolazy").
26   //
27   // The caller is responsible for disposing the list, as well
28   // as every element of it.
29   static std::vector<const char*>* argv();
30 
31   // Set the flag values by parsing the command line. If remove_flags is
32   // set, the recognized flags and associated values are removed from (argc,
33   // argv) and only unknown arguments remain. Returns 0 if no error occurred.
34   // Otherwise, returns the argv index > 0 for the argument where an error
35   // occurred. In that case, (argc, argv) will remain unchanged independent of
36   // the remove_flags value, and no assumptions about flag settings should be
37   // made.
38   //
39   // The following syntax for flags is accepted (both '-' and '--' are ok):
40   //
41   //   --flag        (bool flags only)
42   //   --noflag      (bool flags only)
43   //   --flag=value  (non-bool flags only, no spaces around '=')
44   //   --flag value  (non-bool flags only)
45   //   --            (equivalent to --js_arguments, captures all remaining args)
46   static int SetFlagsFromCommandLine(int* argc,
47                                      char** argv,
48                                      bool remove_flags);
49 
50   // Set the flag values by parsing the string str. Splits string into argc
51   // substrings argv[], each of which consisting of non-white-space chars,
52   // and then calls SetFlagsFromCommandLine() and returns its result.
53   static int SetFlagsFromString(const char* str, int len);
54 
55   // Reset all flags to their default value.
56   static void ResetAllFlags();
57 
58   // Print help to stdout with flags, types, and default values.
59   static void PrintHelp();
60 
61   // Set flags as consequence of being implied by another flag.
62   static void EnforceFlagImplications();
63 
64   // Hash of flags (to quickly determine mismatching flag expectations).
65   // This hash is calculated during V8::Initialize and cached.
66   static uint32_t Hash();
67 };
68 
69 }  // namespace internal
70 }  // namespace v8
71 
72 #endif  // V8_FLAGS_H_
73