From 93357e3461caaf52fd4d3fef5b2c4c818be16baa Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Sun, 26 Jun 2022 11:32:20 -0500 Subject: [PATCH] Updates to build with clang/llvm 13 - This at least works with a cobbled-together nix config - APSInt becomes more annoying to work with? - Not much else changed! --- .gitignore | 3 +++ .project-root | 0 .tasklist.el | 21 --------------------- CMakeLists.txt | 5 ++--- GruntCMake.json | 4 ---- Gruntfile.js | 33 --------------------------------- default.nix | 4 ++-- src/Template.cpp | 15 ++++++++++----- 8 files changed, 17 insertions(+), 68 deletions(-) delete mode 100644 .project-root delete mode 100644 .tasklist.el delete mode 100644 GruntCMake.json delete mode 100644 Gruntfile.js diff --git a/.gitignore b/.gitignore index c6e754f..80cf9bc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build.*/ compile_commands.json CMakeLists.txt.user *~ +.tasklist.el +.project-root +.cache/ \ No newline at end of file diff --git a/.project-root b/.project-root deleted file mode 100644 index e69de29..0000000 diff --git a/.tasklist.el b/.tasklist.el deleted file mode 100644 index 5e1e12d..0000000 --- a/.tasklist.el +++ /dev/null @@ -1,21 +0,0 @@ -((tasks - (build - (:name "Build %p") - (:window "Build/Run %p") - (:command "grunt" "cmake_build --current-only")) - (run - (:name "Run %p") - (:window "Build/Run %p") - (:command "grunt" "cmake_build_run --target=c2ffi")) - (clean - (:name "Clean %p") - (:window "Build/Run %p") - (:command "grunt" "cmake_clean --current-only")) - (cmake - (:name "Configure CMake") - (:window "Build/Run %p") - (:command "grunt" "cmake_config --current-only")) - (cmake-clear-cache - (:name "Clear Cache and Configure CMake") - (:window "Build/Run %p") - (:command "grunt" "cmake_config --clear-cache --current-only")))) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb3c023..9d846a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,8 @@ project(c2ffi) set(SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) # Apparently the LLVM package doesn't support ranges -find_package(LLVM 12.0.0 CONFIG) - -find_package(Clang) +find_package(LLVM 13.0.0 CONFIG) +find_package(Clang REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "LLVM installed in ${LLVM_INSTALL_PREFIX}") diff --git a/GruntCMake.json b/GruntCMake.json deleted file mode 100644 index ac7279b..0000000 --- a/GruntCMake.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "currentConfig": "clang-Debug", - "buildOpts": "-j 4" -} diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index c71671c..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,33 +0,0 @@ -const { cmake } = require('./CMake/gruntutil.js'); - -module.exports = function(grunt) { - grunt.loadNpmTasks('grunt-rpav-cmake'); - - grunt.initConfig({ - cmake_config: { - options: { - srcDir: '.', - buildDir: o => "build/" + o.buildConfig, - env: { - LSAN_OPTIONS: "suppressions=../../../lsan_suppress.txt", - }, - }, - - configs: { - "clang-Debug": cmake({ tc: 'clang', c: 'Debug' }), - "clang-Sanitize": cmake({ tc: 'clang', c: 'Sanitize' }), - "clang-Release": cmake({ tc: 'clang', c: 'Release' }), - }, - }, - - cmake_run: { - c2ffi: { build: "c2ffi", run: "./c2ffi", args: '/usr/include/stdio.h', cwd: "bin" }, - }, - - cmake_build_run: { - c2ffi: {}, - }, - - run: {} - }); -}; diff --git a/default.nix b/default.nix index 2a4c8ae..8266d58 100644 --- a/default.nix +++ b/default.nix @@ -17,8 +17,8 @@ let then import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz) {} else import {}; - c2ffiBranch = "llvm-11.0.0"; - llvmPackages = pkgs.llvmPackages_11; + c2ffiBranch = "llvm-13.0.0"; + llvmPackages = pkgs.llvmPackages_13; in llvmPackages.stdenv.mkDerivation { diff --git a/src/Template.cpp b/src/Template.cpp index d4a6d8b..b7a6617 100644 --- a/src/Template.cpp +++ b/src/Template.cpp @@ -27,15 +27,20 @@ using namespace c2ffi; using namespace std; +std::string toStr(const llvm::APSInt& i) { + llvm::SmallString<32> tmp; + i.toString(tmp, 10); + return std::string(tmp.str()); +} + TemplateArg::TemplateArg(C2FFIASTConsumer* ast, const clang::TemplateArgument& arg) : _type(NULL), _has_val(false), _val("") { - if(arg.getKind() == clang::TemplateArgument::Type) _type = Type::make_type(ast, arg.getAsType().getTypePtrOrNull()); else if(arg.getKind() == clang::TemplateArgument::Integral) { _has_val = true; - _val = arg.getAsIntegral().toString(10); + _val = toStr(arg.getAsIntegral()); _type = Type::make_type(ast, arg.getIntegralType().getTypePtrOrNull()); } else if(arg.getKind() == clang::TemplateArgument::Declaration) { _has_val = true; @@ -53,7 +58,7 @@ TemplateArg::TemplateArg(C2FFIASTConsumer* ast, const clang::TemplateArgument& a if(r.Val.isInt()) { _has_val = true; - _val = r.Val.getInt().toString(10); + _val = toStr(r.Val.getInt()); } } } else { @@ -101,7 +106,7 @@ void C2FFIASTConsumer::write_template( if(arg.getKind() == clang::TemplateArgument::Type) out << arg.getAsType().getAsString(); else if(arg.getKind() == clang::TemplateArgument::Integral) { - out << arg.getAsIntegral().toString(10); + out << toStr(arg.getAsIntegral()); } else if(arg.getKind() == clang::TemplateArgument::Declaration) { out << arg.getAsDecl()->getNameAsString(); } else if(arg.getKind() == clang::TemplateArgument::Expression) { @@ -112,7 +117,7 @@ void C2FFIASTConsumer::write_template( clang::Expr::EvalResult r; expr->EvaluateAsInt(r, ctx); if(r.Val.isInt()) - out << r.Val.getInt().toString(10); + out << toStr(r.Val.getInt()); } } else { out << "?" << arg.getKind() << "?";