From 03120bc29c0452b0bdc125223a009759e4f8f970 Mon Sep 17 00:00:00 2001 From: Harrand Date: Mon, 20 May 2024 02:45:29 +0100 Subject: [PATCH] [cpp] buildmeta - retrieve target triple and necessary llvm setup --- cpp/src/build.cpp | 14 ++++++++++++++ cpp/src/build.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/cpp/src/build.cpp b/cpp/src/build.cpp index 825861c..5c16b39 100644 --- a/cpp/src/build.cpp +++ b/cpp/src/build.cpp @@ -6,6 +6,14 @@ #include "diag.hpp" #include "timer.hpp" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" +// note: do not remove this, even if your editor says its unused. it's used. +#include "llvm/ExecutionEngine/MCJIT.h" + +#include "llvm/Support/TargetSelect.h" +#include "llvm/TargetParser/Host.h" + namespace build { ast::node try_find_build_meta_region(const info& i, std::string_view name, std::size_t* lex_timers, std::size_t* parse_timers); @@ -22,6 +30,12 @@ namespace build static_assert("unknown platform"); ret.link_name += ".out"; #endif + ret.target_triple = llvm::sys::getDefaultTargetTriple(); + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargets(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllAsmPrinters(); // try to find the node that constitutes a build meta-region with the same name as the target provided. ast::node meta_region = try_find_build_meta_region(ret, ret.compiler_args.target_name, lex_timers, parse_timers); diff --git a/cpp/src/build.hpp b/cpp/src/build.hpp index e2863b6..6af5b7a 100644 --- a/cpp/src/build.hpp +++ b/cpp/src/build.hpp @@ -24,6 +24,7 @@ namespace build config_type config = config_type::debug; std::string link_name = "a"; std::vector extra_input_files = {}; + std::string target_triple; config::compiler_args compiler_args; std::filesystem::path get_output_path() const;