Skip to content

Commit

Permalink
Remove all llvm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Spydr06 committed Feb 10, 2024
1 parent 1c39f3f commit 5993a2d
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 462 deletions.
26 changes: 1 addition & 25 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,9 @@ echo "$LD"

CSPC_DEFAULT_STD_PATH="${PREFIX}/share/cspydr/std"

CFLAGS="${CFLAGS} -fPIC -flto -Wall -DDEFAULT_STD_PATH=\"\\\"${CSPC_DEFAULT_STD_PATH}\\\"\""
CFLAGS="${CFLAGS} -fPIC -flto -Wall -Wextra -Wno-unused-parameter -DDEFAULT_STD_PATH=\"\\\"${CSPC_DEFAULT_STD_PATH}\\\"\""
LDFLAGS="${LDFLAGS} -lm"

#
# LLVM checks
#

echo -n "checking for llvm... "
if [ -z "$LLVM_CONFIG" ]; then
if check_tool "llvm-config"; then
export LLVM_CONFIG=$(which llvm-config)
else
echo "not found."
error "llvm library not found. Make sure \`llvm-config\` is in the PATH."
fi
fi
LLVM_VERSION=$($LLVM_CONFIG --version)
echo "$LLVM_VERSION"

LLVM_CFLAGS="$($LLVM_CONFIG --cflags)"
LLVM_LDFLAGS="$($LLVM_CONFIG --ldflags)"

CLANG_LIBS="-lclang"

CFLAGS="${CFLAGS} ${LLVM_CFLAGS}"
LDFLAGS="${LDFLAGS} ${LLVM_LDFLAGS} ${CLANG_LIBS}"

#
# Check for pkg-config
#
Expand Down
41 changes: 0 additions & 41 deletions src/compiler/c_parser/c_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#include <stdio.h>
#include <string.h>

#include "libclang.h"

#include "ast/ast.h"
#include "config.h"
#include "context.h"
#include "error/error.h"
#include "io/log.h"
#include "lexer/token.h"
#include "list.h"
#include "clang-c/Index.h"

#define throw_error(...) \
do { \
Expand All @@ -33,21 +30,6 @@ void c_parser_free(CParser_T* parser)
free_list(parser->include_dirs);
}

static enum CXChildVisitResult visit_children(CXCursor current_cursor, CXCursor parent, CXClientData client_data) {
return CXChildVisit_Recurse;
}

static void create_dummy_file(struct CXUnsavedFile* file, const char* filename, const char* header) {
file->Filename = filename;
file->Length = strlen(header) + 10;
file->Contents = calloc(file->Length + 1, sizeof(char));
snprintf((char*) file->Contents, file->Length, "#include<%s>", header);
}

static void free_dummy_file(struct CXUnsavedFile* file) {
free((void*) file->Contents);
}

void parse_c_header(CParser_T* parser, ASTObj_T* surrounding_obj, Token_T* include_token, const char* header)
{
parser->current_obj = surrounding_obj;
Expand All @@ -56,29 +38,6 @@ void parse_c_header(CParser_T* parser, ASTObj_T* surrounding_obj, Token_T* inclu
fflush(OUTPUT_STREAM);
}

struct CXUnsavedFile unsaved_files[1];
create_dummy_file(&unsaved_files[0], "dummy.c", header);

CXIndex clang_index = clang_createIndex(false, true);
CXTranslationUnit unit = clang_parseTranslationUnit(index, "dummy.c", NULL, 0, unsaved_files, LEN(unsaved_files), CXTranslationUnit_None);
if(!unit) {
throw_error(parser->context, ERR_C_PARSER, include_token, "error while parsing C file `%s`: ", header);
goto finish;
}

CXCursor cursor = clang_getTranslationUnitCursor(unit);
clang_visitChildren(cursor, visit_children, parser);

clang_disposeTranslationUnit(unit);
clang_disposeIndex(clang_index);

for(size_t i = 0; i < LEN(unsaved_files); i++)
free_dummy_file(&unsaved_files[i]);

finish:
if(!parser->context->flags.silent)
LOG_INFO("\33[2k\r");

throw_error(parser->context, ERR_INTERNAL, include_token, "C header includes are not implemented yet.");
parser->current_obj = NULL;
}
Expand Down
7 changes: 0 additions & 7 deletions src/compiler/c_parser/libclang.h

This file was deleted.

Loading

0 comments on commit 5993a2d

Please sign in to comment.