From 0adf4d80ca1c673e5f7c5249faabadccdc1ddbbd Mon Sep 17 00:00:00 2001 From: David Srbecky Date: Mon, 1 Oct 2018 18:17:45 +0100 Subject: 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 --- tools/cpp-define-generator/main.cc | 114 ------------------------------------- 1 file changed, 114 deletions(-) delete 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 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 -#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(const std::string& name, T value) { - std::cout << "#define " << name << " " << pretty_format(value) << std::endl; -} - -template -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(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