From 4334a1985b49fcff714c7a023197d1594abeb200 Mon Sep 17 00:00:00 2001 From: rajdakin Date: Fri, 31 Mar 2023 17:33:40 +0200 Subject: [WRAPPER HELPER] First pass toward a better wrapper helper (#658) --- wrapperhelper/main.cpp | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'wrapperhelper/main.cpp') diff --git a/wrapperhelper/main.cpp b/wrapperhelper/main.cpp index 1d228b43..bb182359 100644 --- a/wrapperhelper/main.cpp +++ b/wrapperhelper/main.cpp @@ -1,61 +1,63 @@ #include "ast.h" #include "utils.h" - -void dump_usage() { +static void dump_usage() { std::string Usage = R"usage( usage: command [guest_triple] [host_triple] -- - : set the header file to be parsed - : set libname required for wrapping func - [guest_triple]: set guest triple arm32/arm64/x86/x64, default is x86 - [host_triple]: set host tripe arm32/arm64/x86/x64, default is arm32 - -- : is necessary + : set the header file to be parsed + : set libname required for wrapping func + [guest_triple]: set guest triple: can be arm32/arm64/x86/x64, default is x64 + [host_triple] : set host triple: can be arm32/arm64/x86/x64, default is arm64 + -- : mandatory + : extra compiler flags )usage"; std::cerr << Usage << std::endl; } std::string parse_triple(const char* arg) { - if (strcmp(arg, "arm32") == 0) { - return TripleName[ARM32]; - } else if (strcmp(arg, "arm64") == 0) { - return TripleName[ARM64]; - } else if (strcmp(arg, "x86") == 0) { - return TripleName[X86]; + if (strcmp(arg, "x86") == 0) { + return "i386-pc-linux-gnu"; } else if (strcmp(arg, "x64") == 0) { - return TripleName[X64]; + return "x86_64-pc-linux-gnu"; + } else if (strcmp(arg, "arm32") == 0) { + return "armv7-unknown-linux-gnueabihf"; + } else if (strcmp(arg, "arm64") == 0) { + return "aarch64-unknown-linux-gnu"; } else { + std::cerr << "Invalid triple: '" << arg << "'\n"; + dump_usage(); return ""; } } -using namespace clang::tooling; int main(int argc, const char* argv[]) { if (argc < 4) { dump_usage(); return 0; } std::string libname = argv[2]; - std::string guest_triple = TripleName[X64]; - std::string host_triple = TripleName[ARM64]; + std::string guest_triple = parse_triple("x64"); + std::string host_triple = parse_triple("arm64"); if (argc >= 5) { guest_triple = parse_triple(argv[3]); } if (argc >= 6) { host_triple = parse_triple(argv[4]); } - bool has_nessary_tag = false; + bool has_necessary_tag = false; for (int i = 0; i < argc; i++) { if (strcmp(argv[i], "--") == 0) { - has_nessary_tag = true; + has_necessary_tag = true; break; } } - if (!has_nessary_tag) { - std::cerr << "Please add '--' after triple arg" << std::endl; + if (!has_necessary_tag) { + std::cerr << "Please add '--' after the triples" << std::endl; + dump_usage(); return 0; } std::string err; - auto compile_db = FixedCompilationDatabase::loadFromCommandLine(argc, argv, err); - ClangTool Tool(*compile_db, {argv[1]}); + auto compile_db = clang::tooling::FixedCompilationDatabase::loadFromCommandLine(argc, argv, err); + clang::tooling::ClangTool Tool(*compile_db, {argv[1]}); return Tool.run(std::make_unique(libname, host_triple, guest_triple).get()); } -- cgit 1.4.1