diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cgrep.cpp | 22 | ||||
-rw-r--r-- | compile_commands.json | 8 | ||||
-rw-r--r-- | makefile | 13 | ||||
-rwxr-xr-x | testscript/main.py | 10 |
5 files changed, 42 insertions, 15 deletions
@@ -142,6 +142,10 @@ For an up-to-date list, you can run `cgrep --help` or look at the man page. `cgrep` is a clang tool, so it will accept all valid clang command line options. ## Known Issues +`cgrep` complains that it cannot find `stddef.h` or some other similar header. If that happens to you , it's because cgrep can't find the clang built-in headers. run `llvm-config --libdir`, then head on to `clang`. Inside that directory you should see one(or maybe more) llvm/clang versions. Pick the one you used to build cgrep against. Inside that directory there will be a directory named `include`. Pass that to cgrep any way you see fit.<br/> +Alternatively, `$(llvm-config --libdir)/clang/$(llvm-config --version)/include` should give the path cgrep needs to include. If you build your llvm/clang from upstream, this might not work. SVN bulds will have the svn string attached to the version number.<br/> +You could,for example, use `--extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include` to call cgrep or you could just alias `cgrep` to `cgrep --extra-arg=-I/usr/lib/llvm-9/lib/clang/9.0.0/include`.<br/> + `cgrep`, replaces the clang diagnosticConsumer with a simple one that only tells you there are erros during the compilation. You can get the normal clang output using the `--clangdiag` switch. The decision was made to declutter the output generated by cgrep. ## License @@ -7,7 +7,27 @@ * */ /***********************************************************************************************/ /*included modules*/ -#include "pch.hpp" +#include "./cfe-extra/cfe_extra.h" +#include "clang/AST/AST.h" +#include "clang/AST/ASTConsumer.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Basic/LLVM.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Lex/Lexer.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Tooling/CommonOptionsParser.h" +#include "clang/Tooling/Tooling.h" +#include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <cstdlib> +#include <dirent.h> +#include <fstream> +#include <iostream> +#include <regex> +#include <string> +#include <vector> /***********************************************************************************************/ /*used namespaces*/ using namespace llvm; diff --git a/compile_commands.json b/compile_commands.json index 86af499..598f647 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,12 +1,12 @@ [ { - "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp", + "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", "directory": "/home/bloodstalker/extra/cgrep", - "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp" + "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp" }, { - "command": "c++ -c -include-pch pch.hpp.gch -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", + "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp", "directory": "/home/bloodstalker/extra/cgrep", - "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp" + "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp" } ]
\ No newline at end of file @@ -11,7 +11,7 @@ endif CXX=clang++ CXX?=clang++ ifdef OS - CXX_FLAGS= + CXX_FLAGS=-MM else CXX_FLAGS=-fpic endif @@ -84,7 +84,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS) .PHONY:all clean help ASM SO TAGS -all: pch.hpp.gch $(TARGET) +all: $(TARGET) everything:$(TARGET) A ASM SO $(TARGET)-dbg TAGS $(TARGET)-cov @@ -98,18 +98,15 @@ depend:.depend -include ./.depend -%.o:%.cpp pch.hpp.gch - $(CXX) -include-pch pch.hpp.gch $(CXX_FLAGS) -c $< -o $@ +%.o:%.cpp + $(CXX) $(CXX_FLAGS) -c $< -o $@ %.odbg:%.cpp $(CXX) $(CXX_FLAGS) -g -c $< -o $@ -%.ocov:%.cpp pch.hpp.gch +%.ocov:%.cpp $(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@ -pch.hpp.gch: pch.hpp - $(CXX) $(CXX_FLAGS) -c $< -o $@ - ./cfe-extra/cfe_extra.o:./cfe-extra/cfe_extra.cpp $(CXX) $(CXX_FLAGS) -c $< -o $@ diff --git a/testscript/main.py b/testscript/main.py index fddc3a3..1015b21 100755 --- a/testscript/main.py +++ b/testscript/main.py @@ -5,6 +5,7 @@ import argparse import subprocess import os import sys +import re test_files = ["/home/bloodstalker/extra/cgrep/cgrep.cpp"] @@ -60,14 +61,19 @@ def main(): argparser = Argparser() cgrep_exe = "cgrep" os.chdir("../") - print(os.getcwd()) + # get LLVM libdir + llvm_libdir = call_from_shell_list(["llvm-config", "--libdir"]) + # get LLVM version. upstream builds can have extra unwanted text attached. + llvm_version = re.findall("[0-9]*\.[0-9]*\.[0-9]*", call_from_shell_list(["llvm-config", "--version"]).stdout.decode("utf-8")) + # buld the magic sause. we dont wanna get stddef.h not found. + clang_builtin_headers = "--extra-arg=-I" + llvm_libdir.stdout.decode("utf-8")[:-1] + "/clang/" + llvm_version[0] + "/include" for cgrep_test_arg in cgrep_test_args: arg_list = cgrep_test_arg.split() arg_list.insert(0, cgrep_exe) + arg_list.append(clang_builtin_headers) arg_list.append(test_files[0]) print(arg_list) ret = call_from_shell_list(arg_list) - #print("ret:", ret.returncode) print("ret:", ret.stdout.decode("utf-8"), end="") print("ret:", ret.stderr.decode("utf-8"), end="") |