Skip to content

Commit

Permalink
Updates to build with clang/llvm 13
Browse files Browse the repository at this point in the history
- This at least works with a cobbled-together nix config
- APSInt becomes more annoying to work with?
- Not much else changed!
  • Loading branch information
rpav committed Jun 26, 2022
1 parent cedddbb commit 93357e3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build.*/
compile_commands.json
CMakeLists.txt.user
*~
.tasklist.el
.project-root
.cache/
Empty file removed .project-root
Empty file.
21 changes: 0 additions & 21 deletions .tasklist.el

This file was deleted.

5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 0 additions & 4 deletions GruntCMake.json

This file was deleted.

33 changes: 0 additions & 33 deletions Gruntfile.js

This file was deleted.

4 changes: 2 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let
then import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz) {}
else import <nixpkgs> {};

c2ffiBranch = "llvm-11.0.0";
llvmPackages = pkgs.llvmPackages_11;
c2ffiBranch = "llvm-13.0.0";
llvmPackages = pkgs.llvmPackages_13;
in

llvmPackages.stdenv.mkDerivation {
Expand Down
15 changes: 10 additions & 5 deletions src/Template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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() << "?";
Expand Down

0 comments on commit 93357e3

Please sign in to comment.