summaryrefslogtreecommitdiff
path: root/runtime/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/utils.h')
-rw-r--r--runtime/utils.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/runtime/utils.h b/runtime/utils.h
index bd52b686fd..5cca2964ce 100644
--- a/runtime/utils.h
+++ b/runtime/utils.h
@@ -26,8 +26,10 @@
#include <vector>
#include "arch/instruction_set.h"
+#include "base/casts.h"
#include "base/logging.h"
#include "base/mutex.h"
+#include "base/stringpiece.h"
#include "globals.h"
#include "primitive.h"
@@ -35,7 +37,6 @@ class BacktraceMap;
namespace art {
-class ArtCode;
class ArtField;
class ArtMethod;
class DexFile;
@@ -321,6 +322,34 @@ static inline const void* EntryPointToCodePointer(const void* entry_point) {
return reinterpret_cast<const void*>(code);
}
+using UsageFn = void (*)(const char*, ...);
+
+template <typename T>
+static void ParseUintOption(const StringPiece& option,
+ const std::string& option_name,
+ T* out,
+ UsageFn Usage,
+ bool is_long_option = true) {
+ std::string option_prefix = option_name + (is_long_option ? "=" : "");
+ DCHECK(option.starts_with(option_prefix));
+ const char* value_string = option.substr(option_prefix.size()).data();
+ int64_t parsed_integer_value;
+ if (!ParseInt(value_string, &parsed_integer_value)) {
+ Usage("Failed to parse %s '%s' as an integer", option_name.c_str(), value_string);
+ }
+ if (parsed_integer_value < 0) {
+ Usage("%s passed a negative value %d", option_name.c_str(), parsed_integer_value);
+ }
+ *out = dchecked_integral_cast<T>(parsed_integer_value);
+}
+
+void ParseDouble(const std::string& option,
+ char after_char,
+ double min,
+ double max,
+ double* parsed_value,
+ UsageFn Usage);
+
} // namespace art
#endif // ART_RUNTIME_UTILS_H_