diff options
author | 2018-10-01 18:17:45 +0100 | |
---|---|---|
committer | 2018-10-12 03:22:29 +0100 | |
commit | 0adf4d80ca1c673e5f7c5249faabadccdc1ddbbd (patch) | |
tree | 0c4f88f1fa6ab56fd1b24426c75f17836a6bd81d /tools/cpp-define-generator/main.cc | |
parent | 78940f2254354373c6b311c759c43f51d3ad77f1 (diff) |
Rewrite cpp-define-generator
The new method works by generating temporary per-architecture
human-readable object file with the constants embedded in it.
Python script extracts those values and generates the header.
This means the values can now implicitly depend on pointer size,
compile time flags, or ABI specific object layout with no hacks.
Test: test-art-host-gtest-arch_test
Change-Id: Id6e8c77c01f9d6c49cd6d40e3487b56fa4777349
Diffstat (limited to 'tools/cpp-define-generator/main.cc')
-rw-r--r-- | tools/cpp-define-generator/main.cc | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/tools/cpp-define-generator/main.cc b/tools/cpp-define-generator/main.cc deleted file mode 100644 index 7c515be12f..0000000000 --- a/tools/cpp-define-generator/main.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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 <algorithm> -#include <ios> -#include <iostream> -#include <sstream> -#include <string> -#include <type_traits> - -// 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 T, typename = void> -typename std::enable_if<!std::is_signed<T>::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 T, typename = void> -typename std::enable_if<std::is_signed<T>::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 <typename T> -void cpp_define(const std::string& name, T value) { - std::cout << "#define " << name << " " << pretty_format(value) << std::endl; -} - -template <typename T> -void emit_check_eq(T value, const 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<field_type>(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; -} |