From 311fdf52f7d33b988130d07b3d3a86eb148051ca Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Fri, 22 Jul 2016 15:59:16 -0700 Subject: runtime: Refactor asm_support to be auto-generated (mostly) Usage: * If the defines are no longer up to date, re-run generate-asm-support * To add a new field: --- Edit one of the offset_ or constant def files. --- Rebuild cpp-define-generator and re-run generate-asm-support Change-Id: I772430fcf1ad9af40898ebb453848f8412612386 TODO: Integrate this into the build somehow TODO: Account for 32 vs 64-bit and read barrier vs no read barrier --- tools/cpp-define-generator/main.cc | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tools/cpp-define-generator/main.cc (limited to 'tools/cpp-define-generator/main.cc') diff --git a/tools/cpp-define-generator/main.cc b/tools/cpp-define-generator/main.cc new file mode 100644 index 0000000000..a1b463a92d --- /dev/null +++ b/tools/cpp-define-generator/main.cc @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +// Art Offset file dependencies +#define DEFINE_INCLUDE_DEPENDENCIES +#include "offsets_all.def" + +std::string to_upper(std::string input) { + std::transform(input.begin(), input.end(), input.begin(), ::toupper); + return input; +} + +template +typename std::enable_if::value, std::string>::type +pretty_format(T value) { + // Print most values as hex. + std::stringstream ss; + ss << std::showbase << std::hex << value; + return ss.str(); +} + +template +typename std::enable_if::value, std::string>::type +pretty_format(T value) { + // Print "signed" values as decimal so that the negativity doesn't get lost. + std::stringstream ss; + + // For negative values add a (). Omit it from positive values for conciseness. + if (value < 0) { + ss << "("; + } + + ss << value; + + if (value < 0) { + ss << ")"; + } + return ss.str(); +} + +template +void cpp_define(std::string name, T value) { + std::cout << "#define " << name << " " << pretty_format(value) << std::endl; +} + +template +void emit_check_eq(T value, std::string expr) { + std::cout << "DEFINE_CHECK_EQ(" << value << ", (" << expr << "))" << std::endl; +} + +const char *kFileHeader = /* // NOLINT [readability/multiline_string] [5] */ R"L1C3NS3( +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ +#define ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ + +// This file has been auto-generated by cpp-define-generator; do not edit directly. +)L1C3NS3"; // NOLINT [readability/multiline_string] [5] + +const char *kFileFooter = /* // NOLINT [readability/multiline_string] [5] */ R"F00T3R( +#endif // ART_RUNTIME_GENERATED_ASM_SUPPORT_GEN_H_ +)F00T3R"; // NOLINT [readability/multiline_string] [5] + +#define MACROIZE(holder_type, field_name) to_upper(#holder_type "_" #field_name "_OFFSET") + +int main() { + std::cout << kFileHeader << std::endl; + + std::string z = ""; + + // Print every constant expression to stdout as a #define or a CHECK_EQ +#define DEFINE_EXPR(macro_name, field_type, expr) \ + cpp_define(to_upper(#macro_name), static_cast(expr)); \ + emit_check_eq(z + "static_cast<" #field_type ">(" + to_upper(#macro_name) + ")", \ + "static_cast<" #field_type ">(" #expr ")"); +#include "offsets_all.def" + + std::cout << kFileFooter << std::endl; + return 0; +} -- cgit v1.2.3-59-g8ed1b