flags.h 3.39 KB
Newer Older
1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_FLAGS_FLAGS_H_
#define V8_FLAGS_FLAGS_H_
7

8 9
#include <vector>

10
#include "src/common/globals.h"
11
#include "src/wasm/wasm-limits.h"
12

13 14
namespace v8 {
namespace internal {
15

16 17
// Declare all of our flags.
#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 23 24 25 26 27
 public:
  // The list of all flags with a value different from the default
  // and their values. The format of the list is like the format of the
  // argv array passed to the main function, e.g.
  // ("--prof", "--log-file", "v8.prof", "--nolazy").
  //
28 29
  // The caller is responsible for disposing the list, as well
  // as every element of it.
30
  static std::vector<const char*>* argv();
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  class HelpOptions {
   public:
    enum ExitBehavior : bool { kExit = true, kDontExit = false };

    explicit HelpOptions(ExitBehavior exit_behavior = kExit,
                         const char* usage = nullptr)
        : exit_behavior_(exit_behavior), usage_(usage) {}

    bool ShouldExit() { return exit_behavior_ == kExit; }
    bool HasUsage() { return usage_ != nullptr; }
    const char* usage() { return usage_; }

   private:
    ExitBehavior exit_behavior_;
    const char* usage_;
  };

49
  // Set the flag values by parsing the command line. If remove_flags is
50 51 52 53 54
  // set, the recognized flags and associated values are removed from (argc,
  // argv) and only unknown arguments remain. Returns 0 if no error occurred.
  // Otherwise, returns the argv index > 0 for the argument where an error
  // occurred. In that case, (argc, argv) will remain unchanged independent of
  // the remove_flags value, and no assumptions about flag settings should be
55 56 57 58
  // made. If exit_behavior is set to Exit and --help has been specified on the
  // command line, then the usage string will be printed, if it was specified,
  // followed by the help flag and then the process will exit. Otherwise the
  // flag help will be displayed but execution will continue.
59 60 61 62
  //
  // The following syntax for flags is accepted (both '-' and '--' are ok):
  //
  //   --flag        (bool flags only)
63
  //   --no-flag     (bool flags only)
64 65
  //   --flag=value  (non-bool flags only, no spaces around '=')
  //   --flag value  (non-bool flags only)
66
  //   --            (capture all remaining args in JavaScript)
67 68 69
  static int SetFlagsFromCommandLine(
      int* argc, char** argv, bool remove_flags,
      FlagList::HelpOptions help_options = FlagList::HelpOptions());
70 71 72 73

  // Set the flag values by parsing the string str. Splits string into argc
  // substrings argv[], each of which consisting of non-white-space chars,
  // and then calls SetFlagsFromCommandLine() and returns its result.
74
  static int SetFlagsFromString(const char* str, size_t len);
75

76 77
  // Reset all flags to their default value.
  static void ResetAllFlags();
78

79 80
  // Print help to stdout with flags, types, and default values.
  static void PrintHelp();
81 82 83

  // Set flags as consequence of being implied by another flag.
  static void EnforceFlagImplications();
84

85 86
  // Hash of flags (to quickly determine mismatching flag expectations).
  // This hash is calculated during V8::Initialize and cached.
87
  static uint32_t Hash();
88 89
};

90 91
}  // namespace internal
}  // namespace v8
92

93
#endif  // V8_FLAGS_FLAGS_H_