Skip to content

Commit

Permalink
Preliminary build/working with llvm-15
Browse files Browse the repository at this point in the history
- No more nix
- No more arch for testing ("official" container builds hopefully incoming)
- A few changes for llvm-15
  • Loading branch information
rpav committed Jun 8, 2023
1 parent 2ccd4f0 commit 36dbe55
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 119 deletions.
40 changes: 0 additions & 40 deletions .nix/build-tools.nix

This file was deleted.

25 changes: 0 additions & 25 deletions .nix/c++.nix

This file was deleted.

8 changes: 0 additions & 8 deletions .nix/deps.nix

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
16 changes: 0 additions & 16 deletions Docker/Test-Build-Archlinux.docker

This file was deleted.

23 changes: 1 addition & 22 deletions src/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,6 @@ Decl* C2FFIASTConsumer::make_decl(const clang::FunctionDecl* d, bool is_toplevel
return fd;
}

static bool convertUTF32ToUTF8String(const llvm::ArrayRef<char> &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<const llvm::UTF32*>(SourceBegins);
const llvm::UTF32* SourceEndingUTF32 = reinterpret_cast<const llvm::UTF32*>(SourceEnding);
llvm::UTF8* ResultBeginsUTF8 = reinterpret_cast<llvm::UTF8*>(&Result[0]);
llvm::UTF8* ResultEndingUTF8 = reinterpret_cast<llvm::UTF8*>(&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<char*>(ResultEndingUTF8) - &Result[0]);
return true;
}

Decl* C2FFIASTConsumer::make_decl(const clang::VarDecl* d, bool is_toplevel)
{
clang::APValue* v = NULL;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions src/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ void c2ffi::init_ci(config &c, clang::CompilerInstance &ci) {
lo.WCharSize = c.wchar_size;

std::vector<std::string> 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());

Expand Down

0 comments on commit 36dbe55

Please sign in to comment.