2017-02-13 20:26:44 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#ifndef RUNTIME_VM_FLAGS_H_
|
|
|
|
#define RUNTIME_VM_FLAGS_H_
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2012-01-16 12:28:10 +00:00
|
|
|
#include "platform/assert.h"
|
2016-02-04 05:10:30 +00:00
|
|
|
#include "vm/flag_list.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/globals.h"
|
|
|
|
|
|
|
|
typedef const char* charp;
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
#define DECLARE_FLAG(type, name) extern type FLAG_##name
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
#define DEFINE_FLAG(type, name, default_value, comment) \
|
2016-11-08 21:54:47 +00:00
|
|
|
type FLAG_##name = \
|
|
|
|
Flags::Register_##type(&FLAG_##name, #name, default_value, comment);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2012-03-09 23:21:09 +00:00
|
|
|
#define DEFINE_FLAG_HANDLER(handler, name, comment) \
|
2018-03-01 16:43:58 +00:00
|
|
|
bool DUMMY_##name = Flags::RegisterFlagHandler(handler, #name, comment);
|
|
|
|
|
|
|
|
#define DEFINE_OPTION_HANDLER(handler, name, comment) \
|
|
|
|
bool DUMMY_##name = Flags::RegisterOptionHandler(handler, #name, comment);
|
2012-03-09 23:21:09 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
namespace dart {
|
|
|
|
|
2012-03-09 23:21:09 +00:00
|
|
|
typedef void (*FlagHandler)(bool value);
|
2018-03-01 16:43:58 +00:00
|
|
|
typedef void (*OptionHandler)(const char* value);
|
2012-03-09 23:21:09 +00:00
|
|
|
|
2014-05-27 21:27:17 +00:00
|
|
|
// Forward declarations.
|
2011-10-05 05:20:07 +00:00
|
|
|
class Flag;
|
2014-05-27 21:27:17 +00:00
|
|
|
class JSONArray;
|
|
|
|
class JSONStream;
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
class Flags {
|
|
|
|
public:
|
|
|
|
static bool Register_bool(bool* addr,
|
|
|
|
const char* name,
|
|
|
|
bool default_value,
|
|
|
|
const char* comment);
|
|
|
|
|
|
|
|
static int Register_int(int* addr,
|
|
|
|
const char* name,
|
|
|
|
int default_value,
|
|
|
|
const char* comment);
|
|
|
|
|
2015-02-10 17:41:01 +00:00
|
|
|
static uint64_t Register_uint64_t(uint64_t* addr,
|
|
|
|
const char* name,
|
|
|
|
uint64_t default_value,
|
|
|
|
const char* comment);
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
static const char* Register_charp(charp* addr,
|
|
|
|
const char* name,
|
|
|
|
const char* default_value,
|
|
|
|
const char* comment);
|
|
|
|
|
2018-03-01 16:43:58 +00:00
|
|
|
static bool RegisterFlagHandler(FlagHandler handler,
|
|
|
|
const char* name,
|
|
|
|
const char* comment);
|
|
|
|
|
|
|
|
static bool RegisterOptionHandler(OptionHandler handler,
|
|
|
|
const char* name,
|
|
|
|
const char* comment);
|
2012-03-09 23:21:09 +00:00
|
|
|
|
2011-12-01 11:59:35 +00:00
|
|
|
static bool ProcessCommandLineFlags(int argc, const char** argv);
|
2011-10-05 05:20:07 +00:00
|
|
|
|
|
|
|
static Flag* Lookup(const char* name);
|
|
|
|
|
2014-05-23 17:43:14 +00:00
|
|
|
static bool IsSet(const char* name);
|
|
|
|
|
2011-12-01 11:59:35 +00:00
|
|
|
static bool Initialized() { return initialized_; }
|
|
|
|
|
2016-07-14 18:13:13 +00:00
|
|
|
#ifndef PRODUCT
|
2014-05-27 21:27:17 +00:00
|
|
|
static void PrintJSON(JSONStream* js);
|
2016-07-14 18:13:13 +00:00
|
|
|
#endif // !PRODUCT
|
2014-05-27 21:27:17 +00:00
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
static bool SetFlag(const char* name, const char* value, const char** error);
|
2014-05-27 21:27:17 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
private:
|
2014-05-27 21:27:17 +00:00
|
|
|
static Flag** flags_;
|
|
|
|
static intptr_t capacity_;
|
|
|
|
static intptr_t num_flags_;
|
2011-10-05 05:20:07 +00:00
|
|
|
|
2011-12-01 11:59:35 +00:00
|
|
|
static bool initialized_;
|
|
|
|
|
2014-05-27 21:27:17 +00:00
|
|
|
static void AddFlag(Flag* flag);
|
|
|
|
|
|
|
|
static bool SetFlagFromString(Flag* flag, const char* argument);
|
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
static void Parse(const char* option);
|
|
|
|
|
2012-08-21 11:18:18 +00:00
|
|
|
static int CompareFlagNames(const void* left, const void* right);
|
|
|
|
|
|
|
|
static void PrintFlags();
|
|
|
|
|
2016-07-14 18:13:13 +00:00
|
|
|
#ifndef PRODUCT
|
2014-05-27 21:27:17 +00:00
|
|
|
static void PrintFlagToJSONArray(JSONArray* jsarr, const Flag* flag);
|
2016-07-14 18:13:13 +00:00
|
|
|
#endif // !PRODUCT
|
2014-05-27 21:27:17 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
// Testing needs direct access to private methods.
|
|
|
|
friend void Dart_TestParseFlags();
|
|
|
|
|
|
|
|
DISALLOW_ALLOCATION();
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Flags);
|
|
|
|
};
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
#define PRODUCT_FLAG_MARCO(name, type, default_value, comment) \
|
2016-02-04 05:10:30 +00:00
|
|
|
extern type FLAG_##name;
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
#define DEBUG_FLAG_MARCO(name, type, default_value, comment) \
|
|
|
|
extern type FLAG_##name;
|
|
|
|
#else // defined(DEBUG)
|
|
|
|
#define DEBUG_FLAG_MARCO(name, type, default_value, comment) \
|
|
|
|
const type FLAG_##name = default_value;
|
|
|
|
#endif // defined(DEBUG)
|
|
|
|
|
2016-02-23 16:48:08 +00:00
|
|
|
#if defined(PRODUCT) && defined(DART_PRECOMPILED_RUNTIME)
|
2016-02-23 20:54:33 +00:00
|
|
|
#define RELEASE_FLAG_MARCO(name, product_value, type, default_value, comment) \
|
2016-02-23 16:48:08 +00:00
|
|
|
const type FLAG_##name = product_value;
|
|
|
|
#define PRECOMPILE_FLAG_MARCO(name, precompiled_value, product_value, type, \
|
|
|
|
default_value, comment) \
|
|
|
|
const type FLAG_##name = precompiled_value;
|
|
|
|
|
|
|
|
#elif defined(PRODUCT) // !PRECOMPILED
|
2016-02-04 05:10:30 +00:00
|
|
|
#define RELEASE_FLAG_MARCO(name, product_value, type, default_value, comment) \
|
|
|
|
const type FLAG_##name = product_value;
|
2016-02-23 16:48:08 +00:00
|
|
|
#define PRECOMPILE_FLAG_MARCO(name, precompiled_value, product_value, type, \
|
|
|
|
default_value, comment) \
|
2016-02-23 20:54:33 +00:00
|
|
|
const type FLAG_##name = product_value;
|
2016-02-04 05:10:30 +00:00
|
|
|
|
2016-02-23 16:48:08 +00:00
|
|
|
#elif defined(DART_PRECOMPILED_RUNTIME) // !PRODUCT
|
|
|
|
#define RELEASE_FLAG_MARCO(name, product_value, type, default_value, comment) \
|
|
|
|
extern type FLAG_##name;
|
|
|
|
#define PRECOMPILE_FLAG_MARCO(name, precompiled_value, product_value, type, \
|
|
|
|
default_value, comment) \
|
|
|
|
const type FLAG_##name = precompiled_value;
|
2016-02-04 05:10:30 +00:00
|
|
|
|
2016-02-23 16:48:08 +00:00
|
|
|
#else // !PRODUCT && !PRECOMPILED
|
2016-02-04 05:10:30 +00:00
|
|
|
#define RELEASE_FLAG_MARCO(name, product_value, type, default_value, comment) \
|
|
|
|
extern type FLAG_##name;
|
2016-02-23 16:48:08 +00:00
|
|
|
#define PRECOMPILE_FLAG_MARCO(name, precompiled_value, product_value, type, \
|
|
|
|
default_value, comment) \
|
|
|
|
extern type FLAG_##name;
|
2016-02-04 05:10:30 +00:00
|
|
|
|
2016-02-23 16:48:08 +00:00
|
|
|
#endif
|
2016-02-04 05:10:30 +00:00
|
|
|
|
|
|
|
// Now declare all flags here.
|
2016-02-23 16:48:08 +00:00
|
|
|
FLAG_LIST(PRODUCT_FLAG_MARCO,
|
|
|
|
RELEASE_FLAG_MARCO,
|
|
|
|
DEBUG_FLAG_MARCO,
|
|
|
|
PRECOMPILE_FLAG_MARCO)
|
2016-02-04 05:10:30 +00:00
|
|
|
|
|
|
|
#undef RELEASE_FLAG_MARCO
|
|
|
|
#undef DEBUG_FLAG_MARCO
|
|
|
|
#undef PRODUCT_FLAG_MARCO
|
2016-02-23 16:48:08 +00:00
|
|
|
#undef PRECOMPILE_FLAG_MARCO
|
2016-02-04 05:10:30 +00:00
|
|
|
|
2011-10-05 05:20:07 +00:00
|
|
|
} // namespace dart
|
|
|
|
|
2016-10-26 07:26:03 +00:00
|
|
|
#endif // RUNTIME_VM_FLAGS_H_
|