diff --git a/.nix/build-tools.nix b/.nix/build-tools.nix deleted file mode 100644 index 115e5f1..0000000 --- a/.nix/build-tools.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ toolchain, ... }: -with import {}; -let - # These should be the _latest_, from which we pull tools - llvm = llvmPackages_14; - clang-tools = clang-tools_14; -in rec { - toolchains = with pkgs; { - gcc-12 = [ - gcc12 - clang-tools - ]; - - clang-14 = [ - clang-tools_14 - ]; - - clang-15 = [ - clang-tools_15 - ]; - }; - - envs = with pkgs; { - gcc-12 = pkgs.stdenv; - clang-14 = llvmPackages_14.stdenv; - clang-15 = llvmPackages_15.stdenv; - }; - - common = with pkgs; [ - cmake - ninja - llvm.lld - ]; - - # Composed packages based on toolchain - nativeBuildInputs = (builtins.getAttr toolchain toolchains) ++ common; - buildInputs = []; - - stdenv = (builtins.getAttr toolchain envs); -} diff --git a/.nix/c++.nix b/.nix/c++.nix deleted file mode 100644 index 806b565..0000000 --- a/.nix/c++.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ toolchain ? "clang-14", project-root ? ".", ... }: -with import {}; -let - build-tools = import ./build-tools.nix { toolchain = toolchain; }; - project-path = /. + project-root; - deps-path = (project-path + /.nix/deps.nix); - - deps = if builtins.pathExists deps-path then - { buildInputs = []; nativeBuildInputs = []; } // import deps-path {} - else - { buildInputs = []; nativeBuildInputs = []; }; - -in -build-tools.stdenv.mkDerivation { - name = "gcc-12-toolchain"; - - nativeBuildInputs = build-tools.nativeBuildInputs ++ deps.nativeBuildInputs; - buildInputs = build-tools.buildInputs ++ deps.buildInputs; - - shellHook = - '' - echo "toolchain: ${toolchain}" - echo "project-root: ${project-root}" - ''; -} diff --git a/.nix/deps.nix b/.nix/deps.nix deleted file mode 100644 index 9ba2cba..0000000 --- a/.nix/deps.nix +++ /dev/null @@ -1,8 +0,0 @@ -{...}: -with import {}; -{ - buildInputs = [ - llvmPackages_14.llvm - llvmPackages_14.libclang - ]; -} diff --git a/CMakeLists.txt b/CMakeLists.txt index f37b2d9..5d7b875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(c2ffi) set(SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) # Apparently the LLVM package doesn't support ranges -find_package(LLVM 14.0.0 CONFIG) +find_package(LLVM 15.0.0 CONFIG) find_package(Clang REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") diff --git a/Docker/Test-Build-Archlinux.docker b/Docker/Test-Build-Archlinux.docker deleted file mode 100644 index 062019f..0000000 --- a/Docker/Test-Build-Archlinux.docker +++ /dev/null @@ -1,16 +0,0 @@ -# Using Ubuntu 20.04 seems to be simplest way to get an LLVM-11 that works -FROM archlinux:latest -RUN pacman --noconfirm -Syu --noconfirm llvm clang cmake make diffutils - -# Copy the source into the Docker container -RUN mkdir -p /c2ffi -COPY / /c2ffi -WORKDIR /c2ffi - -# Build c2ffi -RUN cd /c2ffi && \ - rm -rf build && mkdir -p build && cd build && \ - cmake -DBUILD_CONFIG=Release .. && make - -# As a sanity check, make sure the binary we built can be executed -RUN /c2ffi/build/bin/c2ffi --help diff --git a/src/AST.cpp b/src/AST.cpp index a87920b..777aff7 100644 --- a/src/AST.cpp +++ b/src/AST.cpp @@ -221,27 +221,6 @@ Decl* C2FFIASTConsumer::make_decl(const clang::FunctionDecl* d, bool is_toplevel return fd; } -static bool convertUTF32ToUTF8String(const llvm::ArrayRef &Source, std::string &Result) { - const char* SourceBegins = Source.data(); - const size_t SourceLength = Source.size(); - const char* SourceEnding = SourceBegins + SourceLength; - const size_t ResultMaxLen = SourceLength * UNI_MAX_UTF8_BYTES_PER_CODE_POINT; - Result.resize(ResultMaxLen); - const llvm::UTF32* SourceBeginsUTF32 = reinterpret_cast(SourceBegins); - const llvm::UTF32* SourceEndingUTF32 = reinterpret_cast(SourceEnding); - llvm::UTF8* ResultBeginsUTF8 = reinterpret_cast(&Result[0]); - llvm::UTF8* ResultEndingUTF8 = reinterpret_cast(&Result[0] + ResultMaxLen); - const llvm::ConversionResult CR = llvm::ConvertUTF32toUTF8(&SourceBeginsUTF32, SourceEndingUTF32, - &ResultBeginsUTF8, ResultEndingUTF8, - llvm::strictConversion); - if (CR != llvm::conversionOK) { - Result.clear(); - return false; - } - Result.resize(reinterpret_cast(ResultEndingUTF8) - &Result[0]); - return true; -} - Decl* C2FFIASTConsumer::make_decl(const clang::VarDecl* d, bool is_toplevel) { clang::APValue* v = NULL; @@ -274,7 +253,7 @@ Decl* C2FFIASTConsumer::make_decl(const clang::VarDecl* d, bool is_toplevel) { is_string = true; - if(s->isAscii() || s->isUTF8()) { + if(s->isUTF8()) { value = s->getString(); } else if(s->getCharByteWidth() == 2) { llvm::StringRef bytes = s->getBytes(); diff --git a/src/Expr.cpp b/src/Expr.cpp index 38f594f..83b8cf8 100644 --- a/src/Expr.cpp +++ b/src/Expr.cpp @@ -109,9 +109,7 @@ static best_guess macro_type( if(owns_seen) seen = new StringSet; seen->insert(macro_name); - for(clang::MacroInfo::tokens_iterator j = mi->tokens_begin(); j != mi->tokens_end(); j++) { - const clang::Token& t = (*j); - + for(auto && t : mi->tokens()) { if(t.isLiteral()) { if(t.getKind() == clang::tok::numeric_constant) guess = num_type(ci, t); @@ -152,9 +150,7 @@ static std::string macro_to_string(const clang::Preprocessor& pp, const clang::M { std::stringstream ss; - for(clang::MacroInfo::tokens_iterator j = mi->tokens_begin(); j != mi->tokens_end(); j++) { - const clang::Token& t = (*j); - + for(auto&& t : mi->tokens()) { if(t.getFlags() & clang::Token::LeadingSpace) ss << " "; ss << pp.getSpelling(t); diff --git a/src/init.cpp b/src/init.cpp index 1730d8e..528ff2f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -199,7 +199,9 @@ void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) { lo.WCharSize = c.wchar_size; std::vector includes; - ci.getInvocation().setLangDefaults(lo, c.kind, pti->getTriple(), includes, c.std); + ci.getInvocation().getLangOpts()->setLangDefaults(lo, c.kind.getLanguage(), + pti->getTriple(), includes, c.std); + //clang::LangOptions::setLangDefaults(lo, c.kind.getLanguage(), pti->getTriple(), includes, c.std); ci.createFileManager(); ci.createSourceManager(ci.getFileManager());