From 09c11cfc2fa735b222bee7d359b834697bf95ea1 Mon Sep 17 00:00:00 2001 From: Victor Rodriguez Date: Mon, 26 Nov 2018 03:51:30 -0600 Subject: [PATCH] Add support for cpp files with test examples Fix https://github.com/clearlinux/make-fmv-patch/issues/2 Signed-off-by: Victor Rodriguez --- README | 17 +++++++++++++++++ make-fmv-patch.pl | 2 +- tests/Makefile | 9 +++++++++ tests/loop-test.c | 25 +++++++++++++++++++++++++ tests/max-test.cpp | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile create mode 100644 tests/loop-test.c create mode 100644 tests/max-test.cpp diff --git a/README b/README index 10898b7..27e516f 100644 --- a/README +++ b/README @@ -25,3 +25,20 @@ Requirements In order to use `make-fvm-patch.pl` your system will need Exuberant Ctags (https://sourceforge.net/projects/ctags/), this is due to the `--c-kinds` ctags' flag usage. + +------------ +Test examples +------------ +``` + cd tests + make + cd .. + + perl make-fmv-patch.pl tests/max-build.log tests/ + perl make-fmv-patch.pl tests/loop-build.log tests/ + + This will generate: + + ./tests/max-test.cpp.patch + ./tests/loop-test.c.patch +``` diff --git a/make-fmv-patch.pl b/make-fmv-patch.pl index 66bf4b7..ddc54e7 100644 --- a/make-fmv-patch.pl +++ b/make-fmv-patch.pl @@ -96,7 +96,7 @@ foreach (keys %f) { my $fname = $_; my @flines = @{$f{$_}->{v_line}}; - if ($fname =~ /(\.c$)/) { + if ($fname =~ /(\.c$)/ || $fname =~ /(\.cpp$)/) { my $f_path = &find_file($fname); my @keys = 0; diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..61a1931 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,9 @@ +all: + gcc -O2 -ftree-vectorize loop-test.c -o loop-test -fopt-info-vec &> loop-build.log + g++ -O2 -ftree-vectorize max-test.cpp -o max-test -fopt-info-vec &> max-build.log +clean: + @find . -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print | xargs rm -f +distclean: + @rm -rf *.c.patch + @rm -rf *.cpp.patch + @rm -rf *build.log diff --git a/tests/loop-test.c b/tests/loop-test.c new file mode 100644 index 0000000..3dbb8ca --- /dev/null +++ b/tests/loop-test.c @@ -0,0 +1,25 @@ +#include +#include +#include +#define MAX 1000000 + +static struct timeval tm1; +int a[256], b[256], c[256]; + +void foo(); + +int main(){ + foo(); + return 0; +} + +void foo(){ + int i,x; + for (x=0; x +using namespace std; + +int max(int num1, int num2); +void foo(); + +int a[256], b[256]; + +int main () { + foo(); + return 0; +} + +void foo(){ + + int i; + for (i=0; i<256; i++){ + a[i] = 100; + b[i] = 200; + } + + int ret; + for (i=0; i<256; i++){ + ret = max(a[i], b[i]); + cout << "Max value is : " << ret << endl; + } +} + +int max(int num1, int num2) { + int result; + if (num1 > num2) + result = num1; + else + result = num2; + return result; +}