From 70090f6a5dad406f38270a2dfa1f302b8627e73b Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Thu, 15 Nov 2018 14:48:38 +0330 Subject: update --- test/compile_commands.json | 7 ++ test/main.ast | 80 +++++++++++++++++++++ test/main.cpp | 31 ++++++++ test/makefile | 175 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 293 insertions(+) create mode 100644 test/compile_commands.json create mode 100644 test/main.ast create mode 100644 test/main.cpp create mode 100644 test/makefile diff --git a/test/compile_commands.json b/test/compile_commands.json new file mode 100644 index 0000000..a12a8fc --- /dev/null +++ b/test/compile_commands.json @@ -0,0 +1,7 @@ +[ + { + "command": "c++ -c -std=c++11 -fpic -o main.o main.cpp", + "directory": "/home/bloodstalker/devi/abbatoir/hole114", + "file": "/home/bloodstalker/devi/abbatoir/hole114/main.cpp" + } +] \ No newline at end of file diff --git a/test/main.ast b/test/main.ast new file mode 100644 index 0000000..02edebb --- /dev/null +++ b/test/main.ast @@ -0,0 +1,80 @@ +TranslationUnitDecl 0x6bd18f8 <>  +|-TypedefDecl 0x6bd21d0 <>  implicit __int128_t '__int128' +| `-BuiltinType 0x6bd1e90 '__int128' +|-TypedefDecl 0x6bd2238 <>  implicit __uint128_t 'unsigned __int128' +| `-BuiltinType 0x6bd1eb0 'unsigned __int128' +|-TypedefDecl 0x6bd2568 <>  implicit __NSConstantString '__NSConstantString_tag' +| `-RecordType 0x6bd2310 '__NSConstantString_tag' +| `-CXXRecord 0x6bd2288 '__NSConstantString_tag' +|-TypedefDecl 0x6c0c340 <>  implicit __builtin_ms_va_list 'char *' +| `-PointerType 0x6bd25c0 'char *' +| `-BuiltinType 0x6bd1990 'char' +|-TypedefDecl 0x6c0c668 <>  implicit __builtin_va_list '__va_list_tag [1]' +| `-ConstantArrayType 0x6c0c610 '__va_list_tag [1]' 1 +| `-RecordType 0x6c0c420 '__va_list_tag' +| `-CXXRecord 0x6c0c390 '__va_list_tag' +|-CXXRecordDecl 0x6c0c6b8 <main.cpp:2:1, line:12:1> line:2:7 referenced class myClass definition +| |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init +| | |-DefaultConstructor exists non_trivial user_provided +| | |-CopyConstructor simple trivial has_const_param implicit_has_const_param +| | |-MoveConstructor +| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param +| | |-MoveAssignment +| | `-Destructor non_trivial user_declared +| |-CXXRecordDecl 0x6c0c7c8 <col:1, col:7> col:7 implicit referenced class myClass +| |-AccessSpecDecl 0x6c0c850 <line:3:3, col:9> col:3 public +| |-CXXConstructorDecl 0x6c0c920 <line:4:5, col:13> col:5 used myClass 'void ()' +| |-CXXDestructorDecl 0x6c0ca10 <line:5:5, col:14> col:5 used ~myClass 'void () noexcept' +| |-CXXMethodDecl 0x6c0cb48 <line:7:5, col:27> col:10 used myMehtod1 'void ()' +| | `-CompoundStmt 0x6c0ce28 <col:26, col:27> +| |-CXXMethodDecl 0x6c0cc70 <line:8:5, col:27> col:10 used myMehtod2 'void ()' +| | `-CompoundStmt 0x6c0ce38 <col:26, col:27> +| |-AccessSpecDecl 0x6c0cd08 <line:9:3, col:10> col:3 private +| |-FieldDecl 0x6c0cd48 <line:10:5, col:9> col:9 a 'int' +| |-FieldDecl 0x6c0cda8 <line:11:5, col:11> col:11 b 'float' +| `-CXXConstructorDecl 0x6c3b9a8 <line:2:7> col:7 implicit constexpr myClass 'void (const myClass &)' inline default trivial noexcept-unevaluated 0x6c3b9a8 +| `-ParmVarDecl 0x6c3bad0 <col:7> col:7 'const myClass &' +|-CXXRecordDecl 0x6c0ce48 <line:14:1, line:17:1> line:14:8 struct myStruct definition +| |-DefinitionData empty standard_layout has_user_declared_ctor can_const_default_init +| | |-DefaultConstructor exists non_trivial user_provided defaulted_is_constexpr +| | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param +| | |-MoveConstructor +| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param +| | |-MoveAssignment +| | `-Destructor non_trivial user_declared +| |-CXXRecordDecl 0x6c0cf58 <col:1, col:8> col:8 implicit referenced struct myStruct +| |-CXXConstructorDecl 0x6c0d048 <line:15:3, col:12> col:3 myStruct 'void ()' +| `-CXXDestructorDecl 0x6c0d138 <line:16:3, col:13> col:3 ~myStruct 'void ()' noexcept-unevaluated 0x6c0d138 +|-FunctionDecl 0x6c0d2a8 <line:19:1, col:21> col:6 myFunc1 'void ()' +| `-CompoundStmt 0x6c3b590 <col:20, col:21> +|-FunctionDecl 0x6c3b630 <line:20:1, col:21> col:6 myFunc2 'void ()' +| `-CompoundStmt 0x6c3b6c8 <col:20, col:21> +`-FunctionDecl 0x6c3b868 <line:22:1, line:31:1> line:22:5 main 'int (int, char **)' + |-ParmVarDecl 0x6c3b6f0 <col:11, col:15> col:15 argc 'int' + |-ParmVarDecl 0x6c3b790 <col:21, col:28> col:28 argv 'char **' + `-CompoundStmt 0x6c3c038 <col:34, line:31:1> + |-DeclStmt 0x6c3bba0 <line:23:3, col:13> + | `-VarDecl 0x6c3b920 <col:3, col:11> col:11 used mc 'myClass' callinit + | `-CXXConstructExpr 0x6c3bb38 <col:11> 'myClass' 'void ()' + |-CXXMemberCallExpr 0x6c3bc18 <line:24:3, col:16> 'void' + | `-MemberExpr 0x6c3bbe0 <col:3, col:6> '' .myMehtod1 0x6c0cb48 + | `-DeclRefExpr 0x6c3bbb8 <col:3> 'myClass' lvalue Var 0x6c3b920 'mc' 'myClass' + |-CXXMemberCallExpr 0x6c3bca0 <line:25:3, col:16> 'void' + | `-MemberExpr 0x6c3bc68 <col:3, col:6> '' .myMehtod2 0x6c0cc70 + | `-DeclRefExpr 0x6c3bc40 <col:3> 'myClass' lvalue Var 0x6c3b920 'mc' 'myClass' + |-DeclStmt 0x6c3bd40 <line:26:3, col:8> + | `-VarDecl 0x6c3bce0 <col:3, col:7> col:7 used a 'int' + |-DeclStmt 0x6c3bdd0 <line:27:3, col:10> + | `-VarDecl 0x6c3bd70 <col:3, col:9> col:9 b 'float' + |-DeclStmt 0x6c3bef0 <line:28:3, col:10> + | |-VarDecl 0x6c3be00 <col:3, col:7> col:7 used c 'int' + | `-VarDecl 0x6c3be78 <col:3, col:9> col:9 used d 'int' + |-BinaryOperator 0x6c3bfd8 <line:29:3, col:9> 'int' lvalue '=' + | |-DeclRefExpr 0x6c3bf08 <col:3> 'int' lvalue Var 0x6c3bce0 'a' 'int' + | `-BinaryOperator 0x6c3bfb0 <col:7, col:9> 'int' '+' + | |-ImplicitCastExpr 0x6c3bf80 <col:7> 'int' <LValueToRValue> + | | `-DeclRefExpr 0x6c3bf30 <col:7> 'int' lvalue Var 0x6c3be00 'c' 'int' + | `-ImplicitCastExpr 0x6c3bf98 <col:9> 'int' <LValueToRValue> + | `-DeclRefExpr 0x6c3bf58 <col:9> 'int' lvalue Var 0x6c3be78 'd' 'int' + `-ReturnStmt 0x6c3c020 <line:30:3, col:10> + `-IntegerLiteral 0x6c3c000 <col:10> 'int' 0 diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..815a48d --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,31 @@ + +class myClass { + public: + myClass(); + ~myClass(); + + void myMehtod1(void) {} + void myMehtod2(void) {} + private: + int a; + float b; +}; + +struct myStruct { + myStruct(); + ~myStruct(); +}; + +void myFunc1(void) {} +void myFunc2(void) {} + +int main (int argc, char** argv) { + myClass mc; + mc.myMehtod1(); + mc.myMehtod2(); + int a; + float b; + int c,d; + a = c+d; + return 0; +} diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..127064d --- /dev/null +++ b/test/makefile @@ -0,0 +1,175 @@ +TARGET?=main +SHELL=bash +SHELL?=bash +CXX=clang++ +CXX?=clang++ +CXX_FLAGS=-std=c++11 -fpic +CXX_EXTRA?= +CTAGS_I_PATH?=./ +LD_FLAGS= +EXTRA_LD_FLAGS?= +ADD_SANITIZERS_CC= -g -fsanitize=address -fno-omit-frame-pointer +ADD_SANITIZERS_LD= -g -fsanitize=address +MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer +MEM_SANITIZERS_LD= -g -fsanitize=memory +UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer +UB_SANITIZERS_LD= -g -fsanitize=undefined +COV_CXX= -fprofile-instr-generate -fcoverage-mapping +COV_LD= -fprofile-instr-generate +# BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN +BUILD_MODE?=RELEASE +OBJ_LIST:=$(patsubst %.cpp, %.o, $(wildcard *.cpp)) +ASM_LIST:=$(patsubst %.cpp, %.dis, $(wildcard *.cpp)) +WASM_LIST:=$(patsubst %.cpp, %.wasm, $(wildcard *.cpp)) +JS_LIST:=$(patsubst %.cpp, %.js, $(wildcard *.cpp)) + +ifeq ($(BUILD_MODE), ADDSAN) +ifeq ($(CXX), g++) +$(error This build mode is only useable with clang++.) +endif +CXX_EXTRA+=$(ADD_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(ADD_SANITIZERS_LD) +endif + +ifeq ($(BUILD_MODE), MEMSAN) +ifeq ($(CXX), g++) +$(error This build mode is only useable with clang++.) +endif +CXX_EXTRA+=$(MEM_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(MEM_SANITIZERS_LD) +endif + +ifeq ($(BUILD_MODE), UBSAN) +ifeq ($(CXX), g++) +$(error This build mode is only useable with clang++.) +endif +CXX_EXTRA+=$(UB_SANITIZERS_CC) +EXTRA_LD_FLAGS+=$(UB_SANITIZERS_LD) +endif + +SRCS:=$(wildcard *.cpp) +HDRS:=$(wildcard *.h) +CXX_FLAGS+=$(CXX_EXTRA) +LD_FLAGS+=$(EXTRA_LD_FLAGS) + +.DEFAULT:all + +.PHONY:all clean help ASM SO TAGS WASM JS + +all:$(TARGET) + +everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov WASM JS + +depend:.depend + +.depend:$(SRCS) + rm -rf .depend + $(CXX) -MM $(CXX_FLAGS) $^ > ./.depend + echo $(patsubst %.o:, %.odbg:, $(shell $(CXX) -MM $(CXX_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\-\_]+\.odbg/\n&/g' >> ./.depend + echo $(patsubst %.o:, %.ocov:, $(shell $(CXX) -MM $(CXX_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\-\_]+\.ocov/\n&/g' >> ./.depend + +-include ./.depend + +.cpp.o: + $(CXX) $(CXX_FLAGS) -c $< -o $@ + +%.odbg:%.cpp + $(CXX) $(CXX_FLAGS) -g -c $< -o $@ + +%.ocov:%.cpp + $(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@ + +$(TARGET): $(TARGET).o + $(CXX) $(LD_FLAGS) $^ -o $@ + +$(TARGET)-static: $(TARGET).o + $(CXX) $(LD_FLAGS) $^ -static -o $@ + +$(TARGET)-dbg: $(TARGET).odbg + $(CXX) $(LD_FLAGS) $^ -g -o $@ + +$(TARGET)-cov: $(TARGET).ocov + $(CXX) $(LD_FLAGS) $^ $(COV_LD) -o $@ + +cov: runcov + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov show $(TARGET)-cov -instr-profile=default.profdata + +covrep: runcov + @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata + @llvm-cov report $(TARGET)-cov -instr-profile=default.profdata + +ASM:$(ASM_LIST) + +SO:$(TARGET).so + +A:$(TARGET).a + +WASM:$(WASM_LIST) + +JS:$(JS_LIST) + +TAGS:tags + +#https://github.com/rizsotto/Bear +BEAR: clean + bear make + +tags:$(SRCS) + $(shell $(CXX) -c -I $(CTAGS_I_PATH) -M $(SRCS)|\ + sed -e 's/[\\ ]/\n/g'|sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d'|\ + ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q) + +%.dis: %.o + objdump -r -d -M intel -S $< > $@ + +%.wasm: %.cpp + $(CXX) --compile $< --target=wasm32-unknown-unknown-wasm --output $@ + +%.js: %.cpp + em++ $< -o $@ + +$(TARGET).so: $(TARGET).o + $(CXX) $(LD_FLAGS) $^ -shared -o $@ + +$(TARGET).a: $(TARGET).o + ar rcs $(TARGET).a $(TARGET).o + +runcov: $(TARGET)-cov + $(TARGET)-cov + +test: $(TARGET) + $(TARGET) + +valgrind: $(TARGET) + - valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all $(TARGET) + +format: + - clang-format -i $(SRCS) $(HDRS) + +clean: + rm -f *.o *.dis *.odbg *.ocov *.js *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov + +deepclean: clean + - rm tags + - rm .depend + - rm ./default.profraw ./default.profdata + - rm vgcore.* + - rm compile_commands.json + +help: + @echo "--all is the default target, runs $(TARGET) target" + @echo "--everything will build everything" + @echo "--SO will generate the so" + @echo "--ASM will generate assembly files" + @echo "--TAGS will generate tags file" + @echo "--$(TARGET) builds the dynamically-linked executable" + @echo "--$(TARGET)-dbg will generate the debug build. BUILD_MODE should be set to DEBUG to work" + @echo "--$(TARGET)-static will statically link the executable to the libraries" + @echo "--$(TARGET)-cov is the coverage build" + @echo "--cov will print the coverage report" + @echo "--covrep will print the line coverage report" + @echo "--A will build the static library" + @echo "--TAGS will build the tags file" + @echo "--clean" + @echo "--deepclean will clean almost everything" -- cgit v1.2.3