diff --git a/.travis.yml b/.travis.yml index ca8c2381b4c..bb5f03e72e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -145,13 +145,16 @@ install: eval ${PRE_COMMAND} ${COMMAND} - COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"-Wall -Werror -pedantic -O2 -g $EXTRA_CXXFLAGS\" -j2" && eval ${PRE_COMMAND} ${COMMAND} - - COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"$FLAGS $EXTRA_CXXFLAGS\" -j2 cegis.dir clobber.dir memory-models.dir musketeer.dir" && + - COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"$FLAGS $EXTRA_CXXFLAGS\" -j2 clobber.dir memory-models.dir musketeer.dir" && eval ${PRE_COMMAND} ${COMMAND} script: - if [ -e bin/gcc ] ; then export PATH=$PWD/bin:$PATH ; fi ; COMMAND="env UBSAN_OPTIONS=print_stacktrace=1 make -C regression test" && eval ${PRE_COMMAND} ${COMMAND} + - COMMAND="make -C unit CXX=\"$COMPILER\" CXXFLAGS=\"-Wall -Werror -pedantic -O2 -g $EXTRA_CXXFLAGS\" -j2" && + eval ${PRE_COMMAND} ${COMMAND} + - COMMAND="make -C unit test" && eval ${PRE_COMMAND} ${COMMAND} before_cache: - ccache -s diff --git a/CODING_STANDARD b/CODING_STANDARD index d079889bb8d..ebc2b31f594 100644 --- a/CODING_STANDARD +++ b/CODING_STANDARD @@ -26,23 +26,23 @@ Whitespaces: - No whitespaces in blank lines - Put argument lists on next line (and ident 2 spaces) if too long - Put parameters on separate lines (and ident 2 spaces) if too long -- No whitespaces around colon for inheritance, +- No whitespaces around colon for inheritance, put inherited into separate lines in case of multiple inheritance - The initializer list follows the constructor without a whitespace around the colon. Break line after the colon if required and indent members. - if(...), else, for(...), do, and while(...) are always in a separate line -- Break expressions in if, for, while if necessary and align them +- Break expressions in if, for, while if necessary and align them with the first character following the opening parenthesis - Use {} instead of ; for the empty statement -- Single line blocks without { } are allowed, +- Single line blocks without { } are allowed, but put braces around multi-line blocks -- Use blank lines to visually separate logically cohesive code blocks +- Use blank lines to visually separate logically cohesive code blocks within a function - Have a newline at the end of a file Comments: - Do not use /* */ except for file and function comment blocks -- Each source and header file must start with a comment block +- Each source and header file must start with a comment block stating the Module name and Author [will be changed when we roll out doxygen] - Each function in the source file (not the header) is preceded by a function comment header consisting of a comment block stating @@ -75,9 +75,9 @@ Comments: - Use #ifdef DEBUG to guard debug code Naming: -- Identifiers may use the characters [a-z0-9_] and should start with a +- Identifiers may use the characters [a-z0-9_] and should start with a lower-case letter (parameters in constructors may start with _). -- Use american spelling for identifiers. +- Use american spelling for identifiers. - Separate basic words by _ - Avoid abbreviations (e.g. prefer symbol_table to of st). - User defined type identifiers have to be terminated by 't'. Moreover, @@ -122,7 +122,7 @@ Program Command Line Options from the command line into the options C++ features: -- Do not use namespaces. +- Do not use namespaces, except for anonymous namespaces. - Prefer use of 'typedef' insted of 'using'. - Prefer use of 'class' instead of 'struct'. - Write type modifiers before the type specifier. @@ -136,7 +136,7 @@ C++ features: - Avoid iterators, use ranged for instead - Avoid allocation with new/delete, use unique_ptr - Avoid pointers, use references -- Avoid char *, use std::string +- Avoid char *, use std::string - For numbers, use int, unsigned, long, unsigned long, double - Use mp_integer, not BigInt - Use the functions in util for conversions between numbers and strings @@ -146,13 +146,13 @@ C++ features: - Use instances of std::size_t for comparison with return values of .size() of STL containers and algorithms, and use them as indices to arrays or vectors. - Do not use default values in public functions -- Use assertions to detect programming errors, e.g. whenever you make +- Use assertions to detect programming errors, e.g. whenever you make assumptions on how your code is used -- Use exceptions only when the execution of the program has to abort +- Use exceptions only when the execution of the program has to abort because of erroneous user input -- We allow to use 3rd-party libraries directly. - No wrapper matching the coding rules is required. - Allowed libraries are: STL. +- We allow to use 3rd-party libraries directly. + No wrapper matching the coding rules is required. + Allowed libraries are: STL. - When throwing, omit the brackets, i.e. `throw "error"`. - Error messages should start with a lower case letter. - Use the auto keyword if and only if one of the following @@ -165,12 +165,30 @@ Architecture-specific code: - Don't include architecture-specific header files without #ifdef ... Output: -- Do not output to cout or cerr directly (except in temporary debug code, +- Do not output to cout or cerr directly (except in temporary debug code, and then guard #include by #ifdef DEBUG) - Derive from messaget if the class produces output and use the streams provided (status(), error(), debug(), etc) - Use '\n' instead of std::endl +Unit tests: + - Unit tests are written using Catch: https://github.com/philsquared/Catch/ + - For large classes: + - Create a separate file that contains the tests for each method of each + class + - The file should be named according to + `unit/class/path/class_name/function_name.cpp` + - For small classes: + - Create a separate file that contains the tests for all methods of each + class + - The file should be named according to unit/class/path/class_name.cpp + - Catch supports tagging, tests should be tagged with all the following tags: + - [core] should be used for all tests unless the test takes more than 1 + second to run, then it should be tagged with [long] + - [folder_name] of the file being tested + - [class_name] of the class being tested + - [function_name] of the function being tested + You are allowed to break rules if you have a good reason to do so. Pre-commit hook to run cpplint locally diff --git a/COMPILING b/COMPILING index 7cbdfcaab13..4b47b38b790 100644 --- a/COMPILING +++ b/COMPILING @@ -38,7 +38,7 @@ We assume that you have a Debian/Ubuntu or Red Hat-like distribution. yum install gcc gcc-c++ flex bison perl-libwww-perl patch devtoolset-6 - Note that you need g++ version 5.2 or newer. + Note that you need g++ version 4.9 or newer. 1) As a user, get the CBMC source via diff --git a/appveyor.yml b/appveyor.yml index 5f287b193d4..f1f66142620 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -54,7 +54,7 @@ build_script: cp -r deps/minisat2-2.2.1 minisat-2.2.1 patch -d minisat-2.2.1 -p1 < scripts/minisat-2.2.1-patch call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64 - sed -i "s/BUILD_ENV.*/BUILD_ENV = MSVC/" src/config.inc + sed -i "s/BUILD_ENV[ ]*=.*/BUILD_ENV = MSVC/" src/config.inc make -C src -j2 test_script: @@ -108,3 +108,7 @@ test_script: rmdir /s /q goto-instrument\slice08 make test + + cd .. + make -C unit all + make -C unit test diff --git a/doc/html-manual/api.shtml b/doc/html-manual/api.shtml index 3cfae3cfeb9..141ae88b80a 100644 --- a/doc/html-manual/api.shtml +++ b/doc/html-manual/api.shtml @@ -111,11 +111,14 @@ void __CPROVER_cover(_Bool condition);
+

This statement defines a custom coverage criterion, for usage +with the test suite generation feature.

+

-

__CPROVER_isnan, __CPROVER_isfinite, __CPROVER_isfinite, -__CPROVER_isfinite, __CPROVER_sign

+

__CPROVER_isnan, __CPROVER_isfinite, __CPROVER_isinf, +__CPROVER_isnormal, __CPROVER_sign


diff --git a/doc/html-manual/cover.shtml b/doc/html-manual/cover.shtml index 5e3bfaffad8..54480059399 100644 --- a/doc/html-manual/cover.shtml +++ b/doc/html-manual/cover.shtml @@ -10,8 +10,6 @@

A Small Tutorial with A Case Study

- -

We assume that CBMC is installed on your system. If not so, follow these instructions.

@@ -238,4 +236,42 @@ coverage criteria like branch, decision, path etc. are also available when calling CBMC.

+

Coverage Criteria

+ +

+The table below summarizes the coverage criteria that CBMC supports. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CriterionDefinition
assertionFor every assertion, generate a test that reaches it
locationFor every location, generate a test that reaches it
branchGenerate a test for every branch outcome
decisionGenerate a test for both outcomes of every Boolean expression +that is not an operand of a propositional connective
conditionGenerate a test for both outcomes of every Boolean expression
mcdcModified Condition/Decision Coverage (MC/DC)
pathBounded path coverage
coverGenerate a test for every __CPROVER_cover statement +
+ diff --git a/doc/html-manual/modeling-nondet.shtml b/doc/html-manual/modeling-nondet.shtml index ffd146ba4f6..3b0809ffb79 100644 --- a/doc/html-manual/modeling-nondet.shtml +++ b/doc/html-manual/modeling-nondet.shtml @@ -39,9 +39,8 @@ prefix nondet_. As an example, the following function returns a nondeterministically chosen unsigned short int:

- -unsigned short int nondet_ushortint(); - +
unsigned short int nondet_ushortint();
+

Note that the body of the function is not defined. The name of the function itself is irrelevant (save for the prefix), but must be diff --git a/pkg/arch/PKGBUILD b/pkg/arch/PKGBUILD new file mode 100644 index 00000000000..1a19dce9e39 --- /dev/null +++ b/pkg/arch/PKGBUILD @@ -0,0 +1,40 @@ +# Maintainer: Vlastimil Zeman + +pkgname=cbmc +pkgver=5.7 +pkgrel=1 +pkgdesc="Bounded Model Checker for C and C++ programs" +arch=("x86_64") +url="https://github.com/diffblue/cbmc" +license=("BSD-4-Clause") +depends=("gcc-libs>=6.3") +makedepends=("gcc>=6.3" + "make>=4.2" + "patch>=2.7" + "perl-libwww>=6.24" + "bison>=3.0" + "flex>=2.6") +source=("https://github.com/diffblue/cbmc/archive/$pkgname-$pkgver.tar.gz") +sha256sums=("4f98cdce609532d3fc2587299ee4a6544f63aff5cf42e89d2baaa3d3562edf3e") + + +build() { + make -C "$pkgname-$pkgname-$pkgver/src" minisat2-download + make -C "$pkgname-$pkgname-$pkgver/src" -j$(getconf _NPROCESSORS_ONLN) +} + + +check() { + make -C "$pkgname-$pkgname-$pkgver/regression" test +} + + +package() { + mkdir -p "$pkgdir/usr/bin/" + for binary in $pkgname goto-analyzer goto-cc goto-diff goto-instrument + do + cp "$pkgname-$pkgname-$pkgver/src/$binary/$binary" "$pkgdir/usr/bin/" + chmod 755 "$pkgdir/usr/bin/$binary" + chown root:root "$pkgdir/usr/bin/$binary" + done +} diff --git a/pkg/arch/README.md b/pkg/arch/README.md new file mode 100644 index 00000000000..05dea5516dc --- /dev/null +++ b/pkg/arch/README.md @@ -0,0 +1,17 @@ +# Arch Linux Package + +Update packages and install build dependencies + +```bash +sudo pacman -Sy archlinux-keyring && sudo pacman -Syyu +sudo pacman -S gcc bison flex make patch perl-libwww fakeroot +``` + +Create folder for package and copy [PKGBUILD](PKGBUILD) file there. + +Build package by running `makepkg` in that folder. That will compile *CBMC* and +run all tests. To install package run + +```bash +sudo pacman -U cbmc-5.7-1-x86_64.pkg.tar.xz` +``` diff --git a/regression/cbmc-cover/built-ins1/main.c b/regression/cbmc-cover/built-ins1/main.c new file mode 100644 index 00000000000..2822ea8e7b2 --- /dev/null +++ b/regression/cbmc-cover/built-ins1/main.c @@ -0,0 +1,17 @@ +int main() +{ + char a[10]; + __CPROVER_input("a[3]", a[3]); + + int len = strlen(a); + + if(len==3) + { + return 0; + } + else if(len==4) + { + return -1; + } + return 1; +} diff --git a/regression/cbmc-cover/built-ins1/test.desc b/regression/cbmc-cover/built-ins1/test.desc new file mode 100644 index 00000000000..49b517629f3 --- /dev/null +++ b/regression/cbmc-cover/built-ins1/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--cover location --unwind 1 +^EXIT=0$ +^SIGNAL=0$ +^\*\* 4 of 7 covered +-- +^warning: ignoring +^\[.* + +int main() +{ + const char *s="test"; + int ret=puts(s); //return value is nondet (internal to built-in, thus non-controllable) + + if(ret<0) + { + return 1; + } + + return 0; +} diff --git a/regression/cbmc-cover/built-ins3/test.desc b/regression/cbmc-cover/built-ins3/test.desc new file mode 100644 index 00000000000..bd3fc9fdaa3 --- /dev/null +++ b/regression/cbmc-cover/built-ins3/test.desc @@ -0,0 +1,9 @@ +CORE +main.c +--cover location --unwind 10 +^EXIT=0$ +^SIGNAL=0$ +^\*\* 4 of 4 covered +-- +^warning: ignoring +^\[.* +#include + +int main() +{ + printf("PRINT d1 %d, %d\n", 123, -123); + printf("PRINT g1 %g, %g, %g, %g\n", 123.0, -123.0, 123.123, 0.123); + printf("PRINT e1 %e, %e, %e, %e\n", 123.0, -123.0, 123.123, 0.123); + printf("PRINT f1 %f, %f, %f, %f\n", 123.0, -123.0, 123.123, 0.123); + assert(0); +} diff --git a/regression/cbmc/printf1/test.desc b/regression/cbmc/printf1/test.desc new file mode 100644 index 00000000000..b5c8583e4ff --- /dev/null +++ b/regression/cbmc/printf1/test.desc @@ -0,0 +1,11 @@ +CORE +main.c +--trace +^EXIT=10$ +^SIGNAL=0$ +^PRINT d1 123, -123$ +^PRINT g1 123, -123, 123\.123, 0\.123$ +^PRINT e1 1\.230000e\+2, -1\.230000e\+2, 1\.231230e\+2, 1\.230000e-1$ +^PRINT f1 123\.000000, -123\.000000, 123\.123000, 0\.123000$ +-- +^warning: ignoring diff --git a/regression/cegis/cegis_control_benchmark_01/SatelliteB2.c b/regression/cegis/cegis_control_benchmark_01/SatelliteB2.c deleted file mode 100644 index 65f807bfbeb..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/SatelliteB2.c +++ /dev/null @@ -1,5311 +0,0 @@ -// tag-#anon#ST[ARR100{F64}$F64$'a'|S32'a_size'|U32'$pad0'|ARR100{F64}$F64$'b'|S32'b_size'|U32'$pad1'|F64'sample_time'|ARR100{F64}$F64$'a_uncertainty'|ARR100{F64}$F64$'b_uncertainty'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 144 -struct anonymous$0; - -// tag-#anon#ST[ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'A'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'B'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'C'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'D'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'states'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'outputs'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'inputs'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'K'|U32'nStates'|U32'nInputs'|U32'nOutputs'|U32'$pad0'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 156 -struct anonymous$1; - -// tag-#anon#ST[S32'int_bits'|S32'frac_bits'|F64'max'|F64'min'|S32'default_realization'|U32'$pad0'|F64'delta'|S32'scale'|U32'$pad1'|F64'max_error'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 171 -struct anonymous$3; - -// tag-#anon#ST[S32'push'|S32'in'|S32'sbiw'|S32'cli'|S32'out'|S32'std'|S32'ldd'|S32'subi'|S32'sbci'|S32'lsl'|S32'rol'|S32'add'|S32'adc'|S32'adiw'|S32'rjmp'|S32'mov'|S32'sbc'|S32'ld'|S32'rcall'|S32'cp'|S32'cpc'|S32'ldi'|S32'brge'|S32'pop'|S32'ret'|S32'st'|S32'brlt'|S32'cpi'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 183 -struct anonymous; - -// tag-#anon#ST[S64'clock'|S32'device'|U32'$pad0'|F64'cycle'|SYM#tag-#anon#ST[S32'push'|S32'in'|S32'sbiw'|S32'cli'|S32'out'|S32'std'|S32'ldd'|S32'subi'|S32'sbci'|S32'lsl'|S32'rol'|S32'add'|S32'adc'|S32'adiw'|S32'rjmp'|S32'mov'|S32'sbc'|S32'ld'|S32'rcall'|S32'cp'|S32'cpc'|S32'ldi'|S32'brge'|S32'pop'|S32'ret'|S32'st'|S32'brlt'|S32'cpi']#'assembly'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 215 -struct anonymous$2; - -#include - -#ifndef IEEE_FLOAT_EQUAL -#define IEEE_FLOAT_EQUAL(x,y) ((x)==(y)) -#endif -#ifndef IEEE_FLOAT_NOTEQUAL -#define IEEE_FLOAT_NOTEQUAL(x,y) ((x)!=(y)) -#endif - -// __DSVERIFIER_assert -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 35 -void __DSVERIFIER_assert(_Bool expression); -// __DSVERIFIER_assert_msg -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 39 -void __DSVERIFIER_assert_msg(_Bool expression, char *msg); -// __DSVERIFIER_assume -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 21 -void __DSVERIFIER_assume(_Bool expression); -// __assert_fail -// file /usr/include/assert.h line 67 -extern void __assert_fail(const char *, const char *, unsigned int, const char *) _Noreturn; -// call_closedloop_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 369 -void call_closedloop_verification_task(void *closedloop_verification_task); -// call_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 268 -void call_verification_task(void *verification_task); -// check_stability -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 59 -signed int check_stability(double *a, signed int n); -// check_stability_closedloop -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 70 -signed int check_stability_closedloop(double *a, signed int n, double *plant_num, signed int p_num_size, double *plant_den, signed int p_den_size); -// determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 498 -double determinant(double (*a)[20l], signed int n); -// double_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 315 -void double_add_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]); -// double_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 218 -void double_check_limit_cycle(double *y, signed int y_size); -// double_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 187 -void double_check_oscillations(double *y, signed int y_size); -// double_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 254 -void double_check_persistent_limit_cycle(double *y, signed int y_size); -// double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 83 -double double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_1_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 205 -double double_direct_form_1_MSP430(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 364 -void double_direct_form_1_impl2(double *x, signed int x_size, double *b, signed int b_size, double *a, signed int a_size, double *y); -// double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 102 -double double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 230 -double double_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 428 -void double_exp_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], unsigned int expNumber, double (*result)[20l]); -// double_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 337 -void double_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, double (*m1)[20l], double (*m2)[20l], double (*m3)[20l]); -// double_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 23 -double double_state_space_representation(void); -// double_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 326 -void double_sub_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]); -// double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 122 -double double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_transposed_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 257 -double double_transposed_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// exit -// file /usr/include/stdlib.h line 543 -extern void exit(signed int) _Noreturn; -// fatorial -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 54 -signed int fatorial(signed int n); -// float_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 144 -float float_direct_form_1(float *y, float *x, float *a, float *b, signed int Na, signed int Nb); -// float_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 163 -float float_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// float_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 183 -float float_transposed_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// ft_closedloop_feedback -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 57 -void ft_closedloop_feedback(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// ft_closedloop_sensitivity -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 42 -void ft_closedloop_sensitivity(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// ft_closedloop_series -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 28 -void ft_closedloop_series(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// fxp_abs -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 303 -signed long int fxp_abs(signed long int a); -// fxp_add -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 315 -signed long int fxp_add(signed long int aadd, signed long int badd); -// fxp_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 467 -void fxp_add_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]); -// fxp_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 163 -void fxp_check_limit_cycle(signed long int *y, signed int y_size); -// fxp_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 253 -void fxp_check_oscillations(signed long int *y, signed int y_size); -// fxp_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 201 -void fxp_check_persistent_limit_cycle(signed long int *y, signed int y_size); -// fxp_determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 529 -double fxp_determinant(signed long int (*a_fxp)[20l], signed int n); -// fxp_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 22 -signed long int fxp_direct_form_1(signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 388 -void fxp_direct_form_1_impl2(signed long int *x, signed int x_size, signed long int *b, signed int b_size, signed long int *a, signed int a_size, signed long int *y); -// fxp_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 41 -signed long int fxp_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_div -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 357 -signed long int fxp_div(signed long int a, signed long int b); -// fxp_double_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 211 -signed long int fxp_double_to_fxp(double value); -// fxp_double_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 247 -void fxp_double_to_fxp_array(double *f, signed long int *r, signed int N); -// fxp_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 390 -void fxp_exp_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], unsigned int expNumber, signed long int (*result)[20l]); -// fxp_float_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 198 -signed long int fxp_float_to_fxp(float f); -// fxp_float_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 240 -void fxp_float_to_fxp_array(float *f, signed long int *r, signed int N); -// fxp_get_frac_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 125 -signed long int fxp_get_frac_part(signed long int in); -// fxp_get_int_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 115 -signed long int fxp_get_int_part(signed long int in); -// fxp_int_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 170 -signed long int fxp_int_to_fxp(signed int in); -// fxp_ln -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 288 -signed int fxp_ln(signed int x); -// fxp_log10 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 345 -double fxp_log10(double x); -// fxp_log10_low -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 333 -double fxp_log10_low(double x); -// fxp_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 368 -void fxp_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*m3)[20l]); -// fxp_mult -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 339 -signed long int fxp_mult(signed long int amult, signed long int bmult); -// fxp_neg -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 367 -signed long int fxp_neg(signed long int aneg); -// fxp_print_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 407 -void fxp_print_float(signed long int a); -// fxp_print_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 411 -void fxp_print_float_array(signed long int *a, signed int N); -// fxp_print_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 403 -void fxp_print_int(signed long int a); -// fxp_quantize -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 136 -signed long int fxp_quantize(signed long int aquant); -// fxp_shrl -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 390 -signed long int fxp_shrl(signed long int in, signed int shift); -// fxp_sign -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 380 -signed long int fxp_sign(signed long int a); -// fxp_square -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 399 -signed long int fxp_square(signed long int a); -// fxp_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 67 -double fxp_state_space_representation(void); -// fxp_sub -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 327 -signed long int fxp_sub(signed long int asub, signed long int bsub); -// fxp_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 474 -void fxp_sub_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]); -// fxp_to_double -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 271 -double fxp_to_double(signed long int fxp); -// fxp_to_double_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 291 -void fxp_to_double_array(double *f, signed long int *r, signed int N); -// fxp_to_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 264 -float fxp_to_float(signed long int fxp); -// fxp_to_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 284 -void fxp_to_float_array(float *f, signed long int *r, signed int N); -// fxp_to_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 182 -signed int fxp_to_int(signed long int fxp); -// fxp_transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 582 -void fxp_transpose(signed long int (*a)[20l], signed long int (*b)[20l], signed int n, signed int m); -// fxp_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 61 -signed long int fxp_transposed_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 153 -void fxp_verify_overflow(signed long int value); -// fxp_verify_overflow_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 158 -void fxp_verify_overflow_array(signed long int *array, signed int n); -// generate_delta_coefficients -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 33 -void generate_delta_coefficients(double *vetor, double *out, signed int n, double delta); -// generic_timing_double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 286 -double generic_timing_double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 311 -double generic_timing_double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 338 -double generic_timing_double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_shift_l_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 20 -double generic_timing_shift_l_double(double zIn, double *z, signed int N); -// generic_timing_shift_r_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 37 -double generic_timing_shift_r_double(double zIn, double *z, signed int N); -// get_delta_transfer_function -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 52 -void get_delta_transfer_function(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta); -// get_delta_transfer_function_with_base -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 59 -void get_delta_transfer_function_with_base(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta); -// iirIIOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 428 -float iirIIOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// iirIItOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 452 -float iirIItOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// iirIItOutTime_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 479 -double iirIItOutTime_double(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// iirOutBoth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 506 -void iirOutBoth(float *yf, float *xf, float *af, float *bf, float *sumf_ref, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int *sum_ref, signed int Na, signed int Nb); -// iirOutBothL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 586 -float iirOutBothL(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb); -// iirOutBothL2 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 626 -float iirOutBothL2(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb); -// iirOutFixedL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 536 -signed long int iirOutFixedL(signed long int *y, signed long int *x, signed long int xin, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// iirOutFloatL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 561 -float iirOutFloatL(float *y, float *x, float xin, float *a, float *b, signed int Na, signed int Nb); -// initialization -// file /home/lucascordeiro/dsverifier/bmc/core/initialization.h line 24 -void initialization(); -// initialize_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 22 -void initialize_array(double *v, signed int n); -// initials -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 52 -extern void initials(); -// internal_abs -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 49 -double internal_abs(double a); -// internal_pow -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 39 -double internal_pow(double a, double b); -// nchoosek -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 23 -signed int nchoosek(signed int n, signed int k); -// nondet_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 27 -double nondet_double(); -// nondet_float -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 18 -float nondet_float(); -// nondet_int -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 17 -signed int nondet_int(); -// order -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 158 -signed int order(signed int Na, signed int Nb); -// poly_mult -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 165 -void poly_mult(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans); -// poly_sum -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 141 -void poly_sum(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans); -// print_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 305 -void print_array_elements(char *name, double *v, signed int n); -// print_fxp_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 419 -void print_fxp_array_elements(char *name, signed long int *v, signed int n); -// print_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 481 -void print_matrix(double (*matrix)[20l], unsigned int lines, unsigned int columns); -// printf -// file /usr/include/stdio.h line 362 -extern signed int printf(const char *, ...); -// rand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 417 -extern signed int rand(void); -// revert_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 30 -void revert_array(double *v, double *out, signed int n); -// shiftL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 53 -signed long int shiftL(signed long int zIn, signed long int *z, signed int N); -// shiftLDouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 119 -double shiftLDouble(double zIn, double *z, signed int N); -// shiftLboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 130 -void shiftLboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N); -// shiftLfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 75 -float shiftLfloat(float zIn, float *z, signed int N); -// shiftR -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 64 -signed long int shiftR(signed long int zIn, signed long int *z, signed int N); -// shiftRDdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 97 -double shiftRDdouble(double zIn, double *z, signed int N); -// shiftRboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 144 -void shiftRboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N); -// shiftRdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 108 -double shiftRdouble(double zIn, double *z, signed int N); -// shiftRfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 86 -float shiftRfloat(float zIn, float *z, signed int N); -// snrPoint -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 402 -float snrPoint(float *s, float *n, signed int blksz); -// snrPower -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 381 -float snrPower(float *s, float *n, signed int blksz); -// snrVariance -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 357 -float snrVariance(float *s, float *n, signed int blksz); -// srand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 423 -extern void srand(unsigned int seed); -// transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 571 -void transpose(double (*a)[20l], double (*b)[20l], signed int n, signed int m); -// validation -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 125 -void validation(); -// verify_controllability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 16 -signed int verify_controllability(void); -// verify_controllability_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 120 -signed int verify_controllability_double(void); -// verify_error -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error.h line 20 -signed int verify_error(void); -// verify_error_closedloop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_closedloop.h line 27 -signed int verify_error_closedloop(void); -// verify_error_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 20 -signed int verify_error_state_space(void); -// verify_generic_timing -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 25 -signed int verify_generic_timing(void); -// verify_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 111 -signed int verify_limit_cycle(void); -// verify_limit_cycle_closed_loop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 29 -signed int verify_limit_cycle_closed_loop(void); -// verify_limit_cycle_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 21 -signed int verify_limit_cycle_state_space(void); -// verify_minimum_phase -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_minimum_phase.h line 24 -signed int verify_minimum_phase(void); -// verify_observability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_observability.h line 19 -signed int verify_observability(void); -// verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 23 -signed int verify_overflow(void); -// verify_stability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability.h line 24 -signed int verify_stability(void); -// verify_stability_closedloop_using_dslib -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability_closedloop.h line 21 -signed int verify_stability_closedloop_using_dslib(void); -// verify_timing_msp_430 -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_timing_msp430.h line 22 -signed int verify_timing_msp_430(void); -// verify_zero_input_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_zero_input_limit_cycle.h line 16 -signed int verify_zero_input_limit_cycle(void); -// wrap -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 100 -signed long int wrap(signed long int kX, signed long int kLowerBound, signed long int kUpperBound); - -struct anonymous$0 -{ - // a - double a[100l]; - // a_size - signed int a_size; - // b - double b[100l]; - // b_size - signed int b_size; - // sample_time - double sample_time; - // a_uncertainty - double a_uncertainty[100l]; - // b_uncertainty - double b_uncertainty[100l]; -}; - -struct anonymous$1 -{ - // A - double A[20l][20l]; - // B - double B[20l][20l]; - // C - double C[20l][20l]; - // D - double D[20l][20l]; - // states - double states[20l][20l]; - // outputs - double outputs[20l][20l]; - // inputs - double inputs[20l][20l]; - // K - double K[20l][20l]; - // nStates - unsigned int nStates; - // nInputs - unsigned int nInputs; - // nOutputs - unsigned int nOutputs; -}; - -struct anonymous$3 -{ - // int_bits - signed int int_bits; - // frac_bits - signed int frac_bits; - // max - double max; - // min - double min; - // default_realization - signed int default_realization; - // delta - double delta; - // scale - signed int scale; - // max_error - double max_error; -}; - -struct anonymous -{ - // push - signed int push; - // in - signed int in; - // sbiw - signed int sbiw; - // cli - signed int cli; - // out - signed int out; - // std - signed int std; - // ldd - signed int ldd; - // subi - signed int subi; - // sbci - signed int sbci; - // lsl - signed int lsl; - // rol - signed int rol; - // add - signed int add; - // adc - signed int adc; - // adiw - signed int adiw; - // rjmp - signed int rjmp; - // mov - signed int mov; - // sbc - signed int sbc; - // ld - signed int ld; - // rcall - signed int rcall; - // cp - signed int cp; - // cpc - signed int cpc; - // ldi - signed int ldi; - // brge - signed int brge; - // pop - signed int pop; - // ret - signed int ret; - // st - signed int st; - // brlt - signed int brlt; - // cpi - signed int cpi; -}; - -struct anonymous$2 -{ - // clock - signed long int clock; - // device - signed int device; - // cycle - double cycle; - // assembly - struct anonymous assembly; -}; - - -// X_SIZE_VALUE -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 121 -signed int X_SIZE_VALUE=0; -// _controller -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 17 -extern struct anonymous$1 _controller; -// _dbl_max -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 45 -double _dbl_max; -// _dbl_min -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 46 -double _dbl_min; -// _fxp_fmask -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 49 -signed long int _fxp_fmask; -// _fxp_half -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 39 -signed long int _fxp_half; -// _fxp_imask -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 52 -signed long int _fxp_imask; -// _fxp_max -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 42 -signed long int _fxp_max; -// _fxp_min -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 41 -signed long int _fxp_min; -// _fxp_minus_one -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 40 -signed long int _fxp_minus_one; -// _fxp_one -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 38 -signed long int _fxp_one; -// controller -// file input.c line 3 -struct anonymous$0 controller={ .a={ 1.000000, (double)-4.200000e-1f, (double)-3.465000e-1f, (double)-3.915000e-2f, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .a_size=4, - .b={ 2.880000e+0, (double)-4.896000e+0f, 2.074000e+0, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_size=3, - .sample_time=1.000000, .a_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 } }; -// ds -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 17 -extern struct anonymous$0 ds; -// error_limit -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 18 -extern double error_limit; -// generic_timer -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 23 -signed int generic_timer=0; -// hw -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 18 -extern struct anonymous$2 hw; -// impl -// file input.c line 11 -struct anonymous$3 impl={ .int_bits=3, .frac_bits=7, .max=1.000000, .min=-1.000000, - .default_realization=0, .delta=0.000000, - .scale=1, .max_error=0.000000 }; -// nInputs -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 20 -extern signed int nInputs; -// nOutputs -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 21 -extern signed int nOutputs; -// nStates -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 19 -extern signed int nStates; -// next -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 416 -unsigned long int next=1ul; -// overflow_mode -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 122 -signed int overflow_mode=1; -// plant -// file input.c line 19 -struct anonymous$0 plant={ .a={ 1.000000, (double)-2.000000f, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .a_size=3, - .b={ 1.250000e-1, 1.250000e-1, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_size=2, - .sample_time=0.000000, .a_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 } }; -// plant_cbmc -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 46 -struct anonymous$0 plant_cbmc; -// rounding_mode -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 123 -signed int rounding_mode=0; -// scale_factor -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 55 -static const double scale_factor[31l]={ 1.000000, 2.000000, 4.000000, 8.000000, 16.000000, 32.000000, 64.000000, 128.000000, 256.000000, 512.000000, 1024.000000, 2048.000000, 4096.000000, 8192.000000, 16384.000000, 32768.000000, 65536.000000, 1.310720e+5, 2.621440e+5, 5.242880e+5, 1.048576e+6, 2.097152e+6, 4.194304e+6, 8.388608e+6, 1.677722e+7, 3.355443e+7, 6.710886e+7, 1.342177e+8, 2.684355e+8, 5.368709e+8, 1.073742e+9 }; -// scale_factor_inv -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 62 -static const double scale_factor_inv[31l]={ 1.000000, 5.000000e-1, 2.500000e-1, 1.250000e-1, 6.250000e-2, 3.125000e-2, 1.562500e-2, 7.812500e-3, 3.906250e-3, 1.953125e-3, 9.765625e-4, 4.882813e-4, 2.441406e-4, 1.220703e-4, 6.103516e-5, 3.051758e-5, 1.525879e-5, 7.629395e-6, 3.814697e-6, 1.907349e-6, 9.536743e-7, 4.768372e-7, 2.384186e-7, 1.192093e-7, 5.960465e-8, 2.980232e-8, 1.490116e-8, 7.450581e-9, 3.725290e-9, 1.862645e-9, 9.313230e-10 }; - -// __DSVERIFIER_assert -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 35 -void __DSVERIFIER_assert(_Bool expression) -{ - /* assertion expression */ - assert(expression != (_Bool)0); - if(!(expression == (_Bool)0)) - (void)0; - -} - -// __DSVERIFIER_assert_msg -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 39 -void __DSVERIFIER_assert_msg(_Bool expression, char *msg) -{ - printf("%c", msg); - /* assertion expression */ - assert(expression != (_Bool)0); - if(!(expression == (_Bool)0)) - (void)0; - -} - -// __DSVERIFIER_assume -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 21 -void __DSVERIFIER_assume(_Bool expression) -{ - __CPROVER_assume(expression != (_Bool)0); -} - -// call_closedloop_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 369 -void call_closedloop_verification_task(void *closedloop_verification_task) -{ - _Bool base_case_executed=(_Bool)0; - signed int i=0; - i = 0; - for( ; !(i >= plant.b_size); i = i + 1) - { - if(plant.b_uncertainty[(signed long int)i] > 0.000000) - { - double call_closedloop_verification_task$$1$$1$$1$$1$$factor=(plant.b[(signed long int)i] * plant.b_uncertainty[(signed long int)i]) / 100.000000; - call_closedloop_verification_task$$1$$1$$1$$1$$factor = call_closedloop_verification_task$$1$$1$$1$$1$$factor < 0.000000 ? call_closedloop_verification_task$$1$$1$$1$$1$$factor * (double)-1 : call_closedloop_verification_task$$1$$1$$1$$1$$factor; - double call_closedloop_verification_task$$1$$1$$1$$1$$min=plant.b[(signed long int)i] - call_closedloop_verification_task$$1$$1$$1$$1$$factor; - double call_closedloop_verification_task$$1$$1$$1$$1$$max=plant.b[(signed long int)i] + call_closedloop_verification_task$$1$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_closedloop_verification_task$$1$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L9; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_closedloop_verification_task$$1$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - plant_cbmc.b[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$1; - if(plant_cbmc.b[(signed long int)i] >= call_closedloop_verification_task$$1$$1$$1$$1$$min) - tmp_if_expr$1 = plant_cbmc.b[(signed long int)i] <= call_closedloop_verification_task$$1$$1$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - } - - else - plant_cbmc.b[(signed long int)i] = plant.b[(signed long int)i]; - - __CPROVER_DUMP_L9: - ; - } - i = 0; - for( ; !(i >= plant.a_size); i = i + 1) - { - if(plant.a_uncertainty[(signed long int)i] > 0.000000) - { - double factor=(plant.a[(signed long int)i] * plant.a_uncertainty[(signed long int)i]) / 100.000000; - factor = factor < 0.000000 ? factor * (double)-1 : factor; - double min=plant.a[(signed long int)i] - factor; - double max=plant.a[(signed long int)i] + factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - goto __CPROVER_DUMP_L19; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - base_case_executed = (_Bool)0; - - plant_cbmc.a[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$2; - if(plant_cbmc.a[(signed long int)i] >= min) - tmp_if_expr$2 = plant_cbmc.a[(signed long int)i] <= max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - - else - plant_cbmc.a[(signed long int)i] = plant.a[(signed long int)i]; - - __CPROVER_DUMP_L19: - ; - } - ((void (*)())closedloop_verification_task)(); -} - -// call_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 268 -void call_verification_task(void *verification_task) -{ - signed int i=0; - _Bool base_case_executed=(_Bool)0; - if((_Bool)0) - { - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - { - if(ds.b_uncertainty[(signed long int)i] > 0.000000) - { - double call_verification_task$$1$$1$$1$$1$$1$$factor=ds.b_uncertainty[(signed long int)i]; - call_verification_task$$1$$1$$1$$1$$1$$factor = call_verification_task$$1$$1$$1$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$1$$1$$1$$1$$factor * (double)-1 : call_verification_task$$1$$1$$1$$1$$1$$factor; - double min=ds.b[(signed long int)i] - call_verification_task$$1$$1$$1$$1$$1$$factor; - double max=ds.b[(signed long int)i] + call_verification_task$$1$$1$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$1$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L8; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$1$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.b[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$1; - if(ds.b[(signed long int)i] >= min) - tmp_if_expr$1 = ds.b[(signed long int)i] <= max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - } - - - __CPROVER_DUMP_L8: - ; - } - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - { - if(ds.a_uncertainty[(signed long int)i] > 0.000000) - { - double factor=ds.a_uncertainty[(signed long int)i]; - factor = factor < 0.000000 ? factor * (double)-1 : factor; - double call_verification_task$$1$$1$$2$$1$$1$$min=ds.a[(signed long int)i] - factor; - double call_verification_task$$1$$1$$2$$1$$1$$max=ds.a[(signed long int)i] + factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - goto __CPROVER_DUMP_L17; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.a[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$2; - if(ds.a[(signed long int)i] >= call_verification_task$$1$$1$$2$$1$$1$$min) - tmp_if_expr$2 = ds.a[(signed long int)i] <= call_verification_task$$1$$1$$2$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - - - __CPROVER_DUMP_L17: - ; - } - } - - else - { - signed int call_verification_task$$1$$2$$i=0; - call_verification_task$$1$$2$$i = 0; - for( ; !(call_verification_task$$1$$2$$i >= ds.b_size); call_verification_task$$1$$2$$i = call_verification_task$$1$$2$$i + 1) - { - if(ds.b_uncertainty[(signed long int)call_verification_task$$1$$2$$i] > 0.000000) - { - double call_verification_task$$1$$2$$1$$1$$1$$factor=(ds.b[(signed long int)call_verification_task$$1$$2$$i] * ds.b_uncertainty[(signed long int)call_verification_task$$1$$2$$i]) / 100.000000; - call_verification_task$$1$$2$$1$$1$$1$$factor = call_verification_task$$1$$2$$1$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$2$$1$$1$$1$$factor * (double)-1 : call_verification_task$$1$$2$$1$$1$$1$$factor; - double call_verification_task$$1$$2$$1$$1$$1$$min=ds.b[(signed long int)call_verification_task$$1$$2$$i] - call_verification_task$$1$$2$$1$$1$$1$$factor; - double call_verification_task$$1$$2$$1$$1$$1$$max=ds.b[(signed long int)call_verification_task$$1$$2$$i] + call_verification_task$$1$$2$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L27; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.b[(signed long int)call_verification_task$$1$$2$$i] = nondet_double(); - _Bool tmp_if_expr$3; - if(ds.b[(signed long int)call_verification_task$$1$$2$$i] >= call_verification_task$$1$$2$$1$$1$$1$$min) - tmp_if_expr$3 = ds.b[(signed long int)call_verification_task$$1$$2$$i] <= call_verification_task$$1$$2$$1$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$3 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$3); - } - - - __CPROVER_DUMP_L27: - ; - } - call_verification_task$$1$$2$$i = 0; - for( ; !(call_verification_task$$1$$2$$i >= ds.a_size); call_verification_task$$1$$2$$i = call_verification_task$$1$$2$$i + 1) - { - if(ds.a_uncertainty[(signed long int)call_verification_task$$1$$2$$i] > 0.000000) - { - double call_verification_task$$1$$2$$2$$1$$1$$factor=(ds.a[(signed long int)call_verification_task$$1$$2$$i] * ds.a_uncertainty[(signed long int)call_verification_task$$1$$2$$i]) / 100.000000; - call_verification_task$$1$$2$$2$$1$$1$$factor = call_verification_task$$1$$2$$2$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$2$$2$$1$$1$$factor * (double)-1 : call_verification_task$$1$$2$$2$$1$$1$$factor; - double call_verification_task$$1$$2$$2$$1$$1$$min=ds.a[(signed long int)call_verification_task$$1$$2$$i] - call_verification_task$$1$$2$$2$$1$$1$$factor; - double call_verification_task$$1$$2$$2$$1$$1$$max=ds.a[(signed long int)call_verification_task$$1$$2$$i] + call_verification_task$$1$$2$$2$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$2$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L36; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$2$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.a[(signed long int)call_verification_task$$1$$2$$i] = nondet_double(); - _Bool tmp_if_expr$4; - if(ds.a[(signed long int)call_verification_task$$1$$2$$i] >= call_verification_task$$1$$2$$2$$1$$1$$min) - tmp_if_expr$4 = ds.a[(signed long int)call_verification_task$$1$$2$$i] <= call_verification_task$$1$$2$$2$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$4 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$4); - } - - - __CPROVER_DUMP_L36: - ; - } - } - ((void (*)())verification_task)(); -} - -// check_stability -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 59 -signed int check_stability(double *a, signed int n) -{ - signed int lines=2 * n - 1; - signed int columns=n; - const signed long int columns$array_size0=(signed long int)n; - const signed long int columns$array_size1=(signed long int)lines; - double m[columns$array_size1][columns$array_size0]; - signed int i; - signed int j; - const signed long int j$array_size0=(signed long int)n; - double current_stability[j$array_size0]; - i = 0; - for( ; !(i >= n); i = i + 1) - current_stability[(signed long int)i] = a[(signed long int)i]; - double sum=0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - sum = sum + a[(signed long int)i]; - if(sum <= 0.000000) - { - printf("[DEBUG] the first constraint of Jury criteria failed: (F(1) > 0)"); - return 0; - } - - else - { - sum = 0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - { - double return_value_internal_pow$1=internal_pow((double)-1, (double)((n - 1) - i)); - sum = sum + a[(signed long int)i] * return_value_internal_pow$1; - } - double return_value_internal_pow$2=internal_pow((double)-1, (double)(n - 1)); - sum = sum * return_value_internal_pow$2; - if(sum <= 0.000000) - { - printf("[DEBUG] the second constraint of Jury criteria failed: (F(-1)*(-1)^n > 0)"); - return 0; - } - - else - { - double return_value_internal_abs$3=internal_abs(a[(signed long int)(n - 1)]); - if(return_value_internal_abs$3 > *a) - { - printf("[DEBUG] the third constraint of Jury criteria failed: (abs(a0) < a_{n}*z^{n})"); - return 0; - } - - else - { - i = 0; - for( ; !(i >= lines); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - m[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0; - for( ; !(i >= lines); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - if(i == 0) - m[(signed long int)i][(signed long int)j] = a[(signed long int)j]; - - else - if(!(i % 2 == 0)) - { - signed int x=0; - for( ; !(x >= columns); x = x + 1) - m[(signed long int)i][(signed long int)x] = m[(signed long int)(i - 1)][(signed long int)((columns - x) - 1)]; - columns = columns - 1; - j = columns; - } - - else - m[(signed long int)i][(signed long int)j] = m[(signed long int)(i - 2)][(signed long int)j] - (m[(signed long int)(i - 2)][(signed long int)columns] / m[(signed long int)(i - 2)][0l]) * m[(signed long int)(i - 1)][(signed long int)j]; - } - signed int first_is_positive=m[0l][0l] >= 0.000000 ? 1 : 0; - i = 0; - for( ; !(i >= lines); i = i + 1) - if(i % 2 == 0) - { - signed int line_is_positive=m[(signed long int)i][0l] >= 0.000000 ? 1 : 0; - if(!(first_is_positive == line_is_positive)) - return 0; - - } - - return 1; - } - } - } -} - -// check_stability_closedloop -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 70 -signed int check_stability_closedloop(double *a, signed int n, double *plant_num, signed int p_num_size, double *plant_den, signed int p_den_size) -{ - signed int columns=n; - const signed long int columns$array_size0=(signed long int)n; - const signed long int columns$array_size1=(signed long int)(2 * n - 1); - double m[columns$array_size1][columns$array_size0]; - signed int i; - signed int j; - signed int first_is_positive=0; - double *p_num=plant_num; - double *p_den=plant_den; - double sum=0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - sum = sum + a[(signed long int)i]; - __DSVERIFIER_assert(sum > 0.000000); - sum = 0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - { - double return_value_internal_pow$1=internal_pow((double)-1, (double)((n - 1) - i)); - sum = sum + a[(signed long int)i] * return_value_internal_pow$1; - } - double return_value_internal_pow$2=internal_pow((double)-1, (double)(n - 1)); - sum = sum * return_value_internal_pow$2; - __DSVERIFIER_assert(sum > 0.000000); - double return_value_internal_abs$3=internal_abs(a[(signed long int)(n - 1)]); - __DSVERIFIER_assert(return_value_internal_abs$3 < a[0l]); - i = 0; - for( ; !(i >= 2 * n + -1); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - { - m[(signed long int)i][(signed long int)j] = 0.000000; - if(i == 0) - m[(signed long int)i][(signed long int)j] = a[(signed long int)j]; - - else - if(!(i % 2 == 0)) - { - signed int x=0; - for( ; !(x >= columns); x = x + 1) - m[(signed long int)i][(signed long int)x] = m[(signed long int)(i - 1)][(signed long int)((columns - x) - 1)]; - columns = columns - 1; - j = columns; - } - - else - { - m[(signed long int)i][(signed long int)j] = m[(signed long int)(i - 2)][(signed long int)j] - (m[(signed long int)(i - 2)][(signed long int)columns] / m[(signed long int)(i - 2)][0l]) * m[(signed long int)(i - 1)][(signed long int)j]; - _Bool tmp_if_expr$4; - if(m[0l][0l] >= 0.000000) - tmp_if_expr$4 = m[(signed long int)i][0l] >= 0.000000 ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$4 = (_Bool)0; - __DSVERIFIER_assert(tmp_if_expr$4); - } - } - } - return 1; -} - -// determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 498 -double determinant(double (*a)[20l], signed int n) -{ - signed int i; - signed int j; - signed int j1; - signed int j2; - double det=0.000000; - double m[20l][20l]; - if(n >= 1) - { - if(n == 1) - det = a[0l][0l]; - - else - if(n == 2) - det = a[0l][0l] * a[1l][1l] - a[1l][0l] * a[0l][1l]; - - else - { - det = 0.000000; - j1 = 0; - for( ; !(j1 >= n); j1 = j1 + 1) - { - i = 0; - for( ; !(i >= -1 + n); i = i + 1) - { - i = 1; - for( ; !(i >= n); i = i + 1) - { - j2 = 0; - j = 0; - for( ; !(j >= n); j = j + 1) - if(!(j == j1)) - { - m[(signed long int)(i - 1)][(signed long int)j2] = a[(signed long int)i][(signed long int)j]; - j2 = j2 + 1; - } - - } - } - double return_value_internal_pow$1=internal_pow(-1.000000, 1.000000 + (double)j1 + 1.000000); - double return_value_determinant$2=determinant(m, n - 1); - det = det + return_value_internal_pow$1 * a[0l][(signed long int)j1] * return_value_determinant$2; - } - } - } - - return det; -} - -// double_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 315 -void double_add_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j] + m2[(signed long int)i][(signed long int)j]; - } -} - -// double_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 218 -void double_check_limit_cycle(double *y, signed int y_size) -{ - double reference=y[(signed long int)(y_size - 1)]; - signed int idx=0; - signed int window_size=1; - idx = y_size - 2; - for( ; idx >= 0; idx = idx - 1) - if(IEEE_FLOAT_NOTEQUAL(y[(signed long int)idx], reference)) - window_size = window_size + 1; - - else - break; - __DSVERIFIER_assume(window_size != y_size && window_size != 1); - printf("window_size %d\n", window_size); - signed int desired_elements=2 * window_size; - signed int found_elements=0; - idx = y_size - 1; - for( ; idx >= 0; idx = idx - 1) - if(!(-1 + y_size + -window_size >= idx)) - { - printf("%.0f == %.0f\n", y[(signed long int)idx], y[(signed long int)(idx - window_size)]); - signed int cmp_idx=idx - window_size; - _Bool tmp_if_expr$1; - if(cmp_idx >= 1) - tmp_if_expr$1 = IEEE_FLOAT_EQUAL(y[(signed long int)idx], y[(signed long int)(idx - window_size)]) ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - if(tmp_if_expr$1) - found_elements = found_elements + 2; - - else - break; - } - - printf("desired_elements %d\n", desired_elements); - printf("found_elements %d\n", found_elements); - __DSVERIFIER_assert(desired_elements != found_elements); -} - -// double_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 187 -void double_check_oscillations(double *y, signed int y_size) -{ - __DSVERIFIER_assume(IEEE_FLOAT_NOTEQUAL(y[0l], y[(signed long int)(y_size - 1)])); - signed int window_timer=0; - signed int window_count=0; - signed int i; - signed int j; - i = 2; - for( ; !(i >= y_size); i = i + 1) - { - signed int window_size=i; - j = 0; - for( ; !(j >= y_size); j = j + 1) - { - if(!(window_size >= window_timer)) - { - window_timer = 0; - window_count = 0; - } - - signed int window_index=j + window_size; - if(!(window_index >= y_size)) - { - if(IEEE_FLOAT_EQUAL(y[(signed long int)j], y[(signed long int)window_index])) - { - window_count = window_count + 1; - /* assertion !(window_count == window_size) */ - assert(!(window_count == window_size)); - if(!(window_count == window_size)) - (void)0; - - } - - } - - else - break; - window_timer = window_timer + 1; - } - } -} - -// double_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 254 -void double_check_persistent_limit_cycle(double *y, signed int y_size) -{ - signed int idy=0; - signed int count_same=0; - signed int window_size=0; - double reference=y[0l]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(IEEE_FLOAT_NOTEQUAL(y[(signed long int)idy], reference)) - window_size = window_size + 1; - - else - if(!(window_size == 0)) - break; - - else - count_same = count_same + 1; - window_size = window_size + count_same; - __DSVERIFIER_assume(window_size > 1 && window_size <= y_size / 2); - const signed long int reference$array_size0=(signed long int)window_size; - double lco_elements[reference$array_size0]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(idy >= window_size)) - lco_elements[(signed long int)idy] = y[(signed long int)idy]; - - idy = 0; - signed int lco_idy=0; - _Bool is_persistent=(_Bool)0; - while(!(idy >= y_size)) - { - signed int tmp_post$1=idy; - idy = idy + 1; - signed int tmp_post$2=lco_idy; - lco_idy = lco_idy + 1; - if(IEEE_FLOAT_EQUAL(y[(signed long int)tmp_post$1], lco_elements[(signed long int)tmp_post$2])) - is_persistent = (_Bool)0; - - else - { - is_persistent = (_Bool)0; - break; - } - if(lco_idy == window_size) - lco_idy = 0; - - } - __DSVERIFIER_assert((signed int)is_persistent == 0); -} - -// double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 83 -double double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - sum = sum / a[0l]; - return sum; -} - -// double_direct_form_1_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 205 -double double_direct_form_1_MSP430(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - timer1 = timer1 + 91; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 47; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 57; - } - timer1 = timer1 + 3; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return sum; -} - -// double_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 364 -void double_direct_form_1_impl2(double *x, signed int x_size, double *b, signed int b_size, double *a, signed int a_size, double *y) -{ - signed int i=0; - signed int j=0; - const signed long int j$array_size0=(signed long int)x_size; - double v[j$array_size0]; - i = 0; - for( ; !(i >= x_size); i = i + 1) - { - v[(signed long int)i] = 0.000000; - j = 0; - for( ; !(j >= b_size); j = j + 1) - { - if(!(i >= j)) - break; - - v[(signed long int)i] = v[(signed long int)i] + x[(signed long int)(i - j)] * b[(signed long int)j]; - } - } - y[0l] = v[0l]; - i = 1; - for( ; !(i >= x_size); i = i + 1) - { - y[(signed long int)i] = 0.000000; - y[(signed long int)i] = y[(signed long int)i] + v[(signed long int)i]; - j = 1; - for( ; !(j >= a_size); j = j + 1) - { - if(!(i >= j)) - break; - - y[(signed long int)i] = y[(signed long int)i] + y[(signed long int)(i - j)] * (double)-1 * a[(signed long int)j]; - } - } -} - -// double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 102 -double double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - } - return sum; -} - -// double_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 230 -double double_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - timer1 = timer1 + 71; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 54; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 46; - } - timer1 = timer1 + 38; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return sum; -} - -// double_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 428 -void double_exp_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], unsigned int expNumber, double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - unsigned int l; - double m2[20l][20l]; - if(expNumber == 0u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - if(i == j) - result[(signed long int)i][(signed long int)j] = 1.000000; - - else - result[(signed long int)i][(signed long int)j] = 0.000000; - } - } - - else - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j]; - } - if(!(expNumber == 1u)) - { - l = 1u; - for( ; !(l >= expNumber); l = l + 1u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - m2[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j]; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - { - k = 0u; - for( ; !(k >= columns); k = k + 1u) - result[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j] + m2[(signed long int)i][(signed long int)k] * m1[(signed long int)k][(signed long int)j]; - } - } - } - } - - } -} - -// double_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 337 -void double_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, double (*m1)[20l], double (*m2)[20l], double (*m3)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - if(j1 == i2) - { - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - m3[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - { - k = 0u; - for( ; !(k >= j1); k = k + 1u) - { - double mult=m1[(signed long int)i][(signed long int)k] * m2[(signed long int)k][(signed long int)j]; - m3[(signed long int)i][(signed long int)j] = m3[(signed long int)i][(signed long int)j] + m1[(signed long int)i][(signed long int)k] * m2[(signed long int)k][(signed long int)j]; - } - } - } - } - - else - printf("\nError! Operation invalid, please enter with valid matrices.\n"); -} - -// double_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 23 -double double_state_space_representation(void) -{ - double result1[20l][20l]; - double result2[20l][20l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0.000000; - result2[(signed long int)i][(signed long int)j] = 0.000000; - } - } - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - i = 1; - for( ; !(i >= 0); i = i + 1) - { - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.A, _controller.states, result1); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.B, _controller.inputs, result2); - double_add_matrix((unsigned int)nStates, 1u, result1, result2, _controller.states); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - } - return _controller.outputs[0l][0l]; -} - -// double_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 326 -void double_sub_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j] - m2[(signed long int)i][(signed long int)j]; - } -} - -// double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 122 -double double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - yout = yout / a[0l]; - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - } - return yout; -} - -// double_transposed_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 257 -double double_transposed_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return yout; -} - -// fatorial -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 54 -signed int fatorial(signed int n) -{ - signed int tmp_if_expr$2; - signed int return_value_fatorial$1; - if(n == 0) - tmp_if_expr$2 = 1; - - else - { - return_value_fatorial$1=fatorial(n - 1); - tmp_if_expr$2 = n * return_value_fatorial$1; - } - return tmp_if_expr$2; -} - -// float_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 144 -float float_direct_form_1(float *y, float *x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *y_ptr; - float *b_ptr; - float *x_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - sum = sum / a[0l]; - return sum; -} - -// float_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 163 -float float_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *b_ptr; - float *w_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - } - return sum; -} - -// float_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 183 -float float_transposed_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *b_ptr; - float yout=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - yout = yout / a[0l]; - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - float *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - } - return yout; -} - -// ft_closedloop_feedback -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 57 -void ft_closedloop_feedback(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - Nans_num = (Nc_den + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - signed int Nnum_mult=(Nc_num + Nmodel_num) - 1; - const signed long int Nnum_mult$array_size0=(signed long int)Nans_den; - double den_mult[Nnum_mult$array_size0]; - const signed long int den_mult$array_size0=(signed long int)Nnum_mult; - double num_mult[den_mult$array_size0]; - poly_mult(c_num, Nc_num, model_num, Nmodel_num, num_mult, Nnum_mult); - poly_mult(c_den, Nc_den, model_den, Nmodel_den, den_mult, Nans_den); - poly_sum(num_mult, Nnum_mult, den_mult, Nans_den, ans_den, Nans_den); - poly_mult(c_den, Nc_den, model_num, Nmodel_num, ans_num, Nans_num); -} - -// ft_closedloop_sensitivity -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 42 -void ft_closedloop_sensitivity(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - signed int Nans_num_p=(Nc_num + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - Nans_num = (Nc_den + Nmodel_den) - 1; - const signed long int Nans_num_p$array_size0=(signed long int)Nans_num_p; - double num_mult[Nans_num_p$array_size0]; - poly_mult(c_den, Nc_den, model_den, Nmodel_den, ans_num, Nans_num); - poly_mult(c_num, Nc_num, model_num, Nmodel_num, num_mult, Nans_num_p); - poly_sum(ans_num, Nans_num, num_mult, Nans_num_p, ans_den, Nans_den); -} - -// ft_closedloop_series -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 28 -void ft_closedloop_series(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - Nans_num = (Nc_num + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - const signed long int ft_closedloop_series$array_size0=(signed long int)Nans_den; - double den_mult[ft_closedloop_series$array_size0]; - poly_mult(c_num, Nc_num, model_num, Nmodel_num, ans_num, Nans_num); - poly_mult(c_den, Nc_den, model_den, Nmodel_den, den_mult, Nans_den); - poly_sum(ans_num, Nans_num, den_mult, Nans_den, ans_den, Nans_den); -} - -// fxp_abs -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 303 -signed long int fxp_abs(signed long int a) -{ - signed long int tmp=a < 0l ? -((signed long int)a) : a; - return tmp; -} - -// fxp_add -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 315 -signed long int fxp_add(signed long int aadd, signed long int badd) -{ - signed long int tmpadd=(signed long int)aadd + (signed long int)badd; - return tmpadd; -} - -// fxp_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 467 -void fxp_add_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j]=fxp_add(m1[(signed long int)i][(signed long int)j], m2[(signed long int)i][(signed long int)j]); - } -} - -// fxp_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 163 -void fxp_check_limit_cycle(signed long int *y, signed int y_size) -{ - signed long int reference=y[(signed long int)(y_size - 1)]; - signed int idx=0; - signed int window_size=1; - idx = y_size - 2; - for( ; idx >= 0; idx = idx - 1) - if(!(y[(signed long int)idx] == reference)) - window_size = window_size + 1; - - else - break; - __DSVERIFIER_assume(window_size != y_size && window_size != 1); - printf("window_size %d\n", window_size); - signed int desired_elements=2 * window_size; - signed int found_elements=0; - idx = y_size - 1; - for( ; idx >= 0; idx = idx - 1) - if(!(-1 + y_size + -window_size >= idx)) - { - printf("%.0f == %.0f\n", y[(signed long int)idx], y[(signed long int)(idx - window_size)]); - signed int cmp_idx=idx - window_size; - _Bool tmp_if_expr$1; - if(cmp_idx >= 1) - tmp_if_expr$1 = y[(signed long int)idx] == y[(signed long int)(idx - window_size)] ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - if(tmp_if_expr$1) - found_elements = found_elements + 2; - - else - break; - } - - __DSVERIFIER_assume(found_elements > 0); - printf("desired_elements %d\n", desired_elements); - printf("found_elements %d\n", found_elements); - __DSVERIFIER_assume(found_elements == desired_elements); - __DSVERIFIER_assert((_Bool)0); -} - -// fxp_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 253 -void fxp_check_oscillations(signed long int *y, signed int y_size) -{ - _Bool tmp_if_expr$1; - if(!(*y == y[(signed long int)(-1 + y_size)])) - tmp_if_expr$1 = y[(signed long int)(y_size - 1)] != y[(signed long int)(y_size - 2)] ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - signed int window_timer=0; - signed int window_count=0; - signed int i; - signed int j; - i = 2; - for( ; !(i >= y_size); i = i + 1) - { - signed int window_size=i; - j = 0; - for( ; !(j >= y_size); j = j + 1) - { - if(!(window_size >= window_timer)) - { - window_timer = 0; - window_count = 0; - } - - signed int window_index=j + window_size; - if(!(window_index >= y_size)) - { - if(y[(signed long int)j] == y[(signed long int)window_index]) - { - window_count = window_count + 1; - __DSVERIFIER_assert(!(window_count == window_size)); - } - - } - - else - break; - window_timer = window_timer + 1; - } - } -} - -// fxp_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 201 -void fxp_check_persistent_limit_cycle(signed long int *y, signed int y_size) -{ - signed int idy=0; - signed int count_same=0; - signed int window_size=0; - signed long int reference=y[0l]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(y[(signed long int)idy] == reference)) - window_size = window_size + 1; - - else - if(!(window_size == 0)) - break; - - else - count_same = count_same + 1; - window_size = window_size + count_same; - __DSVERIFIER_assume(window_size > 1 && window_size <= y_size / 2); - const signed long int reference$array_size0=(signed long int)window_size; - signed long int lco_elements[reference$array_size0]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(idy >= window_size)) - lco_elements[(signed long int)idy] = y[(signed long int)idy]; - - idy = 0; - signed int lco_idy=0; - _Bool is_persistent=(_Bool)0; - while(!(idy >= y_size)) - { - signed int tmp_post$1=idy; - idy = idy + 1; - signed int tmp_post$2=lco_idy; - lco_idy = lco_idy + 1; - if(y[(signed long int)tmp_post$1] == lco_elements[(signed long int)tmp_post$2]) - is_persistent = (_Bool)0; - - else - { - is_persistent = (_Bool)0; - break; - } - if(lco_idy == window_size) - lco_idy = 0; - - } - __DSVERIFIER_assert((signed int)is_persistent == 0); -} - -// fxp_determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 529 -double fxp_determinant(signed long int (*a_fxp)[20l], signed int n) -{ - signed int i; - signed int j; - signed int j1; - signed int j2; - double a[20l][20l]; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= n); j = j + 1) - a[(signed long int)i][(signed long int)j]=fxp_to_double(a_fxp[(signed long int)i][(signed long int)j]); - } - double det=0.000000; - double m[20l][20l]; - if(n >= 1) - { - if(n == 1) - det = a[0l][0l]; - - else - if(n == 2) - det = a[0l][0l] * a[1l][1l] - a[1l][0l] * a[0l][1l]; - - else - { - det = 0.000000; - j1 = 0; - for( ; !(j1 >= n); j1 = j1 + 1) - { - i = 0; - for( ; !(i >= -1 + n); i = i + 1) - { - i = 1; - for( ; !(i >= n); i = i + 1) - { - j2 = 0; - j = 0; - for( ; !(j >= n); j = j + 1) - if(!(j == j1)) - { - m[(signed long int)(i - 1)][(signed long int)j2] = a[(signed long int)i][(signed long int)j]; - j2 = j2 + 1; - } - - } - } - double return_value_internal_pow$1=internal_pow(-1.000000, 1.000000 + (double)j1 + 1.000000); - double return_value_determinant$2=determinant(m, n - 1); - det = det + return_value_internal_pow$1 * a[0l][(signed long int)j1] * return_value_determinant$2; - } - } - } - - return det; -} - -// fxp_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 22 -signed long int fxp_direct_form_1(signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$4=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$5=y_ptr; - y_ptr = y_ptr - 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_sub(sum, return_value_fxp_mult$6); - } - sum=fxp_div(sum, a[0l]); - signed long int return_value_fxp_quantize$7=fxp_quantize(sum); - return return_value_fxp_quantize$7; -} - -// fxp_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 388 -void fxp_direct_form_1_impl2(signed long int *x, signed int x_size, signed long int *b, signed int b_size, signed long int *a, signed int a_size, signed long int *y) -{ - signed int i=0; - signed int j=0; - const signed long int j$array_size0=(signed long int)x_size; - signed long int v[j$array_size0]; - i = 0; - for( ; !(i >= x_size); i = i + 1) - { - v[(signed long int)i] = 0l; - j = 0; - for( ; !(j >= b_size); j = j + 1) - { - if(!(i >= j)) - break; - - signed long int return_value_fxp_mult$1=fxp_mult(x[(signed long int)(i - j)], b[(signed long int)j]); - v[(signed long int)i]=fxp_add(v[(signed long int)i], return_value_fxp_mult$1); - } - } - y[0l] = v[0l]; - i = 1; - for( ; !(i >= x_size); i = i + 1) - { - y[(signed long int)i] = 0l; - y[(signed long int)i]=fxp_add(y[(signed long int)i], v[(signed long int)i]); - j = 1; - for( ; !(j >= a_size); j = j + 1) - { - if(!(i >= j)) - break; - - signed long int return_value_fxp_mult$2=fxp_mult(y[(signed long int)(i - j)], -a[(signed long int)j]); - y[(signed long int)i]=fxp_add(y[(signed long int)i], return_value_fxp_mult$2); - } - } -} - -// fxp_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 41 -signed long int fxp_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *b_ptr; - signed long int *w_ptr; - signed long int sum=0l; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - w[0l]=fxp_sub(w[0l], return_value_fxp_mult$3); - } - w[0l]=fxp_add(w[0l], x); - w[0l]=fxp_div(w[0l], a[0l]); - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - signed long int *tmp_post$4=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$5=w_ptr; - w_ptr = w_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_add(sum, return_value_fxp_mult$6); - } - signed long int return_value_fxp_quantize$7=fxp_quantize(sum); - return return_value_fxp_quantize$7; -} - -// fxp_div -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 357 -signed long int fxp_div(signed long int a, signed long int b) -{ - signed long int tmpdiv=(a << impl.frac_bits) / b; - return tmpdiv; -} - -// fxp_double_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 211 -signed long int fxp_double_to_fxp(double value) -{ - signed long int tmp; - double ftemp=value * scale_factor[(signed long int)impl.frac_bits]; - if(rounding_mode == 0) - { - if(value >= 0.000000) - tmp = (signed long int)(ftemp + 5.000000e-1); - - else - tmp = (signed long int)(ftemp - 5.000000e-1); - } - - else - if(rounding_mode == 1) - { - tmp = (signed long int)ftemp; - double residue=ftemp - (double)tmp; - if(value < 0.000000 && IEEE_FLOAT_NOTEQUAL(residue, 0.000000)) - { - ftemp = ftemp - 1.000000; - tmp = (signed long int)ftemp; - } - - } - - else - if(rounding_mode == 0) - tmp = (signed long int)ftemp; - - return tmp; -} - -// fxp_double_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 247 -void fxp_double_to_fxp_array(double *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - r[(signed long int)i]=fxp_double_to_fxp(f[(signed long int)i]); -} - -// fxp_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 390 -void fxp_exp_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], unsigned int expNumber, signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int l; - unsigned int k; - signed long int m2[20l][20l]; - if(expNumber == 0u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - if(i == j) - result[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(1.000000); - - else - result[(signed long int)i][(signed long int)j] = 0l; - } - } - - else - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j]; - } - if(!(expNumber == 1u)) - { - l = 1u; - for( ; !(l >= expNumber); l = l + 1u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - m2[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j]; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = 0l; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - { - k = 0u; - for( ; !(k >= columns); k = k + 1u) - { - signed long int return_value_fxp_mult$1=fxp_mult(m2[(signed long int)i][(signed long int)k], m1[(signed long int)k][(signed long int)j]); - result[(signed long int)i][(signed long int)j]=fxp_add(result[(signed long int)i][(signed long int)j], return_value_fxp_mult$1); - } - } - } - } - } - - } -} - -// fxp_float_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 198 -signed long int fxp_float_to_fxp(float f) -{ - signed long int tmp; - double ftemp=(double)f * scale_factor[(signed long int)impl.frac_bits]; - if(f >= 0.000000f) - tmp = (signed long int)(ftemp + 5.000000e-1); - - else - tmp = (signed long int)(ftemp - 5.000000e-1); - return tmp; -} - -// fxp_float_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 240 -void fxp_float_to_fxp_array(float *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - r[(signed long int)i]=fxp_float_to_fxp(f[(signed long int)i]); -} - -// fxp_get_frac_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 125 -signed long int fxp_get_frac_part(signed long int in) -{ - return in < 0l ? -(-in & _fxp_fmask) : in & _fxp_fmask; -} - -// fxp_get_int_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 115 -signed long int fxp_get_int_part(signed long int in) -{ - return in < 0l ? -(-in & _fxp_imask) : in & _fxp_imask; -} - -// fxp_int_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 170 -signed long int fxp_int_to_fxp(signed int in) -{ - signed long int lin=(signed long int)in * _fxp_one; - return lin; -} - -// fxp_ln -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 288 -signed int fxp_ln(signed int x) -{ - signed int t; - signed int y=0xA65AF; - if(!(x >= 0x8000)) - { - x = x << 16; - y = y - 0xB1721; - } - - if(!(x >= 0x800000)) - { - x = x << 8; - y = y - 0x58B91; - } - - if(!(x >= 0x8000000)) - { - x = x << 4; - y = y - 0x2C5C8; - } - - if(!(x >= 0x20000000)) - { - x = x << 2; - y = y - 0x162E4; - } - - if(!(x >= 0x40000000)) - { - x = x << 1; - y = y - 0xB172; - } - - t = x + (x >> 1); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x67CD; - } - - t = x + (x >> 2); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x3920; - } - - t = x + (x >> 3); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x1E27; - } - - t = x + (x >> 4); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0xF85; - } - - t = x + (x >> 5); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x7E1; - } - - t = x + (x >> 6); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x3F8; - } - - t = x + (x >> 7); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x1FE; - } - - x = (signed int)(0x80000000u - (unsigned int)x); - y = y - (x >> 15); - return y; -} - -// fxp_log10 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 345 -double fxp_log10(double x) -{ - if(x > 32767.000000) - { - if(x > 1.073676e+9) - { - x = x / 1.073676e+9; - double return_value_fxp_log10_low$1=fxp_log10_low(x); - return return_value_fxp_log10_low$1 + 9.030873e+0; - } - - x = x / 32767.000000; - double return_value_fxp_log10_low$2=fxp_log10_low(x); - return return_value_fxp_log10_low$2 + 4.515437e+0; - } - - else - { - double return_value_fxp_log10_low$3=fxp_log10_low(x); - return return_value_fxp_log10_low$3; - } -} - -// fxp_log10_low -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 333 -double fxp_log10_low(double x) -{ - signed int xint=(signed int)(x * 65536.000000 + 5.000000e-1); - signed int lnum=fxp_ln(xint); - signed int lden=fxp_ln(655360); - return (double)lnum / (double)lden; -} - -// fxp_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 368 -void fxp_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*m3)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - if(j1 == i2) - { - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - m3[(signed long int)i][(signed long int)j] = 0l; - } - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - { - k = 0u; - for( ; !(k >= j1); k = k + 1u) - { - signed long int return_value_fxp_mult$1=fxp_mult(m1[(signed long int)i][(signed long int)k], m2[(signed long int)k][(signed long int)j]); - m3[(signed long int)i][(signed long int)j]=fxp_add(m3[(signed long int)i][(signed long int)j], return_value_fxp_mult$1); - } - } - } - } - - else - printf("\nError! Operation invalid, please enter with valid matrices.\n"); -} - -// fxp_mult -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 339 -signed long int fxp_mult(signed long int amult, signed long int bmult) -{ - signed long int tmpmult; - signed long int tmpmultprec; - tmpmult = (signed long int)((signed long int)amult * (signed long int)bmult); - if(tmpmult >= 0l) - tmpmultprec = tmpmult + ((tmpmult & (signed long int)(1 << impl.frac_bits - 1)) << 1) >> impl.frac_bits; - - else - tmpmultprec = -(-tmpmult + ((-tmpmult & (signed long int)(1 << impl.frac_bits - 1)) << 1) >> impl.frac_bits); - return tmpmultprec; -} - -// fxp_neg -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 367 -signed long int fxp_neg(signed long int aneg) -{ - signed long int tmpneg=-((signed long int)aneg); - return tmpneg; -} - -// fxp_print_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 407 -void fxp_print_float(signed long int a) -{ - float return_value_fxp_to_float$1=fxp_to_float(a); - printf("\n%f", return_value_fxp_to_float$1); -} - -// fxp_print_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 411 -void fxp_print_float_array(signed long int *a, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - { - float return_value_fxp_to_float$1=fxp_to_float(a[(signed long int)i]); - printf("\n%f", return_value_fxp_to_float$1); - } -} - -// fxp_print_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 403 -void fxp_print_int(signed long int a) -{ - printf("\n%i", (signed int)a); -} - -// fxp_quantize -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 136 -signed long int fxp_quantize(signed long int aquant) -{ - if(overflow_mode == 2) - { - if(!(aquant >= _fxp_min)) - return _fxp_min; - - else - if(!(_fxp_max >= aquant)) - return _fxp_max; - - } - - else - if(overflow_mode == 3) - { - if(!(_fxp_max >= aquant) || !(aquant >= _fxp_min)) - { - signed long int return_value_wrap$1=wrap(aquant, _fxp_min, _fxp_max); - return return_value_wrap$1; - } - - } - - return (signed long int)aquant; -} - -// fxp_shrl -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 390 -signed long int fxp_shrl(signed long int in, signed int shift) -{ - return (signed long int)((unsigned int)in >> shift); -} - -// fxp_sign -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 380 -signed long int fxp_sign(signed long int a) -{ - return a == 0l ? 0l : (a < 0l ? _fxp_minus_one : _fxp_one); -} - -// fxp_square -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 399 -signed long int fxp_square(signed long int a) -{ - signed long int return_value_fxp_mult$1=fxp_mult(a, a); - return return_value_fxp_mult$1; -} - -// fxp_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 67 -double fxp_state_space_representation(void) -{ - signed long int result1[20l][20l]; - signed long int result2[20l][20l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0l; - result2[(signed long int)i][(signed long int)j] = 0l; - } - } - signed long int A_fpx[20l][20l]; - signed long int B_fpx[20l][20l]; - signed long int C_fpx[20l][20l]; - signed long int D_fpx[20l][20l]; - signed long int states_fpx[20l][20l]; - signed long int inputs_fpx[20l][20l]; - signed long int outputs_fpx[20l][20l]; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - D_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - states_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - inputs_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - outputs_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.B[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.C[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - D_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.D[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - states_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.states[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - inputs_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.inputs[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - outputs_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.outputs[(signed long int)i][(signed long int)j]); - } - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, C_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, D_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nOutputs, 1u, result1, result2, outputs_fpx); - i = 1; - for( ; !(i >= 0); i = i + 1) - { - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, A_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, B_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nStates, 1u, result1, result2, states_fpx); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, C_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, D_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nOutputs, 1u, result1, result2, outputs_fpx); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.states[(signed long int)i][(signed long int)j]=fxp_to_double(states_fpx[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.outputs[(signed long int)i][(signed long int)j]=fxp_to_double(outputs_fpx[(signed long int)i][(signed long int)j]); - } - return _controller.outputs[0l][0l]; -} - -// fxp_sub -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 327 -signed long int fxp_sub(signed long int asub, signed long int bsub) -{ - signed long int tmpsub=(signed long int)((signed long int)asub - (signed long int)bsub); - return tmpsub; -} - -// fxp_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 474 -void fxp_sub_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j]=fxp_sub(m1[(signed long int)i][(signed long int)j], m2[(signed long int)i][(signed long int)j]); - } -} - -// fxp_to_double -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 271 -double fxp_to_double(signed long int fxp) -{ - double f; - signed int f_int=(signed int)fxp; - f = (double)f_int * scale_factor_inv[(signed long int)impl.frac_bits]; - return f; -} - -// fxp_to_double_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 291 -void fxp_to_double_array(double *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - f[(signed long int)i]=fxp_to_double(r[(signed long int)i]); -} - -// fxp_to_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 264 -float fxp_to_float(signed long int fxp) -{ - float f; - signed int f_int=(signed int)fxp; - f = (float)((double)f_int * scale_factor_inv[(signed long int)impl.frac_bits]); - return f; -} - -// fxp_to_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 284 -void fxp_to_float_array(float *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - f[(signed long int)i]=fxp_to_float(r[(signed long int)i]); -} - -// fxp_to_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 182 -signed int fxp_to_int(signed long int fxp) -{ - if(fxp >= 0l) - fxp = fxp + _fxp_half; - - else - fxp = fxp - _fxp_half; - fxp = fxp >> impl.frac_bits; - return (signed int)fxp; -} - -// fxp_transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 582 -void fxp_transpose(signed long int (*a)[20l], signed long int (*b)[20l], signed int n, signed int m) -{ - signed int i; - signed int j; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= m); j = j + 1) - b[(signed long int)j][(signed long int)i] = a[(signed long int)i][(signed long int)j]; - } -} - -// fxp_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 61 -signed long int fxp_transposed_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *b_ptr; - signed long int yout=0l; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int return_value_fxp_mult$2=fxp_mult(*tmp_post$1, x); - yout=fxp_add(return_value_fxp_mult$2, w[0l]); - yout=fxp_div(yout, a[0l]); - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - signed long int *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - signed long int return_value_fxp_mult$4=fxp_mult(*tmp_post$3, yout); - w[(signed long int)j]=fxp_sub(w[(signed long int)j], return_value_fxp_mult$4); - } - - if(!(j >= -1 + Nb)) - { - signed long int *tmp_post$5=b_ptr; - b_ptr = b_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$5, x); - w[(signed long int)j]=fxp_add(w[(signed long int)j], return_value_fxp_mult$6); - } - - } - signed long int return_value_fxp_quantize$7=fxp_quantize(yout); - return return_value_fxp_quantize$7; -} - -// fxp_verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 153 -void fxp_verify_overflow(signed long int value) -{ - fxp_quantize(value); - __DSVERIFIER_assert(value <= _fxp_max && value >= _fxp_min); -} - -// fxp_verify_overflow_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 158 -void fxp_verify_overflow_array(signed long int *array, signed int n) -{ - signed int i=0; - i = 0; - for( ; !(i >= n); i = i + 1) - fxp_verify_overflow(array[(signed long int)i]); -} - -// generate_delta_coefficients -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 33 -void generate_delta_coefficients(double *vetor, double *out, signed int n, double delta) -{ - signed int i; - signed int j; - signed int N=n - 1; - double sum_delta_operator; - i = 0; - for( ; N >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$1=nchoosek(N - j, i - j); - sum_delta_operator = sum_delta_operator + vetor[(signed long int)j] * (double)return_value_nchoosek$1; - } - double return_value_internal_pow$2=internal_pow(delta, (double)(N - i)); - out[(signed long int)i] = return_value_internal_pow$2 * sum_delta_operator; - } -} - -// generic_timing_double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 286 -double generic_timing_double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 6 * hw.assembly.push + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 3 * hw.assembly.out + 12 * hw.assembly.std; - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - generic_timer = generic_timer + 12 * hw.assembly.std + 12 * hw.assembly.ldd + 2 * hw.assembly.subi + 2 * hw.assembly.sbci + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 1 * hw.assembly.adiw; - signed int i; - signed int j; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - generic_timer = generic_timer + 20 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.sbc + 10 * hw.assembly.std + 2 * hw.assembly.ld + 2 * hw.assembly.rcall + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.adiw + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - generic_timer = generic_timer + 2 * hw.assembly.ldi + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - generic_timer = generic_timer + 22 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.subi + 8 * hw.assembly.std + 1 * hw.assembly.sbci + 2 * hw.assembly.ld + 2 * hw.assembly.rcall + 1 * hw.assembly.sbc + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.adiw + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli + 3 * hw.assembly.out + 6 * hw.assembly.pop + 1 * hw.assembly.ret; - return sum; -} - -// generic_timing_double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 311 -double generic_timing_double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 8 * hw.assembly.push + 14 * hw.assembly.std + 3 * hw.assembly.out + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli; - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - generic_timer = generic_timer + 10 * hw.assembly.std + 6 * hw.assembly.ldd + 2 * hw.assembly.adiw; - generic_timer = generic_timer + 2 * hw.assembly.ldi + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - generic_timer = generic_timer + 23 * hw.assembly.ldd + 32 * hw.assembly.mov + 9 * hw.assembly.std + 2 * hw.assembly.subi + 3 * hw.assembly.ld + 2 * hw.assembly.rcall + 2 * hw.assembly.sbci + 1 * hw.assembly.st + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brge; - } - w[0l] = w[0l] + x; - w_ptr = &w[0l]; - generic_timer = generic_timer + 13 * hw.assembly.ldd + 12 * hw.assembly.mov + 5 * hw.assembly.std + 1 * hw.assembly.st + 1 * hw.assembly.ld + 1 * hw.assembly.rcall; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - generic_timer = generic_timer + 20 * hw.assembly.ldd + 24 * hw.assembly.mov + 10 * hw.assembly.std + 2 * hw.assembly.rcall + 2 * hw.assembly.ld + 2 * hw.assembly.subi + 2 * hw.assembly.sbci + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli + 3 * hw.assembly.out + 8 * hw.assembly.pop + 1 * hw.assembly.ret; - return sum; -} - -// generic_timing_double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 338 -double generic_timing_double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 8 * hw.assembly.push + 14 * hw.assembly.std + 3 * hw.assembly.out + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - generic_timer = generic_timer + 15 * hw.assembly.std + 22 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.rcall + 2 * hw.assembly.ld + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.brge + 1 * hw.assembly.adiw; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - generic_timer = generic_timer + 70 * hw.assembly.mov + 65 * hw.assembly.ldd + 12 * hw.assembly.lsl + 12 * hw.assembly.rol + 15 * hw.assembly.std + 6 * hw.assembly.add + 6 * hw.assembly.adc + 2 * hw.assembly.adiw + 3 * hw.assembly.cpc + 3 * hw.assembly.cp + 5 * hw.assembly.ld + 4 * hw.assembly.rcall + 5 * hw.assembly.subi + 3 * hw.assembly.rjmp + 2 * hw.assembly.brlt + 3 * hw.assembly.st + 2 * hw.assembly.sbci + 3 * hw.assembly.sbc + 1 * hw.assembly.brge; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 8 * hw.assembly.pop + 3 * hw.assembly.out + 1 * hw.assembly.in + 1 * hw.assembly.cli + 1 * hw.assembly.adiw + 1 * hw.assembly.ret; - return yout; -} - -// generic_timing_shift_l_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 20 -double generic_timing_shift_l_double(double zIn, double *z, signed int N) -{ - generic_timer = generic_timer + 2 * hw.assembly.push + 3 * hw.assembly.in + 3 * hw.assembly.out + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 8 * hw.assembly.std; - signed int i; - double zOut=z[0l]; - generic_timer = generic_timer + 5 * hw.assembly.ldd + 2 * hw.assembly.mov + 4 * hw.assembly.std + 1 * hw.assembly.ld; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - { - generic_timer = generic_timer + 17 * hw.assembly.ldd + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 6 * hw.assembly.mov + 2 * hw.assembly.adiw + 5 * hw.assembly.std + 1 * hw.assembly.ld + 1 * hw.assembly.st + 1 * hw.assembly.subi + 1 * hw.assembly.sbc + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - z[(signed long int)i] = z[(signed long int)(i + 1)]; - } - z[(signed long int)(N - 1)] = zIn; - generic_timer = generic_timer + 12 * hw.assembly.ldd + 6 * hw.assembly.mov + 3 * hw.assembly.std + 2 * hw.assembly.lsl + 2 * hw.assembly.rol + 1 * hw.assembly.adc + 1 * hw.assembly.add + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.st + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli; - generic_timer = generic_timer + 3 * hw.assembly.out + 2 * hw.assembly.pop + 1 * hw.assembly.ret; - return zOut; -} - -// generic_timing_shift_r_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 37 -double generic_timing_shift_r_double(double zIn, double *z, signed int N) -{ - generic_timer = generic_timer + 2 * hw.assembly.push + 3 * hw.assembly.in + 3 * hw.assembly.out + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 8 * hw.assembly.std; - signed int i; - double zOut=z[(signed long int)(N - 1)]; - generic_timer = generic_timer + 7 * hw.assembly.ldd + 2 * hw.assembly.rol + 2 * hw.assembly.lsl + 2 * hw.assembly.mov + 4 * hw.assembly.std + 1 * hw.assembly.add + 1 * hw.assembly.adc + 1 * hw.assembly.ld + 1 * hw.assembly.subi + 1 * hw.assembly.sbci; - generic_timer = generic_timer + 2 * hw.assembly.ldd + 2 * hw.assembly.std + 1 * hw.assembly.sbiw + 1 * hw.assembly.rjmp; - i = N - 1; - for( ; i >= 1; i = i - 1) - { - z[(signed long int)i] = z[(signed long int)(i - 1)]; - generic_timer = generic_timer + 15 * hw.assembly.ldd + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 4 * hw.assembly.mov + 5 * hw.assembly.std + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.ld + 1 * hw.assembly.st + 1 * hw.assembly.sbiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - } - z[0l] = zIn; - generic_timer = generic_timer + 10 * hw.assembly.ldd + 5 * hw.assembly.mov + 3 * hw.assembly.std + 3 * hw.assembly.out + 2 * hw.assembly.pop + 1 * hw.assembly.ret + 1 * hw.assembly.ret + 1 * hw.assembly.cli + 1 * hw.assembly.in + 1 * hw.assembly.st + 1 * hw.assembly.adiw; - return zOut; -} - -// get_delta_transfer_function -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 52 -void get_delta_transfer_function(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta) -{ - generate_delta_coefficients(b, b_out, b_size, delta); - generate_delta_coefficients(a, a_out, a_size, delta); -} - -// get_delta_transfer_function_with_base -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 59 -void get_delta_transfer_function_with_base(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta) -{ - signed int i; - signed int j; - signed int N=a_size - 1; - signed int M=b_size - 1; - double sum_delta_operator; - i = 0; - for( ; N >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$1=nchoosek(N - j, i - j); - sum_delta_operator = sum_delta_operator + a[(signed long int)j] * (double)return_value_nchoosek$1; - } - double return_value_internal_pow$2=internal_pow(delta, (double)(N - i)); - a_out[(signed long int)i] = return_value_internal_pow$2 * sum_delta_operator; - } - i = 0; - for( ; M >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$3=nchoosek(M - j, i - j); - sum_delta_operator = sum_delta_operator + b[(signed long int)j] * (double)return_value_nchoosek$3; - } - double return_value_internal_pow$4=internal_pow(delta, (double)(M - i)); - b_out[(signed long int)i] = return_value_internal_pow$4 * sum_delta_operator; - } -} - -// iirIIOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 428 -float iirIIOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - float *a_ptr; - float *b_ptr; - float *w_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - timer1 = timer1 + 71; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 54; - } - w[0l] = w[0l] + x; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 46; - } - timer1 = timer1 + 38; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return sum; -} - -// iirIItOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 452 -float iirIItOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - float *a_ptr; - float *b_ptr; - float yout=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - float *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return yout; -} - -// iirIItOutTime_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 479 -double iirIItOutTime_double(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return yout; -} - -// iirOutBoth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 506 -void iirOutBoth(float *yf, float *xf, float *af, float *bf, float *sumf_ref, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int *sum_ref, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - signed long int sum=0l; - float sumf=0.000000f; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - af_ptr = &af[1l]; - yf_ptr = &yf[(signed long int)(Na - 1)]; - bf_ptr = &bf[0l]; - xf_ptr = &xf[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - float *tmp_post$4=bf_ptr; - bf_ptr = bf_ptr + 1l; - float *tmp_post$5=xf_ptr; - xf_ptr = xf_ptr - 1l; - sumf = sumf + *tmp_post$4 * *tmp_post$5; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$6=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$7=y_ptr; - y_ptr = y_ptr - 1l; - signed long int return_value_fxp_mult$8=fxp_mult(*tmp_post$6, *tmp_post$7); - sum=fxp_sub(sum, return_value_fxp_mult$8); - float *tmp_post$9=af_ptr; - af_ptr = af_ptr + 1l; - float *tmp_post$10=yf_ptr; - yf_ptr = yf_ptr - 1l; - sumf = sumf - *tmp_post$9 * *tmp_post$10; - } - *sum_ref = sum; - *sumf_ref = sumf; -} - -// iirOutBothL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 586 -float iirOutBothL(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - float sumf=0.000000f; - af_ptr = &af[(signed long int)(Na - 1)]; - yf_ptr = &yf[1l]; - bf_ptr = &bf[(signed long int)(Nb - 1)]; - xf_ptr = &xf[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - xf[(signed long int)i] = xf[(signed long int)(i + 1)]; - float *tmp_post$4=bf_ptr; - bf_ptr = bf_ptr - 1l; - float *tmp_post$5=xf_ptr; - xf_ptr = xf_ptr + 1l; - sumf = sumf + *tmp_post$4 * *tmp_post$5; - } - x[(signed long int)(Nb - 1)] = xin; - signed long int *tmp_post$6=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$7=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$8=fxp_mult(*tmp_post$6, *tmp_post$7); - sum=fxp_add(sum, return_value_fxp_mult$8); - xf[(signed long int)(Nb - 1)] = xfin; - float *tmp_post$9=bf_ptr; - bf_ptr = bf_ptr - 1l; - float *tmp_post$10=xf_ptr; - xf_ptr = xf_ptr + 1l; - sumf = sumf + *tmp_post$9 * *tmp_post$10; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int *tmp_post$11=a_ptr; - a_ptr = a_ptr - 1l; - signed long int *tmp_post$12=y_ptr; - y_ptr = y_ptr + 1l; - signed long int return_value_fxp_mult$13=fxp_mult(*tmp_post$11, *tmp_post$12); - sum=fxp_sub(sum, return_value_fxp_mult$13); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - float *tmp_post$14=af_ptr; - af_ptr = af_ptr - 1l; - float *tmp_post$15=yf_ptr; - yf_ptr = yf_ptr + 1l; - sumf = sumf - *tmp_post$14 * *tmp_post$15; - yf[(signed long int)j] = yf[(signed long int)(j + 1)]; - } - signed long int *tmp_post$16; - signed long int *tmp_post$17; - signed long int return_value_fxp_mult$18; - if(Na >= 2) - { - tmp_post$16 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$17 = y_ptr; - y_ptr = y_ptr + 1l; - return_value_fxp_mult$18=fxp_mult(*tmp_post$16, *tmp_post$17); - sum=fxp_sub(sum, return_value_fxp_mult$18); - } - - y[(signed long int)(Na - 1)] = sum; - float *tmp_post$19; - float *tmp_post$20; - if(Na >= 2) - { - tmp_post$19 = af_ptr; - af_ptr = af_ptr - 1l; - tmp_post$20 = yf_ptr; - yf_ptr = yf_ptr + 1l; - sumf = sumf - *tmp_post$19 * *tmp_post$20; - } - - yf[(signed long int)(Na - 1)] = sumf; - float return_value_fxp_to_float$21=fxp_to_float(sum); - return return_value_fxp_to_float$21 - sumf; -} - -// iirOutBothL2 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 626 -float iirOutBothL2(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - float sumf=0.000000f; - af_ptr = &af[(signed long int)(Na - 1)]; - yf_ptr = &yf[1l]; - bf_ptr = &bf[(signed long int)(Nb - 1)]; - xf_ptr = &xf[0l]; - signed int i=0; - signed int j=1; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int return_value_fxp_mult$1=fxp_mult(b[(signed long int)((Nb - 1) - i)], x[(signed long int)i]); - sum=fxp_add(sum, return_value_fxp_mult$1); - xf[(signed long int)i] = xf[(signed long int)(i + 1)]; - sumf = sumf + bf[(signed long int)((Nb - 1) - i)] * xf[(signed long int)i]; - } - x[(signed long int)(Nb - 1)] = xin; - signed long int return_value_fxp_mult$2=fxp_mult(b[(signed long int)((Nb - 1) - i)], x[(signed long int)i]); - sum=fxp_add(sum, return_value_fxp_mult$2); - xf[(signed long int)(Nb - 1)] = xfin; - sumf = sumf + bf[(signed long int)((Nb - 1) - i)] * xf[(signed long int)i]; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int return_value_fxp_mult$3=fxp_mult(a[(signed long int)(Na - j)], y[(signed long int)j]); - sum=fxp_sub(sum, return_value_fxp_mult$3); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - sumf = sumf - af[(signed long int)(Na - j)] * yf[(signed long int)j]; - yf[(signed long int)j] = yf[(signed long int)(j + 1)]; - } - signed long int return_value_fxp_mult$4; - if(Na >= 2) - { - return_value_fxp_mult$4=fxp_mult(a[(signed long int)(Na - j)], y[(signed long int)j]); - sum=fxp_sub(sum, return_value_fxp_mult$4); - } - - y[(signed long int)(Na - 1)] = sum; - if(Na >= 2) - sumf = sumf - af[(signed long int)(Na - j)] * yf[(signed long int)j]; - - yf[(signed long int)(Na - 1)] = sumf; - float return_value_fxp_to_float$5=fxp_to_float(sum); - return return_value_fxp_to_float$5 - sumf; -} - -// iirOutFixedL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 536 -signed long int iirOutFixedL(signed long int *y, signed long int *x, signed long int xin, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - } - x[(signed long int)(Nb - 1)] = xin; - signed long int *tmp_post$4=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$5=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_add(sum, return_value_fxp_mult$6); - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int *tmp_post$7=a_ptr; - a_ptr = a_ptr - 1l; - signed long int *tmp_post$8=y_ptr; - y_ptr = y_ptr + 1l; - signed long int return_value_fxp_mult$9=fxp_mult(*tmp_post$7, *tmp_post$8); - sum=fxp_sub(sum, return_value_fxp_mult$9); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - } - signed long int *tmp_post$10; - signed long int *tmp_post$11; - signed long int return_value_fxp_mult$12; - if(Na >= 2) - { - tmp_post$10 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$11 = y_ptr; - y_ptr = y_ptr + 1l; - return_value_fxp_mult$12=fxp_mult(*tmp_post$10, *tmp_post$11); - sum=fxp_sub(sum, return_value_fxp_mult$12); - } - - y[(signed long int)(Na - 1)] = sum; - return sum; -} - -// iirOutFloatL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 561 -float iirOutFloatL(float *y, float *x, float xin, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *y_ptr; - float *b_ptr; - float *x_ptr; - float sum=0.000000f; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - float *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - x[(signed long int)(Nb - 1)] = xin; - float *tmp_post$3=b_ptr; - b_ptr = b_ptr - 1l; - float *tmp_post$4=x_ptr; - x_ptr = x_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - float *tmp_post$5=a_ptr; - a_ptr = a_ptr - 1l; - float *tmp_post$6=y_ptr; - y_ptr = y_ptr + 1l; - sum = sum - *tmp_post$5 * *tmp_post$6; - y[(signed long int)j] = y[(signed long int)(j + 1)]; - } - float *tmp_post$7; - float *tmp_post$8; - if(Na >= 2) - { - tmp_post$7 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$8 = y_ptr; - y_ptr = y_ptr + 1l; - sum = sum - *tmp_post$7 * *tmp_post$8; - } - - y[(signed long int)(Na - 1)] = sum; - return sum; -} - -// initialization -// file /home/lucascordeiro/dsverifier/bmc/core/initialization.h line 24 -void initialization() -{ - if(impl.frac_bits >= 32) - printf("impl.frac_bits must be less than word width!\n"); - - if(impl.int_bits >= 32 + -impl.frac_bits) - { - printf("impl.int_bits must be less than word width subtracted by precision!\n"); - /* assertion 0 */ - assert(0 != 0); - } - - if(impl.frac_bits >= 31) - _fxp_one = 2147483647l; - - else - _fxp_one = (signed long int)(0x1 << impl.frac_bits); - _fxp_half = (signed long int)(0x1 << impl.frac_bits - 1); - _fxp_minus_one = (signed long int)-(0x1 << impl.frac_bits); - _fxp_min = (signed long int)-(0x1 << (impl.frac_bits + impl.int_bits) - 1); - _fxp_max = (signed long int)((0x1 << (impl.frac_bits + impl.int_bits) - 1) - 1); - _fxp_fmask = (signed long int)((1 << impl.frac_bits) - 1); - _fxp_imask = (signed long int)(0x80000000u >> (32 - impl.frac_bits) - 1); - _dbl_min = (double)_fxp_min; - _dbl_min = _dbl_min / (double)(1 << impl.frac_bits); - _dbl_max = (double)_fxp_max; - _dbl_max = _dbl_max / (double)(1 << impl.frac_bits); - if(impl.scale == 0 || impl.scale == 1) - impl.scale = 1; - - else - { - if(IEEE_FLOAT_NOTEQUAL(impl.min, 0.000000)) - impl.min = impl.min / (double)impl.scale; - - if(IEEE_FLOAT_NOTEQUAL(impl.max, 0.000000)) - impl.max = impl.max / (double)impl.scale; - - } -} - -// initialize_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 22 -void initialize_array(double *v, signed int n) -{ - signed int i=0; - for( ; !(i >= n); i = i + 1) - v[(signed long int)i] = 0.000000; -} - -// internal_abs -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 49 -double internal_abs(double a) -{ - return a < 0.000000 ? -a : a; -} - -// internal_pow -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 39 -double internal_pow(double a, double b) -{ - signed int i; - double acc=1.000000; - i = 0; - for( ; (double)i < b; i = i + 1) - acc = acc * a; - return acc; -} - -// main -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 60 -signed int main() -{ - initialization(); - validation(); - rounding_mode = 1; - call_closedloop_verification_task((void *)verify_stability_closedloop_using_dslib); - return 0; -} - -// nchoosek -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 23 -signed int nchoosek(signed int n, signed int k) -{ - if(k == 0) - return 1; - - else - { - signed int return_value_nchoosek$1=nchoosek(n - 1, k - 1); - return (n * return_value_nchoosek$1) / k; - } -} - -// order -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 158 -signed int order(signed int Na, signed int Nb) -{ - return Na > Nb ? Na - 1 : Nb - 1; -} - -// poly_mult -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 165 -void poly_mult(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans) -{ - signed int i; - signed int j; - signed int k; - Nans = (Na + Nb) - 1; - i = 0; - for( ; !(i >= Na); i = i + 1) - { - j = 0; - for( ; !(j >= Nb); j = j + 1) - { - k = (((Na + Nb) - i) - j) - 2; - ans[(signed long int)k] = 0.000000; - } - } - i = 0; - for( ; !(i >= Na); i = i + 1) - { - j = 0; - for( ; !(j >= Nb); j = j + 1) - { - k = (((Na + Nb) - i) - j) - 2; - ans[(signed long int)k] = ans[(signed long int)k] + a[(signed long int)((Na - i) - 1)] * b[(signed long int)((Nb - j) - 1)]; - } - } -} - -// poly_sum -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 141 -void poly_sum(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans) -{ - signed int i; - Nans = Na > Nb ? Na : Nb; - i = 0; - for( ; !(i >= Nans); i = i + 1) - if(!(Nb >= Na)) - { - ans[(signed long int)i] = a[(signed long int)i]; - if(!(-1 + Na + -Nb >= i)) - ans[(signed long int)i] = ans[(signed long int)i] + b[(signed long int)((i - Na) + Nb)]; - - } - - else - { - ans[(signed long int)i] = b[(signed long int)i]; - if(!(-1 + Nb + -Na >= i)) - ans[(signed long int)i] = ans[(signed long int)i] + a[(signed long int)((i - Nb) + Na)]; - - } -} - -// print_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 305 -void print_array_elements(char *name, double *v, signed int n) -{ - printf("%s = {", name); - signed int i=0; - for( ; !(i >= n); i = i + 1) - printf(" %.32f ", v[(signed long int)i]); - printf("}\n"); -} - -// print_fxp_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 419 -void print_fxp_array_elements(char *name, signed long int *v, signed int n) -{ - printf("%s = {", name); - signed int i=0; - for( ; !(i >= n); i = i + 1) - printf(" %jd ", v[(signed long int)i]); - printf("}\n"); -} - -// print_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 481 -void print_matrix(double (*matrix)[20l], unsigned int lines, unsigned int columns) -{ - printf("\nMatrix\n=====================\n\n"); - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - printf("#matrix[%d][%d]: %2.2f ", i, j, matrix[(signed long int)i][(signed long int)j]); - printf("\n"); - } - printf("\n"); -} - -// rand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 417 -extern signed int rand(void) -{ - next = next * 1103515245ul + 12345ul; - return (signed int)((unsigned int)(next / 65536ul) % 32768u); -} - -// revert_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 30 -void revert_array(double *v, double *out, signed int n) -{ - initialize_array(out, n); - signed int i=0; - for( ; !(i >= n); i = i + 1) - out[(signed long int)i] = v[(signed long int)((n - i) - 1)]; -} - -// shiftL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 53 -signed long int shiftL(signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftLDouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 119 -double shiftLDouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftLboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 130 -void shiftLboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut; - float zfOut; - zOut = z[0l]; - zfOut = zf[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - { - z[(signed long int)i] = z[(signed long int)(i + 1)]; - zf[(signed long int)i] = zf[(signed long int)(i + 1)]; - } - z[(signed long int)(N - 1)] = zIn; - zf[(signed long int)(N - 1)] = zfIn; -} - -// shiftLfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 75 -float shiftLfloat(float zIn, float *z, signed int N) -{ - signed int i; - float zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftR -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 64 -signed long int shiftR(signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// shiftRDdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 97 -double shiftRDdouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftRboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 144 -void shiftRboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut; - float zfOut; - zOut = z[(signed long int)(N - 1)]; - zfOut = zf[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - { - z[(signed long int)i] = z[(signed long int)(i - 1)]; - zf[(signed long int)i] = zf[(signed long int)(i - 1)]; - } - z[0l] = zIn; - zf[0l] = zfIn; -} - -// shiftRdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 108 -double shiftRdouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// shiftRfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 86 -float shiftRfloat(float zIn, float *z, signed int N) -{ - signed int i; - float zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// snrPoint -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 402 -float snrPoint(float *s, float *n, signed int blksz) -{ - signed int i; - double ratio=0.000000; - double power=0.000000; - i = 0; - for( ; !(i >= blksz); i = i + 1) - if(!IEEE_FLOAT_EQUAL(n[(signed long int)i], 0.000000f)) - { - ratio = (double)(s[(signed long int)i] / n[(signed long int)i]); - if(!(ratio < -150.000000) && !(ratio > 150.000000)) - { - power = ratio * ratio; - /* assertion power >= 1.0f */ - assert(power >= 1.000000); - if(power >= 1.000000) - (void)0; - - } - - } - - return 9.999900e+3f; -} - -// snrPower -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 381 -float snrPower(float *s, float *n, signed int blksz) -{ - signed int i; - double sv=0.000000; - double nv=0.000000; - double snr; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sv = sv + (double)(s[(signed long int)i] * s[(signed long int)i]); - nv = nv + (double)(n[(signed long int)i] * n[(signed long int)i]); - } - if(IEEE_FLOAT_NOTEQUAL(nv, 0.000000)) - { - /* assertion sv >= nv */ - assert(sv >= nv); - if(sv >= nv) - (void)0; - - snr = sv / nv; - return (float)snr; - } - - else - return 9.999900e+3f; -} - -// snrVariance -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 357 -float snrVariance(float *s, float *n, signed int blksz) -{ - signed int i; - double sm=0.000000; - double nm=0.000000; - double sv=0.000000; - double nv=0.000000; - double snr; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sm = sm + (double)s[(signed long int)i]; - nm = nm + (double)n[(signed long int)i]; - } - sm = sm / (double)blksz; - nm = nm / (double)blksz; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sv = sv + ((double)s[(signed long int)i] - sm) * ((double)s[(signed long int)i] - sm); - nv = nv + ((double)n[(signed long int)i] - nm) * ((double)n[(signed long int)i] - nm); - } - if(IEEE_FLOAT_NOTEQUAL(nv, 0.000000)) - { - /* assertion sv >= nv */ - assert(sv >= nv); - if(sv >= nv) - (void)0; - - snr = sv / nv; - return (float)snr; - } - - else - return 9.999900e+3f; -} - -// srand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 423 -extern void srand(unsigned int seed) -{ - next = (unsigned long int)seed; -} - -// transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 571 -void transpose(double (*a)[20l], double (*b)[20l], signed int n, signed int m) -{ - signed int i; - signed int j; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= m); j = j + 1) - b[(signed long int)j][(signed long int)i] = a[(signed long int)i][(signed long int)j]; - } -} - -// validation -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 125 -void validation() -{ - if(controller.a_size == 0 || plant.b_size == 0 || impl.int_bits == 0) - { - printf("\n\n*****************************************************************************************************\n"); - printf("* set (controller, plant, and impl) parameters to check CLOSED LOOP with DSVerifier *\n"); - printf("*****************************************************************************************************\n"); - __DSVERIFIER_assert((_Bool)0); - } - - else - { - printf("\n\n*****************************************************************************************************\n"); - printf("* set (controller and impl) parameters so that they do not overflow *\n"); - printf("*****************************************************************************************************\n"); - unsigned int j=0u; - for( ; !(j >= (unsigned int)controller.a_size); j = j + 1u) - { - const double validation$$1$$6$$2$$1$$1$$value=controller.a[(signed long int)j]; - __DSVERIFIER_assert(validation$$1$$6$$2$$1$$1$$value <= _dbl_max); - __DSVERIFIER_assert(validation$$1$$6$$2$$1$$1$$value >= _dbl_min); - } - j = 0u; - for( ; !(j >= (unsigned int)controller.b_size); j = j + 1u) - { - const double value=controller.b[(signed long int)j]; - __DSVERIFIER_assert(value <= _dbl_max); - __DSVERIFIER_assert(value >= _dbl_min); - } - } -} - -// verify_controllability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 16 -signed int verify_controllability(void) -{ - signed int i; - signed int j; - signed long int A_fpx[20l][20l]; - signed long int B_fpx[20l][20l]; - signed long int controllabilityMatrix[20l][20l]; - signed long int backup[20l][20l]; - signed long int backupSecond[20l][20l]; - double controllabilityMatrix_double[20l][20l]; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - { - A_fpx[(signed long int)i][(signed long int)j] = 0l; - B_fpx[(signed long int)i][(signed long int)j] = 0l; - controllabilityMatrix[(signed long int)i][(signed long int)j] = 0l; - backup[(signed long int)i][(signed long int)j] = 0l; - backupSecond[(signed long int)i][(signed long int)j] = 0l; - controllabilityMatrix_double[(signed long int)i][(signed long int)j] = 0.000000; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.B[(signed long int)i][(signed long int)j]); - } - if(nInputs >= 2) - { - signed int l=0; - j = 0; - while(!(j >= nInputs * nStates)) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)l, backup); - l = l + 1; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, B_fpx, backupSecond); - signed int k=0; - for( ; !(k >= nInputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][(signed long int)k]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0l; - } - fxp_transpose(controllabilityMatrix, backup, nStates, nStates * nInputs); - signed long int mimo_controllabilityMatrix_fxp[20l][20l]; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nInputs), (unsigned int)(nStates * nInputs), (unsigned int)nStates, controllabilityMatrix, backup, mimo_controllabilityMatrix_fxp); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - controllabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(mimo_controllabilityMatrix_fxp[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$1=determinant(controllabilityMatrix_double, nStates); - /* assertion determinant(controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)j, backup); - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, B_fpx, backupSecond); - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][0l]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - controllabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(controllabilityMatrix[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$2=determinant(controllabilityMatrix_double, nStates); - /* assertion determinant(controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_controllability_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 120 -signed int verify_controllability_double(void) -{ - signed int i; - signed int j; - double controllabilityMatrix[20l][20l]; - double backup[20l][20l]; - double backupSecond[20l][20l]; - double controllabilityMatrix_double[20l][20l]; - if(nInputs >= 2) - { - signed int l=0; - j = 0; - while(!(j >= nInputs * nStates)) - { - double_exp_matrix((unsigned int)nStates, (unsigned int)nStates, _controller.A, (unsigned int)l, backup); - l = l + 1; - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, _controller.B, backupSecond); - signed int k=0; - for( ; !(k >= nInputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][(signed long int)k]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0.000000; - } - transpose(controllabilityMatrix, backup, nStates, nStates * nInputs); - double mimo_controllabilityMatrix_double[20l][20l]; - double_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nInputs), (unsigned int)(nStates * nInputs), (unsigned int)nStates, controllabilityMatrix, backup, mimo_controllabilityMatrix_double); - double return_value_determinant$1=determinant(mimo_controllabilityMatrix_double, nStates); - /* assertion determinant(mimo_controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - double_exp_matrix((unsigned int)nStates, (unsigned int)nStates, _controller.A, (unsigned int)j, backup); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, _controller.B, backupSecond); - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][0l]; - } - double return_value_determinant$2=determinant(controllabilityMatrix, nStates); - /* assertion determinant(controllabilityMatrix,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_error -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error.h line 20 -signed int verify_error(void) -{ - overflow_mode = 2; - double a_cascade[100l]; - signed int a_cascade_size; - double b_cascade[100l]; - signed int b_cascade_size; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - const signed long int x$array_size0=(signed long int)X_SIZE_VALUE; - double yf[x$array_size0]; - const signed long int yf$array_size0=(signed long int)X_SIZE_VALUE; - double xf[yf$array_size0]; - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - const signed long int waux$array_size0=(signed long int)ds.a_size; - double yfaux[waux$array_size0]; - const signed long int yfaux$array_size0=(signed long int)ds.b_size; - double xfaux[yfaux$array_size0]; - const signed long int xfaux$array_size0=(signed long int)Nw; - double wfaux[xfaux$array_size0]; - signed int i=0; - for( ; !(i >= ds.a_size); i = i + 1) - { - yaux[(signed long int)i] = 0l; - yfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - { - xaux[(signed long int)i] = 0l; - xfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - waux[(signed long int)i] = 0l; - wfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - signed int return_value_nondet_int$1=nondet_int(); - x[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = x[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - yf[(signed long int)i] = 0.000000; - xf[(signed long int)i]=fxp_to_double(x[(signed long int)i]); - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - double absolute_error; - double return_value_fxp_to_double$3=fxp_to_double(y[(signed long int)i]); - absolute_error = yf[(signed long int)i] - return_value_fxp_to_double$3; - __DSVERIFIER_assert(absolute_error < impl.max_error && absolute_error > -impl.max_error); - } - return 0; -} - -// verify_error_closedloop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_closedloop.h line 27 -signed int verify_error_closedloop(void) -{ - overflow_mode = 3; - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num_double[100l]; - double ans_num_qtz[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den_qtz[100l]; - double ans_den_double[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num_qtz, ans_num_size, ans_den_qtz, ans_den_size); - ft_closedloop_series(c_num, c_num_size, c_den, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num_double, ans_num_size, ans_den_double, ans_den_size); - signed int i; - const signed long int i$array_size0=(signed long int)X_SIZE_VALUE; - double y_qtz[i$array_size0]; - const signed long int y_qtz$array_size0=(signed long int)X_SIZE_VALUE; - double y_double[y_qtz$array_size0]; - const signed long int y_double$array_size0=(signed long int)X_SIZE_VALUE; - double x_qtz[y_double$array_size0]; - const signed long int x_qtz$array_size0=(signed long int)X_SIZE_VALUE; - double x_double[x_qtz$array_size0]; - const signed long int x_double$array_size0=(signed long int)ans_num_size; - double xaux_qtz[x_double$array_size0]; - const signed long int xaux_qtz$array_size0=(signed long int)ans_num_size; - double xaux_double[xaux_qtz$array_size0]; - const signed long int xaux_double$array_size0=(signed long int)ans_num_size; - double xaux[xaux_double$array_size0]; - double nondet_constant_input=nondet_double(); - __DSVERIFIER_assume(nondet_constant_input >= impl.min && nondet_constant_input <= impl.max); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x_qtz[(signed long int)i] = nondet_constant_input; - x_double[(signed long int)i] = nondet_constant_input; - y_qtz[(signed long int)i] = 0.000000; - y_double[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ans_num_size); i = i + 1) - { - xaux_qtz[(signed long int)i] = nondet_constant_input; - xaux_double[(signed long int)i] = nondet_constant_input; - } - const signed long int nondet_constant_input$array_size0=(signed long int)ans_den_size; - double yaux_qtz[nondet_constant_input$array_size0]; - const signed long int yaux_qtz$array_size0=(signed long int)ans_den_size; - double yaux_double[yaux_qtz$array_size0]; - const signed long int yaux_double$array_size0=(signed long int)ans_den_size; - double y0_qtz[yaux_double$array_size0]; - const signed long int y0_qtz$array_size0=(signed long int)ans_den_size; - double y0_double[y0_qtz$array_size0]; - signed int Nw=ans_den_size > ans_num_size ? ans_den_size : ans_num_size; - const signed long int Nw$array_size0=(signed long int)Nw; - double waux_qtz[Nw$array_size0]; - const signed long int waux_qtz$array_size0=(signed long int)Nw; - double waux_double[waux_qtz$array_size0]; - const signed long int waux_double$array_size0=(signed long int)Nw; - double w0_qtz[waux_double$array_size0]; - const signed long int w0_qtz$array_size0=(signed long int)Nw; - double w0_double[w0_qtz$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - waux_qtz[(signed long int)i] = 0.000000; - waux_double[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - double absolute_error; - double return_value_fxp_to_double$1=fxp_to_double((signed long int)y_qtz[(signed long int)i]); - absolute_error = y_double[(signed long int)i] - return_value_fxp_to_double$1; - __DSVERIFIER_assert(absolute_error < impl.max_error && absolute_error > -impl.max_error); - } - return 0; -} - -// verify_error_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 20 -signed int verify_error_state_space(void) -{ - overflow_mode = 0; - struct anonymous$1 __backupController; - signed int i; - signed int j; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - __backupController.A[(signed long int)i][(signed long int)j] = _controller.A[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - __backupController.B[(signed long int)i][(signed long int)j] = _controller.B[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - __backupController.C[(signed long int)i][(signed long int)j] = _controller.C[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - __backupController.D[(signed long int)i][(signed long int)j] = _controller.D[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.states[(signed long int)i][(signed long int)j] = _controller.states[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.inputs[(signed long int)i][(signed long int)j] = _controller.inputs[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.outputs[(signed long int)i][(signed long int)j] = _controller.outputs[(signed long int)i][(signed long int)j]; - } - double __quant_error=0.000000; - double output_double=double_state_space_representation(); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - _controller.A[(signed long int)i][(signed long int)j] = __backupController.A[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - _controller.B[(signed long int)i][(signed long int)j] = __backupController.B[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - _controller.C[(signed long int)i][(signed long int)j] = __backupController.C[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - _controller.D[(signed long int)i][(signed long int)j] = __backupController.D[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.states[(signed long int)i][(signed long int)j] = __backupController.states[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.inputs[(signed long int)i][(signed long int)j] = __backupController.inputs[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.outputs[(signed long int)i][(signed long int)j] = __backupController.outputs[(signed long int)i][(signed long int)j]; - } - double output_fxp=fxp_state_space_representation(); - fxp_verify_overflow((signed long int)output_fxp); - __quant_error = ((output_fxp - output_double) / output_double) * 100.000000; - /* assertion __quant_error < error_limit && __quant_error > (-error_limit) */ - assert(__quant_error < error_limit && __quant_error > -error_limit); - if(__quant_error < error_limit && __quant_error > -error_limit) - (void)0; - - return 0; -} - -// verify_generic_timing -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 25 -signed int verify_generic_timing(void) -{ - const signed long int verify_generic_timing$array_size0=(signed long int)X_SIZE_VALUE; - double y[verify_generic_timing$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0.000000; - float return_value_nondet_float$1=nondet_float(); - x[(signed long int)i] = (double)return_value_nondet_float$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= impl.min) - tmp_if_expr$2 = x[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - double yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - double xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - double waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0.000000; - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - double initial_timer=(double)generic_timer; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - generic_timer = generic_timer + 2 * hw.assembly.ldd + 1 * hw.assembly.adiw + 2 * hw.assembly.std; - generic_timer = generic_timer + 2 * hw.assembly.ldd + 1 * hw.assembly.cpi + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - double spent_time=(double)generic_timer * hw.cycle; - /* assertion spent_time <= ds.sample_time */ - assert(spent_time <= ds.sample_time); - if(spent_time <= ds.sample_time) - (void)0; - - generic_timer = (signed int)initial_timer; - } - return 0; -} - -// verify_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 111 -signed int verify_limit_cycle(void) -{ - overflow_mode = 3; - signed int i; - signed int Set_xsize_at_least_two_times_Na=2 * ds.a_size; - printf("X_SIZE must be at least 2 * ds.a_size"); - __DSVERIFIER_assert(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na); - const signed long int Set_xsize_at_least_two_times_Na$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[Set_xsize_at_least_two_times_Na$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)ds.b_size; - signed long int xaux[max_fxp$array_size0]; - signed int nondet_constant_input=nondet_int(); - __DSVERIFIER_assume((signed long int)nondet_constant_input >= min_fxp && (signed long int)nondet_constant_input <= max_fxp); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x[(signed long int)i] = (signed long int)nondet_constant_input; - y[(signed long int)i] = 0l; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = (signed long int)nondet_constant_input; - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.a_size; - signed long int y0[yaux$array_size0]; - const signed long int y0$array_size0=(signed long int)Nw; - signed long int waux[y0$array_size0]; - const signed long int waux$array_size0=(signed long int)Nw; - signed long int w0[waux$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = waux[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// verify_limit_cycle_closed_loop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 29 -signed int verify_limit_cycle_closed_loop(void) -{ - overflow_mode = 3; - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num, ans_num_size, ans_den, ans_den_size); - signed int i; - const signed long int i$array_size0=(signed long int)X_SIZE_VALUE; - double y[i$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - const signed long int x$array_size0=(signed long int)ans_num_size; - double xaux[x$array_size0]; - double nondet_constant_input=nondet_double(); - __DSVERIFIER_assume(nondet_constant_input >= impl.min && nondet_constant_input <= impl.max); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x[(signed long int)i] = nondet_constant_input; - y[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ans_num_size); i = i + 1) - xaux[(signed long int)i] = nondet_constant_input; - const signed long int nondet_constant_input$array_size0=(signed long int)ans_den_size; - double yaux[nondet_constant_input$array_size0]; - const signed long int yaux$array_size0=(signed long int)ans_den_size; - double y0[yaux$array_size0]; - signed int Nw=ans_den_size > ans_num_size ? ans_den_size : ans_num_size; - const signed long int Nw$array_size0=(signed long int)Nw; - double waux[Nw$array_size0]; - const signed long int waux$array_size0=(signed long int)Nw; - double w0[waux$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (double)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= impl.min) - tmp_if_expr$2 = waux[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - double_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// verify_limit_cycle_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 21 -signed int verify_limit_cycle_state_space(void) -{ - double stateMatrix[20l][20l]; - double outputMatrix[20l][20l]; - double arrayLimitCycle[20l]; - double result1[20l][20l]; - double result2[20l][20l]; - signed int i; - signed int j; - signed int k; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0.000000; - result2[(signed long int)i][(signed long int)j] = 0.000000; - stateMatrix[(signed long int)i][(signed long int)j] = 0.000000; - outputMatrix[(signed long int)i][(signed long int)j] = 0.000000; - } - } - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - k = 0; - i = 1; - for( ; !(i >= 0); i = i + 1) - { - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.A, _controller.states, result1); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.B, _controller.inputs, result2); - double_add_matrix((unsigned int)nStates, 1u, result1, result2, _controller.states); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - signed int l=0; - for( ; !(l >= nStates); l = l + 1) - stateMatrix[(signed long int)l][(signed long int)k] = _controller.states[(signed long int)l][0l]; - l = 0; - for( ; !(l >= nOutputs); l = l + 1) - stateMatrix[(signed long int)l][(signed long int)k] = _controller.outputs[(signed long int)l][0l]; - k = k + 1; - } - printf("#matrix STATES -------------------------------"); - print_matrix(stateMatrix, (unsigned int)nStates, 0u); - printf("#matrix OUTPUTS -------------------------------"); - print_matrix(outputMatrix, (unsigned int)nOutputs, 0u); - /* assertion 0 */ - assert(0 != 0); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 0); j = j + 1) - arrayLimitCycle[(signed long int)j] = stateMatrix[(signed long int)i][(signed long int)j]; - double_check_persistent_limit_cycle(arrayLimitCycle, 0); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 0); j = j + 1) - arrayLimitCycle[(signed long int)j] = outputMatrix[(signed long int)i][(signed long int)j]; - double_check_persistent_limit_cycle(arrayLimitCycle, 0); - } - /* assertion 0 */ - assert(0 != 0); -} - -// verify_minimum_phase -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_minimum_phase.h line 24 -signed int verify_minimum_phase(void) -{ - overflow_mode = 0; - return 0; -} - -// verify_observability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_observability.h line 19 -signed int verify_observability(void) -{ - signed int i; - signed int j; - signed long int A_fpx[20l][20l]; - signed long int C_fpx[20l][20l]; - signed long int observabilityMatrix[20l][20l]; - signed long int backup[20l][20l]; - signed long int backupSecond[20l][20l]; - double observabilityMatrix_double[20l][20l]; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - observabilityMatrix[(signed long int)i][(signed long int)j] = 0l; - A_fpx[(signed long int)i][(signed long int)j] = 0l; - C_fpx[(signed long int)i][(signed long int)j] = 0l; - backup[(signed long int)i][(signed long int)j] = 0l; - backupSecond[(signed long int)i][(signed long int)j] = 0l; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.C[(signed long int)i][(signed long int)j]); - } - if(nOutputs >= 2) - { - signed int l; - j = 0; - l = 0; - while(!(l >= nStates)) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)l, backup); - l = l + 1; - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, C_fpx, backup, backupSecond); - signed int k=0; - for( ; !(k >= nOutputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - observabilityMatrix[(signed long int)j][(signed long int)i] = backupSecond[(signed long int)k][(signed long int)i]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nOutputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0l; - } - fxp_transpose(observabilityMatrix, backup, nStates * nOutputs, nStates); - signed long int mimo_observabilityMatrix_fxp[20l][20l]; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nOutputs), (unsigned int)(nStates * nOutputs), (unsigned int)nStates, backup, observabilityMatrix, mimo_observabilityMatrix_fxp); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(mimo_observabilityMatrix_fxp[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$1=determinant(observabilityMatrix_double, nStates); - /* assertion determinant(observabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)i, backup); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, C_fpx, backup, backupSecond); - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[0l][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(observabilityMatrix[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$2=determinant(observabilityMatrix_double, nStates); - /* assertion determinant(observabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 23 -signed int verify_overflow(void) -{ - overflow_mode = 1; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - signed int return_value_nondet_int$1=nondet_int(); - x[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = x[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0l; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0l; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0l; - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_verify_overflow_array(y, X_SIZE_VALUE); - return 0; -} - -// verify_stability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability.h line 24 -signed int verify_stability(void) -{ - overflow_mode = 0; - return 0; -} - -// verify_stability_closedloop_using_dslib -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability_closedloop.h line 21 -signed int verify_stability_closedloop_using_dslib(void) -{ - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num, ans_num_size, ans_den, ans_den_size); - printf("Verifying stability for closedloop function\n"); - signed int return_value_check_stability_closedloop$1=check_stability_closedloop(ans_den, ans_den_size, p_num, p_num_size, p_den, p_den_size); - __DSVERIFIER_assert((_Bool)return_value_check_stability_closedloop$1); - return 0; -} - -// verify_timing_msp_430 -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_timing_msp430.h line 22 -signed int verify_timing_msp_430(void) -{ - const signed long int verify_timing_msp_430$array_size0=(signed long int)X_SIZE_VALUE; - double y[verify_timing_msp_430$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0.000000; - float return_value_nondet_float$1=nondet_float(); - x[(signed long int)i] = (double)return_value_nondet_float$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= impl.min) - tmp_if_expr$2 = x[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - double yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - double xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - double waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0.000000; - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - return 0; -} - -// verify_zero_input_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_zero_input_limit_cycle.h line 16 -signed int verify_zero_input_limit_cycle(void) -{ - overflow_mode = 3; - signed int i; - signed int j; - signed int Set_xsize_at_least_two_times_Na=2 * ds.a_size; - printf("X_SIZE must be at least 2 * ds.a_size"); - /* assertion X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na */ - assert(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na); - if(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na) - (void)0; - - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - x[(signed long int)i] = 0l; - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - const signed long int waux$array_size0=(signed long int)ds.a_size; - signed long int y0[waux$array_size0]; - const signed long int y0$array_size0=(signed long int)Nw; - signed long int w0[y0$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = waux[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0l; - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// wrap -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 100 -signed long int wrap(signed long int kX, signed long int kLowerBound, signed long int kUpperBound) -{ - signed int range_size=(signed int)((kUpperBound - kLowerBound) + 1l); - if(!(kX >= kLowerBound)) - kX = kX + (signed long int)range_size * ((kLowerBound - kX) / (signed long int)range_size + 1l); - - return kLowerBound + (kX - kLowerBound) % (signed long int)range_size; -} - diff --git a/regression/cegis/cegis_control_benchmark_01/cegis-control-float.sh b/regression/cegis/cegis_control_benchmark_01/cegis-control-float.sh deleted file mode 100755 index 3fc9b8b5807..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/cegis-control-float.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -export PATH=${PATH//cbmc-5190/cbmc-trunk-diffblue-control-synthesis} -export PATH=${PATH}:/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis/src/cegis:/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis-analyzer/src/goto-analyzer - -benchmark_basedir='/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis/regression' -cd ${benchmark_basedir} - -benchmark_dir=$1 -cd ${benchmark_dir} - -function get_exponent_width() { - if [ $1 -le 8 ]; then return 2; fi - if [ $1 -le 10 ]; then return 3; fi - if [ $1 -le 12 ]; then return 4; fi - if [ $1 -le 14 ]; then return 5; fi - if [ $1 -le 16 ]; then return 6; fi - if [ $1 -le 26 ]; then return 7; fi - if [ $1 -le 37 ]; then return 8; fi - if [ $1 -le 48 ]; then return 9; fi - if [ $1 -le 58 ]; then return 10; fi - return 11 -} - -for word_width in {8..64}; do - get_exponent_width ${word_width} - exponent_width=$? - fraction_width=$((word_width - exponent_width - 1)) - echo "exp: $exponent_width, frac: $fraction_width" - cegis -D _EXPONENT_WIDTH=${fraction_width} -D _FRACTION_WIDTH=${exponent_width} --cegis-control --cegis-statistics --cegis-max-size 1 *.c - if [ $? -eq 0 ]; then exit 0; fi -done -exit 10 diff --git a/regression/cegis/cegis_control_benchmark_01/cegis-control.sh b/regression/cegis/cegis_control_benchmark_01/cegis-control.sh deleted file mode 100755 index e868d3f6cfa..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/cegis-control.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -export PATH=${PATH//cbmc-5190/cbmc-trunk-diffblue-control-synthesis} -export PATH=${PATH}:/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis/src/cegis:/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis-analyzer/src/goto-analyzer - -benchmark_basedir='/users/pkesseli/software/cpp/cbmc/cbmc-trunk-diffblue-control-synthesis/regression' -cd ${benchmark_basedir} - -benchmark_dir=$1 -cd ${benchmark_dir} - -for word_width in {8..64..2}; do - echo "width: $word_width" - cegis -D _FIXEDBV -D _CONTROL_FLOAT_WIDTH=${word_width} --fixedbv --cegis-control --cegis-statistics --cegis-max-size 1 *.c >/dev/null 2>&1 - if [ $? -eq 0 ]; then exit 0; fi -done -exit 10 diff --git a/regression/cegis/cegis_control_benchmark_01/controller.h b/regression/cegis/cegis_control_benchmark_01/controller.h deleted file mode 100644 index 5b581b371a2..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/controller.h +++ /dev/null @@ -1 +0,0 @@ -struct anonymous3 controller={ .den={ 1.000000, (double)-4.200000e-1f, (double)-3.465000e-1f, (double)-3.915000e-2f }, .den_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000 }, .den_size=4, .num={ 2.880000e+0, (double)-4.896000e+0f, 2.074000e+0 }, .num_uncertainty={ 0.000000, 0.000000, 0.000000 }, .num_size=3 }; diff --git a/regression/cegis/cegis_control_benchmark_01/plant.h b/regression/cegis/cegis_control_benchmark_01/plant.h deleted file mode 100644 index 5895230e9bb..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/plant.h +++ /dev/null @@ -1 +0,0 @@ -struct anonymous3 plant={ .den={ 1.000000, (double)-2.000000f, 1.000000 }, .den_uncertainty={ 0.000000, 0.000000, 0.000000 }, .den_size=3, .num={ 1.250000e-1, 1.250000e-1 }, .num_uncertainty={ 0.000000, 0.000000 }, .num_size=2 }; diff --git a/regression/cegis/cegis_control_benchmark_01/simplified_noise.c b/regression/cegis/cegis_control_benchmark_01/simplified_noise.c deleted file mode 100644 index d3f7d64ffc6..00000000000 --- a/regression/cegis/cegis_control_benchmark_01/simplified_noise.c +++ /dev/null @@ -1,505 +0,0 @@ -#include -#include - -/*#define __CONTROLLER_DEN_SIZE 3 -#define __CONTROLLER_NUM_SIZE 3 -#define __PLANT_DEN_SIZE 2 -#define __PLANT_NUM_SIZE 1 -#define SOLUTION_DEN_SIZE 3 -#define SOLUTION_NUM_SIZE 3*/ -#include "sizes.h" -#define __OPENLOOP_DEN_SIZE (__CONTROLLER_DEN_SIZE+__PLANT_DEN_SIZE-1) -#define __OPENLOOP_NUM_SIZE (__CONTROLLER_NUM_SIZE+__PLANT_NUM_SIZE-1) - -#define __NORMALIZED -#ifdef __CPROVER -#ifndef _FIXEDBV - #ifndef _EXPONENT_WIDTH - #define _EXPONENT_WIDTH 16 - #endif - #ifndef _FRACTION_WIDTH - #define _FRACTION_WIDTH 11 - #endif - typedef __CPROVER_floatbv[_EXPONENT_WIDTH][_FRACTION_WIDTH] control_floatt; - control_floatt _imp_max=(((1 <<(_EXPONENT_WIDTH-1))-1)<<1)+1; -#else - #ifndef _CONTROL_FLOAT_WIDTH - #define _CONTROL_FLOAT_WIDTH 16 - #endif - #ifndef _CONTORL_RADIX_WIDTH - #define _CONTORL_RADIX_WIDTH _CONTROL_FLOAT_WIDTH / 2 - #endif - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] control_floatt; - control_floatt _imp_max=(((1 <<(_CONTROL_FLOAT_WIDTH-1))-1)<<1)+1; -#endif - typedef unsigned char cnttype; -#else - typedef double control_floatt; - typedef unsigned int cnttype; - #include - #include -#endif - -struct anonymous0 -{ - cnttype int_bits; - cnttype frac_bits; -}; - -struct anonymous3 -{ - control_floatt den[SOLUTION_DEN_SIZE]; - control_floatt den_uncertainty[SOLUTION_DEN_SIZE]; - cnttype den_size; - control_floatt num[SOLUTION_NUM_SIZE]; - control_floatt num_uncertainty[SOLUTION_NUM_SIZE]; - cnttype num_size; -}; - -control_floatt _dbl_max; -control_floatt _dbl_min; -signed long int _fxp_max; -signed long int _fxp_min; -signed long int _fxp_one; -control_floatt _dbl_lsb; -control_floatt _poly_error; -control_floatt _sum_error; -control_floatt _plant_norm; - -struct anonymous0 impl={ .int_bits=_CONTROLER_INT_BITS, .frac_bits=_CONTROLER_FRAC_BITS}; - -#include "plant.h" -/*struct anonymous3 plant={ .den={ 1.0, -9.998000e-1, 0.0}, .den_uncertainty={0.0, 0.0, 0.0}, .den_size=2, -.num={ 2.640000e-2, 0.0, 0.0}, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=1};*/ -/*struct anonymous3 plant={ .den={ 1.0, -3.32481248817168, 1.64872127070013 }, .den_size=3, - .num={ 0.548693198268086, -0.886738807003861, 0.0 }, .num_size=2};*/ - -struct anonymous3 plant_cbmc,controller_cbmc; -//#ifdef __CPROVER -#include "controller.h" -//extern struct anonymous3 controller; -/*#else -//struct anonymous3 controller = { .den={ 32218.8125, 3544.125, 29723.25 }, .den_uncertainty={0.0, 0.0, 0.0}, .den_size=3, -// .num={ 17509.4375, 7878.25, 12107.6875 }, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=3}; -struct anonymous3 controller = { .den={ 25868.375, -12550.9375, 5127.375 },.den_uncertainty={0.0, 0.0, 0.0}, .den_size=3, - .num={ 26097, -303.0625, -23076.25 }, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=3}; -#endif*/ - -void __DSVERIFIER_assume(_Bool expression) -{ -#ifdef __CPROVER - __CPROVER_assume(expression != (_Bool)0); -#endif -} - -void __DSVERIFIER_assert(_Bool expression) -{ - /* assertion expression */ - assert(expression != (_Bool)0); -} - -void initialization() -{ - __DSVERIFIER_assert(impl.int_bits+impl.frac_bits < 32); -#ifdef __NORMALIZED - _fxp_one = 1 << (impl.frac_bits + impl.int_bits); - _dbl_lsb=1.0/(1 << impl.frac_bits + impl.int_bits); - _fxp_min = -(1 << (impl.frac_bits + impl.int_bits -1)); - _fxp_max = (1 << (impl.frac_bits + impl.int_bits-1))-1; - _dbl_max = (1.0-_dbl_lsb);//Fractional part -#else - if(impl.frac_bits >= 31) - _fxp_one = 2147483647l; - else - _fxp_one = (1 << impl.frac_bits); - _dbl_lsb=1.0/(1 << impl.frac_bits); - _fxp_min = -(1 << (impl.frac_bits + impl.int_bits -1)); - _fxp_max = (1 << (impl.frac_bits + impl.int_bits-1))-1; - _dbl_max = (1 << (impl.int_bits-1))-1;//Integer part - _dbl_max += (1.0-_dbl_lsb);//Fractional part -#endif - _dbl_min = -_dbl_max; -#ifdef __CHECK_FP - if (SOLUTION_DEN_SIZE>SOLUTION_NUM_SIZE) - { - _poly_error=2*_dbl_lsb*SOLUTION_DEN_SIZE; - _sum_error=2*_poly_error*SOLUTION_DEN_SIZE; - } - else - { - _poly_error=2*_dbl_lsb*SOLUTION_NUM_SIZE; - _sum_error=2*_poly_error*SOLUTION_DEN_SIZE; - } -#else - _poly_error=0; - _sum_error=0; -#endif -} - -int validation() -{ - cnttype i; - control_floatt max=0; - for (i=0;imax) max=plant.num[i]; - else if (-plant.num[i]>max) max=-plant.num[i]; - } - for (i=0;imax) max=plant.den[i]; - else if (-plant.den[i]>max) max=-plant.den[i]; - } - unsigned int max_int=max; -#ifdef __NORMALIZED - cnttype mult_bits=1; -#else - cnttype mult_bits=12; -#endif - while (max_int>0) - { - mult_bits++; - max_int>>=1; - } - _plant_norm=1<= _dbl_min); -#else - printf("value=%f", value); - if(value > _dbl_max) return 10; - if(value < _dbl_min) return 10; -#endif - } -#ifdef __CPROVER - __DSVERIFIER_assume(zero_count < __CONTROLLER_DEN_SIZE); -#else - if (zero_count == __CONTROLLER_DEN_SIZE) return 10; -#endif - zero_count = 0; - for(i = 0 ; i < __CONTROLLER_NUM_SIZE; i++) - { - const control_floatt value=controller.num[i]; - if(value == 0.0) ++zero_count; -#ifdef __CPROVER - __DSVERIFIER_assume(value <= _dbl_max); - __DSVERIFIER_assume(value >= _dbl_min); -#else - if (value > _dbl_max) return 10; - if (value < _dbl_min) return 10; -#endif - } -#ifdef __CPROVER - __DSVERIFIER_assume(zero_count < __CONTROLLER_DEN_SIZE); -#else - if (zero_count == __CONTROLLER_DEN_SIZE) return 10; -#endif - return 0; -} - -#ifndef __CPROVER -void print_poly(control_floatt *pol,cnttype n) -{ - cnttype i; - for (i=0;i 0.0) - { - control_floatt factor=(plant.num[i] * plant.num_uncertainty[i]) / 100.0; - factor = factor < 0.0 ? -factor : factor; - control_floatt min=plant.num[i] -factor; - control_floatt max=plant.num[i] +factor; - plant_cbmc.num[i] = nondet_double(); - __DSVERIFIER_assume(plant_cbmc.num[i] >= min); - __DSVERIFIER_assume(plant_cbmc.num[i] <= max); -#ifdef __NORMALIZED - plant_cbmc.num[i]/=_plant_norm; -#endif - } - else -#endif -#ifdef __NORMALIZED - plant_cbmc.num[i] = plant.num[i]/_plant_norm; -#else - plant_cbmc.num[i] = plant.num[i]; -#endif - plant_cbmc.den_size=plant.den_size; - for(i = 0; i < plant.den_size; i++) -#ifdef __CPROVER - if(plant.den_uncertainty[i] > 0.0) - { - control_floatt factor=(plant.den[i] * plant.den_uncertainty[i]) / 100.0; - factor = factor < 0.000000 ? -factor : factor; - control_floatt min=plant.den[i] -factor; - control_floatt max=plant.den[i] +factor; - plant_cbmc.den[i] = nondet_double(); - __DSVERIFIER_assume(plant_cbmc.den[i] >= min); - __DSVERIFIER_assume(plant_cbmc.den[i] <= max); -#ifdef __NORMALIZED - plant_cbmc.den[i]/=_plant_norm; -#endif - } - else -#endif -#ifdef __NORMALIZED - plant_cbmc.den[i] = plant.den[i]/_plant_norm; -#else - plant_cbmc.den[i] = plant.den[i]; -#endif -} - -signed int check_stability_closedloop(control_floatt *a, cnttype n) -{ - cnttype columns=n; - control_floatt m[n][n]; - cnttype i; - cnttype j; - control_floatt sum=0.0; - for(i = 0 ; i < n; i++) { sum += a[i]; } -#ifdef __CPROVER - __DSVERIFIER_assert(a[0] > _poly_error); - __DSVERIFIER_assert(sum > _sum_error); - __DSVERIFIER_assert(a[n-1]+_poly_error < a[0]); - __DSVERIFIER_assert(-a[n-1]+_poly_error < a[0]); -#else - printf("m[0]=%f>0\n", a[0]); - //std::cout << "m[0]=" << a[0] << ">0" << std::endl; - printf("fabs(m[%d]=%f)0\n", sum); - //std::cout << "sum=" << sum << ">0" << std::endl; - if (!(a[0] > _poly_error)) return 0; - if (!(sum > _sum_error)) return 0; - if (!(a[n - 1]+_poly_error < a[0])) return 0; - if (!(-a[n - 1]+_poly_error < a[0])) return 0; -#endif - sum = 0.0; - for(i = 0 ; i < n; i++) - { - if (((n -i)&1)!=0) sum+=a[i]; - else sum-=a[i]; - } - if ((n&1)==0) sum=-sum; -#ifdef __CPROVER - __DSVERIFIER_assert(sum > _sum_error); -#else - printf("sumEven-sumOdd=%f>0\n", sum); - //std::cout << "sumEven-sumOdd=" << sum << ">0" << std::endl; - if (!(sum > _sum_error)) return 0; -#endif - for(j=0;j0 - control_floatt factor=m[i-1][columns] / m[i-1][0]; -#ifdef __CHECK_FP - if (m[i-1][0]<0) __DSVERIFIER_assert(m[i-1][0]<-(mag*mag/_imp_max+_poly_error)); - else __DSVERIFIER_assert(m[i-1][0]> (mag*mag/_imp_max+_poly_error));//check for overflow. - control_floatt efactor=m[i-1][columns]; - if (efactor<0) efactor=-efactor; - efactor+=_poly_error; - efactor/=m[i-1][0]-_poly_error; - efactor-=factor; - __DSVERIFIER_assert(efactor<_poly_error*mag); - if (factor>0) - { - _poly_error*=2+factor;//Unsound! does not consider the error in factor (a+e/b-e = a/(b-e) +e/(b-e)) - mag+=mag*factor; - } - else - { - _poly_error*=2-factor; - mag-=mag*factor; - } -#endif - for(j=0;j= _poly_error); -#else - printf("m[%d]=%f>0\n", i, m[i][0]); - //std::cout << "m[" << i << "]=" << m[i][0] << ">0" << std::endl; - if (!(m[i][0] >= _poly_error)) return 0; -#endif - columns--; - } - return 1; -} - -signed long int fxp_control_floatt_to_fxp(control_floatt value) -{ - signed long int tmp; - control_floatt ftemp=value * _fxp_one; - tmp = ftemp; - control_floatt residue=ftemp - tmp; - if(value < 0.0 && (residue != 0.0)) - { - ftemp = ftemp - 1.0; - tmp = ftemp; - } - return tmp; -} - -void fxp_check(control_floatt *value) -{ -#ifdef __CPROVER - control_floatt tmp_value=*value; - if (tmp_value < 0.0) tmp_value=-tmp_value; - __DSVERIFIER_assert((~_dbl_max&tmp_value)==0); -#else - *value=fxp_control_floatt_to_fxp(*value); - *value/=_fxp_one; -#endif -} - -void fxp_check_array(control_floatt *f, cnttype N) -{ - for(cnttype i=0; i < N; i++) fxp_check(&f[i]); -} - -void poly_mult(control_floatt *a, cnttype Na, control_floatt *b, cnttype Nb, control_floatt *ans, cnttype Nans) -{ - cnttype i; - cnttype j; - cnttype k; - Nans = Na + Nb - 1; - for(i = 0 ; i 0)"); - return 0; - } - - /* check the second constraint condition F(-1)*(-1)^n > 0 */ - sum = 0; - for (i=0; i < __n; i++){ - sum += __a[i] * internal_pow(-1, __n-1-i); - } - sum = sum * internal_pow(-1, __n-1); - if (sum <= 0){ - printf("[DEBUG] the second constraint of Jury criteria failed: (F(-1)*(-1)^n > 0)"); - return 0; - } - - /* check the third constraint condition abs(a0 < an*(z^n) */ - if (internal_abs(__a[__n-1]) > __a[0]){ - printf("[DEBUG] the third constraint of Jury criteria failed: (abs(a0) < a_{n}*z^{n})"); - return 0; - } - - /* check the fourth constraint of condition (Jury Table) */ - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - m[i][j] = 0; - } - } - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - if (i == 0){ - m[i][j] = __a[j]; - continue; - } - if (i % 2 != 0 ){ - int x; - for(x=0; x= 0 ? 1 : 0; - for (i=0; i < lines; i++){ - if (i % 2 == 0){ - int line_is_positive = m[i][0] >= 0 ? 1 : 0; - if (first_is_positive != line_is_positive){ - return 0; - } - continue; - } - } - return 1; -} - - -// P(s)=(s-m11)*(s-m22)*(s-m33) - m13*m31*(s-m22) - m12*m21*(s-m33) - m23*m32*(s-m11) - m12*m23*m31 - m13*m21*m32 -// P(s)=s^3 + (-m_11 - m_22 - m_33) * s^2 + (m_11*m_22 + m_11*m_33 - m_12*m_21 - m_13*m_31 + m_22*m_33 - m_23*m_32) * s - m_11*m_22*m_33 + m_11*m_23*m_32 + m_12*m_21*m_33 - m_12*m_23*m_31 - m_13*m_21*m_32 + m_13*m_22*m_31 -void __CPROVER_EIGEN_charpoly(void) { -#define __m __CPROVER_EIGEN_TEST_A - // m_11*m_22*m_33 + m_11*m_23*m_32 + m_12*m_21*m_33 - m_12*m_23*m_31 - m_13*m_21*m_32 + m_13*m_22*m_31 - __CPROVER_EIGEN_poly[0] = __m[0][0] * __m[1][1] * __m[2][2] + __m[0][0] * __m[1][2] * __m[2][1] + __m[0][1] * __m[1][0] * __m[2][2] - __m[0][1] * __m[1][2] * __m[2][0] - __m[0][2] * __m[1][0] * __m[2][1] + __m[0][2] * __m[1][1] * __m[2][0]; - // (m_11*m_22 + m_11*m_33 - m_12*m_21 - m_13*m_31 + m_22*m_33 - m_23*m_32) * s - __CPROVER_EIGEN_poly[1] = __m[0][0] * __m[1][1] + __m[0][0] * __m[2][2] - __m[0][1] * __m[1][0] - __m[0][2] * __m[2][0] + __m[1][1] * __m[2][2] - __m[1][2] * __m[2][1]; - // (-m_11 - m_22 - m_33) * s^2 - __CPROVER_EIGEN_poly[2] = -__m[0][0] - __m[1][1] - __m[2][2]; - // s^3 - __CPROVER_EIGEN_poly[3] = 1.0; -} - -/*void init(void) { - K_fxp[0][0] = nondet_double(); - K_fxp[0][1] = nondet_double(); - K_fxp[0][2] = nondet_double(); -}*/ - -__CPROVER_EIGEN_fixedbvt __CPROVER_EIGEN_matrix_multiplication_result[4][4]; - -void double_sub_matrix(void/* unsigned int lines, unsigned int columns, __CPROVER_EIGEN_fixedbvt m1[4][4], __CPROVER_EIGEN_fixedbvt m2[4][4], __CPROVER_EIGEN_fixedbvt result[4][4]*/){ -#define __sm_lines NSTATES -#define __sm_columns NSTATES -#define __sm_m1 _controller.A -#define __sm_m2 __CPROVER_EIGEN_matrix_multiplication_result -#define __sm_m3 _controller.A - unsigned int i, j; - for (i = 0; i < __sm_lines; i++){ - for (j = 0; j < __sm_columns; j++){ - __sm_m3[i][j] = __sm_m1[i][j] - __sm_m2[i][j]; - - } - } -} - -void double_matrix_multiplication(void/* unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, __CPROVER_EIGEN_fixedbvt m1[4][4], __CPROVER_EIGEN_fixedbvt m2[4][4], __CPROVER_EIGEN_fixedbvt m3[4][4]*/){ -#define __mm_i1 NSTATES - //unsigned int __mm_i1; -#define __mm_j1 NINPUTS - //unsigned int __mm_j1; -#define __mm_i2 NINPUTS - //unsigned int __mm_i2; -#define __mm_j2 NSTATES - //unsigned int __mm_j2; -#define __mm_m1 _controller.B - //__CPROVER_EIGEN_fixedbvt __mm_m1[4][4]; -#define __mm_m2 K_fxp - //__CPROVER_EIGEN_fixedbvt __mm_m2[4][4]; -#define __mm_m3 __CPROVER_EIGEN_matrix_multiplication_result - //__CPROVER_EIGEN_fixedbvt __mm_m3[4][4]; - - unsigned int i, j, k; - if (__mm_j1 == __mm_i2) { - - /*for (i=0; i<__mm_i1; i++) { - for (j=0; j<__mm_j2; j++) { - __mm_m3[i][j] = 0; - } - }*/ - - for (i=0;i<__mm_i1; i++) { - for (j=0; j<__mm_j2; j++) { - for (k=0; k<__mm_j1; k++) { - - __CPROVER_EIGEN_fixedbvt mult = (__mm_m1[i][k] * __mm_m2[k][j]); - - - __mm_m3[i][j] = __mm_m3[i][j] + (__mm_m1[i][k] * __mm_m2[k][j]); - - - } - - } - } - } else { - printf("\nError! Operation invalid, please enter with valid matrices.\n"); - } -} - -#define LIMIT 4u - -void closed_loop(void) -{ - //__CPROVER_EIGEN_fixedbvt result1[LIMIT][LIMIT]; - - /*int i, j, k; - for(i=0; i counterexample_var, ""); - //__CPROVER_assert(0 == 1, ""); - return 0; -} diff --git a/regression/cegis/cegis_control_benchmark_02/test.desc b/regression/cegis/cegis_control_benchmark_02/test.desc deleted file mode 100644 index 10e88d67b1b..00000000000 --- a/regression/cegis/cegis_control_benchmark_02/test.desc +++ /dev/null @@ -1,7 +0,0 @@ -CORE -eigen_charpoly.c ---gcc --fixedbv --round-to-minus-inf --cegis-control --cegis-statistics --cegis-genetic --cegis-max-size 1 --cegis-show-iterations -EXIT=0 -SIGNAL=0 --- -warning: ignoring diff --git a/regression/cegis/cegis_control_benchmark_03/benchmark.h b/regression/cegis/cegis_control_benchmark_03/benchmark.h deleted file mode 100644 index 1cc819d94d7..00000000000 --- a/regression/cegis/cegis_control_benchmark_03/benchmark.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * benchmark.h - * - * Created on: 18 Jan 2017 - * Author: elipol - */ - -#ifndef BENCHMARK_H_ -#define BENCHMARK_H_ - -#define INT_BITS 8 -#define FRAC_BITS 8 -#include "control_types.h" - -#define NSTATES 3 -#define NINPUTS 1 -#define NOUTPUTS 1 -#define INPUT_UPPERBOUND (__plant_precisiont)1 -#define INPUT_LOWERBOUND (__plant_precisiont)-1 -const __plant_typet _controller_A[NSTATES][NSTATES] = {{ interval(0.9905),interval(0.075687),interval(0.021033) }, - {interval (0.125),interval(0),interval(0) }, - { interval(0),(0.015625),(0) }}; -const __plant_typet _controller_B[NSTATES] = { interval(16), interval(0),interval( 0) }; - - - -#endif /* BENCHMARK_H_ */ diff --git a/regression/cegis/cegis_control_benchmark_03/control_types.h b/regression/cegis/cegis_control_benchmark_03/control_types.h deleted file mode 100644 index 62bbffafb8a..00000000000 --- a/regression/cegis/cegis_control_benchmark_03/control_types.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * control_types.h - * - * Created on: 18 Jan 2017 - * Author: elipol - */ - -#ifndef CONTROL_TYPES_H_ -#define CONTROL_TYPES_H_ - -#ifdef CPROVER - #ifdef INTERVAL - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __plant_precisiont; - #include "intervals.h" - typedef struct intervalt __plant_typet; - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __controller_precisiont; - typedef struct intervalt __controller_typet; - #define interval(x) interval_cast(x); - #else - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __plant_precisiont; - typedef __plant_precisiont __plant_typet; - typedef __CPROVER_fixedbv[INT_BITS+FRAC_BITS][FRAC_BITS] __controller_precisiont; - typedef __controller_precisiont __controller_typet; - #define plant_cast(x) ((__plant_typet)x) - #define controller_cast(x) ((__controller_typet)x) - #define interval(x) x - #endif -#else - #ifdef INTERVAL - typedef double __plant_precisiont; - #include "intervals.h" - typedef struct intervalt __plant_typet; - typedef double __controller_precisiont; //fixed point arithmetic is implemented using doubles - typedef struct intervalt __controller_typet; - #define interval(x) interval_cast(x) - #endif - #ifndef INTERVAL - typedef double __plant_precisiont; - typedef __plant_precisiont __plant_typet; - typedef double __controller_precisiont; //fixed point arithmetic is implemented using doubles - typedef __controller_precisiont __controller_typet; - #define interval(x) (x) - #define plant_cast(x) x - #define controller_cast(x) x - #endif -#endif - -#endif /* CONTROL_TYPES_H_ */ diff --git a/regression/cegis/cegis_control_benchmark_03/operators.h b/regression/cegis/cegis_control_benchmark_03/operators.h deleted file mode 100644 index 3b6c3dcfcb1..00000000000 --- a/regression/cegis/cegis_control_benchmark_03/operators.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * operators.h - * - * Created on: 18 Jan 2017 - * Author: elipol - */ - -#ifndef OPERATORS_H_ -#define OPERATORS_H_ - -#ifndef INTERVAL - #define controller_mult(x,y) ((x) *(y)) - #define mult(x,y) ( (x) * (y)) - - #define _abs(a) ( (a) < 0 ? -(a) : (a)) - #define add(x,y) ( (x) + (y)) - - #define lessthan(x,y) ((x) )< (y)) - #define greaterthan(x,y) ((x)>(y)) - #define lessthanzero(x) ((x) < 0) - #define lessthan_equaltozero(x) ((x) <= 0) - #define zero_type 0 - #define one_type (__plant_precisiont)1.0 - #define minusone (__plant_precisiont)-1 - #define div(x,y) ( (x) / (y)) - #define sub(x,y) ( (x) - (y)) - #define set(x,y) (x)=(y) - - -#endif -#ifdef INTERVAL - - #define controller_mult(x,y) (interval_fxp_mult((x),(y))) - #define mult(x,y) ( interval_mult((x),(y))) - - #define _abs(a) ( abs_interval(a)) - - #define lessthan(x,y) (interval_lessthan(x,y)) - #define greaterthan(x,y) (interval_greaterthan((x),(y))) - #define add(x,y) (interval_add((x),(y))) - #define lessthanzero(x) (interval_lessthanzero(x)) - #define lessthan_equaltozero(x) (interval_lessthan_equal_to_zero(x)) - - #define zero_type (zero_interval) - #define minusone (minusone_interval) - #define one_type one_interval - #define div(x,y) (interval_posDiv((x),(y))) - #define sub(x,y) (interval_sub((x),(y))) - - #define controller_cast(x) (fxp_interval_check(x)) - #define plant_cast(x) x - #define set(x,y) (x.low=y, x.high=y) - - -#endif - -#endif /* OPERATORS_H_ */ diff --git a/regression/cegis/cegis_control_benchmark_03/safety_stability.c b/regression/cegis/cegis_control_benchmark_03/safety_stability.c deleted file mode 100644 index 2471d35b8ba..00000000000 --- a/regression/cegis/cegis_control_benchmark_03/safety_stability.c +++ /dev/null @@ -1,486 +0,0 @@ -#include -#include "benchmark.h" //benchmark header file -//#include "control_types.h" //included via benchmark.h -//#define CPROVER -//#ifdef INTERVAL - // #include "intervals.h" //included via control_types.h -//#endif -#include "operators.h" - -#ifdef CPROVER - //#define __DSVERIFIER_assert(x) __CPROVER_assume(x) -#define __DSVERIFIER_assert(x) __CPROVER_assert(x, "") -#else - #include - #define __DSVERIFIER_assert(x) assert(x) -#endif - -//#define NUMBERLOOPS 5 // Defined by benchmark script -#define INITIALSTATE_UPPERBOUND (__plant_precisiont)0.5 -#define INITIALSTATE_LOWERBOUND (__plant_precisiont)-0.5 -#define SAFE_STATE_UPPERBOUND (__plant_precisiont)1.0 -#define SAFE_STATE_LOWERBOUND (__plant_precisiont)-1.0 - -//other plant variables -extern const __controller_typet K_fxp[NSTATES]; //nondet controller -//const __controller_typet K_fxp[NSTATES] = {interval(0.0234375),interval(-0.1328125), interval(0.00390625)}; -__plant_typet _controller_inputs; -extern __plant_typet _controller_states[NSTATES]; //nondet initial states - -//matrices for stability calculation -__plant_typet _AminusBK[NSTATES][NSTATES]; - -__plant_typet __CPROVER_EIGEN_poly[NSTATES + 1u]; - -//stablity calc - -__plant_typet internal_pow(__plant_typet a, unsigned int b){ - - __plant_typet acc = one_type; - for (int i=0; i < b; i++){ - acc = mult(acc,a); - } - return acc; -} - - -int check_stability(void){ - - - #if NSTATES==1 - if(greaterthan(_AminusBK[0][0], 1) || lessthan( _AminusBK[0][0] ,-1)) - {return 0;} - else - {return 1;} -#endif - - -#define __a __CPROVER_EIGEN_poly -#define __n NSTATES + 1u - int lines = 2 * __n - 1; - int columns = __n; - __plant_typet m[lines][__n]; - int i,j; - - /* to put current values in stability counter-example - * look for current_stability (use: --no-slice) */ - __plant_typet current_stability[__n]; - for (i=0; i < __n; i++){ - current_stability[i] = __a[i]; - } - - /* check the first constraint condition F(1) > 0 */ - __plant_typet sum = zero_type; - for (i=0; i < __n; i++){ - sum = add(sum, __a[i]); - } - if (lessthan_equaltozero(sum)){ - printf("[DEBUG] the first constraint of Jury criteria failed: (F(1) > 0)"); - return 0; - } - - /* check the second constraint condition F(-1)*(-1)^n > 0 */ - sum = zero_type; - for (i=0; i < __n; i++){ - sum = add(sum, mult(__a[i] , internal_pow(minusone, NSTATES-i) )); - } - sum = mult(sum,internal_pow(minusone, NSTATES) ); - - if (lessthan_equaltozero(sum)){ - printf("[DEBUG] the second constraint of Jury criteria failed: (F(-1)*(-1)^n > 0)"); - return 0; - } - - /* check the third constraint condition abs(a0 < an*(z^n) */ - if(greaterthan( _abs(__a[__n-1]), __a[0])){ - // if (abs(__a[__n-1]) > __a[0]){ - printf("[DEBUG] the third constraint of Jury criteria failed: (abs(a0) < a_{n}*z^{n})"); - return 0; - } - - /* check the fourth constraint of condition (Jury Table) */ - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - m[i][j] = zero_type; - } - } - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - if (i == 0){ - m[i][j] = __a[j]; - continue; - } - if (i % 2 != 0 ){ - int x; - for(x=0; x= 0 ? 1 : 0; - for (i=0; i < lines; i++){ - if (i % 2 == 0){ - int line_is_positive = lessthanzero(m[i][0])? 0 : 1; - // int line_is_positive = m[i][0] >= 0 ? 1 : 0; - if (first_is_positive != line_is_positive){ - return 0; - } - continue; - } - } - return 1; -} - -#define __m _AminusBK -#if NSTATES==2 -void __CPROVER_EIGEN_charpoly_2(void) { //m00*m11 - m10*m11 - m00*x - m11*x + x^2 - - __CPROVER_EIGEN_poly[2] = sub ( mult(__m[0][0],__m[1][1]), mult(__m[1][0] , __m[1][1]) ); - - __CPROVER_EIGEN_poly[1] = sub (zero_type, add (__m[0][0], __m[1][1]) ) ; - // s^2 - __CPROVER_EIGEN_poly[0] = one_type; -} -#endif - -#if NSTATES==3 -void __CPROVER_EIGEN_charpoly_3(void) { -// m_11*m_22*m_33 + m_11*m_23*m_32 + m_12*m_21*m_33 - m_12*m_23*m_31 - m_13*m_21*m_32 + m_13*m_22*m_31 -__CPROVER_EIGEN_poly[3] = add(sub(sub(add(add(mult(__m[0][0],mult( __m[1][1], __m[2][2])), mult( __m[0][0] ,mult( __m[1][2] , __m[2][1]))), - mult(__m[0][1],mult( __m[1][0], __m[2][2]))), mult(__m[0][1],mult( __m[1][2], __m[2][0]) )), mult(__m[0][2] ,mult(__m[1][0], __m[2][1]))), - mult( __m[0][2], mult(__m[1][1],__m[2][0]))); -// (m_11*m_22 + m_11*m_33 - m_12*m_21 - m_13*m_31 + m_22*m_33 - m_23*m_32) * s -__CPROVER_EIGEN_poly[2] = sub(add(sub(sub(mult(__m[0][0], mult( __m[1][1], mult( __m[0][0], __m[2][2]))), mult(__m[0][1], __m[1][0])), - mult(__m[0][2],__m[2][0])), mult(__m[1][1], __m[2][2])),mult(__m[1][2], __m[2][1])); -// (-m_11 - m_22 - m_33) * s^2 -__CPROVER_EIGEN_poly[1] = sub(sub(sub(zero_type,__m[0][0]), __m[1][1]), __m[2][2]); -// s^3 -__CPROVER_EIGEN_poly[0] = one_type; - -} -#endif -#if NSTATES==4 -void __CPROVER_EIGEN_charpoly_4(void) { - - __CPROVER_EIGEN_poly[4] = __m[0][0]*__m[1][1]*__m[2][2]*__m[3][3] - __m[0][0]*__m[1][1]*__m[2][3]*__m[3][2] - __m[0][0]*__m[1][2]*__m[2][1]*__m[3][3] + __m[0][0]*__m[1][2]*__m[2][3]*__m[3][1] + __m[0][0]*__m[1][3]*__m[2][1]*__m[3][2] - - __m[0][0]*__m[1][3]*__m[2][2]*__m[3][1] - __m[0][1]*__m[1][0]*__m[2][2]*__m[3][3] + __m[0][1]*__m[1][0]*__m[2][3]*__m[3][2] + __m[0][1]*__m[1][2]*__m[2][0]*__m[3][3] - __m[0][1]*__m[1][2]*__m[2][3]*__m[3][0] - - __m[0][1]*__m[1][3]*__m[2][0]*__m[3][2] + __m[0][1]*__m[1][3]*__m[2][2]*__m[3][0] + __m[0][2]*__m[1][0]*__m[2][1]*__m[3][3] - __m[0][2]*__m[1][0]*__m[2][3]*__m[3][1] - __m[0][2]*__m[1][1]*__m[2][0]*__m[3][3] + - __m[0][2]*__m[1][1]*__m[2][3]*__m[3][0] + __m[0][2]*__m[1][3]*__m[2][0]*__m[3][1] - __m[0][2]*__m[1][3]*__m[2][1]*__m[3][0] - __m[0][3]*__m[1][0]*__m[2][1]*__m[3][2] + __m[0][3]*__m[1][0]*__m[2][2]*__m[3][1] + - __m[0][3]*__m[1][1]*__m[2][0]*__m[3][2] - __m[0][3]*__m[1][1]*__m[2][2]*__m[3][0] - __m[0][3]*__m[1][2]*__m[2][0]*__m[3][1] + __m[0][3]*__m[1][2]*__m[2][1]*__m[3][0]; - - -__CPROVER_EIGEN_poly[3] = - __m[0][0]*__m[1][1]*__m[2][2] + __m[0][0]*__m[1][2]*__m[2][1] + __m[0][1]*__m[1][0]*__m[2][2] - __m[0][1]*__m[1][2]*__m[2][0] - __m[0][2]*__m[1][0]*__m[2][1] + __m[0][2]*__m[1][1]*__m[2][0] - - __m[0][0]*__m[1][1]*__m[3][3] + __m[0][0]*__m[1][3]*__m[3][1] + __m[0][1]*__m[1][0]*__m[3][3] - __m[0][1]*__m[1][3]*__m[3][0] - __m[0][3]*__m[1][0]*__m[3][1] + __m[0][3]*__m[1][1]*__m[3][0] - - __m[0][0]*__m[2][2]*__m[3][3] + __m[0][0]*__m[2][3]*__m[3][2] + __m[0][2]*__m[2][0]*__m[3][3] - __m[0][2]*__m[2][3]*__m[3][0] - __m[0][3]*__m[2][0]*__m[3][2] + __m[0][3]*__m[2][2]*__m[3][0] - - __m[1][1]*__m[2][2]*__m[3][3] + __m[1][1]*__m[2][3]*__m[3][2] + __m[1][2]*__m[2][1]*__m[3][3] - __m[1][2]*__m[2][3]*__m[3][1] - __m[1][3]*__m[2][1]*__m[3][2] + __m[1][3]*__m[2][2]*__m[3][1]; - - - __CPROVER_EIGEN_poly[2] = + __m[0][0]*__m[1][1] - __m[0][1]*__m[1][0] + __m[0][0]*__m[2][2] - __m[0][2]*__m[2][0] + __m[0][0]*__m[3][3] - __m[0][3]*__m[3][0] + __m[1][1]*__m[2][2] - - __m[1][2]*__m[2][1] + __m[1][1]*__m[3][3] - __m[1][3]*__m[3][1] + __m[2][2]*__m[3][3] - __m[2][3]*__m[3][2]; - - - __CPROVER_EIGEN_poly[1] = - __m[3][3] - __m[2][2] - __m[1][1] - __m[0][0]; - __CPROVER_EIGEN_poly[0] = 1.0; -} -#endif - -void __CPROVER_EIGEN_charpoly(void){ - - #if NSTATES==1 - //do nothing - #elif NSTATES==2 - __CPROVER_EIGEN_charpoly_2(); - #elif NSTATES==3 - __CPROVER_EIGEN_charpoly_3(); - #elif NSTATES==4 - __CPROVER_EIGEN_charpoly_4(); - #endif -} - -void A_minus_B_K() -{ - -#ifdef CPROVER - __CPROVER_array_copy(_AminusBK, _controller_A); -#else - for(int i=0; iINPUT_LOWERBOUND); - #else - __CPROVER_assume(_controller_inputs < INPUT_UPPERBOUND && _controller_inputs > INPUT_LOWERBOUND); - #endif - #endif - - } - } - -__plant_typet states_equals_A_states_plus_B_inputs_result[NSTATES]; - -void states_equals_A_states_plus_B_inputs(void) -{ - - #ifdef CPROVER - __CPROVER_array_set(states_equals_A_states_plus_B_inputs_result, zero_type); - #else - for(int i=0; iSAFE_STATE_LOWERBOUND); - __DSVERIFIER_assert( _controller_states[1]SAFE_STATE_LOWERBOUND); - #if NSTATES==3 || NSTATES==4 - __DSVERIFIER_assert( _controller_states[2]SAFE_STATE_LOWERBOUND); - #endif - #if NSTATES==4 - __DSVERIFIER_assert( _controller_states[3]SAFE_STATE_LOWERBOUND); - #endif -#else - for(int i=0; iSAFE_STATE_LOWERBOUND); - } -#endif -#else -#ifdef CPROVER - __CPROVER_array_copy(_controller_states, states_equals_A_states_plus_B_inputs_result); - /*for(i=0; iSAFE_STATE_LOWERBOUND); - __DSVERIFIER_assert( _controller_states[1].highSAFE_STATE_LOWERBOUND); - #if NSTATES==3 || NSTATES==4 - __DSVERIFIER_assert( _controller_states[2].highSAFE_STATE_LOWERBOUND); - #endif - #if NSTATES==4 - __DSVERIFIER_assert( _controller_states[3].highSAFE_STATE_LOWERBOUND); - #endif -#else - for(int i=0; iSAFE_STATE_LOWERBOUND); - } -#endif -#endif - - - - } - - - -int check_safety(void) -{ - - for(int j=0; j=INITIALSTATE_LOWERBOUND); - __CPROVER_assume(_controller_states[j]!=zero_type); - #else - __CPROVER_assume(_controller_states[j]<=INITIALSTATE_UPPERBOUND && _controller_states[j]>=INITIALSTATE_LOWERBOUND); - __CPROVER_assume(_controller_states[j]!=zero_type); - #endif - #endif - } - - for(int k=0; kSAFE_STATE_UPPERBOUND || _controller_states[i].highSAFE_STATE_UPPERBOUND || _controller_states[i] 0); -} - -void safety_stability(void) { -#ifdef INTERVAL - get_bounds(); //get interval bounds -#endif - closed_loop(); //calculate A - BK - __CPROVER_EIGEN_charpoly(); - __DSVERIFIER_assert(check_stability()); -#if NSTATES != 1 - __DSVERIFIER_assert(check_safety()); -#endif - -#ifdef CPROVER - __controller_typet K_fxp_trace[NSTATES] = { controller_cast(0.0) }; - __CPROVER_array_copy(K_fxp_trace, K_fxp); - //__CPROVER_assert(0 == 1, ""); -#endif -} - -int main(void) { -#ifdef CPROVER - assume_corner_cases_for_states(); -#else - for (int poleIndex = 0; poleIndex < NPOLES; ++poleIndex) { - for (int stateIndex = 0; stateIndex < NSTATES; ++stateIndex) { - _controller_states[stateIndex] = _state_poles[poleIndex][poleIndex]; - } -#endif - assert_nonzero_controller(); - safety_stability(); -#ifndef CPROVER - } -#endif - return 0; -} diff --git a/regression/cegis/cegis_control_benchmark_03/test.desc b/regression/cegis/cegis_control_benchmark_03/test.desc deleted file mode 100644 index 3c618c8d745..00000000000 --- a/regression/cegis/cegis_control_benchmark_03/test.desc +++ /dev/null @@ -1,7 +0,0 @@ -CORE -safety_stability.c ---gcc --round-to-minus-inf --cegis-control --cegis-statistics --cegis-max-size 1 --cegis-show-iterations -D CPROVER -D _CONTROL_FLOAT_WIDTH=24 -D _CONTORL_RADIX_WIDTH=12 -D NUMBERLOOPS=10 -EXIT=0 -SIGNAL=0 --- -warning: ignoring diff --git a/regression/cegis/cegis_control_benchmark_04/benchmark.h b/regression/cegis/cegis_control_benchmark_04/benchmark.h deleted file mode 100644 index c5b3724cbb9..00000000000 --- a/regression/cegis/cegis_control_benchmark_04/benchmark.h +++ /dev/null @@ -1,11 +0,0 @@ -#define INT_BITS 12 -#define FRAC_BITS 12 -#include "control_types.h" - -#define NSTATES 3 -#define NINPUTS 1 -#define NOUTPUTS 1 -#define INPUT_LOWERBOUND (__plant_typet)-1 -#define INPUT_UPPERBOUND (__plant_typet)1 -const __plant_typet _controller_A[NSTATES][NSTATES] = { { interval(0.9905),interval(0.075687),interval(0.021033) }, { interval(0.125),interval(0),interval(0) }, { interval(0),interval(0.015625),interval(0) } }; -const __plant_typet _controller_B[NSTATES] = { interval(16), interval(0), interval(0) }; diff --git a/regression/cegis/cegis_control_benchmark_04/control_types.h b/regression/cegis/cegis_control_benchmark_04/control_types.h deleted file mode 100644 index 62bbffafb8a..00000000000 --- a/regression/cegis/cegis_control_benchmark_04/control_types.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * control_types.h - * - * Created on: 18 Jan 2017 - * Author: elipol - */ - -#ifndef CONTROL_TYPES_H_ -#define CONTROL_TYPES_H_ - -#ifdef CPROVER - #ifdef INTERVAL - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __plant_precisiont; - #include "intervals.h" - typedef struct intervalt __plant_typet; - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __controller_precisiont; - typedef struct intervalt __controller_typet; - #define interval(x) interval_cast(x); - #else - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] __plant_precisiont; - typedef __plant_precisiont __plant_typet; - typedef __CPROVER_fixedbv[INT_BITS+FRAC_BITS][FRAC_BITS] __controller_precisiont; - typedef __controller_precisiont __controller_typet; - #define plant_cast(x) ((__plant_typet)x) - #define controller_cast(x) ((__controller_typet)x) - #define interval(x) x - #endif -#else - #ifdef INTERVAL - typedef double __plant_precisiont; - #include "intervals.h" - typedef struct intervalt __plant_typet; - typedef double __controller_precisiont; //fixed point arithmetic is implemented using doubles - typedef struct intervalt __controller_typet; - #define interval(x) interval_cast(x) - #endif - #ifndef INTERVAL - typedef double __plant_precisiont; - typedef __plant_precisiont __plant_typet; - typedef double __controller_precisiont; //fixed point arithmetic is implemented using doubles - typedef __controller_precisiont __controller_typet; - #define interval(x) (x) - #define plant_cast(x) x - #define controller_cast(x) x - #endif -#endif - -#endif /* CONTROL_TYPES_H_ */ diff --git a/regression/cegis/cegis_control_benchmark_04/operators.h b/regression/cegis/cegis_control_benchmark_04/operators.h deleted file mode 100644 index 29b0e021af5..00000000000 --- a/regression/cegis/cegis_control_benchmark_04/operators.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * operators.h - * - * Created on: 18 Jan 2017 - * Author: elipol - */ - -#ifndef OPERATORS_H_ -#define OPERATORS_H_ - -#ifndef INTERVAL - #define controller_mult(x,y) ((x) *(y)) - #define mult(x,y) ( (x) * (y)) - - #define _abs(a) ( (a) < 0 ? -(a) : (a)) - #define add(x,y) ( (x) + (y)) - - #define lessthan(x,y) ((x)<(y)) - #define greaterthan(x,y) ((x)>(y)) - #define lessthanzero(x) ((x) < 0) - #define lessthan_equaltozero(x) ((x) <= 0) - #define zero_type 0 - #define one_type (__plant_precisiont)1.0 - #define minusone (__plant_precisiont)-1 - #define div(x,y) ( (x) / (y)) - #define sub(x,y) ( (x) - (y)) - #define set(x,y) (x)=(y) - - -#endif -#ifdef INTERVAL - - #define controller_mult(x,y) (interval_fxp_mult((x),(y))) - #define mult(x,y) ( interval_mult((x),(y))) - - #define _abs(a) ( abs_interval(a)) - - #define lessthan(x,y) (interval_lessthan(x,y)) - #define greaterthan(x,y) (interval_greaterthan((x),(y))) - #define add(x,y) (interval_add((x),(y))) - #define lessthanzero(x) (interval_lessthanzero(x)) - #define lessthan_equaltozero(x) (interval_lessthan_equal_to_zero(x)) - - #define zero_type (zero_interval) - #define minusone (minusone_interval) - #define one_type one_interval - #define div(x,y) (interval_posDiv((x),(y))) - #define sub(x,y) (interval_sub((x),(y))) - - #define controller_cast(x) (fxp_interval_check(x)) - #define plant_cast(x) x - #define set(x,y) (x.low=y, x.high=y) - - -#endif - -#endif /* OPERATORS_H_ */ diff --git a/regression/cegis/cegis_control_benchmark_04/safety_stability.c b/regression/cegis/cegis_control_benchmark_04/safety_stability.c deleted file mode 100644 index 786ac6ce87f..00000000000 --- a/regression/cegis/cegis_control_benchmark_04/safety_stability.c +++ /dev/null @@ -1,506 +0,0 @@ -#include -#include "benchmark.h" //benchmark header file -//#include "control_types.h" //included via benchmark.h -//#define CPROVER -//#ifdef INTERVAL - // #include "intervals.h" //included via control_types.h -//#endif -#include "operators.h" - -#ifdef CPROVER - //#define __DSVERIFIER_assert(x) __CPROVER_assume(x) - #define __DSVERIFIER_assert(x) __CPROVER_assert(x, "") -#else - #include - #define __DSVERIFIER_assert(x) assert(x) -#endif - -//#define NUMBERLOOPS 5 // Defined by benchmark script -#define INITIALSTATE_UPPERBOUND (__plant_precisiont)0.5 -#define INITIALSTATE_LOWERBOUND (__plant_precisiont)-0.5 -#define SAFE_STATE_UPPERBOUND (__plant_precisiont)1.0 -#define SAFE_STATE_LOWERBOUND (__plant_precisiont)-1.0 - -//other plant variables -//__controller_typet nondet_controller_type(void); - -extern __controller_typet K_fxp[NSTATES]; //nondet controller -//__controller_typet K_fxp[NSTATES]; //nondet controller -//const __controller_typet K_fxp[NSTATES] = { (__controller_typet) 0.0626, (__controller_typet) 0.0, (__controller_typet) 12.2421875 }; //nondet controller -//const __controller_typet K_fxp[NSTATES] = { 249.53271484375, 51.430419921875, -1887.991455078125 }; -//const __controller_typet K_fxp[NSTATES] = { 0.0626, 0.0, 12.2421875 }; -//const __controller_typet K_fxp[NSTATES] = {interval(0.0234375),interval(-0.1328125), interval(0.00390625)}; -__plant_typet _controller_inputs; -extern __plant_typet _controller_states[NSTATES]; //nondet initial states - -//matrices for stability calculation -__plant_typet _AminusBK[NSTATES][NSTATES]; - -__plant_typet __CPROVER_EIGEN_poly[NSTATES + 1u]; - -//stablity calc - -__plant_typet internal_pow(__plant_typet a, unsigned int b){ - - __plant_typet acc = one_type; - for (int i=0; i < b; i++){ - acc = mult(acc,a); - } - return acc; -} - - -int check_stability(void){ - - - #if NSTATES==1 - if(greaterthan(_AminusBK[0][0], 1) || lessthan(_AminusBK[0][0], -1)) - {return 0;} - else - {return 1;} -#endif - - -#define __a __CPROVER_EIGEN_poly -#define __n NSTATES + 1u - int lines = 2 * __n - 1; - int columns = __n; - __plant_typet m[lines][__n]; - int i,j; - - /* to put current values in stability counter-example - * look for current_stability (use: --no-slice) */ - __plant_typet current_stability[__n]; - for (i=0; i < __n; i++){ - current_stability[i] = __a[i]; - } - - /* check the first constraint condition F(1) > 0 */ - __plant_typet sum = zero_type; - for (i=0; i < __n; i++){ - sum = add(sum, __a[i]); - } - if (lessthan_equaltozero(sum)){ - printf("[DEBUG] the first constraint of Jury criteria failed: (F(1) > 0)"); - return 0; - } - - /* check the second constraint condition F(-1)*(-1)^n > 0 */ - sum = zero_type; - for (i=0; i < __n; i++){ - sum = add(sum, mult(__a[i] , internal_pow(minusone, NSTATES-i) )); - } - sum = mult(sum,internal_pow(minusone, NSTATES) ); - - if (lessthan_equaltozero(sum)){ - printf("[DEBUG] the second constraint of Jury criteria failed: (F(-1)*(-1)^n > 0)"); - return 0; - } - - /* check the third constraint condition abs(a0 < an*(z^n) */ - if(greaterthan( _abs(__a[__n-1]), __a[0])){ - // if (abs(__a[__n-1]) > __a[0]){ - printf("[DEBUG] the third constraint of Jury criteria failed: (abs(a0) < a_{n}*z^{n})"); - return 0; - } - - /* check the fourth constraint of condition (Jury Table) */ - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - m[i][j] = zero_type; - } - } - for (i=0; i < lines; i++){ - for (j=0; j < columns; j++){ - if (i == 0){ - m[i][j] = __a[j]; - continue; - } - if (i % 2 != 0 ){ - int x; - for(x=0; x= 0 ? 1 : 0; - for (i=0; i < lines; i++){ - if (i % 2 == 0){ - int line_is_positive = lessthanzero(m[i][0])? 0 : 1; - // int line_is_positive = m[i][0] >= 0 ? 1 : 0; - if (first_is_positive != line_is_positive){ - return 0; - } - continue; - } - } - return 1; -} - -#define __m _AminusBK -#if NSTATES==2 -void __CPROVER_EIGEN_charpoly_2(void) { //m00*m11 - m10*m11 - m00*x - m11*x + x^2 - - __CPROVER_EIGEN_poly[2] = sub ( mult(__m[0][0],__m[1][1]), mult(__m[1][0] , __m[1][1]) ); - - __CPROVER_EIGEN_poly[1] = sub (zero_type, add (__m[0][0], __m[1][1]) ) ; - // s^2 - __CPROVER_EIGEN_poly[0] = one_type; -} -#endif - -#if NSTATES==3 -void __CPROVER_EIGEN_charpoly_3(void) { -// m_11*m_22*m_33 + m_11*m_23*m_32 + m_12*m_21*m_33 - m_12*m_23*m_31 - m_13*m_21*m_32 + m_13*m_22*m_31 -__CPROVER_EIGEN_poly[3] = add(sub(sub(add(add(mult(__m[0][0],mult( __m[1][1], __m[2][2])), mult( __m[0][0] ,mult( __m[1][2] , __m[2][1]))), - mult(__m[0][1],mult( __m[1][0], __m[2][2]))), mult(__m[0][1],mult( __m[1][2], __m[2][0]) )), mult(__m[0][2] ,mult(__m[1][0], __m[2][1]))), - mult( __m[0][2], mult(__m[1][1],__m[2][0]))); -// (m_11*m_22 + m_11*m_33 - m_12*m_21 - m_13*m_31 + m_22*m_33 - m_23*m_32) * s -__CPROVER_EIGEN_poly[2] = sub(add(sub(sub(mult(__m[0][0], mult( __m[1][1], mult( __m[0][0], __m[2][2]))), mult(__m[0][1], __m[1][0])), - mult(__m[0][2],__m[2][0])), mult(__m[1][1], __m[2][2])),mult(__m[1][2], __m[2][1])); -// (-m_11 - m_22 - m_33) * s^2 -__CPROVER_EIGEN_poly[1] = sub(sub(sub(zero_type,__m[0][0]), __m[1][1]), __m[2][2]); -// s^3 -__CPROVER_EIGEN_poly[0] = one_type; - -} -#endif -#if NSTATES==4 -void __CPROVER_EIGEN_charpoly_4(void) { - - __CPROVER_EIGEN_poly[4] = __m[0][0]*__m[1][1]*__m[2][2]*__m[3][3] - __m[0][0]*__m[1][1]*__m[2][3]*__m[3][2] - __m[0][0]*__m[1][2]*__m[2][1]*__m[3][3] + __m[0][0]*__m[1][2]*__m[2][3]*__m[3][1] + __m[0][0]*__m[1][3]*__m[2][1]*__m[3][2] - - __m[0][0]*__m[1][3]*__m[2][2]*__m[3][1] - __m[0][1]*__m[1][0]*__m[2][2]*__m[3][3] + __m[0][1]*__m[1][0]*__m[2][3]*__m[3][2] + __m[0][1]*__m[1][2]*__m[2][0]*__m[3][3] - __m[0][1]*__m[1][2]*__m[2][3]*__m[3][0] - - __m[0][1]*__m[1][3]*__m[2][0]*__m[3][2] + __m[0][1]*__m[1][3]*__m[2][2]*__m[3][0] + __m[0][2]*__m[1][0]*__m[2][1]*__m[3][3] - __m[0][2]*__m[1][0]*__m[2][3]*__m[3][1] - __m[0][2]*__m[1][1]*__m[2][0]*__m[3][3] + - __m[0][2]*__m[1][1]*__m[2][3]*__m[3][0] + __m[0][2]*__m[1][3]*__m[2][0]*__m[3][1] - __m[0][2]*__m[1][3]*__m[2][1]*__m[3][0] - __m[0][3]*__m[1][0]*__m[2][1]*__m[3][2] + __m[0][3]*__m[1][0]*__m[2][2]*__m[3][1] + - __m[0][3]*__m[1][1]*__m[2][0]*__m[3][2] - __m[0][3]*__m[1][1]*__m[2][2]*__m[3][0] - __m[0][3]*__m[1][2]*__m[2][0]*__m[3][1] + __m[0][3]*__m[1][2]*__m[2][1]*__m[3][0]; - - -__CPROVER_EIGEN_poly[3] = - __m[0][0]*__m[1][1]*__m[2][2] + __m[0][0]*__m[1][2]*__m[2][1] + __m[0][1]*__m[1][0]*__m[2][2] - __m[0][1]*__m[1][2]*__m[2][0] - __m[0][2]*__m[1][0]*__m[2][1] + __m[0][2]*__m[1][1]*__m[2][0] - - __m[0][0]*__m[1][1]*__m[3][3] + __m[0][0]*__m[1][3]*__m[3][1] + __m[0][1]*__m[1][0]*__m[3][3] - __m[0][1]*__m[1][3]*__m[3][0] - __m[0][3]*__m[1][0]*__m[3][1] + __m[0][3]*__m[1][1]*__m[3][0] - - __m[0][0]*__m[2][2]*__m[3][3] + __m[0][0]*__m[2][3]*__m[3][2] + __m[0][2]*__m[2][0]*__m[3][3] - __m[0][2]*__m[2][3]*__m[3][0] - __m[0][3]*__m[2][0]*__m[3][2] + __m[0][3]*__m[2][2]*__m[3][0] - - __m[1][1]*__m[2][2]*__m[3][3] + __m[1][1]*__m[2][3]*__m[3][2] + __m[1][2]*__m[2][1]*__m[3][3] - __m[1][2]*__m[2][3]*__m[3][1] - __m[1][3]*__m[2][1]*__m[3][2] + __m[1][3]*__m[2][2]*__m[3][1]; - - - __CPROVER_EIGEN_poly[2] = + __m[0][0]*__m[1][1] - __m[0][1]*__m[1][0] + __m[0][0]*__m[2][2] - __m[0][2]*__m[2][0] + __m[0][0]*__m[3][3] - __m[0][3]*__m[3][0] + __m[1][1]*__m[2][2] - - __m[1][2]*__m[2][1] + __m[1][1]*__m[3][3] - __m[1][3]*__m[3][1] + __m[2][2]*__m[3][3] - __m[2][3]*__m[3][2]; - - - __CPROVER_EIGEN_poly[1] = - __m[3][3] - __m[2][2] - __m[1][1] - __m[0][0]; - __CPROVER_EIGEN_poly[0] = 1.0; -} -#endif - -void __CPROVER_EIGEN_charpoly(void){ - - #if NSTATES==1 - //do nothing - #elif NSTATES==2 - __CPROVER_EIGEN_charpoly_2(); - #elif NSTATES==3 - __CPROVER_EIGEN_charpoly_3(); - #elif NSTATES==4 - __CPROVER_EIGEN_charpoly_4(); - #endif - - // Normalise - __plant_typet max_coefficient=zero_type; - for (int i = 0; i <= NSTATES; ++i) - if (lessthan(max_coefficient, __CPROVER_EIGEN_poly[i])) - max_coefficient=__CPROVER_EIGEN_poly[i]; - - for (int i = 0; i <= NSTATES; ++i) - __CPROVER_EIGEN_poly[i]=div(__CPROVER_EIGEN_poly[i], max_coefficient); -} - -void A_minus_B_K() -{ - -#ifdef CPROVER - __CPROVER_array_copy(_AminusBK, _controller_A); -#else - for(int i=0; iINPUT_LOWERBOUND); - #else - __CPROVER_assume(_controller_inputs < INPUT_UPPERBOUND && _controller_inputs > INPUT_LOWERBOUND); - #endif - #endif - - } - } - -__plant_typet states_equals_A_states_plus_B_inputs_result[NSTATES]; - -void states_equals_A_states_plus_B_inputs(void) -{ - - #ifdef CPROVER - __CPROVER_array_set(states_equals_A_states_plus_B_inputs_result, zero_type); - #else - for(int i=0; iSAFE_STATE_LOWERBOUND); - __DSVERIFIER_assert( _controller_states[1]SAFE_STATE_LOWERBOUND); - #if NSTATES==3 || NSTATES==4 - __DSVERIFIER_assert( _controller_states[2]SAFE_STATE_LOWERBOUND); - #endif - #if NSTATES==4 - __DSVERIFIER_assert( _controller_states[3]SAFE_STATE_LOWERBOUND); - #endif -#else - for(int i=0; iSAFE_STATE_LOWERBOUND); - } -#endif -#else -#ifdef CPROVER - __CPROVER_array_copy(_controller_states, states_equals_A_states_plus_B_inputs_result); - /*for(i=0; iSAFE_STATE_LOWERBOUND); - __DSVERIFIER_assert( _controller_states[1].highSAFE_STATE_LOWERBOUND); - #if NSTATES==3 || NSTATES==4 - __DSVERIFIER_assert( _controller_states[2].highSAFE_STATE_LOWERBOUND); - #endif - #if NSTATES==4 - __DSVERIFIER_assert( _controller_states[3].highSAFE_STATE_LOWERBOUND); - #endif -#else - for(int i=0; iSAFE_STATE_LOWERBOUND); - } -#endif -#endif - - - - } - - - -int check_safety(void) -{ - - for(int j=0; j=INITIALSTATE_LOWERBOUND); - //__CPROVER_assume(_controller_states[j]!=zero_type); - //#else - //__CPROVER_assume(_controller_states[j]<=INITIALSTATE_UPPERBOUND && _controller_states[j]>=INITIALSTATE_LOWERBOUND); - //__CPROVER_assume(_controller_states[j]!=zero_type); - //#endif - #endif - } - - for(int k=0; kSAFE_STATE_UPPERBOUND || _controller_states[i].highSAFE_STATE_UPPERBOUND || _controller_states[i] 0); -} - -void safety_stability(void) { -#ifdef INTERVAL - get_bounds(); //get interval bounds -#endif - closed_loop(); //calculate A - BK - __CPROVER_EIGEN_charpoly(); - __DSVERIFIER_assert(check_stability()); -#if NSTATES != 1 - //check_safety(); - __DSVERIFIER_assert(check_safety()); -#endif - -#ifdef CPROVER - __controller_typet K_fxp_trace[NSTATES] = { controller_cast(0.0) }; - __CPROVER_array_copy(K_fxp_trace, K_fxp); - //__CPROVER_assert(0 == 1, ""); -#endif - - return 0; -} - -int main(void) { -#ifdef CPROVER - assume_corner_cases_for_states(); -#else - for (int poleIndex = 0; poleIndex < NPOLES; ++poleIndex) { - for (int stateIndex = 0; stateIndex < NSTATES; ++stateIndex) { - _controller_states[stateIndex] = _state_poles[poleIndex][poleIndex]; - } -#endif - assert_nonzero_controller(); - safety_stability(); - //__CPROVER_assert(0 == 1, ""); -#ifndef CPROVER - } -#endif - return 0; -} diff --git a/regression/cegis/cegis_control_benchmark_04/test.desc b/regression/cegis/cegis_control_benchmark_04/test.desc deleted file mode 100644 index 5c8ebf51923..00000000000 --- a/regression/cegis/cegis_control_benchmark_04/test.desc +++ /dev/null @@ -1,7 +0,0 @@ -CORE -safety_stability.c ---gcc --round-to-minus-inf --cegis-control --cegis-statistics --cegis-max-size 1 --cegis-show-iterations -D CPROVER -D _CONTROL_FLOAT_WIDTH=32 -D _CONTORL_RADIX_WIDTH=24 -D NUMBERLOOPS=10 -EXIT=0 -SIGNAL=0 --- -warning: ignoring diff --git a/regression/cegis/cegis_control_benchmark_05/SatelliteB2.c b/regression/cegis/cegis_control_benchmark_05/SatelliteB2.c deleted file mode 100644 index 65f807bfbeb..00000000000 --- a/regression/cegis/cegis_control_benchmark_05/SatelliteB2.c +++ /dev/null @@ -1,5311 +0,0 @@ -// tag-#anon#ST[ARR100{F64}$F64$'a'|S32'a_size'|U32'$pad0'|ARR100{F64}$F64$'b'|S32'b_size'|U32'$pad1'|F64'sample_time'|ARR100{F64}$F64$'a_uncertainty'|ARR100{F64}$F64$'b_uncertainty'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 144 -struct anonymous$0; - -// tag-#anon#ST[ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'A'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'B'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'C'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'D'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'states'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'outputs'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'inputs'|ARR20{ARR20{F64}$F64$}$ARR20{F64}$F64$$'K'|U32'nStates'|U32'nInputs'|U32'nOutputs'|U32'$pad0'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 156 -struct anonymous$1; - -// tag-#anon#ST[S32'int_bits'|S32'frac_bits'|F64'max'|F64'min'|S32'default_realization'|U32'$pad0'|F64'delta'|S32'scale'|U32'$pad1'|F64'max_error'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 171 -struct anonymous$3; - -// tag-#anon#ST[S32'push'|S32'in'|S32'sbiw'|S32'cli'|S32'out'|S32'std'|S32'ldd'|S32'subi'|S32'sbci'|S32'lsl'|S32'rol'|S32'add'|S32'adc'|S32'adiw'|S32'rjmp'|S32'mov'|S32'sbc'|S32'ld'|S32'rcall'|S32'cp'|S32'cpc'|S32'ldi'|S32'brge'|S32'pop'|S32'ret'|S32'st'|S32'brlt'|S32'cpi'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 183 -struct anonymous; - -// tag-#anon#ST[S64'clock'|S32'device'|U32'$pad0'|F64'cycle'|SYM#tag-#anon#ST[S32'push'|S32'in'|S32'sbiw'|S32'cli'|S32'out'|S32'std'|S32'ldd'|S32'subi'|S32'sbci'|S32'lsl'|S32'rol'|S32'add'|S32'adc'|S32'adiw'|S32'rjmp'|S32'mov'|S32'sbc'|S32'ld'|S32'rcall'|S32'cp'|S32'cpc'|S32'ldi'|S32'brge'|S32'pop'|S32'ret'|S32'st'|S32'brlt'|S32'cpi']#'assembly'] -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 215 -struct anonymous$2; - -#include - -#ifndef IEEE_FLOAT_EQUAL -#define IEEE_FLOAT_EQUAL(x,y) ((x)==(y)) -#endif -#ifndef IEEE_FLOAT_NOTEQUAL -#define IEEE_FLOAT_NOTEQUAL(x,y) ((x)!=(y)) -#endif - -// __DSVERIFIER_assert -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 35 -void __DSVERIFIER_assert(_Bool expression); -// __DSVERIFIER_assert_msg -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 39 -void __DSVERIFIER_assert_msg(_Bool expression, char *msg); -// __DSVERIFIER_assume -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 21 -void __DSVERIFIER_assume(_Bool expression); -// __assert_fail -// file /usr/include/assert.h line 67 -extern void __assert_fail(const char *, const char *, unsigned int, const char *) _Noreturn; -// call_closedloop_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 369 -void call_closedloop_verification_task(void *closedloop_verification_task); -// call_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 268 -void call_verification_task(void *verification_task); -// check_stability -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 59 -signed int check_stability(double *a, signed int n); -// check_stability_closedloop -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 70 -signed int check_stability_closedloop(double *a, signed int n, double *plant_num, signed int p_num_size, double *plant_den, signed int p_den_size); -// determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 498 -double determinant(double (*a)[20l], signed int n); -// double_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 315 -void double_add_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]); -// double_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 218 -void double_check_limit_cycle(double *y, signed int y_size); -// double_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 187 -void double_check_oscillations(double *y, signed int y_size); -// double_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 254 -void double_check_persistent_limit_cycle(double *y, signed int y_size); -// double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 83 -double double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_1_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 205 -double double_direct_form_1_MSP430(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 364 -void double_direct_form_1_impl2(double *x, signed int x_size, double *b, signed int b_size, double *a, signed int a_size, double *y); -// double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 102 -double double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 230 -double double_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 428 -void double_exp_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], unsigned int expNumber, double (*result)[20l]); -// double_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 337 -void double_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, double (*m1)[20l], double (*m2)[20l], double (*m3)[20l]); -// double_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 23 -double double_state_space_representation(void); -// double_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 326 -void double_sub_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]); -// double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 122 -double double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// double_transposed_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 257 -double double_transposed_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// exit -// file /usr/include/stdlib.h line 543 -extern void exit(signed int) _Noreturn; -// fatorial -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 54 -signed int fatorial(signed int n); -// float_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 144 -float float_direct_form_1(float *y, float *x, float *a, float *b, signed int Na, signed int Nb); -// float_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 163 -float float_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// float_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 183 -float float_transposed_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// ft_closedloop_feedback -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 57 -void ft_closedloop_feedback(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// ft_closedloop_sensitivity -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 42 -void ft_closedloop_sensitivity(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// ft_closedloop_series -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 28 -void ft_closedloop_series(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den); -// fxp_abs -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 303 -signed long int fxp_abs(signed long int a); -// fxp_add -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 315 -signed long int fxp_add(signed long int aadd, signed long int badd); -// fxp_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 467 -void fxp_add_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]); -// fxp_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 163 -void fxp_check_limit_cycle(signed long int *y, signed int y_size); -// fxp_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 253 -void fxp_check_oscillations(signed long int *y, signed int y_size); -// fxp_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 201 -void fxp_check_persistent_limit_cycle(signed long int *y, signed int y_size); -// fxp_determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 529 -double fxp_determinant(signed long int (*a_fxp)[20l], signed int n); -// fxp_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 22 -signed long int fxp_direct_form_1(signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 388 -void fxp_direct_form_1_impl2(signed long int *x, signed int x_size, signed long int *b, signed int b_size, signed long int *a, signed int a_size, signed long int *y); -// fxp_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 41 -signed long int fxp_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_div -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 357 -signed long int fxp_div(signed long int a, signed long int b); -// fxp_double_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 211 -signed long int fxp_double_to_fxp(double value); -// fxp_double_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 247 -void fxp_double_to_fxp_array(double *f, signed long int *r, signed int N); -// fxp_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 390 -void fxp_exp_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], unsigned int expNumber, signed long int (*result)[20l]); -// fxp_float_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 198 -signed long int fxp_float_to_fxp(float f); -// fxp_float_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 240 -void fxp_float_to_fxp_array(float *f, signed long int *r, signed int N); -// fxp_get_frac_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 125 -signed long int fxp_get_frac_part(signed long int in); -// fxp_get_int_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 115 -signed long int fxp_get_int_part(signed long int in); -// fxp_int_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 170 -signed long int fxp_int_to_fxp(signed int in); -// fxp_ln -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 288 -signed int fxp_ln(signed int x); -// fxp_log10 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 345 -double fxp_log10(double x); -// fxp_log10_low -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 333 -double fxp_log10_low(double x); -// fxp_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 368 -void fxp_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*m3)[20l]); -// fxp_mult -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 339 -signed long int fxp_mult(signed long int amult, signed long int bmult); -// fxp_neg -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 367 -signed long int fxp_neg(signed long int aneg); -// fxp_print_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 407 -void fxp_print_float(signed long int a); -// fxp_print_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 411 -void fxp_print_float_array(signed long int *a, signed int N); -// fxp_print_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 403 -void fxp_print_int(signed long int a); -// fxp_quantize -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 136 -signed long int fxp_quantize(signed long int aquant); -// fxp_shrl -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 390 -signed long int fxp_shrl(signed long int in, signed int shift); -// fxp_sign -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 380 -signed long int fxp_sign(signed long int a); -// fxp_square -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 399 -signed long int fxp_square(signed long int a); -// fxp_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 67 -double fxp_state_space_representation(void); -// fxp_sub -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 327 -signed long int fxp_sub(signed long int asub, signed long int bsub); -// fxp_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 474 -void fxp_sub_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]); -// fxp_to_double -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 271 -double fxp_to_double(signed long int fxp); -// fxp_to_double_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 291 -void fxp_to_double_array(double *f, signed long int *r, signed int N); -// fxp_to_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 264 -float fxp_to_float(signed long int fxp); -// fxp_to_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 284 -void fxp_to_float_array(float *f, signed long int *r, signed int N); -// fxp_to_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 182 -signed int fxp_to_int(signed long int fxp); -// fxp_transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 582 -void fxp_transpose(signed long int (*a)[20l], signed long int (*b)[20l], signed int n, signed int m); -// fxp_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 61 -signed long int fxp_transposed_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// fxp_verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 153 -void fxp_verify_overflow(signed long int value); -// fxp_verify_overflow_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 158 -void fxp_verify_overflow_array(signed long int *array, signed int n); -// generate_delta_coefficients -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 33 -void generate_delta_coefficients(double *vetor, double *out, signed int n, double delta); -// generic_timing_double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 286 -double generic_timing_double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 311 -double generic_timing_double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 338 -double generic_timing_double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// generic_timing_shift_l_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 20 -double generic_timing_shift_l_double(double zIn, double *z, signed int N); -// generic_timing_shift_r_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 37 -double generic_timing_shift_r_double(double zIn, double *z, signed int N); -// get_delta_transfer_function -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 52 -void get_delta_transfer_function(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta); -// get_delta_transfer_function_with_base -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 59 -void get_delta_transfer_function_with_base(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta); -// iirIIOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 428 -float iirIIOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// iirIItOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 452 -float iirIItOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb); -// iirIItOutTime_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 479 -double iirIItOutTime_double(double *w, double x, double *a, double *b, signed int Na, signed int Nb); -// iirOutBoth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 506 -void iirOutBoth(float *yf, float *xf, float *af, float *bf, float *sumf_ref, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int *sum_ref, signed int Na, signed int Nb); -// iirOutBothL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 586 -float iirOutBothL(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb); -// iirOutBothL2 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 626 -float iirOutBothL2(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb); -// iirOutFixedL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 536 -signed long int iirOutFixedL(signed long int *y, signed long int *x, signed long int xin, signed long int *a, signed long int *b, signed int Na, signed int Nb); -// iirOutFloatL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 561 -float iirOutFloatL(float *y, float *x, float xin, float *a, float *b, signed int Na, signed int Nb); -// initialization -// file /home/lucascordeiro/dsverifier/bmc/core/initialization.h line 24 -void initialization(); -// initialize_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 22 -void initialize_array(double *v, signed int n); -// initials -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 52 -extern void initials(); -// internal_abs -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 49 -double internal_abs(double a); -// internal_pow -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 39 -double internal_pow(double a, double b); -// nchoosek -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 23 -signed int nchoosek(signed int n, signed int k); -// nondet_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 27 -double nondet_double(); -// nondet_float -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 18 -float nondet_float(); -// nondet_int -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 17 -signed int nondet_int(); -// order -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 158 -signed int order(signed int Na, signed int Nb); -// poly_mult -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 165 -void poly_mult(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans); -// poly_sum -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 141 -void poly_sum(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans); -// print_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 305 -void print_array_elements(char *name, double *v, signed int n); -// print_fxp_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 419 -void print_fxp_array_elements(char *name, signed long int *v, signed int n); -// print_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 481 -void print_matrix(double (*matrix)[20l], unsigned int lines, unsigned int columns); -// printf -// file /usr/include/stdio.h line 362 -extern signed int printf(const char *, ...); -// rand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 417 -extern signed int rand(void); -// revert_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 30 -void revert_array(double *v, double *out, signed int n); -// shiftL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 53 -signed long int shiftL(signed long int zIn, signed long int *z, signed int N); -// shiftLDouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 119 -double shiftLDouble(double zIn, double *z, signed int N); -// shiftLboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 130 -void shiftLboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N); -// shiftLfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 75 -float shiftLfloat(float zIn, float *z, signed int N); -// shiftR -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 64 -signed long int shiftR(signed long int zIn, signed long int *z, signed int N); -// shiftRDdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 97 -double shiftRDdouble(double zIn, double *z, signed int N); -// shiftRboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 144 -void shiftRboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N); -// shiftRdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 108 -double shiftRdouble(double zIn, double *z, signed int N); -// shiftRfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 86 -float shiftRfloat(float zIn, float *z, signed int N); -// snrPoint -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 402 -float snrPoint(float *s, float *n, signed int blksz); -// snrPower -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 381 -float snrPower(float *s, float *n, signed int blksz); -// snrVariance -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 357 -float snrVariance(float *s, float *n, signed int blksz); -// srand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 423 -extern void srand(unsigned int seed); -// transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 571 -void transpose(double (*a)[20l], double (*b)[20l], signed int n, signed int m); -// validation -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 125 -void validation(); -// verify_controllability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 16 -signed int verify_controllability(void); -// verify_controllability_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 120 -signed int verify_controllability_double(void); -// verify_error -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error.h line 20 -signed int verify_error(void); -// verify_error_closedloop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_closedloop.h line 27 -signed int verify_error_closedloop(void); -// verify_error_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 20 -signed int verify_error_state_space(void); -// verify_generic_timing -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 25 -signed int verify_generic_timing(void); -// verify_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 111 -signed int verify_limit_cycle(void); -// verify_limit_cycle_closed_loop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 29 -signed int verify_limit_cycle_closed_loop(void); -// verify_limit_cycle_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 21 -signed int verify_limit_cycle_state_space(void); -// verify_minimum_phase -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_minimum_phase.h line 24 -signed int verify_minimum_phase(void); -// verify_observability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_observability.h line 19 -signed int verify_observability(void); -// verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 23 -signed int verify_overflow(void); -// verify_stability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability.h line 24 -signed int verify_stability(void); -// verify_stability_closedloop_using_dslib -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability_closedloop.h line 21 -signed int verify_stability_closedloop_using_dslib(void); -// verify_timing_msp_430 -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_timing_msp430.h line 22 -signed int verify_timing_msp_430(void); -// verify_zero_input_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_zero_input_limit_cycle.h line 16 -signed int verify_zero_input_limit_cycle(void); -// wrap -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 100 -signed long int wrap(signed long int kX, signed long int kLowerBound, signed long int kUpperBound); - -struct anonymous$0 -{ - // a - double a[100l]; - // a_size - signed int a_size; - // b - double b[100l]; - // b_size - signed int b_size; - // sample_time - double sample_time; - // a_uncertainty - double a_uncertainty[100l]; - // b_uncertainty - double b_uncertainty[100l]; -}; - -struct anonymous$1 -{ - // A - double A[20l][20l]; - // B - double B[20l][20l]; - // C - double C[20l][20l]; - // D - double D[20l][20l]; - // states - double states[20l][20l]; - // outputs - double outputs[20l][20l]; - // inputs - double inputs[20l][20l]; - // K - double K[20l][20l]; - // nStates - unsigned int nStates; - // nInputs - unsigned int nInputs; - // nOutputs - unsigned int nOutputs; -}; - -struct anonymous$3 -{ - // int_bits - signed int int_bits; - // frac_bits - signed int frac_bits; - // max - double max; - // min - double min; - // default_realization - signed int default_realization; - // delta - double delta; - // scale - signed int scale; - // max_error - double max_error; -}; - -struct anonymous -{ - // push - signed int push; - // in - signed int in; - // sbiw - signed int sbiw; - // cli - signed int cli; - // out - signed int out; - // std - signed int std; - // ldd - signed int ldd; - // subi - signed int subi; - // sbci - signed int sbci; - // lsl - signed int lsl; - // rol - signed int rol; - // add - signed int add; - // adc - signed int adc; - // adiw - signed int adiw; - // rjmp - signed int rjmp; - // mov - signed int mov; - // sbc - signed int sbc; - // ld - signed int ld; - // rcall - signed int rcall; - // cp - signed int cp; - // cpc - signed int cpc; - // ldi - signed int ldi; - // brge - signed int brge; - // pop - signed int pop; - // ret - signed int ret; - // st - signed int st; - // brlt - signed int brlt; - // cpi - signed int cpi; -}; - -struct anonymous$2 -{ - // clock - signed long int clock; - // device - signed int device; - // cycle - double cycle; - // assembly - struct anonymous assembly; -}; - - -// X_SIZE_VALUE -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 121 -signed int X_SIZE_VALUE=0; -// _controller -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 17 -extern struct anonymous$1 _controller; -// _dbl_max -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 45 -double _dbl_max; -// _dbl_min -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 46 -double _dbl_min; -// _fxp_fmask -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 49 -signed long int _fxp_fmask; -// _fxp_half -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 39 -signed long int _fxp_half; -// _fxp_imask -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 52 -signed long int _fxp_imask; -// _fxp_max -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 42 -signed long int _fxp_max; -// _fxp_min -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 41 -signed long int _fxp_min; -// _fxp_minus_one -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 40 -signed long int _fxp_minus_one; -// _fxp_one -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 38 -signed long int _fxp_one; -// controller -// file input.c line 3 -struct anonymous$0 controller={ .a={ 1.000000, (double)-4.200000e-1f, (double)-3.465000e-1f, (double)-3.915000e-2f, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .a_size=4, - .b={ 2.880000e+0, (double)-4.896000e+0f, 2.074000e+0, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_size=3, - .sample_time=1.000000, .a_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 } }; -// ds -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 17 -extern struct anonymous$0 ds; -// error_limit -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 18 -extern double error_limit; -// generic_timer -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 23 -signed int generic_timer=0; -// hw -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 18 -extern struct anonymous$2 hw; -// impl -// file input.c line 11 -struct anonymous$3 impl={ .int_bits=3, .frac_bits=7, .max=1.000000, .min=-1.000000, - .default_realization=0, .delta=0.000000, - .scale=1, .max_error=0.000000 }; -// nInputs -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 20 -extern signed int nInputs; -// nOutputs -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 21 -extern signed int nOutputs; -// nStates -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 19 -extern signed int nStates; -// next -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 416 -unsigned long int next=1ul; -// overflow_mode -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 122 -signed int overflow_mode=1; -// plant -// file input.c line 19 -struct anonymous$0 plant={ .a={ 1.000000, (double)-2.000000f, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .a_size=3, - .b={ 1.250000e-1, 1.250000e-1, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_size=2, - .sample_time=0.000000, .a_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 }, .b_uncertainty={ 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000 } }; -// plant_cbmc -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 46 -struct anonymous$0 plant_cbmc; -// rounding_mode -// file /home/lucascordeiro/dsverifier/bmc/core/definitions.h line 123 -signed int rounding_mode=0; -// scale_factor -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 55 -static const double scale_factor[31l]={ 1.000000, 2.000000, 4.000000, 8.000000, 16.000000, 32.000000, 64.000000, 128.000000, 256.000000, 512.000000, 1024.000000, 2048.000000, 4096.000000, 8192.000000, 16384.000000, 32768.000000, 65536.000000, 1.310720e+5, 2.621440e+5, 5.242880e+5, 1.048576e+6, 2.097152e+6, 4.194304e+6, 8.388608e+6, 1.677722e+7, 3.355443e+7, 6.710886e+7, 1.342177e+8, 2.684355e+8, 5.368709e+8, 1.073742e+9 }; -// scale_factor_inv -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 62 -static const double scale_factor_inv[31l]={ 1.000000, 5.000000e-1, 2.500000e-1, 1.250000e-1, 6.250000e-2, 3.125000e-2, 1.562500e-2, 7.812500e-3, 3.906250e-3, 1.953125e-3, 9.765625e-4, 4.882813e-4, 2.441406e-4, 1.220703e-4, 6.103516e-5, 3.051758e-5, 1.525879e-5, 7.629395e-6, 3.814697e-6, 1.907349e-6, 9.536743e-7, 4.768372e-7, 2.384186e-7, 1.192093e-7, 5.960465e-8, 2.980232e-8, 1.490116e-8, 7.450581e-9, 3.725290e-9, 1.862645e-9, 9.313230e-10 }; - -// __DSVERIFIER_assert -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 35 -void __DSVERIFIER_assert(_Bool expression) -{ - /* assertion expression */ - assert(expression != (_Bool)0); - if(!(expression == (_Bool)0)) - (void)0; - -} - -// __DSVERIFIER_assert_msg -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 39 -void __DSVERIFIER_assert_msg(_Bool expression, char *msg) -{ - printf("%c", msg); - /* assertion expression */ - assert(expression != (_Bool)0); - if(!(expression == (_Bool)0)) - (void)0; - -} - -// __DSVERIFIER_assume -// file /home/lucascordeiro/dsverifier/bmc/core/compatibility.h line 21 -void __DSVERIFIER_assume(_Bool expression) -{ - __CPROVER_assume(expression != (_Bool)0); -} - -// call_closedloop_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 369 -void call_closedloop_verification_task(void *closedloop_verification_task) -{ - _Bool base_case_executed=(_Bool)0; - signed int i=0; - i = 0; - for( ; !(i >= plant.b_size); i = i + 1) - { - if(plant.b_uncertainty[(signed long int)i] > 0.000000) - { - double call_closedloop_verification_task$$1$$1$$1$$1$$factor=(plant.b[(signed long int)i] * plant.b_uncertainty[(signed long int)i]) / 100.000000; - call_closedloop_verification_task$$1$$1$$1$$1$$factor = call_closedloop_verification_task$$1$$1$$1$$1$$factor < 0.000000 ? call_closedloop_verification_task$$1$$1$$1$$1$$factor * (double)-1 : call_closedloop_verification_task$$1$$1$$1$$1$$factor; - double call_closedloop_verification_task$$1$$1$$1$$1$$min=plant.b[(signed long int)i] - call_closedloop_verification_task$$1$$1$$1$$1$$factor; - double call_closedloop_verification_task$$1$$1$$1$$1$$max=plant.b[(signed long int)i] + call_closedloop_verification_task$$1$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_closedloop_verification_task$$1$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L9; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_closedloop_verification_task$$1$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - plant_cbmc.b[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$1; - if(plant_cbmc.b[(signed long int)i] >= call_closedloop_verification_task$$1$$1$$1$$1$$min) - tmp_if_expr$1 = plant_cbmc.b[(signed long int)i] <= call_closedloop_verification_task$$1$$1$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - } - - else - plant_cbmc.b[(signed long int)i] = plant.b[(signed long int)i]; - - __CPROVER_DUMP_L9: - ; - } - i = 0; - for( ; !(i >= plant.a_size); i = i + 1) - { - if(plant.a_uncertainty[(signed long int)i] > 0.000000) - { - double factor=(plant.a[(signed long int)i] * plant.a_uncertainty[(signed long int)i]) / 100.000000; - factor = factor < 0.000000 ? factor * (double)-1 : factor; - double min=plant.a[(signed long int)i] - factor; - double max=plant.a[(signed long int)i] + factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - goto __CPROVER_DUMP_L19; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - base_case_executed = (_Bool)0; - - plant_cbmc.a[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$2; - if(plant_cbmc.a[(signed long int)i] >= min) - tmp_if_expr$2 = plant_cbmc.a[(signed long int)i] <= max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - - else - plant_cbmc.a[(signed long int)i] = plant.a[(signed long int)i]; - - __CPROVER_DUMP_L19: - ; - } - ((void (*)())closedloop_verification_task)(); -} - -// call_verification_task -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 268 -void call_verification_task(void *verification_task) -{ - signed int i=0; - _Bool base_case_executed=(_Bool)0; - if((_Bool)0) - { - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - { - if(ds.b_uncertainty[(signed long int)i] > 0.000000) - { - double call_verification_task$$1$$1$$1$$1$$1$$factor=ds.b_uncertainty[(signed long int)i]; - call_verification_task$$1$$1$$1$$1$$1$$factor = call_verification_task$$1$$1$$1$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$1$$1$$1$$1$$factor * (double)-1 : call_verification_task$$1$$1$$1$$1$$1$$factor; - double min=ds.b[(signed long int)i] - call_verification_task$$1$$1$$1$$1$$1$$factor; - double max=ds.b[(signed long int)i] + call_verification_task$$1$$1$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$1$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L8; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$1$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.b[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$1; - if(ds.b[(signed long int)i] >= min) - tmp_if_expr$1 = ds.b[(signed long int)i] <= max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - } - - - __CPROVER_DUMP_L8: - ; - } - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - { - if(ds.a_uncertainty[(signed long int)i] > 0.000000) - { - double factor=ds.a_uncertainty[(signed long int)i]; - factor = factor < 0.000000 ? factor * (double)-1 : factor; - double call_verification_task$$1$$1$$2$$1$$1$$min=ds.a[(signed long int)i] - factor; - double call_verification_task$$1$$1$$2$$1$$1$$max=ds.a[(signed long int)i] + factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - goto __CPROVER_DUMP_L17; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.a[(signed long int)i] = nondet_double(); - _Bool tmp_if_expr$2; - if(ds.a[(signed long int)i] >= call_verification_task$$1$$1$$2$$1$$1$$min) - tmp_if_expr$2 = ds.a[(signed long int)i] <= call_verification_task$$1$$1$$2$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - - - __CPROVER_DUMP_L17: - ; - } - } - - else - { - signed int call_verification_task$$1$$2$$i=0; - call_verification_task$$1$$2$$i = 0; - for( ; !(call_verification_task$$1$$2$$i >= ds.b_size); call_verification_task$$1$$2$$i = call_verification_task$$1$$2$$i + 1) - { - if(ds.b_uncertainty[(signed long int)call_verification_task$$1$$2$$i] > 0.000000) - { - double call_verification_task$$1$$2$$1$$1$$1$$factor=(ds.b[(signed long int)call_verification_task$$1$$2$$i] * ds.b_uncertainty[(signed long int)call_verification_task$$1$$2$$i]) / 100.000000; - call_verification_task$$1$$2$$1$$1$$1$$factor = call_verification_task$$1$$2$$1$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$2$$1$$1$$1$$factor * (double)-1 : call_verification_task$$1$$2$$1$$1$$1$$factor; - double call_verification_task$$1$$2$$1$$1$$1$$min=ds.b[(signed long int)call_verification_task$$1$$2$$i] - call_verification_task$$1$$2$$1$$1$$1$$factor; - double call_verification_task$$1$$2$$1$$1$$1$$max=ds.b[(signed long int)call_verification_task$$1$$2$$i] + call_verification_task$$1$$2$$1$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$1$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L27; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$1$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.b[(signed long int)call_verification_task$$1$$2$$i] = nondet_double(); - _Bool tmp_if_expr$3; - if(ds.b[(signed long int)call_verification_task$$1$$2$$i] >= call_verification_task$$1$$2$$1$$1$$1$$min) - tmp_if_expr$3 = ds.b[(signed long int)call_verification_task$$1$$2$$i] <= call_verification_task$$1$$2$$1$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$3 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$3); - } - - - __CPROVER_DUMP_L27: - ; - } - call_verification_task$$1$$2$$i = 0; - for( ; !(call_verification_task$$1$$2$$i >= ds.a_size); call_verification_task$$1$$2$$i = call_verification_task$$1$$2$$i + 1) - { - if(ds.a_uncertainty[(signed long int)call_verification_task$$1$$2$$i] > 0.000000) - { - double call_verification_task$$1$$2$$2$$1$$1$$factor=(ds.a[(signed long int)call_verification_task$$1$$2$$i] * ds.a_uncertainty[(signed long int)call_verification_task$$1$$2$$i]) / 100.000000; - call_verification_task$$1$$2$$2$$1$$1$$factor = call_verification_task$$1$$2$$2$$1$$1$$factor < 0.000000 ? call_verification_task$$1$$2$$2$$1$$1$$factor * (double)-1 : call_verification_task$$1$$2$$2$$1$$1$$factor; - double call_verification_task$$1$$2$$2$$1$$1$$min=ds.a[(signed long int)call_verification_task$$1$$2$$i] - call_verification_task$$1$$2$$2$$1$$1$$factor; - double call_verification_task$$1$$2$$2$$1$$1$$max=ds.a[(signed long int)call_verification_task$$1$$2$$i] + call_verification_task$$1$$2$$2$$1$$1$$factor; - if((signed int)base_case_executed == 1 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$2$$1$$1$$factor, 0.000000)) - goto __CPROVER_DUMP_L36; - - else - if((signed int)base_case_executed == 0 && IEEE_FLOAT_EQUAL(call_verification_task$$1$$2$$2$$1$$1$$factor, 0.000000)) - base_case_executed = (_Bool)0; - - ds.a[(signed long int)call_verification_task$$1$$2$$i] = nondet_double(); - _Bool tmp_if_expr$4; - if(ds.a[(signed long int)call_verification_task$$1$$2$$i] >= call_verification_task$$1$$2$$2$$1$$1$$min) - tmp_if_expr$4 = ds.a[(signed long int)call_verification_task$$1$$2$$i] <= call_verification_task$$1$$2$$2$$1$$1$$max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$4 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$4); - } - - - __CPROVER_DUMP_L36: - ; - } - } - ((void (*)())verification_task)(); -} - -// check_stability -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 59 -signed int check_stability(double *a, signed int n) -{ - signed int lines=2 * n - 1; - signed int columns=n; - const signed long int columns$array_size0=(signed long int)n; - const signed long int columns$array_size1=(signed long int)lines; - double m[columns$array_size1][columns$array_size0]; - signed int i; - signed int j; - const signed long int j$array_size0=(signed long int)n; - double current_stability[j$array_size0]; - i = 0; - for( ; !(i >= n); i = i + 1) - current_stability[(signed long int)i] = a[(signed long int)i]; - double sum=0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - sum = sum + a[(signed long int)i]; - if(sum <= 0.000000) - { - printf("[DEBUG] the first constraint of Jury criteria failed: (F(1) > 0)"); - return 0; - } - - else - { - sum = 0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - { - double return_value_internal_pow$1=internal_pow((double)-1, (double)((n - 1) - i)); - sum = sum + a[(signed long int)i] * return_value_internal_pow$1; - } - double return_value_internal_pow$2=internal_pow((double)-1, (double)(n - 1)); - sum = sum * return_value_internal_pow$2; - if(sum <= 0.000000) - { - printf("[DEBUG] the second constraint of Jury criteria failed: (F(-1)*(-1)^n > 0)"); - return 0; - } - - else - { - double return_value_internal_abs$3=internal_abs(a[(signed long int)(n - 1)]); - if(return_value_internal_abs$3 > *a) - { - printf("[DEBUG] the third constraint of Jury criteria failed: (abs(a0) < a_{n}*z^{n})"); - return 0; - } - - else - { - i = 0; - for( ; !(i >= lines); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - m[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0; - for( ; !(i >= lines); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - if(i == 0) - m[(signed long int)i][(signed long int)j] = a[(signed long int)j]; - - else - if(!(i % 2 == 0)) - { - signed int x=0; - for( ; !(x >= columns); x = x + 1) - m[(signed long int)i][(signed long int)x] = m[(signed long int)(i - 1)][(signed long int)((columns - x) - 1)]; - columns = columns - 1; - j = columns; - } - - else - m[(signed long int)i][(signed long int)j] = m[(signed long int)(i - 2)][(signed long int)j] - (m[(signed long int)(i - 2)][(signed long int)columns] / m[(signed long int)(i - 2)][0l]) * m[(signed long int)(i - 1)][(signed long int)j]; - } - signed int first_is_positive=m[0l][0l] >= 0.000000 ? 1 : 0; - i = 0; - for( ; !(i >= lines); i = i + 1) - if(i % 2 == 0) - { - signed int line_is_positive=m[(signed long int)i][0l] >= 0.000000 ? 1 : 0; - if(!(first_is_positive == line_is_positive)) - return 0; - - } - - return 1; - } - } - } -} - -// check_stability_closedloop -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 70 -signed int check_stability_closedloop(double *a, signed int n, double *plant_num, signed int p_num_size, double *plant_den, signed int p_den_size) -{ - signed int columns=n; - const signed long int columns$array_size0=(signed long int)n; - const signed long int columns$array_size1=(signed long int)(2 * n - 1); - double m[columns$array_size1][columns$array_size0]; - signed int i; - signed int j; - signed int first_is_positive=0; - double *p_num=plant_num; - double *p_den=plant_den; - double sum=0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - sum = sum + a[(signed long int)i]; - __DSVERIFIER_assert(sum > 0.000000); - sum = 0.000000; - i = 0; - for( ; !(i >= n); i = i + 1) - { - double return_value_internal_pow$1=internal_pow((double)-1, (double)((n - 1) - i)); - sum = sum + a[(signed long int)i] * return_value_internal_pow$1; - } - double return_value_internal_pow$2=internal_pow((double)-1, (double)(n - 1)); - sum = sum * return_value_internal_pow$2; - __DSVERIFIER_assert(sum > 0.000000); - double return_value_internal_abs$3=internal_abs(a[(signed long int)(n - 1)]); - __DSVERIFIER_assert(return_value_internal_abs$3 < a[0l]); - i = 0; - for( ; !(i >= 2 * n + -1); i = i + 1) - { - j = 0; - for( ; !(j >= columns); j = j + 1) - { - m[(signed long int)i][(signed long int)j] = 0.000000; - if(i == 0) - m[(signed long int)i][(signed long int)j] = a[(signed long int)j]; - - else - if(!(i % 2 == 0)) - { - signed int x=0; - for( ; !(x >= columns); x = x + 1) - m[(signed long int)i][(signed long int)x] = m[(signed long int)(i - 1)][(signed long int)((columns - x) - 1)]; - columns = columns - 1; - j = columns; - } - - else - { - m[(signed long int)i][(signed long int)j] = m[(signed long int)(i - 2)][(signed long int)j] - (m[(signed long int)(i - 2)][(signed long int)columns] / m[(signed long int)(i - 2)][0l]) * m[(signed long int)(i - 1)][(signed long int)j]; - _Bool tmp_if_expr$4; - if(m[0l][0l] >= 0.000000) - tmp_if_expr$4 = m[(signed long int)i][0l] >= 0.000000 ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$4 = (_Bool)0; - __DSVERIFIER_assert(tmp_if_expr$4); - } - } - } - return 1; -} - -// determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 498 -double determinant(double (*a)[20l], signed int n) -{ - signed int i; - signed int j; - signed int j1; - signed int j2; - double det=0.000000; - double m[20l][20l]; - if(n >= 1) - { - if(n == 1) - det = a[0l][0l]; - - else - if(n == 2) - det = a[0l][0l] * a[1l][1l] - a[1l][0l] * a[0l][1l]; - - else - { - det = 0.000000; - j1 = 0; - for( ; !(j1 >= n); j1 = j1 + 1) - { - i = 0; - for( ; !(i >= -1 + n); i = i + 1) - { - i = 1; - for( ; !(i >= n); i = i + 1) - { - j2 = 0; - j = 0; - for( ; !(j >= n); j = j + 1) - if(!(j == j1)) - { - m[(signed long int)(i - 1)][(signed long int)j2] = a[(signed long int)i][(signed long int)j]; - j2 = j2 + 1; - } - - } - } - double return_value_internal_pow$1=internal_pow(-1.000000, 1.000000 + (double)j1 + 1.000000); - double return_value_determinant$2=determinant(m, n - 1); - det = det + return_value_internal_pow$1 * a[0l][(signed long int)j1] * return_value_determinant$2; - } - } - } - - return det; -} - -// double_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 315 -void double_add_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j] + m2[(signed long int)i][(signed long int)j]; - } -} - -// double_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 218 -void double_check_limit_cycle(double *y, signed int y_size) -{ - double reference=y[(signed long int)(y_size - 1)]; - signed int idx=0; - signed int window_size=1; - idx = y_size - 2; - for( ; idx >= 0; idx = idx - 1) - if(IEEE_FLOAT_NOTEQUAL(y[(signed long int)idx], reference)) - window_size = window_size + 1; - - else - break; - __DSVERIFIER_assume(window_size != y_size && window_size != 1); - printf("window_size %d\n", window_size); - signed int desired_elements=2 * window_size; - signed int found_elements=0; - idx = y_size - 1; - for( ; idx >= 0; idx = idx - 1) - if(!(-1 + y_size + -window_size >= idx)) - { - printf("%.0f == %.0f\n", y[(signed long int)idx], y[(signed long int)(idx - window_size)]); - signed int cmp_idx=idx - window_size; - _Bool tmp_if_expr$1; - if(cmp_idx >= 1) - tmp_if_expr$1 = IEEE_FLOAT_EQUAL(y[(signed long int)idx], y[(signed long int)(idx - window_size)]) ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - if(tmp_if_expr$1) - found_elements = found_elements + 2; - - else - break; - } - - printf("desired_elements %d\n", desired_elements); - printf("found_elements %d\n", found_elements); - __DSVERIFIER_assert(desired_elements != found_elements); -} - -// double_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 187 -void double_check_oscillations(double *y, signed int y_size) -{ - __DSVERIFIER_assume(IEEE_FLOAT_NOTEQUAL(y[0l], y[(signed long int)(y_size - 1)])); - signed int window_timer=0; - signed int window_count=0; - signed int i; - signed int j; - i = 2; - for( ; !(i >= y_size); i = i + 1) - { - signed int window_size=i; - j = 0; - for( ; !(j >= y_size); j = j + 1) - { - if(!(window_size >= window_timer)) - { - window_timer = 0; - window_count = 0; - } - - signed int window_index=j + window_size; - if(!(window_index >= y_size)) - { - if(IEEE_FLOAT_EQUAL(y[(signed long int)j], y[(signed long int)window_index])) - { - window_count = window_count + 1; - /* assertion !(window_count == window_size) */ - assert(!(window_count == window_size)); - if(!(window_count == window_size)) - (void)0; - - } - - } - - else - break; - window_timer = window_timer + 1; - } - } -} - -// double_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 254 -void double_check_persistent_limit_cycle(double *y, signed int y_size) -{ - signed int idy=0; - signed int count_same=0; - signed int window_size=0; - double reference=y[0l]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(IEEE_FLOAT_NOTEQUAL(y[(signed long int)idy], reference)) - window_size = window_size + 1; - - else - if(!(window_size == 0)) - break; - - else - count_same = count_same + 1; - window_size = window_size + count_same; - __DSVERIFIER_assume(window_size > 1 && window_size <= y_size / 2); - const signed long int reference$array_size0=(signed long int)window_size; - double lco_elements[reference$array_size0]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(idy >= window_size)) - lco_elements[(signed long int)idy] = y[(signed long int)idy]; - - idy = 0; - signed int lco_idy=0; - _Bool is_persistent=(_Bool)0; - while(!(idy >= y_size)) - { - signed int tmp_post$1=idy; - idy = idy + 1; - signed int tmp_post$2=lco_idy; - lco_idy = lco_idy + 1; - if(IEEE_FLOAT_EQUAL(y[(signed long int)tmp_post$1], lco_elements[(signed long int)tmp_post$2])) - is_persistent = (_Bool)0; - - else - { - is_persistent = (_Bool)0; - break; - } - if(lco_idy == window_size) - lco_idy = 0; - - } - __DSVERIFIER_assert((signed int)is_persistent == 0); -} - -// double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 83 -double double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - sum = sum / a[0l]; - return sum; -} - -// double_direct_form_1_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 205 -double double_direct_form_1_MSP430(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - timer1 = timer1 + 91; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 47; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 57; - } - timer1 = timer1 + 3; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return sum; -} - -// double_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 364 -void double_direct_form_1_impl2(double *x, signed int x_size, double *b, signed int b_size, double *a, signed int a_size, double *y) -{ - signed int i=0; - signed int j=0; - const signed long int j$array_size0=(signed long int)x_size; - double v[j$array_size0]; - i = 0; - for( ; !(i >= x_size); i = i + 1) - { - v[(signed long int)i] = 0.000000; - j = 0; - for( ; !(j >= b_size); j = j + 1) - { - if(!(i >= j)) - break; - - v[(signed long int)i] = v[(signed long int)i] + x[(signed long int)(i - j)] * b[(signed long int)j]; - } - } - y[0l] = v[0l]; - i = 1; - for( ; !(i >= x_size); i = i + 1) - { - y[(signed long int)i] = 0.000000; - y[(signed long int)i] = y[(signed long int)i] + v[(signed long int)i]; - j = 1; - for( ; !(j >= a_size); j = j + 1) - { - if(!(i >= j)) - break; - - y[(signed long int)i] = y[(signed long int)i] + y[(signed long int)(i - j)] * (double)-1 * a[(signed long int)j]; - } - } -} - -// double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 102 -double double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - } - return sum; -} - -// double_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 230 -double double_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - timer1 = timer1 + 71; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 54; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 46; - } - timer1 = timer1 + 38; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return sum; -} - -// double_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 428 -void double_exp_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], unsigned int expNumber, double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - unsigned int l; - double m2[20l][20l]; - if(expNumber == 0u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - if(i == j) - result[(signed long int)i][(signed long int)j] = 1.000000; - - else - result[(signed long int)i][(signed long int)j] = 0.000000; - } - } - - else - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j]; - } - if(!(expNumber == 1u)) - { - l = 1u; - for( ; !(l >= expNumber); l = l + 1u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - m2[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j]; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - { - k = 0u; - for( ; !(k >= columns); k = k + 1u) - result[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j] + m2[(signed long int)i][(signed long int)k] * m1[(signed long int)k][(signed long int)j]; - } - } - } - } - - } -} - -// double_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 337 -void double_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, double (*m1)[20l], double (*m2)[20l], double (*m3)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - if(j1 == i2) - { - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - m3[(signed long int)i][(signed long int)j] = 0.000000; - } - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - { - k = 0u; - for( ; !(k >= j1); k = k + 1u) - { - double mult=m1[(signed long int)i][(signed long int)k] * m2[(signed long int)k][(signed long int)j]; - m3[(signed long int)i][(signed long int)j] = m3[(signed long int)i][(signed long int)j] + m1[(signed long int)i][(signed long int)k] * m2[(signed long int)k][(signed long int)j]; - } - } - } - } - - else - printf("\nError! Operation invalid, please enter with valid matrices.\n"); -} - -// double_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 23 -double double_state_space_representation(void) -{ - double result1[20l][20l]; - double result2[20l][20l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0.000000; - result2[(signed long int)i][(signed long int)j] = 0.000000; - } - } - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - i = 1; - for( ; !(i >= 0); i = i + 1) - { - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.A, _controller.states, result1); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.B, _controller.inputs, result2); - double_add_matrix((unsigned int)nStates, 1u, result1, result2, _controller.states); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - } - return _controller.outputs[0l][0l]; -} - -// double_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 326 -void double_sub_matrix(unsigned int lines, unsigned int columns, double (*m1)[20l], double (*m2)[20l], double (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j] - m2[(signed long int)i][(signed long int)j]; - } -} - -// double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 122 -double double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - yout = yout / a[0l]; - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - } - return yout; -} - -// double_transposed_direct_form_2_MSP430 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 257 -double double_transposed_direct_form_2_MSP430(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double) timer1 * hw.cycle <= ds.sample_time */ - assert((double)timer1 * hw.cycle <= ds.sample_time); - if((double)timer1 * hw.cycle <= ds.sample_time) - (void)0; - - return yout; -} - -// fatorial -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 54 -signed int fatorial(signed int n) -{ - signed int tmp_if_expr$2; - signed int return_value_fatorial$1; - if(n == 0) - tmp_if_expr$2 = 1; - - else - { - return_value_fatorial$1=fatorial(n - 1); - tmp_if_expr$2 = n * return_value_fatorial$1; - } - return tmp_if_expr$2; -} - -// float_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 144 -float float_direct_form_1(float *y, float *x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *y_ptr; - float *b_ptr; - float *x_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - sum = sum / a[0l]; - return sum; -} - -// float_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 163 -float float_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *b_ptr; - float *w_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - } - w[0l] = w[0l] + x; - w[0l] = w[0l] / a[0l]; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - } - return sum; -} - -// float_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 183 -float float_transposed_direct_form_2(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *b_ptr; - float yout=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - yout = yout / a[0l]; - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - float *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - } - return yout; -} - -// ft_closedloop_feedback -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 57 -void ft_closedloop_feedback(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - Nans_num = (Nc_den + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - signed int Nnum_mult=(Nc_num + Nmodel_num) - 1; - const signed long int Nnum_mult$array_size0=(signed long int)Nans_den; - double den_mult[Nnum_mult$array_size0]; - const signed long int den_mult$array_size0=(signed long int)Nnum_mult; - double num_mult[den_mult$array_size0]; - poly_mult(c_num, Nc_num, model_num, Nmodel_num, num_mult, Nnum_mult); - poly_mult(c_den, Nc_den, model_den, Nmodel_den, den_mult, Nans_den); - poly_sum(num_mult, Nnum_mult, den_mult, Nans_den, ans_den, Nans_den); - poly_mult(c_den, Nc_den, model_num, Nmodel_num, ans_num, Nans_num); -} - -// ft_closedloop_sensitivity -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 42 -void ft_closedloop_sensitivity(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - signed int Nans_num_p=(Nc_num + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - Nans_num = (Nc_den + Nmodel_den) - 1; - const signed long int Nans_num_p$array_size0=(signed long int)Nans_num_p; - double num_mult[Nans_num_p$array_size0]; - poly_mult(c_den, Nc_den, model_den, Nmodel_den, ans_num, Nans_num); - poly_mult(c_num, Nc_num, model_num, Nmodel_num, num_mult, Nans_num_p); - poly_sum(ans_num, Nans_num, num_mult, Nans_num_p, ans_den, Nans_den); -} - -// ft_closedloop_series -// file /home/lucascordeiro/dsverifier/bmc/core/closed-loop.h line 28 -void ft_closedloop_series(double *c_num, signed int Nc_num, double *c_den, signed int Nc_den, double *model_num, signed int Nmodel_num, double *model_den, signed int Nmodel_den, double *ans_num, signed int Nans_num, double *ans_den, signed int Nans_den) -{ - Nans_num = (Nc_num + Nmodel_num) - 1; - Nans_den = (Nc_den + Nmodel_den) - 1; - const signed long int ft_closedloop_series$array_size0=(signed long int)Nans_den; - double den_mult[ft_closedloop_series$array_size0]; - poly_mult(c_num, Nc_num, model_num, Nmodel_num, ans_num, Nans_num); - poly_mult(c_den, Nc_den, model_den, Nmodel_den, den_mult, Nans_den); - poly_sum(ans_num, Nans_num, den_mult, Nans_den, ans_den, Nans_den); -} - -// fxp_abs -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 303 -signed long int fxp_abs(signed long int a) -{ - signed long int tmp=a < 0l ? -((signed long int)a) : a; - return tmp; -} - -// fxp_add -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 315 -signed long int fxp_add(signed long int aadd, signed long int badd) -{ - signed long int tmpadd=(signed long int)aadd + (signed long int)badd; - return tmpadd; -} - -// fxp_add_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 467 -void fxp_add_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j]=fxp_add(m1[(signed long int)i][(signed long int)j], m2[(signed long int)i][(signed long int)j]); - } -} - -// fxp_check_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 163 -void fxp_check_limit_cycle(signed long int *y, signed int y_size) -{ - signed long int reference=y[(signed long int)(y_size - 1)]; - signed int idx=0; - signed int window_size=1; - idx = y_size - 2; - for( ; idx >= 0; idx = idx - 1) - if(!(y[(signed long int)idx] == reference)) - window_size = window_size + 1; - - else - break; - __DSVERIFIER_assume(window_size != y_size && window_size != 1); - printf("window_size %d\n", window_size); - signed int desired_elements=2 * window_size; - signed int found_elements=0; - idx = y_size - 1; - for( ; idx >= 0; idx = idx - 1) - if(!(-1 + y_size + -window_size >= idx)) - { - printf("%.0f == %.0f\n", y[(signed long int)idx], y[(signed long int)(idx - window_size)]); - signed int cmp_idx=idx - window_size; - _Bool tmp_if_expr$1; - if(cmp_idx >= 1) - tmp_if_expr$1 = y[(signed long int)idx] == y[(signed long int)(idx - window_size)] ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - if(tmp_if_expr$1) - found_elements = found_elements + 2; - - else - break; - } - - __DSVERIFIER_assume(found_elements > 0); - printf("desired_elements %d\n", desired_elements); - printf("found_elements %d\n", found_elements); - __DSVERIFIER_assume(found_elements == desired_elements); - __DSVERIFIER_assert((_Bool)0); -} - -// fxp_check_oscillations -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 253 -void fxp_check_oscillations(signed long int *y, signed int y_size) -{ - _Bool tmp_if_expr$1; - if(!(*y == y[(signed long int)(-1 + y_size)])) - tmp_if_expr$1 = y[(signed long int)(y_size - 1)] != y[(signed long int)(y_size - 2)] ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$1 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$1); - signed int window_timer=0; - signed int window_count=0; - signed int i; - signed int j; - i = 2; - for( ; !(i >= y_size); i = i + 1) - { - signed int window_size=i; - j = 0; - for( ; !(j >= y_size); j = j + 1) - { - if(!(window_size >= window_timer)) - { - window_timer = 0; - window_count = 0; - } - - signed int window_index=j + window_size; - if(!(window_index >= y_size)) - { - if(y[(signed long int)j] == y[(signed long int)window_index]) - { - window_count = window_count + 1; - __DSVERIFIER_assert(!(window_count == window_size)); - } - - } - - else - break; - window_timer = window_timer + 1; - } - } -} - -// fxp_check_persistent_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 201 -void fxp_check_persistent_limit_cycle(signed long int *y, signed int y_size) -{ - signed int idy=0; - signed int count_same=0; - signed int window_size=0; - signed long int reference=y[0l]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(y[(signed long int)idy] == reference)) - window_size = window_size + 1; - - else - if(!(window_size == 0)) - break; - - else - count_same = count_same + 1; - window_size = window_size + count_same; - __DSVERIFIER_assume(window_size > 1 && window_size <= y_size / 2); - const signed long int reference$array_size0=(signed long int)window_size; - signed long int lco_elements[reference$array_size0]; - idy = 0; - for( ; !(idy >= y_size); idy = idy + 1) - if(!(idy >= window_size)) - lco_elements[(signed long int)idy] = y[(signed long int)idy]; - - idy = 0; - signed int lco_idy=0; - _Bool is_persistent=(_Bool)0; - while(!(idy >= y_size)) - { - signed int tmp_post$1=idy; - idy = idy + 1; - signed int tmp_post$2=lco_idy; - lco_idy = lco_idy + 1; - if(y[(signed long int)tmp_post$1] == lco_elements[(signed long int)tmp_post$2]) - is_persistent = (_Bool)0; - - else - { - is_persistent = (_Bool)0; - break; - } - if(lco_idy == window_size) - lco_idy = 0; - - } - __DSVERIFIER_assert((signed int)is_persistent == 0); -} - -// fxp_determinant -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 529 -double fxp_determinant(signed long int (*a_fxp)[20l], signed int n) -{ - signed int i; - signed int j; - signed int j1; - signed int j2; - double a[20l][20l]; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= n); j = j + 1) - a[(signed long int)i][(signed long int)j]=fxp_to_double(a_fxp[(signed long int)i][(signed long int)j]); - } - double det=0.000000; - double m[20l][20l]; - if(n >= 1) - { - if(n == 1) - det = a[0l][0l]; - - else - if(n == 2) - det = a[0l][0l] * a[1l][1l] - a[1l][0l] * a[0l][1l]; - - else - { - det = 0.000000; - j1 = 0; - for( ; !(j1 >= n); j1 = j1 + 1) - { - i = 0; - for( ; !(i >= -1 + n); i = i + 1) - { - i = 1; - for( ; !(i >= n); i = i + 1) - { - j2 = 0; - j = 0; - for( ; !(j >= n); j = j + 1) - if(!(j == j1)) - { - m[(signed long int)(i - 1)][(signed long int)j2] = a[(signed long int)i][(signed long int)j]; - j2 = j2 + 1; - } - - } - } - double return_value_internal_pow$1=internal_pow(-1.000000, 1.000000 + (double)j1 + 1.000000); - double return_value_determinant$2=determinant(m, n - 1); - det = det + return_value_internal_pow$1 * a[0l][(signed long int)j1] * return_value_determinant$2; - } - } - } - - return det; -} - -// fxp_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 22 -signed long int fxp_direct_form_1(signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$4=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$5=y_ptr; - y_ptr = y_ptr - 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_sub(sum, return_value_fxp_mult$6); - } - sum=fxp_div(sum, a[0l]); - signed long int return_value_fxp_quantize$7=fxp_quantize(sum); - return return_value_fxp_quantize$7; -} - -// fxp_direct_form_1_impl2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 388 -void fxp_direct_form_1_impl2(signed long int *x, signed int x_size, signed long int *b, signed int b_size, signed long int *a, signed int a_size, signed long int *y) -{ - signed int i=0; - signed int j=0; - const signed long int j$array_size0=(signed long int)x_size; - signed long int v[j$array_size0]; - i = 0; - for( ; !(i >= x_size); i = i + 1) - { - v[(signed long int)i] = 0l; - j = 0; - for( ; !(j >= b_size); j = j + 1) - { - if(!(i >= j)) - break; - - signed long int return_value_fxp_mult$1=fxp_mult(x[(signed long int)(i - j)], b[(signed long int)j]); - v[(signed long int)i]=fxp_add(v[(signed long int)i], return_value_fxp_mult$1); - } - } - y[0l] = v[0l]; - i = 1; - for( ; !(i >= x_size); i = i + 1) - { - y[(signed long int)i] = 0l; - y[(signed long int)i]=fxp_add(y[(signed long int)i], v[(signed long int)i]); - j = 1; - for( ; !(j >= a_size); j = j + 1) - { - if(!(i >= j)) - break; - - signed long int return_value_fxp_mult$2=fxp_mult(y[(signed long int)(i - j)], -a[(signed long int)j]); - y[(signed long int)i]=fxp_add(y[(signed long int)i], return_value_fxp_mult$2); - } - } -} - -// fxp_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 41 -signed long int fxp_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *b_ptr; - signed long int *w_ptr; - signed long int sum=0l; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j=1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - w[0l]=fxp_sub(w[0l], return_value_fxp_mult$3); - } - w[0l]=fxp_add(w[0l], x); - w[0l]=fxp_div(w[0l], a[0l]); - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - signed long int *tmp_post$4=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$5=w_ptr; - w_ptr = w_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_add(sum, return_value_fxp_mult$6); - } - signed long int return_value_fxp_quantize$7=fxp_quantize(sum); - return return_value_fxp_quantize$7; -} - -// fxp_div -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 357 -signed long int fxp_div(signed long int a, signed long int b) -{ - signed long int tmpdiv=(a << impl.frac_bits) / b; - return tmpdiv; -} - -// fxp_double_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 211 -signed long int fxp_double_to_fxp(double value) -{ - signed long int tmp; - double ftemp=value * scale_factor[(signed long int)impl.frac_bits]; - if(rounding_mode == 0) - { - if(value >= 0.000000) - tmp = (signed long int)(ftemp + 5.000000e-1); - - else - tmp = (signed long int)(ftemp - 5.000000e-1); - } - - else - if(rounding_mode == 1) - { - tmp = (signed long int)ftemp; - double residue=ftemp - (double)tmp; - if(value < 0.000000 && IEEE_FLOAT_NOTEQUAL(residue, 0.000000)) - { - ftemp = ftemp - 1.000000; - tmp = (signed long int)ftemp; - } - - } - - else - if(rounding_mode == 0) - tmp = (signed long int)ftemp; - - return tmp; -} - -// fxp_double_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 247 -void fxp_double_to_fxp_array(double *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - r[(signed long int)i]=fxp_double_to_fxp(f[(signed long int)i]); -} - -// fxp_exp_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 390 -void fxp_exp_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], unsigned int expNumber, signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int l; - unsigned int k; - signed long int m2[20l][20l]; - if(expNumber == 0u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - if(i == j) - result[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(1.000000); - - else - result[(signed long int)i][(signed long int)j] = 0l; - } - } - - else - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = m1[(signed long int)i][(signed long int)j]; - } - if(!(expNumber == 1u)) - { - l = 1u; - for( ; !(l >= expNumber); l = l + 1u) - { - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - m2[(signed long int)i][(signed long int)j] = result[(signed long int)i][(signed long int)j]; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j] = 0l; - } - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - { - k = 0u; - for( ; !(k >= columns); k = k + 1u) - { - signed long int return_value_fxp_mult$1=fxp_mult(m2[(signed long int)i][(signed long int)k], m1[(signed long int)k][(signed long int)j]); - result[(signed long int)i][(signed long int)j]=fxp_add(result[(signed long int)i][(signed long int)j], return_value_fxp_mult$1); - } - } - } - } - } - - } -} - -// fxp_float_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 198 -signed long int fxp_float_to_fxp(float f) -{ - signed long int tmp; - double ftemp=(double)f * scale_factor[(signed long int)impl.frac_bits]; - if(f >= 0.000000f) - tmp = (signed long int)(ftemp + 5.000000e-1); - - else - tmp = (signed long int)(ftemp - 5.000000e-1); - return tmp; -} - -// fxp_float_to_fxp_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 240 -void fxp_float_to_fxp_array(float *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - r[(signed long int)i]=fxp_float_to_fxp(f[(signed long int)i]); -} - -// fxp_get_frac_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 125 -signed long int fxp_get_frac_part(signed long int in) -{ - return in < 0l ? -(-in & _fxp_fmask) : in & _fxp_fmask; -} - -// fxp_get_int_part -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 115 -signed long int fxp_get_int_part(signed long int in) -{ - return in < 0l ? -(-in & _fxp_imask) : in & _fxp_imask; -} - -// fxp_int_to_fxp -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 170 -signed long int fxp_int_to_fxp(signed int in) -{ - signed long int lin=(signed long int)in * _fxp_one; - return lin; -} - -// fxp_ln -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 288 -signed int fxp_ln(signed int x) -{ - signed int t; - signed int y=0xA65AF; - if(!(x >= 0x8000)) - { - x = x << 16; - y = y - 0xB1721; - } - - if(!(x >= 0x800000)) - { - x = x << 8; - y = y - 0x58B91; - } - - if(!(x >= 0x8000000)) - { - x = x << 4; - y = y - 0x2C5C8; - } - - if(!(x >= 0x20000000)) - { - x = x << 2; - y = y - 0x162E4; - } - - if(!(x >= 0x40000000)) - { - x = x << 1; - y = y - 0xB172; - } - - t = x + (x >> 1); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x67CD; - } - - t = x + (x >> 2); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x3920; - } - - t = x + (x >> 3); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x1E27; - } - - t = x + (x >> 4); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0xF85; - } - - t = x + (x >> 5); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x7E1; - } - - t = x + (x >> 6); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x3F8; - } - - t = x + (x >> 7); - if((0x80000000u & (unsigned int)t) == 0u) - { - x = t; - y = y - 0x1FE; - } - - x = (signed int)(0x80000000u - (unsigned int)x); - y = y - (x >> 15); - return y; -} - -// fxp_log10 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 345 -double fxp_log10(double x) -{ - if(x > 32767.000000) - { - if(x > 1.073676e+9) - { - x = x / 1.073676e+9; - double return_value_fxp_log10_low$1=fxp_log10_low(x); - return return_value_fxp_log10_low$1 + 9.030873e+0; - } - - x = x / 32767.000000; - double return_value_fxp_log10_low$2=fxp_log10_low(x); - return return_value_fxp_log10_low$2 + 4.515437e+0; - } - - else - { - double return_value_fxp_log10_low$3=fxp_log10_low(x); - return return_value_fxp_log10_low$3; - } -} - -// fxp_log10_low -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 333 -double fxp_log10_low(double x) -{ - signed int xint=(signed int)(x * 65536.000000 + 5.000000e-1); - signed int lnum=fxp_ln(xint); - signed int lden=fxp_ln(655360); - return (double)lnum / (double)lden; -} - -// fxp_matrix_multiplication -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 368 -void fxp_matrix_multiplication(unsigned int i1, unsigned int j1, unsigned int i2, unsigned int j2, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*m3)[20l]) -{ - unsigned int i; - unsigned int j; - unsigned int k; - if(j1 == i2) - { - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - m3[(signed long int)i][(signed long int)j] = 0l; - } - i = 0u; - for( ; !(i >= i1); i = i + 1u) - { - j = 0u; - for( ; !(j >= j2); j = j + 1u) - { - k = 0u; - for( ; !(k >= j1); k = k + 1u) - { - signed long int return_value_fxp_mult$1=fxp_mult(m1[(signed long int)i][(signed long int)k], m2[(signed long int)k][(signed long int)j]); - m3[(signed long int)i][(signed long int)j]=fxp_add(m3[(signed long int)i][(signed long int)j], return_value_fxp_mult$1); - } - } - } - } - - else - printf("\nError! Operation invalid, please enter with valid matrices.\n"); -} - -// fxp_mult -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 339 -signed long int fxp_mult(signed long int amult, signed long int bmult) -{ - signed long int tmpmult; - signed long int tmpmultprec; - tmpmult = (signed long int)((signed long int)amult * (signed long int)bmult); - if(tmpmult >= 0l) - tmpmultprec = tmpmult + ((tmpmult & (signed long int)(1 << impl.frac_bits - 1)) << 1) >> impl.frac_bits; - - else - tmpmultprec = -(-tmpmult + ((-tmpmult & (signed long int)(1 << impl.frac_bits - 1)) << 1) >> impl.frac_bits); - return tmpmultprec; -} - -// fxp_neg -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 367 -signed long int fxp_neg(signed long int aneg) -{ - signed long int tmpneg=-((signed long int)aneg); - return tmpneg; -} - -// fxp_print_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 407 -void fxp_print_float(signed long int a) -{ - float return_value_fxp_to_float$1=fxp_to_float(a); - printf("\n%f", return_value_fxp_to_float$1); -} - -// fxp_print_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 411 -void fxp_print_float_array(signed long int *a, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - { - float return_value_fxp_to_float$1=fxp_to_float(a[(signed long int)i]); - printf("\n%f", return_value_fxp_to_float$1); - } -} - -// fxp_print_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 403 -void fxp_print_int(signed long int a) -{ - printf("\n%i", (signed int)a); -} - -// fxp_quantize -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 136 -signed long int fxp_quantize(signed long int aquant) -{ - if(overflow_mode == 2) - { - if(!(aquant >= _fxp_min)) - return _fxp_min; - - else - if(!(_fxp_max >= aquant)) - return _fxp_max; - - } - - else - if(overflow_mode == 3) - { - if(!(_fxp_max >= aquant) || !(aquant >= _fxp_min)) - { - signed long int return_value_wrap$1=wrap(aquant, _fxp_min, _fxp_max); - return return_value_wrap$1; - } - - } - - return (signed long int)aquant; -} - -// fxp_shrl -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 390 -signed long int fxp_shrl(signed long int in, signed int shift) -{ - return (signed long int)((unsigned int)in >> shift); -} - -// fxp_sign -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 380 -signed long int fxp_sign(signed long int a) -{ - return a == 0l ? 0l : (a < 0l ? _fxp_minus_one : _fxp_one); -} - -// fxp_square -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 399 -signed long int fxp_square(signed long int a) -{ - signed long int return_value_fxp_mult$1=fxp_mult(a, a); - return return_value_fxp_mult$1; -} - -// fxp_state_space_representation -// file /home/lucascordeiro/dsverifier/bmc/core/state-space.h line 67 -double fxp_state_space_representation(void) -{ - signed long int result1[20l][20l]; - signed long int result2[20l][20l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0l; - result2[(signed long int)i][(signed long int)j] = 0l; - } - } - signed long int A_fpx[20l][20l]; - signed long int B_fpx[20l][20l]; - signed long int C_fpx[20l][20l]; - signed long int D_fpx[20l][20l]; - signed long int states_fpx[20l][20l]; - signed long int inputs_fpx[20l][20l]; - signed long int outputs_fpx[20l][20l]; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - D_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - states_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - inputs_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - outputs_fpx[(signed long int)i][(signed long int)j] = 0l; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.B[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.C[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - D_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.D[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - states_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.states[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - inputs_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.inputs[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - outputs_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.outputs[(signed long int)i][(signed long int)j]); - } - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, C_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, D_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nOutputs, 1u, result1, result2, outputs_fpx); - i = 1; - for( ; !(i >= 0); i = i + 1) - { - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, A_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, B_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nStates, 1u, result1, result2, states_fpx); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, C_fpx, states_fpx, result1); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, D_fpx, inputs_fpx, result2); - fxp_add_matrix((unsigned int)nOutputs, 1u, result1, result2, outputs_fpx); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.states[(signed long int)i][(signed long int)j]=fxp_to_double(states_fpx[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.outputs[(signed long int)i][(signed long int)j]=fxp_to_double(outputs_fpx[(signed long int)i][(signed long int)j]); - } - return _controller.outputs[0l][0l]; -} - -// fxp_sub -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 327 -signed long int fxp_sub(signed long int asub, signed long int bsub) -{ - signed long int tmpsub=(signed long int)((signed long int)asub - (signed long int)bsub); - return tmpsub; -} - -// fxp_sub_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 474 -void fxp_sub_matrix(unsigned int lines, unsigned int columns, signed long int (*m1)[20l], signed long int (*m2)[20l], signed long int (*result)[20l]) -{ - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - result[(signed long int)i][(signed long int)j]=fxp_sub(m1[(signed long int)i][(signed long int)j], m2[(signed long int)i][(signed long int)j]); - } -} - -// fxp_to_double -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 271 -double fxp_to_double(signed long int fxp) -{ - double f; - signed int f_int=(signed int)fxp; - f = (double)f_int * scale_factor_inv[(signed long int)impl.frac_bits]; - return f; -} - -// fxp_to_double_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 291 -void fxp_to_double_array(double *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - f[(signed long int)i]=fxp_to_double(r[(signed long int)i]); -} - -// fxp_to_float -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 264 -float fxp_to_float(signed long int fxp) -{ - float f; - signed int f_int=(signed int)fxp; - f = (float)((double)f_int * scale_factor_inv[(signed long int)impl.frac_bits]); - return f; -} - -// fxp_to_float_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 284 -void fxp_to_float_array(float *f, signed long int *r, signed int N) -{ - signed int i=0; - for( ; !(i >= N); i = i + 1) - f[(signed long int)i]=fxp_to_float(r[(signed long int)i]); -} - -// fxp_to_int -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 182 -signed int fxp_to_int(signed long int fxp) -{ - if(fxp >= 0l) - fxp = fxp + _fxp_half; - - else - fxp = fxp - _fxp_half; - fxp = fxp >> impl.frac_bits; - return (signed int)fxp; -} - -// fxp_transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 582 -void fxp_transpose(signed long int (*a)[20l], signed long int (*b)[20l], signed int n, signed int m) -{ - signed int i; - signed int j; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= m); j = j + 1) - b[(signed long int)j][(signed long int)i] = a[(signed long int)i][(signed long int)j]; - } -} - -// fxp_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 61 -signed long int fxp_transposed_direct_form_2(signed long int *w, signed long int x, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *b_ptr; - signed long int yout=0l; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int return_value_fxp_mult$2=fxp_mult(*tmp_post$1, x); - yout=fxp_add(return_value_fxp_mult$2, w[0l]); - yout=fxp_div(yout, a[0l]); - signed int j=0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - signed long int *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - signed long int return_value_fxp_mult$4=fxp_mult(*tmp_post$3, yout); - w[(signed long int)j]=fxp_sub(w[(signed long int)j], return_value_fxp_mult$4); - } - - if(!(j >= -1 + Nb)) - { - signed long int *tmp_post$5=b_ptr; - b_ptr = b_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$5, x); - w[(signed long int)j]=fxp_add(w[(signed long int)j], return_value_fxp_mult$6); - } - - } - signed long int return_value_fxp_quantize$7=fxp_quantize(yout); - return return_value_fxp_quantize$7; -} - -// fxp_verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 153 -void fxp_verify_overflow(signed long int value) -{ - fxp_quantize(value); - __DSVERIFIER_assert(value <= _fxp_max && value >= _fxp_min); -} - -// fxp_verify_overflow_array -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 158 -void fxp_verify_overflow_array(signed long int *array, signed int n) -{ - signed int i=0; - i = 0; - for( ; !(i >= n); i = i + 1) - fxp_verify_overflow(array[(signed long int)i]); -} - -// generate_delta_coefficients -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 33 -void generate_delta_coefficients(double *vetor, double *out, signed int n, double delta) -{ - signed int i; - signed int j; - signed int N=n - 1; - double sum_delta_operator; - i = 0; - for( ; N >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$1=nchoosek(N - j, i - j); - sum_delta_operator = sum_delta_operator + vetor[(signed long int)j] * (double)return_value_nchoosek$1; - } - double return_value_internal_pow$2=internal_pow(delta, (double)(N - i)); - out[(signed long int)i] = return_value_internal_pow$2 * sum_delta_operator; - } -} - -// generic_timing_double_direct_form_1 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 286 -double generic_timing_double_direct_form_1(double *y, double *x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 6 * hw.assembly.push + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 3 * hw.assembly.out + 12 * hw.assembly.std; - double *a_ptr; - double *y_ptr; - double *b_ptr; - double *x_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - generic_timer = generic_timer + 12 * hw.assembly.std + 12 * hw.assembly.ldd + 2 * hw.assembly.subi + 2 * hw.assembly.sbci + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 1 * hw.assembly.adiw; - signed int i; - signed int j; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - generic_timer = generic_timer + 20 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.sbc + 10 * hw.assembly.std + 2 * hw.assembly.ld + 2 * hw.assembly.rcall + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.adiw + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - generic_timer = generic_timer + 2 * hw.assembly.ldi + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - generic_timer = generic_timer + 22 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.subi + 8 * hw.assembly.std + 1 * hw.assembly.sbci + 2 * hw.assembly.ld + 2 * hw.assembly.rcall + 1 * hw.assembly.sbc + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.adiw + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - double *tmp_post$3=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$4=y_ptr; - y_ptr = y_ptr - 1l; - sum = sum - *tmp_post$3 * *tmp_post$4; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli + 3 * hw.assembly.out + 6 * hw.assembly.pop + 1 * hw.assembly.ret; - return sum; -} - -// generic_timing_double_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 311 -double generic_timing_double_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 8 * hw.assembly.push + 14 * hw.assembly.std + 3 * hw.assembly.out + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli; - double *a_ptr; - double *b_ptr; - double *w_ptr; - double sum=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - generic_timer = generic_timer + 10 * hw.assembly.std + 6 * hw.assembly.ldd + 2 * hw.assembly.adiw; - generic_timer = generic_timer + 2 * hw.assembly.ldi + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - double *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - double *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - generic_timer = generic_timer + 23 * hw.assembly.ldd + 32 * hw.assembly.mov + 9 * hw.assembly.std + 2 * hw.assembly.subi + 3 * hw.assembly.ld + 2 * hw.assembly.rcall + 2 * hw.assembly.sbci + 1 * hw.assembly.st + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brge; - } - w[0l] = w[0l] + x; - w_ptr = &w[0l]; - generic_timer = generic_timer + 13 * hw.assembly.ldd + 12 * hw.assembly.mov + 5 * hw.assembly.std + 1 * hw.assembly.st + 1 * hw.assembly.ld + 1 * hw.assembly.rcall; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - double *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - generic_timer = generic_timer + 20 * hw.assembly.ldd + 24 * hw.assembly.mov + 10 * hw.assembly.std + 2 * hw.assembly.rcall + 2 * hw.assembly.ld + 2 * hw.assembly.subi + 2 * hw.assembly.sbci + 1 * hw.assembly.adiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brge + 1 * hw.assembly.rjmp; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli + 3 * hw.assembly.out + 8 * hw.assembly.pop + 1 * hw.assembly.ret; - return sum; -} - -// generic_timing_double_transposed_direct_form_2 -// file /home/lucascordeiro/dsverifier/bmc/core/realizations.h line 338 -double generic_timing_double_transposed_direct_form_2(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - generic_timer = generic_timer + 8 * hw.assembly.push + 14 * hw.assembly.std + 3 * hw.assembly.out + 3 * hw.assembly.in + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - generic_timer = generic_timer + 15 * hw.assembly.std + 22 * hw.assembly.ldd + 24 * hw.assembly.mov + 2 * hw.assembly.rcall + 2 * hw.assembly.ld + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.brge + 1 * hw.assembly.adiw; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - } - - generic_timer = generic_timer + 70 * hw.assembly.mov + 65 * hw.assembly.ldd + 12 * hw.assembly.lsl + 12 * hw.assembly.rol + 15 * hw.assembly.std + 6 * hw.assembly.add + 6 * hw.assembly.adc + 2 * hw.assembly.adiw + 3 * hw.assembly.cpc + 3 * hw.assembly.cp + 5 * hw.assembly.ld + 4 * hw.assembly.rcall + 5 * hw.assembly.subi + 3 * hw.assembly.rjmp + 2 * hw.assembly.brlt + 3 * hw.assembly.st + 2 * hw.assembly.sbci + 3 * hw.assembly.sbc + 1 * hw.assembly.brge; - } - generic_timer = generic_timer + 4 * hw.assembly.ldd + 4 * hw.assembly.mov + 8 * hw.assembly.pop + 3 * hw.assembly.out + 1 * hw.assembly.in + 1 * hw.assembly.cli + 1 * hw.assembly.adiw + 1 * hw.assembly.ret; - return yout; -} - -// generic_timing_shift_l_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 20 -double generic_timing_shift_l_double(double zIn, double *z, signed int N) -{ - generic_timer = generic_timer + 2 * hw.assembly.push + 3 * hw.assembly.in + 3 * hw.assembly.out + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 8 * hw.assembly.std; - signed int i; - double zOut=z[0l]; - generic_timer = generic_timer + 5 * hw.assembly.ldd + 2 * hw.assembly.mov + 4 * hw.assembly.std + 1 * hw.assembly.ld; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - { - generic_timer = generic_timer + 17 * hw.assembly.ldd + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 6 * hw.assembly.mov + 2 * hw.assembly.adiw + 5 * hw.assembly.std + 1 * hw.assembly.ld + 1 * hw.assembly.st + 1 * hw.assembly.subi + 1 * hw.assembly.sbc + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - z[(signed long int)i] = z[(signed long int)(i + 1)]; - } - z[(signed long int)(N - 1)] = zIn; - generic_timer = generic_timer + 12 * hw.assembly.ldd + 6 * hw.assembly.mov + 3 * hw.assembly.std + 2 * hw.assembly.lsl + 2 * hw.assembly.rol + 1 * hw.assembly.adc + 1 * hw.assembly.add + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.st + 1 * hw.assembly.adiw + 1 * hw.assembly.in + 1 * hw.assembly.cli; - generic_timer = generic_timer + 3 * hw.assembly.out + 2 * hw.assembly.pop + 1 * hw.assembly.ret; - return zOut; -} - -// generic_timing_shift_r_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 37 -double generic_timing_shift_r_double(double zIn, double *z, signed int N) -{ - generic_timer = generic_timer + 2 * hw.assembly.push + 3 * hw.assembly.in + 3 * hw.assembly.out + 1 * hw.assembly.sbiw + 1 * hw.assembly.cli + 8 * hw.assembly.std; - signed int i; - double zOut=z[(signed long int)(N - 1)]; - generic_timer = generic_timer + 7 * hw.assembly.ldd + 2 * hw.assembly.rol + 2 * hw.assembly.lsl + 2 * hw.assembly.mov + 4 * hw.assembly.std + 1 * hw.assembly.add + 1 * hw.assembly.adc + 1 * hw.assembly.ld + 1 * hw.assembly.subi + 1 * hw.assembly.sbci; - generic_timer = generic_timer + 2 * hw.assembly.ldd + 2 * hw.assembly.std + 1 * hw.assembly.sbiw + 1 * hw.assembly.rjmp; - i = N - 1; - for( ; i >= 1; i = i - 1) - { - z[(signed long int)i] = z[(signed long int)(i - 1)]; - generic_timer = generic_timer + 15 * hw.assembly.ldd + 4 * hw.assembly.lsl + 4 * hw.assembly.rol + 2 * hw.assembly.add + 2 * hw.assembly.adc + 4 * hw.assembly.mov + 5 * hw.assembly.std + 1 * hw.assembly.subi + 1 * hw.assembly.sbci + 1 * hw.assembly.ld + 1 * hw.assembly.st + 1 * hw.assembly.sbiw + 1 * hw.assembly.cp + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - } - z[0l] = zIn; - generic_timer = generic_timer + 10 * hw.assembly.ldd + 5 * hw.assembly.mov + 3 * hw.assembly.std + 3 * hw.assembly.out + 2 * hw.assembly.pop + 1 * hw.assembly.ret + 1 * hw.assembly.ret + 1 * hw.assembly.cli + 1 * hw.assembly.in + 1 * hw.assembly.st + 1 * hw.assembly.adiw; - return zOut; -} - -// get_delta_transfer_function -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 52 -void get_delta_transfer_function(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta) -{ - generate_delta_coefficients(b, b_out, b_size, delta); - generate_delta_coefficients(a, a_out, a_size, delta); -} - -// get_delta_transfer_function_with_base -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 59 -void get_delta_transfer_function_with_base(double *b, double *b_out, signed int b_size, double *a, double *a_out, signed int a_size, double delta) -{ - signed int i; - signed int j; - signed int N=a_size - 1; - signed int M=b_size - 1; - double sum_delta_operator; - i = 0; - for( ; N >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$1=nchoosek(N - j, i - j); - sum_delta_operator = sum_delta_operator + a[(signed long int)j] * (double)return_value_nchoosek$1; - } - double return_value_internal_pow$2=internal_pow(delta, (double)(N - i)); - a_out[(signed long int)i] = return_value_internal_pow$2 * sum_delta_operator; - } - i = 0; - for( ; M >= i; i = i + 1) - { - sum_delta_operator = 0.000000; - j = 0; - for( ; i >= j; j = j + 1) - { - signed int return_value_nchoosek$3=nchoosek(M - j, i - j); - sum_delta_operator = sum_delta_operator + b[(signed long int)j] * (double)return_value_nchoosek$3; - } - double return_value_internal_pow$4=internal_pow(delta, (double)(M - i)); - b_out[(signed long int)i] = return_value_internal_pow$4 * sum_delta_operator; - } -} - -// iirIIOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 428 -float iirIIOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - float *a_ptr; - float *b_ptr; - float *w_ptr; - float sum=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - w_ptr = &w[1l]; - signed int k; - signed int j; - timer1 = timer1 + 71; - j = 1; - for( ; !(j >= Na); j = j + 1) - { - float *tmp_post$1=a_ptr; - a_ptr = a_ptr + 1l; - float *tmp_post$2=w_ptr; - w_ptr = w_ptr + 1l; - w[0l] = w[0l] - *tmp_post$1 * *tmp_post$2; - timer1 = timer1 + 54; - } - w[0l] = w[0l] + x; - w_ptr = &w[0l]; - k = 0; - for( ; !(k >= Nb); k = k + 1) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - float *tmp_post$4=w_ptr; - w_ptr = w_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - timer1 = timer1 + 46; - } - timer1 = timer1 + 38; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return sum; -} - -// iirIItOutTime -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 452 -float iirIItOutTime(float *w, float x, float *a, float *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - float *a_ptr; - float *b_ptr; - float yout=0.000000f; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - float *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - float *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return yout; -} - -// iirIItOutTime_double -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 479 -double iirIItOutTime_double(double *w, double x, double *a, double *b, signed int Na, signed int Nb) -{ - signed int timer1=0; - double *a_ptr; - double *b_ptr; - double yout=0.000000; - a_ptr = &a[1l]; - b_ptr = &b[0l]; - signed int Nw=Na > Nb ? Na : Nb; - double *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - yout = *tmp_post$1 * x + w[0l]; - signed int j; - timer1 = timer1 + 105; - j = 0; - for( ; !(j >= -1 + Nw); j = j + 1) - { - w[(signed long int)j] = w[(signed long int)(j + 1)]; - if(!(j >= -1 + Na)) - { - double *tmp_post$2=a_ptr; - a_ptr = a_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] - *tmp_post$2 * yout; - timer1 = timer1 + 41; - } - - if(!(j >= -1 + Nb)) - { - double *tmp_post$3=b_ptr; - b_ptr = b_ptr + 1l; - w[(signed long int)j] = w[(signed long int)j] + *tmp_post$3 * x; - timer1 = timer1 + 38; - } - - timer1 = timer1 + 54; - } - timer1 = timer1 + 7; - /* assertion (double)timer1*CYCLE <= (double)DEADLINE */ - assert(((double)timer1 * 1.000000) / 1.600000e+7 <= 1.000000 / 100.000000); - if((double)timer1 / 1.600000e+7 <= 1.000000 / 100.000000) - (void)0; - - return yout; -} - -// iirOutBoth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 506 -void iirOutBoth(float *yf, float *xf, float *af, float *bf, float *sumf_ref, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int *sum_ref, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - signed long int sum=0l; - float sumf=0.000000f; - a_ptr = &a[1l]; - y_ptr = &y[(signed long int)(Na - 1)]; - b_ptr = &b[0l]; - x_ptr = &x[(signed long int)(Nb - 1)]; - af_ptr = &af[1l]; - yf_ptr = &yf[(signed long int)(Na - 1)]; - bf_ptr = &bf[0l]; - xf_ptr = &xf[(signed long int)(Nb - 1)]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= Nb); i = i + 1) - { - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr + 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr - 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - float *tmp_post$4=bf_ptr; - bf_ptr = bf_ptr + 1l; - float *tmp_post$5=xf_ptr; - xf_ptr = xf_ptr - 1l; - sumf = sumf + *tmp_post$4 * *tmp_post$5; - } - j = 1; - for( ; !(j >= Na); j = j + 1) - { - signed long int *tmp_post$6=a_ptr; - a_ptr = a_ptr + 1l; - signed long int *tmp_post$7=y_ptr; - y_ptr = y_ptr - 1l; - signed long int return_value_fxp_mult$8=fxp_mult(*tmp_post$6, *tmp_post$7); - sum=fxp_sub(sum, return_value_fxp_mult$8); - float *tmp_post$9=af_ptr; - af_ptr = af_ptr + 1l; - float *tmp_post$10=yf_ptr; - yf_ptr = yf_ptr - 1l; - sumf = sumf - *tmp_post$9 * *tmp_post$10; - } - *sum_ref = sum; - *sumf_ref = sumf; -} - -// iirOutBothL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 586 -float iirOutBothL(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - float sumf=0.000000f; - af_ptr = &af[(signed long int)(Na - 1)]; - yf_ptr = &yf[1l]; - bf_ptr = &bf[(signed long int)(Nb - 1)]; - xf_ptr = &xf[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - xf[(signed long int)i] = xf[(signed long int)(i + 1)]; - float *tmp_post$4=bf_ptr; - bf_ptr = bf_ptr - 1l; - float *tmp_post$5=xf_ptr; - xf_ptr = xf_ptr + 1l; - sumf = sumf + *tmp_post$4 * *tmp_post$5; - } - x[(signed long int)(Nb - 1)] = xin; - signed long int *tmp_post$6=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$7=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$8=fxp_mult(*tmp_post$6, *tmp_post$7); - sum=fxp_add(sum, return_value_fxp_mult$8); - xf[(signed long int)(Nb - 1)] = xfin; - float *tmp_post$9=bf_ptr; - bf_ptr = bf_ptr - 1l; - float *tmp_post$10=xf_ptr; - xf_ptr = xf_ptr + 1l; - sumf = sumf + *tmp_post$9 * *tmp_post$10; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int *tmp_post$11=a_ptr; - a_ptr = a_ptr - 1l; - signed long int *tmp_post$12=y_ptr; - y_ptr = y_ptr + 1l; - signed long int return_value_fxp_mult$13=fxp_mult(*tmp_post$11, *tmp_post$12); - sum=fxp_sub(sum, return_value_fxp_mult$13); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - float *tmp_post$14=af_ptr; - af_ptr = af_ptr - 1l; - float *tmp_post$15=yf_ptr; - yf_ptr = yf_ptr + 1l; - sumf = sumf - *tmp_post$14 * *tmp_post$15; - yf[(signed long int)j] = yf[(signed long int)(j + 1)]; - } - signed long int *tmp_post$16; - signed long int *tmp_post$17; - signed long int return_value_fxp_mult$18; - if(Na >= 2) - { - tmp_post$16 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$17 = y_ptr; - y_ptr = y_ptr + 1l; - return_value_fxp_mult$18=fxp_mult(*tmp_post$16, *tmp_post$17); - sum=fxp_sub(sum, return_value_fxp_mult$18); - } - - y[(signed long int)(Na - 1)] = sum; - float *tmp_post$19; - float *tmp_post$20; - if(Na >= 2) - { - tmp_post$19 = af_ptr; - af_ptr = af_ptr - 1l; - tmp_post$20 = yf_ptr; - yf_ptr = yf_ptr + 1l; - sumf = sumf - *tmp_post$19 * *tmp_post$20; - } - - yf[(signed long int)(Na - 1)] = sumf; - float return_value_fxp_to_float$21=fxp_to_float(sum); - return return_value_fxp_to_float$21 - sumf; -} - -// iirOutBothL2 -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 626 -float iirOutBothL2(float *yf, float *xf, float *af, float *bf, float xfin, signed long int *y, signed long int *x, signed long int *a, signed long int *b, signed long int xin, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - float *af_ptr; - float *yf_ptr; - float *bf_ptr; - float *xf_ptr; - float sumf=0.000000f; - af_ptr = &af[(signed long int)(Na - 1)]; - yf_ptr = &yf[1l]; - bf_ptr = &bf[(signed long int)(Nb - 1)]; - xf_ptr = &xf[0l]; - signed int i=0; - signed int j=1; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int return_value_fxp_mult$1=fxp_mult(b[(signed long int)((Nb - 1) - i)], x[(signed long int)i]); - sum=fxp_add(sum, return_value_fxp_mult$1); - xf[(signed long int)i] = xf[(signed long int)(i + 1)]; - sumf = sumf + bf[(signed long int)((Nb - 1) - i)] * xf[(signed long int)i]; - } - x[(signed long int)(Nb - 1)] = xin; - signed long int return_value_fxp_mult$2=fxp_mult(b[(signed long int)((Nb - 1) - i)], x[(signed long int)i]); - sum=fxp_add(sum, return_value_fxp_mult$2); - xf[(signed long int)(Nb - 1)] = xfin; - sumf = sumf + bf[(signed long int)((Nb - 1) - i)] * xf[(signed long int)i]; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int return_value_fxp_mult$3=fxp_mult(a[(signed long int)(Na - j)], y[(signed long int)j]); - sum=fxp_sub(sum, return_value_fxp_mult$3); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - sumf = sumf - af[(signed long int)(Na - j)] * yf[(signed long int)j]; - yf[(signed long int)j] = yf[(signed long int)(j + 1)]; - } - signed long int return_value_fxp_mult$4; - if(Na >= 2) - { - return_value_fxp_mult$4=fxp_mult(a[(signed long int)(Na - j)], y[(signed long int)j]); - sum=fxp_sub(sum, return_value_fxp_mult$4); - } - - y[(signed long int)(Na - 1)] = sum; - if(Na >= 2) - sumf = sumf - af[(signed long int)(Na - j)] * yf[(signed long int)j]; - - yf[(signed long int)(Na - 1)] = sumf; - float return_value_fxp_to_float$5=fxp_to_float(sum); - return return_value_fxp_to_float$5 - sumf; -} - -// iirOutFixedL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 536 -signed long int iirOutFixedL(signed long int *y, signed long int *x, signed long int xin, signed long int *a, signed long int *b, signed int Na, signed int Nb) -{ - signed long int *a_ptr; - signed long int *y_ptr; - signed long int *b_ptr; - signed long int *x_ptr; - signed long int sum=0l; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - signed long int *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$3=fxp_mult(*tmp_post$1, *tmp_post$2); - sum=fxp_add(sum, return_value_fxp_mult$3); - } - x[(signed long int)(Nb - 1)] = xin; - signed long int *tmp_post$4=b_ptr; - b_ptr = b_ptr - 1l; - signed long int *tmp_post$5=x_ptr; - x_ptr = x_ptr + 1l; - signed long int return_value_fxp_mult$6=fxp_mult(*tmp_post$4, *tmp_post$5); - sum=fxp_add(sum, return_value_fxp_mult$6); - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - signed long int *tmp_post$7=a_ptr; - a_ptr = a_ptr - 1l; - signed long int *tmp_post$8=y_ptr; - y_ptr = y_ptr + 1l; - signed long int return_value_fxp_mult$9=fxp_mult(*tmp_post$7, *tmp_post$8); - sum=fxp_sub(sum, return_value_fxp_mult$9); - y[(signed long int)j] = y[(signed long int)(j + 1)]; - } - signed long int *tmp_post$10; - signed long int *tmp_post$11; - signed long int return_value_fxp_mult$12; - if(Na >= 2) - { - tmp_post$10 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$11 = y_ptr; - y_ptr = y_ptr + 1l; - return_value_fxp_mult$12=fxp_mult(*tmp_post$10, *tmp_post$11); - sum=fxp_sub(sum, return_value_fxp_mult$12); - } - - y[(signed long int)(Na - 1)] = sum; - return sum; -} - -// iirOutFloatL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 561 -float iirOutFloatL(float *y, float *x, float xin, float *a, float *b, signed int Na, signed int Nb) -{ - float *a_ptr; - float *y_ptr; - float *b_ptr; - float *x_ptr; - float sum=0.000000f; - a_ptr = &a[(signed long int)(Na - 1)]; - y_ptr = &y[1l]; - b_ptr = &b[(signed long int)(Nb - 1)]; - x_ptr = &x[0l]; - signed int i; - signed int j; - i = 0; - for( ; !(i >= -1 + Nb); i = i + 1) - { - x[(signed long int)i] = x[(signed long int)(i + 1)]; - float *tmp_post$1=b_ptr; - b_ptr = b_ptr - 1l; - float *tmp_post$2=x_ptr; - x_ptr = x_ptr + 1l; - sum = sum + *tmp_post$1 * *tmp_post$2; - } - x[(signed long int)(Nb - 1)] = xin; - float *tmp_post$3=b_ptr; - b_ptr = b_ptr - 1l; - float *tmp_post$4=x_ptr; - x_ptr = x_ptr + 1l; - sum = sum + *tmp_post$3 * *tmp_post$4; - j = 1; - for( ; !(j >= -1 + Na); j = j + 1) - { - float *tmp_post$5=a_ptr; - a_ptr = a_ptr - 1l; - float *tmp_post$6=y_ptr; - y_ptr = y_ptr + 1l; - sum = sum - *tmp_post$5 * *tmp_post$6; - y[(signed long int)j] = y[(signed long int)(j + 1)]; - } - float *tmp_post$7; - float *tmp_post$8; - if(Na >= 2) - { - tmp_post$7 = a_ptr; - a_ptr = a_ptr - 1l; - tmp_post$8 = y_ptr; - y_ptr = y_ptr + 1l; - sum = sum - *tmp_post$7 * *tmp_post$8; - } - - y[(signed long int)(Na - 1)] = sum; - return sum; -} - -// initialization -// file /home/lucascordeiro/dsverifier/bmc/core/initialization.h line 24 -void initialization() -{ - if(impl.frac_bits >= 32) - printf("impl.frac_bits must be less than word width!\n"); - - if(impl.int_bits >= 32 + -impl.frac_bits) - { - printf("impl.int_bits must be less than word width subtracted by precision!\n"); - /* assertion 0 */ - assert(0 != 0); - } - - if(impl.frac_bits >= 31) - _fxp_one = 2147483647l; - - else - _fxp_one = (signed long int)(0x1 << impl.frac_bits); - _fxp_half = (signed long int)(0x1 << impl.frac_bits - 1); - _fxp_minus_one = (signed long int)-(0x1 << impl.frac_bits); - _fxp_min = (signed long int)-(0x1 << (impl.frac_bits + impl.int_bits) - 1); - _fxp_max = (signed long int)((0x1 << (impl.frac_bits + impl.int_bits) - 1) - 1); - _fxp_fmask = (signed long int)((1 << impl.frac_bits) - 1); - _fxp_imask = (signed long int)(0x80000000u >> (32 - impl.frac_bits) - 1); - _dbl_min = (double)_fxp_min; - _dbl_min = _dbl_min / (double)(1 << impl.frac_bits); - _dbl_max = (double)_fxp_max; - _dbl_max = _dbl_max / (double)(1 << impl.frac_bits); - if(impl.scale == 0 || impl.scale == 1) - impl.scale = 1; - - else - { - if(IEEE_FLOAT_NOTEQUAL(impl.min, 0.000000)) - impl.min = impl.min / (double)impl.scale; - - if(IEEE_FLOAT_NOTEQUAL(impl.max, 0.000000)) - impl.max = impl.max / (double)impl.scale; - - } -} - -// initialize_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 22 -void initialize_array(double *v, signed int n) -{ - signed int i=0; - for( ; !(i >= n); i = i + 1) - v[(signed long int)i] = 0.000000; -} - -// internal_abs -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 49 -double internal_abs(double a) -{ - return a < 0.000000 ? -a : a; -} - -// internal_pow -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 39 -double internal_pow(double a, double b) -{ - signed int i; - double acc=1.000000; - i = 0; - for( ; (double)i < b; i = i + 1) - acc = acc * a; - return acc; -} - -// main -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 60 -signed int main() -{ - initialization(); - validation(); - rounding_mode = 1; - call_closedloop_verification_task((void *)verify_stability_closedloop_using_dslib); - return 0; -} - -// nchoosek -// file /home/lucascordeiro/dsverifier/bmc/core/delta-operator.h line 23 -signed int nchoosek(signed int n, signed int k) -{ - if(k == 0) - return 1; - - else - { - signed int return_value_nchoosek$1=nchoosek(n - 1, k - 1); - return (n * return_value_nchoosek$1) / k; - } -} - -// order -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 158 -signed int order(signed int Na, signed int Nb) -{ - return Na > Nb ? Na - 1 : Nb - 1; -} - -// poly_mult -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 165 -void poly_mult(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans) -{ - signed int i; - signed int j; - signed int k; - Nans = (Na + Nb) - 1; - i = 0; - for( ; !(i >= Na); i = i + 1) - { - j = 0; - for( ; !(j >= Nb); j = j + 1) - { - k = (((Na + Nb) - i) - j) - 2; - ans[(signed long int)k] = 0.000000; - } - } - i = 0; - for( ; !(i >= Na); i = i + 1) - { - j = 0; - for( ; !(j >= Nb); j = j + 1) - { - k = (((Na + Nb) - i) - j) - 2; - ans[(signed long int)k] = ans[(signed long int)k] + a[(signed long int)((Na - i) - 1)] * b[(signed long int)((Nb - j) - 1)]; - } - } -} - -// poly_sum -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 141 -void poly_sum(double *a, signed int Na, double *b, signed int Nb, double *ans, signed int Nans) -{ - signed int i; - Nans = Na > Nb ? Na : Nb; - i = 0; - for( ; !(i >= Nans); i = i + 1) - if(!(Nb >= Na)) - { - ans[(signed long int)i] = a[(signed long int)i]; - if(!(-1 + Na + -Nb >= i)) - ans[(signed long int)i] = ans[(signed long int)i] + b[(signed long int)((i - Na) + Nb)]; - - } - - else - { - ans[(signed long int)i] = b[(signed long int)i]; - if(!(-1 + Nb + -Na >= i)) - ans[(signed long int)i] = ans[(signed long int)i] + a[(signed long int)((i - Nb) + Na)]; - - } -} - -// print_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 305 -void print_array_elements(char *name, double *v, signed int n) -{ - printf("%s = {", name); - signed int i=0; - for( ; !(i >= n); i = i + 1) - printf(" %.32f ", v[(signed long int)i]); - printf("}\n"); -} - -// print_fxp_array_elements -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 419 -void print_fxp_array_elements(char *name, signed long int *v, signed int n) -{ - printf("%s = {", name); - signed int i=0; - for( ; !(i >= n); i = i + 1) - printf(" %jd ", v[(signed long int)i]); - printf("}\n"); -} - -// print_matrix -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 481 -void print_matrix(double (*matrix)[20l], unsigned int lines, unsigned int columns) -{ - printf("\nMatrix\n=====================\n\n"); - unsigned int i; - unsigned int j; - i = 0u; - for( ; !(i >= lines); i = i + 1u) - { - j = 0u; - for( ; !(j >= columns); j = j + 1u) - printf("#matrix[%d][%d]: %2.2f ", i, j, matrix[(signed long int)i][(signed long int)j]); - printf("\n"); - } - printf("\n"); -} - -// rand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 417 -extern signed int rand(void) -{ - next = next * 1103515245ul + 12345ul; - return (signed int)((unsigned int)(next / 65536ul) % 32768u); -} - -// revert_array -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 30 -void revert_array(double *v, double *out, signed int n) -{ - initialize_array(out, n); - signed int i=0; - for( ; !(i >= n); i = i + 1) - out[(signed long int)i] = v[(signed long int)((n - i) - 1)]; -} - -// shiftL -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 53 -signed long int shiftL(signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftLDouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 119 -double shiftLDouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftLboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 130 -void shiftLboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut; - float zfOut; - zOut = z[0l]; - zfOut = zf[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - { - z[(signed long int)i] = z[(signed long int)(i + 1)]; - zf[(signed long int)i] = zf[(signed long int)(i + 1)]; - } - z[(signed long int)(N - 1)] = zIn; - zf[(signed long int)(N - 1)] = zfIn; -} - -// shiftLfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 75 -float shiftLfloat(float zIn, float *z, signed int N) -{ - signed int i; - float zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftR -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 64 -signed long int shiftR(signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// shiftRDdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 97 -double shiftRDdouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[0l]; - i = 0; - for( ; !(i >= -1 + N); i = i + 1) - z[(signed long int)i] = z[(signed long int)(i + 1)]; - z[(signed long int)(N - 1)] = zIn; - return zOut; -} - -// shiftRboth -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 144 -void shiftRboth(float zfIn, float *zf, signed long int zIn, signed long int *z, signed int N) -{ - signed int i; - signed long int zOut; - float zfOut; - zOut = z[(signed long int)(N - 1)]; - zfOut = zf[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - { - z[(signed long int)i] = z[(signed long int)(i - 1)]; - zf[(signed long int)i] = zf[(signed long int)(i - 1)]; - } - z[0l] = zIn; - zf[0l] = zfIn; -} - -// shiftRdouble -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 108 -double shiftRdouble(double zIn, double *z, signed int N) -{ - signed int i; - double zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// shiftRfloat -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 86 -float shiftRfloat(float zIn, float *z, signed int N) -{ - signed int i; - float zOut=z[(signed long int)(N - 1)]; - i = N - 1; - for( ; i >= 1; i = i - 1) - z[(signed long int)i] = z[(signed long int)(i - 1)]; - z[0l] = zIn; - return zOut; -} - -// snrPoint -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 402 -float snrPoint(float *s, float *n, signed int blksz) -{ - signed int i; - double ratio=0.000000; - double power=0.000000; - i = 0; - for( ; !(i >= blksz); i = i + 1) - if(!IEEE_FLOAT_EQUAL(n[(signed long int)i], 0.000000f)) - { - ratio = (double)(s[(signed long int)i] / n[(signed long int)i]); - if(!(ratio < -150.000000) && !(ratio > 150.000000)) - { - power = ratio * ratio; - /* assertion power >= 1.0f */ - assert(power >= 1.000000); - if(power >= 1.000000) - (void)0; - - } - - } - - return 9.999900e+3f; -} - -// snrPower -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 381 -float snrPower(float *s, float *n, signed int blksz) -{ - signed int i; - double sv=0.000000; - double nv=0.000000; - double snr; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sv = sv + (double)(s[(signed long int)i] * s[(signed long int)i]); - nv = nv + (double)(n[(signed long int)i] * n[(signed long int)i]); - } - if(IEEE_FLOAT_NOTEQUAL(nv, 0.000000)) - { - /* assertion sv >= nv */ - assert(sv >= nv); - if(sv >= nv) - (void)0; - - snr = sv / nv; - return (float)snr; - } - - else - return 9.999900e+3f; -} - -// snrVariance -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 357 -float snrVariance(float *s, float *n, signed int blksz) -{ - signed int i; - double sm=0.000000; - double nm=0.000000; - double sv=0.000000; - double nv=0.000000; - double snr; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sm = sm + (double)s[(signed long int)i]; - nm = nm + (double)n[(signed long int)i]; - } - sm = sm / (double)blksz; - nm = nm / (double)blksz; - i = 0; - for( ; !(i >= blksz); i = i + 1) - { - sv = sv + ((double)s[(signed long int)i] - sm) * ((double)s[(signed long int)i] - sm); - nv = nv + ((double)n[(signed long int)i] - nm) * ((double)n[(signed long int)i] - nm); - } - if(IEEE_FLOAT_NOTEQUAL(nv, 0.000000)) - { - /* assertion sv >= nv */ - assert(sv >= nv); - if(sv >= nv) - (void)0; - - snr = sv / nv; - return (float)snr; - } - - else - return 9.999900e+3f; -} - -// srand -// file /home/lucascordeiro/dsverifier/bmc/core/functions.h line 423 -extern void srand(unsigned int seed) -{ - next = (unsigned long int)seed; -} - -// transpose -// file /home/lucascordeiro/dsverifier/bmc/core/util.h line 571 -void transpose(double (*a)[20l], double (*b)[20l], signed int n, signed int m) -{ - signed int i; - signed int j; - i = 0; - for( ; !(i >= n); i = i + 1) - { - j = 0; - for( ; !(j >= m); j = j + 1) - b[(signed long int)j][(signed long int)i] = a[(signed long int)i][(signed long int)j]; - } -} - -// validation -// file /home/lucascordeiro/dsverifier/bmc/dsverifier.h line 125 -void validation() -{ - if(controller.a_size == 0 || plant.b_size == 0 || impl.int_bits == 0) - { - printf("\n\n*****************************************************************************************************\n"); - printf("* set (controller, plant, and impl) parameters to check CLOSED LOOP with DSVerifier *\n"); - printf("*****************************************************************************************************\n"); - __DSVERIFIER_assert((_Bool)0); - } - - else - { - printf("\n\n*****************************************************************************************************\n"); - printf("* set (controller and impl) parameters so that they do not overflow *\n"); - printf("*****************************************************************************************************\n"); - unsigned int j=0u; - for( ; !(j >= (unsigned int)controller.a_size); j = j + 1u) - { - const double validation$$1$$6$$2$$1$$1$$value=controller.a[(signed long int)j]; - __DSVERIFIER_assert(validation$$1$$6$$2$$1$$1$$value <= _dbl_max); - __DSVERIFIER_assert(validation$$1$$6$$2$$1$$1$$value >= _dbl_min); - } - j = 0u; - for( ; !(j >= (unsigned int)controller.b_size); j = j + 1u) - { - const double value=controller.b[(signed long int)j]; - __DSVERIFIER_assert(value <= _dbl_max); - __DSVERIFIER_assert(value >= _dbl_min); - } - } -} - -// verify_controllability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 16 -signed int verify_controllability(void) -{ - signed int i; - signed int j; - signed long int A_fpx[20l][20l]; - signed long int B_fpx[20l][20l]; - signed long int controllabilityMatrix[20l][20l]; - signed long int backup[20l][20l]; - signed long int backupSecond[20l][20l]; - double controllabilityMatrix_double[20l][20l]; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - { - A_fpx[(signed long int)i][(signed long int)j] = 0l; - B_fpx[(signed long int)i][(signed long int)j] = 0l; - controllabilityMatrix[(signed long int)i][(signed long int)j] = 0l; - backup[(signed long int)i][(signed long int)j] = 0l; - backupSecond[(signed long int)i][(signed long int)j] = 0l; - controllabilityMatrix_double[(signed long int)i][(signed long int)j] = 0.000000; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - B_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.B[(signed long int)i][(signed long int)j]); - } - if(nInputs >= 2) - { - signed int l=0; - j = 0; - while(!(j >= nInputs * nStates)) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)l, backup); - l = l + 1; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, B_fpx, backupSecond); - signed int k=0; - for( ; !(k >= nInputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][(signed long int)k]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0l; - } - fxp_transpose(controllabilityMatrix, backup, nStates, nStates * nInputs); - signed long int mimo_controllabilityMatrix_fxp[20l][20l]; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nInputs), (unsigned int)(nStates * nInputs), (unsigned int)nStates, controllabilityMatrix, backup, mimo_controllabilityMatrix_fxp); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - controllabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(mimo_controllabilityMatrix_fxp[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$1=determinant(controllabilityMatrix_double, nStates); - /* assertion determinant(controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)j, backup); - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, B_fpx, backupSecond); - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][0l]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - controllabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(controllabilityMatrix[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$2=determinant(controllabilityMatrix_double, nStates); - /* assertion determinant(controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_controllability_double -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_controllability.h line 120 -signed int verify_controllability_double(void) -{ - signed int i; - signed int j; - double controllabilityMatrix[20l][20l]; - double backup[20l][20l]; - double backupSecond[20l][20l]; - double controllabilityMatrix_double[20l][20l]; - if(nInputs >= 2) - { - signed int l=0; - j = 0; - while(!(j >= nInputs * nStates)) - { - double_exp_matrix((unsigned int)nStates, (unsigned int)nStates, _controller.A, (unsigned int)l, backup); - l = l + 1; - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, _controller.B, backupSecond); - signed int k=0; - for( ; !(k >= nInputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][(signed long int)k]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0.000000; - } - transpose(controllabilityMatrix, backup, nStates, nStates * nInputs); - double mimo_controllabilityMatrix_double[20l][20l]; - double_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nInputs), (unsigned int)(nStates * nInputs), (unsigned int)nStates, controllabilityMatrix, backup, mimo_controllabilityMatrix_double); - double return_value_determinant$1=determinant(mimo_controllabilityMatrix_double, nStates); - /* assertion determinant(mimo_controllabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - double_exp_matrix((unsigned int)nStates, (unsigned int)nStates, _controller.A, (unsigned int)j, backup); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nInputs, backup, _controller.B, backupSecond); - i = 0; - for( ; !(i >= nStates); i = i + 1) - controllabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[(signed long int)i][0l]; - } - double return_value_determinant$2=determinant(controllabilityMatrix, nStates); - /* assertion determinant(controllabilityMatrix,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_error -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error.h line 20 -signed int verify_error(void) -{ - overflow_mode = 2; - double a_cascade[100l]; - signed int a_cascade_size; - double b_cascade[100l]; - signed int b_cascade_size; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - const signed long int x$array_size0=(signed long int)X_SIZE_VALUE; - double yf[x$array_size0]; - const signed long int yf$array_size0=(signed long int)X_SIZE_VALUE; - double xf[yf$array_size0]; - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - const signed long int waux$array_size0=(signed long int)ds.a_size; - double yfaux[waux$array_size0]; - const signed long int yfaux$array_size0=(signed long int)ds.b_size; - double xfaux[yfaux$array_size0]; - const signed long int xfaux$array_size0=(signed long int)Nw; - double wfaux[xfaux$array_size0]; - signed int i=0; - for( ; !(i >= ds.a_size); i = i + 1) - { - yaux[(signed long int)i] = 0l; - yfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - { - xaux[(signed long int)i] = 0l; - xfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - waux[(signed long int)i] = 0l; - wfaux[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - signed int return_value_nondet_int$1=nondet_int(); - x[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = x[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - yf[(signed long int)i] = 0.000000; - xf[(signed long int)i]=fxp_to_double(x[(signed long int)i]); - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - double absolute_error; - double return_value_fxp_to_double$3=fxp_to_double(y[(signed long int)i]); - absolute_error = yf[(signed long int)i] - return_value_fxp_to_double$3; - __DSVERIFIER_assert(absolute_error < impl.max_error && absolute_error > -impl.max_error); - } - return 0; -} - -// verify_error_closedloop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_closedloop.h line 27 -signed int verify_error_closedloop(void) -{ - overflow_mode = 3; - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num_double[100l]; - double ans_num_qtz[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den_qtz[100l]; - double ans_den_double[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num_qtz, ans_num_size, ans_den_qtz, ans_den_size); - ft_closedloop_series(c_num, c_num_size, c_den, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num_double, ans_num_size, ans_den_double, ans_den_size); - signed int i; - const signed long int i$array_size0=(signed long int)X_SIZE_VALUE; - double y_qtz[i$array_size0]; - const signed long int y_qtz$array_size0=(signed long int)X_SIZE_VALUE; - double y_double[y_qtz$array_size0]; - const signed long int y_double$array_size0=(signed long int)X_SIZE_VALUE; - double x_qtz[y_double$array_size0]; - const signed long int x_qtz$array_size0=(signed long int)X_SIZE_VALUE; - double x_double[x_qtz$array_size0]; - const signed long int x_double$array_size0=(signed long int)ans_num_size; - double xaux_qtz[x_double$array_size0]; - const signed long int xaux_qtz$array_size0=(signed long int)ans_num_size; - double xaux_double[xaux_qtz$array_size0]; - const signed long int xaux_double$array_size0=(signed long int)ans_num_size; - double xaux[xaux_double$array_size0]; - double nondet_constant_input=nondet_double(); - __DSVERIFIER_assume(nondet_constant_input >= impl.min && nondet_constant_input <= impl.max); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x_qtz[(signed long int)i] = nondet_constant_input; - x_double[(signed long int)i] = nondet_constant_input; - y_qtz[(signed long int)i] = 0.000000; - y_double[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ans_num_size); i = i + 1) - { - xaux_qtz[(signed long int)i] = nondet_constant_input; - xaux_double[(signed long int)i] = nondet_constant_input; - } - const signed long int nondet_constant_input$array_size0=(signed long int)ans_den_size; - double yaux_qtz[nondet_constant_input$array_size0]; - const signed long int yaux_qtz$array_size0=(signed long int)ans_den_size; - double yaux_double[yaux_qtz$array_size0]; - const signed long int yaux_double$array_size0=(signed long int)ans_den_size; - double y0_qtz[yaux_double$array_size0]; - const signed long int y0_qtz$array_size0=(signed long int)ans_den_size; - double y0_double[y0_qtz$array_size0]; - signed int Nw=ans_den_size > ans_num_size ? ans_den_size : ans_num_size; - const signed long int Nw$array_size0=(signed long int)Nw; - double waux_qtz[Nw$array_size0]; - const signed long int waux_qtz$array_size0=(signed long int)Nw; - double waux_double[waux_qtz$array_size0]; - const signed long int waux_double$array_size0=(signed long int)Nw; - double w0_qtz[waux_double$array_size0]; - const signed long int w0_qtz$array_size0=(signed long int)Nw; - double w0_double[w0_qtz$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - waux_qtz[(signed long int)i] = 0.000000; - waux_double[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - double absolute_error; - double return_value_fxp_to_double$1=fxp_to_double((signed long int)y_qtz[(signed long int)i]); - absolute_error = y_double[(signed long int)i] - return_value_fxp_to_double$1; - __DSVERIFIER_assert(absolute_error < impl.max_error && absolute_error > -impl.max_error); - } - return 0; -} - -// verify_error_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_error_state_space.h line 20 -signed int verify_error_state_space(void) -{ - overflow_mode = 0; - struct anonymous$1 __backupController; - signed int i; - signed int j; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - __backupController.A[(signed long int)i][(signed long int)j] = _controller.A[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - __backupController.B[(signed long int)i][(signed long int)j] = _controller.B[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - __backupController.C[(signed long int)i][(signed long int)j] = _controller.C[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - __backupController.D[(signed long int)i][(signed long int)j] = _controller.D[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.states[(signed long int)i][(signed long int)j] = _controller.states[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.inputs[(signed long int)i][(signed long int)j] = _controller.inputs[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - __backupController.outputs[(signed long int)i][(signed long int)j] = _controller.outputs[(signed long int)i][(signed long int)j]; - } - double __quant_error=0.000000; - double output_double=double_state_space_representation(); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - _controller.A[(signed long int)i][(signed long int)j] = __backupController.A[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - _controller.B[(signed long int)i][(signed long int)j] = __backupController.B[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - _controller.C[(signed long int)i][(signed long int)j] = __backupController.C[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nInputs); j = j + 1) - _controller.D[(signed long int)i][(signed long int)j] = __backupController.D[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.states[(signed long int)i][(signed long int)j] = __backupController.states[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nInputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.inputs[(signed long int)i][(signed long int)j] = __backupController.inputs[(signed long int)i][(signed long int)j]; - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 1); j = j + 1) - _controller.outputs[(signed long int)i][(signed long int)j] = __backupController.outputs[(signed long int)i][(signed long int)j]; - } - double output_fxp=fxp_state_space_representation(); - fxp_verify_overflow((signed long int)output_fxp); - __quant_error = ((output_fxp - output_double) / output_double) * 100.000000; - /* assertion __quant_error < error_limit && __quant_error > (-error_limit) */ - assert(__quant_error < error_limit && __quant_error > -error_limit); - if(__quant_error < error_limit && __quant_error > -error_limit) - (void)0; - - return 0; -} - -// verify_generic_timing -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_generic_timing.h line 25 -signed int verify_generic_timing(void) -{ - const signed long int verify_generic_timing$array_size0=(signed long int)X_SIZE_VALUE; - double y[verify_generic_timing$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0.000000; - float return_value_nondet_float$1=nondet_float(); - x[(signed long int)i] = (double)return_value_nondet_float$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= impl.min) - tmp_if_expr$2 = x[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - double yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - double xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - double waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0.000000; - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - generic_timer = generic_timer + 2 * hw.assembly.std + 1 * hw.assembly.rjmp; - double initial_timer=(double)generic_timer; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - generic_timer = generic_timer + 2 * hw.assembly.ldd + 1 * hw.assembly.adiw + 2 * hw.assembly.std; - generic_timer = generic_timer + 2 * hw.assembly.ldd + 1 * hw.assembly.cpi + 1 * hw.assembly.cpc + 1 * hw.assembly.brlt; - double spent_time=(double)generic_timer * hw.cycle; - /* assertion spent_time <= ds.sample_time */ - assert(spent_time <= ds.sample_time); - if(spent_time <= ds.sample_time) - (void)0; - - generic_timer = (signed int)initial_timer; - } - return 0; -} - -// verify_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 111 -signed int verify_limit_cycle(void) -{ - overflow_mode = 3; - signed int i; - signed int Set_xsize_at_least_two_times_Na=2 * ds.a_size; - printf("X_SIZE must be at least 2 * ds.a_size"); - __DSVERIFIER_assert(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na); - const signed long int Set_xsize_at_least_two_times_Na$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[Set_xsize_at_least_two_times_Na$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)ds.b_size; - signed long int xaux[max_fxp$array_size0]; - signed int nondet_constant_input=nondet_int(); - __DSVERIFIER_assume((signed long int)nondet_constant_input >= min_fxp && (signed long int)nondet_constant_input <= max_fxp); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x[(signed long int)i] = (signed long int)nondet_constant_input; - y[(signed long int)i] = 0l; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = (signed long int)nondet_constant_input; - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.a_size; - signed long int y0[yaux$array_size0]; - const signed long int y0$array_size0=(signed long int)Nw; - signed long int waux[y0$array_size0]; - const signed long int waux$array_size0=(signed long int)Nw; - signed long int w0[waux$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = waux[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// verify_limit_cycle_closed_loop -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle_closedloop.h line 29 -signed int verify_limit_cycle_closed_loop(void) -{ - overflow_mode = 3; - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num, ans_num_size, ans_den, ans_den_size); - signed int i; - const signed long int i$array_size0=(signed long int)X_SIZE_VALUE; - double y[i$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - const signed long int x$array_size0=(signed long int)ans_num_size; - double xaux[x$array_size0]; - double nondet_constant_input=nondet_double(); - __DSVERIFIER_assume(nondet_constant_input >= impl.min && nondet_constant_input <= impl.max); - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - x[(signed long int)i] = nondet_constant_input; - y[(signed long int)i] = 0.000000; - } - i = 0; - for( ; !(i >= ans_num_size); i = i + 1) - xaux[(signed long int)i] = nondet_constant_input; - const signed long int nondet_constant_input$array_size0=(signed long int)ans_den_size; - double yaux[nondet_constant_input$array_size0]; - const signed long int yaux$array_size0=(signed long int)ans_den_size; - double y0[yaux$array_size0]; - signed int Nw=ans_den_size > ans_num_size ? ans_den_size : ans_num_size; - const signed long int Nw$array_size0=(signed long int)Nw; - double waux[Nw$array_size0]; - const signed long int waux$array_size0=(signed long int)Nw; - double w0[waux$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (double)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= impl.min) - tmp_if_expr$2 = waux[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - double_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// verify_limit_cycle_state_space -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_limit_cycle.h line 21 -signed int verify_limit_cycle_state_space(void) -{ - double stateMatrix[20l][20l]; - double outputMatrix[20l][20l]; - double arrayLimitCycle[20l]; - double result1[20l][20l]; - double result2[20l][20l]; - signed int i; - signed int j; - signed int k; - i = 0; - for( ; !(i >= 20); i = i + 1) - { - j = 0; - for( ; !(j >= 20); j = j + 1) - { - result1[(signed long int)i][(signed long int)j] = 0.000000; - result2[(signed long int)i][(signed long int)j] = 0.000000; - stateMatrix[(signed long int)i][(signed long int)j] = 0.000000; - outputMatrix[(signed long int)i][(signed long int)j] = 0.000000; - } - } - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - k = 0; - i = 1; - for( ; !(i >= 0); i = i + 1) - { - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.A, _controller.states, result1); - double_matrix_multiplication((unsigned int)nStates, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.B, _controller.inputs, result2); - double_add_matrix((unsigned int)nStates, 1u, result1, result2, _controller.states); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, 1u, _controller.C, _controller.states, result1); - double_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nInputs, (unsigned int)nInputs, 1u, _controller.D, _controller.inputs, result2); - double_add_matrix((unsigned int)nOutputs, 1u, result1, result2, _controller.outputs); - signed int l=0; - for( ; !(l >= nStates); l = l + 1) - stateMatrix[(signed long int)l][(signed long int)k] = _controller.states[(signed long int)l][0l]; - l = 0; - for( ; !(l >= nOutputs); l = l + 1) - stateMatrix[(signed long int)l][(signed long int)k] = _controller.outputs[(signed long int)l][0l]; - k = k + 1; - } - printf("#matrix STATES -------------------------------"); - print_matrix(stateMatrix, (unsigned int)nStates, 0u); - printf("#matrix OUTPUTS -------------------------------"); - print_matrix(outputMatrix, (unsigned int)nOutputs, 0u); - /* assertion 0 */ - assert(0 != 0); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= 0); j = j + 1) - arrayLimitCycle[(signed long int)j] = stateMatrix[(signed long int)i][(signed long int)j]; - double_check_persistent_limit_cycle(arrayLimitCycle, 0); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= 0); j = j + 1) - arrayLimitCycle[(signed long int)j] = outputMatrix[(signed long int)i][(signed long int)j]; - double_check_persistent_limit_cycle(arrayLimitCycle, 0); - } - /* assertion 0 */ - assert(0 != 0); -} - -// verify_minimum_phase -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_minimum_phase.h line 24 -signed int verify_minimum_phase(void) -{ - overflow_mode = 0; - return 0; -} - -// verify_observability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_observability.h line 19 -signed int verify_observability(void) -{ - signed int i; - signed int j; - signed long int A_fpx[20l][20l]; - signed long int C_fpx[20l][20l]; - signed long int observabilityMatrix[20l][20l]; - signed long int backup[20l][20l]; - signed long int backupSecond[20l][20l]; - double observabilityMatrix_double[20l][20l]; - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - { - observabilityMatrix[(signed long int)i][(signed long int)j] = 0l; - A_fpx[(signed long int)i][(signed long int)j] = 0l; - C_fpx[(signed long int)i][(signed long int)j] = 0l; - backup[(signed long int)i][(signed long int)j] = 0l; - backupSecond[(signed long int)i][(signed long int)j] = 0l; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - A_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.A[(signed long int)i][(signed long int)j]); - } - i = 0; - for( ; !(i >= nOutputs); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - C_fpx[(signed long int)i][(signed long int)j]=fxp_double_to_fxp(_controller.C[(signed long int)i][(signed long int)j]); - } - if(nOutputs >= 2) - { - signed int l; - j = 0; - l = 0; - while(!(l >= nStates)) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)l, backup); - l = l + 1; - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, C_fpx, backup, backupSecond); - signed int k=0; - for( ; !(k >= nOutputs); k = k + 1) - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - observabilityMatrix[(signed long int)j][(signed long int)i] = backupSecond[(signed long int)k][(signed long int)i]; - j = j + 1; - } - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nOutputs * nStates); j = j + 1) - backup[(signed long int)i][(signed long int)j] = 0l; - } - fxp_transpose(observabilityMatrix, backup, nStates * nOutputs, nStates); - signed long int mimo_observabilityMatrix_fxp[20l][20l]; - fxp_matrix_multiplication((unsigned int)nStates, (unsigned int)(nStates * nOutputs), (unsigned int)(nStates * nOutputs), (unsigned int)nStates, backup, observabilityMatrix, mimo_observabilityMatrix_fxp); - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(mimo_observabilityMatrix_fxp[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$1=determinant(observabilityMatrix_double, nStates); - /* assertion determinant(observabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$1, 0.000000)) - (void)0; - - } - - else - { - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - fxp_exp_matrix((unsigned int)nStates, (unsigned int)nStates, A_fpx, (unsigned int)i, backup); - fxp_matrix_multiplication((unsigned int)nOutputs, (unsigned int)nStates, (unsigned int)nStates, (unsigned int)nStates, C_fpx, backup, backupSecond); - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix[(signed long int)i][(signed long int)j] = backupSecond[0l][(signed long int)j]; - } - i = 0; - for( ; !(i >= nStates); i = i + 1) - { - j = 0; - for( ; !(j >= nStates); j = j + 1) - observabilityMatrix_double[(signed long int)i][(signed long int)j]=fxp_to_double(observabilityMatrix[(signed long int)i][(signed long int)j]); - } - double return_value_determinant$2=determinant(observabilityMatrix_double, nStates); - /* assertion determinant(observabilityMatrix_double,nStates) != 0 */ - assert(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)); - if(IEEE_FLOAT_NOTEQUAL(return_value_determinant$2, 0.000000)) - (void)0; - - } - return 0; -} - -// verify_overflow -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_overflow.h line 23 -signed int verify_overflow(void) -{ - overflow_mode = 1; - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - signed int return_value_nondet_int$1=nondet_int(); - x[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = x[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0l; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0l; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0l; - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_verify_overflow_array(y, X_SIZE_VALUE); - return 0; -} - -// verify_stability -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability.h line 24 -signed int verify_stability(void) -{ - overflow_mode = 0; - return 0; -} - -// verify_stability_closedloop_using_dslib -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_stability_closedloop.h line 21 -signed int verify_stability_closedloop_using_dslib(void) -{ - double *c_num=controller.b; - signed int c_num_size=controller.b_size; - double *c_den=controller.a; - signed int c_den_size=controller.a_size; - const signed long int c_den_size$array_size0=(signed long int)controller.b_size; - signed long int c_num_fxp[c_den_size$array_size0]; - fxp_double_to_fxp_array(c_num, c_num_fxp, controller.b_size); - const signed long int c_num_fxp$array_size0=(signed long int)controller.a_size; - signed long int c_den_fxp[c_num_fxp$array_size0]; - fxp_double_to_fxp_array(c_den, c_den_fxp, controller.a_size); - const signed long int c_den_fxp$array_size0=(signed long int)controller.b_size; - double c_num_qtz[c_den_fxp$array_size0]; - fxp_to_double_array(c_num_qtz, c_num_fxp, controller.b_size); - const signed long int c_num_qtz$array_size0=(signed long int)controller.a_size; - double c_den_qtz[c_num_qtz$array_size0]; - fxp_to_double_array(c_den_qtz, c_den_fxp, controller.a_size); - double *p_num=plant_cbmc.b; - signed int p_num_size=plant.b_size; - double *p_den=plant_cbmc.a; - signed int p_den_size=plant.a_size; - double ans_num[100l]; - signed int ans_num_size=(controller.b_size + plant.b_size) - 1; - double ans_den[100l]; - signed int ans_den_size=(controller.a_size + plant.a_size) - 1; - ft_closedloop_series(c_num_qtz, c_num_size, c_den_qtz, c_den_size, p_num, p_num_size, p_den, p_den_size, ans_num, ans_num_size, ans_den, ans_den_size); - printf("Verifying stability for closedloop function\n"); - signed int return_value_check_stability_closedloop$1=check_stability_closedloop(ans_den, ans_den_size, p_num, p_num_size, p_den, p_den_size); - __DSVERIFIER_assert((_Bool)return_value_check_stability_closedloop$1); - return 0; -} - -// verify_timing_msp_430 -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_timing_msp430.h line 22 -signed int verify_timing_msp_430(void) -{ - const signed long int verify_timing_msp_430$array_size0=(signed long int)X_SIZE_VALUE; - double y[verify_timing_msp_430$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - double x[y$array_size0]; - signed int i=0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0.000000; - float return_value_nondet_float$1=nondet_float(); - x[(signed long int)i] = (double)return_value_nondet_float$1; - _Bool tmp_if_expr$2; - if(x[(signed long int)i] >= impl.min) - tmp_if_expr$2 = x[(signed long int)i] <= impl.max ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - double yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - double xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - double waux[xaux$array_size0]; - i = 0; - for( ; !(i >= ds.a_size); i = i + 1) - yaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0.000000; - i = 0; - for( ; !(i >= Nw); i = i + 1) - waux[(signed long int)i] = 0.000000; - double xk; - double temp; - double *aptr; - double *bptr; - double *xptr; - double *yptr; - double *wptr; - signed int j; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - return 0; -} - -// verify_zero_input_limit_cycle -// file /home/lucascordeiro/dsverifier/bmc/engine/verify_zero_input_limit_cycle.h line 16 -signed int verify_zero_input_limit_cycle(void) -{ - overflow_mode = 3; - signed int i; - signed int j; - signed int Set_xsize_at_least_two_times_Na=2 * ds.a_size; - printf("X_SIZE must be at least 2 * ds.a_size"); - /* assertion X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na */ - assert(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na); - if(X_SIZE_VALUE >= Set_xsize_at_least_two_times_Na) - (void)0; - - signed long int min_fxp=fxp_double_to_fxp(impl.min); - signed long int max_fxp=fxp_double_to_fxp(impl.max); - const signed long int max_fxp$array_size0=(signed long int)X_SIZE_VALUE; - signed long int y[max_fxp$array_size0]; - const signed long int y$array_size0=(signed long int)X_SIZE_VALUE; - signed long int x[y$array_size0]; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - { - y[(signed long int)i] = 0l; - x[(signed long int)i] = 0l; - } - signed int Nw=0; - Nw = ds.a_size > ds.b_size ? ds.a_size : ds.b_size; - const signed long int Nw$array_size0=(signed long int)ds.a_size; - signed long int yaux[Nw$array_size0]; - const signed long int yaux$array_size0=(signed long int)ds.b_size; - signed long int xaux[yaux$array_size0]; - const signed long int xaux$array_size0=(signed long int)Nw; - signed long int waux[xaux$array_size0]; - const signed long int waux$array_size0=(signed long int)ds.a_size; - signed long int y0[waux$array_size0]; - const signed long int y0$array_size0=(signed long int)Nw; - signed long int w0[y0$array_size0]; - i = 0; - for( ; !(i >= Nw); i = i + 1) - { - signed int return_value_nondet_int$1=nondet_int(); - waux[(signed long int)i] = (signed long int)return_value_nondet_int$1; - _Bool tmp_if_expr$2; - if(waux[(signed long int)i] >= min_fxp) - tmp_if_expr$2 = waux[(signed long int)i] <= max_fxp ? (_Bool)1 : (_Bool)0; - - else - tmp_if_expr$2 = (_Bool)0; - __DSVERIFIER_assume(tmp_if_expr$2); - w0[(signed long int)i] = waux[(signed long int)i]; - } - i = 0; - for( ; !(i >= ds.b_size); i = i + 1) - xaux[(signed long int)i] = 0l; - signed long int xk; - signed long int temp; - signed long int *aptr; - signed long int *bptr; - signed long int *xptr; - signed long int *yptr; - signed long int *wptr; - i = 0; - for( ; !(i >= X_SIZE_VALUE); i = i + 1) - ; - fxp_check_persistent_limit_cycle(y, X_SIZE_VALUE); - return 0; -} - -// wrap -// file /home/lucascordeiro/dsverifier/bmc/core/fixed-point.h line 100 -signed long int wrap(signed long int kX, signed long int kLowerBound, signed long int kUpperBound) -{ - signed int range_size=(signed int)((kUpperBound - kLowerBound) + 1l); - if(!(kX >= kLowerBound)) - kX = kX + (signed long int)range_size * ((kLowerBound - kX) / (signed long int)range_size + 1l); - - return kLowerBound + (kX - kLowerBound) % (signed long int)range_size; -} - diff --git a/regression/cegis/cegis_control_benchmark_05/controller.h b/regression/cegis/cegis_control_benchmark_05/controller.h deleted file mode 100644 index c144be52ec7..00000000000 --- a/regression/cegis/cegis_control_benchmark_05/controller.h +++ /dev/null @@ -1 +0,0 @@ -struct anonymous3 controller={ .den={ (control_floatt)1.000000, (control_floatt)-4.200000e-1f, (control_floatt)-3.465000e-1f, (control_floatt)-3.915000e-2f }, .den_uncertainty={ (control_floatt)0.000000, (control_floatt)0.000000, (control_floatt)0.000000, (control_floatt)0.000000 }, .den_size=4, .num={ (control_floatt)2.880000e+0, (control_floatt)-4.896000e+0f, (control_floatt)2.074000e+0 }, .num_uncertainty={ (control_floatt)0.000000, (control_floatt)0.000000, (control_floatt)0.000000 }, .num_size=3 }; diff --git a/regression/cegis/cegis_control_benchmark_05/plant.h b/regression/cegis/cegis_control_benchmark_05/plant.h deleted file mode 100644 index b8bf5575f9e..00000000000 --- a/regression/cegis/cegis_control_benchmark_05/plant.h +++ /dev/null @@ -1 +0,0 @@ -struct anonymous3 plant={ .den={ (control_floatt)1.000000, (control_floatt)-2.000000f, (control_floatt)1.000000 }, .den_uncertainty={ (control_floatt)0.000000, (control_floatt)0.000000, (control_floatt)0.000000 }, .den_size=3, .num={ (control_floatt)1.250000e-1, (control_floatt)1.250000e-1 }, .num_uncertainty={ (control_floatt)0.000000, (control_floatt)0.000000 }, .num_size=2 }; diff --git a/regression/cegis/cegis_control_benchmark_05/simplified_noise.c b/regression/cegis/cegis_control_benchmark_05/simplified_noise.c deleted file mode 100644 index 5763bdcae90..00000000000 --- a/regression/cegis/cegis_control_benchmark_05/simplified_noise.c +++ /dev/null @@ -1,518 +0,0 @@ -#include -#include - -/*#define __CONTROLLER_DEN_SIZE 3 -#define __CONTROLLER_NUM_SIZE 3 -#define __PLANT_DEN_SIZE 2 -#define __PLANT_NUM_SIZE 1 -#define SOLUTION_DEN_SIZE 3 -#define SOLUTION_NUM_SIZE 3*/ -#include "sizes.h" -#define __OPENLOOP_DEN_SIZE (__CONTROLLER_DEN_SIZE+__PLANT_DEN_SIZE-1) -#define __OPENLOOP_NUM_SIZE (__CONTROLLER_NUM_SIZE+__PLANT_NUM_SIZE-1) - -#define __NORMALIZED -#ifdef __CPROVER -#ifndef _FIXEDBV - #ifndef _EXPONENT_WIDTH - #define _EXPONENT_WIDTH 16 - #endif - #ifndef _FRACTION_WIDTH - #define _FRACTION_WIDTH 11 - #endif - typedef __CPROVER_floatbv[_EXPONENT_WIDTH][_FRACTION_WIDTH] control_floatt; - control_floatt _imp_max=(((1 <<(_EXPONENT_WIDTH-1))-1)<<1)+1; -#else - #ifndef _CONTROL_FLOAT_WIDTH - #define _CONTROL_FLOAT_WIDTH 16 - #endif - #ifndef _CONTORL_RADIX_WIDTH - #define _CONTORL_RADIX_WIDTH _CONTROL_FLOAT_WIDTH / 2 - #endif - typedef __CPROVER_fixedbv[_CONTROL_FLOAT_WIDTH][_CONTORL_RADIX_WIDTH] control_floatt; - control_floatt _imp_max=(((1 <<(_CONTROL_FLOAT_WIDTH-1))-1)<<1)+1; -#endif - typedef unsigned char cnttype; -#else - typedef double control_floatt; - typedef unsigned int cnttype; - #include - #include -#endif - -struct anonymous0 -{ - cnttype int_bits; - cnttype frac_bits; -}; - -struct anonymous3 -{ - control_floatt den[SOLUTION_DEN_SIZE]; - control_floatt den_uncertainty[SOLUTION_DEN_SIZE]; - cnttype den_size; - control_floatt num[SOLUTION_NUM_SIZE]; - control_floatt num_uncertainty[SOLUTION_NUM_SIZE]; - cnttype num_size; -}; - -control_floatt _dbl_max; -control_floatt _dbl_min; -signed long int _fxp_max; -signed long int _fxp_min; -signed long int _fxp_one; -control_floatt _dbl_lsb; -control_floatt _poly_error; -control_floatt _sum_error; -control_floatt _plant_norm; - -struct anonymous0 impl={ .int_bits=_CONTROLER_INT_BITS, .frac_bits=_CONTROLER_FRAC_BITS}; - -#include "plant.h" -/*struct anonymous3 plant={ .den={ 1.0, -9.998000e-1, 0.0}, .den_uncertainty={0.0, 0.0, 0.0}, .den_size=2, -.num={ 2.640000e-2, 0.0, 0.0}, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=1};*/ -/*struct anonymous3 plant={ .den={ 1.0, -3.32481248817168, 1.64872127070013 }, .den_size=3, - .num={ 0.548693198268086, -0.886738807003861, 0.0 }, .num_size=2};*/ - -struct anonymous3 plant_cbmc,controller_cbmc; -//#ifdef __CPROVER -#include "controller.h" -//extern struct anonymous3 controller; -/*#else -//struct anonymous3 controller = { .den={ 32218.8125, 3544.125, 29723.25 }, .den_uncertainty={0.0, 0.0, 0.0}, .den_size=3, -// .num={ 17509.4375, 7878.25, 12107.6875 }, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=3}; -struct anonymous3 controller = { .den={ 25868.375, -12550.9375, 5127.375 },.den_uncertainty={0.0, 0.0, 0.0}, .den_size=3, - .num={ 26097, -303.0625, -23076.25 }, .num_uncertainty={0.0, 0.0, 0.0}, .num_size=3}; -#endif*/ - -void __DSVERIFIER_assume(_Bool expression) -{ -#ifdef __CPROVER - __CPROVER_assume(expression != (_Bool)0); -#endif -} - -void __DSVERIFIER_assert(_Bool expression) -{ - /* assertion expression */ - assert(expression != (_Bool)0); -} - -void initialization() -{ - __DSVERIFIER_assert(impl.int_bits+impl.frac_bits < 32); -#ifdef __NORMALIZED - _fxp_one = 1 << (impl.frac_bits + impl.int_bits); - _dbl_lsb=1.0/(1 << impl.frac_bits + impl.int_bits); - _fxp_min = -(1 << (impl.frac_bits + impl.int_bits -1)); - _fxp_max = (1 << (impl.frac_bits + impl.int_bits-1))-1; - _dbl_max = (1.0-_dbl_lsb);//Fractional part -#else - if(impl.frac_bits >= 31) - _fxp_one = 2147483647l; - else - _fxp_one = (1 << impl.frac_bits); - _dbl_lsb=1.0/(1 << impl.frac_bits); - _fxp_min = -(1 << (impl.frac_bits + impl.int_bits -1)); - _fxp_max = (1 << (impl.frac_bits + impl.int_bits-1))-1; - _dbl_max = (1 << (impl.int_bits-1))-1;//Integer part - _dbl_max += (1.0-_dbl_lsb);//Fractional part -#endif - _dbl_min = -_dbl_max; -#ifdef __CHECK_FP - if (SOLUTION_DEN_SIZE>SOLUTION_NUM_SIZE) - { - _poly_error=2*_dbl_lsb*SOLUTION_DEN_SIZE; - _sum_error=2*_poly_error*SOLUTION_DEN_SIZE; - } - else - { - _poly_error=2*_dbl_lsb*SOLUTION_NUM_SIZE; - _sum_error=2*_poly_error*SOLUTION_DEN_SIZE; - } -#else - _poly_error=0; - _sum_error=0; -#endif -} - -int validation() -{ - cnttype i; - control_floatt max=0; - for (i=0;imax) max=plant.num[i]; - else if (-plant.num[i]>max) max=-plant.num[i]; - } - for (i=0;imax) max=plant.den[i]; - else if (-plant.den[i]>max) max=-plant.den[i]; - } - unsigned int max_int=max; -#ifdef __NORMALIZED - cnttype mult_bits=1; -#else - cnttype mult_bits=12; -#endif - while (max_int>0) - { - mult_bits++; - max_int>>=1; - } - _plant_norm=1<= _dbl_min); -#else - printf("value=%f", value); - if(value > _dbl_max) return 10; - if(value < _dbl_min) return 10; -#endif - } - for(i = 0 ; i < __CONTROLLER_NUM_SIZE; i++) - { - const control_floatt value=controller.num[i]; -#ifdef __CPROVER - __DSVERIFIER_assume(value <= _dbl_max); - __DSVERIFIER_assume(value >= _dbl_min); -#else - if (value > _dbl_max) return 10; - if (value < _dbl_min) return 10; -#endif - } - return 0; -} - -#ifndef __CPROVER -void print_poly(control_floatt *pol,cnttype n) -{ - cnttype i; - for (i=0;i 0.0) - { - control_floatt factor=(plant.num[i] * plant.num_uncertainty[i]) / 100.0; - factor = factor < 0.0 ? -factor : factor; - control_floatt min=plant.num[i] -factor; - control_floatt max=plant.num[i] +factor; - plant_cbmc.num[i] = nondet_double(); - __DSVERIFIER_assume(plant_cbmc.num[i] >= min); - __DSVERIFIER_assume(plant_cbmc.num[i] <= max); -#ifdef __NORMALIZED - plant_cbmc.num[i]/=_plant_norm; -#endif - } - else -#endif -#ifdef __NORMALIZED - plant_cbmc.num[i] = plant.num[i]/_plant_norm; -#else - plant_cbmc.num[i] = plant.num[i]; -#endif - plant_cbmc.den_size=plant.den_size; - for(i = 0; i < plant.den_size; i++) -#ifdef __CPROVER - if(plant.den_uncertainty[i] > 0.0) - { - control_floatt factor=(plant.den[i] * plant.den_uncertainty[i]) / 100.0; - factor = factor < 0.000000 ? -factor : factor; - control_floatt min=plant.den[i] -factor; - control_floatt max=plant.den[i] +factor; - plant_cbmc.den[i] = nondet_double(); - __DSVERIFIER_assume(plant_cbmc.den[i] >= min); - __DSVERIFIER_assume(plant_cbmc.den[i] <= max); -#ifdef __NORMALIZED - plant_cbmc.den[i]/=_plant_norm; -#endif - } - else -#endif -#ifdef __NORMALIZED - plant_cbmc.den[i] = plant.den[i]/_plant_norm; -#else - plant_cbmc.den[i] = plant.den[i]; -#endif -} - -int assert_nonzero_controller(void) -{ - unsigned int zero_count = 0; - for(unsigned int i=0; i < __CONTROLLER_DEN_SIZE; i++) - if (controller.den[i] == 0.0) ++zero_count; -#ifdef __CPROVER - __DSVERIFIER_assert(zero_count < __CONTROLLER_DEN_SIZE); -#else - if (zero_count >= __CONTROLLER_DEN_SIZE) return 0; -#endif - zero_count = 0; - for(unsigned int i = 0 ; i < __CONTROLLER_NUM_SIZE; i++) - if (controller.num[i] == 0.0) ++zero_count; -#ifdef __CPROVER - __DSVERIFIER_assert(zero_count < __CONTROLLER_NUM_SIZE); -#else - if (zero_count >= __CONTROLLER_NUM_SIZE) return 0; -#endif - return 1; -} - -signed int check_stability_closedloop(control_floatt *a, cnttype n) -{ - cnttype columns=n; - control_floatt m[n][n]; - cnttype i; - cnttype j; - control_floatt sum=0.0; - for(i = 0 ; i < n; i++) { sum += a[i]; } -#ifdef __CPROVER - __DSVERIFIER_assert(a[0] > _poly_error); - __DSVERIFIER_assert(sum > _sum_error); - __DSVERIFIER_assert(a[n-1]+_poly_error < a[0]); - __DSVERIFIER_assert(-a[n-1]+_poly_error < a[0]); -#else - printf("m[0]=%f>0\n", a[0]); - //std::cout << "m[0]=" << a[0] << ">0" << std::endl; - printf("fabs(m[%d]=%f)0\n", sum); - //std::cout << "sum=" << sum << ">0" << std::endl; - if (!(a[0] > _poly_error)) return 0; - if (!(sum > _sum_error)) return 0; - if (!(a[n - 1]+_poly_error < a[0])) return 0; - if (!(-a[n - 1]+_poly_error < a[0])) return 0; -#endif - sum = 0.0; - for(i = 0 ; i < n; i++) - { - if (((n -i)&1)!=0) sum+=a[i]; - else sum-=a[i]; - } - if ((n&1)==0) sum=-sum; -#ifdef __CPROVER - __DSVERIFIER_assert(sum > _sum_error); -#else - printf("sumEven-sumOdd=%f>0\n", sum); - //std::cout << "sumEven-sumOdd=" << sum << ">0" << std::endl; - if (!(sum > _sum_error)) return 0; -#endif - for(j=0;j0 - __DSVERIFIER_assert(m[i-1][0] > 0.0); - control_floatt factor=m[i-1][columns] / m[i-1][0]; -#ifdef __CHECK_FP - if (m[i-1][0]<0) __DSVERIFIER_assert(m[i-1][0]<-(mag*mag/_imp_max+_poly_error)); - else __DSVERIFIER_assert(m[i-1][0]> (mag*mag/_imp_max+_poly_error));//check for overflow. - control_floatt efactor=m[i-1][columns]; - if (efactor<0) efactor=-efactor; - efactor+=_poly_error; - efactor/=m[i-1][0]-_poly_error; - efactor-=factor; - __DSVERIFIER_assert(efactor<_poly_error*mag); - if (factor>0) - { - _poly_error*=2+factor;//Unsound! does not consider the error in factor (a+e/b-e = a/(b-e) +e/(b-e)) - mag+=mag*factor; - } - else - { - _poly_error*=2-factor; - mag-=mag*factor; - } -#endif - for(j=0;j= _poly_error); -#else - printf("m[%d]=%f>0\n", i, m[i][0]); - //std::cout << "m[" << i << "]=" << m[i][0] << ">0" << std::endl; - if (!(m[i][0] >= _poly_error)) return 0; -#endif - columns--; - } - return 1; -} - -signed long int fxp_control_floatt_to_fxp(control_floatt value) -{ - signed long int tmp; - control_floatt ftemp=value * _fxp_one; - tmp = ftemp; - control_floatt residue=ftemp - tmp; - if(value < 0.0 && (residue != 0.0)) - { - ftemp = ftemp - 1.0; - tmp = ftemp; - } - return tmp; -} - -void fxp_check(control_floatt *value) -{ -#ifdef __CPROVER - control_floatt tmp_value=*value; - if (tmp_value < 0.0) tmp_value=-tmp_value; - __DSVERIFIER_assert((~_dbl_max&tmp_value)==0); -#else - *value=fxp_control_floatt_to_fxp(*value); - *value/=_fxp_one; -#endif -} - -void fxp_check_array(control_floatt *f, cnttype N) -{ - for(cnttype i=0; i < N; i++) fxp_check(&f[i]); -} - -void poly_mult(control_floatt *a, cnttype Na, control_floatt *b, cnttype Nb, control_floatt *ans, cnttype Nans) -{ - cnttype i; - cnttype j; - cnttype k; - Nans = Na + Nb - 1; - for(i = 0 ; i/dev/null -timeout_time=300 - -start_time=$(($(date +%s%N)/1000000)) -timeout --kill-after=10 ${timeout_time} bash ${tool} --no-unwinding-assertions $2 -if [ $? -eq 124 ]; then - timed_out=0 -else - timed_out=1 -fi -end_time=$(($(date +%s%N)/1000000)) -duration=$(echo "${end_time} - ${start_time}" | bc) -grep "VERIFICATION FAILED" ${out_file} >/dev/null -error_found=$? -grep "VERIFICATION SUCCESSFUL" ${out_file} >/dev/null -no_bugs=$? -if [ ${timed_out} -eq 0 ]; then - echo -e "${benchmark}\tTIMEOUT\t${duration}" >>"${out_file}" -elif [ ${error_found} -eq 0 ]; then - echo -e "${benchmark}\tVER-FALSE\t${duration}" >>"${out_file}" -elif [ ${no_bugs} -eq 0 ]; then - echo -e "${benchmark}\tVER-TRUE\t${duration}" >>"${out_file}" -else - echo -e "${benchmark}\tUNKNOWN\t${duration}" >>"${out_file}" -fi - -echo " ${duration}" >>"${out_file}" -echo "" >>"${out_file}" diff --git a/regression/cegis/cegis_danger_benchmark_01_19/run-danger.sh b/regression/cegis/cegis_danger_benchmark_01_19/run-danger.sh deleted file mode 100755 index 85209320463..00000000000 --- a/regression/cegis/cegis_danger_benchmark_01_19/run-danger.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -# Experiment script. Copy to "/regression/". Use as follows: -# ./run-danger.sh [cegis|cegis-no-ranking] - -defaultArgs='--cegis-statistics --cegis-genetic main.c' -config1Out='main.cegis-config1.out' -config2Out='main.cegis-config2.out' -config3Out='main.cegis-config3.out' -config4Out='main.cegis-config4.out' -successValue='' -baseDir=`pwd` - -trap '' SIGTERM - -config_input=$1 -if [ -z "$1" ]; then config_input='cegis'; fi - -for config in ${config_input}; do - resultFile="${baseDir}/${config}.txt" - truncate -s 0 "${resultFile}" - for benchmark in ${baseDir}/cegis/cegis_danger_benchmark_*; do - echo "${benchmark}" - cd "${benchmark}" - echo -n `basename ${benchmark}` >>"${resultFile}" - benchmarkArgs="--cegis-statistics --cegis-genetic main.c" - if [ "${config}" == "cegis-no-ranking" ]; then - benchmarkArgs="--danger-no-ranking ${benchmarkArgs}" - fi - if grep --quiet 'safety' 'test.desc'; then - benchmarkArgs="--safety ${benchmarkArgs}" - else - benchmarkArgs="--danger ${benchmarkArgs}" - fi - - truncate -s 0 ${config1Out} - truncate -s 0 ${config2Out} - truncate -s 0 ${config3Out} - truncate -s 0 ${config4Out} - - cegis ${benchmarkArgs} --cegis-parallel-verify >${config1Out} 2>main.cegis.err & - config1Pid=$! - cegis ${benchmarkArgs} --cegis-symex-head-start 2 >${config2Out} 2>main.cegis.err & - config2Pid=$! - cegis ${benchmarkArgs} --cegis-tournament-select >${config3Out} 2>main.cegis.err & - config3Pid=$! - cegis ${benchmarkArgs} --cegis-tournament-select --cegis-symex-head-start 2 >${config4Out} 2>main.cegis.err & - config4Pid=$! - - config1Stopped=0 - while [ ${config1Stopped} -eq 0 ] || [ ${config2Stopped} -eq 0 ] || [ ${config3Stopped} -eq 0 ] || [ ${config4Stopped} -eq 0 ]; do - kill -0 ${config1Pid} >/dev/null 2>&1; config1Stopped=$? - grep --quiet "${successValue}" ${config1Out}; config1Success=$? - kill -0 ${config2Pid} >/dev/null 2>&1; config2Stopped=$? - grep --quiet "${successValue}" ${config2Out}; config2Success=$? - kill -0 ${config3Pid} >/dev/null 2>&1; config3Stopped=$? - grep --quiet "${successValue}" ${config3Out}; config3Success=$? - kill -0 ${config4Pid} >/dev/null 2>&1; config4Stopped=$? - grep --quiet "${successValue}" ${config4Out}; config4Success=$? - - if [ ${config1Success} -eq 0 ] || [ ${config2Success} -eq 0 ] || [ ${config3Success} -eq 0 ] || [ ${config4Success} -eq 0 ]; then - while [ ${config1Stopped} -eq 0 ] || [ ${config2Stopped} -eq 0 ] || [ ${config3Stopped} -eq 0 ] || [ ${config4Stopped} -eq 0 ]; do - killall -9 cegis >/dev/null 2>&1 - kill -0 ${config1Pid} >/dev/null 2>&1; config1Stopped=$? - kill -0 ${config2Pid} >/dev/null 2>&1; config2Stopped=$? - kill -0 ${config3Pid} >/dev/null 2>&1; config3Stopped=$? - kill -0 ${config4Pid} >/dev/null 2>&1; config4Stopped=$? - sleep 10 - done - fi - sleep 10 - done - - if [ ${config1Success} -eq 0 ]; then - echo -n ' config1' >>"${resultFile}" - outFile=${config1Out} - elif [ ${config2Success} -eq 0 ]; then - echo -n ' config2' >>"${resultFile}" - outFile=${config2Out} - elif [ ${config3Success} -eq 0 ]; then - echo -n ' config3' >>"${resultFile}" - outFile=${config3Out} - elif [ ${config4Success} -eq 0 ]; then - echo -n ' config4' >>"${resultFile}" - outFile=${config4Out} - else - echo -n ' none' >>"${resultFile}" - outFile='none' - fi - - if [ "${outFile}" == "none" ]; then - echo " N/A" >>"${resultFile}" - else - tac ${outFile} | grep -P '([^<]+)' -m1 | sed -E "s/([^<]+)<\/full_time>/\\1/" >>"${resultFile}" - fi - - done -done diff --git a/regression/cegis/cegis_danger_benchmark_01_19/test.desc b/regression/cegis/cegis_danger_benchmark_01_19/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_01_19/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_02_20/main.c b/regression/cegis/cegis_danger_benchmark_02_20/main.c deleted file mode 100644 index 5a35ed5dd4b..00000000000 --- a/regression/cegis/cegis_danger_benchmark_02_20/main.c +++ /dev/null @@ -1,19 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y; - - x = 0; - y = 0; - - while (x < 1000003) { - x++; - - int nondet_0; - if (nondet_0) { - y++; - } - } - - __CPROVER_assert(x != y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_02_20/test.desc b/regression/cegis/cegis_danger_benchmark_02_20/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_02_20/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_03_21/main.c b/regression/cegis/cegis_danger_benchmark_03_21/main.c deleted file mode 100644 index bd42d8704f3..00000000000 --- a/regression/cegis/cegis_danger_benchmark_03_21/main.c +++ /dev/null @@ -1,19 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y; - - x = 0; - y = 1; - - while (x < 1000000) { - x++; - - int nondet_0; - if (nondet_0) { - y++; - } - } - - __CPROVER_assert(x != y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_03_21/test.desc b/regression/cegis/cegis_danger_benchmark_03_21/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_03_21/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_04_23/main.c b/regression/cegis/cegis_danger_benchmark_04_23/main.c deleted file mode 100644 index 8f8c71b9108..00000000000 --- a/regression/cegis/cegis_danger_benchmark_04_23/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int len; - unsigned int i; - - len = x * 4; - i = 0; - - while (i * 4 < len && i < x) { - i++; - } - - __CPROVER_assert(i * 4 < len || i >= x, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_04_23/test.desc b/regression/cegis/cegis_danger_benchmark_04_23/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_04_23/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_05_24/main.c b/regression/cegis/cegis_danger_benchmark_05_24/main.c deleted file mode 100644 index bfad2d2f107..00000000000 --- a/regression/cegis/cegis_danger_benchmark_05_24/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int i, c, a; - - i = 0; - c = 0; - - while (i < 1000003) { - c = c+i; - i++; - - } - - __CPROVER_assert(a > 0, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_05_24/test.desc b/regression/cegis/cegis_danger_benchmark_05_24/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_05_24/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_06_25/main.c b/regression/cegis/cegis_danger_benchmark_06_25/main.c deleted file mode 100644 index f1e8507a662..00000000000 --- a/regression/cegis/cegis_danger_benchmark_06_25/main.c +++ /dev/null @@ -1,29 +0,0 @@ -int main(void) { - int x, y; - unsigned int lockstate; - - lockstate = 0; - - lockstate = 1; - x = y; - - int nondet_0; - if (nondet_0) { - lockstate = 0; - y++; - } - - while (x != y) { - lockstate = 1; - x = y; - - int nondet_1; - if (nondet_1) { - lockstate = 0; - y++; - } - } - - __CPROVER_assert(lockstate == 0, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_06_25/test.desc b/regression/cegis/cegis_danger_benchmark_06_25/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_06_25/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_11_33/main.c b/regression/cegis/cegis_danger_benchmark_11_33/main.c deleted file mode 100644 index df0d2cb3748..00000000000 --- a/regression/cegis/cegis_danger_benchmark_11_33/main.c +++ /dev/null @@ -1,16 +0,0 @@ -int main(void) { - int x; - - if (x < 100 || x > 200) { - return 0; - } - - x=x; - - while (x > 0) { - x -= 2; - } - - __CPROVER_assert(x >= 0, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_11_33/test.desc b/regression/cegis/cegis_danger_benchmark_11_33/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_11_33/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_17_40/main.c b/regression/cegis/cegis_danger_benchmark_17_40/main.c deleted file mode 100644 index bf19f873fb9..00000000000 --- a/regression/cegis/cegis_danger_benchmark_17_40/main.c +++ /dev/null @@ -1,18 +0,0 @@ -int main(void) { - unsigned int x, y; - - x = 0; - y = 1; - - while (x < 1000003) { - x++; - - unsigned int nondet_0; - if (nondet_0) { - y++; - } - } - - __CPROVER_assert(x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_17_40/test.desc b/regression/cegis/cegis_danger_benchmark_17_40/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_17_40/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_18_41/main.c b/regression/cegis/cegis_danger_benchmark_18_41/main.c deleted file mode 100644 index e989df28345..00000000000 --- a/regression/cegis/cegis_danger_benchmark_18_41/main.c +++ /dev/null @@ -1,22 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y; - - x = 0; - y = 0; - - while (x < 1000003) { - unsigned int nondet_0; - if (nondet_0) { - x++; - } - - unsigned int nondet_1; - if (nondet_1) { - y++; - } - } - - __CPROVER_assert(x != y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_18_41/test.desc b/regression/cegis/cegis_danger_benchmark_18_41/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_18_41/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_19_42/main.c b/regression/cegis/cegis_danger_benchmark_19_42/main.c deleted file mode 100644 index 9f5b452dad8..00000000000 --- a/regression/cegis/cegis_danger_benchmark_19_42/main.c +++ /dev/null @@ -1,21 +0,0 @@ -int main(void) { - unsigned int x, y; - - x = 0; - y = 1; - - while (x < 1000003) { - unsigned int nondet_0; - if (nondet_0) { - x++; - } - - unsigned int nondet_1; - if (nondet_1) { - y++; - } - } - - __CPROVER_assert(x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_19_42/test.desc b/regression/cegis/cegis_danger_benchmark_19_42/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_19_42/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_20_43/main.c b/regression/cegis/cegis_danger_benchmark_20_43/main.c deleted file mode 100644 index 215774942f4..00000000000 --- a/regression/cegis/cegis_danger_benchmark_20_43/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - - unsigned int x; - - - while (x < 10) { - x++; - } - - __CPROVER_assert(x == 10, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_20_43/test.desc b/regression/cegis/cegis_danger_benchmark_20_43/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_20_43/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/main.c deleted file mode 100644 index 1f9d24c007f..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y = 0; - - while (y < 1024) { - x = 0; - y++; - } - - __CPROVER_assert(x == 1, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/main.c deleted file mode 100644 index 4ea09aef903..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y = 0; - - while (y < 10) { - x = 0; - y++; - } - - __CPROVER_assert(x == 1, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_10/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/main.c deleted file mode 100644 index 4d112f6e9b2..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y = 0; - - while (y < 1000003) { - x = 0; - y++; - } - - __CPROVER_assert(x == 1, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_false-unreach-call1_1000003/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/main.c deleted file mode 100644 index 0d6e7303e1c..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y = 0; - - while (y < 1024) { - x = 0; - y++; - } - - __CPROVER_assert(x == 0, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_const_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/main.c deleted file mode 100644 index 3b48a6606ed..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int x=0; - unsigned int y; - - while (x < 99) { - if (y % 2 == 0) { - x++; - } else { - x += 2; - } - } - - __CPROVER_assert((x % 2) == (y % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/main.c deleted file mode 100644 index cb405d0b508..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/main.c +++ /dev/null @@ -1,41 +0,0 @@ -// Adapted version of diamond_true-unreach-call2 in SVCOMP. - -int main(void) { - unsigned int x=0; - unsigned int y; - - while (x < 99) { - if (y % 2 == 0) x++; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x += 4; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x -= 4; - } - - __CPROVER_assert((x % 2) == (y % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_false-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/main.c deleted file mode 100644 index 8adcfbcf849..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int x=0; - unsigned int y; - - while (x < 99) { - if (y % 2 == 0) { - x += 2; - } else { - x++; - } - } - - __CPROVER_assert((x % 2) == (y % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/main.c deleted file mode 100644 index 94fb79f54a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/main.c +++ /dev/null @@ -1,39 +0,0 @@ -int main(void) { - unsigned int x=0; - unsigned int y; - - while (x < 99) { - if (y % 2 == 0) x += 2; - else x++; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x += 4; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x -= 4; - } - - __CPROVER_assert((x % 2) == (y % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_diamond_true-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/main.c deleted file mode 100644 index 94fb79f54a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/main.c +++ /dev/null @@ -1,39 +0,0 @@ -int main(void) { - unsigned int x=0; - unsigned int y; - - while (x < 99) { - if (y % 2 == 0) x += 2; - else x++; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 2; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x += 4; - - if (y % 2 == 0) x += 2; - else x += 2; - - if (y % 2 == 0) x += 2; - else x -= 4; - - if (y % 2 == 0) x += 2; - else x -= 4; - } - - __CPROVER_assert((x % 2) == (y % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_for_bounded_loop1_false-unreach-call_true-termination/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/main.c deleted file mode 100644 index f1e5e9c6ee7..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/main.c +++ /dev/null @@ -1,14 +0,0 @@ -unsigned int f(unsigned int z) { - return z + 2; -} - -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - x = f(x); - } - - __CPROVER_assert(x % 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_functions_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/main.c deleted file mode 100644 index 1a9b0e4ed68..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/main.c +++ /dev/null @@ -1,14 +0,0 @@ -unsigned int f(unsigned int z) { - return z + 2; -} - -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - x = f(x); - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_functions_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/main.c deleted file mode 100644 index fb9479c91e4..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y = x + 1; - - while (x < 1024) { - x++; - y++; - } - - __CPROVER_assert(x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/main.c deleted file mode 100644 index 66612e71701..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y = x + 1; - - while (x < 100) { - x++; - y++; - } - - __CPROVER_assert(x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_false-unreach-call1_100/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/main.c deleted file mode 100644 index 79efc9e9aa1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x; - unsigned int y = x; - - while (x < 1024) { - x++; - y++; - } - - __CPROVER_assert(x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_multivar_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/main.c deleted file mode 100644 index 8f9b9f07f11..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/main.c +++ /dev/null @@ -1,14 +0,0 @@ -// Adapted version of overflow_true-unreach-call1 in SVCOMP. - -int main(void) { - unsigned int x; - - x = 10; - - while (x >= 10) { - x += 2; - } - - __CPROVER_assert(x % 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/main.c deleted file mode 100644 index 524dbaaf2c5..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x; - - x = 10; - - while (x >= 10) { - x += 2; - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_overflow_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/main.c deleted file mode 100644 index f9a6b130731..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/main.c +++ /dev/null @@ -1,14 +0,0 @@ -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - if (x < 0xfff1) { - x++; - } else { - x += 2; - } - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/main.c deleted file mode 100644 index afee13a210b..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y; - - while (y > 0 && x < y) { - if (x > 0 && x < y / x) { - x *= x; - } else { - x++; - } - } - - __CPROVER_assert(y == 0 || x != y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_false-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/main.c deleted file mode 100644 index c3565019410..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/main.c +++ /dev/null @@ -1,14 +0,0 @@ -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - if (x < 0xfff0) { - x++; - } else { - x += 2; - } - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/main.c deleted file mode 100644 index 8d2b8427358..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/main.c +++ /dev/null @@ -1,15 +0,0 @@ -int main(void) { - unsigned int x = 1; - unsigned int y; - - while (y > 0 && x < y) { - if (x > 0 && x < y / x) { - x *= x; - } else { - x++; - } - } - - __CPROVER_assert(y == 0 || x == y, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_phases_true-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/main.c deleted file mode 100644 index d9d7e6f8e5d..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/main.c +++ /dev/null @@ -1,10 +0,0 @@ -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - x += 2; - } - - __CPROVER_assert(x % 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/main.c deleted file mode 100644 index efdd2e988f0..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/main.c +++ /dev/null @@ -1,10 +0,0 @@ -int main(void) { - unsigned int x; - - while (x < 0x0fffffff) { - x++; - } - - __CPROVER_assert(x > 0x0fffffff, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/main.c deleted file mode 100644 index 3ac5510121d..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 0; - //unsigned short N; - unsigned int N; - N %= 0xFFFF; - - while (x < N) { - x += 2; - } - - __CPROVER_assert(x % 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call3/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/main.c deleted file mode 100644 index 01d3e07c68a..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/main.c +++ /dev/null @@ -1,11 +0,0 @@ -int main(void) { - unsigned int x = 0x0ffffff1; - - while (x > 1) { - x -= 2; - } - - __CPROVER_assert(!(x % 2), "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_false-unreach-call4/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/main.c deleted file mode 100644 index 2e203d6ca7e..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/main.c +++ /dev/null @@ -1,10 +0,0 @@ -int main(void) { - unsigned int x = 0; - - while (x < 0x0fffffff) { - x += 2; - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/main.c deleted file mode 100644 index 6f0427de737..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/main.c +++ /dev/null @@ -1,10 +0,0 @@ -int main(void) { - unsigned int x; - - while (x < 0x0fffffff) { - x++; - } - - __CPROVER_assert(x >= 0x0fffffff, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/main.c deleted file mode 100644 index 8add4c8268d..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - unsigned int x = 0; - //unsigned short N; - unsigned int N; - N %= 0xFFFF; - - while (x < N) { - x += 2; - } - - __CPROVER_assert(!(x % 2), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call3/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/main.c deleted file mode 100644 index 4196c8e7ad1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/main.c +++ /dev/null @@ -1,11 +0,0 @@ -int main(void) { - unsigned int x = 0x0ffffff0; - - while (x > 0) { - x -= 2; - } - - __CPROVER_assert(!(x % 2), "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_simple_true-unreach-call4/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_sum01_bug02_false-unreach-call_true-termination/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_sum01_bug02_false-unreach-call_true-termination/main.c deleted file mode 100644 index bf227ba83a4..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_sum01_bug02_false-unreach-call_true-termination/main.c +++ /dev/null @@ -1,16 +0,0 @@ -#define a (2) -int main() { - int i; - int j=10; - int n; - int sn=0; - - for(i=1; i<=n; i++) { - if (i 0 && x<100) - { - x=x+y; - } - - __CPROVER_assert(y<=0 || (y<0 && x>=100), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/main.c deleted file mode 100644 index f66dfed0508..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main() -{ - int x; - int y; - - while(y > 0 && x<1000003) - { - x=x+y; - } - - __CPROVER_assert(y<=0 || (y<0 && x>=1000003), "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_terminator_03_false-unreach-call_true-termination_1000003/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/main.c deleted file mode 100644 index 8d5efa4cdb7..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) { - int x; - - while (x > 0) { - int c; - if(c) x--; - else x--; - } - - __CPROVER_assert(x==0, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_trex02_false-unreach-call_true-termination/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/main.c deleted file mode 100644 index 8a804f41ada..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/main.c +++ /dev/null @@ -1,26 +0,0 @@ -int main(void) { - unsigned int x1; - unsigned int x2; - unsigned int x3; - unsigned int d1=1; - unsigned int d2=1; - unsigned int d3=1; - - int c1; - int c2; - - while(x1>0 && x2>0 && x3>0) - { - if (c1) x1=x1-d1; - else if (c2) x2=x2-d2; - else x3=x3-d3; - int nondet_0; - c1=nondet_0; - int nondet_1; - c2=nondet_1; - } - - __CPROVER_assert(x1==0 && x2==0 && x3==0, "A"); - - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_trex03_false-unreach-call_true-termination/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/main.c deleted file mode 100644 index 3fc2ec7e206..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x = 0; - unsigned int y = 1; - - while (x < 6) { - x++; - y *= 2; - } - - __CPROVER_assert(y != 64, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/main.c deleted file mode 100644 index f087d7766a3..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x = 0; - unsigned int y = 1; - - while (x < 6) { - x++; - y *= 2; - } - - __CPROVER_assert(x != 6, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/test.desc deleted file mode 100644 index f57dcb6d0a1..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_false-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/main.c deleted file mode 100644 index 2266c1b2272..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x = 0; - unsigned int y = 1; - - while (x < 6) { - x++; - y *= 2; - } - - __CPROVER_assert(y % 3, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call1/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/main.c b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/main.c deleted file mode 100644 index 88872e77e2c..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - unsigned int x = 0; - unsigned int y = 1; - - while (x < 6) { - x++; - y *= 2; - } - - __CPROVER_assert(x == 6, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/test.desc b/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/test.desc deleted file mode 100644 index b81a22e5b16..00000000000 --- a/regression/cegis/cegis_danger_benchmark_svcomp_underapprox_true-unreach-call2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_2x0/main.c b/regression/cegis/cegis_danger_unit_2x0/main.c deleted file mode 100644 index 54e1c277b39..00000000000 --- a/regression/cegis/cegis_danger_unit_2x0/main.c +++ /dev/null @@ -1,11 +0,0 @@ -int main(void) -{ - int x; - int y; - int z=0; - while (x != 99 && y != 508) - ++z; - - __CPROVER_assert(y != 508, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_2x0/test.desc b/regression/cegis/cegis_danger_unit_2x0/test.desc deleted file mode 100644 index 14f8e34538d..00000000000 --- a/regression/cegis/cegis_danger_unit_2x0/test.desc +++ /dev/null @@ -1,10 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)]x *- *DANGER_CONSTANT_2u;$ -^.*__CPROVER_danger_R0_x_0 *= *DANGER_CONSTANT_3u *- *[\(]unsigned *int[\)]x;$ -^.*__CPROVER_danger_S0_x_0 *= *[\(]unsigned *int[\)]x *<< *[\(]unsigned *int[\)]x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_full1/main.c b/regression/cegis/cegis_danger_unit_full1/main.c deleted file mode 100644 index 7ee473d7c0c..00000000000 --- a/regression/cegis/cegis_danger_unit_full1/main.c +++ /dev/null @@ -1,13 +0,0 @@ -int main(void) -{ - int x = 0; - while (x < 2) - { - int condition; - if(condition) - ++x; - ++x; - } - __CPROVER_assert(x == 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_full1/test.desc b/regression/cegis/cegis_danger_unit_full1/test.desc deleted file mode 100644 index 14f8e34538d..00000000000 --- a/regression/cegis/cegis_danger_unit_full1/test.desc +++ /dev/null @@ -1,10 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)]x *- *DANGER_CONSTANT_2u;$ -^.*__CPROVER_danger_R0_x_0 *= *DANGER_CONSTANT_3u *- *[\(]unsigned *int[\)]x;$ -^.*__CPROVER_danger_S0_x_0 *= *[\(]unsigned *int[\)]x *<< *[\(]unsigned *int[\)]x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_full2/main.c b/regression/cegis/cegis_danger_unit_full2/main.c deleted file mode 100644 index a3f4677c795..00000000000 --- a/regression/cegis/cegis_danger_unit_full2/main.c +++ /dev/null @@ -1,14 +0,0 @@ -int main(void) -{ - int x = 0; - while (x < 2) - { - int condition; - int condition2; - if(condition || condition2) - ++x; - ++x; - } - __CPROVER_assert(x == 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_full2/test.desc b/regression/cegis/cegis_danger_unit_full2/test.desc deleted file mode 100644 index 043b25c8d05..00000000000 --- a/regression/cegis/cegis_danger_unit_full2/test.desc +++ /dev/null @@ -1,13 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_tmp_0 *= *[\(]unsigned *int[\)][\(][\(]unsigned *int[\)]x *<= *DANGER_CONSTANT_2u *&& *DANGER_CONSTANT_2u *<= *[\(]unsigned *int[\)]x[\)];$ -^.*__CPROVER_danger_D0_x *= *DANGER_CONSTANT_4294967295u *[\+] *__CPROVER_danger_tmp_0;$ -^.*__CPROVER_danger_tmp_0 *= *[\(]unsigned *int[\)][\(][\(]signed *int[\)]DANGER_CONSTANT_4294967295u *>> *[\(]unsigned *int[\)]x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *DANGER_CONSTANT_3u *- *[\(]unsigned *int[\)]x;$ -^.*__CPROVER_danger_S0_x_0 *= *[\(]unsigned *int[\)]x *<< *[\(]unsigned *int[\)]x;$ -^.*__CPROVER_danger_S0_x_1 *= *[\(]unsigned *int[\)][\(]__CPROVER_danger_S0_x_0 *< *DANGER_CONSTANT_0u *&& *DANGER_CONSTANT_0u *< *DANGER_CONSTANT_4294967294u[\)];$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_no_ranking/main.c b/regression/cegis/cegis_danger_unit_no_ranking/main.c deleted file mode 100644 index bf0bc818736..00000000000 --- a/regression/cegis/cegis_danger_unit_no_ranking/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) { - int x; - - x = 1000003; - - while (x > 0) { - x -= 2; - } - - __CPROVER_assert(x >= 0, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_no_ranking/test.desc b/regression/cegis/cegis_danger_unit_no_ranking/test.desc deleted file mode 100644 index ad6c659ec3c..00000000000 --- a/regression/cegis/cegis_danger_unit_no_ranking/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic --danger-no-ranking -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_ranking_and_x0/main.c b/regression/cegis/cegis_danger_unit_ranking_and_x0/main.c deleted file mode 100644 index 7c432a643e7..00000000000 --- a/regression/cegis/cegis_danger_unit_ranking_and_x0/main.c +++ /dev/null @@ -1,8 +0,0 @@ -int main(void) -{ - int x = 0; - while (x < 2) - ++x; - __CPROVER_assert(x == 4, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_ranking_and_x0/test.desc b/regression/cegis/cegis_danger_unit_ranking_and_x0/test.desc deleted file mode 100644 index cae82d5046b..00000000000 --- a/regression/cegis/cegis_danger_unit_ranking_and_x0/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)][\(][\(]signed *int[\)]DANGER_CONSTANT_4u *>> *[\(]unsigned *int[\)]x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *DANGER_CONSTANT_3u *>> *[\(]unsigned *int[\)]x; --- -^warning: ignoring diff --git a/regression/cegis/cegis_danger_unit_x0_only/main.c b/regression/cegis/cegis_danger_unit_x0_only/main.c deleted file mode 100644 index 80ae308f1c9..00000000000 --- a/regression/cegis/cegis_danger_unit_x0_only/main.c +++ /dev/null @@ -1,8 +0,0 @@ -int main(void) -{ - int x; - while (x < 2) - ++x; - __CPROVER_assert(x == 1, "A"); - return 0; -} diff --git a/regression/cegis/cegis_danger_unit_x0_only/test.desc b/regression/cegis/cegis_danger_unit_x0_only/test.desc deleted file mode 100644 index 1a387823ad1..00000000000 --- a/regression/cegis/cegis_danger_unit_x0_only/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --danger --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)][\(][\(]unsigned *int[\)]x *<= *[\(]unsigned *int[\)]x *&& *[\(]unsigned *int[\)]x *<= *DANGER_CONSTANT_3u[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *~[\(][\(]unsigned *int[\)]x[\)];$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_00/Npeople.java b/regression/cegis/cegis_jsa_benchmark_00/Npeople.java deleted file mode 100644 index cbde720ef42..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_00/Npeople.java +++ /dev/null @@ -1,51 +0,0 @@ -import java.util.*; -import java.util.LinkedList; - -public class Npeople { - public static void main(String[] args) { - new Npeople().go(); - } - - public void go() { - List people = fill(new ArrayList(), 10); - List piople = fill(new LinkedList(), 10); - removePeopleFor(people); - removePeople(piople); - - } - - public List fill(List l, int n) { - for (int i = 0; i < n; i++) { - l.add(i); - } - return l; - } - - public void removePeople(List l) { - while (l.size() > 1) { - Iterator it = l.iterator(); - int i = 0; - while (it.hasNext()) { - - Integer el = it.next(); - if ((i % 2) == 0) { - it.remove(); - System.out.println(el + " removed"); - } - i++; - } - } - } - - public void removePeopleFor(List l) { - while (l.size() > 1) { - int n = l.size(); - for (int i = n - 1; i >= 0; i--){ - if ((i % 2) == 0) { - Integer s = l.remove(i); - System.out.println(s + "removed"); - } - } - } - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_00/main.c b/regression/cegis/cegis_jsa_benchmark_00/main.c deleted file mode 100644 index 21b2dc33605..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_00/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 6u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 3u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_data_t i=0; - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t el=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - i++; - } - - return 1; -} diff --git a/regression/cegis/cegis_jsa_benchmark_00/source.url b/regression/cegis/cegis_jsa_benchmark_00/source.url deleted file mode 100644 index 748b898d1a1..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_00/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/larisa-kosareva/learningJava/d676341e8ffcafa00b7a5f6c256b1ac50a642a42/algo/Npeople.java diff --git a/regression/cegis/cegis_jsa_benchmark_00/test.desc b/regression/cegis/cegis_jsa_benchmark_00/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_00/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_01/TestStack.java b/regression/cegis/cegis_jsa_benchmark_01/TestStack.java deleted file mode 100644 index 163e9dcbbb1..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_01/TestStack.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.sinjax.techinterview.collection; - -import static org.junit.Assert.*; - -import java.util.Iterator; - -import org.junit.Test; - -public class TestStack { - @Test public void testStack(){ - Stack s = new LinkedListStack(); - for(int i = 0; i < 10; i++){ - s.push(i); - } - for(int i = 9; i >=0; i--){ - assertTrue(new Integer(i).equals(s.peek())); - assertTrue(new Integer(i).equals(s.pop())); - assertTrue(!new Integer(i).equals(s.peek())); - } - - for(int i = 0; i < 10; i++){ - s.push(i); - } - int expecting = 9; - for(Integer i : s){ - assertTrue((new Integer(expecting--)).equals(i)); - } - - Integer toRemove = 5; - Iterator it = s.iterator(); - for(;!it.hasNext();){ - { - Integer i = it.next(); - if(i.equals(toRemove)){ - it.remove(); - } - } - for(Integer i : s){ - assertTrue(!(new Integer(toRemove)).equals(i)); - } - - } - - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_01/main.c b/regression/cegis/cegis_jsa_benchmark_01/main.c deleted file mode 100644 index 0dcb8612bdb..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_01/main.c +++ /dev/null @@ -1,35 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const int toRemove=5; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (i == toRemove) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_01/source.url b/regression/cegis/cegis_jsa_benchmark_01/source.url deleted file mode 100644 index fde3092e78c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_01/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/sinjax/interviewquestions/547dcadaaaeef08356a5dfdfc6c8228202c29735/workspace/StackLinkedList/src/net/sinjax/techinterview/collection/TestStack.java diff --git a/regression/cegis/cegis_jsa_benchmark_01/test.desc b/regression/cegis/cegis_jsa_benchmark_01/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_01/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_02/RemoveDuplicates.java b/regression/cegis/cegis_jsa_benchmark_02/RemoveDuplicates.java deleted file mode 100644 index 81311b36850..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_02/RemoveDuplicates.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.*; - -public class RemoveDuplicates { - public static removeDuplicates(LinkedList list) { - HashMap occurences = new HashMap(); - - Iterator it = list.iterator(); - while(it.hasNext()) { - Integer i = (int) it.next(); - if (occurences.containsKey(i)) - - } - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_02/main.c b/regression/cegis/cegis_jsa_benchmark_02/main.c deleted file mode 100644 index c8123e2f7b8..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_02/main.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -#define contains_key(v) \ - v < 10; - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - const _Bool occurences_containsKey=contains_key(i); - if (occurences_containsKey) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_02/source.url b/regression/cegis/cegis_jsa_benchmark_02/source.url deleted file mode 100644 index d9a2615be2d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_02/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/grantamos/cracking-the-coding-interview/f38de22e99e150d3768a5b74bd82bca95c59e0f7/src/chapter-2-linked-lists/RemoveDuplicates.java diff --git a/regression/cegis/cegis_jsa_benchmark_02/test.desc b/regression/cegis/cegis_jsa_benchmark_02/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_02/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_03/TreeSetIteratorRemoveTest.java b/regression/cegis/cegis_jsa_benchmark_03/TreeSetIteratorRemoveTest.java deleted file mode 100644 index 181a4a50eef..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_03/TreeSetIteratorRemoveTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package misc; - -import java.util.Iterator; -import java.util.TreeSet; - -import junit.framework.Assert; - -import org.junit.Test; - -public class TreeSetIteratorRemoveTest { - - @Test - public void testRemove() { - - TreeSet ts = new TreeSet(); - for (int i = 1; i <= 5; ++i) - ts.add(i); - - for (Iterator it = ts.iterator(); it.hasNext(); ) { - Integer x = it.next(); - if (x == 3) { - it.remove(); - continue; - } - } - Assert.assertFalse(ts.contains(3)); - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_03/main.c b/regression/cegis/cegis_jsa_benchmark_03/main.c deleted file mode 100644 index 9bf4c2ac478..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_03/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t x=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (x == 3) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_03/source.url b/regression/cegis/cegis_jsa_benchmark_03/source.url deleted file mode 100644 index bd17b318ae0..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_03/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/losvald/spocc/eda38b7fe9eaef3ee920422fef95bcadf6a29db8/spocc-base/src/test/java/misc/TreeSetIteratorRemoveTest.java diff --git a/regression/cegis/cegis_jsa_benchmark_03/test.desc b/regression/cegis/cegis_jsa_benchmark_03/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_03/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_04/ListRemove.java b/regression/cegis/cegis_jsa_benchmark_04/ListRemove.java deleted file mode 100644 index 6bb338b78c6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_04/ListRemove.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mercury.interview; - -import java.util.*; - -public class ListRemove { - public static void main(String[] args) { - List list = new ArrayList(); - list.add(1); - list.add(1); - list.add(3); - list.add(6); - list.add(2); - list.add(1); - myRemove(list, 1); - for(int i = 0; i < list.size(); i++) { - System.out.println(list.get(i)); - } - } - public static void myRemove(List list, int x) { - Iterator it = list.iterator(); - while(it.hasNext()) { - int temp = it.next(); - if (x == temp) { - it.remove(); - } - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_04/main.c b/regression/cegis/cegis_jsa_benchmark_04/main.c deleted file mode 100644 index aa1839ac17b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_04/main.c +++ /dev/null @@ -1,36 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t x; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t temp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (x == temp) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_04/source.url b/regression/cegis/cegis_jsa_benchmark_04/source.url deleted file mode 100644 index e49f3214119..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_04/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/eeveeeevee/interview/0a32bb5ce17c565b9de25b81acd77f6dee31d53a/MyJava/JavaBasic/src/com/mercury/interview/ListRemove.java diff --git a/regression/cegis/cegis_jsa_benchmark_04/test.desc b/regression/cegis/cegis_jsa_benchmark_04/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_04/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_05/Sort.java b/regression/cegis/cegis_jsa_benchmark_05/Sort.java deleted file mode 100644 index 907a91927d0..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_05/Sort.java +++ /dev/null @@ -1,83 +0,0 @@ -package ru.hse.example; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -public class Sort { - - public static void main(String[] args) { - ArrayList list = new ArrayList(); - list.add( 3 ); - list.add(7); - list.add(1); - list.add(4); - list.add(8); - list.add(2); - - System.out.println(sort2(list)); - System.out.println(sort1(list)); - } - - static List sort1(List list) { - List res = new ArrayList(list.size()); - - while (!list.isEmpty()) - res.add(removeMax(list)); - - return res; - } - - static List sort2(List list) { - List res = new LinkedList(); - - for (int v : list) - insertDesc(res, v); - - return res; - } - - static int removeMax(List list) { - Integer max = list.get(0); - - for ( Integer v : list ) - if ( v > max ) - max = v; - - list.remove(max); - - return max; - } - - static int removeMax1(List list) { - Iterator it = list.iterator(); - Integer max = it.next(); - - while ( it.hasNext() ) { - Integer v = it.next(); - - if ( v > max ) - max = v; - } - - list.remove(max); - - return max; - } - - static void insertDesc(List list, int value) { - ListIterator it = list.listIterator(); - - while (it.hasNext() && it.next() > value ); - - if (it.hasPrevious()) - if (it.previous() > value) - it.next(); - - it.add(value); - } - - -} diff --git a/regression/cegis/cegis_jsa_benchmark_05/main.c b/regression/cegis/cegis_jsa_benchmark_05/main.c deleted file mode 100644 index 80f273e8f35..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_05/main.c +++ /dev/null @@ -1,29 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_data_t max=0; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t v=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (v > max) - { - max = v; - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_05/source.url b/regression/cegis/cegis_jsa_benchmark_05/source.url deleted file mode 100644 index 65d766e1bf7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_05/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/alno/hse-oop-java/064d76ba5f477b6976a351685263f31ba725b06c/Sort/src/ru/hse/example/Sort.java diff --git a/regression/cegis/cegis_jsa_benchmark_05/test.desc b/regression/cegis/cegis_jsa_benchmark_05/test.desc deleted file mode 100644 index d3350b330e6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_05/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa --jsa-aggregate=max -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_06/main.c b/regression/cegis/cegis_jsa_benchmark_06/main.c deleted file mode 100644 index c1ba5ed456e..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_06/main.c +++ /dev/null @@ -1,33 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 3u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t e=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - // newHt_put(e); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_06/source.url b/regression/cegis/cegis_jsa_benchmark_06/source.url deleted file mode 100644 index b6c4ffb78e6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_06/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/chympara/multivision-examples/d251d19862aa355f13e376ee3aa66ab0efa7775d/CoreJavaExamples/src/main/java/net/multivision/corejava/collections/IterationExample.java diff --git a/regression/cegis/cegis_jsa_benchmark_06/test.desc b/regression/cegis/cegis_jsa_benchmark_06/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_06/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_07/SimpleArrayListTest.java b/regression/cegis/cegis_jsa_benchmark_07/SimpleArrayListTest.java deleted file mode 100644 index de2c393be4a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_07/SimpleArrayListTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.lysongzi.test; - -import java.util.Iterator; - -import org.junit.Test; - -import com.lysongzi.collection.SimpleArrayList; - -public class SimpleArrayListTest { - private SimpleArrayList sal; - - @Test - public void test() { - sal = new SimpleArrayList(); - for(int i=10; i > 0; i--) - sal.append(i); - System.out.println(sal); - - //ɾ��ǰ����Ԫ�� - sal.remove(0); - sal.remove(0); - System.out.println(sal); - - //���õ�����ɾ��ʣ��Ԫ���е�����ż�� - for(Iterator it = sal.iterator(); it.hasNext();){ - Integer num = it.next(); - //ɾ������ż�� - if(num%2 == 0) - it.remove(); - } - System.out.println(sal); - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_07/main.c b/regression/cegis/cegis_jsa_benchmark_07/main.c deleted file mode 100644 index 2ac5f45cbfc..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_07/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t num=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(num, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_07/source.url b/regression/cegis/cegis_jsa_benchmark_07/source.url deleted file mode 100644 index 3a5b5df3973..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_07/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/lysongzi/java-learn/cd0cdfa7f4b00dd27dd442333e75708cf715c406/src/com/lysongzi/test/SimpleArrayListTest.java diff --git a/regression/cegis/cegis_jsa_benchmark_07/test.desc b/regression/cegis/cegis_jsa_benchmark_07/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_07/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_08/Esai.java b/regression/cegis/cegis_jsa_benchmark_08/Esai.java deleted file mode 100644 index de1ddc42826..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_08/Esai.java +++ /dev/null @@ -1,14 +0,0 @@ -package exo.chap17_Collections; -import java.util.*; -public class Essai -{ public static void main (String args[]) - { LinkedList liste = new LinkedList () ; - liste.add (3) ; liste.add (5) ;liste.add (3) ;liste.add (12) ;liste.add (3) ; - System.out.println (liste) ; - liste.remove (3) ; System.out.println (liste) ; - liste.remove (new Integer(3)) ; System.out.println (liste) ; - Iterator it = liste.iterator () ; - while (it.hasNext())if (it.next()==3) it.remove() ; - System.out.println (liste) ; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_08/main.c b/regression/cegis/cegis_jsa_benchmark_08/main.c deleted file mode 100644 index 7948a1fed44..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_08/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp == 3) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_08/source.url b/regression/cegis/cegis_jsa_benchmark_08/source.url deleted file mode 100644 index 867f37cb925..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_08/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/gifflearn/Eyrolles/807f7590cce3bf525127ed1d6772b47b618c385c/src/exo/chap17_Collections/Esai.java diff --git a/regression/cegis/cegis_jsa_benchmark_08/test.desc b/regression/cegis/cegis_jsa_benchmark_08/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_08/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_09/RemoveDuringIteration.java b/regression/cegis/cegis_jsa_benchmark_09/RemoveDuringIteration.java deleted file mode 100644 index 98a6eea35e7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_09/RemoveDuringIteration.java +++ /dev/null @@ -1,52 +0,0 @@ -package trickyexamples; - -import java.util.ConcurrentModificationException; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public class RemoveDuringIteration { - public static void main(String[] args) { - final Set set = new HashSet(); - for (int i = 0; i < 10; i++) { - set.add(i); - } - - for (int i = 0; i < 2; i++) { - Thread t1 = new Thread() { - @Override - public void run() { - iterateAndRemove(set); - super.run(); - } - }; - t1.start(); - } - - } - - /** - * Sometimes this method throws during iteration a {@link ConcurrentModificationException} because - * of the remove. - * - * @param set - */ - private static void iterateAndRemove(Set set) { - System.out.println("Before remove"); - for (Integer i : set) { - System.out.println(i); - } - Iterator it = set.iterator(); - while (it.hasNext()) { - Integer i = it.next(); - if (i % 2 == 0) { - // set.remove(i); - it.remove(); - } - } - System.out.println("\nAfter remove"); - for (Integer i : set) { - System.out.println(i); - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_09/main.c b/regression/cegis/cegis_jsa_benchmark_09/main.c deleted file mode 100644 index 701daed1f36..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_09/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_09/source.url b/regression/cegis/cegis_jsa_benchmark_09/source.url deleted file mode 100644 index d9a6c31bed2..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_09/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/antalpeti/Test/d92a3e943eb310de1ecb87a753b700dc9128358d/src/trickyexamples/RemoveDuringIteration.java diff --git a/regression/cegis/cegis_jsa_benchmark_09/test.desc b/regression/cegis/cegis_jsa_benchmark_09/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_09/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_10/Solution.java b/regression/cegis/cegis_jsa_benchmark_10/Solution.java deleted file mode 100644 index 17a75d0d99a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_10/Solution.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.javarush.test.level08.lesson08.task02; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/* Удалить все числа больше 10 -Создать множество чисел(Set), занести туда 20 различных чисел. -Удалить из множества все числа больше 10. -*/ - -public class Solution -{ - public static HashSet createSet() - { - HashSet set = new HashSet(); - for (int i = 0; i < 20; i++) - { - set.add(i); - } - return set; - } - - public static HashSet removeAllNumbersMoreThan10(HashSet set) - { - Iterator it = set.iterator(); - while(it.hasNext()){ - if(it.next()>10) - it.remove(); - } - return set; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_10/main.c b/regression/cegis/cegis_jsa_benchmark_10/main.c deleted file mode 100644 index 7fcd43f2387..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_10/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp > 10) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_10/source.url b/regression/cegis/cegis_jsa_benchmark_10/source.url deleted file mode 100644 index bee01933a2e..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_10/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/kapitanN/captain/13889e8aa56121e5315c200ec840ea20e8126f30/src/com/javarush/test/level08/lesson08/task02/Solution.java diff --git a/regression/cegis/cegis_jsa_benchmark_10/test.desc b/regression/cegis/cegis_jsa_benchmark_10/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_10/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_11/Solution.java b/regression/cegis/cegis_jsa_benchmark_11/Solution.java deleted file mode 100644 index 52832fbed31..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_11/Solution.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.javarush.test.level08.lesson08.task02; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -/* Удалить все числа больше 10 -Создать множество чисел(Set), занести туда 20 различных чисел. -Удалить из множества все числа больше 10. -*/ - -public class Solution -{ - public static HashSet createSet() - { - HashSet set = new HashSet(); - for (int i = 0; i < 20; i++) - set.add((int) (i * 2.3456)); - return set; - } - - public static HashSet removeAllNumbersMoreThan10(HashSet set) - { - Iterator it = set.iterator(); - while (it.hasNext()) - { - Integer temp = it.next(); - if (temp > 10) - it.remove(); - } - - return set; - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_11/main.c b/regression/cegis/cegis_jsa_benchmark_11/main.c deleted file mode 100644 index 8af904aac66..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_11/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t temp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (temp > 10) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_11/source.url b/regression/cegis/cegis_jsa_benchmark_11/source.url deleted file mode 100644 index 53c2659e8bd..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_11/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/Gpef/JavaRushHomeWork/5e0b210e129ef9b008a4eaaf7af8887fccbbe2f6/src/com/javarush/test/level08/lesson08/task02/Solution.java diff --git a/regression/cegis/cegis_jsa_benchmark_11/test.desc b/regression/cegis/cegis_jsa_benchmark_11/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_11/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_12/ExerciseTwo.java b/regression/cegis/cegis_jsa_benchmark_12/ExerciseTwo.java deleted file mode 100644 index f2919c1fe14..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_12/ExerciseTwo.java +++ /dev/null @@ -1,36 +0,0 @@ -import java.util.*; -import java.lang.*; - -public class ExerciseTwo { - public static void main(String[] args) { - Integer[] numbers = {7, 2, 5, 9, 4, 10, 21, 31, 6, 19, 2, 32, 21}; - LinkedList list = new LinkedList(Arrays.asList(numbers)); - - for (int i=0; i(Arrays.asList(numbers)); - for (Integer i : list) { - if (list.get(i) % 2 == 0) - list.remove(i); - System.out.println(list); - } - **/ - - list = new LinkedList(Arrays.asList(numbers)); - ListIterator iterator = list.listIterator(); - while (iterator.hasNext()) { - Integer i = iterator.next(); - if (i % 2 == 0) - iterator.remove(); - System.out.println(list); - } - - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_12/main.c b/regression/cegis/cegis_jsa_benchmark_12/main.c deleted file mode 100644 index 173763afb1d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_12/main.c +++ /dev/null @@ -1,36 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - // System_out_println(list); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_12/source.url b/regression/cegis/cegis_jsa_benchmark_12/source.url deleted file mode 100644 index 81b8bec2cb2..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_12/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/steventardojr/schoolProjects/a4c1c5ed25858dfdb7ce6923631a395575ecc913/labs2121/lab7/ExerciseTwo.java diff --git a/regression/cegis/cegis_jsa_benchmark_12/test.desc b/regression/cegis/cegis_jsa_benchmark_12/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_12/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_13/CutSticks.java b/regression/cegis/cegis_jsa_benchmark_13/CutSticks.java deleted file mode 100644 index 0cdba44a542..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_13/CutSticks.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.sanjay.hackerrank; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class CutSticks { - /* Cut Sticks - * Given an array of integers, Subtract the minimum from the entire array elements till its zero. - * At each step return the size of non-zero elements that are being subtracted. Once an element=0 - * ignore it. - * */ - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Integer size = in.nextInt(); - List list = new ArrayList(); - List counts = null; - - while (size > 0) { - String res = in.next(); - list.add(Integer.parseInt(res)); - size--; - - } - in.close(); - - counts = getCount(list); - - for (Integer integer : counts) { - System.out.println(integer); - } - } - - private static List getCount(List list) { - List size = new ArrayList(); - List nonZero = null; - - while (list.size() > 0) { - List newList = new ArrayList(); - nonZero = removeZero(list); - Integer min = getMin(nonZero); - size.add(nonZero.size()); - - for (Integer integer : nonZero) { - if ((integer - min) > 0) - newList.add(integer - min); - } - list = newList; - } - return size; - } - - private static Integer getMin(List list) { - Integer min = list.get(0); - - for (int i = 1; i < list.size(); i++) { - if (list.get(i) < min) - min = list.get(i); - } - return min; - } - - private static List removeZero(List list) { - List nonZero = new ArrayList(); - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) > 0) - nonZero.add(list.get(i)); - } - return nonZero; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_13/main.c b/regression/cegis/cegis_jsa_benchmark_13/main.c deleted file mode 100644 index 7e84c3fb789..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_13/main.c +++ /dev/null @@ -1,38 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - const _Bool not_empty=__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_assume(not_empty); - __CPROVER_jsa_data_t min=__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp < min) - { - min = tmp; - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_13/source.url b/regression/cegis/cegis_jsa_benchmark_13/source.url deleted file mode 100644 index 8758f2a1fde..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_13/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/91sanjay/java-projects/11a291035ee32a4c43149b79a8c25b44ea1e1904/Hacker-Rank/CutSticks.java diff --git a/regression/cegis/cegis_jsa_benchmark_13/test.desc b/regression/cegis/cegis_jsa_benchmark_13/test.desc deleted file mode 100644 index 88f037ea975..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_13/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa --jsa-aggregate=min -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_14/A_1.java b/regression/cegis/cegis_jsa_benchmark_14/A_1.java deleted file mode 100644 index 6fc24a63603..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_14/A_1.java +++ /dev/null @@ -1,29 +0,0 @@ -package by.it.veselov.JD01_12; -import java.util.ArrayList; -import java.util.Iterator; -/** - * Created by yegorveselov on 10.03.16. - */ -public class A_1 { - - - public static void main(String[] args) - { - - int element = 5; - int negative = 3; - ArrayList mark = new ArrayList(); - for (int i = 0; i < element; i++) - { - int a = (int)(Math.random() * 10 + 1); - Integer b = new Integer(a); - mark.add(i, b); - } - System.out.println(mark); - for(Iterator it = mark.iterator(); it.hasNext();) - if(it.next()<= negative) - it.remove(); - System.out.println(mark); - } -} - diff --git a/regression/cegis/cegis_jsa_benchmark_14/main.c b/regression/cegis/cegis_jsa_benchmark_14/main.c deleted file mode 100644 index 601d16e18d7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_14/main.c +++ /dev/null @@ -1,36 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t negative=3; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp <= negative) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_14/source.url b/regression/cegis/cegis_jsa_benchmark_14/source.url deleted file mode 100644 index 7d5383075f4..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_14/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/Khmelov/JD2016/2c5cd667315848eeb2406a715caf983eefca10c5/src/by/it/veselov/JD01_12/A_1.java diff --git a/regression/cegis/cegis_jsa_benchmark_14/test.desc b/regression/cegis/cegis_jsa_benchmark_14/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_14/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_15/ExerciseThree.java b/regression/cegis/cegis_jsa_benchmark_15/ExerciseThree.java deleted file mode 100644 index 09bb067fae9..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_15/ExerciseThree.java +++ /dev/null @@ -1,45 +0,0 @@ -import java.util.*; -import java.lang.*; - -public class ExerciseThree { - public static void main(String[] args) { - Integer[] numbers = {7, 2, 5, 9, 4, 10, 21, 31, 6, 19, 2, 32, 21}; - LinkedList list = new LinkedList(Arrays.asList(numbers)); - - for (int i=0; i(Arrays.asList(numbers)); - for (Integer i : list) { - if (list.get(i) % 2 == 0) - list.remove(i); - System.out.println(list); - } - **/ - - list = new LinkedList(Arrays.asList(numbers)); - ListIterator iterator = list.listIterator(); - while (iterator.hasNext()) { - Integer i = iterator.next(); - if (i % 2 == 0) - iterator.remove(); - System.out.println(list); - } - - System.out.println(); - - PriorityQueue queue = new PriorityQueue(Arrays.asList(numbers)); - Iterator it = queue.iterator(); - while (it.hasNext()) { - System.out.println(queue.poll()); - System.out.println(queue); - } - - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_15/main.c b/regression/cegis/cegis_jsa_benchmark_15/main.c deleted file mode 100644 index a2cee326e76..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_15/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_15/source.url b/regression/cegis/cegis_jsa_benchmark_15/source.url deleted file mode 100644 index d8c9ca39418..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_15/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/steventardojr/schoolProjects/a4c1c5ed25858dfdb7ce6923631a395575ecc913/labs2121/lab7/ExerciseThree.java diff --git a/regression/cegis/cegis_jsa_benchmark_15/test.desc b/regression/cegis/cegis_jsa_benchmark_15/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_15/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_16/Solution.java b/regression/cegis/cegis_jsa_benchmark_16/Solution.java deleted file mode 100644 index 7d967f03d86..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_16/Solution.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.javarush.test.level08.lesson08.task02; - -import java.util.HashSet; -import java.util.Iterator; - -/* Удалить все числа больше 10 -Создать множество чисел(Set), занести туда 20 различных чисел. -Удалить из множества все числа больше 10. -*/ - -public class Solution -{ - - - - public static HashSet createSet() - { - HashSet hs = new HashSet(); - - for (int i=0;i<20;i++){ - hs.add(i+i); - } - - return hs; - } - - public static HashSet removeAllNumbersMoreThen10(HashSet set) - { - - Iterator it = set.iterator(); - - while (it.hasNext()){ - if (it.next()>10) it.remove(); - } - - return set; - - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_16/main.c b/regression/cegis/cegis_jsa_benchmark_16/main.c deleted file mode 100644 index 7fcd43f2387..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_16/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp > 10) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_16/source.url b/regression/cegis/cegis_jsa_benchmark_16/source.url deleted file mode 100644 index c21cdf84214..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_16/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/bskydive/JavaSECorePractice/042bd509fe493db3ba160e4ab1721e7b8670b3cc/level08/lesson08/task02/Solution.java diff --git a/regression/cegis/cegis_jsa_benchmark_16/test.desc b/regression/cegis/cegis_jsa_benchmark_16/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_16/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_17/CollectionFilter.java b/regression/cegis/cegis_jsa_benchmark_17/CollectionFilter.java deleted file mode 100644 index f1024a22ff0..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_17/CollectionFilter.java +++ /dev/null @@ -1,31 +0,0 @@ -package bynull.collections; - -import java.util.*; - -/** - * Created by null on 5/4/14. - */ -public class CollectionFilter { - - public static void main(String[] args) { - List list = new ArrayList(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); - - int counter = 0; - for (Integer currChiper : list) { - counter++; - if (counter == 5) { - filterCollection(list); - } - } - - System.out.println(list); - } - - private static void filterCollection(List list) { - for (ListIterator it = list.listIterator(); it.hasNext(); ) { - if (it.next() > 6) { - it.remove(); - } - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_17/main.c b/regression/cegis/cegis_jsa_benchmark_17/main.c deleted file mode 100644 index 1bb0754265f..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_17/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp > 6) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_17/source.url b/regression/cegis/cegis_jsa_benchmark_17/source.url deleted file mode 100644 index a3a746e6242..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_17/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/xnull/JavaExamples/77861227999047b63326de76c4a38c7f5c79c3ed/investigation-code/src/main/java/bynull/collections/CollectionFilter.java diff --git a/regression/cegis/cegis_jsa_benchmark_17/test.desc b/regression/cegis/cegis_jsa_benchmark_17/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_17/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_18/CutSticks.java b/regression/cegis/cegis_jsa_benchmark_18/CutSticks.java deleted file mode 100644 index 0cdba44a542..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18/CutSticks.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.sanjay.hackerrank; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class CutSticks { - /* Cut Sticks - * Given an array of integers, Subtract the minimum from the entire array elements till its zero. - * At each step return the size of non-zero elements that are being subtracted. Once an element=0 - * ignore it. - * */ - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Integer size = in.nextInt(); - List list = new ArrayList(); - List counts = null; - - while (size > 0) { - String res = in.next(); - list.add(Integer.parseInt(res)); - size--; - - } - in.close(); - - counts = getCount(list); - - for (Integer integer : counts) { - System.out.println(integer); - } - } - - private static List getCount(List list) { - List size = new ArrayList(); - List nonZero = null; - - while (list.size() > 0) { - List newList = new ArrayList(); - nonZero = removeZero(list); - Integer min = getMin(nonZero); - size.add(nonZero.size()); - - for (Integer integer : nonZero) { - if ((integer - min) > 0) - newList.add(integer - min); - } - list = newList; - } - return size; - } - - private static Integer getMin(List list) { - Integer min = list.get(0); - - for (int i = 1; i < list.size(); i++) { - if (list.get(i) < min) - min = list.get(i); - } - return min; - } - - private static List removeZero(List list) { - List nonZero = new ArrayList(); - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) > 0) - nonZero.add(list.get(i)); - } - return nonZero; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_18/main.c b/regression/cegis/cegis_jsa_benchmark_18/main.c deleted file mode 100644 index 1f889d098f1..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18/main.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_newList=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_newList); - const __CPROVER_jsa_data_t min; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t integer=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (integer > min) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_newList, integer); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_18/source.url b/regression/cegis/cegis_jsa_benchmark_18/source.url deleted file mode 100644 index 8758f2a1fde..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/91sanjay/java-projects/11a291035ee32a4c43149b79a8c25b44ea1e1904/Hacker-Rank/CutSticks.java diff --git a/regression/cegis/cegis_jsa_benchmark_18/test.desc b/regression/cegis/cegis_jsa_benchmark_18/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_18_02/CutSticks.java b/regression/cegis/cegis_jsa_benchmark_18_02/CutSticks.java deleted file mode 100644 index 0cdba44a542..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18_02/CutSticks.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.sanjay.hackerrank; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class CutSticks { - /* Cut Sticks - * Given an array of integers, Subtract the minimum from the entire array elements till its zero. - * At each step return the size of non-zero elements that are being subtracted. Once an element=0 - * ignore it. - * */ - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Integer size = in.nextInt(); - List list = new ArrayList(); - List counts = null; - - while (size > 0) { - String res = in.next(); - list.add(Integer.parseInt(res)); - size--; - - } - in.close(); - - counts = getCount(list); - - for (Integer integer : counts) { - System.out.println(integer); - } - } - - private static List getCount(List list) { - List size = new ArrayList(); - List nonZero = null; - - while (list.size() > 0) { - List newList = new ArrayList(); - nonZero = removeZero(list); - Integer min = getMin(nonZero); - size.add(nonZero.size()); - - for (Integer integer : nonZero) { - if ((integer - min) > 0) - newList.add(integer - min); - } - list = newList; - } - return size; - } - - private static Integer getMin(List list) { - Integer min = list.get(0); - - for (int i = 1; i < list.size(); i++) { - if (list.get(i) < min) - min = list.get(i); - } - return min; - } - - private static List removeZero(List list) { - List nonZero = new ArrayList(); - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) > 0) - nonZero.add(list.get(i)); - } - return nonZero; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_18_02/main.c b/regression/cegis/cegis_jsa_benchmark_18_02/main.c deleted file mode 100644 index eccc4402408..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18_02/main.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_newList=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_newList); - const __CPROVER_jsa_data_t min; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t integer=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (integer > min) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_newList, __CPROVER_jsa_minus(integer, min)); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_18_02/source.url b/regression/cegis/cegis_jsa_benchmark_18_02/source.url deleted file mode 100644 index 8758f2a1fde..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18_02/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/91sanjay/java-projects/11a291035ee32a4c43149b79a8c25b44ea1e1904/Hacker-Rank/CutSticks.java diff --git a/regression/cegis/cegis_jsa_benchmark_18_02/test.desc b/regression/cegis/cegis_jsa_benchmark_18_02/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_18_02/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_19/Question3_5.java b/regression/cegis/cegis_jsa_benchmark_19/Question3_5.java deleted file mode 100644 index 0c4302e699a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_19/Question3_5.java +++ /dev/null @@ -1,42 +0,0 @@ -import java.util.*; - -public class Question3_5{ - public static void main(String[] args){ - MyQueue mq = new MyQueue(); - mq.add(1); - mq.add(2); - mq.add(3); - mq.add(4); - mq.remove(); - mq.add(5); - System.out.print(mq.remove() + " "); - mq.add(6); - } -} -class MyQueue{ - Deque addStack = new LinkedList(); - Deque removeStack = new LinkedList(); - - public void add(Integer i){//not thread safe - move(removeStack, addStack); - addStack.push(i); - } - - public Integer remove(){//not thread safe - if (removeStack.size() == 0 && addStack.size() == 0){ - throw new NoSuchElementException(); - } - move(addStack, removeStack); - return removeStack.pop(); - } - - private void move(Deque from, Deque to){ - if (from.size() == 0) return; - if (to.size() > 0) throw new IllegalStateException(); - Iterator it = from.iterator(); - while(it.hasNext()){ - to.push(it.next()); - it.remove(); - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_19/main.c b/regression/cegis/cegis_jsa_benchmark_19/main.c deleted file mode 100644 index b99264633d8..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_19/main.c +++ /dev/null @@ -1,33 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 3u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - // to_push(tmp); - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_19/source.url b/regression/cegis/cegis_jsa_benchmark_19/source.url deleted file mode 100644 index 8789fc7fdb6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_19/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/mnorbi/algo-practice/0e22d78305e592e7ed46e2f1ff0fb1cb5cbfb3c2/cracking-coding-interview/Question3_5.java diff --git a/regression/cegis/cegis_jsa_benchmark_19/test.desc b/regression/cegis/cegis_jsa_benchmark_19/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_19/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_20/CutSticks.java b/regression/cegis/cegis_jsa_benchmark_20/CutSticks.java deleted file mode 100644 index 0cdba44a542..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_20/CutSticks.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.sanjay.hackerrank; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class CutSticks { - /* Cut Sticks - * Given an array of integers, Subtract the minimum from the entire array elements till its zero. - * At each step return the size of non-zero elements that are being subtracted. Once an element=0 - * ignore it. - * */ - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Integer size = in.nextInt(); - List list = new ArrayList(); - List counts = null; - - while (size > 0) { - String res = in.next(); - list.add(Integer.parseInt(res)); - size--; - - } - in.close(); - - counts = getCount(list); - - for (Integer integer : counts) { - System.out.println(integer); - } - } - - private static List getCount(List list) { - List size = new ArrayList(); - List nonZero = null; - - while (list.size() > 0) { - List newList = new ArrayList(); - nonZero = removeZero(list); - Integer min = getMin(nonZero); - size.add(nonZero.size()); - - for (Integer integer : nonZero) { - if ((integer - min) > 0) - newList.add(integer - min); - } - list = newList; - } - return size; - } - - private static Integer getMin(List list) { - Integer min = list.get(0); - - for (int i = 1; i < list.size(); i++) { - if (list.get(i) < min) - min = list.get(i); - } - return min; - } - - private static List removeZero(List list) { - List nonZero = new ArrayList(); - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) > 0) - nonZero.add(list.get(i)); - } - return nonZero; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_20/main.c b/regression/cegis/cegis_jsa_benchmark_20/main.c deleted file mode 100644 index 8e8aea4d9ff..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_20/main.c +++ /dev/null @@ -1,37 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_nonZero=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_nonZero); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp > 0) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_nonZero, tmp); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_20/source.url b/regression/cegis/cegis_jsa_benchmark_20/source.url deleted file mode 100644 index 8758f2a1fde..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_20/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.github.com/91sanjay/java-projects/11a291035ee32a4c43149b79a8c25b44ea1e1904/Hacker-Rank/CutSticks.java diff --git a/regression/cegis/cegis_jsa_benchmark_20/test.desc b/regression/cegis/cegis_jsa_benchmark_20/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_20/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_21/CollectionTest.java b/regression/cegis/cegis_jsa_benchmark_21/CollectionTest.java deleted file mode 100644 index a41c2935b00..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_21/CollectionTest.java +++ /dev/null @@ -1,95 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - - -public class CollectionTest { - - public static void Test() - { - Collection collection = new ArrayList() ; - - for(int i = 1 ;i < 10 ;++i) - { - collection.add(i) ; - } - - for(int value:collection) - { - System.out.println(value); - } - } - - public static void Test2() - { - int []iArr = new int[]{ 1,2,3,4} ; - List intList = new ArrayList( Arrays.asList(iArr )) ; - - } - - public static void Test3() - { - Collection collection = new ArrayList(Arrays.asList(1,2,3,4,5)) ; - Integer []moreInts = {6,7,8,9,10} ; - collection.addAll(Arrays.asList(moreInts)) ; - - Collections.addAll(collection, 11,12,13,14,15) ; - Collections.addAll(collection, moreInts) ; - for(int i: collection) - { - System.out.print(i + "\t"); - } - } - - public static void IteratorTest() - { - List intList = new ArrayList() ; - Collections.addAll(intList, 1,2,3,4,5) ; - - -// Iterator iterator = intList.iterator() ; -// iterator.next() ; -// iterator.remove(); -// while(iterator.hasNext()) -// { -// System.out.println(iterator.next()); -// } - - ///////////////////////////////////////////// - - ListIterator listIterator = intList.listIterator() ; - while(listIterator.hasNext()) - { - System.out.println(listIterator.next() + ", " + listIterator.nextIndex() + ", " + listIterator.previousIndex()); - } - System.out.println("----------------------------------"); - - while(listIterator.hasPrevious()) - { - System.out.print(listIterator.previous() + "\t"); - } - - while(listIterator.hasNext()) - { - int value = listIterator.next() ; - listIterator.set(value*10); - } - while(listIterator.hasPrevious()) - { - System.out.print(listIterator.previous() + "\t"); - } - - } - public static void main(String[] args) { - // TODO Auto-generated method stub - - IteratorTest() ; - - - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_21/main.c b/regression/cegis/cegis_jsa_benchmark_21/main.c deleted file mode 100644 index f0dcc1ed008..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_21/main.c +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_set(&heap, __CPROVER_jsa_iterator_it, __CPROVER_jsa_mult(value, 10)); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_21/source.url b/regression/cegis/cegis_jsa_benchmark_21/source.url deleted file mode 100644 index f9fab52f5c4..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_21/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/liupanpansmile/JavaCode/3ffc6fd87717f40b5a53dd74fba3388be0df2075/CollectionTest/src/CollectionTest.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_21/test.desc b/regression/cegis/cegis_jsa_benchmark_21/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_21/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_22/ListIteration.java b/regression/cegis/cegis_jsa_benchmark_22/ListIteration.java deleted file mode 100644 index 280a562cb4c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_22/ListIteration.java +++ /dev/null @@ -1,13 +0,0 @@ -import java.util.*; - -public class ListIteration { - public static void main(String[] args) { - List l = new LinkedList(); - ListIterator it = l.listIterator(); - while(it.hasNext()) { - it.next(); - it.set(5); - } - } -} - \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_22/main.c b/regression/cegis/cegis_jsa_benchmark_22/main.c deleted file mode 100644 index 457d47e09bb..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_22/main.c +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_l; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_l); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_l); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - __CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_set(&heap, __CPROVER_jsa_iterator_it, 5); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_22/source.url b/regression/cegis/cegis_jsa_benchmark_22/source.url deleted file mode 100644 index b5177b30f5a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_22/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/yang-zhang/java-practice/fb6e88f91c29a5c7549e0f19a1faac6ab9e69b41/p291Exercise14/ListIteration.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_22/test.desc b/regression/cegis/cegis_jsa_benchmark_22/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_22/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_23/ListSetIteratorTest.java b/regression/cegis/cegis_jsa_benchmark_23/ListSetIteratorTest.java deleted file mode 100644 index 7da6f9f38d0..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_23/ListSetIteratorTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.netappsid.observable.internal; - -import java.util.ListIterator; - -import org.junit.Test; - -import com.netappsid.collection.ArrayListSet; - -public class ListSetIteratorTest -{ - private ArrayListSet list; - - @Test - public void testSetSameObject() - { - list = ArrayListSet.of(1, 2); - ListIterator listIterator = list.listIterator(); - - while (listIterator.hasNext()) - { - Object next = listIterator.next(); - listIterator.set(next); - } - } - - @Test - public void testSetDifferentObject_NotAlreadyInList() - { - list = ArrayListSet.of(1); - ListIterator listIterator = list.listIterator(); - - while (listIterator.hasNext()) - { - Integer next = (Integer) listIterator.next(); - listIterator.set(next + 1); - } - } - - @Test(expected = IllegalArgumentException.class) - public void testSetDifferentObject_AlreadyInList() - { - list = ArrayListSet.of(1, 2); - ListIterator listIterator = list.listIterator(); - - while (listIterator.hasNext()) - { - listIterator.next(); - listIterator.set(2); - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_23/main.c b/regression/cegis/cegis_jsa_benchmark_23/main.c deleted file mode 100644 index cbba6558699..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_23/main.c +++ /dev/null @@ -1,31 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_l; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_l); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_l); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_word_t next=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_set(&heap, __CPROVER_jsa_iterator_it, __CPROVER_jsa_plus(next, 1)); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_23/source.url b/regression/cegis/cegis_jsa_benchmark_23/source.url deleted file mode 100644 index 4ffc58a9e5c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_23/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/360-Innovations/observable/c1a9d48dc5a4fb3963fc515e48c3a883fbf61c22/test/com/netappsid/observable/internal/ListSetIteratorTest.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_23/test.desc b/regression/cegis/cegis_jsa_benchmark_23/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_23/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_24/TestIterator.java b/regression/cegis/cegis_jsa_benchmark_24/TestIterator.java deleted file mode 100644 index 83dd1a94c65..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_24/TestIterator.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.training.cap7; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.ListIterator; - -public class TestIterator { - - public static void main(String[] args){ - ArrayList l = new ArrayList<>(); - - for(int i = 0; i<100;i++){ - l.add(new Integer(i)); - } - - Collections.shuffle(l); - - for(ListIterator iter = l.listIterator(); iter.hasNext();){ - int x = (int)iter.next(); - - if( x % 2 == 0){ - iter.set(new Integer(0)); - } - } - - System.out.println(l); - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_24/main.c b/regression/cegis/cegis_jsa_benchmark_24/main.c deleted file mode 100644 index 8ada5d91330..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_24/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 3u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_l; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_l); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_l); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_word_t x=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if(__CPROVER_jsa_mod(x, 2) == 0) - { - __CPROVER_jsa_set(&heap, __CPROVER_jsa_iterator_it, 0); - } - } - - return 1; -} diff --git a/regression/cegis/cegis_jsa_benchmark_24/source.url b/regression/cegis/cegis_jsa_benchmark_24/source.url deleted file mode 100644 index eb820fe8541..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_24/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/pavelmalai/Training/39a2d73430425c270a101a7e659758f15700650b/Training/src/com/training/cap7/TestIterator.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_24/test.desc b/regression/cegis/cegis_jsa_benchmark_24/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_24/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_25/TestIterator.java b/regression/cegis/cegis_jsa_benchmark_25/TestIterator.java deleted file mode 100644 index 2301723fc6b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_25/TestIterator.java +++ /dev/null @@ -1,474 +0,0 @@ -package neural; - -import java.util.ArrayList; - -import fileReader.FileReader; - -public class Network { - private ArrayList inputLayer, outputLayer; - private int inputSize, outputSize, hiddenLayersNumber; - private ArrayList hiddenSizes; - private ArrayList> hiddenLayers; - private double learningRate; - String filename; - - public Network(int inputNumber,int outputNumber, double learningRate , int hiddenLayersNumber, String filename) { - // TODO Auto-generated constructor stub - - inputSize = inputNumber; - outputSize = outputNumber; - this.hiddenLayersNumber = hiddenLayersNumber; - this.learningRate = learningRate; - this.filename = filename; - - inputLayer = new ArrayList(); - hiddenLayers = new ArrayList>(); - outputLayer = new ArrayList(); - hiddenSizes = new ArrayList(); - - for(int i = 0; i < inputSize; i++) - { - inputLayer.add(new Neuron((inputNumber + outputNumber)/2));//tamanho da primeira camada escondida - } - - - for(int i = 0; i < hiddenLayersNumber; i++) - { - int neuronsSize; - ArrayList tempLayer = new ArrayList(); - if(i == 0) - neuronsSize = (inputNumber + outputNumber)/2; - else - neuronsSize = (hiddenSizes.listIterator(i-1).next() + outputNumber)/2; - hiddenSizes.add(neuronsSize); - for(int j = 0; j < neuronsSize; j++) - { - tempLayer.add(new Neuron((neuronsSize + outputNumber)/2)); - } - hiddenLayers.add(tempLayer); - } - - for(int i = 0; i < outputSize; i++) - { - outputLayer.add(new Neuron(0)); - } - } - - - private void normalizeValues(ArrayList layer) - { - - for(int j = 0; j < layer.size();j++) - { - double normalize = sigmoide(layer.listIterator(j).next().getValue() + layer.listIterator(j).next().getBias()); - layer.listIterator(j).next().setValue(normalize); - } - - } - - - private void hiddenFrontPropagation() - { - for(int i = 0; i < hiddenLayersNumber -1;i++)//at� � pen�ltima camada - { - - for(int j = 0; j < hiddenSizes.listIterator(i).next();j++) - { - for(int k = 0; k < hiddenSizes.listIterator(i+1).next(); k++) - { - - double netValue = hiddenLayers.listIterator(i).next().listIterator(j).next().getWeights().listIterator(k).next() * hiddenLayers.listIterator(i).next().listIterator(j).next().getValue(); - - hiddenLayers.listIterator(i+1).next().listIterator(k).next().addValue(netValue); - - } - - normalizeValues(hiddenLayers.listIterator(i+1).next()); - } - - } - } - - public void frontPropagation(double inputValues[]) - { - for(int i = 0; i < inputValues.length;i++) - { - inputLayer.listIterator(i).next().setValue(sigmoide(inputValues[i])); - for(int j = 0; j < hiddenSizes.listIterator(0).next();j++) - { - double netValue = inputLayer.listIterator(i).next().getWeights().listIterator(j).next() * inputLayer.listIterator(i).next().getValue(); - hiddenLayers.listIterator(0).next().listIterator(j).next().addValue(netValue);//primeira camada - } - } - - normalizeValues(hiddenLayers.listIterator(0).next()); - - hiddenFrontPropagation(); - - for(int i = 0; i < hiddenSizes.listIterator(hiddenLayersNumber-1).next();i++) - { - for(int j = 0; j < outputSize;j++) - { - double netValue = hiddenLayers.listIterator(hiddenLayersNumber-1).next().listIterator(i).next().getWeights().listIterator(j).next() * inputLayer.listIterator(i).next().getValue(); - netValue += hiddenLayers.listIterator(hiddenLayersNumber-1).next().listIterator(i).next().getBias(); - - - outputLayer.listIterator(j).next().addValue(netValue); - } - } - - normalizeValues(outputLayer); - } - - public void backPropagation(double ExpectedOutputValues[]){ - updateDeltas(ExpectedOutputValues); - updateWeightBias(); - } - - private void updateHiddenDeltas() - { - for(int i = hiddenLayersNumber -2; i > -1; i--) - { - for(int j = 0; j < hiddenSizes.listIterator(i).next();j++) - { - for(int k = 0; k < hiddenSizes.listIterator(i+1).next();k++) - { - hiddenLayers.listIterator(i).next().listIterator(j).next().addErrorFactor(hiddenLayers.listIterator(i+1).next().listIterator(k).next().getDelta() * hiddenLayers.listIterator(i).next().listIterator(k).next().getWeights().listIterator(j).next()); - } - hiddenLayers.listIterator(i).next().listIterator(j).next().setDelta(hiddenLayers.listIterator(i).next().listIterator(j).next().getValue() * (1 - hiddenLayers.listIterator(i).next().listIterator(j).next().getValue()) * hiddenLayers.listIterator(i).next().listIterator(j).next().getErrorFactor()); - } - } - } - - private void updateDeltas(double ExpectedOutputValues[]){ - - for(int i = 0 ; i < outputSize; i++){ - outputLayer.listIterator(i).next().setErrorFactor(ExpectedOutputValues[i] - outputLayer.listIterator(i).next().getValue()); - double newDelta = outputLayer.listIterator(i).next().getValue() * (1.0 - outputLayer.listIterator(i).next().getValue()) * outputLayer.listIterator(i).next().getErrorFactor(); - outputLayer.listIterator(i).next().setDelta(newDelta); - } - - - ////Last hidden Layer - for( int i = 0 ; i < hiddenSizes.listIterator(hiddenLayersNumber -1).next(); i++) - { - for (int j=0 ; j < outputSize;j++) - hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().addErrorFactor(outputLayer.listIterator(j).next().getDelta() * hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getWeights().listIterator(j).next()); - hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().setDelta(hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getValue() * (1 - hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getValue()) * hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getErrorFactor()); - } - - updateHiddenDeltas(); - - } - - - private void updateHiddenWeightBias() - { - //�ltima camada - for(int i = 0; i < hiddenSizes.listIterator(hiddenLayersNumber-1).next(); i++) - { - for(int j = 0; j < outputSize; j++) - { - hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getWeights().set(j, hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().getWeights().listIterator(j).next() + - learningRate * outputLayer.listIterator(j).next().getValue()*outputLayer.listIterator(j).next().getDelta()); - } - - hiddenLayers.listIterator(hiddenLayersNumber -1).next().listIterator(i).next().updateBias(learningRate); - } - - - - for(int i = hiddenLayersNumber-3; i >-1 ; i--) - { - for(int j = 0; j < hiddenSizes.listIterator(i).next();j++) - { - for(int k = 0;k < hiddenSizes.listIterator(i+1).next();k++) - { - hiddenLayers.listIterator(i).next().listIterator(i).next().getWeights().set(j, hiddenLayers.listIterator(i).next().listIterator(i).next().getWeights().listIterator(j).next() - - learningRate * hiddenLayers.listIterator(i+1).next().listIterator(j).next().getValue()*hiddenLayers.listIterator(i+1).next().listIterator(j).next().getDelta()); - - } - hiddenLayers.listIterator(i).next().listIterator(i).next().updateBias(learningRate); - - } - - - - } - - } - - private void updateWeightBias() - { - - for(int i = 0; i < outputSize; i++) - { - outputLayer.listIterator(i).next().updateBias(learningRate); - } - - updateHiddenWeightBias(); - - - for(int i = 0; i < inputSize; i++) - { - for(int j = 0; j < hiddenSizes.listIterator(0).next(); j++) - { - double temp= inputLayer.listIterator(i).next().getWeights().listIterator(j).next() - - learningRate * hiddenLayers.listIterator(0).next().listIterator(j).next().getValue()*hiddenLayers.listIterator(0).next().listIterator(j).next().getDelta(); - - inputLayer.listIterator(i).next().getWeights().set(j, temp); - } - - inputLayer.listIterator(i).next().updateBias(learningRate); - } - - } - - - public double errorsAvg() - { - double avg = 0.0; - - for(int i = 0; i < outputSize;i++ ) - { - avg += outputLayer.listIterator(i).next().getErrorFactor() *outputLayer.listIterator(i).next().getErrorFactor() ; - - } - - return avg; - } - - - public double outputSum() - { - - double sum = 0; - - for(int i = 0; i < outputSize;i++ ) - { - sum += outputLayer.listIterator(i).next().getValue() ; - } - - return sum; - } - - public void resetErrors() - { - for(int i = 0; i < outputSize;i++ ) - { - outputLayer.listIterator(i).next().resetError(); - - } - - for(int i = 0; i < hiddenLayers.size(); i++) - { - for(int j = 0; j < hiddenLayers.listIterator(i).next().size(); j++) - { - - hiddenLayers.listIterator(i).next().listIterator(j).next().resetError(); - } - - } - - } - - private ArrayList capitalsReader(FileReader f) { - ArrayList capitals = new ArrayList(); - ArrayList> def = f.read(); - - - - for(int i = 0; i < def.size(); i++) - { - boolean inArray = false;; - Double coords[] = {def.listIterator(i).next().listIterator(def.listIterator(i).next().size()-2).next() , def.listIterator(i).next().listIterator(def.listIterator(i).next().size()-1).next() }; - for(int j = 0; j < capitals.size();j++) - { - if(capitals.listIterator(j).next()[0].equals(coords[0]) && capitals.listIterator(j).next()[1].equals(coords[1]) ) - { - inArray = true; - break; - } - - } - - if(!inArray) - capitals.add(coords); - } - return capitals; - } - - public void Run(){ - - FileReader f = new FileReader(filename); - - ArrayList capitals = capitalsReader(f); - - ArrayList> def = f.read(); - ArrayList errors = new ArrayList(); - - for (int l = 0 ; l < 20; l++){ - - /* - if ( l == 799) - { - System.out.println("cenas"); - } - */ - - errors.clear(); - for (int i = 0 ; i < def.size() ; i++){ - - - - resetErrors(); - - ArrayList inputs = new ArrayList(); - for(int k = 0; k < def.listIterator(i).next().size() - 2;k++) - inputs.add(def.listIterator(i).next().listIterator(k).next()); - - double normalInputs[] = new double[inputs.size()]; - - for(int index = 0;index < inputs.size();index++) - normalInputs[index] = inputs.listIterator(index).next(); - - - frontPropagation(normalInputs); - - double coords[] = {def.listIterator(i).next().listIterator(def.listIterator(i).next().size()-2).next() , def.listIterator(i).next().listIterator(def.listIterator(i).next().size()-1).next() }; - double expectedOutput[] = new double[33]; - - int j = 0; - - for(; j < capitals.size();j++) - { - if(capitals.listIterator(j).next()[0].equals(coords[0]) && capitals.listIterator(j).next()[1].equals(coords[1]) ) - expectedOutput[j] = 1; - else - expectedOutput[j] = 0; - } - - - - - backPropagation(expectedOutput); - - errors.add(errorsAvg()); - - } - } - - double avgError = 0; - - - for(int i = 0; i < errors.size();i++) - { - avgError += errors.listIterator(i).next(); - } - - avgError *= 1.0/(2*def.size()); - - double outputsum = outputSum(); - System.out.println("error: " + avgError); - System.out.println("output sum: "+ outputsum); - - - //calcular media do erro - // if erro << 0,0001 -> acabar - // recome�ar do inicio - - - } - - - - private double sigmoide(double netValue){ - - return (1.0) / (1.0 + Math.exp( -netValue)); - } - - public double[] ArrayListToArray(ArrayList Doubles) - { - double[] ret = new double[Doubles.size()]; - for (int i=0; i < ret.length; i++) - { - ret[i] = Doubles.get(i).doubleValue(); - } - return ret; - } - - public ArrayList getInputLayer() { - return inputLayer; - } - - public void setInputLayer(ArrayList inputLayer) { - this.inputLayer = inputLayer; - } - - - - public int getHiddenLayersNumber() { - return hiddenLayersNumber; - } - - - public void setHiddenLayersNumber(int hiddenLayersNumber) { - this.hiddenLayersNumber = hiddenLayersNumber; - } - - - public ArrayList getHiddenSizes() { - return hiddenSizes; - } - - - public void setHiddenSizes(ArrayList hiddenSizes) { - this.hiddenSizes = hiddenSizes; - } - - - public ArrayList> getHiddenLayers() { - return hiddenLayers; - } - - - public void setHiddenLayers(ArrayList> hiddenLayers) { - this.hiddenLayers = hiddenLayers; - } - - - public double getLearningRate() { - return learningRate; - } - - - public void setLearningRate(double learningRate) { - this.learningRate = learningRate; - } - - - public ArrayList getOutputLayer() { - return outputLayer; - } - - public void setOutputLayer(ArrayList outputLayer) { - this.outputLayer = outputLayer; - } - - public int getInputSize() { - return inputSize; - } - - public void setInputSize(int inputSize) { - this.inputSize = inputSize; - } - - public int getOutputSize() { - return outputSize; - } - - public void setOutputSize(int outputSize) { - this.outputSize = outputSize; - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_25/main.c b/regression/cegis/cegis_jsa_benchmark_25/main.c deleted file mode 100644 index 85dcc4e815b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_25/main.c +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_Integers=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_Integers); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_ret=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_ret); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_Integers); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_word_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_ret, tmp); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_25/source.url b/regression/cegis/cegis_jsa_benchmark_25/source.url deleted file mode 100644 index 777b6dc8e8b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_25/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/Inframan/IART/2822c59e054932b13ae3611967f4762b96425875/src/neural/Network.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_25/test.desc b/regression/cegis/cegis_jsa_benchmark_25/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_25/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_26/IteratorMain.java b/regression/cegis/cegis_jsa_benchmark_26/IteratorMain.java deleted file mode 100644 index 90f9671901d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_26/IteratorMain.java +++ /dev/null @@ -1,33 +0,0 @@ -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Scanner; - -public class IteratorMain { - - public static void main(String[] args) { - - Scanner in = new Scanner(System.in); - LinkedList list = new LinkedList(); - - for (int i = 0; i < 100000; i++) { - list.add((int) (Math.random() * 99 + 1)); - } - System.out.println("Your list is: "); - System.out.println(list); - System.out.println("Which number you want to remove? "); - Integer num = in.nextInt(); - in.close(); - - Iterator it = list.iterator(); - while (it.hasNext()) { - Integer number = it.next(); - if (number % num == 0) { - it.remove(); - } - } - - System.out.println(); - System.out.println(list); - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_26/main.c b/regression/cegis/cegis_jsa_benchmark_26/main.c deleted file mode 100644 index 1ce7c4ff3a0..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_26/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t zero=0; - const __CPROVER_jsa_data_t num; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t number=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(number, num) == zero) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_26/source.url b/regression/cegis/cegis_jsa_benchmark_26/source.url deleted file mode 100644 index ee978713374..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_26/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/GordanMasic/bitCampMiniMac/378414b1eb4dac312341390761fbc9ee14d950ab/workspace/VjezbeW9D3/src/IteratorMain.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_26/test.desc b/regression/cegis/cegis_jsa_benchmark_26/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_26/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_27/FilterUneven.java b/regression/cegis/cegis_jsa_benchmark_27/FilterUneven.java deleted file mode 100644 index 2a8228b4b78..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_27/FilterUneven.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.schaeckel.snippets.lists.filter; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class FilterUneven implements Filter{ - - @Override - public List filter(List list) { - List values = new ArrayList(); - values.addAll(list); - Iterator it = values.iterator(); - while (it.hasNext()) { - Integer value = it.next(); - if ((value.intValue() % 2) == 1){ - it.remove(); - } - } - return values; - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_27/main.c b/regression/cegis/cegis_jsa_benchmark_27/main.c deleted file mode 100644 index 49fcd58ae18..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_27/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(value, 2u) == 1u) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_27/source.url b/regression/cegis/cegis_jsa_benchmark_27/source.url deleted file mode 100644 index 1d8e92ac61f..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_27/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/sschaeckel/snippets/e40f950ec24807a57f5e24ad45d0c151337a6107/src/com/schaeckel/snippets/lists/filter/FilterUneven.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_27/test.desc b/regression/cegis/cegis_jsa_benchmark_27/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_27/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_28/CheckedListBash.java b/regression/cegis/cegis_jsa_benchmark_28/CheckedListBash.java deleted file mode 100644 index dfaa8773d03..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_28/CheckedListBash.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 4904067 - * @summary Unit test for Collections.checkedList - * @author Josh Bloch - */ - -import java.util.*; - -public class CheckedListBash { - static Random rnd = new Random(); - - public static void main(String[] args) { - int numItr = 100; - int listSize = 100; - - for (int i=0; i(); - for(int i =0; i < n; i++){ - list.add(sc.nextInt()); - } - Collections.sort(list,Collections.reverseOrder()); - } - - int n; - int c; - LinkedList list; - - void solve () { - int count = 0; - while(!list.isEmpty()){ - int cur = list.removeFirst(); - int dif = c - cur; - Iterator it = list.iterator(); - while(it.hasNext()){ - int next = it.next(); - if(next <=dif){ - it.remove(); - break; - } - } - count++; - } - System.out.println(count); - } - - void run () { - final int cn = sc.nextInt(); - sc.nextLine(); - for (int ci = 1; ci <= cn; ci++) { - read(); - System.out.printf("Case #%d: ", ci); - solve(); - } - } - - public static void main (String[] args) { - new DataPacking().run(); - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_29/main.c b/regression/cegis/cegis_jsa_benchmark_29/main.c deleted file mode 100644 index 79403898166..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_29/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t dif; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t next=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (next <= dif) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - break; - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_29/source.url b/regression/cegis/cegis_jsa_benchmark_29/source.url deleted file mode 100644 index 738c55335f9..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_29/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/TigerSun86/Contest/b224c6b82df749b57bbe99531de8a5ea61170a72/src/DataPacking.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_29/test.desc b/regression/cegis/cegis_jsa_benchmark_29/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_29/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_30/TestArrayList.java b/regression/cegis/cegis_jsa_benchmark_30/TestArrayList.java deleted file mode 100644 index 193c2922763..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_30/TestArrayList.java +++ /dev/null @@ -1,34 +0,0 @@ -package test; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class TestArrayList { - - public static void main(String[] args) { - ArrayList strs = new ArrayList(); - for(int i=0; i<10; i++) { - strs.add(i); - } - - for(Integer i : strs) { - if(i % 2 == 0) - strs.remove(i); - } - - for(Integer i : strs) { - System.out.println(i); - } - } - - //�����ķ��� - public void removeEvensVer(List lst) { - Iterator itr = lst.iterator(); - - while( itr.hasNext()) - if(itr.next()%2 == 0) - itr.remove(); - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_30/main.c b/regression/cegis/cegis_jsa_benchmark_30/main.c deleted file mode 100644 index aba714d2462..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_30/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, 2) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_30/source.url b/regression/cegis/cegis_jsa_benchmark_30/source.url deleted file mode 100644 index 40effab2430..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_30/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/yugj/test-case/d8ba3de14015e015d82e9736328311c64e752d0a/src/test/TestArrayList.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_30/test.desc b/regression/cegis/cegis_jsa_benchmark_30/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_30/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_31/ArrayUtils.java b/regression/cegis/cegis_jsa_benchmark_31/ArrayUtils.java deleted file mode 100644 index 88ef847e1a7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_31/ArrayUtils.java +++ /dev/null @@ -1,80 +0,0 @@ -package arrays; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - - - -public class ArrayUtils { - - public Integer[] merge(Integer[] array1, Integer[] array2){ - - List returnedList = new ArrayList(); - List concatList = array1 != null ? new ArrayList(Arrays.asList(array1)) : - (array2 != null ? new ArrayList(Arrays.asList(array2)) : new ArrayList()) ; - if(array2 != null && array2 != null) - concatList.addAll(Arrays.asList(array2)); - - for(Integer element2: concatList){ - - if(returnedList.indexOf(element2) == -1){ - returnedList.add(element2); - } - - } - return (Integer[]) returnedList.toArray(new Integer[returnedList.size()]); - } - - public Integer[] innerJoin(Integer[] array1, Integer[] array2){ - - List returnedList = new ArrayList(); - - for(Integer element1: array1){ - - for(Integer element2: array2){ - if(element2 == element1){ - returnedList.add(element1); - break; - } - } - } - - return (Integer[]) returnedList.toArray(new Integer[returnedList.size()]); - } - - public Integer[] leftJoin(Integer[] array1, Integer[] array2){ - - List returnedList = array1 != null ? new ArrayList(Arrays.asList(array1)) : - (array2 != null ? new ArrayList(Arrays.asList(array2)) : - new ArrayList()); - if(array1 != null){ - for(Integer element2: array2){ - - if(returnedList.indexOf(element2) > -1){ - returnedList.add(element2); - } - } - } - - return (Integer[]) returnedList.toArray(new Integer[returnedList.size()]); - } - - public Integer[] outerJoin(Integer[] array1, Integer[] array2){ - - List returnedList = new ArrayList(); - List concatList = array1 != null ? new ArrayList(Arrays.asList(array1)) : - (array2 != null ? new ArrayList(Arrays.asList(array2)) : new ArrayList()) ; - if(array1 != null && array2 != null) - concatList.addAll(Arrays.asList(array2)); - - for(Integer element1: concatList){ - if(concatList.indexOf(element1) == concatList.lastIndexOf(element1)){ - returnedList.add(element1); - } - } - - return (Integer[]) returnedList.toArray(new Integer[returnedList.size()]); - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_31/main.c b/regression/cegis/cegis_jsa_benchmark_31/main.c deleted file mode 100644 index e5810cebdea..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_31/main.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_input=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_input); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_returnedList=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_returnedList); - const __CPROVER_jsa_data_t element1; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_input); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t element2=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (element2 == element1) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_returnedList, element2); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_31/source.url b/regression/cegis/cegis_jsa_benchmark_31/source.url deleted file mode 100644 index 58205552b78..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_31/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/Vladimir-Moskov/GitJavaProjects/f12fc8219bb5b7ad53c4af753d32594cab20138e/javaJunior/src/arrays/ArrayUtils.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_31/test.desc b/regression/cegis/cegis_jsa_benchmark_31/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_31/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_32/GenPrime.java b/regression/cegis/cegis_jsa_benchmark_32/GenPrime.java deleted file mode 100644 index 940c4deaf8b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_32/GenPrime.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hackerrank.test; - -import java.util.ArrayList; -import java.util.List; - -public class GenPrime { - public static void main(String[] args) { - int pp = 2; - List ps = new ArrayList(); - ps.add(pp); - int limit = 100; - while (pp < limit){ - pp+=1; - for (Integer integer : ps) { - if(pp%integer == 0) - break; - else - ps.add(pp); - } - - } - for (Integer integer : ps) { - System.out.println(integer); - } - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_32/main.c b/regression/cegis/cegis_jsa_benchmark_32/main.c deleted file mode 100644 index d6764784631..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_32/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_ps; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_ps); - const __CPROVER_jsa_data_t pp; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_ps); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t integer=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if(__CPROVER_jsa_mod(pp, integer) == 0) - break; - else - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_ps, pp); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_32/source.url b/regression/cegis/cegis_jsa_benchmark_32/source.url deleted file mode 100644 index d8282f7c550..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_32/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/vvkalkundri/hacker/fb4eb7917a9c311048d5962b816113c347f4067a/HackerRank/src/com/hackerrank/test/GenPrime.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_32/test.desc b/regression/cegis/cegis_jsa_benchmark_32/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_32/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_33/T1E3R.java b/regression/cegis/cegis_jsa_benchmark_33/T1E3R.java deleted file mode 100644 index e053f212e6d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_33/T1E3R.java +++ /dev/null @@ -1,37 +0,0 @@ -package naivePrimeGeneration; - -import java.util.ArrayList; -import java.util.List; - -public class T1E3R { - - public static List source(int max) { - List primes = new ArrayList(); - OUTERLOOP: for (int i = 2; i <= max; i++) { - for (Integer p : primes) - if (i / p != 0) - break OUTERLOOP; - primes.add(i); - } - return primes; - } - - public static List target(int max) { - List primes = new ArrayList(); - OUTERLOOP: for (int i = 2; i <= max; i++) { - for (Integer p : primes) - if (i % p == 0) - continue OUTERLOOP; - primes.add(i); - } - return primes; - } - -} -/* - * Actual differences: None - * - * Expected difference score: 0.0 - * - * Expected recommended edits: 6: None - */ \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_33/main.c b/regression/cegis/cegis_jsa_benchmark_33/main.c deleted file mode 100644 index 8c01ba1f76d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_33/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_ps; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_ps); - const __CPROVER_jsa_data_t i; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_ps); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t p=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - // Transformed "find" to "filter" to accommodate front-end restrictions. - if (__CPROVER_jsa_div(i, p) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_33/source.url b/regression/cegis/cegis_jsa_benchmark_33/source.url deleted file mode 100644 index ce8fbbab541..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_33/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/kurtisz/ASTRecognition/bb379b75c10979645b6822fe9dd012341a0ff409/TestWorkspace/Tests/src/naivePrimeGeneration/T1E3R.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_33/test.desc b/regression/cegis/cegis_jsa_benchmark_33/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_33/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_34/T1E3R.java b/regression/cegis/cegis_jsa_benchmark_34/T1E3R.java deleted file mode 100644 index e053f212e6d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_34/T1E3R.java +++ /dev/null @@ -1,37 +0,0 @@ -package naivePrimeGeneration; - -import java.util.ArrayList; -import java.util.List; - -public class T1E3R { - - public static List source(int max) { - List primes = new ArrayList(); - OUTERLOOP: for (int i = 2; i <= max; i++) { - for (Integer p : primes) - if (i / p != 0) - break OUTERLOOP; - primes.add(i); - } - return primes; - } - - public static List target(int max) { - List primes = new ArrayList(); - OUTERLOOP: for (int i = 2; i <= max; i++) { - for (Integer p : primes) - if (i % p == 0) - continue OUTERLOOP; - primes.add(i); - } - return primes; - } - -} -/* - * Actual differences: None - * - * Expected difference score: 0.0 - * - * Expected recommended edits: 6: None - */ \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_34/main.c b/regression/cegis/cegis_jsa_benchmark_34/main.c deleted file mode 100644 index 3fab84b0172..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_34/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_ps; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_ps); - const __CPROVER_jsa_data_t i; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_ps); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t p=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - // Transformed "find" to "filter" to accommodate front-end restrictions. - if (__CPROVER_jsa_mod(i, p) != 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_34/source.url b/regression/cegis/cegis_jsa_benchmark_34/source.url deleted file mode 100644 index ce8fbbab541..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_34/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/kurtisz/ASTRecognition/bb379b75c10979645b6822fe9dd012341a0ff409/TestWorkspace/Tests/src/naivePrimeGeneration/T1E3R.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_34/test.desc b/regression/cegis/cegis_jsa_benchmark_34/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_34/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_35/Solution.java b/regression/cegis/cegis_jsa_benchmark_35/Solution.java deleted file mode 100644 index 5f8d33f10e9..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_35/Solution.java +++ /dev/null @@ -1,53 +0,0 @@ -public class Solution -{ - int [] A={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - ArrayList listOfIntegers=new ArrayList(); - ArrayList> results=new ArrayList>(); - sumOfDices(A, A.length-1, 3 , 12, listOfIntegers, results ); - for(ArrayList list: results) - { - for(Integer i: list) - { - System.out.print(i); - } - System.out.println(""); - } -} - -static void sumOfDices(int [] A, int index, int rest, int target, ArrayList listOfIntegers, ArrayList> results ) - { - if(index<0 || rest<=0) return ; - for(int i=0; i<=rest; i++) - { - int tempSum=i*A[index]; - if(tempSum>target) - break; - else if(tempSum==target) - { - if(rest==i) - { - ArrayList tempList=new ArrayList(listOfIntegers); - int counter=0; - while(counter!=i) - { - tempList.add(A[index]); - counter++; - } - results.add(tempList); - break; - }else - break; - - }else - { - ArrayList tempList=new ArrayList(listOfIntegers); - int counter=0; - while(counter!=i) - { - tempList.add(A[index]); - counter++; - } - sumOfDices( A, index-1, rest-i, target-tempSum, tempList, results ); - } - } - } \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_35/main.c b/regression/cegis/cegis_jsa_benchmark_35/main.c deleted file mode 100644 index 4b173f48668..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_35/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 3u -#define __CPROVER_JSA_NUM_PRED_OPS 6u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 3u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_tempList; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_tempList); - const __CPROVER_jsa_data_t A_index; - const __CPROVER_jsa_data_t i; - __CPROVER_jsa_data_t counter=0; - // "generate" not yet in query instruction set - while(counter!=i) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_tempList, A_index); - counter++; - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_35/source.url b/regression/cegis/cegis_jsa_benchmark_35/source.url deleted file mode 100644 index ce8fbbab541..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_35/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/kurtisz/ASTRecognition/bb379b75c10979645b6822fe9dd012341a0ff409/TestWorkspace/Tests/src/naivePrimeGeneration/T1E3R.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_35/test.desc b/regression/cegis/cegis_jsa_benchmark_35/test.desc deleted file mode 100644 index 7af97cec36a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_35/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic --cegis-jsa-generate -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_36/Euler68m.java b/regression/cegis/cegis_jsa_benchmark_36/Euler68m.java deleted file mode 100644 index 0cdba44a542..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_36/Euler68m.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.sanjay.hackerrank; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -public class CutSticks { - /* Cut Sticks - * Given an array of integers, Subtract the minimum from the entire array elements till its zero. - * At each step return the size of non-zero elements that are being subtracted. Once an element=0 - * ignore it. - * */ - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Integer size = in.nextInt(); - List list = new ArrayList(); - List counts = null; - - while (size > 0) { - String res = in.next(); - list.add(Integer.parseInt(res)); - size--; - - } - in.close(); - - counts = getCount(list); - - for (Integer integer : counts) { - System.out.println(integer); - } - } - - private static List getCount(List list) { - List size = new ArrayList(); - List nonZero = null; - - while (list.size() > 0) { - List newList = new ArrayList(); - nonZero = removeZero(list); - Integer min = getMin(nonZero); - size.add(nonZero.size()); - - for (Integer integer : nonZero) { - if ((integer - min) > 0) - newList.add(integer - min); - } - list = newList; - } - return size; - } - - private static Integer getMin(List list) { - Integer min = list.get(0); - - for (int i = 1; i < list.size(); i++) { - if (list.get(i) < min) - min = list.get(i); - } - return min; - } - - private static List removeZero(List list) { - List nonZero = new ArrayList(); - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) > 0) - nonZero.add(list.get(i)); - } - return nonZero; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_36/main.c b/regression/cegis/cegis_jsa_benchmark_36/main.c deleted file mode 100644 index a65b2a1900f..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_36/main.c +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_j=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_j); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_a=1; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_a); - const __CPROVER_jsa_data_t n; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_j); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (n == tmp) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_a, tmp); - // break; // Transformed "find" to "filter" to accommodate for front-end restrictions. - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_36/source.url b/regression/cegis/cegis_jsa_benchmark_36/source.url deleted file mode 100644 index d6be6fe6d87..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_36/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/nimz/projecteuler/0324014b1b5d9b3150c8bf1f5e94153a7b0ca459/Euler68m.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_36/test.desc b/regression/cegis/cegis_jsa_benchmark_36/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_36/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_37/CombinationSum.java b/regression/cegis/cegis_jsa_benchmark_37/CombinationSum.java deleted file mode 100644 index 1751f44902c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_37/CombinationSum.java +++ /dev/null @@ -1,80 +0,0 @@ -package questions100; - -import java.util.*; - -public class CombinationSum { - public ArrayList> combinationSum(int[] candidates, - int target) { - // Start typing your Java solution below - // DO NOT write main() function - - Map>> hashMem = new HashMap>>(); - ArrayList> result = new ArrayList>(); - - Arrays.sort(candidates); - Set can = new HashSet(); - - if(candidates == null) - { - return result; - } - - for (int i = 0; i < candidates.length; i++) { - can.add(candidates[i]); - } - - for (int i = 1; i <= target; i++) { - ArrayList> sol = new ArrayList>(); - - for (int j = 0; j < candidates.length; j++) { - int diff = i - candidates[j]; - if (diff < 0) - break; - else if (diff == 0) { - ArrayList aL = new ArrayList(); - aL.add(candidates[j]); - if(!sol.contains(aL)) - sol.add(aL); - break; - } - else - { - if(hashMem.containsKey(diff)) - { - ArrayList> subSol = hashMem.get(diff); - for(ArrayList intList: subSol) - { - if(candidates[j] >= intList.get(intList.size() -1)) - { - ArrayList newList = new ArrayList(); - newList.addAll(intList); - newList.add(candidates[j]); - if(!sol.contains(newList)) - sol.add(newList); - } - } - continue; - } - if(can.contains(diff)) - { - if(candidates[j] <= diff) - { - ArrayList aL = new ArrayList(); - aL.add(candidates[j]); - aL.add(diff); - if(!sol.contains(aL)) - sol.add(aL); - } - } - } - } - if(!sol.isEmpty()) - { - hashMem.put(i, sol); - } - } - if(hashMem.containsKey(target)) - result = hashMem.get(target); - return result; - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_37/main.c b/regression/cegis/cegis_jsa_benchmark_37/main.c deleted file mode 100644 index a7c72f182e1..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_37/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_candidates=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_candidates); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_cand=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_cand); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_candidates); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t integer=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_cand, integer); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_37/source.url b/regression/cegis/cegis_jsa_benchmark_37/source.url deleted file mode 100644 index 37183f95dc7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_37/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/superff/Leetcode_solution_java/2d2fa25456aff65ff55e5fee404b7711f7ce2a3a/solutions_java_code/CombinationSum.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_37/test.desc b/regression/cegis/cegis_jsa_benchmark_37/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_37/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_38/CombinationSum.java b/regression/cegis/cegis_jsa_benchmark_38/CombinationSum.java deleted file mode 100644 index 191afec121b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_38/CombinationSum.java +++ /dev/null @@ -1,53 +0,0 @@ -package leetcode.l1405; - -import java.util.*; - -public class CombinationSum { - public ArrayList> combinationSum(int[] candidates, int target) { - if (target == 0) - return new ArrayList>(); - Arrays.sort(candidates); - - ArrayList> list = new ArrayList>(); - list.add(new ArrayList()); - - return combinationSum(candidates, target, 0, list); - } - - private ArrayList> combinationSum(int[] a, int target, int s, ArrayList> preList) { - ArrayList> list = new ArrayList>(); //list for this step - - for (int i=s; i target) break; - if (a[i] == target) { - for (ArrayList line: preList){ - ArrayList newLine = new ArrayList(); - for (int j: line) { - newLine.add(j); - } - newLine.add(a[i]); - list.add(newLine); - } - } else { - ArrayList> tempList = new ArrayList>(); - - for (ArrayList line: preList) { - ArrayList newLine = new ArrayList(); - for (int j: line) { - newLine.add(j); - } - newLine.add(a[i]); - tempList.add(newLine); - } - - ArrayList> nextList = combinationSum(a, target-a[i], i, tempList); - - if (nextList.size()!=0) { - list.addAll(nextList); - } - } - } - return list; - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_38/main.c b/regression/cegis/cegis_jsa_benchmark_38/main.c deleted file mode 100644 index 3a7d90a2f10..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_38/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_line=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_line); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_newLine=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_newLine); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_line); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t integer=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_newLine, integer); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_38/source.url b/regression/cegis/cegis_jsa_benchmark_38/source.url deleted file mode 100644 index 37183f95dc7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_38/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/superff/Leetcode_solution_java/2d2fa25456aff65ff55e5fee404b7711f7ce2a3a/solutions_java_code/CombinationSum.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_38/test.desc b/regression/cegis/cegis_jsa_benchmark_38/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_38/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_39/Euler2.java b/regression/cegis/cegis_jsa_benchmark_39/Euler2.java deleted file mode 100644 index 7b111a53652..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_39/Euler2.java +++ /dev/null @@ -1,41 +0,0 @@ -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -class Euler2 { - - private static BigInteger sumIfEven(List values) { - BigInteger result = BigInteger.ZERO; - for (Integer n : values) { - if (n % 2 == 0) { - result = result.add(new BigInteger(n.toString())); - } - } - return result; - } - - private static List fibUpTo(int max) { - List nums = new ArrayList(); - - int next = 1; - for (int i = 0, j = 0, prev; true; ++i) { - prev = next; - next = j + next; - j = prev; - - if (next > max) - break; - - nums.add(next); - } - - return nums; - } - - public static void main(String[] args) { - List nums = fibUpTo(4000000); - System.out.println("The answer is " + sumIfEven(nums)); - } - -} - diff --git a/regression/cegis/cegis_jsa_benchmark_39/main.c b/regression/cegis/cegis_jsa_benchmark_39/main.c deleted file mode 100644 index 674a8eb3253..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_39/main.c +++ /dev/null @@ -1,37 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_input=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_input); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_result=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_result); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_input); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t n=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (n % 2 == 0) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_result, n); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_39/source.url b/regression/cegis/cegis_jsa_benchmark_39/source.url deleted file mode 100644 index b8bba0407f3..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_39/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/jonasgulle/projecteuler/2706a2be5834baafb37ea8c186eeec3be3869ed8/java/Euler2.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_39/test.desc b/regression/cegis/cegis_jsa_benchmark_39/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_39/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_40/Sets.java b/regression/cegis/cegis_jsa_benchmark_40/Sets.java deleted file mode 100644 index fbbbf640639..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_40/Sets.java +++ /dev/null @@ -1,75 +0,0 @@ -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -//SRM 159 DIV 2 - 500 points -public class Sets { - - public int[] operate(int[] A, int[] B, String operation) { - List a = new ArrayList(); - for (int i : A) { - a.add(i); - } - List b = new ArrayList(); - for (int i : B) { - b.add(i); - } - List result = null; - switch (operation) { - case "UNION": result = union(a, b); break; - case "INTERSECTION": result = intersection(a, b); break; - case "SYMMETRIC DIFFERENCE": result = difference(a, b); break; - } - if(result != null) { - int[] intArray = new int[result.size()]; - for (int i = 0; i < intArray.length; i++) { - intArray[i] = result.get(i); - } - return intArray; - } - return null; - } - - private List union(List A, List B) { - List result = new ArrayList(); - for (int a : A) { - if (!result.contains(a)) { - result.add(a); - } - } - for (int b : B) { - if (!result.contains(b)) { - result.add(b); - } - } - Collections.sort(result); - return result; - } - - private List intersection(List A, List B) { - List result = new ArrayList(); - for (int a : A) { - if (!result.contains(a) && B.contains(a)) { - result.add(a); - } - } - Collections.sort(result); - return result; - } - - private List difference(List A, List B) { - List result = new ArrayList(); - for (int a : A) { - if (!result.contains(a) && !B.contains(a)) { - result.add(a); - } - } - for (int b : B) { - if (!result.contains(b) && !A.contains(b)) { - result.add(b); - } - } - Collections.sort(result); - return result; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_40/main.c b/regression/cegis/cegis_jsa_benchmark_40/main.c deleted file mode 100644 index ee88a56e92b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_40/main.c +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_A=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_A); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_a=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_a); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_A); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_word_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_a, i); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_40/source.url b/regression/cegis/cegis_jsa_benchmark_40/source.url deleted file mode 100644 index cd91cf7d30c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_40/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/monjury/TopCoder/88678875a7eb18cabea6f4cbe7d5a9a7dbe1431a/sets-java/Sets.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_40/test.desc b/regression/cegis/cegis_jsa_benchmark_40/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_40/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_41/Filter.java b/regression/cegis/cegis_jsa_benchmark_41/Filter.java deleted file mode 100644 index f3cfc74893b..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_41/Filter.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.thoughtworks.collection; - -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - -import java.util.*; - -public class Filter { - - List array; - - public Filter(List array) { - this.array = array; - } - - public List filterEven() { - List result = new ArrayList<>(); - - for(int i=0; i filterMultipleOfThree() { - List result = new ArrayList<>(); - - for(int i=0; i getDifferentElements() { - List result = new ArrayList<>(); - - for(int i=0; i getMapOfArrayList() { - Map map = new HashMap(); - - for(int i=0; i> getDividedArray() { - - List> result = new ArrayList<>(); - - for(int i=0; i sonList = new ArrayList<>(); - sonList.add(array.get(i)); - result.add(sonList); - } - } - - return result; - } - - public List getCommonElements(List firstList, List secondList) { - List result = new ArrayList<>(); - - for(int i=0; i getUncommonElements(List firstList, List secondList) { - - List result = new ArrayList<>(); - - for(int i=0; i getElementsByRelationship(FilterHandler filterHandler, List objectList) { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_41/main.c b/regression/cegis/cegis_jsa_benchmark_41/main.c deleted file mode 100644 index 9602bbbe6b5..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_41/main.c +++ /dev/null @@ -1,37 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_array=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_array); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_result=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_result); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_array); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(tmp, 3) == 0) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_result, tmp); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_41/source.url b/regression/cegis/cegis_jsa_benchmark_41/source.url deleted file mode 100644 index b8bba0407f3..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_41/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/jonasgulle/projecteuler/2706a2be5834baafb37ea8c186eeec3be3869ed8/java/Euler2.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_41/test.desc b/regression/cegis/cegis_jsa_benchmark_41/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_41/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_42/Ex8.java b/regression/cegis/cegis_jsa_benchmark_42/Ex8.java deleted file mode 100644 index d5ef40261e5..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_42/Ex8.java +++ /dev/null @@ -1,48 +0,0 @@ -package Week3; - -import java.util.ArrayList; - -public class Ex8 { - public static void main(String[] args) { - ArrayList> l = new ArrayList>(); - - ArrayList l1 = new ArrayList(); - l1.add(1); - l1.add(2); - - ArrayList l2 = new ArrayList(); - l2.add(1); - l2.add(1); - - l.add(l1); - l.add(l2); - - ArrayList> newList = findNum(l, 2); - - - for(ArrayList print : l) { - for(Integer printInt : print) { - System.out.println(printInt); - } - } - } - - public static ArrayList> findNum(ArrayList> list, int num) { - - for(ArrayList l1 : list) { - - for(Integer l2 : l1) { - if(l2 == 2) { - list.remove(l1); - break; - } - } - } - return list; - } - - public static void remove(ArrayList l) { - - - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_42/main.c b/regression/cegis/cegis_jsa_benchmark_42/main.c deleted file mode 100644 index d92209e5065..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_42/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t i=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (i == 2) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - // Transformed "find" to "filter" to accomodate for front-end limitations - //break; - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_42/source.url b/regression/cegis/cegis_jsa_benchmark_42/source.url deleted file mode 100644 index 3aca96b3d05..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_42/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/RBirkeland/Algorithms/115e180f44da19f615da0660942d68431ba3c5df/Algorythms/src/Week3/Ex8.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_42/test.desc b/regression/cegis/cegis_jsa_benchmark_42/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_42/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_43/Test.java b/regression/cegis/cegis_jsa_benchmark_43/Test.java deleted file mode 100644 index 717e3b17e09..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_43/Test.java +++ /dev/null @@ -1,20 +0,0 @@ -import java.util.ArrayList; -import java.util.Arrays; - - - -public class Test { - public static void main(String[] args) { - ArrayList list1 = new ArrayList(Arrays.asList(1, 2, 3)); - ArrayList list2 = new ArrayList(Arrays.asList(6, 1, 3, 5, 2, 8, 9)); - for (int i = 0; i < list1.size(); i++) { - for (int j = 0; j < list2.size(); j++) { - if (list2.get(j) == list1.get(i)) { - list2.remove(j); - break; - } - } - } - System.out.println(list2); - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_43/main.c b/regression/cegis/cegis_jsa_benchmark_43/main.c deleted file mode 100644 index 77252758ba5..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_43/main.c +++ /dev/null @@ -1,37 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_word_t list1_get_i; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp == list1_get_i) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - // Transformed "find" to "filter" to accomodate for front-end limitations - //break; - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_43/source.url b/regression/cegis/cegis_jsa_benchmark_43/source.url deleted file mode 100644 index a3851115600..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_43/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/swansond/Experiments/e923e311db55ed1f429b44a9ce62103b19231bf1/Testing/src/Test.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_43/test.desc b/regression/cegis/cegis_jsa_benchmark_43/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_43/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_44/Gray Code.java b/regression/cegis/cegis_jsa_benchmark_44/Gray Code.java deleted file mode 100644 index 7a5260c072a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_44/Gray Code.java +++ /dev/null @@ -1,49 +0,0 @@ -public class Solution { - - int k; - int N; - boolean FIND; - - HashSet set = new HashSet(); - ArrayList list = new ArrayList(); - ArrayList bits = new ArrayList(); - - public ArrayList grayCode(int n) { - k = n; - N = 1 << (k + 1) - 1; - list = new ArrayList(); - bits = new ArrayList(); - - for (int i = 0; i < N; i++) - list.add(0); - for (int i = 0; i < k; i++) - bits.add(1 << i); - - FIND = false; - set.clear(); - set.add(0); - list.set(0, 0); - findNext(0); - return list; - } - - public void findNext(int num){ - if (FIND) - return; - if (set.size() == N){ - FIND = true; - return; - } - for (int i = 0; i < k; i++) { - int temp = num ^ bits.get(i); - if (set.contains(temp)) - continue; - set.add(temp); - list.set(set.size() - 1, temp); - findNext(temp); - set.remove(temp); - if (FIND) - break; - } - } -} \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_44/main.c b/regression/cegis/cegis_jsa_benchmark_44/main.c deleted file mode 100644 index cee9f9e41fc..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_44/main.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 3u -#define __CPROVER_JSA_NUM_PRED_OPS 6u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 3u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t N; - // "generate" not yet in query instruction set - for (int i = 0; i < N; i++) - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_list, 0); - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_44/source.url b/regression/cegis/cegis_jsa_benchmark_44/source.url deleted file mode 100644 index 2a322e93808..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_44/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/hjguyue/leetcode/f0d2d749ddc2e831def203ff48c89fbf8f091086/Gray%20Code.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_44/test.desc b/regression/cegis/cegis_jsa_benchmark_44/test.desc deleted file mode 100644 index 7af97cec36a..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_44/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic --cegis-jsa-generate -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_45/Problem3.java b/regression/cegis/cegis_jsa_benchmark_45/Problem3.java deleted file mode 100644 index 58c8ef65c07..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_45/Problem3.java +++ /dev/null @@ -1,69 +0,0 @@ -package euler; -import java.util.ArrayList; - -public class Problem3 { - - public static ArrayList primesUpToN(int n) { - ArrayList list = new ArrayList(); - if (n < 2) { - return list; - } - list.add(2); - boolean foundmatch; - for (int i = 3; i < n; i += 2) { - if ((i-1)%100000==0){ - //System.out.println(i); - //System.out.println(list.size()); - } - foundmatch = false; - for (Integer j : list) { - if (j *j > i){ - break; - } - if ((i-1)%100000==0){ - //System.out.println(j); - } - if (i % j == 0) { - foundmatch = true; - break; - } - } - if (!foundmatch) { - list.add(i); - } - } - return list; - } - - /** - * @param args - */ - public static void main(String[] args) { - ArrayList list = new ArrayList(); - list.add(2); - boolean foundmatch; - long mynum = 600851475143L; - long orignum = mynum; - for (int i = 3; i < Math.sqrt(orignum); i += 2) { - foundmatch = false; - for (Integer j : list) { - if (i % j == 0) { - foundmatch = true; - break; - } - } - if (!foundmatch) { - System.out.println("Found:"+i); - list.add(i); - while (mynum % i == 0) { - if (i == mynum){ - System.out.println(i); - return; - } - mynum/=i; - } - } - } - - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_45/main.c b/regression/cegis/cegis_jsa_benchmark_45/main.c deleted file mode 100644 index 9a0cfcdfce6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_45/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t i; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t j=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (__CPROVER_jsa_mod(i, j) == 0) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - // Transformed "find" to "filter" to accommodate front-end limitations. - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_45/source.url b/regression/cegis/cegis_jsa_benchmark_45/source.url deleted file mode 100644 index 31279b64391..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_45/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/arfin/EulerProblems/733928de19ae9565aac2b78f3648c362e6401051/Euler/src/euler/Problem3.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_45/test.desc b/regression/cegis/cegis_jsa_benchmark_45/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_45/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_46/Distance.java b/regression/cegis/cegis_jsa_benchmark_46/Distance.java deleted file mode 100644 index 38312a83412..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_46/Distance.java +++ /dev/null @@ -1,88 +0,0 @@ -package distancebetweenmins; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -public class Distance { - public static void main(String[] args) throws Exception { - - List list = readUserInput(); - for (Integer i : list) { - System.out.print(i + " "); - } - List minsPositions = findMins(list); - - List result = getDistance(minsPositions); - System.out.println(); - System.out.println("Distance between minimums: "); - - for (Integer element : result) - System.out.print(element + " "); - - } - - private static List readUserInput() throws Exception { - - List list = new ArrayList(); - BufferedReader reader = new BufferedReader(new InputStreamReader( - System.in)); - - String string = reader.readLine(); - String[] strings = string.split(" "); - try { - for (int i = 0; i < strings.length; i++) { - list.add(Integer.parseInt(strings[i])); - } - } catch (Exception e) { - System.out.println(e); - } - return list; - } - - private static List findMins(List list) { - int min = list.get(0); - List minimums = new ArrayList(); - for (int i = 0; i < list.size(); i++) { - if (min > list.get(i)) { - min = list.get(i); - } - } - for (int i = 0; i < list.size(); i++) { - if (list.get(i) == min) - minimums.add(i); - } - - if (minimums.size() < 2) { - int min2 = list.get(0); - for (int i = 0; i < list.size(); i++) { - if (minimums.contains(i)) { - break; - } else { - if (min2 < list.get(i)) { - min2 = list.get(i); - } - } - } - - for (int i = 0; i < list.size(); i++) { - if (list.get(i) == min2) - minimums.add(i); - } - } - return minimums; - } - - private static List getDistance(List list) { - List dist = new ArrayList(); - int difference = 0; - for (int i = 0; i < list.size() - 1; i++) { - for (int j = 1; j < list.size(); j++) { - difference = Math.abs(list.get(i) - list.get(i + 1)); - dist.add(difference); - } - } - return dist; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_46/main.c b/regression/cegis/cegis_jsa_benchmark_46/main.c deleted file mode 100644 index 4e66218807d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_46/main.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 3u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_minimums=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_minimums); - const __CPROVER_jsa_data_t min2; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (tmp == min2) - { - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_minimums, tmp); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_46/source.url b/regression/cegis/cegis_jsa_benchmark_46/source.url deleted file mode 100644 index 31fb56ce8e7..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_46/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/AnnaSpring/GoJava/9d8044227bf572d1719742e87083be07d2cfe66e/1%20Module%20Java%20Basics/1%20Module%20Java%20Basics/src/distancebetweenmins/Distance.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_46/test.desc b/regression/cegis/cegis_jsa_benchmark_46/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_46/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_47/DistributedNumberOfInboundEdges.java b/regression/cegis/cegis_jsa_benchmark_47/DistributedNumberOfInboundEdges.java deleted file mode 100644 index bcd76413e50..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_47/DistributedNumberOfInboundEdges.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * - */ -package up.teach.dm.mapreduce.examples; - -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - -import up.teach.dm.mapreduce.IMapFunction; -import up.teach.dm.mapreduce.IReduceFunction; -import up.teach.dm.mapreduce.KeyValuePair; -import up.teach.dm.mapreduce.MapReduceJob; -import up.teach.dm.mapreduce.Master; -import up.teach.dm.utils.FileUtils; - -/** - * @author Robin Senge [robin.senge@uni-paderborn.de] - */ -public class DistributedNumberOfInboundEdges { - - public static void main(String[] args) throws Exception { - - final IMapFunction map = new IMapFunction() { - - @Override - public List> map(Integer source, Integer target) { - - List> intermediateKeyValuePairs = new LinkedList<>(); - - intermediateKeyValuePairs.add(new KeyValuePair(target, 1)); - - return intermediateKeyValuePairs; - - - } - }; - - IReduceFunction reduce = new IReduceFunction() { - - @Override - public List> reduce(Integer key, List values) { - - List> finalKeyValuePairs = new LinkedList>(); - int count = 0; - for (Integer value : values) { - count += value; - } - finalKeyValuePairs.add(new KeyValuePair(key, count)); - - return finalKeyValuePairs; - - } - }; - - // get data - List> edges = FileUtils.loadIntegerPairs("data/p2p-Gnutella04.txt"); - - // run - MapReduceJob job = new MapReduceJob<>(map, reduce, edges); - - new Master(20, 20, 5).run(job); - - // sort - Collections.sort(job.getResult(), new Comparator>() { - - @Override - public int compare(KeyValuePair o1, - KeyValuePair o2) { - return -Integer.compare(o1.getValue(), o2.getValue()); - } - - }); - - // print output - int i = 1; - for (KeyValuePair keyValuePair : job.getResult()) { - System.out.println(keyValuePair); - if(i++ >= 5) break; - } - - - - - } - -} diff --git a/regression/cegis/cegis_jsa_benchmark_47/main.c b/regression/cegis/cegis_jsa_benchmark_47/main.c deleted file mode 100644 index 45070aa9f9d..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_47/main.c +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - int count=0; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - count+=value; - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_47/source.url b/regression/cegis/cegis_jsa_benchmark_47/source.url deleted file mode 100644 index 2ae30bd0383..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_47/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/senge/mapreduce-4-lectures/38ec8b87299ee08446931e8300983f841b005fb3/data.mining/src/up/teach/dm/mapreduce/examples/DistributedNumberOfInboundEdges.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_47/test.desc b/regression/cegis/cegis_jsa_benchmark_47/test.desc deleted file mode 100644 index c3924d3001c..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_47/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic --cegis-aggregate -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_benchmark_48/Eratosthenes.java b/regression/cegis/cegis_jsa_benchmark_48/Eratosthenes.java deleted file mode 100644 index 9b476cf4c88..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_48/Eratosthenes.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.madtape.eratosthenes; - -import java.util.LinkedList; - -public class Eratosthenes { - - private LinkedList mPrimes; - - public Eratosthenes() { - mPrimes = null; - } - - private boolean isPrime(int x) { - if(x < 2) return false; - for(Integer num : mPrimes) { - if(num * num > x) break; - if((x % num) == 0)return false; - } - return true; - } - - private void makePrimeList(int max) { - mPrimes.add(new Integer(2)); - for(int x = 3; x * x < max; x += 2) { - if(isPrime(x)) mPrimes.add(new Integer(x)); - } - } - - public LinkedList findPrimes(int min, int max) { - mPrimes = new LinkedList(); - LinkedList retList = new LinkedList(); - makePrimeList(max); - - for(int x = min; x <= max; x++) { - if(isPrime(x)) retList.add(new Integer(x)); - } - return retList; - } -} diff --git a/regression/cegis/cegis_jsa_benchmark_48/main.c b/regression/cegis/cegis_jsa_benchmark_48/main.c deleted file mode 100644 index 5ef24480f99..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_48/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 2u -#define __CPROVER_JSA_NUM_PRED_OPS 4u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_mPrimes; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_mPrimes); - const __CPROVER_jsa_word_t x; - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_mPrimes); - for (;__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t num=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if(__CPROVER_jsa_mult(num, num) > x) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - // Transformed "find" to "filter" to accommodate front-end restrictions. - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_benchmark_48/source.url b/regression/cegis/cegis_jsa_benchmark_48/source.url deleted file mode 100644 index bbf5e836dda..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_48/source.url +++ /dev/null @@ -1 +0,0 @@ -https://raw.githubusercontent.com/bigbros/Eratosthenes/90f8553fb16a62e2dc25703fb76d8e57542407ab/src/com/madtape/eratosthenes/Eratosthenes.java \ No newline at end of file diff --git a/regression/cegis/cegis_jsa_benchmark_48/test.desc b/regression/cegis/cegis_jsa_benchmark_48/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_benchmark_48/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_filter_01/main.c b/regression/cegis/cegis_jsa_filter_01/main.c deleted file mode 100644 index 839e1cab62e..00000000000 --- a/regression/cegis/cegis_jsa_filter_01/main.c +++ /dev/null @@ -1,36 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t limit=3; - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (value <= limit) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_filter_01/test.desc b/regression/cegis/cegis_jsa_filter_01/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_filter_01/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_map_01/main.c b/regression/cegis/cegis_jsa_map_01/main.c deleted file mode 100644 index 61d4dfb8d47..00000000000 --- a/regression/cegis/cegis_jsa_map_01/main.c +++ /dev/null @@ -1,35 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 5u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_copy=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_copy); - for (const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it);) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_copy, __CPROVER_jsa_mult(value, 2)); - } - - return 0; -} diff --git a/regression/cegis/cegis_jsa_map_01/test.desc b/regression/cegis/cegis_jsa_map_01/test.desc deleted file mode 100644 index 07d2c6c73d6..00000000000 --- a/regression/cegis/cegis_jsa_map_01/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --jsa -D __CPROVER --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]signed *int[\)][\(]MINUS_ONE *< *x[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *ONE *- *x;$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_unit_01/main.c b/regression/cegis/cegis_jsa_unit_01/main.c deleted file mode 100644 index cdeaffbe9ee..00000000000 --- a/regression/cegis/cegis_jsa_unit_01/main.c +++ /dev/null @@ -1,102 +0,0 @@ - -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 1u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 1u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -__CPROVER_jsa_abstract_heapt nondet_heap(void); - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap= - { - .concrete_nodes={ { .next=255, .previous=255, .list=0, .value=16 } }, - .abstract_nodes=((struct __CPROVER_jsa_abstract_node *)0), - .abstract_ranges=((struct __CPROVER_jsa_abstract_range *)0), - .iterators={ { .node_id=255, .previous_node_id=255, .index=0, .previous_index=0, .list=255 } }, - .iterator_count=0, - .list_head_nodes={ 0 }, - .list_count=1 - }; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_data_t limit=3; - __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - - unsigned char pred_size=1; - __CPROVER_jsa_pred_instructiont __CPROVER_jsa_predicate[] = { { .opcode=0, .result_op=0, .op0=1, .op1=0 } }; - __CPROVER_JSA_PREDICATES[0]=__CPROVER_jsa_predicate; - __CPROVER_JSA_PREDICATE_SIZES[0]=pred_size; - unsigned char lambda_op=0; - unsigned char tmp0=0; - unsigned char tmp1=0; - unsigned char tmp2=0; - __CPROVER_JSA_PRED_OPS[0]=&lambda_op; - __CPROVER_JSA_PRED_OPS[1]=&limit; - __CPROVER_JSA_PRED_RESULT_OPS[0]=&tmp0; - __CPROVER_JSA_PRED_RESULT_OPS[1]=&tmp1; - __CPROVER_JSA_PRED_RESULT_OPS[2]=&tmp2; - unsigned char query_size=2; - __CPROVER_assume(query_size >= 1 && query_size <= __CPROVER_JSA_MAX_QUERY_SIZE); - __CPROVER_jsa_query_instructiont __CPROVER_jsa_query[] = { { .opcode=0, .op0=0, .op1=0 }, { .opcode=0, .op0=0, .op1=__CPROVER_jsa_null } }; - unsigned char invariant_size; - __CPROVER_assume(invariant_size >= 1 && invariant_size <= 1); - __CPROVER_jsa_invariant_instructiont invariant[] = { { .opcode=0 } }; - __CPROVER_jsa_abstract_heapt queried_heap=heap; - __CPROVER_jsa_query_execute(&queried_heap, __CPROVER_jsa_query, query_size); - _Bool base_case=__CPROVER_jsa_invariant_execute(&heap, &queried_heap, invariant, invariant_size); - __CPROVER_assume(base_case); - - const __CPROVER_jsa_abstract_heapt __tmp= - { - .concrete_nodes={ { .next=255, .previous=255, .list=0, .value=16 } }, - .abstract_nodes=((struct __CPROVER_jsa_abstract_node *)0), - .abstract_ranges=((struct __CPROVER_jsa_abstract_range *)0), - .iterators={ { .node_id=0, .previous_node_id=255, .index=0, .previous_index=0, .list=0 } }, - .iterator_count=1, - .list_head_nodes={ 0 }, - .list_count=1 - }; - heap=__tmp; - __CPROVER_jsa_abstract_heapt org_heap = heap; - queried_heap=org_heap; - __CPROVER_jsa_query_execute(&queried_heap, __CPROVER_jsa_query, query_size); - _Bool invariant_assume=__CPROVER_jsa_invariant_execute(&heap, &queried_heap, invariant, invariant_size); - __CPROVER_assume(invariant_assume); - - //while (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - if (__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)) - { - const __CPROVER_jsa_data_t value=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - if (value <= limit) - { - __CPROVER_jsa_remove(&heap, __CPROVER_jsa_iterator_it); - } - - queried_heap=org_heap; - __CPROVER_jsa_synchronise_iterator(&heap, &queried_heap, __CPROVER_jsa_query, query_size); - __CPROVER_jsa_query_execute(&queried_heap, __CPROVER_jsa_query, query_size); - _Bool invariant_step=__CPROVER_jsa_invariant_execute(&heap, &queried_heap, invariant, invariant_size); - __CPROVER_assume(invariant_step); - } - else - { - queried_heap=org_heap; - __CPROVER_jsa_full_query_execute(&queried_heap, __CPROVER_jsa_query, query_size); - _Bool property_entailment=__CPROVER_jsa_invariant_execute(&org_heap, &queried_heap, invariant, invariant_size); - __CPROVER_assume(invariant_assume); - } - - __CPROVER_assert(0 == 1, ""); - return 0; -} diff --git a/regression/cegis/cegis_jsa_unit_01/test.desc b/regression/cegis/cegis_jsa_unit_01/test.desc deleted file mode 100644 index 24cf3237e6b..00000000000 --- a/regression/cegis/cegis_jsa_unit_01/test.desc +++ /dev/null @@ -1,8 +0,0 @@ -CORE -main.c ---gcc --stop-on-fail -D __CPROVER -^VERIFICATION FAILED$ -^EXIT=10$ -^SIGNAL=0$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_unit_02/main.c b/regression/cegis/cegis_jsa_unit_02/main.c deleted file mode 100644 index 853b33d5a07..00000000000 --- a/regression/cegis/cegis_jsa_unit_02/main.c +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 2u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 3u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -#include - -int main(void) -{ - __CPROVER_jsa_abstract_heapt heap; - __CPROVER_jsa_assume_valid_heap(&heap); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_list=0; - __CPROVER_jsa_assume_valid_list(&heap, __CPROVER_jsa_list_list); - const __CPROVER_jsa_list_id_t __CPROVER_jsa_list_nonZero=1; - __CPROVER_jsa_assume_new_list(&heap, __CPROVER_jsa_list_nonZero); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_list); - __CPROVER_jsa_assume(__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)); - - const __CPROVER_jsa_data_t tmp=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_it); - __CPROVER_jsa_add(&heap, __CPROVER_jsa_list_nonZero, tmp); - __CPORVER_assert(!__CPROVER_jsa_hasNext(&heap, __CPROVER_jsa_iterator_it)); - const __CPROVER_jsa_iterator_id_t __CPROVER_jsa_iterator_copy_it=__CPROVER_jsa_iterator(&heap, __CPROVER_jsa_list_nonZero); - const __CPROVER_jsa_data_t tmp2=__CPROVER_jsa_next(&heap, __CPROVER_jsa_iterator_copy_it); - __CPROVER_jsa_assume(tmp == tmp2); - - __CPROVER_assert(0 == 1, ""); - - return 0; -} diff --git a/regression/cegis/cegis_jsa_unit_02/test.desc b/regression/cegis/cegis_jsa_unit_02/test.desc deleted file mode 100644 index 3d34d3d2404..00000000000 --- a/regression/cegis/cegis_jsa_unit_02/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --stop-on-fail -D __CPROVER -^ 0 == 1$ -^VERIFICATION FAILED$ -^EXIT=10$ -^SIGNAL=0$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_jsa_unit_03/main.c b/regression/cegis/cegis_jsa_unit_03/main.c deleted file mode 100644 index b48f56d8376..00000000000 --- a/regression/cegis/cegis_jsa_unit_03/main.c +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef __CPROVER -#define __CPROVER_JSA_MAX_CONCRETE_NODES 2u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_ITERATORS 1u -#define __CPROVER_JSA_MAX_LISTS 2u - -#define JSA_SYNTHESIS_H_ -#define __CPROVER_JSA_DEFINE_TRANSFORMERS -#define __CPROVER_JSA_MAX_QUERY_SIZE 2u -#define __CPROVER_JSA_MAX_PRED_SIZE 1u -#define __CPROVER_JSA_NUM_PRED_OPS 3u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 2u -#endif - -#include "../../../src/ansi-c/library/jsa.h" - -#define NULL 0 - -int main(void) -{ - const __CPROVER_jsa_abstract_heapt heap={ .concrete_nodes={ { .next=255, .previous=255, .list=255, .value=255 }, - { .next=255, .previous=255, .list=255, .value=255 } }, .abstract_nodes=((struct __CPROVER_jsa_abstract_node *)NULL), - .abstract_ranges=((struct __CPROVER_jsa_abstract_range *)NULL), - .iterators={ { .node_id=255, .previous_node_id=255, .index=0, .previous_index=0, - .list=0 } }, - .iterator_count=1, - .list_head_nodes={ 255, 255 }, .list_count=2 }; - __CPROVER_jsa_assume_valid_heap(&heap); - - __CPROVER_assert(0 == 1, ""); - return 0; -} diff --git a/regression/cegis/cegis_jsa_unit_03/test.desc b/regression/cegis/cegis_jsa_unit_03/test.desc deleted file mode 100644 index 24cf3237e6b..00000000000 --- a/regression/cegis/cegis_jsa_unit_03/test.desc +++ /dev/null @@ -1,8 +0,0 @@ -CORE -main.c ---gcc --stop-on-fail -D __CPROVER -^VERIFICATION FAILED$ -^EXIT=10$ -^SIGNAL=0$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_refactor_benchmark_01/ITaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_01/ITaxCalculator.class deleted file mode 100644 index e7887dbce54..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_01/ITaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_01/NullTaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_01/NullTaxCalculator.class deleted file mode 100644 index fb6020f765f..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_01/NullTaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_01/Runner.class b/regression/cegis/cegis_refactor_benchmark_01/Runner.class deleted file mode 100644 index 952b78f90bd..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_01/Runner.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_01/Runner.java b/regression/cegis/cegis_refactor_benchmark_01/Runner.java deleted file mode 100644 index 03488a20cf2..00000000000 --- a/regression/cegis/cegis_refactor_benchmark_01/Runner.java +++ /dev/null @@ -1,31 +0,0 @@ -interface ITaxCalculator { - double addTaxes(double price); -} -class UsaTaxCalculator implements ITaxCalculator { - public double addTaxes(double price) { - return price * 1.25; - } -} -class NullTaxCalculator implements ITaxCalculator { - public double addTaxes(double price) { - return price; - } -} - -public class Runner { -void sale(ITaxCalculator calc, double price) { - if (calc != null) - price = calc.addTaxes(price); -} -void print(ITaxCalculator calc, double price) { - double percentage; - if (calc == null) - percentage=0; - else - percentage=calc.addTaxes(100.0) - 100.0; - - System.out.print("Tax rate: "); - System.out.print(percentage); - System.out.println('%'); -} -} \ No newline at end of file diff --git a/regression/cegis/cegis_refactor_benchmark_01/UsaTaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_01/UsaTaxCalculator.class deleted file mode 100644 index 0611af2a66c..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_01/UsaTaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_01/test.desc b/regression/cegis/cegis_refactor_benchmark_01/test.desc deleted file mode 100644 index dc2ddd4cf9b..00000000000 --- a/regression/cegis/cegis_refactor_benchmark_01/test.desc +++ /dev/null @@ -1,8 +0,0 @@ -CORE -Runner.class ---gcc --cegis-refactor --cegis-refactor-null-object --cegis-statistics --cegis-genetic -^ *op0 *= *op1; -^EXIT=0 -^SIGNAL=0 --- -^warning: ignoring diff --git a/regression/cegis/cegis_refactor_benchmark_02/DoubleWrapper.class b/regression/cegis/cegis_refactor_benchmark_02/DoubleWrapper.class deleted file mode 100644 index f24efccfa0a..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_02/DoubleWrapper.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_02/ITaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_02/ITaxCalculator.class deleted file mode 100644 index e7887dbce54..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_02/ITaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_02/NullTaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_02/NullTaxCalculator.class deleted file mode 100644 index f0edaa9ce4f..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_02/NullTaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_02/Runner.class b/regression/cegis/cegis_refactor_benchmark_02/Runner.class deleted file mode 100644 index 9b71ae435a7..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_02/Runner.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_02/Runner.java b/regression/cegis/cegis_refactor_benchmark_02/Runner.java deleted file mode 100644 index 0812076e15a..00000000000 --- a/regression/cegis/cegis_refactor_benchmark_02/Runner.java +++ /dev/null @@ -1,41 +0,0 @@ -class DoubleWrapper { - public double value; - - @Override - public boolean equals(Object o) { - DoubleWrapper tmpDoubleWrapper = (DoubleWrapper) o; - return value == tmpDoubleWrapper.value; - } -} - -interface ITaxCalculator { - double addTaxes(double price); -} -class UsaTaxCalculator implements ITaxCalculator { - public double addTaxes(double price) { - return price * 1.25; - } -} -class NullTaxCalculator implements ITaxCalculator { - public double addTaxes(double price) { - return price; - } -} - -public class Runner { -void sale(ITaxCalculator calc, DoubleWrapper price) { - if (calc != null) - price.value = calc.addTaxes(price.value); -} -void print(ITaxCalculator calc, DoubleWrapper price) { - DoubleWrapper percentage = new DoubleWrapper(); - if (calc == null) - percentage.value=0; - else - percentage.value=calc.addTaxes(100.0) - 100.0; - - System.out.print("Tax rate: "); - System.out.print(percentage.value); - System.out.println('%'); -} -} \ No newline at end of file diff --git a/regression/cegis/cegis_refactor_benchmark_02/UsaTaxCalculator.class b/regression/cegis/cegis_refactor_benchmark_02/UsaTaxCalculator.class deleted file mode 100644 index d0bbe5e4e7d..00000000000 Binary files a/regression/cegis/cegis_refactor_benchmark_02/UsaTaxCalculator.class and /dev/null differ diff --git a/regression/cegis/cegis_refactor_benchmark_02/test.desc b/regression/cegis/cegis_refactor_benchmark_02/test.desc deleted file mode 100644 index dc2ddd4cf9b..00000000000 --- a/regression/cegis/cegis_refactor_benchmark_02/test.desc +++ /dev/null @@ -1,8 +0,0 @@ -CORE -Runner.class ---gcc --cegis-refactor --cegis-refactor-null-object --cegis-statistics --cegis-genetic -^ *op0 *= *op1; -^EXIT=0 -^SIGNAL=0 --- -^warning: ignoring diff --git a/regression/cegis/cegis_safety_unit_greater_two/main.c b/regression/cegis/cegis_safety_unit_greater_two/main.c deleted file mode 100644 index fc4086a7819..00000000000 --- a/regression/cegis/cegis_safety_unit_greater_two/main.c +++ /dev/null @@ -1,12 +0,0 @@ -int main(void) -{ - int x, y; - if (x > 2) - x = 2; - - y=0; - while (x < 2) - ++x; - __CPROVER_assert(x == 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_safety_unit_greater_two/test.desc b/regression/cegis/cegis_safety_unit_greater_two/test.desc deleted file mode 100644 index ba5ab1f42ec..00000000000 --- a/regression/cegis/cegis_safety_unit_greater_two/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)][\(][\(]unsigned *int[\)]x *<= *[\(]unsigned *int[\)]x *&& *[\(]unsigned *int[\)]x *<= *DANGER_CONSTANT_3u[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *~[\(][\(]unsigned *int[\)]x[\)];$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_safety_unit_true/main.c b/regression/cegis/cegis_safety_unit_true/main.c deleted file mode 100644 index 3c3f0f3eec1..00000000000 --- a/regression/cegis/cegis_safety_unit_true/main.c +++ /dev/null @@ -1,8 +0,0 @@ -int main(void) -{ - int x=0; - while (x < 2) - ++x; - __CPROVER_assert(x >= 0, "A"); - return 0; -} diff --git a/regression/cegis/cegis_safety_unit_true/test.desc b/regression/cegis/cegis_safety_unit_true/test.desc deleted file mode 100644 index 60aab0a2cea..00000000000 --- a/regression/cegis/cegis_safety_unit_true/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)][\(][\(]unsigned *int[\)]x *<= *[\(]unsigned *int[\)]x *&& *[\(]unsigned *int[\)]x *<= *DANGER_CONSTANT_3u[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *~[\(][\(]unsigned *int[\)]x[\)];$ --- -^warning: ignoring diff --git a/regression/cegis/cegis_safety_unit_true2/main.c b/regression/cegis/cegis_safety_unit_true2/main.c deleted file mode 100644 index dd5e618dd4d..00000000000 --- a/regression/cegis/cegis_safety_unit_true2/main.c +++ /dev/null @@ -1,8 +0,0 @@ -int main(void) -{ - int x; - while (x < 2) - ++x; - __CPROVER_assert(x >= 2, "A"); - return 0; -} diff --git a/regression/cegis/cegis_safety_unit_true2/test.desc b/regression/cegis/cegis_safety_unit_true2/test.desc deleted file mode 100644 index ba5ab1f42ec..00000000000 --- a/regression/cegis/cegis_safety_unit_true2/test.desc +++ /dev/null @@ -1,9 +0,0 @@ -CORE -main.c ---gcc --safety --cegis-statistics --cegis-genetic -^EXIT=0$ -^SIGNAL=0$ -^.*__CPROVER_danger_D0_x *= *[\(]unsigned *int[\)][\(][\(]unsigned *int[\)]x *<= *[\(]unsigned *int[\)]x *&& *[\(]unsigned *int[\)]x *<= *DANGER_CONSTANT_3u[\)];$ -^.*__CPROVER_danger_R0_x_0 *= *~[\(][\(]unsigned *int[\)]x[\)];$ --- -^warning: ignoring diff --git a/src/Makefile b/src/Makefile index 7562863742e..6d2c3f0a8fd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ DIRS = ansi-c big-int cbmc cpp goto-cc goto-instrument goto-programs \ goto-symex langapi pointer-analysis solvers util linking xmllang \ assembler analyses java_bytecode path-symex musketeer \ - json cegis goto-analyzer jsil symex goto-diff clobber \ + json goto-analyzer jsil symex goto-diff clobber \ memory-models miniz all: cbmc.dir goto-cc.dir goto-instrument.dir symex.dir goto-analyzer.dir goto-diff.dir diff --git a/src/analyses/ai.cpp b/src/analyses/ai.cpp index 2d1f4f6b986..45d4b83c92c 100644 --- a/src/analyses/ai.cpp +++ b/src/analyses/ai.cpp @@ -412,11 +412,7 @@ bool ai_baset::visit( statet ¤t=get_state(l); - goto_programt::const_targetst successors; - - goto_program.get_successors(l, successors); - - for(const auto &to_l : successors) + for(const auto &to_l : goto_program.get_successors(l)) { if(to_l==goto_program.instructions.end()) continue; diff --git a/src/analyses/custom_bitvector_analysis.cpp b/src/analyses/custom_bitvector_analysis.cpp index 01947636402..0a3f0306471 100644 --- a/src/analyses/custom_bitvector_analysis.cpp +++ b/src/analyses/custom_bitvector_analysis.cpp @@ -32,19 +32,19 @@ void custom_bitvector_domaint::set_bit( { switch(mode) { - case SET_MUST: + case modet::SET_MUST: set_bit(must_bits[identifier], bit_nr); break; - case CLEAR_MUST: + case modet::CLEAR_MUST: clear_bit(must_bits[identifier], bit_nr); break; - case SET_MAY: + case modet::SET_MAY: set_bit(may_bits[identifier], bit_nr); break; - case CLEAR_MAY: + case modet::CLEAR_MAY: clear_bit(may_bits[identifier], bit_nr); break; } @@ -408,13 +408,13 @@ void custom_bitvector_domaint::transform( modet mode; if(identifier=="__CPROVER_set_must") - mode=SET_MUST; + mode=modet::SET_MUST; else if(identifier=="__CPROVER_clear_must") - mode=CLEAR_MUST; + mode=modet::CLEAR_MUST; else if(identifier=="__CPROVER_set_may") - mode=SET_MAY; + mode=modet::SET_MAY; else if(identifier=="__CPROVER_clear_may") - mode=CLEAR_MAY; + mode=modet::CLEAR_MAY; else assert(false); @@ -423,7 +423,7 @@ void custom_bitvector_domaint::transform( if(lhs.is_constant() && to_constant_expr(lhs).get_value()==ID_NULL) // NULL means all { - if(mode==CLEAR_MAY) + if(mode==modet::CLEAR_MAY) { for(auto &bit : may_bits) clear_bit(bit.second, bit_nr); @@ -431,7 +431,7 @@ void custom_bitvector_domaint::transform( // erase blank ones erase_blank_vectors(may_bits); } - else if(mode==CLEAR_MUST) + else if(mode==modet::CLEAR_MUST) { for(auto &bit : must_bits) clear_bit(bit.second, bit_nr); @@ -475,13 +475,13 @@ void custom_bitvector_domaint::transform( modet mode; if(statement=="set_must") - mode=SET_MUST; + mode=modet::SET_MUST; else if(statement=="clear_must") - mode=CLEAR_MUST; + mode=modet::CLEAR_MUST; else if(statement=="set_may") - mode=SET_MAY; + mode=modet::SET_MAY; else if(statement=="clear_may") - mode=CLEAR_MAY; + mode=modet::CLEAR_MAY; else assert(false); @@ -490,7 +490,7 @@ void custom_bitvector_domaint::transform( if(lhs.is_constant() && to_constant_expr(lhs).get_value()==ID_NULL) // NULL means all { - if(mode==CLEAR_MAY) + if(mode==modet::CLEAR_MAY) { for(bitst::iterator b_it=may_bits.begin(); b_it!=may_bits.end(); @@ -500,7 +500,7 @@ void custom_bitvector_domaint::transform( // erase blank ones erase_blank_vectors(may_bits); } - else if(mode==CLEAR_MUST) + else if(mode==modet::CLEAR_MUST) { for(bitst::iterator b_it=must_bits.begin(); b_it!=must_bits.end(); diff --git a/src/analyses/custom_bitvector_analysis.h b/src/analyses/custom_bitvector_analysis.h index ceb2ba691be..e77cb6fc58b 100644 --- a/src/analyses/custom_bitvector_analysis.h +++ b/src/analyses/custom_bitvector_analysis.h @@ -102,7 +102,7 @@ class custom_bitvector_domaint:public ai_domain_baset custom_bitvector_analysist &) const; private: - typedef enum { SET_MUST, CLEAR_MUST, SET_MAY, CLEAR_MAY } modet; + enum class modet { SET_MUST, CLEAR_MUST, SET_MAY, CLEAR_MAY }; void set_bit(const exprt &, unsigned bit_nr, modet); void set_bit(const irep_idt &, unsigned bit_nr, modet); diff --git a/src/analyses/dependence_graph.cpp b/src/analyses/dependence_graph.cpp index 93588e209a7..730ec0266e4 100644 --- a/src/analyses/dependence_graph.cpp +++ b/src/analyses/dependence_graph.cpp @@ -141,7 +141,7 @@ void dep_graph_domaint::control_dependencies( // add edges to the graph for(const auto &c_dep : control_deps) - dep_graph.add_dep(dep_edget::CTRL, c_dep, to); + dep_graph.add_dep(dep_edget::kindt::CTRL, c_dep, to); } /*******************************************************************\ @@ -234,7 +234,7 @@ void dep_graph_domaint::data_dependencies( // *it might be handled in a future call call to visit only, // depending on the sequence of successors; make sure it exists dep_graph.get_state(d_dep); - dep_graph.add_dep(dep_edget::DATA, d_dep, to); + dep_graph.add_dep(dep_edget::kindt::DATA, d_dep, to); } } diff --git a/src/analyses/dependence_graph.h b/src/analyses/dependence_graph.h index 8b627dd36b0..fae7c7adbd4 100644 --- a/src/analyses/dependence_graph.h +++ b/src/analyses/dependence_graph.h @@ -24,27 +24,21 @@ class dependence_grapht; class dep_edget { public: - typedef enum - { - NONE, - CTRL, - DATA, - BOTH - } kindt; + enum class kindt { NONE, CTRL, DATA, BOTH }; void add(kindt _kind) { switch(kind) { - case NONE: + case kindt::NONE: kind=_kind; break; - case DATA: - case CTRL: + case kindt::DATA: + case kindt::CTRL: if(kind!=_kind) - kind=BOTH; + kind=kindt::BOTH; break; - case BOTH: + case kindt::BOTH: break; } } diff --git a/src/analyses/flow_insensitive_analysis.cpp b/src/analyses/flow_insensitive_analysis.cpp index c2cd188352d..bc4dd11e889 100644 --- a/src/analyses/flow_insensitive_analysis.cpp +++ b/src/analyses/flow_insensitive_analysis.cpp @@ -256,16 +256,13 @@ bool flow_insensitive_analysis_baset::visit( l->location_number << std::endl; #endif - goto_programt::const_targetst successors; - goto_program.get_successors(l, successors); - seen_locations.insert(l); if(statistics.find(l)==statistics.end()) statistics[l]=1; else statistics[l]++; - for(const auto &to_l : successors) + for(const auto &to_l : goto_program.get_successors(l)) { if(to_l==goto_program.instructions.end()) continue; diff --git a/src/analyses/goto_rw.cpp b/src/analyses/goto_rw.cpp index 239918240ab..e5df484cb9c 100644 --- a/src/analyses/goto_rw.cpp +++ b/src/analyses/goto_rw.cpp @@ -179,7 +179,7 @@ void rw_range_sett::get_objects_if( get_objects_rec(mode, if_expr.true_case(), range_start, size); else { - get_objects_rec(READ, if_expr.cond()); + get_objects_rec(get_modet::READ, if_expr.cond()); get_objects_rec(mode, if_expr.false_case(), range_start, size); get_objects_rec(mode, if_expr.true_case(), range_start, size); @@ -205,8 +205,8 @@ void rw_range_sett::get_objects_dereference( const range_spect &size) { const exprt &pointer=deref.pointer(); - get_objects_rec(READ, pointer); - if(mode!=READ) + get_objects_rec(get_modet::READ, pointer); + if(mode!=get_modet::READ) get_objects_rec(mode, pointer); } @@ -395,7 +395,7 @@ void rw_range_sett::get_objects_index( mp_integer index; if(to_integer(simp_index, index)) { - get_objects_rec(READ, expr.index()); + get_objects_rec(get_modet::READ, expr.index()); index=-1; } @@ -593,42 +593,42 @@ void rw_range_sett::get_objects_address_of(const exprt &object) // constant, nothing to do return; else if(object.id()==ID_symbol) - get_objects_rec(READ, object); + get_objects_rec(get_modet::READ, object); else if(object.id()==ID_dereference) - get_objects_rec(READ, object); + get_objects_rec(get_modet::READ, object); else if(object.id()==ID_index) { const index_exprt &index=to_index_expr(object); - get_objects_rec(READ, address_of_exprt(index.array())); - get_objects_rec(READ, index.index()); + get_objects_rec(get_modet::READ, address_of_exprt(index.array())); + get_objects_rec(get_modet::READ, index.index()); } else if(object.id()==ID_member) { const member_exprt &member=to_member_expr(object); - get_objects_rec(READ, address_of_exprt(member.struct_op())); + get_objects_rec(get_modet::READ, address_of_exprt(member.struct_op())); } else if(object.id()==ID_if) { const if_exprt &if_expr=to_if_expr(object); - get_objects_rec(READ, if_expr.cond()); - get_objects_rec(READ, address_of_exprt(if_expr.true_case())); - get_objects_rec(READ, address_of_exprt(if_expr.false_case())); + get_objects_rec(get_modet::READ, if_expr.cond()); + get_objects_rec(get_modet::READ, address_of_exprt(if_expr.true_case())); + get_objects_rec(get_modet::READ, address_of_exprt(if_expr.false_case())); } else if(object.id()==ID_byte_extract_little_endian || object.id()==ID_byte_extract_big_endian) { const byte_extract_exprt &be=to_byte_extract_expr(object); - get_objects_rec(READ, address_of_exprt(be.op())); + get_objects_rec(get_modet::READ, address_of_exprt(be.op())); } else if(object.id()==ID_typecast) { const typecast_exprt &tc=to_typecast_expr(object); - get_objects_rec(READ, address_of_exprt(tc.op())); + get_objects_rec(get_modet::READ, address_of_exprt(tc.op())); } else throw "rw_range_sett: address_of `"+object.id_string()+"' not handled"; @@ -652,7 +652,7 @@ void rw_range_sett::add( const range_spect &range_start, const range_spect &range_end) { - objectst::iterator entry=(mode==LHS_W ? w_range_set : r_range_set). + objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). insert( std::pair(identifier, 0)).first; @@ -742,9 +742,9 @@ void rw_range_sett::get_objects_rec( else add(mode, identifier, 0, -1); } - else if(mode==READ && expr.id()==ID_address_of) + else if(mode==get_modet::READ && expr.id()==ID_address_of) get_objects_address_of(to_address_of_expr(expr).object()); - else if(mode==READ) + else if(mode==get_modet::READ) { // possibly affects the full object size, even if range_start/size // are only a subset of the bytes (e.g., when using the result of @@ -757,7 +757,7 @@ void rw_range_sett::get_objects_rec( { // dereferencing may yield some weird ones, ignore these } - else if(mode==LHS_W) + else if(mode==get_modet::LHS_W) { forall_operands(it, expr) get_objects_rec(mode, *it); @@ -803,7 +803,7 @@ void rw_range_sett::get_objects_rec(const typet &type) if(type.id()==ID_array) { get_objects_rec(type.subtype()); - get_objects_rec(READ, to_array_type(type).size()); + get_objects_rec(get_modet::READ, to_array_type(type).size()); } } @@ -904,7 +904,7 @@ void rw_guarded_range_set_value_sett::get_objects_if( get_objects_rec(mode, if_expr.true_case(), range_start, size); else { - get_objects_rec(READ, if_expr.cond()); + get_objects_rec(get_modet::READ, if_expr.cond()); guardt guard_bak1(guard), guard_bak2(guard); @@ -936,7 +936,7 @@ void rw_guarded_range_set_value_sett::add( const range_spect &range_start, const range_spect &range_end) { - objectst::iterator entry=(mode==LHS_W ? w_range_set : r_range_set). + objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set). insert( std::pair(identifier, 0)).first; @@ -964,8 +964,8 @@ void goto_rw(goto_programt::const_targett target, const code_assignt &assign, rw_range_sett &rw_set) { - rw_set.get_objects_rec(target, rw_range_sett::LHS_W, assign.lhs()); - rw_set.get_objects_rec(target, rw_range_sett::READ, assign.rhs()); + rw_set.get_objects_rec(target, rw_range_sett::get_modet::LHS_W, assign.lhs()); + rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, assign.rhs()); } /*******************************************************************\ @@ -987,16 +987,16 @@ void goto_rw(goto_programt::const_targett target, if(function_call.lhs().is_not_nil()) rw_set.get_objects_rec( target, - rw_range_sett::LHS_W, + rw_range_sett::get_modet::LHS_W, function_call.lhs()); rw_set.get_objects_rec( target, - rw_range_sett::READ, + rw_range_sett::get_modet::READ, function_call.function()); forall_expr(it, function_call.arguments()) - rw_set.get_objects_rec(target, rw_range_sett::READ, *it); + rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, *it); } /*******************************************************************\ @@ -1025,7 +1025,7 @@ void goto_rw(goto_programt::const_targett target, case ASSERT: rw_set.get_objects_rec( target, - rw_range_sett::READ, + rw_range_sett::get_modet::READ, target->guard); break; @@ -1036,7 +1036,7 @@ void goto_rw(goto_programt::const_targett target, if(code_return.has_return_value()) rw_set.get_objects_rec( target, - rw_range_sett::READ, + rw_range_sett::get_modet::READ, code_return.return_value()); } break; @@ -1046,7 +1046,7 @@ void goto_rw(goto_programt::const_targett target, if(target->code.get(ID_statement)==ID_printf) { forall_expr(it, target->code.operands()) - rw_set.get_objects_rec(target, rw_range_sett::READ, *it); + rw_set.get_objects_rec(target, rw_range_sett::get_modet::READ, *it); } break; @@ -1069,7 +1069,7 @@ void goto_rw(goto_programt::const_targett target, case DEAD: rw_set.get_objects_rec( target, - rw_range_sett::LHS_W, + rw_range_sett::get_modet::LHS_W, to_code_dead(target->code).symbol()); break; @@ -1078,7 +1078,7 @@ void goto_rw(goto_programt::const_targett target, to_code_decl(target->code).symbol().type()); rw_set.get_objects_rec( target, - rw_range_sett::LHS_W, + rw_range_sett::get_modet::LHS_W, to_code_decl(target->code).symbol()); break; diff --git a/src/analyses/goto_rw.h b/src/analyses/goto_rw.h index 6c9ae6d9dec..2e826da7728 100644 --- a/src/analyses/goto_rw.h +++ b/src/analyses/goto_rw.h @@ -111,7 +111,7 @@ class rw_range_sett return *static_cast(it->second); } - typedef enum { LHS_W, READ } get_modet; + enum class get_modet { LHS_W, READ }; virtual void get_objects_rec( goto_programt::const_targett _target, diff --git a/src/analyses/local_bitvector_analysis.h b/src/analyses/local_bitvector_analysis.h index a902d19b099..4284ec99475 100644 --- a/src/analyses/local_bitvector_analysis.h +++ b/src/analyses/local_bitvector_analysis.h @@ -61,7 +61,7 @@ class local_bitvector_analysist } // the bits for the "bitvector analysis" - typedef enum + enum bitst { B_unknown=1<<0, B_uninitialized=1<<1, @@ -71,7 +71,7 @@ class local_bitvector_analysist B_null=1<<5, B_static_lifetime=1<<6, B_integer_address=1<<7 - } bitst; + }; explicit flagst(const bitst _bits):bits(_bits) { diff --git a/src/analyses/static_analysis.cpp b/src/analyses/static_analysis.cpp index 96d7e5a9d9a..8309566f27d 100644 --- a/src/analyses/static_analysis.cpp +++ b/src/analyses/static_analysis.cpp @@ -356,11 +356,7 @@ bool static_analysis_baset::visit( current.seen=true; - goto_programt::const_targetst successors; - - goto_program.get_successors(l, successors); - - for(const auto &to_l : successors) + for(const auto &to_l : goto_program.get_successors(l)) { if(to_l==goto_program.instructions.end()) continue; diff --git a/src/ansi-c/ansi_c_parser.cpp b/src/ansi-c/ansi_c_parser.cpp index a32d31bac61..77a71b62dc2 100644 --- a/src/ansi-c/ansi_c_parser.cpp +++ b/src/ansi-c/ansi_c_parser.cpp @@ -59,15 +59,15 @@ ansi_c_id_classt ansi_c_parsert::lookup( { ansi_c_identifiert &i= current_scope().name_map[scope_name]; - i.id_class=ANSI_C_TAG; + i.id_class=ansi_c_id_classt::ANSI_C_TAG; i.prefixed_name=current_scope().prefix+id2string(scope_name); i.base_name=base_name; identifier=i.prefixed_name; - return ANSI_C_TAG; + return ansi_c_id_classt::ANSI_C_TAG; } identifier=base_name; - return ANSI_C_UNKNOWN; + return ansi_c_id_classt::ANSI_C_UNKNOWN; } /*******************************************************************\ @@ -94,7 +94,7 @@ void ansi_c_parsert::add_tag_with_body(irept &tag) // re-defined in a deeper scope ansi_c_identifiert &identifier= current_scope().name_map[scope_name]; - identifier.id_class=ANSI_C_TAG; + identifier.id_class=ansi_c_id_classt::ANSI_C_TAG; identifier.prefixed_name=prefixed_name; tag.set(ID_identifier, prefixed_name); } @@ -180,8 +180,9 @@ void ansi_c_parsert::add_declarator( if(is_extern) force_root_scope=true; - ansi_c_id_classt id_class= - is_typedef?ANSI_C_TYPEDEF:ANSI_C_SYMBOL; + ansi_c_id_classt id_class=is_typedef? + ansi_c_id_classt::ANSI_C_TYPEDEF: + ansi_c_id_classt::ANSI_C_SYMBOL; scopet &scope= force_root_scope?root_scope():current_scope(); @@ -216,19 +217,19 @@ Function: ansi_c_parsert::get_class ansi_c_id_classt ansi_c_parsert::get_class(const typet &type) { if(type.id()==ID_typedef) - return ANSI_C_TYPEDEF; + return ansi_c_id_classt::ANSI_C_TYPEDEF; else if(type.id()==ID_struct || type.id()==ID_union || type.id()==ID_c_enum) - return ANSI_C_TAG; + return ansi_c_id_classt::ANSI_C_TAG; else if(type.id()==ID_merged_type) { forall_subtypes(it, type) - if(get_class(*it)==ANSI_C_TYPEDEF) - return ANSI_C_TYPEDEF; + if(get_class(*it)==ansi_c_id_classt::ANSI_C_TYPEDEF) + return ansi_c_id_classt::ANSI_C_TYPEDEF; } else if(type.has_subtype()) return get_class(type.subtype()); - return ANSI_C_SYMBOL; + return ansi_c_id_classt::ANSI_C_SYMBOL; } diff --git a/src/ansi-c/ansi_c_parser.h b/src/ansi-c/ansi_c_parser.h index 2b35b56f34a..579797db46a 100644 --- a/src/ansi-c/ansi_c_parser.h +++ b/src/ansi-c/ansi_c_parser.h @@ -98,7 +98,7 @@ class ansi_c_parsert:public parsert return scopes.back(); } - typedef enum { TAG, MEMBER, PARAMETER, OTHER } decl_typet; + enum class decl_typet { TAG, MEMBER, PARAMETER, OTHER }; // convert a declarator and then add it to existing an declaration void add_declarator(exprt &declaration, irept &declarator); diff --git a/src/ansi-c/ansi_c_scope.cpp b/src/ansi-c/ansi_c_scope.cpp index 761fd23b19b..ffd3663e1fa 100644 --- a/src/ansi-c/ansi_c_scope.cpp +++ b/src/ansi-c/ansi_c_scope.cpp @@ -29,7 +29,7 @@ void ansi_c_scopet::print(std::ostream &out) const for(const auto &name : name_map) { out << " ID: " << name.first - << " CLASS: " << name.second.id_class + << " CLASS: " << static_cast(name.second.id_class) << "\n"; } } diff --git a/src/ansi-c/ansi_c_scope.h b/src/ansi-c/ansi_c_scope.h index 722774c01cc..6f7b92b876c 100644 --- a/src/ansi-c/ansi_c_scope.h +++ b/src/ansi-c/ansi_c_scope.h @@ -11,8 +11,16 @@ Author: Daniel Kroening, kroening@kroening.com #include -typedef enum { ANSI_C_UNKNOWN, ANSI_C_SYMBOL, ANSI_C_TYPEDEF, - ANSI_C_TAG, ANSI_C_LOCAL_LABEL } ansi_c_id_classt; +enum class ansi_c_id_classt +{ + ANSI_C_UNKNOWN, + ANSI_C_SYMBOL, + ANSI_C_TYPEDEF, + ANSI_C_TAG, + ANSI_C_LOCAL_LABEL +}; + +std::ostream &operator<<(std::ostream &os, ansi_c_id_classt c); class ansi_c_identifiert { @@ -20,7 +28,7 @@ class ansi_c_identifiert ansi_c_id_classt id_class; irep_idt base_name, prefixed_name; - ansi_c_identifiert():id_class(ANSI_C_UNKNOWN) + ansi_c_identifiert():id_class(ansi_c_id_classt::ANSI_C_UNKNOWN) { } }; diff --git a/src/ansi-c/c_typecheck_expr.cpp b/src/ansi-c/c_typecheck_expr.cpp index 5961f64142e..5d4788e5145 100644 --- a/src/ansi-c/c_typecheck_expr.cpp +++ b/src/ansi-c/c_typecheck_expr.cpp @@ -294,6 +294,10 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr) expr.make_bool(gcc_types_compatible_p(subtypes[0], subtypes[1])); expr.add_source_location()=source_location; } + else if(expr.id()==ID_clang_builtin_convertvector) + { + typecheck_type(expr.type()); + } else if(expr.id()==ID_builtin_offsetof) typecheck_expr_builtin_offsetof(expr); else if(expr.id()==ID_string_constant) diff --git a/src/ansi-c/expr2c.cpp b/src/ansi-c/expr2c.cpp index a68f960b852..e8ccb805a76 100644 --- a/src/ansi-c/expr2c.cpp +++ b/src/ansi-c/expr2c.cpp @@ -886,16 +886,16 @@ std::string expr2ct::convert_typecast( if(to_type.id()==ID_c_bool && from_type.id()==ID_bool) - return convert(src.op(), precedence); + return convert_with_precedence(src.op(), precedence); if(to_type.id()==ID_bool && from_type.id()==ID_c_bool) - return convert(src.op(), precedence); + return convert_with_precedence(src.op(), precedence); std::string dest="("+convert(src.type())+")"; unsigned p; - std::string tmp=convert(src.op(), p); + std::string tmp=convert_with_precedence(src.op(), p); if(precedence>p) dest+='('; @@ -934,9 +934,9 @@ std::string expr2ct::convert_trinary( unsigned p0, p1, p2; - std::string s_op0=convert(op0, p0); - std::string s_op1=convert(op1, p1); - std::string s_op2=convert(op2, p2); + std::string s_op0=convert_with_precedence(op0, p0); + std::string s_op1=convert_with_precedence(op1, p1); + std::string s_op2=convert_with_precedence(op2, p2); std::string dest; @@ -991,8 +991,8 @@ std::string expr2ct::convert_quantifier( unsigned p0, p1; - std::string op0=convert(src.op0(), p0); - std::string op1=convert(src.op1(), p1); + std::string op0=convert_with_precedence(src.op0(), p0); + std::string op1=convert_with_precedence(src.op1(), p1); std::string dest=symbol+" { "; dest+=convert(src.op0().type()); @@ -1023,7 +1023,7 @@ std::string expr2ct::convert_with( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); std::string dest; @@ -1069,9 +1069,9 @@ std::string expr2ct::convert_with( p1=10; } else - op1=convert(src.operands()[i], p1); + op1=convert_with_precedence(src.operands()[i], p1); - op2=convert(src.operands()[i+1], p2); + op2=convert_with_precedence(src.operands()[i+1], p2); dest+=op1; dest+=":="; @@ -1110,8 +1110,8 @@ std::string expr2ct::convert_update( std::string op0, op1, op2; unsigned p0, p2; - op0=convert(src.op0(), p0); - op2=convert(src.op2(), p2); + op0=convert_with_precedence(src.op0(), p0); + op2=convert_with_precedence(src.op2(), p2); if(precedence>p0) dest+='('; @@ -1165,7 +1165,7 @@ std::string expr2ct::convert_cond( forall_operands(it, src) { unsigned p; - std::string op=convert(*it, p); + std::string op=convert_with_precedence(*it, p); if(condition) dest+=" "; @@ -1222,7 +1222,7 @@ std::string expr2ct::convert_binary( } unsigned p; - std::string op=convert(*it, p); + std::string op=convert_with_precedence(*it, p); // In pointer arithmetic, x+(y-z) is unfortunately // not the same as (x+y)-z, even though + and - @@ -1267,7 +1267,7 @@ std::string expr2ct::convert_unary( return convert_norep(src, precedence); unsigned p; - std::string op=convert(src.op0(), p); + std::string op=convert_with_precedence(src.op0(), p); std::string dest=symbol; if(precedence>=p || @@ -1301,7 +1301,7 @@ std::string expr2ct::convert_pointer_object_has_type( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); std::string dest="POINTER_OBJECT_HAS_TYPE"; dest+='('; @@ -1333,7 +1333,7 @@ std::string expr2ct::convert_malloc( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); std::string dest="MALLOC"; dest+='('; @@ -1482,7 +1482,7 @@ std::string expr2ct::convert_function( forall_operands(it, src) { unsigned p; - std::string op=convert(*it, p); + std::string op=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -1515,12 +1515,12 @@ std::string expr2ct::convert_comma( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); if(*op0.rbegin()==';') op0.resize(op0.size()-1); unsigned p1; - std::string op1=convert(src.op1(), p1); + std::string op1=convert_with_precedence(src.op1(), p1); if(*op1.rbegin()==';') op1.resize(op1.size()-1); @@ -1553,7 +1553,7 @@ std::string expr2ct::convert_complex( { // This is believed to be gcc only; check if this is sensible // in MSC mode. - return convert(src.op1(), precedence)+"i"; + return convert_with_precedence(src.op1(), precedence)+"i"; } // ISO C11 offers: @@ -1581,7 +1581,7 @@ std::string expr2ct::convert_complex( forall_operands(it, src) { unsigned p; - std::string op=convert(*it, p); + std::string op=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -1636,10 +1636,10 @@ std::string expr2ct::convert_byte_extract( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); unsigned p1; - std::string op1=convert(src.op1(), p1); + std::string op1=convert_with_precedence(src.op1(), p1); std::string dest=src.id_string(); dest+='('; @@ -1673,13 +1673,13 @@ std::string expr2ct::convert_byte_update( return convert_norep(src, precedence); unsigned p0; - std::string op0=convert(src.op0(), p0); + std::string op0=convert_with_precedence(src.op0(), p0); unsigned p1; - std::string op1=convert(src.op1(), p1); + std::string op1=convert_with_precedence(src.op1(), p1); unsigned p2; - std::string op2=convert(src.op2(), p2); + std::string op2=convert_with_precedence(src.op2(), p2); std::string dest=src.id_string(); dest+='('; @@ -1716,7 +1716,7 @@ std::string expr2ct::convert_unary_post( return convert_norep(src, precedence); unsigned p; - std::string op=convert(src.op0(), p); + std::string op=convert_with_precedence(src.op0(), p); std::string dest; if(precedence>p) @@ -1749,7 +1749,7 @@ std::string expr2ct::convert_index( return convert_norep(src, precedence); unsigned p; - std::string op=convert(src.op0(), p); + std::string op=convert_with_precedence(src.op0(), p); std::string dest; if(precedence>p) @@ -1793,7 +1793,7 @@ std::string expr2ct::convert_pointer_arithmetic( dest+=", "; - op=convert(src.op0(), p); + op=convert_with_precedence(src.op0(), p); if(precedence>p) dest+='('; dest+=op; @@ -1802,7 +1802,7 @@ std::string expr2ct::convert_pointer_arithmetic( dest+=", "; - op=convert(src.op1(), p); + op=convert_with_precedence(src.op1(), p); if(precedence>p) dest+='('; dest+=op; @@ -1842,7 +1842,7 @@ std::string expr2ct::convert_pointer_difference( dest+=", "; - op=convert(src.op0(), p); + op=convert_with_precedence(src.op0(), p); if(precedence>p) dest+='('; dest+=op; @@ -1851,7 +1851,7 @@ std::string expr2ct::convert_pointer_difference( dest+=", "; - op=convert(src.op1(), p); + op=convert_with_precedence(src.op1(), p); if(precedence>p) dest+='('; dest+=op; @@ -1932,7 +1932,7 @@ std::string expr2ct::convert_member( if(src.op0().id()==ID_dereference && src.operands().size()==1) { - std::string op=convert(src.op0().op0(), p); + std::string op=convert_with_precedence(src.op0().op0(), p); if(precedence>p || src.op0().op0().id()==ID_typecast) dest+='('; @@ -1944,7 +1944,7 @@ std::string expr2ct::convert_member( } else { - std::string op=convert(src.op0(), p); + std::string op=convert_with_precedence(src.op0(), p); if(precedence>p || src.op0().id()==ID_typecast) dest+='('; @@ -2495,7 +2495,7 @@ std::string expr2ct::convert_constant( return convert_norep(src, precedence); } else - return convert(src.op0(), precedence); + return convert_with_precedence(src.op0(), precedence); } } else if(type.id()==ID_string) @@ -2986,7 +2986,7 @@ std::string expr2ct::convert_function_application( { unsigned p; - std::string function_str=convert(src.function(), p); + std::string function_str=convert_with_precedence(src.function(), p); dest+=function_str; } @@ -2995,7 +2995,7 @@ std::string expr2ct::convert_function_application( forall_expr(it, src.arguments()) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.arguments().begin()) dest+=", "; @@ -3028,7 +3028,7 @@ std::string expr2ct::convert_side_effect_expr_function_call( { unsigned p; - std::string function_str=convert(src.function(), p); + std::string function_str=convert_with_precedence(src.function(), p); dest+=function_str; } @@ -3037,7 +3037,7 @@ std::string expr2ct::convert_side_effect_expr_function_call( forall_expr(it, src.arguments()) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.arguments().begin()) dest+=", "; @@ -3081,7 +3081,7 @@ std::string expr2ct::convert_overflow( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); dest+=", "; // TODO: ggf. Klammern je nach p @@ -3991,7 +3991,7 @@ std::string expr2ct::convert_code_function_call( if(src.lhs().is_not_nil()) { unsigned p; - std::string lhs_str=convert(src.lhs(), p); + std::string lhs_str=convert_with_precedence(src.lhs(), p); // TODO: ggf. Klammern je nach p dest+=lhs_str; @@ -4000,7 +4000,7 @@ std::string expr2ct::convert_code_function_call( { unsigned p; - std::string function_str=convert(src.function(), p); + std::string function_str=convert_with_precedence(src.function(), p); dest+=function_str; } @@ -4011,7 +4011,7 @@ std::string expr2ct::convert_code_function_call( forall_expr(it, arguments) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=arguments.begin()) dest+=", "; @@ -4045,7 +4045,7 @@ std::string expr2ct::convert_code_printf( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -4121,7 +4121,7 @@ std::string expr2ct::convert_code_input( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -4155,7 +4155,7 @@ std::string expr2ct::convert_code_output( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -4188,7 +4188,7 @@ std::string expr2ct::convert_code_array_set( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -4222,7 +4222,7 @@ std::string expr2ct::convert_code_array_copy( forall_operands(it, src) { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(it!=src.operands().begin()) dest+=", "; @@ -4448,9 +4448,9 @@ std::string expr2ct::convert_extractbit( if(src.operands().size()!=2) return convert_norep(src, precedence); - std::string dest=convert(src.op0(), precedence); + std::string dest=convert_with_precedence(src.op0(), precedence); dest+='['; - dest+=convert(src.op1(), precedence); + dest+=convert_with_precedence(src.op1(), precedence); dest+=']'; return dest; @@ -4475,11 +4475,11 @@ std::string expr2ct::convert_extractbits( if(src.operands().size()!=3) return convert_norep(src, precedence); - std::string dest=convert(src.op0(), precedence); + std::string dest=convert_with_precedence(src.op0(), precedence); dest+='['; - dest+=convert(src.op1(), precedence); + dest+=convert_with_precedence(src.op1(), precedence); dest+=", "; - dest+=convert(src.op2(), precedence); + dest+=convert_with_precedence(src.op2(), precedence); dest+=']'; return dest; @@ -4523,7 +4523,7 @@ Function: expr2ct::convert \*******************************************************************/ -std::string expr2ct::convert( +std::string expr2ct::convert_with_precedence( const exprt &src, unsigned &precedence) { @@ -4562,7 +4562,7 @@ std::string expr2ct::convert( std::string dest="FLOAT_TYPECAST("; unsigned p0; - std::string tmp0=convert(src.op0(), p0); + std::string tmp0=convert_with_precedence(src.op0(), p0); if(p0<=1) dest+='('; @@ -4576,7 +4576,7 @@ std::string expr2ct::convert( dest+=", "; unsigned p1; - std::string tmp1=convert(src.op1(), p1); + std::string tmp1=convert_with_precedence(src.op1(), p1); if(p1<=1) dest+='('; @@ -5042,7 +5042,7 @@ Function: expr2ct::convert std::string expr2ct::convert(const exprt &src) { unsigned precedence; - return convert(src, precedence); + return convert_with_precedence(src, precedence); } /*******************************************************************\ diff --git a/src/ansi-c/expr2c_class.h b/src/ansi-c/expr2c_class.h index b0647fb7fbb..771f936afb8 100644 --- a/src/ansi-c/expr2c_class.h +++ b/src/ansi-c/expr2c_class.h @@ -205,7 +205,8 @@ class expr2ct std::string convert_code_array_set(const codet &src, unsigned indent); std::string convert_code_array_copy(const codet &src, unsigned indent); - virtual std::string convert(const exprt &src, unsigned &precedence); + virtual std::string convert_with_precedence( + const exprt &src, unsigned &precedence); // NOLINTNEXTLINE(whitespace/line_length) std::string convert_function_application(const function_application_exprt &src, unsigned &precedence); diff --git a/src/ansi-c/parser.y b/src/ansi-c/parser.y index d81e27dc39f..3529ef5cff0 100644 --- a/src/ansi-c/parser.y +++ b/src/ansi-c/parser.y @@ -146,6 +146,7 @@ extern char *yyansi_ctext; %token TOK_CW_VAR_ARG_TYPEOF "_var_arg_typeof" %token TOK_BUILTIN_VA_ARG "__builtin_va_arg" %token TOK_GCC_BUILTIN_TYPES_COMPATIBLE_P "__builtin_types_compatible_p" +%token TOK_CLANG_BUILTIN_CONVERTVECTOR "__builtin_convertvector" %token TOK_OFFSETOF "__offsetof" %token TOK_ALIGNOF "__alignof__" %token TOK_MSC_TRY "__try" @@ -264,7 +265,8 @@ identifier: irep_idt value=stack($2).get(ID_value); stack($$).set(ID_C_base_name, value); stack($$).set(ID_identifier, value); - stack($$).set(ID_C_id_class, ANSI_C_SYMBOL); + stack($$).set( + ID_C_id_class, static_cast(ansi_c_id_classt::ANSI_C_SYMBOL)); } ; @@ -305,6 +307,7 @@ primary_expression: { $$ = $2; } | statement_expression | gcc_builtin_expressions + | clang_builtin_expressions | cw_builtin_expressions | offsetof | quantifier_expression @@ -370,6 +373,16 @@ gcc_builtin_expressions: } ; +clang_builtin_expressions: + TOK_CLANG_BUILTIN_CONVERTVECTOR '(' assignment_expression ',' type_name ')' + { + $$=$1; + stack($$).id(ID_clang_builtin_convertvector); + mto($$, $3); + stack($$).type().swap(stack($5)); + } + ; + cw_builtin_expressions: TOK_CW_VAR_ARG_TYPEOF '(' type_name ')' { @@ -2375,7 +2388,7 @@ gcc_local_label_statement: irep_idt base_name=it->get(ID_identifier); irep_idt id="label-"+id2string(base_name); ansi_c_parsert::identifiert &i=PARSER.current_scope().name_map[id]; - i.id_class=ANSI_C_LOCAL_LABEL; + i.id_class=ansi_c_id_classt::ANSI_C_LOCAL_LABEL; i.prefixed_name=PARSER.current_scope().prefix+id2string(id); i.base_name=base_name; } diff --git a/src/ansi-c/parser_static.inc b/src/ansi-c/parser_static.inc index eb91ce52983..5e24eff5a05 100644 --- a/src/ansi-c/parser_static.inc +++ b/src/ansi-c/parser_static.inc @@ -364,7 +364,7 @@ static void create_function_scope(const YYSTYPE d) irep_idt base_name=param_decl.declarator().get_base_name(); ansi_c_identifiert &identifier= PARSER.current_scope().name_map[base_name]; - identifier.id_class=ANSI_C_SYMBOL; + identifier.id_class=ansi_c_id_classt::ANSI_C_SYMBOL; identifier.base_name=base_name; identifier.prefixed_name=param_decl.declarator().get_name(); } diff --git a/src/ansi-c/printf_formatter.cpp b/src/ansi-c/printf_formatter.cpp index 59e3dbcc20f..31ddfa735f2 100644 --- a/src/ansi-c/printf_formatter.cpp +++ b/src/ansi-c/printf_formatter.cpp @@ -159,8 +159,18 @@ void printf_formattert::process_format(std::ostream &out) out << ch; break; + case 'e': + case 'E': + format_constant.style=format_spect::stylet::SCIENTIFIC; + if(next_operand==operands.end()) + break; + out << format_constant( + make_type(*(next_operand++), double_type())); + break; + case 'f': case 'F': + format_constant.style=format_spect::stylet::DECIMAL; if(next_operand==operands.end()) break; out << format_constant( @@ -169,6 +179,7 @@ void printf_formattert::process_format(std::ostream &out) case 'g': case 'G': + format_constant.style=format_spect::stylet::AUTOMATIC; if(format_constant.precision==0) format_constant.precision=1; if(next_operand==operands.end()) diff --git a/src/ansi-c/scanner.l b/src/ansi-c/scanner.l index f5b3d7ec6c8..2b58bd40c9f 100644 --- a/src/ansi-c/scanner.l +++ b/src/ansi-c/scanner.l @@ -96,9 +96,9 @@ int make_identifier() stack(yyansi_clval).id(ID_symbol); stack(yyansi_clval).set(ID_C_base_name, base_name); stack(yyansi_clval).set(ID_identifier, identifier); - stack(yyansi_clval).set(ID_C_id_class, result); + stack(yyansi_clval).set(ID_C_id_class, static_cast(result)); - if(result==ANSI_C_TYPEDEF) + if(result==ansi_c_id_classt::ANSI_C_TYPEDEF) return TOK_TYPEDEFNAME; else return TOK_IDENTIFIER; @@ -589,6 +589,14 @@ void ansi_c_scanner_init() return make_identifier(); } +"__builtin_convertvector" { + if(PARSER.mode==configt::ansi_ct::flavourt::GCC || + PARSER.mode==configt::ansi_ct::flavourt::APPLE) + { loc(); return TOK_CLANG_BUILTIN_CONVERTVECTOR; } + else + return make_identifier(); + } + "__alignof__" { if(PARSER.mode==configt::ansi_ct::flavourt::GCC || PARSER.mode==configt::ansi_ct::flavourt::APPLE || PARSER.mode==configt::ansi_ct::flavourt::ARM) diff --git a/src/cbmc/all_properties.cpp b/src/cbmc/all_properties.cpp index 590b7696201..2534ba7827a 100644 --- a/src/cbmc/all_properties.cpp +++ b/src/cbmc/all_properties.cpp @@ -140,7 +140,7 @@ safety_checkert::resultt bmc_all_propertiest::operator()() decision_proceduret::resultt result=cover_goals(); - if(result==decision_proceduret::D_ERROR) + if(result==decision_proceduret::resultt::D_ERROR) { error=true; for(auto &g : goal_map) @@ -166,7 +166,7 @@ safety_checkert::resultt bmc_all_propertiest::operator()() report(cover_goals); if(error) - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; bool safe=(cover_goals.number_covered()==0); @@ -175,7 +175,7 @@ safety_checkert::resultt bmc_all_propertiest::operator()() else bmc.report_failure(); // legacy, might go away - return safe?safety_checkert::SAFE:safety_checkert::UNSAFE; + return safe?safety_checkert::resultt::SAFE:safety_checkert::resultt::UNSAFE; } /*******************************************************************\ @@ -194,7 +194,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals) { switch(bmc.ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: { status() << "\n** Results:" << eom; @@ -222,7 +222,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals) } break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { for(const auto &g : goal_map) { @@ -238,7 +238,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals) break; } - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["result"].make_array(); diff --git a/src/cbmc/bmc.cpp b/src/cbmc/bmc.cpp index f1e005a46a1..0a8fd5053c8 100644 --- a/src/cbmc/bmc.cpp +++ b/src/cbmc/bmc.cpp @@ -77,12 +77,12 @@ void bmct::error_trace() switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: std::cout << "\n" << "Counterexample:" << "\n"; show_goto_trace(std::cout, ns, goto_trace); break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml; convert(ns, goto_trace, xml); @@ -90,7 +90,7 @@ void bmct::error_trace() } break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["results"].make_array(); @@ -130,9 +130,9 @@ void bmct::output_graphml( return; graphml_witnesst graphml_witness(ns); - if(result==UNSAFE) + if(result==resultt::UNSAFE) graphml_witness(safety_checkert::error_trace); - else if(result==SAFE) + else if(result==resultt::SAFE) graphml_witness(equation); else return; @@ -235,10 +235,10 @@ void bmct::report_success() switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="SUCCESS"; @@ -247,7 +247,7 @@ void bmct::report_success() } break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_result["cProverStatus"]=json_stringt("success"); @@ -275,10 +275,10 @@ void bmct::report_failure() switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="FAILURE"; @@ -287,7 +287,7 @@ void bmct::report_failure() } break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_result["cProverStatus"]=json_stringt("failure"); @@ -426,7 +426,7 @@ safety_checkert::resultt bmct::run( { error() << "Invalid memory model " << mm << " -- use one of sc, tso, pso" << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } symex.set_message_handler(get_message_handler()); @@ -464,7 +464,7 @@ safety_checkert::resultt bmct::run( message.error().source_location=symex.last_source_location; message.error() << error_str << messaget::eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } catch(const char *error_str) @@ -473,13 +473,13 @@ safety_checkert::resultt bmct::run( message.error().source_location=symex.last_source_location; message.error() << error_str << messaget::eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } catch(std::bad_alloc) { error() << "Out of memory" << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } statistics() << "size of program expression: " @@ -534,13 +534,13 @@ safety_checkert::resultt bmct::run( symex.output_coverage_report(goto_functions, cov_out)) { error() << "Failed to write symex coverage report" << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } if(options.get_bool_option("show-vcc")) { show_vcc(); - return safety_checkert::SAFE; // to indicate non-error + return safety_checkert::resultt::SAFE; // to indicate non-error } if(!options.get_list_option("cover").empty()) @@ -548,7 +548,7 @@ safety_checkert::resultt bmct::run( const optionst::value_listt criteria= options.get_list_option("cover"); return cover(goto_functions, criteria)? - safety_checkert::ERROR:safety_checkert::SAFE; + safety_checkert::resultt::ERROR:safety_checkert::resultt::SAFE; } if(options.get_option("localize-faults")!="") @@ -563,14 +563,14 @@ safety_checkert::resultt bmct::run( symex.remaining_vccs==0) { report_success(); - output_graphml(SAFE, goto_functions); - return safety_checkert::SAFE; + output_graphml(resultt::SAFE, goto_functions); + return safety_checkert::resultt::SAFE; } if(options.get_bool_option("program-only")) { show_program(); - return safety_checkert::SAFE; + return safety_checkert::resultt::SAFE; } return decide(goto_functions, prop_conv); @@ -579,19 +579,19 @@ safety_checkert::resultt bmct::run( catch(std::string &error_str) { error() << error_str << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } catch(const char *error_str) { error() << error_str << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } catch(std::bad_alloc) { error() << "Out of memory" << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } } @@ -637,12 +637,12 @@ safety_checkert::resultt bmct::stop_on_fail( { switch(run_decision_procedure(prop_conv)) { - case decision_proceduret::D_UNSATISFIABLE: + case decision_proceduret::resultt::D_UNSATISFIABLE: report_success(); - output_graphml(SAFE, goto_functions); - return SAFE; + output_graphml(resultt::SAFE, goto_functions); + return resultt::SAFE; - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: if(options.get_bool_option("trace")) { if(options.get_bool_option("beautify")) @@ -650,20 +650,20 @@ safety_checkert::resultt bmct::stop_on_fail( dynamic_cast(prop_conv), equation, ns); error_trace(); - output_graphml(UNSAFE, goto_functions); + output_graphml(resultt::UNSAFE, goto_functions); } report_failure(); - return UNSAFE; + return resultt::UNSAFE; default: if(options.get_bool_option("dimacs") || options.get_option("outfile")!="") - return SAFE; + return resultt::SAFE; error() << "decision procedure failed" << eom; - return ERROR; + return resultt::ERROR; } } diff --git a/src/cbmc/bmc.h b/src/cbmc/bmc.h index e923711a47e..33d73005c1a 100644 --- a/src/cbmc/bmc.h +++ b/src/cbmc/bmc.h @@ -40,7 +40,7 @@ class bmct:public safety_checkert equation(ns), symex(ns, new_symbol_table, equation), prop_conv(_prop_conv), - ui(ui_message_handlert::PLAIN) + ui(ui_message_handlert::uit::PLAIN) { symex.constant_propagation=options.get_bool_option("propagation"); symex.record_coverage= diff --git a/src/cbmc/bmc_cover.cpp b/src/cbmc/bmc_cover.cpp index 5fb282778f5..fd900dda14d 100644 --- a/src/cbmc/bmc_cover.cpp +++ b/src/cbmc/bmc_cover.cpp @@ -309,7 +309,7 @@ bool bmc_covert::operator()() switch(bmc.ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: { status() << "\n** coverage results:" << eom; @@ -334,7 +334,7 @@ bool bmc_covert::operator()() break; } - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { for(const auto &goal_pair : goal_map) { @@ -386,7 +386,7 @@ bool bmc_covert::operator()() break; } - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &goals_array=json_result["goals"].make_array(); @@ -452,7 +452,7 @@ bool bmc_covert::operator()() << (cover_goals.iterations()==1?"":"s") << eom; - if(bmc.ui==ui_message_handlert::PLAIN) + if(bmc.ui==ui_message_handlert::uit::PLAIN) { std::cout << "Test suite:" << '\n'; diff --git a/src/cbmc/cbmc_parse_options.cpp b/src/cbmc/cbmc_parse_options.cpp index 453ec2d1efc..aaf0aad6b90 100644 --- a/src/cbmc/cbmc_parse_options.cpp +++ b/src/cbmc/cbmc_parse_options.cpp @@ -1047,13 +1047,13 @@ int cbmc_parse_optionst::do_bmc( // do actual BMC switch(bmc.run(goto_functions)) { - case safety_checkert::SAFE: + case safety_checkert::resultt::SAFE: result=0; break; - case safety_checkert::UNSAFE: + case safety_checkert::resultt::UNSAFE: result=10; break; - case safety_checkert::ERROR: + case safety_checkert::resultt::ERROR: result=6; break; } diff --git a/src/cbmc/cbmc_solvers.cpp b/src/cbmc/cbmc_solvers.cpp index b647ba17f52..a9395f476bb 100644 --- a/src/cbmc/cbmc_solvers.cpp +++ b/src/cbmc/cbmc_solvers.cpp @@ -43,24 +43,24 @@ smt1_dect::solvert cbmc_solverst::get_smt1_solver_type() const { assert(options.get_bool_option("smt1")); - smt1_dect::solvert s=smt1_dect::GENERIC; + smt1_dect::solvert s=smt1_dect::solvert::GENERIC; if(options.get_bool_option("boolector")) - s=smt1_dect::BOOLECTOR; + s=smt1_dect::solvert::BOOLECTOR; else if(options.get_bool_option("mathsat")) - s=smt1_dect::MATHSAT; + s=smt1_dect::solvert::MATHSAT; else if(options.get_bool_option("cvc3")) - s=smt1_dect::CVC3; + s=smt1_dect::solvert::CVC3; else if(options.get_bool_option("cvc4")) - s=smt1_dect::CVC4; + s=smt1_dect::solvert::CVC4; else if(options.get_bool_option("opensmt")) - s=smt1_dect::OPENSMT; + s=smt1_dect::solvert::OPENSMT; else if(options.get_bool_option("yices")) - s=smt1_dect::YICES; + s=smt1_dect::solvert::YICES; else if(options.get_bool_option("z3")) - s=smt1_dect::Z3; + s=smt1_dect::solvert::Z3; else if(options.get_bool_option("generic")) - s=smt1_dect::GENERIC; + s=smt1_dect::solvert::GENERIC; return s; } @@ -81,24 +81,24 @@ smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const { assert(options.get_bool_option("smt2")); - smt2_dect::solvert s=smt2_dect::GENERIC; + smt2_dect::solvert s=smt2_dect::solvert::GENERIC; if(options.get_bool_option("boolector")) - s=smt2_dect::BOOLECTOR; + s=smt2_dect::solvert::BOOLECTOR; else if(options.get_bool_option("mathsat")) - s=smt2_dect::MATHSAT; + s=smt2_dect::solvert::MATHSAT; else if(options.get_bool_option("cvc3")) - s=smt2_dect::CVC3; + s=smt2_dect::solvert::CVC3; else if(options.get_bool_option("cvc4")) - s=smt2_dect::CVC4; + s=smt2_dect::solvert::CVC4; else if(options.get_bool_option("opensmt")) - s=smt2_dect::OPENSMT; + s=smt2_dect::solvert::OPENSMT; else if(options.get_bool_option("yices")) - s=smt2_dect::YICES; + s=smt2_dect::solvert::YICES; else if(options.get_bool_option("z3")) - s=smt2_dect::Z3; + s=smt2_dect::solvert::Z3; else if(options.get_bool_option("generic")) - s=smt2_dect::GENERIC; + s=smt2_dect::solvert::GENERIC; return s; } @@ -135,9 +135,9 @@ cbmc_solverst::solvert* cbmc_solverst::get_default() bv_cbmct *bv_cbmc=new bv_cbmct(ns, solver->prop()); if(options.get_option("arrays-uf")=="never") - bv_cbmc->unbounded_array=bv_cbmct::U_NONE; + bv_cbmc->unbounded_array=bv_cbmct::unbounded_arrayt::U_NONE; else if(options.get_option("arrays-uf")=="always") - bv_cbmc->unbounded_array=bv_cbmct::U_ALL; + bv_cbmc->unbounded_array=bv_cbmct::unbounded_arrayt::U_ALL; solver->set_prop_conv(bv_cbmc); @@ -275,7 +275,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver) if(filename=="") { - if(solver==smt1_dect::GENERIC) + if(solver==smt1_dect::solvert::GENERIC) { error() << "please use --outfile" << eom; throw 0; @@ -355,7 +355,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) if(filename=="") { - if(solver==smt2_dect::GENERIC) + if(solver==smt2_dect::solvert::GENERIC) { error() << "please use --outfile" << eom; throw 0; diff --git a/src/cbmc/counterexample_beautification.cpp b/src/cbmc/counterexample_beautification.cpp index c0e5d1ba230..a65069618df 100644 --- a/src/cbmc/counterexample_beautification.cpp +++ b/src/cbmc/counterexample_beautification.cpp @@ -40,7 +40,7 @@ void counterexample_beautificationt::get_minimization_list( it!=equation.SSA_steps.end(); it++) { if(it->is_assignment() && - it->assignment_type==symex_targett::STATE) + it->assignment_type==symex_targett::assignment_typet::STATE) { if(!prop_conv.l_get(it->guard_literal).is_false()) { @@ -136,7 +136,7 @@ void counterexample_beautificationt::operator()( it!=equation.SSA_steps.end(); it++) { if(it->is_assignment() && - it->assignment_type!=symex_targett::HIDDEN) + it->assignment_type!=symex_targett::assignment_typet::HIDDEN) { if(!it->guard_literal.is_constant()) guard_count[it->guard_literal]++; diff --git a/src/cbmc/fault_localization.cpp b/src/cbmc/fault_localization.cpp index 9fa6651c1c8..f248428c5be 100644 --- a/src/cbmc/fault_localization.cpp +++ b/src/cbmc/fault_localization.cpp @@ -64,7 +64,7 @@ void fault_localizationt::collect_guards(lpointst &lpoints) it!=bmc.equation.SSA_steps.end(); it++) { if(it->is_assignment() && - it->assignment_type==symex_targett::STATE && + it->assignment_type==symex_targett::assignment_typet::STATE && !it->ignore) { if(!it->guard_literal.is_constant()) @@ -139,7 +139,7 @@ bool fault_localizationt::check(const lpointst &lpoints, bmc.prop_conv.set_assumptions(assumptions); - if(bmc.prop_conv()==decision_proceduret::D_SATISFIABLE) + if(bmc.prop_conv()==decision_proceduret::resultt::D_SATISFIABLE) return false; return true; @@ -362,11 +362,11 @@ safety_checkert::resultt fault_localizationt::stop_on_fail() { switch(run_decision_procedure(bmc.prop_conv)) { - case decision_proceduret::D_UNSATISFIABLE: + case decision_proceduret::resultt::D_UNSATISFIABLE: bmc.report_success(); - return safety_checkert::SAFE; + return safety_checkert::resultt::SAFE; - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: if(options.get_bool_option("trace")) { if(options.get_bool_option("beautify")) @@ -382,12 +382,12 @@ safety_checkert::resultt fault_localizationt::stop_on_fail() report(ID_nil); bmc.report_failure(); - return safety_checkert::UNSAFE; + return safety_checkert::resultt::UNSAFE; default: error() << "decision procedure failed" << eom; - return safety_checkert::ERROR; + return safety_checkert::resultt::ERROR; } } @@ -453,7 +453,7 @@ void fault_localizationt::report( switch(bmc.ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: if(cover_goals.number_covered()>0) { status() << "\n** Most likely fault location:" << eom; @@ -465,9 +465,9 @@ void fault_localizationt::report( } } break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: break; } } diff --git a/src/cbmc/show_vcc.cpp b/src/cbmc/show_vcc.cpp index 46e7603662f..1ae0de6900a 100644 --- a/src/cbmc/show_vcc.cpp +++ b/src/cbmc/show_vcc.cpp @@ -190,15 +190,15 @@ void bmct::show_vcc() switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: error() << "XML UI not supported" << eom; return; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: show_vcc_json(out); break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: show_vcc_plain(out); break; } diff --git a/src/cegis/Makefile b/src/cegis/Makefile deleted file mode 100644 index 00e4f9d20a1..00000000000 --- a/src/cegis/Makefile +++ /dev/null @@ -1,234 +0,0 @@ -SRC = cegis-util/cbmc_runner.cpp \ - cegis-util/constant_width.cpp \ - cegis-util/counterexample_vars.cpp \ - cegis-util/inline_user_program.cpp \ - cegis-util/instruction_iterator.cpp \ - cegis-util/irep_pipe.cpp \ - cegis-util/module_helper.cpp \ - cegis-util/program_helper.cpp \ - cegis-util/string_helper.cpp \ - cegis-util/task_pool.cpp \ - cegis-util/temporary_output_block.cpp \ - cegis-util/type_helper.cpp \ - constant/add_constant.cpp \ - constant/default_cegis_constant_strategy.cpp \ - constant/literals_collector.cpp \ - control/facade/control_runner.cpp \ - control/learn/nondet_solution.cpp \ - control/learn/print_control_solution.cpp \ - control/learn/rational_solution_configuration.cpp \ - control/learn/vector_solution_configuration.cpp \ - control/options/control_program.cpp \ - control/preprocessing/control_preprocessing.cpp \ - control/preprocessing/propagate_controller_sizes.cpp \ - control/simplify/remove_unused_elements.cpp \ - control/value/control_types.cpp \ - control/value/float_helper.cpp \ - control/verify/insert_solution.cpp \ - control/verify/zero_solutions.cpp \ - danger/constraint/danger_constraint_factory.cpp \ - danger/facade/danger_runner.cpp \ - danger/genetic/dynamic_danger_test_runner.cpp \ - danger/meta/meta_variable_names.cpp \ - danger/options/danger_program.cpp \ - danger/options/danger_program_printer.cpp \ - danger/preprocess/add_ranking_and_skolem_variables.cpp \ - danger/preprocess/danger_preprocessing.cpp \ - danger/preprocess/store_nondet_choices.cpp \ - danger/symex/fitness/danger_fitness_config.cpp \ - danger/symex/learn/add_programs_to_learn.cpp \ - danger/symex/learn/add_variable_refs.cpp \ - danger/symex/learn/add_x0_placeholders.cpp \ - danger/symex/learn/danger_learn_config.cpp \ - danger/symex/learn/encoded_danger_learn_config.cpp \ - danger/symex/learn/read_x0.cpp \ - danger/symex/learn/solution_factory.cpp \ - danger/symex/verify/danger_verify_config.cpp \ - danger/symex/verify/insert_candidate.cpp \ - danger/symex/verify/parallel_danger_verifier.cpp \ - danger/symex/verify/parallel_danger_verify_task.cpp \ - danger/symex/verify/restrict_counterexamples.cpp \ - genetic/dynamic_test_runner_helper.cpp \ - genetic/genetic_constant_strategy.cpp \ - genetic/genetic_settings.cpp \ - genetic/instruction_set_info_factory.cpp \ - genetic/program_individual_test_runner_helper.cpp \ - genetic/random_cross.cpp \ - genetic/random_individual.cpp \ - genetic/random_mutate.cpp \ - genetic/serialise_individual.cpp \ - instructions/instruction_set_factory.cpp \ - instrument/cegis_library.cpp \ - instrument/find_cprover_initialize.cpp \ - instrument/instrument_var_ops.cpp \ - instrument/meta_variables.cpp \ - invariant/constant/add_constant.cpp \ - invariant/constant/default_constant_strategy.cpp \ - invariant/constant/literals_constant_strategy.cpp \ - invariant/fitness/concrete_fitness_source_provider.cpp \ - invariant/meta/meta_variable_names.cpp \ - invariant/options/invariant_program.cpp \ - invariant/options/target_copy_helper.cpp \ - invariant/preprocess/add_invariants_and_temp_variables.cpp \ - invariant/preprocess/remove_loops_and_assertion.cpp \ - invariant/symex/learn/add_counterexamples.cpp \ - invariant/symex/learn/add_invariant_programs_to_learn.cpp \ - invariant/symex/learn/instrument_vars.cpp \ - invariant/symex/learn/replace_operators.cpp \ - invariant/symex/verify/extract_counterexample.cpp \ - invariant/symex/verify/insert_constraint.cpp \ - invariant/symex/verify/insert_program.cpp \ - invariant/util/copy_instructions.cpp \ - invariant/util/invariant_constraint_variables.cpp \ - invariant/util/invariant_program_helper.cpp \ - jsa/constraint/jsa_constraint_factory.cpp \ - jsa/converters/counterexample.cpp \ - jsa/converters/replace_operators.cpp \ - jsa/converters/solution.cpp \ - jsa/converters/translate_to_goto_program.cpp \ - jsa/facade/jsa_runner.cpp \ - jsa/genetic/dynamic_jsa_test_runner.cpp \ - jsa/genetic/jsa_genetic_convert.cpp \ - jsa/genetic/jsa_paragon_wrapper.cpp \ - jsa/genetic/jsa_random.cpp \ - jsa/genetic/jsa_serialiser.cpp \ - jsa/genetic/jsa_source_provider.cpp \ - jsa/genetic/random_jsa_cross.cpp \ - jsa/genetic/random_jsa_mutate.cpp \ - jsa/genetic/solution_helper.cpp \ - jsa/instrument/jsa_meta_data.cpp \ - jsa/instrument/temps_helper.cpp \ - jsa/learn/execute_jsa_programs.cpp \ - jsa/learn/extract_candidate.cpp \ - jsa/learn/insert_counterexample.cpp \ - jsa/learn/insert_predicates_and_queries.cpp \ - jsa/learn/instrument_pred_ops.cpp \ - jsa/learn/jsa_symex_learn.cpp \ - jsa/options/jsa_program.cpp \ - jsa/options/jsa_program_info.cpp \ - jsa/preprocessing/add_constraint_meta_variables.cpp \ - jsa/preprocessing/add_synthesis_library.cpp \ - jsa/preprocessing/clone_heap.cpp \ - jsa/preprocessing/collect_variables.cpp \ - jsa/preprocessing/create_temp_variables.cpp \ - jsa/preprocessing/default_jsa_constant_strategy.cpp \ - jsa/preprocessing/jsa_preprocessing.cpp \ - jsa/preprocessing/remove_loop.cpp \ - jsa/value/default_solution.cpp \ - jsa/value/jsa_counterexample_printer.cpp \ - jsa/value/jsa_solution.cpp \ - jsa/value/jsa_solution_printer.cpp \ - jsa/value/jsa_types.cpp \ - jsa/verify/extract_counterexample.cpp \ - jsa/verify/insert_solution.cpp \ - jsa/verify/jsa_symex_verify.cpp \ - jsa/verify/renondet_inputs.cpp \ - learn/constraint_helper.cpp \ - learn/insert_counterexample.cpp \ - refactor/constraint/constraint_factory.cpp \ - refactor/environment/instrument_state_vars.cpp \ - refactor/facade/refactor_runner.cpp \ - refactor/instructionset/cegis_instruction_factory.cpp \ - refactor/instructionset/cegis_processor_body_factory.cpp \ - refactor/instructionset/create_cegis_processor.cpp \ - refactor/instructionset/execute_cegis_program.cpp \ - refactor/instructionset/instruction_description.cpp \ - refactor/instructionset/processor_symbols.cpp \ - refactor/instructionset/processor_types.cpp \ - refactor/learn/instrument_counterexamples.cpp \ - refactor/learn/refactor_candidate_printer.cpp \ - refactor/learn/refactor_symex_learn.cpp \ - refactor/nullobject/nullable_analysis.cpp \ - refactor/nullobject/range_collector.cpp \ - refactor/options/refactor_program.cpp \ - refactor/options/refactoring_type.cpp \ - refactor/preprocessing/collect_counterexamples.cpp \ - refactor/preprocessing/refactor_preprocessing.cpp \ - refactor/verify/refactor_symex_verify.cpp \ - runner/cegis_languages.cpp \ - runner/cegis_main.cpp \ - runner/cegis_parse_options.cpp \ - safety/constraint/safety_constraint_factory.cpp \ - safety/facade/safety_runner.cpp \ - safety/genetic/dynamic_safety_test_runner.cpp \ - safety/meta/meta_variable_names.cpp \ - safety/options/safety_program.cpp \ - safety/options/safety_program_printer.cpp \ - safety/preprocessing/safety_preprocessing.cpp \ - safety/symex/fitness/safety_fitness_config.cpp \ - safety/symex/learn/add_counterexamples.cpp \ - safety/symex/learn/add_variable_refs.cpp \ - safety/symex/learn/encoded_safety_learn_config.cpp \ - safety/symex/learn/safety_learn_config.cpp \ - safety/symex/learn/solution_factory.cpp \ - safety/symex/verify/insert_candidate.cpp \ - safety/symex/verify/safety_verify_config.cpp \ - safety/value/individual_to_safety_solution_deserialiser.cpp \ - safety/value/safety_goto_ce.cpp \ - seed/literals_seed.cpp \ - value/assignments_printer.cpp \ - value/program_individual_serialisation.cpp \ - wordsize/restrict_bv_size.cpp \ - # Empty last line - -OBJ += ../ansi-c/ansi-c$(LIBEXT) \ - ../cpp/cpp$(LIBEXT) \ - ../java_bytecode/java_bytecode$(LIBEXT) \ - ../linking/linking$(LIBEXT) \ - ../big-int/big-int$(LIBEXT) \ - ../goto-programs/goto-programs$(LIBEXT) \ - ../goto-symex/goto-symex$(LIBEXT) \ - ../pointer-analysis/value_set$(OBJEXT) \ - ../pointer-analysis/value_set_analysis_fi$(OBJEXT) \ - ../pointer-analysis/value_set_domain_fi$(OBJEXT) \ - ../pointer-analysis/value_set_fi$(OBJEXT) \ - ../pointer-analysis/value_set_dereference$(OBJEXT) \ - ../pointer-analysis/dereference_callback$(OBJEXT) \ - ../pointer-analysis/add_failed_symbols$(OBJEXT) \ - ../pointer-analysis/rewrite_index$(OBJEXT) \ - ../pointer-analysis/goto_program_dereference$(OBJEXT) \ - ../goto-instrument/full_slicer$(OBJEXT) \ - ../analyses/analyses$(LIBEXT) \ - ../langapi/langapi$(LIBEXT) \ - ../xmllang/xmllang$(LIBEXT) \ - ../assembler/assembler$(LIBEXT) \ - ../solvers/solvers$(LIBEXT) \ - ../util/util$(LIBEXT) \ - ../goto-instrument/dump_c$(OBJEXT) ../goto-instrument/goto_program2code$(OBJEXT) \ - ../goto-instrument/nondet_static$(OBJEXT) ../goto-instrument/cover$(OBJEXT) \ - ../cbmc/cbmc_parse_options$(OBJEXT) ../cbmc/bmc$(OBJEXT) ../cbmc/cbmc_solvers$(OBJEXT) \ - ../cbmc/symex_bmc$(OBJEXT) ../cbmc/xml_interface$(OBJEXT) ../cbmc/bmc_cover$(OBJEXT) \ - ../cbmc/bv_cbmc$(OBJEXT) ../cbmc/counterexample_beautification$(OBJEXT) \ - ../cbmc/show_vcc$(OBJEXT) \ - ../cbmc/cbmc_dimacs$(OBJEXT) ../cbmc/all_properties$(OBJEXT) \ - ../cbmc/fault_localization$(OBJEXT) \ - ../cbmc/symex_coverage$(OBJEXT) \ - ../miniz/miniz$(OBJEXT) \ - ../json/json$(LIBEXT) - -INCLUDES= -I .. - -include ../config.inc -include ../common - -ifeq ($(filter-out Unix MinGW Cygwin OSX OSX_Universal,$(BUILD_ENV_)),) - DLFCN_LINKFLAGS = -ldl -endif - -LIBS = $(DLFCN_LINKFLAGS) - -CLEANFILES = cegis$(EXEEXT) - -CP_CXXFLAGS += -Wno-unused-label - -all: cegis$(EXEEXT) - -ifneq ($(wildcard ../java_bytecode/Makefile),) - OBJ += ../java_bytecode/java_bytecode$(LIBEXT) - CP_CXXFLAGS += -DHAVE_JAVA_BYTECODE -endif - -############################################################################### - -cegis$(EXEEXT): $(OBJ) - $(LINKBIN) diff --git a/src/cegis/cegis-util/cbmc_runner.cpp b/src/cegis/cegis-util/cbmc_runner.cpp deleted file mode 100644 index 10703739484..00000000000 --- a/src/cegis/cegis-util/cbmc_runner.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include - -#define ARGV_MAX_SIZE 5u - -namespace -{ -bool exists(const std::string &name) -{ - return std::ifstream(name).good(); -} - -std::string get_goto_file_name(const size_t index) -{ - std::string name("cbmc_runner-"); - name+=std::to_string(index); - return name+=".exe"; -} - -std::string get_next_goto_file_name() -{ - size_t index=0; - while(exists(get_goto_file_name(index))) - ++index; - return get_goto_file_name(index); -} - -bool is_gcc() -{ - return configt::ansi_ct::flavourt::GCC == config.ansi_c.mode; -} - -int argc() -{ - return is_gcc()?3:2; -} - -const char **argv() -{ - static const char* n_gcc[]={"cbmc", "--stop-on-fail", 0}; - static const char* w_gcc[]={"cbmc", "--stop-on-fail", "--gcc", 0}; - - return is_gcc()?w_gcc:n_gcc; -} - -class cbmc_runnert:public cbmc_parse_optionst -{ - const symbol_tablet &st; - const goto_functionst &gf; - cbmc_resultt &result; - safety_checkert::resultt bmc_result; - const bool keep_goto_programs; - -public: - cbmc_runnert(const symbol_tablet &st, const goto_functionst &gf, - cbmc_resultt &result, const bool keep_goto_programs) : - cbmc_parse_optionst(argc(), argv()), st(st), gf(gf), result(result), bmc_result( - safety_checkert::UNSAFE), keep_goto_programs(keep_goto_programs) - { - } - - virtual ~cbmc_runnert()=default; - - virtual int get_goto_program(const optionst &options, bmct &bmc, - goto_functionst &goto_functions) - { - symbol_table.clear(); - symbol_table=st; - goto_functions.clear(); - goto_functions.copy_from(gf); - if(process_goto_program(options, goto_functions)) return 6; - if(keep_goto_programs) - { - const std::string path(get_next_goto_file_name()); - message_handlert &msg=get_message_handler(); - write_goto_binary(path, symbol_table, goto_functions, msg); - } - - return -1; - } - - int do_bmc(bmct &bmc, const goto_functionst &goto_functions) - { - bmc.set_ui(get_ui()); - result.symbol_table.clear(); - result.symbol_table=symbol_table; - result.goto_functions.clear(); - result.goto_functions.copy_from(goto_functions); - bmc_result=bmc.run(result.goto_functions); - result.trace=bmc.safety_checkert::error_trace; - return 0; - } - - safety_checkert::resultt get_bmc_result() const - { - return bmc_result; - } -}; -} - -safety_checkert::resultt run_cbmc(const symbol_tablet &st, - const goto_functionst &gf, cbmc_resultt &cbmc_result, - const bool keep_goto_programs) -{ - const temporary_output_blockt disable_output; - cbmc_runnert runner(st, gf, cbmc_result, keep_goto_programs); - const int result=runner.main(); - disable_output.release(); - if(EXIT_SUCCESS != result) - throw std::runtime_error("cbmc_runner.cbmc-execution-failed"); - return runner.get_bmc_result(); -} - -safety_checkert::resultt run_cbmc(const symbol_tablet &st, - const goto_functionst &gf, cbmc_resultt &cbmc_result, const optionst &o) -{ - return run_cbmc(st, gf, cbmc_result, - o.get_bool_option(CEGIS_KEEP_GOTO_PROGRAMS)); -} diff --git a/src/cegis/cegis-util/cbmc_runner.h b/src/cegis/cegis-util/cbmc_runner.h deleted file mode 100644 index 364be5ca2a5..00000000000 --- a/src/cegis/cegis-util/cbmc_runner.h +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_CBMC_RUNNER_H -#define CPROVER_CEGIS_CEGIS_UTIL_CBMC_RUNNER_H - -#include - -/** - * @brief CBMC run result class. - * - * @details Result class with all referenced entities in place - * to avoid undefined behaviour when analysing trace results - * which refer to the GOTO program. - */ -class cbmc_resultt -{ -public: - goto_functionst goto_functions; - symbol_tablet symbol_table; - goto_tracet trace; -}; - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param result - * @param keep_goto_programs - * - * @return - */ -safety_checkert::resultt run_cbmc( - const class symbol_tablet &st, - const class goto_functionst &gf, - cbmc_resultt &result, - bool keep_goto_programs); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param result - * @param options - * - * @return - */ -safety_checkert::resultt run_cbmc( - const class symbol_tablet &st, - const class goto_functionst &gf, - cbmc_resultt &result, - const class optionst &options); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_CBMC_RUNNER_H diff --git a/src/cegis/cegis-util/constant_width.cpp b/src/cegis/cegis-util/constant_width.cpp deleted file mode 100644 index 814cc5bea19..00000000000 --- a/src/cegis/cegis-util/constant_width.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include "constant_width.h" - -// TODO: Consider min word width to be size of character. -#define MIN_WORD_WIDTH 2u - -size_t get_min_word_width(const exprt &expr) -{ - assert(ID_constant == expr.id()); - const std::string &value=id2string(to_constant_expr(expr).get_value()); - if(value.empty()) return MIN_WORD_WIDTH; - const bool is_neg_if_signed=value[0] == '1'; - std::string::size_type first_sb=value.find(is_neg_if_signed ? '0' : '1'); - if(std::string::npos == first_sb) return MIN_WORD_WIDTH; - const size_t value_width=value.size() - first_sb + 1; - // TODO: Make more flexible for other word widths - if(value_width > 16u) return value.size(); - if(value_width > 8u) return 16u; - if(value_width > 4u) return 8u; - if(value_width > 2u) return 4u; - return MIN_WORD_WIDTH; -} diff --git a/src/cegis/cegis-util/constant_width.h b/src/cegis/cegis-util/constant_width.h deleted file mode 100644 index 94effe58964..00000000000 --- a/src/cegis/cegis-util/constant_width.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_CONSTANT_WIDTH_H -#define CPROVER_CEGIS_CEGIS_UTIL_CONSTANT_WIDTH_H - -#include - -/** - * @brief - * - * @details - * - * @param expr - * @param full_width - * - * @return - */ -size_t get_min_word_width(const class exprt &expr); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_CONSTANT_WIDTH_H diff --git a/src/cegis/cegis-util/counterexample_vars.cpp b/src/cegis/cegis-util/counterexample_vars.cpp deleted file mode 100644 index 8ab7b0f9a30..00000000000 --- a/src/cegis/cegis-util/counterexample_vars.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -#include -#include -#include - -namespace -{ -size_t collect_counterexample_locations(goto_programt::targetst &locs, - const char * const marker_prefix, goto_programt &prog, - const std::function is_meta, - size_t marker_index) -{ - goto_programt::instructionst &body=prog.instructions; - const goto_programt::targett end(body.end()); - for(goto_programt::targett instr=body.begin(); instr != end; ++instr) - if(is_nondet(instr, end) && !is_meta(instr)) - { - assert(instr->labels.empty()); - instr->labels.push_back(marker_prefix + std::to_string(marker_index++)); - locs.push_back(instr); - } - return marker_index; -} -} - -void collect_counterexample_locations(goto_programt::targetst &locs, - const char * const marker_prefix, goto_programt &prog, - const std::function is_meta) -{ - collect_counterexample_locations(locs, marker_prefix, prog, is_meta, 0); -} - -#define TMP_IF_EXPR_PREFIX "tmp_if_expr$" - -bool default_cegis_meta_criterion(const goto_programt::const_targett pos) -{ - const goto_programt::instructiont &instr=*pos; - const goto_program_instruction_typet type=instr.type; - if(goto_program_instruction_typet::ASSIGN == type - && ID_symbol != to_code_assign(instr.code).rhs().id()) return false; - const std::string &name=id2string(get_affected_variable(instr)); - return contains(name, TMP_IF_EXPR_PREFIX) || contains(name, CPROVER_PREFIX) - || is_return_value_name(name); -} - -void collect_counterexample_locations(goto_programt::targetst &locs, - const char * const marker_prefix, goto_programt &prog) -{ - collect_counterexample_locations(locs, marker_prefix, prog, - default_cegis_meta_criterion); -} - -void collect_counterexample_locations(goto_programt::targetst &locs, - goto_programt &prog) -{ - collect_counterexample_locations(locs, DEFAULT_MARKER_LABEL_PREFIX, prog); -} - -void collect_counterexample_locations(goto_programt::targetst &locs, - goto_programt &prog, - const std::function is_meta) -{ - collect_counterexample_locations(locs, DEFAULT_MARKER_LABEL_PREFIX, prog, - is_meta); -} - -size_t collect_counterexample_locations(goto_programt::targetst &locs, - goto_programt &prog, - const std::function is_meta, - const size_t marker_index_offset) -{ - return collect_counterexample_locations(locs, DEFAULT_MARKER_LABEL_PREFIX, - prog, is_meta, marker_index_offset); -} - -namespace -{ -goto_programt::instructiont::labelst::const_iterator find_ce_label( - const goto_programt::instructiont::labelst &labels) -{ - const goto_programt::instructiont::labelst::const_iterator end=labels.end(); - return std::find_if(labels.begin(), end, - [](const irep_idt &label) - { return std::string::npos != id2string(label).find(DEFAULT_MARKER_LABEL_PREFIX);}); -} -} - -std::map extract_counterexample( - const goto_tracet &trace) -{ - const goto_tracet::stepst &steps=trace.steps; - std::map result; - for(const goto_trace_stept &step : steps) - { - typedef goto_programt::instructiont::labelst labelst; - const labelst &labels=step.pc->labels; - const labelst::const_iterator it=find_ce_label(labels); - if(labels.end() == it) continue; - result[*it].push_back(step.full_lhs_value); - } - return result; -} - -void show_assignments(std::ostream &os, - const std::map &assignments) -{ - for(const std::pair &ass : assignments) - { - os << "" << std::endl; - os << " " << ass.first << "" << std::endl; - os << " " << std::endl; - for(const exprt &value : ass.second) - os << " " << value.pretty() << "" << std::endl; - os << " " << std::endl; - os << "" << std::endl; - } -} - -namespace -{ -bool is_marker(const irep_idt &label) -{ - return std::string::npos != id2string(label).find(DEFAULT_MARKER_LABEL_PREFIX); -} - -typedef goto_programt::instructiont::labelst labelst; -} - -bool has_counterexample_marker(const goto_programt::const_targett pos) -{ - const labelst &l=pos->labels; - return l.end() != std::find_if(l.begin(), l.end(), is_marker); -} - -const irep_idt &get_counterexample_marker( - const goto_programt::const_targett pos) -{ - const labelst &l=pos->labels; - const labelst::const_iterator it=std::find_if(l.begin(), l.end(), is_marker); - assert(l.end() != it); - return *it; -} diff --git a/src/cegis/cegis-util/counterexample_vars.h b/src/cegis/cegis-util/counterexample_vars.h deleted file mode 100644 index 9604c63b346..00000000000 --- a/src/cegis/cegis-util/counterexample_vars.h +++ /dev/null @@ -1,150 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_COUNTEREXAMPLE_VARS_H -#define CPROVER_CEGIS_CEGIS_UTIL_COUNTEREXAMPLE_VARS_H - -#include -#include - -#include - -#include - -#define DEFAULT_MARKER_LABEL_PREFIX CPROVER_PREFIX "_cegis_ce_location_" - -/** - * @brief - * - * @details - * - * @param locs - * @param marker_label_prefix - * @param prog - * @param is_meta - */ -void collect_counterexample_locations( - goto_programt::targetst &locs, - const char * const marker_label_prefix, - goto_programt &prog, - const std::function is_meta); - -/** - * @brief - * - * @details - * - * @param locs - * @param marker_label_prefix - * @param prog - */ -void collect_counterexample_locations( - goto_programt::targetst &locs, - const char * const marker_label_prefix, - goto_programt &prog); - -/** - * @brief - * - * @details - * - * @param locs - * @param prog - */ -void collect_counterexample_locations( - goto_programt::targetst &locs, - goto_programt &prog); - -/** - * @brief - * - * @details - * - * @param locs - * @param prog - * @param is_meta - */ -void collect_counterexample_locations( - goto_programt::targetst &locs, - goto_programt &prog, - const std::function is_meta); - -/** - * @brief - * - * @details - * - * @param locs - * @param prog - * @param is_meta - * @param marker_index_offset - * - * @return - */ -size_t collect_counterexample_locations( - goto_programt::targetst &locs, - goto_programt &prog, - const std::function is_meta, - size_t marker_index_offset); - -/** - * @brief - * - * @details - * - * @param pos - * - * @return - */ -bool default_cegis_meta_criterion(const goto_programt::const_targett pos); - -/** - * @brief - * - * @details - * - * @param trace - * - * @return - */ -labelled_assignmentst extract_counterexample(const class goto_tracet &trace); - -/** - * @brief - * - * @details - * - * @param assignments - */ -void show_assignments(std::ostream &os, - const labelled_assignmentst &assignments); - -/** - * @brief - * - * @details - * - * @param pos - * - * @return - */ -bool has_counterexample_marker(goto_programt::const_targett pos); - -/** - * @brief - * - * @details - * - * @param pos - * - * @return - */ -const irep_idt &get_counterexample_marker(goto_programt::const_targett pos); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_COUNTEREXAMPLE_VARS_H diff --git a/src/cegis/cegis-util/goto_range.h b/src/cegis/cegis-util/goto_range.h deleted file mode 100644 index e34dd50579f..00000000000 --- a/src/cegis/cegis-util/goto_range.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_GOTO_RANGE_H -#define CPROVER_CEGIS_CEGIS_UTIL_GOTO_RANGE_H - -#include - -/** - * @brief - * - * @details - */ -typedef std::pair goto_ranget; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_GOTO_RANGE_H diff --git a/src/cegis/cegis-util/inline_user_program.cpp b/src/cegis/cegis-util/inline_user_program.cpp deleted file mode 100644 index a3d34a56822..00000000000 --- a/src/cegis/cegis-util/inline_user_program.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include - -namespace -{ -bool is_user_function(const irep_idt &name, - const goto_functionst::goto_functiont &func) -{ - if(std::string::npos != id2string(name).find(id2string(CPROVER_PREFIX))) - return false; - if(!func.body_available()) return false; - const goto_programt::instructionst &instrs=func.body.instructions; - if(instrs.empty()) return false; - return !is_builtin(instrs.front().source_location); -} - -void mark_user_function(const irep_idt &name, - goto_functionst::goto_functiont &func) -{ - if(is_user_function(name, func)) func.type.set_inlined(true); -} -} - -void inline_user_program(const symbol_tablet &st, goto_functionst &gf) -{ - for(goto_functionst::function_mapt::value_type &f : gf.function_map) - mark_user_function(f.first, f.second); - - const namespacet ns(st); - null_message_handlert msg; - goto_partial_inline(gf, ns, msg, 0); -} diff --git a/src/cegis/cegis-util/inline_user_program.h b/src/cegis/cegis-util/inline_user_program.h deleted file mode 100644 index 4bcc9a0c2c2..00000000000 --- a/src/cegis/cegis-util/inline_user_program.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_INLINE_USER_PROGRAM_H -#define CPROVER_CEGIS_CEGIS_UTIL_INLINE_USER_PROGRAM_H - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -void inline_user_program( - const class symbol_tablet &st, - class goto_functionst &gf); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_INLINE_USER_PROGRAM_H diff --git a/src/cegis/cegis-util/instruction_iterator.cpp b/src/cegis/cegis-util/instruction_iterator.cpp deleted file mode 100644 index 0244aacad07..00000000000 --- a/src/cegis/cegis-util/instruction_iterator.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -namespace -{ -bool has_body(const goto_functionst::function_mapt::iterator &it, - const goto_functionst::function_mapt::const_iterator &end) -{ - if(end == it) return false; - return it->second.body_available(); -} -} - -instr_iteratort::instr_iteratort() -{ -} - -instr_iteratort::instr_iteratort(goto_functionst &gf) : - func_it(gf.function_map.begin()), func_end(gf.function_map.end()) -{ - while(!has_body(func_it, func_end) && func_end != func_it) - ++func_it; - if(has_body(func_it, func_end)) - prog_it=func_it->second.body.instructions.begin(); -} - -instr_iteratort &instr_iteratort::operator++() -{ - if(func_it->second.body.instructions.end() == prog_it) do - { - ++func_it; - if(func_end == func_it) - { - func_it=goto_functionst::function_mapt::iterator(); - prog_it=goto_programt::targett(); - break; - } else prog_it=func_it->second.body.instructions.begin(); - } while(func_it->second.body.instructions.end() == prog_it); - else ++prog_it; - return *this; -} - -instr_iteratort instr_iteratort::operator++(int) -{ - const instr_iteratort retval=*this; - operator ++(); - return retval; -} - -bool instr_iteratort::operator==(const instr_iteratort &other) const -{ - return func_it == other.func_it && prog_it == other.prog_it; -} - -bool instr_iteratort::operator!=(const instr_iteratort &other) const -{ - return func_it != other.func_it && prog_it != other.prog_it; -} - -instr_iteratort::reference instr_iteratort::operator*() -{ - return *prog_it; -} - -instr_iteratort::pointer instr_iteratort::operator->() -{ - return &*prog_it; -} - -instr_iteratort::operator goto_programt::targett() const -{ - return prog_it; -} - -const instr_iteratort instr_iteratort::end; diff --git a/src/cegis/cegis-util/instruction_iterator.h b/src/cegis/cegis-util/instruction_iterator.h deleted file mode 100644 index 0cbb042e93d..00000000000 --- a/src/cegis/cegis-util/instruction_iterator.h +++ /dev/null @@ -1,116 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_INSTRUCTION_ITERATOR_H -#define CPROVER_CEGIS_CEGIS_UTIL_INSTRUCTION_ITERATOR_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class instr_iteratort: public std::iterator -{ - goto_functionst::function_mapt::iterator func_it; - const goto_functionst::function_mapt::const_iterator func_end; - goto_programt::targett prog_it; - - /** - * @brief - * - * @details - */ - instr_iteratort(); -public: - /** - * @brief - * - * @details - * - * @param gf - */ - explicit instr_iteratort(goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @return - */ - instr_iteratort &operator++(); - - /** - * @brief - * - * @details - * - * @return - */ - instr_iteratort operator++(int); - - /** - * @brief - * - * @details - * - * @return - */ - bool operator==(const instr_iteratort &other) const; - - /** - * @brief - * - * @details - * - * @return - */ - bool operator!=(const instr_iteratort &other) const; - - /** - * @brief - * - * @details - * - * @return - */ - reference operator*(); - - /** - * @brief - * - * @details - * - * @return - */ - pointer operator->(); - - /** - * @brief - * - * @details - * - * @return - */ - operator goto_programt::targett() const; - - /** - * @brief - * - * @details - */ - static const instr_iteratort end; -}; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_INSTRUCTION_ITERATOR_H diff --git a/src/cegis/cegis-util/irep_pipe.cpp b/src/cegis/cegis-util/irep_pipe.cpp deleted file mode 100644 index 1b4f9463aa1..00000000000 --- a/src/cegis/cegis-util/irep_pipe.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#ifndef _WIN32 -#include -#endif - -#include -#include -#include - -namespace -{ -#define IREP_PIPE "irep_pipe" - -void open_pipe(int filedes[2]) -{ -#ifndef _WIN32 - if(pipe(filedes)) - { - perror(IREP_PIPE " open"); - throw std::runtime_error("Error creating pipe."); - } -#endif -} -} - -irep_pipet::irep_pipet() : - read_closed(false), write_closed(false), close_on_destuction(false) -{ - open_pipe(fd); -} - -irep_pipet::irep_pipet(const bool auto_close) : - read_closed(false), write_closed(false), close_on_destuction(auto_close) -{ - open_pipe(fd); -} - -irep_pipet::~irep_pipet() -{ - if(close_on_destuction) close(); -} - -void irep_pipet::close_read() -{ - assert(!read_closed); -#ifndef _WIN32 - ::close(fd[0u]); -#endif - read_closed=true; -} - -bool irep_pipet::is_read_closed() const -{ - return read_closed; -} - -void irep_pipet::close_write() -{ - assert(!write_closed); -#ifndef _WIN32 - ::close(fd[1u]); -#endif - write_closed=true; -} - -bool irep_pipet::is_write_closed() const -{ - return write_closed; -} - -void irep_pipet::close() -{ - if(!read_closed) close_read(); - if(!write_closed) close_write(); -} - -namespace -{ -const char SDU[]="sdu"; -} - -void irep_pipet::send(const irept &sdu) const -{ -#ifndef _WIN32 - assert(!write_closed); - xmlt xml(SDU); - convert(sdu, xml); - std::ostringstream os; - xml.output(os); - const std::string data(os.str()); - const size_t size=data.size() + 1; - const char * offset=data.c_str(); - for(size_t written=0; written < size;) - { - const ssize_t result=write(fd[1u], offset + written, size - written); - if(result == -1) - { - perror(IREP_PIPE " write"); - throw std::runtime_error("Error writing pipe."); - } - written+=result; - offset+=result; - } -#else - assert(!"Pipes currently not supported on Windows."); -#endif -} - -namespace -{ -const size_t READ_BUFFER_SIZE=1024; -} - -void irep_pipet::receive(irept &sdu) const -{ -#ifndef _WIN32 - assert(!read_closed); - std::string data; - char buffer[READ_BUFFER_SIZE]; - do - { - const ssize_t result=read(fd[0u], buffer, sizeof(buffer)); - if(result == -1) - { - perror(IREP_PIPE " read"); - throw std::runtime_error("Error reading pipe."); - } - if(result > 0) data.append(buffer, result); - else break; - } while(true); - data.erase(data.end() - 1); - std::istringstream is(data); - xmlt xml; - null_message_handlert msg; - parse_xml(is, "", msg, xml); - convert(xml, sdu); -#else - assert(!"Pipes currently not supported on Windows."); -#endif -} - -void irep_pipet::auto_close() -{ - close_on_destuction=true; -} diff --git a/src/cegis/cegis-util/irep_pipe.h b/src/cegis/cegis-util/irep_pipe.h deleted file mode 100644 index b5b8ea592cf..00000000000 --- a/src/cegis/cegis-util/irep_pipe.h +++ /dev/null @@ -1,130 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_IREP_PIPE_H -#define CPROVER_CEGIS_CEGIS_UTIL_IREP_PIPE_H - -/** - * @brief Helper for sending irep SDUs through pipes. - * - * @details Wraps the process of creating and closing pipes - * as well as sending irep service data units through it. - * - * XXX: Windows implementation currently pending! - */ -class irep_pipet -{ - int fd[2u]; - bool read_closed; - bool write_closed; - bool close_on_destuction; -public: - /** - * @brief Creates an irep pipe. - * - * @details Creates an irep pipe which doesn't close - * on destruction. - */ - irep_pipet(); - - /** - * @brief Creates an irep pipe. - * - * @details Creates an irep pipe which optionally - * closes on desctruction - * - * @param auto_close true if irep pipe - * should close automaticall, false - * otherwise. - */ - explicit irep_pipet(bool auto_close); - - /** - * @brief Optionally closing destructor. - * - * @details Closes this irep pipe if - * configured accordingly. - */ - ~irep_pipet(); - - /** - * @brief Closes the read end. - * - * @details Closes this irep pipe's - * read end. Afterwards only writing is permitted. - */ - void close_read(); - - /** - * @brief Provides read end status. - * - * @details Indicates whether read end is closed. - * - * @return true if read end is closed, - * false otherwise. - */ - bool is_read_closed() const; - - /** - * @brief Closes the write end. - * - * @details Closes this irep pipe's - * read end. Afterwards only reading is permitted. - */ - void close_write(); - - /** - * @brief Provides read end status. - * - * @details Indicates whether read end is closed. - * - * @return true if read end is closed, - * false otherwise. - */ - bool is_write_closed() const; - - /** - * @brief Closes the pipe entirely. - * - * @details Closes both the write and the read end - * of this pipe. - */ - void close(); - - /** - * @brief Transmits the given irep. - * - * @details Serialises the given irep SDU and transmits - * it to the peer. - * - * @param sdu The irep SDU to transmit. - */ - void send(const class irept &sdu) const; - - /** - * @brief Receives an irep SDU. - * - * @details Deserialises an SDU transmitted through the pipe - * into sdu. - * - * @param sdu The irep to which the deserialised SDU - * should be written. - */ - void receive(irept &sdu) const; - - /** - * @brief Enable auto-closing mode. - * - * @details Indicates that this irep pipe should - * be closed automatically. - */ - void auto_close(); -}; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_IREP_PIPE_H diff --git a/src/cegis/cegis-util/iterator_helper.h b/src/cegis/cegis-util/iterator_helper.h deleted file mode 100644 index bbd7369cd33..00000000000 --- a/src/cegis/cegis-util/iterator_helper.h +++ /dev/null @@ -1,50 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_ITERATOR_HELPER_H -#define CPROVER_CEGIS_CEGIS_UTIL_ITERATOR_HELPER_H - -/** - * @brief - * - * @details - * - * @tparam containert - * @param old_container - * @param new_container - * @param it - * @return - */ -template -typename containert::iterator copy_iterator( - const containert &old_container, - containert &new_container, - typename containert::const_iterator it); - -/** - * @brief - * - * @details - * - * @tparam containert - * @tparam iterator_containert - * @param old_container - * @param new_container - * @param iterators - * @return - */ -template -iterator_containert copy_iterators( - const containert &old_container, - containert &new_container, - const iterator_containert &iterators); - -#include "iterator_helper.inc" - -#endif // CPROVER_CEGIS_CEGIS_UTIL_ITERATOR_HELPER_H diff --git a/src/cegis/cegis-util/iterator_helper.inc b/src/cegis/cegis-util/iterator_helper.inc deleted file mode 100644 index b724ec02939..00000000000 --- a/src/cegis/cegis-util/iterator_helper.inc +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -template -typename containert::iterator copy_iterator(const containert &old_container, - containert &new_container, typename containert::const_iterator it) -{ - const typename containert::iterator empty; - if (empty == it) return empty; - const size_t old_distance=std::distance(old_container.begin(), it); - typename containert::iterator new_it=new_container.begin(); - std::advance(new_it, old_distance); - return new_it; -} - -template -iterator_containert copy_iterators(const containert &old_container, - containert &new_container, const iterator_containert &iterators) -{ - iterator_containert new_iterators; - std::transform(iterators.begin(), iterators.end(), - std::back_inserter(new_iterators), - [&old_container, &new_container](const typename containert::const_iterator it) - { return copy_iterator(old_container, new_container, it);}); - return new_iterators; -} diff --git a/src/cegis/cegis-util/labelled_assignments.h b/src/cegis/cegis-util/labelled_assignments.h deleted file mode 100644 index 1784731b4f0..00000000000 --- a/src/cegis/cegis-util/labelled_assignments.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_LABELLED_ASSIGNMENTS_H -#define CPROVER_CEGIS_CEGIS_UTIL_LABELLED_ASSIGNMENTS_H - -#include - -#include - -/** - * @brief - * - * @details - */ -typedef std::map labelled_assignmentst; - -/** - * @brief - * - * @details - */ -typedef std::deque labelled_counterexamplest; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_LABELLED_ASSIGNMENTS_H diff --git a/src/cegis/cegis-util/module_helper.cpp b/src/cegis/cegis-util/module_helper.cpp deleted file mode 100644 index ced2432085e..00000000000 --- a/src/cegis/cegis-util/module_helper.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifdef _WIN32 -#include -#else -#include -#include -#include -#endif -#include - -std::string get_current_executable_file_path() -{ -#ifdef _WIN32 - char buffer[MAX_PATH]; - GetModuleFileName(NULL, buffer, MAX_PATH); - return std::string(buffer); -#else - char buffer[PATH_MAX]; - const ssize_t len=::readlink("/proc/self/exe", buffer, sizeof(buffer) - 1); - if(len == -1) throw std::runtime_error("module helper: readlink failed"); - buffer[len]='\0'; - return std::string(buffer); -#endif -} diff --git a/src/cegis/cegis-util/module_helper.h b/src/cegis/cegis-util/module_helper.h deleted file mode 100644 index 6c7413c78b0..00000000000 --- a/src/cegis/cegis-util/module_helper.h +++ /dev/null @@ -1,24 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_MODULE_HELPER_H -#define CPROVER_CEGIS_CEGIS_UTIL_MODULE_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @return - */ -std::string get_current_executable_file_path(); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_MODULE_HELPER_H diff --git a/src/cegis/cegis-util/program_helper.cpp b/src/cegis/cegis-util/program_helper.cpp deleted file mode 100644 index 88520f879f6..00000000000 --- a/src/cegis/cegis-util/program_helper.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -goto_programt &get_entry_body(goto_functionst &gf) -{ - return get_body(gf, id2string(goto_functionst::entry_point())); -} - -const goto_programt &get_entry_body(const goto_functionst &gf) -{ - return get_body(gf, id2string(goto_functionst::entry_point())); -} - -goto_programt &get_body(goto_functionst &gf, const std::string &func_name) -{ - const irep_idt id(func_name); - goto_functionst::function_mapt &function_map=gf.function_map; - const goto_functionst::function_mapt::iterator it=function_map.find(id); - assert(function_map.end() != it && "Danger program function missing."); - goto_function_templatet &f=it->second; - assert(f.body_available() && "Danger program function body missing."); - return f.body; -} - -goto_programt &get_body(goto_functionst &gf, - const goto_programt::const_targett pos) -{ - return get_body(gf, id2string(pos->function)); -} - -const goto_programt &get_body(const goto_functionst &gf, - const std::string &func_name) -{ - const irep_idt id(func_name); - const goto_functionst::function_mapt &function_map=gf.function_map; - const goto_functionst::function_mapt::const_iterator it=function_map.find(id); - assert(function_map.end() != it && "Danger program function missing."); - const goto_function_templatet &f=it->second; - assert(f.body_available() && "Danger program function body missing."); - return f.body; -} - -namespace -{ -class id_searcht: public const_expr_visitort -{ - const irep_idt &id; - bool found; -public: - explicit id_searcht(const irep_idt &id) : - id(id), found(false) - { - } - - virtual ~id_searcht() - { - } - - virtual void operator()(const exprt &expr) - { - if(ID_symbol != expr.id() || found) return; - if(id == to_symbol_expr(expr).get_identifier()) found=true; - } - - bool is_found() - { - return found; - } -}; - -bool contains(const exprt &rhs, const irep_idt &id) -{ - id_searcht search(id); - rhs.visit(search); - return search.is_found(); -} -} - -bool is_nondet(goto_programt::const_targett target, - goto_programt::const_targett end) -{ - const goto_programt::instructiont &instr=*target; - switch(instr.type) - { - case goto_program_instruction_typet::DECL: - { - goto_programt::const_targett next=std::next(target); - if(next == end) return true; - if(goto_program_instruction_typet::FUNCTION_CALL == next->type) - { - if(to_code_function_call(next->code).lhs().is_not_nil()) return false; - else ++next; - } - const goto_programt::instructiont next_instr=*next; - if(goto_program_instruction_typet::ASSIGN != next_instr.type) return true; - const irep_idt id(get_affected_variable(instr)); - if(id != get_affected_variable(next_instr)) return true; - return contains(to_code_assign(next_instr.code).rhs(), id); - } - case goto_program_instruction_typet::ASSIGN: - { - const exprt &rhs=to_code_assign(instr.code).rhs(); - if(ID_side_effect != rhs.id()) return false; - return ID_nondet == to_side_effect_expr(rhs).get_statement(); - } - case goto_program_instruction_typet::FUNCTION_CALL: - { - const code_function_callt &call=to_code_function_call(instr.code); - if(call.lhs().is_not_nil()) return false; - } - default: - return false; - } -} - -bool is_return_value_name(const std::string &name) -{ - return contains(name, "return_value___") - || contains(name, RETURN_VALUE_SUFFIX); -} - -const typet &get_affected_type(const goto_programt::instructiont &instr) -{ - switch(instr.type) - { - case goto_program_instruction_typet::DECL: - return to_code_decl(instr.code).symbol().type(); - case goto_program_instruction_typet::ASSIGN: - return to_code_assign(instr.code).lhs().type(); - case goto_program_instruction_typet::DEAD: - return to_code_dead(instr.code).symbol().type(); - default: - assert(!"Only DECL, ASSIGN, DEAD allowed."); - } -} - -const irep_idt &get_affected_variable(const goto_programt::instructiont &instr) -{ - switch(instr.type) - { - case goto_program_instruction_typet::DECL: - return to_code_decl(instr.code).get_identifier(); - case goto_program_instruction_typet::ASSIGN: - return to_symbol_expr(to_code_assign(instr.code).lhs()).get_identifier(); - case goto_program_instruction_typet::DEAD: - return to_code_dead(instr.code).get_identifier(); - default: - assert(!"Only DECL, ASSIGN, DEAD allowed."); - } -} - -goto_programt::targetst find_nondet_instructions(goto_programt &body) -{ - goto_programt::targetst result; - goto_programt::instructionst &instrs=body.instructions; - const goto_programt::targett end(instrs.end()); - for(goto_programt::targett it=instrs.begin(); it != end; ++it) - if(is_nondet(it, end)) result.push_back(it); - return result; -} - -namespace -{ -const char NS_SEP[]="::"; -} -bool is_global_const(const irep_idt &name, const typet &type) -{ - if(!type.get_bool(ID_C_constant)) return false; - const std::string &n=id2string(name); - if(std::string::npos != n.find(CEGIS_CONSTANT_PREFIX)) return true; - return std::string::npos == n.find(NS_SEP); -} - -void move_labels(goto_programt::instructionst &body, - const goto_programt::targett &from, const goto_programt::targett &to) -{ - for(goto_programt::instructiont &instr : body) - for(goto_programt::targett &target : instr.targets) - if(from == target) target=to; -} - -void move_labels(goto_programt &body, const goto_programt::targett &from, - const goto_programt::targett &to) -{ - move_labels(body.instructions, from, to); -} - -goto_programt::targett insert_before_preserve_labels(goto_programt &body, - const goto_programt::targett &target) -{ - const goto_programt::targett result=body.insert_before(target); - move_labels(body, target, result); - return result; -} - -bool is_builtin(const source_locationt &loc) -{ - if(loc.is_nil()) return true; - const std::string &file=id2string(loc.get_file()); - return file.empty() || file.at(0) == '<'; -} - -symbolt &create_local_cegis_symbol(symbol_tablet &st, - const std::string &full_name, const std::string &base_name, - const typet &type) -{ - symbolt new_symbol; - new_symbol.name=full_name; - new_symbol.type=type; - new_symbol.base_name=base_name; - new_symbol.pretty_name=base_name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - new_symbol.is_thread_local=true; - new_symbol.is_static_lifetime=false; - new_symbol.is_file_local=true; - new_symbol.is_lvalue=true; - assert(!st.add(new_symbol)); - return st.lookup(new_symbol.name); -} - -symbolt &create_cegis_symbol(symbol_tablet &st, const std::string &full_name, - const typet &type) -{ - return create_local_cegis_symbol(st, full_name, full_name, type); -} - -void cegis_assign(const symbol_tablet &st, goto_programt::instructiont &instr, - const exprt &lhs, const exprt &rhs, const source_locationt &loc) -{ - instr.type=goto_program_instruction_typet::ASSIGN; - instr.source_location=loc; - const namespacet ns(st); - const typet &type=lhs.type(); - if(type_eq(type, rhs.type(), ns)) instr.code=code_assignt(lhs, rhs); - else instr.code=code_assignt(lhs, typecast_exprt(rhs, type)); -} - -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs, const source_locationt &loc) -{ - const goto_programt::targett assign=body.insert_after(insert_after_pos); - cegis_assign(st, *assign, lhs, rhs, loc); - return assign; -} - -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs, const source_locationt &loc) -{ - goto_programt &body=get_entry_body(gf); - return cegis_assign(st, body, insert_after_pos, lhs, rhs, loc); -} - -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs) -{ - return cegis_assign(st, gf, insert_after_pos, lhs, rhs, - default_cegis_source_location()); -} - -goto_programt::targett cegis_assign_user_variable(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const irep_idt &name, const exprt &value) -{ - const symbol_exprt lhs(st.lookup(name).symbol_expr()); - return cegis_assign(st, gf, insert_after_pos, lhs, value); -} - -goto_programt::targett cegis_assign_local_variable(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &insert_after_pos, - const std::string &func_name, const std::string &var_name, - const exprt &value) -{ - std::string name(func_name); - name+=NS_SEP; - name+=var_name; - const symbol_exprt lhs(st.lookup(name).symbol_expr()); - const source_locationt loc(default_cegis_source_location()); - return cegis_assign(st, body, insert_after_pos, lhs, value, loc); -} - -symbol_exprt get_ret_val_var(const irep_idt &func_id, const typet &type) -{ - return symbol_exprt(id2string(func_id) + RETURN_VALUE_SUFFIX, type); -} - -void remove_return(goto_programt &body, const goto_programt::targett pos) -{ - code_function_callt &call=to_code_function_call(pos->code); - const irep_idt &id=to_symbol_expr(call.function()).get_identifier(); - const typet &type=call.lhs().type(); - const source_locationt &loc=pos->source_location; - const irep_idt &func=pos->function; - const goto_programt::targett assign=body.insert_after(pos); - assign->make_assignment(); - assign->source_location=loc; - assign->code=code_assignt(call.lhs(), get_ret_val_var(id, type)); - assign->function=func; - call.lhs().make_nil(); -} - -goto_programt::targett add_return_assignment(goto_programt &body, - goto_programt::targett pos, const irep_idt &func_id, const exprt &value) -{ - const source_locationt &loc=pos->source_location; - pos=body.insert_after(pos); - pos->make_assignment(); - pos->source_location=loc; - pos->code=code_assignt(get_ret_val_var(func_id, value.type()), value); - return pos; -} - -namespace -{ -goto_programt::targett insert_preserving_source_location( - goto_programt::targett pos, - const std::function &inserter) -{ - const source_locationt &loc=pos->source_location; - const irep_idt &func_name=pos->function; - pos=inserter(pos); - pos->source_location=loc; - pos->function=func_name; - return pos; -} -} - -goto_programt::targett insert_after_preserving_source_location( - goto_programt &body, goto_programt::targett pos) -{ - const auto op=std::bind1st(std::mem_fun(&goto_programt::insert_after), &body); - return insert_preserving_source_location(pos, op); -} - -goto_programt::targett insert_before_preserving_source_location( - goto_programt &body, goto_programt::targett pos) -{ - typedef goto_programt::targett (goto_programt::*ftype)( - goto_programt::targett); - const auto op=std::bind1st( - std::mem_fun(static_cast(&goto_programt::insert_before)), &body); - return insert_preserving_source_location(pos, op); -} - -void assign_in_cprover_init(goto_functionst &gf, symbolt &symbol, - const exprt &value) -{ - symbol.value=value; - goto_programt &body=get_body(gf, CPROVER_INIT); - goto_programt::instructionst &instrs=body.instructions; - const auto p(std::mem_fun_ref(&goto_programt::instructiont::is_end_function)); - goto_programt::targett pos=std::find_if(instrs.begin(), instrs.end(), p); - assert(instrs.end() != pos); - pos=insert_before_preserving_source_location(body, pos); - pos->type=goto_program_instruction_typet::ASSIGN; - const symbol_exprt lhs(symbol.symbol_expr()); - pos->code=code_assignt(lhs, value); -} diff --git a/src/cegis/cegis-util/program_helper.h b/src/cegis/cegis-util/program_helper.h deleted file mode 100644 index b2476d228a6..00000000000 --- a/src/cegis/cegis-util/program_helper.h +++ /dev/null @@ -1,405 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_PROGRAM_HELPER_H -#define CPROVER_CEGIS_CEGIS_UTIL_PROGRAM_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param gf - * - * @return - */ -class goto_programt &get_entry_body(class goto_functionst &gf); - -/** - * @brief - * - * @details - * - * @param gf - * - * @return - */ -const goto_programt &get_entry_body(const goto_functionst &gf); - -/** - * @brief - * - * @details - * - * @param gf - * @param func_name - * - * @return - */ -goto_programt &get_body( - goto_functionst &gf, - const std::string &func_name); - -/** - * @brief - * - * @details - * - * @param gf - * @param pos - * - * @return - */ -goto_programt &get_body( - goto_functionst &gf, - goto_programt::const_targett pos); - -/** - * @brief - * - * @details - * - * @param gf - * @param func_name - * - * @return - */ -const goto_programt &get_body( - const goto_functionst &gf, - const std::string &func_name); - -/** - * @brief - * - * @details - * - * @param target - * @param end - * - * @return - */ -bool is_nondet( - goto_programt::const_targett target, - goto_programt::const_targett end); - -/** - * @brief - * - * @details - * - * @param name - * - * @return - */ -bool is_return_value_name(const std::string &name); - -/** - * @brief - * - * @details - * - * @param body - * @return - */ -goto_programt::targetst find_nondet_instructions(goto_programt &body); - -/** - * @brief - * - * @details - * - * @param instr - * - * @return - */ -const typet &get_affected_type(const goto_programt::instructiont &instr); - -/** - * @brief - * - * @details - * - * @param instr - * - * @return - */ -const irep_idt &get_affected_variable(const goto_programt::instructiont &instr); - -/** - * @brief - * - * @details - * - * @param name - * @param type - * - * @return - */ -bool is_global_const(const irep_idt &name, const typet &type); - -/** - * @brief - * - * @details - * - * @param body - * @param from - * @param to - */ -void move_labels( - goto_programt::instructionst &body, - const goto_programt::targett &from, - const goto_programt::targett &to); - -/** - * @brief - * - * @details - * - * @param body - * @param from - * @param to - */ -void move_labels( - goto_programt &body, - const goto_programt::targett &from, - const goto_programt::targett &to); - -/** - * @brief - * - * @details - * - * @param body - * @param target - * - * @return - */ -goto_programt::targett insert_before_preserve_labels( - goto_programt &body, - const goto_programt::targett &target); - -/** - * @brief - * - * @details - * - * @param loc - * - * @return - */ -bool is_builtin(const source_locationt &loc); - -/** - * @brief - * - * @details - * - * @param st - * @param full_name - * @param base_name - * @param type - * - * @return - */ -symbolt &create_local_cegis_symbol(symbol_tablet &st, const std::string &full_name, - const std::string &base_name, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param full_name - * @param type - * - * @return - */ -symbolt &create_cegis_symbol(symbol_tablet &st, const std::string &full_name, - const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param insert_after_pos - * @param lhs - * @param rhs - * - * @return - */ -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs); - -/** - * @brief - * - * @details - * - * @param st - * @param instr - * @param lhs - * @param rhs - * @param loc - */ -void cegis_assign(const symbol_tablet &st, goto_programt::instructiont &instr, - const exprt &lhs, const exprt &rhs, const source_locationt &loc); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param insert_after_pos - * @param lhs - * @param rhs - * @param loc - * - * @return - */ -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs, const source_locationt &loc); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param insert_after_pos - * @param lhs - * @param rhs - * @param loc - * - * @return - */ -goto_programt::targett cegis_assign(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const exprt &lhs, const exprt &rhs, const source_locationt &loc); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param insert_after_pos - * @param base_name - * @param value - * - * @return - */ -goto_programt::targett cegis_assign_user_variable(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const irep_idt &name, const exprt &value); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param insert_after_pos - * @param func_name - * @param var_name - * @param value - * - * @return - */ -goto_programt::targett cegis_assign_local_variable(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &insert_after_pos, - const std::string &func_name, const std::string &var_name, - const exprt &value); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - */ -void remove_return( - goto_programt &body, - goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param func_id - * @param value - * - * @return - */ -goto_programt::targett add_return_assignment( - goto_programt &body, - goto_programt::targett pos, - const irep_idt &func_id, - const exprt &value); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * - * @return - */ -goto_programt::targett insert_after_preserving_source_location( - goto_programt &body, - goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * - * @return - */ -goto_programt::targett insert_before_preserving_source_location( - goto_programt &body, - goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param gf - * @param symbol - * @param value - */ -void assign_in_cprover_init( - goto_functionst &gf, - symbolt &symbol, - const exprt &value); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_PROGRAM_HELPER_H diff --git a/src/cegis/cegis-util/string_helper.cpp b/src/cegis/cegis-util/string_helper.cpp deleted file mode 100644 index 10055438139..00000000000 --- a/src/cegis/cegis-util/string_helper.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -bool contains(const std::string &haystack, const std::string &needle) -{ - return std::string::npos != haystack.find(needle); -} - -bool starts_with(const std::string &haystack, const std::string &prefix) -{ - return haystack.substr(0, prefix.size()) == prefix; -} - -bool ends_with(const std::string &haystack, const std::string &suffix) -{ - const std::string::size_type haystack_sz=haystack.size(); - const std::string::size_type suffix_sz=suffix.size(); - if(haystack_sz < suffix_sz) return false; - return haystack.substr(haystack_sz - suffix_sz) == suffix; -} - -void remove_suffix(std::string &haystack, const std::string &suffix) -{ - assert(ends_with(haystack, suffix)); - const size_t new_size=haystack.size() - suffix.size(); - haystack=haystack.substr(0, new_size); -} diff --git a/src/cegis/cegis-util/string_helper.h b/src/cegis/cegis-util/string_helper.h deleted file mode 100644 index 3aedc93f68b..00000000000 --- a/src/cegis/cegis-util/string_helper.h +++ /dev/null @@ -1,61 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_STRING_HELPER_H -#define CPROVER_CEGIS_CEGIS_UTIL_STRING_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param haystack - * @param needle - * - * @return - */ -bool contains(const std::string &haystack, const std::string &needle); - -/** - * @brief - * - * @details - * - * @param haystack - * @param prefix - * - * @return - */ -bool starts_with(const std::string &haystack, const std::string &prefix); - -/** - * @brief - * - * @details - * - * @param haystack - * @param suffix - * - * @return - */ -bool ends_with(const std::string &haystack, const std::string &suffix); - -/** - * @brief - * - * @details - * - * @param haystack - * @param suffix - */ -void remove_suffix(std::string &haystack, const std::string &suffix); - -#endif // CPROVER_CEGIS_CEGIS_UTIL_STRING_HELPER_H diff --git a/src/cegis/cegis-util/task_pool.cpp b/src/cegis/cegis-util/task_pool.cpp deleted file mode 100644 index d667a704c97..00000000000 --- a/src/cegis/cegis-util/task_pool.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef _WIN32 -#include -#include -#include -#endif - -#include -#include -#include -#include - -#include - -#include - -task_poolt::task_poolt() -{ -} - -task_poolt::~task_poolt() -{ -} - -#ifdef _WIN32 -#define NOT_SUPPORTED() assert(!"task_poolt not supported on Windows.") -#endif - -namespace -{ -#ifndef _WIN32 -void execute_and_remove(task_poolt::handlerst &handlers, const pid_t pid, - const int status) -{ - const task_poolt::handlerst::iterator it=handlers.find(pid); - if(handlers.end() != it) - { - it->second(status); - handlers.erase(it); - } -} -#endif - -void cleanup(task_poolt::task_idst &task_ids, task_poolt::handlerst &handlers) -{ -#ifndef _WIN32 - std::map joined; - int status; - for(pid_t child_pid=waitpid(-1, &status, WNOHANG); child_pid > 0; child_pid= - waitpid(-1, &status, WNOHANG)) - joined.insert(std::make_pair(child_pid, status)); - for(const std::pair &task : joined) - { - const task_poolt::task_idt id=task.first; - execute_and_remove(handlers, id, task.second); - task_ids.erase(id); - } -#else - NOT_SUPPORTED(); -#endif -} - -#ifndef _WIN32 -bool erase_if_managed(task_poolt::task_idst &ids, const task_poolt::task_idt id) -{ - const task_poolt::task_idst::iterator task_id=ids.find(id); - if(ids.end() == task_id) return false; - ids.erase(task_id); - return true; -} -#endif -} - -#define FORK_ERROR "Fork system call failed." - -task_poolt::task_idt task_poolt::schedule(const taskt &task) -{ - cleanup(task_ids, handlers); -#ifndef _WIN32 - const pid_t child_pid=fork(); - if(child_pid == -1) - { - perror(FORK_ERROR); - throw std::runtime_error(FORK_ERROR); - } - if(child_pid) - { - task_ids.insert(child_pid); - return child_pid; - } - setpgid(child_pid, 0); - try - { - exit(task()); - } catch (...) - { - exit(EXIT_FAILURE); - } -#else - NOT_SUPPORTED(); - return 0; -#endif -} - -task_poolt::task_idt task_poolt::schedule(const taskt &task, - const on_completet &on_complete) -{ - cleanup(task_ids, handlers); - const task_poolt::task_idt id=schedule(task); - handlers.insert(std::make_pair(id, on_complete)); - return id; -} - -#define MAX_WAIT 5u - -void task_poolt::cancel(const task_idt id) -{ -#ifndef _WIN32 - if(!erase_if_managed(task_ids, id)) return; - int status; - size_t wait_count=0; - do - { - kill(id, SIGTERM); - usleep(20000); - } while(!waitpid(id, &status, WNOHANG) && ++wait_count < MAX_WAIT); - if(wait_count >= MAX_WAIT) - { - kill(id, SIGKILL); - waitpid(id, &status, 0); - } - execute_and_remove(handlers, id, status); -#else - NOT_SUPPORTED(); -#endif -} - -void task_poolt::join(const task_idt id) -{ -#ifndef _WIN32 - if(!erase_if_managed(task_ids, id)) return; - int status; - waitpid(id, &status, 0); - execute_and_remove(handlers, id, status); -#else - NOT_SUPPORTED(); -#endif -} - -void task_poolt::join_all() -{ -#ifndef _WIN32 - const size_t num_children=task_ids.size(); - int status; - for(size_t i=0; i < num_children; ++i) - { - const pid_t pid=waitpid(-1, &status, 0); - assert(pid > 0); - execute_and_remove(handlers, pid, status); - } - task_ids.clear(); - assert(handlers.empty()); -#else - NOT_SUPPORTED(); -#endif -} - -void task_poolt::join_some() -{ -#ifndef _WIN32 - cleanup(task_ids, handlers); -#else - NOT_SUPPORTED(); -#endif -} diff --git a/src/cegis/cegis-util/task_pool.h b/src/cegis/cegis-util/task_pool.h deleted file mode 100644 index d7c0dafc168..00000000000 --- a/src/cegis/cegis-util/task_pool.h +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_TASK_POOL_H -#define CPROVER_CEGIS_CEGIS_UTIL_TASK_POOL_H - -#ifndef _WIN32 -#include -#endif -#include -#include -#include - -/** - * @brief Task pool implementation. - * - * @details Uses fork() on Linux. - * XXX: Not supported on Windows. - */ -class task_poolt -{ -public: -#ifndef _WIN32 - typedef pid_t task_idt; -#else - typedef size_t task_idt; -#endif - typedef std::set task_idst; - typedef std::function taskt; - typedef std::function on_completet; - typedef std::map handlerst; -private: - task_idst task_ids; - handlerst handlers; -public: - /** - * @brief Creates a task pool - * - * @details Creates an empty task pool - */ - task_poolt(); - - /** - * @brief Default destructor. - * - * @details Closes all remaining pipes. - */ - ~task_poolt(); - - /** - * @brief Schedules a task. - * - * @details Schedules a task without pipe. - * - * @param task The task to run. - */ - task_idt schedule(const taskt &task); - - /** - * @brief - * - * @details - * - * @param task - * @param on_complete - * - * @return - */ - task_idt schedule(const taskt &task, const on_completet &on_complete); - - /** - * @brief - * - * @details - * - * @param id - */ - void cancel(task_idt id); - - /** - * @brief Joins a task. - * - * @details Waits for the given task to complete. - * - * @param id The task to wait for. - */ - void join(task_idt id); - - /** - * @brief Joins all tasks. - * - * @details Waits for all scheduled tasks to complete. - */ - void join_all(); - - /** - * @brief Joins already terminated tasks. - * - * @details Joins termianted tasks and executes their handlers, but - * doesn't block. - */ - void join_some(); -}; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_TASK_POOL_H diff --git a/src/cegis/cegis-util/temporary_output_block.cpp b/src/cegis/cegis-util/temporary_output_block.cpp deleted file mode 100644 index d15641c6ca1..00000000000 --- a/src/cegis/cegis-util/temporary_output_block.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -temporary_output_blockt::temporary_output_blockt() -{ - std::cout.setstate(std::ios_base::failbit); -} - -temporary_output_blockt::~temporary_output_blockt() -{ - release(); -} - -void temporary_output_blockt::release() const -{ - std::cout.clear(); -} diff --git a/src/cegis/cegis-util/temporary_output_block.h b/src/cegis/cegis-util/temporary_output_block.h deleted file mode 100644 index 719cb0d1af1..00000000000 --- a/src/cegis/cegis-util/temporary_output_block.h +++ /dev/null @@ -1,43 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_TEMPORARY_OUTPUT_BLOCK_H -#define CPROVER_CEGIS_CEGIS_UTIL_TEMPORARY_OUTPUT_BLOCK_H - -/** - * @brief - * - * @details - */ -class temporary_output_blockt -{ -public: - /** - * @brief - * - * @details - */ - temporary_output_blockt(); - - /** - * @brief - * - * @details - */ - ~temporary_output_blockt(); - - /** - * @brief - * - * @details - */ - void release() const; -}; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_TEMPORARY_OUTPUT_BLOCK_H diff --git a/src/cegis/cegis-util/type_helper.cpp b/src/cegis/cegis-util/type_helper.cpp deleted file mode 100644 index a4ea0e84cf1..00000000000 --- a/src/cegis/cegis-util/type_helper.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -#include - -const typet &replace_struct_by_symbol_type( - const symbol_tablet &st, - const typet &type) -{ - const irep_idt &type_id=type.id(); - if(type_id!=ID_struct && type_id!=ID_incomplete_struct && - type_id!=ID_union && type_id!=ID_incomplete_union) - { - return type; - } - std::string tag(TAG_PREFIX); - tag+=id2string(to_struct_union_type(type).get_tag()); - return st.lookup(tag).type; -} - -namespace -{ -bool instanceof(const typet &lhs, const typet &rhs, const namespacet &ns) -{ - if(type_eq(lhs, rhs, ns)) - { - return true; - } - assert(ID_class==lhs.id()); - const class_typet &lhs_class=to_class_type(lhs); - const class_typet::basest &bases=lhs_class.bases(); - return std::any_of( - std::begin(bases), - std::end(bases), - [&](const exprt &base) - { - return instanceof(ns.follow(base.type()), rhs, ns); - }); -} -} - -bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs) -{ - const namespacet ns(st); - const typet &resolved_lhs=ns.follow(lhs); - const typet &resolved_rhs=ns.follow(rhs); - if(ID_class!=resolved_lhs.id() || ID_class!=resolved_rhs.id()) - { - return type_eq(resolved_lhs, resolved_rhs, ns); - } - return instanceof(resolved_lhs, resolved_rhs, ns); -} - -instanceof_anyt::instanceof_anyt( - const symbol_tablet &st, - const std::set &types): - st(st), - types(types) -{ -} - -bool instanceof_anyt::operator()(const typet &type) const -{ - if(types.empty()) - { - return true; - } - return types.end()!=std::find_if( - types.begin(), - types.end(), - [this, &type](const typet &rhs) - { - return instanceof(st, type, rhs); - }); -} diff --git a/src/cegis/cegis-util/type_helper.h b/src/cegis/cegis-util/type_helper.h deleted file mode 100644 index f8898d6344a..00000000000 --- a/src/cegis/cegis-util/type_helper.h +++ /dev/null @@ -1,77 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CEGIS_UTIL_TYPE_HELPER_H -#define CPROVER_CEGIS_CEGIS_UTIL_TYPE_HELPER_H - -#include - -/** - * @brief - * - * @details - */ -#define TAG_PREFIX "tag-" - -/** - * @brief - * - * @details - * - * @param st - * @param type - */ -const class typet &replace_struct_by_symbol_type( - const class symbol_tablet &st, - const typet &type); - -/** - * @brief - * - * @details - * - * @param lhs - * @param rhs - * @param st - */ -bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs); - -/** - * @brief - * - * @details - */ -class instanceof_anyt -{ - const symbol_tablet &st; - const std::set &types; -public: - /** - * @brief - * - * @details - * - * @param st - * @param types - */ - instanceof_anyt(const symbol_tablet &st, const std::set &types); - - /** - * @brief - * - * @details - * - * @param type - * - * @return - */ - bool operator()(const typet &type) const; -}; - -#endif // CPROVER_CEGIS_CEGIS_UTIL_TYPE_HELPER_H diff --git a/src/cegis/constant/add_constant.cpp b/src/cegis/constant/add_constant.cpp deleted file mode 100644 index 74098c4fa1e..00000000000 --- a/src/cegis/constant/add_constant.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include - -namespace -{ -const char NS_SEP[]="::"; -bool is_meta_or_not_global(const symbolt &symbol) -{ - if(ID_code == symbol.type.id()) return true; - const std::string &name=id2string(symbol.name); - if(std::string::npos != name.find("#return_value")) return true; - if(std::string::npos != name.find(CPROVER_PREFIX)) return true; - return std::string::npos != name.find(NS_SEP); -} - -bool contains_constant(const symbol_tablet &st, const exprt &value) -{ - typedef symbol_tablet::symbolst symbolst; - exprt lhs=value; - lhs.add_source_location()=source_locationt(); - const symbolst &s=st.symbols; - for(symbolst::const_iterator it=s.begin(); it != s.end(); ++it) - { - const symbolt &symbol=it->second; - if(is_meta_or_not_global(symbol)) continue; - exprt rhs=symbol.value; - rhs.add_source_location()=lhs.source_location(); - if(lhs == rhs) return true; - } - return false; -} - -bool is_empty(const exprt &expr) -{ - return exprt() == expr; -} -} - -void add_cegis_constant(symbol_tablet &st, goto_functionst &gf, - const std::string &name, const exprt &value, goto_programt::targett pos) -{ - while(is_builtin(pos->source_location)) - ++pos; - typet type=value.type(); - type.set(ID_C_constant, true); - create_cegis_symbol(st, name, type).value=value; - if(!is_empty(value)) - pos=cegis_assign_user_variable(st, gf, pos, name, value); -} - -void add_cegis_constant(symbol_tablet &st, goto_functionst &gf, - const exprt &value, goto_programt::targett pos) -{ - if(contains_constant(st, value)) return; - const namespacet ns(st); - std::string name(CEGIS_CONSTANT_PREFIX); - name+=expr2c(value, ns); - add_cegis_constant(st, gf, name, value, pos); -} diff --git a/src/cegis/constant/add_constant.h b/src/cegis/constant/add_constant.h deleted file mode 100644 index 5d61c80dde9..00000000000 --- a/src/cegis/constant/add_constant.h +++ /dev/null @@ -1,48 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONSTANT_ADD_CONSTANT_H -#define CPROVER_CEGIS_CONSTANT_ADD_CONSTANT_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param value - */ -void add_cegis_constant( - class symbol_tablet &st, - class goto_functionst &gf, - const class exprt &value, - goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param name - * @param value - * @param pos - */ -void add_cegis_constant( - class symbol_tablet &st, - class goto_functionst &gf, - const std::string &name, - const exprt &value, - goto_programt::targett pos); - -#endif // CPROVER_CEGIS_CONSTANT_ADD_CONSTANT_H diff --git a/src/cegis/constant/default_cegis_constant_strategy.cpp b/src/cegis/constant/default_cegis_constant_strategy.cpp deleted file mode 100644 index c02abe8e048..00000000000 --- a/src/cegis/constant/default_cegis_constant_strategy.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include - -namespace -{ -std::string get_name(size_t index) -{ - std::string name(CEGIS_CONSTANT_PREFIX); - return name+=integer2string(index); -} -} - -size_t default_cegis_constant_strategy(symbol_tablet &st, goto_functionst &gf) -{ - const std::vector literals(collect_integer_literals(st, gf)); - size_t max_word_width=0u; - size_t const_index=0u; - goto_programt::targett pos=get_entry_body(gf).instructions.begin(); - // XXX: Literals strategy, benchmark performance - for(const constant_exprt &expr : literals) - { - // XXX: Debug - // std::cout << "" << const_index << "" << std::endl; - // std::cout << "" << expr.to_string() << "" << std::endl; - // XXX: Debug - const std::string base_name(get_name(const_index++)); - pos=declare_cegis_meta_variable(st, gf, pos, base_name, expr.type()); - pos=assign_cegis_meta_variable(st, gf, pos, base_name, expr); - max_word_width=std::max(max_word_width, get_min_word_width(expr)); - } - return max_word_width; -} diff --git a/src/cegis/constant/default_cegis_constant_strategy.h b/src/cegis/constant/default_cegis_constant_strategy.h deleted file mode 100644 index 2e687a1611e..00000000000 --- a/src/cegis/constant/default_cegis_constant_strategy.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONSTANT_DEFAULT_CEGIS_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_CONSTANT_DEFAULT_CEGIS_CONSTANT_STRATEGY_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param max_length - */ -size_t default_cegis_constant_strategy( - class symbol_tablet &st, - class goto_functionst &gf); - -#endif // CPROVER_CEGIS_CONSTANT_DEFAULT_CEGIS_CONSTANT_STRATEGY_H diff --git a/src/cegis/constant/literals_collector.cpp b/src/cegis/constant/literals_collector.cpp deleted file mode 100644 index e72a4dca9fc..00000000000 --- a/src/cegis/constant/literals_collector.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include - -namespace -{ -class compare_constantt -{ - const namespacet ns; -public: - explicit compare_constantt(const symbol_tablet &st) : - ns(st) - { - } - - bool operator()(const constant_exprt &lhs, const constant_exprt &rhs) const - { - return lhs.get_value() < rhs.get_value(); - } -}; - -typedef std::set constant_sett; - -class constant_expr_visitort: public const_expr_visitort -{ - const namespacet ns; - const typet type; - constant_sett &constants; -public: - constant_expr_visitort(const symbol_tablet &st, constant_sett &constants) : - ns(st), type(unsigned_int_type()), constants(constants) - { - } - - virtual void operator()(const exprt &expr) - { - if(ID_constant != expr.id()) return; - const typet &expr_type=expr.type(); - const irep_idt &type_id=expr_type.id(); - if(ID_unsignedbv != type_id && ID_signedbv != type_id) return; - const constant_exprt constant(to_constant_expr(expr)); - const bv_arithmetict bv(constant); - const mp_integer::llong_t value=bv.to_integer().to_long(); - constants.insert(from_integer(static_cast(value), type)); - } - - void operator()(const goto_programt::instructiont &instr) - { - if(is_builtin(instr.source_location)) return; - instr.code.visit(*this); - instr.guard.visit(*this); - } -}; -} - -std::vector collect_integer_literals(const symbol_tablet &st, - const goto_functionst &gf) -{ - const compare_constantt compare(st); - constant_sett constants(compare); - const constant_expr_visitort visitor(st, constants); - const goto_programt::instructionst &instrs=get_entry_body(gf).instructions; - std::for_each(instrs.begin(), instrs.end(), visitor); - return std::vector(constants.begin(), constants.end()); -} diff --git a/src/cegis/constant/literals_collector.h b/src/cegis/constant/literals_collector.h deleted file mode 100644 index 85f12c19e99..00000000000 --- a/src/cegis/constant/literals_collector.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONSTANT_LITERALS_COLLECTOR_H -#define CPROVER_CEGIS_CONSTANT_LITERALS_COLLECTOR_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * - * @return - */ -std::vector collect_integer_literals( - const class symbol_tablet &st, - const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_CONSTANT_LITERALS_COLLECTOR_H diff --git a/src/cegis/control/facade/control_runner.cpp b/src/cegis/control/facade/control_runner.cpp deleted file mode 100644 index 06e126864b3..00000000000 --- a/src/cegis/control/facade/control_runner.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -template -int run(optionst &o, messaget::mstreamt &result, const symbol_tablet &st, - const goto_functionst &gf, const zero_solutiont &default_solution) -{ - control_preprocessingt prep(st, gf); - const control_programt &program=prep.get_program(); - typedef control_symex_learnt control_learnt; - control_learnt lcfg(program); - cegis_symex_learnt learn(o, prep, - lcfg, default_solution); - typedef control_symex_verifyt verifyt; - verifyt vcfg(program); - cegis_symex_verifyt oracle(o, vcfg); - return run_cegis_with_statistics_wrapper(result, o, learn, oracle, prep); -} -} - -int run_control(optionst &o, messaget::mstreamt &result, - const symbol_tablet &st, const goto_functionst &gf) -{ - if(is_vector_solution_config(st)) - { - const zero_vector_solutiont def(st); - return run(o, result, st, gf, def); - } - const zero_rational_solutiont def(st); - return run(o, result, st, gf, def); -} diff --git a/src/cegis/control/facade/control_runner.h b/src/cegis/control/facade/control_runner.h deleted file mode 100644 index f37974ec3ba..00000000000 --- a/src/cegis/control/facade/control_runner.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_FACADE_CONTROL_RUNNER_H -#define CPROVER_CEGIS_CONTROL_FACADE_CONTROL_RUNNER_H - -#include - -/** - * @brief - * - * @details - * - * @param options - * @param result - * @param st - * @param gf - * - * @return - */ -int run_control(class optionst &options, messaget::mstreamt &result, - const class symbol_tablet &st, const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_CONTROL_FACADE_CONTROL_RUNNER_H diff --git a/src/cegis/control/learn/control_symex_learn.h b/src/cegis/control/learn/control_symex_learn.h deleted file mode 100644 index 0ec02f3c2b4..00000000000 --- a/src/cegis/control/learn/control_symex_learn.h +++ /dev/null @@ -1,110 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_LEARN_CONTROL_SYMEX_LEARN_H -#define CPROVER_CEGIS_CONTROL_LEARN_CONTROL_SYMEX_LEARN_H - -#include - -#include -#include -#include - -/** - * @brief - * - * @details - */ -template -class control_symex_learnt -{ - const control_programt &original_program; - control_programt current_program; -public: - typedef control_counterexamplet counterexamplet; - typedef control_counterexamplest counterexamplest; - typedef typename solution_configt::solutiont candidatet; - /** - * @brief - * - * @details - * - * @param original_program - */ - explicit control_symex_learnt(const control_programt &original_program); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process( - const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits) const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert( - candidatet ¤t_candidate, - const class goto_tracet &trace, - size_t max_solution_size) const; - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate( - messaget::mstreamt &os, - const candidatet &candidate) const; -}; - -#include "control_symex_learn.inc" - -#endif // CPROVER_CEGIS_CONTROL_LEARN_CONTROL_SYMEX_LEARN_H diff --git a/src/cegis/control/learn/control_symex_learn.inc b/src/cegis/control/learn/control_symex_learn.inc deleted file mode 100644 index 25b42b1cc3e..00000000000 --- a/src/cegis/control/learn/control_symex_learn.inc +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -template -control_symex_learnt::control_symex_learnt( - const control_programt &original_program) : - original_program(original_program) -{ -} - -template -void control_symex_learnt::process( - const counterexamplest &counterexamples, const size_t max_solution_size) -{ - current_program=original_program; - symbol_tablet &st=current_program.st; - goto_functionst &gf=current_program.gf; - solution_configt::nondeterminise_solution_configuration(st, gf); - transform_asserts_to_assumes(gf); - const goto_programt::targetst &ce_locs= - current_program.counterexample_locations; - insert_counterexamples(st, gf, counterexamples, ce_locs); - gf.update(); -} - -template -const symbol_tablet &control_symex_learnt::get_symbol_table() const -{ - return current_program.st; -} - -template -const goto_functionst &control_symex_learnt::get_goto_functions() const -{ - return current_program.gf; -} - -template -void control_symex_learnt::set_word_width( - const size_t word_width_in_bits) const -{ -} - -template -void control_symex_learnt::convert( - candidatet ¤t_candidate, const goto_tracet &trace, - const size_t max_solution_size) const -{ - solution_configt::convert(current_candidate, trace, current_program.st); -} - -template -void control_symex_learnt::show_candidate( - messaget::mstreamt &os, const candidatet &candidate) const -{ - solution_configt::show_candidate(os, candidate, current_program.st); -} diff --git a/src/cegis/control/learn/nondet_solution.cpp b/src/cegis/control/learn/nondet_solution.cpp deleted file mode 100644 index 7a7a4c710e5..00000000000 --- a/src/cegis/control/learn/nondet_solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include - -void nondet_control_solution(const symbol_tablet &st, goto_functionst &gf) -{ - const std::string name(CEGIS_CONTROL_SOLUTION_VAR_NAME); - const symbolt &symbol=st.lookup(name); - const side_effect_expr_nondett value(symbol.type); - const symbol_exprt solution_var(symbol.symbol_expr()); - goto_programt &body=get_entry_body(gf); - const goto_programt::targett pos(find_cprover_initialize(body)); - cegis_assign_user_variable(st, gf, std::prev(pos), name, value); - goto_programt &init=get_body(gf, CPROVER_INIT); - remove_solution_assignment(init); -} diff --git a/src/cegis/control/learn/nondet_solution.h b/src/cegis/control/learn/nondet_solution.h deleted file mode 100644 index 9bdbcbb383e..00000000000 --- a/src/cegis/control/learn/nondet_solution.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_LEARN_NONDET_SOLUTION_H -#define CPROVER_CEGIS_CONTROL_LEARN_NONDET_SOLUTION_H - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -void nondet_control_solution( - const class symbol_tablet &st, - class goto_functionst &gf); - -#endif // CPROVER_CEGIS_CONTROL_LEARN_NONDET_SOLUTION_H diff --git a/src/cegis/control/learn/print_control_solution.cpp b/src/cegis/control/learn/print_control_solution.cpp deleted file mode 100644 index c8946711039..00000000000 --- a/src/cegis/control/learn/print_control_solution.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -void print_control_array(messaget::mstreamt &os, const array_exprt &array, - const char * name, const symbol_tablet &st) -{ - const namespacet ns(st); - const array_exprt::operandst &ops=array.operands(); - os << '<' << name << '>' << messaget::endl; - for(const array_exprt::operandst::value_type &value : ops) - os << "" << expr2c(value, ns) << "" << messaget::endl; - os << "' << messaget::endl; - os << '<' << name << "_size>" << ops.size(); - os << "" << messaget::endl; -} diff --git a/src/cegis/control/learn/print_control_solution.h b/src/cegis/control/learn/print_control_solution.h deleted file mode 100644 index a6f0bcab9ef..00000000000 --- a/src/cegis/control/learn/print_control_solution.h +++ /dev/null @@ -1,33 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_LEARN_PRINT_CONTROL_SOLUTION_H -#define CPROVER_CEGIS_CONTROL_LEARN_PRINT_CONTROL_SOLUTION_H - -#include -#include -#include - -/** - * @brief - * - * @details - * - * @param os - * @param array - * @param name - * @param st - */ -void print_control_array( - messaget::mstreamt &os, - const array_exprt &array, - const char * name, - const symbol_tablet &st); - -#endif // CPROVER_CEGIS_CONTROL_LEARN_PRINT_CONTROL_SOLUTION_H diff --git a/src/cegis/control/learn/rational_solution_configuration.cpp b/src/cegis/control/learn/rational_solution_configuration.cpp deleted file mode 100644 index c49f81e621d..00000000000 --- a/src/cegis/control/learn/rational_solution_configuration.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void rational_solution_configurationt::nondeterminise_solution_configuration( - symbol_tablet &st, goto_functionst &gf) -{ - nondet_control_solution(st, gf); -} - -namespace -{ -const struct_exprt &find_solution(const goto_tracet &trace) -{ - for(const goto_trace_stept &step : trace.steps) - { - const exprt &lhs=step.full_lhs; - if(ID_symbol != lhs.id()) continue; - const std::string &id=id2string(to_symbol_expr(lhs).get_identifier()); - if(CEGIS_CONTROL_SOLUTION_VAR_NAME != id) continue; - return to_struct_expr(step.full_lhs_value); - } - assert(!"Control solution not found in trace."); -} -} - -void rational_solution_configurationt::convert(solutiont ¤t_candidate, - const goto_tracet &trace, const symbol_tablet &st) -{ - const struct_exprt &solution=find_solution(trace); - const namespacet ns(st); - current_candidate.a=get_a_controller_comp(ns, solution); - current_candidate.b=get_b_controller_comp(ns, solution); -} - -void rational_solution_configurationt::show_candidate(messaget::mstreamt &os, - const solutiont &candidate, const symbol_tablet &st) -{ - print_control_array(os, candidate.a, "a", st); - print_control_array(os, candidate.b, "b", st); -} diff --git a/src/cegis/control/learn/rational_solution_configuration.h b/src/cegis/control/learn/rational_solution_configuration.h deleted file mode 100644 index f135c58578f..00000000000 --- a/src/cegis/control/learn/rational_solution_configuration.h +++ /dev/null @@ -1,74 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_LEARN_RATIONAL_SOLUTION_CONFIGURATION_H -#define CPROVER_CEGIS_CONTROL_LEARN_RATIONAL_SOLUTION_CONFIGURATION_H - -#include - -/** - * @brief - * - * @details - */ -class rational_solution_configurationt -{ -public: - rational_solution_configurationt()=delete; - ~rational_solution_configurationt()=delete; - - /** - * @brief - * - * @details - */ - typedef class control_solutiont solutiont; - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - static void nondeterminise_solution_configuration( - class symbol_tablet &st, - class goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param st - */ - static void convert( - solutiont ¤t_candidate, - const class goto_tracet &trace, - const symbol_tablet &st); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - * @param st - */ - static void show_candidate( - messaget::mstreamt &os, - const solutiont &candidate, - const symbol_tablet &st); -}; - -#endif // CPROVER_CEGIS_CONTROL_LEARN_RATIONAL_SOLUTION_CONFIGURATION_H diff --git a/src/cegis/control/learn/vector_solution_configuration.cpp b/src/cegis/control/learn/vector_solution_configuration.cpp deleted file mode 100644 index 33dc43a730e..00000000000 --- a/src/cegis/control/learn/vector_solution_configuration.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_assignment_to_solution_var(const goto_programt::instructiont &instr) -{ - if(goto_program_instruction_typet::ASSIGN != instr.type) return false; - const std::string &var_name=id2string(get_affected_variable(instr)); - return CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == var_name; -} -} - -void vector_solution_configurationt::nondeterminise_solution_configuration( - symbol_tablet &st, goto_functionst &gf) -{ - goto_programt &init_body=get_body(gf, CPROVER_INIT); - goto_programt::instructionst &init_instrs=init_body.instructions; - const goto_programt::targett assignment=std::find_if(init_instrs.begin(), - init_instrs.end(), is_assignment_to_solution_var); - goto_programt &entry_body=get_entry_body(gf); - const goto_programt::targett first_entry=entry_body.instructions.begin(); - const goto_programt::targett new_assignment=entry_body.insert_before( - first_entry); - new_assignment->source_location=first_entry->source_location; - new_assignment->type=assignment->type; - new_assignment->code=assignment->code; - init_body.instructions.erase(assignment); - init_body.update(); - entry_body.update(); -} - -namespace -{ -bool is_solution(const goto_trace_stept &step) -{ - const exprt &lhs=step.full_lhs; - if(ID_symbol != lhs.id()) return false; - const std::string &id=id2string(to_symbol_expr(lhs).get_identifier()); - return CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == id; -} - -const array_exprt &find_solution(const goto_tracet &trace) -{ - const goto_tracet::stepst &steps=trace.steps; - const auto it=std::find_if(steps.begin(), steps.end(), is_solution); - assert(steps.end() != it); - return to_array_expr(it->full_lhs_value); -} -} - -void vector_solution_configurationt::convert(solutiont ¤t_candidate, - const goto_tracet &trace, const symbol_tablet &st) -{ - current_candidate.K=find_solution(trace); -} - -void vector_solution_configurationt::show_candidate(messaget::mstreamt &os, - const solutiont &candidate, const symbol_tablet &st) -{ - print_control_array(os, candidate.K, "K", st); -} diff --git a/src/cegis/control/learn/vector_solution_configuration.h b/src/cegis/control/learn/vector_solution_configuration.h deleted file mode 100644 index d79aae04eed..00000000000 --- a/src/cegis/control/learn/vector_solution_configuration.h +++ /dev/null @@ -1,75 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_LEARN_VECTOR_SOLUTION_CONFIGURATION_H -#define CPROVER_CEGIS_CONTROL_LEARN_VECTOR_SOLUTION_CONFIGURATION_H - -#include - -/** - * @brief - * - * @details - */ -class vector_solution_configurationt -{ -public: - vector_solution_configurationt()=delete; - ~vector_solution_configurationt()=delete; - - - /** - * @brief - * - * @details - */ - typedef class control_vector_solutiont solutiont; - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - static void nondeterminise_solution_configuration( - class symbol_tablet &st, - class goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param st - */ - static void convert( - solutiont ¤t_candidate, - const class goto_tracet &trace, - const symbol_tablet &st); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - * @param st - */ - static void show_candidate( - messaget::mstreamt &os, - const solutiont &candidate, - const symbol_tablet &st); -}; - -#endif // CPROVER_CEGIS_CONTROL_LEARN_VECTOR_SOLUTION_CONFIGURATION_H diff --git a/src/cegis/control/options/control_program.cpp b/src/cegis/control/options/control_program.cpp deleted file mode 100644 index e8fd02460c2..00000000000 --- a/src/cegis/control/options/control_program.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -control_programt::control_programt(const symbol_tablet &st, - const goto_functionst &gf) : - st(st) -{ - this->gf.copy_from(gf); -} - -namespace -{ -control_programt ©(control_programt &lhs, const control_programt &rhs) -{ - lhs.gf.copy_from(rhs.gf); - goto_programt &lhs_body=get_entry_body(lhs.gf); - const goto_programt &rhs_body=get_entry_body(rhs.gf); - const target_copy_helpert copy(rhs_body, lhs_body); - copy(lhs.counterexample_locations, rhs.counterexample_locations); - return lhs; -} -} - -control_programt::control_programt(const control_programt &other) : - st(other.st) -{ - copy(*this, other); -} - -control_programt::control_programt() -{ -} - -control_programt &control_programt::operator =(const control_programt &other) -{ - st.clear(); - st=other.st; - gf.clear(); - return copy(*this, other); -} diff --git a/src/cegis/control/options/control_program.h b/src/cegis/control/options/control_program.h deleted file mode 100644 index f8bab843305..00000000000 --- a/src/cegis/control/options/control_program.h +++ /dev/null @@ -1,69 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_OPTIONS_CONTROL_PROGRAM_H -#define CPROVER_CEGIS_CONTROL_OPTIONS_CONTROL_PROGRAM_H - -#include - -/** - * @brief - * - * @details - */ -class control_programt -{ -public: - symbol_tablet st; - goto_functionst gf; - - /** - * @brief - * - * @details All variable locations to be considered in counterexamles (including loop bodies). - */ - goto_programt::targetst counterexample_locations; - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - control_programt(const symbol_tablet &st, const goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @param other - */ - control_programt(const control_programt &other); - - /** - * @brief - * - * @details - */ - control_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - control_programt &operator=(const control_programt &other); -}; - -#endif // CPROVER_CEGIS_CONTROL_OPTIONS_CONTROL_PROGRAM_H diff --git a/src/cegis/control/preprocessing/control_preprocessing.cpp b/src/cegis/control/preprocessing/control_preprocessing.cpp deleted file mode 100644 index 42535dbe805..00000000000 --- a/src/cegis/control/preprocessing/control_preprocessing.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TMP_MARKER "$tmp" - -// XXX: Debug -#include -// XXX: Debug - -control_preprocessingt::control_preprocessingt(const symbol_tablet &st, - const goto_functionst &gf) : - control_program(st, gf) -{ -} - -namespace -{ -const char * const excluded_functions[]= { - "verify_stability_closedloop_using_dslib", "check_stability_closedloop", - "fxp_double_to_fxp", "fxp_to_double", "ft_closedloop_series", "poly_mult", - "poly_sum", "internal_pow", "fxp_check", "fxp_control_floatt_to_fxp", - "main", "validation", "double_matrix_multiplication", "double_sub_matrix", - "check_stability" }; - -bool is_meta(const goto_programt::const_targett pos) -{ - if(default_cegis_meta_criterion(pos)) return true; - const source_locationt &loc=pos->code.source_location(); - const std::string &func=id2string(loc.get_function()); - for(const char * const excluded : excluded_functions) - if(contains(func, excluded)) return true; - if((goto_program_instruction_typet::ASSIGN != pos->type - && goto_program_instruction_typet::DECL != pos->type) - || !pos->code.has_operands() - || (pos->code.has_operands() && ID_symbol != pos->code.op0().id())) - return false; - const std::string &var=id2string(get_affected_variable(*pos)); - if(contains(var, TMP_MARKER) || contains(var, RETURN_VALUE_SUFFIX) - || contains(var, CPROVER_PREFIX)) return true; - return CEGIS_CONTROL_SOLUTION_VAR_NAME == var - || CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == var; -} - -void add_explicit_nondet_for_extern_vars(const symbol_tablet &st, - goto_functionst &gf) -{ - goto_programt &entry_body=get_entry_body(gf); - goto_programt &init_body=get_body(gf, CPROVER_INIT); - goto_programt::targett entry_pos=entry_body.instructions.begin(); - goto_programt::targett init_pos=std::prev(init_body.instructions.end(), 1); - for(const symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols) - { - const symbolt &symbol=id_and_symbol.second; - const std::string &name=id2string(id_and_symbol.first); - if(!symbol.is_extern || contains(name, CPROVER_PREFIX)) continue; - const bool is_solution_var=CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == name - || CEGIS_CONTROL_SOLUTION_VAR_NAME == name; - goto_programt &body=is_solution_var ? init_body : entry_body; - goto_programt::targett &pos=is_solution_var ? init_pos : entry_pos; - const source_locationt &loc=pos->source_location; - if(is_solution_var) pos=body.insert_before(pos); - else pos=body.insert_after(pos); - pos->source_location=loc; - pos->type=goto_program_instruction_typet::ASSIGN; - const side_effect_expr_nondett rhs(symbol.type); - pos->code=code_assignt(symbol.symbol_expr(), rhs); - } - entry_body.update(); -} -} - -void control_preprocessingt::operator ()() -{ - symbol_tablet &st=control_program.st; - goto_functionst &gf=control_program.gf; - remove_unused_elements(st, gf); - inline_user_program(st, gf); - goto_programt::targetst &locs=control_program.counterexample_locations; - goto_programt &body=get_entry_body(gf); - add_explicit_nondet_for_extern_vars(st, gf); - collect_counterexample_locations(locs, body, is_meta); - // XXX: Debug - for(const goto_programt::const_targett target : locs) - { - std::cout << "" << target->code.pretty() << "" << std::endl; - } - // XXX: Debug - propagate_controller_sizes(st, gf); -} - -void control_preprocessingt::operator ()(const size_t max_length) const -{ -} - -size_t control_preprocessingt::get_min_solution_size() const -{ - return 1u; -} - -const control_programt &control_preprocessingt::get_program() const -{ - return control_program; -} diff --git a/src/cegis/control/preprocessing/control_preprocessing.h b/src/cegis/control/preprocessing/control_preprocessing.h deleted file mode 100644 index 3631a195003..00000000000 --- a/src/cegis/control/preprocessing/control_preprocessing.h +++ /dev/null @@ -1,71 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_PREPROCESSING_CONTROL_PREPROCESSING_H -#define CPROVER_CEGIS_CONTROL_PREPROCESSING_CONTROL_PREPROCESSING_H - -#include - -/** - * @brief - * - * @details - */ -class control_preprocessingt -{ - control_programt control_program; -public: - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - explicit control_preprocessingt( - const symbol_tablet &st, - const goto_functionst &gf); - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_length - */ - void operator()(size_t max_length) const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - * - * @return - */ - const control_programt &get_program() const; -}; - -#endif // CPROVER_CEGIS_CONTROL_PREPROCESSING_CONTROL_PREPROCESSING_H diff --git a/src/cegis/control/preprocessing/propagate_controller_sizes.cpp b/src/cegis/control/preprocessing/propagate_controller_sizes.cpp deleted file mode 100644 index a451f290965..00000000000 --- a/src/cegis/control/preprocessing/propagate_controller_sizes.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include - -namespace -{ -template -exprt_typet &get_comp(const namespacet &ns, struct_exprt_typet &value, - const char * const comp) -{ - const struct_typet &type=to_struct_type(ns.follow(value.type())); - const struct_typet::componentst &comps=type.components(); - for(size_t i=0; i < comps.size(); ++i) - if(id2string(comps[i].get_name()) == comp) return value.operands()[i]; - assert(!"Solution component not found."); -} -} - -const exprt &get_controller_comp(const namespacet &ns, - const struct_exprt &value, const char * const comp) -{ - return get_comp(ns, value, comp); -} - -exprt &get_controller_comp(const namespacet &ns, struct_exprt &value, - const char * const comp) -{ - return get_comp(ns, value, comp); -} - -const array_exprt &get_a_controller_comp(const namespacet &ns, - const struct_exprt &value) -{ - return to_array_expr( - get_controller_comp(ns, value, CEGIS_CONTROL_A_MEMBER_NAME)); -} - -const array_exprt &get_b_controller_comp(const namespacet &ns, - const struct_exprt &value) -{ - return to_array_expr( - get_controller_comp(ns, value, CEGIS_CONTROL_B_MEMBER_NAME)); -} - -namespace -{ -const exprt &get_a_size(const namespacet &ns, const struct_exprt &value) -{ - return get_controller_comp(ns, value, CEGIS_CONTROL_A_SIZE_MEMBER_NAME); -} - -const exprt &get_b_size(const namespacet &ns, const struct_exprt &value) -{ - return get_controller_comp(ns, value, CEGIS_CONTROL_B_SIZE_MEMBER_NAME); -} - -class replace_sizes_visitort: public expr_visitort -{ - std::deque a_sizes, b_sizes; - const exprt &a_size; - const exprt &b_size; -public: - replace_sizes_visitort(const exprt &a_size, const exprt &b_size) : - a_size(a_size), b_size(b_size) - { - } - - virtual ~replace_sizes_visitort() - { - for(exprt * const expr : a_sizes) - *expr=a_size; - for(exprt * const expr : b_sizes) - *expr=b_size; - } - - virtual void operator()(exprt &expr) - { - if(ID_member != expr.id()) return; - const member_exprt &member=to_member_expr(expr); - const exprt &struct_op=member.struct_op(); - if(ID_symbol != struct_op.id()) return; - const symbol_exprt &symbol=to_symbol_expr(struct_op); - const std::string &var=id2string(symbol.get_identifier()); - if(CEGIS_CONTROL_SOLUTION_VAR_NAME != var) return; - const std::string &comp=id2string(member.get_component_name()); - if(CEGIS_CONTROL_A_SIZE_MEMBER_NAME == comp) a_sizes.push_back(&expr); - else if(CEGIS_CONTROL_B_SIZE_MEMBER_NAME == comp) b_sizes.push_back(&expr); - } -}; -} - -void propagate_controller_sizes(const symbol_tablet &st, goto_functionst &gf) -{ - if(!st.has_symbol(CEGIS_CONTROL_SOLUTION_VAR_NAME)) return; - const symbolt &symbol=st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME); - const struct_exprt &controller_value=to_struct_expr(symbol.value); - const namespacet ns(st); - const exprt &a_size=get_a_size(ns, controller_value); - const exprt &b_size=get_b_size(ns, controller_value); - replace_sizes_visitort visitor(a_size, b_size); - goto_programt &body=get_entry_body(gf); - for(goto_programt::instructiont &instr : body.instructions) - { - instr.code.visit(visitor); - instr.guard.visit(visitor); - } -} - -namespace -{ -bool is_sol_assign(const goto_programt::instructiont &instr) -{ - if(goto_program_instruction_typet::ASSIGN != instr.type) return false; - const std::string &var=id2string(get_affected_variable(instr)); - return CEGIS_CONTROL_SOLUTION_VAR_NAME == var; -} -} - -goto_programt::targett get_solution_assignment(goto_programt &body) -{ - goto_programt::instructionst &i=body.instructions; - const goto_programt::targett end(i.end()); - const goto_programt::targett pos=std::find_if(i.begin(), end, is_sol_assign); - assert(end != pos); - return pos; -} - -void remove_solution_assignment(goto_programt &body) -{ - body.instructions.erase(get_solution_assignment(body)); -} diff --git a/src/cegis/control/preprocessing/propagate_controller_sizes.h b/src/cegis/control/preprocessing/propagate_controller_sizes.h deleted file mode 100644 index 0358270c62a..00000000000 --- a/src/cegis/control/preprocessing/propagate_controller_sizes.h +++ /dev/null @@ -1,103 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_PREPROCESSING_PROPAGATE_CONTROLLER_SIZES_H -#define CPROVER_CEGIS_CONTROL_PREPROCESSING_PROPAGATE_CONTROLLER_SIZES_H - -#include - -/** - * @brief - * - * @details - * - * @param ns - * @param value - * @param comp - */ -const exprt &get_controller_comp( - const namespacet &ns, - const struct_exprt &value, - const char * const comp); - -/** - * @brief - * - * @details - * - * @param ns - * @param value - * @param comp - */ -exprt &get_controller_comp( - const namespacet &ns, - struct_exprt &value, - const char * const comp); - -/** - * @brief - * - * @details - * - * @param ns - * @param value - * - * @return - */ -const array_exprt &get_a_controller_comp( - const namespacet &ns, - const struct_exprt &value); - -/** - * @brief - * - * @details - * - * @param ns - * @param value - * - * @return - */ -const array_exprt &get_b_controller_comp( - const namespacet &ns, - const struct_exprt &value); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -void propagate_controller_sizes( - const class symbol_tablet &st, - class goto_functionst &gf); - -/** - * @brief - * - * @details - * - * @param body - */ -void remove_solution_assignment(goto_programt &body); - -/** - * @brief - * - * @details - * - * @param body - * - * @return - */ -goto_programt::targett get_solution_assignment(goto_programt &body); - -#endif // CPROVER_CEGIS_CONTROL_PREPROCESSING_PROPAGATE_CONTROLLER_SIZES_H diff --git a/src/cegis/control/simplify/remove_unused_elements.cpp b/src/cegis/control/simplify/remove_unused_elements.cpp deleted file mode 100644 index cdd163bd7a0..00000000000 --- a/src/cegis/control/simplify/remove_unused_elements.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include - -namespace -{ -class symbol_visitort: public const_expr_visitort -{ - std::set &vars; -public: - explicit symbol_visitort(std::set &vars) : - vars(vars) - { - } - - virtual ~symbol_visitort()=default; - - virtual void operator()(const exprt &expr) - { - if(ID_symbol != expr.id()) return; - vars.insert(to_symbol_expr(expr).get_identifier()); - } -}; - -void visit_functions(std::set &vars, std::set &funcs, - const goto_functionst &gf, const goto_programt &body) -{ - symbol_visitort visitor(vars); - for(const goto_programt::instructiont &instr : body.instructions) - { - instr.code.visit(visitor); - instr.guard.visit(visitor); - if(goto_program_instruction_typet::FUNCTION_CALL != instr.type) continue; - const exprt &func=to_code_function_call(instr.code).function(); - assert(ID_symbol == func.id()); - const irep_idt &id=to_symbol_expr(func).get_identifier(); - funcs.insert(id); - typedef goto_functionst::function_mapt fmapt; - const fmapt &fmap=gf.function_map; - const fmapt::const_iterator it=fmap.find(id); - assert(fmap.end() != it); - const goto_function_templatet &prog=it->second; - if(prog.body_available()) visit_functions(vars, funcs, gf, prog.body); - } -} -} - -void remove_unused_functions(symbol_tablet &st, goto_functionst &gf, - const std::set &funcs) -{ - typedef goto_functionst::function_mapt fmapt; - fmapt &fmap=gf.function_map; - for(fmapt::iterator it=fmap.begin(); it != fmap.end();) - { - const irep_idt &id=it->first; - if(funcs.end() == funcs.find(id)) - { - it=fmap.erase(it); - st.remove(id); - } else ++it; - } -} - -namespace -{ -void remove_assignments_to(goto_programt &init, const irep_idt &id) -{ - goto_programt::instructionst &ins=init.instructions; - for(goto_programt::targett pos=ins.begin(); pos != ins.end();) - { - const goto_programt::instructiont &instr=*pos; - if(goto_program_instruction_typet::ASSIGN == instr.type - && ID_symbol == to_code_assign(instr.code).lhs().id() - && id - == to_symbol_expr(to_code_assign(instr.code).lhs()).get_identifier()) - { - pos=ins.erase(pos); - } else ++pos; - } -} - -bool is_meta(const irep_idt &id) -{ - const std::string &str=id2string(id); - return contains(str, CPROVER_PREFIX) || contains(str, RETURN_VALUE_SUFFIX); -} -} - -void remove_unused_globals(symbol_tablet &st, goto_functionst &gf, - const std::set &variables) -{ - std::set to_remove; - for(const std::pair named_symbol : st.symbols) - { - const symbolt &symbol=named_symbol.second; - const irep_idt &name=named_symbol.first; - if(symbol.is_static_lifetime && variables.end() == variables.find(name) - && !is_meta(name)) to_remove.insert(name); - } - goto_programt &init=get_body(gf, CPROVER_INIT); - for(const irep_idt &var : to_remove) - { - st.remove(var); - remove_assignments_to(init, var); - } -} - -void remove_unused_elements(symbol_tablet &st, goto_functionst &gf) -{ - std::set vars, funcs; - funcs.insert(CPROVER_INIT); - funcs.insert(goto_functionst::entry_point()); - visit_functions(vars, funcs, gf, get_entry_body(gf)); - remove_unused_functions(st, gf, funcs); - remove_unused_globals(st, gf, vars); -} diff --git a/src/cegis/control/simplify/remove_unused_elements.h b/src/cegis/control/simplify/remove_unused_elements.h deleted file mode 100644 index ab0fdc0e151..00000000000 --- a/src/cegis/control/simplify/remove_unused_elements.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_SIMPLIFY_REMOVE_UNUSED_ELEMENTS_H -#define CPROVER_CEGIS_CONTROL_SIMPLIFY_REMOVE_UNUSED_ELEMENTS_H - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -void remove_unused_elements( - symbol_tablet &st, - goto_functionst &gf); - -#endif // CPROVER_CEGIS_CONTROL_SIMPLIFY_REMOVE_UNUSED_ELEMENTS_H diff --git a/src/cegis/control/value/control_counterexample.h b/src/cegis/control/value/control_counterexample.h deleted file mode 100644 index b09ce580997..00000000000 --- a/src/cegis/control/value/control_counterexample.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_CONTROL_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_COUNTEREXAMPLE_H - -#include -#include - -#include - -/** - * @brief - * - * @details List of values per CE location. - */ -typedef std::map control_counterexamplet; - -typedef std::deque control_counterexamplest; - -#endif // CPROVER_CEGIS_CONTROL_VALUE_CONTROL_COUNTEREXAMPLE_H diff --git a/src/cegis/control/value/control_solution.h b/src/cegis/control/value/control_solution.h deleted file mode 100644 index 3d135ebfd27..00000000000 --- a/src/cegis/control/value/control_solution.h +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_CONTROL_SOLUTION_H -#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_SOLUTION_H - -#include - -/** - * @brief - * - * @details - */ -class control_solutiont -{ -public: - /** - * @brief - * - * @details - */ - array_exprt a; - - /** - * @brief - * - * @details - */ - array_exprt b; -}; - -#endif // CPROVER_CEGIS_CONTROL_VALUE_CONTROL_SOLUTION_H diff --git a/src/cegis/control/value/control_types.cpp b/src/cegis/control/value/control_types.cpp deleted file mode 100644 index 598ce3c8f75..00000000000 --- a/src/cegis/control/value/control_types.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -const symbol_typet &control_solution_type(const symbol_tablet &st) -{ - return to_symbol_type(st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME).type); -} - -const array_typet &control_vector_solution_type(const symbol_tablet &st) -{ - return to_array_type(st.lookup(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME).type); -} - -namespace -{ -const struct_typet::componentt &get_comp(const symbol_tablet &st, - const char * const name) -{ - const typet &type=st.lookup(control_solution_type(st).get_identifier()).type; - return to_struct_type(type).get_component(name); -} -} - -const typet &control_float_value_type(const symbol_tablet &st) -{ - const struct_typet::componentt &c=get_comp(st, CEGIS_CONTROL_A_MEMBER_NAME); - return to_array_type(c.type()).subtype(); -} - -const typet &control_array_size_type(const symbol_tablet &st) -{ - const struct_typet::componentt &c=get_comp(st, CEGIS_CONTROL_A_MEMBER_NAME); - return to_array_type(c.type()).size().type(); -} - -const typet &control_runtime_array_size_type(const symbol_tablet &st) -{ - const char * const name=CEGIS_CONTROL_A_SIZE_MEMBER_NAME; - const struct_typet::componentt &c=get_comp(st, name); - return c.type(); -} diff --git a/src/cegis/control/value/control_types.h b/src/cegis/control/value/control_types.h deleted file mode 100644 index 395c6f9218d..00000000000 --- a/src/cegis/control/value/control_types.h +++ /dev/null @@ -1,68 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_CONTROL_TYPES_H -#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_TYPES_H - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -const class symbol_typet &control_solution_type(const class symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -const class array_typet &control_vector_solution_type(const class symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -const typet &control_float_value_type(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -const typet &control_array_size_type(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -const typet &control_runtime_array_size_type(const symbol_tablet &st); - -#endif // CPROVER_CEGIS_CONTROL_VALUE_CONTROL_TYPES_H diff --git a/src/cegis/control/value/control_vars.h b/src/cegis/control/value/control_vars.h deleted file mode 100644 index 9a93729c788..00000000000 --- a/src/cegis/control/value/control_vars.h +++ /dev/null @@ -1,28 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VARS_H -#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VARS_H - -#define CEGIS_CONTROL_SOLUTION_VAR_NAME "controller" -#define CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME "K_fxp" -#define __CEGIS_ALTERNATIVE_MEMBER_NAMES -#ifndef __CEGIS_ALTERNATIVE_MEMBER_NAMES -#define CEGIS_CONTROL_A_MEMBER_NAME "a" -#define CEGIS_CONTROL_B_MEMBER_NAME "b" -#define CEGIS_CONTROL_A_SIZE_MEMBER_NAME "a_size" -#define CEGIS_CONTROL_B_SIZE_MEMBER_NAME "b_size" -#else -#define CEGIS_CONTROL_A_MEMBER_NAME "den" -#define CEGIS_CONTROL_B_MEMBER_NAME "num" -#define CEGIS_CONTROL_A_SIZE_MEMBER_NAME "den_size" -#define CEGIS_CONTROL_B_SIZE_MEMBER_NAME "num_size" -#endif - -#endif // CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VARS_H diff --git a/src/cegis/control/value/control_vector_solution.cpp b/src/cegis/control/value/control_vector_solution.cpp deleted file mode 100644 index 9ec0d622f88..00000000000 --- a/src/cegis/control/value/control_vector_solution.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -control_vector_solutiont::control_vector_solutiont() -{ - // TODO Auto-generated constructor stub - -} - -control_vector_solutiont::~control_vector_solutiont() -{ - // TODO Auto-generated destructor stub -} - diff --git a/src/cegis/control/value/control_vector_solution.h b/src/cegis/control/value/control_vector_solution.h deleted file mode 100644 index 6b118960711..00000000000 --- a/src/cegis/control/value/control_vector_solution.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VECTOR_SOLUTION_H -#define CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VECTOR_SOLUTION_H - -#include - - /** - * @brief - * - * @details - */ -class control_vector_solutiont -{ -public: - /** - * @brief - * - * @details - */ - array_exprt K; -}; - -#endif // CPROVER_CEGIS_CONTROL_VALUE_CONTROL_VECTOR_SOLUTION_H diff --git a/src/cegis/control/value/float_helper.cpp b/src/cegis/control/value/float_helper.cpp deleted file mode 100644 index a905061b942..00000000000 --- a/src/cegis/control/value/float_helper.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#define FLOAT_WIDTH 32u - -double to_control_float(const constant_exprt &expr) -{ - const typet &data_type=expr.type(); - if(ID_fixedbv == data_type.id()) - { - // TODO: Implement - assert(false); - } - ieee_floatt ieee_float(expr); - ieee_float.change_spec(ieee_float_spect::double_precision()); - return ieee_float.to_double(); -} - -exprt to_control_float_expr(const symbol_tablet &st, double value) -{ - const typet &data_type=control_float_value_type(st); - if(ID_fixedbv == data_type.id()) - { - const fixedbv_spect spec(to_fixedbv_type(data_type)); - const bool is_neg=value < 0.0; - const mp_integer factor=pow(mp_integer(2), spec.width); - double abs_value=is_neg ? -value : value; - const mp_integer::llong_t converted=factor.to_long() * abs_value; - fixedbvt bv; - bv.spec=spec; - bv.from_integer(converted); - const constant_exprt constant_expr(bv.to_expr()); - if(!is_neg) return constant_expr; - return unary_minus_exprt(constant_expr); - } - ieee_floatt ieee(ieee_float_spect::double_precision()); - ieee.from_double(value); - const exprt result(ieee.to_expr()); - if(type_eq(result.type(), data_type, namespacet(st))) return result; - return typecast_exprt(result, data_type); -} diff --git a/src/cegis/control/value/float_helper.h b/src/cegis/control/value/float_helper.h deleted file mode 100644 index ee1a8652a31..00000000000 --- a/src/cegis/control/value/float_helper.h +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VALUE_FLOAT_HELPER_H -#define CPROVER_CEGIS_CONTROL_VALUE_FLOAT_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param expr - * - * @return - */ -double to_control_float(const constant_exprt &expr); - -/** - * @brief - * - * @details - * - * @param st - * @param value - * - * @return - */ -exprt to_control_float_expr(const class symbol_tablet &st, double value); - -#endif // CPROVER_CEGIS_CONTROL_VALUE_FLOAT_HELPER_H diff --git a/src/cegis/control/verify/control_symex_verify.h b/src/cegis/control/verify/control_symex_verify.h deleted file mode 100644 index e40f8dabce3..00000000000 --- a/src/cegis/control/verify/control_symex_verify.h +++ /dev/null @@ -1,97 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VERIFY_CONTROL_SYMEX_VERIFY_H -#define CPROVER_CEGIS_CONTROL_VERIFY_CONTROL_SYMEX_VERIFY_H - -#include - -#include -#include -#include - -/** - * @brief - * - * @details - */ -template -class control_symex_verifyt -{ - const control_programt &original_program; - control_programt current_program; -public: - typedef control_counterexamplet counterexamplet; - typedef control_counterexamplest counterexamplest; - typedef solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param original_program - */ - explicit control_symex_verifyt(const control_programt &original_program); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void process(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param trace - */ - void convert( - counterexamplest &counterexamples, - const class goto_tracet &trace) const; - - /** - * @brief - * - * @details - * - * @param os - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#include "control_symex_verify.inc" - -#endif // CPROVER_CEGIS_CONTROL_VERIFY_CONTROL_SYMEX_VERIFY_H diff --git a/src/cegis/control/verify/control_symex_verify.inc b/src/cegis/control/verify/control_symex_verify.inc deleted file mode 100644 index eed13008c66..00000000000 --- a/src/cegis/control/verify/control_symex_verify.inc +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -template -control_symex_verifyt::control_symex_verifyt( - const control_programt &original_program) : - original_program(original_program) -{ -} - -template -void control_symex_verifyt::process(const candidatet &candidate) -{ - current_program=original_program; - goto_functionst &gf=current_program.gf; - insert_solution(current_program, candidate); - gf.update(); -} - -template -const symbol_tablet &control_symex_verifyt::get_symbol_table() const -{ - return current_program.st; -} - -template -const goto_functionst &control_symex_verifyt::get_goto_functions() const -{ - return current_program.gf; -} - -template -void control_symex_verifyt::convert( - counterexamplest &counterexamples, const goto_tracet &trace) const -{ - counterexamples.push_back(extract_counterexample(trace)); -} - -template -void control_symex_verifyt::show_counterexample( - messaget::mstreamt &os, const counterexamplet &counterexample) const -{ - show_assignments(os, counterexample); -} diff --git a/src/cegis/control/verify/insert_solution.cpp b/src/cegis/control/verify/insert_solution.cpp deleted file mode 100644 index db4d09d3038..00000000000 --- a/src/cegis/control/verify/insert_solution.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -exprt &get_comp(struct_exprt::operandst &ops, const struct_typet &struct_type, - const char * const comp) -{ - const struct_typet::componentst &comps=struct_type.components(); - const size_t comps_size=comps.size(); - size_t offset=0; - for(offset=0; offset < comps_size; ++offset) - if(id2string(comps[offset].get_name()) == comp) break; - assert(offset < comps_size); - return ops[offset]; -} - -void set_array(struct_exprt::operandst &ops, const symbol_tablet &st, - const struct_typet &struct_type, const array_exprt &array, - const char * const comp) -{ - to_array_expr(get_comp(ops, struct_type, comp))=array; - const typet &size_type=control_runtime_array_size_type(st); - const constant_exprt size(from_integer(array.operands().size(), size_type)); - const char * const sz_comp= - std::string(CEGIS_CONTROL_A_MEMBER_NAME) == comp ? - CEGIS_CONTROL_A_SIZE_MEMBER_NAME : CEGIS_CONTROL_B_SIZE_MEMBER_NAME; - get_comp(ops, struct_type, sz_comp)=size; -} - -struct_exprt to_struct_expr(const symbol_tablet &st, - const control_solutiont &solution, const source_locationt &loc) -{ - const symbol_typet &type=control_solution_type(st); - const namespacet ns(st); - const struct_typet &struct_type=to_struct_type(ns.follow(type)); - const exprt zero(zero_initializer(type, loc, ns)); - struct_exprt result(to_struct_expr(zero)); - struct_exprt::operandst &ops=result.operands(); - set_array(ops, st, struct_type, solution.a, CEGIS_CONTROL_A_MEMBER_NAME); - set_array(ops, st, struct_type, solution.b, CEGIS_CONTROL_B_MEMBER_NAME); - return result; -} -} - -void insert_solution(control_programt &program, - const control_solutiont &solution) -{ - goto_programt &init=get_body(program.gf, CPROVER_INIT); - const goto_programt::targett pos=get_solution_assignment(init); - const symbol_tablet &st=program.st; - const source_locationt &loc=pos->source_location; - to_code_assign(pos->code).rhs()=to_struct_expr(st, solution, loc); -} - -namespace -{ -class is_assignment_tot -{ - const std::string name; -public: - explicit is_assignment_tot(const std::string &name):name(name) - { - } - - bool operator()(const goto_programt::instructiont &instr) const - { - if(goto_program_instruction_typet::ASSIGN != instr.type) return false; - const std::string &var=id2string(get_affected_variable(instr)); - return name == var; - } -}; -} - -void insert_solution(control_programt &program, - const control_vector_solutiont &solution) -{ - goto_programt &init=get_body(program.gf, CPROVER_INIT); - goto_programt::instructionst &instrs=init.instructions; - const goto_programt::targett end(instrs.end()); - const is_assignment_tot pred(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME); - const goto_programt::targett it=std::find_if(instrs.begin(), end, pred); - assert(end != it); - to_code_assign(it->code).rhs()=solution.K; -} diff --git a/src/cegis/control/verify/insert_solution.h b/src/cegis/control/verify/insert_solution.h deleted file mode 100644 index 61e92c29d68..00000000000 --- a/src/cegis/control/verify/insert_solution.h +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VERIFY_INSERT_SOLUTION_H -#define CPROVER_CEGIS_CONTROL_VERIFY_INSERT_SOLUTION_H - -/** - * @brief - * - * @details - * - * @param program - * @param solution - */ -void insert_solution( - class control_programt &program, - const class control_solutiont &solution); - -/** - * @brief - * - * @details - * - * @param program - * @param solution - */ -void insert_solution( - class control_programt &program, - const class control_vector_solutiont &solution); - - -#endif // CPROVER_CEGIS_CONTROL_VERIFY_INSERT_SOLUTION_H diff --git a/src/cegis/control/verify/zero_solutions.cpp b/src/cegis/control/verify/zero_solutions.cpp deleted file mode 100644 index 3b4656b97fb..00000000000 --- a/src/cegis/control/verify/zero_solutions.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include - -bool is_vector_solution_config(const symbol_tablet &st) -{ - return st.has_symbol(CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME); -} - -zero_rational_solutiont::zero_rational_solutiont(const symbol_tablet &st) : - st(st) -{ -} - -namespace -{ -struct_exprt make_zero(const namespacet &ns, const symbol_typet &type) -{ - const source_locationt loc(default_cegis_source_location()); - return to_struct_expr(zero_initializer(type, loc, ns)); -} -} - -void zero_rational_solutiont::operator ()(control_solutiont &solution) const -{ - if(!solution.a.operands().empty()) return; - const symbol_typet &type=control_solution_type(st); - const namespacet ns(st); - const struct_exprt zero_struct=make_zero(ns, type); - solution.a=get_a_controller_comp(ns, zero_struct); - solution.b=get_b_controller_comp(ns, zero_struct); -} - -zero_vector_solutiont::zero_vector_solutiont(const symbol_tablet &st) : - st(st) -{ -} - -void zero_vector_solutiont::operator ()( - control_vector_solutiont &solution) const -{ - if(!solution.K.operands().empty()) return; - const namespacet ns(st); - const array_typet &type=control_vector_solution_type(st); - const source_locationt loc(default_cegis_source_location()); - solution.K=to_array_expr(zero_initializer(type, loc, ns)); -} diff --git a/src/cegis/control/verify/zero_solutions.h b/src/cegis/control/verify/zero_solutions.h deleted file mode 100644 index 3173b8ddb85..00000000000 --- a/src/cegis/control/verify/zero_solutions.h +++ /dev/null @@ -1,80 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_CONTROL_VERIFY_ZERO_SOLUTIONS_H -#define CPROVER_CEGIS_CONTROL_VERIFY_ZERO_SOLUTIONS_H - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -bool is_vector_solution_config(const class symbol_tablet &st); - -/** - * @brief - * - * @details - */ -class zero_rational_solutiont -{ - const symbol_tablet &st; -public: - /** - * @brief - * - * @details - * - * @param st - */ - explicit zero_rational_solutiont(const symbol_tablet &st); - - /** - * @brief - * - * @details - * - * @param solution - */ - void operator()(class control_solutiont &solution) const; -}; - -/** - * @brief - * - * @details - */ -class zero_vector_solutiont -{ - const symbol_tablet &st; -public: - /** - * @brief - * - * @details - * - * @param st - */ - explicit zero_vector_solutiont(const symbol_tablet &st); - - /** - * @brief - * - * @details - * - * @param solution - */ - void operator()(class control_vector_solutiont &solution) const; -}; - -#endif // CPROVER_CEGIS_CONTROL_VERIFY_ZERO_SOLUTIONS_H diff --git a/src/cegis/danger/constraint/danger_constraint_factory.cpp b/src/cegis/danger/constraint/danger_constraint_factory.cpp deleted file mode 100644 index 23f0344c773..00000000000 --- a/src/cegis/danger/constraint/danger_constraint_factory.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include -#include -#include - -#define as_bool danger_component_as_bool - -namespace -{ -symbol_exprt as_var(const std::string &base_name) -{ - const std::string name=get_cegis_meta_name(base_name); - return symbol_exprt(name, cegis_default_integer_type()); -} - -constant_exprt get_min_value() -{ - const typet type(cegis_default_integer_type()); - const bv_spect spec(type); - return from_integer(spec.min_value(), type); -} - -exprt create_danger_constraint(const size_t number_of_loops, const bool use_ranking) -{ - assert(number_of_loops >= 1 && "At least one loop required."); - const constant_exprt min(get_min_value()); - and_exprt root; - root.copy_to_operands(as_bool(get_Dx0())); - for(size_t i=0; i < number_of_loops; ++i) - { - const notequal_exprt D0_x(as_bool(get_Dx(i))); - const notequal_exprt D0_x_prime(as_bool(get_Dx_prime(i))); - const notequal_exprt G0_x(as_bool(get_Gx(i))); - const symbol_exprt R0_x(as_var(get_Rx(i, 0u))); // XXX: Lexicographical ranking? - const symbol_exprt R0_x_prime(as_var(get_Rx_prime(i, 0u))); // XXX: Lexicographical ranking? - const and_exprt D0_x_and_G0_x(D0_x, G0_x); - const not_exprt not_D0_x_and_G0_x(D0_x_and_G0_x); - exprt first_conseq; - if(use_ranking) - { - const binary_predicate_exprt R0_x_gt_min(R0_x, ID_gt, min); - const binary_predicate_exprt R0_x_prime_lt_R0_x(R0_x_prime, ID_lt, R0_x); - first_conseq=and_exprt(R0_x_gt_min, D0_x_prime, R0_x_prime_lt_R0_x); - } else first_conseq=D0_x_prime; - const or_exprt first_implication(not_D0_x_and_G0_x, first_conseq); - root.copy_to_operands(first_implication); - const and_exprt D0_x_and_not_G0_x(D0_x, not_exprt(G0_x)); - const not_exprt not_D0_x_and_not_G0_x(D0_x_and_not_G0_x); - const notequal_exprt D1_x(as_bool(get_Dx(i + 1))); - const notequal_exprt A_x(as_bool(get_Ax())); - exprt second_conseq; - const bool is_last_component=(i == (number_of_loops - 1)); - if(is_last_component) second_conseq=not_exprt(A_x); - else second_conseq=D1_x; - const or_exprt second_implication(not_D0_x_and_not_G0_x, second_conseq); - root.copy_to_operands(second_implication); - } - return root; -} -} - -notequal_exprt danger_component_as_bool(const std::string &base_name) -{ - const constant_exprt rhs(from_integer(0u, cegis_default_integer_type())); - return notequal_exprt(as_var(base_name), rhs); -} - -danger_constraint::danger_constraint(const bool use_ranking) : - use_ranking(use_ranking) -{ -} - -exprt danger_constraint::operator ()(const size_t number_of_loops) const -{ - return create_danger_constraint(number_of_loops, use_ranking); -} diff --git a/src/cegis/danger/constraint/danger_constraint_factory.h b/src/cegis/danger/constraint/danger_constraint_factory.h deleted file mode 100644 index 140e397efb1..00000000000 --- a/src/cegis/danger/constraint/danger_constraint_factory.h +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_CONSTRAINT_DANGER_CONSTRAINT_FACTORY_H -#define CPROVER_CEGIS_DANGER_CONSTRAINT_DANGER_CONSTRAINT_FACTORY_H - -#include - -/** - * @brief - * - * @details - */ -class danger_constraint { - const bool use_ranking; -public: - /** - * @brief - * - * @details - * - * @param use_ranking - */ - explicit danger_constraint(bool use_ranking); - - /** - * @brief - * - * @details - * - * @param number_of_loops - */ - exprt operator()(size_t number_of_loops) const; -}; - -/** - * @brief - * - * @details - * - * @param base_name - * - * @return - */ -notequal_exprt danger_component_as_bool(const std::string &base_name); - -#endif // CPROVER_CEGIS_DANGER_CONSTRAINT_DANGER_CONSTRAINT_FACTORY_H diff --git a/src/cegis/danger/facade/danger_runner.cpp b/src/cegis/danger/facade/danger_runner.cpp deleted file mode 100644 index 3ce2b47b0e0..00000000000 --- a/src/cegis/danger/facade/danger_runner.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_genetic(const optionst &opt) -{ - return opt.get_bool_option(CEGIS_GENETIC); -} - -typedef messaget::mstreamt mstreamt; - -template -int run_statistics(mstreamt &os, const optionst &opt, - const danger_programt &prog, learnt &learn, verifyt &verify, - preproct &preproc) -{ - null_seedt seed; - // danger_literals_seedt seed(prog); // XXX: Benchmark performance - const size_t max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - if(!opt.get_bool_option(CEGIS_STATISTICS)) - return run_cegis(learn, verify, preproc, seed, max_prog_size, os); - cegis_statistics_wrappert stat(learn, verify, os, opt); - return run_cegis(stat, stat, preproc, seed, max_prog_size, os); -} - -template -int run_limited(mstreamt &os, optionst &options, const danger_programt &prog, - danger_verify_configt &config, learnert &learn, verifiert &verify, - preproct &preproc) -{ - if(!options.get_bool_option(CEGIS_LIMIT_WORDSIZE)) - return run_statistics(os, options, prog, learn, verify, preproc); - limited_wordsize_verifyt limited_verify(options, verify, - [&config](const size_t width) - { config.set_max_ce_width(width);}); - return run_statistics(os, options, prog, learn, limited_verify, preproc); -} - -template -int run_parallel(mstreamt &os, optionst &options, const danger_programt &prog, - learnert &learn, preproct &preproc) -{ - danger_verify_configt config(prog); - if(options.get_bool_option(CEGIS_PARALLEL_VERIFY)) - { - parallel_danger_verifiert verify(options, config); - return run_limited(os, options, prog, config, learn, verify, preproc); - } - cegis_symex_verifyt verify(options, config); - return run_limited(os, options, prog, config, learn, verify, preproc); -} - -template -int run_match(mstreamt &os, optionst &opt, const danger_programt &prog, - random_individualt &rnd, instruction_set_info_factoryt &info_fac, - const size_t rounds, fitnesst &fitness, mutatet &mutate, crosst &cross, - convertert &converter, preproct &preproc, symex_learnt &symex_learn) -{ - const size_t symex_head_start=opt.get_unsigned_int_option(CEGIS_SYMEX_HEAD_START); - const individual_to_danger_solution_deserialisert deser(prog, info_fac); - if(opt.get_bool_option(CEGIS_MATCH_SELECT)) - { - typedef match_selectt selectt; - selectt select(fitness.get_test_case_data(), rnd, rounds); - typedef ga_learnt ga_learnt; - ga_learnt ga_learn(opt, rnd, select, mutate, cross, fitness, converter); -#ifndef _WIN32 - if(!opt.get_bool_option(CEGIS_GENETIC_ONLY)) - { - concurrent_learnt learn(ga_learn, symex_learn, - serialise, std::ref(deser), deserialise, symex_head_start); - return run_parallel(os, opt, prog, learn, preproc); - } -#endif - return run_parallel(os, opt, prog, ga_learn, preproc); - } - typedef tournament_selectt selectt; - selectt select(rounds); - typedef ga_learnt ga_learnt; - ga_learnt ga_learn(opt, rnd, select, mutate, cross, fitness, converter); -#ifndef _WIN32 - if(!opt.get_bool_option(CEGIS_GENETIC_ONLY)) - { - concurrent_learnt learn(ga_learn, symex_learn, - serialise, std::ref(deser), deserialise, symex_head_start); - return run_parallel(os, opt, prog, learn, preproc); - } -#endif - return run_parallel(os, opt, prog, ga_learn, preproc); -} - -template -int run_genetic_and_symex(mstreamt &os, optionst &opt, - const danger_programt &prog, preproct &prep) -{ - if(!is_genetic(opt)) - { - danger_learn_configt cfg(prog); - cegis_symex_learnt learn(opt, prep, cfg); - return run_parallel(os, opt, prog, learn, prep); - } - typedef encoded_danger_learn_configt cfgt; - cfgt cfg(prog); - cegis_symex_learnt learn(opt, prep, cfg); - - // Danger program properties and GA settings - danger_program_genetic_settingst set(opt, prog, prep); - lazy_genetic_settingst > lazy(set); - invariant_exec_body_providert body(DANGER_EXECUTE, prog); - instruction_set_info_factoryt info_fac(std::ref(body)); - const size_t rounds=opt.get_unsigned_int_option(CEGIS_ROUNDS); - - // Set-up genetic algorithm - const typet type=cegis_default_integer_type(); // XXX: Currently single user data type. - random_individualt rnd(type, info_fac, lazy); - danger_fitness_configt converter(info_fac, prog); - concrete_fitness_source_providert src( - prog, lazy.max_prog_sz_provider(), DANGER_EXECUTE); - dynamic_danger_test_runnert test_runner(std::ref(src), - lazy.max_prog_sz_per_index_provider()); - typedef lazy_fitnesst fitnesst; - fitnesst fitness(test_runner); - random_mutatet mutate(rnd, lazy.num_consts_provder()); - random_crosst cross(rnd); - return run_match(os, opt, prog, rnd, info_fac, rounds, fitness, mutate, cross, - converter, prep, learn); -} -} - -int run_danger(optionst &options, mstreamt &result, const symbol_tablet &st, - const goto_functionst &gf) -{ - srand(options.get_unsigned_int_option(CEGIS_SEED)); - const bool is_gen=is_genetic(options); - const constant_strategyt str= - is_gen ? genetic_constant_strategy : default_constant_strategy; - danger_preprocessingt preproc(options, st, gf, str); - const danger_programt &prog=preproc.get_danger_program(); - genetic_preprocessingt gen_preproc(options, preproc); - return run_genetic_and_symex(result, options, prog, gen_preproc); -} diff --git a/src/cegis/danger/facade/danger_runner.h b/src/cegis/danger/facade/danger_runner.h deleted file mode 100644 index b25579edfc0..00000000000 --- a/src/cegis/danger/facade/danger_runner.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_FACADE_DANGER_RUNNER_H -#define CPROVER_CEGIS_DANGER_FACADE_DANGER_RUNNER_H - -#include - -/** - * @brief - * - * @details - * - * @param cmdline - * @param options - * @param result - * @param st - * @param gf - * - * @return - */ -int run_danger(class optionst &options, messaget::mstreamt &result, - const class symbol_tablet &st, const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_DANGER_FACADE_DANGER_RUNNER_H diff --git a/src/cegis/danger/genetic/dynamic_danger_test_runner.cpp b/src/cegis/danger/genetic/dynamic_danger_test_runner.cpp deleted file mode 100644 index 8a81346abd8..00000000000 --- a/src/cegis/danger/genetic/dynamic_danger_test_runner.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -dynamic_danger_test_runnert::dynamic_danger_test_runnert( - const std::function &source_code_provider, - const std::function &max_prog_sz) : - source_code_provider(source_code_provider), max_prog_sz(max_prog_sz), shared_library( - LIBRARY_PREFIX, - LIBRARY_SUFFIX), handle(0), fitness_tester(0) -{ -} - -dynamic_danger_test_runnert::~dynamic_danger_test_runnert() -{ - close_fitness_tester_library(handle, fitness_tester); -} - -void dynamic_danger_test_runnert::run_test(individualt &ind, - const counterexamplet &ce, const std::function on_complete) -{ - prepare_fitness_tester_library(handle, fitness_tester, source_code_provider, - shared_library()); - std::deque args; - serialise(args, ce); - serialise(args, ind, max_prog_sz); - - const int argc=args.size(); - std::vector argv; - argv.resize(argc); - for(int i=0; i < argc; ++i) - argv[i]=args[i]; - - on_complete(EXIT_SUCCESS == fitness_tester(argv.data())); -} - -void dynamic_danger_test_runnert::join() -{ -} diff --git a/src/cegis/danger/genetic/dynamic_danger_test_runner.h b/src/cegis/danger/genetic/dynamic_danger_test_runner.h deleted file mode 100644 index ba0be5780a9..00000000000 --- a/src/cegis/danger/genetic/dynamic_danger_test_runner.h +++ /dev/null @@ -1,79 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_GENETIC_DYNAMIC_DANGER_TEST_RUNNER_H -#define CPROVER_CEGIS_DANGER_GENETIC_DYNAMIC_DANGER_TEST_RUNNER_H - -#include - -#include -#include - -#include - -/** - * @brief - * - * @details - */ -class dynamic_danger_test_runnert -{ -public: - typedef int (*fitness_testert)(const unsigned int[]); - typedef void *lib_handlet; -private: - const std::function source_code_provider; - const std::function max_prog_sz; - const temporary_filet shared_library; - lib_handlet handle; - fitness_testert fitness_tester; -public: - typedef std::map counterexamplet; - typedef program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param source_code_provider - * @param max_prog_sz - */ - dynamic_danger_test_runnert( - const std::function &source_code_provider, - const std::function &max_prog_sz); - - /** - * @brief - * - * @details - */ - ~dynamic_danger_test_runnert(); - - /** - * @brief - * - * @details - * - * @param ind - * @param ce - * @param on_complete - */ - void run_test(individualt &ind, const counterexamplet &ce, - std::function on_complete); - - /** - * @brief - * - * @details - */ - void join(); -}; - -#endif // CPROVER_CEGIS_DANGER_GENETIC_DYNAMIC_DANGER_TEST_RUNNER_H diff --git a/src/cegis/danger/meta/literals.h b/src/cegis/danger/meta/literals.h deleted file mode 100644 index f936d14b41b..00000000000 --- a/src/cegis/danger/meta/literals.h +++ /dev/null @@ -1,17 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_META_LITERALS_H -#define CPROVER_CEGIS_DANGER_META_LITERALS_H - -#define DANGER_PREFIX "__CPROVER_danger_" -#define DANGER_EXECUTE DANGER_PREFIX "execute" -#define DANGER_X0_PLACEHOLDER_PREFIX DANGER_PREFIX "x0_" - -#endif // CPROVER_CEGIS_DANGER_META_LITERALS_H diff --git a/src/cegis/danger/meta/meta_variable_names.cpp b/src/cegis/danger/meta/meta_variable_names.cpp deleted file mode 100644 index fff265aa752..00000000000 --- a/src/cegis/danger/meta/meta_variable_names.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -namespace -{ -const char INVARIANT_PREFIX[]=DANGER_PREFIX"D"; -const char SEP='_'; -const char INITIAL_STATE[]="x0"; -} - -std::string get_Dx0() -{ - std::string result(INVARIANT_PREFIX); - result+=SEP; - return result+=INITIAL_STATE; -} - -namespace -{ -std::string build_var_name(const char * const prefix, const size_t loop_id, - const char * const state) -{ - std::string result(prefix); - result+=integer2string(loop_id); - result+=SEP; - return result+=state; -} - -const char STATE_BEFORE_LOOP[]="x"; -} - -std::string get_Dx(const size_t loop_id) -{ - return build_var_name(INVARIANT_PREFIX, loop_id, STATE_BEFORE_LOOP); -} - -namespace -{ -const char STATE_AFTER_LOOP[]="x" CEGIS_PRIME_SUFFIX; -} - -std::string get_Dx_prime(const size_t loop_id) -{ - return build_var_name(INVARIANT_PREFIX, loop_id, STATE_AFTER_LOOP); -} - -namespace -{ -std::string build_var_name(const char * const prefix, const size_t loop_id, - const char * const state, const size_t result_id) -{ - std::string result(prefix); - result+=integer2string(loop_id); - result+=SEP; - result+=state; - result+=SEP; - return result+=integer2string(result_id); -} - -const char RANKING_PREFIX[]=DANGER_PREFIX"R"; -} - -std::string get_Rx(const size_t loop_id, const size_t result_id) -{ - return build_var_name(RANKING_PREFIX, loop_id, STATE_BEFORE_LOOP, result_id); -} - -std::string get_Rx_prime(const size_t loop_id, const size_t result_id) -{ - return build_var_name(RANKING_PREFIX, loop_id, STATE_AFTER_LOOP, result_id); -} - -namespace -{ -const char SKOLEM_PREFIX[]=DANGER_PREFIX"S"; -} - -std::string get_Sx(const size_t loop_id, const size_t result_id) -{ - return build_var_name(SKOLEM_PREFIX, loop_id, STATE_BEFORE_LOOP, result_id); -} diff --git a/src/cegis/danger/meta/meta_variable_names.h b/src/cegis/danger/meta/meta_variable_names.h deleted file mode 100644 index 6a36666713b..00000000000 --- a/src/cegis/danger/meta/meta_variable_names.h +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_META_META_VARIABLE_NAMES_H -#define CPROVER_CEGIS_DANGER_META_META_VARIABLE_NAMES_H - -#include - -/** - * @brief - * - * @details - * - * @return - */ -std::string get_Dx0(); - -/** - * @brief - * - * @details - * - * @param loop_id - * - * @return - */ -std::string get_Dx(const size_t loop_id); - -/** - * @brief - * - * @details - * - * @param loop_id - * - * @return - */ -std::string get_Dx_prime(const size_t loop_id); - -/** - * @brief - * - * @details - * - * @param loop_id - * @param result_id - * - * @return - */ -std::string get_Rx(const size_t loop_id, const size_t result_id); - -/** - * @brief - * - * @details - * - * @param loop_id - * @param result_id - * - * @return - */ -std::string get_Rx_prime(const size_t loop_id, const size_t result_id); - -/** - * @brief - * - * @details - * - * @param loop_id - * @param result_id - * - * @return - */ -std::string get_Sx(const size_t loop_id, const size_t result_id); - -#endif // CPROVER_CEGIS_DANGER_META_META_VARIABLE_NAMES_H diff --git a/src/cegis/danger/options/danger_program.cpp b/src/cegis/danger/options/danger_program.cpp deleted file mode 100644 index 7b9e1d77dae..00000000000 --- a/src/cegis/danger/options/danger_program.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -danger_programt::danger_programt() : - use_ranking(true) -{ -} - -danger_programt::danger_programt(const symbol_tablet &st, - const goto_functionst &gf, const bool use_ranking) : - invariant_programt(st, gf), use_ranking(use_ranking) -{ -} - -danger_programt::~danger_programt() -{ -} - -namespace -{ -class copy_targett -{ - const target_copy_helpert fix; -public: - copy_targett(const goto_functionst &old_gf, goto_functionst &new_gf) : - fix(get_entry_body(old_gf), get_entry_body(new_gf)) - { - } - goto_programt::targett operator()(const goto_programt::targett &target) const - { - return fix(target); - } - danger_programt::danger_meta_vars_positionst operator()( - const danger_programt::danger_meta_vars_positionst &vars) const - { - danger_programt::danger_meta_vars_positionst result; - const goto_programt::targetst &old_r=vars.Rx; - goto_programt::targetst &new_r=result.Rx; - new_r.resize(old_r.size()); - std::transform(old_r.begin(), old_r.end(), new_r.begin(), fix); - const goto_programt::targetst &old_s=vars.Sx; - goto_programt::targetst &new_s=result.Sx; - new_s.resize(old_s.size()); - std::transform(old_s.begin(), old_s.end(), new_s.begin(), fix); - const goto_programt::targetst &old_rp=vars.Rx_prime; - goto_programt::targetst &new_rp=result.Rx_prime; - new_rp.resize(old_rp.size()); - std::transform(old_rp.begin(), old_rp.end(), new_rp.begin(), fix); - return result; - } - danger_programt::loopt operator()(const danger_programt::loopt &loop) const - { - danger_programt::loopt result; - fix(result, loop); - result.danger_meta_variables=operator()(loop.danger_meta_variables); - return result; - } -}; - -danger_programt &assign(danger_programt &lhs, const danger_programt &rhs) -{ - const copy_targett fix(rhs.gf, lhs.gf); - const danger_programt::loopst &old_loops=rhs.loops; - lhs.loops.resize(old_loops.size()); - std::transform(old_loops.begin(), old_loops.end(), lhs.loops.begin(), fix); - lhs.use_ranking=rhs.use_ranking; - return lhs; -} -} - -danger_programt::danger_programt(const danger_programt &other) : - invariant_programt(other), use_ranking(true) -{ - assign(*this, other); -} - -danger_programt &danger_programt::operator =(const danger_programt &other) -{ - invariant_programt::operator =(other); - return assign(*this, other); -} - -invariant_programt::const_invariant_loopst danger_programt::get_loops() const -{ - const_invariant_loopst result(loops.size()); - std::transform(loops.begin(), loops.end(), result.begin(), - [](const loopt &loop) - { return &loop;}); - return result; -} - -invariant_programt::invariant_loopst danger_programt::get_loops() -{ - invariant_loopst result(loops.size()); - std::transform(loops.begin(), loops.end(), result.begin(), [](loopt &loop) - { return &loop;}); - return result; -} - -invariant_programt::invariant_loopt &danger_programt::add_loop() -{ - loops.push_back(loopt()); - return loops.back(); -} diff --git a/src/cegis/danger/options/danger_program.h b/src/cegis/danger/options/danger_program.h deleted file mode 100644 index 96b350d3c7c..00000000000 --- a/src/cegis/danger/options/danger_program.h +++ /dev/null @@ -1,113 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_H -#define CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_H - -#include - -/** - * @brief - * - * @details - */ -class danger_programt: public invariant_programt -{ -public: - /** - * @brief - * - * @details - */ - struct danger_meta_vars_positionst - { - goto_programt::targetst Rx; - goto_programt::targetst Sx; - goto_programt::targetst Rx_prime; - }; - - /** - * @brief - * - * @details - */ - struct loopt: public invariant_loopt - { - danger_meta_vars_positionst danger_meta_variables; - }; - typedef std::vector loopst; - - loopst loops; - bool use_ranking; - - /** - * @brief - * - * @details - */ - danger_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - danger_programt(const danger_programt &other); - - /** - * @brief - * - * @details - * - * @param st - * @param gf - * @param use_ranking - */ - danger_programt( - const symbol_tablet &st, - const goto_functionst &gf, - const bool use_ranking); - - /** - * @brief - * - * @details - */ - virtual ~danger_programt(); - - /** - * @brief - * - * @details - * - * @param other - * - * @return - */ - danger_programt &operator=(const danger_programt &other); - - /** - * @see invariant_programt::get_loops - */ - virtual const_invariant_loopst get_loops() const; - - /** - * @see invariant_programt::get_loops - */ - virtual invariant_loopst get_loops(); - - /** - * @see invariant_programt::add_loop - */ - virtual invariant_loopt &add_loop(); -}; - -#endif // CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_H diff --git a/src/cegis/danger/options/danger_program_genetic_settings.h b/src/cegis/danger/options/danger_program_genetic_settings.h deleted file mode 100644 index 5f0b1e5c034..00000000000 --- a/src/cegis/danger/options/danger_program_genetic_settings.h +++ /dev/null @@ -1,84 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_GENETIC_SETTINGS_H -#define CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_GENETIC_SETTINGS_H - -#include - -/** - * @brief - * - * @details - */ -template -class danger_program_genetic_settingst: public genetic_settingst -{ - const class optionst &opt; - const class danger_programt &prog; - preproct &preproc; -public: - /** - * @brief - * - * @details - * - * @param opt - * @param prog - * @param preproc - */ - danger_program_genetic_settingst(const optionst &opt, - const danger_programt &prog, preproct &preproc); - - /** - * @brief - * - * @details - */ - virtual ~danger_program_genetic_settingst(); - - /** - * @see genetic_settingst::min_prog_sz(size_t) - */ - virtual size_t min_prog_sz(size_t prog_index); - - /** - * @see genetic_settingst::max_prog_sz(size_t) - */ - virtual size_t max_prog_sz(size_t prog_index); - - /** - * @see genetic_settingst::max_prog_sz() - */ - virtual size_t max_prog_sz(); - - /** - * @see genetic_settingst::num_progs() - */ - virtual size_t num_progs(); - - /** - * @see genetic_settingst::num_vars() - */ - virtual size_t num_vars(); - - /** - * @see genetic_settingst::num_consts() - */ - virtual size_t num_consts(); - - /** - * @see genetic_settingst::num_x0() - */ - virtual size_t num_x0(); -}; - -#include "danger_program_genetic_settings.inc" - -#endif // CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_GENETIC_SETTINGS_H diff --git a/src/cegis/danger/options/danger_program_genetic_settings.inc b/src/cegis/danger/options/danger_program_genetic_settings.inc deleted file mode 100644 index 13fd32f6a0b..00000000000 --- a/src/cegis/danger/options/danger_program_genetic_settings.inc +++ /dev/null @@ -1,97 +0,0 @@ -#include - -#include -#include -#include - -template -danger_program_genetic_settingst::danger_program_genetic_settingst( - const optionst &opt, const danger_programt &prog, preproct &preproc) : - opt(opt), prog(prog), preproc(preproc) -{ -} - -template -danger_program_genetic_settingst::~danger_program_genetic_settingst() -{ -} - -template -size_t danger_program_genetic_settingst::min_prog_sz( - const size_t prog_index) -{ - return preproc.get_min_solution_size(); -} - -namespace -{ -const size_t RANKING_PROG_INDEX=1u; -const size_t SKOLEM_PROG_INDEX=2u; -const size_t PROGS_PER_LOOP=3u; -} - -template -size_t danger_program_genetic_settingst::max_prog_sz( - const size_t prog_index) -{ - const size_t user_max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - switch (prog_index) - { - case RANKING_PROG_INDEX: - if (prog.use_ranking) return user_max_prog_size; - return 0u; - case SKOLEM_PROG_INDEX: - { - const size_t loop_index=prog_index / PROGS_PER_LOOP; - const size_t num_skolem=prog.loops[loop_index].skolem_choices.size(); - if (num_skolem == 0u) return 0u; - return std::max(num_skolem, user_max_prog_size); - } - default: - return user_max_prog_size; - } -} - -template -size_t danger_program_genetic_settingst::max_prog_sz() -{ - const size_t user_max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - const danger_programt::loopst &l=prog.loops; - const size_t max_num_skolem= - std::max_element(l.begin(), l.end(), - [](const danger_programt::loopt &l, const danger_programt::loopt &r) - { return l.skolem_choices.size() < r.skolem_choices.size();})->skolem_choices.size(); - return std::max(max_num_skolem, user_max_prog_size); -} - -namespace -{ -const size_t NUM_PROG_TYPES=3u; -} - -template -size_t danger_program_genetic_settingst::num_progs() -{ - return NUM_PROG_TYPES * prog.loops.size(); -} - -template -size_t danger_program_genetic_settingst::num_vars() -{ - operand_variable_idst vars; - get_invariant_variable_ids(prog.st, vars); - return vars.size(); -} - -template -size_t danger_program_genetic_settingst::num_consts() -{ - operand_variable_idst vars; - return get_invariant_variable_ids(prog.st, vars); -} - -template -size_t danger_program_genetic_settingst::num_x0() -{ - return prog.x0_choices.size(); -} diff --git a/src/cegis/danger/options/danger_program_printer.cpp b/src/cegis/danger/options/danger_program_printer.cpp deleted file mode 100644 index 2b200136ff5..00000000000 --- a/src/cegis/danger/options/danger_program_printer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include - -namespace -{ -class danger_program_printert -{ - const namespacet ns; - const goto_programt &body_printer; - messaget::mstreamt &os; - size_t func_count; -public: - danger_program_printert(const danger_programt &prog, messaget::mstreamt &os) : - ns(prog.st), body_printer(get_entry_body(prog.gf)), os(os), func_count(0) - { - } - - void operator()(const goto_programt::instructionst &prog) const - { - /*goto_programt tmp; - tmp.instructions=prog; - tmp.compute_incoming_edges(); - tmp.compute_target_numbers(); - tmp.output(ns, "", os);*/ - // XXX: Debug - for(goto_programt::const_targett it=prog.begin(); it != prog.end(); ++it) - body_printer.output_instruction(ns, "", os, it); - // XXX: Debug - } - - void operator()(const danger_goto_solutiont::danger_programt &prog) - { - const danger_program_printert &print=*this; - os << "Invariant " << func_count << ": " << messaget::endl; - print(prog.invariant); - os << "Ranking " << func_count << ": " << messaget::endl; - print(prog.ranking); - os << "Skolem " << func_count++ << ": " << messaget::endl; - print(prog.skolem); - } -}; - -class expr_printert -{ - const namespacet ns; - goto_programt::targetst::const_iterator current_choice; - messaget::mstreamt &os; -public: - expr_printert(const danger_programt &prog, messaget::mstreamt &os) : - ns(prog.st), current_choice(prog.x0_choices.begin()), os(os) - { - } - - void operator()(const exprt &expr) - { - os << get_affected_variable(**current_choice++) << "="; - os << from_expr(ns, "", expr) << messaget::endl; - } -}; -} - -void print_danger_program(messaget::mstreamt &os, - const danger_programt &program, const danger_goto_solutiont &solution) -{ - const danger_goto_solutiont::nondet_choicest &x0=solution.x0_choices; - const danger_goto_solutiont::danger_programst &progs=solution.danger_programs; - if(x0.empty() && progs.empty()) return; - os << "x0:" << messaget::endl; - const expr_printert x0_printer(program, os); - std::for_each(x0.begin(), x0.end(), x0_printer); - os << "Programs:" << messaget::endl; - const danger_program_printert prog_printer(program, os); - std::for_each(progs.begin(), progs.end(), prog_printer); - os << messaget::eom; -} diff --git a/src/cegis/danger/options/danger_program_printer.h b/src/cegis/danger/options/danger_program_printer.h deleted file mode 100644 index 3891f760374..00000000000 --- a/src/cegis/danger/options/danger_program_printer.h +++ /dev/null @@ -1,28 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_PRINTER_H -#define CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_PRINTER_H - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param program - * @param solution - */ -void print_danger_program(messaget::mstreamt &os, - const class danger_programt &program, - const class danger_goto_solutiont &solution); - -#endif // CPROVER_CEGIS_DANGER_OPTIONS_DANGER_PROGRAM_PRINTER_H diff --git a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp b/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp deleted file mode 100644 index e676b50a800..00000000000 --- a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -class create_skolem_meta_variablest -{ - symbol_tablet &st; - goto_functionst &gf; - const size_t loop_id; - const typet type; - danger_programt::danger_meta_vars_positionst &meta; - goto_programt::targett pos; - size_t skid; -public: - create_skolem_meta_variablest(symbol_tablet &st, goto_functionst &gf, - const size_t loop_id, danger_programt::danger_meta_vars_positionst &meta, - const goto_programt::targett &pos) : - st(st), gf(gf), loop_id(loop_id), type(cegis_default_integer_type()), meta(meta), pos( - pos), skid(0) - { - } - - void operator()(const goto_programt::targett &sklm) - { - const std::string meta_name=get_Sx(loop_id, skid++); - pos=declare_cegis_meta_variable(st, gf, pos, meta_name, type); - const std::string full_meta_name(get_cegis_meta_name(meta_name)); - const symbol_exprt meta_var(st.lookup(full_meta_name).symbol_expr()); - const irep_idt &sklm_name=get_affected_variable(*sklm); - cegis_assign_user_variable(st, gf, sklm, sklm_name, meta_var); - meta.Sx.push_back(pos); - } -}; - -class create_danger_meta_variables_for_loopt -{ - symbol_tablet &st; - goto_functionst &gf; - size_t loop_id; - const bool use_ranking; -public: - explicit create_danger_meta_variables_for_loopt(danger_programt &prog) : - st(prog.st), gf(prog.gf), loop_id(0u), use_ranking(prog.use_ranking) - { - } - - void operator()(danger_programt::loopt &loop) - { - const typet type(cegis_default_integer_type()); - invariant_programt::meta_vars_positionst &im=loop.meta_variables; - danger_programt::danger_meta_vars_positionst &dm=loop.danger_meta_variables; - goto_programt::targett pos=im.Gx; - ++pos; - const size_t ranking_count=1; // XXX: Lexicographical ranking? - if(use_ranking) for(size_t i=0; i < ranking_count; ++i) - { - pos=declare_cegis_meta_variable(st, gf, pos, get_Rx(loop_id, i), type); - dm.Rx.push_back(pos); - } - const goto_programt::targetst &sklm=loop.skolem_choices; - const create_skolem_meta_variablest create_sklm(st, gf, loop_id, dm, pos); - std::for_each(sklm.begin(), sklm.end(), create_sklm); - pos=im.Ix_prime; - if(use_ranking) for(size_t i=0; i < ranking_count; ++i) - { - const std::string rx_prime(get_Rx_prime(loop_id, i)); - pos=declare_cegis_meta_variable(st, gf, pos, rx_prime, type); - dm.Rx_prime.push_back(pos); - } - ++loop_id; - } -}; -} - -void add_ranking_and_skolem_variables(danger_programt &program, - const size_t max_program_length) -{ - danger_programt::loopst &loops=program.loops; - const create_danger_meta_variables_for_loopt create_meta(program); - std::for_each(loops.begin(), loops.end(), create_meta); -} diff --git a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.h b/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.h deleted file mode 100644 index e1cdfb47d1c..00000000000 --- a/src/cegis/danger/preprocess/add_ranking_and_skolem_variables.h +++ /dev/null @@ -1,24 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_PREPROCESS_ADD_RANKING_AND_SKOLEM_VARIABLES_H -#define CPROVER_CEGIS_DANGER_PREPROCESS_ADD_RANKING_AND_SKOLEM_VARIABLES_H - -/** - * @brief - * - * @details - * - * @param program - * @param max_program_length - */ -void add_ranking_and_skolem_variables(class danger_programt &program, - const size_t max_program_length); - -#endif // CPROVER_CEGIS_DANGER_PREPROCESS_ADD_RANKING_AND_SKOLEM_VARIABLES_H diff --git a/src/cegis/danger/preprocess/danger_preprocessing.cpp b/src/cegis/danger/preprocess/danger_preprocessing.cpp deleted file mode 100644 index 642ccffc713..00000000000 --- a/src/cegis/danger/preprocess/danger_preprocessing.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -danger_preprocessingt::danger_preprocessingt(optionst &options, - const symbol_tablet &st, const goto_functionst &gf, - const constant_strategyt &constant_strategy) : - options(options), original_program(st, gf, - !options.get_bool_option("danger-no-ranking")), constant_strategy( - constant_strategy) -{ -} - -danger_preprocessingt::~danger_preprocessingt() -{ -} - -namespace -{ -bool cmp(const danger_programt::loopt &lhs, const danger_programt::loopt &rhs) -{ - return lhs.skolem_choices.size() < rhs.skolem_choices.size(); -} -} - -size_t danger_preprocessingt::get_min_solution_size() const -{ - const danger_programt::loopst &l=original_program.loops; - size_t sklm=std::max_element(l.begin(), l.end(), &cmp)->skolem_choices.size(); - return std::max(sklm, size_t(1u)); -} - -void danger_preprocessingt::operator ()() -{ - const namespacet ns(original_program.st); - null_message_handlert null_msg; - goto_functionst &gf=original_program.gf; - goto_inline(gf, ns, null_msg); - invariant_remove_loops_and_assertion(original_program); - store_skolem_choices(original_program); - store_x0_choices(original_program); - gf.update(); - current_program=original_program; -} - -void danger_preprocessingt::operator ()(const size_t max_length) -{ - current_program=original_program; - const unsigned int max_width=constant_strategy(current_program, max_length); - options.set_option("max-constant-width", max_width); - create_tmp_variables(current_program, max_length); - add_invariant_variables(current_program, get_Dx0(), get_Dx, get_Dx_prime); - add_ranking_and_skolem_variables(current_program, max_length); -} - -const danger_programt &danger_preprocessingt::get_danger_program() const -{ - return current_program; -} diff --git a/src/cegis/danger/preprocess/danger_preprocessing.h b/src/cegis/danger/preprocess/danger_preprocessing.h deleted file mode 100644 index b69ab0813b7..00000000000 --- a/src/cegis/danger/preprocess/danger_preprocessing.h +++ /dev/null @@ -1,81 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_PREPROCESS_DANGER_PREPROCESSING_H -#define CPROVER_CEGIS_DANGER_PREPROCESS_DANGER_PREPROCESSING_H - -#include -#include - -/** - * @brief - * - * @details - */ -class danger_preprocessingt -{ - class optionst &options; - danger_programt original_program; - danger_programt current_program; - const constant_strategyt constant_strategy; -public: - /** - * @brief - * - * @details - * - * @param st - * @param gf - * @param constant_strategy - */ - danger_preprocessingt(optionst &options, const symbol_tablet &st, - const goto_functionst &gf, const constant_strategyt &constant_strategy); - - /** - * @brief - * - * @details - */ - ~danger_preprocessingt(); - - /** - * @brief Provides the minimum solution size. - * - * @details Properties like the number of skolem choices dictate the minimum - * solution size. - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_solution_length - */ - void operator()(const size_t max_solution_length); - - /** - * @brief - * - * @details - * - * @return - */ - const danger_programt &get_danger_program() const; -}; - -#endif // CPROVER_CEGIS_DANGER_PREPROCESS_DANGER_PREPROCESSING_H diff --git a/src/cegis/danger/preprocess/store_nondet_choices.cpp b/src/cegis/danger/preprocess/store_nondet_choices.cpp deleted file mode 100644 index 79da79aa775..00000000000 --- a/src/cegis/danger/preprocess/store_nondet_choices.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -namespace -{ -void store_skolem_choices_for_loop(invariant_programt::invariant_loopt *loop) -{ - const danger_programt::program_ranget &range=loop->body; - const goto_programt::targett &end=range.end; - for(goto_programt::targett it=range.begin; it != end; ++it) - if(is_nondet(it, end)) loop->skolem_choices.push_back(it); -} -} - -void store_skolem_choices(invariant_programt &program) -{ - invariant_programt::invariant_loopst loops(program.get_loops()); - std::for_each(loops.begin(), loops.end(), &store_skolem_choices_for_loop); -} - -namespace -{ -void store_x0_choices_for_range(invariant_programt &program, - const goto_programt::targett &begin, const goto_programt::targett &end) -{ - for(goto_programt::targett it=begin; it != end; ++it) - if(is_nondet(it, end)) program.x0_choices.push_back(it); -} -} - -void store_x0_choices(invariant_programt &program) -{ - goto_programt::targett begin=program.invariant_range.begin; - goto_programt::targett end; - const invariant_programt &prog=program; - const invariant_programt::const_invariant_loopst loops(prog.get_loops()); - for(const invariant_programt::const_invariant_loopst::value_type &loop : loops) - { - end=loop->body.begin; - store_x0_choices_for_range(program, begin, end); - begin=loop->body.end; - } - end=program.invariant_range.end; - store_x0_choices_for_range(program, begin, end); -} diff --git a/src/cegis/danger/preprocess/store_nondet_choices.h b/src/cegis/danger/preprocess/store_nondet_choices.h deleted file mode 100644 index b19a165c624..00000000000 --- a/src/cegis/danger/preprocess/store_nondet_choices.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_PREPROCESS_STORE_NONDET_CHOICES_H -#define CPROVER_CEGIS_DANGER_PREPROCESS_STORE_NONDET_CHOICES_H - -/** - * @brief - * - * @details - * - * @param program - */ -void store_skolem_choices(class invariant_programt &program); - -/** - * @brief - * - * @details - * - * @param program - */ -void store_x0_choices(invariant_programt &program); - -#endif // CPROVER_CEGIS_DANGER_PREPROCESS_STORE_NONDET_CHOICES_H diff --git a/src/cegis/danger/symex/fitness/danger_fitness_config.cpp b/src/cegis/danger/symex/fitness/danger_fitness_config.cpp deleted file mode 100644 index a5b3e143435..00000000000 --- a/src/cegis/danger/symex/fitness/danger_fitness_config.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -danger_fitness_configt::danger_fitness_configt( - instruction_set_info_factoryt &info_fac, const danger_programt &prog) : - info_fac(info_fac), original_program(prog), constraint_inserted(false), program_contains_ce( - false), max_solution_size(0u) -{ -} - -danger_fitness_configt::~danger_fitness_configt() -{ -} - -void danger_fitness_configt::convert(candidatet ¤t_candidate, - const individualt &ind) -{ - operand_variable_idst ids; - get_invariant_variable_ids(original_program.st, ids); - const instruction_sett &instrs=info_fac.get_instructions(); - create_danger_solution(current_candidate, original_program, ind, instrs, ids); -} - -namespace -{ -void fix_quantifiers(const danger_programt &org_prog, danger_programt &new_prog, - goto_programt::targetst &quantifiers) -{ - goto_programt::const_targett org_off=org_prog.loops.front().meta_variables.Ix; - --org_off; - goto_programt::targett new_off=new_prog.loops.front().meta_variables.Ix; - --new_off; - goto_programt::targett::difference_type diff; - for(goto_programt::targett &q : quantifiers) - { - diff=std::distance(org_off, static_cast(q)); - q=new_off; - std::advance(q, diff); - } -} -} - -void danger_fitness_configt::set_candidate(const candidatet &candidate) -{ - if(!constraint_inserted) - { - program_with_constraint=original_program; - const danger_constraint constraint(program_with_constraint.use_ranking); - invariant_insert_constraint(original_quantifiers, program_with_constraint, - std::cref(constraint)); - constraint_inserted=true; - } - program=program_with_constraint; - quantifiers=original_quantifiers; - fix_quantifiers(program_with_constraint, program, quantifiers); - program_contains_ce=false; - danger_insert_candidate(program, candidate); -} - -void danger_fitness_configt::set_test_case(const counterexamplet &ce) -{ - if(quantifiers.empty()) return; - goto_functionst &gf=program.gf; - for(goto_programt::targett quantifier : quantifiers) - { - const irep_idt &var=get_affected_variable(*quantifier); - const counterexamplet::const_iterator it=ce.find(var); - if(ce.end() == it) continue; - symbol_tablet &st=program.st; - if(program_contains_ce) - { - goto_programt::targett assignment=quantifier; - erase_target(get_entry_body(gf).instructions, ++assignment); - } - cegis_assign_user_variable(st, gf, quantifier, var, it->second); - } - gf.update(); - program_contains_ce=true; -} - -const symbol_tablet &danger_fitness_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &danger_fitness_configt::get_goto_functions() const -{ - return program.gf; -} - -void danger_fitness_configt::set_max_solution_size(const size_t size) -{ - max_solution_size=size; -} - -void danger_fitness_configt::show(messaget::mstreamt &os, - const candidatet &candidate) const -{ - print_danger_program(os, original_program, candidate); -} diff --git a/src/cegis/danger/symex/fitness/danger_fitness_config.h b/src/cegis/danger/symex/fitness/danger_fitness_config.h deleted file mode 100644 index d2fb750aa6c..00000000000 --- a/src/cegis/danger/symex/fitness/danger_fitness_config.h +++ /dev/null @@ -1,120 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_FITNESS_DANGER_FITNESS_CONFIG_H -#define CPROVER_CEGIS_DANGER_SYMEX_FITNESS_DANGER_FITNESS_CONFIG_H - -#include - -/** - * @brief - * - * @details - */ -class danger_fitness_configt -{ - class instruction_set_info_factoryt &info_fac; - const danger_programt &original_program; - danger_programt program_with_constraint; - goto_programt::targetst original_quantifiers; - danger_programt program; - goto_programt::targetst quantifiers; - bool constraint_inserted; - bool program_contains_ce; - size_t max_solution_size; -public: - typedef class danger_goto_solutiont candidatet; - typedef std::map counterexamplet; - typedef class program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param info_fac - * @param prog - */ - danger_fitness_configt(instruction_set_info_factoryt &info_fac, - const danger_programt &prog); - - /** - * @brief - * - * @details - */ - ~danger_fitness_configt(); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void set_candidate(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @param ce - */ - void set_test_case(const counterexamplet &ce); - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param ind - */ - void convert(candidatet ¤t_candidate, const individualt &ind); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param size - */ - void set_max_solution_size(size_t size); - - /** - * @brief - * - * @details - * - * @param candidate - * @param os - */ - void show(messaget::mstreamt &os, const candidatet &candidate) const; -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_FITNESS_DANGER_FITNESS_CONFIG_H diff --git a/src/cegis/danger/symex/learn/add_programs_to_learn.cpp b/src/cegis/danger/symex/learn/add_programs_to_learn.cpp deleted file mode 100644 index 6404d6ba743..00000000000 --- a/src/cegis/danger/symex/learn/add_programs_to_learn.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -class declare_danger_programst -{ - danger_programt &prog; - const size_t max_sol_sz; - goto_programt::targett pos; -public: - declare_danger_programst(danger_programt &prog, - const size_t max_solution_size, const goto_programt::targett &pos) : - prog(prog), max_sol_sz(max_solution_size), pos(pos) - { - } - - void operator()(const danger_programt::loopt &loop) - { - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - const danger_programt::danger_meta_vars_positionst &dm= - loop.danger_meta_variables; - const goto_programt::targetst &rx=dm.Rx; - const goto_programt::targetst &rx_prime=dm.Rx_prime; - if(!rx.empty() && !rx_prime.empty()) - { - const goto_programt::targett rx_prog=*rx.rbegin(); - pos=add_inv_prog(prog, pos, max_sol_sz, rx_prog); - const std::string rx_prog_name=get_prog_var_name(st, rx_prog); - execute_inv_prog(st, gf, max_sol_sz, *rx_prime.rbegin(), rx_prog_name); - } - const goto_programt::targetst &sx=dm.Sx; - if(!sx.empty()) pos=add_inv_prog(prog, pos, max_sol_sz, *sx.rbegin()); - } -}; -} - -void danger_add_programs_to_learn(danger_programt &prog, const size_t max_sz) -{ - const danger_programt::loopst &loops=prog.loops; - if(loops.empty()) return; - const goto_programt::targett pos=add_invariant_progs_to_learn(prog, max_sz); - const declare_danger_programst declare_danger_progs(prog, max_sz, pos); - std::for_each(loops.begin(), loops.end(), declare_danger_progs); - const danger_programt::loopt first_loop=*loops.begin(); - const symbol_tablet &st=prog.st; - const std::string D0=get_prog_var_name(st, first_loop.meta_variables.Ix); - execute_inv_prog(st, prog.gf, max_sz, prog.Ix0, D0); -} diff --git a/src/cegis/danger/symex/learn/add_programs_to_learn.h b/src/cegis/danger/symex/learn/add_programs_to_learn.h deleted file mode 100644 index c8f1278c240..00000000000 --- a/src/cegis/danger/symex/learn/add_programs_to_learn.h +++ /dev/null @@ -1,23 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_PROGRAMS_TO_LEARN_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_PROGRAMS_TO_LEARN_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void danger_add_programs_to_learn(class danger_programt &prog, - const size_t max_solution_size); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_PROGRAMS_TO_LEARN_H diff --git a/src/cegis/danger/symex/learn/add_variable_refs.cpp b/src/cegis/danger/symex/learn/add_variable_refs.cpp deleted file mode 100644 index aacce395c14..00000000000 --- a/src/cegis/danger/symex/learn/add_variable_refs.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -void link_skolem(danger_programt &prog, const size_t num_user_vars, - const size_t user_vars, const size_t max_solution_size, - const danger_programt::loopt &loop) -{ - const goto_programt::targetst &sklm=loop.danger_meta_variables.Sx; - if(sklm.empty()) return; - const symbol_tablet &st=prog.st; - goto_programt &body=get_entry_body(prog.gf); - goto_programt::targett pos=sklm.front(); - const size_t num_skolem=sklm.size(); - const size_t num_tmp=max_solution_size - num_skolem; - link_temp_vars(st, body, --pos, num_tmp, user_vars); - goto_programt::targetst::const_iterator it=sklm.begin(); - for(size_t i=0; i < num_skolem - 1; ++i, ++it) - { - pos=*it; - const goto_programt::instructiont &instr=*pos; - const size_t id=num_tmp + i; - const irep_idt &variable=get_affected_variable(instr); - pos=set_rops_reference(st, body, pos, variable, id); - pos=set_ops_reference(st, body, pos, variable, id + num_user_vars); - } - pos=sklm.back(); - const size_t final_id=max_solution_size - 1; - set_rops_reference(st, body, pos, get_affected_variable(*pos), final_id); -} - -class link_meta_variablest -{ - danger_programt &prog; - const size_t user_vars; - const size_t max_size; -public: - link_meta_variablest(danger_programt &prog, const size_t num_user_vars, - const size_t max_solution_size) : - prog(prog), user_vars(num_user_vars), max_size(max_solution_size) - { - } - - void operator()(const invariant_programt::invariant_loopt &loop) const - { - const invariant_programt::meta_vars_positionst &im=loop.meta_variables; - link_result_var(prog.st, prog.gf, user_vars, max_size, im.Ix); - link_result_var(prog.st, prog.gf, user_vars, max_size, im.Ix_prime); - } - - void operator()(const danger_programt::loopt &loop) const - { - operator()(static_cast(loop)); - const danger_programt::danger_meta_vars_positionst &dm= - loop.danger_meta_variables; - auto inv=[this](const goto_programt::targett &pos) - { link_result_var(prog.st, prog.gf, user_vars, max_size, pos);}; - std::for_each(dm.Rx.begin(), dm.Rx.end(), inv); - std::for_each(dm.Rx_prime.begin(), dm.Rx_prime.end(), inv); - link_skolem(prog, user_vars, user_vars, max_size, loop); - } -}; -} - -void link_meta_variables(danger_programt &prog, const size_t user_vars, - const size_t max_solution_size) -{ - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - link_result_var(st, gf, user_vars, max_solution_size, prog.Ix0); - const danger_programt::loopst &loops=prog.loops; - const link_meta_variablest link(prog, user_vars, max_solution_size); - std::for_each(loops.begin(), loops.end(), link); -} diff --git a/src/cegis/danger/symex/learn/add_variable_refs.h b/src/cegis/danger/symex/learn/add_variable_refs.h deleted file mode 100644 index aa275c149dd..00000000000 --- a/src/cegis/danger/symex/learn/add_variable_refs.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_VARIABLE_REFS_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_VARIABLE_REFS_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param user_vars - * @param max_solution_size - */ -void link_meta_variables(danger_programt &prog, const size_t user_vars, - const size_t max_solution_size); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_VARIABLE_REFS_H diff --git a/src/cegis/danger/symex/learn/add_x0_placeholders.cpp b/src/cegis/danger/symex/learn/add_x0_placeholders.cpp deleted file mode 100644 index 206ad30aaf7..00000000000 --- a/src/cegis/danger/symex/learn/add_x0_placeholders.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include - -namespace -{ -const typet &get_type(const goto_programt::targett &target) -{ - const goto_programt::instructiont &instr=*target; - switch(instr.type) - { - case goto_program_instruction_typet::DECL: - return to_code_decl(instr.code).symbol().type(); - case goto_program_instruction_typet::ASSIGN: - return to_code_assign(instr.code).lhs().type(); - default: - assert(!"Only DECL or ASSIGN supported."); - } -} - -class add_x0_placeholdert -{ - danger_programt &prog; - symbol_tablet &st; - goto_functionst &gf; -public: - explicit add_x0_placeholdert(danger_programt &prog) : - prog(prog), st(prog.st), gf(prog.gf) - { - } - - void operator()(const goto_programt::targett &target) const - { - const irep_idt &x0_name=get_affected_variable(*target); - std::string base_name(DANGER_X0_PLACEHOLDER_PREFIX); - base_name+=id2string(x0_name); - goto_programt::targett pos=prog.invariant_range.begin; - const typet &type=get_type(target); - declare_cegis_meta_variable(st, gf, --pos, base_name, type); - const std::string full_name(get_cegis_meta_name(base_name)); - const symbol_exprt placeholder(full_name, type); - cegis_assign_user_variable(st, gf, target, x0_name, placeholder); - } -}; -} - -void danger_add_x0_placeholders(danger_programt &prog) -{ - const goto_programt::targetst &x0=prog.x0_choices; - const add_x0_placeholdert add_placeholder(prog); - std::for_each(x0.begin(), x0.end(), add_placeholder); -} diff --git a/src/cegis/danger/symex/learn/add_x0_placeholders.h b/src/cegis/danger/symex/learn/add_x0_placeholders.h deleted file mode 100644 index f5ae6f3fbcf..00000000000 --- a/src/cegis/danger/symex/learn/add_x0_placeholders.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_X0_PLACEHOLDERS_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_X0_PLACEHOLDERS_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void danger_add_x0_placeholders(class danger_programt &prog); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_ADD_X0_PLACEHOLDERS_H diff --git a/src/cegis/danger/symex/learn/danger_learn_config.cpp b/src/cegis/danger/symex/learn/danger_learn_config.cpp deleted file mode 100644 index a955ac49257..00000000000 --- a/src/cegis/danger/symex/learn/danger_learn_config.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -danger_learn_configt::danger_learn_configt(const danger_programt &program) : - original_program(program), num_consts(0u) -{ -} - -danger_learn_configt::~danger_learn_configt() -{ -} - -void danger_learn_configt::process(const counterexamplest &ces, - const size_t max_sz) -{ - program=original_program; - var_ids.clear(); - num_consts=get_invariant_variable_ids(program.st, var_ids); - const size_t num_vars=var_ids.size(); - null_message_handlert msg; - const std::string name(DANGER_EXECUTE); - symbol_tablet &st=program.st; - goto_functionst &gf=program.gf; - add_cegis_library(st, gf, msg, num_vars, num_consts, max_sz, name); - link_user_program_variables(program, var_ids); - link_meta_variables(program, var_ids.size(), max_sz); - danger_add_programs_to_learn(program, max_sz); - danger_add_x0_placeholders(program); - const danger_constraint constr(program.use_ranking); - invariant_add_learned_counterexamples(program, ces, std::cref(constr), true); - gf.update(); -} - -void danger_learn_configt::process(const size_t max_solution_size) -{ - constraint_varst ce_vars; - get_invariant_constraint_vars(ce_vars, original_program); - counterexamplet dummy_ce; - const typet type(cegis_default_integer_type()); // XXX: Currently single data type - const exprt zero(from_integer(0, type)); - for(const symbol_exprt &var : ce_vars) - dummy_ce.insert(std::make_pair(var.get_identifier(), zero)); - counterexamplest empty(1, dummy_ce); - process(empty, max_solution_size); -} - -void danger_learn_configt::set_word_width(const size_t word_width_in_bits) -{ - restrict_bv_size(program, word_width_in_bits); - program.gf.update(); -} - -const symbol_tablet &danger_learn_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &danger_learn_configt::get_goto_functions() const -{ - return program.gf; -} - -const danger_programt &danger_learn_configt::get_danger_program() const -{ - return program; -} - -void danger_learn_configt::convert(candidatet &candidate, - const class goto_tracet &trace, const size_t max_solution_size) -{ - candidate.danger_programs.clear(); - candidate.x0_choices.clear(); - create_danger_solution(candidate, program, trace, var_ids, max_solution_size); -} - -void danger_learn_configt::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) -{ - print_danger_program(os, program, candidate); -} - -const danger_learn_configt::invariant_variable_idst &danger_learn_configt::get_vars() const -{ - return var_ids; -} - -size_t danger_learn_configt::get_num_vars() const -{ - return var_ids.size(); -} - -size_t danger_learn_configt::get_num_consts() const -{ - return num_consts; -} diff --git a/src/cegis/danger/symex/learn/danger_learn_config.h b/src/cegis/danger/symex/learn/danger_learn_config.h deleted file mode 100644 index 15be7ace25f..00000000000 --- a/src/cegis/danger/symex/learn/danger_learn_config.h +++ /dev/null @@ -1,179 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_DANGER_LEARN_CONFIG_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_DANGER_LEARN_CONFIG_H - -#include - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class danger_learn_configt -{ -public: - /** - * @brief - * - * @details - */ - typedef std::map invariant_variable_idst; -private: - const danger_programt &original_program; - danger_programt program; - invariant_variable_idst var_ids; - size_t num_consts; -public: - /** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ - typedef std::map counterexamplet; - typedef std::deque counterexamplest; - - /** - * @brief Candidate solution type for this CEGIS component. - * - * @details Solutions are provided as a set of GOTO function bodies - * (goto_programt::instructionst) for function names. - */ - typedef danger_goto_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit danger_learn_configt(const danger_programt &program); - - /** - * @brief - * - * @details - */ - ~danger_learn_configt(); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process(const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief Process the goto program using template data. - * - * @details Creates template counterexamples and processes the goto - * program with them. This is useful for GA source code generation. - * - * @param max_solution_size - */ - void process(size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @return - */ - const danger_programt &get_danger_program() const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert(candidatet ¤t_candidate, const class goto_tracet &trace, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate(messaget::mstreamt &os, const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const invariant_variable_idst &get_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_consts() const; -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_DANGER_LEARN_CONFIG_H diff --git a/src/cegis/danger/symex/learn/encoded_danger_learn_config.cpp b/src/cegis/danger/symex/learn/encoded_danger_learn_config.cpp deleted file mode 100644 index d9a995f3821..00000000000 --- a/src/cegis/danger/symex/learn/encoded_danger_learn_config.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -encoded_danger_learn_configt::encoded_danger_learn_configt( - const danger_programt &program) : - danger_learn_config(program) -{ -} - -encoded_danger_learn_configt::~encoded_danger_learn_configt() -{ -} - -void encoded_danger_learn_configt::process( - const counterexamplest &counterexamples, const size_t max_solution_size) -{ - danger_learn_config.process(counterexamples, max_solution_size); -} - -void encoded_danger_learn_configt::set_word_width( - const size_t word_width_in_bits) -{ - danger_learn_config.set_word_width(word_width_in_bits); -} - -const symbol_tablet &encoded_danger_learn_configt::get_symbol_table() const -{ - return danger_learn_config.get_symbol_table(); -} - -const goto_functionst &encoded_danger_learn_configt::get_goto_functions() const -{ - return danger_learn_config.get_goto_functions(); -} - -void encoded_danger_learn_configt::convert(candidatet &candidate, - const class goto_tracet &trace, const size_t max_solution_size) -{ - const danger_programt &prog=danger_learn_config.get_danger_program(); - candidate=to_program_individual(prog, trace); -} - -void encoded_danger_learn_configt::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) -{ - const danger_programt &prog=danger_learn_config.get_danger_program(); - const danger_learn_configt::invariant_variable_idst &vars= - danger_learn_config.get_vars(); - danger_goto_solutiont converted; - create_danger_solution(converted, prog, candidate, vars); - danger_learn_config.show_candidate(os, converted); -} - -size_t encoded_danger_learn_configt::get_num_vars() const -{ - return danger_learn_config.get_num_vars(); -} - -size_t encoded_danger_learn_configt::get_num_consts() const -{ - return danger_learn_config.get_num_consts(); -} diff --git a/src/cegis/danger/symex/learn/encoded_danger_learn_config.h b/src/cegis/danger/symex/learn/encoded_danger_learn_config.h deleted file mode 100644 index f618b1c2f69..00000000000 --- a/src/cegis/danger/symex/learn/encoded_danger_learn_config.h +++ /dev/null @@ -1,125 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_ENCODED_DANGER_LEARN_CONFIG_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_ENCODED_DANGER_LEARN_CONFIG_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class encoded_danger_learn_configt -{ - danger_learn_configt danger_learn_config; -public: - typedef danger_learn_configt::counterexamplet counterexamplet; - typedef danger_learn_configt::counterexamplest counterexamplest; - typedef program_individualt candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit encoded_danger_learn_configt(const danger_programt &program); - - /** - * @brief - * - * @details - */ - ~encoded_danger_learn_configt(); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process(const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert(candidatet ¤t_candidate, const class goto_tracet &trace, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate(messaget::mstreamt &os, const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_consts() const; -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_ENCODED_DANGER_LEARN_CONFIG_H diff --git a/src/cegis/danger/symex/learn/read_x0.cpp b/src/cegis/danger/symex/learn/read_x0.cpp deleted file mode 100644 index 7240f18424c..00000000000 --- a/src/cegis/danger/symex/learn/read_x0.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_placeholder_of(const goto_programt::targett &x0, - const goto_programt::const_targett &placeholder) -{ - const goto_programt::instructiont &placeholder_instr=*placeholder; - if(goto_program_instruction_typet::DECL != placeholder_instr.type) - return false; - std::string placeholder_base(DANGER_X0_PLACEHOLDER_PREFIX); - placeholder_base+=id2string(get_affected_variable(*x0)); - const std::string placeholder_name(get_cegis_meta_name(placeholder_base)); - return placeholder_name == id2string(get_affected_variable(placeholder_instr)); -} - -class extract_x0_choice -{ - danger_goto_solutiont &result; - const goto_tracet &trace; - goto_tracet::stepst::const_iterator current_step; -public: - extract_x0_choice(danger_goto_solutiont &result, const goto_tracet &trace) : - result(result), trace(trace) - { - assert(!trace.steps.empty()); - current_step=trace.steps.begin(); - } - - void operator()(const goto_programt::targett &x0) - { - const goto_tracet::stepst::const_iterator end(trace.steps.end()); - while(end != current_step && !is_placeholder_of(x0, current_step->pc)) - ++current_step; - assert(end != current_step); - result.x0_choices.push_back(current_step->full_lhs_value); - } -}; -} - -void danger_read_x0(danger_goto_solutiont &result, const danger_programt &prog, - const goto_tracet &trace) -{ - const goto_programt::targetst &x0=prog.x0_choices; - const extract_x0_choice extract(result, trace); - std::for_each(x0.begin(), x0.end(), extract); -} - -void danger_read_x0(program_individualt &ind, const danger_programt &prog, - const goto_tracet &trace) -{ - danger_goto_solutiont tmp; - danger_read_x0(tmp, prog, trace); - program_individualt::x0t &x0=ind.x0; - for(const danger_goto_solutiont::nondet_choicest::value_type &choice : tmp.x0_choices) - { - const bv_arithmetict arith(choice); - const mp_integer::llong_t value=arith.to_integer().to_long(); - x0.push_back(static_cast(value)); - } -} diff --git a/src/cegis/danger/symex/learn/read_x0.h b/src/cegis/danger/symex/learn/read_x0.h deleted file mode 100644 index b47620bac74..00000000000 --- a/src/cegis/danger/symex/learn/read_x0.h +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_READ_X0_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_READ_X0_H - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param trace - */ -void danger_read_x0(class danger_goto_solutiont &result, - const class danger_programt &prog, const class goto_tracet &trace); - -/** - * @brief - * - * @details - * - * @param ind - * @param prog - * @param trace - */ -void danger_read_x0(class program_individualt &ind, const danger_programt &prog, - const goto_tracet &trace); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_READ_X0_H diff --git a/src/cegis/danger/symex/learn/solution_factory.cpp b/src/cegis/danger/symex/learn/solution_factory.cpp deleted file mode 100644 index b548724e991..00000000000 --- a/src/cegis/danger/symex/learn/solution_factory.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -size_t create_temps(invariant_variable_namest &rnames, const size_t num_tmp) -{ - for(size_t i=0; i < num_tmp; ++i) - rnames.insert(std::make_pair(i, get_cegis_meta_name(get_tmp(i)))); - return num_tmp; -} - -typedef enum -{ - INV, RNK, SKO -} prog_typet; - -goto_programt::instructionst &get_prog( - danger_goto_solutiont::danger_programst &progs, const prog_typet type, - const size_t instr_idx) -{ - switch(type) - { - case INV: - if(!instr_idx) progs.push_back(danger_goto_solutiont::danger_programt()); - return progs.back().invariant; - case SKO: - return progs.back().skolem; - case RNK: - return progs.back().ranking; - default: - return progs.back().invariant; - } -} - -// TODO: Replace construct by name prefixes for programs -class read_instrt -{ - danger_goto_solutiont::danger_programst &progs; - const danger_programt &danger_prog; - const invariant_variable_namest &names; - invariant_variable_namest rnames; - const instruction_sett &instrset; - size_t prog_size; - size_t loop_index; - size_t insidx; - prog_typet prog_type; - - void switch_prog() - { - insidx=0; - rnames.clear(); - switch(prog_type) - { - case INV: - { - if(prog_size) - { - const size_t idx=create_temps(rnames, prog_size - 1); - const std::string result(get_cegis_meta_name(get_Rx(loop_index, 0))); // XXX: Lexicographical ranking? - rnames.insert(std::make_pair(idx, result)); - } - prog_type=RNK; - break; - } - case RNK: - { - const danger_programt::loopt &loop=danger_prog.loops[loop_index]; - const size_t num_skolem=loop.skolem_choices.size(); - const size_t num_temps=create_temps(rnames, prog_size - num_skolem); - for(size_t i=num_temps; i < prog_size; ++i) - { - const size_t sk=i - num_temps; - const std::string name(get_cegis_meta_name(get_Sx(loop_index, sk))); - rnames.insert(std::make_pair(i, name)); - } - prog_type=SKO; - ++loop_index; - break; - } - case SKO: - { - const size_t idx=create_temps(rnames, prog_size - 1); - const std::string result_name( - get_cegis_meta_name(get_Dx(loop_index))); - rnames.insert(std::make_pair(idx, result_name)); - prog_type=INV; - break; - } - } - } -public: - read_instrt(danger_goto_solutiont::danger_programst &progs, - const danger_programt &danger_prog, const invariant_variable_namest &names, - const instruction_sett &instrset, const size_t prog_size) : - progs(progs), danger_prog(danger_prog), names(names), instrset(instrset), prog_size( - prog_size), loop_index(0u), insidx(0u), prog_type(SKO) - { - switch_prog(); - } - - read_instrt(danger_goto_solutiont::danger_programst &progs, - const danger_programt &danger_prog, const invariant_variable_namest &names, - const instruction_sett &instrset) : - progs(progs), danger_prog(danger_prog), names(names), instrset(instrset), prog_size( - 0u), loop_index(0u), insidx(0u), prog_type(SKO) - { - } - - void operator()(const program_individualt::instructiont &instruction) - { - const program_individualt::instructiont::opcodet opcode=instruction.opcode; - const instruction_sett::const_iterator instr_entry=instrset.find(opcode); - assert(instrset.end() != instr_entry); - goto_programt::instructionst &prog=get_prog(progs, prog_type, insidx); - const goto_programt::instructionst &instr=instr_entry->second; - goto_programt::targett first=prog.end(); - const goto_programt::targett last=prog.end(); - copy_instructionst copy_instr; - for(goto_programt::const_targett it=instr.begin(); it != instr.end(); ++it) - { - prog.push_back(goto_programt::instructiont()); - goto_programt::targett new_instr=prog.end(); - copy_instr(--new_instr, it); - } - copy_instr.finalize(); - std::advance(first, -instr.size()); - const program_individualt::instructiont::opst &ops=instruction.ops; - const size_t empty_op=0u; - const size_t op0=!ops.empty() ? ops.front() : empty_op; - const size_t op1=ops.size() >= 2 ? ops.at(1) : empty_op; - const size_t op2=ops.size() >= 3 ? ops.at(2) : empty_op; - const symbol_tablet &st=danger_prog.st; - replace_ops_in_instr(st, DANGER_EXECUTE, first, last, names, rnames, op0, - op1, op2, insidx); - if(++insidx % prog_size == 0) invariant_make_presentable(prog); - } - - void operator()(const exprt &prog_arary_member) - { - const struct_exprt &instr_rep=to_struct_expr(prog_arary_member); - operator()(to_program_individual_instruction(instr_rep)); - if(insidx % prog_size == 0) switch_prog(); - } - - void set_prog_size(const size_t prog_size) - { - this->prog_size=prog_size; - switch_prog(); - } -}; - -class extract_programt -{ - read_instrt read_instr; -public: - extract_programt(danger_goto_solutiont::danger_programst &progs, - const danger_programt &prog, const invariant_variable_namest &names, - const instruction_sett &instrset, const size_t max_size) : - read_instr(progs, prog, names, instrset, max_size) - { - } - - void operator()(const goto_trace_stept &step) - { - if(!is_program_individual_decl(step)) return; - for(const exprt &prog_array_member : step.full_lhs_value.operands()) - read_instr(prog_array_member); - } -}; - -void extract_programs(danger_goto_solutiont::danger_programst &progs, - const danger_programt &prog, const goto_tracet &trace, - const invariant_variable_namest &names, const instruction_sett &instrset, - const size_t max_size) -{ - const extract_programt extract(progs, prog, names, instrset, max_size); - std::for_each(trace.steps.begin(), trace.steps.end(), extract); -} - -void extract_instruction_set(instruction_sett &instr_set, - const goto_functionst &gf) -{ - typedef goto_functionst::function_mapt function_mapt; - const function_mapt &function_map=gf.function_map; - const function_mapt::const_iterator it=function_map.find(DANGER_EXECUTE); - assert(function_map.end() != it); - instr_set=extract_instruction_set(it->second.body); -} -} - -void create_danger_solution(danger_goto_solutiont &result, - const danger_programt &prog, const goto_tracet &trace, - const operand_variable_idst &ids, const size_t max_size) -{ - invariant_variable_namest names; - reverse_invariant_var_ids(names, ids); - instruction_sett instr_set; - extract_instruction_set(instr_set, prog.gf); - danger_goto_solutiont::danger_programst &progs=result.danger_programs; - extract_programs(progs, prog, trace, names, instr_set, max_size); - danger_read_x0(result, prog, trace); -} - -void create_danger_solution(danger_goto_solutiont &result, - const danger_programt &prog, const program_individualt &ind, - const instruction_sett &instr_set, const operand_variable_idst &ids) -{ - invariant_variable_namest names; - reverse_invariant_var_ids(names, ids); - danger_goto_solutiont::danger_programst &progs=result.danger_programs; - progs.clear(); - typedef program_individualt individualt; - const individualt::programst &ind_progs=ind.programs; - read_instrt extract(progs, prog, names, instr_set); - for(const individualt::programt &program : ind_progs) - { - extract.set_prog_size(program.size()); - for(const individualt::instructiont &instr : program) - extract(instr); - } - danger_goto_solutiont::nondet_choicest &nondet=result.x0_choices; - nondet.clear(); - const typet type=cegis_default_integer_type(); // XXX: Currently single data type. - for(const individualt::x0t::value_type &x0 : ind.x0) - nondet.push_back(from_integer(x0, type)); -} - -void create_danger_solution(danger_goto_solutiont &result, - const danger_programt &prog, const program_individualt &ind, - const operand_variable_idst &ids) -{ - instruction_sett instr_set; - extract_instruction_set(instr_set, prog.gf); - create_danger_solution(result, prog, ind, instr_set, ids); -} diff --git a/src/cegis/danger/symex/learn/solution_factory.h b/src/cegis/danger/symex/learn/solution_factory.h deleted file mode 100644 index c67b02c2826..00000000000 --- a/src/cegis/danger/symex/learn/solution_factory.h +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_LEARN_SOLUTION_FACTORY_H -#define CPROVER_CEGIS_DANGER_SYMEX_LEARN_SOLUTION_FACTORY_H - -#include - -#include - -typedef std::map instruction_sett; -typedef std::map operand_variable_idst; - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param trace - * @param ids - * @param max_solution_size - * - * @return - */ -void create_danger_solution(class danger_goto_solutiont &result, - const class danger_programt &prog, const class goto_tracet &trace, - const operand_variable_idst &ids, const size_t max_solution_size); - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param ind - * @param instr - * @param ids - */ -void create_danger_solution(danger_goto_solutiont &result, - const danger_programt &prog, const program_individualt &ind, - const instruction_sett &instr, const operand_variable_idst &ids); - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param ind - * @param ids - */ -void create_danger_solution(danger_goto_solutiont &result, - const danger_programt &prog, const program_individualt &ind, - const operand_variable_idst &ids); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_LEARN_SOLUTION_FACTORY_H diff --git a/src/cegis/danger/symex/verify/danger_verify_config.cpp b/src/cegis/danger/symex/verify/danger_verify_config.cpp deleted file mode 100644 index a583829df5a..00000000000 --- a/src/cegis/danger/symex/verify/danger_verify_config.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -danger_verify_configt::danger_verify_configt(const danger_programt &program) : - original_program(program), limit_ce(false), max_ce_width(0u) -{ -} - -danger_verify_configt::~danger_verify_configt() -{ -} - -void danger_verify_configt::process(const candidatet &candidate) -{ - program=original_program; - quantifiers.clear(); - const danger_constraint constraint(program.use_ranking); - invariant_insert_constraint(quantifiers, program, std::cref(constraint)); - danger_insert_candidate(program, candidate); - goto_functionst &gf=program.gf; - if(limit_ce) restrict_bv_size(program.st, gf, max_ce_width); - gf.update(); -} - -const symbol_tablet &danger_verify_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &danger_verify_configt::get_goto_functions() const -{ - return program.gf; -} - -goto_functionst &danger_verify_configt::get_goto_functions() -{ - return program.gf; -} - -void danger_verify_configt::convert(counterexamplest &counterexamples, - const goto_tracet &trace) -{ - counterexamples.push_back(counterexamplet()); - invariant_extract_counterexample(counterexamples.back(), trace, quantifiers); -} - -size_t danger_verify_configt::get_number_of_loops() const -{ - return original_program.loops.size(); -} - -exprt::operandst danger_verify_configt::get_loop_guards() const -{ - exprt::operandst loop_guards; - const danger_programt::loopst &loops=original_program.loops; - std::transform(loops.begin(), loops.end(), std::back_inserter(loop_guards), - [](const danger_programt::loopt &loop) - { return loop.guard;}); - return loop_guards; -} - -void danger_verify_configt::set_max_ce_width(const size_t size) -{ - limit_ce=true; - max_ce_width=size; -} - -void danger_verify_configt::show_counterexample(messaget::mstreamt &os, - const counterexamplet &counterexample) const -{ - os << "" << messaget::endl; - print_assignments(os, get_symbol_table(), counterexample); - os << "" << messaget::endl << messaget::eom; -} diff --git a/src/cegis/danger/symex/verify/danger_verify_config.h b/src/cegis/danger/symex/verify/danger_verify_config.h deleted file mode 100644 index 70d8c79da83..00000000000 --- a/src/cegis/danger/symex/verify/danger_verify_config.h +++ /dev/null @@ -1,150 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_VERIFY_DANGER_VERIFY_CONFIG_H -#define CPROVER_CEGIS_DANGER_SYMEX_VERIFY_DANGER_VERIFY_CONFIG_H - -#include - -#include - -#include - -/** - * @brief - * - * @details - */ -class danger_verify_configt -{ - const danger_programt &original_program; - danger_programt program; - goto_programt::targetst quantifiers; - bool limit_ce; - size_t max_ce_width; -public: - /** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ - typedef std::map counterexamplet; - typedef std::deque counterexamplest; - - /** - * @brief Candidate solution type for this CEGIS component. - * - * @details Solutions are provided as a set of GOTO function bodies - * (goto_programt::instructionst) for function names. - */ - typedef class danger_goto_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit danger_verify_configt(const danger_programt &program); - - /** - * @brief - * - * @details - */ - ~danger_verify_configt(); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void process(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @return - */ - goto_functionst &get_goto_functions(); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param trace - */ - void convert(counterexamplest &counterexamples, - const class goto_tracet &trace); - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_number_of_loops() const; - - /** - * @brief - * - * @details - * - * @return - */ - exprt::operandst get_loop_guards() const; - - /** - * @brief - * - * @details - * - * @param size - */ - void set_max_ce_width(size_t size); - - /** - * @brief - * - * @details - * - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_VERIFY_DANGER_VERIFY_CONFIG_H diff --git a/src/cegis/danger/symex/verify/insert_candidate.cpp b/src/cegis/danger/symex/verify/insert_candidate.cpp deleted file mode 100644 index cf79475bde1..00000000000 --- a/src/cegis/danger/symex/verify/insert_candidate.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -class assign_x0t -{ - const symbol_tablet &st; - goto_functionst &gf; - goto_programt::targetst::const_iterator current_choice; -public: - explicit assign_x0t(danger_programt &prog) : - st(prog.st), gf(prog.gf), current_choice(prog.x0_choices.begin()) - { - } - - ~assign_x0t() - { - } - - void operator()(const exprt &x0_value) - { - const goto_programt::targett pos=*current_choice++; - const irep_idt &var_name=get_affected_variable(*pos); - cegis_assign_user_variable(st, gf, pos, var_name, x0_value); - } -}; - -void assign_x0(danger_programt &prog, const candidatet &candidate) -{ - const candidatet::nondet_choicest &x0_values=candidate.x0_choices; - const goto_programt::targetst &x0_choices=prog.x0_choices; - assert(x0_values.size() <= x0_choices.size()); - const assign_x0t assign(prog); - std::for_each(x0_values.begin(), x0_values.end(), assign); -} - -class insert_danger_programt -{ - const danger_programt::loopst &loops; - goto_programt &body; - size_t loop_id; -public: - insert_danger_programt(danger_programt &prog, goto_programt &body) : - loops(prog.loops), body(body), loop_id(0u) - { - } - - void operator()(const candidatet::danger_programt &solution) - { - const danger_programt::loopt &loop=loops.at(loop_id); - const invariant_programt::meta_vars_positionst &im=loop.meta_variables; - const danger_programt::danger_meta_vars_positionst &dm= - loop.danger_meta_variables; - insert_program(body, im.Ix, solution.invariant); - const irep_idt &Dx=get_affected_variable(*im.Ix); - const irep_idt &Dx_prime=get_affected_variable(*im.Ix_prime); - insert_program(body, im.Ix_prime, solution.invariant, Dx, Dx_prime); - if(!dm.Rx.empty() && !dm.Rx_prime.empty()) - { - const goto_programt::targett Rx=*dm.Rx.rbegin(); - insert_program(body, *dm.Rx.rbegin(), solution.ranking); - const irep_idt &Rx_n=get_affected_variable(*Rx); - const goto_programt::targett Rx_prime=*dm.Rx_prime.rbegin(); - const irep_idt &Rx_pn=get_affected_variable(*Rx_prime); - insert_program(body, Rx_prime, solution.ranking, Rx_n, Rx_pn); // XXX: Lexicographical ranking? - } - if(!dm.Sx.empty()) insert_program(body, *dm.Sx.rbegin(), solution.skolem); - } -}; - -void insert_programs(danger_programt &prog, const candidatet &candidate) -{ - const candidatet::danger_programst &progs=candidate.danger_programs; - if(progs.empty()) return; - goto_programt &body=get_entry_body(prog.gf); - const goto_programt::instructionst &first_inv=progs.begin()->invariant; - const std::string D0x(get_cegis_meta_name(get_Dx(0))); - const std::string Dx0(get_cegis_meta_name(get_Dx0())); - insert_program(body, prog.Ix0, first_inv, D0x, Dx0); - const insert_danger_programt insert(prog, body); - std::for_each(progs.begin(), progs.end(), insert); -} -} - -void danger_insert_candidate(danger_programt &program, - const candidatet &candidate) -{ - assign_x0(program, candidate); - insert_programs(program, candidate); -} diff --git a/src/cegis/danger/symex/verify/insert_candidate.h b/src/cegis/danger/symex/verify/insert_candidate.h deleted file mode 100644 index 00014b5ddbc..00000000000 --- a/src/cegis/danger/symex/verify/insert_candidate.h +++ /dev/null @@ -1,32 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_VERIFY_INSERT_CANDIDATE_H -#define CPROVER_CEGIS_DANGER_SYMEX_VERIFY_INSERT_CANDIDATE_H - -/** - * @brief Candidate solution type for this CEGIS component. - * - * @details Solutions are provided as a set of GOTO function bodies - * (goto_programt::instructionst) for function names. - */ -typedef class danger_goto_solutiont candidatet; - -/** - * @brief - * - * @details - * - * @param program - * @param candidate - */ -void danger_insert_candidate(class danger_programt &program, - const candidatet &candidate); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_VERIFY_INSERT_CANDIDATE_H diff --git a/src/cegis/danger/symex/verify/parallel_danger_verifier.cpp b/src/cegis/danger/symex/verify/parallel_danger_verifier.cpp deleted file mode 100644 index ee57b71e9e9..00000000000 --- a/src/cegis/danger/symex/verify/parallel_danger_verifier.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#ifndef _WIN32 -#include -#endif - -#include - -#include -#include -#include - -parallel_danger_verifiert::parallel_danger_verifiert(const optionst &options, - danger_verify_configt &config) : - options(options), config(config), is_failure(true) -{ -} - -parallel_danger_verifiert::~parallel_danger_verifiert() -{ -} - -void parallel_danger_verifiert::verify(const candidatet &candidate) -{ - all_ces.clear(); - config.process(candidate); - parallel_danger_verify_poolt pool(all_ces, options, config, candidate); - pool.schedule(parallel_danger_verify_taskt::FULL); - pool.schedule(parallel_danger_verify_taskt::RANKING); - pool.schedule(parallel_danger_verify_taskt::ASSERTION); - is_failure=!pool.join(); -} - -parallel_danger_verifiert::const_iterator parallel_danger_verifiert::counterexamples_begin() const -{ - return all_ces.begin(); -} - -parallel_danger_verifiert::const_iterator parallel_danger_verifiert::counterexamples_end() const -{ - return all_ces.end(); -} - -bool parallel_danger_verifiert::has_counterexamples() const -{ - return !all_ces.empty(); -} - -bool parallel_danger_verifiert::success() const -{ - return !is_failure; -} - -void parallel_danger_verifiert::show_counterexample(messaget::mstreamt &os, - const counterexamplet &counterexample) const -{ - config.show_counterexample(os, counterexample); -} diff --git a/src/cegis/danger/symex/verify/parallel_danger_verifier.h b/src/cegis/danger/symex/verify/parallel_danger_verifier.h deleted file mode 100644 index 64f80ca17da..00000000000 --- a/src/cegis/danger/symex/verify/parallel_danger_verifier.h +++ /dev/null @@ -1,110 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFIER_H -#define CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFIER_H - -#include - -// TODO: Refactor this to use task_poolt. -/** - * @brief - * - * @details - */ -class parallel_danger_verifiert -{ -public: - typedef danger_verify_configt::counterexamplet counterexamplet; - typedef std::set counterexamplest; -private: - const class optionst &options; - danger_verify_configt &config; - counterexamplest all_ces; - bool is_failure; -public: - typedef danger_verify_configt::candidatet candidatet; - typedef counterexamplest::const_iterator const_iterator; - - /** - * @brief - * - * @details - * - * @param options - * @param config - */ - parallel_danger_verifiert(const optionst &options, danger_verify_configt &config); - - /** - * @brief - * - * @details - */ - ~parallel_danger_verifiert(); - - /** - * @brief Verifies a given candidate solution. - * - * @details Effectively invokes CBMC using the given function bodies. - * - * @param candidate The candidate implementation provided by the learner. - */ - void verify(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_begin() const; - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_end() const; - - /** - * @brief Indicates whether a counterexample could be produced. - * - * @details If the verification fails, but the oracle is unable to provide a - * counterexample, this marks an error in the CBMC execution. - * - * @return true if a counterexample was created, false otherwise. - */ - bool has_counterexamples() const; - - /** - * @brief Indicates whether the provided solution holds. - * - * @details Provides the result of the last "verify()" operation. - * - * @return true if the last solution holds, false otherwise. - */ - bool success() const; - - /** - * @brief - * - * @details - * - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFIER_H diff --git a/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp b/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp deleted file mode 100644 index 843f033a18c..00000000000 --- a/src/cegis/danger/symex/verify/parallel_danger_verify_task.cpp +++ /dev/null @@ -1,336 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#ifndef _WIN32 -#include -#include -#include -#endif - -#include - -#include -#include - -parallel_danger_verify_taskt::parallel_danger_verify_taskt( - const optionst &options, danger_verify_configt &config, - const candidatet &candidate, modet mode) : - options(options), config(config), candidate(candidate), mode(mode), success( - false), child_pid(-1) -{ -} - -parallel_danger_verify_taskt::~parallel_danger_verify_taskt() -{ -} - -parallel_danger_verify_taskt::parallel_danger_verify_taskt( - const parallel_danger_verify_taskt &other) : - options(other.options), config(other.config), candidate(other.candidate), mode( - other.mode), success(other.success), pipe(other.pipe), child_pid(other.child_pid) -{ - pipe.auto_close(); -} - -void parallel_danger_verify_taskt::set_parent_mode(const pid_t child_pid) -{ - pipe.close_write(); - this->child_pid=child_pid; -} - -pid_t parallel_danger_verify_taskt::get_child_pid() const -{ - return child_pid; -} - -namespace -{ -class danger_config_fullt -{ - danger_verify_configt &config; -public: - typedef danger_verify_configt::counterexamplet counterexamplet; - typedef danger_verify_configt::counterexamplest counterexamplest; - typedef danger_verify_configt::candidatet candidatet; - - explicit danger_config_fullt(danger_verify_configt &config) : - config(config) - { - } - - void process(const candidatet &candidate) - { - // Already pre-processed - } - - const symbol_tablet &get_symbol_table() - { - return config.get_symbol_table(); - } - - const goto_functionst &get_goto_functions() - { - return config.get_goto_functions(); - } - - void convert(counterexamplest &counterexamples, const goto_tracet &trace) - { - config.convert(counterexamples, trace); - } -}; - -class danger_config_rankingt -{ - danger_verify_configt &config; - goto_functionst &gf; -public: - typedef danger_verify_configt::counterexamplet counterexamplet; - typedef danger_verify_configt::counterexamplest counterexamplest; - typedef danger_verify_configt::candidatet candidatet; - - explicit danger_config_rankingt(danger_verify_configt &config) : - config(config), gf(config.get_goto_functions()) - { - } - - void process(const candidatet &candidate) - { - force_ranking_error(gf, config.get_number_of_loops()); - } - - const symbol_tablet &get_symbol_table() - { - return config.get_symbol_table(); - } - - const goto_functionst &get_goto_functions() - { - return gf; - } - - void convert(counterexamplest &counterexamples, const goto_tracet &trace) - { - config.convert(counterexamples, trace); - } -}; - -class danger_config_assertiont -{ - danger_verify_configt &config; - goto_functionst &gf; -public: - typedef danger_verify_configt::counterexamplet counterexamplet; - typedef danger_verify_configt::counterexamplest counterexamplest; - typedef danger_verify_configt::candidatet candidatet; - - explicit danger_config_assertiont(danger_verify_configt &config) : - config(config), gf(config.get_goto_functions()) - { - } - - void process(const candidatet &candidate) - { - force_assertion_violation(gf, config.get_number_of_loops()); - } - - const symbol_tablet &get_symbol_table() - { - return config.get_symbol_table(); - } - - const goto_functionst &get_goto_functions() - { - return gf; - } - - void convert(counterexamplest &counterexamples, const goto_tracet &trace) - { - config.convert(counterexamples, trace); - } -}; - -template -bool run_bmc(danger_verify_configt::counterexamplest &ces, - const optionst &options, danger_verify_configt &config, - const parallel_danger_verify_taskt::candidatet &candidate) -{ - configt cfg(config); - cegis_symex_verifyt bmc(options, cfg); - bmc.verify(candidate); - std::copy(bmc.counterexamples_begin(), bmc.counterexamples_end(), - std::back_inserter(ces)); - return bmc.success(); -} - -class ce_to_irept -{ - irept &result; -public: - explicit ce_to_irept(irept &result) : - result(result) - { - } - - void operator()( - const danger_verify_configt::counterexamplet::value_type &entry) - { - result.set(entry.first, entry.second); - } -}; - -void to_irep(irept &result, const danger_verify_configt::counterexamplet &ce) -{ - const ce_to_irept convert(result); - std::for_each(ce.begin(), ce.end(), convert); -} - -class ces_to_irept -{ - irept &result; -public: - explicit ces_to_irept(irept &result) : - result(result) - { - } - - void operator()(const danger_verify_configt::counterexamplet &ce) - { - irept converted; - to_irep(converted, ce); - result.move_to_sub(converted); - } -}; - -const char RESULT[]="__CPROVER_danger_result"; - -void to_irep(irept &result, const bool success, - const danger_verify_configt::counterexamplest &ces) -{ - result.set(RESULT, success); - const ces_to_irept convert(result); - std::for_each(ces.begin(), ces.end(), convert); -} - -void from_irep(danger_verify_configt::counterexamplet &ce, const irept &result) -{ - forall_named_irep(it, result.get_named_sub()) { - const exprt &expr=static_cast(it->second); - ce.insert(std::make_pair(it->first, expr)); -} -} - -void from_irep(bool &success, danger_verify_configt::counterexamplest &ces, - const irept &result) -{ - success=result.get_bool(RESULT); - forall_irep(it, result.get_sub()) { - ces.push_back(danger_verify_configt::counterexamplet()); - danger_verify_configt::counterexamplet &ce=ces.back(); - from_irep(ce, *it); -} -} -} - -void parallel_danger_verify_taskt::operator()() -{ - switch(mode) - { - case modet::FULL: - success=run_bmc(new_ces, options, config, candidate); - break; - case modet::ASSERTION: - success=run_bmc(new_ces, options, config, candidate); - break; - default: - success=run_bmc(new_ces, options, config, candidate); - break; - } - irept package; - to_irep(package, success, new_ces); -#ifndef _WIN32 - pipe.close_read(); - pipe.send(package); - pipe.close_write(); -#endif -} - -void parallel_danger_verify_taskt::read_counterexamples(bool &success, -counterexamplest &counterexamples) -{ - irept package; -#ifndef _WIN32 - pipe.receive(package); - pipe.close_read(); -#endif - from_irep(this->success, new_ces, package); - std::copy(new_ces.begin(), new_ces.end(), std::inserter(counterexamples, counterexamples.end())); - success=this->success; -} - -parallel_danger_verify_poolt::parallel_danger_verify_poolt( - counterexamplest &counterexamples, - const optionst &options, - danger_verify_configt &config, - const candidatet &candidate) : ces(counterexamples), options(options), config(config), candidate(candidate) -{ -} - -parallel_danger_verify_poolt::~parallel_danger_verify_poolt() -{ -} - -void parallel_danger_verify_poolt::schedule(parallel_danger_verify_taskt::modet mode) -{ - tasks.push_back(parallel_danger_verify_taskt(options, config, candidate, mode)); - parallel_danger_verify_taskt &task=tasks.back(); -#ifndef _WIN32 - const pid_t child_pid=fork(); - if(child_pid) return task.set_parent_mode(child_pid); -#endif - task(); -#ifndef _WIN32 - exit(EXIT_SUCCESS); -#endif -} - -namespace -{ -class joint -{ - bool &success; - parallel_danger_verify_poolt::counterexamplest &counterexamples; -public: - joint(bool &success, parallel_danger_verify_poolt::counterexamplest &counterexamples) : - success(success), counterexamples(counterexamples) -{ -} - -void operator()(parallel_danger_verify_taskt &task) const -{ -#ifndef _WIN32 - int status; - waitpid(task.get_child_pid(), &status, 0); -#endif - bool success=false; - task.read_counterexamples(success, counterexamples); - if(!success) this->success=false; -} -}; -} - -bool parallel_danger_verify_poolt::join() -{ - bool success=true; - const joint join(success, ces); - std::for_each(tasks.begin(), tasks.end(), join); - return success; -} diff --git a/src/cegis/danger/symex/verify/parallel_danger_verify_task.h b/src/cegis/danger/symex/verify/parallel_danger_verify_task.h deleted file mode 100644 index 4947826096b..00000000000 --- a/src/cegis/danger/symex/verify/parallel_danger_verify_task.h +++ /dev/null @@ -1,167 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFY_TASK_H -#define CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFY_TASK_H - -#include -#include - -#ifdef _WIN32 -typedef int pid_t; -#endif - -/** - * @brief - * - * @details - */ -class parallel_danger_verify_taskt -{ -public: - typedef enum - { - FULL=0, RANKING=1, ASSERTION=2 - } modet; - typedef danger_verify_configt::candidatet candidatet; - typedef std::set counterexamplest; -private: - const class optionst &options; - danger_verify_configt &config; - const candidatet &candidate; - const modet mode; - danger_verify_configt::counterexamplest new_ces; - bool success; - irep_pipet pipe; - pid_t child_pid; -public: - /** - * @brief - * - * @details - * - * @param options - * @param config - * @param candidate - * @param mode - */ - parallel_danger_verify_taskt(const optionst &options, - danger_verify_configt &config, const candidatet &candidate, modet mode); - - /** - * @brief - * - * @details - * - * @param other - */ - explicit parallel_danger_verify_taskt(const parallel_danger_verify_taskt &other); - - /** - * @brief - * - * @details - */ - ~parallel_danger_verify_taskt(); - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param child_pid - */ - void set_parent_mode(pid_t child_pid); - - /** - * @brief - * - * @details - * - * @param success - * @param counterexamples - */ - void read_counterexamples(bool &success, counterexamplest &counterexamples); - - /** - * @brief - * - * @details - * - * @return - */ - pid_t get_child_pid() const; -}; - -/** - * @brief - * - * @details - */ -class parallel_danger_verify_poolt -{ -public: - typedef parallel_danger_verify_taskt::counterexamplest counterexamplest; - typedef parallel_danger_verify_taskt::candidatet candidatet; -private: - counterexamplest &ces; - const optionst &options; - danger_verify_configt &config; - const candidatet &candidate; - std::deque tasks; -public: - /** - * @brief - * - * @details - * - * @param counterexamples - * @param options - * @param config - * @param candidate - */ - parallel_danger_verify_poolt(counterexamplest &counterexamples, - const optionst &options, danger_verify_configt &config, - const candidatet &candidate); - - /** - * @brief - * - * @details - */ - ~parallel_danger_verify_poolt(); - - /** - * @brief - * - * @details - * - * @param config - * @param mode - */ - void schedule(parallel_danger_verify_taskt::modet mode); - - /** - * @brief - * - * @details - * - * @return - */ - bool join(); -}; - -#endif // CPROVER_CEGIS_DANGER_SYMEX_VERIFY_PARALLEL_DANGER_VERIFY_TASK_H diff --git a/src/cegis/danger/symex/verify/restrict_counterexamples.cpp b/src/cegis/danger/symex/verify/restrict_counterexamples.cpp deleted file mode 100644 index fde94f98cab..00000000000 --- a/src/cegis/danger/symex/verify/restrict_counterexamples.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_assert(const goto_programt::instructiont &instr) -{ - return goto_program_instruction_typet::ASSERT == instr.type; -} - -goto_programt::targett find_assertion(goto_functionst &gf) -{ - goto_programt &body=get_entry_body(gf); - goto_programt::instructionst &i=body.instructions; - const goto_programt::targett it=std::find_if(i.begin(), i.end(), &is_assert); - assert(i.end() != it); - return it; -} - -goto_programt::targett add_assume(goto_functionst &gf) -{ - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=find_assertion(gf); - if(goto_program_instruction_typet::ASSUME == (--pos)->type) return pos; - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSUME; - pos->source_location=default_cegis_source_location(); - return pos; -} - -void force_all_guards_violated(exprt::operandst &op, const size_t num_loops) -{ - for(size_t i=0; i < num_loops; ++i) - { - const notequal_exprt Gx=danger_component_as_bool(get_Gx(i)); - const equal_exprt not_Gx(Gx.lhs(), Gx.rhs()); - op.push_back(not_Gx); - } -} -} - -void force_assertion_violation(goto_functionst &gf, const size_t num_loops) -{ - exprt::operandst op; - force_all_guards_violated(op, num_loops); - const notequal_exprt Ax(danger_component_as_bool(get_Ax())); - const equal_exprt not_Ax(Ax.lhs(), Ax.rhs()); - op.push_back(not_Ax); - goto_programt::targett pos=add_assume(gf); - pos->guard=conjunction(op); -} - -void force_ranking_error(goto_functionst &gf, const size_t num_loops) -{ - exprt::operandst op; - for(size_t i=0; i < num_loops; ++i) - { - const exprt::operandst conj={ danger_component_as_bool(get_Dx(i)), - danger_component_as_bool(get_Dx(i)), danger_component_as_bool(get_Gx(i)), - danger_component_as_bool(get_Dx_prime(i)) }; - op.push_back(conjunction(conj)); - } - goto_programt::targett pos=add_assume(gf); - pos->guard=disjunction(op); -} diff --git a/src/cegis/danger/symex/verify/restrict_counterexamples.h b/src/cegis/danger/symex/verify/restrict_counterexamples.h deleted file mode 100644 index 1dcc09891ac..00000000000 --- a/src/cegis/danger/symex/verify/restrict_counterexamples.h +++ /dev/null @@ -1,67 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_SYMEX_VERIFY_RESTRICT_COUNTEREXAMPLES_H -#define CPROVER_CEGIS_DANGER_SYMEX_VERIFY_RESTRICT_COUNTEREXAMPLES_H - -#include - -/** - * @brief - * - * @details - * - * @param gf - * @param num_loops - */ -void force_assertion_satisfaction(class goto_functionst &gf, - const size_t num_loops); - -/** - * @brief - * - * @details - * - * @param gf - * @param num_loop - */ -void force_assertion_violation(goto_functionst &gf, const size_t num_loops); - -/** - * @brief - * - * @details - * - * @param gf - * @param loop_guards - */ -void force_loop_exit(goto_functionst &gf, const exprt::operandst &loop_guards); - -/** - * @brief - * - * @details - * - * @param gf - * @param num_loops - */ -void force_guard_violation(goto_functionst &gf, const size_t num_loops); - -/** - * @brief - * - * @details - * - * @param gf - * @param num_loops - */ -void force_ranking_error(goto_functionst &gf, - const size_t num_loops); - -#endif // CPROVER_CEGIS_DANGER_SYMEX_VERIFY_RESTRICT_COUNTEREXAMPLES_H diff --git a/src/cegis/danger/value/danger_goto_solution.h b/src/cegis/danger/value/danger_goto_solution.h deleted file mode 100644 index 2f351979333..00000000000 --- a/src/cegis/danger/value/danger_goto_solution.h +++ /dev/null @@ -1,41 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_DANGER_VALUE_DANGER_GOTO_SOLUTION_H -#define CPROVER_CEGIS_DANGER_VALUE_DANGER_GOTO_SOLUTION_H - -#include - -/** - * @brief - * - * @details - */ -class danger_goto_solutiont -{ -public: - /** - * @brief - * - * @details - */ - struct danger_programt - { - goto_programt::instructionst invariant; - goto_programt::instructionst ranking; - goto_programt::instructionst skolem; - }; - typedef std::vector danger_programst; - danger_programst danger_programs; - - typedef std::vector nondet_choicest; - nondet_choicest x0_choices; -}; - -#endif // CPROVER_CEGIS_DANGER_VALUE_DANGER_GOTO_SOLUTION_H diff --git a/src/cegis/facade/cegis.h b/src/cegis/facade/cegis.h deleted file mode 100644 index 027ffe1c386..00000000000 --- a/src/cegis/facade/cegis.h +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_FACADE_CEGIS_H -#define CPROVER_CEGIS_FACADE_CEGIS_H - -#include - -/** - * @brief CEGIS template algorithm. - * - * @details Counterexample-guided inductive synthesis implementation - * relying on generic learning algorithms and verification oracles. - * - * @param preproc The preprocessing configuration. - * @param learn The learning algorithm to use. - * @param oracle The verification oracle to use. - * @param os Stream for solution output. - * - * @tparam learnt CEGIS learning algorithm type (e.g. GA). - * @tparam oraclet CEGIS verification oracle type (e.g BMC). - * @tparam preproct - * @tparam mstreamt - */ -template -int run_cegis(learnt &learn, oraclet &oracle, preproct &preproc, seedt &seed, size_t max_size, mstreamt &os) -{ - preproc(); - const size_t min_size=preproc.get_min_solution_size(); - preproc(min_size); - learn.set_solution_size_range(min_size, max_size); - learn.seed(seed); - do - { - const typename learnt::candidatet &candidate=learn.next_candidate(); - oracle.verify(candidate); - } while (oracle.has_counterexamples() - && learn.learn(oracle.counterexamples_begin(), oracle.counterexamples_end())); - if (oracle.success()) - { - learn.show_candidate(os); - return 0; - } - return 10; -} - -#endif // CPROVER_CEGIS_FACADE_CEGIS_H diff --git a/src/cegis/facade/runner_helper.h b/src/cegis/facade/runner_helper.h deleted file mode 100644 index 6b53c015b47..00000000000 --- a/src/cegis/facade/runner_helper.h +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_FACADE_RUNNER_HELPER_H -#define CPROVER_CEGIS_FACADE_RUNNER_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param opt - * @paral learn - * @param verify - * @param preproc - * - * @tparam learnt - * @tparam verifyt - * @tparam preproct - */ -template -int run_cegis_with_statistics_wrapper( - messaget::mstreamt &os, - const class optionst &opt, - learnt &learn, - verifyt &verify, - preproct &preproc); - -/** - * @brief - * - * @details - * - * @param os - * @param opt - * @paral learn - * @param verify - * @param preproc - * @param seed - * - * @tparam learnt - * @tparam verifyt - * @tparam preproct - * @tparam seedt - */ -template -int run_cegis_with_statistics_wrapper( - messaget::mstreamt &os, - const class optionst &opt, - learnt &learn, - verifyt &verify, - preproct &preproc, - seedt &seed); - -#include "runner_helper.inc" - -#endif // CPROVER_CEGIS_FACADE_RUNNER_HELPER_H diff --git a/src/cegis/facade/runner_helper.inc b/src/cegis/facade/runner_helper.inc deleted file mode 100644 index a40f18c1caa..00000000000 --- a/src/cegis/facade/runner_helper.inc +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -template -int run_cegis_with_statistics_wrapper(messaget::mstreamt &os, - const optionst &opt, learnt &l, verifyt &v, preproct &p) -{ - null_seedt seed; - return run_cegis_with_statistics_wrapper(os, opt, l, v, p, seed); -} - -template -int run_cegis_with_statistics_wrapper(messaget::mstreamt &os, - const optionst &opt, learnt &l, verifyt &v, preproct &p, seedt &seed) -{ - const size_t max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - if (!opt.get_bool_option(CEGIS_STATISTICS)) - return run_cegis(l, v, p, seed, max_prog_size, os); - typedef messaget::mstreamt streamt; - cegis_statistics_wrappert stat(l, v, os, opt); - return run_cegis(stat, stat, p, seed, max_prog_size, os); -} diff --git a/src/cegis/genetic/concrete_test_runner.cpp b/src/cegis/genetic/concrete_test_runner.cpp deleted file mode 100644 index 7af89361018..00000000000 --- a/src/cegis/genetic/concrete_test_runner.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#ifndef _WIN32 -#include -#endif - -#include -#include - -#include -#include - -#define EXECUTABLE_PREFIX "test_runner" -#define EXECUTABLE_SUFFIX ".exe" -#define SOURCE_FILE_PREFIX "concrete_test" -#define SOURCE_FILE_SUFFIX ".c" - -concrete_test_runnert::concrete_test_runnert( - const std::function source_code_provider) : - source_code_provider(source_code_provider), executable(EXECUTABLE_PREFIX, - EXECUTABLE_SUFFIX), executable_compiled(false) -{ -} - -concrete_test_runnert::~concrete_test_runnert() -{ -} - -namespace -{ -void implement_deserialise(std::string &source) -{ - source+= - "#include \n\n" - "#define " CEGIS_PREFIX "next_arg() atol(argv[__CPROVER_cegis_deserialise_index++])\n" - "#define " CEGIS_PREFIX "deserialise_init() unsigned int __CPROVER_cegis_deserialise_index=1u+__CPROVER_cegis_first_prog_offset\n" - "#define " CEGIS_PREFIX "declare_prog(var_name, sz) const size_t sz=__CPROVER_cegis_next_arg(); \\\n" - " struct " CEGIS_PREFIX "instructiont var_name[sz]; \\\n" - "for (unsigned int i=0; i < sizeof(var_name) / sizeof(struct " CEGIS_PREFIX "instructiont); ++i) \\\n" - "{ \\\n" - " var_name[i].opcode=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op0=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op1=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op2=" CEGIS_PREFIX "next_arg(); \\\n" - "}\n" - "#define " CEGIS_PREFIX "deserialise_x0(var_name) var_name=" CEGIS_PREFIX "next_arg()\n" - "#define " CEGIS_PREFIX "ce_value_init() unsigned int " CEGIS_PREFIX "ce_index=1u\n" - "#define " CEGIS_PREFIX "ce_value() atol(argv[" CEGIS_PREFIX "ce_index++])\n"; - -} - -void write_file(const std::string &path, const std::string &content) -{ - std::ofstream ofs(path); - ofs << content; -} - -#define COMPILE_COMMAND "gcc -std=c99 -g0 -O2 " -#define ARTIFACT_SEPARATOR " -o " -#define COMPLING_FAILED "Compiling test runner failed." - -void prepare_executable(bool &executable_compiled, - const std::function &source_code_provider, - const std::string &executable) -{ - if(executable_compiled) return; - const temporary_filet source_file(SOURCE_FILE_PREFIX, SOURCE_FILE_SUFFIX); - const std::string source_file_name(source_file()); - std::string source; - implement_deserialise(source); - source+=source_code_provider(); - write_file(source_file_name, source); - std::string compile_command(COMPILE_COMMAND); - compile_command+=source_file_name; - compile_command+=ARTIFACT_SEPARATOR; - compile_command+=executable; - const int result=system(compile_command.c_str()); - if(result) throw std::runtime_error(COMPLING_FAILED); - executable_compiled=true; -} - -#ifdef _WIN32 -#define NOT_SUPPORTED() assert(!"task_poolt not supported on Windows.") -#endif - -class conrete_test_runner_taskt -{ - concrete_test_runnert::individualt &ind; - const std::string command; -public: - conrete_test_runner_taskt(concrete_test_runnert::individualt &ind, - const std::string &command) : - ind(ind), command(command) - { - } - - int operator()() const - { -#ifndef _WIN32 - const int result=system(command.c_str()); - if(!WIFEXITED(result)) return EXIT_FAILURE; - return WEXITSTATUS(result); -#else - NOT_SUPPORTED(); - return 0; -#endif - } - - void operator()(const int status) const - { -#ifndef _WIN32 - if(!WIFEXITED(status)) return; - if(EXIT_SUCCESS == WEXITSTATUS(status)) ++ind.fitness; -#else - NOT_SUPPORTED(); -#endif - } -}; - -#define NUM_RUNNER_OPS 3u -} - -void concrete_test_runnert::run_test(individualt &ind, - const counterexamplet &ce) -{ - const std::string exe(executable()); - prepare_executable(executable_compiled, source_code_provider, exe); - std::string command(exe); - for(const std::pair &assignment : ce) - { - command+=" "; - const bv_arithmetict arith(assignment.second); - const mp_integer::llong_t v=arith.to_integer().to_long(); - command+=integer2string(static_cast(v)); - } - for(const individualt::programt &prog : ind.programs) - { - if(prog.empty()) continue; - command+=" "; - command+=integer2string(prog.size()); - for(const individualt::instructiont &instr : prog) - { - command+=" "; - command+=integer2string(static_cast(instr.opcode)); - size_t op_count=0; - for(const individualt::instructiont::opt &op : instr.ops) - { - command+=" "; - command+=integer2string(static_cast(op)); - ++op_count; - } - for(; op_count < 3u; ++op_count) - command+=" 0"; - } - } - for(const individualt::x0t::value_type &x0 : ind.x0) - { - command+=" "; - command+=integer2string(static_cast(x0)); - } - const conrete_test_runner_taskt task(ind, command); - task_pool.schedule(task, task); -} - -void concrete_test_runnert::join() -{ - task_pool.join_all(); -} diff --git a/src/cegis/genetic/concrete_test_runner.h b/src/cegis/genetic/concrete_test_runner.h deleted file mode 100644 index cb633130d77..00000000000 --- a/src/cegis/genetic/concrete_test_runner.h +++ /dev/null @@ -1,71 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_CONCRETE_TEST_RUNNER_H -#define CPROVER_CEGIS_GENETIC_CONCRETE_TEST_RUNNER_H - -#include - -#include -#include - -#include - -#include - -/** - * @brief - * - * @details - */ -class concrete_test_runnert -{ - const std::function source_code_provider; - const temporary_filet executable; - bool executable_compiled; - task_poolt task_pool; -public: - typedef std::map counterexamplet; - typedef program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param source_code_provider - */ - explicit concrete_test_runnert(std::function source_code_provider); - - /** - * @brief - * - * @details - */ - ~concrete_test_runnert(); - - /** - * @brief - * - * @details - * - * @param ind - * @param ce - */ - void run_test(individualt &ind, const counterexamplet &ce); - - /** - * @brief - * - * @details - */ - void join(); -}; - -#endif // CPROVER_CEGIS_GENETIC_CONCRETE_TEST_RUNNER_H diff --git a/src/cegis/genetic/dynamic_test_runner_helper.cpp b/src/cegis/genetic/dynamic_test_runner_helper.cpp deleted file mode 100644 index 106b92e75af..00000000000 --- a/src/cegis/genetic/dynamic_test_runner_helper.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#if !defined(_WIN32) || defined(_HAVE_DLFCN) -#include -#endif - -#include -#include -#include - -#include -#include - -#include -#include - -void close_fitness_tester_library(fitness_lib_handlet &handle) -{ - if(handle) - { -#if !defined(_WIN32) || defined(_HAVE_DLFCN) - dlclose(handle); - handle=0; -#endif - } -} - -namespace -{ -void write_file(const std::string &path, const std::string &content) -{ - std::ofstream ofs(path); - ofs << content; -} - -#define SOURCE_FILE_PREFIX "concrete_test" -#define SOURCE_FILE_SUFFIX ".c" -#ifndef _WIN32 -#define COMPILE_COMMAND "gcc -std=c99 -g0 -O2 -shared -rdynamic -fPIC " -#define CLANG_COMPILE_COMMAND "clang -std=c99 -g0 -O2 -shared -rdynamic -fPIC " -#else -#define COMPILE_COMMAND "gcc -std=c99 -g0 -O2 -shared " -#define CLANG_COMPILE_COMMAND "clang -std=c99 -g0 -O2 " -#endif -#define ARTIFACT_SEPARATOR " -o " -#define COMPLING_FAILED "Compiling test runner failed." -#define OPEN_LIB_FAILED "Opening fitness test library failed." -#define LOAD_FUNC_FAILED "Loading fitness test function failed." -} - -void *prepare_fitness_tester_library(fitness_lib_handlet &handle, - const std::function &source_code_provider, - const std::string &library_file_path, const std::string &compile_options) -{ - const temporary_filet source_file(SOURCE_FILE_PREFIX, SOURCE_FILE_SUFFIX); - const std::string source_file_name(source_file()); - write_file(source_file_name, source_code_provider()); - std::string compile_command; - if(configt::ansi_ct::preprocessort::CLANG == config.ansi_c.preprocessor) - compile_command+=CLANG_COMPILE_COMMAND; - else - compile_command+=COMPILE_COMMAND; - compile_command+=compile_options; - compile_command+=source_file_name; - compile_command+=ARTIFACT_SEPARATOR; - compile_command+=library_file_path; - const int result=system(compile_command.c_str()); - if(result) throw std::runtime_error(COMPLING_FAILED); - -#if !defined(_WIN32) || defined(_HAVE_DLFCN) - handle=dlopen(library_file_path.c_str(), RTLD_NOW); - if(!handle) - { - perror(OPEN_LIB_FAILED); - throw std::runtime_error(OPEN_LIB_FAILED); - } - void * const func_result=dlsym(handle, CEGIS_FITNESS_TEST_FUNC); - char *error=0; - if((error=dlerror())) - { - perror(error); - throw std::runtime_error(LOAD_FUNC_FAILED); - } - return func_result; -#else - assert(!"Dynamic library loading currently not supported on Windows."); -#endif -} diff --git a/src/cegis/genetic/dynamic_test_runner_helper.h b/src/cegis/genetic/dynamic_test_runner_helper.h deleted file mode 100644 index 74453d08768..00000000000 --- a/src/cegis/genetic/dynamic_test_runner_helper.h +++ /dev/null @@ -1,83 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_DYNAMIC_TEST_RUNNER_HELPER_H -#define CPROVER_CEGIS_GENETIC_DYNAMIC_TEST_RUNNER_HELPER_H - -#include - -typedef void *fitness_lib_handlet; - -#define LIBRARY_PREFIX "fitness_test" -#ifndef _WIN32 -#define LIBRARY_SUFFIX ".so" -#else -#define LIBRARY_SUFFIX ".dll" -#endif - -/** - * @brief - * - * @details - * - * @param handle - * @param source_code_provider - * @param library_file_path - * @param compile_options - */ -void *prepare_fitness_tester_library( - fitness_lib_handlet &handle, - const std::function &source_code_provider, - const std::string &library_file_path, - const std::string &compile_options); - -/** - * @brief - * - * @details - * - * @param handle - * @param fitness_tester - * @param source_code_provider - * @param library_file_path - * @param compile_options - */ -template -void prepare_fitness_tester_library( - fitness_lib_handlet &handle, - fitness_testert &fitness_tester, - const std::function &source_code_provider, - const std::string &library_file_path, - std::string compile_options = ""); - -/** - * @brief - * - * @details - * - * @param handle - */ -void close_fitness_tester_library(fitness_lib_handlet &handle); - -/** - * @brief - * - * @details - * - * @param handle - * @param fitness_tester - */ -template -void close_fitness_tester_library( - fitness_lib_handlet &handle, - fitness_testert &fitness_tester); - -#include "dynamic_test_runner_helper.inc" - -#endif // CPROVER_CEGIS_GENETIC_DYNAMIC_TEST_RUNNER_HELPER_H diff --git a/src/cegis/genetic/dynamic_test_runner_helper.inc b/src/cegis/genetic/dynamic_test_runner_helper.inc deleted file mode 100644 index c284b0cf1b3..00000000000 --- a/src/cegis/genetic/dynamic_test_runner_helper.inc +++ /dev/null @@ -1,19 +0,0 @@ -template -void prepare_fitness_tester_library(fitness_lib_handlet &handle, - fitness_testert &fitness_tester, - const std::function &source_code_provider, - const std::string &library_file_path, const std::string compile_options) -{ - if (fitness_tester) return; - void * const func=prepare_fitness_tester_library(handle, source_code_provider, - library_file_path, compile_options); - fitness_tester=reinterpret_cast(func); -} - -template -void close_fitness_tester_library(fitness_lib_handlet &handle, - fitness_testert &fitness_tester) -{ - close_fitness_tester_library(handle); - if (fitness_tester) fitness_tester=0; -} diff --git a/src/cegis/genetic/family_selection.h b/src/cegis/genetic/family_selection.h deleted file mode 100644 index 715fe2dfe2b..00000000000 --- a/src/cegis/genetic/family_selection.h +++ /dev/null @@ -1,84 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_FAMILY_SELECTION_H -#define CPROVER_CEGIS_GENETIC_FAMILY_SELECTION_H - - /** - * @brief - * - * @details - * - * @tparam populationt - */ -template -class family_selectiont -{ -public: - /** - * @brief - * - * @details - */ - typedef std::deque individualst; - - /** - * @brief - * - * @details - */ - individualst parents; - - /** - * @brief - * - * @details - */ - individualst children; - - /** - * @brief - * - * @details - * - * @return - */ - bool can_mutate() const; - - /** - * @brief - * - * @details - * - * @return - */ - bool can_cross() const; - - /** - * @brief - * - * @details - * - * @return - */ - typename populationt::value_type &mutation_lhs(); - - /** - * @brief - * - * @details - * - * @return - */ - const typename populationt::value_type &mutation_rhs() const; -}; - -#include "family_selection.inc" - -#endif // CPROVER_CEGIS_GENETIC_FAMILY_SELECTION_H diff --git a/src/cegis/genetic/family_selection.inc b/src/cegis/genetic/family_selection.inc deleted file mode 100644 index bbdc3287971..00000000000 --- a/src/cegis/genetic/family_selection.inc +++ /dev/null @@ -1,26 +0,0 @@ -template -bool family_selectiont::can_mutate() const -{ - return !parents.empty() && !children.empty(); -} - -#define CEGIS_FAMILY_SELECTION_MIN_NUM_OPS 2u - -template -bool family_selectiont::can_cross() const -{ - return parents.size() >= CEGIS_FAMILY_SELECTION_MIN_NUM_OPS - && children.size() >= CEGIS_FAMILY_SELECTION_MIN_NUM_OPS; -} - -template -typename populationt::value_type &family_selectiont::mutation_lhs() -{ - return *children.front(); -} - -template -const typename populationt::value_type &family_selectiont::mutation_rhs() const -{ - return *parents.front(); -} diff --git a/src/cegis/genetic/ga_learn.h b/src/cegis/genetic/ga_learn.h deleted file mode 100644 index 8ecb2376b88..00000000000 --- a/src/cegis/genetic/ga_learn.h +++ /dev/null @@ -1,156 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_GA_LEARN_H -#define CPROVER_CEGIS_GENETIC_GA_LEARN_H - -#include -#include - -/** - * @brief - * - * @details - */ -template -class ga_learnt -{ -public: - typedef typename convertt::candidatet candidatet; - typedef typename fitnesst::counterexamplet counterexamplet; - typedef typename fitnesst::counterexamplest counterexamplest; - typedef typename selectt::populationt populationt; - typedef typename selectt::individualt individualt; - typedef individualt paragont; - typedef typename selectt::selectiont selectiont; -private: - typedef std::chrono::high_resolution_clock clockt; - typedef clockt::time_point time_pointt; - const class optionst &options; - const std::function havoc; - selectt &select; - mutatet &mutate; - crosst ✗ - fitnesst &fitness; - convertt &convert; - time_pointt program_startup; - const size_t max_runtime_in_seconds; - populationt pop; - selectiont selection; - candidatet current_candidate; - std::function is_evolving; - - bool set_fitness(individualt &ind); -public: - /** - * @brief - * - * @details - * - * @param options - * @param random - * @param select - * @param mutate - * @param cross - * @param fitness - * @param convert - * - * @tparam randomt - */ - template - ga_learnt(const optionst &options, randomt &random, selectt &select, - mutatet &mutate, crosst &cross, fitnesst &fitness, convertt &convert); - - - /** - * @brief - * - * @details - * - * @param seed - */ - template - void seed(seedt &seed); - - /** - * @brief Provides the next candidate. - * - * @details Provides the last candidate generated using learn. - * - * @return The next candidate. - */ - const candidatet &next_candidate() const; - - /** - * @brief Generates a candidate solution. - * - * @details Receives set of counterexample from the verification oracle - * and adds it to its information base. Generates a new candidate - * based on received counterexamples. - * - * @param first The first iterator of the counterexample set. - * @param last The last iterator of the counterexample set. - * - * @return true if learning was successful, false - * if no new candidate could be generated. - */ - template - bool learn(itert first, const itert &last); - - /** - * @brief Displays the last candidate. - * - * @details Prints the last candidate generated using learn. - * - * @param os The stream to output the candidate. - */ - void show_candidate(messaget::mstreamt &os) const; - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate(messaget::mstreamt &os, const candidatet &candidate) const; - - /** - * @brief - * - * @details - * - * @param min - * @param max - */ - void set_solution_size_range(size_t min, size_t max); - - /** - * @brief - * - * @details - * - * @param is_evolving - */ - void set_termination_condition(std::function is_evolving); - - /** - * @brief - * - * @details - * - * @param ind - */ - void add_paragon(paragont ind); -}; - -#include "ga_learn.inc" - -#endif // CPROVER_CEGIS_GENETIC_GA_LEARN_H diff --git a/src/cegis/genetic/ga_learn.inc b/src/cegis/genetic/ga_learn.inc deleted file mode 100644 index 31bfb7cc986..00000000000 --- a/src/cegis/genetic/ga_learn.inc +++ /dev/null @@ -1,173 +0,0 @@ -#include - -#include - -template -template -ga_learnt::ga_learnt( - const optionst &options, randomt &random, selectt &select, mutatet &mutate, - crosst &cross, fitnesst &fitness, convertt &convert) : - options(options), havoc([&random](individualt &ind) - { random.havoc(ind);}), select(select), mutate(mutate), cross(cross), fitness( - fitness), convert(convert), program_startup(clockt::now()), max_runtime_in_seconds( - options.get_unsigned_int_option(CEGIS_MAX_RUNTIME)) -{ -} - -template -template -void ga_learnt::seed( - seedt &seeder) -{ - fitness.seed(seeder); - const size_t pop_size=options.get_unsigned_int_option(CEGIS_POPSIZE); - pop.resize(pop_size); - for (individualt &ind : pop) - havoc(ind); - typename populationt::iterator ind=pop.begin(); - std::advance(ind, rand() % pop.size()); - convert.convert(current_candidate, *ind); -} - -template -const typename ga_learnt::candidatet &ga_learnt< - selectt, mutatet, crosst, fitnesst, convertt>::next_candidate() const -{ - return current_candidate; -} - -namespace -{ -bool roll_rate(const int rate) -{ - return rand() < RAND_MAX / 100 * rate; -} - -bool should_mutate(const optionst &opt) -{ - return roll_rate(opt.get_unsigned_int_option("cegis-genetic-mutation-rate")); -} - -bool should_replace(const optionst &opt) -{ - return roll_rate(opt.get_unsigned_int_option("cegis-genetic-replace-rate")); -} -} - -template -bool ga_learnt::set_fitness( - individualt &ind) -{ - // XXX: Specific optimisation for PLDI 2016 submissions. - mutate.post_process(ind); - // XXX: Specific optimisation for PLDI 2016 submissions. - fitness.set_fitness(ind); - typedef typename individualt::fitnesst target_fitnesst; - const target_fitnesst target_fitness=fitness.get_target_fitness(); - const bool have_solution=(target_fitness == ind.fitness); - if (have_solution) convert.convert(current_candidate, ind); - return have_solution; -} - -template -template -bool ga_learnt::learn(itert first, - const itert &last) -{ - for (; first != last; ++first) - fitness.add_test_case(*first); - - const typename selectt::populationt::iterator it=fitness.init(pop); - if (pop.end() != it) - { - convert.convert(current_candidate, *it); - return true; - } - - typename selectt::selectiont selection; - while (!is_evolving || is_evolving()) - { - if (std::chrono::duration_cast(clockt::now() - program_startup) - > std::chrono::seconds(max_runtime_in_seconds)) return false; - selection=select.select(pop); - if (should_mutate(options)) - { - if (!selection.can_mutate()) return false; - individualt &lhs=selection.mutation_lhs(); - mutate(lhs, selection.mutation_rhs()); - if (set_fitness(lhs)) return true; - } else if (should_replace(options)) - { - individualt &ind=*selection.children.back(); - mutate.havoc(ind); - if (set_fitness(ind)) return true; - } else - { - if (!selection.can_cross()) return false; - cross(selection.parents, selection.children); - for (const typename populationt::iterator &child : selection.children) - if (set_fitness(*child)) return true; - } - } - return false; -} - -template -void ga_learnt::show_candidate( - messaget::mstreamt &os) const -{ - show_candidate(os, current_candidate); -} - -template -void ga_learnt::show_candidate( - messaget::mstreamt &os, const candidatet &candidate) const -{ - convert.show(os, candidate); -} - -template -void ga_learnt::set_termination_condition( - const std::function is_evolving) -{ - this->is_evolving=is_evolving; -} - -template -void ga_learnt::set_solution_size_range( - const size_t min, const size_t max) -{ - // TODO: ga_learn currently gets this info directly from the options. Refactor! -} - -template -void ga_learnt::add_paragon( - individualt ind) -{ - const size_t num_sacrifices=std::max(size_t(1u), pop.size() / 200); - const size_t rounds=10u; - typename populationt::iterator sacrifice=pop.end(); - for (size_t s=0; s < num_sacrifices; ++s) - { - for (size_t round=0; round < rounds; ++round) - { - typename populationt::iterator candidate=pop.begin(); - std::advance(candidate, rand() % pop.size()); - if (pop.end() == sacrifice || sacrifice->fitness < candidate->fitness) - sacrifice=candidate; - } - *sacrifice=ind; - set_fitness(*sacrifice); - assert(sacrifice->fitness == fitness.get_target_fitness()); - } -} diff --git a/src/cegis/genetic/genetic_constant_strategy.cpp b/src/cegis/genetic/genetic_constant_strategy.cpp deleted file mode 100644 index 4840fb2be26..00000000000 --- a/src/cegis/genetic/genetic_constant_strategy.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -namespace -{ -std::string get_name(size_t index) -{ - std::string name(CEGIS_CONSTANT_PREFIX); - return name+=integer2string(index); -} - -// XXX: Debug -bool constants_printed=false; -// XXX: Debug -} - -// XXX: Debug -#include -// XXX: Debug - -size_t genetic_constant_strategy(invariant_programt &prog, - const size_t max_length) -{ - symbol_tablet &st=prog.st; - const namespacet ns(st); - goto_functionst &gf=prog.gf; - goto_programt::targett pos=prog.invariant_range.begin; - const std::vector literals(collect_literal_constants(prog)); - size_t max_word_width=0u; - size_t const_index=0u; - // XXX: Literals strategy, benchmark performance - for(const constant_exprt &expr : literals) - { - // XXX: Debug - if(!constants_printed) - { - std::cout << "" << const_index << "" << std::endl; - std::cout << "" << from_expr(ns, "", expr) << "\n"; - } - // XXX: Debug - const std::string base_name(get_name(const_index++)); - pos=declare_cegis_meta_variable(st, gf, pos, base_name, expr.type()); - pos=assign_cegis_meta_variable(st, gf, pos, base_name, expr); - max_word_width=std::max(max_word_width, get_min_word_width(expr)); - } - constants_printed=true; - - // XXX: 0/1 constant strategy, benchmark performance - /*const typet type(danger_meta_type()); - const bv_spect spec(type); - const std::vector def={ from_integer(0u, type), from_integer( - 1u, type), from_integer(spec.max_value().to_ulong(), type) };*/ - /*const std::vector def={ from_integer(0u, type), from_integer( - 1u, type) };*/ - /*for (const constant_exprt &expr : def) - { - // XXX: Debug - std::cout << "" << const_index << "" << std::endl; - std::cout << "" << expr.to_string() << "" << std::endl; - // XXX: Debug - const std::string base_name(get_name(const_index++)); - pos=declare_danger_variable(st, gf, pos, base_name, expr.type()); - pos=assign_danger_variable(st, gf, pos, base_name, expr); - max_word_width=std::max(max_word_width, get_min_word_width(expr)); - }*/ - return max_word_width; - /*typet type=danger_meta_type(); // XXX: Currently single data type - type.set(ID_C_constant, true); - // TODO: Multiply by number of programs and loops? - for (size_t i=0; i < max_length; ++i) - pos=declare_danger_variable(st, gf, pos, get_ndt_name(const_index++), type);*/ -} diff --git a/src/cegis/genetic/genetic_constant_strategy.h b/src/cegis/genetic/genetic_constant_strategy.h deleted file mode 100644 index 12bfafaf31e..00000000000 --- a/src/cegis/genetic/genetic_constant_strategy.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_GENETIC_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_GENETIC_GENETIC_CONSTANT_STRATEGY_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param max_length - */ -size_t genetic_constant_strategy(class invariant_programt &program, - size_t max_length); - -#endif // CPROVER_CEGIS_GENETIC_GENETIC_CONSTANT_STRATEGY_H diff --git a/src/cegis/genetic/genetic_preprocessing.h b/src/cegis/genetic/genetic_preprocessing.h deleted file mode 100644 index b0875c413af..00000000000 --- a/src/cegis/genetic/genetic_preprocessing.h +++ /dev/null @@ -1,68 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_GENETIC_PREPROCESSING_H -#define CPROVER_CEGIS_GENETIC_GENETIC_PREPROCESSING_H - -/** - * @brief - * - * @details - */ -template -class genetic_preprocessingt -{ - const class optionst &options; - preproct &preproc; -public: - /** - * @brief - * - * @details - * - * @param options - * @param preproc - */ - genetic_preprocessingt(const optionst &options, preproct &preproc); - - /** - * @brief - * - * @details - */ - ~genetic_preprocessingt(); - - /** - * @brief Provides the minimum solution size. - * - * @details Properties like the number of skolem choices dictate the minimum - * solution size. - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_solution_length - */ - void operator()(const size_t max_solution_length); -}; - -#include "genetic_preprocessing.inc" - -#endif // CPROVER_CEGIS_GENETIC_GENETIC_PREPROCESSING_H diff --git a/src/cegis/genetic/genetic_preprocessing.inc b/src/cegis/genetic/genetic_preprocessing.inc deleted file mode 100644 index f071b1fbc75..00000000000 --- a/src/cegis/genetic/genetic_preprocessing.inc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -template -genetic_preprocessingt::genetic_preprocessingt( - const optionst &options, preproct &preproc) : - options(options), preproc(preproc) -{ -} - -template -genetic_preprocessingt::~genetic_preprocessingt() -{ -} - -template -size_t genetic_preprocessingt::get_min_solution_size() const -{ - return preproc.get_min_solution_size(); -} - -template -void genetic_preprocessingt::operator()() -{ - preproc(); -} - -template -void genetic_preprocessingt::operator()( - const size_t max_solution_length) -{ - preproc(options.get_unsigned_int_option("cegis-max-size")); -} diff --git a/src/cegis/genetic/genetic_settings.cpp b/src/cegis/genetic/genetic_settings.cpp deleted file mode 100644 index 0997c1ff693..00000000000 --- a/src/cegis/genetic/genetic_settings.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -genetic_settingst::~genetic_settingst() -{ -} diff --git a/src/cegis/genetic/genetic_settings.h b/src/cegis/genetic/genetic_settings.h deleted file mode 100644 index 3eddd3ee225..00000000000 --- a/src/cegis/genetic/genetic_settings.h +++ /dev/null @@ -1,98 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_GENETIC_SETTINGS_H -#define CPROVER_CEGIS_GENETIC_GENETIC_SETTINGS_H - -#include - -/** - * @brief - * - * @details - */ -class genetic_settingst -{ -public: - /** - * @brief - * - * @details - * - * @param prog_index - * - * @return - */ - virtual size_t min_prog_sz(size_t prog_index) = 0; - - /** - * @brief - * - * @details - * - * @param prog_index - * - * @return - */ - virtual size_t max_prog_sz(size_t prog_index) = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual size_t max_prog_sz() = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual size_t num_progs() = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual size_t num_vars() = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual size_t num_consts() = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual size_t num_x0() = 0; - - /** - * @brief - * - * @details - */ - virtual ~genetic_settingst(); -}; - -#endif // CPROVER_CEGIS_GENETIC_GENETIC_SETTINGS_H diff --git a/src/cegis/genetic/instruction_set_info_factory.cpp b/src/cegis/genetic/instruction_set_info_factory.cpp deleted file mode 100644 index a6213810fa4..00000000000 --- a/src/cegis/genetic/instruction_set_info_factory.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include - -instruction_set_info_factoryt::instruction_set_info_factoryt( - const goto_programt &body) : - body_provider([&body] () -> const goto_programt & - { return body;}) -{ -} - -instruction_set_info_factoryt::~instruction_set_info_factoryt() -{ -} - -namespace -{ -const char OPCODE_SIGNIFIER[]="::opcode"; -const char OP_SIGNIFIER[]="::op"; - -class count_ops: public const_expr_visitort -{ - size_t count; -public: - count_ops() : - count(0u) - { - } - - virtual ~count_ops() - { - } - - virtual void operator()(const exprt &expr) - { - if(ID_symbol != expr.id()) return; - const std::string &id=id2string(to_symbol_expr(expr).get_identifier()); - if(std::string::npos != id.find(OPCODE_SIGNIFIER)) return; - const std::string::size_type op_id_pos=id.find(OP_SIGNIFIER); - if(std::string::npos == op_id_pos) return; - const std::string::size_type value_pos=op_id_pos + strlen(OP_SIGNIFIER); - const mp_integer::llong_t v=string2integer(id.substr(value_pos)).to_long(); - const size_t op_id=static_cast(v); - count=std::max(count, op_id + 1); - } - - void operator()(const goto_programt::instructiont &instr) - { - instr.guard.visit(*this); - instr.code.visit(*this); - } - - const count_ops &operator()(const goto_programt::instructionst &instrs) - { - for(const goto_programt::instructiont &instr : instrs) - this->operator()(instr); - return *this; - } - - size_t get_count() const - { - return count; - } -}; - -class transform_to_info -{ -public: - transform_to_info() - { - } - - instruction_set_infot::value_type operator()( - const instruction_sett::value_type &instr) const - { - const size_t count=count_ops()(instr.second).get_count(); - return std::make_pair(instr.first, count); - } -}; - -void initialise(instruction_set_infot &info, instruction_sett &ins, - const std::function &body_provider) -{ - if(!info.empty()) return; - const goto_programt &body=body_provider(); - ins=extract_instruction_set(body); - const transform_to_info op; - std::transform(ins.begin(), ins.end(), std::inserter(info, info.end()), op); -} -} - -const instruction_sett &instruction_set_info_factoryt::get_instructions() -{ - initialise(info, instructions, body_provider); - return instructions; -} - -const instruction_set_infot &instruction_set_info_factoryt::get_info() -{ - initialise(info, instructions, body_provider); - return info; -} diff --git a/src/cegis/genetic/instruction_set_info_factory.h b/src/cegis/genetic/instruction_set_info_factory.h deleted file mode 100644 index 69e158789f0..00000000000 --- a/src/cegis/genetic/instruction_set_info_factory.h +++ /dev/null @@ -1,80 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_INSTRUCTION_SET_INFO_FACTORY_H -#define CPROVER_CEGIS_GENETIC_INSTRUCTION_SET_INFO_FACTORY_H - -#include - -#include - -typedef std::map instruction_sett; -typedef std::map instruction_set_infot; - -/** - * @brief - * - * @details - */ -class instruction_set_info_factoryt -{ - std::function body_provider; - instruction_sett instructions; - instruction_set_infot info; -public: - /** - * @brief - * - * @details - * - * @param body - */ - explicit instruction_set_info_factoryt(const goto_programt &body); - - /** - * @brief - * - * @details - * - * @param provider - * @tparam goto_program_providert - */ - template - explicit instruction_set_info_factoryt( - const goto_program_providert &provider); - - /** - * @brief - * - * @details - */ - ~instruction_set_info_factoryt(); - - /** - * @brief - * - * @details - * - * @return - */ - const instruction_sett &get_instructions(); - - /** - * @brief - * - * @details - * - * @return - */ - const instruction_set_infot &get_info(); -}; - -#include "instruction_set_info_factory.inc" - -#endif // CPROVER_CEGIS_GENETIC_INSTRUCTION_SET_INFO_FACTORY_H diff --git a/src/cegis/genetic/instruction_set_info_factory.inc b/src/cegis/genetic/instruction_set_info_factory.inc deleted file mode 100644 index 4a1ce3821d0..00000000000 --- a/src/cegis/genetic/instruction_set_info_factory.inc +++ /dev/null @@ -1,6 +0,0 @@ -template -instruction_set_info_factoryt::instruction_set_info_factoryt( - const goto_program_providert &provider) : - body_provider(provider) -{ -} diff --git a/src/cegis/genetic/lazy_fitness.h b/src/cegis/genetic/lazy_fitness.h deleted file mode 100644 index 6563d5d1a77..00000000000 --- a/src/cegis/genetic/lazy_fitness.h +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_LAZY_FITNESS_H -#define CPROVER_CEGIS_GENETIC_LAZY_FITNESS_H - -/** - * @brief - * - * @details - * - * @tparam populationt - * @tparam test_runnert - * @tparam counterexample_typet - */ -template -class lazy_fitnesst -{ -public: - typedef counterexample_typet counterexamplet; - typedef std::deque counterexamplest; - typedef typename populationt::value_type individualt; - typedef typename populationt::iterator iterator; - typedef std::map > test_case_datat; -private: - test_runnert &test_runner; - counterexamplest counterexamples; - test_case_datat test_case_data; - - iterator find_candidate(populationt &pop); -public: - /** - * @brief - * - * @details - * - * @param test_runner - */ - explicit lazy_fitnesst(test_runnert &); - - /** - * @brief - * - * @details - */ - ~lazy_fitnesst(); - - /** - * @brief - * - * @details - * - * @param seed - * @tparam seedt - */ - template - void seed(seedt &seed); - - /** - * @brief - * - * @details - * - * @param ce - */ - void add_test_case(const counterexamplet &ce); - - /** - * @brief - * - * @details - * - * @param pop - */ - iterator init(populationt &pop); - - /** - * @brief - * - * @details - * - * @param individual - */ - void set_fitness(individualt &individual); - - /** - * @brief - * - * @details - */ - typename individualt::fitnesst get_target_fitness() const; - - /** - * @brief - * - * @details - * - * @return - */ - const test_case_datat &get_test_case_data() const; -}; - -#include "lazy_fitness.inc" - -#endif // CPROVER_CEGIS_GENETIC_LAZY_FITNESS_H diff --git a/src/cegis/genetic/lazy_fitness.inc b/src/cegis/genetic/lazy_fitness.inc deleted file mode 100644 index 53db522d131..00000000000 --- a/src/cegis/genetic/lazy_fitness.inc +++ /dev/null @@ -1,123 +0,0 @@ -#include - -template -lazy_fitnesst::lazy_fitnesst( - test_runnert &test_runner) : - test_runner(test_runner) -{ -} - -template -lazy_fitnesst::~lazy_fitnesst() -{ -} - -template -template -void lazy_fitnesst::seed( - seedt &seeder) -{ - seeder(counterexamples); -} - -template -void lazy_fitnesst::add_test_case( - const counterexamplet &ce) -{ - const typename counterexamplest::iterator end=counterexamples.end(); - assert(end == std::find(counterexamples.begin(), end, ce)); - counterexamples.push_back(ce); -} - -template -typename lazy_fitnesst::iterator lazy_fitnesst< - populationt, test_runnert, counterexample_typet>::find_candidate( - populationt &pop) -{ - const size_t ces=get_target_fitness(); - for (iterator it=pop.begin(); it != pop.end(); ++it) - if (it->fitness == ces) return it; - return pop.end(); -} - -namespace -{ -bool &new_test_result(std::list &test_case_data) -{ - test_case_data.push_back(false); - return test_case_data.back(); -} - -template -class test_callbackt -{ - typename individualt::fitnesst &fitness; - bool &test_result; -public: - test_callbackt(individualt &ind, std::list &test_case_data) : - fitness(ind.fitness), test_result(new_test_result(test_case_data)) - { - } - - void operator()(const bool success) - { - if (success) ++fitness; - test_result=success; - } -}; -} - -template -typename lazy_fitnesst::iterator lazy_fitnesst< - populationt, test_runnert, counterexample_typet>::init(populationt &pop) -{ - const counterexamplest &ces=counterexamples; - const size_t ce_count=ces.size(); - for (individualt &individual : pop) - { - std::list &ind_test_data=test_case_data[&individual]; - for (size_t i=ind_test_data.size(); i < ce_count; ++i) - test_runner.run_test(individual, ces[i], - test_callbackt(individual, ind_test_data)); - const iterator candidate=find_candidate(pop); - if (pop.end() != candidate) - { - test_runner.join(); - return candidate; - } - } - test_runner.join(); - return find_candidate(pop); -} - -template -void lazy_fitnesst::set_fitness( - individualt &individual) -{ - individual.fitness=0u; - std::list &ind_test_data=test_case_data[&individual]; - ind_test_data.clear(); - const size_t num_ces=counterexamples.size(); - for (size_t i=0; i < num_ces; ++i) - test_runner.run_test(individual, counterexamples[i], - test_callbackt(individual, ind_test_data)); - test_runner.join(); -} - -template -typename lazy_fitnesst::individualt::fitnesst lazy_fitnesst< - populationt, test_runnert, counterexample_typet>::get_target_fitness() const -{ - size_t fitness=0; - const size_t end=counterexamples.size(); - for (size_t i=0u; i < end; ++i) - ++fitness; - return fitness; -} - -template -const typename lazy_fitnesst::test_case_datat &lazy_fitnesst< - populationt, test_runnert, counterexample_typet>::get_test_case_data() const -{ - return test_case_data; -} diff --git a/src/cegis/genetic/lazy_genetic_settings.h b/src/cegis/genetic/lazy_genetic_settings.h deleted file mode 100644 index 1229ce85667..00000000000 --- a/src/cegis/genetic/lazy_genetic_settings.h +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_LAZY_GENETIC_SETTINGS_H -#define CPROVER_CEGIS_GENETIC_LAZY_GENETIC_SETTINGS_H - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class lazy_genetic_settingst: public genetic_settingst -{ - wrappedt wrapped; - std::pair stored_max_prog_sz; - std::pair stored_num_progs; - std::pair stored_num_vars; - std::pair stored_num_consts; - std::pair stored_num_x0; -public: - /** - * @brief - * - * @details - */ - explicit lazy_genetic_settingst(const wrappedt &wrapped); - - /** - * @brief - * - * @details - */ - virtual ~lazy_genetic_settingst(); - - /** - * @see genetic_settingst::min_prog_sz(size_t) - */ - virtual size_t min_prog_sz(size_t prog_index); - - /** - * @see genetic_settingst::max_prog_sz(size_t) - */ - virtual size_t max_prog_sz(size_t prog_index); - - /** - * @brief - * - * @details - * - * @return - */ - std::function max_prog_sz_provider(); - - /** - * @brief - * - * @details - * - * @return - */ - std::function max_prog_sz_per_index_provider(); - - /** - * @see genetic_settingst::max_prog_sz() - */ - virtual size_t max_prog_sz(); - - /** - * @see genetic_settingst::num_progs() - */ - virtual size_t num_progs(); - - /** - * @see genetic_settingst::num_vars() - */ - virtual size_t num_vars(); - - /** - * @see genetic_settingst::num_consts() - */ - virtual size_t num_consts(); - - /** - * @brief - * - * @details - * - * @return - */ - std::function num_consts_provder(); - - /** - * @see genetic_settingst::num_x0() - */ - virtual size_t num_x0(); -}; - -#include "lazy_genetic_settings.inc" - -#endif // CPROVER_CEGIS_GENETIC_LAZY_GENETIC_SETTINGS_H diff --git a/src/cegis/genetic/lazy_genetic_settings.inc b/src/cegis/genetic/lazy_genetic_settings.inc deleted file mode 100644 index a59adb2be03..00000000000 --- a/src/cegis/genetic/lazy_genetic_settings.inc +++ /dev/null @@ -1,84 +0,0 @@ -#include - -template -lazy_genetic_settingst::lazy_genetic_settingst( - const wrappedt &wrapped) : - wrapped(wrapped) -{ -} - -template -lazy_genetic_settingst::~lazy_genetic_settingst() -{ -} - -template -size_t lazy_genetic_settingst::min_prog_sz(const size_t prog_index) -{ - return wrapped.min_prog_sz(prog_index); -} - -template -size_t lazy_genetic_settingst::max_prog_sz(size_t prog_index) -{ - return wrapped.max_prog_sz(prog_index); -} - -template -std::function lazy_genetic_settingst::max_prog_sz_provider() -{ - return [this]() - { return wrapped.max_prog_sz();}; -} - -template -std::function lazy_genetic_settingst::max_prog_sz_per_index_provider() -{ - return [this](const size_t prog_index) - { return wrapped.max_prog_sz(prog_index);}; -} - -#define lazy_cache_access(store, source) \ - if (!store.first) \ - { \ - store.second=source(); \ - store.first=true; \ - } \ - return store.second; - -template -size_t lazy_genetic_settingst::max_prog_sz() -{ - lazy_cache_access(stored_max_prog_sz, wrapped.max_prog_sz); -} - -template -size_t lazy_genetic_settingst::num_progs() -{ - lazy_cache_access(stored_num_progs, wrapped.num_progs); -} - -template -size_t lazy_genetic_settingst::num_vars() -{ - lazy_cache_access(stored_num_vars, wrapped.num_vars); -} - -template -size_t lazy_genetic_settingst::num_consts() -{ - lazy_cache_access(stored_num_consts, wrapped.num_consts); -} - -template -std::function lazy_genetic_settingst::num_consts_provder() -{ - return [this]() - { return wrapped.num_consts();}; -} - -template -size_t lazy_genetic_settingst::num_x0() -{ - lazy_cache_access(stored_num_x0, wrapped.num_x0); -} diff --git a/src/cegis/genetic/learn_preprocess_seed.h b/src/cegis/genetic/learn_preprocess_seed.h deleted file mode 100644 index 9bfac990f85..00000000000 --- a/src/cegis/genetic/learn_preprocess_seed.h +++ /dev/null @@ -1,48 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_LEARN_PREPROCESS_SEED_H -#define CPROVER_CEGIS_GENETIC_LEARN_PREPROCESS_SEED_H - -/** - * @brief - * - * @details - */ -template -class learn_preprocess_seedt -{ - const class optionst &options; - learnt &learn; -public: - /** - * @brief - * - * @details - * - * @param options - * @param learn - */ - learn_preprocess_seedt(const optionst &options, learnt &learn); - - /** - * @brief - * - * @details - * - * @param ces - * @tparam ces - */ - template - void operator()(cest &ces) const; -}; - -#include "learn_preprocess_seed.inc" - -#endif // CPROVER_CEGIS_GENETIC_LEARN_PREPROCESS_SEED_H diff --git a/src/cegis/genetic/learn_preprocess_seed.inc b/src/cegis/genetic/learn_preprocess_seed.inc deleted file mode 100644 index a73a1a2609c..00000000000 --- a/src/cegis/genetic/learn_preprocess_seed.inc +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include - -template -learn_preprocess_seedt::learn_preprocess_seedt(const optionst &options, - learnt &learn) : - options(options), learn(learn) -{ -} - -template -template -void learn_preprocess_seedt::operator()(cest &ces) const -{ - const size_t max_sz=options.get_unsigned_int_option(CEGIS_MAX_SIZE); - learn.process(max_sz); -} diff --git a/src/cegis/genetic/match_select.cpp b/src/cegis/genetic/match_select.cpp deleted file mode 100644 index 2359dc7c7bb..00000000000 --- a/src/cegis/genetic/match_select.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -match_selectt::match_selectt(const test_case_datat &test_case_data, - random_individualt &random, size_t pop_size, size_t rounds) : - test_case_data(test_case_data), random(random), pop_size(pop_size), rounds( - rounds) -{ -} - -match_selectt::~match_selectt() -{ -} - -void match_selectt::init(populationt &pop) -{ - pop.resize(pop_size); - for(program_individualt &ind : pop) - random.havoc(ind); -} - -bool match_selectt::selectiont::can_cross() const -{ - return true; -} - -bool match_selectt::selectiont::can_mutate() const -{ - return true; -} - -match_selectt::individualt &match_selectt::selectiont::mutation_lhs() -{ - return *children.front(); -} - -const match_selectt::individualt &match_selectt::selectiont::mutation_rhs() const -{ - return *parents.front(); -} - -namespace -{ -typedef match_selectt::populationt::iterator contestantt; - -class is_contestant_less_thant -{ - const contestantt no_contestant; -public: - explicit is_contestant_less_thant(const contestantt &no_contestant) : - no_contestant(no_contestant) - { - } - - bool operator()(const contestantt &lhs, const contestantt &rhs) const - { - const bool is_rhs_null=no_contestant == rhs; - if(no_contestant == lhs) return !is_rhs_null; - if(is_rhs_null) return false; - return lhs->fitness < rhs->fitness; - } -}; - -size_t get_match_fitness(const match_selectt::test_case_datat &data, - const contestantt &no_contestant, const contestantt &father, - const contestantt &mother) -{ - const match_selectt::test_case_datat::const_iterator f=data.find(&*father); - assert(data.end() != f); - const match_selectt::test_case_datat::const_iterator m=data.find(&*mother); - assert(data.end() != m); - const std::list &f_dt=f->second; - const std::list &m_dt=m->second; - const size_t f_data_size=f_dt.size(); - assert(f_data_size == m_dt.size()); - size_t match_value=mother->fitness; - typedef std::list::const_iterator itert; - for(itert fv=f_dt.begin(), mv=m_dt.begin(); fv != f_dt.end(); ++fv, ++mv) - if(*fv != *mv) match_value+=2; // Excessive? - return match_value; -} -} - -match_selectt::selectiont match_selectt::select(populationt &pop) -{ - const contestantt no_contestant=pop.end(); - const is_contestant_less_thant is_less_than(no_contestant); - contestantt father=no_contestant; - for(size_t contestants=0; contestants < rounds / 2;) - { - contestantt contestant=pop.begin(); - std::advance(contestant, random.rand() % pop.size()); - if(father == contestant) continue; - if(is_less_than(father, contestant)) father=contestant; - ++contestants; - } - contestantt mother=no_contestant; - size_t match_fitness=0u; - for(size_t contestants=0; contestants < rounds / 2;) - { - contestantt contestant=pop.begin(); - std::advance(contestant, random.rand() % pop.size()); - if(mother == contestant || father == contestant) continue; - if(no_contestant == mother) mother=contestant; - else - { - const size_t new_match=get_match_fitness(test_case_data, no_contestant, - father, contestant); - if(match_fitness < new_match) - { - match_fitness=new_match; - mother=contestant; - } - } - ++contestants; - } - contestantt son=no_contestant; - contestantt daughter=no_contestant; - for(size_t contestants=0; contestants < rounds / 2;) - { - contestantt contestant=pop.begin(); - std::advance(contestant, random.rand() % pop.size()); - if(father == contestant || mother == contestant || son == contestant - || daughter == contestant) continue; - if(no_contestant == son) son=contestant; - else if(no_contestant == daughter) daughter=contestant; - else if(son->fitness > contestant->fitness) - { - daughter=son; - son=contestant; - } else if(daughter->fitness > contestant->fitness) daughter=contestant; - ++contestants; - } - selectiont selection; - selection.parents.push_back(father); - assert(no_contestant != father); - selection.parents.push_back(mother); - assert(no_contestant != mother); - selection.children.push_back(son); - assert(no_contestant != son); - selection.children.push_back(daughter); - assert(no_contestant != daughter); - return selection; -} diff --git a/src/cegis/genetic/match_select.h b/src/cegis/genetic/match_select.h deleted file mode 100644 index 07e67df55aa..00000000000 --- a/src/cegis/genetic/match_select.h +++ /dev/null @@ -1,84 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_MATCH_SELECT_H -#define CPROVER_CEGIS_GENETIC_MATCH_SELECT_H - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class match_selectt -{ -public: - typedef population_typet populationt; - typedef typename populationt::value_type individualt; - typedef family_selectiont selectiont; - typedef typename selectiont::individualst individualst; - typedef typename populationt::iterator contestantt; - typedef std::map > test_case_datat; -private: - const test_case_datat &test_case_data; - const std::function next_random_unsigned_int; - const size_t rounds; -public: - /** - * @brief - * - * @details - * - * @param test_case_data - * @param random - * @param rounds - */ - match_selectt( - const test_case_datat &test_case_data, - std::function random, - size_t rounds); - - /** - * @brief - * - * @details - * - * @param test_case_data - * @param rounds - */ - match_selectt( - const test_case_datat &test_case_data, - size_t rounds); - - /** - * @brief - * - * @details - */ - ~match_selectt(); - - /** - * @brief - * - * @details - * - * @param population - * - * @return - */ - selectiont select(populationt &population) const; -}; - -#include "match_select.inc" - -#endif // CPROVER_CEGIS_GENETIC_MATCH_SELECT_H diff --git a/src/cegis/genetic/match_select.inc b/src/cegis/genetic/match_select.inc deleted file mode 100644 index fe4d464b6b3..00000000000 --- a/src/cegis/genetic/match_select.inc +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include - -template -match_selectt::match_selectt(const test_case_datat &test_case_data, - const std::function random, const size_t rounds) : - test_case_data(test_case_data), next_random_unsigned_int(random), rounds( - rounds) -{ -} - -template -match_selectt::match_selectt(const test_case_datat &test_case_data, - const size_t rounds) : - test_case_data(test_case_data), next_random_unsigned_int(::rand), rounds( - rounds) -{ -} - -template -match_selectt::~match_selectt() -{ -} - -namespace -{ -template -class is_contestant_less_thant -{ - const contestantt no_contestant; -public: - is_contestant_less_thant(const contestantt &no_contestant) : - no_contestant(no_contestant) - { - } - - bool operator()(const contestantt &lhs, const contestantt &rhs) const - { - const bool is_rhs_null=no_contestant == rhs; - if (no_contestant == lhs) return !is_rhs_null; - if (is_rhs_null) return false; - return lhs->fitness < rhs->fitness; - } -}; - -template -size_t get_match_fitness( - const typename match_selectt::test_case_datat &data, - const typename match_selectt::contestantt &no_contestant, - const typename match_selectt::contestantt &father, - const typename match_selectt::contestantt &mother) -{ - typedef typename match_selectt::test_case_datat::const_iterator test_data_const_iterator; - const test_data_const_iterator f=data.find(&*father); - assert(data.end() != f); - const test_data_const_iterator m=data.find(&*mother); - assert(data.end() != m); - const std::list &f_dt=f->second; - const std::list &m_dt=m->second; - const size_t f_data_size=f_dt.size(); - assert(f_data_size == m_dt.size()); - size_t match_value=mother->fitness; - typedef std::list::const_iterator itert; - for (itert fv=f_dt.begin(), mv=m_dt.begin(); fv != f_dt.end(); ++fv, ++mv) - if (*fv != *mv) match_value+=2; // Excessive? - return match_value; -} -} - -template -typename match_selectt::selectiont match_selectt::select( - populationt &pop) const -{ - const contestantt no_contestant=pop.end(); - const is_contestant_less_thant is_less_than(no_contestant); - contestantt father=no_contestant; - for (size_t contestants=0; contestants < rounds / 2;) - { - const contestantt contestant=std::next(pop.begin(), next_random_unsigned_int() % pop.size()); - if (father == contestant) continue; - if (is_less_than(father, contestant)) father=contestant; - ++contestants; - } - contestantt mother=no_contestant; - size_t match_fitness=0u; - for (size_t contestants=0; contestants < rounds / 2;) - { - const contestantt contestant=std::next(pop.begin(), next_random_unsigned_int() % pop.size()); - if (mother == contestant || father == contestant) continue; - if (no_contestant == mother) mother=contestant; - else - { - const size_t new_match=get_match_fitness(test_case_data, - no_contestant, father, contestant); - if (match_fitness < new_match) - { - match_fitness=new_match; - mother=contestant; - } - } - ++contestants; - } - contestantt son=no_contestant; - contestantt daughter=no_contestant; - for (size_t contestants=0; contestants < rounds / 2;) - { - const contestantt contestant=std::next(pop.begin(), next_random_unsigned_int() % pop.size()); - if (father == contestant || mother == contestant || son == contestant - || daughter == contestant) continue; - if (no_contestant == son) son=contestant; - else if (no_contestant == daughter) daughter=contestant; - else if (son->fitness > contestant->fitness) - { - daughter=son; - son=contestant; - } else if (daughter->fitness > contestant->fitness) daughter=contestant; - ++contestants; - } - selectiont selection; - selection.parents.push_back(father); - assert(no_contestant != father); - selection.parents.push_back(mother); - assert(no_contestant != mother); - selection.children.push_back(son); - assert(no_contestant != son); - selection.children.push_back(daughter); - assert(no_contestant != daughter); - return selection; -} diff --git a/src/cegis/genetic/program_individual_test_runner_helper.cpp b/src/cegis/genetic/program_individual_test_runner_helper.cpp deleted file mode 100644 index ef8c42ad260..00000000000 --- a/src/cegis/genetic/program_individual_test_runner_helper.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -void implement_program_individual_deserialise(std::string &source, - const bool danger) -{ - source+= - "#include \n\n" - "#define " CEGIS_PREFIX "next_arg() argv[" CEGIS_PREFIX "deserialise_index++]\n"; - source+= - danger ? - "#define " CEGIS_PREFIX "deserialise_init() unsigned int " CEGIS_PREFIX "deserialise_index=" CEGIS_PREFIX "first_prog_offset\n" : - "#define " CEGIS_PREFIX "deserialise_init() unsigned int " CEGIS_PREFIX "deserialise_index=0u\n"; - source+= - "#define " CEGIS_PREFIX "declare_prog(var_name, sz) const size_t sz=" CEGIS_PREFIX "next_arg(); \\\n" - " struct " CEGIS_PREFIX "instructiont var_name[sz]; \\\n" - "for (unsigned int i=0; i < sizeof(var_name) / sizeof(struct " CEGIS_PREFIX "instructiont); ++i) \\\n" - "{ \\\n" - " var_name[i].opcode=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op0=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op1=" CEGIS_PREFIX "next_arg(); \\\n" - " var_name[i].op2=" CEGIS_PREFIX "next_arg(); \\\n" - "}\n" - "#define " CEGIS_PREFIX "deserialise_x0(var_name) var_name=" CEGIS_PREFIX "next_arg()\n"; - source+= - danger ? - "#define " CEGIS_PREFIX "ce_value_init() unsigned int " CEGIS_PREFIX "ce_index=0u\n" : - "#define " CEGIS_PREFIX "ce_value_init() unsigned int " CEGIS_PREFIX "ce_index=" CEGIS_PREFIX "deserialise_index\n"; - source+= - "#define " CEGIS_PREFIX "ce_value() argv[" CEGIS_PREFIX "ce_index++]\n"; - -} - -namespace -{ -void add_default_return(std::string &source) -{ - source.replace(source.rfind('}'), 1, "return 0;}"); -} -} - -void transform_program_individual_main_to_lib(std::string &source, - const bool danger) -{ - substitute(source, "int main(const int argc, const char * const argv[])\n" - "{\n", "int " CEGIS_FITNESS_TEST_FUNC "(const unsigned int argv[])\n" - "{\n" - "memset(" CEGIS_OPS ", 0, sizeof(" CEGIS_OPS "));\n" - "memset(" CEGIS_RESULT_OPS ", 0, sizeof(" CEGIS_RESULT_OPS "));\n"); - add_default_return(source); -} diff --git a/src/cegis/genetic/program_individual_test_runner_helper.h b/src/cegis/genetic/program_individual_test_runner_helper.h deleted file mode 100644 index a7f1c79b345..00000000000 --- a/src/cegis/genetic/program_individual_test_runner_helper.h +++ /dev/null @@ -1,35 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_PROGRAM_INDIVIDUAL_TEST_RUNNER_HELPER_H -#define CPROVER_CEGIS_GENETIC_PROGRAM_INDIVIDUAL_TEST_RUNNER_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param source - * @param danger - */ -void implement_program_individual_deserialise(std::string &source, bool danger); - -/** - * @brief - * - * @details - * - * @param source - * @param danger - */ -void transform_program_individual_main_to_lib(std::string &source, bool danger); - -#endif // CPROVER_CEGIS_GENETIC_PROGRAM_INDIVIDUAL_TEST_RUNNER_HELPER_H diff --git a/src/cegis/genetic/random_cross.cpp b/src/cegis/genetic/random_cross.cpp deleted file mode 100644 index 507f6a18476..00000000000 --- a/src/cegis/genetic/random_cross.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include - -random_crosst::random_crosst(random_individualt &random) : - random(random) -{ -} - -random_crosst::~random_crosst() -{ -} - -namespace -{ -void fix_result_ops(random_crosst::programt::value_type &instr, - const size_t org_index, const size_t new_index, const size_t num_vars) -{ - for(random_crosst::programt::value_type::opt &op : instr.ops) - { - if(op < num_vars) continue; - if(org_index > new_index) op-=(org_index - new_index); - else op+=(new_index - org_index); - op%=(num_vars + new_index); - } -} -} - -void random_crosst::operator ()(const individualst &parents, - const individualst &children) -{ - assert(parents.size() >= 2 && children.size() >= 2); - const populationt::value_type &father=*parents.front(); - const populationt::value_type &mother=*parents[1u]; - populationt::value_type &son=*children.front(); - populationt::value_type &daughter=*children[1u]; - - const populationt::value_type::x0t &f_x0=father.x0; - const populationt::value_type::x0t &m_x0=mother.x0; - populationt::value_type::x0t &s_x0=son.x0; - populationt::value_type::x0t &d_x0=daughter.x0; - const size_t x0_offset=random.rand() % (f_x0.size() + 1); - std::copy(f_x0.begin(), f_x0.begin() + x0_offset, s_x0.begin()); - std::copy(m_x0.begin() + x0_offset, m_x0.end(), s_x0.begin() + x0_offset); - std::copy(m_x0.begin(), m_x0.begin() + x0_offset, d_x0.begin()); - std::copy(f_x0.begin() + x0_offset, f_x0.end(), d_x0.begin() + x0_offset); - - const size_t prog_limit=parents.front()->programs.size(); - const size_t target_prog_index=random.rand() % prog_limit; - // XXX: Use two two prog_indexes? - const programt &f_prog=father.programs[target_prog_index]; - const programt &m_prog=mother.programs[target_prog_index]; - programt &s_prog=son.programs[target_prog_index]; - programt &d_prog=daughter.programs[target_prog_index]; - - const size_t min_prog_sz=random.get_min_prog_size(target_prog_index); - const size_t max_prog_sz=random.get_max_prog_size(target_prog_index); - const size_t f_sz=f_prog.size(); - const size_t m_sz=m_prog.size(); - if(f_sz < min_prog_sz || m_sz < min_prog_sz) return; - const size_t all_instrs=f_sz + m_sz; - const size_t child_max=std::min(max_prog_sz, all_instrs - min_prog_sz); - const size_t father_offset=random.rand() % (f_sz + 1); - size_t mo_lower=father_offset + m_sz; - mo_lower=mo_lower <= child_max ? 0u : mo_lower - child_max; - const size_t mo_upper=std::min(m_sz, child_max + father_offset - f_sz); - assert(mo_upper >= mo_lower); - const size_t mo_range=mo_upper - mo_lower + 1; - const size_t mother_offset= - mo_range ? mo_lower + random.rand() % mo_range : 0u; - - s_prog.resize(father_offset + m_sz - mother_offset); - d_prog.resize(mother_offset + f_sz - father_offset); - assert(!s_prog.empty()); - assert(!d_prog.empty()); - std::copy(f_prog.begin(), f_prog.begin() + father_offset, s_prog.begin()); - std::copy(m_prog.begin(), m_prog.begin() + mother_offset, d_prog.begin()); - const size_t num_vars=random.get_num_vars(); - for(size_t f=father_offset, m=mother_offset; m < m_sz; ++f, ++m) - fix_result_ops(s_prog[f]=m_prog[m], m, f, num_vars); - for(size_t m=mother_offset, f=father_offset; f < f_sz; ++m, ++f) - fix_result_ops(d_prog[m]=f_prog[f], f, m, num_vars); -} diff --git a/src/cegis/genetic/random_cross.h b/src/cegis/genetic/random_cross.h deleted file mode 100644 index 840a674b72f..00000000000 --- a/src/cegis/genetic/random_cross.h +++ /dev/null @@ -1,55 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_RANDOM_CROSS_H -#define CPROVER_CEGIS_GENETIC_RANDOM_CROSS_H - -#include - -/** - * @brief - * - * @details - */ -class random_crosst -{ - class random_individualt &random; -public: - typedef program_populationt populationt; - typedef std::deque individualst; - typedef populationt::value_type::programt programt; - - /** - * @brief - * - * @details - * - * @param random - */ - explicit random_crosst(random_individualt &random); - - /** - * @brief - * - * @details - */ - ~random_crosst(); - - /** - * @brief - * - * @details - * - * @param parents - * @param children - */ - void operator()(const individualst &parents, const individualst &children); -}; - -#endif // CPROVER_CEGIS_GENETIC_RANDOM_CROSS_H diff --git a/src/cegis/genetic/random_individual.cpp b/src/cegis/genetic/random_individual.cpp deleted file mode 100644 index 34b9c01c93e..00000000000 --- a/src/cegis/genetic/random_individual.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -#include -#include - -random_individualt::random_individualt(const typet &type, - const instruction_set_info_factoryt &info_factory, - genetic_settingst &settings) : - type(type), info_factory(info_factory), settings(settings) -{ -} - -random_individualt::~random_individualt() -{ -} - -size_t random_individualt::prog_size(const size_t index) const -{ - const size_t max=settings.max_prog_sz(index); - if(max == 0u) return 0u; - const size_t min=settings.min_prog_sz(index); - if(min >= max) return min; - const size_t diff=max - min; - return min + rand() % (diff + 1); -} - -program_individualt::instructiont::opcodet random_individualt::opcode() -{ - return rand() % info_factory.get_info().size(); -} - -// XXX: Symmetry breaking? -program_individualt::instructiont::opt random_individualt::op( - const size_t instr_index) const -{ - return rand() % (settings.num_vars() + instr_index); -} - -void random_individualt::havoc(program_individualt::instructiont &instr, - const size_t index) -{ - instr.opcode=opcode(); - const instruction_set_infot &info=info_factory.get_info(); - const instruction_set_infot::const_iterator num_ops=info.find(instr.opcode); - assert(info.end() != num_ops); - instr.ops.resize(num_ops->second); - for(program_individualt::instructiont::opt &o : instr.ops) - o=op(index); -} - -void random_individualt::havoc(program_individualt::programt &prog, - const size_t index) -{ - const size_t prog_sz=prog_size(index); - prog.resize(prog_sz); - for(size_t i=0; i < prog_sz; ++i) - havoc(prog[i], i); -} - -program_individualt::x0t::value_type random_individualt::x0() const -{ - return rand(); -} - -program_individualt::x0t::value_type random_individualt::constant() const -{ - const bv_spect spec(type); - const unsigned int width=spec.width; - const mp_integer::llong_t v=spec.max_value().to_long(); - const unsigned int wordmask=static_cast(v); - const unsigned int r=rand() % 6u; - switch(r) - { - case 0: - return 0; - case 1: - return 1; - case 2: - return wordmask; - case 3: - return 1 << (width - 1); - case 4: - return (1 << (width - 1)) - 1; - default: - return rand(); - } -} - -void random_individualt::havoc(program_individualt &ind) -{ - program_individualt::programst &progs=ind.programs; - progs.resize(settings.num_progs()); - for(size_t i=0u; i < progs.size(); ++i) - havoc(progs[i], i); - post_process(ind); - const size_t number_of_x0=settings.num_x0(); - program_individualt::x0t &ind_x0=ind.x0; - ind_x0.resize(number_of_x0); - const size_t number_of_constants=settings.num_consts(); - for(size_t i=0; i < number_of_constants; ++i) - ind_x0[i]=constant(); - for(size_t i=number_of_constants; i < number_of_x0; ++i) - ind_x0[i]=x0(); -} - -unsigned int random_individualt::rand() const -{ - return ::rand(); -} - -size_t random_individualt::get_num_vars() const -{ - return settings.num_vars(); -} - -size_t random_individualt::get_max_prog_size(const size_t prog_index) const -{ - return settings.max_prog_sz(prog_index); -} - -size_t random_individualt::get_min_prog_size(const size_t prog_index) const -{ - return settings.min_prog_sz(prog_index); -} - -namespace -{ -#define RANKING_INDEX 1u -} - -void random_individualt::post_process(program_individualt &ind) const -{ - // XXX: Specific optimisation for PLDI 2016 submissions. - program_individualt::programst &progs=ind.programs; - if(progs.size() <= RANKING_INDEX) return; - program_individualt::programt &ranking=progs[RANKING_INDEX]; - for(program_individualt::instructiont &instr : ranking) - switch(instr.opcode) - { - case 1u: - case 19u: - instr.opcode=10; - break; - default: - break; - } - // XXX: Specific optimisation for PLDI 2016 submissions. -} - -random_individualt::operator std::function() const -{ - return ::rand; -} diff --git a/src/cegis/genetic/random_individual.h b/src/cegis/genetic/random_individual.h deleted file mode 100644 index cbaf28df4b2..00000000000 --- a/src/cegis/genetic/random_individual.h +++ /dev/null @@ -1,186 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_RANDOM_INDIVIDUAL_H -#define CPROVER_CEGIS_GENETIC_RANDOM_INDIVIDUAL_H - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class random_individualt -{ - const typet type; - instruction_set_info_factoryt info_factory; - class genetic_settingst &settings; -public: - /** - * @brief - * - * @details - * - * @param type - * @param instruction_set_info_factory - * @param settings - */ - random_individualt(const typet &type, - const instruction_set_info_factoryt &info_factory, - genetic_settingst &settings); - - /** - * @brief - * - * @details - */ - ~random_individualt(); - - /** - * @brief - * - * @details - * - * @param index - * - * @return - */ - program_individualt::programt::size_type prog_size(size_t index) const; - - /** - * @brief - * - * @details - * - * @return - */ - program_individualt::instructiont::opcodet opcode(); - - /** - * @brief - * - * @details - * - * @param instr_index - * - * @return - */ - program_individualt::instructiont::opt op(size_t instr_index) const; - - /** - * @brief - * - * @details - * - * @param instr - * @param index - */ - void havoc(program_individualt::instructiont &instr, size_t index); - - /** - * @brief - * - * @details - * - * @param prog - * @param index - */ - void havoc(program_individualt::programt &prog, size_t index); - - /** - * @brief - * - * @details - * - * @return - */ - program_individualt::x0t::value_type x0() const; - - /** - * @brief - * - * @details - * - * @return - */ - program_individualt::x0t::value_type constant() const; - - /** - * @brief - * - * @details - * - * @param ind - */ - void havoc(program_individualt &ind); - - /** - * @brief - * - * @details - * - * @return - */ - unsigned int rand() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_vars() const; - - /** - * @brief - * - * @details - * - * @param prog_index - * - * @return - */ - size_t get_max_prog_size(size_t prog_index) const; - - /** - * @brief - * - * @details - * - * @param prog_index - * - * @return - */ - size_t get_min_prog_size(size_t prog_index) const; - - /** - * @brief - * - * @details - * - * @param ind - */ - void post_process(program_individualt &ind) const; - - /** - * @brief - * - * @details - * - * @return - */ - operator std::function() const; -}; - -#endif // CPROVER_CEGIS_GENETIC_RANDOM_INDIVIDUAL_H diff --git a/src/cegis/genetic/random_mutate.cpp b/src/cegis/genetic/random_mutate.cpp deleted file mode 100644 index 45c85bc7aee..00000000000 --- a/src/cegis/genetic/random_mutate.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -random_mutatet::random_mutatet(random_individualt &random, - const std::function &num_consts) : - random(random), num_consts(num_consts) -{ -} - -random_mutatet::~random_mutatet() -{ -} - -namespace -{ -void mutate_opcode(random_mutatet::individualt::instructiont &instr, - random_individualt &rand, const size_t index) -{ - const random_mutatet::individualt::instructiont::opst old_ops=instr.ops; - rand.havoc(instr, index); - random_mutatet::individualt::instructiont::opst &new_ops=instr.ops; - const size_t size=std::min(old_ops.size(), new_ops.size()); - for(size_t i=0; i < size; ++i) - new_ops[i]=old_ops[i]; -} -} - -void random_mutatet::operator()(individualt &lhs, const individualt &rhs) const -{ - lhs=rhs; - const size_t num_x0=lhs.x0.size(); - size_t num_mutation_candidates=num_x0; - for(const individualt::programt &prog : lhs.programs) - { - for(const individualt::instructiont &instr : prog) - num_mutation_candidates+=instr.ops.size() + 1; - } - - size_t mutation_target=random.rand() % (num_mutation_candidates + 1); - if(mutation_target < num_consts()) - { - lhs.x0[mutation_target]=random.constant(); - return; - } - if(mutation_target < num_x0) - { - lhs.x0[mutation_target]=random.x0(); - return; - } - mutation_target-=num_x0; - for(individualt::programt &prog : lhs.programs) - { - for(size_t i=0; i < prog.size(); ++i) - { - individualt::instructiont &instr=prog[i]; - if(!mutation_target) return mutate_opcode(instr, random, i); - --mutation_target; - const size_t length=instr.ops.size(); - if(mutation_target < length) - { - instr.ops[mutation_target]=random.op(i); - return; - } - mutation_target-=length; - } - } -} - -void random_mutatet::havoc(individualt &ind) const -{ - random.havoc(ind); -} - -void random_mutatet::post_process(program_individualt &ind) const -{ - random.post_process(ind); -} diff --git a/src/cegis/genetic/random_mutate.h b/src/cegis/genetic/random_mutate.h deleted file mode 100644 index f573bbe7bbe..00000000000 --- a/src/cegis/genetic/random_mutate.h +++ /dev/null @@ -1,74 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_RANDOM_MUTATE_H -#define CPROVER_CEGIS_GENETIC_RANDOM_MUTATE_H - -#include - -/** - * @brief - * - * @details - */ -class random_mutatet -{ - class random_individualt &random; - const std::function num_consts; -public: - typedef program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param random - * @param num_consts - */ - random_mutatet(random_individualt &random, - const std::function &num_consts); - - /** - * @brief - * - * @details - */ - ~random_mutatet(); - - /** - * @brief - * - * @details - * - * @param lhs - * @param rhs - */ - void operator()(individualt &lhs, const individualt &rhs) const; - - /** - * @brief - * - * @details - * - * @param lhs - */ - void havoc(individualt &ind) const; - - /** - * @brief - * - * @details - * - * @param ind - */ - void post_process(program_individualt &ind) const; -}; - -#endif // CPROVER_CEGIS_GENETIC_RANDOM_MUTATE_H diff --git a/src/cegis/genetic/serialise_individual.cpp b/src/cegis/genetic/serialise_individual.cpp deleted file mode 100644 index 9bf5da35d8c..00000000000 --- a/src/cegis/genetic/serialise_individual.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -void serialise(std::deque &stream, - const class program_individualt &ind, - const std::function max_prog_sz) -{ - const program_individualt::programst &progs=ind.programs; - const size_t num_progs=progs.size(); - for(size_t i=0; i < num_progs; ++i) - { - if(max_prog_sz(i) == 0u) continue; - const program_individualt::programt &prog=progs[i]; - assert(!prog.empty()); - stream.push_back(static_cast(prog.size())); - for(const program_individualt::instructiont &instr : prog) - { - stream.push_back(static_cast(instr.opcode)); - size_t op_count=0; - for(const program_individualt::instructiont::opt &op : instr.ops) - { - stream.push_back(static_cast(op)); - ++op_count; - } - for(; op_count < 3u; ++op_count) - stream.push_back(0u); - } - } - for(const program_individualt::x0t::value_type &x0 : ind.x0) - stream.push_back(static_cast(x0)); -} - -void serialise(std::deque &stream, - const std::map assignments) -{ - for(const std::pair &assignment : assignments) - { - const bv_arithmetict arith(assignment.second); - const mp_integer::llong_t v=arith.to_integer().to_long(); - stream.push_back(static_cast(v)); - } -} diff --git a/src/cegis/genetic/serialise_individual.h b/src/cegis/genetic/serialise_individual.h deleted file mode 100644 index fe921dd1b08..00000000000 --- a/src/cegis/genetic/serialise_individual.h +++ /dev/null @@ -1,42 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_SERIALISE_INDIVIDUAL_H -#define CPROVER_CEGIS_GENETIC_SERIALISE_INDIVIDUAL_H - -#include -#include - -#include - -/** - * @brief - * - * @details - * - * @param stream - * @param ind - * @param max_prog_sz - */ -void serialise(std::deque &stream, - const class program_individualt &ind, - const std::function max_prog_sz); - -/** - * @brief - * - * @details - * - * @param stream - * @param assignments - */ -void serialise(std::deque &stream, - const std::map assignments); - -#endif // CPROVER_CEGIS_GENETIC_SERIALISE_INDIVIDUAL_H diff --git a/src/cegis/genetic/symex_test_runner.h b/src/cegis/genetic/symex_test_runner.h deleted file mode 100644 index c4aede09473..00000000000 --- a/src/cegis/genetic/symex_test_runner.h +++ /dev/null @@ -1,85 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_SYMEX_TEST_RUNNER_H -#define CPROVER_CEGIS_GENETIC_SYMEX_TEST_RUNNER_H - -#include - -#include - -#ifdef _WIN32 -typedef int pid_t; -#endif - -template -class symex_test_runnert -{ -public: - typedef std::map counterexamplet; - typedef program_individualt individualt; -private: - class bool_pipet - { -#ifndef _WIN32 - int fd[2u]; -#endif - individualt *individual; - public: - pid_t child_pid; - explicit bool_pipet(individualt *individual); - void run_test(const class optionst &options, configt &config, - const counterexamplet &ce); - void join(); - }; - typedef std::deque taskst; - taskst tasks; - const optionst &options; - configt &config; - - void cleanup(); -public: - /** - * @brief - * - * @details - * - * @param options - * @param config - */ - symex_test_runnert(const optionst &options, configt &config); - - /** - * @brief - * - * @details - */ - ~symex_test_runnert(); - - /** - * @brief - * - * @details - * - * @param ind - * @param ce - */ - void run_test(individualt &ind, const counterexamplet &ce); - - /** - * @brief - * - * @details - */ - void join(); -}; - -#include "symex_test_runner.inc" - -#endif // CPROVER_CEGIS_GENETIC_SYMEX_TEST_RUNNER_H diff --git a/src/cegis/genetic/symex_test_runner.inc b/src/cegis/genetic/symex_test_runner.inc deleted file mode 100644 index 9033a97f622..00000000000 --- a/src/cegis/genetic/symex_test_runner.inc +++ /dev/null @@ -1,170 +0,0 @@ -#include - -#ifndef _WIN32 -#include -#include -#include -#endif - -#include -#include - -#ifndef _WIN32 -#define BOOL_PIPE "bool_pipe" -#define FORK "fork" -#endif - -template -symex_test_runnert::bool_pipet::bool_pipet(individualt *individual) : - individual(individual), child_pid(0u) -{ -} - -template -void symex_test_runnert::bool_pipet::run_test( - const class optionst &options, configt &config, const counterexamplet &ce) -{ -#ifndef _WIN32 - if (pipe(fd)) - { - perror(BOOL_PIPE); - throw std::runtime_error("Error creating pipe."); - } - child_pid=fork(); - if (-1 == child_pid) - { - perror(FORK); - throw std::runtime_error("Error forking process."); - } - if (child_pid) - { - close(fd[1u]); - return; - } - close(fd[0u]); -#endif - danger_goto_solutiont converted; - config.convert(converted, *individual); - config.set_candidate(converted); - null_message_handlert msg; - config.set_test_case(ce); - const symbol_tablet &st=config.get_symbol_table(); - cbmc_solverst solvers(options, st, msg); - const goto_functionst &gf=config.get_goto_functions(); - const std::unique_ptr solver=solvers.get_solver(); - bmct bmc(options, st, msg, solver->prop_conv()); - const unsigned char is_safe=(safety_checkert::SAFE == bmc(gf)); -#ifdef _WIN32 - if (is_safe) ++individual->fitness; -#else - ssize_t result; - do - { - result=write(fd[1u], &is_safe, sizeof(unsigned char)); - } while (result == 0); - if (result == -1) - { - perror(BOOL_PIPE); - throw std::runtime_error("Error writing to pipe."); - } - close(fd[1u]); - exit(EXIT_SUCCESS); -#endif -} - -template -void symex_test_runnert::bool_pipet::join() -{ -#ifndef _WIN32 - ssize_t result; - unsigned char is_safe; - do - { - result=read(fd[0u], &is_safe, sizeof(unsigned char)); - if (result == -1) - { - perror(BOOL_PIPE); - throw std::runtime_error("Error reading pipe."); - } - } while (result == 0); - close(fd[0u]); - if (is_safe) ++individual->fitness; -#endif -} - -template -symex_test_runnert::symex_test_runnert(const optionst &options, - configt &config) : - options(options), config(config) -{ -} - -template -symex_test_runnert::~symex_test_runnert() -{ -} - -#ifndef _WIN32 -namespace -{ -#define MAX_CHILDREN 200u - -pid_t wait_child(int &status, const size_t size) -{ - const int options=size < MAX_CHILDREN ? WNOHANG : 0; - return waitpid(-1, &status, options); -} -} -#endif - -template -void symex_test_runnert::cleanup() -{ -#ifndef _WIN32 - std::deque t; - int status; - for (pid_t child_pid=wait_child(status, tasks.size()); child_pid > 0; - child_pid=wait_child(status, tasks.size())) - { - assert(WIFEXITED(status) && EXIT_SUCCESS == WEXITSTATUS(status)); - t.push_back(child_pid); - } - tasks.erase(std::remove_if(tasks.begin(), tasks.end(), [&t](bool_pipet &task) - { - if(std::find(t.begin(), t.end(), task.child_pid) != t.end()) - { - task.join(); - return true; - } - return false;}), tasks.end()); -#endif -} - -template -void symex_test_runnert::run_test(individualt &individual, - const counterexamplet &ce) -{ - cleanup(); - bool_pipet pipe(&individual); -#ifndef _WIN32 - tasks.push_back(pipe); - tasks.back().run_test(options, config, ce); -#else - pipe.run_test(options, config, ce); -#endif -} - -template -void symex_test_runnert::join() -{ -#ifndef _WIN32 - for (bool_pipet &task : tasks) - { - int status; - waitpid(task.child_pid, &status, 0); - assert(WIFEXITED(status) && EXIT_SUCCESS == WEXITSTATUS(status)); - task.join(); - } - tasks.clear(); -#endif -} diff --git a/src/cegis/genetic/tournament_select.cpp b/src/cegis/genetic/tournament_select.cpp deleted file mode 100644 index 16e80cbbb3d..00000000000 --- a/src/cegis/genetic/tournament_select.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -#define MUTATION_OPS 2u - -bool tournament_selectt::selectiont::can_mutate() const -{ - return parents.size() >= MUTATION_OPS; -} - -#define NUM_PARENTS 2u -#define NUM_CHILDREN 2u - -bool tournament_selectt::selectiont::can_cross() const -{ - return parents.size() >= NUM_PARENTS && children.size() >= NUM_CHILDREN; -} - -tournament_selectt::individualt &tournament_selectt::selectiont::mutation_lhs() -{ - return *children.front(); -} - -const tournament_selectt::individualt &tournament_selectt::selectiont::mutation_rhs() const -{ - return *parents.front(); -} - -tournament_selectt::tournament_selectt(random_individualt &random, - size_t pop_size, size_t rounds) : - random(random), pop_size(pop_size), rounds(rounds) -{ -} - -tournament_selectt::~tournament_selectt() -{ -} - -void tournament_selectt::init(populationt &pop) -{ - pop.resize(pop_size); - for(program_individualt &ind : pop) - random.havoc(ind); -} - -namespace -{ -typedef tournament_selectt::populationt::iterator contestantt; - -class arenat -{ - const contestantt no_contestant; - contestantt father; - contestantt mother; - contestantt son; - contestantt daughter; - - bool contains(const contestantt &c) - { - return father == c || mother == c || son == c || daughter == c; - } -public: - explicit arenat(tournament_selectt::populationt &pop) : - no_contestant(pop.end()), father(no_contestant), mother(no_contestant), son( - no_contestant), daughter(no_contestant) - { - } - - bool add_contestant(const contestantt &contestant) - { - if(contains(contestant)) return false; - if(no_contestant == father) father=contestant; - else if(no_contestant == mother) mother=contestant; - else if(no_contestant == son) son=contestant; - else if(no_contestant == daughter) daughter=contestant; - else if(father->fitness < contestant->fitness) - { - mother=father; - father=contestant; - } else if(mother->fitness < contestant->fitness) mother=contestant; - else if(daughter->fitness > contestant->fitness) - { - son=daughter; - daughter=contestant; - } else if(son->fitness > contestant->fitness) son=contestant; - return true; - } - - void select(tournament_selectt::selectiont &selection) - { - selection.parents.push_back(father); - selection.parents.push_back(mother); - selection.children.push_back(son); - selection.children.push_back(daughter); - } -}; -} - -tournament_selectt::selectiont tournament_selectt::select(populationt &pop) -{ - arenat arena(pop); - for(size_t contestants=0; contestants < rounds;) - { - populationt::iterator contestant=pop.begin(); - std::advance(contestant, rand() % pop.size()); - if(arena.add_contestant(contestant)) ++contestants; - } - tournament_selectt::selectiont selection; - arena.select(selection); - return selection; -} diff --git a/src/cegis/genetic/tournament_select.h b/src/cegis/genetic/tournament_select.h deleted file mode 100644 index e4ba07452b5..00000000000 --- a/src/cegis/genetic/tournament_select.h +++ /dev/null @@ -1,62 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_GENETIC_TOURNAMENT_SELECT_H -#define CPROVER_CEGIS_GENETIC_TOURNAMENT_SELECT_H - -#include - -/** - * @brief - * - * @details - */ -template -class tournament_selectt -{ - const size_t rounds; -public: - typedef population_typet populationt; - typedef typename populationt::value_type individualt; - typedef family_selectiont selectiont; - typedef typename selectiont::individualst individualst; - typedef typename populationt::iterator contestantt; - - /** - * @brief - * - * @details - * - * @param random - * @param rounds - */ - explicit tournament_selectt(size_t rounds); - - /** - * @brief - * - * @details - */ - ~tournament_selectt(); - - /** - * @brief - * - * @details - * - * @param population - * - * @return - */ - selectiont select(populationt &population); -}; - -#include "tournament_select.inc" - -#endif // CPROVER_CEGIS_GENETIC_TOURNAMENT_SELECT_H diff --git a/src/cegis/genetic/tournament_select.inc b/src/cegis/genetic/tournament_select.inc deleted file mode 100644 index 338cf91ff97..00000000000 --- a/src/cegis/genetic/tournament_select.inc +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include - -template -tournament_selectt::tournament_selectt(const size_t rounds) : - rounds(rounds) -{ -} - -template -tournament_selectt::~tournament_selectt() -{ -} - -namespace -{ -template -class arenat -{ - typedef typename tournament_selectt::contestantt contestantt; - typedef typename tournament_selectt::selectiont selectiont; - const contestantt no_contestant; - contestantt father; - contestantt mother; - contestantt son; - contestantt daughter; - - bool contains(const contestantt &c) - { - return father == c || mother == c || son == c || daughter == c; - } -public: - arenat(populationt &pop) : - no_contestant(pop.end()), father(no_contestant), mother(no_contestant), son( - no_contestant), daughter(no_contestant) - { - } - - bool add_contestant(const contestantt &contestant) - { - if (contains(contestant)) return false; - if (no_contestant == father) father=contestant; - else if (no_contestant == mother) mother=contestant; - else if (no_contestant == son) son=contestant; - else if (no_contestant == daughter) daughter=contestant; - else if (father->fitness < contestant->fitness) - { - mother=father; - father=contestant; - } else if (mother->fitness < contestant->fitness) mother=contestant; - else if (daughter->fitness > contestant->fitness) - { - son=daughter; - daughter=contestant; - } else if (son->fitness > contestant->fitness) son=contestant; - return true; - } - - void select(selectiont &selection) - { - selection.parents.push_back(father); - selection.parents.push_back(mother); - selection.children.push_back(son); - selection.children.push_back(daughter); - } -}; -} - -template -typename tournament_selectt::selectiont tournament_selectt< - population_typet>::select(populationt &pop) -{ - arenat arena(pop); - for (size_t contestants=0; contestants < rounds;) - { - const contestantt contestant=std::next(pop.begin(), rand() % pop.size()); - if (arena.add_contestant(contestant)) ++contestants; - } - tournament_selectt::selectiont selection; - arena.select(selection); - return selection; -} diff --git a/src/cegis/instructions/instruction_set_factory.cpp b/src/cegis/instructions/instruction_set_factory.cpp deleted file mode 100644 index e8b7b48ff9a..00000000000 --- a/src/cegis/instructions/instruction_set_factory.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include -#include - -namespace -{ -class execute_instruction_handlert -{ - const std::string first_prefix; - const std::string last_prefix; - const std::string single_prefix; - copy_instructionst copy_instruction; - instruction_sett &instruction_set; - bool has_current_instr; - bool is_last_in_range; - size_t instr_idx; - goto_programt::const_targett current_instr_offset; -public: - execute_instruction_handlert(const std::string &first_prefix, - const std::string &last_prefix, const std::string &single_prefix, - instruction_sett &instruction_set) : - first_prefix(first_prefix), last_prefix(last_prefix), single_prefix( - single_prefix), instruction_set(instruction_set), has_current_instr( - false), is_last_in_range(false), instr_idx(0u) - { - } - - void handle_meta_info(const goto_programt::const_targett &target) - { - const goto_programt::instructiont &instr=*target; - const goto_programt::instructiont::labelst &labels=instr.labels; - if(labels.empty()) return; - const std::string &label=id2string(instr.labels.front()); - if(std::string::npos != label.find(first_prefix)) - { - current_instr_offset=target; - has_current_instr=true; - is_last_in_range=false; - instr_idx=string2integer(label.substr(first_prefix.size())).to_ulong(); - } else if(std::string::npos != label.find(last_prefix)) - { - is_last_in_range=true; - instr_idx=string2integer(label.substr(last_prefix.size())).to_ulong(); - } else if(std::string::npos != label.find(single_prefix)) - { - has_current_instr=true; - is_last_in_range=true; - instr_idx=string2integer(label.substr(single_prefix.size())).to_ulong(); - } - } - - void copy_op(goto_programt::const_targett target) - { - goto_programt::instructionst &instr=instruction_set[instr_idx]; - instr.push_back(goto_programt::instructiont()); - goto_programt::targett new_target=instr.end(); - copy_instruction(--new_target, target); - if(is_last_in_range) - { - instr.push_back(goto_programt::instructiont(SKIP)); - goto_programt::targett new_target=instr.end(); - copy_instruction.finalize(--new_target, ++target); - has_current_instr=false; - } - } - - void operator()(const goto_programt::const_targett &target) - { - handle_meta_info(target); - if(has_current_instr) copy_op(target); - } -}; -} - -#define DEFAULT_FIRST CEGIS_PREFIX "opcode_first_" -#define DEFAULT_LAST CEGIS_PREFIX "opcode_last_" -#define DEFAULT_SINGLE CEGIS_PREFIX "opcode_" - -instruction_sett extract_instruction_set(const goto_programt &body) -{ - return extract_instruction_set(body, DEFAULT_FIRST, DEFAULT_LAST, DEFAULT_SINGLE); -} - -instruction_sett extract_instruction_set(const goto_programt &body, - const std::string &first_prefix, const std::string &last_prefix, - const std::string &single_prefix) -{ - const goto_programt::instructionst &instrs=body.instructions; - instruction_sett instruction_set; - execute_instruction_handlert handler(first_prefix, last_prefix, single_prefix, instruction_set); - for(goto_programt::const_targett it=instrs.begin(); it != instrs.end(); ++it) - handler(it); - return instruction_set; -} diff --git a/src/cegis/instructions/instruction_set_factory.h b/src/cegis/instructions/instruction_set_factory.h deleted file mode 100644 index fd01c29229f..00000000000 --- a/src/cegis/instructions/instruction_set_factory.h +++ /dev/null @@ -1,44 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUCTIONS_INSTRUCTION_SET_FACTORY_H -#define CPROVER_CEGIS_INSTRUCTIONS_INSTRUCTION_SET_FACTORY_H - -#include - -typedef std::map instruction_sett; - -/** - * @brief - * - * @details - * - * @param body - * @return - */ -instruction_sett extract_instruction_set(const goto_programt &body); - -/** - * @brief - * - * @details - * - * @param body - * @param first_prefix - * @param last_prefix - * @param single_prefix - * @return - */ -instruction_sett extract_instruction_set( - const goto_programt &body, - const std::string &first_prefix, - const std::string &last_prefix, - const std::string &single_prefix); - -#endif // CPROVER_CEGIS_INSTRUCTIONS_INSTRUCTION_SET_FACTORY_H diff --git a/src/cegis/instrument/cegis_library.cpp b/src/cegis/instrument/cegis_library.cpp deleted file mode 100644 index 6de8c886961..00000000000 --- a/src/cegis/instrument/cegis_library.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -const char BASE_NAME_SEP[]="::"; -const char PROGRAM_ARG_BASE_NAME[]="program"; -const char SIZE_ARG_BASE_NAME[]="size"; - -pointer_typet instr_type() -{ - return pointer_typet(symbol_typet(CEGIS_INSTRUCTION_TYPE_NAME)); -} - -code_typet cegis_execute_type() -{ - code_typet type; - type.return_type()=void_typet(); - type.parameter_identifiers().push_back(PROGRAM_ARG_BASE_NAME); - type.parameter_identifiers().push_back(SIZE_ARG_BASE_NAME); - code_typet::parametert program(instr_type()); - std::string program_arg(CEGIS_EXECUTE); - program_arg+=BASE_NAME_SEP; - program_arg+=PROGRAM_ARG_BASE_NAME; - program.set_identifier(program_arg); - program.set_base_name(PROGRAM_ARG_BASE_NAME); - type.parameters().push_back(program); - code_typet::parametert size(unsigned_char_type()); - std::string size_arg(CEGIS_EXECUTE); - size_arg+=BASE_NAME_SEP; - size_arg+=SIZE_ARG_BASE_NAME; - size.set_identifier(size_arg); - size.set_base_name(SIZE_ARG_BASE_NAME); - type.parameters().push_back(size); - return type; -} - -void add_execute_placeholder(symbol_tablet &symbol_table, - const std::string &func_name, const code_typet &type) -{ - if(symbol_table.has_symbol(func_name)) return; - symbolt symbol; - symbol.name=func_name; - symbol.base_name=symbol.name; - symbol.pretty_name=symbol.base_name; - symbol.type=type; - symbol.is_lvalue=true; - symbol.mode=ID_C; - symbol.module=CEGIS_MODULE; - symbol_table.add(symbol); -} - -goto_programt::targett init_array(const symbol_tablet &st, goto_programt &body, - const char * const name, goto_programt::targett pos) -{ - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=default_cegis_source_location(); - const symbol_exprt array(st.lookup(name).symbol_expr()); - const array_typet &type=to_array_type(array.type()); - const namespacet ns(st); - pos->code= - code_assignt( - array, - zero_initializer(type, pos->source_location, ns)); - return pos; -} - -void set_init_values(const symbol_tablet &st, goto_functionst &gf) -{ - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=body.instructions.begin(); - pos=init_array(st, body, CEGIS_OPS, pos); - init_array(st, body, CEGIS_RESULT_OPS, pos); -} -} - -std::string get_cegis_library_text(const size_t num_vars, - const size_t num_consts, const size_t max_size, - const std::string &func_name) -{ - symbol_tablet st; - add_execute_placeholder(st, func_name, cegis_execute_type()); - std::set functions; - functions.insert(func_name); - std::string text(get_cegis_code_prefix(num_vars, num_consts, max_size)); - return text+=get_cprover_library_text(functions, st); -} - -void add_cegis_library(symbol_tablet &st, goto_functionst &gf, - message_handlert &msg, const size_t num_vars, const size_t num_consts, - const size_t max_solution_size, const std::string &func_name) -{ - add_execute_placeholder(st, func_name, cegis_execute_type()); - std::set functions; - functions.insert(func_name); - const std::string library_src( - get_cegis_library_text(num_vars, num_consts, max_solution_size, - func_name)); - - add_library(library_src, st, msg); - goto_convert(func_name, st, gf, msg); - gf.compute_loop_numbers(); - gf.update(); - set_init_values(st, gf); -} - -void add_cegis_execute_placeholder(symbol_tablet &st) -{ - add_execute_placeholder(st, CEGIS_EXECUTE, cegis_execute_type()); -} diff --git a/src/cegis/instrument/cegis_library.h b/src/cegis/instrument/cegis_library.h deleted file mode 100644 index d824159ace9..00000000000 --- a/src/cegis/instrument/cegis_library.h +++ /dev/null @@ -1,64 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUMENT_CEGIS_LIBRARY_H -#define CPROVER_CEGIS_INSTRUMENT_CEGIS_LIBRARY_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param num_vars - * @param num_consts - * @param max_solution_size - * @param func_name - */ -std::string get_cegis_library_text(size_t num_vars, size_t num_consts, - size_t max_solution_size, const std::string &func_name); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param msg - * @param num_vars - * @param num_consts - * @param max_solution_size - * @param func_name - */ -void add_cegis_library(symbol_tablet &st, class goto_functionst &gf, - class message_handlert &msg, size_t num_vars, size_t num_consts, - size_t max_solution_size, const std::string &func_name); - -/** - * @brief - * - * @details - * - * @param st - */ -void add_cegis_execute_placeholder(symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @return - */ -code_typet cegis_execute_type(); - -#endif // CPROVER_CEGIS_INSTRUMENT_CEGIS_LIBRARY_H diff --git a/src/cegis/instrument/find_cprover_initialize.cpp b/src/cegis/instrument/find_cprover_initialize.cpp deleted file mode 100644 index 14c4714bde1..00000000000 --- a/src/cegis/instrument/find_cprover_initialize.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -goto_programt::targett find_cprover_initialize(goto_programt &body) -{ - goto_programt::instructionst &instrs=body.instructions; - goto_programt::targett pos; - const goto_programt::targett end=instrs.end(); - for(pos=instrs.begin(); pos != end; ++pos) - { - const goto_programt::instructiont &instr=*pos; - if(goto_program_instruction_typet::FUNCTION_CALL != instr.type) continue; - const code_function_callt &call=to_code_function_call(instr.code); - const exprt &func=call.function(); - if(ID_symbol != func.id()) continue; - const std::string &func_id=id2string(to_symbol_expr(func).get_identifier()); - if(CPROVER_INIT == func_id) break; - } - assert(end != pos); - return pos; -} - -goto_programt::targett find_last_instr(goto_programt &body) -{ - goto_programt::targett result=body.instructions.end(); - assert(goto_program_instruction_typet::END_FUNCTION == (--result)->type); - return --result; -} diff --git a/src/cegis/instrument/find_cprover_initialize.h b/src/cegis/instrument/find_cprover_initialize.h deleted file mode 100644 index 49c74e750ed..00000000000 --- a/src/cegis/instrument/find_cprover_initialize.h +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUMENT_FIND_CPROVER_INITIALIZE_H -#define CPROVER_CEGIS_INSTRUMENT_FIND_CPROVER_INITIALIZE_H - -#include - -/** - * @brief - * - * @details - * - * @param body - * - * @return - */ -goto_programt::targett find_cprover_initialize(goto_programt &body); - -/** - * @brief - * - * @details - * - * @param body - * - * @return - */ -goto_programt::targett find_last_instr(goto_programt &body); - -#endif // CPROVER_CEGIS_INSTRUMENT_FIND_CPROVER_INITIALIZE_H diff --git a/src/cegis/instrument/instrument_var_ops.cpp b/src/cegis/instrument/instrument_var_ops.cpp deleted file mode 100644 index 1bbce736d58..00000000000 --- a/src/cegis/instrument/instrument_var_ops.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include - -#include -#include -#include - -namespace -{ -bool is_cegis_constant(const irep_idt &name) -{ - return std::string::npos != id2string(name).find(CEGIS_CONSTANT_PREFIX); -} - -void link_user_symbols(const symbol_tablet &st, operand_variable_idst &var_ids, - size_t &variable_id, bool consts, const is_op_variablet is_op_variable) -{ - typedef symbol_tablet::symbolst symbolst; - const symbolst &symbols=st.symbols; - for(symbolst::const_iterator it=symbols.begin(); it != symbols.end(); ++it) - { - const symbolt &s=it->second; - if(!is_op_variable(s.name, s.type) - || (is_builtin(s.location) && !is_cegis_constant(s.name))) continue; - const bool is_const=is_global_const(s.name, s.type); - if(is_const == consts) - var_ids.insert(std::make_pair(s.name, variable_id++)); - } -} - -size_t get_min_id(const operand_variable_idst &ids) -{ - if(ids.empty()) return 0; - return std::max_element(ids.begin(), ids.end(), - [](const operand_variable_idst::value_type &lhs, const operand_variable_idst::value_type &rhs) - { return lhs.second < rhs.second;})->second + 1; -} -} - -size_t get_variable_op_ids(const symbol_tablet &st, operand_variable_idst &ids, - const is_op_variablet is_op_variable) -{ - size_t variable_id=get_min_id(ids); - link_user_symbols(st, ids, variable_id, true, is_op_variable); - const size_t num_consts=ids.size(); - link_user_symbols(st, ids, variable_id, false, is_op_variable); - return num_consts; -} - -namespace -{ -const char RETURN_VALUE_IDENTIFIER[]="#return_value"; -} - -bool is_instrumentable_user_variable(const irep_idt &id, const typet &type) -{ - if(ID_code == type.id()) return false; - const std::string &name=id2string(id); - if(std::string::npos != name.find("::") - && std::string::npos == name.find(id2string(ID_main)) - && std::string::npos == name.find(id2string(goto_functionst::entry_point()))) - return false; // Inlined variables - if(std::string::npos != name.find(RETURN_VALUE_IDENTIFIER)) return false; - return std::string::npos == name.find(CPROVER_PREFIX); -} - -size_t get_variable_op_ids(const symbol_tablet &st, operand_variable_idst &ids) -{ - return get_variable_op_ids(st, ids, &is_instrumentable_user_variable); -} - -namespace -{ -null_pointer_exprt get_null() -{ - const pointer_typet void_pointer_type=pointer_typet(void_typet()); - return null_pointer_exprt(void_pointer_type); -} -} - -void link_user_program_variable_ops(const symbol_tablet &st, - class goto_functionst &gf, const operand_variable_idst &var_ids, - const is_op_variablet is_op_variable, const goto_programt::targett begin, - const goto_programt::targett end) -{ - operand_variable_idst to_instrument(var_ids); - goto_programt &body=get_entry_body(gf); - goto_programt::instructionst &instrs=body.instructions; - goto_programt::targett pos=begin; - while(is_builtin(pos->source_location) && pos != end) - ++pos; - for(goto_programt::targett it=pos; it != end; ++it) - { - goto_programt::instructiont &instr=*it; - const goto_program_instruction_typet type=instr.type; - if(DECL != type && DEAD != type) continue; - const irep_idt &name=get_affected_variable(instr); - if(!is_op_variable(name, st.lookup(name).type)) continue; - const operand_variable_idst::const_iterator id=var_ids.find(name); - if(DEAD == type) set_ops_reference(st, body, it, get_null(), id->second); - else - { - set_ops_reference(st, body, it, name, id->second); - to_instrument.erase(id->first); - } - } - if(pos != instrs.begin()) --pos; - typedef operand_variable_idst::const_iterator itt; - const itt first=to_instrument.begin(); - for(itt it=first; it != to_instrument.end(); ++it) - { - pos=set_ops_reference(st, body, pos, it->first, it->second); - if(first == it) move_labels(body, begin, pos); - } -} - -void link_user_program_variable_ops(const symbol_tablet &st, - class goto_functionst &gf, const operand_variable_idst &var_ids, - const goto_programt::targett begin, const goto_programt::targett end) -{ - const is_op_variablet filter=&is_instrumentable_user_variable; - link_user_program_variable_ops(st, gf, var_ids, filter, begin, end); -} - -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const char * const ops_array, const exprt &rhs, const unsigned int id) -{ - const goto_programt::targett target=body.insert_after(pos); - goto_programt::instructiont &set_op=*target; - set_op.type=ASSIGN; - set_op.source_location=default_cegis_source_location(); - const constant_exprt index(from_integer(id, unsigned_int_type())); - const symbol_exprt ops(st.lookup(ops_array).symbol_expr()); - const index_exprt op(ops, index); - set_op.code=code_assignt(op, rhs); - return target; -} - -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const char * const ops_array, const irep_idt &name, const unsigned int id) -{ - const symbol_exprt rhs(st.lookup(name).symbol_expr()); - return set_ops_reference(st, body, pos, ops_array, address_of_exprt(rhs), id); -} - -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, const exprt &rhs, - const unsigned int id) -{ - return set_ops_reference(st, body, pos, CEGIS_OPS, rhs, id); -} - -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const irep_idt &name, const unsigned int id) -{ - return set_ops_reference(st, body, pos, CEGIS_OPS, name, id); -} - -source_locationt default_cegis_source_location() -{ - source_locationt loc; - loc.set_file(CEGIS_MODULE); - loc.set_function(goto_functionst::entry_point()); - return loc; -} diff --git a/src/cegis/instrument/instrument_var_ops.h b/src/cegis/instrument/instrument_var_ops.h deleted file mode 100644 index 256be2e1706..00000000000 --- a/src/cegis/instrument/instrument_var_ops.h +++ /dev/null @@ -1,169 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUMENT_INSTRUMENT_VAR_OPS_H -#define CPROVER_CEGIS_INSTRUMENT_INSTRUMENT_VAR_OPS_H - -#include - -typedef std::map operand_variable_idst; -typedef bool (*is_op_variablet)(const irep_idt &id, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @params ids - * - * @return - */ -size_t get_variable_op_ids(const class symbol_tablet &st, - operand_variable_idst &ids); - -/** - * @brief - * - * @details - * - * @param st - * @params ids - * @param is_op_variable - * - * @return - */ -size_t get_variable_op_ids(const class symbol_tablet &st, - operand_variable_idst &ids, is_op_variablet is_op_variable); - -/** - * @brief - * - * @details - * - * @param id - * @param type - * - * @return - */ -bool is_instrumentable_user_variable(const irep_idt &id, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param var_ids - * @param is_op_variable - * @param begin - * @param end - */ -void link_user_program_variable_ops(const symbol_tablet &st, class goto_functionst &gf, - const operand_variable_idst &var_ids, const is_op_variablet is_op_variable, - goto_programt::targett begin, goto_programt::targett end); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param var_ids - * @param begin - * @param end - */ -void link_user_program_variable_ops( - const symbol_tablet &st, class goto_functionst &gf, - const operand_variable_idst &var_ids, - goto_programt::targett begin, goto_programt::targett end); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param name - * @param id - * - * @return - */ -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const irep_idt &name, const unsigned int id); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param ops_array - * @param name - * @param id - * - * @return - */ -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const char * const ops_array, const irep_idt &name, const unsigned int id); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param ops_array - * @param rhs - * @param id - * - * @return - */ -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const char * const ops_array, const exprt &rhs, const unsigned int id); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param rhs - * @param id - * - * @return - */ -goto_programt::targett set_ops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, const exprt &rhs, - const unsigned int id); - - -/** - * @brief - * - * @details - * - * @return - */ -source_locationt default_cegis_source_location(); - -#endif // CPROVER_CEGIS_INSTRUMENT_INSTRUMENT_VAR_OPS_H diff --git a/src/cegis/instrument/literals.h b/src/cegis/instrument/literals.h deleted file mode 100644 index ddc7eab7e30..00000000000 --- a/src/cegis/instrument/literals.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUMENT_LITERALS_H -#define CPROVER_CEGIS_INSTRUMENT_LITERALS_H - -#include - -#define CEGIS_INSTRUCTION_TYPE_NAME "tag-__CPROVER_cegis_instructiont" -#define CEGIS_OPS "__CPROVER_cegis_OPS" -#define CEGIS_EXECUTE "__CPROVER_danger_execute" -#define CEGIS_RESULT_OPS "__CPROVER_cegis_RESULT_OPS" -#define CEGIS_MODULE "" -#define CEGIS_PREFIX CPROVER_PREFIX "cegis_" -#define CEGIS_TMP_PREFIX CEGIS_PREFIX "tmp_" -#define CEGIS_PRIME_SUFFIX "_prime" -#define CEGIS_CONSTANT_PREFIX "CEGIS_CONSTANT_" -#define CEGIS_FITNESS_TEST_FUNC "__CPROVER_cegis_test_fitness" -#define CPROVER_INIT CPROVER_PREFIX "initialize" -#define CONSTRAINT_CALLER_NAME CEGIS_PREFIX "constraint_caller" -#define CONSTRAINT_CALLER CONSTRAINT_CALLER_NAME ":()V" -#define CONSTRAINT_CALLER_ID "java::" CONSTRAINT_CALLER - -#endif // CPROVER_CEGIS_INSTRUMENT_LITERALS_H diff --git a/src/cegis/instrument/meta_variables.cpp b/src/cegis/instrument/meta_variables.cpp deleted file mode 100644 index 2b5e302a546..00000000000 --- a/src/cegis/instrument/meta_variables.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include - -#define NS_SEP "::" - -namespace -{ -std::string concat(std::string lhs, const std::string &rhs) -{ - lhs+= NS_SEP; - return lhs+=rhs; -} -} - -std::string get_cegis_meta_name(const std::string &base_name) -{ - return concat(id2string(goto_functionst::entry_point()), base_name); -} - -std::string get_local_meta_name(const std::string &func, const std::string &var) -{ - return concat(func, var); -} - -namespace -{ -void declare_local_var(goto_programt::instructiont &instr, - const symbolt &symbol) -{ - instr.type=goto_program_instruction_typet::DECL; - instr.code=code_declt(symbol.symbol_expr()); - instr.source_location=default_cegis_source_location(); -} - -goto_programt::targett declare_local_var(goto_programt &body, - goto_programt::targett pos, const symbolt &symbol) -{ - pos=body.insert_after(pos); - declare_local_var(*pos, symbol); - return pos; -} -} - -goto_programt::targett declare_cegis_meta_variable(symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &pos, - const std::string &base_name, const typet &type) -{ - const std::string symbol_name(get_cegis_meta_name(base_name)); - const symbolt &symbol=create_cegis_symbol(st, symbol_name, type); - return declare_local_var(get_entry_body(gf), pos, symbol); -} - -goto_programt::targett declare_local_meta_variable(symbol_tablet &st, - const std::string &fn, goto_programt &body, - const goto_programt::targett &insert_after_pos, const std::string &bn, - const typet &t) -{ - const symbolt &smb=create_cegis_symbol(st, get_local_meta_name(fn, bn), t); - return declare_local_var(body, insert_after_pos, smb); -} - -void declare_local_meta_variable(symbol_tablet &st, const std::string &fn, - goto_programt::instructiont &instr, const std::string &bn, const typet &t) -{ - const symbolt &smb=create_cegis_symbol(st, get_local_meta_name(fn, bn), t); - declare_local_var(instr, smb); -} - -goto_programt::targett assign_cegis_meta_variable(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const std::string &base_name, const exprt &value) -{ - const std::string name(get_cegis_meta_name(base_name)); - return cegis_assign_user_variable(st, gf, insert_after_pos, name, value); -} - -typet cegis_default_integer_type() -{ - return unsigned_int_type(); -} - -std::string get_cegis_code_prefix(const size_t num_vars, - const size_t num_consts, const size_t max_solution_size) -{ - std::string prefix("#define " CEGIS_PREFIX "number_of_vars "); - prefix+=integer2string(num_vars); - prefix+="\n#define " CEGIS_PREFIX "number_of_consts "; - prefix+=integer2string(num_consts); - prefix+="u\n#define " CEGIS_PREFIX "number_of_ops "; - prefix+=integer2string(num_vars + max_solution_size); - prefix+="u\n#define " CEGIS_PREFIX "max_solution_size "; - prefix+=integer2string(max_solution_size); - return prefix+="u\n"; -} - -const symbolt &declare_global_meta_variable(symbol_tablet &st, - const std::string &name, const typet &type) -{ - symbolt new_symbol; - new_symbol.name=name; - new_symbol.type=type; - new_symbol.base_name=name; - new_symbol.pretty_name=name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - new_symbol.is_lvalue=true; - new_symbol.is_static_lifetime=true; - new_symbol.is_state_var=true; - assert(!st.add(new_symbol)); - return st.lookup(name); -} - -const symbolt &declare_global_meta_variable(symbol_tablet &st, - goto_functionst &gf, const std::string &name, const exprt &value) -{ - const symbolt &symbol=declare_global_meta_variable(st, name, value.type()); - goto_programt &init_body=get_body(gf, CPROVER_INIT); - goto_programt::instructionst &instrs=init_body.instructions; - goto_programt::targett pos=instrs.begin(); - if(instrs.size() >= 2) pos=std::prev(init_body.instructions.end(), 2); - const symbol_exprt lhs(symbol.symbol_expr()); - cegis_assign(st, init_body, pos, lhs, value, default_cegis_source_location()); - return symbol; -} diff --git a/src/cegis/instrument/meta_variables.h b/src/cegis/instrument/meta_variables.h deleted file mode 100644 index 378f44bb055..00000000000 --- a/src/cegis/instrument/meta_variables.h +++ /dev/null @@ -1,158 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INSTRUMENT_META_VARIABLES_H -#define CPROVER_CEGIS_INSTRUMENT_META_VARIABLES_H - -#include - -/** - * @brief - * - * @details - * - * @param base_name - * - * @return - */ -std::string get_cegis_meta_name(const std::string &base_name); - -/** - * @brief - * - * @details - * - * @param func - * @param var - * - * @return - */ -std::string get_local_meta_name(const std::string &func, const std::string &var); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param insert_after_pos - * @param base_name - * @param type - * - * @return - */ -goto_programt::targett declare_cegis_meta_variable(symbol_tablet &st, - class goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const std::string &base_name, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param func_name - * @param body - * @param insert_after_pos - * @param base_name - * @param type - */ -goto_programt::targett declare_local_meta_variable(symbol_tablet &st, - const std::string &func_name, goto_programt &body, - const goto_programt::targett &insert_after_pos, - const std::string &base_name, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param func_name - * @param instr - * @param base_name - * @param type - */ -void declare_local_meta_variable(symbol_tablet &st, - const std::string &func_name, goto_programt::instructiont &instr, - const std::string &base_name, const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param name - * @param type - */ -const symbolt &declare_global_meta_variable( - symbol_tablet &st, - const std::string &name, - const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param name - * @param value - */ -const symbolt &declare_global_meta_variable( - symbol_tablet &st, - goto_functionst &gf, - const std::string &name, - const exprt &value); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param insert_after_pos - * @param base_name - * @param value - * - * @return - */ -goto_programt::targett assign_cegis_meta_variable(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &insert_after_pos, - const std::string &base_name, const exprt &value); - -/** - * @brief - * - * @details - * - * @return - */ -typet cegis_default_integer_type(); - -/** - * @brief - * - * @details - * - * @param num_vars - * @param num_consts - * @param max_solution_size - * @return - */ -std::string get_cegis_code_prefix( - size_t num_vars, - size_t num_consts, - size_t max_solution_size); - -#endif // CPROVER_CEGIS_INSTRUMENT_META_VARIABLES_H diff --git a/src/cegis/invariant/constant/add_constant.cpp b/src/cegis/invariant/constant/add_constant.cpp deleted file mode 100644 index 585268973fa..00000000000 --- a/src/cegis/invariant/constant/add_constant.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include - -namespace -{ -const char NS_SEP[]="::"; -bool is_meta_or_not_global(const symbolt &symbol) -{ - if(ID_code == symbol.type.id()) return true; - const std::string &name=id2string(symbol.name); - if(std::string::npos != name.find("#return_value")) return true; - if(std::string::npos != name.find(CPROVER_PREFIX)) return true; - return std::string::npos != name.find(NS_SEP); -} - -bool contains_constant(const symbol_tablet &st, const exprt &value) -{ - typedef symbol_tablet::symbolst symbolst; - exprt lhs=value; - lhs.add_source_location()=source_locationt(); - const symbolst &s=st.symbols; - for(symbolst::const_iterator it=s.begin(); it != s.end(); ++it) - { - const symbolt &symbol=it->second; - if(is_meta_or_not_global(symbol)) continue; - exprt rhs=symbol.value; - rhs.add_source_location()=lhs.source_location(); - if(lhs == rhs) return true; - } - return false; -} - -bool is_empty(const exprt &expr) -{ - return exprt() == expr; -} -} - -void add_danger_constant(invariant_programt &program, const exprt &value) -{ - symbol_tablet &st=program.st; - if(contains_constant(st, value)) return; - const namespacet ns(st); - std::string name(CEGIS_CONSTANT_PREFIX); - name+=expr2c(value, ns); - add_danger_constant(program, name, value); -} - -void add_danger_constant(invariant_programt &prog, const std::string &name, - const exprt &value) -{ - goto_programt::targett pos=prog.invariant_range.begin; - while(is_builtin(pos->source_location)) - ++pos; - typet type=value.type(); - type.set(ID_C_constant, true); - symbol_tablet &st=prog.st; - create_cegis_symbol(st, name, type).value=value; - if(!is_empty(value)) - pos=cegis_assign_user_variable(st, prog.gf, pos, name, value); -} diff --git a/src/cegis/invariant/constant/add_constant.h b/src/cegis/invariant/constant/add_constant.h deleted file mode 100644 index 272e8f152c9..00000000000 --- a/src/cegis/invariant/constant/add_constant.h +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_CONSTANT_ADD_CONSTANT_H -#define CPROVER_CEGIS_INVARIANT_CONSTANT_ADD_CONSTANT_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param value - */ -void add_danger_constant(class invariant_programt &program, - const class exprt &value); - -/** - * @brief - * - * @details - * - * @param program - * @param name - * @param value - */ -void add_danger_constant(invariant_programt &program, const std::string &name, - const exprt &value); - -#endif // CPROVER_CEGIS_INVARIANT_CONSTANT_ADD_CONSTANT_H diff --git a/src/cegis/invariant/constant/constant_strategy.h b/src/cegis/invariant/constant/constant_strategy.h deleted file mode 100644 index 0ba229066be..00000000000 --- a/src/cegis/invariant/constant/constant_strategy.h +++ /dev/null @@ -1,28 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_CONSTANT_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_INVARIANT_CONSTANT_CONSTANT_STRATEGY_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param max_length - * - * @return - */ -typedef size_t (*constant_strategyt)(class invariant_programt &program, - const size_t max_length); - -#endif // CPROVER_CEGIS_INVARIANT_CONSTANT_CONSTANT_STRATEGY_H diff --git a/src/cegis/invariant/constant/default_constant_strategy.cpp b/src/cegis/invariant/constant/default_constant_strategy.cpp deleted file mode 100644 index 3123a7eab71..00000000000 --- a/src/cegis/invariant/constant/default_constant_strategy.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include - -size_t default_constant_strategy(invariant_programt &program, - const size_t max_length) -{ - const typet type(cegis_default_integer_type()); - const bv_spect spec(type); - add_danger_constant(program, from_integer(spec.max_value().to_ulong(), type)); - add_danger_constant(program, from_integer(0u, type)); - return std::max(size_t(1u), literals_constant_strategy(program, max_length)); - // return 2u + literals_constant_strategy(program, max_length); - /*for (size_t i=0; i < max_length; ++i) - { - const side_effect_expr_nondett value(type); - std::string name(NONDET_PREFIX); - add_danger_constant(program, name+=integer2string(i), value); - } - return 2u + max_length + literals_constant_strategy(program, max_length);*/ -} diff --git a/src/cegis/invariant/constant/default_constant_strategy.h b/src/cegis/invariant/constant/default_constant_strategy.h deleted file mode 100644 index 124d4eb81c7..00000000000 --- a/src/cegis/invariant/constant/default_constant_strategy.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_CONSTANT_DEFAULT_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_INVARIANT_CONSTANT_DEFAULT_CONSTANT_STRATEGY_H - -/** - * @brief - * - * @details - * - * @param program - * @param max_length - * - * @return - */ -size_t default_constant_strategy(class invariant_programt &program, - const size_t max_length); - -#endif // CPROVER_CEGIS_INVARIANT_CONSTANT_DEFAULT_CONSTANT_STRATEGY_H diff --git a/src/cegis/invariant/constant/literals_constant_strategy.cpp b/src/cegis/invariant/constant/literals_constant_strategy.cpp deleted file mode 100644 index afdfbded2b7..00000000000 --- a/src/cegis/invariant/constant/literals_constant_strategy.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include - -namespace -{ -class compare_constantt -{ - const namespacet ns; -public: - explicit compare_constantt(const invariant_programt &program) : - ns(program.st) - { - } - - bool operator()(const constant_exprt &lhs, const constant_exprt &rhs) const - { - return lhs.get_value() < rhs.get_value(); - } -}; - -typedef std::set constant_sett; - -class constant_expr_visitort: public const_expr_visitort -{ - const namespacet ns; - const typet type; - constant_sett &constants; -public: - virtual ~constant_expr_visitort() - { - } - - virtual void operator()(const exprt &expr) - { - if(ID_constant != expr.id()) return; - const typet &expr_type=expr.type(); - const irep_idt &type_id=expr_type.id(); - if(ID_unsignedbv != type_id && ID_signedbv != type_id) return; - const constant_exprt constant(to_constant_expr(expr)); - const bv_arithmetict bv(constant); - const mp_integer value=bv.to_integer(); - constants.insert(from_integer(value, type)); - // XXX: Add constant +/- 1? - // constants.insert(from_integer(value + 1, type)); - // constants.insert(from_integer(value - 1, type)); - } - - void operator()(const goto_programt::instructiont &instr) - { - instr.code.visit(*this); - instr.guard.visit(*this); - } - - void operator()(const invariant_programt::invariant_loopt *loop) - { - loop->guard.visit(*this); - } - - constant_expr_visitort(const invariant_programt &prog, - constant_sett &constants) : - ns(prog.st), type(cegis_default_integer_type()), constants(constants) - { - const invariant_programt::const_invariant_loopst loops=prog.get_loops(); - constant_expr_visitort &op=*this; - std::for_each(loops.begin(), loops.end(), op); - prog.assertion.visit(op); - } -}; -} - -std::vector collect_literal_constants( - const invariant_programt &program) -{ - const compare_constantt compare(program); - constant_sett constants(compare); - const constant_expr_visitort visitor(program, constants); - const invariant_programt::program_ranget &range=program.invariant_range; - std::for_each(range.begin, range.end, visitor); - return std::vector(constants.begin(), constants.end()); -} - -size_t literals_constant_strategy(invariant_programt &program, - const size_t max_length) -{ - const std::vector lit(collect_literal_constants(program)); - size_t max_word_width=0u; - for(const constant_exprt &expr : lit) - { - add_danger_constant(program, expr); - // XXX: Add negation of every constant? - // if (!expr.is_zero()) add_danger_constant(program, unary_minus_exprt(expr)); - max_word_width=std::max(max_word_width, get_min_word_width(expr)); - } - return max_word_width; -} diff --git a/src/cegis/invariant/constant/literals_constant_strategy.h b/src/cegis/invariant/constant/literals_constant_strategy.h deleted file mode 100644 index 6b7f73564d3..00000000000 --- a/src/cegis/invariant/constant/literals_constant_strategy.h +++ /dev/null @@ -1,42 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_CONSTANT_LITERALS_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_INVARIANT_CONSTANT_LITERALS_CONSTANT_STRATEGY_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param program - * - * @return - */ -std::vector collect_literal_constants( - const class invariant_programt &program); - -/** - * @brief - * - * @details - * - * @param program - * @param max_length - * - * @return - */ -size_t literals_constant_strategy(invariant_programt &program, - const size_t max_length); - -#endif // CPROVER_CEGIS_INVARIANT_CONSTANT_LITERALS_CONSTANT_STRATEGY_H diff --git a/src/cegis/invariant/fitness/concrete_fitness_source_provider.cpp b/src/cegis/invariant/fitness/concrete_fitness_source_provider.cpp deleted file mode 100644 index 5269d8d1d47..00000000000 --- a/src/cegis/invariant/fitness/concrete_fitness_source_provider.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include - -namespace -{ -void add_assume_implementation(std::string &source) -{ - source+= - "#define " CEGIS_PREFIX "assert(constraint) if(constraint) { return 0; } else { return 1; }\n"; - source+="#define __CPROVER_assume(constraint) \n"; - source+= - "#define " CEGIS_PREFIX "execute_assume(constraint) if (!(constraint)) { return 1; }\n"; -} - -void add_danger_execute(std::string &source, const size_t num_vars, - const size_t num_consts, const size_t max_prog_size, - const std::string &exec_func_name) -{ - std::string text=get_cegis_library_text(num_vars, num_consts, max_prog_size, - exec_func_name); - substitute(text, "#define opcode program[i].opcode", - "const opcodet opcode=program[i].opcode;"); - substitute(text, "#line 1 \"\"", - "//#line 2 \"\""); - substitute(text, "#line 1 \"\"", - "//#line 2 \"\""); - const char result_op[]= - " *(unsigned int *)" CEGIS_RESULT_OPS "[i]=result;\n }\n"; - const std::string::size_type pos=text.find(result_op); - assert(std::string::npos != pos); - text.insert(pos + strlen(result_op), - "if (size <= 0 || size >= " CEGIS_PREFIX "max_solution_size) return 0;\n" - "int diff=" CEGIS_PREFIX "max_solution_size-size;\n" - "for (int i = size-1; i >= 0; --i) {\n" - " *(unsigned int *)" CEGIS_RESULT_OPS "[i+diff]=*(unsigned int *)" CEGIS_RESULT_OPS "[i];\n" - "}\n" - "return 0;\n"); - substitute(text, "__CPROVER_assume(op0_ptr && op1_ptr && op2_ptr)", - CEGIS_PREFIX "execute_assume(op0_ptr && op1_ptr && op2_ptr)"); - substitute(text, "__CPROVER_assume((opcode != 19 && opcode != 20) || op1)", - CEGIS_PREFIX "execute_assume(opcode != 19 && opcode != 20 || op1)"); - substitute(text, "void __CPROVER_danger_execute(", - "int __CPROVER_danger_execute_impl("); - source+=text; - source+= - "#define __CPROVER_danger_execute(prog, size) if (__CPROVER_danger_execute_impl(prog, size)) { return 1; }\n"; -} - -bool contains(const std::string &haystack, const std::string &needle) -{ - return std::string::npos != haystack.find(needle); -} - -bool handle_start( - const goto_functionst &gf, - std::string &source, - const std::string &line) -{ - std::ostringstream start_sig; - start_sig << "void " << gf.entry_point() << "(void)"; - if(start_sig.str()!=line) - return false; - source+="int main(const int argc, const char * const argv[])\n"; - return true; -} - -bool handle_return_value(const std::string &line) -{ - return contains(line, "main#return_value") || contains(line, "_return'"); -} - -#define PROG_PREFIX " struct " CEGIS_PREFIX "instructiont " -#define PROG_PREFIX_LEN strlen(PROG_PREFIX) - -void replace_ce_index(std::string &line) -{ - substitute(line, "[" CEGIS_PREFIX "x_index]", "[0u]"); -} - -void replace_assume(std::string &line) -{ - substitute(line, "__CPROVER_assume", CEGIS_PREFIX "assert"); -} - -void replace_danger_execute_size(std::string &line) -{ - if(!contains(line, "__CPROVER_danger_execute(")) return; - const std::string::size_type name_start=line.find('(') + 1; - const std::string::size_type name_end=line.find(','); - const std::string::size_type name_len=name_end - name_start; - const std::string name(line.substr(name_start, name_len)); - line.erase(name_end, std::string::npos); - line+=", "; - line+=name; - line+="_size);\n"; -} - -void replace_return_values(std::string &line) -{ - substitute(line, "OUTPUT(\"return\", return')", ""); - substitute(line, "#return_value", "__return_value"); - substitute(line, "return'", "__return_value"); -} - -void fix_cprover_names(std::string &line) -{ - substitute(line, "$$", "__"); -} - -bool handle_programs(std::string &source, bool &initialised, - const std::string &line) -{ - const size_t len=PROG_PREFIX_LEN; - if(PROG_PREFIX != line.substr(0, len)) return false; - if(!initialised) - { - source+=" " CEGIS_PREFIX "deserialise_init();\n"; - initialised=true; - } - const std::string::size_type name_len=line.find('[', len) - len; - std::string name(line.substr(len, name_len)); - fix_cprover_names(name); - source+=" " CEGIS_PREFIX "declare_prog("; - source+=name; - source+=", "; - source+=name; - source+="_size"; - source+=");\n"; - return true; -} - -bool handle_x0(std::string &source, std::string &line) -{ - if(!contains(line, "__CPROVER") || !contains(line, "_x0_") - || contains(line, "=")) return false; - fix_cprover_names(line); - const std::string::size_type name_start=line.rfind(' ') + 1; - const std::string name(line.substr(name_start, line.size() - name_start - 1)); - source+=line; - source+="\n " CEGIS_PREFIX "deserialise_x0("; - source+=name; - source+=");\n"; - return true; -} - -bool handle_ce(std::string &source, bool &initialised, const std::string &line) -{ - if(!(contains(line, CEGIS_PREFIX "x_choice_") - || contains(line, CEGIS_PREFIX "x0_choice_")) - || contains(line, CEGIS_PREFIX "x_index")) return false; - if(!initialised) - { - source+=" " CEGIS_PREFIX "ce_value_init();\n"; - initialised=true; - } - const std::string::size_type name_end=line.find("={ "); - source+="\n"; - std::string prefix=line.substr(0, name_end); - fix_cprover_names(prefix); - source+=prefix; - source+="={ " CEGIS_PREFIX "ce_value() };\n"; - return true; -} - -bool handle_second_instr_struct(std::string &source, const std::string &line) -{ - if("struct " CEGIS_PREFIX "instructiont" != line) return false; - source+="struct " CEGIS_PREFIX "instructiont_escaped\n"; - return true; -} - -bool handle_ce_loop(const std::string &line, std::stringstream &ss) -{ - if(" " CEGIS_PREFIX "x_index = " CEGIS_PREFIX "x_index + 1u;" == line - || " do" == line) - { - std::string skip; - std::getline(ss, skip); - return true; - } - return " while(" CEGIS_PREFIX "index < 2u);" == line; -} - -bool handle_internals(const std::string &line) -{ - if(contains(line, "ARRAY_OF(")) return true; - return contains(line, "__CPROVER_malloc_size =") - || contains(line, "__CPROVER_dead_object =") - || contains(line, "__CPROVER_deallocated =") - || contains(line, "__CPROVER_malloc_is_new_array =") - || contains(line, "__CPROVER_malloc_object =") - || contains(line, "__CPROVER_malloc_size =") - || contains(line, "__CPROVER_memory_leak =") - || contains(line, "__CPROVER_next_thread_id =") - || contains(line, "__CPROVER_pipe_count =") - || contains(line, "__CPROVER_rounding_mode =") - || contains(line, "__CPROVER_thread_id =") - || contains(line, "__CPROVER_threads_exited =") - || " assert((_Bool)0);" == line || "void assert(void);" == line - || "static signed int assert#return_value;" == line; -} - -void post_process( - const goto_functionst &gf, - std::string &source, - std::stringstream &ss) -{ - bool deserialise_initialised=false; - bool ce_initialised=false; - for(std::string line; std::getline(ss, line);) - { - if(handle_start(gf, source, line) || - handle_return_value(line) || - handle_ce_loop(line, ss) || - handle_internals(line) || - handle_programs(source, deserialise_initialised, line) || - handle_x0(source, line) || - handle_ce(source, ce_initialised, line) || - handle_second_instr_struct(source, line)) - continue; - replace_ce_index(line); - replace_assume(line); - fix_cprover_names(line); - replace_danger_execute_size(line); - replace_return_values(line); - source+=line; - source+='\n'; - } -} - -void add_first_prog_offset(std::string &source, const size_t num_ce_vars) -{ - source+="#define " CEGIS_PREFIX "first_prog_offset "; - source+=integer2string(num_ce_vars); - source+="\n"; -} -} - -std::string &post_process_fitness_source(std::string &result, - const symbol_tablet &st, const goto_functionst &gf, - const size_t num_ce_vars, const size_t num_vars, const size_t num_consts, - const size_t max_prog_size, const std::string &exec) -{ - const bool danger=DANGER_EXECUTE == exec; - implement_program_individual_deserialise(result, danger); - const namespacet ns(st); - std::stringstream ss; - dump_c(gf, true, ns, ss); - add_first_prog_offset(result, num_ce_vars); - add_assume_implementation(result); - add_danger_execute(result, num_vars, num_consts, max_prog_size, exec); - post_process(gf, result, ss); - transform_program_individual_main_to_lib(result, danger); - return result; -} diff --git a/src/cegis/invariant/fitness/concrete_fitness_source_provider.h b/src/cegis/invariant/fitness/concrete_fitness_source_provider.h deleted file mode 100644 index 4176e2b685e..00000000000 --- a/src/cegis/invariant/fitness/concrete_fitness_source_provider.h +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_FITNESS_CONCRETE_FITNESS_SOURCE_PROVIDER_H -#define CPROVER_CEGIS_INVARIANT_FITNESS_CONCRETE_FITNESS_SOURCE_PROVIDER_H - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class concrete_fitness_source_providert -{ - const progt &prog; - configt learn_config; - const std::function max_size; - const std::string execute_func_name; - std::string source; -public: - /** - * @brief - * - * @details - * - * @param prog - * @param max_size - * @param execute_func_name - */ - concrete_fitness_source_providert(const progt &prog, - std::function max_size, - const std::string &execute_func_name); - - /** - * @brief - * - * @details - */ - ~concrete_fitness_source_providert(); - - /** - * @brief - * - * @details - * - * @return - */ - std::string operator()(); -}; - -/** - * @brief - * - * @details - * - * @param result - * @param st - * @param gf - * @param num_ce_vars - * @param num_vars - * @param num_consts - * @param max_prog_size - * @param exec_func_name - */ -std::string &post_process_fitness_source(std::string &result, - const symbol_tablet &st, const goto_functionst &gf, size_t num_ce_vars, - size_t num_vars, size_t num_consts, size_t max_prog_size, - const std::string &exec_func_name); - -#include "concrete_fitness_source_provider.inc" - -#endif // CPROVER_CEGIS_INVARIANT_FITNESS_CONCRETE_FITNESS_SOURCE_PROVIDER_H diff --git a/src/cegis/invariant/fitness/concrete_fitness_source_provider.inc b/src/cegis/invariant/fitness/concrete_fitness_source_provider.inc deleted file mode 100644 index 89e9d602ca1..00000000000 --- a/src/cegis/invariant/fitness/concrete_fitness_source_provider.inc +++ /dev/null @@ -1,31 +0,0 @@ -#include - -template -concrete_fitness_source_providert::concrete_fitness_source_providert( - const progt &prog, const std::function max_size, - const std::string &execute_func_name) : - prog(prog), learn_config(prog), max_size(max_size), execute_func_name( - execute_func_name) -{ -} - -template -concrete_fitness_source_providert::~concrete_fitness_source_providert() -{ -} - -template -std::string concrete_fitness_source_providert::operator ()() -{ - if (!source.empty()) return source; - constraint_varst ce_vars; - get_invariant_constraint_vars(ce_vars, prog); - const size_t max_prog_size=max_size(); - learn_config.process(max_prog_size); - const symbol_tablet &st(learn_config.get_symbol_table()); - const goto_functionst &gf=learn_config.get_goto_functions(); - const size_t num_vars=learn_config.get_num_vars(); - const size_t num_consts=learn_config.get_num_consts(); - return post_process_fitness_source(source, st, gf, ce_vars.size(), num_vars, - num_consts, max_prog_size, execute_func_name); -} diff --git a/src/cegis/invariant/meta/meta_variable_names.cpp b/src/cegis/invariant/meta/meta_variable_names.cpp deleted file mode 100644 index be19ceb945b..00000000000 --- a/src/cegis/invariant/meta/meta_variable_names.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -std::string get_Ax() -{ - return CEGIS_PREFIX "A_x"; -} - -namespace -{ -const char GUARD_PREFIX[]=CEGIS_PREFIX "G"; -const char STATE_BEFORE_LOOP[]="x"; -} - -std::string get_Gx(const size_t loop_id) -{ - std::string result(GUARD_PREFIX); - result+=integer2string(loop_id); - return result+=STATE_BEFORE_LOOP; -} - -std::string get_tmp(const size_t id) -{ - std::string result(CEGIS_TMP_PREFIX); - return result+=integer2string(id); -} diff --git a/src/cegis/invariant/meta/meta_variable_names.h b/src/cegis/invariant/meta/meta_variable_names.h deleted file mode 100644 index 683a5115ed1..00000000000 --- a/src/cegis/invariant/meta/meta_variable_names.h +++ /dev/null @@ -1,48 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_META_META_VARIABLE_NAMES_H -#define CPROVER_CEGIS_INVARIANT_META_META_VARIABLE_NAMES_H - -#include - -#define DANGER_CE_QUANTIFIER_LABEL_PREFIX "__CPROVER_danger_ceq_" - -/** - * @brief - * - * @details - * - * @return - */ -std::string get_Ax(); - -/** - * @brief - * - * @details - * - * @param loop_id - * - * @return - */ -std::string get_Gx(const size_t loop_id); - -/** - * @brief - * - * @details - * - * @param id - * - * @return - */ -std::string get_tmp(const size_t id); - -#endif // CPROVER_CEGIS_INVARIANT_META_META_VARIABLE_NAMES_H diff --git a/src/cegis/invariant/options/invariant_program.cpp b/src/cegis/invariant/options/invariant_program.cpp deleted file mode 100644 index c139a756baf..00000000000 --- a/src/cegis/invariant/options/invariant_program.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -invariant_programt::invariant_programt() -{ -} - -invariant_programt::invariant_programt(const symbol_tablet &st, - const goto_functionst &gf) : - st(st) -{ - this->gf.copy_from(gf); -} - -namespace -{ -invariant_programt &assign(invariant_programt &lhs, - const invariant_programt &rhs) -{ - const target_copy_helpert fix(get_entry_body(rhs.gf), get_entry_body(lhs.gf)); - lhs.invariant_range=fix(rhs.invariant_range); - lhs.assertion=rhs.assertion; - lhs.Ix0=fix(rhs.Ix0); - lhs.Ax=fix(rhs.Ax); - const goto_programt::targetst &old_x0=rhs.x0_choices; - lhs.x0_choices.resize(old_x0.size()); - std::transform(old_x0.begin(), old_x0.end(), lhs.x0_choices.begin(), fix); - return lhs; -} -} - -invariant_programt::invariant_programt(const invariant_programt &other) : - st(other.st) -{ - gf.copy_from(other.gf); - assign(*this, other); -} - -invariant_programt &invariant_programt::operator =( - const invariant_programt &other) -{ - st=other.st; - gf.clear(); - gf.copy_from(other.gf); - return assign(*this, other); -} - -invariant_programt::~invariant_programt() -{ -} diff --git a/src/cegis/invariant/options/invariant_program.h b/src/cegis/invariant/options/invariant_program.h deleted file mode 100644 index a87161a6292..00000000000 --- a/src/cegis/invariant/options/invariant_program.h +++ /dev/null @@ -1,148 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_OPTIONS_INVARIANT_PROGRAM_H -#define CPROVER_CEGIS_INVARIANT_OPTIONS_INVARIANT_PROGRAM_H - -#include - -/** - * @brief - * - * @details - */ -class invariant_programt -{ -public: - /** - * @brief - * - * @details - */ - struct program_ranget - { - goto_programt::targett begin; - goto_programt::targett end; - }; - - /** - * @brief - * - * @details - */ - struct meta_vars_positionst - { - goto_programt::targett Ix; - goto_programt::targett Gx; - goto_programt::targett Ix_prime; - }; - - /** - * @brief - * - * @details - */ - struct invariant_loopt - { - exprt guard; - program_ranget body; - goto_programt::targetst skolem_choices; - meta_vars_positionst meta_variables; - }; - typedef std::vector const_invariant_loopst; - typedef std::vector invariant_loopst; - - symbol_tablet st; - goto_functionst gf; - /** - * @brief The range in the program relevant for invariant analysis. - * - * @details Spans from the original beginning of the analysed program up to the - * assertion. - */ - program_ranget invariant_range; - exprt assertion; - goto_programt::targett Ix0; - goto_programt::targett Ax; - - goto_programt::targetst x0_choices; - - /** - * @brief - * - * @details - */ - invariant_programt(); - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - invariant_programt(const symbol_tablet &st, const goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @param other - */ - invariant_programt(const invariant_programt &other); - - /** - * @brief - * - * @details - */ - virtual ~invariant_programt(); - - /** - * @brief - * - * @details - * - * @param other - * - * @return - */ - invariant_programt &operator=(const invariant_programt &other); - - /** - * @brief - * - * @details - * - * @return - */ - virtual const_invariant_loopst get_loops() const = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual invariant_loopst get_loops() = 0; - - /** - * @brief - * - * @details - * - * @return - */ - virtual invariant_loopt &add_loop() = 0; -}; - -#endif // CPROVER_CEGIS_INVARIANT_OPTIONS_INVARIANT_PROGRAM_H diff --git a/src/cegis/invariant/options/target_copy_helper.cpp b/src/cegis/invariant/options/target_copy_helper.cpp deleted file mode 100644 index af0c209bb7c..00000000000 --- a/src/cegis/invariant/options/target_copy_helper.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include - -target_copy_helpert::target_copy_helpert(const goto_programt &old_body, - goto_programt &new_body) : - old_instrs(old_body.instructions), new_instrs(new_body.instructions) -{ -} - -goto_programt::targett target_copy_helpert::operator()( - const goto_programt::targett &target) const -{ - return copy_iterator(old_instrs, new_instrs, target); -} - -void target_copy_helpert::operator()(goto_programt::targetst &tgt, - const goto_programt::targetst &src) const -{ - tgt.resize(src.size()); - std::transform(src.begin(), src.end(), tgt.begin(), *this); -} - -invariant_programt::program_ranget target_copy_helpert::operator()( - const invariant_programt::program_ranget &range) const -{ - invariant_programt::program_ranget result; - result.begin=operator()(range.begin); - result.end=operator()(range.end); - return result; -} - -invariant_programt::meta_vars_positionst target_copy_helpert::operator()( - const invariant_programt::meta_vars_positionst &vars) const -{ - invariant_programt::meta_vars_positionst result; - result.Gx=operator()(vars.Gx); - result.Ix=operator()(vars.Ix); - result.Ix_prime=operator()(vars.Ix_prime); - return result; -} - -void target_copy_helpert::operator()( - invariant_programt::invariant_loopt &result, - const invariant_programt::invariant_loopt &loop) const -{ - result.guard=loop.guard; - result.body=operator()(loop.body); - result.meta_variables=operator()(loop.meta_variables); - goto_programt::targetst &new_s=result.skolem_choices; - const goto_programt::targetst &old_s=loop.skolem_choices; - const auto &fix=std::ref(*this); - std::transform(old_s.begin(), old_s.end(), std::back_inserter(new_s), fix); -} diff --git a/src/cegis/invariant/options/target_copy_helper.h b/src/cegis/invariant/options/target_copy_helper.h deleted file mode 100644 index c69aa677a6d..00000000000 --- a/src/cegis/invariant/options/target_copy_helper.h +++ /dev/null @@ -1,96 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_OPTIONS_TARGET_COPY_HELPER_H -#define CPROVER_CEGIS_INVARIANT_OPTIONS_TARGET_COPY_HELPER_H - -#include - -/** - * @brief - * - * @details - */ -class target_copy_helpert -{ - const goto_programt::instructionst &old_instrs; - goto_programt::instructionst &new_instrs; -public: - /** - * @brief - * - * @details - * - * @param old_body - * @param new_body - */ - target_copy_helpert(const goto_programt &old_body, goto_programt &new_body); - - /** - * @brief - * - * @details - * - * @param target - * - * @return - */ - goto_programt::targett operator()(const goto_programt::targett &target) const; - - /** - * @brief - * - * @details - * - * @param target_targets - * @param src_targets - * - * @return - */ - void operator()( - goto_programt::targetst &target_targets, - const goto_programt::targetst &src_targets) const; - - /** - * @brief - * - * @details - * - * @param range - * - * @return - */ - invariant_programt::program_ranget operator()( - const invariant_programt::program_ranget &range) const; - - /** - * @brief - * - * @details - * - * @param vars - * - * @return - */ - invariant_programt::meta_vars_positionst operator()( - const invariant_programt::meta_vars_positionst &vars) const; - - /** - * @brief - * - * @details - * - * @param result - * @param loop - */ - void operator()(invariant_programt::invariant_loopt &result, - const invariant_programt::invariant_loopt &loop) const; -}; - -#endif // CPROVER_CEGIS_INVARIANT_OPTIONS_TARGET_COPY_HELPER_H diff --git a/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.cpp b/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.cpp deleted file mode 100644 index 2532a1ceca3..00000000000 --- a/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -bool need_temp_variables(const size_t max_program_length) -{ - return max_program_length >= 2u; -} -} - -void create_tmp_variables(invariant_programt &program, - const size_t max_program_length) -{ - create_tmp_variables(program, max_program_length, - cegis_default_integer_type()); -} - -void create_tmp_variables(invariant_programt &program, - const size_t max_program_length, const typet &type) -{ - if(!need_temp_variables(max_program_length)) return; - symbol_tablet &st=program.st; - goto_functionst &gf=program.gf; - goto_programt &body=get_entry_body(gf); - goto_programt::targett insert_after=program.invariant_range.begin; - --insert_after; - for(size_t i=0; i < max_program_length - 1; ++i) - { - const std::string name(get_tmp(i)); - insert_after=declare_cegis_meta_variable(st, gf, insert_after, name, type); - if(i == 0) move_labels(body, program.invariant_range.begin, insert_after); - } -} - -namespace -{ -class create_meta_variables_for_loopt -{ - symbol_tablet &st; - goto_functionst &gf; - const inv_name_factoryt &inv_name; - const inv_name_factoryt &inv_prime_name; - const typet &type; - size_t loop_id; -public: - create_meta_variables_for_loopt(invariant_programt &prog, - const inv_name_factoryt &inv_name, - const inv_name_factoryt &inv_prime_name, const typet &type) : - st(prog.st), gf(prog.gf), inv_name(inv_name), inv_prime_name( - inv_prime_name), type(type), loop_id(0u) - { - } - - void operator()(invariant_programt::invariant_loopt * const loop) - { - invariant_programt::meta_vars_positionst &im=loop->meta_variables; - goto_programt::targett pos=loop->body.begin; - const std::string inv(inv_name(loop_id)); - im.Ix=declare_cegis_meta_variable(st, gf, --pos, inv, type); - goto_programt &body=get_entry_body(gf); - move_labels(body, loop->body.begin, im.Ix); - const std::string guard(get_Gx(loop_id)); - im.Gx=declare_cegis_meta_variable(st, gf, im.Ix, guard, type); - assign_cegis_meta_variable(st, gf, im.Gx, guard, loop->guard); - pos=loop->body.end; - const std::string x_prime(inv_prime_name(loop_id)); - im.Ix_prime=declare_cegis_meta_variable(st, gf, --pos, x_prime, type); - move_labels(body, loop->body.end, im.Ix_prime); - ++loop_id; - } -}; - -void createAx(invariant_programt &program, const typet &type) -{ - symbol_tablet &st=program.st; - goto_functionst &gf=program.gf; - goto_programt::targett pos=program.get_loops().back()->body.begin; - const std::string base_name(get_Ax()); - program.Ax=declare_cegis_meta_variable(st, gf, --pos, get_Ax(), type); - assign_cegis_meta_variable(st, gf, program.Ax, base_name, program.assertion); -} - -void createIx0(invariant_programt &program, const std::string &inv0_name, - const typet &type) -{ - const invariant_programt &prog=program; - invariant_programt::const_invariant_loopst loops(prog.get_loops()); - assert(!loops.empty() && "At least one loop required."); - const invariant_programt::invariant_loopt &first=*loops.front(); - goto_programt::targett &meta=program.Ix0; - goto_programt::targett pos=first.meta_variables.Ix; - goto_functionst &gf=program.gf; - meta=declare_cegis_meta_variable(program.st, gf, --pos, inv0_name, type); - move_labels(get_entry_body(gf), first.body.begin, meta); -} -} - -void add_invariant_variables(invariant_programt &p, - const std::string &inv0_name, const inv_name_factoryt inv_name, - const inv_name_factoryt inv_prime_name) -{ - add_invariant_variables(p, inv0_name, inv_name, inv_prime_name, - cegis_default_integer_type()); -} - -void add_invariant_variables(invariant_programt &p, - const std::string &inv0_name, const inv_name_factoryt inv_name, - const inv_name_factoryt inv_prime_name, const typet &type) -{ - const invariant_programt::invariant_loopst loops(p.get_loops()); - const create_meta_variables_for_loopt c(p, inv_name, inv_prime_name, type); - std::for_each(loops.begin(), loops.end(), c); - createIx0(p, inv0_name, type); - createAx(p, type); -} diff --git a/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.h b/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.h deleted file mode 100644 index 4272953976f..00000000000 --- a/src/cegis/invariant/preprocess/add_invariants_and_temp_variables.h +++ /dev/null @@ -1,73 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_PREPROCESS_ADD_INVARIANTS_AND_TEMP_VARIABLES_H -#define CPROVER_CEGIS_INVARIANT_PREPROCESS_ADD_INVARIANTS_AND_TEMP_VARIABLES_H - -#include - -typedef std::function inv_name_factoryt; - -/** - * @brief - * - * @details - * - * @param program - * @param max_program_length - * @param inv0_name - * @param inv_name - * @param inv_prime_name - */ -void add_invariant_variables(class invariant_programt &program, - const std::string &inv0_name, const inv_name_factoryt inv_name, - const inv_name_factoryt inv_prime_name); - -/** - * @brief - * - * @details - * - * @param program - * @param max_program_length - * @param inv0_name - * @param inv_name - * @param inv_prime_name - * @param type - */ -void add_invariant_variables(class invariant_programt &program, - const std::string &inv0_name, const inv_name_factoryt inv_name, - const inv_name_factoryt inv_prime_name, const class typet &type); - -/** - * @brief - * - * @details - * - * @param program - * @param max_program_length - */ -void create_tmp_variables(invariant_programt &program, - const size_t max_program_length); - -/** - * @brief - * - * @details - * - * @param program - * @param max_program_length - * @param type - */ -void create_tmp_variables( - invariant_programt &program, - const size_t max_program_length, - const class typet &type); - -#endif // CPROVER_CEGIS_INVARIANT_PREPROCESS_ADD_INVARIANTS_AND_TEMP_VARIABLES_H diff --git a/src/cegis/invariant/preprocess/remove_loops_and_assertion.cpp b/src/cegis/invariant/preprocess/remove_loops_and_assertion.cpp deleted file mode 100644 index acaa96e499a..00000000000 --- a/src/cegis/invariant/preprocess/remove_loops_and_assertion.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -namespace -{ -bool handle_assertion_removal(invariant_programt &program, - goto_programt::instructionst &instrs, const goto_programt::targett &target) -{ - const goto_programt::instructiont &instr=*target; - if(goto_program_instruction_typet::ASSERT != instr.type) return false; - const namespacet ns(program.st); - assert(program.assertion.id().empty()); - program.assertion=instr.guard; - goto_programt::targett &end=program.invariant_range.end; - end=target; - --end; - goto_programt::targett &last_loop_end=program.get_loops().back()->body.end; - const bool is_last_loop_end=last_loop_end == target; - erase_target(instrs, target); - ++end; - if(is_last_loop_end) last_loop_end=end; - return true; -} - -goto_programt::targett handle_loop_removal(invariant_programt &program, - goto_programt::instructionst &instrs, goto_programt::targett target) -{ - if(!target->is_backwards_goto()) return target; - invariant_programt::invariant_loopt &loop=program.add_loop(); - const goto_programt::targett next_in_loop=std::prev(target); - invariant_remove_loop(program.st, instrs, target, loop.guard, loop.body.begin, - loop.body.end); - return next_in_loop; -} -} - -void invariant_remove_loop(const symbol_tablet &st, - goto_programt::instructionst &instrs, const goto_programt::targett &target, - exprt &guard, goto_programt::targett &body_begin, - goto_programt::targett &body_end) -{ - const goto_programt::instructiont &instr=*target; - const namespacet ns(st); - const goto_programt::targett goto_target=instr.get_target(); - if(instr.guard.is_true()) - { - goto_programt::targett guard_instr=goto_target; - const goto_programt::targett end=instrs.end(); - while(end != guard_instr && guard_instr->guard.is_true()) - ++guard_instr; - assert(end != guard_instr); - if(ID_not == guard.id()) guard=to_not_expr(guard_instr->guard).op(); - else guard=simplify_expr(not_exprt(guard_instr->guard), ns); - body_begin=std::next(guard_instr); - erase_target(instrs, guard_instr); - } else - { - guard=simplify_expr(instr.guard, ns); - body_begin=goto_target; - } - assert(!guard.id().empty()); - body_end=std::prev(target); - erase_target(instrs, target); - ++body_end; -} - -void invariant_remove_loops_and_assertion(invariant_programt &program) -{ - goto_programt &body=get_entry_body(program.gf); - goto_programt::instructionst &instrs=body.instructions; - program.invariant_range.begin=instrs.begin(); - for(goto_programt::targett it=instrs.begin(); it != instrs.end(); ++it) - { - if(handle_assertion_removal(program, instrs, it)) break; - it=handle_loop_removal(program, instrs, it); - } -} diff --git a/src/cegis/invariant/preprocess/remove_loops_and_assertion.h b/src/cegis/invariant/preprocess/remove_loops_and_assertion.h deleted file mode 100644 index ac3bd191dcf..00000000000 --- a/src/cegis/invariant/preprocess/remove_loops_and_assertion.h +++ /dev/null @@ -1,43 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_PREPROCESS_REMOVE_LOOPS_AND_ASSERTION_H -#define CPROVER_CEGIS_INVARIANT_PREPROCESS_REMOVE_LOOPS_AND_ASSERTION_H - -#include - -/** - * @brief - * - * @details - * - * @param program - */ -void invariant_remove_loops_and_assertion(class invariant_programt &program); - -/** - * @brief - * - * @details - * - * @param instrs - * @param instr - * @param guard - * @param body_begin - * @param body_end - */ -void invariant_remove_loop( - const class symbol_tablet &st, - goto_programt::instructionst &instrs, - const goto_programt::targett &instr, - exprt &guard, - goto_programt::targett &body_begin, - goto_programt::targett &body_end); - -#endif // CPROVER_CEGIS_INVARIANT_PREPROCESS_REMOVE_LOOPS_AND_ASSERTION_H diff --git a/src/cegis/invariant/symex/learn/add_counterexamples.cpp b/src/cegis/invariant/symex/learn/add_counterexamples.cpp deleted file mode 100644 index 6e4c83e59b9..00000000000 --- a/src/cegis/invariant/symex/learn/add_counterexamples.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -typedef std::map array_valuest; - -typedef counterexamplet::const_iterator ceitt; -class create_x_array_valuest -{ - array_valuest &vals; - const counterexamplet &prototype; - const size_t num_ces; -public: - array_valuest::value_type to_array(const ceitt &it, const exprt &size) - { - const array_exprt array(array_typet(it->second.type(), size)); - return std::make_pair(it->first, array); - } - - create_x_array_valuest(array_valuest &vals, const counterexamplet &prototype, - const size_t num_ces) : - vals(vals), prototype(prototype), num_ces(num_ces) - { - const constant_exprt size(from_integer(num_ces, unsigned_int_type())); - for(ceitt it=prototype.begin(); it != prototype.end(); ++it) - vals.insert(to_array(it, size)); - } - - void operator()(const counterexamplet &ce) const - { - for(ceitt it=ce.begin(); it != ce.end(); ++it) - vals[it->first].copy_to_operands(it->second); - } -}; - -void declare_x_arrays(symbol_tablet &st, goto_functionst &gf, - goto_programt::targett pos, const array_valuest &vals, - const std::string &meta_var_prefix) -{ - for(array_valuest::const_iterator it=vals.begin(); it != vals.end(); ++it) - { - std::string base_name(meta_var_prefix); - base_name+=id2string(it->first); - const array_exprt &value=it->second; - const typet &type=value.type(); - pos=declare_cegis_meta_variable(st, gf, pos, base_name, type); - pos=assign_cegis_meta_variable(st, gf, pos, base_name, value); - } -} - -const char X_INDEX[]=CEGIS_PREFIX "x_index"; -symbol_exprt get_index(const symbol_tablet &st) -{ - const std::string index_name(get_cegis_meta_name(X_INDEX)); - return st.lookup(index_name).symbol_expr(); -} - -goto_programt::targett find_decl(goto_programt::targett begin, - const goto_programt::targett &end, const irep_idt &id) -{ - for(; begin != end; ++begin) - if(begin->is_decl() && get_affected_variable(*begin) == id) return begin; - return end; -} - -class assign_ce_valuet -{ - const invariant_programt &prog; - const symbol_tablet &st; - goto_functionst &gf; - goto_programt::targett pos; - goto_programt::targett goto_pos; - const std::string meta_var_prefix; - const bool use_x0_ce; -public: - void add_x0_case(const size_t ces_size) - { - const typet size_type(unsigned_int_type()); - const constant_exprt num_ces(from_integer(ces_size, size_type)); - const symbol_exprt index(get_index(st)); - const equal_exprt cond(index, num_ces); - pos->guard=cond; - goto_pos=pos; - } - - assign_ce_valuet(invariant_programt &prog, const size_t ces_size, - const goto_programt::targett begin_pos, - const std::string &meta_var_prefix, const bool use_x0_ce) : - prog(prog), st(prog.st), gf(prog.gf), meta_var_prefix(meta_var_prefix), use_x0_ce( - use_x0_ce) - { - const invariant_programt::invariant_loopst loops(prog.get_loops()); - assert(!loops.empty()); - pos=begin_pos; - ++pos; - if(use_x0_ce) - { - pos=get_entry_body(gf).insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - pos->source_location=default_cegis_source_location(); - add_x0_case(ces_size); - } - } - - void operator()(const std::pair &assignment) - { - std::string base_name(meta_var_prefix); - base_name+=id2string(assignment.first); - const std::string array_name(get_cegis_meta_name(base_name)); - const symbol_exprt array(st.lookup(array_name).symbol_expr()); - const index_exprt rhs(array, get_index(st)); - const irep_idt &id=assignment.first; - const symbol_exprt lhs(st.lookup(id).symbol_expr()); - const goto_programt::targett end(prog.invariant_range.end); - const goto_programt::targett decl(find_decl(pos, end, id)); - if(end == decl) pos=cegis_assign(st, gf, pos, lhs, rhs); - else cegis_assign(st, gf, decl, lhs, rhs); - } - - void finalize_x0_case() - { - if(use_x0_ce) goto_pos->targets.push_back(++pos); - } -}; - -void create_constraints(invariant_programt &prog, - const constraint_factoryt &constraint) -{ - goto_programt::targett pos=prog.invariant_range.end; - std::advance(pos, -3); - goto_programt &body=get_entry_body(prog.gf); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSUME; - pos->source_location=default_cegis_source_location(); - pos->guard=constraint(prog.get_loops().size()); -} - -void add_final_assertion(invariant_programt &prog, - const goto_programt::targett &loop_end) -{ - goto_programt &body=get_entry_body(prog.gf); - goto_programt::targett assertion=body.insert_after(loop_end); - assertion->type=goto_program_instruction_typet::ASSERT; - assertion->source_location=default_cegis_source_location(); - assertion->guard=false_exprt(); -} -} - -void invariant_declare_x_choice_arrays(invariant_programt &prog, - const counterexamplest &ces, const std::string &meta_var_prefix) -{ - array_valuest vals; - const create_x_array_valuest create_values(vals, ces.front(), ces.size()); - std::for_each(ces.begin(), ces.end(), create_values); - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt::targett pos=prog.invariant_range.begin; - declare_x_arrays(st, gf, --pos, vals, meta_var_prefix); -} - -namespace -{ -const char X_LABEL[]=CEGIS_PREFIX"x_loop"; -} - -goto_programt::targett invariant_add_ce_loop(invariant_programt &prog, - const size_t ces_size, const bool use_x0_ce) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt::targett pos=prog.invariant_range.begin; - const typet size_type(unsigned_int_type()); - pos=declare_cegis_meta_variable(st, gf, --pos, X_INDEX, size_type); - const constant_exprt first_index(from_integer(0, size_type)); - pos=assign_cegis_meta_variable(st, gf, pos, X_INDEX, first_index); - goto_programt::targett loop_head=pos; - (++loop_head)->labels.push_back(X_LABEL); - goto_programt &body=get_entry_body(gf); - pos=insert_before_preserve_labels(body, prog.invariant_range.end); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=default_cegis_source_location(); - const symbol_exprt index(get_index(st)); - const constant_exprt one(from_integer(1, size_type)); - const code_assignt inc(index, plus_exprt(index, one)); - pos->code=inc; - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - pos->source_location=default_cegis_source_location(); - pos->function=goto_functionst::entry_point(); - pos->targets.push_back(loop_head); - pos->loop_number=0u; - const size_t loop_limit=use_x0_ce ? ces_size + 1 : ces_size; - const constant_exprt num_ces(from_integer(loop_limit, size_type)); - const binary_relation_exprt cond(index, ID_lt, num_ces); - pos->guard=cond; - return pos; -} - -void invariant_assign_ce_values(invariant_programt &prog, - const counterexamplet &prototype_ce, const size_t num_ces, - const std::string &prefix, const goto_programt::targett pos, - const bool use_x0_ce) -{ - const assign_ce_valuet assign_value(prog, num_ces, pos, prefix, use_x0_ce); - std::for_each(prototype_ce.begin(), prototype_ce.end(), assign_value).finalize_x0_case(); -} - -void invariant_add_constraint(invariant_programt &prog, - const constraint_factoryt constraint, - const goto_programt::targett &ce_loop_end) -{ - create_constraints(prog, constraint); - add_final_assertion(prog, ce_loop_end); -} - -void invariant_add_learned_counterexamples(invariant_programt &prog, - const counterexamplest &ces, const constraint_factoryt constraint, - const bool x0_ce) -{ - // TODO: Danger counterexamples need one map per loop (per quantifier)! - if(ces.empty()) return; - const std::string pre(X_CHOICE_PREFIX); - invariant_declare_x_choice_arrays(prog, ces, pre); - const size_t sz=ces.size(); - const goto_programt::targett loop_end=invariant_add_ce_loop(prog, sz, x0_ce); - const goto_programt::targett pos=prog.get_loops().front()->meta_variables.Ix; - invariant_assign_ce_values(prog, ces.front(), ces.size(), pre, pos, x0_ce); - invariant_add_constraint(prog, constraint, loop_end); -} diff --git a/src/cegis/invariant/symex/learn/add_counterexamples.h b/src/cegis/invariant/symex/learn/add_counterexamples.h deleted file mode 100644 index 97a95560536..00000000000 --- a/src/cegis/invariant/symex/learn/add_counterexamples.h +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H - -#include -#include - -#include - -#include - -/** - * @brief - * - * @details - */ -#define X_CHOICE_PREFIX CEGIS_PREFIX "x_choice_" - -/** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ -typedef std::map counterexamplet; -typedef std::deque counterexamplest; - -/** - * @brief Constraint factory function. - * - * @details Provides the constraint to test counterexamples against (safety or danger). - */ -typedef std::function constraint_factoryt; - -/** - * @brief - * - * @details - * - * @param prog - * @param ces - * @param use_x0_ce - */ -void invariant_add_learned_counterexamples(class invariant_programt &prog, - const counterexamplest &ces, constraint_factoryt constraint, - bool use_x0_ce); - -/** - * @brief - * - * @details - * - * @param prog - * @param ces - * @param meta_var_prefix - */ -void invariant_declare_x_choice_arrays(invariant_programt &prog, - const counterexamplest &ces, const std::string &meta_var_prefix); - -/** - * @brief - * - * @details - * - * @param prog - * @param ces_size - * @param use_x0_ce - * - * @return - */ -goto_programt::targett invariant_add_ce_loop(invariant_programt &prog, - const size_t ces_size, const bool use_x0_ce); - -/** - * @brief - * - * @details - * - * @param prog - * @param prototype_ce - * @param num_ces - * @param meta_var_prefix - * @param pos - * @param use_x0_ce - */ -void invariant_assign_ce_values(invariant_programt &prog, - const counterexamplet &prototype_ce, const size_t num_ces, - const std::string &meta_var_prefix, const goto_programt::targett pos, - const bool use_x0_ce); - -/** - * @brief - * - * @details - * - * @param prog - * @param constraint - * @param ce_loop_end - */ -void invariant_add_constraint(invariant_programt &prog, - const constraint_factoryt constraint, - const goto_programt::targett &ce_loop_end); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H diff --git a/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.cpp b/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.cpp deleted file mode 100644 index 39f9b696072..00000000000 --- a/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -const char PROG_SUFFIX[]="_prog"; -} - -std::string get_prog_var_name(const symbol_tablet &st, - const goto_programt::targett &decl) -{ - const irep_idt &base_id=st.lookup(get_affected_variable(*decl)).base_name; - std::string base_name(id2string(base_id)); - return base_name+=PROG_SUFFIX; -} - -void execute_inv_prog(const symbol_tablet &st, goto_functionst &gf, - const size_t max_solution_size, const goto_programt::targett &decl, - const std::string &prog_base_name) -{ - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=decl; - goto_programt::targett execution=body.insert_after(++pos); - execution->type=goto_program_instruction_typet::FUNCTION_CALL; - execution->source_location=default_cegis_source_location(); - code_function_callt call; - call.function()=st.lookup(DANGER_EXECUTE).symbol_expr(); - const std::string prog_name(get_cegis_meta_name(prog_base_name)); - const symbol_exprt prog_symbol(st.lookup(prog_name).symbol_expr()); - const typet size_type(unsigned_int_type()); - const constant_exprt index(from_integer(0u, size_type)); - const index_exprt first_elem(prog_symbol, index); - call.arguments().push_back(address_of_exprt(first_elem)); - const typet size_arg_type(unsigned_char_type()); - const constant_exprt size(from_integer(max_solution_size, size_arg_type)); - call.arguments().push_back(size); - execution->code=call; -} - -void execute_inv_prog(const symbol_tablet &st, goto_functionst &gf, - const size_t max_solution_size, const goto_programt::targett &decl) -{ - execute_inv_prog(st, gf, max_solution_size, decl, - get_prog_var_name(st, decl)); -} - -goto_programt::targett add_inv_prog(invariant_programt &prog, - goto_programt::targett pos, const size_t max_solution_size, - const goto_programt::targett &decl) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - const std::string base_name(get_prog_var_name(st, decl)); - const typet size_type(unsigned_int_type()); - const constant_exprt size(from_integer(max_solution_size, size_type)); - const symbol_typet instr_type(CEGIS_INSTRUCTION_TYPE_NAME); - const array_typet prog_type(instr_type, size); - pos=declare_cegis_meta_variable(st, gf, pos, base_name, prog_type); - execute_inv_prog(st, gf, max_solution_size, decl); - return pos; -} - -namespace -{ -class declare_programst -{ - invariant_programt &prog; - const size_t max_solution_size; - goto_programt::targett pos; -public: - declare_programst(invariant_programt &prog, const size_t max_solution_size, - const goto_programt::targett &pos) : - prog(prog), max_solution_size(max_solution_size), pos(pos) - { - } - - void operator()(const invariant_programt::invariant_loopt * const loop) - { - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - const invariant_programt::meta_vars_positionst &im=loop->meta_variables; - pos=add_inv_prog(prog, pos, max_solution_size, im.Ix); - const std::string dx_prog_name=get_prog_var_name(st, im.Ix); - execute_inv_prog(st, gf, max_solution_size, im.Ix_prime, dx_prog_name); - } - - const goto_programt::targett &get_pos() const - { - return pos; - } -}; -} - -goto_programt::targett add_invariant_progs_to_learn(invariant_programt &prog, - const size_t max_sol_sz) -{ - const invariant_programt::invariant_loopst loops(prog.get_loops()); - goto_programt::targett pos=prog.invariant_range.begin; - if(loops.empty()) return pos; - const declare_programst declare_progs(prog, max_sol_sz, --pos); - return std::for_each(loops.begin(), loops.end(), declare_progs).get_pos(); -} diff --git a/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.h b/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.h deleted file mode 100644 index cfbccfbca8c..00000000000 --- a/src/cegis/invariant/symex/learn/add_invariant_programs_to_learn.h +++ /dev/null @@ -1,78 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_INVARIANT_PROGRAMS_TO_LEARN_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_INVARIANT_PROGRAMS_TO_LEARN_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param decl - */ -std::string get_prog_var_name(const symbol_tablet &st, - const goto_programt::targett &decl); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param max_solution_size - * @param decl - * @param prog_base_name - */ -void execute_inv_prog(const symbol_tablet &st, goto_functionst &gf, - size_t max_solution_size, const goto_programt::targett &decl, - const std::string &prog_base_name); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param max_solution_size - * @param decl - */ -void execute_inv_prog(const symbol_tablet &st, goto_functionst &gf, - size_t max_solution_size, const goto_programt::targett &decl); - -/** - * @brief - * - * @details - * - * @param prog - * @param pos - * @param max_solution_size - * @param decl - */ -goto_programt::targett add_inv_prog(invariant_programt &prog, - goto_programt::targett pos, size_t max_solution_size, - const goto_programt::targett &decl); - -/** - * @brief - * - * @details - * - * @param prog - */ -goto_programt::targett add_invariant_progs_to_learn( - class invariant_programt &prog, size_t max_solution_size); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_ADD_INVARIANT_PROGRAMS_TO_LEARN_H diff --git a/src/cegis/invariant/symex/learn/instrument_vars.cpp b/src/cegis/invariant/symex/learn/instrument_vars.cpp deleted file mode 100644 index 798c083cdcd..00000000000 --- a/src/cegis/invariant/symex/learn/instrument_vars.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#if 0 -namespace -{ -null_pointer_exprt get_null() -{ - const pointer_typet void_pointer_type=pointer_typet(void_typet()); - return null_pointer_exprt(void_pointer_type); -} -} -#endif - -void link_result_var(const symbol_tablet &st, goto_functionst &gf, - const size_t num_user_vars, const size_t max_solution_size, - goto_programt::targett pos) -{ - goto_programt &body=get_entry_body(gf); - const size_t num_temps=max_solution_size - 1; - pos=link_temp_vars(st, body, --pos, num_temps, num_user_vars); - ++pos; - set_rops_reference(st, body, pos, get_affected_variable(*pos), num_temps); -} - -goto_programt::targett set_rops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const irep_idt &name, const unsigned int id) -{ - return set_ops_reference(st, body, pos, CEGIS_RESULT_OPS, name, id); -} - -goto_programt::targett link_temp_vars(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, const size_t num_temps, - const size_t num_user_vars) -{ - goto_programt::targett previous_successor(pos); - ++previous_successor; - for(size_t i=0; i < num_temps; ++i) - { - const std::string name=get_cegis_meta_name(get_tmp(i)); - pos=set_rops_reference(st, body, pos, name, i); - if(i == 0) move_labels(body, previous_successor, pos); - pos=set_ops_reference(st, body, pos, name, i + num_user_vars); - } - return pos; -} - -void link_user_program_variables(invariant_programt &prog, - const operand_variable_idst &var_ids) -{ - const goto_programt::targett begin=prog.invariant_range.begin; - const goto_programt::targett end=prog.invariant_range.end; - link_user_program_variable_ops(prog.st, prog.gf, var_ids, - is_instrumentable_user_variable, begin, end); -} - -#if 0 -namespace -{ -void link_user_symbols(const symbol_tablet &st, operand_variable_idst &var_ids, - size_t &variable_id, bool consts) -{ - typedef symbol_tablet::symbolst symbolst; - const symbolst &symbols=st.symbols; - for(symbolst::const_iterator it=symbols.begin(); it != symbols.end(); ++it) - { - const symbolt &symbol=it->second; - if(!is_instrumentable_user_variable(symbol.name, symbol.type)) continue; - const bool is_const=is_global_const(symbol.name, symbol.type); - if(is_const == consts) - var_ids.insert(std::make_pair(symbol.name, variable_id++)); - } -} -} -#endif - -size_t get_invariant_variable_ids(const symbol_tablet &st, - operand_variable_idst &ids) -{ - return get_variable_op_ids(st, ids, &is_instrumentable_user_variable); -} diff --git a/src/cegis/invariant/symex/learn/instrument_vars.h b/src/cegis/invariant/symex/learn/instrument_vars.h deleted file mode 100644 index f2b963cb173..00000000000 --- a/src/cegis/invariant/symex/learn/instrument_vars.h +++ /dev/null @@ -1,92 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INSTRUMENT_VARS_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INSTRUMENT_VARS_H - -#include - -#include - -/** - * @brief - * - * @details - */ -typedef std::map operand_variable_idst; - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param num_temps - * @param num_user_vars - */ -goto_programt::targett link_temp_vars(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, const size_t num_temps, - const size_t num_user_vars); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param num_user_vars - * @param max_solution_size - * @param pos - */ -void link_result_var(const symbol_tablet &st, goto_functionst &gf, - size_t num_user_vars, size_t max_solution_size, goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param name - * @param id - */ -goto_programt::targett set_rops_reference(const symbol_tablet &st, - goto_programt &body, const goto_programt::targett &pos, - const irep_idt &name, const unsigned int id); - -/** - * @brief - * - * @details - * - * @param prog - * @param var_ids - */ -void link_user_program_variables(class invariant_programt &prog, - const operand_variable_idst &var_ids); - -/** - * @brief - * - * @details - * - * @param st - * @params ids - * - * @return - */ -size_t get_invariant_variable_ids(const class symbol_tablet &st, - operand_variable_idst &ids); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INSTRUMENT_VARS_H diff --git a/src/cegis/invariant/symex/learn/invariant_body_provider.h b/src/cegis/invariant/symex/learn/invariant_body_provider.h deleted file mode 100644 index d58fea886fb..00000000000 --- a/src/cegis/invariant/symex/learn/invariant_body_provider.h +++ /dev/null @@ -1,58 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INVARIANT_BODY_PROVIDER_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INVARIANT_BODY_PROVIDER_H - -#include - -/** - * @brief - * - * @details - */ -template -class invariant_exec_body_providert -{ - const std::string exec_func_name; - const inv_progt &original_prog; - inv_progt prog; - bool initialised; -public: - /** - * @brief - * - * @details - * - * @param exec_func_name - * @param prog - */ - invariant_exec_body_providert(const std::string &exec_func_name, - const inv_progt &prog); - - /** - * @brief - * - * @details - */ - ~invariant_exec_body_providert(); - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_programt &operator()(); -}; - -#include "invariant_body_provider.inc" - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_INVARIANT_BODY_PROVIDER_H diff --git a/src/cegis/invariant/symex/learn/invariant_body_provider.inc b/src/cegis/invariant/symex/learn/invariant_body_provider.inc deleted file mode 100644 index 669cc7f9ba2..00000000000 --- a/src/cegis/invariant/symex/learn/invariant_body_provider.inc +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#include - -template -invariant_exec_body_providert::invariant_exec_body_providert( - const std::string &exec_func_name, const inv_progt &prog) : - exec_func_name(exec_func_name), original_prog(prog), initialised(false) -{ -} - -template -invariant_exec_body_providert::~invariant_exec_body_providert() -{ -} - -template -const goto_programt &invariant_exec_body_providert::operator ()() -{ - if (!initialised) - { - prog=original_prog; - null_message_handlert msg; - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - add_cegis_library(st, gf, msg, 0u, 0u, 1u, exec_func_name); - initialised=true; - } - const irep_idt id(exec_func_name); - const goto_functionst::function_mapt &function_map=prog.gf.function_map; - const goto_functionst::function_mapt::const_iterator it=function_map.find(id); - assert(function_map.end() != it); - const goto_function_templatet &f=it->second; - assert(f.body_available()); - return f.body; -} diff --git a/src/cegis/invariant/symex/learn/replace_operators.cpp b/src/cegis/invariant/symex/learn/replace_operators.cpp deleted file mode 100644 index 7646629311a..00000000000 --- a/src/cegis/invariant/symex/learn/replace_operators.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -namespace -{ -const char ROP_SUFFIX[]="::1::1::1::result"; -const char OP0_SUFFIX[]="::1::1::1::op0"; -const char OP1_SUFFIX[]="::1::1::1::op1"; -const char OP2_SUFFIX[]="::1::1::1::op2"; -class replace_ops_visitort: public expr_visitort -{ -private: - const symbol_tablet &st; - const namespacet ns; - const std::string rop_name; - const std::string op0_name; - const std::string op1_name; - const std::string op2_name; - invariant_variable_namest names; - const invariant_variable_namest &rnames; - const size_t op0; - const size_t op1; - const size_t op2; - const size_t instr_idx; -public: - replace_ops_visitort(const symbol_tablet &st, const std::string &func_name, - const invariant_variable_namest &names, const invariant_variable_namest &rnames, - const size_t op0, const size_t op1, const size_t op2, - const size_t instr_idx) : - st(st), ns(st), rop_name(func_name + ROP_SUFFIX), op0_name( - func_name + OP0_SUFFIX), op1_name(func_name + OP1_SUFFIX), op2_name( - func_name + OP2_SUFFIX), names(names), rnames(rnames), op0(op0), op1( - op1), op2(op2), instr_idx(instr_idx) - { - typedef invariant_variable_namest::const_iterator itt; - const size_t offset(names.size()); - for(itt it=rnames.begin(); it != rnames.end(); ++it) - this->names.insert(std::make_pair(offset + it->first, it->second)); - } - virtual ~replace_ops_visitort() - { - } -public: - virtual void operator()(exprt &expr) - { - if(ID_symbol != expr.id()) return; - const irep_idt &op_name=to_symbol_expr(expr).get_identifier(); - const bool is_res=op_name == rop_name; - const bool is_op0=op_name == op0_name; - const bool is_op1=op_name == op1_name; - const bool is_op2=op_name == op2_name; - if(!is_res && !is_op0 && !is_op1 && !is_op2) return; - const invariant_variable_namest &names=is_res ? rnames : this->names; - const size_t op=is_res ? instr_idx : is_op0 ? op0 : is_op1 ? op1 : op2; - const invariant_variable_namest::const_iterator name=names.find(op); - assert(names.end() != name); - const symbol_exprt symbol(st.lookup(name->second).symbol_expr()); - const typet danger_type(cegis_default_integer_type()); - if(type_eq(danger_type, symbol.type(), ns)) expr=symbol; - else expr=typecast_exprt(symbol, danger_type); // XXX: Change if operations for other types are added. - } -}; -} - -void replace_ops_in_instr(const symbol_tablet &st, const std::string &func, - const goto_programt::targett &first, const goto_programt::targett &last, - const invariant_variable_namest &names, const invariant_variable_namest &rnames, - const size_t op0, const size_t op1, const size_t op2, - const size_t instr_idx) -{ - replace_ops_visitort v(st, func, names, rnames, op0, op1, op2, instr_idx); - for(goto_programt::targett it=first; it != last; ++it) - { - goto_programt::instructiont &instr=*it; - instr.code.visit(v); - instr.guard.visit(v); - } -} - -void reverse_invariant_var_ids(invariant_variable_namest &names, - const operand_variable_idst &ids) -{ - for(const auto id : ids) - names.insert(std::make_pair(id.second, id.first)); -} diff --git a/src/cegis/invariant/symex/learn/replace_operators.h b/src/cegis/invariant/symex/learn/replace_operators.h deleted file mode 100644 index 1668871c951..00000000000 --- a/src/cegis/invariant/symex/learn/replace_operators.h +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_REPLACE_OPERATORS_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_REPLACE_OPERATORS_H - -#include - -typedef std::map invariant_variable_namest; -typedef std::map operand_variable_idst; - -/** - * @brief - * - * @details - * - * @param names - * @param ids - */ -void reverse_invariant_var_ids(invariant_variable_namest &names, - const operand_variable_idst &ids); - -/** - * @brief - * - * @details - * - * @param st - * @param func_name - * @param first - * @param last - * @param names - * @param rnames - * @param op0 - * @param op1 - * @param op2 - * @param instr_idx - */ -void replace_ops_in_instr(const symbol_tablet &st, const std::string &func_name, - const goto_programt::targett &first, const goto_programt::targett &last, - const invariant_variable_namest &names, const invariant_variable_namest &rnames, - const size_t op0, const size_t op1, const size_t op2, - const size_t instr_idx); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_LEARN_REPLACE_OPERATORS_H diff --git a/src/cegis/invariant/symex/verify/extract_counterexample.cpp b/src/cegis/invariant/symex/verify/extract_counterexample.cpp deleted file mode 100644 index ab12cc33951..00000000000 --- a/src/cegis/invariant/symex/verify/extract_counterexample.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include - -#include -#include -#include - -namespace -{ -goto_programt::instructiont::labelst::const_iterator find_ceq_label( - const goto_programt::const_targett &pc) -{ - const goto_programt::instructiont::labelst &l=pc->labels; - return std::find_if(l.begin(), l.end(), - [](const irep_idt &label) - { return std::string::npos != id2string(label).find(DANGER_CE_QUANTIFIER_LABEL_PREFIX);}); -} - -bool has_label(const goto_programt::const_targett &pc, const irep_idt &id) -{ - const goto_programt::instructiont::labelst &l=pc->labels; - return l.end() != std::find(l.begin(), l.end(), id); -} - -class extract_counterexamplet -{ - counterexamplet &result; - goto_programt::targetst q; - - bool should_extract(const goto_trace_stept &step) - { - const goto_programt::instructiont::labelst::const_iterator it= - find_ceq_label(step.pc); - if(step.pc->labels.end() == it) return false; - const irep_idt &label=*it; - const size_t original_size=q.size(); - q.erase( - std::remove_if(q.begin(), q.end(), - std::bind(has_label, std::placeholders::_1, label)), q.end()); - return q.size() != original_size; - } -public: - extract_counterexamplet(counterexamplet &result, - const goto_programt::targetst &quantifiers) : - result(result), q(quantifiers) - { - } - - void finalise() - { - for(const goto_programt::targett &pos : q) - { - const irep_idt &var=get_affected_variable(*pos); - const exprt value(from_integer(0, get_affected_type(*pos))); - result.insert(std::make_pair(var, value)); - } - q.clear(); - } - - bool is_done() const - { - return q.empty(); - } - - void operator()(const goto_trace_stept &step) - { - if(!should_extract(step)) return; - const symbol_exprt &lhs=step.lhs_object; - result.insert(std::make_pair(lhs.get_identifier(), step.lhs_object_value)); - } -}; -} - -void invariant_extract_counterexample(counterexamplet &result, - const goto_tracet &trace, const goto_programt::targetst &quantifiers) -{ - const size_t existing_entries=result.size(); - const goto_tracet::stepst &s=trace.steps; - extract_counterexamplet extract(result, quantifiers); - typedef goto_tracet::stepst::const_iterator itt; - for(itt it=s.begin(); it != s.end() && !extract.is_done(); ++it) - extract(*it); - extract.finalise(); - const size_t new_entries=result.size() - existing_entries; - assert(new_entries == quantifiers.size()); - assert(extract.is_done()); -} diff --git a/src/cegis/invariant/symex/verify/extract_counterexample.h b/src/cegis/invariant/symex/verify/extract_counterexample.h deleted file mode 100644 index 70f480762a7..00000000000 --- a/src/cegis/invariant/symex/verify/extract_counterexample.h +++ /dev/null @@ -1,34 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_EXTRACT_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_EXTRACT_COUNTEREXAMPLE_H - -#include - -/** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ -typedef std::map counterexamplet; - -/** - * @brief - * - * @details - * - * @param result - * @param trace - * @param quantifiers - */ -void invariant_extract_counterexample(counterexamplet &result, - const class goto_tracet &trace, const goto_programt::targetst &quantifiers); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_EXTRACT_COUNTEREXAMPLE_H diff --git a/src/cegis/invariant/symex/verify/insert_constraint.cpp b/src/cegis/invariant/symex/verify/insert_constraint.cpp deleted file mode 100644 index 1e8b84fdfe3..00000000000 --- a/src/cegis/invariant/symex/verify/insert_constraint.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -class quantifyt -{ - goto_programt::targetst &quantifiers; - goto_programt::targett pos; - goto_programt &body; - size_t quantifier_count; -public: - quantifyt(goto_programt::targetst &quantifiers, - const goto_programt::targett &pos, invariant_programt &program, - const size_t quantifier_label_offset) : - quantifiers(quantifiers), pos(pos), body(get_entry_body(program.gf)), quantifier_count( - quantifier_label_offset) - { - } - - void operator()(const symbol_exprt &var) - { - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=default_cegis_source_location(); - pos->code=code_assignt(var, side_effect_expr_nondett(var.type())); - std::string label(DANGER_CE_QUANTIFIER_LABEL_PREFIX); - label+=integer2string(quantifier_count++); - pos->labels.push_back(label); - quantifiers.push_back(pos); - } -}; - -void add_universal_quantifier(goto_programt::targetst &quantifiers, - invariant_programt &program, const size_t quantifier_label_offset) -{ - invariant_symbol_set vars(create_empty_symbol_set()); - collect_counterexample_variables(vars, program); - goto_programt::targett Ix=program.get_loops().front()->meta_variables.Ix; - const quantifyt quantify(quantifiers, --Ix, program, quantifier_label_offset); - std::for_each(vars.begin(), vars.end(), quantify); -} - -void add_final_assertion(invariant_programt &program, - const constraint_factoryt &constraint_factory) -{ - goto_programt::targett pos=program.invariant_range.end; - pos=get_entry_body(program.gf).insert_after(--pos); - pos->type=goto_program_instruction_typet::ASSERT; - pos->source_location=default_cegis_source_location(); - pos->guard=constraint_factory(program.get_loops().size()); -} -} - -void invariant_insert_constraint(goto_programt::targetst &quantifiers, - invariant_programt &program, const constraint_factoryt constraint_factory, - const size_t quantifier_label_offset) -{ - add_universal_quantifier(quantifiers, program, quantifier_label_offset); - add_final_assertion(program, constraint_factory); -} diff --git a/src/cegis/invariant/symex/verify/insert_constraint.h b/src/cegis/invariant/symex/verify/insert_constraint.h deleted file mode 100644 index 6c730f9cff0..00000000000 --- a/src/cegis/invariant/symex/verify/insert_constraint.h +++ /dev/null @@ -1,41 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_CONSTRAINT_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_CONSTRAINT_H - -#include -#include - -#include - -/** - * @brief Constraint factory function. - * - * @details Provides the constraint to test counterexamples against (safety or danger). - */ -typedef std::function constraint_factoryt; - -/** - * @brief - * - * @details - * - * @param quantifiers - * @param program - * @param constraint_factory - * @param quantifier_label_offset - */ -void invariant_insert_constraint( - goto_programt::targetst &quantifiers, - class invariant_programt &program, - constraint_factoryt constraint_factory, - size_t quantifier_label_offset = 0); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_CONSTRAINT_H diff --git a/src/cegis/invariant/symex/verify/insert_program.cpp b/src/cegis/invariant/symex/verify/insert_program.cpp deleted file mode 100644 index 59d18506d19..00000000000 --- a/src/cegis/invariant/symex/verify/insert_program.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -namespace -{ -class replace_name_visitort: public expr_visitort -{ - const replacementst &repl; -public: - explicit replace_name_visitort(const replacementst &repl) : - repl(repl) - { - } - - virtual ~replace_name_visitort() - { - } - - virtual void operator()(exprt &expr) - { - if(ID_symbol != expr.id()) return; - symbol_exprt &symbol=to_symbol_expr(expr); - for(replacementst::const_iterator it=repl.begin(); it != repl.end(); ++it) - if(symbol.get_identifier() == it->first) - symbol.set_identifier(it->second); - } -}; - -class insert_instrt -{ - copy_instructionst ©_instr; - goto_programt &body; - goto_programt::targett &pos; - replace_name_visitort visitor; -public: - insert_instrt(copy_instructionst ©_instr, goto_programt &body, - goto_programt::targett &pos, const replacementst &replacements) : - copy_instr(copy_instr), body(body), pos(pos), visitor(replacements) - { - } - - void operator()(const goto_programt::const_targett &target) - { - copy_instr(pos=body.insert_after(pos), target); - pos->guard.visit(visitor); - pos->code.visit(visitor); - } -}; -} - -void insert_program(goto_programt &body, goto_programt::targett pos, - const goto_programt::instructionst &prog, const replacementst &replacements) -{ - copy_instructionst copy_instr; - insert_instrt insert_instr(copy_instr, body, pos, replacements); - goto_programt::const_targett first=prog.begin(); - goto_programt::const_targett last=prog.end(); - if(first == last) return; - --last; - for(; first != last; ++first) - insert_instr(first); - copy_instr.finalize(++pos, last); -} - -void insert_program(goto_programt &body, const goto_programt::targett &pos, - const goto_programt::instructionst &prog, const irep_idt &org_name, - const irep_idt &new_name) -{ - replacementst repl; - repl.insert(std::make_pair(org_name, new_name)); - insert_program(body, pos, prog, repl); -} - -void insert_program(goto_programt &body, const goto_programt::targett &pos, - const goto_programt::instructionst &prog) -{ - const replacementst replacements; - insert_program(body, pos, prog, replacements); -} diff --git a/src/cegis/invariant/symex/verify/insert_program.h b/src/cegis/invariant/symex/verify/insert_program.h deleted file mode 100644 index 5a6ae8c3d65..00000000000 --- a/src/cegis/invariant/symex/verify/insert_program.h +++ /dev/null @@ -1,57 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_PROGRAM_H -#define CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_PROGRAM_H - -#include - -typedef std::map replacementst; - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param prog - */ -void insert_program(goto_programt &body, const goto_programt::targett &pos, - const goto_programt::instructionst &prog); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param prog - * @param org_name - * @param new_name - */ -void insert_program(goto_programt &body, const goto_programt::targett &pos, - const goto_programt::instructionst &prog, const irep_idt &org_name, - const irep_idt &new_name); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param prog - * @param replacements - */ -void insert_program(goto_programt &body, goto_programt::targett pos, - const goto_programt::instructionst &prog, const replacementst &replacements); - -#endif // CPROVER_CEGIS_INVARIANT_SYMEX_VERIFY_INSERT_PROGRAM_H diff --git a/src/cegis/invariant/util/copy_instructions.cpp b/src/cegis/invariant/util/copy_instructions.cpp deleted file mode 100644 index a7ad1057fd5..00000000000 --- a/src/cegis/invariant/util/copy_instructions.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -void copy_instructionst::operator()(const goto_programt::targett &new_target, - const goto_programt::const_targett &old_target) -{ - *new_target=*old_target; - target_mapping.insert(std::make_pair(old_target, new_target)); -} - -void copy_instructionst::operator()(goto_programt::instructionst &new_instrs, - const goto_programt::instructionst &old_instrs) -{ - for(goto_programt::const_targett pos=old_instrs.begin(); - pos != old_instrs.end(); ++pos) - { - new_instrs.push_back(goto_programt::instructiont()); - operator()(std::prev(new_instrs.end()), pos); - } -} - -goto_programt::targett copy_instructionst::operator()( - goto_programt::instructionst &new_instrs, - goto_programt::targett insert_after, - const goto_programt::instructionst &old_instrs) -{ - assert(!old_instrs.empty()); - ++insert_after; - for(goto_programt::const_targett pos=old_instrs.begin(); - pos != old_instrs.end(); ++pos) - { - insert_after=new_instrs.insert(insert_after, goto_programt::instructiont()); - operator()(insert_after++, pos); - } - return std::prev(insert_after); -} - -namespace -{ -typedef std::map target_mapt; - -class fix_targetst -{ - const target_mapt &target_mapping; -public: - fix_targetst( - const std::map &target_mapping) : - target_mapping(target_mapping) - { - } - - void operator()(goto_programt::targett &target) const - { - const target_mapt::const_iterator it=target_mapping.find(target); - assert(target_mapping.end() != it); - target=it->second; - } - - void operator()( - const std::pair &entry) const - { - goto_programt::targetst &targets=entry.second->targets; - std::for_each(targets.begin(), targets.end(), *this); - } -}; -} - -void copy_instructionst::finalize() -{ - const fix_targetst fix_targets(target_mapping); - std::for_each(target_mapping.begin(), target_mapping.end(), fix_targets); - target_mapping.clear(); -} - -namespace -{ -const char DANGER_SKIP_LABEL[]="__CPROVER_danger_skip"; -} - -void copy_instructionst::finalize(const goto_programt::targett &new_target, - const goto_programt::const_targett &old_target) -{ - new_target->labels.push_back(DANGER_SKIP_LABEL); - new_target->target_number=0; - target_mapping.insert(std::make_pair(old_target, new_target)); - finalize(); -} - -namespace -{ -class skip_removert -{ - goto_programt::instructionst &instrs; - typedef std::map skipst; - skipst skips; -public: - explicit skip_removert(goto_programt::instructionst &instrs) : - instrs(instrs) - { - } - - void operator()(const goto_programt::targett &target) - { - const goto_programt::instructiont::labelst &labels=target->labels; - if(labels.empty()) return; - if(id2string(labels.front()) != DANGER_SKIP_LABEL) return; - goto_programt::targett next(target); - skips.insert(std::make_pair(target, ++next)); - } - - void operator()(goto_programt::targett first, - const goto_programt::targett &last) - { - for(; first != last; ++first) - this->operator()(first); - } - - void replace_targets(goto_programt::instructiont &instr) const - { - goto_programt::targetst &targets=instr.targets; - goto_programt::targetst::iterator it; - for(it=targets.begin(); it != targets.end(); ++it) - { - skipst::const_iterator e=skips.find(*it); - if(skips.end() == e) continue; - *it=e->second; - } - } - - void remove() - { - for(goto_programt::instructiont &instr : instrs) - replace_targets(instr); - for(const skipst::value_type &skip : skips) - instrs.erase(skip.first); - } -}; -} - -void invariant_make_presentable(goto_programt::instructionst &instrs) -{ - const goto_programt::targett &begin=instrs.begin(); - const goto_programt::targett &last=instrs.end(); - if(begin == last) return; - skip_removert op(instrs); - op(begin, std::prev(last)); - op.remove(); -} - -void copy_instructions(goto_programt::instructionst &target, - const goto_programt::instructionst &source) -{ - copy_instructionst copy; - copy(target, source); - copy.finalize(); -} - -goto_programt::targett copy_instructions(goto_programt::instructionst &target, - goto_programt::targett pos, const goto_programt::instructionst &source) -{ - copy_instructionst copy; - goto_programt::targett result=copy(target, pos, source); - copy.finalize(); - return result; -} diff --git a/src/cegis/invariant/util/copy_instructions.h b/src/cegis/invariant/util/copy_instructions.h deleted file mode 100644 index 3fcf7d5abaa..00000000000 --- a/src/cegis/invariant/util/copy_instructions.h +++ /dev/null @@ -1,116 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_UTIL_COPY_INSTRUCTIONS_H -#define CPROVER_CEGIS_INVARIANT_UTIL_COPY_INSTRUCTIONS_H - -#include - -/** - * @brief - * - * @details - */ -class copy_instructionst -{ - typedef std::map target_mapt; - target_mapt target_mapping; -public: - /** - * @brief - * - * @details - * - * @param new_target - * @param old_target - */ - void operator()(const goto_programt::targett &new_target, - const goto_programt::const_targett &old_target); - - /** - * @brief - * - * @details - * - * @param new_instrs - * @param old_instrs - */ - void operator()( - goto_programt::instructionst &new_instrs, - const goto_programt::instructionst &old_instrs); - - /** - * @brief - * - * @details - * - * @param new_instrs - * @param pos - * @param old_instrs - */ - goto_programt::targett operator()( - goto_programt::instructionst &new_instrs, - goto_programt::targett pos, - const goto_programt::instructionst &old_instrs); - - /** - * @brief - * - * @details - */ - void finalize(); - - /** - * @brief - * - * @details - * - * @param new_target - * @param old_target - */ - void finalize(const goto_programt::targett &new_target, - const goto_programt::const_targett &old_target); -}; - -/** - * @brief - * - * @details - * - * @param instrs - */ -void invariant_make_presentable(goto_programt::instructionst &instrs); - -/** - * @brief - * - * @details - * - * @param target - * @param source - */ -void copy_instructions( - goto_programt::instructionst &target, - const goto_programt::instructionst &source); - -/** - * @brief - * - * @details - * - * @param target - * @param pos - * @param source - */ -goto_programt::targett copy_instructions( - goto_programt::instructionst &target, - goto_programt::targett pos, - const goto_programt::instructionst &source); - -#endif // CPROVER_CEGIS_INVARIANT_UTIL_COPY_INSTRUCTIONS_H diff --git a/src/cegis/invariant/util/invariant_constraint_variables.cpp b/src/cegis/invariant/util/invariant_constraint_variables.cpp deleted file mode 100644 index 378362f85d8..00000000000 --- a/src/cegis/invariant/util/invariant_constraint_variables.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include - -#include -#include -#include - -namespace -{ -bool is_local(const std::string &name) -{ - return std::string::npos != name.find("::"); // XXX: Better way to do this? -} - -bool is_const(const typet &type) -{ - return type.get_bool(ID_C_constant); -} - -bool is_local_or_constant(const symbolt &symbol) -{ - if(is_local(id2string(symbol.name))) return true; - return is_const(symbol.type); -} - -bool is_meta(const irep_idt &id, const typet &type) -{ - if(ID_code == type.id()) return true; - const std::string &name=id2string(id); - if(std::string::npos != name.find(CEGIS_CONSTANT_PREFIX)) return true; - if(std::string::npos != name.find("#return_value")) return true; - return std::string::npos != name.find(CPROVER_PREFIX); -} - -class counterexample_variable_collectort -{ - invariant_symbol_set &vars; -public: - explicit counterexample_variable_collectort(invariant_symbol_set &vars) : - vars(vars) - { - } - - void operator()(const goto_programt::instructiont &instr) const - { - if(goto_program_instruction_typet::DECL != instr.type) return; - const code_declt &code_decl=to_code_decl(instr.code); - const symbol_exprt &symbol=to_symbol_expr(code_decl.symbol()); - const typet &type=symbol.type(); - if(is_const(type)) return; - if(is_meta(symbol.get_identifier(), type)) return; - vars.insert(symbol); - } - - void operator()(const std::pair &named_symbol) const - { - const symbolt &symbol=named_symbol.second; - if(is_local_or_constant(symbol) || is_meta(symbol.name, symbol.type)) - return; - vars.insert(symbol.symbol_expr()); - } -}; - -bool compare_symbol_by_id(const symbol_exprt &lhs, const symbol_exprt &rhs) -{ - return lhs.get_identifier() < rhs.get_identifier(); -} -} - -void collect_counterexample_variables(invariant_symbol_set &vars, - const invariant_programt &program) -{ - const counterexample_variable_collectort collector(vars); - const symbol_tablet &st=program.st; - std::for_each(st.symbols.begin(), st.symbols.end(), collector); - const invariant_programt::const_invariant_loopst loops(program.get_loops()); - assert(!loops.empty()); - const goto_programt::targett Ix=loops.front()->meta_variables.Ix; - std::for_each(program.invariant_range.begin, Ix, collector); -} - -void get_invariant_constraint_vars(constraint_varst &vars, - const invariant_programt &program) -{ - invariant_symbol_set smb(&compare_symbol_by_id); - collect_counterexample_variables(smb, program); - std::copy(smb.begin(), smb.end(), std::back_inserter(vars)); -} - -invariant_symbol_set create_empty_symbol_set() -{ - return invariant_symbol_set(&compare_symbol_by_id); -} diff --git a/src/cegis/invariant/util/invariant_constraint_variables.h b/src/cegis/invariant/util/invariant_constraint_variables.h deleted file mode 100644 index 93efd59da0b..00000000000 --- a/src/cegis/invariant/util/invariant_constraint_variables.h +++ /dev/null @@ -1,70 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_CONSTRAINT_VARIABLES_H -#define CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_CONSTRAINT_VARIABLES_H - -#include -#include - -#include - -/** - * @brief - * - * @details - */ -typedef bool (*symbol_comparatort)(const symbol_exprt &, const symbol_exprt &); - -/** - * @brief - * - * @details - */ -typedef std::set invariant_symbol_set; - -/** - * @brief - * - * @details - * - * @return - */ -invariant_symbol_set create_empty_symbol_set(); - -/** - * @brief - * - * @details - * - * @param vars - * @param program - */ -void collect_counterexample_variables(invariant_symbol_set &vars, - const class invariant_programt &program); - -/** - * @brief - * - * @details - */ -typedef std::deque constraint_varst; - -/** - * @brief - * - * @details - * - * @param vars - * @param program - */ -void get_invariant_constraint_vars(constraint_varst &vars, - const invariant_programt &program); - -#endif // CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_CONSTRAINT_VARIABLES_H diff --git a/src/cegis/invariant/util/invariant_program_helper.cpp b/src/cegis/invariant/util/invariant_program_helper.cpp deleted file mode 100644 index 9671613355d..00000000000 --- a/src/cegis/invariant/util/invariant_program_helper.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include - -void erase_target(goto_programt::instructionst &body, - const goto_programt::targett &target) -{ - goto_programt::targett succ=std::next(target); - assert(succ != body.end()); - - for(goto_programt::instructiont &instr : body) - for(goto_programt::targett &t : instr.targets) - if(target == t) t=succ; - - body.erase(target); -} - -void restrict_bv_size(invariant_programt &prog, const size_t width_in_bits) -{ - restrict_bv_size(prog.st, prog.gf, width_in_bits); - const invariant_programt::invariant_loopst loops(prog.get_loops()); - for(invariant_programt::invariant_loopt * const loop : loops) - restrict_bv_size(loop->guard, width_in_bits); - restrict_bv_size(prog.assertion, width_in_bits); -} diff --git a/src/cegis/invariant/util/invariant_program_helper.h b/src/cegis/invariant/util/invariant_program_helper.h deleted file mode 100644 index 1af13d90fed..00000000000 --- a/src/cegis/invariant/util/invariant_program_helper.h +++ /dev/null @@ -1,50 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_PROGRAM_HELPER_H -#define CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_PROGRAM_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param body - * @param target - */ -void erase_target(goto_programt::instructionst &body, - const goto_programt::targett &target); - -/** - * @brief - * - * @details - * - * @param prog - * @param width_in_bits - */ -void restrict_bv_size(class invariant_programt &prog, size_t width_in_bits); - -/** - * @brief - * - * @details - * - * @param prog - * @param first_loop - * @param last_loop - * @param width_in_bits - */ -template -void restrict_bv_size(invariant_programt &prog, loop_itert first_loop, - const loop_itert &last_loop, size_t width_in_bits); - -#endif // CPROVER_CEGIS_INVARIANT_UTIL_INVARIANT_PROGRAM_HELPER_H diff --git a/src/cegis/jsa/constraint/jsa_constraint_factory.cpp b/src/cegis/jsa/constraint/jsa_constraint_factory.cpp deleted file mode 100644 index 7db0d975c79..00000000000 --- a/src/cegis/jsa/constraint/jsa_constraint_factory.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -namespace -{ -symbol_exprt as_symbol(const symbol_tablet &st, const irep_idt &id) -{ - return st.lookup(id).symbol_expr(); -} - -const notequal_exprt get_base_case(const jsa_programt &prog) -{ - const irep_idt &id=get_affected_variable(*prog.base_case); - const symbol_exprt symbol(prog.st.lookup(id).symbol_expr()); - return notequal_exprt(symbol, from_integer(0, symbol.type())); -} - -void imply_true(const jsa_programt &prog, goto_programt &body, - const goto_programt::targett &pos, - const goto_program_instruction_typet instr_type) -{ - const goto_programt::targett restriction=body.insert_after(pos); - restriction->type=instr_type; - const symbol_exprt smb(as_symbol(prog.st, get_affected_variable(*pos))); - const notequal_exprt consequent(smb, from_integer(0, smb.type())); - const irep_idt &sid=get_affected_variable(*prog.inductive_assumption); - const symbol_exprt si(as_symbol(prog.st, sid)); - const equal_exprt antecedent(si, from_integer(0, si.type())); - const or_exprt safety_implication(antecedent, consequent); - restriction->guard=and_exprt(get_base_case(prog), safety_implication); - restriction->source_location=jsa_builtin_source_location(); -} - -void add_guard_goto(const jsa_programt &prog, goto_programt &body) -{ - const goto_programt::targett guard_check=body.insert_after( - std::next(prog.inductive_assumption)); - const namespacet ns(prog.st); - guard_check->type=goto_program_instruction_typet::GOTO; - guard_check->guard=simplify_expr(not_exprt(prog.guard), ns); - guard_check->targets.push_back(prog.property_entailment); - const goto_programt::targett goto_end=body.insert_after( - std::next(prog.inductive_step)); - goto_end->type=goto_program_instruction_typet::GOTO; - goto_end->targets.push_back(std::next(prog.property_entailment, 2)); - body.compute_target_numbers(); -} -} - -void insert_jsa_constraint(jsa_programt &prog, const bool use_assume) -{ - const goto_program_instruction_typet instr_type(use_assume ? ASSUME : ASSERT); - goto_programt &body=get_entry_body(prog.gf); - imply_true(prog, body, prog.inductive_step, instr_type); - imply_true(prog, body, prog.property_entailment, instr_type); - add_guard_goto(prog, body); -} diff --git a/src/cegis/jsa/constraint/jsa_constraint_factory.h b/src/cegis/jsa/constraint/jsa_constraint_factory.h deleted file mode 100644 index f5c5fe48f9c..00000000000 --- a/src/cegis/jsa/constraint/jsa_constraint_factory.h +++ /dev/null @@ -1,23 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_CONSTRAINT_JSA_CONSTRAINT_FACTORY_H -#define CPROVER_CEGIS_JSA_CONSTRAINT_JSA_CONSTRAINT_FACTORY_H - -/** - * @brief - * - * @details - * - * @param prog - * @param use_assume - */ -void insert_jsa_constraint(class jsa_programt &prog, bool use_assume); - -#endif // CPROVER_CEGIS_JSA_CONSTRAINT_JSA_CONSTRAINT_FACTORY_H diff --git a/src/cegis/jsa/converters/counterexample.cpp b/src/cegis/jsa/converters/counterexample.cpp deleted file mode 100644 index 57968fa1803..00000000000 --- a/src/cegis/jsa/converters/counterexample.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#define HEAP_VAR_SIGNIFIER "heap" -#define CONCRETE_NODES_COMP_INDEX 0 -#define ABSTRACT_NODES_COMP_INDEX 1 -#define ABSTRACT_RANGES_COMP_INDEX 2 -#define ITERATORS_COMP_INDEX 3 -#define ITERATOR_COUNT_COMP_INDEX 4 -#define LIST_HEAD_NODES_COMP_INDEX 5 -#define LIST_COUNT_COMP_INDEX 6 -#define NEXT_COMP_INDEX 0 -#define PREV_COMP_INDEX 1 -#define LIST_COMP_INDEX 2 -#define VALUE_COMP_INDEX 3 -#define MIN_COMP_INDEX 0 -#define MAX_COMP_INDEX 1 -#define SIZE_COMP_INDEX 2 -#define NODE_COMP_INDEX 0 -#define PREV_NODE_COMP_INDEX 1 -#define ITERATOR_INDEX_COMP_INDEX 2 -#define PREV_ITERATOR_INDEX_COMP_INDEX 3 -#define ITERATOR_LIST_COMP_INDEX 4 -#define NUM_ABSTRACT_HEAP_MEMBERS 7 - -namespace -{ -bool is_heap(const jsa_counterexamplet::value_type &ass) -{ - return ID_struct == ass.second.id(); -} -} - -size_t count_heaps(const jsa_counterexamplet &ce) -{ - return std::count_if(ce.begin(), ce.end(), is_heap); -} - -namespace -{ -bool compare_assignment(const jsa_counterexamplet::value_type &lhs, - const jsa_counterexamplet::value_type &rhs) -{ - return id2string(lhs.first) < id2string(rhs.first); -} - -__CPROVER_jsa_word_t to_integer(const exprt &expr) -{ - const bv_arithmetict bv(expr); - const mp_integer::llong_t value=bv.to_integer().to_long(); - return static_cast<__CPROVER_jsa_word_t >(value); -} - -void read_element(__CPROVER_jsa_word_t &e, const exprt &value) -{ - e=to_integer(value); -} - -template -void make_zero(structt &value) -{ - value={}; -} - -void read_element(__CPROVER_jsa_concrete_nodet &e, const exprt &value) -{ - if(ID_struct != value.id()) return make_zero(e); - const struct_exprt::operandst &ops=to_struct_expr(value).operands(); - assert(ops.size() > VALUE_COMP_INDEX); - e.next=to_integer(ops[NEXT_COMP_INDEX]); - e.previous=to_integer(ops[PREV_COMP_INDEX]); - e.list=to_integer(ops[LIST_COMP_INDEX]); - e.value=to_integer(ops[VALUE_COMP_INDEX]); -} - -void read_element(__CPROVER_jsa_abstract_nodet &e, const exprt &value) -{ - if(ID_struct != value.id()) return make_zero(e); - const struct_exprt::operandst &ops=to_struct_expr(value).operands(); - assert(ops.size() > VALUE_COMP_INDEX); - e.next=to_integer(ops[NEXT_COMP_INDEX]); - e.previous=to_integer(ops[PREV_COMP_INDEX]); - e.list=to_integer(ops[LIST_COMP_INDEX]); - e.value_ref=to_integer(ops[VALUE_COMP_INDEX]); -} - -void read_element(__CPROVER_jsa_abstract_ranget &e, const exprt &value) -{ - if(ID_struct != value.id()) return make_zero(e); - const struct_exprt::operandst &ops=to_struct_expr(value).operands(); - assert(ops.size() > SIZE_COMP_INDEX); - e.min=to_integer(ops[MIN_COMP_INDEX]); - e.max=to_integer(ops[MAX_COMP_INDEX]); - e.size=to_integer(ops[SIZE_COMP_INDEX]); -} - -void read_element(__CPROVER_jsa_iteratort &e, const exprt &value) -{ - if(ID_struct != value.id()) return make_zero(e); - const struct_exprt::operandst &ops=to_struct_expr(value).operands(); - assert(ops.size() > ITERATOR_LIST_COMP_INDEX); - e.node_id=to_integer(ops[NODE_COMP_INDEX]); - e.previous_node_id=to_integer(ops[PREV_NODE_COMP_INDEX]); - e.index=to_integer(ops[ITERATOR_INDEX_COMP_INDEX]); - e.previous_index=to_integer(ops[PREV_ITERATOR_INDEX_COMP_INDEX]); - e.list=to_integer(ops[ITERATOR_LIST_COMP_INDEX]); -} - -void fill_null(__CPROVER_jsa_concrete_nodet *array, size_t count) -{ - assert(__CPROVER_JSA_MAX_CONCRETE_NODES >= count); - const __CPROVER_jsa_concrete_nodet null_node={ __CPROVER_jsa_null, - __CPROVER_jsa_null, __CPROVER_jsa_null, __CPROVER_jsa_null }; - while(count < __CPROVER_JSA_MAX_CONCRETE_NODES) - array[count++]=null_node; -} - -void fill_null(__CPROVER_jsa_abstract_nodet *array, const size_t count) -{ - assert(__CPROVER_JSA_MAX_ABSTRACT_NODES >= count); - assert(count == 0); -} - -void fill_null(__CPROVER_jsa_abstract_ranget *array, const size_t count) -{ - assert(__CPROVER_JSA_MAX_ABSTRACT_RANGES >= count); - assert(count == 0); -} - -void fill_null(__CPROVER_jsa_iteratort *array, size_t count) -{ - assert(__CPROVER_JSA_MAX_ITERATORS >= count); - const __CPROVER_jsa_iteratort null_it={ __CPROVER_jsa_null, - __CPROVER_jsa_null, 0, 0, __CPROVER_jsa_null }; - while(count < __CPROVER_JSA_MAX_ITERATORS) - array[count++]=null_it; -} - -void fill_null(__CPROVER_jsa_node_id_t *array, size_t count) -{ - assert(__CPROVER_JSA_MAX_LISTS >= count); - while(count < __CPROVER_JSA_MAX_LISTS) - array[count++]=__CPROVER_jsa_null; -} - -template -void read_array(wordt *data, const exprt &value) -{ - if(ID_array != value.id()) return; - size_t index=0; - const exprt::operandst &ops=value.operands(); - for(const exprt &op : ops) - read_element(data[index++], op); - fill_null(data, ops.size()); -} - -void remove_padding(struct_exprt::operandst &ops, const typet &type) -{ - assert(!ops.empty()); - const struct_typet::componentst &comps=to_struct_type(type).components(); - assert(comps.size() == ops.size()); - for(int i=ops.size() - 1; i >= 0; --i) - if(comps[i].get_bool(ID_C_is_padding)) - ops.erase(std::next(ops.begin(), i)); -} -} - -void retrieve_heaps(const jsa_counterexamplet &ce, - __CPROVER_jsa_abstract_heapt *heaps) -{ - assert(std::is_sorted(ce.begin(), ce.end(), compare_assignment)); - size_t index=0; - for(const jsa_counterexamplet::value_type &assignment : ce) - if(is_heap(assignment)) - { - const struct_exprt &value=to_struct_expr(assignment.second); - __CPROVER_jsa_abstract_heapt &heap=heaps[index++]; - struct_exprt::operandst ops(value.operands()); - remove_padding(ops, value.type()); - assert(NUM_ABSTRACT_HEAP_MEMBERS == ops.size()); - read_array(heap.concrete_nodes, ops[CONCRETE_NODES_COMP_INDEX]); - read_array(heap.abstract_nodes, ops[ABSTRACT_NODES_COMP_INDEX]); - read_array(heap.abstract_ranges, ops[ABSTRACT_RANGES_COMP_INDEX]); - read_array(heap.iterators, ops[ITERATORS_COMP_INDEX]); - heap.iterator_count=to_integer(ops[ITERATOR_COUNT_COMP_INDEX]); - read_array(heap.list_head_nodes, ops[LIST_HEAD_NODES_COMP_INDEX]); - heap.list_count=to_integer(ops[LIST_COUNT_COMP_INDEX]); - } -} - -namespace -{ -bool is_word(const jsa_counterexamplet::value_type &assignment) -{ - return !is_heap(assignment); -} -} - -size_t count_words(const jsa_counterexamplet &ce) -{ - return std::count_if(ce.begin(), ce.end(), is_word); -} - -void retrieve_words(const jsa_counterexamplet &ce, __CPROVER_jsa_word_t *words) -{ - assert(std::is_sorted(ce.begin(), ce.end(), compare_assignment)); - size_t index=0; - for(const jsa_counterexamplet::value_type &assignment : ce) - if(is_word(assignment)) words[index++]=to_integer(assignment.second); -} diff --git a/src/cegis/jsa/converters/counterexample.h b/src/cegis/jsa/converters/counterexample.h deleted file mode 100644 index 42a4e6fb13d..00000000000 --- a/src/cegis/jsa/converters/counterexample.h +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_CONVERTERS_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_JSA_CONVERTERS_COUNTEREXAMPLE_H - -#include -#include - -/** - * @brief - * - * @details - * - * @param counterexample - * - * @return - */ -size_t count_heaps(const jsa_counterexamplet &counterexample); - -/** - * @brief - * - * @details - * - * @param counterexample - * @param heaps - * - * @return - */ -void retrieve_heaps( - const jsa_counterexamplet &counterexample, - __CPROVER_jsa_abstract_heapt *heaps); - -/** - * @brief - * - * @details - * - * @param counterexample - * - * @return - */ -size_t count_words(const jsa_counterexamplet &counterexample); - -/** - * @brief - * - * @details - * - * @param counterexample - * @param words - * - * @return - */ -void retrieve_words( - const jsa_counterexamplet &counterexample, - __CPROVER_jsa_word_t *words); - -#endif // CPROVER_CEGIS_JSA_CONVERTERS_COUNTEREXAMPLE_H diff --git a/src/cegis/jsa/converters/replace_operators.cpp b/src/cegis/jsa/converters/replace_operators.cpp deleted file mode 100644 index 567811120a2..00000000000 --- a/src/cegis/jsa/converters/replace_operators.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#define INSTR "instr" -#define OPCODE "opcode" -#define ROP "result_op" -#define OP0 "op0" -#define OP1 "op1" -#define LOCAL_HEAP "heap" -#define LOCAL_LIST "list" -#define LOCAL_IT "it" - -namespace -{ -bool is_instr_name(const std::string &name) -{ - return std::string::npos != name.find(JSA_PRED_EXEC) - && std::string::npos != name.find(INSTR); -} - -class replace_pred_ops_visitort: public expr_visitort -{ - const __CPROVER_jsa_pred_instructiont &instr; -public: - explicit replace_pred_ops_visitort( - const __CPROVER_jsa_pred_instructiont &instr):instr(instr) - { - } - - virtual void operator()(exprt &expr) - { - if(ID_typecast != expr.id()) return; - const typecast_exprt &cast=to_typecast_expr(expr); - const exprt &cast_op=cast.op(); - if(ID_member != cast_op.id()) return; - const member_exprt &member=to_member_expr(cast_op); - const exprt &compound=member.compound(); - if(ID_symbol != compound.id()) return; - const irep_idt &compound_id=to_symbol_expr(compound).get_identifier(); - if(!is_instr_name(id2string(compound_id))) return; - const std::string &component=id2string(member.get_component_name()); - const typet &type=cast.type(); - if(ROP == component) expr=from_integer(instr.result_op, type); - else if(OP0 == component) expr=from_integer(instr.op0, type); - else if(OP1 == component) expr=from_integer(instr.op1, type); - else assert(!"Illegal compound member"); - } -}; -} - -void replace_pred_ops(goto_programt::targett first, - const goto_programt::const_targett &last, - const __CPROVER_jsa_pred_instructiont &instr) -{ - replace_pred_ops_visitort visitor(instr); - for(; first != last; ++first) - { - first->guard.visit(visitor); - first->code.visit(visitor); - } -} - -namespace -{ -class replace_query_ops_visitort: public expr_visitort -{ - const symbol_tablet &st; - const __CPROVER_jsa_query_instructiont &instr; - const __CPROVER_jsa_query_instructiont &prefix; - std::vector heap_occurrences; -public: - replace_query_ops_visitort(const symbol_tablet &st, - const __CPROVER_jsa_query_instructiont &instr, - const __CPROVER_jsa_query_instructiont &prefix) : - st(st), instr(instr), prefix(prefix) - { - } - - ~replace_query_ops_visitort() - { - for(exprt * const expr : heap_occurrences) - *expr=address_of_exprt(get_queried_heap(st)); - } - - void handle_member(member_exprt &member_expr) - { - const exprt &compound=member_expr.compound(); - if(ID_symbol != compound.id()) return; - const std::string &id=id2string(to_symbol_expr(compound).get_identifier()); - if(std::string::npos == id.find(INSTR)) return; - const std::string &member=id2string(member_expr.get_component_name()); - exprt &expr=static_cast(member_expr); - if(OP0 == member) expr=from_integer(instr.op0, expr.type()); - else if(OP1 == member) expr=from_integer(instr.op1, expr.type()); - else if(OPCODE == member) expr=from_integer(instr.opcode, expr.type()); - else assert(!"Illegal compound member"); - } - - virtual void operator()(exprt &expr) - { - const irep_idt &expr_id=expr.id(); - if(ID_member == expr_id) return handle_member(to_member_expr(expr)); - if(ID_symbol != expr_id) return; - const std::string &id=id2string(to_symbol_expr(expr).get_identifier()); - if(std::string::npos != id.find(LOCAL_HEAP)) heap_occurrences.push_back( - &expr); - else if(std::string::npos != id.find(LOCAL_LIST)) expr=from_integer( - prefix.opcode, expr.type()); - else if(std::string::npos != id.find(LOCAL_IT)) - expr=from_integer(prefix.op0, expr.type()); - } -}; -} - -void replace_query_ops(const symbol_tablet &st, goto_programt::targett first, - const goto_programt::const_targett &last, - const __CPROVER_jsa_query_instructiont &instr, - const __CPROVER_jsa_query_instructiont &prefix) -{ - replace_query_ops_visitort visitor(st, instr, prefix); - for(; first != last; ++first) - { - first->guard.visit(visitor); - first->code.visit(visitor); - } -} diff --git a/src/cegis/jsa/converters/replace_operators.h b/src/cegis/jsa/converters/replace_operators.h deleted file mode 100644 index 00ba51b4f29..00000000000 --- a/src/cegis/jsa/converters/replace_operators.h +++ /dev/null @@ -1,49 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_CONVERTERS_REPLACE_OPERATORS_H -#define CPROVER_CEGIS_JSA_CONVERTERS_REPLACE_OPERATORS_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param first - * @param last - * @param instr - */ -void replace_pred_ops( - goto_programt::targett first, - const goto_programt::const_targett &last, - const __CPROVER_jsa_pred_instructiont &instr); - -/** - * @brief - * - * @details - * - * @param st - * @param first - * @param last - * @param instr - * @param prefix - */ -void replace_query_ops( - const class symbol_tablet &st, - goto_programt::targett first, - const goto_programt::const_targett &last, - const __CPROVER_jsa_query_instructiont &instr, - const __CPROVER_jsa_query_instructiont &prefix); - -#endif // CPROVER_CEGIS_JSA_CONVERTERS_REPLACE_OPERATORS_H diff --git a/src/cegis/jsa/converters/solution.cpp b/src/cegis/jsa/converters/solution.cpp deleted file mode 100644 index 451b33d1bc2..00000000000 --- a/src/cegis/jsa/converters/solution.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include - -jsa_solutiont convert(const jsa_genetic_solutiont &solution, - const jsa_programt &prog) -{ - jsa_solutiont result; - for(const jsa_genetic_solutiont::predicatest::value_type &pred : solution.predicates) - { - result.predicates.push_back(goto_programt::instructionst()); - convert(result.predicates.back(), prog, pred); - } - convert(result.query, prog, solution.query); - convert(result.invariant, prog, solution.invariant); - return result; -} diff --git a/src/cegis/jsa/converters/solution.h b/src/cegis/jsa/converters/solution.h deleted file mode 100644 index d262f415477..00000000000 --- a/src/cegis/jsa/converters/solution.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#ifndef CPROVER_CEGIS_JSA_CONVERTERS_SOLUTION_H -#define CPROVER_CEGIS_JSA_CONVERTERS_SOLUTION_H - -// TODO: Convert genetic solution to irep / irep to genetic solution - -/** - * @brief - * - * @details - * - * @param solution - * @param prog - * @return - */ -jsa_solutiont convert( - const class jsa_genetic_solutiont &solution, - const class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_CONVERTERS_SOLUTION_H diff --git a/src/cegis/jsa/converters/translate_to_goto_program.cpp b/src/cegis/jsa/converters/translate_to_goto_program.cpp deleted file mode 100644 index 53ee9ecfe56..00000000000 --- a/src/cegis/jsa/converters/translate_to_goto_program.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PRED_SINGLE JSA_PREFIX "pred_opcode_" -#define PRED_FIRST JSA_PREFIX "pred_opcode_first_" -#define PRED_LAST JSA_PREFIX "pred_opcode_last_" -#define QUERY_SINGLE JSA_PREFIX "query_opcode_" -#define QUERY_FIRST JSA_PREFIX "query_opcode_first_" -#define QUERY_LAST JSA_PREFIX "query_opcode_last_" - -namespace -{ -instruction_sett get_instruction_set(const goto_functionst &gf, - const char * const func, const char * const first, - const char * const last, const char * const single) -{ - return extract_instruction_set(get_body(gf, func), first, last, single); -} - -instruction_sett get_pred_instruction_set(const goto_functionst &gf) -{ - return get_instruction_set(gf, JSA_PRED_EXEC, PRED_FIRST, PRED_LAST, PRED_SINGLE); -} - -instruction_sett get_query_instruction_set(const goto_functionst &gf) -{ - return get_instruction_set(gf, JSA_QUERY_EXEC, QUERY_FIRST, QUERY_LAST, QUERY_SINGLE); -} -} - -void convert(goto_programt::instructionst &result, const jsa_programt &prog, - const std::vector<__CPROVER_jsa_pred_instructiont> &solution) -{ - const instruction_sett instr_set(get_pred_instruction_set(prog.gf)); - assert(__CPROVER_JSA_NUM_PRED_INSTRUCTIONS == instr_set.size()); - copy_instructionst copy; - for(const __CPROVER_jsa_pred_instructiont &instr : solution) - { - const instruction_sett::const_iterator it=instr_set.find(instr.opcode); - assert(instr_set.end() != it); - const size_t previous_size=result.size(); - copy(result, it->second); - const goto_programt::targett new_instr(std::next(result.begin(), previous_size)); - replace_pred_ops(new_instr, result.end(), instr); - } - copy.finalize(); -} - -void convert(goto_programt::instructionst &result, const jsa_programt &prog, - const std::vector<__CPROVER_jsa_query_instructiont> &solution) -{ - const instruction_sett instr_set(get_query_instruction_set(prog.gf)); - assert(!instr_set.empty()); - assert(!solution.empty()); - std::vector<__CPROVER_jsa_query_instructiont>::const_iterator instr=solution.begin(); - const __CPROVER_jsa_query_instructiont &prefix=*instr++; - copy_instructionst copy; - for(; instr != solution.end(); ++instr) - { - const instruction_sett::const_iterator it=instr_set.begin(); - const size_t previous_size=result.size(); - copy(result, it->second); - const goto_programt::targett new_instr(std::next(result.begin(), previous_size)); - replace_query_ops(prog.st, new_instr, result.end(), *instr, prefix); - } - copy.finalize(); -} - -void convert(goto_programt::instructionst &result, const jsa_programt &prog, - const std::vector<__CPROVER_jsa_invariant_instructiont> &solution) -{ - assert(!solution.empty()); - assert(solution.front().opcode == 0); - result.push_back(goto_programt::instructiont()); - goto_programt::instructiont &instr=result.back(); - instr.source_location=jsa_builtin_source_location(); - instr.type=goto_program_instruction_typet::FUNCTION_CALL; - code_function_callt call; - call.function()=prog.st.lookup(JSA_INV_VERIFY_EXEC).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - args.push_back(address_of_exprt(get_user_heap(prog.gf))); - args.push_back(address_of_exprt(get_queried_heap(prog.st))); - instr.code=call; -} diff --git a/src/cegis/jsa/converters/translate_to_goto_program.h b/src/cegis/jsa/converters/translate_to_goto_program.h deleted file mode 100644 index bac64b05b73..00000000000 --- a/src/cegis/jsa/converters/translate_to_goto_program.h +++ /dev/null @@ -1,59 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_CONVERTERS_TRANSLATE_TO_GOTO_PROGRAM_H -#define CPROVER_CEGIS_JSA_CONVERTERS_TRANSLATE_TO_GOTO_PROGRAM_H - -#include -#include - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param solution - * @return - */ -void convert( - goto_programt::instructionst &result, - const class jsa_programt &prog, - const std::vector<__CPROVER_jsa_pred_instructiont> &solution); - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param solution - */ -void convert( - goto_programt::instructionst &result, - const jsa_programt &prog, - const std::vector<__CPROVER_jsa_query_instructiont> &solution); - -/** - * @brief - * - * @details - * - * @param result - * @param prog - * @param solution - */ -void convert( - goto_programt::instructionst &result, - const jsa_programt &prog, - const std::vector<__CPROVER_jsa_invariant_instructiont> &solution); - -#endif // CPROVER_CEGIS_JSA_CONVERTERS_TRANSLATE_TO_GOTO_PROGRAM_H diff --git a/src/cegis/jsa/facade/jsa_runner.cpp b/src/cegis/jsa/facade/jsa_runner.cpp deleted file mode 100644 index 19f88ff236e..00000000000 --- a/src/cegis/jsa/facade/jsa_runner.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -typedef messaget::mstreamt mstreamt; - -std::function get_default_solution( - const jsa_programt &prog) -{ - return [&prog](jsa_solutiont &solution) - { if(solution.invariant.empty()) solution=default_jsa_solution(prog);}; -} - -template -int run_with_ga(const symbol_tablet &st, const optionst &o, mstreamt &result, - jsa_symex_learnt &l, oraclet &oracle, prept &prep) -{ - jsa_source_providert source_provider(l); - dynamic_jsa_test_runnert test_runner(std::ref(source_provider)); - typedef lazy_fitnesst fitnesst; - fitnesst fitness(test_runner); - typedef match_selectt selectt; - const selectt::test_case_datat &test_case_data=fitness.get_test_case_data(); - const size_t rounds=o.get_unsigned_int_option(CEGIS_ROUNDS); - const selectt select(test_case_data, rounds); - jsa_randomt rnd(st, l.get_pred_ops_count(), l.get_const_pred_ops_count()); - const random_jsa_mutatet mutate(rnd); - const random_jsa_crosst cross(rnd); - const jsa_genetic_convertt convert(l); - ga_learnt ga(o, rnd, select, mutate, cross, fitness, convert); - const jsa_serialisert serialiser(l.get_jsa_program()); - const size_t num_sym=o.get_unsigned_int_option(CEGIS_SYMEX_HEAD_START); - const jsa_paragon_wrappert paragon_wrapper(l); - typedef cegis_symex_learnt symex_learnt; - symex_learnt symex_learn(o, prep, paragon_wrapper); - concurrent_learnt learn(ga, - symex_learn, - serialiser, - num_sym); - learn_preprocess_seedt seed(o, l); - return run_cegis_with_statistics_wrapper(result, o, learn, oracle, prep, seed); -} -} - -int run_jsa(optionst &o, mstreamt &result, const symbol_tablet &st, - const goto_functionst &gf) -{ - jsa_preprocessingt prep(o, st, gf); - const jsa_programt &prog=prep.get_jsa_program(); - jsa_symex_learnt lcfg(prog); - cegis_symex_learnt learn(o, prep, lcfg, get_default_solution(prog)); - jsa_symex_verifyt vcfg(prog); - cegis_symex_verifyt oracle(o, vcfg); - if(o.get_bool_option(CEGIS_GENETIC)) - return run_with_ga(st, o, result, lcfg, oracle, prep); - else - return run_cegis_with_statistics_wrapper(result, o, learn, oracle, prep); -} diff --git a/src/cegis/jsa/facade/jsa_runner.h b/src/cegis/jsa/facade/jsa_runner.h deleted file mode 100644 index 66e1e62456f..00000000000 --- a/src/cegis/jsa/facade/jsa_runner.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_FACADE_JSA_RUNNER_H -#define CPROVER_CEGIS_JSA_FACADE_JSA_RUNNER_H - -#include - -/** - * @brief - * - * @details - * - * @param options - * @param result - * @param st - * @param gf - * - * @return - */ -int run_jsa(class optionst &options, messaget::mstreamt &result, - const class symbol_tablet &st, const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_JSA_FACADE_JSA_RUNNER_H diff --git a/src/cegis/jsa/genetic/dynamic_jsa_test_runner.cpp b/src/cegis/jsa/genetic/dynamic_jsa_test_runner.cpp deleted file mode 100644 index 542fbed9922..00000000000 --- a/src/cegis/jsa/genetic/dynamic_jsa_test_runner.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include - -dynamic_jsa_test_runnert::dynamic_jsa_test_runnert( - const std::function &source_code_provider) : - source_code(source_code_provider), shared_library(LIBRARY_PREFIX, - LIBRARY_SUFFIX), handle(0), fitness_tester(0) -{ -} - -dynamic_jsa_test_runnert::~dynamic_jsa_test_runnert() -{ - close_fitness_tester_library(handle, fitness_tester); -} - -std::string get_compile_options() -{ - std::string path("-I "); - const std::string exe(get_current_executable_file_path()); - path+=exe.substr(0, exe.rfind("cegis", exe.rfind("cegis") - 1) - 1); - return path+=' '; -} - -void dynamic_jsa_test_runnert::run_test(individualt &individual, - const counterexamplet &counterexample, - const std::function on_complete) -{ - const std::string lib(shared_library()); - const std::string opt(get_compile_options()); - prepare_fitness_tester_library(handle, fitness_tester, source_code, lib, opt); - - const individualt::queryt &query=individual.query; - const std::size_t jsa_query_size=query.size(); - std::vector<__CPROVER_jsa_query_instructiont> jsa_query; - jsa_query.resize(jsa_query_size); - size_t index=0; - for(const individualt::queryt::value_type &instr : query) - jsa_query[index++]=instr; - - const individualt::invariantt &invariant=individual.invariant; - const __CPROVER_jsa_index_t jsa_invariant_size=__CPROVER_jsa_index_t(invariant.size()); - std::vector<__CPROVER_jsa_invariant_instructiont> jsa_invariant; - jsa_invariant.resize(jsa_invariant_size); - index=0; - for(const individualt::invariantt::value_type &instr : invariant) - jsa_invariant[index++]=instr; - - const individualt::predicatest &preds=individual.predicates; - const size_t num_preds=preds.size(); - std::vector<__CPROVER_jsa_index_t> jsa_predicate_sizes; - jsa_predicate_sizes.reserve(num_preds); - std::vector > jsa_predicates; - jsa_predicates.reserve(num_preds); - std::vector jsa_predicates_arg; - for(const individualt::predicatet &pred : preds) - { - jsa_predicates.push_back(decltype(jsa_predicates)::value_type()); - for(const individualt::predicatet::value_type &instr : pred) - jsa_predicates.back().push_back(instr); - - jsa_predicates_arg.push_back(jsa_predicates.back().data()); - jsa_predicate_sizes.push_back(__CPROVER_jsa_index_t(pred.size())); - } - - const std::size_t num_heaps=count_heaps(counterexample); - std::vector<__CPROVER_jsa_abstract_heapt> heaps; - heaps.resize(num_heaps); - retrieve_heaps(counterexample, heaps.data()); - - const std::size_t num_words=count_words(counterexample); - std::vector<__CPROVER_jsa_word_t> words; - words.resize(num_words); - retrieve_words(counterexample, words.data()); - - on_complete(EXIT_SUCCESS == fitness_tester( - jsa_query_size, jsa_query.data(), - jsa_invariant_size, - jsa_invariant.data(), - jsa_predicate_sizes.data(), - jsa_predicates_arg.data(), - heaps.data(), - words.data())); -} - -void dynamic_jsa_test_runnert::join() -{ -} diff --git a/src/cegis/jsa/genetic/dynamic_jsa_test_runner.h b/src/cegis/jsa/genetic/dynamic_jsa_test_runner.h deleted file mode 100644 index 8990800a90b..00000000000 --- a/src/cegis/jsa/genetic/dynamic_jsa_test_runner.h +++ /dev/null @@ -1,85 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_DYNAMIC_JSA_TEST_RUNNER_H -#define CPROVER_CEGIS_JSA_GENETIC_DYNAMIC_JSA_TEST_RUNNER_H - -#include - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class dynamic_jsa_test_runnert -{ - typedef void *lib_handlet; -public: - typedef jsa_counterexamplet counterexamplet; - typedef class jsa_genetic_solutiont individualt; -private: - typedef int (*fitness_testert)( - const __CPROVER_jsa_index_t __CPROVER_jsa_query_size, - const __CPROVER_jsa_query_instructiont *__CPROVER_jsa_query, - const __CPROVER_jsa_index_t __CPROVER_jsa_invariant_size, - const __CPROVER_jsa_invariant_instructiont *__CPROVER_jsa_invariant, - const __CPROVER_jsa_index_t *__CPROVER_jsa_predicate_sizes, - const __CPROVER_jsa_pred_instructiont **__CPROVER_jsa_predicates, - const __CPROVER_jsa_abstract_heapt *__CPROVER_jsa_counterexample_heaps, - const __CPROVER_jsa_word_t *__CPROVER_jsa_counterexample_words); - const std::function source_code; - const temporary_filet shared_library; - lib_handlet handle; - fitness_testert fitness_tester; -public: - /** - * @brief - * - * @details - * - * @param source_code_provider - */ - explicit dynamic_jsa_test_runnert( - const std::function &source_code_provider); - - /** - * @brief - * - * @details - */ - ~dynamic_jsa_test_runnert(); - - /** - * @brief - * - * @details - * - * @param individual - * @param counterexample - * @param on_complete - */ - void run_test( - individualt &individual, - const counterexamplet &counterexample, - std::function on_complete); - - /** - * @brief - * - * @details - */ - void join(); -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_DYNAMIC_JSA_TEST_RUNNER_H diff --git a/src/cegis/jsa/genetic/jsa_genetic_convert.cpp b/src/cegis/jsa/genetic/jsa_genetic_convert.cpp deleted file mode 100644 index 4729430f2b3..00000000000 --- a/src/cegis/jsa/genetic/jsa_genetic_convert.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -jsa_genetic_convertt::jsa_genetic_convertt(const jsa_symex_learnt &learn) : - learn(learn) -{ -} - -void jsa_genetic_convertt::convert(candidatet &candidate, - const individualt &individual) const -{ - candidate=::convert(individual, learn.get_jsa_program()); -} - -void jsa_genetic_convertt::show(messaget::mstreamt &os, - const candidatet &candidate) const -{ - learn.show_candidate(os, candidate); -} diff --git a/src/cegis/jsa/genetic/jsa_genetic_convert.h b/src/cegis/jsa/genetic/jsa_genetic_convert.h deleted file mode 100644 index 45271ffeb87..00000000000 --- a/src/cegis/jsa/genetic/jsa_genetic_convert.h +++ /dev/null @@ -1,57 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_JSA_GENETIC_CONVERT_H -#define CPROVER_CEGIS_JSA_GENETIC_JSA_GENETIC_CONVERT_H - -#include - -/** - * @brief - * - * @details - */ -class jsa_genetic_convertt -{ - const class jsa_symex_learnt &learn; -public: - typedef class jsa_solutiont candidatet; - typedef class jsa_genetic_solutiont individualt; - - /** - * @brief - * - * @details - * - * @param learn - */ - explicit jsa_genetic_convertt(const jsa_symex_learnt &learn); - - /** - * @brief - * - * @details - * - * @param candidate - * @param individual - */ - void convert(candidatet &candidate, const individualt &individual) const; - - /** - * @brief - * - * @details - * - * @param candidate - * @param os - */ - void show(messaget::mstreamt &os, const candidatet &candidate) const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_JSA_GENETIC_CONVERT_H diff --git a/src/cegis/jsa/genetic/jsa_paragon_wrapper.cpp b/src/cegis/jsa/genetic/jsa_paragon_wrapper.cpp deleted file mode 100644 index f682bb1e455..00000000000 --- a/src/cegis/jsa/genetic/jsa_paragon_wrapper.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include - -jsa_paragon_wrappert::jsa_paragon_wrappert(jsa_symex_learnt &wrapped) : - wrapped(wrapped) -{ -} - -void jsa_paragon_wrappert::process(const counterexamplest &counterexamples, - const size_t max_solution_size) const -{ - wrapped.process(counterexamples, max_solution_size); -} - -void jsa_paragon_wrappert::process(const size_t max_solution_size) const -{ - wrapped.process(max_solution_size); -} - -void jsa_paragon_wrappert::set_word_width(const size_t word_width_in_bits) const -{ - wrapped.set_word_width(word_width_in_bits); -} - -void jsa_paragon_wrappert::convert(candidatet ¤t_candidate, - const goto_tracet &trace, const size_t max_solution_size) const -{ - const jsa_programt &prog=wrapped.get_jsa_program(); - extract_jsa_genetic_candidate(current_candidate, prog, trace); - current_candidate.fitness=0; -} - -const symbol_tablet &jsa_paragon_wrappert::get_symbol_table() const -{ - return wrapped.get_symbol_table(); -} - -const goto_functionst &jsa_paragon_wrappert::get_goto_functions() const -{ - return wrapped.get_goto_functions(); -} - -void jsa_paragon_wrappert::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) const -{ - const jsa_programt &prog=wrapped.get_jsa_program(); - wrapped.show_candidate(os, ::convert(candidate, prog)); -} diff --git a/src/cegis/jsa/genetic/jsa_paragon_wrapper.h b/src/cegis/jsa/genetic/jsa_paragon_wrapper.h deleted file mode 100644 index f5094398b20..00000000000 --- a/src/cegis/jsa/genetic/jsa_paragon_wrapper.h +++ /dev/null @@ -1,113 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_JSA_PARAGON_WRAPPER_H -#define CPROVER_CEGIS_JSA_GENETIC_JSA_PARAGON_WRAPPER_H - -#include -#include - -/** - * @brief - * - * @details - */ -class jsa_paragon_wrappert -{ - class jsa_symex_learnt &wrapped; -public: - typedef jsa_counterexamplet counterexamplet; - typedef jsa_counterexamplest counterexamplest; - typedef jsa_genetic_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param wrapped - */ - explicit jsa_paragon_wrappert(jsa_symex_learnt &wrapped); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process( - const counterexamplest &counterexamples, - size_t max_solution_size) const; - - /** - * @brief - * - * @details - * - * @param max_solution_size - */ - void process(size_t max_solution_size) const; - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits) const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert( - candidatet ¤t_candidate, - const class goto_tracet &trace, - size_t max_solution_size) const; - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate( - messaget::mstreamt &os, - const candidatet &candidate) const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_JSA_PARAGON_WRAPPER_H diff --git a/src/cegis/jsa/genetic/jsa_random.cpp b/src/cegis/jsa/genetic/jsa_random.cpp deleted file mode 100644 index 7c3457fb606..00000000000 --- a/src/cegis/jsa/genetic/jsa_random.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -jsa_randomt::jsa_randomt(const symbol_tablet &st, - std::function pred_ops_count, - std::function const_pred_ops_count) : - st(st), pred_ops_count(pred_ops_count), const_pred_ops_count( - const_pred_ops_count) -{ -} - -void jsa_randomt::havoc(jsa_genetic_solutiont &individual) const -{ - individual.fitness=0; - havoc(individual.invariant); - havoc(individual.predicates); - havoc(individual.query); -} - -namespace -{ -template -void havoc_size(containert &container, const size_t max, const size_t min=1u) -{ - const size_t size=rand() % (max + 1); - container.resize(std::max(min, size)); -} -} - -void jsa_randomt::havoc(jsa_genetic_solutiont::predicatest &predicates) const -{ - predicates.resize(get_num_jsa_preds(st)); - for(jsa_genetic_solutiont::predicatet &predicate : predicates) - havoc(predicate); -} - -void jsa_randomt::havoc(jsa_genetic_solutiont::predicatet &predicate) const -{ - havoc_size(predicate, get_max_pred_size(st)); - for(jsa_genetic_solutiont::predicatet::value_type &instr : predicate) - havoc(instr); -} - -void jsa_randomt::havoc( - jsa_genetic_solutiont::predicatet::value_type &instr) const -{ - instr.opcode=rand() % get_pred_instruction_set_size(); - instr.op0=rand() % const_pred_ops_count(); - instr.op1=rand() % const_pred_ops_count(); - instr.result_op=rand() % pred_ops_count(); -} - -void jsa_randomt::havoc(jsa_genetic_solutiont::invariantt &invariant) const -{ - invariant.resize(get_max_inv_size()); - for(jsa_genetic_solutiont::invariantt::value_type &instr : invariant) - havoc(instr); -} - -void jsa_randomt::havoc( - jsa_genetic_solutiont::invariantt::value_type &instr) const -{ - instr.opcode=rand() % get_invariant_instruction_set_size(); -} - -#define MIN_QUERY_SIZE 2u - -void jsa_randomt::havoc(jsa_genetic_solutiont::queryt &query) const -{ - havoc_size(query, get_max_query_size(st), MIN_QUERY_SIZE); - for(size_t i=0; i < query.size(); ++i) - havoc(query[i], i); -} - -#define QUERY_PREFIX_OP1_VALUE 0u - -void jsa_randomt::havoc(jsa_genetic_solutiont::queryt::value_type &instr, - const size_t index) const -{ - if(index == 0) - { - havoc_list(instr.opcode); - havoc_iterator(instr.op0); - instr.op1=QUERY_PREFIX_OP1_VALUE; - } else - { - instr.opcode=rand() % get_query_instruction_set_size(); - havoc_pred(instr.op0); - switch(instr.opcode) - { - case __CPROVER_jsa_query_idt::FILTER: - instr.op1=__CPROVER_jsa_null; - break; - case __CPROVER_jsa_query_idt::MAP_IN_PLACE: - instr.op1=__CPROVER_jsa_null; - break; - default: - havoc_list(instr.op1); - } - } -} - -unsigned int jsa_randomt::rand() const -{ - return ::rand(); -} - -void jsa_randomt::havoc_iterator(__CPROVER_jsa_opt &it) const -{ - it=rand() % get_max_iterators(st); -} - -void jsa_randomt::havoc_list(__CPROVER_jsa_opt &list) const -{ - list=rand() % get_max_lists(st); -} - -void jsa_randomt::havoc_pred(__CPROVER_jsa_opt &pred) const -{ - pred=rand() % get_num_jsa_preds(st); -} diff --git a/src/cegis/jsa/genetic/jsa_random.h b/src/cegis/jsa/genetic/jsa_random.h deleted file mode 100644 index 3bd1921bb9d..00000000000 --- a/src/cegis/jsa/genetic/jsa_random.h +++ /dev/null @@ -1,153 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_JSA_RANDOM_H -#define CPROVER_CEGIS_JSA_GENETIC_JSA_RANDOM_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class jsa_randomt -{ - const class symbol_tablet &st; - const std::function pred_ops_count; - const std::function const_pred_ops_count; -public: - /** - * @brief - * - * @details - * - * @param st - * @param pred_ops_count - * @param const_pred_ops_count - */ - jsa_randomt(const symbol_tablet &st, - std::function pred_ops_count, - std::function const_pred_ops_count); - - /** - * @brief - * - * @details - * - * @param individual - */ - void havoc(jsa_genetic_solutiont &individual) const; - - /** - * @brief - * - * @details - * - * @param predicates - */ - void havoc(jsa_genetic_solutiont::predicatest &predicates) const; - - /** - * @brief - * - * @details - * - * @param predicate - */ - void havoc(jsa_genetic_solutiont::predicatet &predicate) const; - - /** - * @brief - * - * @details - * - * @param instr - */ - void havoc(jsa_genetic_solutiont::predicatet::value_type &instr) const; - - /** - * @brief - * - * @details - * - * @param invariant - */ - void havoc(jsa_genetic_solutiont::invariantt &invariant) const; - - /** - * @brief - * - * @details - * - * @param instr - */ - void havoc(jsa_genetic_solutiont::invariantt::value_type &instr) const; - - /** - * @brief - * - * @details - * - * @param query - */ - void havoc(jsa_genetic_solutiont::queryt &query) const; - - /** - * @brief - * - * @details - * - * @param instr - * @param index - */ - void havoc( - jsa_genetic_solutiont::queryt::value_type &instr, - size_t index) const; - - /** - * @brief - * - * @details - * - * @return - */ - void havoc_iterator(__CPROVER_jsa_opt &it) const; - - /** - * @brief - * - * @details - * - * @return - */ - void havoc_list(__CPROVER_jsa_opt &list) const; - - /** - * @brief - * - * @details - * - * @return - */ - void havoc_pred(__CPROVER_jsa_opt &pred) const; - - /** - * @brief - * - * @details - * - * @return - */ - unsigned int rand() const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_JSA_RANDOM_H diff --git a/src/cegis/jsa/genetic/jsa_serialiser.cpp b/src/cegis/jsa/genetic/jsa_serialiser.cpp deleted file mode 100644 index 10aedd39268..00000000000 --- a/src/cegis/jsa/genetic/jsa_serialiser.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -jsa_serialisert::jsa_serialisert(const jsa_programt &prog) : - prog(prog) -{ -} - -#define FITNESS "fitness" -#define OP0 "op0" -#define OP1 "op1" -#define RESULT_OP "result_op" -#define OPCODE "opcode" -#define INVARIANT "invariant" -#define PREDICATES "predicates" -#define QUERY "query" - -void jsa_serialisert::operator()(irept &sdu, - const jsa_genetic_solutiont &entity) const -{ - sdu.set(FITNESS, entity.fitness); - irept invariant; - irept::subt &invariant_instructions=invariant.get_sub(); - for(const jsa_genetic_solutiont::invariantt::value_type &instr : entity.invariant) - { - irept instruction; - instruction.set(OPCODE, instr.opcode); - invariant_instructions.push_back(instruction); - } - sdu.set(INVARIANT, invariant); - irept predicates; - irept::subt &predicates_list=predicates.get_sub(); - for(const jsa_genetic_solutiont::predicatet &predicate : entity.predicates) - { - irept pred; - irept::subt &predicate_instructions=pred.get_sub(); - for(const jsa_genetic_solutiont::predicatet::value_type &instr : predicate) - { - irept instruction; - instruction.set(OPCODE, instr.opcode); - instruction.set(OP0, instr.op0); - instruction.set(OP1, instr.op1); - instruction.set(RESULT_OP, instr.result_op); - predicate_instructions.push_back(instruction); - } - predicates_list.push_back(pred); - } - sdu.set(PREDICATES, predicates); - irept query; - irept::subt &query_instructions=query.get_sub(); - for(const jsa_genetic_solutiont::queryt::value_type &instr : entity.query) - { - irept instruction; - instruction.set(OPCODE, instr.opcode); - instruction.set(OP0, instr.op0); - instruction.set(OP1, instr.op1); - query_instructions.push_back(instruction); - } - sdu.set(QUERY, query); -} - -void jsa_serialisert::operator()(jsa_genetic_solutiont &entity, - const irept &sdu) const -{ - entity.fitness=jsa_genetic_solutiont::fitnesst(sdu.get_long_long(FITNESS)); - const irept::named_subt &named_sub=sdu.get_named_sub(); - typedef irept::named_subt::const_iterator const_iterator; - const const_iterator invariant=named_sub.find(INVARIANT); - assert(named_sub.end() != invariant); - for(const irept &instruction : invariant->second.get_sub()) - { - jsa_genetic_solutiont::invariantt::value_type instr; - instr.opcode=__CPROVER_jsa_opcodet(instruction.get_long_long(OPCODE)); - entity.invariant.push_back(instr); - } - const const_iterator predicates=named_sub.find(PREDICATES); - assert(named_sub.end() != predicates); - for(const irept &predicate : predicates->second.get_sub()) - { - jsa_genetic_solutiont::predicatet pred; - for(const irept &instruction : predicate.get_sub()) - { - jsa_genetic_solutiont::predicatet::value_type instr; - instr.opcode=__CPROVER_jsa_opcodet(instruction.get_long_long(OPCODE)); - instr.op0=__CPROVER_jsa_opt(instruction.get_long_long(OP0)); - instr.op1=__CPROVER_jsa_opt(instruction.get_long_long(OP1)); - instr.result_op=__CPROVER_jsa_opt(instruction.get_long_long(RESULT_OP)); - pred.push_back(instr); - } - entity.predicates.push_back(pred); - } - const const_iterator query=named_sub.find(QUERY); - assert(named_sub.end() != query); - for(const irept &instruction : query->second.get_sub()) - { - jsa_genetic_solutiont::queryt::value_type instr; - instr.opcode=__CPROVER_jsa_opcodet(instruction.get_long_long(OPCODE)); - instr.op0=__CPROVER_jsa_opt(instruction.get_long_long(OP0)); - instr.op1=__CPROVER_jsa_opt(instruction.get_long_long(OP1)); - entity.query.push_back(instr); - } -} - -void jsa_serialisert::operator()(jsa_solutiont &entity, const irept &sdu) const -{ - jsa_genetic_solutiont tmp; - operator ()(tmp, sdu); - entity=convert(tmp, prog); -} - -jsa_serialisert::operator std::function() const -{ - return [this](irept &sdu, const jsa_genetic_solutiont &entity) - { jsa_serialisert::operator ()(sdu, entity);}; -} - -jsa_serialisert::operator std::function() const -{ - return [this](jsa_genetic_solutiont &entity, const irept &sdu) - { jsa_serialisert::operator ()(entity, sdu);}; -} - -jsa_serialisert::operator std::function() const -{ - return [this](jsa_solutiont &entity, const irept &sdu) - { jsa_serialisert::operator ()(entity, sdu);}; -} diff --git a/src/cegis/jsa/genetic/jsa_serialiser.h b/src/cegis/jsa/genetic/jsa_serialiser.h deleted file mode 100644 index 48adbfa5e42..00000000000 --- a/src/cegis/jsa/genetic/jsa_serialiser.h +++ /dev/null @@ -1,91 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_JSA_SERIALISER_H -#define CPROVER_CEGIS_JSA_GENETIC_JSA_SERIALISER_H - -#include - -/** - * @brief - * - * @details - */ -class jsa_serialisert -{ - const class jsa_programt &prog; -public: - /** - * @brief - * - * @details - * - * @param prog - */ - explicit jsa_serialisert(const jsa_programt &prog); - - /** - * @brief - * - * @details - * - * @param sdu - * @param entity - */ - void operator()(class irept &sdu, const class jsa_genetic_solutiont &entity) const; - - /** - * @brief - * - * @details - * - * @param entity - * @param sdu - */ - void operator()(class jsa_genetic_solutiont &entity, const irept &sdu) const; - - /** - * @brief - * - * @details - * - * @param entity - * @param sdu - */ - void operator()(class jsa_solutiont &entity, const irept &sdu) const; - - /** - * @brief - * - * @details - * - * @return - */ - operator std::function() const; - - /** - * @brief - * - * @details - * - * @return - */ - operator std::function() const; - - /** - * @brief - * - * @details - * - * @return - */ - operator std::function() const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_JSA_SERIALISER_H diff --git a/src/cegis/jsa/genetic/jsa_source_provider.cpp b/src/cegis/jsa/genetic/jsa_source_provider.cpp deleted file mode 100644 index 3b4c3c52d3e..00000000000 --- a/src/cegis/jsa/genetic/jsa_source_provider.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -jsa_source_providert::jsa_source_providert(jsa_symex_learnt &lcfg) : - lcfg(lcfg) -{ -} - -#define RETURN_VALUE_ASSIGNMENT RETURN_VALUE_SUFFIX" =" -#define JUMP_BUFFER "__CPROVER_jsa_jump_buffer" -#define TEST_SIGNATURE "int " CEGIS_FITNESS_TEST_FUNC \ - "(const __CPROVER_jsa_index_t __CPROVER_jsa_query_size, " \ - "const __CPROVER_jsa_query_instructiont * const __CPROVER_jsa_query, " \ - "const __CPROVER_jsa_index_t __CPROVER_jsa_invariant_size, " \ - "const __CPROVER_jsa_invariant_instructiont * const __CPROVER_jsa_invariant, " \ - "const __CPROVER_jsa_index_t * const __CPROVER_jsa_predicate_sizes, " \ - "const __CPROVER_jsa_pred_instructiont **__CPROVER_jsa_predicates, " \ - "const __CPROVER_jsa_abstract_heapt *__CPROVER_jsa_counterexample_heaps, " \ - "const __CPROVER_jsa_word_t *__CPROVER_jsa_counterexample_words)" -#define CE_ASSIGNMENT_MARKER "= __CPROVER_jsa_ce_array___CPROVER_jsa_predicate_ce_marker_" - -namespace -{ -void add_jsa_defines(std::string &result, const jsa_symex_learnt &lcfg) -{ - result+="#define __CPROVER_assume(c) __CPROVER_jsa_assume(c)\n" - "#define __CPROVER_JSA_DYNAMIC_TEST_RUNNER\n" - "#define __CPROVER_JSA_MAX_CONCRETE_NODES "; - result+=std::to_string(__CPROVER_JSA_MAX_CONCRETE_NODES); - result+="\n#define __CPROVER_JSA_MAX_ABSTRACT_NODES "; - result+=std::to_string(__CPROVER_JSA_MAX_ABSTRACT_NODES); - result+="\n#define JSA_SYNTHESIS_H_\n" - "#define __CPROVER_JSA_DEFINE_TRANSFORMERS\n"; - result+="\n#define __CPROVER_JSA_MAX_LISTS "; - result+=std::to_string(__CPROVER_JSA_MAX_LISTS); - result+="\n#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST "; - result+=std::to_string(__CPROVER_JSA_MAX_NODES_PER_CE_LIST); - result+="\n#define __CPROVER_JSA_MAX_ITERATORS "; - result+=std::to_string(__CPROVER_JSA_MAX_ITERATORS); - result+="\n#define __CPROVER_JSA_MAX_QUERY_SIZE "; - result+=std::to_string(__CPROVER_JSA_MAX_QUERY_SIZE); - result+="\n#define __CPROVER_JSA_MAX_PRED_SIZE "; - result+=std::to_string(__CPROVER_JSA_MAX_PRED_SIZE); - result+="\n#define __CPROVER_JSA_NUM_PRED_OPS "; - result+=std::to_string(__CPROVER_JSA_NUM_PRED_OPS); - result+="\n#define __CPROVER_JSA_NUM_PRED_RESULT_OPS "; - result+=std::to_string(__CPROVER_JSA_NUM_PRED_RESULT_OPS); - result+="\n#define __CPROVER_JSA_NUM_PREDS "; - result+=std::to_string(__CPROVER_JSA_NUM_PREDS); - result+="\n\n"; -} - -void add_includes_and_globals(std::string &result) -{ - result+="#include \n\n" - "#include \n\n"; - result+="jmp_buf " JUMP_BUFFER";\n\n"; -} - -void add_temp_clean(std::string &result, const symbol_tablet &st) -{ - result+="void __CPROVER_jsa_internal__clear_temps(void)\n{\n"; - const size_t num_temps=count_tmps(st); - assert(num_temps >= 1); - for(size_t i=1; i <= num_temps; ++i) - { - result+=" *" JSA_PRED_RES_OPS "["; - result+=std::to_string(i); - result+="]=0;\n"; - } - result+="}\n\n"; -} - -void add_main_body(std::string &result, const jsa_symex_learnt &lcfg) -{ - const goto_functionst &gf=lcfg.get_goto_functions(); - const goto_functionst::function_mapt &fm=gf.function_map; - goto_functionst entry_only; - const irep_idt entry_id(goto_functionst::entry_point()); - const goto_functionst::function_mapt::const_iterator it=fm.find(entry_id); - entry_only.function_map[entry_id].copy_from(it->second); - const namespacet ns(lcfg.get_symbol_table()); - std::ostringstream oss; - dump_c(entry_only, false, ns, oss); - const std::string main_body(oss.str()); - result+= - main_body.substr( - main_body.find(std::string("void ")+id2string(gf.entry_point()))); -} - -void fix_return_values(std::string &result) -{ - std::string::size_type pos=result.find(RETURN_VALUE_ASSIGNMENT); - while(std::string::npos != pos) - { - const std::string::size_type start=result.rfind(' ', pos); - const std::string::size_type value=result.find('=', pos); - const std::string::size_type end=result.find(';', pos); - std::string return_statement=" return"; - return_statement+=result.substr(value + 1, end - value); - result.replace(start, end, return_statement); - pos=result.find(RETURN_VALUE_ASSIGNMENT, start); - } - pos=result.find(RETURN_VALUE_SUFFIX); - while(std::string::npos != pos) - { - const std::string::size_type end=result.rfind("= ", pos); - const std::string::size_type start=result.rfind(' ', end - 2); - std::string var_name=result.substr(start + 1, end - start); - var_name+=' '; - const std::string::size_type prev_end=result.rfind('\n', start); - const std::string::size_type prev_start=result.rfind(" ", prev_end); - const std::string::size_type line_end=result.find('\n', prev_end + 1); - result.erase(prev_end, line_end - prev_end); - result.insert(prev_start + 2, var_name); - pos=result.find(RETURN_VALUE_SUFFIX, prev_start); - } - substitute(result, "assert((_Bool)0)", "return EXIT_SUCCESS"); - substitute(result, "\n return 0;", ""); -} - -void add_facade_function(const goto_functionst &gf, std::string &result) -{ - std::ostringstream start_sig; - start_sig << "void " << gf.entry_point() << "(void)"; - substitute(result, start_sig.str(), TEST_SIGNATURE); - const std::string::size_type pos=result.find(" __CPROVER_initialize();"); - result.insert(pos, " if (setjmp(" JUMP_BUFFER")) return EXIT_FAILURE;\n"); -} - -void remove_line_with(std::string &result, const std::string &value) -{ - const std::string::size_type pos=result.find(value); - const std::string::size_type start=result.rfind('\n', pos); - const std::string::size_type end=result.find('\n', pos); - result.erase(start, end - start); -} - -void remove_predicates(std::string &result, const size_t num_preds) -{ - for(size_t i=0; i < num_preds; ++i) - { - std::string base_name="__CPROVER_jsa_predicate_"; - base_name+=std::to_string(i); - std::string size_var_name(base_name); - size_var_name+="_size;"; - remove_line_with(result, size_var_name); - std::string var_name(base_name); - var_name+='['; - remove_line_with(result, var_name); - } -} - -void declare_predicates(std::string &result, const size_t num_preds, - const std::string::size_type pos) -{ - std::string source; - for(size_t i=0; i < num_preds; ++i) - { - std::string base_name("__CPROVER_jsa_predicate_"); - base_name+=std::to_string(i); - source+=" __CPROVER_jsa_index_t "; - source+=base_name; - source+="_size=__CPROVER_jsa_predicate_sizes["; - source+=std::to_string(i); - source+="];\n"; - source+=" const __CPROVER_jsa_pred_instructiont * const "; - source+=base_name; - source+="=__CPROVER_jsa_predicates["; - source+=std::to_string(i); - source+="];\n"; - } - result.insert(pos, source); -} - -void insert_solution(std::string &result, const jsa_symex_learnt &lcfg) -{ - const std::string::size_type pos=result.find(" __CPROVER_initialize();\n"); - const size_t num_preds=get_num_jsa_preds(lcfg.get_symbol_table()); - remove_predicates(result, num_preds); - declare_predicates(result, num_preds, pos); - remove_line_with(result, "__CPROVER_jsa_query_size;"); - remove_line_with(result, "__CPROVER_jsa_query["); - remove_line_with(result, "__CPROVER_jsa_invariant_size;"); - remove_line_with(result, "__CPROVER_jsa_invariant["); -} - -bool is_heap(const std::string &line) -{ - return std::string::npos != line.find("heap"); -} - -void insert_counterexample(std::string &result) -{ - std::string::size_type pos=result.find(CE_ASSIGNMENT_MARKER); - size_t heap_count=0; - size_t word_count=0; - while(std::string::npos != pos) - { - const std::string::size_type line_start=result.rfind(" ", pos); - const std::string::size_type line_end=result.find('\n', pos); - const std::string line(result.substr(line_start, line_end - line_start)); - const std::string::size_type stmt_end=result.find(';', pos); - std::string value("= "); - if(is_heap(line)) - { - value+="__CPROVER_jsa_counterexample_heaps["; - value+=std::to_string(heap_count++); - } else - { - value+="__CPROVER_jsa_counterexample_words["; - value+=std::to_string(word_count++); - } - value+=']'; - result.replace(pos, stmt_end - pos, value); - pos=result.find(CE_ASSIGNMENT_MARKER, line_start); - } -} - -void cleanup(std::string &result) -{ - substitute(result, " __CPROVER_initialize();\n", ""); - result+="\n}\n"; -} -} - -const std::string &jsa_source_providert::operator ()() -{ - if(!source.empty()) return source; - add_jsa_defines(source, lcfg); - add_includes_and_globals(source); - add_temp_clean(source, lcfg.get_symbol_table()); - add_main_body(source, lcfg); - fix_return_values(source); - add_facade_function(lcfg.get_goto_functions(), source); - insert_solution(source, lcfg); - insert_counterexample(source); - cleanup(source); - return source; -} diff --git a/src/cegis/jsa/genetic/jsa_source_provider.h b/src/cegis/jsa/genetic/jsa_source_provider.h deleted file mode 100644 index 5f892219b6b..00000000000 --- a/src/cegis/jsa/genetic/jsa_source_provider.h +++ /dev/null @@ -1,44 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_JSA_SOURCE_PROVIDER_H -#define CPROVER_CEGIS_JSA_GENETIC_JSA_SOURCE_PROVIDER_H - -#include - -/** - * @brief - * - * @details - */ -class jsa_source_providert -{ - class jsa_symex_learnt &lcfg; - std::string source; -public: - /** - * @brief - * - * @details - * - * @param lcfg - */ - explicit jsa_source_providert(jsa_symex_learnt &lcfg); - - /** - * @brief - * - * @details - * - * @return - */ - const std::string &operator()(); -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_JSA_SOURCE_PROVIDER_H diff --git a/src/cegis/jsa/genetic/random_jsa_cross.cpp b/src/cegis/jsa/genetic/random_jsa_cross.cpp deleted file mode 100644 index 882f2ed1a7f..00000000000 --- a/src/cegis/jsa/genetic/random_jsa_cross.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -random_jsa_crosst::random_jsa_crosst(const jsa_randomt &random) : - random(random) -{ -} - -namespace -{ -typedef random_jsa_crosst::individualt individualt; -typedef individualt::invariantt invariantt; -typedef individualt::predicatet predicatet; -typedef individualt::queryt queryt; - -void splice(invariantt::value_type &result, const invariantt::value_type &lhs, - const invariantt::value_type &rhs, const size_t offset) -{ - result=lhs; -} - -void splice(predicatet::value_type &result, const predicatet::value_type &lhs, - const predicatet::value_type &rhs, const size_t offset) -{ - result=rhs; - switch(offset) { - case 3: result.opcode=lhs.opcode; - case 2: result.op1=lhs.op1; - case 1: result.op0=lhs.op0; - case 0: break; - default: assert(!"Invalid predicate instruction index."); - } -} - -void splice(queryt::value_type &result, const queryt::value_type &lhs, - const queryt::value_type &rhs, const size_t offset) -{ - result=rhs; - switch(offset) { - case 2: result.op1=lhs.op1; - case 1: result.op0=lhs.op0; - case 0: break; - default: assert(!"Invalid query instruction index."); - } -} - -template -void splice(containert &result, const containert &lhs, const containert &rhs, - const size_t offset, const size_t element_size) -{ - const size_t rhs_size=rhs.size(); - const size_t offset_index=offset / element_size; - assert(rhs_size > 0); - const size_t rhs_offset_index=std::min(offset_index, rhs_size - 1); - const size_t result_size=offset_index + rhs_size - rhs_offset_index; - result.resize(result_size); - const typename containert::const_iterator lhs_first=lhs.begin(); - const typename containert::iterator result_first=result.begin(); - std::copy(lhs_first, std::next(lhs_first, offset_index), result_first); - const typename containert::const_iterator rhs_first=rhs.begin(); - const typename containert::iterator result_mid=std::next(result_first, offset_index); - std::copy(std::next(rhs_first, rhs_offset_index), rhs.end(), result_mid); - splice(result[offset_index], lhs[offset_index], rhs[rhs_offset_index], offset % element_size); -} - -void check_consistency(const individualt &individual) -{ - assert(individual.invariant.size() == 1); - assert(individual.predicates.size() >= 1); - for(const individualt::predicatet &predicate : individual.predicates) - assert(predicate.size() >= 1); - assert(individual.query.size() >= 1); -} - -void cross(individualt &offspring, const individualt &father, - const individualt &mother, size_t offset) -{ - offspring.predicates=mother.predicates; - offspring.query=mother.query; - const individualt::invariantt &f_inv=father.invariant; - const size_t f_inv_size=f_inv.size(); - if(offset < f_inv_size) - { - const individualt::invariantt &m_inv=mother.invariant; - return splice(offspring.invariant, f_inv, m_inv, offset, OPERANDS_PER_JSA_INVARIANT_INSTRUCTION); - } - offset-=f_inv_size; - offspring.invariant=father.invariant; - for(size_t pred_index=0; pred_index < father.predicates.size(); ++pred_index) - { - const individualt::predicatet &f_pred=father.predicates[pred_index]; - const size_t f_pred_size=f_pred.size() * OPERANDS_PER_JSA_PREDICATE_INSTRUCTION; - individualt::predicatet &offspring_pred=offspring.predicates[pred_index]; - if(offset >= f_pred_size) - { - offspring_pred=f_pred; - offset-=f_pred_size; - continue; - } - const individualt::predicatet &m_pred=mother.predicates[pred_index]; - return splice(offspring_pred, f_pred, m_pred, offset, OPERANDS_PER_JSA_PREDICATE_INSTRUCTION); - } - offspring.predicates=father.predicates; - const queryt &f_query=father.query; - assert(offset < f_query.size() * OPERANDS_PER_JSA_QUERY_INSTRUCTION); - splice(offspring.query, f_query, mother.query, offset, OPERANDS_PER_JSA_QUERY_INSTRUCTION); - check_consistency(offspring); -} -} - -void random_jsa_crosst::operator()(const individualst &parents, - const individualst &children) const -{ - assert(parents.size() >= 2 && children.size() >= 2); - const individualt &father=*parents.front(); - const individualt &mother=*parents[1]; - individualt &son=*children.front(); - individualt &daughter=*children[1]; - - const size_t father_sz=get_num_genetic_targets(father); - const size_t mother_sz=get_num_genetic_targets(mother); - const size_t son_offset=random.rand() % father_sz; - const size_t daughter_offset=random.rand() % mother_sz; - cross(son, father, mother, son_offset); - cross(daughter, mother, father, daughter_offset); -} diff --git a/src/cegis/jsa/genetic/random_jsa_cross.h b/src/cegis/jsa/genetic/random_jsa_cross.h deleted file mode 100644 index dad01f21373..00000000000 --- a/src/cegis/jsa/genetic/random_jsa_cross.h +++ /dev/null @@ -1,52 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_CROSS_H -#define CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_CROSS_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class random_jsa_crosst -{ - const class jsa_randomt &random; -public: - typedef jsa_populationt populationt; - typedef std::deque individualst; - typedef populationt::value_type individualt; - - /** - * @brief - * - * @details - * - * @param random - */ - explicit random_jsa_crosst(const jsa_randomt &random); - - /** - * @brief - * - * @details - * - * @param parents - * @param children - */ - void operator()( - const individualst &parents, - const individualst &children) const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_CROSS_H diff --git a/src/cegis/jsa/genetic/random_jsa_mutate.cpp b/src/cegis/jsa/genetic/random_jsa_mutate.cpp deleted file mode 100644 index 2623b7aeea7..00000000000 --- a/src/cegis/jsa/genetic/random_jsa_mutate.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -random_jsa_mutatet::random_jsa_mutatet(const jsa_randomt &random) : - random(random) -{ -} - -void random_jsa_mutatet::operator()(individualt &lhs, - const individualt &rhs) const -{ - lhs=rhs; - size_t mutation_index=random.rand() % get_num_genetic_targets(lhs); - const size_t num_inv_instrs=lhs.invariant.size(); - if(mutation_index < num_inv_instrs) - return random.havoc(lhs.invariant[mutation_index]); - mutation_index-=num_inv_instrs; - for(individualt::predicatet &pred : lhs.predicates) - { - const size_t num_instrs=pred.size() * OPERANDS_PER_JSA_PREDICATE_INSTRUCTION; - if(mutation_index >= num_instrs) { mutation_index-=num_instrs; continue; } - - individualt::predicatet::value_type &instr=pred[mutation_index / OPERANDS_PER_JSA_PREDICATE_INSTRUCTION]; - individualt::predicatet::value_type tmp(instr); - random.havoc(tmp); - switch(mutation_index % OPERANDS_PER_JSA_PREDICATE_INSTRUCTION) - { - case 0: instr.op0=tmp.op0; return; - case 1: instr.op1=tmp.op1; return; - case 2: instr.opcode=tmp.opcode; return; - case 3: instr.result_op=tmp.result_op; return; - default: assert(!"Invalid predicate mutation index"); - } - } - individualt::queryt &query=lhs.query; - assert(mutation_index < query.size() * OPERANDS_PER_JSA_QUERY_INSTRUCTION); - const size_t query_index=mutation_index / OPERANDS_PER_JSA_QUERY_INSTRUCTION; - individualt::queryt::value_type &instr=query[query_index]; - individualt::queryt::value_type tmp(instr); - random.havoc(tmp, query_index); - switch(mutation_index % OPERANDS_PER_JSA_QUERY_INSTRUCTION) - { - case 0: instr.op0=tmp.op0; break; - case 1: instr.op1=tmp.op1; break; - case 2: instr.opcode=tmp.opcode; break; - default: assert(!"Invalid query mutation index"); - } -} - -void random_jsa_mutatet::havoc(individualt &ind) const -{ - random.havoc(ind); -} - -void random_jsa_mutatet::post_process(individualt &ind) const -{ - // TODO: Implement! -} diff --git a/src/cegis/jsa/genetic/random_jsa_mutate.h b/src/cegis/jsa/genetic/random_jsa_mutate.h deleted file mode 100644 index e931ae48319..00000000000 --- a/src/cegis/jsa/genetic/random_jsa_mutate.h +++ /dev/null @@ -1,62 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_MUTATE_H -#define CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_MUTATE_H - -/** - * @brief - * - * @details - */ -class random_jsa_mutatet -{ - const class jsa_randomt &random; -public: - typedef class jsa_genetic_solutiont individualt; - - /** - * @brief - * - * @details - * - * @param random - */ - explicit random_jsa_mutatet(const jsa_randomt &random); - - /** - * @brief - * - * @details - * - * @param lhs - * @param rhs - */ - void operator()(individualt &lhs, const individualt &rhs) const; - - /** - * @brief - * - * @details - * - * @param lhs - */ - void havoc(individualt &ind) const; - - /** - * @brief - * - * @details - * - * @param ind - */ - void post_process(individualt &ind) const; -}; - -#endif // CPROVER_CEGIS_JSA_GENETIC_RANDOM_JSA_MUTATE_H diff --git a/src/cegis/jsa/genetic/solution_helper.cpp b/src/cegis/jsa/genetic/solution_helper.cpp deleted file mode 100644 index a4b206a9d73..00000000000 --- a/src/cegis/jsa/genetic/solution_helper.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -namespace -{ -size_t sum_pred(const size_t sum, const jsa_genetic_solutiont::predicatet &pred) -{ - return sum + pred.size() * OPERANDS_PER_JSA_PREDICATE_INSTRUCTION; -} -} - -size_t get_num_genetic_targets(const jsa_genetic_solutiont &solution) -{ - size_t result=solution.invariant.size(); - const jsa_genetic_solutiont::predicatest &preds=solution.predicates; - result=std::accumulate(preds.begin(), preds.end(), result, sum_pred); - return result+=solution.query.size() * OPERANDS_PER_JSA_QUERY_INSTRUCTION; -} diff --git a/src/cegis/jsa/genetic/solution_helper.h b/src/cegis/jsa/genetic/solution_helper.h deleted file mode 100644 index e31538404e7..00000000000 --- a/src/cegis/jsa/genetic/solution_helper.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_GENETIC_SOLUTION_HELPER_H -#define CPROVER_CEGIS_JSA_GENETIC_SOLUTION_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param solution - * - * @return - */ -size_t get_num_genetic_targets(const class jsa_genetic_solutiont &solution); - -#endif // CPROVER_CEGIS_JSA_GENETIC_SOLUTION_HELPER_H diff --git a/src/cegis/jsa/instrument/jsa_meta_data.cpp b/src/cegis/jsa/instrument/jsa_meta_data.cpp deleted file mode 100644 index 92f443979a2..00000000000 --- a/src/cegis/jsa/instrument/jsa_meta_data.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -bool is_jsa_heap(const typet &type) -{ - const irep_idt &type_id=type.id(); - if(ID_symbol == type_id) - return id2string(to_symbol_type(type).get_identifier()) == JSA_HEAP_TAG; - if(ID_struct != type_id) return false; - const irep_idt tag(to_struct_type(type).get_tag()); - return id2string(tag) == JSA_HEAP_TAG; -} - -#define JSA_ITERATOR_PREFIX JSA_PREFIX "iterator_" -#define JSA_LIST_PREFIX JSA_PREFIX "list_" - -namespace -{ -bool contains(const irep_idt &haystack, const std::string &needle) -{ - return std::string::npos != id2string(haystack).find(needle); -} -} - -bool is_jsa_iterator(const irep_idt &id) -{ - return contains(id, JSA_ITERATOR_PREFIX); -} - -bool is_jsa_list(const irep_idt &id) -{ - return contains(id, JSA_LIST_PREFIX); -} - -source_locationt jsa_builtin_source_location() -{ - source_locationt loc; - loc.set_file(JSA_MODULE); - loc.set_function(goto_functionst::entry_point()); - return loc; -} - -bool is_jsa_const(const symbol_exprt &symbol) -{ - const std::string &id=id2string(symbol.get_identifier()); - if(std::string::npos != id.find(JSA_CONSTANT_PREFIX)) return true; - return symbol.type().get_bool(ID_C_constant); -} diff --git a/src/cegis/jsa/instrument/jsa_meta_data.h b/src/cegis/jsa/instrument/jsa_meta_data.h deleted file mode 100644 index d5fbc8f69dc..00000000000 --- a/src/cegis/jsa/instrument/jsa_meta_data.h +++ /dev/null @@ -1,98 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#ifndef CPROVER_CEGIS_JSA_INSTRUMENT_JSA_META_DATA_H -#define CPROVER_CEGIS_JSA_INSTRUMENT_JSA_META_DATA_H - -#define JSA_MODULE "" -#define JSA_PREFIX CPROVER_PREFIX "jsa_" -#define JSA_BASE_CASE JSA_PREFIX "base_case" -#define JSA_IND_ASSUME JSA_PREFIX "inductive_assume" -#define JSA_IND_STEP JSA_PREFIX "inductive_step" -#define JSA_PROP_ENTAIL JSA_PREFIX "property_entailment" -#define JSA_TMP_PREFIX JSA_PREFIX "tmp_" -#define JSA_LAMBDA_OP JSA_PREFIX "lambda_op" -#define JSA_CONSTANT_PREFIX CPROVER_PREFIX "jsa_constant_" -#define JSA_QUERY JSA_PREFIX "query" -#define JSA_QUERY_SZ JSA_QUERY "_size" -#define JSA_INV JSA_PREFIX "invariant" -#define JSA_INV_SZ JSA_INV "_size" -#define JSA_POST JSA_PREFIX "postcondition" -#define JSA_POST_SZ JSA_POST "_size" -#define JSA_QUERIED_HEAP JSA_PREFIX "queried_heap" -#define JSA_ORG_HEAP JSA_PREFIX "org_heap" -#define JSA_HEAP_TAG "tag-" JSA_PREFIX "abstract_heap" -#define JSA_PRED_PREFIX JSA_PREFIX "predicate_" -#define JSA_SIZE_SUFFIX "_size" -#define JSA_INV_EXEC JSA_PREFIX "invariant_execute" -#define JSA_INV_VERIFY_EXEC JSA_PREFIX "verify_invariant_execute" -#define JSA_QUERY_EXEC JSA_PREFIX "query_execute" -#define JSA_STREAM_OP JSA_PREFIX "stream_op" -#define JSA_PRED_EXEC JSA_PREFIX "execute_pred" -#define JSA_STATIC_META_VAR_PREFIX CPROVER_PREFIX "JSA_" -#define JSA_ASSUME_VALID_PRED JSA_PREFIX "assume_valid_pred" -#define JSA_PRED_RES_OPS "__CPROVER_JSA_PRED_RESULT_OPS" - -/** - * @brief - * - * @details - * - * @param type - * - * @return - */ -bool is_jsa_heap(const class typet &type); - -/** - * @brief - * - * @details - * - * @param id - * - * @return - */ -bool is_jsa_iterator(const irep_idt &id); - -/** - * @brief - * - * @details - * - * @param id - * - * @return - */ -bool is_jsa_list(const irep_idt &id); - -/** - * @brief - * - * @details - * - * @return - */ -source_locationt jsa_builtin_source_location(); - -/** - * @brief - * - * @details - * - * @param symbol - * - * @return - */ -bool is_jsa_const(const class symbol_exprt &symbol); - -#endif // CPROVER_CEGIS_JSA_INSTRUMENT_JSA_META_DATA_H diff --git a/src/cegis/jsa/instrument/temps_helper.cpp b/src/cegis/jsa/instrument/temps_helper.cpp deleted file mode 100644 index f57ea1fd23e..00000000000 --- a/src/cegis/jsa/instrument/temps_helper.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_tmp(const symbol_tablet::symbolst::value_type &symbol) -{ - return std::string::npos != id2string(symbol.first).find(JSA_TMP_PREFIX); -} -} - -goto_programt::targett zero_jsa_temps(jsa_programt &prog, - goto_programt::targett pos) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - for(const symbol_tablet::symbolst::value_type &symbol : st.symbols) - { - if(!is_tmp(symbol)) continue; - const symbol_exprt lhs(symbol.second.symbol_expr()); - pos=jsa_assign(st, gf, pos, lhs, from_integer(0, lhs.type())); - } - return pos; -} - -void add_zero_jsa_temps_to_pred_exec(jsa_programt &prog) -{ - symbol_tablet &st=prog.st; - const size_t num_tmps=count_tmps(st); - assert(num_tmps > 0); - goto_functionst::function_mapt &fm=prog.gf.function_map; - const goto_functionst::function_mapt::iterator it=fm.find(JSA_PRED_EXEC); - assert(fm.end() != it); - goto_function_templatet &exec=it->second; - assert(exec.body_available()); - goto_programt &body=exec.body; - goto_programt::instructionst &instr=body.instructions; - source_locationt loc; - loc.set_file(JSA_MODULE); - loc.set_function(JSA_PRED_EXEC); - for(goto_programt::targett pos=instr.begin(); pos != instr.end(); ++pos) - { - const codet &code=pos->code; - if(ID_assign != code.get_statement()) continue; - const code_assignt &assign=to_code_assign(code); - const exprt &lhs=assign.lhs(); - if(ID_symbol != lhs.id()) continue; - const symbol_exprt &symbol=to_symbol_expr(lhs); - const irep_idt &id=symbol.get_identifier(); - if(std::string::npos == id2string(id).find(RETURN_VALUE_SUFFIX)) continue; - const goto_programt::targett return_pos(pos); - std::advance(pos, -1); - const symbol_exprt ops(st.lookup(JSA_PRED_RES_OPS).symbol_expr()); - for(size_t i=1; i <= num_tmps; ++i) - { - const constant_exprt index(from_integer(i, signed_int_type())); - const index_exprt elem(ops, index); - const dereference_exprt lhs(elem, jsa_word_type()); - const exprt rhs(from_integer(0, lhs.type())); - pos=cegis_assign(st, body, pos, lhs, rhs, loc); - } - move_labels(body, return_pos, pos); - return; - } - assert(!"insertion point for temp assignment in " JSA_PRED_EXEC "not found"); -} - -size_t count_tmps(const symbol_tablet &st) -{ - return std::count_if(st.symbols.begin(), st.symbols.end(), is_tmp); -} diff --git a/src/cegis/jsa/instrument/temps_helper.h b/src/cegis/jsa/instrument/temps_helper.h deleted file mode 100644 index 0bdb7401197..00000000000 --- a/src/cegis/jsa/instrument/temps_helper.h +++ /dev/null @@ -1,46 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_INSTRUMENT_TEMPS_HELPER_H -#define CPROVER_CEGIS_JSA_INSTRUMENT_TEMPS_HELPER_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - */ -goto_programt::targett zero_jsa_temps( - class jsa_programt &prog, - goto_programt::targett pos); - -/** - * @brief - * - * @details - * - * @param result_ops - * - * @return - */ -void add_zero_jsa_temps_to_pred_exec(jsa_programt &prog); - -/** - * @brief - * - * @details - * - * @param st - */ -size_t count_tmps(const symbol_tablet &st); - -#endif // CPROVER_CEGIS_JSA_INSTRUMENT_TEMPS_HELPER_H diff --git a/src/cegis/jsa/learn/execute_jsa_programs.cpp b/src/cegis/jsa/learn/execute_jsa_programs.cpp deleted file mode 100644 index a32f08bbc14..00000000000 --- a/src/cegis/jsa/learn/execute_jsa_programs.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define EXEC_FULL "__CPROVER_jsa_full_query_execute" -#define SYNC "__CPROVER_jsa_synchronise_iterator" - -namespace -{ -void make_constraint_call(const symbol_tablet &st, goto_functionst &gf, - goto_programt::targett pos, const code_function_callt::argumentst &args) -{ - goto_programt &body=get_entry_body(gf); - const symbol_exprt lhs(st.lookup(get_affected_variable(*pos)).symbol_expr()); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - code_function_callt call; - call.lhs()=lhs; - call.function()=st.lookup(JSA_INV_EXEC).symbol_expr(); - call.arguments()=args; - pos->code=call; - remove_return(body, pos); -} - -void make_constraint_call(const symbol_tablet &st, goto_functionst &gf, - const goto_programt::targett &pos) -{ - code_function_callt::argumentst args; - args.push_back(address_of_exprt(get_user_heap(gf))); - args.push_back(address_of_exprt(get_queried_heap(st))); - const symbol_exprt p(st.lookup(get_cegis_meta_name(JSA_INV)).symbol_expr()); - constant_exprt zero=from_integer(0, signed_int_type()); - args.push_back(address_of_exprt(index_exprt(p, zero))); - args.push_back(st.lookup(get_cegis_meta_name(JSA_INV_SZ)).symbol_expr()); - make_constraint_call(st, gf, pos, args); -} - -void make_query_call(jsa_programt &prog, const symbol_tablet &st, - goto_functionst &gf, goto_programt::targett pos, - const bool full_query=false) -{ - goto_programt &body=get_entry_body(gf); - pos=insert_before_preserve_labels(body, pos); - const goto_programt::targett temps_end=zero_jsa_temps(prog, pos); - if(pos != temps_end) - { - move_labels(body, pos, std::next(pos)); - body.instructions.erase(pos); - pos=body.insert_after(temps_end); - } - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - code_function_callt call; - call.function()= - st.lookup(full_query ? EXEC_FULL : JSA_QUERY_EXEC).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - args.push_back(address_of_exprt(get_queried_heap(st))); - const symbol_exprt p(st.lookup(get_cegis_meta_name(JSA_QUERY)).symbol_expr()); - constant_exprt zero=from_integer(0, signed_int_type()); - args.push_back(address_of_exprt(index_exprt(p, zero))); - args.push_back(st.lookup(get_cegis_meta_name(JSA_QUERY_SZ)).symbol_expr()); - pos->code=call; -} - -void make_sync_call(const symbol_tablet &st, goto_functionst &gf, - goto_programt::targett pos) -{ - goto_programt &body=get_entry_body(gf); - pos=insert_before_preserve_labels(body, pos); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - code_function_callt call; - call.function()=st.lookup(SYNC).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - args.push_back(address_of_exprt(get_user_heap(gf))); - args.push_back(address_of_exprt(get_queried_heap(st))); - const symbol_exprt p(st.lookup(get_cegis_meta_name(JSA_QUERY)).symbol_expr()); - constant_exprt zero=from_integer(0, signed_int_type()); - args.push_back(address_of_exprt(index_exprt(p, zero))); - args.push_back(st.lookup(get_cegis_meta_name(JSA_QUERY_SZ)).symbol_expr()); - pos->code=call; -} -} - -void execute_jsa_learn_programs(jsa_programt &prog) -{ - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - make_constraint_call(st, gf, prog.base_case); - make_query_call(prog, st, gf, prog.base_case); - make_constraint_call(st, gf, prog.inductive_assumption); - make_query_call(prog, st, gf, prog.inductive_assumption); - make_constraint_call(st, gf, prog.inductive_step); - make_sync_call(st, gf, prog.inductive_step); - make_query_call(prog, st, gf, prog.inductive_step); - make_constraint_call(st, gf, prog.property_entailment); - make_query_call(prog, st, gf, prog.property_entailment, true); - make_sync_call(st, gf, prog.property_entailment); -} diff --git a/src/cegis/jsa/learn/execute_jsa_programs.h b/src/cegis/jsa/learn/execute_jsa_programs.h deleted file mode 100644 index 9942f873be5..00000000000 --- a/src/cegis/jsa/learn/execute_jsa_programs.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_EXECUTE_JSA_PROGRAMS_H -#define CPROVER_CEGIS_JSA_LEARN_EXECUTE_JSA_PROGRAMS_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void execute_jsa_learn_programs(class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_LEARN_EXECUTE_JSA_PROGRAMS_H diff --git a/src/cegis/jsa/learn/extract_candidate.cpp b/src/cegis/jsa/learn/extract_candidate.cpp deleted file mode 100644 index fb58a93b827..00000000000 --- a/src/cegis/jsa/learn/extract_candidate.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -typedef std::pair encoded_programt; -typedef std::vector encoded_programst; - -inline bool is_integer(const std::string &s) -{ - if(s.empty() || (!isdigit(s[0]) && s[0] != '-' && s[0] != '+')) return false; - char *p; - long result=strtol(s.c_str(), &p, 10); - (void)result; // unused as just used for testing string format - return *p==0; -} - -bool is_prog_name(const std::string &var_name, const std::string &prefix) -{ - const std::string::size_type prefix_size=prefix.size(); - if(var_name.substr(0, prefix_size) != prefix) return false; - const std::string suffix(var_name.substr(prefix_size)); - return suffix.empty() || is_integer(suffix); -} - -bool find_prog(encoded_programt &result, - goto_tracet::stepst::const_iterator &first, - const goto_tracet::stepst::const_iterator &last, const std::string &name) -{ - const goto_tracet::stepst::const_iterator origin(first); - const std::string prefix(get_cegis_meta_name(name)); - for(; first != last; ++first) - { - if(goto_trace_stept::DECL != first->type) continue; - const std::string &var_name=id2string(first->lhs_object.get_identifier()); - if(!is_prog_name(var_name, prefix)) continue; - std::string sz_name(var_name); - sz_name+= JSA_SIZE_SUFFIX; - goto_tracet::stepst::const_iterator sz; - for(sz=first; id2string(sz->lhs_object.get_identifier()) != sz_name; --sz) - assert(sz != origin); - const bv_arithmetict bv(sz->full_lhs_value); - result.first=bv.to_integer().to_ulong(); - result.second=to_array_expr(first++->full_lhs_value); - return true; - } - return false; -} - -std::vector<__CPROVER_jsa_pred_instructiont> to_genetic_pred(const encoded_programt &prog) -{ - std::vector<__CPROVER_jsa_pred_instructiont> result(prog.first); - const array_exprt::operandst &ops=prog.second.operands(); - for(size_t i=0; i < result.size(); ++i) - { - const struct_exprt::operandst &members=to_struct_expr(ops[i]).operands(); - assert(members.size() == 4u); - __CPROVER_jsa_pred_instruction &instr=result[i]; - struct_exprt::operandst::const_iterator member=members.begin(); - instr.opcode=bv_arithmetict(*member++).to_integer().to_ulong(); - instr.result_op=bv_arithmetict(*member++).to_integer().to_ulong(); - instr.op0=bv_arithmetict(*member++).to_integer().to_ulong(); - instr.op1=bv_arithmetict(*member).to_integer().to_ulong(); - } - return result; -} - -std::vector<__CPROVER_jsa_query_instructiont> to_genetic_query(const encoded_programt &prog) -{ - std::vector<__CPROVER_jsa_query_instructiont> result(prog.first); - const array_exprt::operandst &ops=prog.second.operands(); - for(size_t i=0; i < result.size(); ++i) - { - const struct_exprt::operandst &members=to_struct_expr(ops[i]).operands(); - assert(members.size() == 3u); - __CPROVER_jsa_query_instructiont &instr=result[i]; - struct_exprt::operandst::const_iterator member=members.begin(); - instr.opcode=bv_arithmetict(*member++).to_integer().to_ulong(); - instr.op0=bv_arithmetict(*member++).to_integer().to_ulong(); - instr.op1=bv_arithmetict(*member).to_integer().to_ulong(); - } - return result; -} - -std::vector<__CPROVER_jsa_invariant_instructiont> to_genetic_inv(const encoded_programt &prog) -{ - std::vector<__CPROVER_jsa_invariant_instructiont> result(prog.first); - const array_exprt::operandst &ops=prog.second.operands(); - for(size_t i=0; i < result.size(); ++i) - { - const struct_exprt::operandst &members=to_struct_expr(ops[i]).operands(); - assert(members.size() == 1u); - __CPROVER_jsa_invariant_instructiont &instr=result[i]; - instr.opcode=bv_arithmetict(members.front()).to_integer().to_ulong(); - } - return result; -} -} - -void extract_jsa_genetic_candidate(jsa_genetic_solutiont &solution, - const jsa_programt &prog, const goto_tracet &trace) -{ - goto_tracet::stepst::const_iterator first(trace.steps.begin()); - const goto_tracet::stepst::const_iterator last(trace.steps.end()); - goto_tracet::stepst::const_iterator last_pred; - encoded_programt tmp; - while(find_prog(tmp, first, last, JSA_PRED_PREFIX)) - { - solution.predicates.push_back(to_genetic_pred(tmp)); - last_pred=first; - } - first=last_pred; - assert(find_prog(tmp, first, last, JSA_QUERY)); - solution.query=to_genetic_query(tmp); - assert(find_prog(tmp, first, last, JSA_INV)); - solution.invariant=to_genetic_inv(tmp); -} - -namespace -{ -void post_process(jsa_genetic_solutiont &solution, const pred_op_idst &pred_ops, - const pred_op_idst &result_pred_ops, const size_t max_size) -{ - // Unused predicates need to be zeroed. - const __CPROVER_jsa_pred_instructiont zero = { 0, 0, 0, 0 }; - const size_t num_ops=pred_ops.size(); - for(jsa_genetic_solutiont::predicatest::value_type &pred : solution.predicates) - for(const __CPROVER_jsa_pred_instructiont &instr : pred) - if(instr.opcode >= __CPROVER_JSA_NUM_PRED_INSTRUCTIONS || - instr.result_op >= result_pred_ops.size() || - instr.op0 >= num_ops || instr.op1 >= num_ops) - { - std::fill(pred.begin(), pred.end(), zero); - break; - } -} -} - -void extract_jsa_candidate(jsa_solutiont &solution, const jsa_programt &prog, - const goto_tracet &trace, const pred_op_idst &pred_ops, - const pred_op_idst &result_pred_ops, const size_t max_size) -{ - jsa_genetic_solutiont tmp; - extract_jsa_genetic_candidate(tmp, prog, trace); - post_process(tmp, pred_ops, result_pred_ops, max_size); - solution=convert(tmp, prog); -} diff --git a/src/cegis/jsa/learn/extract_candidate.h b/src/cegis/jsa/learn/extract_candidate.h deleted file mode 100644 index acfaa4461de..00000000000 --- a/src/cegis/jsa/learn/extract_candidate.h +++ /dev/null @@ -1,48 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_EXTRACT_CANDIDATE_H -#define CPROVER_CEGIS_JSA_LEARN_EXTRACT_CANDIDATE_H - -#include - -/** - * @brief - * - * @details - * - * @param solution - * @param prog - * @param trace - */ -void extract_jsa_genetic_candidate( - class jsa_genetic_solutiont &solution, - const class jsa_programt &prog, - const class goto_tracet &trace); - -/** - * @brief - * - * @details - * - * @param solution - * @param trace - * @param const_pred_ops - * @param pred_ops - * @param max_size - */ -void extract_jsa_candidate( - class jsa_solutiont &solution, - const jsa_programt &prog, - const goto_tracet &trace, - const pred_op_idst &pred_ops, - const pred_op_idst &result_pred_ops, - const size_t max_size); - -#endif // CPROVER_CEGIS_JSA_LEARN_EXTRACT_CANDIDATE_H diff --git a/src/cegis/jsa/learn/insert_counterexample.cpp b/src/cegis/jsa/learn/insert_counterexample.cpp deleted file mode 100644 index b7f1e938498..00000000000 --- a/src/cegis/jsa/learn/insert_counterexample.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#define CE_ARRAY_PREFIX JSA_PREFIX "ce_array_" -#define CE_ARRAY_INDEX JSA_PREFIX "ce_array_index" - -namespace -{ -constant_exprt get_size_expr(const size_t size) -{ - return from_integer(size, signed_int_type()); -} - -typedef std::map array_valuest; -array_valuest get_array_values(const symbol_tablet &st, - const jsa_counterexamplest &ces) -{ - const constant_exprt size_expr(get_size_expr(ces.size())); - const jsa_counterexamplet &prototype=ces.front(); - array_valuest array_values; - for(const jsa_counterexamplet::value_type &value : prototype) - { - const typet &org_type=value.second.type(); - const typet &element_type=replace_struct_by_symbol_type(st, org_type); - const array_typet array_type(element_type, size_expr); - array_values.insert(std::make_pair(value.first, array_exprt(array_type))); - } - for(const jsa_counterexamplet &ce : ces) - for(const jsa_counterexamplet::value_type &value : ce) - array_values[value.first].copy_to_operands(value.second); - return array_values; -} - -std::string get_array_name(const irep_idt &loc_id) -{ - std::string base_name(CE_ARRAY_PREFIX); - return base_name+=id2string(loc_id); -} - -void add_array_declarations(jsa_programt &program, - const jsa_counterexamplest &ces) -{ - symbol_tablet &st=program.st; - goto_functionst &gf=program.gf; - goto_programt &body=get_entry_body(gf); - const jsa_counterexamplet &prototype=ces.front(); - const array_valuest array_values(get_array_values(st, ces)); - const constant_exprt size_expr(get_size_expr(ces.size())); - goto_programt::targett &pos=program.synthetic_variables; - for(const jsa_counterexamplet::value_type &value : prototype) - { - const jsa_counterexamplet::value_type::first_type loc_id=value.first; - const typet &org_type=value.second.type(); - const typet &element_type=replace_struct_by_symbol_type(st, org_type); - const array_typet array_type(element_type, size_expr); - const std::string base_name(get_array_name(loc_id)); - pos=body.insert_after(pos); - declare_jsa_meta_variable(st, pos, base_name, array_type); - const array_valuest::const_iterator array_val=array_values.find(loc_id); - assert(array_values.end() != array_val); - const array_exprt &array_expr=array_val->second; - assert(array_expr.operands().size() == ces.size()); - pos=assign_jsa_meta_variable(st, gf, pos, base_name, array_val->second); - } -} - -void add_array_index(jsa_programt &prog) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - goto_programt::targett &pos=prog.synthetic_variables; - pos=body.insert_after(pos); - const typet type(signed_int_type()); - declare_jsa_meta_variable(st, pos, CE_ARRAY_INDEX, type); - constant_exprt zero=from_integer(0, signed_int_type()); - pos=assign_jsa_meta_variable(st, gf, pos, CE_ARRAY_INDEX, zero); -} - -symbol_exprt get_ce_array_index(const symbol_tablet &st) -{ - return st.lookup(get_cegis_meta_name(CE_ARRAY_INDEX)).symbol_expr(); -} - -void add_ce_goto(jsa_programt &prog, const size_t ces_size) -{ - goto_programt &body=get_entry_body(prog.gf); - goto_programt::targett pos=std::next(prog.property_entailment, 2); - pos=insert_before_preserve_labels(body, pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::ASSIGN; - const symbol_exprt lhs(get_ce_array_index(prog.st)); - const typet &type=lhs.type(); - const plus_exprt inc(lhs, from_integer(1, type), type); - pos->code=code_assignt(lhs, inc); - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::GOTO; - pos->targets.push_back(std::next(prog.synthetic_variables)); - const binary_relation_exprt guard(lhs, ID_lt, get_size_expr(ces_size)); - pos->guard=guard; - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::ASSERT; - pos->guard=false_exprt(); - body.compute_target_numbers(); -} - -const index_exprt get_array_val_expr(const symbol_tablet &st, - const irep_idt &loc) -{ - const std::string index_name(get_cegis_meta_name(CE_ARRAY_INDEX)); - const symbol_exprt index(st.lookup(index_name).symbol_expr()); - const std::string array_name(get_cegis_meta_name(get_array_name(loc))); - const symbol_exprt array(st.lookup(array_name).symbol_expr()); - return index_exprt(array, index); -} - -void assign_ce_values(jsa_programt &prog) -{ - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - for(const goto_programt::targett &pos : prog.counterexample_locations) - { - assert(pos->labels.size() == 1u); - const index_exprt value(get_array_val_expr(st, pos->labels.front())); - switch(pos->type) - { - case ASSIGN: - to_code_assign(pos->code).rhs()=value; - break; - case DECL: - jsa_assign(st, gf, pos, - st.lookup(get_affected_variable(*pos)).symbol_expr(), value); - break; - default: - assert(!"Unsupported counterexample location type."); - } - } -} -} - -void insert_counterexamples(jsa_programt &program, - const jsa_counterexamplest &ces) -{ - assert(!ces.empty()); - assert(ces.front().size() == program.counterexample_locations.size()); - add_array_declarations(program, ces); - add_array_index(program); - add_ce_goto(program, ces.size()); - assign_ce_values(program); -} diff --git a/src/cegis/jsa/learn/insert_counterexample.h b/src/cegis/jsa/learn/insert_counterexample.h deleted file mode 100644 index 19fab3cb363..00000000000 --- a/src/cegis/jsa/learn/insert_counterexample.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_INSERT_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_JSA_LEARN_INSERT_COUNTEREXAMPLE_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param ces - */ -void insert_counterexamples( - class jsa_programt &program, - const jsa_counterexamplest &ces); - -#endif // CPROVER_CEGIS_JSA_LEARN_INSERT_COUNTEREXAMPLE_H diff --git a/src/cegis/jsa/learn/insert_predicates_and_queries.cpp b/src/cegis/jsa/learn/insert_predicates_and_queries.cpp deleted file mode 100644 index 4f226975f5c..00000000000 --- a/src/cegis/jsa/learn/insert_predicates_and_queries.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#define PRED_SIZES "__CPROVER_JSA_PREDICATE_SIZES" - -namespace -{ -goto_programt::targett assume_less_than(goto_programt &body, - goto_programt::targett pos, const exprt &lhs, const size_t max) -{ - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::ASSUME; - const constant_exprt max_expr(from_integer(max, jsa_internal_index_type())); - const binary_relation_exprt size_limit(lhs, ID_le, max_expr); - const exprt min(from_integer(1, jsa_internal_index_type())); - const binary_relation_exprt min_size(lhs, ID_ge, min); - pos->guard=and_exprt(min_size, size_limit); - return pos; -} - -void declare_size_and_prog(jsa_programt &prog, const std::string &prog_name, - const std::string &size_name, - const std::function type_factory, - const size_t max_size) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - goto_programt::targett &pos=prog.synthetic_variables; - pos=body.insert_after(pos); - declare_jsa_meta_variable(st, pos, size_name, jsa_internal_index_type()); - const irep_idt &size_id=get_affected_variable(*pos); - const symbol_exprt sz_expr(st.lookup(size_id).symbol_expr()); - pos=assume_less_than(body, pos, sz_expr, max_size); - pos=body.insert_after(pos); - const constant_exprt array_sz_expr(from_integer(max_size, sz_expr.type())); - declare_jsa_meta_variable(st, pos, prog_name, type_factory(array_sz_expr)); -} -} - -void declare_jsa_predicates(jsa_programt &prog, const size_t max_sz) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - const symbol_exprt preds(st.lookup(JSA_PREDS).symbol_expr()); - const symbol_exprt pred_sizes(st.lookup(PRED_SIZES).symbol_expr()); - const bv_arithmetict bv(to_array_type(preds.type()).size()); - const mp_integer::ullong_t num_preds=bv.to_integer().to_ulong(); - const typet sz_type(signed_int_type()); - const exprt zero(from_integer(0, sz_type)); - const size_t max_pred_size=get_max_pred_size(st); - for(mp_integer::ullong_t i=0; i < num_preds; ++i) - { - goto_programt::targett &pos=prog.synthetic_variables; - std::string base_name(JSA_PRED_PREFIX); - base_name+=std::to_string(i); - const std::string sz_name(base_name + JSA_SIZE_SUFFIX); - declare_size_and_prog(prog, base_name, sz_name, jsa_predicate_type, max_pred_size); - const constant_exprt index(from_integer(i, sz_type)); - const index_exprt preds_elem(preds, index); - const std::string local_pred_name(get_cegis_meta_name(base_name)); - const symbol_exprt &local_pred(st.lookup(local_pred_name).symbol_expr()); - const index_exprt local_preds_elem(local_pred, zero); - pos=jsa_assign(st, gf, pos, preds_elem, address_of_exprt(local_preds_elem)); - const index_exprt pred_sizes_elem(pred_sizes, index); - const symbolt &sz_symb(st.lookup(get_cegis_meta_name(sz_name))); - pos=jsa_assign(st, gf, pos, pred_sizes_elem, sz_symb.symbol_expr()); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - code_function_callt call; - call.function()=st.lookup(JSA_ASSUME_VALID_PRED).symbol_expr(); - call.arguments().push_back(index); - pos->code=call; - } -} - -void declare_jsa_query(jsa_programt &prog, const size_t max_size) -{ - declare_size_and_prog(prog, JSA_QUERY, JSA_QUERY_SZ, jsa_query_type, - get_max_query_size(prog.st)); -} - -void declare_jsa_invariant(jsa_programt &prog, const size_t max_size) -{ - declare_size_and_prog(prog, JSA_INV, JSA_INV_SZ, jsa_invariant_type, 1); -} diff --git a/src/cegis/jsa/learn/insert_predicates_and_queries.h b/src/cegis/jsa/learn/insert_predicates_and_queries.h deleted file mode 100644 index fb6cb745400..00000000000 --- a/src/cegis/jsa/learn/insert_predicates_and_queries.h +++ /dev/null @@ -1,45 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_INSERT_PREDICATES_AND_QUERIES_H -#define CPROVER_CEGIS_JSA_LEARN_INSERT_PREDICATES_AND_QUERIES_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param max_size - */ -void declare_jsa_predicates(class jsa_programt &prog, size_t max_size); - -/** - * @brief - * - * @details - * - * @param prog - * @param max_size - */ -void declare_jsa_query(jsa_programt &prog, size_t max_size); - -/** - * @brief - * - * @details - * - * @param prog - * @param max_size - */ -void declare_jsa_invariant(jsa_programt &prog, size_t max_size); - -#endif // CPROVER_CEGIS_JSA_LEARN_INSERT_PREDICATES_AND_QUERIES_H diff --git a/src/cegis/jsa/learn/instrument_pred_ops.cpp b/src/cegis/jsa/learn/instrument_pred_ops.cpp deleted file mode 100644 index fc72db0f6f0..00000000000 --- a/src/cegis/jsa/learn/instrument_pred_ops.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -bool contains(const std::string &haystack, const char * const needle) -{ - return std::string::npos != haystack.find(needle); -} - -bool is_pred_op_decl(const symbol_tablet &st, const goto_programt::targett &pos) -{ - if(goto_program_instruction_typet::DECL != pos->type) return false; - const std::string &id=id2string(get_affected_variable(*pos)); - if(contains(id, JSA_TMP_PREFIX) || contains(id, JSA_LAMBDA_OP) - || contains(id, JSA_CONSTANT_PREFIX)) return true; - if(contains(id, CPROVER_PREFIX)) return false; - const namespacet ns(st); - const typet lhs(jsa_word_type()); - return type_eq(lhs, st.lookup(id).type, ns); -} -} - -goto_programt::targetst collect_pred_ops(jsa_programt &prog) -{ - const symbol_tablet &st=prog.st; - goto_programt::instructionst &body=get_entry_body(prog.gf).instructions; - const goto_programt::targett end(prog.body.first); - goto_programt::targetst pred_ops; - for(goto_programt::targett it=body.begin(); it != end; ++it) - if(is_pred_op_decl(st, it)) pred_ops.push_back(it); - return pred_ops; -} - -#define PRED_OPS "__CPROVER_JSA_PRED_OPS" -#define JSA_PRED_OP_COUNT "__CPROVER_JSA_PRED_OPS_COUNT" -#define JSA_PRED_RESULT_OP_COUNT "__CPROVER_JSA_PRED_RESULT_OPS_COUNT" - -namespace -{ -void mark_dead(goto_programt &body, goto_programt::targett pos, - const index_exprt &op_elem) -{ - const irep_idt &id=get_affected_variable(*pos); - goto_programt::instructionst &instrs=body.instructions; - const goto_programt::targett end(instrs.end()); - pos=std::find_if(pos, end, [&id](const goto_programt::instructiont &instr) - { return DEAD == instr.type && id == get_affected_variable(instr);}); - if(end == pos) return; - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=jsa_builtin_source_location(); - pos->code=code_assignt(op_elem, from_integer(0, op_elem.type())); -} -} - -void instrument_pred_ops(jsa_programt &prog, const goto_programt::targetst &ops, - pred_op_idst &op_ids, pred_op_idst &const_op_ids) -{ - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - const symbol_exprt pred_ops(st.lookup(PRED_OPS).symbol_expr()); - const symbol_exprt pred_res_ops(st.lookup(JSA_PRED_RES_OPS).symbol_expr()); - const typet sz_type(signed_int_type()); - size_t op_index=0; - size_t res_op_idx=0; - for(const goto_programt::targett &op : ops) - { - const symbol_exprt var(st.lookup(get_affected_variable(*op)).symbol_expr()); - const address_of_exprt var_ptr(var); - const_op_ids.insert(std::make_pair(op_index, var)); - const constant_exprt op_index_expr(from_integer(op_index++, sz_type)); - const index_exprt op_elem(pred_ops, op_index_expr); - mark_dead(body, op, op_elem); - goto_programt::targett pos=jsa_assign(st, gf, op, op_elem, var_ptr); - if(!is_jsa_const(var)) - { - op_ids.insert(std::make_pair(res_op_idx, var)); - const constant_exprt res_op_idx_expr(from_integer(res_op_idx++, sz_type)); - const index_exprt res_op_elem(pred_res_ops, res_op_idx_expr); - mark_dead(body, op, res_op_elem); - pos=jsa_assign(st, gf, pos, res_op_elem, address_of_exprt(var)); - } - if(op == prog.synthetic_variables) prog.synthetic_variables=pos; - } - const symbol_exprt op_count(st.lookup(JSA_PRED_OP_COUNT).symbol_expr()); - const constant_exprt op_value(from_integer(op_index, op_count.type())); - goto_programt::targett &pos=prog.synthetic_variables; - pos=jsa_assign(st, gf, pos, op_count, op_value); - const symbol_exprt res_cnt(st.lookup(JSA_PRED_RESULT_OP_COUNT).symbol_expr()); - const constant_exprt res_value(from_integer(res_op_idx, res_cnt.type())); - pos=jsa_assign(st, gf, pos, res_cnt, res_value); -} - -void instrument_pred_ops(jsa_programt &prog, const goto_programt::targetst &ops) -{ - pred_op_idst op_ids; - pred_op_idst const_op_ids; - instrument_pred_ops(prog, ops, op_ids, const_op_ids); -} diff --git a/src/cegis/jsa/learn/instrument_pred_ops.h b/src/cegis/jsa/learn/instrument_pred_ops.h deleted file mode 100644 index 8188961bfa4..00000000000 --- a/src/cegis/jsa/learn/instrument_pred_ops.h +++ /dev/null @@ -1,54 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_INSTRUMENT_PRED_OPS_H -#define CPROVER_CEGIS_JSA_LEARN_INSTRUMENT_PRED_OPS_H - -#include -#include - -/** - * @brief - * - * @details - * - * @param prog - * @return - */ -goto_programt::targetst collect_pred_ops(class jsa_programt &prog); - -/** - * @brief - * - * @details - * - * @param prog - * @param ops - * @param op_ids - * @param const_op_ids - */ -void instrument_pred_ops( - class jsa_programt &prog, - const goto_programt::targetst &ops, - pred_op_idst &op_ids, - pred_op_idst &const_op_ids); - -/** - * @brief - * - * @details - * - * @param prog - * @param ops - */ -void instrument_pred_ops( - class jsa_programt &prog, - const goto_programt::targetst &ops); - -#endif // CPROVER_CEGIS_JSA_LEARN_INSTRUMENT_PRED_OPS_H diff --git a/src/cegis/jsa/learn/jsa_symex_learn.cpp b/src/cegis/jsa/learn/jsa_symex_learn.cpp deleted file mode 100644 index ecea9feea6a..00000000000 --- a/src/cegis/jsa/learn/jsa_symex_learn.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -jsa_symex_learnt::jsa_symex_learnt(const jsa_programt &program) : - original_program(program) -{ -} - -void jsa_symex_learnt::process(const counterexamplest &counterexamples, - const size_t max_solution_size) -{ - program=original_program; - const goto_programt::targetst pred_ops(collect_pred_ops(program)); - // add_jsa_library(program, max_solution_size, pred_ops); - instrument_pred_ops(program, pred_ops, op_ids, const_op_ids); - insert_jsa_constraint(program, true); - insert_counterexamples(program, counterexamples); - declare_jsa_predicates(program, max_solution_size); - declare_jsa_query(program, max_solution_size); - declare_jsa_invariant(program, max_solution_size); - execute_jsa_learn_programs(program); - remove_returns(program.st, program.gf); - program.gf.update(); -} - -void jsa_symex_learnt::process(const size_t max_solution_size) -{ - const namespacet ns(original_program.st); - counterexamplest counterexamples(1); - counterexamplet &counterexample=counterexamples.front(); - for(const goto_programt::targett &pos : original_program.counterexample_locations) - { - assert(pos->labels.size() == 1u); - const irep_idt &key=pos->labels.front(); - const typet &type=get_affected_type(*pos); - const source_locationt &loc=pos->source_location; - const exprt value(zero_initializer(type, loc, ns)); - counterexample.insert(std::make_pair(key, value)); - } - process(counterexamples, max_solution_size); -} - -void jsa_symex_learnt::set_word_width(const size_t word_width_in_bits) -{ - // XXX: Unsupported -} - -void jsa_symex_learnt::convert(candidatet &result, const goto_tracet &trace, - const size_t max_sz) -{ - result.clear(); - extract_jsa_candidate(result, program, trace, const_op_ids, op_ids, max_sz); - result.max_size=max_sz; -} - -const symbol_tablet &jsa_symex_learnt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &jsa_symex_learnt::get_goto_functions() const -{ - return program.gf; -} - -const jsa_programt &jsa_symex_learnt::get_jsa_program() const -{ - return program; -} - -void jsa_symex_learnt::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) const -{ - print_jsa_solution(os, program, candidate, op_ids, const_op_ids); -} - -std::function jsa_symex_learnt::get_pred_ops_count() const -{ - return [this]() - { return op_ids.size();}; -} - -std::function jsa_symex_learnt::get_const_pred_ops_count() const -{ - return [this]() - { return const_op_ids.size();}; -} diff --git a/src/cegis/jsa/learn/jsa_symex_learn.h b/src/cegis/jsa/learn/jsa_symex_learn.h deleted file mode 100644 index 18de6d242e5..00000000000 --- a/src/cegis/jsa/learn/jsa_symex_learn.h +++ /dev/null @@ -1,150 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_LEARN_JSA_SYMEX_LEARN_H -#define CPROVER_CEGIS_JSA_LEARN_JSA_SYMEX_LEARN_H - -#include -#include - -#include - -#include -#include -#include -#include - -/** - * @brief - * - * @details - */ -class jsa_symex_learnt -{ - const jsa_programt &original_program; - jsa_programt program; - pred_op_idst op_ids; - pred_op_idst const_op_ids; -public: - typedef jsa_counterexamplet counterexamplet; - typedef jsa_counterexamplest counterexamplest; - typedef jsa_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit jsa_symex_learnt(const jsa_programt &program); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process( - const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param max_solution_size - */ - void process(size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits); - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert( - candidatet ¤t_candidate, - const class goto_tracet &trace, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @return - */ - const jsa_programt &get_jsa_program() const; - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate( - messaget::mstreamt &os, - const candidatet &candidate) const; - - /** - * @brief - * - * @details - * - * @return - */ - std::function get_pred_ops_count() const; - - /** - * @brief - * - * @details - * - * @return - */ - std::function get_const_pred_ops_count() const; -}; - -#endif // CPROVER_CEGIS_JSA_LEARN_JSA_SYMEX_LEARN_H diff --git a/src/cegis/jsa/options/jsa_program.cpp b/src/cegis/jsa/options/jsa_program.cpp deleted file mode 100644 index d7d6cc8870e..00000000000 --- a/src/cegis/jsa/options/jsa_program.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -jsa_programt::jsa_programt() -{ -} - -namespace -{ -jsa_programt &assign(jsa_programt &lhs, const jsa_programt &rhs) -{ - lhs.gf.clear(); - lhs.gf.copy_from(rhs.gf); - goto_programt &new_body=get_entry_body(lhs.gf); - const goto_programt &old_body=get_entry_body(rhs.gf); - const target_copy_helpert copy(old_body, new_body); - copy(lhs.inductive_step_renondets, rhs.inductive_step_renondets); - copy(lhs.counterexample_locations, rhs.counterexample_locations); - lhs.synthetic_variables=copy(rhs.synthetic_variables); - lhs.base_case=copy(rhs.base_case); - lhs.inductive_assumption=copy(rhs.inductive_assumption); - lhs.inductive_step=copy(rhs.inductive_step); - lhs.property_entailment=copy(rhs.property_entailment); - lhs.body.first=copy(rhs.body.first); - lhs.body.second=copy(rhs.body.second); - lhs.guard=rhs.guard; - return lhs; -} -} - -jsa_programt::jsa_programt(const jsa_programt &other) : - st(other.st) -{ - assign(*this, other); -} - -jsa_programt::jsa_programt(const symbol_tablet &st, const goto_functionst &gf) : - st(st) -{ - this->gf.copy_from(gf); -} - -jsa_programt::~jsa_programt() -{ -} - -jsa_programt &jsa_programt::operator =(const jsa_programt &other) -{ - st=other.st; - return assign(*this, other); -} diff --git a/src/cegis/jsa/options/jsa_program.h b/src/cegis/jsa/options/jsa_program.h deleted file mode 100644 index c9f0001686d..00000000000 --- a/src/cegis/jsa/options/jsa_program.h +++ /dev/null @@ -1,132 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_H -#define CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_H - -#include - -/** - * @brief - * - * @details JSA program for single-loop stream refactorings. - */ -class jsa_programt -{ -public: - symbol_tablet st; - goto_functionst gf; - - /** - * @brief - * - * @details All variables which get non-determinised at the inductive step. - */ - goto_programt::targetst inductive_step_renondets; - - /** - * @brief - * - * @details All variable locations to be considered in counterexamles (including loop bodies). - */ - goto_programt::targetst counterexample_locations; - - /** - * @brief - * - * @details Insertion position for synthetic variables (auto-generated constants, temps) - */ - goto_programt::targett synthetic_variables; - - /** - * @brief - * - * @details Base case assertion meta variable. - */ - goto_programt::targett base_case; - - /** - * @brief - * - * @details Invariant assumption meta variable. - */ - goto_programt::targett inductive_assumption; - - /** - * @brief - * - * @details Inductive step assertion meta variable. - */ - goto_programt::targett inductive_step; - - /** - * @brief - * - * @details Property entailment meta variable. - */ - goto_programt::targett property_entailment; - - /** - * @brief - * - * @details Expression of removed loop guard. - */ - exprt guard; - - /** - * @brief - * - * @details Body range from first to second (exclusive). - */ - std::pair body; - - /** - * @brief - * - * @details - */ - jsa_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - jsa_programt(const jsa_programt &other); - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - jsa_programt(const symbol_tablet &st, const goto_functionst &gf); - - /** - * @brief - * - * @details - */ - ~jsa_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - jsa_programt &operator=(const jsa_programt &other); -}; - -#endif // CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_H diff --git a/src/cegis/jsa/options/jsa_program_info.cpp b/src/cegis/jsa/options/jsa_program_info.cpp deleted file mode 100644 index d2464b6fead..00000000000 --- a/src/cegis/jsa/options/jsa_program_info.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include - -size_t to_size(const exprt &expr) -{ - const bv_arithmetict bv(expr); - return static_cast(bv.to_integer().to_long()); -} - -size_t get_size(const symbol_tablet &st, const char * const id) -{ - return to_size(to_array_type(st.lookup(id).type).size()); -} - -#define PRED_RELAY "__CPROVER_JSA_MAX_PRED_SIZE_RELAY" - -size_t get_max_pred_size(const symbol_tablet &st) -{ - return get_size(st, PRED_RELAY); -} - -#define QUERY_RELAY "__CPROVER_JSA_MAX_QUERY_SIZE_RELAY" - -size_t get_max_query_size(const symbol_tablet &st) -{ - return get_size(st, QUERY_RELAY); -} - -size_t get_max_inv_size() -{ - return 1; -} - -size_t get_pred_instruction_set_size() -{ - return __CPROVER_JSA_NUM_PRED_INSTRUCTIONS; -} - -size_t get_query_instruction_set_size() -{ - return __CPROVER_JSA_NUM_QUERY_INSTRUCTIONS; -} - -size_t get_invariant_instruction_set_size() -{ - return __CPROVER_JSA_NUM_INV_INSTRUCTIONS; -} - -size_t get_num_jsa_preds(const symbol_tablet &st) -{ - return get_size(st, JSA_PREDS); -} - -#define MAX_IT "__CPROVER_JSA_MAX_ITERATORS_RELAY" - -size_t get_max_iterators(const symbol_tablet &st) -{ - return get_size(st, MAX_IT); -} - -#define MAX_LIST "__CPROVER_JSA_MAX_LISTS_RELAY" - -size_t get_max_lists(const symbol_tablet &st) -{ - return get_size(st, MAX_LIST); -} diff --git a/src/cegis/jsa/options/jsa_program_info.h b/src/cegis/jsa/options/jsa_program_info.h deleted file mode 100644 index 95df2352f25..00000000000 --- a/src/cegis/jsa/options/jsa_program_info.h +++ /dev/null @@ -1,127 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_INFO_H -#define CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_INFO_H - -#include - -/** - * @brief - * - * @details - */ -#define JSA_PREDS "__CPROVER_JSA_PREDICATES" - -/** - * @brief - * - * @details - * - * @param st - * @param symbol_name - * - * @return - */ -size_t get_array_size( - const class symbol_tablet &st, - const char * const symbol_name); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -size_t get_max_pred_size(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -size_t get_max_query_size(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @return - */ -size_t get_max_inv_size(); - -/** - * @brief - * - * @details - * - * @return - */ -size_t get_pred_instruction_set_size(); - -/** - * @brief - * - * @details - * - * @return - */ -size_t get_query_instruction_set_size(); - -/** - * @brief - * - * @details - * - * @return - */ -size_t get_invariant_instruction_set_size(); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -size_t get_num_jsa_preds(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -size_t get_max_iterators(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * - * @return - */ -size_t get_max_lists(const symbol_tablet &st); - -#endif // CPROVER_CEGIS_JSA_OPTIONS_JSA_PROGRAM_INFO_H diff --git a/src/cegis/jsa/preprocessing/add_constraint_meta_variables.cpp b/src/cegis/jsa/preprocessing/add_constraint_meta_variables.cpp deleted file mode 100644 index da4d98bf48e..00000000000 --- a/src/cegis/jsa/preprocessing/add_constraint_meta_variables.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include - -namespace -{ -#if 0 -symbolt &create_jsa_symbol(symbol_tablet &st, const std::string &full_name, - const typet &type) -{ - symbolt new_symbol; - new_symbol.name=full_name; - new_symbol.type=type; - new_symbol.base_name=full_name; - new_symbol.pretty_name=new_symbol.base_name; - new_symbol.location=jsa_builtin_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=JSA_MODULE; - new_symbol.is_thread_local=true; - new_symbol.is_static_lifetime=false; - new_symbol.is_file_local=true; - new_symbol.is_lvalue=true; - assert(!st.add(new_symbol)); - return st.lookup(new_symbol.name); -} -#endif - -void declare_lambda(jsa_programt &p, goto_programt &body) -{ - const goto_programt::targett pos=body.insert_after(body.instructions.begin()); - const typet type(jsa_word_type()); - declare_jsa_meta_variable(p.st, pos, JSA_LAMBDA_OP, type); -} -} - -void declare_jsa_meta_variable(symbol_tablet &st, - const goto_programt::targett &decl, const std::string &base_name, - const typet &type) -{ - const std::string symbol_name(get_cegis_meta_name(base_name)); - create_cegis_symbol(st, symbol_name, type); - const symbol_exprt symbol(symbol_name, type); - decl->type=goto_program_instruction_typet::DECL; - decl->code=code_declt(symbol); - decl->source_location=jsa_builtin_source_location(); -} - -goto_programt::targett assign_jsa_meta_variable(const symbol_tablet &st, - goto_functionst &gf, const goto_programt::targett &pos, - const std::string &base_name, const exprt &expr_value) -{ - const std::string name(get_cegis_meta_name(base_name)); - const symbol_exprt lhs(st.lookup(name).symbol_expr()); - return jsa_assign(st, gf, pos, lhs, expr_value); -} - -goto_programt::targett jsa_assign(const symbol_tablet &st, goto_functionst &gf, - const goto_programt::targett &pos, const exprt &lhs, const exprt &rhs) -{ - const source_locationt loc(jsa_builtin_source_location()); - return cegis_assign(st, gf, pos, lhs, rhs, loc); -} - -void add_jsa_constraint_meta_variables(jsa_programt &p) -{ - symbol_tablet &st=p.st; - goto_programt &body=get_entry_body(p.gf); - const typet type(c_bool_type()); - declare_lambda(p, body); - p.base_case=insert_before_preserve_labels(body, p.body.first); - declare_jsa_meta_variable(st, p.base_case, JSA_BASE_CASE, type); - p.inductive_assumption=body.insert_after(p.base_case); - declare_jsa_meta_variable(st, p.inductive_assumption, JSA_IND_ASSUME, type); - p.inductive_step=insert_before_preserve_labels(body, p.body.second); - declare_jsa_meta_variable(st, p.inductive_step, JSA_IND_STEP, type); - p.property_entailment=insert_before_preserve_labels(body, p.body.second); - declare_jsa_meta_variable(st, p.property_entailment, JSA_PROP_ENTAIL, type); - p.body.second=p.property_entailment; -} diff --git a/src/cegis/jsa/preprocessing/add_constraint_meta_variables.h b/src/cegis/jsa/preprocessing/add_constraint_meta_variables.h deleted file mode 100644 index f9268c01bae..00000000000 --- a/src/cegis/jsa/preprocessing/add_constraint_meta_variables.h +++ /dev/null @@ -1,75 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_ADD_CONSTRAINT_META_VARIABLES_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_ADD_CONSTRAINT_META_VARIABLES_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param decl - * @param base_name - */ -void declare_jsa_meta_variable( - symbol_tablet &st, - const goto_programt::targett &decl, - const std::string &base_name, - const typet &type); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param pos - * @param base_name - * @param expr_value - */ -goto_programt::targett assign_jsa_meta_variable( - const symbol_tablet &st, - goto_functionst &gf, - const goto_programt::targett &pos, - const std::string &base_name, - const exprt &expr_value); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param pos - * @param lhs - * @param rhs - */ -goto_programt::targett jsa_assign( - const symbol_tablet &st, - goto_functionst &gf, - const goto_programt::targett &pos, - const exprt &lhs, - const exprt &rhs); - -/** - * @brief - * - * @details - * - * @param prog - */ -void add_jsa_constraint_meta_variables(class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_ADD_CONSTRAINT_META_VARIABLES_H diff --git a/src/cegis/jsa/preprocessing/add_synthesis_library.cpp b/src/cegis/jsa/preprocessing/add_synthesis_library.cpp deleted file mode 100644 index 9982ebc86ff..00000000000 --- a/src/cegis/jsa/preprocessing/add_synthesis_library.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define CPROVER_INIT "__CPROVER_initialize" -#define JSA_LIB "__CPROVER_jsa_synthesise" - -namespace -{ -void add_placenholder(symbol_tablet &st, const irep_idt &id) -{ - if(st.has_symbol(id)) return; - symbolt symbol; - symbol.name=id; - symbol.base_name=symbol.name; - symbol.pretty_name=symbol.base_name; - symbol.type=signed_int_type(); - symbol.is_lvalue=true; - symbol.mode=ID_C; - symbol.module=JSA_MODULE; - st.add(symbol); -} - -std::string get_array_size(const typet &type) -{ - const irep_idt &type_id=type.id(); - if(ID_array == type_id) - { - const bv_arithmetict bv(to_array_type(type).size()); - return std::to_string(bv.to_integer().to_ulong()); - } - assert(ID_pointer == type_id); - return "0u"; -} - -std::string get_sizes(const symbol_tablet &st) -{ - const namespacet ns(st); - const typet &type=ns.follow(st.lookup(JSA_HEAP_TAG).type); - const struct_typet &struct_type=to_struct_type(type); - std::string sizes("#define __CPROVER_JSA_MAX_CONCRETE_NODES "); - sizes+=get_array_size(struct_type.get_component("concrete_nodes").type()); - sizes+="\n#define __CPROVER_JSA_MAX_ABSTRACT_NODES "; - sizes+=get_array_size(struct_type.get_component("abstract_nodes").type()); - sizes+="\n#define __CPROVER_JSA_MAX_ITERATORS "; - sizes+=get_array_size(struct_type.get_component("iterators").type()); - sizes+="\n#define __CPROVER_JSA_MAX_LISTS "; - sizes+=get_array_size(struct_type.get_component("list_head_nodes").type()); - return sizes+='\n'; -} - -std::vector get_functions(const symbol_tablet &st) -{ - std::vector functions; - for(const symbol_tablet::symbolst::value_type &symbol : st.symbols) - if(ID_code == symbol.second.type.id()) functions.push_back(symbol.first); - return functions; -} - -bool is_jsa_constant(const symbolt &symbol) -{ - if(!symbol.is_static_lifetime) return false; - const std::string &name=id2string(symbol.name); - return std::string::npos != name.find(JSA_CONSTANT_PREFIX) - || std::string::npos != name.find(JSA_STATIC_META_VAR_PREFIX); -} - -void zero_new_global_vars(const symbol_tablet &st, goto_functionst &gf) -{ - goto_functionst::function_mapt &fm=gf.function_map; - const goto_functionst::function_mapt::iterator it=fm.find(CPROVER_INIT); - assert(fm.end() != it); - goto_functionst::goto_functiont &init=it->second; - assert(init.body_available()); - goto_programt &body=init.body; - goto_programt::targett pos=std::prev(body.instructions.end(), 2); - const source_locationt loc(jsa_builtin_source_location()); - const namespacet ns(st); - for(const symbol_tablet::symbolst::value_type &symbol : st.symbols) - if(is_jsa_constant(symbol.second)) - { - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=loc; - const symbol_exprt lhs(ns.lookup(symbol.first).symbol_expr()); - const exprt rhs(zero_initializer(lhs.type(), loc, ns)); - pos->code=code_assignt(lhs, rhs); - } -} - -bool is_const(const symbol_tablet &st, const goto_programt::instructiont &instr) -{ - return is_jsa_const(st.lookup(get_affected_variable(instr)).symbol_expr()); -} -} - -void add_jsa_library(jsa_programt &prog, const size_t max_sz, - const goto_programt::targetst &pred_op_locations) -{ - std::string library_text("#define JSA_SYNTHESIS_H_"); - library_text+="\n#define __CPROVER_JSA_MAX_QUERY_SIZE "; - library_text+=std::to_string(max_sz + 1); - library_text+="\n#define __CPROVER_JSA_MAX_PRED_SIZE "; - library_text+=std::to_string(max_sz); - library_text+="\n#define __CPROVER_JSA_NUM_PRED_OPS "; - const size_t num_pred_ops=pred_op_locations.size(); - library_text+=std::to_string(num_pred_ops); - symbol_tablet &st=prog.st; - const size_t num_result_pred_ops=std::count_if(pred_op_locations.begin(), - pred_op_locations.end(), [&st](const goto_programt::targett &target) - { return !is_const(st, *target);}); - library_text+="\n#define __CPROVER_JSA_NUM_PRED_RESULT_OPS "; - library_text+=std::to_string(num_result_pred_ops); - library_text+='\n'; - library_text+=get_sizes(prog.st); - const std::set functions={ JSA_LIB }; - symbol_tablet blank; - add_placenholder(blank, JSA_LIB); - library_text+=get_cprover_library_text(functions, blank); - blank.clear(); - null_message_handlert msg; - add_library(library_text, blank, msg); - - assert(!linking(st, blank, msg)); - goto_functionst &gf=prog.gf; - const std::vector new_funcs(get_functions(blank)); - for(const irep_idt &func_name : new_funcs) - goto_convert(func_name, st, gf, msg); - zero_new_global_vars(blank, gf); - gf.compute_loop_numbers(); - gf.update(); -} diff --git a/src/cegis/jsa/preprocessing/add_synthesis_library.h b/src/cegis/jsa/preprocessing/add_synthesis_library.h deleted file mode 100644 index 95d50d000d5..00000000000 --- a/src/cegis/jsa/preprocessing/add_synthesis_library.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_ADD_SYNTHESIS_LIBRARY_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_ADD_SYNTHESIS_LIBRARY_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param max_sz - * @param pred_op_locations - */ -void add_jsa_library( - class jsa_programt &prog, - size_t max_sz, - const goto_programt::targetst &pred_op_locations); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_ADD_SYNTHESIS_LIBRARY_H diff --git a/src/cegis/jsa/preprocessing/clone_heap.cpp b/src/cegis/jsa/preprocessing/clone_heap.cpp deleted file mode 100644 index 46d3290b75a..00000000000 --- a/src/cegis/jsa/preprocessing/clone_heap.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_heap_type(const typet &type) -{ - if(ID_symbol != type.id()) return false; - return to_symbol_type(type).get_identifier() == JSA_HEAP_TAG; -} - -bool is_heap(const goto_programt::instructiont &instr) -{ - if(goto_program_instruction_typet::DECL != instr.type) return false; - return is_heap_type(to_code_decl(instr.code).symbol().type()); -} -} - -const symbol_exprt &get_user_heap(const goto_functionst &gf) -{ - const goto_programt::instructionst &i=get_entry_body(gf).instructions; - const goto_programt::const_targett end(i.end()); - const goto_programt::const_targett p=std::find_if(i.begin(), end, is_heap); - assert(end != p); - return to_symbol_expr(to_code_decl(p->code).symbol()); -} - -symbol_exprt get_queried_heap(const symbol_tablet &st) -{ - return st.lookup(get_cegis_meta_name(JSA_QUERIED_HEAP)).symbol_expr(); -} - -symbol_exprt get_org_heap(const symbol_tablet &st) -{ - return st.lookup(get_cegis_meta_name(JSA_ORG_HEAP)).symbol_expr(); -} - -void clone_heap(jsa_programt &prog) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=prog.base_case; - pos=insert_before_preserve_labels(body, pos); - const symbol_typet heap_type(jsa_heap_type()); - declare_jsa_meta_variable(st, pos, JSA_QUERIED_HEAP, heap_type); - jsa_assign(st, gf, pos, get_queried_heap(st), get_user_heap(gf)); - pos=insert_before_preserve_labels(body, prog.inductive_assumption); - declare_jsa_meta_variable(st, pos, JSA_ORG_HEAP, heap_type); - pos=jsa_assign(st, gf, pos, get_org_heap(st), get_user_heap(gf)); - const side_effect_expr_nondett nondet_heap(heap_type); - pos=jsa_assign(st, gf, pos, get_user_heap(gf), nondet_heap); - pos=assume_valid_heap(st, body, pos, address_of_exprt(get_user_heap(gf))); - jsa_assign(st, gf, pos, get_queried_heap(st), get_org_heap(st)); - pos=jsa_assign(st, gf, prog.inductive_assumption, get_queried_heap(st), get_org_heap(st)); -} - -#define VALID_LIST JSA_PREFIX "assume_valid_list" -// #define VALID_IT JSA_PREFIX "assume_valid_iterator" -#define VALID_IT JSA_PREFIX "assume_valid_invariant_iterator" // XXX: TODO: Find a cleaner way. - -namespace -{ -std::vector collect(goto_programt::targett first, - const goto_programt::targett &last, - const std::function pred) -{ - std::vector symbols; - for(; first != last; ++first) - { - if(goto_program_instruction_typet::DECL != first->type) continue; - const symbol_exprt symb(to_symbol_expr(to_code_decl(first->code).symbol())); - if(pred(symb.get_identifier())) symbols.push_back(symb); - } - return symbols; -} - -goto_programt::targett call_assume(const symbol_tablet &st, - const char * const type, const exprt &heap, const exprt &arg, - goto_programt &body, const goto_programt::targett &pos) -{ - const goto_programt::targett assume=body.insert_after(pos); - assume->source_location=jsa_builtin_source_location(); - assume->type=goto_program_instruction_typet::FUNCTION_CALL; - code_function_callt call; - call.function()=st.lookup(type).symbol_expr(); - call.arguments().push_back(heap); - call.arguments().push_back(arg); - assume->code=call; - return assume; -} - -goto_programt::targett assume_lists_and_its_valid(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, const exprt &heap_ptr) -{ - const goto_programt::targett first=body.instructions.begin(); - const std::vector its(collect(first, pos, is_jsa_iterator)); - for(const symbol_exprt &it : its) - pos=call_assume(st, VALID_IT, heap_ptr, it, body, pos); - const std::vector lists(collect(first, pos, is_jsa_list)); - for(const symbol_exprt &list : lists) - pos=call_assume(st, VALID_LIST, heap_ptr, list, body, pos); - return pos; -} -} - -#define VALID_HEAP JSA_PREFIX "assume_valid_heap" - -goto_programt::targett assume_valid_heap(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, const exprt &heap_ptr) -{ - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - code_function_callt call; - call.function()=st.lookup(VALID_HEAP).symbol_expr(); - call.arguments().push_back(heap_ptr); - pos->code=call; - return assume_lists_and_its_valid(st, body, pos, heap_ptr); -} diff --git a/src/cegis/jsa/preprocessing/clone_heap.h b/src/cegis/jsa/preprocessing/clone_heap.h deleted file mode 100644 index cad2c8360c7..00000000000 --- a/src/cegis/jsa/preprocessing/clone_heap.h +++ /dev/null @@ -1,70 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_CLONE_HEAP_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_CLONE_HEAP_H - -#include - -/** - * @brief - * - * @details - * - * @param gf - * @return - */ -const class symbol_exprt &get_user_heap(const class goto_functionst &gf); - -/** - * @brief - * - * @details - * - * @param st - * @return - */ -symbol_exprt get_queried_heap(const class symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param st - * @return - */ -symbol_exprt get_org_heap(const symbol_tablet &st); - -/** - * @brief - * - * @details - * - * @param prog - */ -void clone_heap(class jsa_programt &prog); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param heap_ptr - */ -goto_programt::targett assume_valid_heap( - const symbol_tablet &st, - goto_programt &body, - goto_programt::targett pos, - const exprt &heap_ptr); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_CLONE_HEAP_H diff --git a/src/cegis/jsa/preprocessing/collect_variables.cpp b/src/cegis/jsa/preprocessing/collect_variables.cpp deleted file mode 100644 index 0979b39890d..00000000000 --- a/src/cegis/jsa/preprocessing/collect_variables.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include - -namespace -{ -bool is_meta(const goto_programt::const_targett pos) -{ - const std::string &name=id2string(get_affected_variable(*pos)); - if(is_jsa_list(name) || is_jsa_iterator(name)) return false; - return contains(name, CPROVER_PREFIX) || is_return_value_name(name); -} - -bool is_const(const symbol_exprt &symbol_expr) -{ - return symbol_expr.type().get_bool(ID_C_constant); -} -} - -void add_inductive_step_renondets(jsa_programt &prog) -{ - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt::instructionst &body=get_entry_body(gf).instructions; - const goto_programt::targett last=prog.base_case; - goto_programt::targett pos=prog.base_case; - for(goto_programt::targett it=body.begin(); it != last; ++it) - { - if(goto_program_instruction_typet::DECL != it->type) continue; - const irep_idt &id=get_affected_variable(*it); - if(is_meta(it)) continue; - const symbol_exprt symbol(st.lookup(id).symbol_expr()); - if(is_const(symbol)) continue; - const typet &type=symbol.type(); - pos=jsa_assign(st, gf, pos, symbol, side_effect_expr_nondett(type)); - prog.inductive_step_renondets.push_back(pos); - } -} - -#define CE_MARKER_PREFIX JSA_PRED_PREFIX "ce_marker_" - -void collect_counterexample_vars(jsa_programt &prog) -{ - goto_programt::targetst &locs=prog.counterexample_locations; - goto_programt &body=get_entry_body(prog.gf); - collect_counterexample_locations(locs, CE_MARKER_PREFIX, body, is_meta); -} diff --git a/src/cegis/jsa/preprocessing/collect_variables.h b/src/cegis/jsa/preprocessing/collect_variables.h deleted file mode 100644 index 434600639a4..00000000000 --- a/src/cegis/jsa/preprocessing/collect_variables.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_COLLECT_VARIABLES_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_COLLECT_VARIABLES_H - -/** - * @brief - * - * @details - * - * @param - */ -void add_inductive_step_renondets(class jsa_programt &prog); - -/** - * @brief - * - * @details - * - * @param - */ -void collect_counterexample_vars(jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_COLLECT_VARIABLES_H diff --git a/src/cegis/jsa/preprocessing/create_temp_variables.cpp b/src/cegis/jsa/preprocessing/create_temp_variables.cpp deleted file mode 100644 index 8d0503c1c4d..00000000000 --- a/src/cegis/jsa/preprocessing/create_temp_variables.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include - -void create_jsa_temp_variables(jsa_programt &prog, const size_t max_size) -{ - goto_programt::targett pos=prog.synthetic_variables; - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - const std::string tmp_prefix(JSA_TMP_PREFIX); - const typet type(jsa_word_type()); - for(size_t i=0; i < max_size; ++i) - { - pos=body.insert_after(pos); - const std::string base_name(tmp_prefix + std::to_string(i)); - declare_jsa_meta_variable(st, pos, base_name, type); - pos=assign_jsa_meta_variable(st, gf, pos, base_name, from_integer(0, type)); - } - prog.synthetic_variables=pos; -} diff --git a/src/cegis/jsa/preprocessing/create_temp_variables.h b/src/cegis/jsa/preprocessing/create_temp_variables.h deleted file mode 100644 index a2024748a95..00000000000 --- a/src/cegis/jsa/preprocessing/create_temp_variables.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_CREATE_TEMP_VARIABLES_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_CREATE_TEMP_VARIABLES_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param max_size - */ -void create_jsa_temp_variables(class jsa_programt &prog, size_t max_size); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_CREATE_TEMP_VARIABLES_H diff --git a/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.cpp b/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.cpp deleted file mode 100644 index d0dbbe10bbd..00000000000 --- a/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -namespace -{ -std::string get_name(size_t index) -{ - std::string name(JSA_CONSTANT_PREFIX); - return name+=integer2string(index); -} -} - -goto_programt::targett default_jsa_constant_strategy(symbol_tablet &st, - goto_functionst &gf) -{ - const std::vector literals(collect_integer_literals(st, gf)); - const typet word_type(jsa_word_type()); - size_t const_index=0u; - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=body.instructions.begin(); - for(const constant_exprt &expr : literals) - { - mp_integer value; - to_integer(expr, value); - const constant_exprt expr_value(from_integer(value, word_type)); - const std::string base_name(get_name(const_index++)); - pos=body.insert_after(pos); - declare_jsa_meta_variable(st, pos, base_name, expr_value.type()); - pos=assign_jsa_meta_variable(st, gf, pos, base_name, expr_value); - } - return pos; -} diff --git a/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.h b/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.h deleted file mode 100644 index f6170ca01ba..00000000000 --- a/src/cegis/jsa/preprocessing/default_jsa_constant_strategy.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_DEFAULT_JSA_CONSTANT_STRATEGY_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_DEFAULT_JSA_CONSTANT_STRATEGY_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -goto_programt::targett default_jsa_constant_strategy( - class symbol_tablet &st, - class goto_functionst &gf); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_DEFAULT_JSA_CONSTANT_STRATEGY_H diff --git a/src/cegis/jsa/preprocessing/inline_user_program.cpp b/src/cegis/jsa/preprocessing/inline_user_program.cpp deleted file mode 100644 index 6e492acf569..00000000000 --- a/src/cegis/jsa/preprocessing/inline_user_program.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include - -namespace -{ -bool is_user_function(const irep_idt &name, - const goto_functionst::goto_functiont &func) -{ - if(std::string::npos != id2string(name).find(id2string(CPROVER_PREFIX))) - return false; - if(!func.body_available()) return false; - const goto_programt::instructionst &instrs=func.body.instructions; - if(instrs.empty()) return false; - return !is_builtin(instrs.front().source_location); -} - -void mark_user_function(const irep_idt &name, - goto_functionst::goto_functiont &func) -{ - if(is_user_function(name, func)) func.type.set_inlined(true); -} -} - -void inline_jsa_user_program(const symbol_tablet &st, goto_functionst &gf) -{ - for(goto_functionst::function_mapt::value_type &f : gf.function_map) - mark_user_function(f.first, f.second); - - const namespacet ns(st); - null_message_handlert msg; - goto_partial_inline(gf, ns, msg, 0); -} diff --git a/src/cegis/jsa/preprocessing/inline_user_program.h b/src/cegis/jsa/preprocessing/inline_user_program.h deleted file mode 100644 index 6e732f321d8..00000000000 --- a/src/cegis/jsa/preprocessing/inline_user_program.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_INLINE_USER_PROGRAM_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_INLINE_USER_PROGRAM_H - -/** - * @brief - * - * @details - * - * @param st - * @param gf - */ -void inline_jsa_user_program( - const class symbol_tablet &st, - class goto_functionst &gf); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_INLINE_USER_PROGRAM_H diff --git a/src/cegis/jsa/preprocessing/jsa_preprocessing.cpp b/src/cegis/jsa/preprocessing/jsa_preprocessing.cpp deleted file mode 100644 index 433f8a3ef38..00000000000 --- a/src/cegis/jsa/preprocessing/jsa_preprocessing.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -jsa_preprocessingt::jsa_preprocessingt(const optionst &options, - const symbol_tablet &st, const goto_functionst &gf) : - options(options), original_program(st, gf) -{ -} - -jsa_preprocessingt::~jsa_preprocessingt() -{ -} - -void jsa_preprocessingt::operator()() -{ - goto_functionst &gf=original_program.gf; - symbol_tablet &st=original_program.st; - inline_user_program(st, gf); - remove_loop(original_program); - original_program.synthetic_variables=default_jsa_constant_strategy(st, gf); - add_jsa_constraint_meta_variables(original_program); - add_inductive_step_renondets(original_program); - clone_heap(original_program); - collect_counterexample_vars(original_program); - gf.update(); -} - -void jsa_preprocessingt::operator()(const size_t max_length) -{ - current_program=original_program; - goto_functionst &gf=current_program.gf; - create_jsa_temp_variables(current_program, max_length); - add_zero_jsa_temps_to_pred_exec(current_program); - gf.update(); -} - -size_t jsa_preprocessingt::get_min_solution_size() const -{ - return 1u; -} - -const jsa_programt &jsa_preprocessingt::get_jsa_program() const -{ - return current_program; -} diff --git a/src/cegis/jsa/preprocessing/jsa_preprocessing.h b/src/cegis/jsa/preprocessing/jsa_preprocessing.h deleted file mode 100644 index 0d9bf4d7ad9..00000000000 --- a/src/cegis/jsa/preprocessing/jsa_preprocessing.h +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_JSA_PREPROCESSING_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_JSA_PREPROCESSING_H - -#include - -/** - * @brief - * - * @details - */ -class jsa_preprocessingt -{ - const class optionst &options; - jsa_programt original_program; - jsa_programt current_program; -public: - /** - * @brief - * - * @details - * - * @param options - * @param st - * @param gf - */ - jsa_preprocessingt( - const optionst &options, - const symbol_tablet &st, - const goto_functionst &gf); - - /** - * @brief - * - * @details - */ - ~jsa_preprocessingt(); - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_length - */ - void operator()(size_t max_length); - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - * - * @return - */ - const jsa_programt &get_jsa_program() const; -}; - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_JSA_PREPROCESSING_H diff --git a/src/cegis/jsa/preprocessing/remove_loop.cpp b/src/cegis/jsa/preprocessing/remove_loop.cpp deleted file mode 100644 index 9469133750c..00000000000 --- a/src/cegis/jsa/preprocessing/remove_loop.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -#include -#include - -void remove_loop(jsa_programt &p) -{ - goto_programt::instructionst &b=get_entry_body(p.gf).instructions; - auto pred=std::mem_fn(&goto_programt::instructiont::is_backwards_goto); - const goto_programt::targett bw_goto=std::find_if(b.begin(), b.end(), pred); - assert(b.end() != bw_goto); - assert(b.end() == std::find_if(std::next(bw_goto), b.end(), pred)); - goto_programt::targett body_begin; - goto_programt::targett body_end; - invariant_remove_loop(p.st, b, bw_goto, p.guard, p.body.first, p.body.second); -} diff --git a/src/cegis/jsa/preprocessing/remove_loop.h b/src/cegis/jsa/preprocessing/remove_loop.h deleted file mode 100644 index 53c3138952f..00000000000 --- a/src/cegis/jsa/preprocessing/remove_loop.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_PREPROCESSING_REMOVE_LOOP_H -#define CPROVER_CEGIS_JSA_PREPROCESSING_REMOVE_LOOP_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void remove_loop(class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_PREPROCESSING_REMOVE_LOOP_H diff --git a/src/cegis/jsa/value/default_solution.cpp b/src/cegis/jsa/value/default_solution.cpp deleted file mode 100644 index d11641546ac..00000000000 --- a/src/cegis/jsa/value/default_solution.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -jsa_solutiont default_jsa_solution(const jsa_programt &prog) -{ - jsa_genetic_solutiont result; - result.fitness=0; - const jsa_genetic_solutiont::invariantt::value_type inv={ 0 }; - result.invariant.push_back(inv); - jsa_genetic_solutiont::predicatet pred; - const jsa_genetic_solutiont::predicatet::value_type pred_instr={ 0, 0, 0, 0 }; - pred.push_back(pred_instr); - result.predicates.push_back(pred); - const jsa_genetic_solutiont::queryt::value_type query_prefix={ 0, 0, 0 }; - const jsa_genetic_solutiont::queryt::value_type query_instr={ FILTER, 0, __CPROVER_jsa_null }; - result.query.push_back(query_prefix); - result.query.push_back(query_instr); - return convert(result, prog); -} diff --git a/src/cegis/jsa/value/default_solution.h b/src/cegis/jsa/value/default_solution.h deleted file mode 100644 index d8678ad23bc..00000000000 --- a/src/cegis/jsa/value/default_solution.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_DEFAULT_SOLUTION_H -#define CPROVER_CEGIS_JSA_VALUE_DEFAULT_SOLUTION_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * - * @return - */ -jsa_solutiont default_jsa_solution(const class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_VALUE_DEFAULT_SOLUTION_H diff --git a/src/cegis/jsa/value/jsa_counterexample.h b/src/cegis/jsa/value/jsa_counterexample.h deleted file mode 100644 index f16a6267039..00000000000 --- a/src/cegis/jsa/value/jsa_counterexample.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_H - -#include -#include - -#include - -/** - * @brief - * - * @details List of values per CE location. - */ -typedef std::map jsa_counterexamplet; - -typedef std::deque jsa_counterexamplest; - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_H diff --git a/src/cegis/jsa/value/jsa_counterexample_printer.cpp b/src/cegis/jsa/value/jsa_counterexample_printer.cpp deleted file mode 100644 index 83c443a9d51..00000000000 --- a/src/cegis/jsa/value/jsa_counterexample_printer.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -void print_jsa_counterexample(messaget::mstreamt &os, - const jsa_counterexamplet &counterexample) -{ - -} diff --git a/src/cegis/jsa/value/jsa_counterexample_printer.h b/src/cegis/jsa/value/jsa_counterexample_printer.h deleted file mode 100644 index 2ae1080a540..00000000000 --- a/src/cegis/jsa/value/jsa_counterexample_printer.h +++ /dev/null @@ -1,46 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_PRINTER_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_PRINTER_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param counterexample - */ -void print_jsa_counterexample( - messaget::mstreamt &os, - const jsa_counterexamplet &counterexample); - -/** - * @brief - * - * @details - * - * @param os - * @param first - * @param last - */ -template -void print_jsa_counterexample( - messaget::mstreamt &os, - counterexamplet_itert first, - counterexamplet_itert last); - -#include - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_COUNTEREXAMPLE_PRINTER_H diff --git a/src/cegis/jsa/value/jsa_counterexample_printer.inc b/src/cegis/jsa/value/jsa_counterexample_printer.inc deleted file mode 100644 index 9856b8e4aa8..00000000000 --- a/src/cegis/jsa/value/jsa_counterexample_printer.inc +++ /dev/null @@ -1,8 +0,0 @@ -template -void print_jsa_counterexample( - messaget::mstreamt &os, - counterexamplet_itert first, - const counterexamplet_itert last) -{ - for (; first != last; ++first) print_jsa_counterexample(os, *first); -} diff --git a/src/cegis/jsa/value/jsa_genetic_counterexample.h b/src/cegis/jsa/value/jsa_genetic_counterexample.h deleted file mode 100644 index f984768566e..00000000000 --- a/src/cegis/jsa/value/jsa_genetic_counterexample.h +++ /dev/null @@ -1,34 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_COUNTEREXAMPLE_H - -#include -#include - -#include - -/** - * @brief - * - * @details - */ -class jsa_genetic_counterexamplet -{ -public: - __CPROVER_jsa_abstract_heapt init_org; - __CPROVER_jsa_abstract_heapt inductive_org; - __CPROVER_jsa_abstract_heapt inductive_body_result; - - typedef std::map assignments_per_program_locationt; - assignments_per_program_locationt assignments_per_program_location; -}; - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_COUNTEREXAMPLE_H diff --git a/src/cegis/jsa/value/jsa_genetic_solution.h b/src/cegis/jsa/value/jsa_genetic_solution.h deleted file mode 100644 index 1f2a7d6e5ed..00000000000 --- a/src/cegis/jsa/value/jsa_genetic_solution.h +++ /dev/null @@ -1,117 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SOLUTION_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SOLUTION_H - -#include - -#include - -/** - * @brief - * - * @details - */ -#define OPERANDS_PER_JSA_INVARIANT_INSTRUCTION 1 - -/** - * @brief - * - * @details - */ -#define OPERANDS_PER_JSA_PREDICATE_INSTRUCTION 4 - -/** - * @brief - * - * @details - */ -#define OPERANDS_PER_JSA_QUERY_INSTRUCTION 3 - -/** - * @brief - * - * @details - */ -class jsa_genetic_solutiont -{ -public: - /** - * @brief - * - * @details - */ - typedef std::vector<__CPROVER_jsa_pred_instructiont> predicatet; - - /** - * @brief - * - * @details - */ - typedef std::vector predicatest; - - /** - * @brief - * - * @details - */ - predicatest predicates; - - /** - * @brief - * - * @details - */ - typedef std::vector<__CPROVER_jsa_query_instructiont> queryt; - - /** - * @brief - * - * @details - */ - queryt query; - - /** - * @brief - * - * @details - */ - typedef std::vector<__CPROVER_jsa_invariant_instructiont> invariantt; - - /** - * @brief - * - * @details - */ - invariantt invariant; - - /** - * @brief - * - * @details - */ - typedef size_t fitnesst; - - /** - * @brief - * - * @details - */ - fitnesst fitness; -}; - -/** - * @brief - * - * @details - */ -typedef std::vector jsa_populationt; - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SOLUTION_H diff --git a/src/cegis/jsa/value/jsa_genetic_synthesis.h b/src/cegis/jsa/value/jsa_genetic_synthesis.h deleted file mode 100644 index 823f6dc9bf4..00000000000 --- a/src/cegis/jsa/value/jsa_genetic_synthesis.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SYNTHESIS_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SYNTHESIS_H - -#define __CPROVER_JSA_MAX_CONCRETE_NODES 3u -#define __CPROVER_JSA_MAX_ABSTRACT_NODES 0u -#define __CPROVER_JSA_MAX_LISTS 2u -#define __CPROVER_JSA_MAX_NODES_PER_CE_LIST 1u -#define __CPROVER_JSA_MAX_ITERATORS 2u - -#define __CPROVER_JSA_MAX_QUERY_SIZE 4u -#define __CPROVER_JSA_MAX_PRED_SIZE 3u -#define __CPROVER_JSA_NUM_PRED_OPS 7u -#define __CPROVER_JSA_NUM_PRED_RESULT_OPS 3u - -#define JSA_GENETIC_SYNTHESIS_H_ - -typedef bool _Bool; - -#include - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_GENETIC_SYNTHESIS_H diff --git a/src/cegis/jsa/value/jsa_solution.cpp b/src/cegis/jsa/value/jsa_solution.cpp deleted file mode 100644 index 32895832edb..00000000000 --- a/src/cegis/jsa/value/jsa_solution.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -jsa_solutiont::jsa_solutiont() : - max_size(1) -{ -} - -namespace -{ -jsa_solutiont ©_instrs(jsa_solutiont &lhs, const jsa_solutiont &rhs) -{ - lhs.predicates.clear(); - lhs.predicates.resize(rhs.predicates.size()); - for(size_t i=0; i < lhs.predicates.size(); ++i) - copy_instructions(lhs.predicates[i], rhs.predicates[i]); - lhs.query.clear(); - copy_instructions(lhs.query, rhs.query); - lhs.invariant.clear(); - copy_instructions(lhs.invariant, rhs.invariant); - return lhs; -} -} - -jsa_solutiont::jsa_solutiont(const jsa_solutiont &other) : - max_size(other.max_size) -{ - copy_instrs(*this, other); -} - -jsa_solutiont &jsa_solutiont::operator =(const jsa_solutiont &other) -{ - max_size=other.max_size; - return copy_instrs(*this, other); -} - -void jsa_solutiont::clear() { - max_size=0; - predicates.clear(); - query.clear(); - invariant.clear(); -} diff --git a/src/cegis/jsa/value/jsa_solution.h b/src/cegis/jsa/value/jsa_solution.h deleted file mode 100644 index 6a93f254f10..00000000000 --- a/src/cegis/jsa/value/jsa_solution.h +++ /dev/null @@ -1,86 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_H - -#include - -/** - * @brief - * - * @details - */ -class jsa_solutiont -{ -public: - typedef std::vector predicatest; - - /** - * @brief - * - * @details - */ - predicatest predicates; - - /** - * @brief - * - * @details - */ - goto_programt::instructionst query; - - /** - * @brief - * - * @details - */ - goto_programt::instructionst invariant; - - /** - * @brief - * - * @details - */ - size_t max_size; - - /** - * @brief - * - * @details - */ - jsa_solutiont(); - - /** - * @brief - * - * @details - * - * @param other - */ - jsa_solutiont(const jsa_solutiont &other); - - /** - * @brief - * - * @details - * - * @param other - */ - jsa_solutiont &operator=(const jsa_solutiont &other); - - /** - * @brief - * - * @details - */ - void clear(); -}; - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_H diff --git a/src/cegis/jsa/value/jsa_solution_printer.cpp b/src/cegis/jsa/value/jsa_solution_printer.cpp deleted file mode 100644 index e279d6f6b16..00000000000 --- a/src/cegis/jsa/value/jsa_solution_printer.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include - -namespace -{ -void print(messaget::mstreamt &os, const pred_op_idst &op_ids) -{ - for(const pred_op_idst::value_type &op : op_ids) - { - os << " " << op.first << ""; - const irep_idt &id=op.second.get_identifier(); - os << "" << id << "" << messaget::endl; - } -} - -void print_consts(messaget::mstreamt &os, const jsa_programt &prog) -{ - const symbol_tablet &st=prog.st; - const goto_functionst &gf=prog.gf; - const std::vector values(collect_integer_literals(st, gf)); - os << " " << messaget::endl; - size_t index=0; - for(const constant_exprt &expr : values) - { - mp_integer literal; - to_integer(expr, literal); - os << " " << index++ << ""; - const mp_integer::llong_t value=literal.to_long(); - os << "" << value << "" << messaget::endl; - } - os << " " << messaget::endl; -} - -void print_instructions(messaget::mstreamt &os, const jsa_programt &program, - const goto_programt::instructionst &instrs) -{ - const goto_programt &prog=get_entry_body(program.gf); - const namespacet ns(program.st); - for(goto_programt::const_targett it=instrs.begin(); it != instrs.end(); ++it) - prog.output_instruction(ns, "", os, it); -} -} - -void print_jsa_solution(messaget::mstreamt &os, const jsa_programt &program, - const jsa_solutiont &solution, const pred_op_idst &op_ids, - const pred_op_idst &const_op_ids) -{ - if(solution.query.empty() || program.st.symbols.empty()) - { - os << "" << messaget::endl << messaget::eom; - return; - } - os << "" << messaget::endl; - print_consts(os, program); - os << " " << messaget::endl; - os << " " << messaget::endl; - print(os, op_ids); - os << " " << messaget::endl; - os << " " << messaget::endl; - print(os, const_op_ids); - os << " " << messaget::endl; - os << " " << messaget::endl; - os << " " << messaget::endl; - const jsa_solutiont::predicatest &predicates=solution.predicates; - for(const goto_programt::instructionst &predicate : predicates) - { - os << " " << messaget::endl; - print_instructions(os, program, predicate); - os << " " << messaget::endl; - } - os << " " << messaget::endl; - os << " " << messaget::endl; - print_instructions(os, program, solution.query); - os << " " << messaget::endl; - os << " " << messaget::endl; - print_instructions(os, program, solution.invariant); - os << " " << messaget::endl; - os << "" << messaget::endl << messaget::eom; -} diff --git a/src/cegis/jsa/value/jsa_solution_printer.h b/src/cegis/jsa/value/jsa_solution_printer.h deleted file mode 100644 index 1dcf9632db7..00000000000 --- a/src/cegis/jsa/value/jsa_solution_printer.h +++ /dev/null @@ -1,35 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_PRINTER_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_PRINTER_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param program - * @param solution - * @param op_ids - * @param const_op_ids - */ -void print_jsa_solution( - messaget::mstreamt &os, - const class jsa_programt &program, - const class jsa_solutiont &solution, - const pred_op_idst &op_ids, - const pred_op_idst &const_op_ids); - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_SOLUTION_PRINTER_H diff --git a/src/cegis/jsa/value/jsa_types.cpp b/src/cegis/jsa/value/jsa_types.cpp deleted file mode 100644 index e9234b4889b..00000000000 --- a/src/cegis/jsa/value/jsa_types.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -typet jsa_word_type() -{ - return unsigned_char_type(); -} - -typet jsa_internal_index_type() -{ - return jsa_word_type(); -} - -typet jsa_iterator_id_type() -{ - return jsa_word_type(); -} - -#define PRED_INSTR_TYPE "tag-__CPROVER_jsa_pred_instruction" -symbol_typet jsa_predicate_instruction_type() -{ - return symbol_typet(PRED_INSTR_TYPE); -} - -array_typet jsa_predicate_type(const exprt &size) -{ - return array_typet(jsa_predicate_instruction_type(), size); -} - -#define INV_INSTR_TYPE "tag-__CPROVER_jsa_invariant_instruction" -symbol_typet jsa_invariant_instruction_type() -{ - return symbol_typet(INV_INSTR_TYPE); -} - -array_typet jsa_invariant_type(const exprt &size) -{ - return array_typet(jsa_invariant_instruction_type(), size); -} - -#define QUERY_INSTR_TYPE "tag-__CPROVER_jsa_query_instruction" -symbol_typet jsa_query_instruction_type() -{ - return symbol_typet(QUERY_INSTR_TYPE); -} - -array_typet jsa_query_type(const exprt &size) -{ - return array_typet(jsa_query_instruction_type(), size); -} - -symbol_typet jsa_heap_type() -{ - return symbol_typet(JSA_HEAP_TAG); -} diff --git a/src/cegis/jsa/value/jsa_types.h b/src/cegis/jsa/value/jsa_types.h deleted file mode 100644 index 739076e81bf..00000000000 --- a/src/cegis/jsa/value/jsa_types.h +++ /dev/null @@ -1,111 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_JSA_TYPES_H -#define CPROVER_CEGIS_JSA_VALUE_JSA_TYPES_H - -#include - -/** - * @brief - * - * @details - * - * @return - */ -typet jsa_word_type(); - -/** - * @brief - * - * @details - * - * @return - */ -typet jsa_internal_index_type(); - -/** - * @brief - * - * @details - * - * @return - */ -typet jsa_iterator_id_type(); - -/** - * @brief - * - * @details - * - * @return - */ -symbol_typet jsa_predicate_instruction_type(); - -/** - * @brief - * - * @details - * - * @param size - * - * @return - */ -array_typet jsa_predicate_type(const exprt &size); - -/** - * @brief - * - * @details - * - * @return - */ -symbol_typet jsa_invariant_instruction_type(); - -/** - * @brief - * - * @details - * - * @param size - * - * @return - */ -array_typet jsa_invariant_type(const exprt &size); - -/** - * @brief - * - * @details - * - * @return - */ -symbol_typet jsa_query_instruction_type(); - -/** - * @brief - * - * @details - * - * @param size - * - * @return - */ -array_typet jsa_query_type(const exprt &size); - -/** - * @brief - * - * @details - * - * @return - */ -symbol_typet jsa_heap_type(); - -#endif // CPROVER_CEGIS_JSA_VALUE_JSA_TYPES_H diff --git a/src/cegis/jsa/value/pred_ops.h b/src/cegis/jsa/value/pred_ops.h deleted file mode 100644 index fa84df5fb59..00000000000 --- a/src/cegis/jsa/value/pred_ops.h +++ /dev/null @@ -1,17 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VALUE_PRED_OPS_H -#define CPROVER_CEGIS_JSA_VALUE_PRED_OPS_H - -#include - -typedef std::map pred_op_idst; - -#endif // CPROVER_CEGIS_JSA_VALUE_PRED_OPS_H diff --git a/src/cegis/jsa/verify/extract_counterexample.cpp b/src/cegis/jsa/verify/extract_counterexample.cpp deleted file mode 100644 index d3d6290869e..00000000000 --- a/src/cegis/jsa/verify/extract_counterexample.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include - -void extract(const jsa_programt &prog, jsa_counterexamplet &ce, - const goto_tracet &trace) -{ - const symbol_tablet &st=prog.st; - const namespacet ns(st); - const goto_programt::targetst &ce_locs=prog.counterexample_locations; - const goto_tracet::stepst &steps=trace.steps; - for(const goto_programt::targett &ce_loc : ce_locs) - { - assert(ce_loc->labels.size() == 1u); - const irep_idt &id=ce_loc->labels.front(); - const goto_tracet::stepst::const_iterator it=std::find_if(steps.begin(), - steps.end(), [&id](const goto_trace_stept &step) - { - const goto_programt::instructiont::labelst &labels=step.pc->labels; - return labels.end() != std::find(labels.begin(), labels.end(), id); - }); - if(steps.end() != it) ce.insert(std::make_pair(id, it->full_lhs_value)); - else - assert( - !"We need counterexample for each location." - "Synthesiser can't differentiate base case/inductive step/entailment violation"); - } - assert(ce.size() == prog.counterexample_locations.size()); -} diff --git a/src/cegis/jsa/verify/extract_counterexample.h b/src/cegis/jsa/verify/extract_counterexample.h deleted file mode 100644 index 006ec48adb0..00000000000 --- a/src/cegis/jsa/verify/extract_counterexample.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VERIFY_EXTRACT_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_JSA_VERIFY_EXTRACT_COUNTEREXAMPLE_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param ce - * @param trace - */ -void extract( - const class jsa_programt &prog, - jsa_counterexamplet &ce, - const class goto_tracet &trace); - -#endif // CPROVER_CEGIS_JSA_VERIFY_EXTRACT_COUNTEREXAMPLE_H diff --git a/src/cegis/jsa/verify/insert_solution.cpp b/src/cegis/jsa/verify/insert_solution.cpp deleted file mode 100644 index 8356db7c303..00000000000 --- a/src/cegis/jsa/verify/insert_solution.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define JSA_PRED_RESULT JSA_PREFIX "pred_result" -#define SYNC_IT "__CPROVER_jsa_verify_synchronise_iterator" -#define MAKE_NULL "__CPROVER_jsa__internal_make_null" - -namespace -{ -void add_predicates(jsa_programt &prog, const jsa_solutiont::predicatest &preds) -{ - assert(!preds.empty()); - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_body(gf, JSA_PRED_EXEC); - body.clear(); - goto_programt::instructionst &instrs=body.instructions; - std::string pred_id_name(JSA_PRED_EXEC); - pred_id_name+="::pred_id"; - const symbol_exprt pred_id(st.lookup(pred_id_name).symbol_expr()); - goto_programt::targett pos=body.insert_after(instrs.begin()); - declare_jsa_meta_variable(st, pos, JSA_PRED_RESULT, jsa_word_type()); - const std::string result(get_cegis_meta_name(JSA_PRED_RESULT)); - const symbol_exprt ret_val(st.lookup(result).symbol_expr()); - const goto_programt::targett first=pos; - pos=add_return_assignment(body, pos, JSA_PRED_EXEC, ret_val); - const goto_programt::targett end=pos; - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::END_FUNCTION; - std::vector pred_begins; - pos=first; - size_t idx=0; - for(const jsa_solutiont::predicatest::value_type &pred : preds) - { - assert(!pred.empty()); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - pos->source_location=jsa_builtin_source_location(); - const constant_exprt pred_idx_expr(from_integer(idx++, pred_id.type())); - pos->guard=notequal_exprt(pred_id, pred_idx_expr); - pred_begins.push_back(pos); - pos=copy_instructions(instrs, pos, pred); - const goto_programt::targett last_assign=std::prev(pos); - const exprt &last_lhs=to_code_assign(last_assign->code).lhs(); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=jsa_builtin_source_location(); - pos->code=code_assignt(ret_val, last_lhs); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - pos->source_location=jsa_builtin_source_location(); - pos->targets.push_back(end); - } - assert(pred_begins.size() == preds.size()); - for(auto it=pred_begins.begin(); it != std::prev(pred_begins.end()); ++it) - { - const goto_programt::targett &pos=*it; - pos->targets.push_back(*std::next(it)); - } - pred_begins.back()->targets.push_back(end); - add_zero_jsa_temps_to_pred_exec(prog); - - body.compute_incoming_edges(); - body.compute_target_numbers(); -} - -void insert_invariant(const symbol_tablet &st, const goto_functionst &gf, goto_programt &body, - goto_programt::targett pos, const goto_programt::instructionst &prog) -{ - assert(prog.size() == 1); - const symbol_exprt v(st.lookup(get_affected_variable(*pos)).symbol_expr()); - pos=body.insert_after(pos); - pos->source_location=jsa_builtin_source_location(); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - code_function_callt call; - call.lhs()=v; - call.function()=st.lookup(JSA_INV_VERIFY_EXEC).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - args.push_back(address_of_exprt(get_user_heap(gf))); - args.push_back(address_of_exprt(get_queried_heap(st))); - pos->code=call; - remove_return(body, pos); -} - -const exprt &get_iterator_arg(const codet &code) -{ - const code_function_callt &call=to_code_function_call(code); - const code_function_callt::argumentst &args=call.arguments(); - assert(args.size() >= 3); - return args.at(2); -} - -void insert_sync_call(const symbol_tablet &st, const goto_functionst &gf, - goto_programt &body, goto_programt::targett pos, - const goto_programt::instructionst &query) -{ - assert(!query.empty()); - if(query.empty()) return; - const exprt &it_arg=get_iterator_arg(query.front().code); - code_function_callt sync; - code_function_callt::argumentst &sync_args=sync.arguments(); - sync_args.push_back(address_of_exprt(get_user_heap(gf))); - sync_args.push_back(address_of_exprt(get_queried_heap(st))); - sync_args.push_back(it_arg); - sync.function()=st.lookup(SYNC_IT).symbol_expr(); - pos=insert_before_preserve_labels(body, pos); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - pos->code=sync; -} - -void make_full_query_call(const symbol_tablet &st, const goto_functionst &gf, - goto_programt &body, goto_programt::targett pos, - const goto_programt::instructionst &query) -{ - if(query.empty()) return; - pos=insert_before_preserve_labels(body, pos); - pos->type=goto_program_instruction_typet::FUNCTION_CALL; - pos->source_location=jsa_builtin_source_location(); - code_function_callt call; - call.function()=st.lookup(MAKE_NULL).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - args.push_back(address_of_exprt(get_user_heap(gf))); - args.push_back(get_iterator_arg(query.front().code)); - pos->code=call; -} - -void insert_before(jsa_programt &jsa_prog, goto_programt &body, - const goto_programt::targett &pos, const goto_programt::instructionst &prog) -{ - if(prog.empty()) return; - const goto_programt::targett insert_after=std::prev(pos); - copy_instructions(body.instructions, insert_after, prog); - zero_jsa_temps(jsa_prog, insert_after); - move_labels(body, pos, std::next(insert_after)); -} -} - -void insert_jsa_solution(jsa_programt &prog, const jsa_solutiont &solution) -{ - add_predicates(prog, solution.predicates); - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - goto_programt &body=get_entry_body(gf); - - insert_before(prog, body, prog.base_case, solution.query); - insert_invariant(st, gf, body, prog.base_case, solution.invariant); - insert_before(prog, body, prog.inductive_assumption, solution.query); - insert_invariant(st, gf, body, prog.inductive_assumption, solution.invariant); - insert_sync_call(st, gf, body, prog.inductive_step, solution.query); - insert_before(prog, body, prog.inductive_step, solution.query); - insert_invariant(st, gf, body, prog.inductive_step, solution.invariant); - make_full_query_call(st, gf, body, prog.property_entailment, solution.query); - insert_before(prog, body, prog.property_entailment, solution.query); - insert_sync_call(st, gf, body, prog.property_entailment, solution.query); - insert_invariant(st, gf, body, prog.property_entailment, solution.invariant); - - body.compute_incoming_edges(); - body.compute_target_numbers(); -} diff --git a/src/cegis/jsa/verify/insert_solution.h b/src/cegis/jsa/verify/insert_solution.h deleted file mode 100644 index 0d8822ea065..00000000000 --- a/src/cegis/jsa/verify/insert_solution.h +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VERIFY_INSERT_SOLUTION_H -#define CPROVER_CEGIS_JSA_VERIFY_INSERT_SOLUTION_H - -/** - * @brief - * - * @details - * - * @param prog - * @param solution - */ -void insert_jsa_solution( - class jsa_programt &prog, - const class jsa_solutiont &solution); - -#endif // CPROVER_CEGIS_JSA_VERIFY_INSERT_SOLUTION_H diff --git a/src/cegis/jsa/verify/jsa_symex_verify.cpp b/src/cegis/jsa/verify/jsa_symex_verify.cpp deleted file mode 100644 index 1d63b29de7d..00000000000 --- a/src/cegis/jsa/verify/jsa_symex_verify.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -jsa_symex_verifyt::jsa_symex_verifyt(const jsa_programt &program) : - original_program(program) -{ -} - -void jsa_symex_verifyt::process(const candidatet &cand) -{ - program=original_program; - const goto_programt::targetst pred_ops(collect_pred_ops(program)); - // add_jsa_library(program, cand.max_size, pred_ops); - instrument_pred_ops(program, pred_ops); - insert_jsa_constraint(program, false); - assume_renondet_inputs_valid(program); - - insert_jsa_solution(program, cand); - remove_returns(program.st, program.gf); - program.gf.update(); -} - -const symbol_tablet &jsa_symex_verifyt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &jsa_symex_verifyt::get_goto_functions() const -{ - return program.gf; -} - -void jsa_symex_verifyt::convert(counterexamplest &counterexamples, - const goto_tracet &trace) -{ - counterexamples.push_back(counterexamplet()); - extract(program, counterexamples.back(), trace); -} - -void jsa_symex_verifyt::show_counterexample(messaget::mstreamt &os, - const counterexamplet &counterexample) const -{ - os << "" << messaget::endl; - print_assignments(os, get_symbol_table(), counterexample); - os << "" << messaget::endl; -} diff --git a/src/cegis/jsa/verify/jsa_symex_verify.h b/src/cegis/jsa/verify/jsa_symex_verify.h deleted file mode 100644 index f07077b6743..00000000000 --- a/src/cegis/jsa/verify/jsa_symex_verify.h +++ /dev/null @@ -1,96 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VERIFY_JSA_SYMEX_VERIFY_H -#define CPROVER_CEGIS_JSA_VERIFY_JSA_SYMEX_VERIFY_H - -#include - -#include - -#include -#include -#include - -/** - * @brief - * - * @details - */ -class jsa_symex_verifyt -{ - const jsa_programt &original_program; - jsa_programt program; -public: - typedef jsa_counterexamplet counterexamplet; - typedef jsa_counterexamplest counterexamplest; - typedef jsa_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit jsa_symex_verifyt(const jsa_programt &program); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void process(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param trace - */ - void convert( - counterexamplest &counterexamples, - const class goto_tracet &trace); - - /** - * @brief - * - * @details - * - * @param os - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#endif // CPROVER_CEGIS_JSA_VERIFY_JSA_SYMEX_VERIFY_H diff --git a/src/cegis/jsa/verify/renondet_inputs.cpp b/src/cegis/jsa/verify/renondet_inputs.cpp deleted file mode 100644 index b947a96b6ce..00000000000 --- a/src/cegis/jsa/verify/renondet_inputs.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -void assume_renondet_inputs_valid(jsa_programt &prog) -{ - if(prog.counterexample_locations.empty()) return; - const symbol_tablet &st=prog.st; - goto_programt &body=get_entry_body(prog.gf); - - for(const goto_programt::targett &pos : prog.inductive_step_renondets) - { - const irep_idt &id=get_affected_variable(*pos); - const symbol_exprt lhs(st.lookup(id).symbol_expr()); - const typet &type=lhs.type(); - if(is_jsa_heap(type)) - assume_valid_heap(st, body, pos, address_of_exprt(lhs)); - } -} diff --git a/src/cegis/jsa/verify/renondet_inputs.h b/src/cegis/jsa/verify/renondet_inputs.h deleted file mode 100644 index ffe987129df..00000000000 --- a/src/cegis/jsa/verify/renondet_inputs.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_JSA_VERIFY_RENONDET_INPUTS_H -#define CPROVER_CEGIS_JSA_VERIFY_RENONDET_INPUTS_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void assume_renondet_inputs_valid(class jsa_programt &prog); - -#endif // CPROVER_CEGIS_JSA_VERIFY_RENONDET_INPUTS_H diff --git a/src/cegis/learn/concurrent_learn.h b/src/cegis/learn/concurrent_learn.h deleted file mode 100644 index 7e8c2f62b12..00000000000 --- a/src/cegis/learn/concurrent_learn.h +++ /dev/null @@ -1,93 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_LEARN_CONCURRENT_LEARN_H -#define CPROVER_CEGIS_LEARN_CONCURRENT_LEARN_H - -#include - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class concurrent_learnt -{ -public: - typedef typename learner1t::candidatet learner1_candidatet; - typedef typename learner2t::candidatet learner2_candidatet; - typedef learner1_candidatet candidatet; - typedef typename learner1t::counterexamplet counterexamplet; - typedef typename learner1t::counterexamplest counterexamplest; - typedef std::function learner2_serialisert; - typedef std::function learner1_deserialisert; - typedef std::function paragon_deserialisert; -private: - learner1t &learner1; - learner2t &learner2; - task_poolt task_pool; - const learner2_serialisert learner2_serialiser; - const learner1_deserialisert learner1_deserialiser; - const paragon_deserialisert paragon_deserialiser; - bool is_decoded_candidate; - learner1_candidatet decoded_candidate; - size_t num_ces; - const size_t num_symex_ces; -public: - /** - * @brief - * - * @details - * - * @param learner1 - * @param learner2 - * @param serialiser - * @param deserialiser - * @param encoded_deserialiser - * @param learner1_head_start - */ - concurrent_learnt(learner1t &learner1, learner2t &learner2, - learner2_serialisert serialiser, learner1_deserialisert deserialiser, - paragon_deserialisert encoded_deserialiser, size_t learner1_head_start); - - /** - * @brief - * - * @details - * - * @param learner1 - * @param learner2 - * @param serialiser - * @param learner1_head_start - */ - template - concurrent_learnt(learner1t &learner1, learner2t &learner2, - serialisert serialiser, size_t learner1_head_start); - - template - void seed(seedt &seed); - - const learner1_candidatet &next_candidate() const; - - template - bool learn(itert first, const itert &last); - - void show_candidate(messaget::mstreamt &os) const; - - void set_solution_size_range(size_t min, size_t max); -}; - -#include "concurrent_learn.inc" - -#endif // CPROVER_CEGIS_LEARN_CONCURRENT_LEARN_H diff --git a/src/cegis/learn/concurrent_learn.inc b/src/cegis/learn/concurrent_learn.inc deleted file mode 100644 index 7e181bb064d..00000000000 --- a/src/cegis/learn/concurrent_learn.inc +++ /dev/null @@ -1,115 +0,0 @@ -#include - -template -concurrent_learnt::concurrent_learnt(learner1t &learner1, - learner2t &learner2, const learner2_serialisert serialiser, - const learner1_deserialisert deserialiser, - const paragon_deserialisert encoded_deserialiser, - const size_t learner1_head_start) : - learner1(learner1), learner2(learner2), learner2_serialiser(serialiser), learner1_deserialiser( - deserialiser), paragon_deserialiser(encoded_deserialiser), is_decoded_candidate( - false), num_ces(0), num_symex_ces(learner1_head_start) -{ -} - -template -template -concurrent_learnt::concurrent_learnt(learner1t &learner1, - learner2t &learner2, serialisert serialiser, - const size_t learner1_head_start) : - learner1(learner1), learner2(learner2), learner2_serialiser(serialiser), learner1_deserialiser( - serialiser), paragon_deserialiser(serialiser), is_decoded_candidate( - false), num_ces(0), num_symex_ces(learner1_head_start) -{ -} - -template -template -void concurrent_learnt::seed(seedt &seed) -{ - learner1.seed(seed); - learner2.seed(seed); -} - -template -const typename concurrent_learnt::learner1_candidatet &concurrent_learnt< - learner1t, learner2t>::next_candidate() const -{ - if (is_decoded_candidate) return decoded_candidate; - return learner1.next_candidate(); -} - -template -template -bool concurrent_learnt::learn(itert first, - const itert &last) -{ - num_ces += std::distance(first, last); - bool symex_running=true; - learner1.set_termination_condition([this, &symex_running]() - { - task_pool.join_some(); - return symex_running; - }); - bool symex_success=false; - irep_pipet irep_pipe; - const task_poolt::task_idt symex_task=task_pool.schedule( - [this, first, last, &irep_pipe]() mutable - { - irep_pipe.close_read(); - try - { - const bool result=learner2.learn(first, last); - if (!result) return EXIT_FAILURE; - irept sdu; - learner2_serialiser(sdu, learner2.next_candidate()); - irep_pipe.send(sdu); - irep_pipe.close_write(); - return EXIT_SUCCESS; - } catch(...) - { - irep_pipe.close_write(); - return EXIT_FAILURE; - } - }, [this, &symex_running, &symex_success, &irep_pipe](const int status) - { - if (EXIT_SUCCESS != status) return; - symex_running=false; - symex_success=true; - irept sdu; - irep_pipe.receive(sdu); - learner2_candidatet ind; - paragon_deserialiser(ind, sdu); - learner1.add_paragon(ind); - typename learner2t::candidatet symex_candidate; - learner1_deserialiser(decoded_candidate, sdu); - is_decoded_candidate=true; - }); - irep_pipe.close_write(); - const bool genetic_success=learner1.learn(first, last); - if (num_ces <= num_symex_ces) - task_pool.join_all(); - if (symex_running) task_pool.cancel(symex_task); - irep_pipe.close_read(); - if (genetic_success && !symex_success) is_decoded_candidate=false; - learner2.add_counterexamples(first, last); - return genetic_success || symex_success; -} - -template -void concurrent_learnt::show_candidate( - messaget::mstreamt &os) const -{ - if (is_decoded_candidate) - learner1.show_candidate(os, decoded_candidate); - else - learner1.show_candidate(os); -} - -template -void concurrent_learnt::set_solution_size_range( - const size_t min, const size_t max) -{ - learner1.set_solution_size_range(min, max); - learner2.set_solution_size_range(min, max); -} diff --git a/src/cegis/learn/constraint_helper.cpp b/src/cegis/learn/constraint_helper.cpp deleted file mode 100644 index 1ad6d23649a..00000000000 --- a/src/cegis/learn/constraint_helper.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -void transform_asserts_to_assumes(goto_functionst &gf) -{ - typedef goto_functionst::function_mapt fmapt; - fmapt &fmap=gf.function_map; - for(fmapt::value_type &entry : fmap) - { - if(!entry.second.body_available()) continue; - for(goto_programt::instructiont &instr : entry.second.body.instructions) - if(ASSERT == instr.type) instr.type=ASSUME; - } -} diff --git a/src/cegis/learn/constraint_helper.h b/src/cegis/learn/constraint_helper.h deleted file mode 100644 index ae084a2e545..00000000000 --- a/src/cegis/learn/constraint_helper.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_LEARN_CONSTRAINT_HELPER_H -#define CPROVER_CEGIS_LEARN_CONSTRAINT_HELPER_H - -/** - * @brief - * - * @details - * - * @param gf - */ -void transform_asserts_to_assumes(class goto_functionst &gf); - -#endif // CPROVER_CEGIS_LEARN_CONSTRAINT_HELPER_H diff --git a/src/cegis/learn/insert_counterexample.cpp b/src/cegis/learn/insert_counterexample.cpp deleted file mode 100644 index 35b067bbcb2..00000000000 --- a/src/cegis/learn/insert_counterexample.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define CE_ARRAY_PREFIX CPROVER_PREFIX "ce_array_" -#define CE_VALUES_INDEX_PREFIX CPROVER_PREFIX "ce_values_index_" - -zero_valuest get_zero_values(const symbol_tablet &st, - const goto_programt::targetst &ce_locs) -{ - std::map zero_values; - const source_locationt loc(default_cegis_source_location()); - const namespacet ns(st); - for(const goto_programt::const_targett pos : ce_locs) - { - const irep_idt &marker=get_counterexample_marker(pos); - const typet &type=get_affected_type(*pos); - const exprt value(zero_initializer(type, loc, ns)); - zero_values.insert(std::make_pair(marker, value)); - } - return zero_values; -} - -void normalise(const std::set &ce_keys, const zero_valuest &zv, - labelled_counterexamplest &ces) -{ - const exprt::operandst no_values; - std::map sizes; - for(labelled_counterexamplest::value_type &ce : ces) - { - for(const irep_idt &loc : ce_keys) - { - std::map::iterator sz=sizes.find(loc); - if(sizes.end() == sz) sz=sizes.insert(std::make_pair(loc, 1)).first; - size_t &size=sz->second; - labelled_assignmentst::const_iterator values=ce.find(loc); - if(ce.end() == values) - values=ce.insert(std::make_pair(loc, no_values)).first; - size=std::max(size, values->second.size()); - } - assert(ce.size() == zv.size()); - } - assert(sizes.size() == zv.size()); - for(labelled_counterexamplest::value_type &ce : ces) - for(labelled_counterexamplest::value_type::value_type &ass : ce) - { - labelled_assignmentst::value_type::second_type &values=ass.second; - const size_t current_size=values.size(); - const irep_idt &lbl=ass.first; - const std::map::const_iterator it=sizes.find(lbl); - assert(sizes.end() != it); - const size_t target_size=it->second; - assert(current_size <= target_size); - const size_t missing=target_size - current_size; - if(missing) - { - const std::map::const_iterator it=zv.find(lbl); - assert(zv.end() != it); - std::fill_n(std::back_inserter(values), missing, it->second); - } - assert(target_size == values.size()); - } -} - -namespace -{ -std::set get_all_keys(const zero_valuest &zv) -{ - std::set result; - std::transform(zv.begin(), zv.end(), std::inserter(result, result.end()), - [](const zero_valuest::value_type &v) - { return v.first;}); - return result; -} - -array_exprt to_values(const exprt::operandst &ops) -{ - assert(!ops.empty()); - const typet sz_type(signed_int_type()); - const constant_exprt sz_expr(from_integer(ops.size(), sz_type)); - const array_typet array_type(ops.front().type(), sz_expr); - array_exprt result(array_type); - copy(ops.begin(), ops.end(), std::back_inserter(result.operands())); - return result; -} -} - -array_valuest get_array_values(const labelled_counterexamplest &ces) -{ - const typet sz_type(signed_int_type()); - const constant_exprt ces_sz_expr(from_integer(ces.size(), sz_type)); - array_valuest result; - for(const labelled_assignmentst &ce : ces) - for(const labelled_assignmentst::value_type &ass : ce) - { - const array_exprt ass_values(to_values(ass.second)); - const irep_idt &loc=ass.first; - array_valuest::iterator it=result.find(loc); - if(result.end() == it) - { - const array_typet type(ass_values.type(), ces_sz_expr); - it=result.insert(std::make_pair(loc, array_exprt(type))).first; - } - it->second.copy_to_operands(ass_values); - } - return result; -} - -std::string get_ce_array_name(const irep_idt &loc_id) -{ - std::string base_name(CE_ARRAY_PREFIX); - return base_name+=id2string(loc_id); -} - -std::string get_ce_value_index_name(const irep_idt &loc) -{ - std::string label(CE_VALUES_INDEX_PREFIX); - return label+=id2string(loc); -} - -namespace -{ -void add_array_declarations(symbol_tablet &st, goto_functionst &gf, - const labelled_counterexamplest &ces, const goto_programt::targett &begin) -{ - const typet sz_type(signed_int_type()); - const constant_exprt sz_expr(from_integer(ces.size(), sz_type)); - const array_valuest array_values(get_array_values(ces)); - const labelled_counterexamplest::value_type &prototype=ces.front(); - goto_programt::targett pos=std::prev(begin); - for(const labelled_counterexamplest::value_type::value_type &value : prototype) - { - const labelled_assignmentst::value_type::first_type loc_id=value.first; - const array_valuest::const_iterator array_val=array_values.find(loc_id); - assert(array_values.end() != array_val); - const array_exprt &array_expr=array_val->second; - const std::string base_name(get_ce_array_name(loc_id)); - pos=declare_cegis_meta_variable(st, gf, pos, base_name, array_expr.type()); - assert(array_expr.operands().size() == ces.size()); - pos=assign_cegis_meta_variable(st, gf, pos, base_name, array_expr); - } -} - -void add_array_indexes(const std::set &ce_keys, symbol_tablet &st, - goto_functionst &gf) -{ - goto_programt &body=get_entry_body(gf); - const goto_programt::targett cprover_init(find_cprover_initialize(body)); - goto_programt::targett pos=cprover_init; - const typet type(signed_int_type()); - pos=declare_cegis_meta_variable(st, gf, std::prev(pos), CE_ARRAY_INDEX, type); - const source_locationt loc(default_cegis_source_location()); - const namespacet ns(st); - const exprt zero(zero_initializer(type, loc, ns)); - assign_cegis_meta_variable(st, gf, pos, CE_ARRAY_INDEX, zero); - pos=cprover_init; - for(const irep_idt &key : ce_keys) - { - const std::string label(get_ce_value_index_name(key)); - pos=declare_cegis_meta_variable(st, gf, pos, label, type); - pos=assign_cegis_meta_variable(st, gf, pos, label, zero); - } -} - -plus_exprt increment(const symbol_exprt &symbol) -{ - const typet sz_type(signed_int_type()); - const constant_exprt one(from_integer(1, sz_type)); - return plus_exprt(symbol, one); -} - -void add_ce_goto(symbol_tablet &st, goto_functionst &gf, const size_t num_ces, - const goto_programt::targett &begin) -{ - goto_programt &body=get_entry_body(gf); - goto_programt::targett pos=find_last_instr(body); - const std::string ce_index_name(get_cegis_meta_name(CE_ARRAY_INDEX)); - const symbol_exprt ce_index(st.lookup(ce_index_name).symbol_expr()); - const plus_exprt rhs(increment(ce_index)); - pos=assign_cegis_meta_variable(st, gf, pos, CE_ARRAY_INDEX, rhs); - const source_locationt loc(default_cegis_source_location()); - pos=body.insert_after(pos); - pos->source_location=loc; - pos->type=goto_program_instruction_typet::GOTO; - pos->targets.push_back(begin); - const constant_exprt num_ces_sz(from_integer(num_ces, signed_int_type())); - const binary_relation_exprt guard(ce_index, ID_lt, num_ces_sz); - pos->guard=guard; - pos=body.insert_after(pos); - pos->source_location=loc; - pos->type=goto_program_instruction_typet::ASSERT; - pos->guard=false_exprt(); - body.compute_target_numbers(); -} - -const index_exprt get_array_val_expr(const symbol_tablet &st, - const irep_idt &loc) -{ - const std::string index_name(get_cegis_meta_name(CE_ARRAY_INDEX)); - const symbol_exprt index(st.lookup(index_name).symbol_expr()); - const std::string array_name(get_cegis_meta_name(get_ce_array_name(loc))); - const symbol_exprt array(st.lookup(array_name).symbol_expr()); - const index_exprt ce(array, index); - const std::string value_index(get_cegis_meta_name(get_ce_value_index_name(loc))); - const symbol_exprt value_index_expr(st.lookup(value_index).symbol_expr()); - return index_exprt(ce, value_index_expr); -} - -void assign_ce_values(symbol_tablet &st, goto_functionst &gf, - const goto_programt::targetst &ce_locs) -{ - const typet sz_type(signed_int_type()); - const constant_exprt one(from_integer(1, sz_type)); - for(goto_programt::targett pos : ce_locs) - { - const irep_idt &label=get_counterexample_marker(pos); - const index_exprt value(get_array_val_expr(st, pos->labels.front())); - switch(pos->type) - { - case ASSIGN: - to_code_assign(pos->code).rhs()=value; - break; - case DECL: - pos=cegis_assign(st, gf, pos, - st.lookup(get_affected_variable(*pos)).symbol_expr(), value); - break; - default: - assert(!"Unsupported counterexample location type."); - } - const std::string value_index(get_cegis_meta_name(get_ce_value_index_name(label))); - const symbol_exprt value_index_expr(st.lookup(value_index).symbol_expr()); - const plus_exprt inc(increment(value_index_expr)); - cegis_assign(st, gf, pos, value_index_expr, inc); - } -} -} - -void insert_counterexamples(symbol_tablet &st, goto_functionst &gf, - labelled_counterexamplest ces, const goto_programt::targetst &ce_locs) -{ - assert(!ces.empty()); - const zero_valuest zero_values(get_zero_values(st, ce_locs)); - const std::set ce_keys(get_all_keys(zero_values)); - normalise(ce_keys, zero_values, ces); - goto_programt &body=get_entry_body(gf); - const goto_programt::targett begin(find_cprover_initialize(body)); - add_array_declarations(st, gf, ces, begin); - add_array_indexes(ce_keys, st, gf); - add_ce_goto(st, gf, ces.size(), begin); - assign_ce_values(st, gf, ce_locs); -} diff --git a/src/cegis/learn/insert_counterexample.h b/src/cegis/learn/insert_counterexample.h deleted file mode 100644 index 39382ceae5c..00000000000 --- a/src/cegis/learn/insert_counterexample.h +++ /dev/null @@ -1,115 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_LEARN_INSERT_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_LEARN_INSERT_COUNTEREXAMPLE_H - -#include - -#include - -/** - * @brief - * - * @details - */ -#define CE_ARRAY_INDEX CPROVER_PREFIX "ce_array_index" - -/** - * @brief - * - * @details - */ -typedef std::map zero_valuest; - -/** - * @brief - * - * @details - * - * @param st - * @param ce_locs - * - * @return - */ -zero_valuest get_zero_values( - const symbol_tablet &st, - const goto_programt::targetst &ce_locs); - -/** - * @brief - * - * @details - * - * @param ce_keys - * @param zv - * @param ces - */ -void normalise( - const std::set &ce_keys, - const zero_valuest &zv, - labelled_counterexamplest &ces); - -/** - * @brief - * - * @details - */ -typedef std::map array_valuest; - -/** - * @brief - * - * @details - * - * @param ces - * - * @return - */ -array_valuest get_array_values(const labelled_counterexamplest &ces); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param counterexamples - * @param ce_locs - */ -void insert_counterexamples( - class symbol_tablet &st, - class goto_functionst &gf, - labelled_counterexamplest counterexamples, - const goto_programt::targetst &ce_locs); - -/** - * @brief - * - * @details - * - * @param loc_id - * - * @return - */ -std::string get_ce_array_name(const irep_idt &loc_id); - -/** - * @brief - * - * @details - * - * @param loc_id - * - * @return - */ -std::string get_ce_value_index_name(const irep_idt &loc_id); - -#endif // CPROVER_CEGIS_LEARN_INSERT_COUNTEREXAMPLE_H diff --git a/src/cegis/options/parameters.h b/src/cegis/options/parameters.h deleted file mode 100644 index bf9d6ee931d..00000000000 --- a/src/cegis/options/parameters.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_OPTIONS_PARAMETERS_H -#define CPROVER_CEGIS_OPTIONS_PARAMETERS_H - -#define CEGIS_GENETIC "cegis-genetic" -#define CEGIS_GENETIC_ONLY "cegis-genetic-only" -#define CEGIS_MAX_SIZE "cegis-max-size" -#define CEGIS_SEED "cegis-seed" -#define CEGIS_STATISTICS "cegis-statistics" -#define CEGIS_POPSIZE "cegis-genetic-popsize" -#define CEGIS_ROUNDS "cegis-genetic-rounds" -#define CEGIS_LIMIT_WORDSIZE "cegis-limit-wordsize" -#define CEGIS_PARALLEL_VERIFY "cegis-parallel-verify" -#define CEGIS_MATCH_SELECT "cegis-match-select" -#define CEGIS_SYMEX_HEAD_START "cegis-symex-head-start" -#define CEGIS_SHOW_ITERATIONS "cegis-show-iterations" -#define CEGIS_KEEP_GOTO_PROGRAMS "cegis-keep-goto-programs" -#define CEGIS_MAX_RUNTIME "cegis-max-runtime" -#define CEGIS_CONTROL "cegis-control" -#define CEGIS_REFACTOR "cegis-refactor" -#define CEGIS_NULL_OBJECT_REFACTOR "cegis-refactor-null-object" - -#endif // CPROVER_CEGIS_OPTIONS_PARAMETERS_H diff --git a/src/cegis/refactor/constraint/constraint_factory.cpp b/src/cegis/refactor/constraint/constraint_factory.cpp deleted file mode 100644 index 318093a5a79..00000000000 --- a/src/cegis/refactor/constraint/constraint_factory.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -code_typet create_func_type() -{ - code_typet result; - result.return_type()=empty_typet(); - return result; -} - -void create_or_redirect_entry(symbol_tablet &st, goto_functionst &gf) -{ - typedef goto_functionst::function_mapt fmapt; - fmapt &fmap=gf.function_map; - const fmapt::const_iterator it=fmap.find(goto_functionst::entry_point()); - null_message_handlert msg; - if(fmap.end() == it) - { - config.main=CONSTRAINT_CALLER; - assert(!java_entry_point(st, ID_empty, msg, false, 0)); - goto_convert(CPROVER_INIT, st, gf, msg); - goto_convert(goto_functionst::entry_point(), st, gf, msg); - } else - { - // TODO: Implement - assert(false); - } -} - -void add_to_symbol_table(symbol_tablet &st, const std::string &name, - const goto_functionst::function_mapt::mapped_type &func) -{ - if(st.has_symbol(name)) return; - symbolt new_symbol; - new_symbol.name=name; - new_symbol.type=func.type; - new_symbol.base_name=name; - new_symbol.pretty_name=name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - new_symbol.value=code_blockt(); - assert(!st.add(new_symbol)); -} -} - -void create_constraint_function_caller(refactor_programt &prog) -{ - goto_functionst &gf=prog.gf; - const char * const func_name=CONSTRAINT_CALLER_ID; - goto_functionst::function_mapt::mapped_type &func=gf.function_map[func_name]; - func.type=create_func_type(); - goto_programt &body=func.body; - const source_locationt loc(default_cegis_source_location()); - symbol_tablet &st=prog.st; - for(const refactor_programt::sketcht &sketch : prog.sketches) - { - const symbolt &symbol=st.lookup(sketch.init->function); - const code_typet &type=to_code_type(symbol.type); - goto_programt::targett pos=body.add_instruction( - goto_program_instruction_typet::FUNCTION_CALL); - pos->source_location=loc; - code_function_callt call; - call.function()=symbol.symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - for(const code_typet::parametert ¶m : type.parameters()) - args.push_back(from_integer(0, param.type())); - pos->code=call; - } - body.add_instruction(goto_program_instruction_typet::END_FUNCTION); - body.update(); - add_to_symbol_table(st, func_name, func); - create_or_redirect_entry(st, gf); -} - -#define CLONE_SUFFIX "_CLONE" -#define INIT_SUFFIX "_INIT" - -namespace -{ -const goto_ranget &get_first_range(const refactor_programt::sketcht &sketch) -{ - const size_t input_dist=std::distance(sketch.init, sketch.input_range.first); - const size_t spec_dist=std::distance(sketch.init, sketch.spec_range.first); - return input_dist < spec_dist ? sketch.input_range : sketch.spec_range; -} - -const goto_ranget &get_second_range(const refactor_programt::sketcht &sketch) -{ - const size_t input_dist=std::distance(sketch.init, sketch.input_range.first); - const size_t spec_dist=std::distance(sketch.init, sketch.spec_range.first); - return input_dist >= spec_dist ? sketch.input_range : sketch.spec_range; -} - -void make_skip(const goto_programt::targett first, - const goto_programt::targett last) -{ - std::for_each(first, last, [](goto_programt::instructiont &instr) - { if(!instr.is_decl()) instr.make_skip();}); -} - -void link_refactoring_ranges(goto_programt &body, - const refactor_programt::sketcht &sketch) -{ - goto_programt::instructionst &instrs=body.instructions; - make_skip(instrs.begin(), sketch.init); - sketch.init->make_skip(); - const goto_ranget &first=get_first_range(sketch); - const goto_ranget &second=get_second_range(sketch); - make_skip(first.second, second.first); - make_skip(second.second, std::prev(instrs.end())); -} - -goto_programt::targett nondet_init(const symbol_tablet &st, goto_programt &body, - goto_programt::targett pos, const irep_idt &state_var) -{ - const symbolt &symbol=st.lookup(state_var); - if(!is_cegis_primitive(symbol.type)) return pos; // TODO: Handle class types - pos=insert_after_preserving_source_location(body, pos); - pos->type=goto_program_instruction_typet::ASSIGN; - const symbol_exprt lhs(symbol.symbol_expr()); - const side_effect_expr_nondett rhs(lhs.type()); - pos->code=code_assignt(lhs, rhs); - return pos; -} - -goto_programt::targett havoc_inputs(const symbol_tablet &st, - goto_programt &body, const refactor_programt::sketcht &sketch) -{ - goto_programt::targett pos=sketch.init; - for(const irep_idt &state_var : sketch.state_vars) - pos=nondet_init(st, body, pos, state_var); - return pos; -} - -std::string get_clone_name(const irep_idt &id, const char * const suffix) -{ - std::string result(id2string(id)); - return result+=suffix; -} - -std::string get_clone_id(const irep_idt &id, const std::string &func, - const char * suffix) -{ - return get_local_meta_name(func, get_clone_name(id, suffix)); -} - -goto_programt::targett create_snapshot(symbol_tablet &st, goto_programt &body, - const std::string &func_name, const std::set &state_vars, - goto_programt::targett pos, const char * const suffix) -{ - for(const irep_idt &state_var : state_vars) - { - const symbolt &symbol=st.lookup(state_var); - const typet &type=symbol.type; - if(!is_cegis_primitive(type)) continue; // TODO: Handle class types (clone) - const std::string clone_name(get_clone_name(symbol.base_name, suffix)); - pos=declare_local_meta_variable(st, func_name, body, pos, clone_name, type); - const symbol_exprt rhs(symbol.symbol_expr()); - pos=cegis_assign_local_variable(st, body, pos, func_name, clone_name, rhs); - } - return pos; -} - -void create_init_snapshot(symbol_tablet &st, goto_programt &body, - const refactor_programt::sketcht &sketch, const goto_programt::targett pos) -{ - if(sketch.state_vars.empty()) return; - const std::string func(id2string(sketch.init->function)); - create_snapshot(st, body, func, sketch.state_vars, pos, INIT_SUFFIX); -} - -goto_programt::targett create_baseline_snapshot(symbol_tablet &st, - goto_programt &body, const refactor_programt::sketcht &sketch) -{ - const goto_ranget &range=get_second_range(sketch); - goto_programt::targett pos=std::prev(range.first); - const std::string func(id2string(sketch.init->function)); - return create_snapshot(st, body, func, sketch.state_vars, pos, CLONE_SUFFIX); -} - -void assign_init_snapshot(symbol_tablet &st, goto_programt &body, - const refactor_programt::sketcht &sketch, goto_programt::targett pos) -{ - const std::string &func=id2string(sketch.init->function); - for(const irep_idt &var : sketch.state_vars) - { - const symbolt &symbol=st.lookup(var); - if(!is_cegis_primitive(symbol.type)) continue; // TODO: Handle class types - const symbol_exprt lhs(symbol.symbol_expr()); - const irep_idt &base_name=symbol.base_name; - const std::string rhs_name(get_clone_id(base_name, func, INIT_SUFFIX)); - const symbol_exprt rhs(st.lookup(rhs_name).symbol_expr()); - pos=cegis_assign(st, body, pos, lhs, rhs, pos->source_location); - } -} - -equal_exprt equal_to_clone(const symbol_tablet &st, const irep_idt &func_name, - const irep_idt &state_var) -{ - const symbolt &symbol=st.lookup(state_var); - const symbol_exprt lhs(symbol.symbol_expr()); - const irep_idt &base_name=symbol.base_name; - const std::string fn(id2string(func_name)); - const std::string clone_var(get_clone_id(base_name, fn, CLONE_SUFFIX)); - const symbol_exprt rhs(st.lookup(clone_var).symbol_expr()); - return equal_exprt(lhs, rhs); -} - -void insert_assertion(/*const */symbol_tablet &st, goto_programt &body, - const refactor_programt::sketcht &sketch) -{ - const irep_idt &func_name=sketch.init->function; - exprt::operandst clauses; - for(const irep_idt &var : sketch.state_vars) - { - if(!is_cegis_primitive(st.lookup(var).type)) continue; // TODO: Handle class types - if(is_refactor_meta_var(var)) continue; - clauses.push_back(equal_to_clone(st, func_name, var)); - } - goto_programt::targett pos=get_second_range(sketch).second; - pos=insert_after_preserving_source_location(body, pos); - pos->type=goto_program_instruction_typet::ASSERT; - pos->guard=conjunction(clauses); -} -} - -void create_refactoring_constraint(refactor_programt &prog) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - for(const refactor_programt::sketcht &sketch : prog.sketches) - { - goto_programt &body=get_body(gf, sketch.init); - link_refactoring_ranges(body, sketch); - goto_programt::targett pos=havoc_inputs(st, body, sketch); - create_init_snapshot(st, body, sketch, pos); - pos=create_baseline_snapshot(st, body, sketch); - assign_init_snapshot(st, body, sketch, pos); - insert_assertion(st, body, sketch); - body.update(); - body.compute_loop_numbers(); - } -} diff --git a/src/cegis/refactor/constraint/constraint_factory.h b/src/cegis/refactor/constraint/constraint_factory.h deleted file mode 100644 index a6c42be5661..00000000000 --- a/src/cegis/refactor/constraint/constraint_factory.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_CONSTRAINT_CONSTRAINT_FACTORY_H -#define CPROVER_CEGIS_REFACTOR_CONSTRAINT_CONSTRAINT_FACTORY_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void create_constraint_function_caller(class refactor_programt &prog); - -/** - * @brief - * - * @details - * - * @param prog - */ -void create_refactoring_constraint(refactor_programt &prog); - -#endif // CPROVER_CEGIS_REFACTOR_CONSTRAINT_CONSTRAINT_FACTORY_H diff --git a/src/cegis/refactor/environment/instrument_state_vars.cpp b/src/cegis/refactor/environment/instrument_state_vars.cpp deleted file mode 100644 index 176a47bb933..00000000000 --- a/src/cegis/refactor/environment/instrument_state_vars.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -namespace -{ -class var_findert: public const_expr_visitort -{ - std::set &vars; -public: - explicit var_findert(std::set &vars) : - vars(vars) - { - } - - virtual ~var_findert()=default; - - virtual void operator()(const exprt &expr) - { - if(ID_symbol != expr.id()) return; - if(ID_code == expr.type().id()) return; - // TODO: Follow function calls - vars.insert(to_symbol_expr(expr).get_identifier()); - } -}; -} - -void collect_state_vars(std::set &result, - goto_programt::const_targett first, const goto_programt::const_targett last) -{ - var_findert visitor(result); - for(; first != last; ++first) - { - first->code.visit(visitor); - first->guard.visit(visitor); - } -} - -void instrument_program_ops(goto_programt &body, goto_programt::targett pos, - const std::set &state_vars, - const std::function predicate) -{ - // TODO: Implement - assert(false); -} - -namespace -{ -bool use_all(const typet &instr) -{ - return true; -} -} - -void instrument_program_ops(goto_programt &body, goto_programt::targett pos, - const std::set &state_vars) -{ - instrument_program_ops(body, pos, state_vars, use_all); -} diff --git a/src/cegis/refactor/environment/instrument_state_vars.h b/src/cegis/refactor/environment/instrument_state_vars.h deleted file mode 100644 index ee5cdd5679e..00000000000 --- a/src/cegis/refactor/environment/instrument_state_vars.h +++ /dev/null @@ -1,61 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_ENVIRONMENT_INSTRUMENT_STATE_VARS_H -#define CPROVER_CEGIS_REFACTOR_ENVIRONMENT_INSTRUMENT_STATE_VARS_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param result - * @param first - * @param last - */ -void collect_state_vars( - std::set &result, - goto_programt::const_targett first, - goto_programt::const_targett last); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param state_vars - * @param predicate - */ -void instrument_program_ops( - goto_programt &body, - goto_programt::targett pos, - const std::set &state_vars, - std::function predicate); - -/** - * @brief - * - * @details - * - * @param body - * @param pos - * @param state_vars - */ -void instrument_program_ops( - goto_programt &body, - goto_programt::targett pos, - const std::set &state_vars); - -#endif // CPROVER_CEGIS_REFACTOR_ENVIRONMENT_INSTRUMENT_STATE_VARS_H diff --git a/src/cegis/refactor/facade/refactor_runner.cpp b/src/cegis/refactor/facade/refactor_runner.cpp deleted file mode 100644 index 3d4ed42ddc2..00000000000 --- a/src/cegis/refactor/facade/refactor_runner.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -int run_refactor(optionst &options, messaget::mstreamt &result, - const symbol_tablet &st, const goto_functionst &gf) -{ - refactor_preprocessingt preproc(options, st, gf); - refactor_symex_learnt learn_cfg(preproc.get_program()); - refactor_symex_verifyt verify_cfg(preproc.get_program()); - cegis_symex_learnt learn( - options, preproc, learn_cfg); - cegis_symex_verifyt oracle(options, verify_cfg); - return run_cegis_with_statistics_wrapper( - result, options, learn, oracle, preproc); -} diff --git a/src/cegis/refactor/facade/refactor_runner.h b/src/cegis/refactor/facade/refactor_runner.h deleted file mode 100644 index b27073e3f0e..00000000000 --- a/src/cegis/refactor/facade/refactor_runner.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_FACADE_REFACTOR_RUNNER_H -#define CPROVER_CEGIS_REFACTOR_FACADE_REFACTOR_RUNNER_H - -#include - -/** - * @brief - * - * @details - * - * @param options - * @param result - * @param st - * @param gf - * - * @return - */ -int run_refactor(class optionst &options, messaget::mstreamt &result, - const class symbol_tablet &st, const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_REFACTOR_FACADE_REFACTOR_RUNNER_H diff --git a/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp b/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp deleted file mode 100644 index 9bf45fd9ec3..00000000000 --- a/src/cegis/refactor/instructionset/cegis_instruction_factory.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include - -namespace -{ -class arithmetic_assignt -{ - const irep_idt id; - const typet type; -public: - arithmetic_assignt(const irep_idt &id, const typet &type) : - id(id), type(type) - { - } - - goto_programt::targett operator()(const symbol_tablet &st, - const std::string &func_name, goto_programt &body, - const goto_programt::targett pos) const - { - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=default_cegis_source_location(); - const dereference_exprt lhs(cegis_operand(st, func_name, type, 1)); - const dereference_exprt rhs(cegis_operand(st, func_name, type, 2)); - const binary_exprt result(lhs, id, rhs); - pos->code=code_assignt(cegis_operand(st, func_name, type, 0), result); - return pos; - } -}; - -class arithmetic_instructionst -{ - const typet &type; - const instruction_descriptiont::typest sig; -public: - explicit arithmetic_instructionst(const typet &type) : - type(type), sig( { type, type, type }) - { - } - - instruction_descriptiont plus() const - { - return instruction_descriptiont(sig, arithmetic_assignt(ID_plus, type)); - } - - instruction_descriptiont minus() const - { - return instruction_descriptiont(sig, arithmetic_assignt(ID_minus, type)); - } - - instruction_descriptiont mult() const - { - return instruction_descriptiont(sig, arithmetic_assignt(ID_mult, type)); - } - - instruction_descriptiont div() const - { - return instruction_descriptiont(sig, arithmetic_assignt(ID_div, type)); - } -}; - -class assignt -{ - const typet type; -public: - explicit assignt(const typet &type) : - type(type) - { - } - - goto_programt::targett operator()(const symbol_tablet &st, - const std::string &func_name, goto_programt &body, - goto_programt::targett pos) const - { - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=default_cegis_source_location(); - const dereference_exprt lhs(cegis_operand(st, func_name, type, 0)); - const dereference_exprt rhs(cegis_operand(st, func_name, type, 1)); - pos->code=code_assignt(lhs, rhs); - return pos; - } -}; - -instruction_descriptiont assign_desc(const typet &type) -{ - return instruction_descriptiont( { type, type }, assignt(type)); -} - -void insert( - std::map &result, - const instruction_descriptiont &instr) -{ - result[instr.signature].push_back(instr); -} -} - -ordered_instructionst get_instructions_for_types( - const cegis_operand_datat &signature) -{ - ordered_instructionst result; - for(const cegis_operand_datat::value_type &typeWithSlots : signature) - { - const typet &type=typeWithSlots.first; - if(!is_cegis_primitive(type)) continue; // TODO: Add support for class types - const arithmetic_instructionst arith(type); - insert(result, arith.plus()); - insert(result, arith.minus()); - insert(result, arith.mult()); - insert(result, arith.div()); - insert(result, assign_desc(type)); - } - return result; -} - -instruction_descriptionst::size_type num_instrs( - const ordered_instructionst &instrs) -{ - return std::accumulate(instrs.begin(), instrs.end(), 0, - [](const size_t count, const ordered_instructionst::value_type &instrs) - { return count + instrs.second.size();}); -} diff --git a/src/cegis/refactor/instructionset/cegis_instruction_factory.h b/src/cegis/refactor/instructionset/cegis_instruction_factory.h deleted file mode 100644 index f5426c54cfb..00000000000 --- a/src/cegis/refactor/instructionset/cegis_instruction_factory.h +++ /dev/null @@ -1,42 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H - -#include -#include - -typedef std::map ordered_instructionst; - -/** - * @brief - * - * @details - * - * @param signature - * - * @return - */ -ordered_instructionst get_instructions_for_types( - const cegis_operand_datat &signature); - -/** - * @brief - * - * @details - * - * @param instrs - * - * @result - */ -instruction_descriptionst::size_type num_instrs( - const ordered_instructionst &instrs); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_INSTRUCTION_FACTORY_H diff --git a/src/cegis/refactor/instructionset/cegis_processor_body_factory.cpp b/src/cegis/refactor/instructionset/cegis_processor_body_factory.cpp deleted file mode 100644 index 06161aa4e1d..00000000000 --- a/src/cegis/refactor/instructionset/cegis_processor_body_factory.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#define NUM_PRIMITIVE_OPERANDS 3u - -namespace -{ -size_t cegis_max_operands(const typet &type) -{ - if(!is_cegis_primitive(type)) return 0; // TODO: Add support for class types - return NUM_PRIMITIVE_OPERANDS; -} -} - -size_t cegis_max_operands(const cegis_operand_datat &slots) -{ - size_t max=0; - for(const cegis_operand_datat::value_type &slot : slots) - max=std::max(max, cegis_max_operands(slot.first)); - return max; -} - -namespace -{ -class body_factoryt -{ - const cegis_operand_datat &slots; - const ordered_instructionst &ordered_instructions; - symbol_tablet &st; - goto_programt &body; - const std::string &func_name; - const source_locationt loc; - const goto_programt::targett first; - const goto_programt::targett last; - goto_programt::targett pos; - goto_programt::targett loop_head; - goto_programt::targett last_case; - goto_programt::targett switch_end; - - std::string meta_name(const std::string &base_name) - { - return get_local_meta_name(func_name, base_name); - } - - void src_loc(const goto_programt::targett pos) - { - pos->source_location=loc; - pos->function=func_name; - } - - goto_programt::targett dead(const std::string &name) - { - goto_programt::targett pos=body.insert_after(this->pos); - pos->type=goto_program_instruction_typet::DEAD; - src_loc(pos); - const std::string symbol_name(meta_name(name)); - pos->code=code_deadt(st.lookup(symbol_name).symbol_expr()); - return pos; - } - - void decl(const std::string &name, const typet &type) - { - pos=declare_local_meta_variable(st, func_name, body, pos, name, type); - dead(name); - } - - void decl(const std::string &name, const exprt &value) - { - decl(name, value.type()); - pos=cegis_assign_local_variable(st, body, pos, func_name, name, value); - } - - void add_goto(const exprt &guard, const goto_programt::targett &target) - { - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - src_loc(pos); - pos->set_target(target); - pos->guard=guard; - } - - goto_programt::targett add_conditional_instr_goto(const size_t opcode, - const irep_idt &relation) - { - if(last == switch_end) - { - switch_end=body.insert_after(pos); - switch_end->type=goto_program_instruction_typet::SKIP; - switch_end->source_location=loc; - } - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - src_loc(pos); - const constant_exprt rhs(from_integer(opcode, cegis_size_type())); - const member_exprt lhs(cegis_opcode(st, func_name)); - pos->guard=binary_relation_exprt(lhs, relation, rhs); - if(last != last_case) last_case->set_target(pos); - last_case=pos; - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::SKIP; - src_loc(pos); - const goto_programt::targett result(pos); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::GOTO; - src_loc(pos); - pos->set_target(switch_end); - return result; - } - - void finalise_conditional_instr_gotos() - { - assert(last != last_case); - last_case->set_target(switch_end); - last_case=last; - assert(last != switch_end); - pos=switch_end; - switch_end=last; - } - - void assume_less(const goto_programt::targett pos, const exprt &lhs, - const size_t value) - { - const constant_exprt rhs(from_integer(value, cegis_opcode_type())); - pos->type=goto_program_instruction_typet::ASSUME; - src_loc(pos); - pos->guard=binary_relation_exprt(lhs, ID_lt, rhs); - } -public: - body_factoryt(const cegis_operand_datat &slots, - const ordered_instructionst &ordered_instructions, symbol_tablet &st, - goto_programt &body, const std::string &func_name) : - slots(slots), ordered_instructions(ordered_instructions), st(st), body( - body), func_name(func_name), loc(default_cegis_source_location()), first( - body.add_instruction(SKIP)), last(body.instructions.end()), pos( - first), loop_head(last), last_case(last), switch_end(last) - { - } - - ~body_factoryt() - { - body.instructions.erase(first); - } - - void declare_instruction_loop_head() - { - decl(CEGIS_PROC_INSTR_INDEX, from_integer(0, cegis_size_type())); - const member_exprt opcode(cegis_opcode(st, func_name)); - const size_t size(num_instrs(ordered_instructions)); - assume_less(pos=body.insert_after(pos), opcode, size); - loop_head=pos; - } - - void finish_instruction_loop() - { - pos=std::prev(body.instructions.end(), 2); - while(goto_program_instruction_typet::DEAD == pos->type) - pos=std::prev(pos); - const char * const base_idx_name=CEGIS_PROC_INSTR_INDEX; - const std::string idx(meta_name(base_idx_name)); - const symbol_exprt idx_expr(st.lookup(idx).symbol_expr()); - const plus_exprt rhs(idx_expr, from_integer(1, idx_expr.type())); - cegis_assign_local_variable(st, body, pos, func_name, base_idx_name, rhs); - pos=std::prev(body.instructions.end(), 2); - const std::string index(meta_name(CEGIS_PROC_INSTR_INDEX)); - const symbol_exprt index_expr(st.lookup(index).symbol_expr()); - const std::string sz(meta_name(CEGIS_PROC_PROGRAM_SIZE_PARAM_ID)); - const symbol_exprt sz_expr(st.lookup(sz).symbol_expr()); - const binary_relation_exprt guard(index_expr, ID_lt, sz_expr); - add_goto(guard, std::next(loop_head)); - } - - void add_signature_assumptions() - { - size_t opcode=0; - for(const ordered_instructionst::value_type &entry : ordered_instructions) - { - const ordered_instructionst::value_type::second_type &instrs=entry.second; - opcode+=instrs.size(); - goto_programt::targett pos=add_conditional_instr_goto(opcode, ID_ge); - const ordered_instructionst::value_type::first_type &sig=entry.first; - for(size_t op=0; op < sig.size(); ++op) - { - if(SKIP != pos->type) pos=body.insert_after(pos); - const cegis_operand_datat::const_iterator it=slots.find(sig[op]); - assert(slots.end() != it); - const member_exprt operand_id(cegis_operand_id(st, func_name, op)); - assume_less(pos, operand_id, it->second); - } - } - finalise_conditional_instr_gotos(); - } - - void execute_instructions() - { - const irep_idt id(ID_notequal); - size_t opc=0; - for(const ordered_instructionst::value_type &entry : ordered_instructions) - for(const instruction_descriptiont &instr : entry.second) - { - const goto_programt::targett it=add_conditional_instr_goto(opc++, id); - instr(st, func_name, body, it); - } - finalise_conditional_instr_gotos(); - } -}; -} - -void generate_processor_body(symbol_tablet &st, goto_programt &body, - const std::string &name, const cegis_operand_datat &slots) -{ - const ordered_instructionst instructions(get_instructions_for_types(slots)); - if(!slots.empty()) - { - body_factoryt factory(slots, instructions, st, body, name); - factory.declare_instruction_loop_head(); - factory.add_signature_assumptions(); - factory.execute_instructions(); - factory.finish_instruction_loop(); - } - body.add_instruction(goto_program_instruction_typet::END_FUNCTION); - body.compute_loop_numbers(); - body.update(); -} diff --git a/src/cegis/refactor/instructionset/cegis_processor_body_factory.h b/src/cegis/refactor/instructionset/cegis_processor_body_factory.h deleted file mode 100644 index bd2b3e5470d..00000000000 --- a/src/cegis/refactor/instructionset/cegis_processor_body_factory.h +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_PROCESSOR_BODY_FACTORY_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_PROCESSOR_BODY_FACTORY_H - -#include - -/** - * @brief - * - * @details - * - * @param op - * - * @return - */ -std::string cegis_operand_base_name(size_t op); - -/** - * @brief - * - * @details - * - * @param slots - * - * @return - */ -size_t cegis_max_operands(const cegis_operand_datat &slots); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param name - * @param slots - */ -void generate_processor_body( - class symbol_tablet &st, - class goto_programt &body, - const std::string &name, - const cegis_operand_datat &slots); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CEGIS_PROCESSOR_BODY_FACTORY_H diff --git a/src/cegis/refactor/instructionset/create_cegis_processor.cpp b/src/cegis/refactor/instructionset/create_cegis_processor.cpp deleted file mode 100644 index 5df7c1055a0..00000000000 --- a/src/cegis/refactor/instructionset/create_cegis_processor.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -bool is_empty(const typet &type) -{ - const irep_idt &id=type.id(); - if(ID_pointer == id) return is_empty(type.subtype()); - return ID_empty == id || id.empty(); -} - -class type_collectort: public const_expr_visitort -{ -public: - std::set types; - - virtual ~type_collectort()=default; - - virtual void operator()(const exprt &expr) - { - const typet &type=expr.type(); - if(ID_code != type.id() && !is_empty(type)) types.insert(expr.type()); - } -}; -} - -std::set collect_context_types(const goto_ranget &range) -{ - type_collectort collector; - for(goto_programt::const_targett it(range.first); it != range.second; ++it) - it->code.visit(collector); - return collector.types; -} - -#define MAX_PROCESSORS 128u - -namespace -{ -void create_variable_array(symbol_tablet &st, goto_functionst &gf, - const typet &type, const size_t size) -{ - const std::string name(cegis_operand_array_name(st, type)); - if(st.has_symbol(name)) return; - const typet size_type(signed_int_type()); - const constant_exprt sz_expr(from_integer(size, size_type)); - const array_typet array_type(pointer_typet(type), sz_expr); - symbolt new_symbol; - new_symbol.name=name; - new_symbol.type=array_type; - new_symbol.base_name=name; - new_symbol.pretty_name=name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - new_symbol.is_static_lifetime=true; - new_symbol.is_lvalue=true; - assert(!st.add(new_symbol)); - goto_programt &body=get_body(gf, CPROVER_INIT); - goto_programt::targett pos=body.instructions.begin(); - pos=body.insert_after(pos); - pos->type=goto_program_instruction_typet::ASSIGN; - pos->source_location=new_symbol.location; - const symbol_exprt lhs(st.lookup(name).symbol_expr()); - const namespacet ns(st); - const exprt rhs(zero_initializer(array_type, new_symbol.location, ns)); - pos->code=code_assignt(lhs, rhs); - body.update(); -} - -#define CEGIS_PROCESSOR_FUNCTION_PREFIX CEGIS_PREFIX "processor_" - -std::string get_next_processor_name(const symbol_tablet &st) -{ - std::string name(CEGIS_PROCESSOR_FUNCTION_PREFIX); - for(size_t index=0; index < MAX_PROCESSORS; ++index) - { - name+=std::to_string(index); - if(!st.has_symbol(name)) return name; - else name= CEGIS_PROCESSOR_FUNCTION_PREFIX; - } - assert(!"Exceeded maximum number of CEGIS processors."); - return ""; -} - -symbol_typet create_instruction_type(symbol_tablet &st, - const cegis_operand_datat &variable_slots_per_context_type, - const std::string &func_name) -{ - std::string instr_type_name(func_name); - instr_type_name+= INSTR_TYPE_SUFFIX; - if(st.has_symbol(instr_type_name)) return symbol_typet(instr_type_name); - struct_typet type; - std::string tag(TAG_PREFIX); - tag+=instr_type_name; - type.set_tag(tag); - struct_union_typet::componentst &comps=type.components(); - const typet opcode_type(cegis_opcode_type()); - const std::string member_name(CEGIS_PROC_OPCODE_MEMBER_NAME); - comps.push_back(struct_typet::componentt(member_name, opcode_type)); - const size_t max_operands=cegis_max_operands(variable_slots_per_context_type); - const typet op_type(cegis_operand_type()); - for(size_t i=0; i < max_operands; ++i) - { - struct_union_typet::componentt comp(cegis_operand_base_name(i), op_type); - comps.push_back(comp); - } - symbolt new_symbol; - new_symbol.name=instr_type_name; - new_symbol.type=type; - new_symbol.base_name=instr_type_name; - new_symbol.pretty_name=instr_type_name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - new_symbol.is_type=true; - assert(!st.add(new_symbol)); - return symbol_typet(instr_type_name); -} - -code_typet create_func_type(const symbol_tablet &st, - const symbol_typet &instruction_type, const std::string &func_name) -{ - code_typet code_type; - code_type.return_type()=empty_typet(); - const pointer_typet instr_ref_type(instruction_type); - code_typet::parametert prog(instr_ref_type); - const char * const prog_base_name=CEGIS_PROC_PROGRAM_PARAM_ID; - prog.set_identifier(get_local_meta_name(func_name, prog_base_name)); - code_type.parameters().push_back(prog); - code_typet::parametert size(cegis_size_type()); - const char * const size_base_name=CEGIS_PROC_PROGRAM_SIZE_PARAM_ID; - size.set_identifier(get_local_meta_name(func_name, size_base_name)); - code_type.parameters().push_back(size); - return code_type; -} - -void add_param(symbol_tablet &st, const std::string &func, - const char * const name, const typet &type) -{ - symbolt prog_param_symbol; - prog_param_symbol.name=get_local_meta_name(func, name); - prog_param_symbol.type=type; - prog_param_symbol.base_name=name; - prog_param_symbol.pretty_name=name; - prog_param_symbol.location=default_cegis_source_location(); - prog_param_symbol.mode=ID_C; - prog_param_symbol.module=CEGIS_MODULE; - prog_param_symbol.is_lvalue=true; - prog_param_symbol.is_thread_local=true; - prog_param_symbol.is_file_local=true; - prog_param_symbol.is_parameter=true; - prog_param_symbol.is_state_var=true; - assert(!st.add(prog_param_symbol)); -} - -void add_to_symbol_table(symbol_tablet &st, const std::string &name, - const goto_functionst::function_mapt::mapped_type &func) -{ - if(st.has_symbol(name)) return; - symbolt new_symbol; - new_symbol.name=name; - new_symbol.type=func.type; - new_symbol.base_name=name; - new_symbol.pretty_name=name; - new_symbol.location=default_cegis_source_location(); - new_symbol.mode=ID_C; - new_symbol.module=CEGIS_MODULE; - assert(!st.add(new_symbol)); - const code_typet::parameterst ¶ms=func.type.parameters(); - assert(2 == params.size()); - add_param(st, name, CEGIS_PROC_PROGRAM_PARAM_ID, params.front().type()); - add_param(st, name, CEGIS_PROC_PROGRAM_SIZE_PARAM_ID, params.back().type()); -} -} - -std::string create_cegis_processor(symbol_tablet &st, goto_functionst &gf, - const cegis_operand_datat &slots) -{ - for(const std::pair &var_slot : slots) - create_variable_array(st, gf, var_slot.first, var_slot.second); - const std::string func_name(get_next_processor_name(st)); - const symbol_typet instr_type(create_instruction_type(st, slots, func_name)); - goto_functionst::function_mapt::mapped_type &func=gf.function_map[func_name]; - func.parameter_identifiers.push_back(CEGIS_PROC_PROGRAM_PARAM_ID); - func.parameter_identifiers.push_back(CEGIS_PROC_PROGRAM_SIZE_PARAM_ID); - func.type=create_func_type(st, instr_type, func_name); - add_to_symbol_table(st, func_name, func); - goto_programt &body=func.body; - generate_processor_body(st, body, func_name, slots); - return func_name; -} diff --git a/src/cegis/refactor/instructionset/create_cegis_processor.h b/src/cegis/refactor/instructionset/create_cegis_processor.h deleted file mode 100644 index 7b4a1273f66..00000000000 --- a/src/cegis/refactor/instructionset/create_cegis_processor.h +++ /dev/null @@ -1,92 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CREATE_CEGIS_PROCESSOR_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CREATE_CEGIS_PROCESSOR_H - -#include - -#include -#include - -#include - -/** - * @brief - * - * @details - * - * @param range - * - * @return - */ -std::set collect_context_types(const goto_ranget &range); - -/** - * @brief - * - * @details - * @code - * execute_next_instr: - * #define program[i].opcode opcode - * #define program[i].op0 op0 - * #define program[i].op1 op1 - * #define program[i].op2 op2 - * - * if (instr_code < 2) - * { - * __CPROVER_assume(op0 < __CPROVER_cegis_variable_array_int_size); - * __CPROVER_assume(op1 < __CPROVER_cegis_variable_array_int_size); - * __CPROVER_assume(op2 < __CPROVER_cegis_variable_array_int_size); - * } else if (instr_code < 4) - * { - * __CPROVER_assume(op0 < __CPROVER_cegis_variable_array_double_size); - * __CPROVER_assume(op1 < __CPROVER_cegis_variable_array_double_size); - * __CPROVER_assume(op2 < __CPROVER_cegis_variable_array_double_size); - * } else if (instr_code < 5) - * { - * __CPROVER_assume(op0 < __CPROVER_cegis_variable_array_iobject_size); - * __CPROVER_assume(op1 < __CPROVER_cegis_variable_array_double_size); - * } - * - * switch(instr_code) - * { - * case 0: - * *__CPROVER_cegis_variable_array_int[op0]=*__CPROVER_cegis_variable_array_int[op1] + *__CPROVER_cegis_variable_array_int[op2]; - * break; - * case 1: - * *__CPROVER_cegis_variable_array_int[op0]=*__CPROVER_cegis_variable_array_int[op1] - *__CPROVER_cegis_variable_array_int[op2]; - * break; - * case 2: - * *__CPROVER_cegis_variable_array_double[op0]=*__CPROVER_cegis_variable_array_double[op1] + *__CPROVER_cegis_variable_array_double[op2]; - * break; - * case 3: - * *__CPROVER_cegis_variable_array_double[op0]=*__CPROVER_cegis_variable_array_double[op1] - *__CPROVER_cegis_variable_array_double[op2]; - * break; - * case 4: - * *__CPROVER_cegis_variable_array_double[op0]=(*__CPROVER_cegis_variable_array_iobject[op1]).someMethod(*__CPROVER_cegis_variable_array_int[op2]); - * break; - * case 5: - * (*__CPROVER_cegis_variable_array_iobject[op0]).someOtherMethod(*__CPROVER_cegis_variable_array_double[op1]); - * break; - * } - * @endcode - * - * @param st - * @param gf - * @param variable_slots_per_context_type - * - * @return - */ -std::string create_cegis_processor( - symbol_tablet &st, - class goto_functionst &gf, - const std::map &variable_slots_per_context_type); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_CREATE_CEGIS_PROCESSOR_H diff --git a/src/cegis/refactor/instructionset/execute_cegis_program.cpp b/src/cegis/refactor/instructionset/execute_cegis_program.cpp deleted file mode 100644 index cdf64d359ba..00000000000 --- a/src/cegis/refactor/instructionset/execute_cegis_program.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -void declare_cegis_program(symbol_tablet &st, goto_functionst &gf, - const std::string &processor, const std::string &program_name) -{ - const typet size_type(signed_int_type()); - const constant_exprt sz_expr(from_integer(0, size_type)); - const code_typet &code_type=to_code_type(st.lookup(processor).type); - const typet &type=code_type.parameters().front().type().subtype(); - const array_typet array_type(type, sz_expr); - declare_global_meta_variable(st, program_name, array_type); -} - -std::string declare_cegis_program(symbol_tablet &st, goto_functionst &gf, - const std::string &processor) -{ - std::string prog_name(processor); - prog_name+=CEGIS_REFACTOR_PROG_SUFFIX; - declare_cegis_program(st, gf, processor, prog_name); - return prog_name; -} - -namespace -{ -const exprt &get_size(const symbolt &prog) -{ - return to_array_type(prog.type).size(); -} -} - -void call_processor(const symbol_tablet &st, goto_programt::instructiont &instr, - const std::string &processor, const std::string &program_name) -{ - instr.type=goto_program_instruction_typet::FUNCTION_CALL; - code_function_callt call; - call.function()=st.lookup(processor).symbol_expr(); - code_function_callt::argumentst &args=call.arguments(); - const symbolt &prog_symbol=st.lookup(program_name); - const symbol_exprt prog(prog_symbol.symbol_expr()); - const index_exprt first_instr(prog, from_integer(0, signed_int_type())); - args.push_back(address_of_exprt(first_instr)); - const bv_arithmetict bv(get_size(prog_symbol)); - const mp_integer sz_val(bv.to_integer()); - args.push_back(from_integer(sz_val, cegis_size_type())); - instr.code=call; - instr.source_location=default_cegis_source_location(); -} - -goto_programt::targett call_processor(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, - const std::string &processor, const std::string &program_name) -{ - pos=body.insert_after(pos); - call_processor(st, *pos, processor, program_name); - return pos; -} - -void set_cegis_processor_sizes(symbol_tablet &st, const size_t size) -{ - const constant_exprt sz_expr(from_integer(size, signed_int_type())); - for(symbol_tablet::symbolst::value_type &entry : st.symbols) - { - typet &type=entry.second.type; - if(ID_array != type.id()) continue; - array_typet &array_type=to_array_type(type); - const typet &elem_type=array_type.subtype(); - if(ID_symbol != elem_type.id()) continue; - const symbol_typet &symbol_type=to_symbol_type(elem_type); - const std::string &type_name=id2string(symbol_type.get_identifier()); - if(ends_with(type_name, INSTR_TYPE_SUFFIX)) array_type.size()=sz_expr; - } -} - -#define NUM_PROC_CALL_ARGS 2u - -void set_cegis_processor_sizes(const symbol_tablet &st, - goto_programt::targett first, const goto_programt::const_targett last, - const size_t size) -{ - const constant_exprt sz_expr(from_integer(size, cegis_size_type())); - for(; first != last; ++first) - { - if(goto_program_instruction_typet::FUNCTION_CALL != first->type) continue; - code_function_callt &call=to_code_function_call(first->code); - const exprt &func=call.function(); - if(ID_symbol != func.id()) continue; - const irep_idt &func_name=to_symbol_expr(func).get_identifier(); - if(!st.has_symbol(func_name)) continue; - const symbolt &symbol=st.lookup(func_name); - const code_typet &code_type=to_code_type(symbol.type); - const code_typet::parameterst ¶ms=code_type.parameters(); - if(params.size() != NUM_PROC_CALL_ARGS) continue; - const typet ¶m_ptr_type=params.front().type(); - if(ID_pointer != param_ptr_type.id()) continue; - const typet ¶m_type=param_ptr_type.subtype(); - if(ID_symbol != param_type.id()) continue; - const irep_idt ¶m_id=to_symbol_type(param_type).get_identifier(); - if(!ends_with(id2string(param_id), INSTR_TYPE_SUFFIX)) continue; - assert(call.arguments().size() == NUM_PROC_CALL_ARGS); - call.arguments().back()=sz_expr; - } -} - -void instrument_cegis_operand(const symbol_tablet &st, - goto_programt::instructiont &instr, const size_t index, - const irep_idt &var_name) -{ - const symbol_exprt var(st.lookup(var_name).symbol_expr()); - const std::string array_name(cegis_operand_array_name(st, var.type())); - const symbol_exprt array(st.lookup(array_name).symbol_expr()); - const constant_exprt index_expr(from_integer(index, signed_int_type())); - const index_exprt lhs(array, index_expr); - const address_of_exprt rhs(var); - instr.type=goto_program_instruction_typet::ASSIGN; - instr.source_location=default_cegis_source_location(); - instr.code=code_assignt(lhs, rhs); -} - -goto_programt::targett instrument_cegis_operand(const symbol_tablet &st, - goto_programt &body, goto_programt::targett pos, size_t index, - const irep_idt &var_name) -{ - pos=body.insert_after(pos); - instrument_cegis_operand(st, *pos, index, var_name); - return pos; -} diff --git a/src/cegis/refactor/instructionset/execute_cegis_program.h b/src/cegis/refactor/instructionset/execute_cegis_program.h deleted file mode 100644 index bf3c9d1dc8c..00000000000 --- a/src/cegis/refactor/instructionset/execute_cegis_program.h +++ /dev/null @@ -1,145 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_EXECUTE_CEGIS_PROGRAM_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_EXECUTE_CEGIS_PROGRAM_H - -#include - -#define CEGIS_REFACTOR_PROG_SUFFIX "_prog" - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param processor - * @param program_name - */ -void declare_cegis_program( - class symbol_tablet &st, - class goto_functionst &gf, - const std::string &processor, - const std::string &program_name); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param processor - * - * @return - */ -std::string declare_cegis_program( - symbol_tablet &st, - goto_functionst &gf, - const std::string &processor); - -/** - * @brief - * - * @details - * - * @param st - * @param instr - * @param processor - * @param program_name - */ -void call_processor( - const symbol_tablet &st, - goto_programt::instructiont &instr, - const std::string &processor, - const std::string &program_name); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param processor - * @param program_name - * - * @return - */ -goto_programt::targett call_processor( - const symbol_tablet &st, - goto_programt &body, - goto_programt::targett pos, - const std::string &processor, - const std::string &program_name); - -/** - * @brief - * - * @details - * - * @param st - * @param size - */ -void set_cegis_processor_sizes(symbol_tablet &st, size_t size); - -/** - * @brief - * - * @details - * - * @param st - * @param first - * @param last - * @param size - */ -void set_cegis_processor_sizes( - const symbol_tablet &st, - goto_programt::targett first, - goto_programt::const_targett last, - size_t size); - -/** - * @brief - * - * @details - * - * @param st - * @param instr - * @param index - * @param var_name - */ -void instrument_cegis_operand( - const symbol_tablet &st, - goto_programt::instructiont &instr, - size_t index, - const irep_idt &var_name); - -/** - * @brief - * - * @details - * - * @param st - * @param body - * @param pos - * @param index - * @param var_name - */ -goto_programt::targett instrument_cegis_operand( - const symbol_tablet &st, - goto_programt &body, - goto_programt::targett pos, - size_t index, - const irep_idt &var_name); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_EXECUTE_CEGIS_PROGRAM_H diff --git a/src/cegis/refactor/instructionset/instruction_description.cpp b/src/cegis/refactor/instructionset/instruction_description.cpp deleted file mode 100644 index ee063db4e6a..00000000000 --- a/src/cegis/refactor/instructionset/instruction_description.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -instruction_descriptiont::instruction_descriptiont(const typest &signature, - const instruction_factoryt &factory) : - signature(signature), factory(factory) -{ - assert(!signature.empty()); -} - -bool instruction_descriptiont::has_result() const -{ - return ID_empty != result_type().id(); -} - -const typet &instruction_descriptiont::result_type() const -{ - return signature.front(); -} - -instruction_descriptiont::typest instruction_descriptiont::operand_types() const -{ - return typest(std::next(signature.begin()), signature.end()); -} - -goto_programt::targett instruction_descriptiont::operator()( - const symbol_tablet &st, const std::string &func_name, goto_programt &body, - goto_programt::targett pos) const -{ - return factory(st, func_name, body, pos); -} diff --git a/src/cegis/refactor/instructionset/instruction_description.h b/src/cegis/refactor/instructionset/instruction_description.h deleted file mode 100644 index 00b08fcb0bb..00000000000 --- a/src/cegis/refactor/instructionset/instruction_description.h +++ /dev/null @@ -1,101 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_INSTRUCTION_DESCRIPTION_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_INSTRUCTION_DESCRIPTION_H - -#include - -#include - -typedef std::function< - goto_programt::targett( - const symbol_tablet &, - std::string, - goto_programt &, - goto_programt::targett)> instruction_factoryt; - -/** - * @brief - * - * @details - */ -class instruction_descriptiont { -public: - typedef std::vector typest; - const typest signature; -private: - const instruction_factoryt factory; -public: - /** - * @brief - * - * @detais - * - * @param signature - * @param factory - */ - instruction_descriptiont( - const typest &signature, - const instruction_factoryt &factory); - - /** - * @brief - * - * @details - * - * @return - */ - bool has_result() const; - - /** - * @brief - * - * @details - * - * @return - */ - const typet &result_type() const; - - /** - * @brief - * - * @details - * - * @return - */ - typest operand_types() const; - - /** - * @brief - * - * @details - * - * @param st - * @param func_name - * @param body - * @param pos - * - * @return - */ - goto_programt::targett operator()( - const symbol_tablet &st, - const std::string &func_name, - goto_programt &body, - goto_programt::targett pos) const; -}; - -/** - * @brief - * - * @details - */ -typedef std::vector instruction_descriptionst; - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_INSTRUCTION_DESCRIPTION_H diff --git a/src/cegis/refactor/instructionset/operand_data.h b/src/cegis/refactor/instructionset/operand_data.h deleted file mode 100644 index 34339985649..00000000000 --- a/src/cegis/refactor/instructionset/operand_data.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_OPERAND_DATA_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_OPERAND_DATA_H - -#include - -/** - * @brief - * - * @details - */ -typedef std::map cegis_operand_datat; - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_OPERAND_DATA_H diff --git a/src/cegis/refactor/instructionset/processor_symbols.cpp b/src/cegis/refactor/instructionset/processor_symbols.cpp deleted file mode 100644 index 2a5fd442a66..00000000000 --- a/src/cegis/refactor/instructionset/processor_symbols.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define VARIABLE_ARRAY_PREFIX CEGIS_PREFIX "variable_array_" - -std::string cegis_operand_array_name(const symbol_tablet &st, const typet &type) -{ - std::string result(VARIABLE_ARRAY_PREFIX); - return result+=type2c(type, namespacet(st)); -} - -#define OPERAND_ID_MEMBER_NAME_PREFIX "op_" - -std::string cegis_operand_base_name(const size_t op) -{ - std::string name(OPERAND_ID_MEMBER_NAME_PREFIX); - return name+=std::to_string(op); -} - -namespace -{ -dereference_exprt cegis_instr(const symbol_tablet &st, - const std::string &func_name) -{ - const char * const prog_base_name=CEGIS_PROC_PROGRAM_PARAM_ID; - const std::string prog_name(get_local_meta_name(func_name, prog_base_name)); - const symbol_exprt prog(st.lookup(prog_name).symbol_expr()); - const char * const index_base_name=CEGIS_PROC_INSTR_INDEX; - const std::string index_name(get_local_meta_name(func_name, index_base_name)); - const symbol_exprt index(st.lookup(index_name).symbol_expr()); - return dereference_exprt(plus_exprt(prog, index), prog.type().subtype()); -} -} - -member_exprt cegis_opcode(const symbol_tablet &st, const std::string &func_name) -{ - const dereference_exprt instr(cegis_instr(st, func_name)); - const typet member_type(cegis_opcode_type()); - return member_exprt(instr, CEGIS_PROC_OPCODE_MEMBER_NAME, member_type); -} - -member_exprt cegis_operand_id(const symbol_tablet &st, - const std::string &func_name, const size_t op) -{ - const dereference_exprt instr(cegis_instr(st, func_name)); - const std::string member_name(cegis_operand_base_name(op)); - const typet member_type(cegis_operand_type()); - return member_exprt(instr, member_name, member_type); -} - -dereference_exprt cegis_operand(const symbol_tablet &st, - const std::string &func_name, const typet &type, const size_t op) -{ - const member_exprt operand_id(cegis_operand_id(st, func_name, op)); - const std::string array_name(cegis_operand_array_name(st, type)); - const symbol_exprt array(st.lookup(array_name).symbol_expr()); - return dereference_exprt(index_exprt(array, operand_id), type); -} - -namespace -{ -#define JAVA_TMP_RETURN "::return_tmp" -} - -bool is_refactor_meta_var(const irep_idt &var) -{ - const std::string &var_name=id2string(var); - return starts_with(var_name, CPROVER_PREFIX) - || contains(var_name, RETURN_VALUE_SUFFIX) - || contains(var_name, JAVA_TMP_RETURN); -} diff --git a/src/cegis/refactor/instructionset/processor_symbols.h b/src/cegis/refactor/instructionset/processor_symbols.h deleted file mode 100644 index cf6a0734ee7..00000000000 --- a/src/cegis/refactor/instructionset/processor_symbols.h +++ /dev/null @@ -1,142 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_SYMBOLS_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_SYMBOLS_H - -#include - -/** - * @brief - * - * @details - */ -#define CEGIS_PROC_PROGRAM_PARAM_ID "program" - -/** - * @brief - * - * @details - */ -#define CEGIS_PROC_PROGRAM_SIZE_PARAM_ID "size" - -/** - * @brief - * - * @details - */ -#define CEGIS_PROC_OPCODE_MEMBER_NAME "opcode" - -/** - * @brief - * - * @details - */ -#define CEGIS_PROC_INSTR_INDEX "i" - -/** - * @brief - * - * @details - */ -#define INSTR_TYPE_SUFFIX "_instructiont" - -/** - * @brief - * - * @details - * - * @param st - * @param type - */ -std::string cegis_operand_array_name( - const symbol_tablet &st, - const typet &type); - -/** - * @brief - * - * @details - * - * @param op - * - * @return - */ -std::string cegis_operand_base_name(size_t op); - -/** - * @brief - * - * @details - * @code - * program[index].op_i - * @endcode - * - * @param st - * @param func_name - * @param op - * - * @return - */ -member_exprt cegis_opcode( - const symbol_tablet &st, - const std::string &func_name); - -/** - * @brief - * - * @details - * @code - * program[index].op_i - * @endcode - * - * @param st - * @param func_name - * @param op - * - * @return - */ -member_exprt cegis_operand_id( - const symbol_tablet &st, - const std::string &func_name, - size_t op); - -/** - * @brief - * - * @details - * @code - * __CPROVER_cegis_variable_array_type[program[index].op_i] - * @endcode - * - * @param st - * @param func_name - * @param type - * @param op - * - * @return - */ -dereference_exprt cegis_operand( - const symbol_tablet &st, - const std::string &func_name, - const typet &type, - size_t op); - -/** - * @brief - * - * @details - * - * @param var - * - * @return - */ -bool is_refactor_meta_var(const irep_idt &var); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_SYMBOLS_H diff --git a/src/cegis/refactor/instructionset/processor_types.cpp b/src/cegis/refactor/instructionset/processor_types.cpp deleted file mode 100644 index af1c9d44c04..00000000000 --- a/src/cegis/refactor/instructionset/processor_types.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -typet cegis_opcode_type() -{ - return unsigned_char_type(); -} - -typet cegis_operand_type() -{ - return cegis_opcode_type(); -} - -typet cegis_size_type() -{ - return cegis_opcode_type(); -} - -bool is_cegis_primitive(const typet &type) -{ - const irep_idt &id=type.id(); - return ID_c_bool == id || ID_floatbv == id || ID_unsignedbv == id - || ID_signedbv == id; -} diff --git a/src/cegis/refactor/instructionset/processor_types.h b/src/cegis/refactor/instructionset/processor_types.h deleted file mode 100644 index b01e3cd860f..00000000000 --- a/src/cegis/refactor/instructionset/processor_types.h +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_TYPES_H -#define CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_TYPES_H - -#include - -/** - * @brief - * - * @details - * - * @return - */ -typet cegis_opcode_type(); - -/** - * @brief - * - * @details - * - * @return - */ -typet cegis_operand_type(); - -/** - * @brief - * - * @details - * - * @return - */ -typet cegis_size_type(); - -/** - * @brief - * - * @details - * - * @param type - * - * @return - */ -bool is_cegis_primitive(const typet &type); - -#endif // CPROVER_CEGIS_REFACTOR_INSTRUCTIONSET_PROCESSOR_TYPES_H diff --git a/src/cegis/refactor/learn/instrument_counterexamples.cpp b/src/cegis/refactor/learn/instrument_counterexamples.cpp deleted file mode 100644 index 0dd6b24e1d1..00000000000 --- a/src/cegis/refactor/learn/instrument_counterexamples.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -goto_programt::targetst unify( - const refactor_programt::counterexample_locationst &locs) -{ - goto_programt::targetst result; - for(const refactor_programt::counterexample_locationst::value_type &entry : locs) - { - const goto_programt::targetst &rhs=entry.second; - std::copy(rhs.begin(), rhs.end(), std::back_inserter(result)); - } - return result; -} - -std::set get_all_keys( - const refactor_programt::counterexample_locationst &locs) -{ - std::set keys; - for(const refactor_programt::counterexample_locationst::value_type &entry : locs) - { - const goto_programt::targetst &rhs=entry.second; - std::transform(rhs.begin(), rhs.end(), std::inserter(keys, keys.begin()), - [](const goto_programt::const_targett pos) - { return get_counterexample_marker(pos);}); - } - return keys; -} - -void create_ce_arrays(symbol_tablet &st, goto_functionst &gf, - const labelled_counterexamplest &ces) -{ - if(ces.empty()) return; - const typet sz_type(signed_int_type()); - const constant_exprt sz_expr(from_integer(ces.size(), sz_type)); - const array_valuest array_values(get_array_values(ces)); - const labelled_counterexamplest::value_type &prototype=ces.front(); - for(const labelled_counterexamplest::value_type::value_type &value : prototype) - { - const labelled_assignmentst::value_type::first_type loc_id=value.first; - const array_valuest::const_iterator array_val=array_values.find(loc_id); - assert(array_values.end() != array_val); - const array_exprt &array_expr=array_val->second; - const std::string name(get_ce_array_name(loc_id)); - assert(array_expr.operands().size() == ces.size()); - declare_global_meta_variable(st, gf, name, array_expr); - } -} - -void create_ce_array_indexes(const std::set &ce_keys, - symbol_tablet &st, goto_functionst &gf) -{ - const exprt zero(from_integer(0, signed_int_type())); - declare_global_meta_variable(st, gf, CE_ARRAY_INDEX, zero); - goto_programt &body=get_body(gf, CONSTRAINT_CALLER_ID); - goto_programt::targett pos=body.instructions.begin(); - const goto_programt::targett init=body.insert_before(pos); - pos=init; - const source_locationt &loc=pos->source_location; - const irep_idt &function=pos->function; - for(const irep_idt &key : ce_keys) - { - const std::string name(get_ce_value_index_name(key)); - declare_global_meta_variable(st, name, zero.type()); - pos=cegis_assign(st, body, pos, st.lookup(name).symbol_expr(), zero, loc); - pos->function=function; - } - body.instructions.erase(init); -} - -void add_ce_goto(const symbol_tablet &st, goto_functionst &gf, - const size_t num_ces) -{ - goto_programt &body=get_body(gf, CONSTRAINT_CALLER_ID); - goto_programt::targett pos=find_last_instr(body); - const source_locationt &loc=pos->source_location; - const irep_idt &function=pos->function; - const symbol_exprt ce_index(st.lookup(CE_ARRAY_INDEX).symbol_expr()); - const plus_exprt rhs(ce_index, from_integer(1, ce_index.type())); - pos=cegis_assign(st, body, pos, ce_index, rhs, loc); - pos->function=function; - pos=insert_after_preserving_source_location(body, pos); - pos->type=goto_program_instruction_typet::GOTO; - pos->targets.push_back(body.instructions.begin()); - const constant_exprt num_ces_sz(from_integer(num_ces, signed_int_type())); - pos->guard=binary_relation_exprt(ce_index, ID_lt, num_ces_sz); - pos=insert_after_preserving_source_location(body, pos); - pos->type=goto_program_instruction_typet::ASSERT; - pos->guard=false_exprt(); - body.compute_target_numbers(); -} - -const index_exprt get_array_val_expr(const symbol_tablet &st, - const irep_idt &loc) -{ - const symbol_exprt index(st.lookup(CE_ARRAY_INDEX).symbol_expr()); - const symbol_exprt array(st.lookup(get_ce_array_name(loc)).symbol_expr()); - const index_exprt ce(array, index); - const std::string value_index(get_ce_value_index_name(loc)); - const symbol_exprt value_index_expr(st.lookup(value_index).symbol_expr()); - return index_exprt(ce, value_index_expr); -} - -void assign_ce_values(symbol_tablet &st, goto_functionst &gf, - const refactor_programt::counterexample_locationst &ce_locs) -{ - for(const refactor_programt::counterexample_locationst::value_type ce_loc : ce_locs) - { - for(goto_programt::targett pos : ce_loc.second) - { - const irep_idt &label=get_counterexample_marker(pos); - const index_exprt value(get_array_val_expr(st, label)); - switch(pos->type) - { - case ASSIGN: - to_code_assign(pos->code).rhs()=value; - break; - case DECL: - pos=cegis_assign(st, gf, pos, - st.lookup(get_affected_variable(*pos)).symbol_expr(), value); - break; - default: - assert(!"Unsupported counterexample location type."); - } - const std::string value_index_name(get_ce_value_index_name(label)); - const symbol_exprt value_index(st.lookup(value_index_name).symbol_expr()); - const plus_exprt inc(value_index, from_integer(1, value_index.type())); - cegis_assign(st, gf, pos, value_index, inc); - } - } -} -} - -void instrument_counterexamples(refactor_programt &prog, - refactor_counterexamplest ces) -{ - symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - const refactor_programt::counterexample_locationst &ce_locs= - prog.counterexample_locations; - const goto_programt::targetst unified(unify(ce_locs)); - const std::set all_keys(get_all_keys(ce_locs)); - const zero_valuest zeroes(get_zero_values(st, unified)); - normalise(all_keys, zeroes, ces); - create_ce_arrays(st, gf, ces); - create_ce_array_indexes(all_keys, st, gf); - add_ce_goto(st, gf, ces.size()); - assign_ce_values(st, gf, ce_locs); -} diff --git a/src/cegis/refactor/learn/instrument_counterexamples.h b/src/cegis/refactor/learn/instrument_counterexamples.h deleted file mode 100644 index 45493db0a30..00000000000 --- a/src/cegis/refactor/learn/instrument_counterexamples.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_LEARN_INSTRUMENT_COUNTEREXAMPLES_H -#define CPROVER_CEGIS_REFACTOR_LEARN_INSTRUMENT_COUNTEREXAMPLES_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * @param ces - */ -void instrument_counterexamples( - class refactor_programt &prog, - refactor_counterexamplest ces); - -#endif // CPROVER_CEGIS_REFACTOR_LEARN_INSTRUMENT_COUNTEREXAMPLES_H diff --git a/src/cegis/refactor/learn/refactor_candidate_printer.cpp b/src/cegis/refactor/learn/refactor_candidate_printer.cpp deleted file mode 100644 index 2e0b215dee8..00000000000 --- a/src/cegis/refactor/learn/refactor_candidate_printer.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include -#include - -namespace -{ -bool matches_opcode(const goto_programt::instructiont &instr, - const mp_integer &opcode) -{ - if(!instr.is_goto() || ID_notequal != instr.guard.id()) return false; - const notequal_exprt &guard=to_notequal_expr(instr.guard); - return opcode == bv_arithmetict(guard.rhs()).to_integer(); -} - -void print_instr(messaget::mstreamt &os, const namespacet &ns, - const goto_programt &body, const irep_idt &func_name, - const struct_exprt &instr) -{ - std::ostringstream oss; - const struct_exprt::operandst &ops=instr.operands(); - assert(!ops.empty()); - const mp_integer opcode(bv_arithmetict(ops.front()).to_integer()); - const goto_programt::instructionst &instrs=body.instructions; - const goto_programt::const_targett end(instrs.end()); - goto_programt::const_targett first=std::next( - std::find_if(instrs.begin(), end, - [opcode](const goto_programt::instructiont &instr) - { return matches_opcode(instr, opcode);})); - const goto_programt::const_targett last=std::find_if(first, end, - std::mem_fun_ref(&goto_programt::instructiont::is_goto)); - for(; first != last; ++first) - body.output_instruction(ns, func_name, oss, first); - std::string result(oss.str()); - for(size_t i=1; i < ops.size(); ++i) - { - std::string nd("*__CPROVER_cegis_variable_array_double[(program + i)->op_"); - nd+=std::to_string(i - 1); - nd+=']'; - std::string replacement("op"); - replacement+=expr2c(ops[i], ns); - substitute(result, nd, replacement); - } - os << result << messaget::endl; -} - -void print_program(messaget::mstreamt &os, const namespacet &ns, - const goto_programt &body, const irep_idt &func_name, - const refactor_solutiont::value_type &prog) -{ - os << " " << messaget::endl; - os << " " << func_name << "" << messaget::endl; - os << " " << messaget::endl; - for(const exprt &instr : prog.second.operands()) - print_instr(os, ns, body, func_name, to_struct_expr(instr)); - os << " " << messaget::endl; - os << " " << messaget::endl; -} -} - -void print_refactor_candidate(messaget::mstreamt &os, const symbol_tablet &st, - const goto_functionst &gf, const refactor_solutiont &candidate) -{ - os << "" << messaget::endl; - const namespacet ns(st); - const goto_functionst::function_mapt &fmap=gf.function_map; - for(const refactor_solutiont::value_type &entry : candidate) - { - std::string func(id2string(entry.first)); - remove_suffix(func, CEGIS_REFACTOR_PROG_SUFFIX); - const goto_functionst::function_mapt::const_iterator it=fmap.find(func); - assert(fmap.end() != it); - assert(it->second.body_available()); - print_program(os, ns, it->second.body, it->first, entry); - } - os << "" << messaget::eom; -} diff --git a/src/cegis/refactor/learn/refactor_candidate_printer.h b/src/cegis/refactor/learn/refactor_candidate_printer.h deleted file mode 100644 index 53041c573fe..00000000000 --- a/src/cegis/refactor/learn/refactor_candidate_printer.h +++ /dev/null @@ -1,32 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_CANDIDATE_PRINTER_H -#define CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_CANDIDATE_PRINTER_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param gf - * @param candidate - */ -void print_refactor_candidate( - messaget::mstreamt &os, - const class symbol_tablet &st, - const class goto_functionst &gf, - const refactor_solutiont &candidate); - -#endif // CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_CANDIDATE_PRINTER_H diff --git a/src/cegis/refactor/learn/refactor_symex_learn.cpp b/src/cegis/refactor/learn/refactor_symex_learn.cpp deleted file mode 100644 index 57e7618dd71..00000000000 --- a/src/cegis/refactor/learn/refactor_symex_learn.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -refactor_symex_learnt::refactor_symex_learnt( - const refactor_programt &original_program) : - original_program(original_program) -{ -} - -void refactor_symex_learnt::process(const counterexamplest &counterexamples, - const size_t max_solution_size) -{ - current_program=original_program; - symbol_tablet &st=current_program.st; - goto_functionst &gf=current_program.gf; - for(const irep_idt &program : current_program.programs) - { - symbolt &symbol=st.lookup(program); - assign_in_cprover_init(gf, symbol, side_effect_expr_nondett(symbol.type)); - } - transform_asserts_to_assumes(current_program.gf); - instrument_counterexamples(current_program, counterexamples); -} - -const symbol_tablet &refactor_symex_learnt::get_symbol_table() const -{ - return current_program.st; -} - -const goto_functionst &refactor_symex_learnt::get_goto_functions() const -{ - return current_program.gf; -} - -void refactor_symex_learnt::set_word_width( - const size_t word_width_in_bits) const -{ -} - -namespace -{ -class handle_assignt -{ - const std::set &progs; - refactor_symex_learnt::candidatet &candidate; -public: - handle_assignt(const std::set &programs, - refactor_symex_learnt::candidatet &candidate) : - progs(programs), candidate(candidate) - { - } - - void operator()(const goto_trace_stept &step) const - { - if(!step.is_assignment()) return; - const std::string &v=id2string(step.lhs_object.get_identifier()); - const auto it=std::find_if(progs.begin(), progs.end(), - std::bind(starts_with, v, std::bind(id2string, std::placeholders::_1))); - if(progs.end() == it || !ends_with(v, CEGIS_REFACTOR_PROG_SUFFIX)) return; - const array_exprt &value=to_array_expr(step.full_lhs_value); - assert(candidate.insert(std::make_pair(v, value)).second); - } -}; -} - -void refactor_symex_learnt::convert(candidatet ¤t_candidate, - const goto_tracet &trace, const size_t max_solution_size) const -{ - current_candidate.clear(); - const goto_tracet::stepst &steps=trace.steps; - const handle_assignt handle(current_program.programs, current_candidate); - std::for_each(steps.begin(), steps.end(), handle); -} - -void refactor_symex_learnt::show_candidate(messaget::mstreamt &os, - const candidatet &c) const -{ - print_refactor_candidate(os, current_program.st, current_program.gf, c); -} diff --git a/src/cegis/refactor/learn/refactor_symex_learn.h b/src/cegis/refactor/learn/refactor_symex_learn.h deleted file mode 100644 index dee68ce2afb..00000000000 --- a/src/cegis/refactor/learn/refactor_symex_learn.h +++ /dev/null @@ -1,103 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_SYMEX_LEARN_H -#define CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_SYMEX_LEARN_H - -#include - -#include -#include -#include - -class refactor_symex_learnt -{ - const refactor_programt &original_program; - refactor_programt current_program; -public: - typedef refactor_counterexamplet counterexamplet; - typedef refactor_counterexamplest counterexamplest; - typedef refactor_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param original_program - */ - explicit refactor_symex_learnt(const refactor_programt &original_program); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process( - const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits) const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert( - candidatet ¤t_candidate, - const class goto_tracet &trace, - size_t max_solution_size) const; - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate( - messaget::mstreamt &os, - const candidatet &candidate) const; -}; - -#endif // CPROVER_CEGIS_REFACTOR_LEARN_REFACTOR_SYMEX_LEARN_H diff --git a/src/cegis/refactor/nullobject/nullable_analysis.cpp b/src/cegis/refactor/nullobject/nullable_analysis.cpp deleted file mode 100644 index 6bf4166d137..00000000000 --- a/src/cegis/refactor/nullobject/nullable_analysis.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -std::set get_nullable_classes( - const refactor_programt::sketcht::typest &types) -{ - std::set result; - for(const typet &type : types) - { - if(!type.get_bool(CEGIS_NULLED_TYPE_ID)) continue; - const typet &class_type=to_pointer_type(type).subtype(); - result.insert(to_symbol_type(class_type).get_identifier()); - } - return result; -} - -bool is_member_of(const irep_idt &class_id, const irep_idt &method_id) -{ - std::string prefix(id2string(class_id)); - return starts_with(id2string(method_id), prefix+='.'); -} - -template -bool is_member_of_any(itert first, const itert last, const irep_idt &meth_id) -{ - return last != std::find_if(first, last, [&meth_id](const irep_idt &class_id) - { return is_member_of(class_id, meth_id);}); -} -} - -std::set get_nullable_methods(const refactor_programt &prog) -{ - const symbol_tablet::symbolst &symbols=prog.st.symbols; - std::set nullable_methods; - for(const refactor_programt::sketcht &sketch : prog.sketches) - { - const refactor_programt::sketcht::typest &types=sketch.types; - const std::set null_cls(get_nullable_classes(types)); - for(const typet &type : types) - if(type.get_bool(CEGIS_NULLED_TYPE_ID)) - for(const symbol_tablet::symbolst::value_type &entry : symbols) - { - const symbolt &symbol=entry.second; - if(ID_code != symbol.type.id()) continue; - const irep_idt &name=entry.first; - if(is_member_of_any(null_cls.begin(), null_cls.end(), name)) - nullable_methods.insert(name); - } - } - return nullable_methods; -} - -cegis_operand_datat slots_per_type(const symbol_tablet &st, - const std::set &state_vars) -{ - const namespacet ns(st); - cegis_operand_datat result; - for(const irep_idt &state_var : state_vars) - ++result[ns.follow(st.lookup(state_var).type)]; - return result; -} - -std::string get_return_value_name(const irep_idt &method) -{ - std::string ret_val_name(id2string(method)); - return ret_val_name+=RETURN_VALUE_SUFFIX; -} - -cegis_operand_datat get_operand_signature(const symbol_tablet &st, - const irep_idt &method) -{ - assert(st.has_symbol(method)); - // TODO: Add global vars - cegis_operand_datat result; - const code_typet &code_type=to_code_type(st.lookup(method).type); - const std::string ret_val_name(get_return_value_name(method)); - if(st.has_symbol(ret_val_name)) result[st.lookup(ret_val_name).type]=1; - for(const code_typet::parameterst::value_type ¶m : code_type.parameters()) - ++result[param.type()]; - return result; -} - -namespace -{ -bool calls_method(const goto_programt::instructiont &instr, - const irep_idt &method) -{ - if(goto_program_instruction_typet::FUNCTION_CALL != instr.type) return false; - const exprt &func=to_code_function_call(instr.code).function(); - if(ID_symbol != func.id()) return false; - return method == to_symbol_expr(func).get_identifier(); -} - -std::vector prepare_ops(symbol_tablet &st, const goto_functionst &gf, - const irep_idt &method, goto_programt &body, - const goto_programt::targett first) -{ - typedef goto_functionst::function_mapt fmapt; - const fmapt &fmap=gf.function_map; - const fmapt::const_iterator it=fmap.find(method); - assert(fmap.end() != it); - std::vector result; - const std::string ret_val_name(get_return_value_name(method)); - if(st.has_symbol(ret_val_name)) result.push_back(ret_val_name); - const code_function_callt &call=to_code_function_call(first->code); - const symbol_exprt &func=to_symbol_expr(call.function()); - const code_function_callt::argumentst &args=call.arguments(); - const code_typet &code_type=to_code_type(func.type()); - const code_typet::parameterst ¶ms=code_type.parameters(); - const size_t size=args.size(); - assert(size == params.size()); - const source_locationt &loc=first->source_location; - goto_programt::targett pos=first; - for(size_t i=0; i < size; ++i) - if(!params[i].get_this()) - { - const symbolt &lhs=st.lookup(params[i].get_identifier()); - if(first == pos) - { - pos=insert_before_preserve_labels(body, pos); - pos->source_location=loc; - pos->function=first->function; - } else pos=insert_after_preserving_source_location(body, pos); - cegis_assign(st, *pos, lhs.symbol_expr(), args[i], loc); - result.push_back(lhs.name); - } - // TODO: Add globals - return result; -} -} - -void replace_method_call_by_processor(symbol_tablet &st, goto_functionst &gf, - goto_programt::targett first, const goto_programt::targett last, - const irep_idt &meth, const std::string &processor, const std::string &prog) -{ - // TODO: Find topmost class for "method" to uniquely identify it. - goto_programt &body=get_body(gf, first); - for(; first != last; ++first) - if(calls_method(*first, meth)) - { - const std::vector ops(prepare_ops(st, gf, meth, body, first)); - if(!ops.empty()) - { - goto_programt::targett pos=insert_before_preserve_labels(body, first); - instrument_cegis_operand(st, *pos, 0, ops.front()); - for(size_t i=1; i < ops.size(); ++i) - pos=instrument_cegis_operand(st, body, pos, i, ops[i]); - } - call_processor(st, *first, processor, prog); - } -} diff --git a/src/cegis/refactor/nullobject/nullable_analysis.h b/src/cegis/refactor/nullobject/nullable_analysis.h deleted file mode 100644 index 7d2d6578e95..00000000000 --- a/src/cegis/refactor/nullobject/nullable_analysis.h +++ /dev/null @@ -1,75 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_NULLOBJECT_NULLABLE_ANALYSIS_H -#define CPROVER_CEGIS_REFACTOR_NULLOBJECT_NULLABLE_ANALYSIS_H - -#include - -/** - * @brief - * - * @details - * - * @param prog - * - * @return - */ -std::set get_nullable_methods(const class refactor_programt &prog); - -/** - * @brief - * - * @details - * - * @param st - * @param state_vars - * - * @return - */ -std::map slots_per_type(const symbol_tablet &st, - const std::set &state_vars); - -/** - * @brief - * - * @details - * - * @param st - * @param method - * - * @return - */ -cegis_operand_datat get_operand_signature( - const symbol_tablet &st, - const irep_idt &method); - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param first - * @param last - * @param method - * @param processor - * @param prog - */ -void replace_method_call_by_processor( - symbol_tablet &st, - goto_functionst &gf, - goto_programt::targett first, - goto_programt::targett last, - const irep_idt &method, - const std::string &processor, - const std::string &prog); - -#endif // CPROVER_CEGIS_REFACTOR_NULLOBJECT_NULLABLE_ANALYSIS_H diff --git a/src/cegis/refactor/nullobject/range_collector.cpp b/src/cegis/refactor/nullobject/range_collector.cpp deleted file mode 100644 index f0e54e12341..00000000000 --- a/src/cegis/refactor/nullobject/range_collector.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include - -namespace -{ -bool is_null(const exprt &expr) -{ - if(ID_constant != expr.id()) return false; - return ID_NULL == to_constant_expr(expr).get_value(); -} - -class is_null_comparisont -{ -public: - pointer_typet nulled_type; -private: - bool extract_nulled_type(const exprt &operand) - { - if(ID_typecast == operand.id()) - return extract_nulled_type(to_typecast_expr(operand).op()); - nulled_type=to_pointer_type(to_symbol_expr(operand).type()); - return true; - } -public: - bool operator()(const exprt &guard) - { - const irep_idt &id=guard.id(); - if(ID_equal != id && ID_notequal != id) return false; - const binary_relation_exprt &binary=to_binary_relation_expr(guard); - const exprt &lhs=binary.lhs(); - const exprt &rhs=binary.rhs(); - if(is_null(lhs)) return extract_nulled_type(rhs); - else if(is_null(rhs)) return extract_nulled_type(lhs); - return false; - } -}; - -goto_ranget get_then_range(const goto_programt::targett &else_range_last) -{ - const goto_programt::targett then_range_first(else_range_last); - const goto_programt::targett last_else_instr(std::prev(else_range_last)); - if(GOTO != last_else_instr->type) - return goto_ranget(then_range_first, then_range_first); - return goto_ranget(then_range_first, last_else_instr->get_target()); -} - -goto_programt::targett get_else_range_last(const goto_programt::targett pos) -{ - const goto_programt::targett prev=std::prev(pos); - if(goto_program_instruction_typet::GOTO != prev->type - || prev->is_backwards_goto()) return pos; - return prev; -} -} - -void collect_nullobject_ranges(refactor_programt &prog) -{ - for(instr_iteratort it(prog.gf); it != instr_iteratort::end; ++it) - { - if(goto_program_instruction_typet::GOTO != it->type) continue; - const exprt &guard=it->guard; - is_null_comparisont is_null_comparison; - if(!is_null_comparison(guard)) continue; - prog.sketches.push_back(refactor_programt::sketcht()); - refactor_programt::sketcht &sketch=prog.sketches.back(); - sketch.init=it; - const goto_programt::targett then_target=it->get_target(); - const goto_programt::targett else_last=get_else_range_last(then_target); - const goto_ranget else_range(++it, else_last); - const goto_ranget then_range(get_then_range(then_target)); - if(ID_equal == guard.id()) - { - sketch.spec_range=then_range; - sketch.input_range=else_range; - } else - { - sketch.spec_range=else_range; - sketch.input_range=then_range; - } - refactor_programt::sketcht::typest &types=sketch.types; - types=collect_context_types(then_range); - const auto tmp(collect_context_types(else_range)); - types.insert(tmp.begin(), tmp.end()); - pointer_typet &nulled_type=is_null_comparison.nulled_type; - types.erase(nulled_type); - nulled_type.set(CEGIS_NULLED_TYPE_ID, true); - types.insert(nulled_type); - } -} diff --git a/src/cegis/refactor/nullobject/range_collector.h b/src/cegis/refactor/nullobject/range_collector.h deleted file mode 100644 index fba93debae3..00000000000 --- a/src/cegis/refactor/nullobject/range_collector.h +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_NULLOBJECT_RANGE_COLLECTOR_H -#define CPROVER_CEGIS_REFACTOR_NULLOBJECT_RANGE_COLLECTOR_H - -/** - * @brief - * - * @details - */ -#define CEGIS_NULLED_TYPE_ID "nulled_type" - -/** - * @brief - * - * @details - */ -void collect_nullobject_ranges(class refactor_programt &prog); - -#endif // CPROVER_CEGIS_REFACTOR_NULLOBJECT_RANGE_COLLECTOR_H diff --git a/src/cegis/refactor/options/refactor_program.cpp b/src/cegis/refactor/options/refactor_program.cpp deleted file mode 100644 index 0a20f6f6394..00000000000 --- a/src/cegis/refactor/options/refactor_program.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -refactor_programt::refactor_programt(const symbol_tablet &st, - const goto_functionst &gf) : - st(st) -{ - this->gf.copy_from(gf); -} - -namespace -{ -class copy_targett -{ - goto_functionst &lhs_func; - const goto_functionst &rhs_func; -public: - copy_targett(goto_functionst &lhs_func, const goto_functionst &rhs_func) : - lhs_func(lhs_func), rhs_func(rhs_func) - { - } - - goto_programt::targett operator()(const goto_programt::targett rhs) const - { - const goto_programt::targett empty; - if(empty == rhs) return empty; - const std::string &function=id2string(rhs->function); - goto_programt &lhs_body=get_body(lhs_func, function); - const goto_programt &rhs_body=get_body(rhs_func, function); - return copy_iterator(rhs_body.instructions, lhs_body.instructions, rhs); - } - - void operator()(goto_programt::targetst &lhs, - const goto_programt::targetst &rhs) const - { - lhs.resize(rhs.size()); - std::transform(rhs.begin(), rhs.end(), lhs.begin(), *this); - } -}; - -void copy(const copy_targett ©, goto_ranget &lhs, const goto_ranget &rhs) -{ - lhs.first=copy(rhs.first); - lhs.second=copy(rhs.second); -} - -void copy(const copy_targett ©, refactor_programt::sketcht &lhs, - const refactor_programt::sketcht &rhs) -{ - lhs.init=copy(rhs.init); - ::copy(copy, lhs.input_range, rhs.input_range); - ::copy(copy, lhs.spec_range, rhs.spec_range); - lhs.state_vars=rhs.state_vars; - lhs.types=rhs.types; -} - -refactor_programt ©(refactor_programt &lhs, const refactor_programt &rhs) -{ - lhs.gf.copy_from(rhs.gf); - const copy_targett copy(lhs.gf, rhs.gf); - lhs.counterexample_locations.clear(); - for(const refactor_programt::counterexample_locationst::value_type &entry : rhs.counterexample_locations) - copy(lhs.counterexample_locations[entry.first], entry.second); - lhs.sketches.resize(rhs.sketches.size()); - for(size_t i=0; i < lhs.sketches.size(); ++i) - ::copy(copy, lhs.sketches[i], rhs.sketches[i]); - lhs.programs=rhs.programs; - return lhs; -} -} - -refactor_programt::refactor_programt(const refactor_programt &other) : - st(other.st) -{ - copy(*this, other); -} - -refactor_programt::refactor_programt() -{ -} - -refactor_programt &refactor_programt::operator =(const refactor_programt &other) -{ - st.clear(); - st=other.st; - gf.clear(); - return copy(*this, other); -} diff --git a/src/cegis/refactor/options/refactor_program.h b/src/cegis/refactor/options/refactor_program.h deleted file mode 100644 index 558fb645b2e..00000000000 --- a/src/cegis/refactor/options/refactor_program.h +++ /dev/null @@ -1,117 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTOR_PROGRAM_H -#define CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTOR_PROGRAM_H - -#include - -#include - -#include - -/** - * @brief - * - * @details - */ -class refactor_programt -{ -public: - symbol_tablet st; - goto_functionst gf; - - /** - * @brief - * - * @details - */ - typedef std::map counterexample_locationst; - - /** - * @brief - * - * @details All variable locations to be considered in counterexamples (including loop bodies). - */ - counterexample_locationst counterexample_locations; - - /** - * @brief - * - * @details - */ - class sketcht - { - public: - goto_programt::targett init; - goto_ranget input_range; - goto_ranget spec_range; - std::set state_vars; - typedef std::set typest; - typest types; - }; - - /** - * @brief - * - * @details - */ - typedef std::deque sketchest; - - /** - * @brief - * - * @details - */ - sketchest sketches; - - /** - * @brief - * - * @details - */ - std::set programs; - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - explicit refactor_programt(const symbol_tablet &st, const goto_functionst &gf); - - /** - * @brief - * - * @details - * - * @param other - */ - explicit refactor_programt(const refactor_programt &other); - - /** - * @brief - * - * @details - */ - refactor_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - refactor_programt &operator=(const refactor_programt &other); -}; - -#endif // CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTOR_PROGRAM_H diff --git a/src/cegis/refactor/options/refactoring_type.cpp b/src/cegis/refactor/options/refactoring_type.cpp deleted file mode 100644 index 834fe47357a..00000000000 --- a/src/cegis/refactor/options/refactoring_type.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include - -refactoring_typet get_refactoring_type(const class optionst &options) -{ - if(options.get_bool_option(CEGIS_NULL_OBJECT_REFACTOR)) - return refactoring_typet::NULL_OBJECT; - assert(!"Invalid refactoring type selected."); -} diff --git a/src/cegis/refactor/options/refactoring_type.h b/src/cegis/refactor/options/refactoring_type.h deleted file mode 100644 index 189e97af520..00000000000 --- a/src/cegis/refactor/options/refactoring_type.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H -#define CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H - -typedef enum -{ - NULL_OBJECT -} refactoring_typet; - -/** - * @brief - * - * @details - * - * @param options - * - * @return - */ -refactoring_typet get_refactoring_type(const class optionst &options); - -#endif // CPROVER_CEGIS_REFACTOR_OPTIONS_REFACTORING_TYPE_H diff --git a/src/cegis/refactor/preprocessing/collect_counterexamples.cpp b/src/cegis/refactor/preprocessing/collect_counterexamples.cpp deleted file mode 100644 index 58d4bd32b8d..00000000000 --- a/src/cegis/refactor/preprocessing/collect_counterexamples.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -namespace -{ -bool is_meta(const goto_programt::const_targett target) -{ - return false; -} -} - -void collect_counterexamples(refactor_programt &prog) -{ - refactor_programt::counterexample_locationst &ls=prog.counterexample_locations; - typedef goto_functionst::function_mapt fmapt; - size_t idx=0; - for(fmapt::value_type &entry : prog.gf.function_map) - { - fmapt::value_type::second_type &func=entry.second; - if(!func.body_available()) continue; - goto_programt::targetst &ce_locs=ls[entry.first]; - idx=collect_counterexample_locations(ce_locs, func.body, is_meta, idx); - } -} diff --git a/src/cegis/refactor/preprocessing/collect_counterexamples.h b/src/cegis/refactor/preprocessing/collect_counterexamples.h deleted file mode 100644 index 5238f84c069..00000000000 --- a/src/cegis/refactor/preprocessing/collect_counterexamples.h +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_PREPROCESSING_COLLECT_COUNTEREXAMPLES_H -#define CPROVER_CEGIS_REFACTOR_PREPROCESSING_COLLECT_COUNTEREXAMPLES_H - -/** - * @brief - * - * @details - * - * @param prog - */ -void collect_counterexamples(class refactor_programt &prog); - -#endif // CPROVER_CEGIS_REFACTOR_PREPROCESSING_COLLECT_COUNTEREXAMPLES_H diff --git a/src/cegis/refactor/preprocessing/refactor_preprocessing.cpp b/src/cegis/refactor/preprocessing/refactor_preprocessing.cpp deleted file mode 100644 index 9177d1462a1..00000000000 --- a/src/cegis/refactor/preprocessing/refactor_preprocessing.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -refactor_preprocessingt::refactor_preprocessingt(const optionst &options, - const symbol_tablet &st, const goto_functionst &gf) : - options(options), original_program(st, gf) -{ -} - -void refactor_preprocessingt::operator()() -{ - symbol_tablet &st=original_program.st; - goto_functionst &gf=original_program.gf; - const refactoring_typet type(get_refactoring_type(options)); - switch(type) - { - case refactoring_typet::NULL_OBJECT: - collect_nullobject_ranges(original_program); - break; - } - create_constraint_function_caller(original_program); - for(refactor_programt::sketcht &s : original_program.sketches) - { - collect_state_vars(s.state_vars, s.spec_range.first, s.spec_range.second); - collect_state_vars(s.state_vars, s.input_range.first, s.input_range.second); - } - switch(type) - { - case refactoring_typet::NULL_OBJECT: - const std::set null_meths(get_nullable_methods(original_program)); - for(const irep_idt &m : null_meths) - { - const cegis_operand_datat op_data(get_operand_signature(st, m)); - const std::string proc(create_cegis_processor(st, gf, op_data)); - const std::string prog(declare_cegis_program(st, gf, proc)); - original_program.programs.insert(prog); - for(refactor_programt::sketcht &s : original_program.sketches) - { - const goto_programt::targett first=s.input_range.first; - const goto_programt::targett last=s.input_range.second; - replace_method_call_by_processor(st, gf, first, last, m, proc, prog); - } - } - break; - } - create_refactoring_constraint(original_program); - collect_counterexamples(original_program); -} - -namespace -{ -void set_cegis_processor_sizes(const symbol_tablet &st, - const goto_ranget &range, const size_t size) -{ - set_cegis_processor_sizes(st, range.first, range.second, size); -} -} - -void refactor_preprocessingt::operator()(const size_t max_length) -{ - current_program=original_program; - symbol_tablet &st=current_program.st; - set_cegis_processor_sizes(st, max_length); - for(const refactor_programt::sketcht &sketch : current_program.sketches) - { - set_cegis_processor_sizes(st, sketch.input_range, max_length); - set_cegis_processor_sizes(st, sketch.spec_range, max_length); - } -} - -size_t refactor_preprocessingt::get_min_solution_size() const -{ - return 1u; -} - -const refactor_programt &refactor_preprocessingt::get_program() const -{ - return current_program; -} diff --git a/src/cegis/refactor/preprocessing/refactor_preprocessing.h b/src/cegis/refactor/preprocessing/refactor_preprocessing.h deleted file mode 100644 index b3b3e86c6e3..00000000000 --- a/src/cegis/refactor/preprocessing/refactor_preprocessing.h +++ /dev/null @@ -1,75 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_PREPROCESSING_REFACTOR_PREPROCESSING_H -#define CPROVER_CEGIS_REFACTOR_PREPROCESSING_REFACTOR_PREPROCESSING_H - -#include - -/** - * @brief - * - * @details - */ -class refactor_preprocessingt -{ - const class optionst &options; - refactor_programt original_program; - refactor_programt current_program; -public: - /** - * @brief - * - * @details - * - * @param options - * @param st - * @param gf - */ - explicit refactor_preprocessingt( - const optionst &options, - const symbol_tablet &st, - const goto_functionst &gf); - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_length - */ - void operator()(size_t max_length); - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - * - * @return - */ - const refactor_programt &get_program() const; -}; - -#endif // CPROVER_CEGIS_REFACTOR_PREPROCESSING_REFACTOR_PREPROCESSING_H diff --git a/src/cegis/refactor/value/refactor_counterexample.h b/src/cegis/refactor/value/refactor_counterexample.h deleted file mode 100644 index fd1bf021e9c..00000000000 --- a/src/cegis/refactor/value/refactor_counterexample.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_COUNTEREXAMPLE_H -#define CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_COUNTEREXAMPLE_H - -#include - -/** - * @brief - * - * @details - */ -typedef labelled_assignmentst refactor_counterexamplet; - -/** - * @brief - * - * @details - */ -typedef labelled_counterexamplest refactor_counterexamplest; - -#endif // CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_COUNTEREXAMPLE_H diff --git a/src/cegis/refactor/value/refactor_solution.h b/src/cegis/refactor/value/refactor_solution.h deleted file mode 100644 index 15e5c1e8963..00000000000 --- a/src/cegis/refactor/value/refactor_solution.h +++ /dev/null @@ -1,17 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_SOLUTION_H -#define CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_SOLUTION_H - -#include - -typedef std::map refactor_solutiont; - -#endif // CPROVER_CEGIS_REFACTOR_VALUE_REFACTOR_SOLUTION_H diff --git a/src/cegis/refactor/verify/refactor_symex_verify.cpp b/src/cegis/refactor/verify/refactor_symex_verify.cpp deleted file mode 100644 index 3d2655b1943..00000000000 --- a/src/cegis/refactor/verify/refactor_symex_verify.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include -#include -#include - -refactor_symex_verifyt::refactor_symex_verifyt(const refactor_programt &prog) : - original_program(prog) -{ -} - -void refactor_symex_verifyt::process(const candidatet &candidate) -{ - current_program=original_program; - symbol_tablet &st=current_program.st; - goto_functionst &gf=current_program.gf; - const namespacet ns(st); - for(const irep_idt &program : current_program.programs) - { - symbolt &symbol=st.lookup(program); - const candidatet::const_iterator it=candidate.find(program); - if(candidate.end() == it) - { - const exprt zero(zero_initializer(symbol.type, symbol.location, ns)); - assign_in_cprover_init(gf, symbol, zero); - } else assign_in_cprover_init(gf, symbol, it->second); - } -} - -const symbol_tablet &refactor_symex_verifyt::get_symbol_table() const -{ - return current_program.st; -} - -const goto_functionst &refactor_symex_verifyt::get_goto_functions() const -{ - return current_program.gf; -} - -void refactor_symex_verifyt::convert(counterexamplest &counterexamples, - const goto_tracet &trace) const -{ - counterexamples.push_back(extract_counterexample(trace)); -} - -void refactor_symex_verifyt::show_counterexample(messaget::mstreamt &os, - const counterexamplet &counterexample) const -{ - show_assignments(os, counterexample); -} diff --git a/src/cegis/refactor/verify/refactor_symex_verify.h b/src/cegis/refactor/verify/refactor_symex_verify.h deleted file mode 100644 index c78efc5af07..00000000000 --- a/src/cegis/refactor/verify/refactor_symex_verify.h +++ /dev/null @@ -1,94 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_REFACTOR_VERIFY_REFACTOR_SYMEX_VERIFY_H -#define CPROVER_CEGIS_REFACTOR_VERIFY_REFACTOR_SYMEX_VERIFY_H - -#include - -#include -#include -#include - -/** - * @brief - * - * @details - */ -class refactor_symex_verifyt -{ - const refactor_programt &original_program; - refactor_programt current_program; -public: - typedef refactor_counterexamplet counterexamplet; - typedef refactor_counterexamplest counterexamplest; - typedef refactor_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param prog - */ - explicit refactor_symex_verifyt(const refactor_programt &prog); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void process(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param trace - */ - void convert( - counterexamplest &counterexamples, - const class goto_tracet &trace) const; - - /** - * @brief - * - * @details - * - * @param os - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#endif // CPROVER_CEGIS_REFACTOR_VERIFY_REFACTOR_SYMEX_VERIFY_H diff --git a/src/cegis/runner/cegis_languages.cpp b/src/cegis/runner/cegis_languages.cpp deleted file mode 100644 index cdf90e27426..00000000000 --- a/src/cegis/runner/cegis_languages.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/*******************************************************************\ - -Module: Language Registration - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#include - -#include -#include - -#ifdef HAVE_JAVA_BYTECODE -#include -#endif - -#include - -/*******************************************************************\ - -Function: cbmc_parse_optionst::register_languages - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void cbmc_parse_optionst::register_languages() -{ - register_language(new_ansi_c_language); - register_language(new_cpp_language); - - #ifdef HAVE_JAVA_BYTECODE - register_language(new_java_bytecode_language); - #endif -} diff --git a/src/cegis/runner/cegis_main.cpp b/src/cegis/runner/cegis_main.cpp deleted file mode 100644 index 1d285529a67..00000000000 --- a/src/cegis/runner/cegis_main.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*******************************************************************\ - -Module: CEGIS Main Module - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#include - -#ifdef IREP_HASH_STATS -#include -#endif - -#include "cegis_parse_options.h" - -/*******************************************************************\ - -Function: main / wmain - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -#ifdef IREP_HASH_STATS -extern unsigned long long irep_hash_cnt; -extern unsigned long long irep_cmp_cnt; -extern unsigned long long irep_cmp_ne_cnt; -#endif - -#ifdef _MSC_VER -int wmain(int argc, const wchar_t **argv_wide) -{ - const char **argv=narrow_argv(argc, argv_wide); -#else -int main(int argc, const char **argv) -{ -#endif - cegis_parse_optionst parse_options(argc, argv); - - int res=parse_options.main(); - - #ifdef IREP_HASH_STATS - std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << std::endl; - std::cout << "IREP_CMP_CNT=" << irep_cmp_cnt << std::endl; - std::cout << "IREP_CMP_NE_CNT=" << irep_cmp_ne_cnt << std::endl; - #endif - - return res; -} diff --git a/src/cegis/runner/cegis_parse_options.cpp b/src/cegis/runner/cegis_parse_options.cpp deleted file mode 100644 index 263dfa31c50..00000000000 --- a/src/cegis/runner/cegis_parse_options.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*******************************************************************\ - -Module: CEGIS Command Line Option Processing - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -/*******************************************************************\ - -Function: cegis_parse_optionst::cegis_parse_optionst - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -cegis_parse_optionst::cegis_parse_optionst(int argc, const char **argv): - cbmc_parse_optionst(argc, argv, CEGIS_OPTIONS) -{ -} - -namespace -{ -void set_integer_option(optionst &opt, const cmdlinet &cmd, - const char * const name, const unsigned int default_value) -{ - if(!cmd.isset(name)) return opt.set_option(name, default_value); - const std::string text_value(cmd.get_value(name)); - const mp_integer::ullong_t value=string2integer(text_value).to_ulong(); - opt.set_option(name, static_cast(value)); -} -} - -/*******************************************************************\ - -Function: cegis_parse_optionst::get_command_line_options - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void cegis_parse_optionst::get_command_line_options(optionst &options) -{ - cbmc_parse_optionst::get_command_line_options(options); - - const bool configure_cegis=cmdline.isset("danger") || cmdline.isset("safety") - || cmdline.isset("jsa") || cmdline.isset(CEGIS_CONTROL) - || cmdline.isset(CEGIS_REFACTOR); - if(configure_cegis) - { - set_integer_option(options, cmdline, "cegis-min-size", 1u); - set_integer_option(options, cmdline, "cegis-max-size", 5u); - options.set_option("cegis-parallel-verify", cmdline.isset("cegis-parallel-verify")); - options.set_option("cegis-limit-wordsize", cmdline.isset("cegis-limit-wordsize")); - options.set_option("cegis-match-select", !cmdline.isset("cegis-tournament-select")); - options.set_option("cegis-statistics", cmdline.isset("cegis-statistics")); - options.set_option(CEGIS_GENETIC, cmdline.isset(CEGIS_GENETIC)); - options.set_option(CEGIS_GENETIC_ONLY, cmdline.isset(CEGIS_GENETIC_ONLY)); - set_integer_option(options, cmdline, "cegis-genetic-rounds", 10u); - set_integer_option(options, cmdline, "cegis-seed", 747864937u); - set_integer_option(options, cmdline, "cegis-genetic-popsize", 2000u); - set_integer_option(options, cmdline, "cegis-genetic-mutation-rate", 1u); - set_integer_option(options, cmdline, "cegis-genetic-replace-rate", 15u); - options.set_option("danger-no-ranking", cmdline.isset("danger-no-ranking")); - set_integer_option(options, cmdline, CEGIS_SYMEX_HEAD_START, 0u); - options.set_option(CEGIS_SHOW_ITERATIONS, cmdline.isset(CEGIS_SHOW_ITERATIONS)); - options.set_option(CEGIS_KEEP_GOTO_PROGRAMS, cmdline.isset(CEGIS_KEEP_GOTO_PROGRAMS)); - set_integer_option(options, cmdline, CEGIS_MAX_RUNTIME, 300u); - options.set_option(CEGIS_NULL_OBJECT_REFACTOR, cmdline.isset(CEGIS_NULL_OBJECT_REFACTOR)); - } -} - -/*******************************************************************\ - -Function: cegis_parse_optionst::do_bmc - - Inputs: - - Outputs: - - Purpose: invoke main modules - -\*******************************************************************/ - -int cegis_parse_optionst::do_bmc( - bmct &bmc, - const goto_functionst &goto_functions) -{ - optionst options; - get_command_line_options(options); - - if(cmdline.isset("danger")) - return run_danger(options, result(), symbol_table, goto_functions); - if(cmdline.isset("safety")) - return run_safety(options, result(), symbol_table, goto_functions); - if(cmdline.isset("jsa")) - return run_jsa(options, result(), symbol_table, goto_functions); - if(cmdline.isset(CEGIS_CONTROL)) - return run_control(options, result(), symbol_table, goto_functions); - if(cmdline.isset(CEGIS_REFACTOR)) - return run_refactor(options, result(), symbol_table, goto_functions); - - return cbmc_parse_optionst::do_bmc(bmc, goto_functions); -} - -/*******************************************************************\ - -Function: cegis_parse_optionst::help - - Inputs: - - Outputs: - - Purpose: print help - -\*******************************************************************/ - -void cegis_parse_optionst::help() -{ - std::cout << - "\n" - "* * CEGIS " CBMC_VERSION " - Copyright (C) 2015-2016 "; - - std::cout << "(" << (sizeof(void *)*8) << "-bit version)"; - - std::cout << " * *\n"; - - std::cout << - "* * Matt Lewis, Pascal Kesseli, Daniel Kroening * *\n" - "* * University of Oxford, Computer Science Department * *\n" - "* * kroening@kroening.com * *\n" - "\n" - "Usage: Purpose:\n" - "\n" - " cegis [-?] [-h] [--help] show help\n" - " cegis [--danger|--safety] file.c ... source file names\n" - "\n" - "Invariant options:\n" - " --danger synthesise danger invariant\n" - " --safety synthesise safety invariant\n" - "\n" - "GA options:\n" - " --cegis-genetic use symex and genetic back-end\n" - " --cegis-match-select use \"match\" genetic selector\n" - " --cegis-tournament-select use \"tournament\" genetic selector\n" - " --cegis-genetic-rounds number of wheel rounds per evolution step\n" - " --cegis-genetic-popsize population size\n" - " --cegis-genetic-mutation-rate likelihood of mutation (1-100)\n" - " --cegis-genetic-replace-rate evolutionary pressure (1-100)\n" - "\n" - "Output options:\n" - " --cegis-statistics show runtime and CEGIS statistics\n" - " --cegis-keep-goto-programs keep generated GOTO programs\n" - " --cegis-show-iterations show intermediate solutions in CEGIS loop\n" - "\n" - "Experiment options:\n" - " --cegis-max-runtime maximum runtime timeout\n" - " --cegis-min-size minimum solution length to consider\n" - " --cegis-max-size maximum solution length to consider\n" - " --cegis-parallel-verify find multiple counterexamples concurrently\n" - " --cegis-limit-wordsize allow inductive conjecture with limited word size\n" - " --cegis-seed starting seed for random number generator\n" - " --danger-no-ranking use total danger invariants\n" - " --cegis-symex-head-start number of iterations head-start for symex over GA \n" - "\n"; -} diff --git a/src/cegis/runner/cegis_parse_options.h b/src/cegis/runner/cegis_parse_options.h deleted file mode 100644 index 87f6fb001d9..00000000000 --- a/src/cegis/runner/cegis_parse_options.h +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************\ - -Module: CBMC/CEGIS Command Line Option Processing - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_RUNNER_CEGIS_PARSE_OPTIONS_H -#define CPROVER_CEGIS_RUNNER_CEGIS_PARSE_OPTIONS_H - -#include - -#define CEGIS_OPTIONS \ - "(cegis)(cegis-seed):(cegis-root):(cegis-targets):" \ - "(cegis-min-prog-size):(cegis-max-prog-size):(cegis-skolem):(cegis-ranking):" \ - "(cegis-max-size):(cegis-statistics)(cegis-show-iterations)" \ - "(cegis-keep-goto-programs)(cegis-genetic)(cegis-genetic-only)(cegis-genetic-rounds):" \ - "(cegis-genetic-popsize):(cegis-tournament-select)" \ - "(cegis-genetic-mutation-rate):(cegis-genetic-replace-rate):" \ - "(cegis-limit-wordsize)(cegis-parallel-verify)(cegis-symex-head-start):" \ - "(safety)(danger)(jsa)(danger-max-size):(danger-no-ranking)" \ - "(cegis-control)" \ - "(cegis-refactor)(cegis-refactor-null-object)" - -class cegis_parse_optionst: public cbmc_parse_optionst -{ -public: - cegis_parse_optionst(int argc, const char **argv); - virtual ~cegis_parse_optionst()=default; - virtual void help(); - -protected: - virtual void get_command_line_options(optionst &options); - virtual int do_bmc(bmct &bmc, const goto_functionst &goto_functions); -}; - -#endif // CPROVER_CEGIS_RUNNER_CEGIS_PARSE_OPTIONS_H diff --git a/src/cegis/safety/constraint/safety_constraint_factory.cpp b/src/cegis/safety/constraint/safety_constraint_factory.cpp deleted file mode 100644 index eb6554a9546..00000000000 --- a/src/cegis/safety/constraint/safety_constraint_factory.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include - -namespace -{ -symbol_exprt as_var(const std::string &base_name) -{ - const std::string name=get_cegis_meta_name(base_name); - return symbol_exprt(name, cegis_default_integer_type()); -} - -constant_exprt get_min_value() -{ - const typet type(cegis_default_integer_type()); - const bv_spect spec(type); - return from_integer(spec.min_value(), type); -} - -notequal_exprt as_bool(const std::string &base_name) -{ - const constant_exprt rhs(from_integer(0u, cegis_default_integer_type())); - return notequal_exprt(as_var(base_name), rhs); -} -} - -exprt create_safety_constraint(const size_t number_of_loops) -{ - assert(number_of_loops >= 1 && "At least one loop required."); - const constant_exprt min(get_min_value()); - const notequal_exprt A_x(as_bool(get_Ax())); - and_exprt root; - root.copy_to_operands(as_bool(get_Ix0())); - for(size_t i=0; i < number_of_loops; ++i) - { - const notequal_exprt S0_x(as_bool(get_Ix(i))); - const notequal_exprt G0_x(as_bool(get_Gx(i))); - const and_exprt S0_x_and_G0_0x(S0_x, G0_x); - const not_exprt not_S0_x_and_G0_0x(S0_x_and_G0_0x); - const notequal_exprt S0_x_prime(as_bool(get_Ix_prime(i))); - const or_exprt induction(not_S0_x_and_G0_0x, S0_x_prime); - root.copy_to_operands(induction); - const bool is_last_component=(i == (number_of_loops - 1)); - const not_exprt not_G0_x(G0_x); - const and_exprt S0_x_and_not_G0_x(S0_x, not_G0_x); - const not_exprt not_S0_x_and_not_G0_x(S0_x_and_not_G0_x); - const notequal_exprt S1_x(as_bool(get_Ix(i + 1))); - const exprt &conseq=is_last_component ? A_x : S1_x; - const or_exprt implication(not_S0_x_and_not_G0_x, conseq); - root.copy_to_operands(implication); - } - return root; -} diff --git a/src/cegis/safety/constraint/safety_constraint_factory.h b/src/cegis/safety/constraint/safety_constraint_factory.h deleted file mode 100644 index b34922a97b1..00000000000 --- a/src/cegis/safety/constraint/safety_constraint_factory.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_CONSTRAINT_SAFETY_CONSTRAINT_FACTORY_H -#define CPROVER_CEGIS_SAFETY_CONSTRAINT_SAFETY_CONSTRAINT_FACTORY_H - -#include - -/** - * @brief - * - * @details - * - * @param number_of_loops - * - * @return - */ -exprt create_safety_constraint(const size_t number_of_loops); - -#endif // CPROVER_CEGIS_SAFETY_CONSTRAINT_SAFETY_CONSTRAINT_FACTORY_H diff --git a/src/cegis/safety/facade/safety_runner.cpp b/src/cegis/safety/facade/safety_runner.cpp deleted file mode 100644 index 236bdb159ee..00000000000 --- a/src/cegis/safety/facade/safety_runner.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -typedef messaget::mstreamt mstreamt; - -template -int configure_ui_and_run(mstreamt &os, const optionst &opt, learnt &learn, - verifyt &verify, preproct &preproc) -{ - null_seedt seed; - const size_t max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - if(!opt.get_bool_option(CEGIS_STATISTICS)) - return run_cegis(learn, verify, preproc, seed, max_prog_size, os); - cegis_statistics_wrappert stat(learn, verify, os, opt); - return run_cegis(stat, stat, preproc, seed, max_prog_size, os); -} - -template -int configure_backend(mstreamt &os, const optionst &o, - const safety_programt &prog, learnt &cfg, verifyt &verify, prept &prep) -{ - if(!o.get_bool_option(CEGIS_GENETIC)) - { - cegis_symex_learnt learn(o, prep, cfg); - return configure_ui_and_run(os, o, learn, verify, prep); - } - encoded_safety_learn_configt enc(cfg); - typedef genetic_preprocessingt preproct; - preproct pre(o, prep); - typedef cegis_symex_learnt symex_learnt; - symex_learnt learn(o, pre, enc); - safety_program_genetic_settingst set(o, prog, pre); - lazy_genetic_settingst > lazy(set); - invariant_exec_body_providert body(DANGER_EXECUTE, prog); - instruction_set_info_factoryt info_fac(std::ref(body)); - const size_t rounds=o.get_unsigned_int_option(CEGIS_ROUNDS); - const typet type=cegis_default_integer_type(); // XXX: Currently single user data type. - random_individualt rnd(type, info_fac, lazy); - safety_fitness_configt safety_fitness_config(info_fac, prog); - concrete_fitness_source_providert src( - prog, lazy.max_prog_sz_provider(), DANGER_EXECUTE); - dynamic_safety_test_runnert test_runner(std::ref(src), - lazy.max_prog_sz_per_index_provider()); - typedef lazy_fitnesst fitnesst; - fitnesst fit(test_runner); - random_mutatet mutate(rnd, lazy.num_consts_provder()); - random_crosst cross(rnd); - const size_t symex_head_start=o.get_unsigned_int_option(CEGIS_SYMEX_HEAD_START); - if(o.get_bool_option(CEGIS_MATCH_SELECT)) - { - typedef match_selectt selectt; - selectt select(fit.get_test_case_data(), rnd, rounds); - typedef ga_learnt, safety_fitness_configt> ga_learnt; - ga_learnt ga_learn(o, rnd, select, mutate, cross, fit, safety_fitness_config); -#ifndef _WIN32 - if(!o.get_bool_option(CEGIS_GENETIC_ONLY)) - { - const individual_to_safety_solution_deserialisert deser(prog, info_fac); - concurrent_learnt learner(ga_learn, learn, - serialise, deser, deserialise, symex_head_start); - return configure_ui_and_run(os, o, learner, verify, pre); - } -#endif - return configure_ui_and_run(os, o, ga_learn, verify, pre); - } - typedef tournament_selectt selectt; - selectt select(rounds); - typedef ga_learnt, safety_fitness_configt> ga_learnt; - ga_learnt ga_learn(o, rnd, select, mutate, cross, fit, safety_fitness_config); -#ifndef _WIN32 - if(!o.get_bool_option(CEGIS_GENETIC_ONLY)) - { - const individual_to_safety_solution_deserialisert deser(prog, info_fac); - concurrent_learnt learner(ga_learn, learn, - serialise, std::ref(deser), deserialise, symex_head_start); - return configure_ui_and_run(os, o, learner, verify, pre); - } -#endif - return configure_ui_and_run(os, o, ga_learn, verify, pre); -} - -constant_strategyt get_constant_strategy(const optionst &opt) -{ - if(opt.get_bool_option(CEGIS_GENETIC)) return genetic_constant_strategy; - return default_constant_strategy; -} -} - -int run_safety(optionst &options, mstreamt &result, const symbol_tablet &st, - const goto_functionst &gf) -{ - srand(options.get_unsigned_int_option(CEGIS_SEED)); - safety_preprocessingt prep(options, st, gf, get_constant_strategy(options)); - const safety_programt &safety_program=prep.get_safety_program(); - safety_learn_configt learn(safety_program); - safety_verify_configt verify_cfg(safety_program); - cegis_symex_verifyt verify(options, verify_cfg); - return configure_backend(result, options, safety_program, learn, verify, prep); -} diff --git a/src/cegis/safety/facade/safety_runner.h b/src/cegis/safety/facade/safety_runner.h deleted file mode 100644 index cea2774c334..00000000000 --- a/src/cegis/safety/facade/safety_runner.h +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_FACADE_SAFETY_RUNNER_H -#define CPROVER_CEGIS_SAFETY_FACADE_SAFETY_RUNNER_H - -#include - -/** - * @brief - * - * @details - * - * @param cmdline - * @param options - * @param result - * @param st - * @param gf - * - * @return - */ -int run_safety(class optionst &options, messaget::mstreamt &result, - const class symbol_tablet &st, const class goto_functionst &gf); - -#endif // CPROVER_CEGIS_SAFETY_FACADE_SAFETY_RUNNER_H diff --git a/src/cegis/safety/genetic/dynamic_safety_test_runner.cpp b/src/cegis/safety/genetic/dynamic_safety_test_runner.cpp deleted file mode 100644 index 8cdde344803..00000000000 --- a/src/cegis/safety/genetic/dynamic_safety_test_runner.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include - -dynamic_safety_test_runnert::dynamic_safety_test_runnert( - const std::function &source_code_provider, - const std::function &max_prog_sz) : - source_code_provider(source_code_provider), max_prog_sz(max_prog_sz), shared_library( - LIBRARY_PREFIX, - LIBRARY_SUFFIX), handle(0), fitness_tester(0) -{ -} - -dynamic_safety_test_runnert::~dynamic_safety_test_runnert() -{ - close_fitness_tester_library(handle, fitness_tester); -} - -void dynamic_safety_test_runnert::run_test(individualt &ind, - const counterexamplet &ce, const std::function on_complete) -{ - const auto source_code_provider= - [this]() - { - std::string code(this->source_code_provider()); - substitute(code, "unsigned int __CPROVER_cegis_deserialise_index=__CPROVER_cegis_first_prog_offset", "unsigned int __CPROVER_cegis_deserialise_index=0"); - substitute(code, "unsigned int __CPROVER_cegis_ce_index=0u", "unsigned int __CPROVER_cegis_ce_index=__CPROVER_cegis_deserialise_index"); - return code; - }; - prepare_fitness_tester_library(handle, fitness_tester, source_code_provider, - shared_library()); - assert(ind.x0.empty()); - std::deque args; - // TODO: Implement for multiple loops (change constraint, instrumentation) - assert(ind.programs.size() == 1u); - serialise(args, ind, max_prog_sz); - serialise(args, ce.x0); - // TODO: Implement for multiple loops (change constraint, instrumentation) - assert(ce.x.size() == 1u); - serialise(args, ce.x.front()); - - const int argc=args.size(); - std::vector argv; - argv.resize(argc); - for(int i=0; i < argc; ++i) - argv[i]=args[i]; - - on_complete(EXIT_SUCCESS == fitness_tester(argv.data())); -} - -void dynamic_safety_test_runnert::join() -{ -} diff --git a/src/cegis/safety/genetic/dynamic_safety_test_runner.h b/src/cegis/safety/genetic/dynamic_safety_test_runner.h deleted file mode 100644 index bb696fb7a7e..00000000000 --- a/src/cegis/safety/genetic/dynamic_safety_test_runner.h +++ /dev/null @@ -1,79 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_GENETIC_DYNAMIC_SAFETY_TEST_RUNNER_H -#define CPROVER_CEGIS_SAFETY_GENETIC_DYNAMIC_SAFETY_TEST_RUNNER_H - -#include - -#include -#include - -#include - -/** - * @brief - * - * @details - */ -class dynamic_safety_test_runnert -{ -public: - typedef int (*fitness_testert)(const unsigned int[]); - typedef void *lib_handlet; -private: - const std::function source_code_provider; - const std::function max_prog_sz; - const temporary_filet shared_library; - lib_handlet handle; - fitness_testert fitness_tester; -public: - typedef class safety_goto_cet counterexamplet; - typedef program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param source_code_provider - * @param max_prog_sz - */ - dynamic_safety_test_runnert( - const std::function &source_code_provider, - const std::function &max_prog_sz); - - /** - * @brief - * - * @details - */ - ~dynamic_safety_test_runnert(); - - /** - * @brief - * - * @details - * - * @param ind - * @param ce - * @param on_complete - */ - void run_test(individualt &ind, const counterexamplet &ce, - std::function on_complete); - - /** - * @brief - * - * @details - */ - void join(); -}; - -#endif // CPROVER_CEGIS_SAFETY_GENETIC_DYNAMIC_SAFETY_TEST_RUNNER_H diff --git a/src/cegis/safety/meta/meta_variable_names.cpp b/src/cegis/safety/meta/meta_variable_names.cpp deleted file mode 100644 index 64be5eea8de..00000000000 --- a/src/cegis/safety/meta/meta_variable_names.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -namespace -{ -const char INVARIANT_PREFIX[]=CEGIS_PREFIX"I"; -const char SEP='_'; -const char INITIAL_STATE[]="x0"; -} - -std::string get_Ix0() -{ - std::string result(INVARIANT_PREFIX); - result+=SEP; - return result+=INITIAL_STATE; -} - -namespace -{ -std::string build_var_name(const char * const prefix, const size_t loop_id, - const char * const state) -{ - std::string result(prefix); - result+=integer2string(loop_id); - result+=SEP; - return result+=state; -} - -const char STATE_BEFORE_LOOP[]="x"; -} - -std::string get_Ix(const size_t loop_id) -{ - return build_var_name(INVARIANT_PREFIX, loop_id, STATE_BEFORE_LOOP); -} - -namespace -{ -const char STATE_AFTER_LOOP[]="x" CEGIS_PRIME_SUFFIX; -} - -std::string get_Ix_prime(const size_t loop_id) -{ - return build_var_name(INVARIANT_PREFIX, loop_id, STATE_AFTER_LOOP); -} diff --git a/src/cegis/safety/meta/meta_variable_names.h b/src/cegis/safety/meta/meta_variable_names.h deleted file mode 100644 index 81b68f16242..00000000000 --- a/src/cegis/safety/meta/meta_variable_names.h +++ /dev/null @@ -1,46 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_META_META_VARIABLE_NAMES_H -#define CPROVER_CEGIS_SAFETY_META_META_VARIABLE_NAMES_H - -#include - -/** - * @brief - * - * @details - * - * @return - */ -std::string get_Ix0(); - -/** - * @brief - * - * @details - * - * @param loop_id - * - * @return - */ -std::string get_Ix(const size_t loop_id); - -/** - * @brief - * - * @details - * - * @param loop_id - * - * @return - */ -std::string get_Ix_prime(const size_t loop_id); - -#endif // CPROVER_CEGIS_SAFETY_META_META_VARIABLE_NAMES_H diff --git a/src/cegis/safety/options/safety_program.cpp b/src/cegis/safety/options/safety_program.cpp deleted file mode 100644 index c7019b95aaf..00000000000 --- a/src/cegis/safety/options/safety_program.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include - -safety_programt::safety_programt() -{ -} - -namespace -{ -safety_programt &assign(safety_programt &lhs, const safety_programt &rhs) -{ - const target_copy_helpert copy(get_entry_body(rhs.gf), - get_entry_body(lhs.gf)); - const safety_programt::safety_loopst &old_loops=rhs.safety_loops; - safety_programt::safety_loopst &new_loops=lhs.safety_loops; - new_loops.resize(old_loops.size()); - std::transform(old_loops.begin(), old_loops.end(), new_loops.begin(), - [©](const invariant_programt::invariant_loopt &old_loop) - { invariant_programt::invariant_loopt new_loop; - copy(new_loop, old_loop); - return new_loop;}); - return lhs; -} -} - -safety_programt::safety_programt(const safety_programt &other) : - invariant_programt(other) -{ - assign(*this, other); -} - -safety_programt::safety_programt(const symbol_tablet &st, - const class goto_functionst &gf) : - invariant_programt(st, gf) -{ -} - -safety_programt::~safety_programt() -{ -} - -safety_programt &safety_programt::operator=(const safety_programt &other) -{ - invariant_programt::operator =(other); - return assign(*this, other); -} - -invariant_programt::const_invariant_loopst safety_programt::get_loops() const -{ - const_invariant_loopst result(safety_loops.size()); - std::transform(safety_loops.begin(), safety_loops.end(), result.begin(), - [](const invariant_loopt &loop) - { return &loop;}); - return result; -} - -invariant_programt::invariant_loopst safety_programt::get_loops() -{ - invariant_loopst result(safety_loops.size()); - std::transform(safety_loops.begin(), safety_loops.end(), result.begin(), - [](invariant_loopt &loop) - { return &loop;}); - return result; -} - -invariant_programt::invariant_loopt &safety_programt::add_loop() -{ - safety_loops.push_back(invariant_loopt()); - return safety_loops.back(); -} diff --git a/src/cegis/safety/options/safety_program.h b/src/cegis/safety/options/safety_program.h deleted file mode 100644 index 08b76f2ea09..00000000000 --- a/src/cegis/safety/options/safety_program.h +++ /dev/null @@ -1,86 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_H -#define CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_H - -#include - -/** - * @brief - * - * @details - */ -class safety_programt: public invariant_programt -{ -public: - typedef std::vector safety_loopst; - safety_loopst safety_loops; - - /** - * @brief - * - * @details - */ - safety_programt(); - - /** - * @brief - * - * @details - * - * @param other - */ - explicit safety_programt(const safety_programt &other); - - /** - * @brief - * - * @details - * - * @param st - * @param gf - */ - safety_programt(const symbol_tablet &st, const goto_functionst &gf); - - /** - * @brief - * - * @details - */ - virtual ~safety_programt(); - - /** - * @brief - * - * @details - * - * @param other - * - * @return - */ - safety_programt &operator=(const safety_programt &other); - - /** - * @see invariant_programt::get_loops - */ - virtual const_invariant_loopst get_loops() const; - - /** - * @see invariant_programt::get_loops - */ - virtual invariant_loopst get_loops(); - - /** - * @see invariant_programt::add_loop - */ - virtual invariant_loopt &add_loop(); -}; - -#endif // CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_H diff --git a/src/cegis/safety/options/safety_program_genetic_settings.h b/src/cegis/safety/options/safety_program_genetic_settings.h deleted file mode 100644 index 81157207e4d..00000000000 --- a/src/cegis/safety/options/safety_program_genetic_settings.h +++ /dev/null @@ -1,84 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_GENETIC_SETTINGS_H -#define CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_GENETIC_SETTINGS_H - -#include - -/** - * @brief - * - * @details - */ -template -class safety_program_genetic_settingst: public genetic_settingst -{ - const class optionst &opt; - const class safety_programt &prog; - preproct &preproc; -public: - /** - * @brief - * - * @details - * - * @param opt - * @param prog - * @param preproc - */ - safety_program_genetic_settingst(const optionst &opt, - const safety_programt &prog, preproct &preproc); - - /** - * @brief - * - * @details - */ - virtual ~safety_program_genetic_settingst(); - - /** - * @see genetic_settingst::min_prog_sz(size_t) - */ - virtual size_t min_prog_sz(size_t prog_index); - - /** - * @see genetic_settingst::max_prog_sz(size_t) - */ - virtual size_t max_prog_sz(size_t prog_index); - - /** - * @see genetic_settingst::max_prog_sz() - */ - virtual size_t max_prog_sz(); - - /** - * @see genetic_settingst::num_progs() - */ - virtual size_t num_progs(); - - /** - * @see genetic_settingst::num_vars() - */ - virtual size_t num_vars(); - - /** - * @see genetic_settingst::num_consts() - */ - virtual size_t num_consts(); - - /** - * @see genetic_settingst::num_x0() - */ - virtual size_t num_x0(); -}; - -#include "safety_program_genetic_settings.inc" - -#endif // CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_GENETIC_SETTINGS_H diff --git a/src/cegis/safety/options/safety_program_genetic_settings.inc b/src/cegis/safety/options/safety_program_genetic_settings.inc deleted file mode 100644 index 41bfcef44cc..00000000000 --- a/src/cegis/safety/options/safety_program_genetic_settings.inc +++ /dev/null @@ -1,70 +0,0 @@ -#include - -#include -#include -#include - -template -safety_program_genetic_settingst::safety_program_genetic_settingst( - const optionst &opt, const safety_programt &prog, preproct &preproc) : - opt(opt), prog(prog), preproc(preproc) -{ -} - -template -safety_program_genetic_settingst::~safety_program_genetic_settingst() -{ -} - -namespace -{ -const size_t MIN_PROG_SZ=1u; -} - -template -size_t safety_program_genetic_settingst::min_prog_sz( - const size_t prog_index) -{ - return std::max(MIN_PROG_SZ, preproc.get_min_solution_size()); -} - -template -size_t safety_program_genetic_settingst::max_prog_sz( - const size_t prog_index) -{ - return max_prog_sz(); -} - -template -size_t safety_program_genetic_settingst::max_prog_sz() -{ - const size_t user_max_prog_size=opt.get_unsigned_int_option(CEGIS_MAX_SIZE); - return std::max(min_prog_sz(0u), user_max_prog_size); -} - -template -size_t safety_program_genetic_settingst::num_progs() -{ - return prog.safety_loops.size(); -} - -template -size_t safety_program_genetic_settingst::num_vars() -{ - operand_variable_idst vars; - get_invariant_variable_ids(prog.st, vars); - return vars.size(); -} - -template -size_t safety_program_genetic_settingst::num_consts() -{ - operand_variable_idst vars; - return get_invariant_variable_ids(prog.st, vars); -} - -template -size_t safety_program_genetic_settingst::num_x0() -{ - return 0u; -} diff --git a/src/cegis/safety/options/safety_program_printer.cpp b/src/cegis/safety/options/safety_program_printer.cpp deleted file mode 100644 index 898479edfb1..00000000000 --- a/src/cegis/safety/options/safety_program_printer.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include -#include -#include -#include - -namespace -{ -class program_printert -{ - const namespacet ns; - const goto_programt &body_printer; - messaget::mstreamt &os; - size_t func_count; -public: - program_printert(const safety_programt &prog, messaget::mstreamt &os) : - ns(prog.st), body_printer(get_entry_body(prog.gf)), os(os), func_count(0) - { - } - - void operator()(const goto_programt::instructionst &prog) - { - os << "Invariant " << func_count++ << ": " << messaget::endl; - for(goto_programt::const_targett it=prog.begin(); it != prog.end(); ++it) - body_printer.output_instruction(ns, "", os, it); - } -}; -} - -void print_safety_program(messaget::mstreamt &os, - const safety_programt &program, const safety_goto_solutiont &solution) -{ - os << "Programs:" << messaget::endl; - const program_printert prog_printer(program, os); - std::for_each(solution.begin(), solution.end(), prog_printer); - os << messaget::eom; -} diff --git a/src/cegis/safety/options/safety_program_printer.h b/src/cegis/safety/options/safety_program_printer.h deleted file mode 100644 index 39fff5e8251..00000000000 --- a/src/cegis/safety/options/safety_program_printer.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_PRINTER_H -#define CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_PRINTER_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param os - * @param program - * @param solution - */ -void print_safety_program(messaget::mstreamt &os, - const class safety_programt &program, - const safety_goto_solutiont &solution); - -#endif // CPROVER_CEGIS_SAFETY_OPTIONS_SAFETY_PROGRAM_PRINTER_H diff --git a/src/cegis/safety/preprocessing/safety_preprocessing.cpp b/src/cegis/safety/preprocessing/safety_preprocessing.cpp deleted file mode 100644 index 11ce7386ba4..00000000000 --- a/src/cegis/safety/preprocessing/safety_preprocessing.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include -#include - -#include - -#include -#include -#include -// TODO: Move to invariant folder -#include -#include -#include - -safety_preprocessingt::safety_preprocessingt(optionst &options, - const symbol_tablet &st, const goto_functionst &gf, - const constant_strategyt &constant_strategy) : - options(options), original_program(st, gf), constant_strategy( - constant_strategy) -{ -} - -safety_preprocessingt::~safety_preprocessingt() -{ -} - -size_t safety_preprocessingt::get_min_solution_size() const -{ - return 1u; -} - -namespace -{ -void add_choice_labels(const goto_programt::targetst &choices, size_t offset=0) -{ - for(const goto_programt::targett &choice : choices) - { - goto_programt::instructiont::labelst &labels=choice->labels; - std::string label(DANGER_CE_QUANTIFIER_LABEL_PREFIX); - label+=integer2string(offset++); - labels.push_back(label); - } -} - -void add_skolem_labels(const invariant_programt &prog) -{ - size_t offset=0; - const invariant_programt::const_invariant_loopst loops(prog.get_loops()); - for(const invariant_programt::invariant_loopt * const loop : loops) - { - add_choice_labels(loop->skolem_choices, offset); - offset+=loop->skolem_choices.size(); - } -} -} - -void safety_preprocessingt::operator ()() -{ - const namespacet ns(original_program.st); - null_message_handlert null_msg; - goto_functionst &gf=original_program.gf; - goto_inline(gf, ns, null_msg); - invariant_remove_loops_and_assertion(original_program); - store_skolem_choices(original_program); - add_skolem_labels(original_program); - gf.update(); - current_program=original_program; -} - -size_t get_x0_offset(const invariant_programt &prog) -{ - const invariant_programt::const_invariant_loopst l(prog.get_loops()); - return std::accumulate(l.begin(), l.end(), 0, - [](const size_t sum, const invariant_programt::invariant_loopt * const loop) - { return sum + loop->skolem_choices.size();}); -} - -void safety_preprocessingt::operator ()(const size_t max_length) -{ - current_program=original_program; - const unsigned int max_width=constant_strategy(current_program, max_length); - options.set_option("max-constant-width", max_width); - store_x0_choices(current_program); - add_choice_labels(current_program.x0_choices, get_x0_offset(current_program)); - create_tmp_variables(current_program, max_length); - add_invariant_variables(current_program, get_Ix0(), get_Ix, get_Ix_prime); -} - -const safety_programt &safety_preprocessingt::get_safety_program() const -{ - return current_program; -} diff --git a/src/cegis/safety/preprocessing/safety_preprocessing.h b/src/cegis/safety/preprocessing/safety_preprocessing.h deleted file mode 100644 index 9f3251b8481..00000000000 --- a/src/cegis/safety/preprocessing/safety_preprocessing.h +++ /dev/null @@ -1,82 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_PREPROCESSING_SAFETY_PREPROCESSING_H -#define CPROVER_CEGIS_SAFETY_PREPROCESSING_SAFETY_PREPROCESSING_H - -#include -#include - -/** - * @brief - * - * @details - */ -class safety_preprocessingt -{ - class optionst &options; - safety_programt original_program; - safety_programt current_program; - const constant_strategyt constant_strategy; -public: - /** - * @brief - * - * @details - * - * @param options - * @param st - * @param gf - * @param constant_strategy - */ - safety_preprocessingt(optionst &options, const symbol_tablet &st, - const goto_functionst &gf, const constant_strategyt &constant_strategy); - - /** - * @brief - * - * @details - */ - ~safety_preprocessingt(); - - /** - * @brief Provides the minimum solution size. - * - * @details Properties like the number of skolem choices dictate the minimum - * solution size. - */ - size_t get_min_solution_size() const; - - /** - * @brief - * - * @details - */ - void operator()(); - - /** - * @brief - * - * @details - * - * @param max_solution_length - */ - void operator()(size_t max_solution_length); - - /** - * @brief - * - * @details - * - * @return - */ - const safety_programt &get_safety_program() const; -}; - -#endif // CPROVER_CEGIS_SAFETY_PREPROCESSING_SAFETY_PREPROCESSING_H diff --git a/src/cegis/safety/symex/fitness/safety_fitness_config.cpp b/src/cegis/safety/symex/fitness/safety_fitness_config.cpp deleted file mode 100644 index e000fa967c1..00000000000 --- a/src/cegis/safety/symex/fitness/safety_fitness_config.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -safety_fitness_configt::safety_fitness_configt( - instruction_set_info_factoryt &info_fac, const safety_programt &prog) : - info_fac(info_fac), original_program(prog), constraint_inserted(false), program_contains_ce( - false), max_solution_size(0u) -{ -} - -safety_fitness_configt::~safety_fitness_configt() -{ -} - -void safety_fitness_configt::convert(candidatet ¤t_candidate, - const individualt &ind) -{ - const symbol_tablet &st=original_program.st; - const goto_functionst &gf=original_program.gf; - operand_variable_idst ids; - get_invariant_variable_ids(st, ids); - create_safety_solution(current_candidate, st, gf, ind, ids, info_fac); -} - -namespace -{ -void fix_quantifiers(const safety_programt &org_prog, safety_programt &new_prog, - goto_programt::targetst &quantifiers) -{ - goto_programt::const_targett org_off= - org_prog.safety_loops.front().meta_variables.Ix; - --org_off; - goto_programt::targett new_off=new_prog.safety_loops.front().meta_variables.Ix; - --new_off; - goto_programt::targett::difference_type diff; - for(goto_programt::targett &q : quantifiers) - { - diff=std::distance(org_off, static_cast(q)); - q=new_off; - std::advance(q, diff); - } -} -} - -void safety_fitness_configt::set_candidate(const candidatet &candidate) -{ - if(!constraint_inserted) - { - program_with_constraint=original_program; - invariant_insert_constraint(original_quantifiers, program_with_constraint, - create_safety_constraint); - constraint_inserted=true; - } - program=program_with_constraint; - quantifiers=original_quantifiers; - fix_quantifiers(program_with_constraint, program, quantifiers); - program_contains_ce=false; - safety_insert_candidate(program, candidate); -} - -void safety_fitness_configt::set_test_case(const counterexamplet &ce) -{ - if(quantifiers.empty()) return; - goto_functionst &gf=program.gf; - // TODO: Implement for multiple loops (change constraint, instrumentation) - const counterexamplet::assignmentst &ass=ce.x.back(); - typedef counterexamplet::assignmentst counterexamplet; - - for(goto_programt::targett quantifier : quantifiers) - { - const irep_idt &var=get_affected_variable(*quantifier); - const counterexamplet::const_iterator it=ass.find(var); - if(ass.end() == it) continue; - symbol_tablet &st=program.st; - if(program_contains_ce) - { - goto_programt::targett assignment=quantifier; - erase_target(get_entry_body(gf).instructions, ++assignment); - } - cegis_assign_user_variable(st, gf, quantifier, var, it->second); - } - gf.update(); - program_contains_ce=true; -} - -const symbol_tablet &safety_fitness_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &safety_fitness_configt::get_goto_functions() const -{ - return program.gf; -} - -void safety_fitness_configt::set_max_solution_size(const size_t size) -{ - max_solution_size=size; -} - -void safety_fitness_configt::show(messaget::mstreamt &os, - const candidatet &candidate) const -{ - print_safety_program(os, original_program, candidate); -} diff --git a/src/cegis/safety/symex/fitness/safety_fitness_config.h b/src/cegis/safety/symex/fitness/safety_fitness_config.h deleted file mode 100644 index 64fb8bb30f8..00000000000 --- a/src/cegis/safety/symex/fitness/safety_fitness_config.h +++ /dev/null @@ -1,123 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_FITNESS_SAFETY_FITNESS_CONFIG_H -#define CPROVER_CEGIS_SAFETY_SYMEX_FITNESS_SAFETY_FITNESS_CONFIG_H - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class safety_fitness_configt -{ - class instruction_set_info_factoryt &info_fac; - const safety_programt &original_program; - safety_programt program_with_constraint; - goto_programt::targetst original_quantifiers; - safety_programt program; - goto_programt::targetst quantifiers; - bool constraint_inserted; - bool program_contains_ce; - size_t max_solution_size; -public: - typedef safety_goto_solutiont candidatet; - typedef class safety_goto_cet counterexamplet; - typedef class program_individualt individualt; - - /** - * @brief - * - * @details - * - * @param info_fac - * @param prog - */ - safety_fitness_configt(instruction_set_info_factoryt &info_fac, - const safety_programt &prog); - - /** - * @brief - * - * @details - */ - ~safety_fitness_configt(); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void set_candidate(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @param ce - */ - void set_test_case(const counterexamplet &ce); - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param ind - */ - void convert(candidatet ¤t_candidate, const individualt &ind); - - /** - * @brief - * - * @details - * - * @return - */ - const class symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const class goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param size - */ - void set_max_solution_size(size_t size); - - /** - * @brief - * - * @details - * - * @param candidate - * @param os - */ - void show(messaget::mstreamt &os, const candidatet &candidate) const; -}; - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_FITNESS_SAFETY_FITNESS_CONFIG_H diff --git a/src/cegis/safety/symex/learn/add_counterexamples.cpp b/src/cegis/safety/symex/learn/add_counterexamples.cpp deleted file mode 100644 index 4b3bcbe7e64..00000000000 --- a/src/cegis/safety/symex/learn/add_counterexamples.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include -#include -#include - -namespace -{ -void positional_assign(invariant_programt &prog, - const goto_programt::targetst &vars, const counterexamplest &values, - const std::string &pre) -{ - const counterexamplet &ce_template=values.front(); - for(const goto_programt::targett x0 : vars) - { - const irep_idt &id=get_affected_variable(*x0); - const counterexamplet::const_iterator it=ce_template.find(id); - assert(ce_template.end() != it); - counterexamplet tmp; - tmp.insert(std::make_pair(id, it->second)); - invariant_assign_ce_values(prog, tmp, values.size(), pre, x0, false); - } -} -} - -void safety_add_learned_counterexamples(safety_programt &prog, - const safety_goto_cest &ces, constraint_factoryt constraint) -{ - if(ces.empty()) return; - // TODO: Implement for multiple loops (change constraint, instrumentation) - counterexamplest x0s; - std::transform(ces.begin(), ces.end(), std::back_inserter(x0s), - [](const safety_goto_cet &ce) - { return ce.x0;}); - counterexamplest first_loop_only; - std::transform(ces.begin(), ces.end(), std::back_inserter(first_loop_only), - [](const safety_goto_cet &ce) - { assert(!ce.x.empty()); return ce.x.front();}); - const std::string x0_pre(X0_CHOICE_PREFIX); - const std::string x_pre(X_CHOICE_PREFIX); - invariant_declare_x_choice_arrays(prog, x0s, x0_pre); - invariant_declare_x_choice_arrays(prog, first_loop_only, x_pre); - const size_t sz=ces.size(); - const goto_programt::targett loop_end=invariant_add_ce_loop(prog, sz, false); - positional_assign(prog, prog.x0_choices, first_loop_only, x0_pre); - for(const goto_programt::targett x0 : prog.x0_choices) - { - const irep_idt &id=get_affected_variable(*x0); - const counterexamplet &ce_template=x0s.front(); - const counterexamplet::const_iterator it=ce_template.find(id); - assert(ce_template.end() != it); - counterexamplet tmp; - tmp.insert(std::make_pair(id, it->second)); - invariant_assign_ce_values(prog, tmp, x0s.size(), x0_pre, x0, false); - } - goto_programt::targett pos=prog.get_loops().front()->meta_variables.Ix; - const size_t first_loop_sz=first_loop_only.size(); - invariant_assign_ce_values(prog, first_loop_only.front(), first_loop_sz, - x_pre, pos, false); - invariant_add_constraint(prog, constraint, loop_end); -} diff --git a/src/cegis/safety/symex/learn/add_counterexamples.h b/src/cegis/safety/symex/learn/add_counterexamples.h deleted file mode 100644 index 08dae224adb..00000000000 --- a/src/cegis/safety/symex/learn/add_counterexamples.h +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H -#define CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H - -#include -#include - -typedef std::deque safety_goto_cest; - -/** - * @brief - * - * @details - */ -#define X0_CHOICE_PREFIX CEGIS_PREFIX "x0_choice_" - -/** - * @brief - * - * @details - * - * @param prog - * @param ces - * @param use_x0_ce - */ -void safety_add_learned_counterexamples(class safety_programt &prog, - const safety_goto_cest &ces, constraint_factoryt constraint); - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_COUNTEREXAMPLES_H diff --git a/src/cegis/safety/symex/learn/add_variable_refs.cpp b/src/cegis/safety/symex/learn/add_variable_refs.cpp deleted file mode 100644 index efa358402e5..00000000000 --- a/src/cegis/safety/symex/learn/add_variable_refs.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -void add_safety_learning_variable_refs(invariant_programt &prog, - const operand_variable_idst &var_ids, const size_t max_sz) -{ - link_user_program_variables(prog, var_ids); - const symbol_tablet &st=prog.st; - goto_functionst &gf=prog.gf; - const size_t num_vars=var_ids.size(); - const invariant_programt::const_invariant_loopst loops( - static_cast(prog).get_loops()); - for(const invariant_programt::invariant_loopt * const loop : loops) - { - link_result_var(st, gf, num_vars, max_sz, loop->meta_variables.Ix); - link_result_var(st, gf, num_vars, max_sz, loop->meta_variables.Ix_prime); - } -} diff --git a/src/cegis/safety/symex/learn/add_variable_refs.h b/src/cegis/safety/symex/learn/add_variable_refs.h deleted file mode 100644 index 51fc08a03f2..00000000000 --- a/src/cegis/safety/symex/learn/add_variable_refs.h +++ /dev/null @@ -1,29 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_VARIABLE_REFS_H -#define CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_VARIABLE_REFS_H - -#include - -typedef std::map operand_variable_idst; - -/** - * @brief - * - * @details - * - * @param prog - * @param var_ids - * @parma max_solution_size - */ -void add_safety_learning_variable_refs(class invariant_programt &prog, - const operand_variable_idst &var_ids, size_t max_solution_size); - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ADD_VARIABLE_REFS_H diff --git a/src/cegis/safety/symex/learn/encoded_safety_learn_config.cpp b/src/cegis/safety/symex/learn/encoded_safety_learn_config.cpp deleted file mode 100644 index 31c7b53f2a8..00000000000 --- a/src/cegis/safety/symex/learn/encoded_safety_learn_config.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -encoded_safety_learn_configt::encoded_safety_learn_configt( - safety_learn_configt &config) : - config(config) -{ -} - -encoded_safety_learn_configt::~encoded_safety_learn_configt() -{ -} - -void encoded_safety_learn_configt::process( - const counterexamplest &counterexamples, const size_t max_solution_size) -{ - config.process(counterexamples, max_solution_size); -} - -void encoded_safety_learn_configt::set_word_width( - const size_t word_width_in_bits) -{ - config.set_word_width(word_width_in_bits); -} - -const symbol_tablet &encoded_safety_learn_configt::get_symbol_table() const -{ - return config.get_symbol_table(); -} - -const goto_functionst &encoded_safety_learn_configt::get_goto_functions() const -{ - return config.get_goto_functions(); -} - -void encoded_safety_learn_configt::convert(candidatet &candidate, - const class goto_tracet &trace, const size_t max_solution_size) -{ - const invariant_programt &prog=config.get_safety_program(); - candidate=to_program_individual(prog, trace); -} - -void encoded_safety_learn_configt::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) -{ - safety_goto_solutiont converted; - const symbol_tablet &st=get_symbol_table(); - const goto_functionst &gf=get_goto_functions(); - const safety_learn_configt::invariant_variable_idst &vars=config.get_vars(); - create_safety_solution(converted, st, gf, candidate, vars); - config.show_candidate(os, converted); -} - -size_t encoded_safety_learn_configt::get_num_vars() const -{ - return config.get_num_vars(); -} - -size_t encoded_safety_learn_configt::get_num_consts() const -{ - return config.get_num_consts(); -} diff --git a/src/cegis/safety/symex/learn/encoded_safety_learn_config.h b/src/cegis/safety/symex/learn/encoded_safety_learn_config.h deleted file mode 100644 index 7aa502ad1f8..00000000000 --- a/src/cegis/safety/symex/learn/encoded_safety_learn_config.h +++ /dev/null @@ -1,125 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ENCODED_SAFETY_LEARN_CONFIG_H -#define CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ENCODED_SAFETY_LEARN_CONFIG_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class encoded_safety_learn_configt -{ - class safety_learn_configt &config; -public: - typedef safety_learn_configt::counterexamplet counterexamplet; - typedef safety_learn_configt::counterexamplest counterexamplest; - typedef program_individualt candidatet; - - /** - * @brief - * - * @details - * - * @param config - */ - explicit encoded_safety_learn_configt(safety_learn_configt &config); - - /** - * @brief - * - * @details - */ - ~encoded_safety_learn_configt(); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process(const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert(candidatet ¤t_candidate, const class goto_tracet &trace, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate(messaget::mstreamt &os, const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_consts() const; -}; - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_LEARN_ENCODED_SAFETY_LEARN_CONFIG_H diff --git a/src/cegis/safety/symex/learn/safety_learn_config.cpp b/src/cegis/safety/symex/learn/safety_learn_config.cpp deleted file mode 100644 index 254c84a1238..00000000000 --- a/src/cegis/safety/symex/learn/safety_learn_config.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -safety_learn_configt::safety_learn_configt(const safety_programt &program) : - original_program(program), num_consts(0) -{ -} - -safety_learn_configt::~safety_learn_configt() -{ -} - -void safety_learn_configt::process(const counterexamplest &ces, - const size_t max_sz) -{ - program=original_program; - var_ids.clear(); - symbol_tablet &st=program.st; - num_consts=get_invariant_variable_ids(st, var_ids); - const size_t num_vars=var_ids.size(); - null_message_handlert msg; - const std::string name(DANGER_EXECUTE); - goto_functionst &gf=program.gf; - add_cegis_library(st, gf, msg, num_vars, num_consts, max_sz, name); - add_safety_learning_variable_refs(program, var_ids, max_sz); - link_result_var(st, gf, var_ids.size(), max_sz, program.Ix0); - add_invariant_progs_to_learn(program, max_sz); - const invariant_programt &prog=program; - const invariant_programt::const_invariant_loopst loops(prog.get_loops()); - const invariant_programt::invariant_loopt &first_loop=*loops.front(); - const std::string I0=get_prog_var_name(st, first_loop.meta_variables.Ix); - execute_inv_prog(st, gf, max_sz, program.Ix0, I0); - safety_add_learned_counterexamples(program, ces, create_safety_constraint); - gf.update(); -} - -void safety_learn_configt::process(const size_t max_solution_size) -{ - constraint_varst ce_vars; - get_invariant_constraint_vars(ce_vars, original_program); - const typet type(cegis_default_integer_type()); // XXX: Currently single data type - const exprt zero(from_integer(0, type)); - counterexamplet dummy_ce; - dummy_ce.x.push_back(counterexamplet::assignmentst()); - counterexamplet::assignmentst &x=dummy_ce.x.front(); - for(const symbol_exprt &var : ce_vars) - x.insert(std::make_pair(var.get_identifier(), zero)); - // TODO: Implement for multiple loops (change constraint, instrumentation) - const safety_programt &prog=original_program; - const invariant_programt::const_invariant_loopst loops=prog.get_loops(); - assert(!loops.empty()); - // XXX: We might have to handle skolem choices explicitly at some point - for(const goto_programt::targett &skolem_choice : loops.front()->skolem_choices) - x.insert(std::make_pair(get_affected_variable(*skolem_choice), zero)); - counterexamplet::assignmentst &x0=dummy_ce.x0; - for(const goto_programt::targett &x0_choice : original_program.x0_choices) - x0.insert(std::make_pair(get_affected_variable(*x0_choice), zero)); - counterexamplest empty(1, dummy_ce); - process(empty, max_solution_size); -} - -void safety_learn_configt::set_word_width(const size_t word_width_in_bits) -{ - // TODO: Implement! -} - -const symbol_tablet &safety_learn_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &safety_learn_configt::get_goto_functions() const -{ - return program.gf; -} - -const safety_programt &safety_learn_configt::get_safety_program() const -{ - return program; -} - -void safety_learn_configt::convert(candidatet ¤t_candidate, - const goto_tracet &trace, const size_t max_sz) -{ - create_safety_solution(current_candidate, program, trace, var_ids, max_sz); -} - -void safety_learn_configt::show_candidate(messaget::mstreamt &os, - const candidatet &candidate) -{ - print_safety_program(os, program, candidate); -} - -const safety_learn_configt::invariant_variable_idst &safety_learn_configt::get_vars() const -{ - return var_ids; -} - -size_t safety_learn_configt::get_num_vars() const -{ - return var_ids.size(); -} - -size_t safety_learn_configt::get_num_consts() const -{ - return num_consts; -} diff --git a/src/cegis/safety/symex/learn/safety_learn_config.h b/src/cegis/safety/symex/learn/safety_learn_config.h deleted file mode 100644 index 0d93d2a4e3b..00000000000 --- a/src/cegis/safety/symex/learn/safety_learn_config.h +++ /dev/null @@ -1,179 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SAFETY_LEARN_CONFIG_H -#define CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SAFETY_LEARN_CONFIG_H - -#include - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class safety_learn_configt -{ -public: - /** - * @brief - * - * @details - */ - typedef std::map invariant_variable_idst; -private: - const safety_programt &original_program; - safety_programt program; - invariant_variable_idst var_ids; - size_t num_consts; -public: - /** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ - typedef class safety_goto_cet counterexamplet; - typedef std::deque counterexamplest; - - /** - * @brief Candidate solution type for this CEGIS component. - * - * @details Solutions are provided as a set of GOTO function bodies - * (goto_programt::instructionst) for function names. - */ - typedef safety_goto_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit safety_learn_configt(const safety_programt &program); - - /** - * @brief - * - * @details - */ - ~safety_learn_configt(); - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param max_solution_size - */ - void process(const counterexamplest &counterexamples, - size_t max_solution_size); - - /** - * @brief Process the goto program using template data. - * - * @details Creates template counterexamples and processes the goto - * program with them. This is useful for GA source code generation. - * - * @param max_solution_size - */ - void process(size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param word_width_in_bits - */ - void set_word_width(size_t word_width_in_bits); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @return - */ - const safety_programt &get_safety_program() const; - - /** - * @brief - * - * @details - * - * @param current_candidate - * @param trace - * @param max_solution_size - */ - void convert(candidatet ¤t_candidate, const class goto_tracet &trace, - size_t max_solution_size); - - /** - * @brief - * - * @details - * - * @param os - * @param candidate - */ - void show_candidate(messaget::mstreamt &os, const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @param - */ - const invariant_variable_idst &get_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_vars() const; - - /** - * @brief - * - * @details - * - * @return - */ - size_t get_num_consts() const; -}; - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SAFETY_LEARN_CONFIG_H diff --git a/src/cegis/safety/symex/learn/solution_factory.cpp b/src/cegis/safety/symex/learn/solution_factory.cpp deleted file mode 100644 index 158467e3270..00000000000 --- a/src/cegis/safety/symex/learn/solution_factory.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -const goto_programt &get_execute_body(const goto_functionst &gf) -{ - typedef goto_functionst::function_mapt function_mapt; - const function_mapt &function_map=gf.function_map; - const function_mapt::const_iterator it=function_map.find(DANGER_EXECUTE); - assert(function_map.end() != it); - assert(it->second.body_available()); - return it->second.body; -} - -void copy_instructions(goto_programt::instructionst &prog, - const symbol_tablet &st, const invariant_variable_namest &var_names, - const invariant_variable_namest &result_var_names, - const program_individualt::instructiont &instr, - const instruction_sett::value_type::second_type &entry, - const size_t instr_idx) -{ - copy_instructionst copy_instr; - for(goto_programt::const_targett it=entry.begin(); it != entry.end(); ++it) - { - prog.push_back(goto_programt::instructiont()); - goto_programt::targett new_instr=prog.end(); - copy_instr(--new_instr, it); - } - copy_instr.finalize(); - goto_programt::targett first=prog.end(); - std::advance(first, -entry.size()); - const program_individualt::instructiont::opst &ops=instr.ops; - const size_t empty_op=0u; - const size_t op0=!ops.empty() ? ops.front() : empty_op; - const size_t op1=ops.size() >= 2 ? ops.at(1) : empty_op; - const size_t op2=ops.size() >= 3 ? ops.at(2) : empty_op; - replace_ops_in_instr(st, DANGER_EXECUTE, first, prog.end(), var_names, - result_var_names, op0, op1, op2, instr_idx); -} - -void extract_program(goto_programt::instructionst &prog, - const symbol_tablet &st, const instruction_sett &instr_set, - const invariant_variable_namest &var_names, - const invariant_variable_namest &result_var_names, - const program_individualt::programt &instructions) -{ - size_t instr_idx=0; - for(const program_individualt::instructiont &instr : instructions) - { - const program_individualt::instructiont::opcodet opcode=instr.opcode; - const instruction_sett::const_iterator instr_entry=instr_set.find(opcode); - assert(instr_set.end() != instr_entry); - copy_instructions(prog, st, var_names, result_var_names, instr, - instr_entry->second, instr_idx++); - } -} - -void extract_program(goto_programt::instructionst &prog, - const symbol_tablet &st, const instruction_sett &instr_set, - const invariant_variable_namest &vars, - const invariant_variable_namest &rvars, - const exprt::operandst &instructions) -{ - program_individualt::programt converted(instructions.size()); - std::transform(instructions.begin(), instructions.end(), converted.begin(), - [](const exprt &instruction) - { return to_program_individual_instruction(to_struct_expr(instruction));}); - extract_program(prog, st, instr_set, vars, rvars, converted); -} - -size_t create_temps(invariant_variable_namest &rnames, const size_t num_tmp) -{ - for(size_t i=0; i < num_tmp; ++i) - rnames.insert(std::make_pair(i, get_cegis_meta_name(get_tmp(i)))); - return num_tmp; -} - -void set_result_var(invariant_variable_namest &result_var_names, - const size_t var_idx, const size_t loop_idx) -{ - result_var_names.erase(var_idx); - const std::string result_name(get_cegis_meta_name(get_Ix(loop_idx))); - result_var_names.insert(std::make_pair(var_idx, result_name)); -} -} - -void create_safety_solution(safety_goto_solutiont &solution, - const safety_programt &prog, const goto_tracet &trace, - const operand_variable_idst &var_ids, const size_t max_sz) -{ - solution.clear(); - const goto_programt &execute_body=get_execute_body(prog.gf); - const instruction_sett instr_set(extract_instruction_set(execute_body)); - invariant_variable_namest var_names; - reverse_invariant_var_ids(var_names, var_ids); - invariant_variable_namest result_var_names; - assert(max_sz > 0); - const size_t idx=create_temps(result_var_names, max_sz - 1); - size_t loop_idx=0; - for(const goto_trace_stept &step : trace.steps) - { - if(!is_program_individual_decl(step)) continue; - const exprt::operandst &instrs=step.full_lhs_value.operands(); - set_result_var(result_var_names, idx, loop_idx++); - solution.push_back(goto_programt::instructionst()); - extract_program(solution.back(), prog.st, instr_set, var_names, - result_var_names, instrs); - } -} - -namespace -{ -void create_safety_solution(safety_goto_solutiont &solution, - const symbol_tablet &st, const goto_functionst &gf, - const program_individualt &ind, const operand_variable_idst &var_ids, - const instruction_sett &instr_set) -{ - solution.clear(); - invariant_variable_namest vars; - reverse_invariant_var_ids(vars, var_ids); - size_t loop_idx=0; - for(const program_individualt::programt &instrs : ind.programs) - { - invariant_variable_namest rvars; - const size_t prog_size=instrs.size(); - const size_t idx=prog_size > 0 ? create_temps(rvars, prog_size - 1) : 0; - set_result_var(rvars, idx, loop_idx++); - solution.push_back(goto_programt::instructionst()); - extract_program(solution.back(), st, instr_set, vars, rvars, instrs); - } -} -} - -void create_safety_solution(safety_goto_solutiont &solution, - const symbol_tablet &st, const goto_functionst &gf, - const program_individualt &ind, const operand_variable_idst &var_ids) -{ - const goto_programt &execute_body=get_execute_body(gf); - const instruction_sett instr_set(extract_instruction_set(execute_body)); - create_safety_solution(solution, st, gf, ind, var_ids, instr_set); -} - -void create_safety_solution(safety_goto_solutiont &solution, - const symbol_tablet &st, const goto_functionst &gf, - const program_individualt &ind, const operand_variable_idst &var_ids, - instruction_set_info_factoryt &info_fac) -{ - const instruction_sett &instr_set=info_fac.get_instructions(); - create_safety_solution(solution, st, gf, ind, var_ids, instr_set); -} diff --git a/src/cegis/safety/symex/learn/solution_factory.h b/src/cegis/safety/symex/learn/solution_factory.h deleted file mode 100644 index a3b52e5cf76..00000000000 --- a/src/cegis/safety/symex/learn/solution_factory.h +++ /dev/null @@ -1,66 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SOLUTION_FACTORY_H -#define CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SOLUTION_FACTORY_H - -#include - -typedef std::map operand_variable_idst; - -/** - * @brief - * - * @details - * - * @param solution - * @param prog - * @param trace - * @param var_ids - * @param max_solution_size - */ -void create_safety_solution(safety_goto_solutiont &solution, - const class safety_programt &prog, const class goto_tracet &trace, - const operand_variable_idst &var_ids, size_t max_solution_size); - -/** - * @brief - * - * @details - * - * @param solution - * @param st - * @param gf - * @param ind - * @param var_ids - */ -void create_safety_solution(safety_goto_solutiont &solution, - const symbol_tablet &st, const class goto_functionst &gf, - const class program_individualt &ind, - const operand_variable_idst &var_ids); - -/** - * @brief - * - * @details - * - * @param solution - * @param st - * @param gf - * @param ind - * @param var_ids - * @param info_fac - */ -void create_safety_solution(safety_goto_solutiont &solution, - const symbol_tablet &st, const class goto_functionst &gf, - const program_individualt &ind, - const operand_variable_idst &var_ids, - class instruction_set_info_factoryt &info_fac); - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_LEARN_SOLUTION_FACTORY_H diff --git a/src/cegis/safety/symex/verify/insert_candidate.cpp b/src/cegis/safety/symex/verify/insert_candidate.cpp deleted file mode 100644 index 3d9c2da2856..00000000000 --- a/src/cegis/safety/symex/verify/insert_candidate.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -void safety_insert_candidate(safety_programt &program, - const safety_goto_solutiont &candidate) -{ - if(candidate.empty()) return; - const safety_programt::safety_loopst &loops=program.safety_loops; - const size_t size=loops.size(); - assert(size == candidate.size()); - goto_programt &body=get_entry_body(program.gf); - const std::string Ix_0(get_cegis_meta_name(get_Ix(0))); - const std::string Ix0(get_cegis_meta_name(get_Ix0())); - insert_program(body, program.Ix0, candidate.front(), Ix_0, Ix0); - for(size_t i=0; i < size; ++i) - { - const invariant_programt::invariant_loopt &loop=loops[i]; - const goto_programt::instructionst &prog=candidate[i]; - const invariant_programt::meta_vars_positionst &meta=loop.meta_variables; - insert_program(body, meta.Ix, prog); - const std::string Ix(get_cegis_meta_name(get_Ix(i))); - const std::string Ix_prime(get_cegis_meta_name(get_Ix_prime(i))); - insert_program(body, meta.Ix_prime, prog, Ix, Ix_prime); - } -} diff --git a/src/cegis/safety/symex/verify/insert_candidate.h b/src/cegis/safety/symex/verify/insert_candidate.h deleted file mode 100644 index b1723872c65..00000000000 --- a/src/cegis/safety/symex/verify/insert_candidate.h +++ /dev/null @@ -1,26 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_INSERT_CANDIDATE_H -#define CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_INSERT_CANDIDATE_H - -#include - -/** - * @brief - * - * @details - * - * @param program - * @param canddiate - */ -void safety_insert_candidate(class safety_programt &program, - const safety_goto_solutiont &candidate); - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_INSERT_CANDIDATE_H diff --git a/src/cegis/safety/symex/verify/safety_verify_config.cpp b/src/cegis/safety/symex/verify/safety_verify_config.cpp deleted file mode 100644 index 389baf71e0f..00000000000 --- a/src/cegis/safety/symex/verify/safety_verify_config.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -safety_verify_configt::safety_verify_configt(const safety_programt &prog) : - original_program(prog) -{ -} - -safety_verify_configt::~safety_verify_configt() -{ -} - -void safety_verify_configt::process(const candidatet &candidate) -{ - program=original_program; - quantifiers.clear(); - const safety_programt &prog=program; - const invariant_programt::const_invariant_loopst loops(prog.get_loops()); - assert(!loops.empty()); - const size_t offset( - program.x0_choices.size() + loops.front()->skolem_choices.size()); - invariant_insert_constraint(quantifiers, program, create_safety_constraint, - offset); - safety_insert_candidate(program, candidate); - program.gf.update(); -} - -const symbol_tablet &safety_verify_configt::get_symbol_table() const -{ - return program.st; -} - -const goto_functionst &safety_verify_configt::get_goto_functions() const -{ - return program.gf; -} - -void safety_verify_configt::convert(counterexamplest &counterexamples, - const goto_tracet &trace) -{ - counterexamples.push_back(counterexamplet()); - counterexamplet &new_ce=counterexamples.back(); - invariant_extract_counterexample(new_ce.x0, trace, program.x0_choices); - counterexamplet::assignments_per_loopt &x=new_ce.x; - // TODO: Implement for multiple loops (change constraint, instrumentation) - x.push_back(counterexamplet::assignmentst()); - counterexamplet::assignmentst &ass=x.back(); - ass.clear(); - invariant_extract_counterexample(ass, trace, quantifiers); - const safety_programt &prog=program; - const invariant_programt::const_invariant_loopst loops(prog.get_loops()); - assert(!loops.empty()); - // TODO: Implement for multiple loops (change constraint, instrumentation) - invariant_extract_counterexample(ass, trace, loops.front()->skolem_choices); -} - -void safety_verify_configt::show_counterexample(messaget::mstreamt &os, - const counterexamplet &counterexample) const -{ - os << "" << messaget::endl; - os << " " << messaget::endl; - const symbol_tablet &st=get_symbol_table(); - print_assignments(os, st, counterexample.x0); - os << " " << messaget::endl; - os << " " << messaget::endl; - for(const counterexamplet::assignments_per_loopt::value_type &loop : counterexample.x) - { - os << " " << messaget::endl; - print_assignments(os, st, loop); - os << " " << messaget::endl; - } - os << " " << messaget::endl; - os << "" << messaget::endl << messaget::eom; -} diff --git a/src/cegis/safety/symex/verify/safety_verify_config.h b/src/cegis/safety/symex/verify/safety_verify_config.h deleted file mode 100644 index 3bc7d5bab32..00000000000 --- a/src/cegis/safety/symex/verify/safety_verify_config.h +++ /dev/null @@ -1,113 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_SAFETY_VERIFY_CONFIG_H -#define CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_SAFETY_VERIFY_CONFIG_H - -#include - -#include - -#include -#include - -/** - * @brief - * - * @details - */ -class safety_verify_configt -{ - const safety_programt &original_program; - safety_programt program; - goto_programt::targetst quantifiers; -public: - /** - * @brief Counterexample type for this CEGIS component. - * - * @details Counterexamples give a set of values used for the state variables. - */ - typedef class safety_goto_cet counterexamplet; - typedef std::deque counterexamplest; - - /** - * @brief Candidate solution type for this CEGIS component. - * - * @details Solutions are provided as a set of GOTO function bodies - * (goto_programt::instructionst) for function names. - */ - typedef safety_goto_solutiont candidatet; - - /** - * @brief - * - * @details - * - * @param program - */ - explicit safety_verify_configt(const safety_programt &program); - - /** - * @brief - * - * @details - */ - ~safety_verify_configt(); - - /** - * @brief - * - * @details - * - * @param candidate - */ - void process(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const symbol_tablet &get_symbol_table() const; - - /** - * @brief - * - * @details - * - * @return - */ - const goto_functionst &get_goto_functions() const; - - /** - * @brief - * - * @details - * - * @param counterexamples - * @param trace - */ - void convert(counterexamplest &counterexamples, - const class goto_tracet &trace); - - /** - * @brief - * - * @details - * - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#endif // CPROVER_CEGIS_SAFETY_SYMEX_VERIFY_SAFETY_VERIFY_CONFIG_H diff --git a/src/cegis/safety/value/individual_to_safety_solution_deserialiser.cpp b/src/cegis/safety/value/individual_to_safety_solution_deserialiser.cpp deleted file mode 100644 index 2cddeea2621..00000000000 --- a/src/cegis/safety/value/individual_to_safety_solution_deserialiser.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include - -individual_to_safety_solution_deserialisert::individual_to_safety_solution_deserialisert( - const safety_programt &prog, instruction_set_info_factoryt &info_fac) : - prog(prog), info_fac(info_fac) -{ -} - -void individual_to_safety_solution_deserialisert::operator()( - safety_goto_solutiont &result, const irept &sdu) const -{ - program_individualt ind; - deserialise(ind, sdu); - operand_variable_idst ids; - const symbol_tablet &st=prog.st; - get_invariant_variable_ids(st, ids); - create_safety_solution(result, st, prog.gf, ind, ids, info_fac); -} diff --git a/src/cegis/safety/value/individual_to_safety_solution_deserialiser.h b/src/cegis/safety/value/individual_to_safety_solution_deserialiser.h deleted file mode 100644 index 5e4dce7ecee..00000000000 --- a/src/cegis/safety/value/individual_to_safety_solution_deserialiser.h +++ /dev/null @@ -1,49 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_VALUE_INDIVIDUAL_TO_SAFETY_SOLUTION_DESERIALISER_H -#define CPROVER_CEGIS_SAFETY_VALUE_INDIVIDUAL_TO_SAFETY_SOLUTION_DESERIALISER_H - -#include - -#include - -/** - * @brief - * - * @details - */ -class individual_to_safety_solution_deserialisert -{ - const class safety_programt &prog; - class instruction_set_info_factoryt &info_fac; -public: - /** - * @brief - * - * @details - * - * @param prog - * @param inf_fac - */ - individual_to_safety_solution_deserialisert(const safety_programt &prog, - instruction_set_info_factoryt &info_fac); - - /** - * @brief - * - * @details - * - * @param entity - * @param sdu - */ - void operator()(safety_goto_solutiont &entity, const irept &sdu) const; -}; - -#endif // CPROVER_CEGIS_SAFETY_VALUE_INDIVIDUAL_TO_SAFETY_SOLUTION_DESERIALISER_H diff --git a/src/cegis/safety/value/safety_goto_ce.cpp b/src/cegis/safety/value/safety_goto_ce.cpp deleted file mode 100644 index d97153cfeec..00000000000 --- a/src/cegis/safety/value/safety_goto_ce.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -bool safety_goto_cet::operator ==(const safety_goto_cet &other) const -{ - return x0 == other.x0 && x == other.x; -} diff --git a/src/cegis/safety/value/safety_goto_ce.h b/src/cegis/safety/value/safety_goto_ce.h deleted file mode 100644 index 6fc139b2346..00000000000 --- a/src/cegis/safety/value/safety_goto_ce.h +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_CE_H -#define CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_CE_H - -#include - -/** - * @brief - * - * @details - */ -class safety_goto_cet -{ -public: - typedef std::map assignmentst; - typedef std::vector assignments_per_loopt; - - /** - * @brief x0 assignment. - * - * @details Initial assignment. Indicates that I(x) => S(x) doesn't hold. - */ - assignmentst x0; - - /** - * @brief x assignments. - * - * @details Assignments for each loop constraint. Indicates that - * \forall_x (Si(x) && G(x) => Si'(x)) && (Si(x) && -G(x) => A(x)) - * doesn't hold. - */ - assignments_per_loopt x; - - /** - * @brief - * - * @details - * - * @param other - * @return - */ - bool operator==(const safety_goto_cet &other) const; -}; - -#endif // CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_CE_H diff --git a/src/cegis/safety/value/safety_goto_solution.h b/src/cegis/safety/value/safety_goto_solution.h deleted file mode 100644 index b6ef8734e96..00000000000 --- a/src/cegis/safety/value/safety_goto_solution.h +++ /dev/null @@ -1,17 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_SOLUTION_H -#define CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_SOLUTION_H - -#include - -typedef std::vector safety_goto_solutiont; - -#endif // CPROVER_CEGIS_SAFETY_VALUE_SAFETY_GOTO_SOLUTION_H diff --git a/src/cegis/seed/literals_seed.cpp b/src/cegis/seed/literals_seed.cpp deleted file mode 100644 index d83c7c7c2e7..00000000000 --- a/src/cegis/seed/literals_seed.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -#include -#include -#include -#include - -danger_literals_seedt::danger_literals_seedt(const danger_programt &prog) : - prog(prog), seeded(false) -{ -} - -danger_literals_seedt::~danger_literals_seedt() -{ -} - -namespace -{ -class is_same_symbolt -{ - const irep_idt &name; -public: - explicit is_same_symbolt(const irep_idt &name) : - name(name) - { - } - - bool operator()(const exprt &expr) const - { - if(ID_symbol != expr.id()) return false; - return name == to_symbol_expr(expr).get_identifier(); - } -}; - -typedef std::set keyst; -typedef std::deque valuest; - -class add_symbolt -{ - keyst &keys; -public: - explicit add_symbolt(keyst &keys) : - keys(keys) - { - } - - void operator()(const exprt &expr) const - { - if(ID_symbol != expr.id()) return; - keys.insert(to_symbol_expr(expr).get_identifier()); - } -}; - -class compare_literalt -{ - const constant_exprt &literal; -public: - explicit compare_literalt(const constant_exprt &literal) : - literal(literal) - { - } - - bool operator()(const constant_exprt &expr) const - { - return literal.get_value() == expr.get_value(); - } -}; - -class add_literalt -{ - valuest &values; -public: - explicit add_literalt(valuest &values) : - values(values) - { - } - - void operator()(const exprt &expr) const - { - if(ID_constant != expr.id()) return; - const constant_exprt &new_literal=to_constant_expr(expr); - const compare_literalt compare(new_literal); - if(values.end() != std::find_if(values.begin(), values.end(), compare)) - return; - values.push_back(new_literal); - } -}; - -class init_pool_keyst: public const_expr_visitort -{ - keyst &keys; - const irep_idt &var; -public: - init_pool_keyst(keyst &keys, const irep_idt &var) : - keys(keys), var(var) - { - } - - virtual ~init_pool_keyst() - { - } - - virtual void operator()(const exprt &expr) - { - exprt::operandst ops(expr.operands()); - if(ops.size() < 2u) return; - const is_same_symbolt pred(var); - if(ops.end() == std::find_if(ops.begin(), ops.end(), pred)) return; - const add_symbolt add(keys); - std::for_each(ops.begin(), ops.end(), add); - } - - void operator()(const goto_programt::instructiont &instr) - { - const_expr_visitort &visitor=*this; - instr.guard.visit(visitor); - instr.code.visit(visitor); - } -}; - -typedef std::map pool_storaget; - -pool_storaget::const_iterator find(const pool_storaget &pool, - const irep_idt &id) -{ - for(pool_storaget::const_iterator it=pool.begin(); it != pool.end(); ++it) - { - const keyst &keys=it->first; - if(std::find(keys.begin(), keys.end(), id) == keys.end()) continue; - return it; - } - return pool.end(); -} - -class create_pool_keyst -{ - const danger_programt &prog; - pool_storaget &pool; -public: - create_pool_keyst(const danger_programt &prog, pool_storaget &pool) : - prog(prog), pool(pool) - { - } - - void operator()(const symbol_exprt &var) - { - const irep_idt &id=var.get_identifier(); - pool_storaget::const_iterator it=find(pool, id); - if(pool.end() != it) return; - keyst newKey; - newKey.insert(id); - const init_pool_keyst add(newKey, id); - const goto_programt &body=get_entry_body(prog.gf); - const goto_programt::instructionst &instrs=body.instructions; - std::for_each(instrs.begin(), instrs.end(), add); - it=pool.insert(std::make_pair(newKey, valuest())).first; - } -}; - -const keyst &get_first(const std::pair &pair) -{ - return pair.first; -} - -class is_keyt -{ - const exprt::operandst &ops; -public: - explicit is_keyt(const exprt::operandst &ops) : - ops(ops) - { - } - - bool operator()(const irep_idt &key) const - { - for(exprt::operandst::const_iterator it=ops.begin(); ops.end() != it; ++it) - { - const exprt &op=*it; - if(ID_symbol != op.id()) continue; - if(key == to_symbol_expr(op).get_identifier()) return true; - } - return false; - } - - bool operator()(const keyst &keys) const - { - return keys.end() != std::find_if(keys.begin(), keys.end(), *this); - } -}; - -std::deque::const_iterator find_key(const std::deque &keys, - const exprt::operandst &ops) -{ - const is_keyt is_key(ops); - return std::find_if(keys.begin(), keys.end(), is_key); -} - -class scrape_literalst: public const_expr_visitort -{ - std::deque keys; - pool_storaget &pool; -public: - explicit scrape_literalst(pool_storaget &p) : - pool(p) - { - std::transform(p.begin(), p.end(), std::back_inserter(keys), &get_first); - } - - virtual ~scrape_literalst() - { - } - - virtual void operator()(const exprt &expr) - { - const exprt::operandst &ops=expr.operands(); - if(ops.size() < 2u) return; - std::deque::const_iterator it=find_key(keys, ops); - if(keys.end() == it) return; - const add_literalt add(pool[*it]); - std::for_each(ops.begin(), ops.end(), add); - } - - void operator()(const goto_programt::instructiont &instr) - { - const_expr_visitort &visitor=*this; - instr.code.visit(visitor); - instr.guard.visit(visitor); - } -}; - -class value_poolt -{ - const constraint_varst &vs; - pool_storaget pool; -public: - value_poolt(const danger_programt &prog, const constraint_varst &vars) : - vs(vars) - { - const create_pool_keyst create_keys(prog, pool); - std::for_each(vars.begin(), vars.end(), create_keys); - const goto_programt &body=get_entry_body(prog.gf); - const goto_programt::instructionst &instr=body.instructions; - const scrape_literalst scrape(pool); - std::for_each(instr.begin(), instr.end(), scrape); - } - - const valuest &operator[](const irep_idt &id) const - { - pool_storaget::const_iterator it=find(pool, id); - assert(pool.end() != it); - return it->second; - } - - size_t size() const - { - size_t size=0; - for(pool_storaget::const_iterator it=pool.begin(); it != pool.end(); ++it) - size=std::max(size, it->second.size()); - return size; - } - - valuest::value_type get_value(const irep_idt &id, const typet &type, - const size_t index) const - { - const valuest &values=operator[](id); - if(values.empty()) - return from_integer(0, type); - return values.at(index % values.size()); - } - - void seed(danger_verify_configt::counterexamplest &counterexamples) const - { - const size_t sz=size(); - for(size_t i=0; i < sz; ++i) - { - danger_verify_configt::counterexamplet ce; - for(constraint_varst::const_iterator v=vs.begin(); v != vs.end(); ++v) - { - const irep_idt &id=v->get_identifier(); - const typet &type=v->type(); - ce.insert(std::make_pair(id, get_value(id, type, i))); - } - counterexamples.push_back(ce); - } - } -}; -} - -void danger_literals_seedt::operator()( - danger_verify_configt::counterexamplest &counterexamples) -{ - if(seeded) return; - constraint_varst vars; - get_invariant_constraint_vars(vars, prog); - const value_poolt pool(prog, vars); - pool.seed(counterexamples); - seeded=true; -} diff --git a/src/cegis/seed/literals_seed.h b/src/cegis/seed/literals_seed.h deleted file mode 100644 index df57f12d1f8..00000000000 --- a/src/cegis/seed/literals_seed.h +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SEED_LITERALS_SEED_H -#define CPROVER_CEGIS_SEED_LITERALS_SEED_H - -#include - -/** - * @brief - * - * @details - */ -class danger_literals_seedt -{ - const danger_programt &prog; - bool seeded; -public: - /** - * @brief - * - * @details - * - * @param prog - */ - explicit danger_literals_seedt(const danger_programt &prog); - - /** - * @brief - * - * @details - */ - ~danger_literals_seedt(); - - /** - * @brief - * - * @details - * - * @param ces - */ - void operator()(danger_verify_configt::counterexamplest &ces); -}; - -#endif // CPROVER_CEGIS_SEED_LITERALS_SEED_H diff --git a/src/cegis/seed/null_seed.h b/src/cegis/seed/null_seed.h deleted file mode 100644 index a9d07acfdf5..00000000000 --- a/src/cegis/seed/null_seed.h +++ /dev/null @@ -1,37 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SEED_NULL_SEED_H -#define CPROVER_CEGIS_SEED_NULL_SEED_H - -#include - -/** - * @brief - * - * @details - */ -class null_seedt -{ -public: - /** - * @brief - * - * @details - * - * @param ces - * @tparam ces - */ - template - void operator()(cest &ces) const; -}; - -#include "null_seed.inc" - -#endif // CPROVER_CEGIS_SEED_NULL_SEED_H diff --git a/src/cegis/seed/null_seed.inc b/src/cegis/seed/null_seed.inc deleted file mode 100644 index 36a7d8995a7..00000000000 --- a/src/cegis/seed/null_seed.inc +++ /dev/null @@ -1,4 +0,0 @@ -template -void null_seedt::operator()(cest &ces) const -{ -} diff --git a/src/cegis/statistics/cegis_statistics_wrapper.h b/src/cegis/statistics/cegis_statistics_wrapper.h deleted file mode 100644 index 6100c243a80..00000000000 --- a/src/cegis/statistics/cegis_statistics_wrapper.h +++ /dev/null @@ -1,87 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_STATISTICS_CEGIS_STATISTICS_WRAPPER_H -#define CPROVER_CEGIS_STATISTICS_CEGIS_STATISTICS_WRAPPER_H - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class cegis_statistics_wrappert -{ - learnt &learner; - verifyt &verifier; - mstreamt &os; - size_t num_ces; - typedef std::chrono::milliseconds millisecondst; - millisecondst learner_time; - millisecondst verifier_time; - std::chrono::high_resolution_clock::time_point start_time; - const bool show_iterations; -public: - typedef typename learnt::counterexamplet counterexamplet; - typedef typename learnt::candidatet candidatet; - typedef typename verifyt::const_iterator const_iterator; - - /** - * @brief - * - * @details - * - * @param learner - * @param verifier - * @param os - * @param options - */ - cegis_statistics_wrappert( - learnt &learner, - verifyt &verifier, - mstreamt &os, - const optionst &options); - - /** - * @brief - * - * @details - */ - ~cegis_statistics_wrappert(); - - template - void seed(seedt &seed); - - const candidatet &next_candidate() const; - - template - bool learn(itert first, const itert &last); - - void show_candidate(messaget::mstreamt &os) const; - - void verify(const candidatet &candidate); - - const_iterator counterexamples_begin() const; - - const_iterator counterexamples_end() const; - - bool has_counterexamples() const; - - bool success() const; - - void set_solution_size_range(size_t min, size_t max); -}; - -#include "cegis_statistics_wrapper.inc" - -#endif // CPROVER_CEGIS_STATISTICS_CEGIS_STATISTICS_WRAPPER_H diff --git a/src/cegis/statistics/cegis_statistics_wrapper.inc b/src/cegis/statistics/cegis_statistics_wrapper.inc deleted file mode 100644 index 04056947268..00000000000 --- a/src/cegis/statistics/cegis_statistics_wrapper.inc +++ /dev/null @@ -1,126 +0,0 @@ -#include - -#include - -typedef std::chrono::high_resolution_clock my_clockt; - -template -cegis_statistics_wrappert::cegis_statistics_wrappert( - learnt &learner, verifyt &verifier, mstreamt &os, const optionst &options) : - learner(learner), verifier(verifier), os(os), num_ces(0), learner_time(0), verifier_time( - 0), start_time(my_clockt::now()), show_iterations( - options.get_bool_option(CEGIS_SHOW_ITERATIONS)) -{ -} - -template -cegis_statistics_wrappert::~cegis_statistics_wrappert() -{ -} - -template -template -void cegis_statistics_wrappert::seed(seedt &seed) -{ - learner.seed(seed); -} - -template -const typename cegis_statistics_wrappert::candidatet &cegis_statistics_wrappert< - learnt, verifyt, mstreamt>::next_candidate() const -{ - return learner.next_candidate(); -} - -typedef my_clockt::time_point my_time_pointt; - -template -template -bool cegis_statistics_wrappert::learn(itert first, - const itert &last) -{ - num_ces+=std::distance(first, last); - my_time_pointt before=my_clockt::now(); - const bool result=learner.learn(first, last); - my_time_pointt after=my_clockt::now(); - learner_time+=std::chrono::duration_cast(after - before); - return result; -} - -template -void cegis_statistics_wrappert::show_candidate( - messaget::mstreamt &os) const -{ - os << "" << messaget::endl; - os << " " << num_ces << "" << messaget::endl; - os << " " << learner_time.count() << "" - << messaget::endl; - os << " " << verifier_time.count() << "" - << messaget::endl; - const my_time_pointt now=my_clockt::now(); - const millisecondst full_time( - std::chrono::duration_cast < millisecondst > (now - start_time)); - os << " " << full_time.count() << "" - << messaget::endl; - os << " " << messaget::endl; - learner.show_candidate(os); - os << " " << messaget::endl; - os << "" << messaget::eom; -} - -template -void cegis_statistics_wrappert::verify( - const candidatet &candidate) -{ - my_time_pointt before=my_clockt::now(); - verifier.verify(candidate); - my_time_pointt after=my_clockt::now(); - verifier_time+=std::chrono::duration_cast < millisecondst > (after - before); - if (show_iterations) - { - os << "" << messaget::endl; - const const_iterator last=counterexamples_end(); - for (const_iterator it=counterexamples_begin(); it != last; ++it) - { - os << "" << messaget::endl; - verifier.show_counterexample(os, *it); - os << "" << messaget::endl; - } - os << "" << messaget::endl; - show_candidate(os); - os << messaget::eom; - } -} - -template -typename cegis_statistics_wrappert::const_iterator cegis_statistics_wrappert< - learnt, verifyt, mstreamt>::counterexamples_begin() const -{ - return verifier.counterexamples_begin(); -} - -template -typename cegis_statistics_wrappert::const_iterator cegis_statistics_wrappert< - learnt, verifyt, mstreamt>::counterexamples_end() const -{ - return verifier.counterexamples_end(); -} - -template -bool cegis_statistics_wrappert::has_counterexamples() const -{ - return verifier.has_counterexamples(); -} - -template -bool cegis_statistics_wrappert::success() const -{ - return verifier.success(); -} - -template -void cegis_statistics_wrappert::set_solution_size_range( - const size_t min, const size_t max) -{ - learner.set_solution_size_range(min, max); -} diff --git a/src/cegis/symex/cegis_symex_learn.h b/src/cegis/symex/cegis_symex_learn.h deleted file mode 100644 index a8f5b0c1bb8..00000000000 --- a/src/cegis/symex/cegis_symex_learn.h +++ /dev/null @@ -1,141 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_LEARN_H -#define CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_LEARN_H - -#include - -#include - -/** - * @brief - * - * @details - */ -template -class cegis_symex_learnt -{ -public: - typedef typename learn_configurationt::candidatet candidatet; - typedef typename learn_configurationt::counterexamplet counterexamplet; - typedef typename learn_configurationt::counterexamplest counterexamplest; -private: - const class optionst &options; - preproct &preproc; - learn_configurationt &config; - size_t word_width; - size_t current_solution_size; - size_t max_solution_size; - candidatet current_candidate; - const std::function default_candidate; - counterexamplest counterexamples; - - safety_checkert::resultt run_bmc(); - bool learn_at_current_size(); -public: - /** - * @brief - * - * @details - * - * @param options - * @param preproc - * @param config - */ - cegis_symex_learnt( - const optionst &options, - preproct &preproc, - learn_configurationt &config); - - /** - * @brief - * - * @details - * - * @param options - * @param preproc - * @param config - * @param default_candidate - */ - cegis_symex_learnt( - const optionst &options, - preproct &preproc, - learn_configurationt &config, - const std::function &default_candidate); - - /** - * @brief - * - * @details - * - * @param seed - */ - template - void seed(seedt &seed); - - /** - * @brief Provides the next candidate. - * - * @details Provides the last candidate generated using learn. - * - * @return The next candidate. - */ - const candidatet &next_candidate(); - - /** - * @brief Generates a candidate solution. - * - * @details Receives set of counterexample from the verification oracle - * and adds it to its information base. Generates a new candidate - * based on received counterexamples. - * - * @param first The first iterator of the counterexample set. - * @param last The last iterator of the counterexample set. - * - * @return true if learning was successful, false - * if no new candidate could be generated. - */ - template - bool learn(itert first, const itert &last); - - /** - * @brief Adds explicit counterexamples. - * - * @details Adds counterexamples to the learner without starting a new learn round. - * - * @param first The first iterator of the counterexample set. - * @param last The last iterator of the counterexample set. - */ - template - void add_counterexamples(itert first, const itert &last); - - /** - * @brief Displays the last candidate. - * - * @details Prints the last candidate generated using learn. - * - * @param os The stream to output the candidate. - */ - void show_candidate(messaget::mstreamt &os) const; - - /** - * @brief - * - * @details - * - * @param min - * @param max - */ - void set_solution_size_range(size_t min, size_t max); -}; - -#include "cegis_symex_learn.inc" - -#endif // CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_LEARN_H diff --git a/src/cegis/symex/cegis_symex_learn.inc b/src/cegis/symex/cegis_symex_learn.inc deleted file mode 100644 index 40cc5ecb96d..00000000000 --- a/src/cegis/symex/cegis_symex_learn.inc +++ /dev/null @@ -1,147 +0,0 @@ -#include - -#include - -#include -#include - -#define CONSTANT_WIDTH_OPTION "max-constant-width" -#define CEGIS_DEFAULT_MIN_WORD_WIDTH 4u - -template -cegis_symex_learnt::cegis_symex_learnt( - const optionst &options, preproct &preproc, learn_configurationt &config) : - options(options), preproc(preproc), config(config), word_width( - CEGIS_DEFAULT_MIN_WORD_WIDTH), current_solution_size(1u), max_solution_size( - current_solution_size) -{ -} - -template -cegis_symex_learnt::cegis_symex_learnt( - const optionst &options, preproct &preproc, learn_configurationt &config, - const std::function &default_candidate) : - options(options), preproc(preproc), config(config), word_width( - CEGIS_DEFAULT_MIN_WORD_WIDTH), current_solution_size(1u), max_solution_size( - current_solution_size), default_candidate(default_candidate) -{ -} - -template -template -void cegis_symex_learnt::seed(seedt &seed) -{ - seed(counterexamples); -} - -template -const typename cegis_symex_learnt::candidatet &cegis_symex_learnt< - preproct, learn_configurationt>::next_candidate() -{ - if (default_candidate) - default_candidate(current_candidate); - return current_candidate; -} - -template -safety_checkert::resultt cegis_symex_learnt::run_bmc() -{ - const symbol_tablet &st=config.get_symbol_table(); - const goto_functionst &gf=config.get_goto_functions(); - cbmc_resultt result; - const safety_checkert::resultt bmc_result=run_cbmc(st, gf, result, options); - if (safety_checkert::UNSAFE != bmc_result) return bmc_result; - config.process(counterexamples, current_solution_size); - config.convert(current_candidate, result.trace, current_solution_size); - return safety_checkert::UNSAFE; -} - -namespace -{ -// TODO: Detect automatically -#define FULL_WIDTH 32u -#define CEGIS_LIMIT_WORDSIZE "cegis-limit-wordsize" -#define WIDTH_OPT "cegis-word-width" - -size_t calculate_word_width(const optionst &options) -{ - if (!options.get_bool_option(CEGIS_LIMIT_WORDSIZE)) return FULL_WIDTH; - return options.get_unsigned_int_option(WIDTH_OPT); -} -} - -template -bool cegis_symex_learnt::learn_at_current_size() -{ - word_width=calculate_word_width(options); - const symbol_tablet &st=config.get_symbol_table(); - const goto_functionst &gf=config.get_goto_functions(); - safety_checkert::resultt full_width_result=safety_checkert::ERROR; - cbmc_resultt full_width_cbmc_result; - for (; word_width < FULL_WIDTH; word_width*=2) - { - config.process(counterexamples, current_solution_size); - config.set_word_width(word_width); - const safety_checkert::resultt limited_result=run_bmc(); - if (safety_checkert::UNSAFE == limited_result) return true; - if (safety_checkert::ERROR == limited_result) return false; - if (safety_checkert::ERROR == full_width_result) - { - config.process(counterexamples, current_solution_size); - full_width_result=run_cbmc(st, gf, full_width_cbmc_result, options); - if (safety_checkert::UNSAFE != full_width_result) return false; - } - } - config.process(counterexamples, current_solution_size); - if (safety_checkert::ERROR == full_width_result) full_width_result= - run_cbmc(st, gf, full_width_cbmc_result, options); - if (safety_checkert::UNSAFE != full_width_result) return false; - config.convert(current_candidate, full_width_cbmc_result.trace, current_solution_size); - return true; -} - -template -template -bool cegis_symex_learnt::learn(itert first, - const itert &last) -{ - add_counterexamples(first, last); - if (counterexamples.empty()) return true; - - for (; current_solution_size <= max_solution_size; ++current_solution_size) - { - preproc(current_solution_size); - if (learn_at_current_size()) return true; - } - return false; -} - -template -template -void cegis_symex_learnt::add_counterexamples( - itert first, const itert &last) -{ - counterexamplest &ces=counterexamples; - for (; first != last; ++first) - { - const counterexamplet &ce=*first; - assert(ces.end() == std::find(ces.begin(), ces.end(), ce)); - ces.push_back(ce); - } -} - -template -void cegis_symex_learnt::show_candidate( - messaget::mstreamt &os) const -{ - config.show_candidate(os, current_candidate); -} - -template -void cegis_symex_learnt::set_solution_size_range( - const size_t min, const size_t max) -{ - current_solution_size=std::max(current_solution_size, min); - current_solution_size=std::min(current_solution_size, max); - max_solution_size=max; -} diff --git a/src/cegis/symex/cegis_symex_verify.h b/src/cegis/symex/cegis_symex_verify.h deleted file mode 100644 index 7c862d7089f..00000000000 --- a/src/cegis/symex/cegis_symex_verify.h +++ /dev/null @@ -1,112 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_VERIFY_H -#define CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_VERIFY_H - -#include -#include - -/** - * @brief - * - * @details - */ -template -class cegis_symex_verifyt -{ -public: - typedef typename verify_configurationt::candidatet candidatet; - typedef typename verify_configurationt::counterexamplet counterexamplet; - typedef typename verify_configurationt::counterexamplest counterexamplest; - typedef typename counterexamplest::const_iterator const_iterator; -private: - const class optionst &options; - verify_configurationt &config; - counterexamplest current_counterexamples; - bool is_failure; -public: - /** - * @brief - * - * @details - * - * @param options - * @param config - */ - cegis_symex_verifyt(const optionst &options, verify_configurationt &config); - - /** - * @brief Default destructor. - * - * @details No cleanup tasks performed. - */ - ~cegis_symex_verifyt(); - - /** - * @brief Verifies a given candidate solution. - * - * @details Effectively invokes CBMC using the given function bodies. - * - * @param candidate The candidate implementation provided by the learner. - */ - void verify(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_begin() const; - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_end() const; - - /** - * @brief Indicates whether a counterexample could be produced. - * - * @details If the verification fails, but the oracle is unable to provide a - * counterexample, this marks an error in the CBMC execution. - * - * @return true if a counterexample was created, false otherwise. - */ - bool has_counterexamples() const; - - /** - * @brief Indicates whether the provided solution holds. - * - * @details Provides the result of the last "verify()" operation. - * - * @return true if the last solution holds, false otherwise. - */ - bool success() const; - - /** - * @brief - * - * @details - * - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#include "cegis_symex_verify.inc" - -#endif // CPROVER_CEGIS_SYMEX_CEGIS_SYMEX_VERIFY_H diff --git a/src/cegis/symex/cegis_symex_verify.inc b/src/cegis/symex/cegis_symex_verify.inc deleted file mode 100644 index a780e463814..00000000000 --- a/src/cegis/symex/cegis_symex_verify.inc +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - -template -cegis_symex_verifyt::cegis_symex_verifyt( - const optionst &options, verify_configurationt &config) : - options(options), config(config), is_failure(true) -{ -} - -template -cegis_symex_verifyt::~cegis_symex_verifyt() -{ -} - -safety_checkert::resultt run_cegis_symex(goto_tracet &trace, - const optionst &options, const class symbol_tablet &st, - const class goto_functionst &gf); - -template -void cegis_symex_verifyt::verify( - const candidatet &candidate) -{ - is_failure=true; - current_counterexamples.clear(); - config.process(candidate); - const symbol_tablet &st=config.get_symbol_table(); - const goto_functionst &gf=config.get_goto_functions(); - cbmc_resultt cbmc_result; - const safety_checkert::resultt result=run_cbmc(st, gf, cbmc_result, options); - switch (result) - { - case safety_checkert::SAFE: - is_failure=false; - case safety_checkert::ERROR: - return; - default: - config.convert(current_counterexamples, cbmc_result.trace); - } -} - -template -typename cegis_symex_verifyt::const_iterator cegis_symex_verifyt< - verify_configurationt>::counterexamples_begin() const -{ - return current_counterexamples.begin(); -} - -template -typename cegis_symex_verifyt::const_iterator cegis_symex_verifyt< - verify_configurationt>::counterexamples_end() const -{ - return current_counterexamples.end(); -} - -template -bool cegis_symex_verifyt::has_counterexamples() const -{ - return !current_counterexamples.empty(); -} - -template -bool cegis_symex_verifyt::success() const -{ - return !is_failure; -} - -template -void cegis_symex_verifyt::show_counterexample( - messaget::mstreamt &os, const counterexamplet &counterexample) const -{ - config.show_counterexample(os, counterexample); -} diff --git a/src/cegis/value/assignments_printer.cpp b/src/cegis/value/assignments_printer.cpp deleted file mode 100644 index 6c192728f28..00000000000 --- a/src/cegis/value/assignments_printer.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include - -void print_assignments(messaget::mstreamt &os, const symbol_tablet &st, - const std::map &assignments) -{ - const namespacet ns(st); - for(const std::map::value_type &assignment : assignments) - { - os << "" << messaget::endl; - os << " " << assignment.first << "" << messaget::endl; - os << " " << expr2c(assignment.second, ns) << "" << messaget::endl; - os << "" << messaget::endl; - } - os << messaget::eom; -} diff --git a/src/cegis/value/assignments_printer.h b/src/cegis/value/assignments_printer.h deleted file mode 100644 index eda5f2d849a..00000000000 --- a/src/cegis/value/assignments_printer.h +++ /dev/null @@ -1,30 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_VALUE_ASSIGNMENTS_PRINTER_H -#define CPROVER_CEGIS_VALUE_ASSIGNMENTS_PRINTER_H - -#include -#include - -/** - * @brief - * - * @details - * - * @param os - * @param st - * @param assignments - */ -void print_assignments( - messaget::mstreamt &os, - const class symbol_tablet &st, - const std::map &assignments); - -#endif // CPROVER_CEGIS_VALUE_ASSIGNMENTS_PRINTER_H diff --git a/src/cegis/value/program_individual.h b/src/cegis/value/program_individual.h deleted file mode 100644 index 1139cdafd0b..00000000000 --- a/src/cegis/value/program_individual.h +++ /dev/null @@ -1,67 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_H -#define CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_H - -#include -#include -#include - -#include - -/** - * @brief - * - * @details - */ -class program_individualt -{ -public: - /** - * @brief - * - * @details - */ - class instructiont - { - public: - typedef unsigned char opcodet; - typedef unsigned char opt; - typedef std::vector opst; - - opcodet opcode; - opst ops; - }; - - typedef std::vector programt; - typedef std::vector programst; - typedef std::vector x0t; - typedef size_t fitnesst; - - programst programs; - x0t x0; - fitnesst fitness; -}; - -/** - * @brief - * - * @details - */ -typedef std::vector program_populationt; - -/** - * @brief - * - * @details - */ -typedef family_selectiont program_individual_selectiont; - -#endif // CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_H diff --git a/src/cegis/value/program_individual_serialisation.cpp b/src/cegis/value/program_individual_serialisation.cpp deleted file mode 100644 index a9ecb4703a5..00000000000 --- a/src/cegis/value/program_individual_serialisation.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -bool is_program_individual_decl(const goto_trace_stept &step) -{ - if(goto_trace_stept::DECL != step.type) return false; - const exprt &value=step.full_lhs_value; - if(ID_array != value.id()) return false; - const typet &type=value.type().subtype(); - if(ID_struct != type.id()) return false; - const std::string &tname=id2string(to_struct_type(type).get_tag()); - const char * const danger_tag=CEGIS_INSTRUCTION_TYPE_NAME+4; - return std::string::npos != tname.find(danger_tag); -} - -namespace -{ -const program_individualt::instructiont::opt get_const_value(const exprt &expr) -{ - const bv_arithmetict bv(expr); - return static_cast(bv.to_integer().to_ulong()); -} -} - -program_individualt::instructiont to_program_individual_instruction( - const struct_exprt &instr_rep) -{ - program_individualt::instructiont result; - result.opcode=get_const_value(instr_rep.op0()); - result.ops.push_back(get_const_value(instr_rep.op1())); - result.ops.push_back(get_const_value(instr_rep.op2())); - result.ops.push_back(get_const_value(instr_rep.op3())); - return result; -} - -program_individualt to_program_individual(const invariant_programt &prog, - const goto_tracet &trace) -{ - program_individualt individual; - individual.fitness=0u; - for(const goto_trace_stept &step : trace.steps) - if(is_program_individual_decl(step)) - { - program_individualt::programt prog; - for(const exprt &op : step.full_lhs_value.operands()) - { - const struct_exprt &instr=to_struct_expr(op); - prog.push_back(to_program_individual_instruction(instr)); - } - individual.programs.push_back(prog); - } - return individual; -} - -program_individualt to_program_individual(const danger_programt &prog, - const goto_tracet &trace) -{ - const invariant_programt &inv_prog=prog; - program_individualt individual(to_program_individual(inv_prog, trace)); - const program_individualt::programt empty; - if(!prog.loops.empty() && prog.loops.front().skolem_choices.empty()) - { - const size_t num_progs=individual.programs.size(); - assert(num_progs == prog.use_ranking ? 2 : 1); - individual.programs.push_back(empty); - } - if(!prog.use_ranking) - { - assert(individual.programs.size() == 2); - individual.programs.insert(std::next(individual.programs.begin()), empty); - assert(individual.programs.at(1).empty()); - } - danger_read_x0(individual, prog, trace); - return individual; -} - -#define VALUE "value" - -irept singleton_irep(const long long int value) -{ - irept result; - result.set(VALUE, value); - return result; -} - -long long int get_value(const irept &singleton) -{ - return singleton.get_long_long(VALUE); -} - -#define PROGRAMS "programs" -#define OPCODE "opcode" -#define OPS "ops" -#define X0 "x0" -#define FITNESS "fitness" - -void serialise(irept &sdu, const program_individualt &individual) -{ - irept programs; - irept::subt &program_list=programs.get_sub(); - for(const program_individualt::programt &prog : individual.programs) - { - irept program; - irept::subt &instr_list=program.get_sub(); - for(const program_individualt::instructiont &instr : prog) - { - irept instruction; - instruction.set(OPCODE, instr.opcode); - irept ops; - irept::subt &ops_list=ops.get_sub(); - for(const program_individualt::instructiont::opt op : instr.ops) - ops_list.push_back(singleton_irep(op)); - instruction.set(OPS, ops); - instr_list.push_back(instruction); - } - program_list.push_back(program); - } - sdu.set(PROGRAMS, programs); - irept x0; - irept::subt &x0_list=x0.get_sub(); - for(const program_individualt::x0t::value_type value : individual.x0) - x0_list.push_back(singleton_irep(value)); - sdu.set(X0, x0); - sdu.set(FITNESS, individual.fitness); -} - -void deserialise(program_individualt &individual, const irept &sdu) -{ - const irept::named_subt &named_sub=sdu.get_named_sub(); - typedef irept::named_subt::const_iterator const_iterator; - const const_iterator programs=named_sub.find(PROGRAMS); - assert(named_sub.end() != programs); - for(const irept &program : programs->second.get_sub()) - { - program_individualt::programt prog; - for(const irept &instruction : program.get_sub()) - { - program_individualt::instructiont instr; - instr.opcode=instruction.get_long_long(OPCODE); - const irept::named_subt &named_sub=instruction.get_named_sub(); - const const_iterator ops=named_sub.find(OPS); - assert(named_sub.end() != ops); - for(const irept &op : ops->second.get_sub()) - instr.ops.push_back(get_value(op)); - prog.push_back(instr); - } - individual.programs.push_back(prog); - } - const irept::named_subt::const_iterator x0=named_sub.find(X0); - assert(named_sub.end() != x0); - for(const irept &value : x0->second.get_sub()) - individual.x0.push_back(get_value(value)); - individual.fitness=sdu.get_long_long(FITNESS); -} - -individual_to_danger_solution_deserialisert::individual_to_danger_solution_deserialisert( - const danger_programt &prog, instruction_set_info_factoryt &info_fac) : - prog(prog), info_fac(info_fac) -{ -} - -individual_to_danger_solution_deserialisert::~individual_to_danger_solution_deserialisert() -{ -} - -void individual_to_danger_solution_deserialisert::operator ()( - danger_goto_solutiont &result, const irept &sdu) const -{ - program_individualt ind; - deserialise(ind, sdu); - operand_variable_idst ids; - get_invariant_variable_ids(prog.st, ids); - const instruction_sett &instrs=info_fac.get_instructions(); - create_danger_solution(result, prog, ind, instrs, ids); -} diff --git a/src/cegis/value/program_individual_serialisation.h b/src/cegis/value/program_individual_serialisation.h deleted file mode 100644 index 83429992a2b..00000000000 --- a/src/cegis/value/program_individual_serialisation.h +++ /dev/null @@ -1,125 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_SERIALISATION_H -#define CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_SERIALISATION_H - -#include - -#include - -/** - * @brief - * - * @details - * - * @param step - * - * @return - */ -bool is_program_individual_decl(const class goto_trace_stept &step); - -/** - * @brief - * - * @details - * - * @param expr - * - * @return - */ -program_individualt::instructiont to_program_individual_instruction( - const struct_exprt &expr); - -/** - * @brief - * - * @details - * - * @param prog - * @param trace - * - * @return - */ -program_individualt to_program_individual(const class invariant_programt &prog, - const class goto_tracet &trace); - -/** - * @brief - * - * @details - * - * @param prog - * @param trace - * - * @return - */ -program_individualt to_program_individual(const class danger_programt &prog, - const goto_tracet &trace); - -/** - * @brief - * - * @details - * - * @param sdu - * @param individual - */ -void serialise(irept &sdu, const program_individualt &individual); - -/** - * @brief - * - * @details - * - * @param sdu - * @param individual - */ -void deserialise(program_individualt &individual, const irept &sdu); - -/** - * @brief Deserialises and converts an individual. - * - * @details Deserialises an individual and converts it to a goto solution. - */ -class individual_to_danger_solution_deserialisert -{ - const danger_programt &prog; - class instruction_set_info_factoryt &info_fac; -public: - /** - * @brief - * - * @details - * - * @param prog - * @param info_fac - */ - individual_to_danger_solution_deserialisert(const danger_programt &prog, - instruction_set_info_factoryt &info_fac); - - /** - * @brief - * - * @details - */ - ~individual_to_danger_solution_deserialisert(); - - /** - * @brief - * - * @details - * - * @param result - * @param sdu - */ - void operator()(class danger_goto_solutiont &result, const irept &sdu) const; -}; - -#endif // CPROVER_CEGIS_VALUE_PROGRAM_INDIVIDUAL_SERIALISATION_H diff --git a/src/cegis/wordsize/limited_wordsize_verify.h b/src/cegis/wordsize/limited_wordsize_verify.h deleted file mode 100644 index bc9c3e78b70..00000000000 --- a/src/cegis/wordsize/limited_wordsize_verify.h +++ /dev/null @@ -1,120 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_WORDSIZE_LIMITED_WORDSIZE_VERIFY_H -#define CPROVER_CEGIS_WORDSIZE_LIMITED_WORDSIZE_VERIFY_H - -#include -#include - -#include - -/** - * @brief - * - * @details - */ -template -class limited_wordsize_verifyt -{ - class optionst &options; - verifyt &verifier; - const std::function set_wordsize; - bool is_success; - size_t word_width; -public: - typedef typename verifyt::candidatet candidatet; - typedef typename verifyt::counterexamplet counterexamplet; - typedef typename std::deque counterexamplest; - typedef typename counterexamplest::const_iterator const_iterator; -private: - counterexamplest ces; - void verify_full(counterexamplest &ces, const candidatet &candidate); -public: - /** - * @brief - * - * @details - * - * @param options - * @param verifier - * @param set_wordsize - */ - limited_wordsize_verifyt(optionst &options, verifyt &verifier, - std::function set_wordsize); - - /** - * @brief Default destructor. - * - * @details No cleanup tasks performed. - */ - ~limited_wordsize_verifyt(); - - /** - * @brief Verifies a given candidate solution. - * - * @details Effectively invokes CBMC using the given function bodies. - * - * @param candidate The candidate implementation provided by the learner. - */ - void verify(const candidatet &candidate); - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_begin() const; - - /** - * @brief - * - * @details - * - * @return - */ - const_iterator counterexamples_end() const; - - /** - * @brief Indicates whether a counterexample could be produced. - * - * @details If the verification fails, but the oracle is unable to provide a - * counterexample, this marks an error in the CBMC execution. - * - * @return true if a counterexample was created, false otherwise. - */ - bool has_counterexamples() const; - - /** - * @brief Indicates whether the provided solution holds. - * - * @details Provides the result of the last "verify()" operation. - * - * @return true if the last solution holds, false otherwise. - */ - bool success() const; - - /** - * @brief - * - * @details - * - * @param os - * @param counterexample - */ - void show_counterexample( - messaget::mstreamt &os, - const counterexamplet &counterexample) const; -}; - -#include "limited_wordsize_verify.inc" - -#endif // CPROVER_CEGIS_WORDSIZE_LIMITED_WORDSIZE_VERIFY_H diff --git a/src/cegis/wordsize/limited_wordsize_verify.inc b/src/cegis/wordsize/limited_wordsize_verify.inc deleted file mode 100644 index b5379adf897..00000000000 --- a/src/cegis/wordsize/limited_wordsize_verify.inc +++ /dev/null @@ -1,108 +0,0 @@ -#include - -#include - -#include -#include - -#define CEGIS_DEFAULT_MIN_WORD_WIDTH 4u - -template -limited_wordsize_verifyt::limited_wordsize_verifyt(optionst &options, - verifyt &verifier, const std::function set_wordsize) : - options(options), verifier(verifier), set_wordsize(set_wordsize), is_success( - false), word_width(CEGIS_DEFAULT_MIN_WORD_WIDTH) -{ -} - -template -limited_wordsize_verifyt::~limited_wordsize_verifyt() -{ -} - -namespace -{ -template -void get_ces(verifyt &verifier, - typename limited_wordsize_verifyt::counterexamplest &ces) -{ - std::copy(verifier.counterexamples_begin(), verifier.counterexamples_end(), - std::back_inserter(ces)); -} -} - -template -void limited_wordsize_verifyt::verify_full(counterexamplest &ces, - const candidatet &candidate) -{ - verifier.verify(candidate); - if (verifier.has_counterexamples()) get_ces(verifier, ces); - else is_success=verifier.success(); -} - -namespace -{ -#define MAX_CONST_WIDTH "max-constant-width" -#define WIDTH_OPT "cegis-word-width" -} - -template -void limited_wordsize_verifyt::verify(const candidatet &candidate) -{ - ces.clear(); - counterexamplest full_ces; - const size_t full_width=32u; - const size_t max_const_width=options.get_unsigned_int_option(MAX_CONST_WIDTH); - word_width=std::max(max_const_width, word_width); - for (; word_width < full_width; word_width*=2u) - { - set_wordsize(word_width); - options.set_option(WIDTH_OPT, static_cast(word_width)); - verifier.verify(candidate); - if (verifier.has_counterexamples()) return get_ces(verifier, ces); - if (full_ces.empty()) - { - set_wordsize(full_width); - verify_full(full_ces, candidate); - if (!verifier.has_counterexamples()) return; - } - } - if (full_ces.empty()) - { - options.set_option(WIDTH_OPT, static_cast(full_width)); - verify_full(ces, candidate); - } else std::copy(full_ces.begin(), full_ces.end(), std::back_inserter(ces)); -} - -template -typename limited_wordsize_verifyt::const_iterator limited_wordsize_verifyt< - verifyt>::counterexamples_begin() const -{ - return ces.begin(); -} - -template -typename limited_wordsize_verifyt::const_iterator limited_wordsize_verifyt< - verifyt>::counterexamples_end() const -{ - return ces.end(); -} - -template -bool limited_wordsize_verifyt::has_counterexamples() const -{ - return !ces.empty(); -} - -template -bool limited_wordsize_verifyt::success() const -{ - return is_success; -} - -template -void limited_wordsize_verifyt::show_counterexample( - messaget::mstreamt &os, const counterexamplet &counterexample) const -{ - verifier.show_counterexample(os, counterexample); -} diff --git a/src/cegis/wordsize/restrict_bv_size.cpp b/src/cegis/wordsize/restrict_bv_size.cpp deleted file mode 100644 index c821133fd71..00000000000 --- a/src/cegis/wordsize/restrict_bv_size.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#include - -#include - -void restrict_bv_size(symbol_tablet &st, goto_functionst &gf, - const size_t width_in_bits) -{ - for(symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols) - { - symbolt &symbol=id_and_symbol.second; - restrict_bv_size(symbol.type, width_in_bits); - restrict_bv_size(symbol.value, width_in_bits); - } - for(goto_functionst::function_mapt::value_type &entry : gf.function_map) - { - goto_functionst::function_mapt::value_type::second_type &func=entry.second; - restrict_bv_size(func.type, width_in_bits); - if(!func.body_available()) continue; - goto_programt::instructionst &body=func.body.instructions; - for(goto_programt::instructiont &instr : body) - { - restrict_bv_size(instr.code, width_in_bits); - restrict_bv_size(instr.guard, width_in_bits); - } - } -} - -namespace -{ -bool is_bv_type(const typet &type) -{ - const irep_idt &type_id=type.id(); - return type_id == ID_signedbv || type_id == ID_unsignedbv - || type_id == ID_fixedbv || type_id == ID_floatbv - || type_id == ID_verilog_signedbv || type_id == ID_verilog_unsignedbv - || type_id == ID_bv || type_id == ID_pointer || type_id == ID_c_bit_field - || type_id == ID_c_bool; -} - -class restrict_bv_size_visitort: public expr_visitort -{ - const size_t width_in_bits; -public: - explicit restrict_bv_size_visitort(const size_t width_in_bits) : - width_in_bits(width_in_bits) - { - } - virtual ~restrict_bv_size_visitort() - { - } - - virtual void operator()(exprt &expr) - { - typet &type=expr.type(); - if(!restrict_bv_size(type, width_in_bits)) return; - if(ID_constant != expr.id()) return; - constant_exprt &constant=to_constant_expr(expr); - const std::string &value=id2string(constant.get_value()); - if(value.empty()) return; - assert(width_in_bits < value.size()); - std::string new_value(value.substr(value.size() - width_in_bits)); - // XXX: Restrict positive constant from being turned negative. Sensible? - if(ID_signedbv == type.id()) new_value[0]=value[0]; - constant.set_value(new_value); - } -}; -} - -void restrict_bv_size(exprt &expr, const size_t width_in_bits) -{ - restrict_bv_size_visitort visitor(width_in_bits); - expr.visit(visitor); -} - -namespace -{ -bool restrict_bv_size(code_typet &type, const size_t width_in_bits) -{ - restrict_bv_size(type.return_type(), width_in_bits); - for(code_typet::parametert ¶m : type.parameters()) - { - restrict_bv_size(param, width_in_bits); - restrict_bv_size(param.default_value(), width_in_bits); - } - return false; -} - -bool restrict_bv_size(struct_union_typet &type, const size_t width_in_bits) -{ - for(struct_union_typet::componentt &comp : type.components()) - restrict_bv_size(comp, width_in_bits); - return false; -} -} - -bool restrict_bv_size(typet &type, const size_t width_in_bits) -{ - const irep_idt &type_id=type.id(); - if(ID_code == type_id) - return restrict_bv_size(to_code_type(type), width_in_bits); - if(ID_struct == type_id || ID_union == type_id) - return restrict_bv_size(to_struct_union_type(type), width_in_bits); - if(static_cast(type).subtype().is_not_nil()) - restrict_bv_size(type.subtype(), width_in_bits); - if(!is_bv_type(type)) return false; - bitvector_typet &bvtype=to_bitvector_type(type); - if(width_in_bits >= bvtype.get_width()) return false; - to_bitvector_type(type).set_width(width_in_bits); - return true; -} diff --git a/src/cegis/wordsize/restrict_bv_size.h b/src/cegis/wordsize/restrict_bv_size.h deleted file mode 100644 index cdda0d7254b..00000000000 --- a/src/cegis/wordsize/restrict_bv_size.h +++ /dev/null @@ -1,47 +0,0 @@ -/*******************************************************************\ - -Module: Counterexample-Guided Inductive Synthesis - -Author: Daniel Kroening, kroening@kroening.com - Pascal Kesseli, pascal.kesseli@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_CEGIS_WORDSIZE_RESTRICT_BV_SIZE_H -#define CPROVER_CEGIS_WORDSIZE_RESTRICT_BV_SIZE_H - -#include - -/** - * @brief - * - * @details - * - * @param st - * @param gf - * @param width_in_bits - */ -void restrict_bv_size(class symbol_tablet &st, class goto_functionst &gf, - size_t width_in_bits); - -/** - * @brief - * - * @details - * - * @param expr - * @param width_in_bits - */ -void restrict_bv_size(class exprt &expr, size_t width_in_bits); - -/** - * @brief - * - * @details - * - * @param type - * @param width_in_bits - */ -bool restrict_bv_size(class typet &type, size_t width_in_bits); - -#endif // CPROVER_CEGIS_WORDSIZE_RESTRICT_BV_SIZE_H diff --git a/src/clobber/clobber_parse_options.cpp b/src/clobber/clobber_parse_options.cpp index 803ab9db5b1..a8fd471ecb6 100644 --- a/src/clobber/clobber_parse_options.cpp +++ b/src/clobber/clobber_parse_options.cpp @@ -524,10 +524,10 @@ void clobber_parse_optionst::report_success() switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="SUCCESS"; @@ -560,12 +560,12 @@ void clobber_parse_optionst::show_counterexample( switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: std::cout << std::endl << "Counterexample:" << std::endl; show_goto_trace(std::cout, ns, error_trace); break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml; convert(ns, error_trace, xml); @@ -596,10 +596,10 @@ void clobber_parse_optionst::report_failure() switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="FAILURE"; diff --git a/src/config.inc b/src/config.inc index e1c1266f683..dc2c8f6a47c 100644 --- a/src/config.inc +++ b/src/config.inc @@ -1,11 +1,12 @@ # Build platform (use one of AUTO, Unix, OSX_Universal, MSVC, Cygwin, MinGW) BUILD_ENV = AUTO -# Enable all warnings -#CXXFLAGS += -Wall -Wno-long-long -Wno-sign-compare -Wno-parentheses -Wno-strict-aliasing -pedantic - -# Treat warnings as errors -#CXXFLAGS += -Werror +# Enable all warnings and treat them as errors +ifeq ($(BUILD_ENV),MSVC) + #CXXFLAGS += /Wall /WX +else + CXXFLAGS += -Wall -pedantic -Werror +endif # Select optimisation or debug info #CXXFLAGS += -O2 -DNDEBUG diff --git a/src/cpp/cpp_declarator_converter.cpp b/src/cpp/cpp_declarator_converter.cpp index 83f5f1c1b38..24a295a03f7 100644 --- a/src/cpp/cpp_declarator_converter.cpp +++ b/src/cpp/cpp_declarator_converter.cpp @@ -100,7 +100,7 @@ symbolt &cpp_declarator_convertert::convert( get_final_identifier(); // first see if it is a member - if(scope->id_class==cpp_idt::CLASS && !is_friend) + if(scope->id_class==cpp_idt::id_classt::CLASS && !is_friend) { // it's a member! it must be declared already @@ -160,7 +160,7 @@ symbolt &cpp_declarator_convertert::convert( exprt symbol_expr= cpp_typecheck.resolve( name, - cpp_typecheck_resolvet::TYPE, + cpp_typecheck_resolvet::wantt::TYPE, cpp_typecheck_fargst()); if(symbol_expr.id()!=ID_type || @@ -238,13 +238,13 @@ symbolt &cpp_declarator_convertert::convert( cpp_scopet::id_sett id_set; scope->lookup_identifier( - symbol.name, cpp_idt::TEMPLATE_PARAMETER, id_set); + symbol.name, cpp_idt::id_classt::TEMPLATE_PARAMETER, id_set); if(id_set.empty()) { cpp_idt &identifier= cpp_typecheck.cpp_scopes.put_into_scope(symbol, *scope); - identifier.id_class=cpp_idt::TEMPLATE_PARAMETER; + identifier.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER; } } @@ -618,13 +618,13 @@ symbolt &cpp_declarator_convertert::convert_new_symbol( cpp_typecheck.cpp_scopes.put_into_scope(*new_symbol, *scope, is_friend); if(is_template) - identifier.id_class=cpp_idt::TEMPLATE; + identifier.id_class=cpp_idt::id_classt::TEMPLATE; else if(is_template_parameter) - identifier.id_class=cpp_idt::TEMPLATE_PARAMETER; + identifier.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER; else if(is_typedef) - identifier.id_class=cpp_idt::TYPEDEF; + identifier.id_class=cpp_idt::id_classt::TYPEDEF; else - identifier.id_class=cpp_idt::SYMBOL; + identifier.id_class=cpp_idt::id_classt::SYMBOL; // do the value if(!new_symbol->is_type) diff --git a/src/cpp/cpp_id.cpp b/src/cpp/cpp_id.cpp index 1357c646fe6..4ccb1a095d1 100644 --- a/src/cpp/cpp_id.cpp +++ b/src/cpp/cpp_id.cpp @@ -29,7 +29,7 @@ cpp_idt::cpp_idt(): is_static_member(false), is_scope(false), is_constructor(false), - id_class(UNKNOWN), + id_class(id_classt::UNKNOWN), this_expr(static_cast(get_nil_irep())), compound_counter(0), parent(NULL) @@ -163,20 +163,16 @@ std::ostream &operator<<(std::ostream &out, const cpp_idt::id_classt &id_class) { switch(id_class) { - case cpp_idt::UNKNOWN: out << "UNKNOWN"; break; - case cpp_idt::SYMBOL: out << "SYMBOL"; break; - case cpp_idt::TYPEDEF: out << "TYPEDEF"; break; - case cpp_idt::CLASS: out << "CLASS"; break; - case cpp_idt::TEMPLATE: out << "TEMPLATE"; break; - case cpp_idt::TEMPLATE_PARAMETER: out << "TEMPLATE_PARAMETER"; break; - case cpp_idt::ROOT_SCOPE: out << "ROOT_SCOPE"; break; - case cpp_idt::BLOCK_SCOPE: out << "BLOCK_SCOPE"; break; - case cpp_idt::TEMPLATE_SCOPE: out << "TEMPLATE_SCOPE"; break; - case cpp_idt::NAMESPACE: out << "NAMESPACE"; break; - - default: - out << "(OTHER)"; + case cpp_idt::id_classt::UNKNOWN: return out<<"UNKNOWN"; + case cpp_idt::id_classt::SYMBOL: return out<<"SYMBOL"; + case cpp_idt::id_classt::TYPEDEF: return out<<"TYPEDEF"; + case cpp_idt::id_classt::CLASS: return out<<"CLASS"; + case cpp_idt::id_classt::TEMPLATE: return out<<"TEMPLATE"; + case cpp_idt::id_classt::TEMPLATE_PARAMETER:return out<<"TEMPLATE_PARAMETER"; + case cpp_idt::id_classt::ROOT_SCOPE: return out<<"ROOT_SCOPE"; + case cpp_idt::id_classt::BLOCK_SCOPE: return out<<"BLOCK_SCOPE"; + case cpp_idt::id_classt::TEMPLATE_SCOPE: return out<<"TEMPLATE_SCOPE"; + case cpp_idt::id_classt::NAMESPACE: return out<<"NAMESPACE"; + default: return out << "(OTHER)"; } - - return out; } diff --git a/src/cpp/cpp_id.h b/src/cpp/cpp_id.h index 0e56b1d50cb..103297c4303 100644 --- a/src/cpp/cpp_id.h +++ b/src/cpp/cpp_id.h @@ -26,12 +26,20 @@ class cpp_idt public: cpp_idt(); - typedef enum + enum class id_classt { - UNKNOWN, SYMBOL, TYPEDEF, CLASS, ENUM, TEMPLATE, - TEMPLATE_PARAMETER, NAMESPACE, BLOCK_SCOPE, - TEMPLATE_SCOPE, ROOT_SCOPE - } id_classt; + UNKNOWN, + SYMBOL, + TYPEDEF, + CLASS, + ENUM, + TEMPLATE, + TEMPLATE_PARAMETER, + NAMESPACE, + BLOCK_SCOPE, + TEMPLATE_SCOPE, + ROOT_SCOPE, + }; bool is_member, is_method, is_static_member, is_scope, is_constructor; @@ -40,22 +48,22 @@ class cpp_idt bool is_class() const { - return id_class==CLASS; + return id_class==id_classt::CLASS; } bool is_enum() const { - return id_class==ENUM; + return id_class==id_classt::ENUM; } bool is_namespace() const { - return id_class==NAMESPACE; + return id_class==id_classt::NAMESPACE; } bool is_typedef() const { - return id_class==TYPEDEF; + return id_class==id_classt::TYPEDEF; } irep_idt identifier, base_name; diff --git a/src/cpp/cpp_instantiate_template.cpp b/src/cpp/cpp_instantiate_template.cpp index 0a6b9d5c129..6e1984f56f5 100644 --- a/src/cpp/cpp_instantiate_template.cpp +++ b/src/cpp/cpp_instantiate_template.cpp @@ -201,13 +201,13 @@ const symbolt &cpp_typecheckt::class_template_symbol( // put into template scope cpp_idt &id=cpp_scopes.put_into_scope(*s_ptr, *template_scope); - id.id_class=cpp_idt::CLASS; + id.id_class=cpp_idt::id_classt::CLASS; id.is_scope=true; id.prefix=template_scope->prefix+ id2string(s_ptr->base_name)+ id2string(suffix)+"::"; id.class_identifier=s_ptr->name; - id.id_class=cpp_idt::CLASS; + id.id_class=cpp_idt::id_classt::CLASS; return *s_ptr; } @@ -390,13 +390,13 @@ const symbolt &cpp_typecheckt::instantiate_template( // It has already been instantianted! const cpp_idt &cpp_id = **id_set.begin(); - assert(cpp_id.id_class == cpp_idt::CLASS || - cpp_id.id_class == cpp_idt::SYMBOL); + assert(cpp_id.id_class == cpp_idt::id_classt::CLASS || + cpp_id.id_class == cpp_idt::id_classt::SYMBOL); const symbolt &symb=lookup(cpp_id.identifier); // continue if the type is incomplete only - if(cpp_id.id_class==cpp_idt::CLASS && + if(cpp_id.id_class==cpp_idt::id_classt::CLASS && symb.type.id()==ID_struct) return symb; else if(symb.value.is_not_nil()) @@ -410,7 +410,7 @@ const symbolt &cpp_typecheckt::instantiate_template( // set up a scope as subscope of the template scope cpp_scopet &sub_scope= cpp_scopes.current_scope().new_scope(subscope_name); - sub_scope.id_class=cpp_idt::TEMPLATE_SCOPE; + sub_scope.id_class=cpp_idt::id_classt::TEMPLATE_SCOPE; sub_scope.prefix=template_scope->get_parent().prefix; sub_scope.suffix=suffix; sub_scope.add_using_scope(template_scope->get_parent()); diff --git a/src/cpp/cpp_scope.cpp b/src/cpp/cpp_scope.cpp index 35b52479419..6254cc70af3 100644 --- a/src/cpp/cpp_scope.cpp +++ b/src/cpp/cpp_scope.cpp @@ -175,7 +175,7 @@ void cpp_scopet::lookup( } if(!id_set.empty() && - id_class!=TEMPLATE) return; // done, upwards scopes are hidden + id_class!=id_classt::TEMPLATE) return; // done, upwards scopes are hidden // secondary scopes for(scope_listt::iterator @@ -194,7 +194,7 @@ void cpp_scopet::lookup( return; // done if(!id_set.empty() && - id_class!=TEMPLATE) return; // done, upwards scopes are hidden + id_class!=id_classt::TEMPLATE) return; // done, upwards scopes are hidden // ask parent, recursive call if(!is_root_scope()) diff --git a/src/cpp/cpp_scope.h b/src/cpp/cpp_scope.h index 07cded727fa..0c806f427b8 100644 --- a/src/cpp/cpp_scope.h +++ b/src/cpp/cpp_scope.h @@ -69,18 +69,18 @@ class cpp_scopet:public cpp_idt bool is_root_scope() const { - return id_class==ROOT_SCOPE; + return id_class==id_classt::ROOT_SCOPE; } bool is_global_scope() const { - return id_class==ROOT_SCOPE || - id_class==NAMESPACE; + return id_class==id_classt::ROOT_SCOPE || + id_class==id_classt::NAMESPACE; } bool is_template_scope() const { - return id_class==TEMPLATE_SCOPE; + return id_class==id_classt::TEMPLATE_SCOPE; } cpp_scopet &get_parent() const @@ -118,7 +118,7 @@ class cpp_root_scopet:public cpp_scopet public: cpp_root_scopet() { - id_class=ROOT_SCOPE; + id_class=id_classt::ROOT_SCOPE; identifier="::"; } }; diff --git a/src/cpp/cpp_scopes.cpp b/src/cpp/cpp_scopes.cpp index 51923be1929..bdd78980e9b 100644 --- a/src/cpp/cpp_scopes.cpp +++ b/src/cpp/cpp_scopes.cpp @@ -26,7 +26,7 @@ Function: cpp_scopest::new_block_scope cpp_scopet &cpp_scopest::new_block_scope() { unsigned prefix=++current_scope().compound_counter; - return new_scope(std::to_string(prefix), cpp_idt::BLOCK_SCOPE); + return new_scope(std::to_string(prefix), cpp_idt::id_classt::BLOCK_SCOPE); } /*******************************************************************\ @@ -57,7 +57,7 @@ cpp_idt &cpp_scopest::put_into_scope( { irep_idt block_base_name(std::string("$block:")+symbol.base_name.c_str()); cpp_idt &id = scope.insert(block_base_name); - id.id_class=cpp_idt::BLOCK_SCOPE; + id.id_class=cpp_idt::id_classt::BLOCK_SCOPE; id.identifier=symbol.name; id.is_scope=true; id.prefix = id2string(scope.prefix) + id2string(symbol.base_name) + "::"; @@ -74,7 +74,7 @@ cpp_idt &cpp_scopest::put_into_scope( cpp_idt &id=current_scope().insert(symbol.base_name); id.identifier=symbol.name; - id.id_class = cpp_idt::SYMBOL; + id.id_class = cpp_idt::id_classt::SYMBOL; if(id_map.find(symbol.name)==id_map.end()) id_map[symbol.name]=&id; return id; @@ -83,7 +83,7 @@ cpp_idt &cpp_scopest::put_into_scope( { cpp_idt &id=scope.insert(symbol.base_name); id.identifier=symbol.name; - id.id_class = cpp_idt::SYMBOL; + id.id_class = cpp_idt::id_classt::SYMBOL; if(id_map.find(symbol.name)==id_map.end()) id_map[symbol.name]=&id; return id; diff --git a/src/cpp/cpp_scopes.h b/src/cpp/cpp_scopes.h index e2034a436f7..92d9ebdb6e2 100644 --- a/src/cpp/cpp_scopes.h +++ b/src/cpp/cpp_scopes.h @@ -46,7 +46,7 @@ class cpp_scopest cpp_scopet &new_namespace(const irep_idt &new_scope_name) { - return new_scope(new_scope_name, cpp_idt::NAMESPACE); + return new_scope(new_scope_name, cpp_idt::id_classt::NAMESPACE); } cpp_scopet &new_block_scope(); diff --git a/src/cpp/cpp_typecheck_bases.cpp b/src/cpp/cpp_typecheck_bases.cpp index 5bcb06e55e3..1c768d63153 100644 --- a/src/cpp/cpp_typecheck_bases.cpp +++ b/src/cpp/cpp_typecheck_bases.cpp @@ -40,7 +40,7 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type) exprt base_symbol_expr= resolve( name, - cpp_typecheck_resolvet::TYPE, + cpp_typecheck_resolvet::wantt::TYPE, cpp_typecheck_fargst()); if(base_symbol_expr.id()!=ID_type) diff --git a/src/cpp/cpp_typecheck_code.cpp b/src/cpp/cpp_typecheck_code.cpp index 3d86c0f5f5d..f375cd4dbf6 100644 --- a/src/cpp/cpp_typecheck_code.cpp +++ b/src/cpp/cpp_typecheck_code.cpp @@ -256,7 +256,7 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code) // Plus, this should happen in class scope, not the scope of // the constructor because of the constructor arguments. exprt symbol_expr= - resolve(member, cpp_typecheck_resolvet::VAR, fargs); + resolve(member, cpp_typecheck_resolvet::wantt::VAR, fargs); if(symbol_expr.type().id()==ID_code) { @@ -340,7 +340,7 @@ void cpp_typecheckt::typecheck_member_initializer(codet &code) cpp_save_scopet cpp_saved_scope(cpp_scopes); cpp_scopes.go_to( *(cpp_scopes.id_map[cpp_scopes.current_scope().class_identifier])); - symbol_expr=resolve(member, cpp_typecheck_resolvet::VAR, fargs); + symbol_expr=resolve(member, cpp_typecheck_resolvet::wantt::VAR, fargs); } if(symbol_expr.id() == ID_dereference && diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index e1ece6d8be9..56db1bbba6c 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -269,13 +269,13 @@ void cpp_typecheckt::typecheck_compound_type( // put into dest_scope cpp_idt &id=cpp_scopes.put_into_scope(*new_symbol, *dest_scope); - id.id_class=cpp_idt::CLASS; + id.id_class=cpp_idt::id_classt::CLASS; id.is_scope=true; id.prefix=cpp_scopes.current_scope().prefix+ id2string(new_symbol->base_name)+ cpp_scopes.current_scope().suffix+"::"; id.class_identifier=new_symbol->name; - id.id_class=cpp_idt::CLASS; + id.id_class=cpp_idt::id_classt::CLASS; if(has_body) typecheck_compound_body(*new_symbol); @@ -856,7 +856,9 @@ void cpp_typecheckt::put_compound_into_scope( { // put the symbol into scope cpp_idt &id=cpp_scopes.current_scope().insert(base_name); - id.id_class=compound.get_bool("is_type")?cpp_idt::TYPEDEF:cpp_idt::SYMBOL; + id.id_class=compound.get_bool("is_type")? + cpp_idt::id_classt::TYPEDEF: + cpp_idt::id_classt::SYMBOL; id.identifier=name; id.class_identifier=cpp_scopes.current_scope().identifier; id.is_member=true; @@ -870,7 +872,7 @@ void cpp_typecheckt::put_compound_into_scope( cpp_scopes.current_scope().insert( irep_idt(std::string("$block:") + base_name.c_str())); - id_block.id_class=cpp_idt::BLOCK_SCOPE; + id_block.id_class=cpp_idt::id_classt::BLOCK_SCOPE; id_block.identifier=name; id_block.class_identifier=cpp_scopes.current_scope().identifier; id_block.is_method=true; @@ -905,7 +907,9 @@ void cpp_typecheckt::put_compound_into_scope( // put into the scope cpp_idt &id=cpp_scopes.current_scope().insert(base_name); - id.id_class=compound.get_bool(ID_is_type)?cpp_idt::TYPEDEF:cpp_idt::SYMBOL; + id.id_class=compound.get_bool(ID_is_type)? + cpp_idt::id_classt::TYPEDEF: + cpp_idt::id_classt::SYMBOL; id.identifier=name; id.class_identifier=cpp_scopes.current_scope().identifier; id.is_member=true; @@ -1545,7 +1549,7 @@ void cpp_typecheckt::add_anonymous_members_to_scope( } cpp_idt &id=cpp_scopes.current_scope().insert(base_name); - id.id_class=cpp_idt::SYMBOL; + id.id_class=cpp_idt::id_classt::SYMBOL; id.identifier=comp.get_name(); id.class_identifier=struct_union_symbol.name; id.is_member=true; diff --git a/src/cpp/cpp_typecheck_declaration.cpp b/src/cpp/cpp_typecheck_declaration.cpp index fd846d90c0d..980413225b1 100644 --- a/src/cpp/cpp_typecheck_declaration.cpp +++ b/src/cpp/cpp_typecheck_declaration.cpp @@ -118,7 +118,7 @@ void cpp_typecheckt::convert_anonymous_union( } cpp_idt &id=cpp_scopes.current_scope().insert(base_name); - id.id_class = cpp_idt::SYMBOL; + id.id_class = cpp_idt::id_classt::SYMBOL; id.identifier=it->get(ID_name); id.class_identifier=union_symbol.name; id.is_member=true; diff --git a/src/cpp/cpp_typecheck_enum_type.cpp b/src/cpp/cpp_typecheck_enum_type.cpp index 2e1bcf67172..09c57e9e9bc 100644 --- a/src/cpp/cpp_typecheck_enum_type.cpp +++ b/src/cpp/cpp_typecheck_enum_type.cpp @@ -83,7 +83,7 @@ void cpp_typecheckt::typecheck_enum_body(symbolt &enum_symbol) cpp_idt &scope_identifier= cpp_scopes.put_into_scope(*new_symbol); - scope_identifier.id_class=cpp_idt::SYMBOL; + scope_identifier.id_class=cpp_idt::id_classt::SYMBOL; ++i; } @@ -212,7 +212,7 @@ void cpp_typecheckt::typecheck_enum_type(typet &type) cpp_idt &scope_identifier= cpp_scopes.put_into_scope(*new_symbol, dest_scope); - scope_identifier.id_class=cpp_idt::CLASS; + scope_identifier.id_class=cpp_idt::id_classt::CLASS; typecheck_enum_body(*new_symbol); } diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index 51b43cde996..a29d27634d8 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -379,7 +379,7 @@ void cpp_typecheckt::typecheck_expr_sizeof(exprt &expr) exprt symbol_expr=resolve( to_cpp_name(static_cast(type)), - cpp_typecheck_resolvet::BOTH, + cpp_typecheck_resolvet::wantt::BOTH, fargs); if(symbol_expr.id()!=ID_type) @@ -398,7 +398,7 @@ void cpp_typecheckt::typecheck_expr_sizeof(exprt &expr) exprt symbol_expr=resolve( to_cpp_name(static_cast(type.subtype())), - cpp_typecheck_resolvet::BOTH, + cpp_typecheck_resolvet::wantt::BOTH, fargs); if(symbol_expr.id()!=ID_type) @@ -725,7 +725,7 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) // should really be a qualified search exprt resolve_result=resolve( - cpp_name, cpp_typecheck_resolvet::VAR, fargs, false); + cpp_name, cpp_typecheck_resolvet::wantt::VAR, fargs, false); if(resolve_result.is_not_nil()) { @@ -767,7 +767,7 @@ bool cpp_typecheckt::operator_is_overloaded(exprt &expr) fargs.in_use=true; exprt resolve_result=resolve( - cpp_name, cpp_typecheck_resolvet::VAR, fargs, false); + cpp_name, cpp_typecheck_resolvet::wantt::VAR, fargs, false); if(resolve_result.is_not_nil()) { @@ -1063,7 +1063,7 @@ void cpp_typecheckt::typecheck_expr_explicit_typecast(exprt &expr) exprt symbol_expr=resolve( to_cpp_name(static_cast(expr.type())), - cpp_typecheck_resolvet::TYPE, + cpp_typecheck_resolvet::wantt::TYPE, fargs, false); // fail silently @@ -1356,7 +1356,7 @@ void cpp_typecheckt::typecheck_expr_member( exprt symbol_expr=resolve( component_cpp_name, - cpp_typecheck_resolvet::VAR, + cpp_typecheck_resolvet::wantt::VAR, new_fargs); if(symbol_expr.id()==ID_dereference) @@ -2097,7 +2097,7 @@ void cpp_typecheckt::typecheck_expr_cpp_name( exprt symbol_expr= resolve( to_cpp_name(expr), - cpp_typecheck_resolvet::VAR, + cpp_typecheck_resolvet::wantt::VAR, fargs); // we want VAR @@ -3141,7 +3141,7 @@ void cpp_typecheckt::explicit_typecast_ambiguity(exprt &expr) exprt resolve_result= resolve( to_cpp_name(expr.type()), - cpp_typecheck_resolvet::BOTH, + cpp_typecheck_resolvet::wantt::BOTH, cpp_typecheck_fargst()); if(resolve_result.id()!=ID_type) diff --git a/src/cpp/cpp_typecheck_initializer.cpp b/src/cpp/cpp_typecheck_initializer.cpp index ef19cba6050..f51490e77f8 100644 --- a/src/cpp/cpp_typecheck_initializer.cpp +++ b/src/cpp/cpp_typecheck_initializer.cpp @@ -110,7 +110,7 @@ void cpp_typecheckt::convert_initializer(symbolt &symbol) exprt resolved_expr=resolve( to_cpp_name(static_cast(symbol.value.op0())), - cpp_typecheck_resolvet::BOTH, fargs); + cpp_typecheck_resolvet::wantt::BOTH, fargs); assert(symbol.type.subtype() == resolved_expr.type()); diff --git a/src/cpp/cpp_typecheck_resolve.cpp b/src/cpp/cpp_typecheck_resolve.cpp index 47628c9f3f7..82250a8a748 100644 --- a/src/cpp/cpp_typecheck_resolve.cpp +++ b/src/cpp/cpp_typecheck_resolve.cpp @@ -303,7 +303,7 @@ exprt cpp_typecheck_resolvet::convert_identifier( const wantt want, const cpp_typecheck_fargst &fargs) { - if(identifier.id_class==cpp_scopet::TEMPLATE_PARAMETER) + if(identifier.id_class==cpp_scopet::id_classt::TEMPLATE_PARAMETER) return convert_template_parameter(identifier); exprt e; @@ -329,11 +329,11 @@ exprt cpp_typecheck_resolvet::convert_identifier( const typet &type=component.type(); assert(type.is_not_nil()); - if(identifier.id_class==cpp_scopet::TYPEDEF) + if(identifier.id_class==cpp_scopet::id_classt::TYPEDEF) { e=type_exprt(type); } - else if(identifier.id_class==cpp_scopet::SYMBOL) + else if(identifier.id_class==cpp_scopet::id_classt::SYMBOL) { // A non-static, non-type member. // There has to be an object. @@ -494,15 +494,15 @@ void cpp_typecheck_resolvet::filter( switch(want) { - case TYPE: + case wantt::TYPE: match=(it->id()==ID_type); break; - case VAR: + case wantt::VAR: match=(it->id()!=ID_type); break; - case BOTH: + case wantt::BOTH: match=true; break; @@ -1065,7 +1065,7 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope( cpp_typecheck.cpp_scopes.current_scope().lookup( final_base_name, recursive?cpp_scopet::RECURSIVE:cpp_scopet::QUALIFIED, - cpp_idt::TEMPLATE, + cpp_idt::id_classt::TEMPLATE, id_set); // std::cout << "S: " @@ -1630,7 +1630,7 @@ exprt cpp_typecheck_resolvet::resolve( base_name, lookup_kind, id_set); else cpp_typecheck.cpp_scopes.current_scope().lookup( - base_name, lookup_kind, cpp_idt::TEMPLATE, id_set); + base_name, lookup_kind, cpp_idt::id_classt::TEMPLATE, id_set); // Argument-dependent name lookup #if 0 @@ -1695,7 +1695,7 @@ exprt cpp_typecheck_resolvet::resolve( have_methods=true; } - if(want==BOTH && have_classes && have_methods) + if(want==wantt::BOTH && have_classes && have_methods) { if(!fail_with_exception) return nil_exprt(); @@ -1708,7 +1708,7 @@ exprt cpp_typecheck_resolvet::resolve( throw 0; } - if(want==TYPE || have_classes) + if(want==wantt::TYPE || have_classes) { typet instance= disambiguate_template_classes(base_name, id_set, template_args); @@ -1731,7 +1731,7 @@ exprt cpp_typecheck_resolvet::resolve( } // change types into constructors if we want a constructor - if(want==VAR) + if(want==wantt::VAR) make_constructors(identifiers); filter(identifiers, want); @@ -1877,7 +1877,7 @@ exprt cpp_typecheck_resolvet::resolve( switch(want) { - case VAR: + case wantt::VAR: if(result.id()==ID_type && !cpp_typecheck.cpp_is_pod(result.type())) { if(!fail_with_exception) @@ -1894,7 +1894,7 @@ exprt cpp_typecheck_resolvet::resolve( } break; - case TYPE: + case wantt::TYPE: if(result.id()!=ID_type) { if(!fail_with_exception) @@ -1958,7 +1958,7 @@ void cpp_typecheck_resolvet::guess_template_args( { const cpp_idt &id=**it; // template parameter? - if(id.id_class==cpp_idt::TEMPLATE_PARAMETER) + if(id.id_class==cpp_idt::id_classt::TEMPLATE_PARAMETER) { // see if unassigned exprt &e=cpp_typecheck.template_map.expr_map[id.identifier]; @@ -2062,7 +2062,7 @@ void cpp_typecheck_resolvet::guess_template_args( const cpp_idt &id=**it; // template argument? - if(id.id_class==cpp_idt::TEMPLATE_PARAMETER) + if(id.id_class==cpp_idt::id_classt::TEMPLATE_PARAMETER) { // see if unassigned typet &t=cpp_typecheck.template_map.type_map[id.identifier]; @@ -2545,7 +2545,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( break; } } - else if(id.id_class==cpp_scopet::TEMPLATE) + else if(id.id_class==cpp_scopet::id_classt::TEMPLATE) { // std::cout << "X3\n"; #if 0 @@ -2561,7 +2561,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes( } #endif } - else if(id.id_class==cpp_scopet::TEMPLATE_PARAMETER) + else if(id.id_class==cpp_scopet::id_classt::TEMPLATE_PARAMETER) { // std::cout << "X4\n"; // a template parameter may evaluate to be a scope: it could diff --git a/src/cpp/cpp_typecheck_resolve.h b/src/cpp/cpp_typecheck_resolve.h index 07e3511e0b3..6d9031b62e0 100644 --- a/src/cpp/cpp_typecheck_resolve.h +++ b/src/cpp/cpp_typecheck_resolve.h @@ -19,7 +19,7 @@ class cpp_typecheck_resolvet cpp_typecheck_resolvet( class cpp_typecheckt &_cpp_typecheck); - typedef enum { VAR, TYPE, BOTH } wantt; + enum class wantt { VAR, TYPE, BOTH }; exprt resolve( const cpp_namet &cpp_name, diff --git a/src/cpp/cpp_typecheck_template.cpp b/src/cpp/cpp_typecheck_template.cpp index 79c609a0a4b..29acce8c65c 100644 --- a/src/cpp/cpp_typecheck_template.cpp +++ b/src/cpp/cpp_typecheck_template.cpp @@ -180,7 +180,8 @@ void cpp_typecheckt::typecheck_class_template( previous_declaration.template_type()); } - assert(cpp_scopes.id_map[symbol_name]->id_class == cpp_idt::TEMPLATE_SCOPE); + assert(cpp_scopes.id_map[symbol_name]->id_class == + cpp_idt::id_classt::TEMPLATE_SCOPE); return; } @@ -212,13 +213,14 @@ void cpp_typecheckt::typecheck_class_template( // put into current scope cpp_idt &id=cpp_scopes.put_into_scope(*new_symbol); - id.id_class=cpp_idt::TEMPLATE; + id.id_class=cpp_idt::id_classt::TEMPLATE; id.prefix=cpp_scopes.current_scope().prefix+ id2string(new_symbol->base_name); // link the template symbol with the template scope cpp_scopes.id_map[symbol_name]=&template_scope; - assert(cpp_scopes.id_map[symbol_name]->id_class==cpp_idt::TEMPLATE_SCOPE); + assert(cpp_scopes.id_map[symbol_name]->id_class == + cpp_idt::id_classt::TEMPLATE_SCOPE); } /*******************************************************************\ @@ -326,12 +328,12 @@ void cpp_typecheckt::typecheck_function_template( // put into scope cpp_idt &id=cpp_scopes.put_into_scope(*new_symbol); - id.id_class=cpp_idt::TEMPLATE; + id.id_class=cpp_idt::id_classt::TEMPLATE; id.prefix=cpp_scopes.current_scope().prefix+ id2string(new_symbol->base_name); // link the template symbol with the template scope - assert(template_scope.id_class==cpp_idt::TEMPLATE_SCOPE); + assert(template_scope.id_class==cpp_idt::id_classt::TEMPLATE_SCOPE); cpp_scopes.id_map[symbol_name] = &template_scope; } @@ -389,7 +391,7 @@ void cpp_typecheckt::typecheck_class_template_member( cpp_scopes.current_scope().lookup( cpp_name.get_sub().front().get(ID_identifier), cpp_scopet::SCOPE_ONLY, // look only in current scope - cpp_scopet::TEMPLATE, // must be template + cpp_scopet::id_classt::TEMPLATE, // must be template id_set); if(id_set.empty()) @@ -409,7 +411,7 @@ void cpp_typecheckt::typecheck_class_template_member( << "' is ambiguous" << eom; throw 0; } - else if((*(id_set.begin()))->id_class!=cpp_idt::TEMPLATE) + else if((*(id_set.begin()))->id_class!=cpp_idt::id_classt::TEMPLATE) { // std::cerr << *(*id_set.begin()) << std::endl; error().source_location=cpp_name.source_location(); @@ -616,7 +618,7 @@ void cpp_typecheckt::convert_class_template_specialization( cpp_scopest::id_sett id_set; cpp_scopes.current_scope().lookup( - base_name, cpp_scopet::SCOPE_ONLY, cpp_idt::TEMPLATE, id_set); + base_name, cpp_scopet::SCOPE_ONLY, cpp_idt::id_classt::TEMPLATE, id_set); // remove any specializations for(cpp_scopest::id_sett::iterator @@ -833,7 +835,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters( cpp_scopes.current_scope().prefix+id_suffix); template_scope.prefix=template_scope.get_parent().prefix+id_suffix; - template_scope.id_class=cpp_idt::TEMPLATE_SCOPE; + template_scope.id_class=cpp_idt::id_classt::TEMPLATE_SCOPE; cpp_scopes.go_to(template_scope); @@ -887,7 +889,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters( // add to scope cpp_idt &id=scope.insert(base_name); id.identifier=identifier; - id.id_class=cpp_idt::TEMPLATE_PARAMETER; + id.id_class=cpp_idt::id_classt::TEMPLATE_PARAMETER; // is it a type or not? if(declaration.get_bool(ID_is_type)) diff --git a/src/cpp/cpp_typecheck_type.cpp b/src/cpp/cpp_typecheck_type.cpp index 0101ae9b93d..3672acfc0d2 100644 --- a/src/cpp/cpp_typecheck_type.cpp +++ b/src/cpp/cpp_typecheck_type.cpp @@ -59,7 +59,7 @@ void cpp_typecheckt::typecheck_type(typet &type) exprt symbol_expr=resolve( cpp_name, - cpp_typecheck_resolvet::TYPE, + cpp_typecheck_resolvet::wantt::TYPE, cpp_typecheck_fargst()); if(symbol_expr.id()!=ID_type) @@ -209,7 +209,7 @@ void cpp_typecheckt::typecheck_type(typet &type) exprt symbol_expr=resolve( to_cpp_name(static_cast(tmp_type)), - cpp_typecheck_resolvet::BOTH, + cpp_typecheck_resolvet::wantt::BOTH, fargs); type=symbol_expr.type(); diff --git a/src/cpp/cpp_typecheck_using.cpp b/src/cpp/cpp_typecheck_using.cpp index 4908539a2d4..9ad812ca8ec 100644 --- a/src/cpp/cpp_typecheck_using.cpp +++ b/src/cpp/cpp_typecheck_using.cpp @@ -63,7 +63,7 @@ void cpp_typecheckt::convert(cpp_usingt &cpp_using) { if(using_directive) { - if((*it)->id_class==cpp_idt::NAMESPACE) + if((*it)->id_class==cpp_idt::id_classt::NAMESPACE) cpp_scopes.current_scope().add_using_scope( static_cast(**it)); else @@ -74,8 +74,8 @@ void cpp_typecheckt::convert(cpp_usingt &cpp_using) else // declaration { // we copy all 'normal' identifiers into the current scope - if((*it)->id_class!=cpp_idt::TEMPLATE_PARAMETER && - (*it)->id_class!=cpp_idt::NAMESPACE) + if((*it)->id_class!=cpp_idt::id_classt::TEMPLATE_PARAMETER && + (*it)->id_class!=cpp_idt::id_classt::NAMESPACE) cpp_scopes.current_scope().insert(**it); } } diff --git a/src/cpp/expr2cpp.cpp b/src/cpp/expr2cpp.cpp index 052483a06f0..715809ca3c1 100644 --- a/src/cpp/expr2cpp.cpp +++ b/src/cpp/expr2cpp.cpp @@ -26,18 +26,9 @@ class expr2cppt:public expr2ct public: explicit expr2cppt(const namespacet &_ns):expr2ct(_ns) { } - std::string convert(const exprt &src) override - { - return expr2ct::convert(src); - } - - std::string convert(const typet &src) override - { - return expr2ct::convert(src); - } - protected: - std::string convert(const exprt &src, unsigned &precedence) override; + std::string convert_with_precedence( + const exprt &src, unsigned &precedence) override; std::string convert_cpp_this(const exprt &src, unsigned precedence); std::string convert_cpp_new(const exprt &src, unsigned precedence); std::string convert_extractbit(const exprt &src, unsigned precedence); @@ -529,7 +520,7 @@ Function: expr2cppt::convert \*******************************************************************/ -std::string expr2cppt::convert( +std::string expr2cppt::convert_with_precedence( const exprt &src, unsigned &precedence) { @@ -557,7 +548,7 @@ std::string expr2cppt::convert( else if(src.id()=="pod_constructor") return "pod_constructor"; else - return expr2ct::convert(src, precedence); + return expr2ct::convert_with_precedence(src, precedence); } /*******************************************************************\ diff --git a/src/cpp/parse.cpp b/src/cpp/parse.cpp index b16340c3eef..536c54f5169 100644 --- a/src/cpp/parse.cpp +++ b/src/cpp/parse.cpp @@ -44,63 +44,90 @@ struct indenter // NOLINT(readability/identifiers) class new_scopet { public: - new_scopet():kind(NONE), anon_count(0), parent(NULL) + new_scopet():kind(kindt::NONE), anon_count(0), parent(NULL) { } - typedef enum { NONE, - TEMPLATE, MEMBER, FUNCTION, VARIABLE, - TYPEDEF, TAG, - NAMESPACE, CLASS_TEMPLATE, MEMBER_TEMPLATE, - FUNCTION_TEMPLATE, BLOCK, - NON_TYPE_TEMPLATE_PARAMETER, - TYPE_TEMPLATE_PARAMETER, - TEMPLATE_TEMPLATE_PARAMETER } kindt; + enum class kindt + { + NONE, + TEMPLATE, + MEMBER, + FUNCTION, + VARIABLE, + TYPEDEF, + TAG, + NAMESPACE, + CLASS_TEMPLATE, + MEMBER_TEMPLATE, + FUNCTION_TEMPLATE, + BLOCK, + NON_TYPE_TEMPLATE_PARAMETER, + TYPE_TEMPLATE_PARAMETER, + TEMPLATE_TEMPLATE_PARAMETER + }; + kindt kind; irep_idt id; bool is_type() const { - return kind==TYPEDEF || - kind==TYPE_TEMPLATE_PARAMETER || - kind==TAG || - kind==CLASS_TEMPLATE; + return kind==kindt::TYPEDEF || + kind==kindt::TYPE_TEMPLATE_PARAMETER || + kind==kindt::TAG || + kind==kindt::CLASS_TEMPLATE; } bool is_template() const { - return kind==FUNCTION_TEMPLATE || - kind==CLASS_TEMPLATE || - kind==MEMBER_TEMPLATE; + return kind==kindt::FUNCTION_TEMPLATE || + kind==kindt::CLASS_TEMPLATE || + kind==kindt::MEMBER_TEMPLATE; } bool is_named_scope() const { - return kind==NAMESPACE || - kind==TAG || - kind==TYPE_TEMPLATE_PARAMETER; + return kind==kindt::NAMESPACE || + kind==kindt::TAG || + kind==kindt::TYPE_TEMPLATE_PARAMETER; } static const char *kind2string(kindt kind) { switch(kind) { - case NONE: return "?"; - case TEMPLATE: return "TEMPLATE"; - case MEMBER: return "MEMBER"; - case FUNCTION: return "FUNCTION"; - case VARIABLE: return "VARIABLE"; - case TYPEDEF: return "TYPEDEF"; - case TAG: return "TAG"; - case NAMESPACE: return "NAMESPACE"; - case CLASS_TEMPLATE: return "CLASS_TEMPLATE"; - case MEMBER_TEMPLATE: return "MEMBER_TEMPLATE"; - case FUNCTION_TEMPLATE: return "FUNCTION_TEMPLATE"; - case BLOCK: return "BLOCK"; - case NON_TYPE_TEMPLATE_PARAMETER: return "NON_TYPE_TEMPLATE_PARAMETER"; - case TYPE_TEMPLATE_PARAMETER: return "TYPE_TEMPLATE_PARAMETER"; - case TEMPLATE_TEMPLATE_PARAMETER: return "TEMPLATE_TEMPLATE_PARAMETER"; - default: return ""; + case kindt::NONE: + return "?"; + case kindt::TEMPLATE: + return "TEMPLATE"; + case kindt::MEMBER: + return "MEMBER"; + case kindt::FUNCTION: + return "FUNCTION"; + case kindt::VARIABLE: + return "VARIABLE"; + case kindt::TYPEDEF: + return "TYPEDEF"; + case kindt::TAG: + return "TAG"; + case kindt::NAMESPACE: + return "NAMESPACE"; + case kindt::CLASS_TEMPLATE: + return "CLASS_TEMPLATE"; + case kindt::MEMBER_TEMPLATE: + return "MEMBER_TEMPLATE"; + case kindt::FUNCTION_TEMPLATE: + return "FUNCTION_TEMPLATE"; + case kindt::BLOCK: + return "BLOCK"; + case kindt::NON_TYPE_TEMPLATE_PARAMETER: + return "NON_TYPE_TEMPLATE_PARAMETER"; + case kindt::TYPE_TEMPLATE_PARAMETER: + return "TYPE_TEMPLATE_PARAMETER"; + case kindt::TEMPLATE_TEMPLATE_PARAMETER: + return "TEMPLATE_TEMPLATE_PARAMETER"; + default: + return ""; } } @@ -184,7 +211,7 @@ class Parser // NOLINT(readability/identifiers) lex(_cpp_parser.token_buffer), parser(_cpp_parser) { - root_scope.kind=new_scopet::NAMESPACE; + root_scope.kind=new_scopet::kindt::NAMESPACE; current_scope=&root_scope; } @@ -1214,7 +1241,7 @@ bool Parser::rTemplateDecl(cpp_declarationt &decl) { TemplateDeclKind kind=tdk_unknown; - make_sub_scope("#template", new_scopet::TEMPLATE); + make_sub_scope("#template", new_scopet::kindt::TEMPLATE); current_scope->id_map.clear(); typet template_type; @@ -1446,7 +1473,7 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration) cpp_name.get_sub().push_back(name); declarator.name().swap(cpp_name); - add_id(declarator.name(), new_scopet::TYPE_TEMPLATE_PARAMETER); + add_id(declarator.name(), new_scopet::kindt::TYPE_TEMPLATE_PARAMETER); if(has_ellipsis) { @@ -1551,7 +1578,7 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration) << "Parser::rTempArgDeclaration 4\n"; #endif - add_id(declarator.name(), new_scopet::NON_TYPE_TEMPLATE_PARAMETER); + add_id(declarator.name(), new_scopet::kindt::NON_TYPE_TEMPLATE_PARAMETER); if(has_ellipsis) { @@ -4968,7 +4995,7 @@ bool Parser::rClassSpec(typet &spec) #endif save_scopet saved_scope(current_scope); - make_sub_scope(spec.find(ID_tag), new_scopet::TAG); + make_sub_scope(spec.find(ID_tag), new_scopet::kindt::TAG); exprt body; diff --git a/src/goto-analyzer/goto_analyzer_parse_options.cpp b/src/goto-analyzer/goto_analyzer_parse_options.cpp index 5f889ff99d7..c783243a0d3 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.cpp +++ b/src/goto-analyzer/goto_analyzer_parse_options.cpp @@ -16,6 +16,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include #include #include @@ -214,9 +215,7 @@ int goto_analyzer_parse_optionst::doit() register_languages(); - goto_model.set_message_handler(get_message_handler()); - - if(goto_model(cmdline)) + if(initialize_goto_model(goto_model, cmdline, get_message_handler())) return 6; if(process_goto_program(options)) diff --git a/src/goto-analyzer/goto_analyzer_parse_options.h b/src/goto-analyzer/goto_analyzer_parse_options.h index a72dd9ca76a..538bf47ac3e 100644 --- a/src/goto-analyzer/goto_analyzer_parse_options.h +++ b/src/goto-analyzer/goto_analyzer_parse_options.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include -#include +#include #include #include @@ -56,7 +56,7 @@ class goto_analyzer_parse_optionst: protected: ui_message_handlert ui_message_handler; - get_goto_modelt goto_model; + goto_modelt goto_model; virtual void register_languages(); diff --git a/src/goto-cc/compile.cpp b/src/goto-cc/compile.cpp index 04d50e76f82..58f74669c32 100644 --- a/src/goto-cc/compile.cpp +++ b/src/goto-cc/compile.cpp @@ -580,7 +580,7 @@ bool compilet::parse(const std::string &file_name) if(language.parse(infile, file_name)) { - if(get_ui()==ui_message_handlert::PLAIN) + if(get_ui()==ui_message_handlert::uit::PLAIN) error() << "PARSING ERROR" << eom; return true; } @@ -634,7 +634,7 @@ bool compilet::parse_stdin() { if(language.parse(std::cin, "")) { - if(get_ui()==ui_message_handlert::PLAIN) + if(get_ui()==ui_message_handlert::uit::PLAIN) error() << "PARSING ERROR" << eom; return true; } diff --git a/src/goto-diff/change_impact.cpp b/src/goto-diff/change_impact.cpp index 0644cef2220..6ca431c0f1d 100644 --- a/src/goto-diff/change_impact.cpp +++ b/src/goto-diff/change_impact.cpp @@ -260,7 +260,7 @@ class change_impactt dependence_grapht old_dep_graph; dependence_grapht new_dep_graph; - typedef enum + enum mod_flagt { SAME=0, NEW=1<<0, @@ -269,7 +269,7 @@ class change_impactt DEL_DATA_DEP=1<<3, NEW_CTRL_DEP=1<<4, DEL_CTRL_DEP=1<<5 - } mod_flagt; + }; typedef std::map goto_program_change_impactt; @@ -445,13 +445,15 @@ void change_impactt::change_impact( const dependence_grapht::nodet &d_node= old_dep_graph[old_dep_graph[o_it].get_node_id()]; - if(impact_mode==BACKWARD || impact_mode==BOTH) + if(impact_mode==impact_modet::BACKWARD || + impact_mode==impact_modet::BOTH) propogate_dep_back( d_node, old_dep_graph, old_change_impact, true); - if(impact_mode==FORWARD || impact_mode==BOTH) + if(impact_mode==impact_modet::FORWARD || + impact_mode==impact_modet::BOTH) propogate_dep_forward( d_node, old_dep_graph, @@ -468,13 +470,15 @@ void change_impactt::change_impact( const dependence_grapht::nodet &d_node= new_dep_graph[new_dep_graph[n_it].get_node_id()]; - if(impact_mode==BACKWARD || impact_mode==BOTH) + if(impact_mode==impact_modet::BACKWARD || + impact_mode==impact_modet::BOTH) propogate_dep_back( d_node, new_dep_graph, new_change_impact, false); - if(impact_mode==FORWARD || impact_mode==BOTH) + if(impact_mode==impact_modet::FORWARD || + impact_mode==impact_modet::BOTH) propogate_dep_forward( d_node, new_dep_graph, @@ -518,8 +522,8 @@ void change_impactt::propogate_dep_forward( if((change_impact[src->function][src] &data_flag) || (change_impact[src->function][src] &ctrl_flag)) continue; - if(it->second.get() == dep_edget::DATA - || it->second.get() == dep_edget::BOTH) + if(it->second.get() == dep_edget::kindt::DATA + || it->second.get() == dep_edget::kindt::BOTH) change_impact[src->function][src] |= data_flag; else change_impact[src->function][src] |= ctrl_flag; @@ -559,8 +563,8 @@ void change_impactt::propogate_dep_back( { continue; } - if(it->second.get() == dep_edget::DATA - || it->second.get() == dep_edget::BOTH) + if(it->second.get() == dep_edget::kindt::DATA + || it->second.get() == dep_edget::kindt::BOTH) change_impact[src->function][src] |= data_flag; else change_impact[src->function][src] |= ctrl_flag; diff --git a/src/goto-diff/change_impact.h b/src/goto-diff/change_impact.h index e86867303c1..234ec15a7c8 100644 --- a/src/goto-diff/change_impact.h +++ b/src/goto-diff/change_impact.h @@ -12,7 +12,7 @@ Date: April 2016 #define CPROVER_GOTO_DIFF_CHANGE_IMPACT_H class goto_modelt; -typedef enum {FORWARD, BACKWARD, BOTH} impact_modet; +enum class impact_modet { FORWARD, BACKWARD, BOTH }; void change_impact( const goto_modelt &model_old, diff --git a/src/goto-diff/goto_diff.h b/src/goto-diff/goto_diff.h index 94155664129..bb6a7bb05cc 100644 --- a/src/goto-diff/goto_diff.h +++ b/src/goto-diff/goto_diff.h @@ -28,7 +28,7 @@ class goto_difft:public messaget messaget(_message_handler), goto_model1(_goto_model1), goto_model2(_goto_model2), - ui(ui_message_handlert::PLAIN), + ui(ui_message_handlert::uit::PLAIN), total_functions_count(0) {} diff --git a/src/goto-diff/goto_diff_base.cpp b/src/goto-diff/goto_diff_base.cpp index 248c161b8eb..7c6a0e5bf4e 100644 --- a/src/goto-diff/goto_diff_base.cpp +++ b/src/goto-diff/goto_diff_base.cpp @@ -26,7 +26,7 @@ std::ostream &goto_difft::output_functions(std::ostream &out) const { switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: { out << "total number of functions: " << total_functions_count << "\n"; out << "new functions: \n"; @@ -63,7 +63,7 @@ std::ostream &goto_difft::output_functions(std::ostream &out) const } break; } - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_result["totalNumberOfFunctions"]= @@ -77,7 +77,7 @@ std::ostream &goto_difft::output_functions(std::ostream &out) const out << ",\n" << json_result; break; } - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { out << "not supported yet"; } diff --git a/src/goto-diff/goto_diff_parse_options.cpp b/src/goto-diff/goto_diff_parse_options.cpp index c66bd9817a6..f0266b006e4 100644 --- a/src/goto-diff/goto_diff_parse_options.cpp +++ b/src/goto-diff/goto_diff_parse_options.cpp @@ -350,8 +350,10 @@ int goto_diff_parse_optionst::doit() impact_modet impact_mode= cmdline.isset("forward-impact") ? - FORWARD : - (cmdline.isset("backward-impact") ? BACKWARD : BOTH); + impact_modet::FORWARD : + (cmdline.isset("backward-impact") ? + impact_modet::BACKWARD : + impact_modet::BOTH); change_impact( goto_model1, goto_model2, diff --git a/src/goto-instrument/accelerate/all_paths_enumerator.cpp b/src/goto-instrument/accelerate/all_paths_enumerator.cpp index 8b1038d426d..b8db795bdfd 100644 --- a/src/goto-instrument/accelerate/all_paths_enumerator.cpp +++ b/src/goto-instrument/accelerate/all_paths_enumerator.cpp @@ -69,8 +69,7 @@ int all_paths_enumeratort::backtrack(patht &path) path.pop_back(); path_nodet &parent=path.back(); - goto_programt::targetst succs; - goto_program.get_successors(parent.loc, succs); + const auto succs=goto_program.get_successors(parent.loc); unsigned int ret=0; @@ -119,12 +118,9 @@ void all_paths_enumeratort::extend_path( int succ) { goto_programt::targett next; - goto_programt::targetst succs; exprt guard=true_exprt(); - goto_program.get_successors(t, succs); - - for(const auto &s : succs) + for(const auto &s : goto_program.get_successors(t)) { if(succ==0) { diff --git a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp index 29d5ac0f81b..e2ede0567cb 100644 --- a/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp +++ b/src/goto-instrument/accelerate/disjunctive_polynomial_acceleration.cpp @@ -757,23 +757,19 @@ void disjunctive_polynomial_accelerationt::find_distinguishing_points() it!=loop.end(); ++it) { - goto_programt::targetst succs; - - goto_program.get_successors(*it, succs); + const auto succs=goto_program.get_successors(*it); if(succs.size() > 1) { // This location has multiple successors -- each successor is a // distinguishing point. - for(goto_programt::targetst::iterator jt=succs.begin(); - jt!=succs.end(); - ++jt) + for(const auto &jt : succs) { symbolt distinguisher_sym = utils.fresh_symbol("polynomial::distinguisher", bool_typet()); symbol_exprt distinguisher=distinguisher_sym.symbol_expr(); - distinguishing_points[*jt]=distinguisher; + distinguishing_points[jt]=distinguisher; distinguishers.push_back(distinguisher); } } @@ -788,9 +784,8 @@ void disjunctive_polynomial_accelerationt::build_path( do { goto_programt::targett next; - goto_programt::targetst succs; - goto_program.get_successors(t, succs); + const auto succs=goto_program.get_successors(t); // We should have a looping path, so we should never hit a location // with no successors. diff --git a/src/goto-instrument/accelerate/sat_path_enumerator.cpp b/src/goto-instrument/accelerate/sat_path_enumerator.cpp index d8067ec3640..2a64a2d5949 100644 --- a/src/goto-instrument/accelerate/sat_path_enumerator.cpp +++ b/src/goto-instrument/accelerate/sat_path_enumerator.cpp @@ -109,9 +109,7 @@ void sat_path_enumeratort::find_distinguishing_points() it!=loop.end(); ++it) { - goto_programt::targetst succs; - - goto_program.get_successors(*it, succs); + const auto succs=goto_program.get_successors(*it); if(succs.size()>1) { @@ -139,9 +137,7 @@ void sat_path_enumeratort::build_path( do { goto_programt::targett next; - goto_programt::targetst succs; - - goto_program.get_successors(t, succs); + const auto succs=goto_program.get_successors(t); // We should have a looping path, so we should never hit a location // with no successors. diff --git a/src/goto-instrument/accelerate/scratch_program.cpp b/src/goto-instrument/accelerate/scratch_program.cpp index 8f7e1f40c2d..c09410eb77d 100644 --- a/src/goto-instrument/accelerate/scratch_program.cpp +++ b/src/goto-instrument/accelerate/scratch_program.cpp @@ -58,7 +58,7 @@ bool scratch_programt::check_sat(bool do_slice) std::cout << "Finished symex, invoking decision procedure.\n"; #endif - return (checker->dec_solve()==decision_proceduret::D_SATISFIABLE); + return (checker->dec_solve()==decision_proceduret::resultt::D_SATISFIABLE); } exprt scratch_programt::eval(const exprt &e) diff --git a/src/goto-instrument/accelerate/scratch_program.h b/src/goto-instrument/accelerate/scratch_program.h index 10194798891..2523a3184e3 100644 --- a/src/goto-instrument/accelerate/scratch_program.h +++ b/src/goto-instrument/accelerate/scratch_program.h @@ -37,7 +37,7 @@ class scratch_programt:public goto_programt symex(ns, symbol_table, equation), satcheck(new satcheckt), satchecker(ns, *satcheck), - z3(ns, "accelerate", "", "", smt2_dect::Z3), + z3(ns, "accelerate", "", "", smt2_dect::solvert::Z3), checker(&z3) // checker(&satchecker) { } diff --git a/src/goto-instrument/accelerate/trace_automaton.cpp b/src/goto-instrument/accelerate/trace_automaton.cpp index 10682862e7b..086b1be7d31 100644 --- a/src/goto-instrument/accelerate/trace_automaton.cpp +++ b/src/goto-instrument/accelerate/trace_automaton.cpp @@ -38,10 +38,7 @@ void trace_automatont::build_alphabet(goto_programt &program) { Forall_goto_program_instructions(it, program) { - goto_programt::targetst succs; - - program.get_successors(it, succs); - + const auto succs=program.get_successors(it); if(succs.size()>1) { alphabet.insert(succs.begin(), succs.end()); diff --git a/src/goto-instrument/call_sequences.cpp b/src/goto-instrument/call_sequences.cpp index 875d89051a6..d8c651bd1a7 100644 --- a/src/goto-instrument/call_sequences.cpp +++ b/src/goto-instrument/call_sequences.cpp @@ -62,14 +62,11 @@ void show_call_sequences( continue; // abort search } - // get successors - goto_programt::const_targetst s; - goto_program.get_successors(t, s); - - // add to stack - for(goto_programt::const_targetst::const_iterator - it=s.begin(); it!=s.end(); it++) - stack.push(*it); + // get successors and add to stack + for(const auto &it : goto_program.get_successors(t)) + { + stack.push(it); + } } } diff --git a/src/goto-instrument/cover.cpp b/src/goto-instrument/cover.cpp index 33ce83bc2f7..c3c5e0a5c06 100644 --- a/src/goto-instrument/cover.cpp +++ b/src/goto-instrument/cover.cpp @@ -826,6 +826,7 @@ Function: eval_expr the atomic expr values \*******************************************************************/ + bool eval_expr( const std::map &atomic_exprs, const exprt &src) @@ -1369,7 +1370,7 @@ void instrument_cover_goals( // check whether the current goal already exists if(!goals.is_existing_goal(source_location) && !source_location.get_file().empty() && - source_location.get_file()[0]!='<' && + !source_location.is_built_in() && cover_curr_function) { std::string comment= @@ -1412,7 +1413,8 @@ void instrument_cover_goals( t->source_location.set_function(i_it->function); } - if(i_it->is_goto() && !i_it->guard.is_true() && cover_curr_function) + if(i_it->is_goto() && !i_it->guard.is_true() && cover_curr_function && + !i_it->source_location.is_built_in()) { std::string b=std::to_string(basic_blocks[i_it]); std::string true_comment= @@ -1448,7 +1450,7 @@ void instrument_cover_goals( i_it->make_skip(); // Conditions are all atomic predicates in the programs. - if(cover_curr_function) + if(cover_curr_function && !i_it->source_location.is_built_in()) { const std::set conditions=collect_conditions(i_it); @@ -1488,7 +1490,7 @@ void instrument_cover_goals( i_it->make_skip(); // Decisions are maximal Boolean combinations of conditions. - if(cover_curr_function) + if(cover_curr_function && !i_it->source_location.is_built_in()) { const std::set decisions=collect_decisions(i_it); @@ -1532,7 +1534,7 @@ void instrument_cover_goals( // 3. Each condition in a decision takes every possible outcome // 4. Each condition in a decision is shown to independently // affect the outcome of the decision. - if(cover_curr_function) + if(cover_curr_function && !i_it->source_location.is_built_in()) { const std::set conditions=collect_conditions(i_it); const std::set decisions=collect_decisions(i_it); @@ -1646,7 +1648,8 @@ void instrument_cover_goals( Forall_goto_functions(f_it, goto_functions) { if(f_it->first==goto_functions.entry_point() || - f_it->first==(CPROVER_PREFIX "initialize")) + f_it->first==(CPROVER_PREFIX "initialize") || + f_it->second.is_hidden()) continue; instrument_cover_goals( diff --git a/src/goto-instrument/dot.cpp b/src/goto-instrument/dot.cpp index 8fc7cd3449a..455381c4c51 100644 --- a/src/goto-instrument/dot.cpp +++ b/src/goto-instrument/dot.cpp @@ -217,8 +217,7 @@ void dott::write_dot_subgraph( write_edge(out, *it, **frit, flabel); seen.insert(it); - goto_programt::const_targetst temp; - goto_program.get_successors(it, temp); + const auto temp=goto_program.get_successors(it); worklist.insert(worklist.end(), temp.begin(), temp.end()); } } diff --git a/src/goto-instrument/goto_instrument_parse_options.cpp b/src/goto-instrument/goto_instrument_parse_options.cpp index 0b899e5b4b6..bebf863c862 100644 --- a/src/goto-instrument/goto_instrument_parse_options.cpp +++ b/src/goto-instrument/goto_instrument_parse_options.cpp @@ -200,19 +200,20 @@ int goto_instrument_parse_optionst::doit() throw "more than one of --unwinding-assertions,--partial-loops," "--continue-as-loops selected"; - goto_unwindt::unwind_strategyt unwind_strategy=goto_unwindt::ASSUME; + goto_unwindt::unwind_strategyt unwind_strategy= + goto_unwindt::unwind_strategyt::ASSUME; if(unwinding_assertions) { - unwind_strategy=goto_unwindt::ASSERT; + unwind_strategy=goto_unwindt::unwind_strategyt::ASSERT; } else if(partial_loops) { - unwind_strategy=goto_unwindt::PARTIAL; + unwind_strategy=goto_unwindt::unwind_strategyt::PARTIAL; } else if(continue_as_loops) { - unwind_strategy=goto_unwindt::CONTINUE; + unwind_strategy=goto_unwindt::unwind_strategyt::CONTINUE; } goto_unwindt goto_unwind; diff --git a/src/goto-instrument/k_induction.cpp b/src/goto-instrument/k_induction.cpp index 92ab83e51b1..50abfe492f4 100644 --- a/src/goto-instrument/k_induction.cpp +++ b/src/goto-instrument/k_induction.cpp @@ -79,7 +79,7 @@ void k_inductiont::process_loop( // now unwind k times goto_unwindt goto_unwind; goto_unwind.unwind(goto_function.body, loop_head, loop_exit, k, - goto_unwindt::PARTIAL); + goto_unwindt::unwind_strategyt::PARTIAL); // assume the loop condition has become false goto_programt::instructiont assume(ASSUME); @@ -103,8 +103,13 @@ void k_inductiont::process_loop( std::vector iteration_points; goto_unwindt goto_unwind; - goto_unwind.unwind(goto_function.body, loop_head, loop_exit, k+1, - goto_unwindt::PARTIAL, iteration_points); + goto_unwind.unwind( + goto_function.body, + loop_head, + loop_exit, + k+1, + goto_unwindt::unwind_strategyt::PARTIAL, + iteration_points); // we can remove everything up to the first assertion for(goto_programt::targett t=loop_head; t!=loop_exit; t++) diff --git a/src/goto-instrument/object_id.cpp b/src/goto-instrument/object_id.cpp index f8fa7de4ca0..9df8b426df2 100644 --- a/src/goto-instrument/object_id.cpp +++ b/src/goto-instrument/object_id.cpp @@ -20,7 +20,7 @@ Function: get_objects_rec \*******************************************************************/ -typedef enum { LHS_R, LHS_W, READ } get_modet; +enum class get_modet { LHS_R, LHS_W, READ }; void get_objects_rec( get_modet mode, @@ -30,18 +30,18 @@ void get_objects_rec( { if(expr.id()==ID_symbol) { - if(mode==LHS_W || mode==READ) + if(mode==get_modet::LHS_W || mode==get_modet::READ) dest.insert(object_idt(to_symbol_expr(expr))); } else if(expr.id()==ID_index) { const index_exprt &index_expr=to_index_expr(expr); - if(mode==LHS_R || mode==READ) - get_objects_rec(READ, index_expr.index(), dest, ""); + if(mode==get_modet::LHS_R || mode==get_modet::READ) + get_objects_rec(get_modet::READ, index_expr.index(), dest, ""); - if(mode==LHS_R) - get_objects_rec(READ, index_expr.array(), dest, "[]"+suffix); + if(mode==get_modet::LHS_R) + get_objects_rec(get_modet::READ, index_expr.array(), dest, "[]"+suffix); else get_objects_rec(mode, index_expr.array(), dest, "[]"+suffix); } @@ -49,8 +49,8 @@ void get_objects_rec( { const if_exprt &if_expr=to_if_expr(expr); - if(mode==LHS_R || mode==READ) - get_objects_rec(READ, if_expr.cond(), dest, ""); + if(mode==get_modet::LHS_R || mode==get_modet::READ) + get_objects_rec(get_modet::READ, if_expr.cond(), dest, ""); get_objects_rec(mode, if_expr.true_case(), dest, suffix); get_objects_rec(mode, if_expr.false_case(), dest, suffix); @@ -67,14 +67,14 @@ void get_objects_rec( const dereference_exprt &dereference_expr= to_dereference_expr(expr); - if(mode==LHS_R || mode==READ) - get_objects_rec(READ, dereference_expr.pointer(), dest, ""); + if(mode==get_modet::LHS_R || mode==get_modet::READ) + get_objects_rec(get_modet::READ, dereference_expr.pointer(), dest, ""); } else { - if(mode==LHS_R || mode==READ) + if(mode==get_modet::LHS_R || mode==get_modet::READ) forall_operands(it, expr) - get_objects_rec(READ, *it, dest, ""); + get_objects_rec(get_modet::READ, *it, dest, ""); } } @@ -92,7 +92,7 @@ Function: get_objects void get_objects(const exprt &expr, object_id_sett &dest) { - get_objects_rec(READ, expr, dest, ""); + get_objects_rec(get_modet::READ, expr, dest, ""); } /*******************************************************************\ @@ -109,8 +109,8 @@ Function: get_objects_r void get_objects_r(const code_assignt &assign, object_id_sett &dest) { - get_objects_rec(LHS_R, assign.lhs(), dest, ""); - get_objects_rec(READ, assign.rhs(), dest, ""); + get_objects_rec(get_modet::LHS_R, assign.lhs(), dest, ""); + get_objects_rec(get_modet::READ, assign.rhs(), dest, ""); } /*******************************************************************\ @@ -127,7 +127,7 @@ Function: get_objects_w void get_objects_w(const code_assignt &assign, object_id_sett &dest) { - get_objects_rec(LHS_W, assign.lhs(), dest, ""); + get_objects_rec(get_modet::LHS_W, assign.lhs(), dest, ""); } /*******************************************************************\ @@ -144,7 +144,7 @@ Function: get_objects_w_lhs void get_objects_w(const exprt &lhs, object_id_sett &dest) { - get_objects_rec(LHS_W, lhs, dest, ""); + get_objects_rec(get_modet::LHS_W, lhs, dest, ""); } /*******************************************************************\ @@ -161,5 +161,5 @@ Function: get_objects_r_lhs void get_objects_r_lhs(const exprt &lhs, object_id_sett &dest) { - get_objects_rec(LHS_R, lhs, dest, ""); + get_objects_rec(get_modet::LHS_R, lhs, dest, ""); } diff --git a/src/goto-instrument/show_locations.cpp b/src/goto-instrument/show_locations.cpp index ef31898e294..411422e07fd 100644 --- a/src/goto-instrument/show_locations.cpp +++ b/src/goto-instrument/show_locations.cpp @@ -41,7 +41,7 @@ void show_locations( switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("program_location"); xml.new_element("function").data=id2string(function_id); @@ -59,7 +59,7 @@ void show_locations( } break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: std::cout << function_id << " " << it->location_number << " " << it->source_location << std::endl; diff --git a/src/goto-instrument/unwind.cpp b/src/goto-instrument/unwind.cpp index 1d3e2cc29e8..1ae2451c3a6 100644 --- a/src/goto-instrument/unwind.cpp +++ b/src/goto-instrument/unwind.cpp @@ -180,7 +180,7 @@ void goto_unwindt::unwind( // rest program after unwound part goto_programt rest_program; - if(unwind_strategy==PARTIAL) + if(unwind_strategy==unwind_strategyt::PARTIAL) { goto_programt::targett t=rest_program.add_instruction(); unwind_log.insert(t, loop_head->location_number); @@ -190,7 +190,7 @@ void goto_unwindt::unwind( t->function=loop_head->function; t->location_number=loop_head->location_number; } - else if(unwind_strategy==CONTINUE) + else if(unwind_strategy==unwind_strategyt::CONTINUE) { copy_segment(loop_head, loop_exit, rest_program); } @@ -216,9 +216,9 @@ void goto_unwindt::unwind( goto_programt::targett new_t=rest_program.add_instruction(); - if(unwind_strategy==ASSERT) + if(unwind_strategy==unwind_strategyt::ASSERT) new_t->make_assertion(exit_cond); - else if(unwind_strategy==ASSUME) + else if(unwind_strategy==unwind_strategyt::ASSUME) new_t->make_assumption(exit_cond); else assert(false); diff --git a/src/goto-instrument/unwind.h b/src/goto-instrument/unwind.h index 7240c3a4c61..99719f7ddf1 100644 --- a/src/goto-instrument/unwind.h +++ b/src/goto-instrument/unwind.h @@ -22,7 +22,7 @@ void parse_unwindset(const std::string &us, unwind_sett &unwind_set); class goto_unwindt { public: - typedef enum { CONTINUE, PARTIAL, ASSERT, ASSUME } unwind_strategyt; + enum class unwind_strategyt { CONTINUE, PARTIAL, ASSERT, ASSUME }; // unwind loop @@ -47,14 +47,14 @@ class goto_unwindt goto_programt &goto_program, const unwind_sett &unwind_set, const int k=-1, // -1: no global bound - const unwind_strategyt unwind_strategy=PARTIAL); + const unwind_strategyt unwind_strategy=unwind_strategyt::PARTIAL); // unwind all functions void operator()( goto_functionst &goto_functions, const unsigned k, // global bound - const unwind_strategyt unwind_strategy=PARTIAL) + const unwind_strategyt unwind_strategy=unwind_strategyt::PARTIAL) { const unwind_sett unwind_set; operator()(goto_functions, unwind_set, k, unwind_strategy); @@ -64,7 +64,7 @@ class goto_unwindt goto_functionst &goto_functions, const unwind_sett &unwind_set, const int k=-1, // -1: no global bound - const unwind_strategyt unwind_strategy=PARTIAL); + const unwind_strategyt unwind_strategy=unwind_strategyt::PARTIAL); // unwind log diff --git a/src/goto-instrument/wmm/abstract_event.cpp b/src/goto-instrument/wmm/abstract_event.cpp index c02a4a4d1f7..e080ba3ef3c 100644 --- a/src/goto-instrument/wmm/abstract_event.cpp +++ b/src/goto-instrument/wmm/abstract_event.cpp @@ -27,9 +27,9 @@ bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt &next, bool lwsync_met) const { /* pairs with fences are not properly pairs */ - if(operation==Fence || next.operation==Fence - || operation==Lwfence || next.operation==Lwfence - || operation==ASMfence || next.operation==ASMfence) + if(operation==operationt::Fence || next.operation==operationt::Fence + || operation==operationt::Lwfence || next.operation==operationt::Lwfence + || operation==operationt::ASMfence || next.operation==operationt::ASMfence) return false; /* pairs of shared variables */ @@ -39,40 +39,64 @@ bool abstract_eventt::unsafe_pair_lwfence_param(const abstract_eventt &next, switch(model) { case TSO: - return (thread==next.thread && operation==Write && next.operation==Read); + return (thread==next.thread && + operation==operationt::Write && + next.operation==operationt::Read); case PSO: - return (thread==next.thread && operation==Write + return (thread==next.thread && operation==operationt::Write /* lwsyncWW -> mfenceWW */ - && !(operation==Write && next.operation==Write && lwsync_met)); + && !(operation==operationt::Write && + next.operation==operationt::Write && + lwsync_met)); case RMO: return thread==next.thread && /* lwsyncWW -> mfenceWW */ - !(operation==Write && next.operation==Write && lwsync_met) && + !(operation==operationt::Write && + next.operation==operationt::Write && + lwsync_met) && /* lwsyncRW -> mfenceRW */ - !(operation==Read && next.operation==Write && lwsync_met) && + !(operation==operationt::Read && + next.operation==operationt::Write && + lwsync_met) && /* lwsyncRR -> mfenceRR */ - !(operation==Read && next.operation==Read && lwsync_met) && + !(operation==operationt::Read && + next.operation==operationt::Read && + lwsync_met) && /* if posWW, wsi maintained by the processor */ - !(variable==next.variable && operation==Write && next.operation==Write) && + !(variable==next.variable && + operation==operationt::Write && + next.operation==operationt::Write) && /* if posRW, fri maintained by the processor */ - !(variable==next.variable && operation==Read && next.operation==Write); + !(variable==next.variable && + operation==operationt::Read && + next.operation==operationt::Write); case Power: return ((thread==next.thread /* lwsyncWW -> mfenceWW */ - && !(operation==Write && next.operation==Write && lwsync_met) + && !(operation==operationt::Write && + next.operation==operationt::Write && + lwsync_met) /* lwsyncRW -> mfenceRW */ - && !(operation==Read && next.operation==Write && lwsync_met) + && !(operation==operationt::Read && + next.operation==operationt::Write && + lwsync_met) /* lwsyncRR -> mfenceRR */ - && !(operation==Read && next.operation==Read && lwsync_met) + && !(operation==operationt::Read && + next.operation==operationt::Read && + lwsync_met) /* if posWW, wsi maintained by the processor */ - && (variable!=next.variable || operation!=Write || next.operation!=Write)) + && (variable!=next.variable || + operation!=operationt::Write || + next.operation!=operationt::Write)) /* rfe */ - || (thread!=next.thread && operation==Write && next.operation==Read - && variable==next.variable)); + || (thread!=next.thread && + operation==operationt::Write && + next.operation==operationt::Read && + variable==next.variable)); case Unknown: { @@ -100,9 +124,12 @@ bool abstract_eventt::unsafe_pair_asm(const abstract_eventt &next, unsigned char met) const { /* pairs with fences are not properly pairs */ - if(operation==Fence || next.operation==Fence - || operation==Lwfence || next.operation==Lwfence - || operation==ASMfence || next.operation==ASMfence) + if(operation==operationt::Fence || + next.operation==operationt::Fence || + operation==operationt::Lwfence || + next.operation==operationt::Lwfence || + operation==operationt::ASMfence || + next.operation==operationt::ASMfence) return false; /* pairs of shared variables */ @@ -112,31 +139,38 @@ bool abstract_eventt::unsafe_pair_asm(const abstract_eventt &next, switch(model) { case TSO: - return (thread==next.thread && operation==Write && next.operation==Read - && (met&1)==0); + return (thread==next.thread && + operation==operationt::Write && + next.operation==operationt::Read && + (met&1)==0); case PSO: - return (thread==next.thread && operation==Write - && (met&3)==0); + return (thread==next.thread && + operation==operationt::Write && + (met&3)==0); case RMO: return thread==next.thread && (met&15)==0 && /* if posWW, wsi maintained by the processor */ - !(variable==next.variable && operation==Write && next.operation==Write) && + !(variable==next.variable && + operation==operationt::Write && + next.operation==operationt::Write) && /* if posRW, fri maintained by the processor */ - !(variable==next.variable && operation==Read && next.operation==Write); + !(variable==next.variable && + operation==operationt::Read && + next.operation==operationt::Write); case Power: return (thread==next.thread && (met&15)==0 && /* if posWW, wsi maintained by the processor */ (variable!=next.variable || - operation!=Write || - next.operation!=Write)) || + operation!=operationt::Write || + next.operation!=operationt::Write)) || /* rfe */ (thread!=next.thread && - operation==Write && - next.operation==Read && + operation==operationt::Write && + next.operation==operationt::Read && variable==next.variable); case Unknown: diff --git a/src/goto-instrument/wmm/abstract_event.h b/src/goto-instrument/wmm/abstract_event.h index db76a92f1f4..ba0c0f5f1ff 100644 --- a/src/goto-instrument/wmm/abstract_event.h +++ b/src/goto-instrument/wmm/abstract_event.h @@ -28,7 +28,7 @@ class abstract_eventt:public graph_nodet public: /* for now, both fence functions and asm fences accepted */ - typedef enum {Write, Read, Fence, Lwfence, ASMfence} operationt; + enum class operationt { Write, Read, Fence, Lwfence, ASMfence }; operationt operation; unsigned thread; @@ -111,7 +111,9 @@ class abstract_eventt:public graph_nodet bool is_fence() const { - return operation==Fence || operation==Lwfence || operation==ASMfence; + return operation==operationt::Fence || + operation==operationt::Lwfence || + operation==operationt::ASMfence; } /* checks the safety of the pair locally (i.e., w/o taking fences @@ -138,11 +140,11 @@ class abstract_eventt:public graph_nodet { switch(operation) { - case Write: return "W"; - case Read: return "R"; - case Fence: return "F"; - case Lwfence: return "f"; - case ASMfence: return "asm:"; + case operationt::Write: return "W"; + case operationt::Read: return "R"; + case operationt::Fence: return "F"; + case operationt::Lwfence: return "f"; + case operationt::ASMfence: return "asm:"; } assert(false); return "?"; @@ -152,16 +154,18 @@ class abstract_eventt:public graph_nodet const abstract_eventt &second) const { return - (WRfence && first.operation==Write && second.operation==Read) || + (WRfence && + first.operation==operationt::Write && + second.operation==operationt::Read) || ((WWfence || WWcumul) && - first.operation==Write && - second.operation==Write) || + first.operation==operationt::Write && + second.operation==operationt::Write) || ((RWfence || RWcumul) && - first.operation==Read && - second.operation==Write) || + first.operation==operationt::Read && + second.operation==operationt::Write) || ((RRfence || RRcumul) && - first.operation==Read && - second.operation==Read); + first.operation==operationt::Read && + second.operation==operationt::Read); } bool is_direct() const { return WWfence || WRfence || RRfence || RWfence; } diff --git a/src/goto-instrument/wmm/cycle_collection.cpp b/src/goto-instrument/wmm/cycle_collection.cpp index 1239aef6fa8..c8110665ead 100644 --- a/src/goto-instrument/wmm/cycle_collection.cpp +++ b/src/goto-instrument/wmm/cycle_collection.cpp @@ -263,7 +263,7 @@ bool event_grapht::graph_explorert::backtrack( if(!this_vertex.local) { /* only the lwsyncWR can be interpreted as poWR (i.e., skip of the fence) */ - if(lwfence_met && this_vertex.operation!=abstract_eventt::Read) + if(lwfence_met && this_vertex.operation!=abstract_eventt::operationt::Read) return false; // {no_comm=true;get_com_only=false;}//return false; bool has_to_be_unsafe_updated=false; @@ -274,9 +274,9 @@ bool event_grapht::graph_explorert::backtrack( id2string(this_vertex.variable).find("[]")==std::string::npos) { /* no more than 4 events per thread */ - if(this_vertex.operation!=abstract_eventt::Fence && - this_vertex.operation!=abstract_eventt::Lwfence && - this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::operationt::Fence && + this_vertex.operation!=abstract_eventt::operationt::Lwfence && + this_vertex.operation!=abstract_eventt::operationt::ASMfence) { if(events_per_thread[this_vertex.thread]==4) return false; @@ -295,13 +295,16 @@ bool event_grapht::graph_explorert::backtrack( point_stack.pop(); const event_idt preprevious=point_stack.top(); point_stack.push(previous); - if(!egraph[preprevious].unsafe_pair(this_vertex, model) - && !(this_vertex.operation==abstract_eventt::Fence - || egraph[preprevious].operation==abstract_eventt::Fence - || this_vertex.operation==abstract_eventt::Lwfence - || egraph[preprevious].operation==abstract_eventt::Lwfence - || this_vertex.operation==abstract_eventt::ASMfence - || egraph[preprevious].operation==abstract_eventt::ASMfence)) + if(!egraph[preprevious].unsafe_pair(this_vertex, model) && + !(this_vertex.operation==abstract_eventt::operationt::Fence || + egraph[preprevious].operation== + abstract_eventt::operationt::Fence || + this_vertex.operation==abstract_eventt::operationt::Lwfence || + egraph[preprevious].operation== + abstract_eventt::operationt::Lwfence || + this_vertex.operation==abstract_eventt::operationt::ASMfence || + egraph[preprevious].operation== + abstract_eventt::operationt::ASMfence)) return false; } } @@ -316,14 +319,15 @@ bool event_grapht::graph_explorert::backtrack( not taken into account) */ if(!point_stack.empty() && egraph.are_po_ordered(point_stack.top(), vertex) && - this_vertex.operation!=abstract_eventt::Fence && - this_vertex.operation!=abstract_eventt::Lwfence && - this_vertex.operation!=abstract_eventt::ASMfence && + this_vertex.operation!=abstract_eventt::operationt::Fence && + this_vertex.operation!=abstract_eventt::operationt::Lwfence && + this_vertex.operation!=abstract_eventt::operationt::ASMfence && this_vertex.variable==egraph[point_stack.top()].variable) { if(same_var_pair || - (this_vertex.operation==abstract_eventt::Read && - egraph[point_stack.top()].operation==abstract_eventt::Read)) + (this_vertex.operation==abstract_eventt::operationt::Read && + egraph[point_stack.top()].operation== + abstract_eventt::operationt::Read)) { events_per_thread[this_vertex.thread]--; return false; // {no_comm=true;get_com_only=false;} //return false; @@ -339,18 +343,18 @@ bool event_grapht::graph_explorert::backtrack( /* constraint 1.b */ if(!point_stack.empty() && egraph.are_po_ordered(point_stack.top(), vertex) && - this_vertex.operation!=abstract_eventt::Fence && - this_vertex.operation!=abstract_eventt::Lwfence && - this_vertex.operation!=abstract_eventt::ASMfence && + this_vertex.operation!=abstract_eventt::operationt::Fence && + this_vertex.operation!=abstract_eventt::operationt::Lwfence && + this_vertex.operation!=abstract_eventt::operationt::ASMfence && this_vertex.variable!=egraph[point_stack.top()].variable) { same_var_pair_updated=false; } /* constraint 2: per variable, either W W, R W, W R, or R W R */ - if(this_vertex.operation!=abstract_eventt::Fence && - this_vertex.operation!=abstract_eventt::Lwfence && - this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::operationt::Fence && + this_vertex.operation!=abstract_eventt::operationt::Lwfence && + this_vertex.operation!=abstract_eventt::operationt::ASMfence) { const unsigned char nb_writes=writes_per_variable[this_vertex.variable]; const unsigned char nb_reads=reads_per_variable[this_vertex.variable]; @@ -360,7 +364,7 @@ bool event_grapht::graph_explorert::backtrack( events_per_thread[this_vertex.thread]--; return false; // {no_comm=true;get_com_only=false;} //return false; } - else if(this_vertex.operation==abstract_eventt::Write) + else if(this_vertex.operation==abstract_eventt::operationt::Write) { if(nb_writes==2) { @@ -370,7 +374,7 @@ bool event_grapht::graph_explorert::backtrack( else writes_per_variable[this_vertex.variable]++; } - else if(this_vertex.operation==abstract_eventt::Read) + else if(this_vertex.operation==abstract_eventt::operationt::Read) { if(nb_reads==2) { @@ -522,11 +526,11 @@ bool event_grapht::graph_explorert::backtrack( point_stack.pop(); /* removes variable access */ - if(this_vertex.operation!=abstract_eventt::Fence && - this_vertex.operation!=abstract_eventt::Lwfence && - this_vertex.operation!=abstract_eventt::ASMfence) + if(this_vertex.operation!=abstract_eventt::operationt::Fence && + this_vertex.operation!=abstract_eventt::operationt::Lwfence && + this_vertex.operation!=abstract_eventt::operationt::ASMfence) { - if(this_vertex.operation==abstract_eventt::Write) + if(this_vertex.operation==abstract_eventt::operationt::Write) writes_per_variable[this_vertex.variable]--; else reads_per_variable[this_vertex.variable]--; @@ -544,12 +548,14 @@ bool event_grapht::graph_explorert::backtrack( (po_trans > 1 || po_trans==0) && !point_stack.empty() && egraph.are_po_ordered(point_stack.top(), vertex) && - this_vertex.operation!=abstract_eventt::Fence && - (this_vertex.operation!=abstract_eventt::Lwfence || - egraph[point_stack.top()].operation==abstract_eventt::Write) && - (this_vertex.operation!=abstract_eventt::ASMfence || + this_vertex.operation!=abstract_eventt::operationt::Fence && + (this_vertex.operation!=abstract_eventt::operationt::Lwfence || + egraph[point_stack.top()].operation== + abstract_eventt::operationt::Write) && + (this_vertex.operation!=abstract_eventt::operationt::ASMfence || !this_vertex.WRfence || - egraph[point_stack.top()].operation==abstract_eventt::Write)) + egraph[point_stack.top()].operation== + abstract_eventt::operationt::Write)) { skip_tracked.insert(vertex); @@ -590,11 +596,13 @@ bool event_grapht::graph_explorert::backtrack( /* skip lwfence by po-transition only if we consider a WR */ // TO CHECK const bool is_lwfence= - (this_vertex.operation==abstract_eventt::Lwfence && - egraph[point_stack.top()].operation==abstract_eventt::Write) || - (this_vertex.operation==abstract_eventt::ASMfence && + (this_vertex.operation==abstract_eventt::operationt::Lwfence && + egraph[point_stack.top()].operation== + abstract_eventt::operationt::Write) || + (this_vertex.operation==abstract_eventt::operationt::ASMfence && (!this_vertex.WRfence && - egraph[point_stack.top()].operation==abstract_eventt::Write)); + egraph[point_stack.top()].operation== + abstract_eventt::operationt::Write)); for(wmm_grapht::edgest::const_iterator w_it= egraph.po_out(vertex).begin(); diff --git a/src/goto-instrument/wmm/event_graph.cpp b/src/goto-instrument/wmm/event_graph.cpp index 9490d69f46c..dce7b3de474 100644 --- a/src/goto-instrument/wmm/event_graph.cpp +++ b/src/goto-instrument/wmm/event_graph.cpp @@ -237,7 +237,7 @@ bool event_grapht::critical_cyclet::check_AC( for(; AC_it!=end(); ++AC_it) { const abstract_eventt &AC_evt=egraph[*AC_it]; - if(AC_evt.operation==abstract_eventt::Fence) + if(AC_evt.operation==abstract_eventt::operationt::Fence) { AC=true; break; @@ -254,7 +254,7 @@ bool event_grapht::critical_cyclet::check_AC( for(AC_it=begin(); ; ++AC_it) { const abstract_eventt &AC_evt=egraph[*AC_it]; - if(AC_evt.operation==abstract_eventt::Fence) + if(AC_evt.operation==abstract_eventt::operationt::Fence) { AC=true; break; @@ -300,7 +300,7 @@ bool event_grapht::critical_cyclet::check_BC( for(; BC_it!=begin(); --BC_it) { const abstract_eventt &BC_evt=egraph[*BC_it]; - if(BC_evt.operation==abstract_eventt::Fence) + if(BC_evt.operation==abstract_eventt::operationt::Fence) { BC=true; break; @@ -319,7 +319,7 @@ bool event_grapht::critical_cyclet::check_BC( for(; ; --BC_it) { const abstract_eventt &BC_evt=egraph[*BC_it]; - if(BC_evt.operation==abstract_eventt::Fence) + if(BC_evt.operation==abstract_eventt::operationt::Fence) { BC=true; break; @@ -372,20 +372,21 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) const abstract_eventt &next_evt=egraph[*next]; /* strong fence -- this pair is safe */ - if(it_evt.operation==abstract_eventt::Fence) + if(it_evt.operation==abstract_eventt::operationt::Fence) continue; - if(next_evt.operation==abstract_eventt::Fence) + if(next_evt.operation==abstract_eventt::operationt::Fence) continue; /* first element is a weak fence */ - if(it_evt.operation==abstract_eventt::Lwfence) + if(it_evt.operation==abstract_eventt::operationt::Lwfence) continue; /* selects the next event which is not a weak fence */ const_iterator s_it=next; - for( ; s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; + for(; s_it!=end() && + egraph[*s_it].operation==abstract_eventt::operationt::Lwfence; ++s_it) { } @@ -395,7 +396,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) const abstract_eventt &s_evt=egraph[*s_it]; - if(s_evt.operation==abstract_eventt::Fence) + if(s_evt.operation==abstract_eventt::operationt::Fence) continue; /* if the whole cycle has been explored */ @@ -509,18 +510,19 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) } /* strong fence -- this pair is safe */ - if(egraph[back()].operation==abstract_eventt::Fence - || egraph[front()].operation==abstract_eventt::Fence) + if(egraph[back()].operation==abstract_eventt::operationt::Fence + || egraph[front()].operation==abstract_eventt::operationt::Fence) return unsafe_met; /* first element is a weak fence */ - if(egraph[back()].operation==abstract_eventt::Lwfence) + if(egraph[back()].operation==abstract_eventt::operationt::Lwfence) return unsafe_met; /* selects the next event which is not a weak fence */ const_iterator s_it; for(s_it=begin(); - s_it!=end() && egraph[*s_it].operation==abstract_eventt::Lwfence; + s_it!=end() && + egraph[*s_it].operation==abstract_eventt::operationt::Lwfence; s_it++) { } @@ -529,7 +531,7 @@ bool event_grapht::critical_cyclet::is_unsafe(memory_modelt model, bool fast) if(s_it==end()) return unsafe_met; - if(egraph[*s_it].operation==abstract_eventt::Fence) + if(egraph[*s_it].operation==abstract_eventt::operationt::Fence) return unsafe_met; const abstract_eventt &first=egraph[back()]; @@ -663,10 +665,10 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( fences_met=0; /* fence -- this pair is safe */ - if(egraph[*it].operation==abstract_eventt::ASMfence) + if(egraph[*it].operation==abstract_eventt::operationt::ASMfence) continue; - if(egraph[*(++it)].operation==abstract_eventt::ASMfence) + if(egraph[*(++it)].operation==abstract_eventt::operationt::ASMfence) { --it; continue; @@ -679,14 +681,15 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( --it; for(; - s_it!=end() && egraph[*s_it].operation==abstract_eventt::ASMfence; + s_it!=end() && + egraph[*s_it].operation==abstract_eventt::operationt::ASMfence; s_it++) fences_met |= egraph[*s_it].fence_value(); if(s_it==end()) continue; - if(egraph[*s_it].operation==abstract_eventt::ASMfence) + if(egraph[*s_it].operation==abstract_eventt::operationt::ASMfence) continue; /* if the whole cycle has been explored */ @@ -714,7 +717,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(; AC_it!=end() && egraph[*AC_it].thread==second.thread; AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence + if(egraph[*AC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*AC_it].is_cumul() && egraph[*AC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { @@ -730,7 +733,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(AC_it=begin(); !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence && + if(egraph[*AC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*AC_it].is_cumul() && egraph[*AC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { @@ -758,7 +761,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( BC_it!=begin() && egraph[*BC_it].thread==first.thread; BC_it--) { - if(egraph[*BC_it].operation==abstract_eventt::ASMfence && + if(egraph[*BC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { @@ -775,7 +778,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(BC_it=end(); !(egraph[*BC_it]==second) && egraph[*BC_it].thread==first.thread; BC_it--) - if(egraph[*BC_it].operation==abstract_eventt::ASMfence && + if(egraph[*BC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(egraph[*it], egraph[*s_it])) { @@ -827,8 +830,8 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( } /* strong fence -- this pair is safe */ - if(egraph[back()].operation==abstract_eventt::ASMfence - || egraph[front()].operation==abstract_eventt::ASMfence) + if(egraph[back()].operation==abstract_eventt::operationt::ASMfence + || egraph[front()].operation==abstract_eventt::operationt::ASMfence) return unsafe_met; fences_met=0; @@ -836,14 +839,16 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( /* selects the next event which is not a weak fence */ const_iterator s_it; for(s_it=begin(); - s_it!=end() && egraph[*s_it].operation==abstract_eventt::ASMfence; s_it++) + s_it!=end() && + egraph[*s_it].operation==abstract_eventt::operationt::ASMfence; + s_it++) fences_met |= egraph[*s_it].fence_value(); /* if the whole cycle has been explored */ if(s_it==end()) return unsafe_met; - if(egraph[*s_it].operation==abstract_eventt::ASMfence) + if(egraph[*s_it].operation==abstract_eventt::operationt::ASMfence) return unsafe_met; const abstract_eventt &first=egraph[back()]; @@ -867,7 +872,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(; AC_it!=end() && egraph[*AC_it].thread==second.thread; AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence + if(egraph[*AC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*AC_it].is_cumul() && egraph[*AC_it].is_corresponding_fence(first, second)) { @@ -883,7 +888,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(AC_it=begin(); !(egraph[*AC_it]==first) && egraph[*AC_it].thread==second.thread; AC_it++) - if(egraph[*AC_it].operation==abstract_eventt::ASMfence && + if(egraph[*AC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*AC_it].is_cumul() && egraph[*AC_it].is_corresponding_fence(first, second)) { @@ -902,7 +907,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(; BC_it!=begin() && egraph[*BC_it].thread==first.thread; BC_it--) - if(egraph[*BC_it].operation==abstract_eventt::ASMfence + if(egraph[*BC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(first, second)) { @@ -920,7 +925,7 @@ bool event_grapht::critical_cyclet::is_unsafe_asm( for(; !(egraph[*BC_it]==second) && egraph[*BC_it].thread==first.thread; BC_it--) - if(egraph[*BC_it].operation==abstract_eventt::ASMfence + if(egraph[*BC_it].operation==abstract_eventt::operationt::ASMfence && egraph[*BC_it].is_cumul() && egraph[*BC_it].is_corresponding_fence(first, second)) { @@ -985,9 +990,9 @@ bool event_grapht::critical_cyclet::is_not_uniproc() const for(; it!=end(); ++it) { const abstract_eventt &it_evt=egraph[*it]; - if(it_evt.operation!=abstract_eventt::Fence - && it_evt.operation!=abstract_eventt::Lwfence - && it_evt.operation!=abstract_eventt::ASMfence) + if(it_evt.operation!=abstract_eventt::operationt::Fence + && it_evt.operation!=abstract_eventt::operationt::Lwfence + && it_evt.operation!=abstract_eventt::operationt::ASMfence) break; } @@ -1006,9 +1011,9 @@ bool event_grapht::critical_cyclet::is_not_uniproc() const { const abstract_eventt &it_evt=egraph[*it]; if(it_evt.variable!=var - && it_evt.operation!=abstract_eventt::Fence - && it_evt.operation!=abstract_eventt::Lwfence - && it_evt.operation!=abstract_eventt::ASMfence) + && it_evt.operation!=abstract_eventt::operationt::Fence + && it_evt.operation!=abstract_eventt::operationt::Lwfence + && it_evt.operation!=abstract_eventt::operationt::ASMfence) break; } @@ -1035,9 +1040,9 @@ bool event_grapht::critical_cyclet::is_not_weak_uniproc() const for(; it!=end(); it++) { const abstract_eventt &it_evt=egraph[*it]; - if(it_evt.operation!=abstract_eventt::Fence - && it_evt.operation!=abstract_eventt::Lwfence - && it_evt.operation!=abstract_eventt::ASMfence) + if(it_evt.operation!=abstract_eventt::operationt::Fence + && it_evt.operation!=abstract_eventt::operationt::Lwfence + && it_evt.operation!=abstract_eventt::operationt::ASMfence) break; } @@ -1053,11 +1058,11 @@ bool event_grapht::critical_cyclet::is_not_weak_uniproc() const const abstract_eventt &it_evt=egraph[*it]; if( !(it_evt.variable==var - &&(it==begin() || it_evt.operation!=abstract_eventt::Read - || egraph[*prev].operation!=abstract_eventt::Read)) - && it_evt.operation!=abstract_eventt::Fence - && it_evt.operation!=abstract_eventt::Lwfence - && it_evt.operation!=abstract_eventt::ASMfence) + &&(it==begin() || it_evt.operation!=abstract_eventt::operationt::Read + || egraph[*prev].operation!=abstract_eventt::operationt::Read)) + && it_evt.operation!=abstract_eventt::operationt::Fence + && it_evt.operation!=abstract_eventt::operationt::Lwfence + && it_evt.operation!=abstract_eventt::operationt::ASMfence) break; } @@ -1094,8 +1099,8 @@ bool event_grapht::critical_cyclet::is_not_thin_air() const const abstract_eventt &next=egraph[*n_it]; /* rf */ - if(current.operation==abstract_eventt::Write && - next.operation==abstract_eventt::Read) + if(current.operation==abstract_eventt::operationt::Write && + next.operation==abstract_eventt::operationt::Read) continue; /* data dependencies */ @@ -1111,8 +1116,8 @@ bool event_grapht::critical_cyclet::is_not_thin_air() const const abstract_eventt &next=egraph[front()]; /* rf */ - if(current.operation==abstract_eventt::Write && - next.operation==abstract_eventt::Read) + if(current.operation==abstract_eventt::operationt::Write && + next.operation==abstract_eventt::operationt::Read) return false; /* data dependencies */ @@ -1167,24 +1172,24 @@ std::string event_grapht::critical_cyclet::print_unsafes() const const abstract_eventt &last=egraph[it->first]; if(last.variable==first.variable - && last.operation==abstract_eventt::Write - && first.operation==abstract_eventt::Read) + && last.operation==abstract_eventt::operationt::Write + && first.operation==abstract_eventt::operationt::Read) { name += " Rf"; name += (last.thread==first.thread?"i":"e"); } else if(last.variable==first.variable && - last.operation==abstract_eventt::Read && - first.operation==abstract_eventt::Write && + last.operation==abstract_eventt::operationt::Read && + first.operation==abstract_eventt::operationt::Write && (last.thread!=first.thread || it->first > it->second)) { name += " Fr"; name += (last.thread==first.thread?"i":"e"); } else if(last.variable==first.variable && - last.operation==abstract_eventt::Write && - first.operation==abstract_eventt::Write && + last.operation==abstract_eventt::operationt::Write && + first.operation==abstract_eventt::operationt::Write && (last.thread!=first.thread || it->first > it->second)) { /* we prefer to write Po rather than Wsi */ @@ -1192,7 +1197,7 @@ std::string event_grapht::critical_cyclet::print_unsafes() const name += (last.thread==first.thread?"i":"e"); } else if(last.thread==first.thread && - last.operation!=abstract_eventt::Fence) + last.operation!=abstract_eventt::operationt::Fence) { name += " Po"; name += (last.variable==first.variable?"s":"d") + last.get_operation() @@ -1453,15 +1458,15 @@ std::string event_grapht::critical_cyclet::print_name( { const abstract_eventt &prev=egraph[*prev_it]; - if(prev.operation==abstract_eventt::Fence || - prev.operation==abstract_eventt::Lwfence || - prev.operation==abstract_eventt::ASMfence) + if(prev.operation==abstract_eventt::operationt::Fence || + prev.operation==abstract_eventt::operationt::Lwfence || + prev.operation==abstract_eventt::operationt::ASMfence) { ++extra_fence_count; // nothing to do } - else if(cur.operation==abstract_eventt::Fence) + else if(cur.operation==abstract_eventt::operationt::Fence) { const_iterator n_it=cur_it; bool wraparound=false; @@ -1477,9 +1482,9 @@ std::string event_grapht::critical_cyclet::print_name( n_it=reduced.begin(); } const abstract_eventt &cand=egraph[*n_it]; - if(cand.operation!=abstract_eventt::Fence && - cand.operation!=abstract_eventt::Lwfence && - cand.operation!=abstract_eventt::ASMfence) + if(cand.operation!=abstract_eventt::operationt::Fence && + cand.operation!=abstract_eventt::operationt::Lwfence && + cand.operation!=abstract_eventt::operationt::ASMfence) break; if(!wraparound) ++cur_it; @@ -1487,14 +1492,14 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; } const abstract_eventt &succ=egraph[*n_it]; - assert(succ.operation==abstract_eventt::Read || - succ.operation==abstract_eventt::Write); + assert(succ.operation==abstract_eventt::operationt::Read || + succ.operation==abstract_eventt::operationt::Write); name += (model==Power?" Sync":" MFence"); name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } - else if(cur.operation==abstract_eventt::Lwfence) + else if(cur.operation==abstract_eventt::operationt::Lwfence) { std::string cand_name=" LwSync"; const_iterator n_it=cur_it; @@ -1511,12 +1516,12 @@ std::string event_grapht::critical_cyclet::print_name( n_it=reduced.begin(); } const abstract_eventt &cand=egraph[*n_it]; - if(cand.operation!=abstract_eventt::Fence && - cand.operation!=abstract_eventt::Lwfence && - cand.operation!=abstract_eventt::ASMfence) + if(cand.operation!=abstract_eventt::operationt::Fence && + cand.operation!=abstract_eventt::operationt::Lwfence && + cand.operation!=abstract_eventt::operationt::ASMfence) break; - else if(cand.operation==abstract_eventt::Fence || - (cand.operation==abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::operationt::Fence || + (cand.operation==abstract_eventt::operationt::ASMfence && cand.fence_value()&1)) cand_name=(model==Power?" Sync":" MFence"); if(!wraparound) @@ -1525,14 +1530,14 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; } const abstract_eventt &succ=egraph[*n_it]; - assert(succ.operation==abstract_eventt::Read || - succ.operation==abstract_eventt::Write); + assert(succ.operation==abstract_eventt::operationt::Read || + succ.operation==abstract_eventt::operationt::Write); name += cand_name; name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } - else if(cur.operation==abstract_eventt::ASMfence) + else if(cur.operation==abstract_eventt::operationt::ASMfence) { std::string cand_name; if(cur.fence_value()&1) @@ -1553,12 +1558,12 @@ std::string event_grapht::critical_cyclet::print_name( n_it=reduced.begin(); } const abstract_eventt &cand=egraph[*n_it]; - if(cand.operation!=abstract_eventt::Fence && - cand.operation!=abstract_eventt::Lwfence && - cand.operation!=abstract_eventt::ASMfence) + if(cand.operation!=abstract_eventt::operationt::Fence && + cand.operation!=abstract_eventt::operationt::Lwfence && + cand.operation!=abstract_eventt::operationt::ASMfence) break; - else if(cand.operation==abstract_eventt::Fence || - (cand.operation==abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::operationt::Fence || + (cand.operation==abstract_eventt::operationt::ASMfence && cand.fence_value()&1)) cand_name=(model==Power?" Sync":" MFence"); if(!wraparound) @@ -1567,24 +1572,24 @@ std::string event_grapht::critical_cyclet::print_name( ++extra_fence_count; } const abstract_eventt &succ=egraph[*n_it]; - assert(succ.operation==abstract_eventt::Read || - succ.operation==abstract_eventt::Write); + assert(succ.operation==abstract_eventt::operationt::Read || + succ.operation==abstract_eventt::operationt::Write); name += cand_name; name += (prev.variable==succ.variable?"s":"d") + prev.get_operation() + succ.get_operation(); } else if(prev.variable==cur.variable - && prev.operation==abstract_eventt::Write - && cur.operation==abstract_eventt::Read) + && prev.operation==abstract_eventt::operationt::Write + && cur.operation==abstract_eventt::operationt::Read) { name += " Rf"; name += (prev.thread==cur.thread?"i":"e"); } else if(prev.variable==cur.variable - && prev.operation==abstract_eventt::Read - && cur.operation==abstract_eventt::Write + && prev.operation==abstract_eventt::operationt::Read + && cur.operation==abstract_eventt::operationt::Write && (prev.thread!=cur.thread || *prev_it > *cur_it)) { name += " Fr"; @@ -1592,8 +1597,8 @@ std::string event_grapht::critical_cyclet::print_name( } else if(prev.variable==cur.variable && - prev.operation==abstract_eventt::Write && - cur.operation==abstract_eventt::Write && + prev.operation==abstract_eventt::operationt::Write && + cur.operation==abstract_eventt::operationt::Write && (prev.thread!=cur.thread || *prev_it > *cur_it)) { /* we prefer to write Po rather than Wsi */ @@ -1602,13 +1607,13 @@ std::string event_grapht::critical_cyclet::print_name( } else if(prev.thread==cur.thread - && prev.operation!=abstract_eventt::Fence - && prev.operation!=abstract_eventt::Lwfence - && prev.operation!=abstract_eventt::ASMfence) + && prev.operation!=abstract_eventt::operationt::Fence + && prev.operation!=abstract_eventt::operationt::Lwfence + && prev.operation!=abstract_eventt::operationt::ASMfence) { const data_dpt &dep=egraph.map_data_dp[cur.thread]; - if(prev.operation==abstract_eventt::Read && + if(prev.operation==abstract_eventt::operationt::Read && dep.dp(prev, cur)) { name += " DpData"; @@ -1646,13 +1651,13 @@ std::string event_grapht::critical_cyclet::print_name( const abstract_eventt &first=egraph[reduced.front()]; const abstract_eventt &last=egraph[reduced.back()]; - assert(last.operation!=abstract_eventt::Fence && - last.operation!=abstract_eventt::Lwfence && - last.operation!=abstract_eventt::ASMfence); + assert(last.operation!=abstract_eventt::operationt::Fence && + last.operation!=abstract_eventt::operationt::Lwfence && + last.operation!=abstract_eventt::operationt::ASMfence); - if(first.operation==abstract_eventt::Fence || - first.operation==abstract_eventt::Lwfence || - first.operation==abstract_eventt::ASMfence) + if(first.operation==abstract_eventt::operationt::Fence || + first.operation==abstract_eventt::operationt::Lwfence || + first.operation==abstract_eventt::operationt::ASMfence) { std::string cand_name=" LwSync"; const_iterator it=reduced.begin(); @@ -1660,35 +1665,35 @@ std::string event_grapht::critical_cyclet::print_name( { const abstract_eventt &cand=egraph[*it]; - if(cand.operation!=abstract_eventt::Fence && - cand.operation!=abstract_eventt::Lwfence && - cand.operation!=abstract_eventt::ASMfence) + if(cand.operation!=abstract_eventt::operationt::Fence && + cand.operation!=abstract_eventt::operationt::Lwfence && + cand.operation!=abstract_eventt::operationt::ASMfence) break; - else if(cand.operation==abstract_eventt::Fence || - (cand.operation==abstract_eventt::ASMfence && + else if(cand.operation==abstract_eventt::operationt::Fence || + (cand.operation==abstract_eventt::operationt::ASMfence && cand.fence_value()&1)) cand_name=(model==Power?" Sync":" MFence"); } assert(it!=reduced.begin() && it!=reduced.end()); const abstract_eventt &succ=egraph[*it]; - assert(succ.operation==abstract_eventt::Read || - succ.operation==abstract_eventt::Write); + assert(succ.operation==abstract_eventt::operationt::Read || + succ.operation==abstract_eventt::operationt::Write); name += cand_name; name += (last.variable==succ.variable?"s":"d") + last.get_operation() + succ.get_operation(); } else if(last.variable==first.variable - && last.operation==abstract_eventt::Write - && first.operation==abstract_eventt::Read) + && last.operation==abstract_eventt::operationt::Write + && first.operation==abstract_eventt::operationt::Read) { name += " Rf"; name += (last.thread==first.thread?"i":"e"); } else if(last.variable==first.variable - && last.operation==abstract_eventt::Read - && first.operation==abstract_eventt::Write + && last.operation==abstract_eventt::operationt::Read + && first.operation==abstract_eventt::operationt::Write && (last.thread!=first.thread || reduced.back() > reduced.front())) { name += " Fr"; @@ -1696,8 +1701,8 @@ std::string event_grapht::critical_cyclet::print_name( } else if(last.variable==first.variable && - last.operation==abstract_eventt::Write && - first.operation==abstract_eventt::Write && + last.operation==abstract_eventt::operationt::Write && + first.operation==abstract_eventt::operationt::Write && (last.thread!=first.thread || reduced.back() > reduced.front())) { /* we prefer to write Po rather than Wsi */ @@ -1709,7 +1714,7 @@ std::string event_grapht::critical_cyclet::print_name( { const data_dpt &dep=egraph.map_data_dp[last.thread]; - if(last.operation==abstract_eventt::Read && + if(last.operation==abstract_eventt::operationt::Read && dep.dp(last, first)) { name += " DpData"; @@ -1786,7 +1791,7 @@ void event_grapht::critical_cyclet::print_dot( const abstract_eventt &prev=egraph[*prev_it]; str << prev.id << "->"; - if(cur.operation==abstract_eventt::Fence) + if(cur.operation==abstract_eventt::operationt::Fence) { const_iterator n_it=cur_it; ++n_it; @@ -1797,7 +1802,7 @@ void event_grapht::critical_cyclet::print_dot( str << (prev.variable==cur.variable?"s":"d"); str << prev.get_operation() << succ.get_operation(); } - else if(cur.operation==abstract_eventt::Lwfence) + else if(cur.operation==abstract_eventt::operationt::Lwfence) { const_iterator n_it=cur_it; ++n_it; @@ -1808,22 +1813,22 @@ void event_grapht::critical_cyclet::print_dot( str <"; - if(first.operation==abstract_eventt::Fence) + if(first.operation==abstract_eventt::operationt::Fence) { const_iterator next=begin(); ++next; @@ -1864,7 +1869,7 @@ void event_grapht::critical_cyclet::print_dot( str << (last.variable==first.variable?"s":"d"); str << last.get_operation() << succ.get_operation(); } - else if(first.operation==abstract_eventt::Lwfence) + else if(first.operation==abstract_eventt::operationt::Lwfence) { const_iterator next=begin(); ++next; @@ -1874,22 +1879,22 @@ void event_grapht::critical_cyclet::print_dot( str << last.get_operation() << succ.get_operation(); } else if(last.variable==first.variable && - last.operation==abstract_eventt::Write && - first.operation==abstract_eventt::Read) + last.operation==abstract_eventt::operationt::Write && + first.operation==abstract_eventt::operationt::Read) { str << first.id << "[label=\""; str << "Rf" << (last.thread==first.thread?"i":"e"); } else if(last.variable==first.variable && - last.operation==abstract_eventt::Read && - first.operation==abstract_eventt::Write) + last.operation==abstract_eventt::operationt::Read && + first.operation==abstract_eventt::operationt::Write) { str << first.id << "[label=\""; str << "Fr" << (last.thread==first.thread?"i":"e"); } else if(last.variable==first.variable && - last.operation==abstract_eventt::Write && - first.operation==abstract_eventt::Write && + last.operation==abstract_eventt::operationt::Write && + first.operation==abstract_eventt::operationt::Write && last.thread!=first.thread) { /* we prefer to write Po rather than Wsi */ @@ -1897,7 +1902,7 @@ void event_grapht::critical_cyclet::print_dot( str << "Ws" << (last.thread==first.thread?"i":"e"); } else if(last.thread==first.thread && - last.operation!=abstract_eventt::Fence) + last.operation!=abstract_eventt::operationt::Fence) { str << first.id << "[label=\""; str << "Po" << (last.variable==first.variable?"s":"d"); diff --git a/src/goto-instrument/wmm/goto2graph.cpp b/src/goto-instrument/wmm/goto2graph.cpp index bdd97555c06..efcd626cb10 100644 --- a/src/goto-instrument/wmm/goto2graph.cpp +++ b/src/goto-instrument/wmm/goto2graph.cpp @@ -886,7 +886,7 @@ void instrumentert::cfg_visitort::visit_cfg_lwfence( goto_programt::instructionst::iterator i_it) { const goto_programt::instructiont &instruction=*i_it; - const abstract_eventt new_fence_event(abstract_eventt::Lwfence, + const abstract_eventt new_fence_event(abstract_eventt::operationt::Lwfence, thread, "f", instrumenter.unique_id++, instruction.source_location, false); const event_idt new_fence_node=egraph.add_node(); egraph[new_fence_node](new_fence_event); @@ -937,7 +937,7 @@ void instrumentert::cfg_visitort::visit_cfg_asm_fence( bool WWcumul=instruction.code.get_bool(ID_WWcumul); bool RRcumul=instruction.code.get_bool(ID_RRcumul); bool RWcumul=instruction.code.get_bool(ID_RWcumul); - const abstract_eventt new_fence_event(abstract_eventt::ASMfence, + const abstract_eventt new_fence_event(abstract_eventt::operationt::ASMfence, thread, "asm", instrumenter.unique_id++, instruction.source_location, false, WRfence, WWfence, RRfence, RWfence, WWcumul, RWcumul, RRcumul); const event_idt new_fence_node=egraph.add_node(); @@ -1026,7 +1026,7 @@ void instrumentert::cfg_visitort::visit_cfg_assign( assert(read_expr); #endif - const abstract_eventt new_read_event(abstract_eventt::Read, + const abstract_eventt new_read_event(abstract_eventt::operationt::Read, thread, id2string(read), instrumenter.unique_id++, instruction.source_location, local(read)); @@ -1124,7 +1124,7 @@ void instrumentert::cfg_visitort::visit_cfg_assign( // assert(write_expr); /* creates Write */ - const abstract_eventt new_write_event(abstract_eventt::Write, + const abstract_eventt new_write_event(abstract_eventt::operationt::Write, thread, id2string(write), instrumenter.unique_id++, instruction.source_location, local(write)); @@ -1311,7 +1311,7 @@ void instrumentert::cfg_visitort::visit_cfg_fence( goto_programt::instructionst::iterator i_it) { const goto_programt::instructiont &instruction=*i_it; - const abstract_eventt new_fence_event(abstract_eventt::Fence, + const abstract_eventt new_fence_event(abstract_eventt::operationt::Fence, thread, "F", instrumenter.unique_id++, instruction.source_location, false); const event_idt new_fence_node=egraph.add_node(); egraph[new_fence_node](new_fence_event); @@ -1532,16 +1532,15 @@ bool instrumentert::is_cfg_spurious(const event_grapht::critical_cyclet &cyc) } /* now test whether this part of the code can exist */ + goto_functionst::function_mapt map; goto_function_templatet one_interleaving; one_interleaving.body.copy_from(interleaving); - - std::pair > p( - goto_functionst::entry_point(), one_interleaving); - goto_functionst::function_mapt map; - map.insert(p); + map.insert(std::make_pair( + goto_functionst::entry_point(), + std::move(one_interleaving))); goto_functionst this_interleaving; - this_interleaving.function_map=map; + this_interleaving.function_map=std::move(map); optionst no_option; null_message_handlert no_message; diff --git a/src/goto-instrument/wmm/instrumenter_strategies.cpp b/src/goto-instrument/wmm/instrumenter_strategies.cpp index c5bb5563973..f06ed867ab5 100644 --- a/src/goto-instrument/wmm/instrumenter_strategies.cpp +++ b/src/goto-instrument/wmm/instrumenter_strategies.cpp @@ -249,9 +249,9 @@ unsigned inline instrumentert::cost( /* cost(poW*)=1 cost(poRW)=cost(rfe)=2 cost(poRR)=3 */ - if(egraph[e.first].operation==abstract_eventt::Write) + if(egraph[e.first].operation==abstract_eventt::operationt::Write) return 1; - else if(egraph[e.second].operation==abstract_eventt::Write + else if(egraph[e.second].operation==abstract_eventt::operationt::Write || !e.is_po) return 2; else diff --git a/src/goto-instrument/wmm/pair_collection.cpp b/src/goto-instrument/wmm/pair_collection.cpp index c86a0e6994b..4748ac2d2e7 100644 --- a/src/goto-instrument/wmm/pair_collection.cpp +++ b/src/goto-instrument/wmm/pair_collection.cpp @@ -59,7 +59,7 @@ void event_grapht::graph_pensieve_explorert::collect_pairs(namespacet &ns) /* directly outputs */ OUTPUT(res, "fence", first_event.source_location.get_file(), first_event.source_location.get_line(), first_event.variable, - first_event.operation); + static_cast(first_event.operation)); } catch(std::string s) { diff --git a/src/goto-instrument/wmm/wmm.h b/src/goto-instrument/wmm/wmm.h index fd3cbcc4e45..101234df3ae 100644 --- a/src/goto-instrument/wmm/wmm.h +++ b/src/goto-instrument/wmm/wmm.h @@ -11,16 +11,16 @@ Date: 2012 #ifndef CPROVER_GOTO_INSTRUMENT_WMM_WMM_H #define CPROVER_GOTO_INSTRUMENT_WMM_WMM_H -typedef enum +enum memory_modelt { Unknown=-1, TSO=0, PSO=1, RMO=2, Power=3 -} memory_modelt; +}; -typedef enum +enum instrumentation_strategyt { all=0, min_interference=1, @@ -28,13 +28,13 @@ typedef enum write_first=3, my_events=4, one_event_per_cycle=5 -} instrumentation_strategyt; +}; -typedef enum +enum loop_strategyt { arrays_only=0, all_loops=1, no_loop=2 -} loop_strategyt; +}; #endif // CPROVER_GOTO_INSTRUMENT_WMM_WMM_H diff --git a/src/goto-programs/Makefile b/src/goto-programs/Makefile index 6837ce82003..1a3583bff53 100644 --- a/src/goto-programs/Makefile +++ b/src/goto-programs/Makefile @@ -7,7 +7,7 @@ SRC = basic_blocks.cpp \ destructor.cpp \ elf_reader.cpp \ format_strings.cpp \ - get_goto_model.cpp \ + initialize_goto_model.cpp \ goto_asm.cpp \ goto_clean_expr.cpp \ goto_convert.cpp \ diff --git a/src/goto-programs/convert_nondet.cpp b/src/goto-programs/convert_nondet.cpp index e4655716d9b..7762b13a9f3 100644 --- a/src/goto-programs/convert_nondet.cpp +++ b/src/goto-programs/convert_nondet.cpp @@ -92,10 +92,10 @@ static goto_programt::targett insert_nondet_init_code( init_code, symbol_table, source_loc, - false, true, !nullable, - max_nondet_array_length); + max_nondet_array_length, + NO_UPDATE_IN_PLACE); // Convert this code into goto instructions goto_programt new_instructions; diff --git a/src/goto-programs/elf_reader.h b/src/goto-programs/elf_reader.h index 80b443401e2..737d631bee6 100644 --- a/src/goto-programs/elf_reader.h +++ b/src/goto-programs/elf_reader.h @@ -99,7 +99,7 @@ class elf_readert public: explicit elf_readert(std::istream &_in); - typedef enum { ELF32=1, ELF64=2 } elf_classt; + enum elf_classt { ELF32=1, ELF64=2 }; elf_classt elf_class; // the ELF header diff --git a/src/goto-programs/format_strings.cpp b/src/goto-programs/format_strings.cpp index 18be68e61ed..1e8be3b09cd 100644 --- a/src/goto-programs/format_strings.cpp +++ b/src/goto-programs/format_strings.cpp @@ -36,11 +36,16 @@ void parse_flags( { switch(*it) { - case '#': curtok.flags.push_back(format_tokent::ALTERNATE); break; - case '0': curtok.flags.push_back(format_tokent::ZERO_PAD); break; - case '-': curtok.flags.push_back(format_tokent::LEFT_ADJUST); break; - case ' ': curtok.flags.push_back(format_tokent::SIGNED_SPACE); break; - case '+': curtok.flags.push_back(format_tokent::SIGN); break; + case '#': + curtok.flags.push_back(format_tokent::flag_typet::ALTERNATE); break; + case '0': + curtok.flags.push_back(format_tokent::flag_typet::ZERO_PAD); break; + case '-': + curtok.flags.push_back(format_tokent::flag_typet::LEFT_ADJUST); break; + case ' ': + curtok.flags.push_back(format_tokent::flag_typet::SIGNED_SPACE); break; + case '+': + curtok.flags.push_back(format_tokent::flag_typet::SIGN); break; default: throw 0; } it++; @@ -65,7 +70,7 @@ void parse_field_width( { if(*it=='*') { - curtok.flags.push_back(format_tokent::ASTERISK); + curtok.flags.push_back(format_tokent::flag_typet::ASTERISK); it++; } @@ -96,7 +101,7 @@ void parse_precision( if(*it=='*') { - curtok.flags.push_back(format_tokent::ASTERISK); + curtok.flags.push_back(format_tokent::flag_typet::ASTERISK); it++; } else @@ -129,29 +134,29 @@ void parse_length_modifier( it++; if(*it=='h') it++; - curtok.length_modifier = format_tokent::LEN_h; + curtok.length_modifier = format_tokent::length_modifierst::LEN_h; } else if(*it=='l') { it++; if(*it=='l') it++; - curtok.length_modifier = format_tokent::LEN_l; + curtok.length_modifier = format_tokent::length_modifierst::LEN_l; } else if(*it=='L') { it++; - curtok.length_modifier = format_tokent::LEN_L; + curtok.length_modifier = format_tokent::length_modifierst::LEN_L; } else if(*it=='j') { it++; - curtok.length_modifier = format_tokent::LEN_j; + curtok.length_modifier = format_tokent::length_modifierst::LEN_j; } else if(*it=='t') { it++; - curtok.length_modifier = format_tokent::LEN_L; + curtok.length_modifier = format_tokent::length_modifierst::LEN_L; } } @@ -176,34 +181,37 @@ void parse_conversion_specifier( { case 'd': case 'i': - curtok.type=format_tokent::INT; - curtok.representation=format_tokent::SIGNED_DEC; + curtok.type=format_tokent::token_typet::INT; + curtok.representation=format_tokent::representationt::SIGNED_DEC; break; case 'o': - curtok.type=format_tokent::INT; - curtok.representation=format_tokent::UNSIGNED_OCT; + curtok.type=format_tokent::token_typet::INT; + curtok.representation=format_tokent::representationt::UNSIGNED_OCT; break; case 'u': - curtok.type=format_tokent::INT; - curtok.representation=format_tokent::UNSIGNED_DEC; + curtok.type=format_tokent::token_typet::INT; + curtok.representation=format_tokent::representationt::UNSIGNED_DEC; break; case 'x': case 'X': - curtok.type=format_tokent::INT; - curtok.representation=format_tokent::UNSIGNED_HEX; + curtok.type=format_tokent::token_typet::INT; + curtok.representation=format_tokent::representationt::UNSIGNED_HEX; break; case 'e': - case 'E': curtok.type=format_tokent::FLOAT; break; + case 'E': curtok.type=format_tokent::token_typet::FLOAT; break; case 'f': - case 'F': curtok.type=format_tokent::FLOAT; break; + case 'F': curtok.type=format_tokent::token_typet::FLOAT; break; case 'g': - case 'G': curtok.type=format_tokent::FLOAT; break; + case 'G': curtok.type=format_tokent::token_typet::FLOAT; break; case 'a': - case 'A': curtok.type=format_tokent::FLOAT; break; - case 'c': curtok.type=format_tokent::CHAR; break; - case 's': curtok.type=format_tokent::STRING; break; - case 'p': curtok.type=format_tokent::POINTER; break; - case '%': curtok.type=format_tokent::TEXT; curtok.value="%"; break; + case 'A': curtok.type=format_tokent::token_typet::FLOAT; break; + case 'c': curtok.type=format_tokent::token_typet::CHAR; break; + case 's': curtok.type=format_tokent::token_typet::STRING; break; + case 'p': curtok.type=format_tokent::token_typet::POINTER; break; + case '%': + curtok.type=format_tokent::token_typet::TEXT; + curtok.value="%"; + break; case '[': // pattern matching in, e.g., fscanf. { std::string tmp; @@ -264,8 +272,8 @@ format_token_listt parse_format_string(const std::string &arg_string) else { if(token_list.empty() || - token_list.back().type!=format_tokent::TEXT) - token_list.push_back(format_tokent(format_tokent::TEXT)); + token_list.back().type!=format_tokent::token_typet::TEXT) + token_list.push_back(format_tokent(format_tokent::token_typet::TEXT)); std::string tmp; for( ; it!=arg_string.end() && *it!='%'; it++) @@ -295,62 +303,63 @@ typet get_type(const format_tokent &token) { switch(token.type) { - case format_tokent::INT: + case format_tokent::token_typet::INT: switch(token.length_modifier) { - case format_tokent::LEN_h: - if(token.representation==format_tokent::SIGNED_DEC) + case format_tokent::length_modifierst::LEN_h: + if(token.representation==format_tokent::representationt::SIGNED_DEC) return signed_char_type(); else return unsigned_char_type(); - case format_tokent::LEN_hh: - if(token.representation==format_tokent::SIGNED_DEC) + case format_tokent::length_modifierst::LEN_hh: + if(token.representation==format_tokent::representationt::SIGNED_DEC) return signed_short_int_type(); else return unsigned_short_int_type(); - case format_tokent::LEN_l: - if(token.representation==format_tokent::SIGNED_DEC) + case format_tokent::length_modifierst::LEN_l: + if(token.representation==format_tokent::representationt::SIGNED_DEC) return signed_long_int_type(); else return unsigned_long_int_type(); - case format_tokent::LEN_ll: - if(token.representation==format_tokent::SIGNED_DEC) + case format_tokent::length_modifierst::LEN_ll: + if(token.representation==format_tokent::representationt::SIGNED_DEC) return signed_long_long_int_type(); else return unsigned_long_long_int_type(); default: - if(token.representation==format_tokent::SIGNED_DEC) + if(token.representation==format_tokent::representationt::SIGNED_DEC) return signed_int_type(); else return unsigned_int_type(); } - case format_tokent::FLOAT: + case format_tokent::token_typet::FLOAT: switch(token.length_modifier) { - case format_tokent::LEN_l: return double_type(); - case format_tokent::LEN_L: return long_double_type(); + case format_tokent::length_modifierst::LEN_l: return double_type(); + case format_tokent::length_modifierst::LEN_L: return long_double_type(); default: return float_type(); } - case format_tokent::CHAR: + case format_tokent::token_typet::CHAR: switch(token.length_modifier) { - case format_tokent::LEN_l: return wchar_t_type(); + case format_tokent::length_modifierst::LEN_l: return wchar_t_type(); default: return char_type(); } - case format_tokent::POINTER: + case format_tokent::token_typet::POINTER: return pointer_type(void_type()); - case format_tokent::STRING: + case format_tokent::token_typet::STRING: switch(token.length_modifier) { - case format_tokent::LEN_l: return array_typet(wchar_t_type(), nil_exprt()); + case format_tokent::length_modifierst::LEN_l: + return array_typet(wchar_t_type(), nil_exprt()); default: return array_typet(char_type(), nil_exprt()); } diff --git a/src/goto-programs/format_strings.h b/src/goto-programs/format_strings.h index 4959d51123e..6283b77f19b 100644 --- a/src/goto-programs/format_strings.h +++ b/src/goto-programs/format_strings.h @@ -18,39 +18,57 @@ Author: CM Wintersteiger class format_tokent { public: - typedef enum { UNKNOWN, - TEXT, - INT, // d, i, o, u, x - FLOAT, // a, e, f, g - CHAR, // c - STRING, // s - POINTER // p - } token_typet; - - typedef enum { ALTERNATE, ZERO_PAD, LEFT_ADJUST, - SIGNED_SPACE, SIGN, ASTERISK } flag_typet; - - typedef enum + enum class token_typet { - LEN_undef, LEN_h, LEN_hh, LEN_l, LEN_ll, - LEN_L, LEN_j, LEN_t - } length_modifierst; - - typedef enum + UNKNOWN, + TEXT, + INT, // d, i, o, u, x + FLOAT, // a, e, f, g + CHAR, // c + STRING, // s + POINTER // p + }; + + enum class flag_typet + { + ALTERNATE, + ZERO_PAD, + LEFT_ADJUST, + SIGNED_SPACE, + SIGN, + ASTERISK + }; + + enum class length_modifierst + { + LEN_undef, + LEN_h, + LEN_hh, + LEN_l, + LEN_ll, + LEN_L, + LEN_j, + LEN_t + }; + + enum class representationt { - SIGNED_undef, SIGNED_DEC, UNSIGNED_DEC, - UNSIGNED_OCT, UNSIGNED_HEX - } representationt; + SIGNED_undef, + SIGNED_DEC, + UNSIGNED_DEC, + UNSIGNED_OCT, + UNSIGNED_HEX + }; explicit format_tokent(token_typet _type) : type(_type), - length_modifier(LEN_undef), - representation(SIGNED_undef) + length_modifier(length_modifierst::LEN_undef), + representation(representationt::SIGNED_undef) { } format_tokent(): - type(UNKNOWN), - length_modifier(LEN_undef), - representation(SIGNED_undef) + type(token_typet::UNKNOWN), + length_modifier(length_modifierst::LEN_undef), + representation(representationt::SIGNED_undef) { } diff --git a/src/goto-programs/get_goto_model.h b/src/goto-programs/get_goto_model.h deleted file mode 100644 index c2c8cfd1230..00000000000 --- a/src/goto-programs/get_goto_model.h +++ /dev/null @@ -1,23 +0,0 @@ -/*******************************************************************\ - -Module: Obtain a Goto Program - -Author: Daniel Kroening, kroening@kroening.com - -\*******************************************************************/ - -#ifndef CPROVER_GOTO_PROGRAMS_GET_GOTO_MODEL_H -#define CPROVER_GOTO_PROGRAMS_GET_GOTO_MODEL_H - -#include -#include - -#include "goto_model.h" - -class get_goto_modelt:public goto_modelt, public messaget -{ -public: - bool operator()(const cmdlinet &); -}; - -#endif // CPROVER_GOTO_PROGRAMS_GET_GOTO_MODEL_H diff --git a/src/goto-programs/goto_functions.h b/src/goto-programs/goto_functions.h index 60c7fa90658..096fab391ec 100644 --- a/src/goto-programs/goto_functions.h +++ b/src/goto-programs/goto_functions.h @@ -17,6 +17,29 @@ Date: June 2003 class goto_functionst:public goto_functions_templatet { public: + goto_functionst()=default; + + // Copying is unavailable as base class copy is deleted + // MSVC is unable to automatically determine this + goto_functionst(const goto_functionst &)=delete; + goto_functionst &operator=(const goto_functionst &)=delete; + + // Move operations need to be explicitly enabled as they are deleted with the + // copy operations + // default for move operations isn't available on Windows yet, so define + // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx + // under "Defaulted and Deleted Functions") + + goto_functionst(goto_functionst &&other): + goto_functions_templatet(std::move(other)) + { + } + + goto_functionst &operator=(goto_functionst &&other) + { + goto_functions_templatet::operator=(std::move(other)); + return *this; + } }; #define Forall_goto_functions(it, functions) \ diff --git a/src/goto-programs/goto_functions_template.h b/src/goto-programs/goto_functions_template.h index 7c427b4f72f..9333cce06b3 100644 --- a/src/goto-programs/goto_functions_template.h +++ b/src/goto-programs/goto_functions_template.h @@ -66,18 +66,29 @@ class goto_function_templatet parameter_identifiers.swap(other.parameter_identifiers); } - void copy_from(const goto_function_templatet &other) + void copy_from(const goto_function_templatet &other) { body.copy_from(other.body); type=other.type; parameter_identifiers=other.parameter_identifiers; } - goto_function_templatet(const goto_function_templatet &src): - type(src.type), - parameter_identifiers(src.parameter_identifiers) + goto_function_templatet(const goto_function_templatet &)=delete; + goto_function_templatet &operator=(const goto_function_templatet &)=delete; + + goto_function_templatet(goto_function_templatet &&other): + body(std::move(other.body)), + type(std::move(other.type)), + parameter_identifiers(std::move(other.parameter_identifiers)) + { + } + + goto_function_templatet &operator=(goto_function_templatet &&other) { - body.copy_from(src.body); + body=std::move(other.body); + type=std::move(other.type); + parameter_identifiers=std::move(other.parameter_identifiers); + return *this; } }; @@ -93,10 +104,18 @@ class goto_functions_templatet { } - // copy constructor, don't use me! - goto_functions_templatet(const goto_functions_templatet &src) + goto_functions_templatet(const goto_functions_templatet &)=delete; + goto_functions_templatet &operator=(const goto_functions_templatet &)=delete; + + goto_functions_templatet(goto_functions_templatet &&other): + function_map(std::move(other.function_map)) + { + } + + goto_functions_templatet &operator=(goto_functions_templatet &&other) { - assert(src.function_map.empty()); + function_map=std::move(other.function_map); + return *this; } void clear() diff --git a/src/goto-programs/goto_inline.cpp b/src/goto-programs/goto_inline.cpp index 5ca3e1d55c3..01c0f1bf392 100644 --- a/src/goto-programs/goto_inline.cpp +++ b/src/goto-programs/goto_inline.cpp @@ -123,10 +123,20 @@ void goto_inline( Function: goto_partial_inline Inputs: + goto_model: + Source of the symbol table and function map to use. + message_handler: + Message handler used by goto_inlinet. + smallfunc_limit: + The maximum number of instructions in functions to be inlined. + adjust_function: + Tell goto_inlinet to adjust function. Outputs: Purpose: + Inline all function calls to functions either marked as "inlined" or + smaller than smallfunc_limit (by instruction count). \*******************************************************************/ @@ -150,10 +160,23 @@ void goto_partial_inline( Function: goto_partial_inline Inputs: + goto_functions: + The function map to use to find functions containing calls and function + bodies. + ns: + Namespace used by goto_inlinet. + message_handler: + Message handler used by goto_inlinet. + smallfunc_limit: + The maximum number of instructions in functions to be inlined. + adjust_function: + Tell goto_inlinet to adjust function. Outputs: Purpose: + Inline all function calls to functions either marked as "inlined" or + smaller than smallfunc_limit (by instruction count). \*******************************************************************/ @@ -182,6 +205,10 @@ void goto_partial_inline( if(!goto_function.body_available()) continue; + if(f_it->first==goto_functions.entry_point()) + // Don't inline any function calls made from the _start function. + continue; + goto_programt &goto_program=goto_function.body; goto_inlinet::call_listt &call_list=inline_map[f_it->first]; @@ -195,10 +222,10 @@ void goto_partial_inline( exprt function_expr; exprt::operandst arguments; exprt constrain; - goto_inlinet::get_call(i_it, lhs, function_expr, arguments, constrain); if(function_expr.id()!=ID_symbol) + // Can't handle pointers to functions continue; const symbol_exprt &symbol_expr=to_symbol_expr(function_expr); @@ -208,17 +235,14 @@ void goto_partial_inline( goto_functions.function_map.find(id); if(f_it==goto_functions.function_map.end()) + // Function not loaded, can't check size continue; // called function const goto_functiont &goto_function=f_it->second; - // We can't take functions without bodies to find functions - // inside them to be inlined. - // We also don't allow for the _start function to have any of its - // function calls to be inlined - if(!goto_function.body_available() || - f_it->first==goto_functions.entry_point()) + if(!goto_function.body_available()) + // The bodies of functions that don't have bodies can't be inlined. continue; const goto_programt &goto_program=goto_function.body; @@ -240,10 +264,16 @@ void goto_partial_inline( Function: goto_function_inline Inputs: + goto_model: Source of the symbol table and function map to use. + function: The function whose calls to inline. + message_handler: Message handler used by goto_inlinet. + adjust_function: Tell goto_inlinet to adjust function. + caching: Tell goto_inlinet to cache. Outputs: Purpose: + Inline all function calls made from a particular function \*******************************************************************/ @@ -251,14 +281,17 @@ void goto_function_inline( goto_modelt &goto_model, const irep_idt function, message_handlert &message_handler, - bool adjust_function) + bool adjust_function, + bool caching) { const namespacet ns(goto_model.symbol_table); goto_function_inline( goto_model.goto_functions, function, ns, - message_handler); + message_handler, + adjust_function, + caching); } /*******************************************************************\ @@ -266,10 +299,17 @@ void goto_function_inline( Function: goto_function_inline Inputs: + goto_functions: The function map to use to find function bodies. + function: The function whose calls to inline. + ns: Namespace used by goto_inlinet. + message_handler: Message handler used by goto_inlinet. + adjust_function: Tell goto_inlinet to adjust function. + caching: Tell goto_inlinet to cache. Outputs: Purpose: + Inline all function calls made from a particular function \*******************************************************************/ diff --git a/src/goto-programs/goto_model.h b/src/goto-programs/goto_model.h index ff7a671e074..37b491dc996 100644 --- a/src/goto-programs/goto_model.h +++ b/src/goto-programs/goto_model.h @@ -38,14 +38,28 @@ class goto_modelt { } - goto_modelt(goto_modelt &&other) + // Copying is normally too expensive + goto_modelt(const goto_modelt &)=delete; + goto_modelt &operator=(const goto_modelt &)=delete; + + // Move operations need to be explicitly enabled as they are deleted with the + // copy operations + // default for move operations isn't available on Windows yet, so define + // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx + // under "Defaulted and Deleted Functions") + + goto_modelt(goto_modelt &&other): + symbol_table(std::move(other.symbol_table)), + goto_functions(std::move(other.goto_functions)) { - symbol_table.swap(other.symbol_table); - goto_functions.swap(other.goto_functions); } - // copying is likely too expensive - goto_modelt(const goto_modelt &) = delete; + goto_modelt &operator=(goto_modelt &&other) + { + symbol_table=std::move(other.symbol_table); + goto_functions=std::move(other.goto_functions); + return *this; + } }; #endif // CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H diff --git a/src/goto-programs/goto_program.h b/src/goto-programs/goto_program.h index 06e2895529f..83fb020c096 100644 --- a/src/goto-programs/goto_program.h +++ b/src/goto-programs/goto_program.h @@ -15,7 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "goto_program_template.h" -/*! \brief A specialization of goto_program_templatet do +/*! \brief A specialization of goto_program_templatet over goto programs in which instructions have codet type. \ingroup gr_goto_programs */ @@ -36,6 +36,28 @@ class goto_programt:public goto_program_templatet goto_programt() { } + // Copying is unavailable as base class copy is deleted + // MSVC is unable to automatically determine this + goto_programt(const goto_programt &)=delete; + goto_programt &operator=(const goto_programt &)=delete; + + // Move operations need to be explicitly enabled as they are deleted with the + // copy operations + // default for move operations isn't available on Windows yet, so define + // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx + // under "Defaulted and Deleted Functions") + + goto_programt(goto_programt &&other): + goto_program_templatet(std::move(other)) + { + } + + goto_programt &operator=(goto_programt &&other) + { + goto_program_templatet::operator=(std::move(other)); + return *this; + } + // get the variables in decl statements typedef std::set decl_identifierst; void get_decl_identifiers(decl_identifierst &decl_identifiers) const; diff --git a/src/goto-programs/goto_program_template.h b/src/goto-programs/goto_program_template.h index 14f9e4a519e..fc36d573ef9 100644 --- a/src/goto-programs/goto_program_template.h +++ b/src/goto-programs/goto_program_template.h @@ -23,7 +23,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -typedef enum +enum goto_program_instruction_typet { NO_INSTRUCTION_TYPE=0, GOTO=1, // branch, possibly guarded @@ -44,7 +44,7 @@ typedef enum FUNCTION_CALL=16, // call a function THROW=17, // throw an exception CATCH=18 // catch an exception -} goto_program_instruction_typet; +}; std::ostream &operator<<(std::ostream &, goto_program_instruction_typet); @@ -56,26 +56,24 @@ template class goto_program_templatet { public: - /*! \brief copy constructor - \param[in] src an empty goto program - \remark Use copy_from to copy non-empty goto-programs - */ - goto_program_templatet(const goto_program_templatet &src) + // Copying is deleted as this class contains pointers that cannot be copied + goto_program_templatet(const goto_program_templatet &)=delete; + goto_program_templatet &operator=(const goto_program_templatet &)=delete; + + // Move operations need to be explicitly enabled as they are deleted with the + // copy operations + // default for move operations isn't available on Windows yet, so define + // explicitly (see https://msdn.microsoft.com/en-us/library/hh567368.aspx + // under "Defaulted and Deleted Functions") + + goto_program_templatet(goto_program_templatet &&other): + instructions(std::move(other.instructions)) { - // DO NOT COPY ME! I HAVE POINTERS IN ME! - assert(src.instructions.empty()); } - /*! \brief assignment operator - \param[in] src an empty goto program - \remark Use copy_from to copy non-empty goto-programs - */ - goto_program_templatet &operator=(const goto_program_templatet &src) + goto_program_templatet &operator=(goto_program_templatet &&other) { - // DO NOT COPY ME! I HAVE POINTERS IN ME! - assert(src.instructions.empty()); - instructions.clear(); - update(); + instructions=std::move(other.instructions); return *this; } @@ -193,11 +191,7 @@ class goto_program_templatet bool is_end_function () const { return type==END_FUNCTION; } instructiont(): - source_location(static_cast(get_nil_irep())), - type(NO_INSTRUCTION_TYPE), - guard(true_exprt()), - location_number(0), - target_number(nil_target) + instructiont(NO_INSTRUCTION_TYPE) // NOLINT(runtime/explicit) { } @@ -206,6 +200,7 @@ class goto_program_templatet type(_type), guard(true_exprt()), location_number(0), + loop_number(0), target_number(nil_target) { } @@ -213,12 +208,13 @@ class goto_program_templatet //! swap two instructions void swap(instructiont &instruction) { - instruction.code.swap(code); - instruction.source_location.swap(source_location); - std::swap(instruction.type, type); - instruction.guard.swap(guard); - instruction.targets.swap(targets); - instruction.function.swap(function); + using std::swap; + swap(instruction.code, code); + swap(instruction.source_location, source_location); + swap(instruction.type, type); + swap(instruction.guard, guard); + swap(instruction.targets, targets); + swap(instruction.function, function); } //! Uniquely identify an invalid target or location @@ -292,7 +288,7 @@ class goto_program_templatet const_targett l) { while(!l->is_end_function()) - l++; + ++l; return l->function; } @@ -305,13 +301,8 @@ class goto_program_templatet return get_function_id(--p.instructions.end()); } - void get_successors( - targett target, - targetst &successors); - - void get_successors( - const_targett target, - const_targetst &successors) const; + template + std::list get_successors(Target target) const; void compute_incoming_edges(); @@ -319,8 +310,7 @@ class goto_program_templatet void insert_before_swap(targett target) { assert(target!=instructions.end()); - targett next=target; - next++; + const auto next=std::next(target); instructions.insert(next, instructiont())->swap(*target); } @@ -342,19 +332,11 @@ class goto_program_templatet if(p.instructions.empty()) return; insert_before_swap(target, p.instructions.front()); - targett next=target; - next++; + auto next=std::next(target); p.instructions.erase(p.instructions.begin()); instructions.splice(next, p.instructions); } - //! Insertion before the given target - //! \return newly inserted location - targett insert_before(targett target) - { - return instructions.insert(target, instructiont()); - } - //! Insertion before the given target //! \return newly inserted location targett insert_before(const_targett target) @@ -364,11 +346,9 @@ class goto_program_templatet //! Insertion after the given target //! \return newly inserted location - targett insert_after(targett target) + targett insert_after(const_targett target) { - targett t=target; - t++; - return instructions.insert(t, instructiont()); + return instructions.insert(std::next(target), instructiont()); } //! Appends the given program, which is destroyed @@ -379,16 +359,6 @@ class goto_program_templatet // BUG: The iterators to p-instructions are invalidated! } - //! Inserts the given program at the given location. - //! The program is destroyed. - void destructive_insert( - targett target, - goto_program_templatet &p) - { - instructions.splice(target, p.instructions); - // BUG: The iterators to p-instructions are invalidated! - } - //! Inserts the given program at the given location. //! The program is destroyed. void destructive_insert( @@ -494,7 +464,7 @@ class goto_program_templatet targett get_end_function() { assert(!instructions.empty()); - targett end_function=--instructions.end(); + const auto end_function=std::prev(instructions.end()); assert(end_function->is_end_function()); return end_function; } @@ -516,99 +486,63 @@ void goto_program_templatet::compute_loop_numbers() } template -void goto_program_templatet::get_successors( - targett target, - targetst &successors) +template +std::list goto_program_templatet::get_successors( + Target target) const { - successors.clear(); if(target==instructions.end()) - return; + return std::list(); - targett next=target; - next++; + const auto next=std::next(target); const instructiont &i=*target; if(i.is_goto()) { - for(const auto &t : i.targets) - successors.push_back(t); + std::list successors(i.targets.begin(), i.targets.end()); if(!i.guard.is_true() && next!=instructions.end()) successors.push_back(next); + + return successors; } - else if(i.is_start_thread()) + + if(i.is_start_thread()) { - for(const auto &t : i.targets) - successors.push_back(t); + std::list successors(i.targets.begin(), i.targets.end()); if(next!=instructions.end()) successors.push_back(next); + + return successors; } - else if(i.is_end_thread()) + + if(i.is_end_thread()) { // no successors + return std::list(); } - else if(i.is_throw()) + + if(i.is_throw()) { // the successors are non-obvious + return std::list(); } - else if(i.is_assume()) - { - if(!i.guard.is_false() && next!=instructions.end()) - successors.push_back(next); - } - else - { - if(next!=instructions.end()) - successors.push_back(next); - } -} - -template -void goto_program_templatet::get_successors( - const_targett target, - const_targetst &successors) const -{ - successors.clear(); - if(target==instructions.end()) - return; - const_targett next=target; - next++; - - const instructiont &i=*target; - - if(i.is_goto()) + if(i.is_assume()) { - for(const auto &t : i.targets) - successors.push_back(t); - - if(!i.guard.is_true() && next!=instructions.end()) - successors.push_back(next); + return + !i.guard.is_false() && next!=instructions.end() ? + std::list{next} : + std::list(); } - else if(i.is_start_thread()) - { - for(const auto &t : i.targets) - successors.push_back(t); - if(next!=instructions.end()) - successors.push_back(next); - } - else if(i.is_end_thread()) - { - // no successors - } - else if(i.is_assume()) + if(next!=instructions.end()) { - if(!i.guard.is_false() && next!=instructions.end()) - successors.push_back(next); - } - else - { - if(next!=instructions.end()) - successors.push_back(next); + return std::list{next}; } + + return std::list(); } #include @@ -633,7 +567,7 @@ std::ostream &goto_program_templatet::output( for(typename instructionst::const_iterator it=instructions.begin(); it!=instructions.end(); - it++) + ++it) output_instruction(ns, identifier, out, it); return out; @@ -701,9 +635,9 @@ void goto_program_templatet::copy_from( for(typename instructionst::const_iterator it=src.instructions.begin(); it!=src.instructions.end(); - it++) + ++it) { - targett new_instruction=add_instruction(); + auto new_instruction=add_instruction(); targets_mapping[it]=new_instruction; *new_instruction=*it; } @@ -750,13 +684,9 @@ void goto_program_templatet::compute_incoming_edges() for(typename instructionst::iterator it=instructions.begin(); it!=instructions.end(); - it++) + ++it) { - targetst successors; - - get_successors(it, successors); - - for(const auto &s : successors) + for(const auto &s : get_successors(it)) { if(s!=instructions.end()) s->incoming_edges.insert(it); diff --git a/src/goto-programs/goto_trace.cpp b/src/goto-programs/goto_trace.cpp index 4179afb5395..d3ddb767d0c 100644 --- a/src/goto-programs/goto_trace.cpp +++ b/src/goto-programs/goto_trace.cpp @@ -59,27 +59,28 @@ void goto_trace_stept::output( switch(type) { - case goto_trace_stept::ASSERT: out << "ASSERT"; break; - case goto_trace_stept::ASSUME: out << "ASSUME"; break; - case goto_trace_stept::LOCATION: out << "LOCATION"; break; - case goto_trace_stept::ASSIGNMENT: out << "ASSIGNMENT"; break; - case goto_trace_stept::GOTO: out << "GOTO"; break; - case goto_trace_stept::DECL: out << "DECL"; break; - case goto_trace_stept::DEAD: out << "DEAD"; break; - case goto_trace_stept::OUTPUT: out << "OUTPUT"; break; - case goto_trace_stept::INPUT: out << "INPUT"; break; - case goto_trace_stept::ATOMIC_BEGIN: out << "ATOMC_BEGIN"; break; - case goto_trace_stept::ATOMIC_END: out << "ATOMIC_END"; break; - case goto_trace_stept::SHARED_READ: out << "SHARED_READ"; break; - case goto_trace_stept::SHARED_WRITE: out << "SHARED WRITE"; break; - case goto_trace_stept::FUNCTION_CALL: out << "FUNCTION CALL"; break; - case goto_trace_stept::FUNCTION_RETURN: out << "FUNCTION RETURN"; break; + case goto_trace_stept::typet::ASSERT: out << "ASSERT"; break; + case goto_trace_stept::typet::ASSUME: out << "ASSUME"; break; + case goto_trace_stept::typet::LOCATION: out << "LOCATION"; break; + case goto_trace_stept::typet::ASSIGNMENT: out << "ASSIGNMENT"; break; + case goto_trace_stept::typet::GOTO: out << "GOTO"; break; + case goto_trace_stept::typet::DECL: out << "DECL"; break; + case goto_trace_stept::typet::DEAD: out << "DEAD"; break; + case goto_trace_stept::typet::OUTPUT: out << "OUTPUT"; break; + case goto_trace_stept::typet::INPUT: out << "INPUT"; break; + case goto_trace_stept::typet::ATOMIC_BEGIN: out << "ATOMC_BEGIN"; break; + case goto_trace_stept::typet::ATOMIC_END: out << "ATOMIC_END"; break; + case goto_trace_stept::typet::SHARED_READ: out << "SHARED_READ"; break; + case goto_trace_stept::typet::SHARED_WRITE: out << "SHARED WRITE"; break; + case goto_trace_stept::typet::FUNCTION_CALL: out << "FUNCTION CALL"; break; + case goto_trace_stept::typet::FUNCTION_RETURN: + out << "FUNCTION RETURN"; break; default: - out << "unknown type: " << type << std::endl; + out << "unknown type: " << static_cast(type) << std::endl; assert(false); } - if(type==ASSERT || type==ASSUME || type==GOTO) + if(type==typet::ASSERT || type==typet::ASSUME || type==typet::GOTO) out << " (" << cond_value << ")"; if(hidden) @@ -335,7 +336,7 @@ void show_goto_trace( switch(step.type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: if(!step.cond_value) { out << "\n"; @@ -351,7 +352,7 @@ void show_goto_trace( } break; - case goto_trace_stept::ASSUME: + case goto_trace_stept::typet::ASSUME: if(!step.cond_value) { out << "\n"; @@ -366,13 +367,13 @@ void show_goto_trace( } break; - case goto_trace_stept::LOCATION: + case goto_trace_stept::typet::LOCATION: break; - case goto_trace_stept::GOTO: + case goto_trace_stept::typet::GOTO: break; - case goto_trace_stept::ASSIGNMENT: + case goto_trace_stept::typet::ASSIGNMENT: if(step.pc->is_assign() || step.pc->is_return() || // returns have a lhs! step.pc->is_function_call() || @@ -395,7 +396,7 @@ void show_goto_trace( } break; - case goto_trace_stept::DECL: + case goto_trace_stept::typet::DECL: if(prev_step_nr!=step.step_nr || first_step) { first_step=false; @@ -406,7 +407,7 @@ void show_goto_trace( trace_value(out, ns, step.lhs_object, step.full_lhs, step.full_lhs_value); break; - case goto_trace_stept::OUTPUT: + case goto_trace_stept::typet::OUTPUT: if(step.formatted) { printf_formattert printf_formatter(ns); @@ -436,7 +437,7 @@ void show_goto_trace( } break; - case goto_trace_stept::INPUT: + case goto_trace_stept::typet::INPUT: show_state_header(out, step, step.pc->source_location, step.step_nr); out << " INPUT " << step.io_id << ":"; @@ -456,21 +457,21 @@ void show_goto_trace( out << "\n"; break; - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: - case goto_trace_stept::SPAWN: - case goto_trace_stept::MEMORY_BARRIER: - case goto_trace_stept::ATOMIC_BEGIN: - case goto_trace_stept::ATOMIC_END: - case goto_trace_stept::DEAD: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: + case goto_trace_stept::typet::SPAWN: + case goto_trace_stept::typet::MEMORY_BARRIER: + case goto_trace_stept::typet::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_END: + case goto_trace_stept::typet::DEAD: break; - case goto_trace_stept::CONSTRAINT: + case goto_trace_stept::typet::CONSTRAINT: assert(false); break; - case goto_trace_stept::SHARED_READ: - case goto_trace_stept::SHARED_WRITE: + case goto_trace_stept::typet::SHARED_READ: + case goto_trace_stept::typet::SHARED_WRITE: assert(false); break; diff --git a/src/goto-programs/goto_trace.h b/src/goto-programs/goto_trace.h index dc270863894..7bcbc1077b8 100644 --- a/src/goto-programs/goto_trace.h +++ b/src/goto-programs/goto_trace.h @@ -33,31 +33,48 @@ class goto_trace_stept public: unsigned step_nr; - bool is_assignment() const { return type==ASSIGNMENT; } - bool is_assume() const { return type==ASSUME; } - bool is_assert() const { return type==ASSERT; } - bool is_goto() const { return type==GOTO; } - bool is_constraint() const { return type==CONSTRAINT; } - bool is_function_call() const { return type==FUNCTION_CALL; } - bool is_function_return() const { return type==FUNCTION_RETURN; } - bool is_location() const { return type==LOCATION; } - bool is_output() const { return type==OUTPUT; } - bool is_input() const { return type==INPUT; } - bool is_decl() const { return type==DECL; } - bool is_dead() const { return type==DEAD; } - bool is_shared_read() const { return type==SHARED_READ; } - bool is_shared_write() const { return type==SHARED_WRITE; } - bool is_spawn() const { return type==SPAWN; } - bool is_memory_barrier() const { return type==MEMORY_BARRIER; } - bool is_atomic_begin() const { return type==ATOMIC_BEGIN; } - bool is_atomic_end() const { return type==ATOMIC_END; } - - typedef enum { NONE, ASSIGNMENT, ASSUME, ASSERT, GOTO, - LOCATION, INPUT, OUTPUT, DECL, DEAD, - FUNCTION_CALL, FUNCTION_RETURN, - CONSTRAINT, - SHARED_READ, SHARED_WRITE, - SPAWN, MEMORY_BARRIER, ATOMIC_BEGIN, ATOMIC_END } typet; + bool is_assignment() const { return type==typet::ASSIGNMENT; } + bool is_assume() const { return type==typet::ASSUME; } + bool is_assert() const { return type==typet::ASSERT; } + bool is_goto() const { return type==typet::GOTO; } + bool is_constraint() const { return type==typet::CONSTRAINT; } + bool is_function_call() const { return type==typet::FUNCTION_CALL; } + bool is_function_return() const { return type==typet::FUNCTION_RETURN; } + bool is_location() const { return type==typet::LOCATION; } + bool is_output() const { return type==typet::OUTPUT; } + bool is_input() const { return type==typet::INPUT; } + bool is_decl() const { return type==typet::DECL; } + bool is_dead() const { return type==typet::DEAD; } + bool is_shared_read() const { return type==typet::SHARED_READ; } + bool is_shared_write() const { return type==typet::SHARED_WRITE; } + bool is_spawn() const { return type==typet::SPAWN; } + bool is_memory_barrier() const { return type==typet::MEMORY_BARRIER; } + bool is_atomic_begin() const { return type==typet::ATOMIC_BEGIN; } + bool is_atomic_end() const { return type==typet::ATOMIC_END; } + + enum class typet + { + NONE, + ASSIGNMENT, + ASSUME, + ASSERT, + GOTO, + LOCATION, + INPUT, + OUTPUT, + DECL, + DEAD, + FUNCTION_CALL, + FUNCTION_RETURN, + CONSTRAINT, + SHARED_READ, + SHARED_WRITE, + SPAWN, + MEMORY_BARRIER, + ATOMIC_BEGIN, + ATOMIC_END + }; + typet type; // we may choose to hide a step @@ -67,7 +84,7 @@ class goto_trace_stept bool internal; // we categorize - typedef enum { STATE, ACTUAL_PARAMETER } assignment_typet; + enum class assignment_typet { STATE, ACTUAL_PARAMETER }; assignment_typet assignment_type; goto_programt::const_targett pc; @@ -108,10 +125,10 @@ class goto_trace_stept goto_trace_stept(): step_nr(0), - type(NONE), + type(typet::NONE), hidden(false), internal(false), - assignment_type(STATE), + assignment_type(assignment_typet::STATE), thread_nr(0), cond_value(false), formatted(false) diff --git a/src/goto-programs/graphml_witness.cpp b/src/goto-programs/graphml_witness.cpp index 85bd1eec40f..ae10705e232 100644 --- a/src/goto-programs/graphml_witness.cpp +++ b/src/goto-programs/graphml_witness.cpp @@ -245,7 +245,7 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) goto_tracet::stepst::const_iterator next=it; ++next; if(next!=goto_trace.steps.end() && - next->type==goto_trace_stept::ASSIGNMENT && + next->type==goto_trace_stept::typet::ASSIGNMENT && it->full_lhs==next->full_lhs && it->pc->source_location==next->pc->source_location) { @@ -265,7 +265,7 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) graphml[node].line=source_location.get_line(); graphml[node].thread_nr=it->thread_nr; graphml[node].is_violation= - it->type==goto_trace_stept::ASSERT && !it->cond_value; + it->type==goto_trace_stept::typet::ASSERT && !it->cond_value; graphml[node].has_invariant=false; step_to_node[it->step_nr]=node; @@ -299,9 +299,9 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) switch(it->type) { - case goto_trace_stept::ASSIGNMENT: - case goto_trace_stept::ASSERT: - case goto_trace_stept::GOTO: + case goto_trace_stept::typet::ASSIGNMENT: + case goto_trace_stept::typet::ASSERT: + case goto_trace_stept::typet::GOTO: { xmlt edge("edge"); edge.set_attribute("source", graphml[from].node_name); @@ -317,7 +317,7 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) data_l.data=id2string(graphml[from].line); } - if(it->type==goto_trace_stept::ASSIGNMENT && + if(it->type==goto_trace_stept::typet::ASSIGNMENT && it->lhs_object_value.is_not_nil() && it->full_lhs.is_not_nil()) { @@ -337,7 +337,7 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) val_s.data=id2string(it->pc->source_location.get_function()); } } - else if(it->type==goto_trace_stept::GOTO && + else if(it->type==goto_trace_stept::typet::GOTO && it->pc->is_goto()) { xmlt &val=edge.new_element("data"); @@ -374,22 +374,22 @@ void graphml_witnesst::operator()(const goto_tracet &goto_trace) } break; - case goto_trace_stept::DECL: - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: - case goto_trace_stept::LOCATION: - case goto_trace_stept::ASSUME: - case goto_trace_stept::INPUT: - case goto_trace_stept::OUTPUT: - case goto_trace_stept::SHARED_READ: - case goto_trace_stept::SHARED_WRITE: - case goto_trace_stept::SPAWN: - case goto_trace_stept::MEMORY_BARRIER: - case goto_trace_stept::ATOMIC_BEGIN: - case goto_trace_stept::ATOMIC_END: - case goto_trace_stept::DEAD: - case goto_trace_stept::CONSTRAINT: - case goto_trace_stept::NONE: + case goto_trace_stept::typet::DECL: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: + case goto_trace_stept::typet::LOCATION: + case goto_trace_stept::typet::ASSUME: + case goto_trace_stept::typet::INPUT: + case goto_trace_stept::typet::OUTPUT: + case goto_trace_stept::typet::SHARED_READ: + case goto_trace_stept::typet::SHARED_WRITE: + case goto_trace_stept::typet::SPAWN: + case goto_trace_stept::typet::MEMORY_BARRIER: + case goto_trace_stept::typet::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_END: + case goto_trace_stept::typet::DEAD: + case goto_trace_stept::typet::CONSTRAINT: + case goto_trace_stept::typet::NONE: // ignore break; } @@ -500,9 +500,9 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation) switch(it->type) { - case goto_trace_stept::ASSIGNMENT: - case goto_trace_stept::ASSERT: - case goto_trace_stept::GOTO: + case goto_trace_stept::typet::ASSIGNMENT: + case goto_trace_stept::typet::ASSERT: + case goto_trace_stept::typet::GOTO: { xmlt edge("edge"); edge.set_attribute("source", graphml[from].node_name); @@ -546,22 +546,22 @@ void graphml_witnesst::operator()(const symex_target_equationt &equation) } break; - case goto_trace_stept::DECL: - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: - case goto_trace_stept::LOCATION: - case goto_trace_stept::ASSUME: - case goto_trace_stept::INPUT: - case goto_trace_stept::OUTPUT: - case goto_trace_stept::SHARED_READ: - case goto_trace_stept::SHARED_WRITE: - case goto_trace_stept::SPAWN: - case goto_trace_stept::MEMORY_BARRIER: - case goto_trace_stept::ATOMIC_BEGIN: - case goto_trace_stept::ATOMIC_END: - case goto_trace_stept::DEAD: - case goto_trace_stept::CONSTRAINT: - case goto_trace_stept::NONE: + case goto_trace_stept::typet::DECL: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: + case goto_trace_stept::typet::LOCATION: + case goto_trace_stept::typet::ASSUME: + case goto_trace_stept::typet::INPUT: + case goto_trace_stept::typet::OUTPUT: + case goto_trace_stept::typet::SHARED_READ: + case goto_trace_stept::typet::SHARED_WRITE: + case goto_trace_stept::typet::SPAWN: + case goto_trace_stept::typet::MEMORY_BARRIER: + case goto_trace_stept::typet::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_END: + case goto_trace_stept::typet::DEAD: + case goto_trace_stept::typet::CONSTRAINT: + case goto_trace_stept::typet::NONE: // ignore break; } diff --git a/src/goto-programs/get_goto_model.cpp b/src/goto-programs/initialize_goto_model.cpp similarity index 59% rename from src/goto-programs/get_goto_model.cpp rename to src/goto-programs/initialize_goto_model.cpp index 9e594b37865..52a6caeeba2 100644 --- a/src/goto-programs/get_goto_model.cpp +++ b/src/goto-programs/initialize_goto_model.cpp @@ -18,11 +18,11 @@ Author: Daniel Kroening, kroening@kroening.com #include "goto_convert_functions.h" #include "read_goto_binary.h" -#include "get_goto_model.h" +#include "initialize_goto_model.h" /*******************************************************************\ -Function: get_goto_modelt::operator() +Function: initialize_goto_model Inputs: @@ -32,12 +32,16 @@ Function: get_goto_modelt::operator() \*******************************************************************/ -bool get_goto_modelt::operator()(const cmdlinet &_cmdline) +bool initialize_goto_model( + goto_modelt &goto_model, + const cmdlinet &cmdline, + message_handlert &message_handler) { - const std::vector &files=_cmdline.args; + messaget msg(message_handler); + const std::vector &files=cmdline.args; if(files.empty()) { - error() << "Please provide a program" << eom; + msg.error() << "Please provide a program" << messaget::eom; return true; } @@ -59,7 +63,7 @@ bool get_goto_modelt::operator()(const cmdlinet &_cmdline) { language_filest language_files; - language_files.set_message_handler(get_message_handler()); + language_files.set_message_handler(message_handler); for(const auto &filename : sources) { @@ -71,8 +75,8 @@ bool get_goto_modelt::operator()(const cmdlinet &_cmdline) if(!infile) { - error() << "failed to open input file `" << filename - << '\'' << eom; + msg.error() << "failed to open input file `" << filename + << '\'' << messaget::eom; return true; } @@ -87,38 +91,38 @@ bool get_goto_modelt::operator()(const cmdlinet &_cmdline) if(lf.language==NULL) { - error("failed to figure out type of file", filename); + msg.error("failed to figure out type of file", filename); return true; } languaget &language=*lf.language; - language.set_message_handler(get_message_handler()); - language.get_language_options(_cmdline); + language.set_message_handler(message_handler); + language.get_language_options(cmdline); - status() << "Parsing " << filename << eom; + msg.status() << "Parsing " << filename << messaget::eom; if(language.parse(infile, filename)) { - error() << "PARSING ERROR" << eom; + msg.error() << "PARSING ERROR" << messaget::eom; return true; } lf.get_modules(); } - status() << "Converting" << eom; + msg.status() << "Converting" << messaget::eom; - if(language_files.typecheck(symbol_table)) + if(language_files.typecheck(goto_model.symbol_table)) { - error() << "CONVERSION ERROR" << eom; + msg.error() << "CONVERSION ERROR" << messaget::eom; return true; } if(binaries.empty()) { - if(language_files.final(symbol_table)) + if(language_files.final(goto_model.symbol_table)) { - error() << "CONVERSION ERROR" << eom; + msg.error() << "CONVERSION ERROR" << messaget::eom; return true; } } @@ -126,42 +130,39 @@ bool get_goto_modelt::operator()(const cmdlinet &_cmdline) for(const auto &file : binaries) { - status() << "Reading GOTO program from file" << eom; + msg.status() << "Reading GOTO program from file" << messaget::eom; - if(read_object_and_link(file, *this, get_message_handler())) + if(read_object_and_link(file, goto_model, message_handler)) return true; } if(!binaries.empty()) - config.set_from_symbol_table(symbol_table); + config.set_from_symbol_table(goto_model.symbol_table); - status() << "Generating GOTO Program" << eom; + msg.status() << "Generating GOTO Program" << messaget::eom; - goto_convert(symbol_table, - goto_functions, - get_message_handler()); + goto_convert( + goto_model.symbol_table, + goto_model.goto_functions, + message_handler); } - catch(const char *e) { - error() << e << eom; + msg.error() << e << messaget::eom; return true; } - catch(const std::string e) { - error() << e << eom; + msg.error() << e << messaget::eom; return true; } - catch(int) { return true; } - catch(std::bad_alloc) { - error() << "Out of memory" << eom; + msg.error() << "Out of memory" << messaget::eom; return true; } diff --git a/src/goto-programs/initialize_goto_model.h b/src/goto-programs/initialize_goto_model.h new file mode 100644 index 00000000000..2b4b03615ca --- /dev/null +++ b/src/goto-programs/initialize_goto_model.h @@ -0,0 +1,22 @@ +/*******************************************************************\ + +Module: Initialize a Goto Program + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + +#ifndef CPROVER_GOTO_PROGRAMS_INITIALIZE_GOTO_MODEL_H +#define CPROVER_GOTO_PROGRAMS_INITIALIZE_GOTO_MODEL_H + +#include +#include + +#include "goto_model.h" + +bool initialize_goto_model( + goto_modelt &goto_model, + const cmdlinet &cmdline, + message_handlert &message_handler); + +#endif // CPROVER_GOTO_PROGRAMS_INITIALIZE_GOTO_MODEL_H diff --git a/src/goto-programs/interpreter.cpp b/src/goto-programs/interpreter.cpp index b4cb45ded3e..149f4002651 100644 --- a/src/goto-programs/interpreter.cpp +++ b/src/goto-programs/interpreter.cpp @@ -307,17 +307,17 @@ void interpretert::step() switch(pc->type) { case GOTO: - trace_step.type=goto_trace_stept::GOTO; + trace_step.type=goto_trace_stept::typet::GOTO; execute_goto(); break; case ASSUME: - trace_step.type=goto_trace_stept::ASSUME; + trace_step.type=goto_trace_stept::typet::ASSUME; execute_assume(); break; case ASSERT: - trace_step.type=goto_trace_stept::ASSERT; + trace_step.type=goto_trace_stept::typet::ASSERT; execute_assert(); break; @@ -326,20 +326,20 @@ void interpretert::step() break; case DECL: - trace_step.type=goto_trace_stept::DECL; + trace_step.type=goto_trace_stept::typet::DECL; execute_decl(); break; case SKIP: case LOCATION: - trace_step.type=goto_trace_stept::LOCATION; + trace_step.type=goto_trace_stept::typet::LOCATION; break; case END_FUNCTION: - trace_step.type=goto_trace_stept::FUNCTION_RETURN; + trace_step.type=goto_trace_stept::typet::FUNCTION_RETURN; break; case RETURN: - trace_step.type=goto_trace_stept::FUNCTION_RETURN; + trace_step.type=goto_trace_stept::typet::FUNCTION_RETURN; if(call_stack.empty()) throw "RETURN without call"; // NOLINT(readability/throw) @@ -355,17 +355,17 @@ void interpretert::step() break; case ASSIGN: - trace_step.type=goto_trace_stept::ASSIGNMENT; + trace_step.type=goto_trace_stept::typet::ASSIGNMENT; execute_assign(); break; case FUNCTION_CALL: - trace_step.type=goto_trace_stept::FUNCTION_CALL; + trace_step.type=goto_trace_stept::typet::FUNCTION_CALL; execute_function_call(); break; case START_THREAD: - trace_step.type=goto_trace_stept::SPAWN; + trace_step.type=goto_trace_stept::typet::SPAWN; throw "START_THREAD not yet implemented"; // NOLINT(readability/throw) case END_THREAD: @@ -373,18 +373,18 @@ void interpretert::step() break; case ATOMIC_BEGIN: - trace_step.type=goto_trace_stept::ATOMIC_BEGIN; + trace_step.type=goto_trace_stept::typet::ATOMIC_BEGIN; throw "ATOMIC_BEGIN not yet implemented"; // NOLINT(readability/throw) case ATOMIC_END: - trace_step.type=goto_trace_stept::ATOMIC_END; + trace_step.type=goto_trace_stept::typet::ATOMIC_END; throw "ATOMIC_END not yet implemented"; // NOLINT(readability/throw) case DEAD: - trace_step.type=goto_trace_stept::DEAD; + trace_step.type=goto_trace_stept::typet::DEAD; break; case THROW: - trace_step.type=goto_trace_stept::GOTO; + trace_step.type=goto_trace_stept::typet::GOTO; while(!done && (pc->type!=CATCH)) { if(pc==function->second.body.instructions.end()) diff --git a/src/goto-programs/json_goto_trace.cpp b/src/goto-programs/json_goto_trace.cpp index 3dca95bc93b..20bd46bc7d7 100644 --- a/src/goto-programs/json_goto_trace.cpp +++ b/src/goto-programs/json_goto_trace.cpp @@ -50,7 +50,7 @@ void convert( switch(step.type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: if(!step.cond_value) { irep_idt property_id; @@ -78,8 +78,8 @@ void convert( } break; - case goto_trace_stept::ASSIGNMENT: - case goto_trace_stept::DECL: + case goto_trace_stept::typet::ASSIGNMENT: + case goto_trace_stept::typet::DECL: { irep_idt identifier=step.lhs_object.get_identifier(); json_objectt &json_assignment=dest_array.push_back().make_object(); @@ -123,12 +123,15 @@ void convert( json_assignment["thread"]=json_numbert(std::to_string(step.thread_nr)); json_assignment["assignmentType"]= - json_stringt(step.assignment_type==goto_trace_stept::ACTUAL_PARAMETER? - "actual-parameter":"variable"); + json_stringt( + step.assignment_type== + goto_trace_stept::assignment_typet::ACTUAL_PARAMETER? + "actual-parameter": + "variable"); } break; - case goto_trace_stept::OUTPUT: + case goto_trace_stept::typet::OUTPUT: { json_objectt &json_output=dest_array.push_back().make_object(); @@ -153,7 +156,7 @@ void convert( } break; - case goto_trace_stept::INPUT: + case goto_trace_stept::typet::INPUT: { json_objectt &json_input=dest_array.push_back().make_object(); @@ -178,11 +181,11 @@ void convert( } break; - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: { std::string tag= - (step.type==goto_trace_stept::FUNCTION_CALL)? + (step.type==goto_trace_stept::typet::FUNCTION_CALL)? "function-call":"function-return"; json_objectt &json_call_return=dest_array.push_back().make_object(); diff --git a/src/goto-programs/loop_ids.cpp b/src/goto-programs/loop_ids.cpp index 4d3eedec739..723ffe329aa 100644 --- a/src/goto-programs/loop_ids.cpp +++ b/src/goto-programs/loop_ids.cpp @@ -52,7 +52,7 @@ void show_loop_ids( { switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: { forall_goto_program_instructions(it, goto_program) { @@ -69,7 +69,7 @@ void show_loop_ids( } break; } - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { forall_goto_program_instructions(it, goto_program) { @@ -87,7 +87,7 @@ void show_loop_ids( } break; } - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: assert(false); // use function below } } @@ -97,7 +97,7 @@ void show_loop_ids_json( const goto_programt &goto_program, json_arrayt &loops) { - assert(ui==ui_message_handlert::JSON_UI); // use function above + assert(ui==ui_message_handlert::uit::JSON_UI); // use function above forall_goto_program_instructions(it, goto_program) { @@ -131,12 +131,12 @@ void show_loop_ids( { switch(ui) { - case ui_message_handlert::PLAIN: - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::PLAIN: + case ui_message_handlert::uit::XML_UI: forall_goto_functions(it, goto_functions) show_loop_ids(ui, it->second.body); break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: json_objectt json_result; json_arrayt &loops=json_result["loops"].make_array(); diff --git a/src/goto-programs/property_checker.cpp b/src/goto-programs/property_checker.cpp index 01c8d2f08ae..de790db2dd4 100644 --- a/src/goto-programs/property_checker.cpp +++ b/src/goto-programs/property_checker.cpp @@ -24,10 +24,10 @@ std::string property_checkert::as_string(resultt result) { switch(result) { - case property_checkert::PASS: return "OK"; - case property_checkert::FAIL: return "FAILURE"; - case property_checkert::ERROR: return "ERROR"; - case property_checkert::UNKNOWN: return "UNKNOWN"; + case property_checkert::resultt::PASS: return "OK"; + case property_checkert::resultt::FAIL: return "FAILURE"; + case property_checkert::resultt::ERROR: return "ERROR"; + case property_checkert::resultt::UNKNOWN: return "UNKNOWN"; } return ""; @@ -82,7 +82,7 @@ void property_checkert::initialize_property_map( irep_idt property_id=source_location.get_property_id(); property_statust &property_status=property_map[property_id]; - property_status.result=UNKNOWN; + property_status.result=resultt::UNKNOWN; property_status.location=i_it; } } diff --git a/src/goto-programs/property_checker.h b/src/goto-programs/property_checker.h index 95c209f2430..c6a4dbe40b5 100644 --- a/src/goto-programs/property_checker.h +++ b/src/goto-programs/property_checker.h @@ -26,7 +26,7 @@ class property_checkert:public messaget explicit property_checkert( message_handlert &_message_handler); - typedef enum { PASS, FAIL, ERROR, UNKNOWN } resultt; + enum class resultt { PASS, FAIL, ERROR, UNKNOWN }; static std::string as_string(resultt); diff --git a/src/goto-programs/remove_unreachable.cpp b/src/goto-programs/remove_unreachable.cpp index 38f8e93974a..14f92e97be1 100644 --- a/src/goto-programs/remove_unreachable.cpp +++ b/src/goto-programs/remove_unreachable.cpp @@ -39,10 +39,8 @@ void remove_unreachable(goto_programt &goto_program) t!=goto_program.instructions.end()) { reachable.insert(t); - goto_programt::targetst successors; - goto_program.get_successors(t, successors); - for(const auto &succ : successors) + for(const auto &succ : goto_program.get_successors(t)) working.push(succ); } } diff --git a/src/goto-programs/safety_checker.h b/src/goto-programs/safety_checker.h index f4c4c3694ba..e7f5e0b81ea 100644 --- a/src/goto-programs/safety_checker.h +++ b/src/goto-programs/safety_checker.h @@ -26,7 +26,7 @@ class safety_checkert:public messaget const namespacet &_ns, message_handlert &_message_handler); - typedef enum { SAFE, UNSAFE, ERROR } resultt; + enum class resultt { SAFE, UNSAFE, ERROR }; // check whether all assertions in goto_functions are safe // if UNSAFE, then a trace is returned diff --git a/src/goto-programs/show_goto_functions.cpp b/src/goto-programs/show_goto_functions.cpp index 83eb3434717..2b07d6d6db8 100644 --- a/src/goto-programs/show_goto_functions.cpp +++ b/src/goto-programs/show_goto_functions.cpp @@ -42,21 +42,21 @@ void show_goto_functions( { switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { show_goto_functions_xmlt xml_show_functions(ns); xml_show_functions(goto_functions, std::cout); } break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { show_goto_functions_jsont json_show_functions(ns); json_show_functions(goto_functions, std::cout); } break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: goto_functions.output(ns, std::cout); break; } diff --git a/src/goto-programs/show_properties.cpp b/src/goto-programs/show_properties.cpp index cbbb00225c7..b6b03d1a7a4 100644 --- a/src/goto-programs/show_properties.cpp +++ b/src/goto-programs/show_properties.cpp @@ -53,7 +53,7 @@ void show_properties( switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { // use me instead xmlt xml_property("property"); @@ -71,11 +71,11 @@ void show_properties( } break; - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: assert(false); break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: std::cout << "Property " << property_id << ":" << std::endl; std::cout << " " << ins.source_location << std::endl @@ -189,7 +189,7 @@ void show_properties( ui_message_handlert::uit ui, const goto_functionst &goto_functions) { - if(ui == ui_message_handlert::JSON_UI) + if(ui == ui_message_handlert::uit::JSON_UI) show_properties_json(ns, goto_functions); else for(const auto &fct : goto_functions.function_map) @@ -214,7 +214,7 @@ void show_properties( ui_message_handlert::uit ui) { const namespacet ns(goto_model.symbol_table); - if(ui == ui_message_handlert::JSON_UI) + if(ui == ui_message_handlert::uit::JSON_UI) show_properties_json(ns, goto_model.goto_functions); else show_properties(ns, ui, goto_model.goto_functions); diff --git a/src/goto-programs/show_symbol_table.cpp b/src/goto-programs/show_symbol_table.cpp index 955a444695a..cf24e4677ca 100644 --- a/src/goto-programs/show_symbol_table.cpp +++ b/src/goto-programs/show_symbol_table.cpp @@ -148,11 +148,11 @@ void show_symbol_table( { switch(ui) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: show_symbol_table_plain(goto_model, std::cout); break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: show_symbol_table_xml_ui(); break; diff --git a/src/goto-programs/string_abstraction.cpp b/src/goto-programs/string_abstraction.cpp index 67abff95812..5c7a1868578 100644 --- a/src/goto-programs/string_abstraction.cpp +++ b/src/goto-programs/string_abstraction.cpp @@ -153,15 +153,15 @@ string_abstractiont::string_abstractiont( s.components()[0].set_name("is_zero"); s.components()[0].set_pretty_name("is_zero"); - s.components()[0].type()=build_type(IS_ZERO); + s.components()[0].type()=build_type(whatt::IS_ZERO); s.components()[1].set_name("length"); s.components()[1].set_pretty_name("length"); - s.components()[1].type()=build_type(LENGTH); + s.components()[1].type()=build_type(whatt::LENGTH); s.components()[2].set_name("size"); s.components()[2].set_pretty_name("size"); - s.components()[2].type()=build_type(SIZE); + s.components()[2].type()=build_type(whatt::SIZE); string_struct=s; } @@ -184,9 +184,9 @@ typet string_abstractiont::build_type(whatt what) switch(what) { - case IS_ZERO: type=bool_typet(); break; - case LENGTH: type=size_type(); break; - case SIZE: type=size_type(); break; + case whatt::IS_ZERO: type=bool_typet(); break; + case whatt::LENGTH: type=size_type(); break; + case whatt::SIZE: type=size_type(); break; } return type; @@ -598,11 +598,11 @@ symbol_exprt string_abstractiont::add_dummy_symbol_and_value( { new_symbol.value=struct_exprt(string_struct); new_symbol.value.operands().resize(3); - new_symbol.value.op0()=build_unknown(IS_ZERO, false); - new_symbol.value.op1()=build_unknown(LENGTH, false); + new_symbol.value.op0()=build_unknown(whatt::IS_ZERO, false); + new_symbol.value.op1()=build_unknown(whatt::LENGTH, false); new_symbol.value.op2()=to_array_type(source_type).size().id()==ID_infinity? - build_unknown(SIZE, false):to_array_type(source_type).size(); - make_type(new_symbol.value.op2(), build_type(SIZE)); + build_unknown(whatt::SIZE, false):to_array_type(source_type).size(); + make_type(new_symbol.value.op2(), build_type(whatt::SIZE)); } else new_symbol.value= @@ -832,19 +832,19 @@ void string_abstractiont::replace_string_macros( if(expr.id()=="is_zero_string") { assert(expr.operands().size()==1); - exprt tmp=build(expr.op0(), IS_ZERO, lhs, source_location); + exprt tmp=build(expr.op0(), whatt::IS_ZERO, lhs, source_location); expr.swap(tmp); } else if(expr.id()=="zero_string_length") { assert(expr.operands().size()==1); - exprt tmp=build(expr.op0(), LENGTH, lhs, source_location); + exprt tmp=build(expr.op0(), whatt::LENGTH, lhs, source_location); expr.swap(tmp); } else if(expr.id()=="buffer_size") { assert(expr.operands().size()==1); - exprt tmp=build(expr.op0(), SIZE, false, source_location); + exprt tmp=build(expr.op0(), whatt::SIZE, false, source_location); expr.swap(tmp); } else @@ -888,7 +888,7 @@ exprt string_abstractiont::build( exprt result=member(str_struct, what); - if(what==LENGTH || what==SIZE) + if(what==whatt::LENGTH || what==whatt::SIZE) { // adjust for offset exprt pointer_offset(ID_pointer_offset, size_type()); @@ -1227,12 +1227,12 @@ exprt string_abstractiont::build_unknown(whatt what, bool write) switch(what) { - case IS_ZERO: + case whatt::IS_ZERO: result=false_exprt(); break; - case LENGTH: - case SIZE: + case whatt::LENGTH: + case whatt::SIZE: result=side_effect_expr_nondett(type); break; } @@ -1401,8 +1401,8 @@ bool string_abstractiont::build_symbol_constant( value.operands().resize(3); value.op0()=true_exprt(); - value.op1()=from_integer(zero_length, build_type(LENGTH)); - value.op2()=from_integer(buf_size, build_type(SIZE)); + value.op1()=from_integer(zero_length, build_type(whatt::LENGTH)); + value.op2()=from_integer(buf_size, build_type(whatt::SIZE)); // initialization goto_programt::targett assignment1=initialization.add_instruction(); @@ -1535,7 +1535,7 @@ goto_programt::targett string_abstractiont::abstract_char_assign( exprt new_lhs; if(!build_wrap(i_lhs.array(), new_lhs, true)) { - exprt i2=member(new_lhs, LENGTH); + exprt i2=member(new_lhs, whatt::LENGTH); assert(i2.is_not_nil()); exprt new_length=i_lhs.index(); @@ -1553,10 +1553,10 @@ goto_programt::targett string_abstractiont::abstract_char_assign( exprt new_lhs; if(!build_wrap(ptr.pointer, new_lhs, true)) { - const exprt i2=member(new_lhs, LENGTH); + const exprt i2=member(new_lhs, whatt::LENGTH); assert(i2.is_not_nil()); - make_type(ptr.offset, build_type(LENGTH)); + make_type(ptr.offset, build_type(whatt::LENGTH)); return char_assign( dest, @@ -1564,7 +1564,7 @@ goto_programt::targett string_abstractiont::abstract_char_assign( new_lhs, i2, ptr.offset.is_nil()? - from_integer(0, build_type(LENGTH)): + from_integer(0, build_type(whatt::LENGTH)): ptr.offset); } } @@ -1593,7 +1593,7 @@ goto_programt::targett string_abstractiont::char_assign( { goto_programt tmp; - const exprt i1=member(new_lhs, IS_ZERO); + const exprt i1=member(new_lhs, whatt::IS_ZERO); assert(i1.is_not_nil()); goto_programt::targett assignment1=tmp.add_instruction(); @@ -1753,8 +1753,8 @@ goto_programt::targett string_abstractiont::value_assignments_string_struct( { goto_programt::targett assignment=tmp.add_instruction(ASSIGN); assignment->code=code_assignt( - member(lhs, IS_ZERO), - member(rhs, IS_ZERO)); + member(lhs, whatt::IS_ZERO), + member(rhs, whatt::IS_ZERO)); assignment->code.add_source_location()=target->source_location; assignment->function=target->function; assignment->source_location=target->source_location; @@ -1763,8 +1763,8 @@ goto_programt::targett string_abstractiont::value_assignments_string_struct( { goto_programt::targett assignment=tmp.add_instruction(ASSIGN); assignment->code=code_assignt( - member(lhs, LENGTH), - member(rhs, LENGTH)); + member(lhs, whatt::LENGTH), + member(rhs, whatt::LENGTH)); assignment->code.add_source_location()=target->source_location; assignment->function=target->function; assignment->source_location=target->source_location; @@ -1773,8 +1773,8 @@ goto_programt::targett string_abstractiont::value_assignments_string_struct( { goto_programt::targett assignment=tmp.add_instruction(ASSIGN); assignment->code=code_assignt( - member(lhs, SIZE), - member(rhs, SIZE)); + member(lhs, whatt::SIZE), + member(rhs, whatt::SIZE)); assignment->code.add_source_location()=target->source_location; assignment->function=target->function; assignment->source_location=target->source_location; @@ -1813,9 +1813,9 @@ exprt string_abstractiont::member(const exprt &a, whatt what) switch(what) { - case IS_ZERO: result.set_component_name("is_zero"); break; - case SIZE: result.set_component_name("size"); break; - case LENGTH: result.set_component_name("length"); break; + case whatt::IS_ZERO: result.set_component_name("is_zero"); break; + case whatt::SIZE: result.set_component_name("size"); break; + case whatt::LENGTH: result.set_component_name("length"); break; } return result; diff --git a/src/goto-programs/string_abstraction.h b/src/goto-programs/string_abstraction.h index 2ea2be22da9..ebc716accc3 100644 --- a/src/goto-programs/string_abstraction.h +++ b/src/goto-programs/string_abstraction.h @@ -108,7 +108,7 @@ class string_abstractiont:public messaget goto_programt::targett target, const exprt &lhs, const exprt &rhs); - typedef enum { IS_ZERO, LENGTH, SIZE } whatt; + enum class whatt { IS_ZERO, LENGTH, SIZE }; static typet build_type(whatt what); exprt build( diff --git a/src/goto-programs/string_instrumentation.cpp b/src/goto-programs/string_instrumentation.cpp index d53e2465386..5a6596a97cd 100644 --- a/src/goto-programs/string_instrumentation.cpp +++ b/src/goto-programs/string_instrumentation.cpp @@ -562,7 +562,7 @@ void string_instrumentationt::do_format_string_read( for(const auto &token : token_list) { - if(token.type==format_tokent::STRING) + if(token.type==format_tokent::token_typet::STRING) { const exprt &arg=arguments[argument_start_inx+args]; const typet &arg_type=ns.follow(arg.type()); @@ -591,10 +591,13 @@ void string_instrumentationt::do_format_string_read( } } - if(token.type!=format_tokent::TEXT && - token.type!=format_tokent::UNKNOWN) args++; + if(token.type!=format_tokent::token_typet::TEXT && + token.type!=format_tokent::token_typet::UNKNOWN) args++; - if(find(token.flags.begin(), token.flags.end(), format_tokent::ASTERISK)!= + if(find( + token.flags.begin(), + token.flags.end(), + format_tokent::flag_typet::ASTERISK)!= token.flags.end()) args++; // just eat the additional argument } @@ -674,13 +677,16 @@ void string_instrumentationt::do_format_string_write( for(const auto &token : token_list) { - if(find(token.flags.begin(), token.flags.end(), format_tokent::ASTERISK)!= + if(find( + token.flags.begin(), + token.flags.end(), + format_tokent::flag_typet::ASTERISK)!= token.flags.end()) continue; // asterisk means `ignore this' switch(token.type) { - case format_tokent::STRING: + case format_tokent::token_typet::STRING: { const exprt &argument=arguments[argument_start_inx+args]; const typet &arg_type=ns.follow(argument.type()); @@ -729,8 +735,8 @@ void string_instrumentationt::do_format_string_write( args++; break; } - case format_tokent::TEXT: - case format_tokent::UNKNOWN: + case format_tokent::token_typet::TEXT: + case format_tokent::token_typet::UNKNOWN: { // nothing break; diff --git a/src/goto-programs/vcd_goto_trace.cpp b/src/goto-programs/vcd_goto_trace.cpp index 3fe1ebbb660..9a3bbf443f7 100644 --- a/src/goto-programs/vcd_goto_trace.cpp +++ b/src/goto-programs/vcd_goto_trace.cpp @@ -149,7 +149,7 @@ void output_vcd( { switch(step.type) { - case goto_trace_stept::ASSIGNMENT: + case goto_trace_stept::typet::ASSIGNMENT: { irep_idt identifier=step.lhs_object.get_identifier(); const typet &type=step.lhs_object.type(); diff --git a/src/goto-programs/wp.cpp b/src/goto-programs/wp.cpp index 7f10498810d..4290734e2f5 100644 --- a/src/goto-programs/wp.cpp +++ b/src/goto-programs/wp.cpp @@ -101,7 +101,7 @@ Function: aliasing \*******************************************************************/ -typedef enum { A_MAY, A_MUST, A_MUSTNOT } aliasingt; +enum class aliasingt { A_MAY, A_MUST, A_MUSTNOT }; aliasingt aliasing( const exprt &e1, const exprt &e2, @@ -122,20 +122,20 @@ aliasingt aliasing( // fairly radical. Ignores struct prefixes and the like. if(!base_type_eq(e1.type(), e2.type(), ns)) - return A_MUSTNOT; + return aliasingt::A_MUSTNOT; // syntactically the same? if(e1==e2) - return A_MUST; + return aliasingt::A_MUST; // the trivial case first if(e1.id()==ID_symbol && e2.id()==ID_symbol) { if(to_symbol_expr(e1).get_identifier()== to_symbol_expr(e2).get_identifier()) - return A_MUST; + return aliasingt::A_MUST; else - return A_MUSTNOT; + return aliasingt::A_MUSTNOT; } // an array or struct will never alias with a variable, @@ -143,16 +143,16 @@ aliasingt aliasing( if(e1.id()==ID_index || e1.id()==ID_struct) if(e2.id()!=ID_dereference && e1.id()!=e2.id()) - return A_MUSTNOT; + return aliasingt::A_MUSTNOT; if(e2.id()==ID_index || e2.id()==ID_struct) if(e2.id()!=ID_dereference && e1.id()!=e2.id()) - return A_MUSTNOT; + return aliasingt::A_MUSTNOT; // we give up, and say it may // (could do much more here) - return A_MAY; + return aliasingt::A_MAY; } /*******************************************************************\ @@ -187,11 +187,11 @@ void substitute_rec( // could these be possible the same? switch(aliasing(dest, what, ns)) { - case A_MUST: + case aliasingt::A_MUST: dest=by; // they are always the same break; - case A_MAY: + case aliasingt::A_MAY: { // consider possible aliasing between 'what' and 'dest' exprt what_address=address_of_exprt(what); @@ -210,7 +210,7 @@ void substitute_rec( return; } - case A_MUSTNOT: + case aliasingt::A_MUSTNOT: // nothing to do break; } diff --git a/src/goto-programs/xml_goto_trace.cpp b/src/goto-programs/xml_goto_trace.cpp index 6469b2a2132..8b1bdb0e885 100644 --- a/src/goto-programs/xml_goto_trace.cpp +++ b/src/goto-programs/xml_goto_trace.cpp @@ -49,7 +49,7 @@ void convert( switch(step.type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: if(!step.cond_value) { irep_idt property_id; @@ -76,8 +76,8 @@ void convert( } break; - case goto_trace_stept::ASSIGNMENT: - case goto_trace_stept::DECL: + case goto_trace_stept::typet::ASSIGNMENT: + case goto_trace_stept::typet::DECL: { irep_idt identifier=step.lhs_object.get_identifier(); xmlt &xml_assignment=dest.new_element("assignment"); @@ -128,7 +128,8 @@ void convert( xml_assignment.set_attribute("step_nr", std::to_string(step.step_nr)); xml_assignment.set_attribute("assignment_type", - step.assignment_type==goto_trace_stept::ACTUAL_PARAMETER? + step.assignment_type== + goto_trace_stept::assignment_typet::ACTUAL_PARAMETER? "actual_parameter":"state"); if(step.lhs_object_value.is_not_nil()) @@ -137,7 +138,7 @@ void convert( } break; - case goto_trace_stept::OUTPUT: + case goto_trace_stept::typet::OUTPUT: { printf_formattert printf_formatter(ns); printf_formatter(id2string(step.format_string), step.io_args); @@ -162,7 +163,7 @@ void convert( } break; - case goto_trace_stept::INPUT: + case goto_trace_stept::typet::INPUT: { xmlt &xml_input=dest.new_element("input"); xml_input.new_element("input_id").data=id2string(step.io_id); @@ -183,11 +184,11 @@ void convert( } break; - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: { std::string tag= - (step.type==goto_trace_stept::FUNCTION_CALL)? + (step.type==goto_trace_stept::typet::FUNCTION_CALL)? "function_call":"function_return"; xmlt &xml_call_return=dest.new_element(tag); diff --git a/src/goto-symex/build_goto_trace.cpp b/src/goto-symex/build_goto_trace.cpp index 081fcbe55d3..29ba8e30236 100644 --- a/src/goto-symex/build_goto_trace.cpp +++ b/src/goto-symex/build_goto_trace.cpp @@ -197,8 +197,8 @@ void update_internal_field( } // set internal field to input and output steps - if(goto_trace_step.type==goto_trace_stept::OUTPUT || - goto_trace_step.type==goto_trace_stept::INPUT) + if(goto_trace_step.type==goto_trace_stept::typet::OUTPUT || + goto_trace_step.type==goto_trace_stept::typet::INPUT) { goto_trace_step.internal=true; } @@ -300,8 +300,10 @@ void build_goto_trace( // drop PHI and GUARD assignments altogether if(it->is_assignment() && - (SSA_step.assignment_type==symex_target_equationt::PHI || - SSA_step.assignment_type==symex_target_equationt::GUARD)) + (SSA_step.assignment_type== + symex_target_equationt::assignment_typet::PHI || + SSA_step.assignment_type== + symex_target_equationt::assignment_typet::GUARD)) continue; goto_tracet::stepst &steps=time_map[current_time]; @@ -330,10 +332,12 @@ void build_goto_trace( goto_trace_step.assignment_type= (it->is_assignment()&& - (SSA_step.assignment_type==symex_targett::VISIBLE_ACTUAL_PARAMETER || - SSA_step.assignment_type==symex_targett::HIDDEN_ACTUAL_PARAMETER))? - goto_trace_stept::ACTUAL_PARAMETER: - goto_trace_stept::STATE; + (SSA_step.assignment_type== + symex_targett::assignment_typet::VISIBLE_ACTUAL_PARAMETER || + SSA_step.assignment_type== + symex_targett::assignment_typet::HIDDEN_ACTUAL_PARAMETER))? + goto_trace_stept::assignment_typet::ACTUAL_PARAMETER: + goto_trace_stept::assignment_typet::STATE; if(SSA_step.original_full_lhs.is_not_nil()) goto_trace_step.full_lhs= diff --git a/src/goto-symex/goto_symex_state.cpp b/src/goto-symex/goto_symex_state.cpp index e1a8938d823..7b9b206902b 100644 --- a/src/goto-symex/goto_symex_state.cpp +++ b/src/goto-symex/goto_symex_state.cpp @@ -759,7 +759,7 @@ bool goto_symex_statet::l2_thread_read_encoding( ssa_l1.get_original_expr(), tmp, source, - symex_targett::PHI); + symex_targett::assignment_typet::PHI); set_ssa_indices(ssa_l1, ns, L2); expr=ssa_l1; diff --git a/src/goto-symex/goto_symex_state.h b/src/goto-symex/goto_symex_state.h index 292dec478c7..4560d762d25 100644 --- a/src/goto-symex/goto_symex_state.h +++ b/src/goto-symex/goto_symex_state.h @@ -142,7 +142,7 @@ class goto_symex_statet } } propagation; - typedef enum { L0=0, L1=1, L2=2 } levelt; + enum levelt { L0=0, L1=1, L2=2 }; // performs renaming _up to_ the given level void rename(exprt &expr, const namespacet &ns, levelt level=L2); diff --git a/src/goto-symex/partial_order_concurrency.cpp b/src/goto-symex/partial_order_concurrency.cpp index 7ec03afab34..568a799b098 100644 --- a/src/goto-symex/partial_order_concurrency.cpp +++ b/src/goto-symex/partial_order_concurrency.cpp @@ -96,7 +96,7 @@ void partial_order_concurrencyt::add_init_writes( // no SSA L2 index, thus nondet value SSA_step.ssa_lhs=e_it->ssa_lhs; SSA_step.ssa_lhs.remove_level_2(); - SSA_step.type=goto_trace_stept::SHARED_WRITE; + SSA_step.type=goto_trace_stept::typet::SHARED_WRITE; SSA_step.atomic_section_id=0; SSA_step.source=e_it->source; } diff --git a/src/goto-symex/partial_order_concurrency.h b/src/goto-symex/partial_order_concurrency.h index c18c8925d42..86817ba5360 100644 --- a/src/goto-symex/partial_order_concurrency.h +++ b/src/goto-symex/partial_order_concurrency.h @@ -24,13 +24,13 @@ class partial_order_concurrencyt:public messaget typedef eventst::const_iterator event_it; // the name of a clock variable for a shared read/write - typedef enum + enum axiomt { AX_SC_PER_LOCATION=1, AX_NO_THINAIR=2, AX_OBSERVATION=4, AX_PROPAGATION=8 - } axiomt; + }; static irep_idt rw_clock_id( event_it e, @@ -191,14 +191,14 @@ class partial_order_concurrencyt { public: // the is-acyclic checks - typedef enum + enum acyclict { AC_UNIPROC=0, AC_THINAIR=1, AC_GHB=2, AC_PPC_WS_FENCE=3, AC_N_AXIOMS=4 - } acyclict; + }; typedef abstract_eventt evtt; typedef std::map > adj_matrixt; diff --git a/src/goto-symex/slice.cpp b/src/goto-symex/slice.cpp index ab377e2d9c9..483e76211bc 100644 --- a/src/goto-symex/slice.cpp +++ b/src/goto-symex/slice.cpp @@ -113,50 +113,50 @@ void symex_slicet::slice(symex_target_equationt::SSA_stept &SSA_step) switch(SSA_step.type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: get_symbols(SSA_step.cond_expr); break; - case goto_trace_stept::ASSUME: + case goto_trace_stept::typet::ASSUME: get_symbols(SSA_step.cond_expr); break; - case goto_trace_stept::GOTO: + case goto_trace_stept::typet::GOTO: get_symbols(SSA_step.cond_expr); break; - case goto_trace_stept::LOCATION: + case goto_trace_stept::typet::LOCATION: // ignore break; - case goto_trace_stept::ASSIGNMENT: + case goto_trace_stept::typet::ASSIGNMENT: slice_assignment(SSA_step); break; - case goto_trace_stept::DECL: + case goto_trace_stept::typet::DECL: slice_decl(SSA_step); break; - case goto_trace_stept::OUTPUT: - case goto_trace_stept::INPUT: + case goto_trace_stept::typet::OUTPUT: + case goto_trace_stept::typet::INPUT: break; - case goto_trace_stept::DEAD: + case goto_trace_stept::typet::DEAD: // ignore for now break; - case goto_trace_stept::CONSTRAINT: - case goto_trace_stept::SHARED_READ: - case goto_trace_stept::SHARED_WRITE: - case goto_trace_stept::ATOMIC_BEGIN: - case goto_trace_stept::ATOMIC_END: - case goto_trace_stept::SPAWN: - case goto_trace_stept::MEMORY_BARRIER: + case goto_trace_stept::typet::CONSTRAINT: + case goto_trace_stept::typet::SHARED_READ: + case goto_trace_stept::typet::SHARED_WRITE: + case goto_trace_stept::typet::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_END: + case goto_trace_stept::typet::SPAWN: + case goto_trace_stept::typet::MEMORY_BARRIER: // ignore for now break; - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: // ignore for now break; @@ -248,39 +248,39 @@ void symex_slicet::collect_open_variables( switch(SSA_step.type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: get_symbols(SSA_step.cond_expr); break; - case goto_trace_stept::ASSUME: + case goto_trace_stept::typet::ASSUME: get_symbols(SSA_step.cond_expr); break; - case goto_trace_stept::LOCATION: + case goto_trace_stept::typet::LOCATION: // ignore break; - case goto_trace_stept::ASSIGNMENT: + case goto_trace_stept::typet::ASSIGNMENT: get_symbols(SSA_step.ssa_rhs); lhs.insert(SSA_step.ssa_lhs.get_identifier()); break; - case goto_trace_stept::OUTPUT: - case goto_trace_stept::INPUT: - case goto_trace_stept::DEAD: - case goto_trace_stept::NONE: + case goto_trace_stept::typet::OUTPUT: + case goto_trace_stept::typet::INPUT: + case goto_trace_stept::typet::DEAD: + case goto_trace_stept::typet::NONE: break; - case goto_trace_stept::DECL: - case goto_trace_stept::FUNCTION_CALL: - case goto_trace_stept::FUNCTION_RETURN: - case goto_trace_stept::CONSTRAINT: - case goto_trace_stept::SHARED_READ: - case goto_trace_stept::SHARED_WRITE: - case goto_trace_stept::ATOMIC_BEGIN: - case goto_trace_stept::ATOMIC_END: - case goto_trace_stept::SPAWN: - case goto_trace_stept::MEMORY_BARRIER: + case goto_trace_stept::typet::DECL: + case goto_trace_stept::typet::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_RETURN: + case goto_trace_stept::typet::CONSTRAINT: + case goto_trace_stept::typet::SHARED_READ: + case goto_trace_stept::typet::SHARED_WRITE: + case goto_trace_stept::typet::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_END: + case goto_trace_stept::typet::SPAWN: + case goto_trace_stept::typet::MEMORY_BARRIER: // ignore for now break; diff --git a/src/goto-symex/slice_by_trace.cpp b/src/goto-symex/slice_by_trace.cpp index 096edf8ae38..07a4f81b96a 100644 --- a/src/goto-symex/slice_by_trace.cpp +++ b/src/goto-symex/slice_by_trace.cpp @@ -119,7 +119,7 @@ void symex_slice_by_tracet::slice_by_trace( SSA_step.guard=t_guard.as_expr(); SSA_step.ssa_lhs.make_nil(); SSA_step.cond_expr.swap(trace_condition); - SSA_step.type=goto_trace_stept::ASSUME; + SSA_step.type=goto_trace_stept::typet::ASSUME; SSA_step.source=empty_source; assign_merges(equation); // Now add the merge variable assignments to eqn @@ -630,10 +630,10 @@ void symex_slice_by_tracet::assign_merges( SSA_step.guard=t_guard.as_expr(); SSA_step.ssa_lhs=merge_sym; SSA_step.ssa_rhs.swap(merge_copy); - SSA_step.assignment_type=symex_targett::HIDDEN; + SSA_step.assignment_type=symex_targett::assignment_typet::HIDDEN; SSA_step.cond_expr=equal_exprt(SSA_step.ssa_lhs, SSA_step.ssa_rhs); - SSA_step.type=goto_trace_stept::ASSIGNMENT; + SSA_step.type=goto_trace_stept::typet::ASSIGNMENT; SSA_step.source=empty_source; } } diff --git a/src/goto-symex/symex_assign.cpp b/src/goto-symex/symex_assign.cpp index 795e1240f32..61b6ad28488 100644 --- a/src/goto-symex/symex_assign.cpp +++ b/src/goto-symex/symex_assign.cpp @@ -93,21 +93,21 @@ void goto_symext::symex_assign( } else { - assignment_typet assignment_type=symex_targett::STATE; + assignment_typet assignment_type=symex_targett::assignment_typet::STATE; // Let's hide return value assignments. if(lhs.id()==ID_symbol && id2string(to_symbol_expr(lhs).get_identifier()).find( "#return_value!")!=std::string::npos) - assignment_type=symex_targett::HIDDEN; + assignment_type=symex_targett::assignment_typet::HIDDEN; // We hide if we are in a hidden function. if(state.top().hidden_function) - assignment_type=symex_targett::HIDDEN; + assignment_type=symex_targett::assignment_typet::HIDDEN; // We hide if we are executing a hidden instruction. if(state.source.pc->source_location.get_hide()) - assignment_type=symex_targett::HIDDEN; + assignment_type=symex_targett::assignment_typet::HIDDEN; guardt guard; // NOT the state guard! symex_assign_rec(state, lhs, nil_exprt(), rhs, guard, assignment_type); @@ -303,7 +303,7 @@ void goto_symext::symex_assign_symbol( // do the assignment const symbolt &symbol=ns.lookup(ssa_lhs.get_original_expr()); if(symbol.is_auxiliary) - assignment_type=symex_targett::HIDDEN; + assignment_type=symex_targett::assignment_typet::HIDDEN; target.assignment( tmp_guard.as_expr(), diff --git a/src/goto-symex/symex_decl.cpp b/src/goto-symex/symex_decl.cpp index b0b490b42b9..4d5e162a4d9 100644 --- a/src/goto-symex/symex_decl.cpp +++ b/src/goto-symex/symex_decl.cpp @@ -120,7 +120,9 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr) state.guard.as_expr(), ssa, state.source, - hidden?symex_targett::HIDDEN:symex_targett::STATE); + hidden? + symex_targett::assignment_typet::HIDDEN: + symex_targett::assignment_typet::STATE); assert(state.dirty); if((*state.dirty)(ssa.get_object_name()) && diff --git a/src/goto-symex/symex_dereference.cpp b/src/goto-symex/symex_dereference.cpp index 1ef9ac69962..513655f44b9 100644 --- a/src/goto-symex/symex_dereference.cpp +++ b/src/goto-symex/symex_dereference.cpp @@ -302,7 +302,9 @@ void goto_symext::dereference_rec( dereference.dereference( tmp1, guard, - write?value_set_dereferencet::WRITE:value_set_dereferencet::READ); + write? + value_set_dereferencet::modet::WRITE: + value_set_dereferencet::modet::READ); // std::cout << "**** " << from_expr(ns, "", tmp2) << std::endl; expr.swap(tmp2); diff --git a/src/goto-symex/symex_goto.cpp b/src/goto-symex/symex_goto.cpp index 8b36cfc26af..0f6328bdc44 100644 --- a/src/goto-symex/symex_goto.cpp +++ b/src/goto-symex/symex_goto.cpp @@ -184,7 +184,7 @@ void goto_symext::symex_goto(statet &state) new_lhs, new_lhs, guard_symbol_expr, new_rhs, original_source, - symex_targett::GUARD); + symex_targett::assignment_typet::GUARD); guard_expr=guard_symbol_expr; guard_expr.make_not(); @@ -437,7 +437,7 @@ void goto_symext::phi_function( new_lhs, new_lhs, new_lhs.get_original_expr(), rhs, dest_state.source, - symex_targett::PHI); + symex_targett::assignment_typet::PHI); } } diff --git a/src/goto-symex/symex_start_thread.cpp b/src/goto-symex/symex_start_thread.cpp index eb4687a1fb9..67cb147964c 100644 --- a/src/goto-symex/symex_start_thread.cpp +++ b/src/goto-symex/symex_start_thread.cpp @@ -94,7 +94,12 @@ void goto_symext::symex_start_thread(statet &state) const bool record_events=state.record_events; state.record_events=false; symex_assign_symbol( - state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); + state, + lhs, + nil_exprt(), + rhs, + guard, + symex_targett::assignment_typet::HIDDEN); state.record_events=record_events; } @@ -122,6 +127,11 @@ void goto_symext::symex_start_thread(statet &state) guardt guard; symex_assign_symbol( - state, lhs, nil_exprt(), rhs, guard, symex_targett::HIDDEN); + state, + lhs, + nil_exprt(), + rhs, + guard, + symex_targett::assignment_typet::HIDDEN); } } diff --git a/src/goto-symex/symex_target.h b/src/goto-symex/symex_target.h index e3b94fc15b6..2aae977f71f 100644 --- a/src/goto-symex/symex_target.h +++ b/src/goto-symex/symex_target.h @@ -51,10 +51,10 @@ class symex_targett } }; - typedef enum + enum class assignment_typet { STATE, HIDDEN, VISIBLE_ACTUAL_PARAMETER, HIDDEN_ACTUAL_PARAMETER, PHI, GUARD - } assignment_typet; + }; // read event virtual void shared_read( diff --git a/src/goto-symex/symex_target_equation.cpp b/src/goto-symex/symex_target_equation.cpp index 3cf9612e556..e522affb3ac 100644 --- a/src/goto-symex/symex_target_equation.cpp +++ b/src/goto-symex/symex_target_equation.cpp @@ -74,7 +74,7 @@ void symex_target_equationt::shared_read( SSA_step.guard=guard; SSA_step.ssa_lhs=ssa_object; - SSA_step.type=goto_trace_stept::SHARED_READ; + SSA_step.type=goto_trace_stept::typet::SHARED_READ; SSA_step.atomic_section_id=atomic_section_id; SSA_step.source=source; @@ -104,7 +104,7 @@ void symex_target_equationt::shared_write( SSA_step.guard=guard; SSA_step.ssa_lhs=ssa_object; - SSA_step.type=goto_trace_stept::SHARED_WRITE; + SSA_step.type=goto_trace_stept::typet::SHARED_WRITE; SSA_step.atomic_section_id=atomic_section_id; SSA_step.source=source; @@ -130,7 +130,7 @@ void symex_target_equationt::spawn( SSA_steps.push_back(SSA_stept()); SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::SPAWN; + SSA_step.type=goto_trace_stept::typet::SPAWN; SSA_step.source=source; merge_ireps(SSA_step); @@ -155,7 +155,7 @@ void symex_target_equationt::memory_barrier( SSA_steps.push_back(SSA_stept()); SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::MEMORY_BARRIER; + SSA_step.type=goto_trace_stept::typet::MEMORY_BARRIER; SSA_step.source=source; merge_ireps(SSA_step); @@ -181,7 +181,7 @@ void symex_target_equationt::atomic_begin( SSA_steps.push_back(SSA_stept()); SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::ATOMIC_BEGIN; + SSA_step.type=goto_trace_stept::typet::ATOMIC_BEGIN; SSA_step.atomic_section_id=atomic_section_id; SSA_step.source=source; @@ -208,7 +208,7 @@ void symex_target_equationt::atomic_end( SSA_steps.push_back(SSA_stept()); SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::ATOMIC_END; + SSA_step.type=goto_trace_stept::typet::ATOMIC_END; SSA_step.atomic_section_id=atomic_section_id; SSA_step.source=source; @@ -249,9 +249,9 @@ void symex_target_equationt::assignment( SSA_step.assignment_type=assignment_type; SSA_step.cond_expr=equal_exprt(SSA_step.ssa_lhs, SSA_step.ssa_rhs); - SSA_step.type=goto_trace_stept::ASSIGNMENT; - SSA_step.hidden=(assignment_type!=STATE && - assignment_type!=VISIBLE_ACTUAL_PARAMETER); + SSA_step.type=goto_trace_stept::typet::ASSIGNMENT; + SSA_step.hidden=(assignment_type!=assignment_typet::STATE && + assignment_type!=assignment_typet::VISIBLE_ACTUAL_PARAMETER); SSA_step.source=source; merge_ireps(SSA_step); @@ -284,9 +284,9 @@ void symex_target_equationt::decl( SSA_step.ssa_lhs=ssa_lhs; SSA_step.ssa_full_lhs=ssa_lhs; SSA_step.original_full_lhs=ssa_lhs.get_original_expr(); - SSA_step.type=goto_trace_stept::DECL; + SSA_step.type=goto_trace_stept::typet::DECL; SSA_step.source=source; - SSA_step.hidden=(assignment_type!=STATE); + SSA_step.hidden=(assignment_type!=assignment_typet::STATE); // the condition is trivially true, and only // there so we see the symbols @@ -335,7 +335,7 @@ void symex_target_equationt::location( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::LOCATION; + SSA_step.type=goto_trace_stept::typet::LOCATION; SSA_step.source=source; merge_ireps(SSA_step); @@ -362,7 +362,7 @@ void symex_target_equationt::function_call( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::FUNCTION_CALL; + SSA_step.type=goto_trace_stept::typet::FUNCTION_CALL; SSA_step.source=source; SSA_step.identifier=identifier; @@ -390,7 +390,7 @@ void symex_target_equationt::function_return( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::FUNCTION_RETURN; + SSA_step.type=goto_trace_stept::typet::FUNCTION_RETURN; SSA_step.source=source; SSA_step.identifier=identifier; @@ -419,7 +419,7 @@ void symex_target_equationt::output( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::OUTPUT; + SSA_step.type=goto_trace_stept::typet::OUTPUT; SSA_step.source=source; SSA_step.io_args=args; SSA_step.io_id=output_id; @@ -450,7 +450,7 @@ void symex_target_equationt::output_fmt( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::OUTPUT; + SSA_step.type=goto_trace_stept::typet::OUTPUT; SSA_step.source=source; SSA_step.io_args=args; SSA_step.io_id=output_id; @@ -482,7 +482,7 @@ void symex_target_equationt::input( SSA_stept &SSA_step=SSA_steps.back(); SSA_step.guard=guard; - SSA_step.type=goto_trace_stept::INPUT; + SSA_step.type=goto_trace_stept::typet::INPUT; SSA_step.source=source; SSA_step.io_args=args; SSA_step.io_id=input_id; @@ -512,7 +512,7 @@ void symex_target_equationt::assumption( SSA_step.guard=guard; SSA_step.cond_expr=cond; - SSA_step.type=goto_trace_stept::ASSUME; + SSA_step.type=goto_trace_stept::typet::ASSUME; SSA_step.source=source; merge_ireps(SSA_step); @@ -541,7 +541,7 @@ void symex_target_equationt::assertion( SSA_step.guard=guard; SSA_step.cond_expr=cond; - SSA_step.type=goto_trace_stept::ASSERT; + SSA_step.type=goto_trace_stept::typet::ASSERT; SSA_step.source=source; SSA_step.comment=msg; @@ -570,7 +570,7 @@ void symex_target_equationt::goto_instruction( SSA_step.guard=guard; SSA_step.cond_expr=cond; - SSA_step.type=goto_trace_stept::GOTO; + SSA_step.type=goto_trace_stept::typet::GOTO; SSA_step.source=source; merge_ireps(SSA_step); @@ -599,7 +599,7 @@ void symex_target_equationt::constraint( SSA_step.guard=true_exprt(); SSA_step.cond_expr=cond; - SSA_step.type=goto_trace_stept::CONSTRAINT; + SSA_step.type=goto_trace_stept::typet::CONSTRAINT; SSA_step.source=source; SSA_step.comment=msg; @@ -981,32 +981,38 @@ void symex_target_equationt::SSA_stept::output( switch(type) { - case goto_trace_stept::ASSERT: + case goto_trace_stept::typet::ASSERT: out << "ASSERT " << from_expr(ns, "", cond_expr) << std::endl; break; - case goto_trace_stept::ASSUME: + case goto_trace_stept::typet::ASSUME: out << "ASSUME " << from_expr(ns, "", cond_expr) << std::endl; break; - case goto_trace_stept::LOCATION: + case goto_trace_stept::typet::LOCATION: out << "LOCATION" << std::endl; break; - case goto_trace_stept::INPUT: + case goto_trace_stept::typet::INPUT: out << "INPUT" << std::endl; break; - case goto_trace_stept::OUTPUT: + case goto_trace_stept::typet::OUTPUT: out << "OUTPUT" << std::endl; break; - case goto_trace_stept::DECL: + case goto_trace_stept::typet::DECL: out << "DECL" << std::endl; out << from_expr(ns, "", ssa_lhs) << std::endl; break; - case goto_trace_stept::ASSIGNMENT: + case goto_trace_stept::typet::ASSIGNMENT: out << "ASSIGNMENT ("; switch(assignment_type) { - case HIDDEN: out << "HIDDEN"; break; - case STATE: out << "STATE"; break; - case VISIBLE_ACTUAL_PARAMETER: out << "VISIBLE_ACTUAL_PARAMETER"; break; - case HIDDEN_ACTUAL_PARAMETER: out << "HIDDEN_ACTUAL_PARAMETER"; break; - case PHI: out << "PHI"; break; - case GUARD: out << "GUARD"; break; + case assignment_typet::HIDDEN: + out << "HIDDEN"; break; + case assignment_typet::STATE: + out << "STATE"; break; + case assignment_typet::VISIBLE_ACTUAL_PARAMETER: + out << "VISIBLE_ACTUAL_PARAMETER"; break; + case assignment_typet::HIDDEN_ACTUAL_PARAMETER: + out << "HIDDEN_ACTUAL_PARAMETER"; break; + case assignment_typet::PHI: + out << "PHI"; break; + case assignment_typet::GUARD: + out << "GUARD"; break; default: { } @@ -1015,27 +1021,27 @@ void symex_target_equationt::SSA_stept::output( out << ")" << std::endl; break; - case goto_trace_stept::DEAD: + case goto_trace_stept::typet::DEAD: out << "DEAD" << std::endl; break; - case goto_trace_stept::FUNCTION_CALL: + case goto_trace_stept::typet::FUNCTION_CALL: out << "FUNCTION_CALL" << std::endl; break; - case goto_trace_stept::FUNCTION_RETURN: + case goto_trace_stept::typet::FUNCTION_RETURN: out << "FUNCTION_RETURN" << std::endl; break; - case goto_trace_stept::CONSTRAINT: + case goto_trace_stept::typet::CONSTRAINT: out << "CONSTRAINT" << std::endl; break; - case goto_trace_stept::SHARED_READ: + case goto_trace_stept::typet::SHARED_READ: out << "SHARED READ" << std::endl; break; - case goto_trace_stept::SHARED_WRITE: + case goto_trace_stept::typet::SHARED_WRITE: out << "SHARED WRITE" << std::endl; break; - case goto_trace_stept::ATOMIC_BEGIN: + case goto_trace_stept::typet::ATOMIC_BEGIN: out << "ATOMIC_BEGIN" << std::endl; break; - case goto_trace_stept::ATOMIC_END: + case goto_trace_stept::typet::ATOMIC_END: out << "AUTOMIC_END" << std::endl; break; - case goto_trace_stept::SPAWN: + case goto_trace_stept::typet::SPAWN: out << "SPAWN" << std::endl; break; - case goto_trace_stept::MEMORY_BARRIER: + case goto_trace_stept::typet::MEMORY_BARRIER: out << "MEMORY_BARRIER" << std::endl; break; - case goto_trace_stept::GOTO: + case goto_trace_stept::typet::GOTO: out << "IF " << from_expr(ns, "", cond_expr) << " GOTO" << std::endl; break; default: assert(false); diff --git a/src/goto-symex/symex_target_equation.h b/src/goto-symex/symex_target_equation.h index 855b44ee0bb..e7f0274aac1 100644 --- a/src/goto-symex/symex_target_equation.h +++ b/src/goto-symex/symex_target_equation.h @@ -170,31 +170,38 @@ class symex_target_equationt:public symex_targett sourcet source; goto_trace_stept::typet type; - bool is_assert() const { return type==goto_trace_stept::ASSERT; } - bool is_assume() const { return type==goto_trace_stept::ASSUME; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_assignment() const { return type==goto_trace_stept::ASSIGNMENT; } - bool is_goto() const { return type==goto_trace_stept::GOTO; } + bool is_assert() const { return type==goto_trace_stept::typet::ASSERT; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_constraint() const { return type==goto_trace_stept::CONSTRAINT; } - bool is_location() const { return type==goto_trace_stept::LOCATION; } - bool is_output() const { return type==goto_trace_stept::OUTPUT; } - bool is_decl() const { return type==goto_trace_stept::DECL; } + bool is_assume() const { return type==goto_trace_stept::typet::ASSUME; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_function_call() const { return type==goto_trace_stept::FUNCTION_CALL; } + bool is_assignment() const { return type==goto_trace_stept::typet::ASSIGNMENT; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_function_return() const { return type==goto_trace_stept::FUNCTION_RETURN; } + bool is_goto() const { return type==goto_trace_stept::typet::GOTO; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_shared_read() const { return type==goto_trace_stept::SHARED_READ; } + bool is_constraint() const { return type==goto_trace_stept::typet::CONSTRAINT; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_shared_write() const { return type==goto_trace_stept::SHARED_WRITE; } - bool is_spawn() const { return type==goto_trace_stept::SPAWN; } + bool is_location() const { return type==goto_trace_stept::typet::LOCATION; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_memory_barrier() const { return type==goto_trace_stept::MEMORY_BARRIER; } + bool is_output() const { return type==goto_trace_stept::typet::OUTPUT; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_atomic_begin() const { return type==goto_trace_stept::ATOMIC_BEGIN; } + bool is_decl() const { return type==goto_trace_stept::typet::DECL; } // NOLINTNEXTLINE(whitespace/line_length) - bool is_atomic_end() const { return type==goto_trace_stept::ATOMIC_END; } + bool is_function_call() const { return type==goto_trace_stept::typet::FUNCTION_CALL; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_function_return() const { return type==goto_trace_stept::typet::FUNCTION_RETURN; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_shared_read() const { return type==goto_trace_stept::typet::SHARED_READ; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_shared_write() const { return type==goto_trace_stept::typet::SHARED_WRITE; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_spawn() const { return type==goto_trace_stept::typet::SPAWN; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_memory_barrier() const { return type==goto_trace_stept::typet::MEMORY_BARRIER; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_atomic_begin() const { return type==goto_trace_stept::typet::ATOMIC_BEGIN; } + // NOLINTNEXTLINE(whitespace/line_length) + bool is_atomic_end() const { return type==goto_trace_stept::typet::ATOMIC_END; } // we may choose to hide bool hidden; @@ -229,7 +236,7 @@ class symex_target_equationt:public symex_targett bool ignore; SSA_stept(): - type(goto_trace_stept::NONE), + type(goto_trace_stept::typet::NONE), hidden(false), guard(static_cast(get_nil_irep())), guard_literal(const_literal(false)), diff --git a/src/java_bytecode/Makefile b/src/java_bytecode/Makefile index db243bd8083..677987cfc9b 100644 --- a/src/java_bytecode/Makefile +++ b/src/java_bytecode/Makefile @@ -1,5 +1,6 @@ SRC = bytecode_info.cpp \ character_refine_preprocess.cpp \ + ci_lazy_methods.cpp \ expr2java.cpp \ jar_file.cpp \ java_bytecode_convert_class.cpp \ diff --git a/src/java_bytecode/ci_lazy_methods.cpp b/src/java_bytecode/ci_lazy_methods.cpp new file mode 100644 index 00000000000..5cafa74ac73 --- /dev/null +++ b/src/java_bytecode/ci_lazy_methods.cpp @@ -0,0 +1,53 @@ +/*******************************************************************\ + +Module: Context-insensitive lazy methods container + +Author: Chris Smowton, chris.smowton@diffblue.com + +\*******************************************************************/ + +#include + +#include "ci_lazy_methods.h" + +/*******************************************************************\ + +Function: ci_lazy_methodst::add_needed_method + + Inputs: `method_symbol_name`: method name; must exist in symbol table. + + Outputs: + + Purpose: Notes `method_symbol_name` is referenced from some reachable + function, and should therefore be elaborated. + +\*******************************************************************/ + +void ci_lazy_methodst::add_needed_method(const irep_idt &method_symbol_name) +{ + needed_methods.push_back(method_symbol_name); +} + +/*******************************************************************\ + +Function: java_bytecode_parsert::parse + + Inputs: `class_symbol_name`: class name; must exist in symbol table. + + Outputs: Returns true if `class_symbol_name` is new (not seen before). + + Purpose: Notes class `class_symbol_name` will be instantiated, or + a static field belonging to it will be accessed. Also notes + that its static initializer is therefore reachable. + +\*******************************************************************/ + +bool ci_lazy_methodst::add_needed_class(const irep_idt &class_symbol_name) +{ + if(!needed_classes.insert(class_symbol_name).second) + return false; + const irep_idt clinit_name(id2string(class_symbol_name)+".:()V"); + if(symbol_table.symbols.count(clinit_name)) + add_needed_method(clinit_name); + return true; +} diff --git a/src/java_bytecode/ci_lazy_methods.h b/src/java_bytecode/ci_lazy_methods.h new file mode 100644 index 00000000000..54c4664c694 --- /dev/null +++ b/src/java_bytecode/ci_lazy_methods.h @@ -0,0 +1,46 @@ +/*******************************************************************\ + +Module: Context-insensitive lazy methods container + +Author: Chris Smowton, chris.smowton@diffblue.com + +\*******************************************************************/ + +#ifndef CPROVER_JAVA_BYTECODE_CI_LAZY_METHODS_H +#define CPROVER_JAVA_BYTECODE_CI_LAZY_METHODS_H + +#include +#include +#include + +class ci_lazy_methodst +{ +public: + ci_lazy_methodst( + std::vector &_needed_methods, + std::set &_needed_classes, + symbol_tablet &_symbol_table): + needed_methods(_needed_methods), + needed_classes(_needed_classes), + symbol_table(_symbol_table) + {} + + void add_needed_method(const irep_idt &); + // Returns true if new + bool add_needed_class(const irep_idt &); + +private: + // needed_methods is a vector because it's used as a work-list + // which is periodically cleared. It can't be relied upon to + // contain all methods that have previously been elaborated. + // It should be changed to a set if we develop the need to use + // it that way. + std::vector &needed_methods; + // needed_classes on the other hand is a true set of every class + // found so far, so we can use a membership test to avoid + // repeatedly exploring a class hierarchy. + std::set &needed_classes; + symbol_tablet &symbol_table; +}; + +#endif diff --git a/src/java_bytecode/expr2java.cpp b/src/java_bytecode/expr2java.cpp index 5f07b5850fb..e5a1d921bfa 100644 --- a/src/java_bytecode/expr2java.cpp +++ b/src/java_bytecode/expr2java.cpp @@ -48,7 +48,7 @@ std::string expr2javat::convert_code_function_call( if(src.lhs().is_not_nil()) { unsigned p; - std::string lhs_str=convert(src.lhs(), p); + std::string lhs_str=convert_with_precedence(src.lhs(), p); dest+=lhs_str; dest+='='; @@ -63,14 +63,14 @@ std::string expr2javat::convert_code_function_call( if(has_this) { unsigned p; - std::string this_str=convert(src.arguments()[0], p); + std::string this_str=convert_with_precedence(src.arguments()[0], p); dest+=this_str; dest+=" . "; // extra spaces for readability } { unsigned p; - std::string function_str=convert(src.function(), p); + std::string function_str=convert_with_precedence(src.function(), p); dest+=function_str; } @@ -88,7 +88,7 @@ std::string expr2javat::convert_code_function_call( else { unsigned p; - std::string arg_str=convert(*it, p); + std::string arg_str=convert_with_precedence(*it, p); if(first) first=false; @@ -484,7 +484,7 @@ Function: expr2javat::convert \*******************************************************************/ -std::string expr2javat::convert( +std::string expr2javat::convert_with_precedence( const exprt &src, unsigned &precedence) { @@ -516,7 +516,7 @@ std::string expr2javat::convert( else if(src.id()==ID_constant) return convert_constant(to_constant_expr(src), precedence=16); else - return expr2ct::convert(src, precedence); + return expr2ct::convert_with_precedence(src, precedence); } /*******************************************************************\ diff --git a/src/java_bytecode/expr2java.h b/src/java_bytecode/expr2java.h index d7889dc73a6..4df0d240cf9 100644 --- a/src/java_bytecode/expr2java.h +++ b/src/java_bytecode/expr2java.h @@ -16,19 +16,9 @@ class expr2javat:public expr2ct { public: explicit expr2javat(const namespacet &_ns):expr2ct(_ns) { } - - virtual std::string convert(const exprt &src) - { - return expr2ct::convert(src); - } - - virtual std::string convert(const typet &src) - { - return expr2ct::convert(src); - } - protected: - virtual std::string convert(const exprt &src, unsigned &precedence); + virtual std::string convert_with_precedence( + const exprt &src, unsigned &precedence); virtual std::string convert_java_this(const exprt &src, unsigned precedence); virtual std::string convert_java_instanceof( const exprt &src, diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index 0990027e0a0..ef905eebad2 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -293,6 +293,8 @@ void java_bytecode_convert_classt::convert( component.set_access(ID_protected); else if(f.is_public) component.set_access(ID_public); + else + component.set_access(ID_default); } } diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 82f4424db0f..9e295f2dcc6 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -283,6 +283,14 @@ void java_bytecode_convert_method_lazy( method_symbol.mode=ID_java; method_symbol.location=m.source_location; method_symbol.location.set_function(method_identifier); + if(m.is_public) + member_type.set(ID_access, ID_public); + else if(m.is_protected) + member_type.set(ID_access, ID_protected); + else if(m.is_private) + member_type.set(ID_access, ID_private); + else + member_type.set(ID_access, ID_default); if(method_symbol.base_name=="") { @@ -1080,7 +1088,7 @@ codet java_bytecode_convert_methodt::get_clinit_call( /*******************************************************************\ -Function: java_bytecode_convert_methodt::convert_instructions +Function: get_bytecode_type_width Inputs: @@ -1097,6 +1105,18 @@ static unsigned get_bytecode_type_width(const typet &ty) return ty.get_unsigned_int(ID_width); } +/*******************************************************************\ + +Function: java_bytecode_convert_methodt::convert_instructions + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + codet java_bytecode_convert_methodt::convert_instructions( const methodt &method, const code_typet &method_type) @@ -1450,8 +1470,8 @@ codet java_bytecode_convert_methodt::convert_instructions( if(as_string(arg0.get(ID_identifier)) .find("")!=std::string::npos) { - if(needed_classes) - needed_classes->insert(classname); + if(lazy_methods) + lazy_methods->add_needed_class(classname); code_type.set(ID_constructor, true); } else @@ -1551,8 +1571,8 @@ codet java_bytecode_convert_methodt::convert_instructions( { // static binding call.function()=symbol_exprt(arg0.get(ID_identifier), arg0.type()); - if(needed_methods) - needed_methods->push_back(arg0.get(ID_identifier)); + if(lazy_methods) + lazy_methods->add_needed_method(arg0.get(ID_identifier)); } call.function().add_source_location()=loc; @@ -2100,9 +2120,9 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); - if(needed_classes && arg0.type().id()==ID_symbol) + if(lazy_methods && arg0.type().id()==ID_symbol) { - needed_classes->insert( + lazy_methods->add_needed_class( to_symbol_type(arg0.type()).get_identifier()); } results[0]=java_bytecode_promotion(symbol_expr); @@ -2127,9 +2147,9 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); - if(needed_classes && arg0.type().id()==ID_symbol) + if(lazy_methods && arg0.type().id()==ID_symbol) { - needed_classes->insert( + lazy_methods->add_needed_class( to_symbol_type(arg0.type()).get_identifier()); } c=code_assignt(symbol_expr, op[0]); @@ -2747,8 +2767,7 @@ void java_bytecode_convert_method( symbol_tablet &symbol_table, message_handlert &message_handler, size_t max_array_length, - safe_pointer > needed_methods, - safe_pointer > needed_classes) + safe_pointer lazy_methods) { static const std::unordered_set methods_to_ignore { @@ -2777,8 +2796,7 @@ void java_bytecode_convert_method( symbol_table, message_handler, max_array_length, - needed_methods, - needed_classes); + lazy_methods); java_bytecode_convert_method(class_symbol, method); } diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index bc25eccb0c7..db6fcc729e1 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include "java_bytecode_parse_tree.h" +#include "ci_lazy_methods.h" class class_hierarchyt; @@ -23,10 +24,8 @@ void java_bytecode_convert_method( symbol_tablet &symbol_table, message_handlert &message_handler, size_t max_array_length, - safe_pointer > needed_methods, - safe_pointer > needed_classes); + safe_pointer lazy_methods); -// Must provide both the optional parameters or neither. inline void java_bytecode_convert_method( const symbolt &class_symbol, const java_bytecode_parse_treet::methodt &method, @@ -40,8 +39,7 @@ inline void java_bytecode_convert_method( symbol_table, message_handler, max_array_length, - safe_pointer >::create_null(), - safe_pointer >::create_null()); + safe_pointer::create_null()); } void java_bytecode_convert_method_lazy( diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 75cfacd222e..da9196e6a67 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -17,6 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include "java_bytecode_parse_tree.h" #include "java_bytecode_convert_class.h" +#include "ci_lazy_methods.h" #include #include @@ -31,13 +32,11 @@ class java_bytecode_convert_methodt:public messaget symbol_tablet &_symbol_table, message_handlert &_message_handler, size_t _max_array_length, - safe_pointer > _needed_methods, - safe_pointer > _needed_classes): + safe_pointer _lazy_methods): messaget(_message_handler), symbol_table(_symbol_table), max_array_length(_max_array_length), - needed_methods(_needed_methods), - needed_classes(_needed_classes) + lazy_methods(_lazy_methods) { } @@ -55,8 +54,7 @@ class java_bytecode_convert_methodt:public messaget protected: symbol_tablet &symbol_table; const size_t max_array_length; - safe_pointer > needed_methods; - safe_pointer > needed_classes; + safe_pointer lazy_methods; irep_idt method_id; irep_idt current_method; @@ -97,11 +95,11 @@ class java_bytecode_convert_methodt:public messaget std::map class_has_clinit_method; std::map any_superclass_has_clinit_method; - typedef enum instruction_sizet + enum instruction_sizet { INST_INDEX=2, INST_INDEX_CONST=3 - } instruction_sizet; + }; codet get_array_bounds_check( const exprt &arraystruct, diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 444208f0c87..69f9f3eb2a4 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -412,11 +412,10 @@ Function: gather_field_types Inputs: `class_type`: root of class tree to search `ns`: global namespace - Outputs: Populates `needed_classes` with all Java reference types + Outputs: Populates `lazy_methods` with all Java reference types reachable starting at `class_type`. For example if `class_type` is `symbol_typet("java::A")` and A has a B - field, then `B` (but not `A`) will be added to - `needed_classes`. + field, then `B` (but not `A`) will noted as a needed class. Purpose: See output @@ -425,13 +424,13 @@ Function: gather_field_types static void gather_field_types( const typet &class_type, const namespacet &ns, - std::set &needed_classes) + ci_lazy_methodst &lazy_methods) { const auto &underlying_type=to_struct_type(ns.follow(class_type)); for(const auto &field : underlying_type.components()) { if(field.type().id()==ID_struct || field.type().id()==ID_symbol) - gather_field_types(field.type(), ns, needed_classes); + gather_field_types(field.type(), ns, lazy_methods); else if(field.type().id()==ID_pointer) { // Skip array primitive pointers, for example: @@ -439,8 +438,8 @@ static void gather_field_types( continue; const auto &field_classid= to_symbol_type(field.type().subtype()).get_identifier(); - if(needed_classes.insert(field_classid).second) - gather_field_types(field.type().subtype(), ns, needed_classes); + if(lazy_methods.add_needed_class(field_classid)) + gather_field_types(field.type().subtype(), ns, lazy_methods); } } } @@ -454,7 +453,7 @@ Function: initialize_needed_classes `ns`: global namespace `ch`: global class hierarchy - Outputs: Populates `needed_classes` with all Java reference types + Outputs: Populates `lazy_methods` with all Java reference types whose references may be passed, directly or indirectly, to any of the functions in `entry_points`. @@ -466,7 +465,7 @@ static void initialize_needed_classes( const std::vector &entry_points, const namespacet &ns, const class_hierarchyt &ch, - std::set &needed_classes) + ci_lazy_methodst &lazy_methods) { for(const auto &mname : entry_points) { @@ -482,8 +481,8 @@ static void initialize_needed_classes( ch.get_parents_trans(param_classid); class_and_parents.push_back(param_classid); for(const auto &classid : class_and_parents) - needed_classes.insert(classid); - gather_field_types(param.type().subtype(), ns, needed_classes); + lazy_methods.add_needed_class(classid); + gather_field_types(param.type().subtype(), ns, lazy_methods); } } } @@ -491,9 +490,9 @@ static void initialize_needed_classes( // Also add classes whose instances are magically // created by the JVM and so won't be spotted by // looking for constructors and calls as usual: - needed_classes.insert("java::java.lang.String"); - needed_classes.insert("java::java.lang.Class"); - needed_classes.insert("java::java.lang.Object"); + lazy_methods.add_needed_class("java::java.lang.String"); + lazy_methods.add_needed_class("java::java.lang.Class"); + lazy_methods.add_needed_class("java::java.lang.Object"); } /*******************************************************************\ @@ -628,11 +627,23 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( method_worklist2.push_back(main_function.main_function.name); std::set needed_classes; - initialize_needed_classes( - method_worklist2, - namespacet(symbol_table), - ch, - needed_classes); + + { + std::vector needed_clinits; + ci_lazy_methodst initial_lazy_methods( + needed_clinits, + needed_classes, + symbol_table); + initialize_needed_classes( + method_worklist2, + namespacet(symbol_table), + ch, + initial_lazy_methods); + method_worklist2.insert( + method_worklist2.end(), + needed_clinits.begin(), + needed_clinits.end()); + } std::set methods_already_populated; std::vector virtual_callsites; @@ -656,16 +667,18 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( } debug() << "CI lazy methods: elaborate " << mname << eom; const auto &parsed_method=findit->second; + // Note this wraps *references* to method_worklist2, needed_classes: + ci_lazy_methodst lazy_methods( + method_worklist2, + needed_classes, + symbol_table); java_bytecode_convert_method( *parsed_method.first, *parsed_method.second, symbol_table, get_message_handler(), max_user_array_length, - safe_pointer >::create_non_null( - &method_worklist2), - safe_pointer >::create_non_null( - &needed_classes)); + safe_pointer::create_non_null(&lazy_methods)); gather_virtual_callsites( symbol_table.lookup(mname).value, virtual_callsites); diff --git a/src/java_bytecode/java_bytecode_parser.cpp b/src/java_bytecode/java_bytecode_parser.cpp index 012a1c21dea..dd458860c97 100644 --- a/src/java_bytecode/java_bytecode_parser.cpp +++ b/src/java_bytecode/java_bytecode_parser.cpp @@ -709,6 +709,13 @@ void java_bytecode_parsert::rfields(classt &parsed_class) field.is_final=(access_flags&ACC_FINAL)!=0; field.is_enum=(access_flags&ACC_ENUM)!=0; field.signature=id2string(pool_entry(descriptor_index).s); + field.is_public=(access_flags&ACC_PUBLIC)!=0; + field.is_protected=(access_flags&ACC_PROTECTED)!=0; + field.is_private=(access_flags&ACC_PRIVATE)!=0; + size_t flags=(field.is_public?1:0)+ + (field.is_protected?1:0)+ + (field.is_private?1:0); + assert(flags<=1); for(std::size_t j=0; j #include -#include #include #include "java_entry_point.h" @@ -98,10 +97,9 @@ Function: java_static_lifetime_init \*******************************************************************/ -bool java_static_lifetime_init( +void java_static_lifetime_init( symbol_tablet &symbol_table, const source_locationt &source_location, - message_handlert &message_handler, bool assume_init_pointers_not_null, unsigned max_nondet_array_length) { @@ -138,6 +136,7 @@ bool java_static_lifetime_init( } auto newsym=object_factory( sym.type, + symname, code_block, allow_null, symbol_table, @@ -154,8 +153,6 @@ bool java_static_lifetime_init( } } } - - return false; } /*******************************************************************\ @@ -175,8 +172,7 @@ exprt::operandst java_build_arguments( code_blockt &init_code, symbol_tablet &symbol_table, bool assume_init_pointers_not_null, - unsigned max_nondet_array_length, - message_handlert &message_handler) + unsigned max_nondet_array_length) { const code_typet::parameterst ¶meters= to_code_type(function.type).parameters(); @@ -205,27 +201,29 @@ exprt::operandst java_build_arguments( is_main=(named_main && has_correct_type); } + const code_typet::parametert &p=parameters[param_number]; + const irep_idt base_name=p.get_base_name().empty()? + ("argument#"+std::to_string(param_number)):p.get_base_name(); + bool allow_null=(!is_main) && (!is_this) && !assume_init_pointers_not_null; main_arguments[param_number]= object_factory( - parameters[param_number].type(), + p.type(), + base_name, init_code, allow_null, symbol_table, max_nondet_array_length, function.location); - const symbolt &p_symbol= - symbol_table.lookup(parameters[param_number].get_identifier()); - // record as an input codet input(ID_input); input.operands().resize(2); input.op0()= address_of_exprt( index_exprt( - string_constantt(p_symbol.base_name), + string_constantt(base_name), from_integer(0, index_type()))); input.op1()=main_arguments[param_number]; input.add_source_location()=function.location; @@ -538,13 +536,11 @@ bool java_entry_point( create_initialize(symbol_table); - if(java_static_lifetime_init( - symbol_table, - symbol.location, - message_handler, - assume_init_pointers_not_null, - max_nondet_array_length)) - return true; + java_static_lifetime_init( + symbol_table, + symbol.location, + assume_init_pointers_not_null, + max_nondet_array_length); code_blockt init_code; @@ -608,8 +604,7 @@ bool java_entry_point( init_code, symbol_table, assume_init_pointers_not_null, - max_nondet_array_length, - message_handler); + max_nondet_array_length); call_main.arguments()=main_arguments; init_code.move_to_operands(call_main); diff --git a/src/java_bytecode/java_object_factory.cpp b/src/java_bytecode/java_object_factory.cpp index 501691477b4..011f2ad2be3 100644 --- a/src/java_bytecode/java_object_factory.cpp +++ b/src/java_bytecode/java_object_factory.cpp @@ -22,6 +22,8 @@ Author: Daniel Kroening, kroening@kroening.com #include +#include + #include "java_object_factory.h" #include "java_types.h" #include "java_utils.h" @@ -55,13 +57,13 @@ static symbolt &new_tmp_symbol( class java_object_factoryt { - code_blockt &init_code; + std::vector &symbols_created; + const source_locationt &loc; std::unordered_set recursion_set; bool assume_non_null; size_t max_nondet_array_length; symbol_tablet &symbol_table; namespacet ns; - const source_locationt &loc; void set_null( const exprt &expr, @@ -73,31 +75,51 @@ class java_object_factoryt bool create_dynamic_objects, update_in_placet update_in_place); + code_assignt get_null_assignment( + const exprt &expr, + const pointer_typet &ptr_type); + + void gen_pointer_target_init( + code_blockt &assignments, + const exprt &expr, + const typet &target_type, + bool create_dynamic_objects, + update_in_placet); + + void allocate_nondet_length_array( + code_blockt &assignments, + const exprt &lhs, + const exprt &max_length_expr, + const typet &element_type); + public: java_object_factoryt( - code_blockt &_init_code, + std::vector &_symbols_created, + const source_locationt &loc, bool _assume_non_null, size_t _max_nondet_array_length, - symbol_tablet &_symbol_table, - const source_locationt &_loc): - init_code(_init_code), - assume_non_null(_assume_non_null), - max_nondet_array_length(_max_nondet_array_length), - symbol_table(_symbol_table), - ns(_symbol_table), - loc(_loc) - {} + symbol_tablet &_symbol_table): + symbols_created(_symbols_created), + loc(loc), + assume_non_null(_assume_non_null), + max_nondet_array_length(_max_nondet_array_length), + symbol_table(_symbol_table), + ns(_symbol_table) + {} exprt allocate_object( + code_blockt &assignments, const exprt &, const typet &, bool create_dynamic_objects); void gen_nondet_array_init( + code_blockt &assignments, const exprt &expr, update_in_placet); void gen_nondet_init( + code_blockt &assignments, const exprt &expr, bool is_sub, irep_idt class_identifier, @@ -112,8 +134,12 @@ class java_object_factoryt Function: java_object_factoryt::allocate_object - Inputs: the target expression, desired object type, source location - and Boolean whether to create a dynamic object + Inputs: + assignments - The code block to add code to + target_expr - The expression which we are allocating a symbol for + allocate_type - + create_dynamic_objects - Whether to create a symbol with static + lifetime or Outputs: the allocated object @@ -124,6 +150,7 @@ Function: java_object_factoryt::allocate_object \*******************************************************************/ exprt java_object_factoryt::allocate_object( + code_blockt &assignments, const exprt &target_expr, const typet &allocate_type, bool create_dynamic_objects) @@ -134,7 +161,7 @@ exprt java_object_factoryt::allocate_object( if(!create_dynamic_objects) { symbolt &aux_symbol=new_tmp_symbol(symbol_table, loc, allocate_type); - aux_symbol.is_static_lifetime=true; + symbols_created.push_back(&aux_symbol); exprt object=aux_symbol.symbol_expr(); exprt aoe=address_of_exprt(object); @@ -142,7 +169,7 @@ exprt java_object_factoryt::allocate_object( aoe=typecast_exprt(aoe, target_expr.type()); code_assignt code(target_expr, aoe); code.add_source_location()=loc; - init_code.copy_to_operands(code); + assignments.copy_to_operands(code); return aoe; } else @@ -166,16 +193,17 @@ exprt java_object_factoryt::allocate_object( loc, pointer_typet(allocate_type), "malloc_site"); + symbols_created.push_back(&malloc_sym); code_assignt assign=code_assignt(malloc_sym.symbol_expr(), malloc_expr); code_assignt &malloc_assign=assign; malloc_assign.add_source_location()=loc; - init_code.copy_to_operands(malloc_assign); + assignments.copy_to_operands(malloc_assign); malloc_expr=malloc_sym.symbol_expr(); if(cast_needed) malloc_expr=typecast_exprt(malloc_expr, target_expr.type()); code_assignt code(target_expr, malloc_expr); code.add_source_location()=loc; - init_code.copy_to_operands(code); + assignments.copy_to_operands(code); return malloc_sym.symbol_expr(); } else @@ -184,7 +212,7 @@ exprt java_object_factoryt::allocate_object( null_pointer_exprt null_pointer_expr(to_pointer_type(target_expr.type())); code_assignt code(target_expr, null_pointer_expr); code.add_source_location()=loc; - init_code.copy_to_operands(code); + assignments.copy_to_operands(code); return exprt(); } } @@ -192,7 +220,7 @@ exprt java_object_factoryt::allocate_object( /*******************************************************************\ -Function: java_object_factoryt::set_null +Function: java_object_factoryt::get_null_assignment Inputs: `expr`: pointer-typed lvalue expression to initialise `ptr_type`: pointer type to write @@ -204,14 +232,14 @@ Function: java_object_factoryt::set_null \*******************************************************************/ -void java_object_factoryt::set_null( +code_assignt java_object_factoryt::get_null_assignment( const exprt &expr, const pointer_typet &ptr_type) { null_pointer_exprt null_pointer_expr(ptr_type); code_assignt code(expr, null_pointer_expr); code.add_source_location()=loc; - init_code.move_to_operands(code); + return code; } /*******************************************************************\ @@ -238,6 +266,7 @@ Function: java_object_factoryt::gen_pointer_target_init \*******************************************************************/ void java_object_factoryt::gen_pointer_target_init( + code_blockt &assignments, const exprt &expr, const typet &target_type, bool create_dynamic_objects, @@ -251,6 +280,7 @@ void java_object_factoryt::gen_pointer_target_init( "java::array[")) { gen_nondet_array_init( + assignments, expr, update_in_place); } @@ -260,6 +290,7 @@ void java_object_factoryt::gen_pointer_target_init( if(update_in_place==NO_UPDATE_IN_PLACE) { target=allocate_object( + assignments, expr, target_type, create_dynamic_objects); @@ -275,6 +306,7 @@ void java_object_factoryt::gen_pointer_target_init( init_expr= dereference_exprt(target, target.type().subtype()); gen_nondet_init( + assignments, init_expr, false, "", @@ -321,6 +353,7 @@ Function: java_object_factoryt::gen_nondet_init \*******************************************************************/ void java_object_factoryt::gen_nondet_init( + code_blockt &assignments, const exprt &expr, bool is_sub, irep_idt class_identifier, @@ -347,76 +380,87 @@ void java_object_factoryt::gen_nondet_init( if(!recursion_set.insert(struct_tag).second) { if(update_in_place==NO_UPDATE_IN_PLACE) - set_null(expr, pointer_type); + { + assignments.copy_to_operands( + get_null_assignment(expr, pointer_type)); + } // Otherwise leave it as it is. return; } } - nondet_ifthenelset update_in_place_diamond( - init_code, - symbol_table, - loc, - ID_java, - "nondet_update_in_place"); + code_blockt new_object_assignments; + code_blockt update_in_place_assignments; - if(update_in_place==MAY_UPDATE_IN_PLACE || - update_in_place==MUST_UPDATE_IN_PLACE) + if(update_in_place!=NO_UPDATE_IN_PLACE) { - if(update_in_place==MAY_UPDATE_IN_PLACE) - update_in_place_diamond.begin_if(); - - // If we're trying to update an object in place - // but it is null, just leave it alone. - static unsigned long null_check_count=0; - std::ostringstream oss; - oss << "null_check_failed_" << (++null_check_count); - code_labelt post_null_check(oss.str(), code_skipt()); - code_ifthenelset null_check; - null_check.cond()=equal_exprt(expr, null_pointer_exprt(pointer_type)); - null_check.then_case()=code_gotot(post_null_check.get_label()); - - init_code.move_to_operands(null_check); - gen_pointer_target_init( + update_in_place_assignments, expr, subtype, create_dynamic_objects, MUST_UPDATE_IN_PLACE); - - init_code.move_to_operands(post_null_check); - - if(update_in_place==MUST_UPDATE_IN_PLACE) - return; - - update_in_place_diamond.begin_else(); } - nondet_ifthenelset init_null_diamond( - init_code, - symbol_table, - loc, - ID_java, - "nondet_ptr_is_null"); - - if(!assume_non_null) + if(update_in_place==MUST_UPDATE_IN_PLACE) { - init_null_diamond.begin_if(); - set_null(expr, pointer_type); - init_null_diamond.begin_else(); + assignments.append(update_in_place_assignments); + return; } + // Otherwise we need code for the allocate-new-object case: + + code_blockt non_null_inst; gen_pointer_target_init( + non_null_inst, expr, subtype, create_dynamic_objects, NO_UPDATE_IN_PLACE); - if(!assume_non_null) - init_null_diamond.finish(); + if(assume_non_null) + { + // Add the following code to assignments: + // = ; + new_object_assignments.append(non_null_inst); + } + else + { + // Add the following code to assignments: + // IF !NONDET(_Bool) THEN GOTO + // = + // GOTO + // : = &tmp$; + // > + // And the next line is labelled label2 + auto set_null_inst=get_null_assignment(expr, pointer_type); - if(update_in_place==MAY_UPDATE_IN_PLACE) - update_in_place_diamond.finish(); + code_ifthenelset null_check; + null_check.cond()=side_effect_expr_nondett(bool_typet()); + null_check.then_case()=set_null_inst; + null_check.else_case()=non_null_inst; + + new_object_assignments.add(null_check); + } + + // Similarly to above, maybe use a conditional if both the + // allocate-fresh and update-in-place cases are allowed: + if(update_in_place==NO_UPDATE_IN_PLACE) + { + assignments.append(new_object_assignments); + } + else + { + assert(update_in_place==MAY_UPDATE_IN_PLACE); + + code_ifthenelset update_check; + update_check.cond()=side_effect_expr_nondett(bool_typet()); + update_check.then_case()=update_in_place_assignments; + update_check.else_case()=new_object_assignments; + + assignments.add(update_check); + } } else if(type.id()==ID_struct) { @@ -439,14 +483,17 @@ void java_object_factoryt::gen_nondet_init( if(name=="@class_identifier") { - if(skip_classid || update_in_place==MUST_UPDATE_IN_PLACE) + if(update_in_place==MUST_UPDATE_IN_PLACE) + continue; + + if(skip_classid) continue; irep_idt qualified_clsid="java::"+as_string(class_identifier); constant_exprt ci(qualified_clsid, string_typet()); code_assignt code(me, ci); code.add_source_location()=loc; - init_code.copy_to_operands(code); + assignments.copy_to_operands(code); } else if(name=="@lock") { @@ -454,7 +501,7 @@ void java_object_factoryt::gen_nondet_init( continue; code_assignt code(me, from_integer(0, me.type())); code.add_source_location()=loc; - init_code.copy_to_operands(code); + assignments.copy_to_operands(code); } else { @@ -474,6 +521,7 @@ void java_object_factoryt::gen_nondet_init( MAY_UPDATE_IN_PLACE : update_in_place; gen_nondet_init( + assignments, me, _is_sub, class_identifier, @@ -493,35 +541,93 @@ void java_object_factoryt::gen_nondet_init( code_assignt assign(expr, rhs); assign.add_source_location()=loc; - init_code.copy_to_operands(assign); + assignments.copy_to_operands(assign); } } /*******************************************************************\ +Function: java_object_factoryt::allocate_nondet_length_array + + Inputs: `lhs`, symbol to assign the new array structure + `max_length_expr`, maximum length of the new array + (minimum is fixed at zero for now) + `element_type`, actual element type of the array (the array + for all reference types will have void* type, but this + will be annotated as the true member type) + + Outputs: Appends instructions to `assignments` + + Purpose: Allocates a fresh array. Single-use herem at the moment, but + useful to keep as a separate function for downstream branches. + +\*******************************************************************/ + +void java_object_factoryt::allocate_nondet_length_array( + code_blockt &assignments, + const exprt &lhs, + const exprt &max_length_expr, + const typet &element_type) +{ + symbolt &length_sym=new_tmp_symbol( + symbol_table, + loc, + java_int_type(), + "nondet_array_length"); + symbols_created.push_back(&length_sym); + const auto &length_sym_expr=length_sym.symbol_expr(); + + // Initialize array with some undetermined length: + gen_nondet_init( + assignments, + length_sym_expr, + false, + irep_idt(), + false, + false, + false, + typet(), + NO_UPDATE_IN_PLACE); + + // Insert assumptions to bound its length: + binary_relation_exprt + assume1(length_sym_expr, ID_ge, from_integer(0, java_int_type())); + binary_relation_exprt + assume2(length_sym_expr, ID_le, max_length_expr); + code_assumet assume_inst1(assume1); + code_assumet assume_inst2(assume2); + assignments.move_to_operands(assume_inst1); + assignments.move_to_operands(assume_inst2); + + side_effect_exprt java_new_array(ID_java_new_array, lhs.type()); + java_new_array.copy_to_operands(length_sym_expr); + java_new_array.type().subtype().set(ID_C_element_type, element_type); + codet assign=code_assignt(lhs, java_new_array); + assign.add_source_location()=loc; + assignments.copy_to_operands(assign); +} + +/*******************************************************************\ + Function: java_object_factoryt::gen_nondet_array_init - Inputs: `expr`: Array-typed expression to initialise - `update_in_place`: - NO_UPDATE_IN_PLACE: initialise `expr` from scratch - MUST_UPDATE_IN_PLACE: reinitialise an existing array - MAY_UPDATE_IN_PLACE: invalid input + Inputs: Outputs: Purpose: create code to initialize a Java array with size `max_nondet_array_length`, loop over elements and initialize - or reinitialize them + them \*******************************************************************/ void java_object_factoryt::gen_nondet_array_init( + code_blockt &assignments, const exprt &expr, update_in_placet update_in_place) { - assert(update_in_place!=MAY_UPDATE_IN_PLACE); assert(expr.type().id()==ID_pointer); - + assert(update_in_place!=MAY_UPDATE_IN_PLACE); const typet &type=ns.follow(expr.type().subtype()); const struct_typet &struct_type=to_struct_type(type); assert(expr.type().subtype().id()==ID_symbol); @@ -530,65 +636,23 @@ void java_object_factoryt::gen_nondet_array_init( auto max_length_expr=from_integer(max_nondet_array_length, java_int_type()); - typet allocate_type; - exprt length_sym_expr; - if(update_in_place==NO_UPDATE_IN_PLACE) { - const symbolt &length_sym=new_tmp_symbol( - symbol_table, - loc, - java_int_type(), - "nondet_array_length"); - length_sym_expr=length_sym.symbol_expr(); - - // Initialise array with some undetermined length: - gen_nondet_init( - length_sym_expr, - false, - irep_idt(), - false, - false, - false, - typet(), - NO_UPDATE_IN_PLACE); - - // Insert assumptions to bound its length: - binary_relation_exprt assume1(length_sym_expr, ID_ge, - from_integer(0, java_int_type())); - binary_relation_exprt assume2(length_sym_expr, ID_le, - max_length_expr); - - code_assumet assume_inst1(assume1); - code_assumet assume_inst2(assume2); - init_code.move_to_operands(assume_inst1); - init_code.move_to_operands(assume_inst2); - - side_effect_exprt java_new_array(ID_java_new_array, expr.type()); - java_new_array.copy_to_operands(length_sym_expr); - // Retain the array_set instruction for the special case of a - // zero-length array, where this will be the only assignment against - // the array's identifier. - java_new_array.set(ID_skip_initialize, false); - java_new_array.type().subtype().set(ID_C_element_type, element_type); - codet assign=code_assignt(expr, java_new_array); - assign.add_source_location()=loc; - init_code.copy_to_operands(assign); - } - else - { - // Update in place. Get existing array length: - length_sym_expr= - member_exprt( - dereference_exprt(expr, expr.type().subtype()), - "length", - struct_type.component_type("length")); + allocate_nondet_length_array( + assignments, + expr, + max_length_expr, + element_type); } - exprt init_array_expr=member_exprt( - dereference_exprt(expr, expr.type().subtype()), - "data", - struct_type.component_type("data")); + // Otherwise we're updating the array in place, and use the + // existing array allocation and length. + + dereference_exprt deref_expr(expr, expr.type().subtype()); + const auto &comps=struct_type.components(); + exprt length_expr=member_exprt(deref_expr, "length", comps[1].type()); + exprt init_array_expr=member_exprt(deref_expr, "data", comps[2].type()); + if(init_array_expr.type()!=pointer_typet(element_type)) init_array_expr= typecast_exprt(init_array_expr, pointer_typet(element_type)); @@ -600,38 +664,40 @@ void java_object_factoryt::gen_nondet_array_init( loc, init_array_expr.type(), "array_data_init"); + symbols_created.push_back(&array_init_symbol); const auto &array_init_symexpr=array_init_symbol.symbol_expr(); codet data_assign=code_assignt(array_init_symexpr, init_array_expr); data_assign.add_source_location()=loc; - init_code.copy_to_operands(data_assign); + assignments.copy_to_operands(data_assign); // Emit init loop for(array_init_iter=0; array_init_iter!=array.length; // ++array_init_iter) init(array[array_init_iter]); symbolt &counter=new_tmp_symbol( symbol_table, loc, - length_sym_expr.type(), + length_expr.type(), "array_init_iter"); + symbols_created.push_back(&counter); exprt counter_expr=counter.symbol_expr(); exprt java_zero=from_integer(0, java_int_type()); - init_code.copy_to_operands(code_assignt(counter_expr, java_zero)); + assignments.copy_to_operands(code_assignt(counter_expr, java_zero)); std::string head_name=as_string(counter.base_name)+"_header"; code_labelt init_head_label(head_name, code_skipt()); code_gotot goto_head(head_name); - init_code.move_to_operands(init_head_label); + assignments.move_to_operands(init_head_label); std::string done_name=as_string(counter.base_name)+"_done"; code_labelt init_done_label(done_name, code_skipt()); code_gotot goto_done(done_name); code_ifthenelset done_test; - done_test.cond()=equal_exprt(counter_expr, length_sym_expr); + done_test.cond()=equal_exprt(counter_expr, length_expr); done_test.then_case()=goto_done; - init_code.move_to_operands(done_test); + assignments.move_to_operands(done_test); if(update_in_place!=MUST_UPDATE_IN_PLACE) { @@ -640,7 +706,8 @@ void java_object_factoryt::gen_nondet_array_init( code_ifthenelset max_test; max_test.cond()=equal_exprt(counter_expr, max_length_expr); max_test.then_case()=goto_done; - init_code.move_to_operands(max_test); + + assignments.move_to_operands(max_test); } exprt arraycellref=dereference_exprt( @@ -655,6 +722,7 @@ void java_object_factoryt::gen_nondet_array_init( MAY_UPDATE_IN_PLACE : update_in_place; gen_nondet_init( + assignments, arraycellref, false, irep_idt(), @@ -667,9 +735,9 @@ void java_object_factoryt::gen_nondet_array_init( exprt java_one=from_integer(1, java_int_type()); code_assignt incr(counter_expr, plus_exprt(counter_expr, java_one)); - init_code.move_to_operands(incr); - init_code.move_to_operands(goto_head); - init_code.move_to_operands(init_done_label); + assignments.move_to_operands(incr); + assignments.move_to_operands(goto_head); + assignments.move_to_operands(init_done_label); } /*******************************************************************\ @@ -696,24 +764,45 @@ Function: object_factory exprt object_factory( const typet &type, + const irep_idt base_name, code_blockt &init_code, bool allow_null, symbol_tablet &symbol_table, size_t max_nondet_array_length, const source_locationt &loc) { + irep_idt identifier=id2string(goto_functionst::entry_point())+ + "::"+id2string(base_name); + + auxiliary_symbolt main_symbol; + main_symbol.mode=ID_java; + main_symbol.is_static_lifetime=false; + main_symbol.name=identifier; + main_symbol.base_name=base_name; + main_symbol.type=type; + main_symbol.location=loc; + + exprt object=main_symbol.symbol_expr(); + + symbolt *main_symbol_ptr; + bool moving_symbol_failed=symbol_table.move(main_symbol, main_symbol_ptr); + assert(!moving_symbol_failed); + + std::vector symbols_created; + symbols_created.push_back(main_symbol_ptr); + symbolt &aux_symbol=new_tmp_symbol(symbol_table, loc, type); aux_symbol.is_static_lifetime=true; - exprt object=aux_symbol.symbol_expr(); - java_object_factoryt state( - init_code, + symbols_created, + loc, !allow_null, max_nondet_array_length, - symbol_table, - loc); + symbol_table); + code_blockt assignments; state.gen_nondet_init( + assignments, object, false, "", @@ -723,6 +812,16 @@ exprt object_factory( typet(), NO_UPDATE_IN_PLACE); + // Add the following code to init_code for each symbol that's been created: + // ; + for(const symbolt * const symbol_ptr : symbols_created) + { + code_declt decl(symbol_ptr->symbol_expr()); + decl.add_source_location()=loc; + init_code.add(decl); + } + + init_code.append(assignments); return object; } @@ -770,13 +869,17 @@ void gen_nondet_init( size_t max_nondet_array_length, update_in_placet update_in_place) { + std::vector symbols_created; + java_object_factoryt state( - init_code, + symbols_created, + loc, assume_non_null, max_nondet_array_length, - symbol_table, - loc); + symbol_table); + code_blockt assignments; state.gen_nondet_init( + assignments, expr, false, "", @@ -785,4 +888,15 @@ void gen_nondet_init( false, typet(), update_in_place); + + // Add the following code to init_code for each symbol that's been created: + // ; + for(const symbolt * const symbol_ptr : symbols_created) + { + code_declt decl(symbol_ptr->symbol_expr()); + decl.add_source_location()=loc; + init_code.add(decl); + } + + init_code.append(assignments); } diff --git a/src/java_bytecode/java_object_factory.h b/src/java_bytecode/java_object_factory.h index fb614d906ee..d2d2d0d937f 100644 --- a/src/java_bytecode/java_object_factory.h +++ b/src/java_bytecode/java_object_factory.h @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com exprt object_factory( const typet &type, + const irep_idt base_name, code_blockt &init_code, bool allow_null, symbol_tablet &symbol_table, diff --git a/src/jsil/expr2jsil.cpp b/src/jsil/expr2jsil.cpp index fde6cf87f00..e100aa13432 100644 --- a/src/jsil/expr2jsil.cpp +++ b/src/jsil/expr2jsil.cpp @@ -15,16 +15,6 @@ class expr2jsilt:public expr2ct public: explicit expr2jsilt(const namespacet &_ns):expr2ct(_ns) { } - virtual std::string convert(const exprt &src) - { - return expr2ct::convert(src); - } - - virtual std::string convert(const typet &src) - { - return expr2ct::convert(src); - } - protected: }; diff --git a/src/langapi/language_ui.cpp b/src/langapi/language_ui.cpp index f516f57622d..73016a87874 100644 --- a/src/langapi/language_ui.cpp +++ b/src/langapi/language_ui.cpp @@ -127,7 +127,7 @@ bool language_uit::parse(const std::string &filename) if(language.parse(infile, filename)) { - if(get_ui()==ui_message_handlert::PLAIN) + if(get_ui()==ui_message_handlert::uit::PLAIN) std::cerr << "PARSING ERROR" << std::endl; return true; @@ -210,11 +210,11 @@ void language_uit::show_symbol_table(bool brief) { switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: show_symbol_table_plain(std::cout, brief); break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: show_symbol_table_xml_ui(brief); break; diff --git a/src/musketeer/cycles_visitor.cpp b/src/musketeer/cycles_visitor.cpp index c5fc1402311..762b667c6d2 100644 --- a/src/musketeer/cycles_visitor.cpp +++ b/src/musketeer/cycles_visitor.cpp @@ -275,8 +275,9 @@ void cycles_visitort::powr_constraint( for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) { - if(e_i->is_po && (graph[e_i->first].operation==abstract_eventt::Write - && graph[e_i->second].operation==abstract_eventt::Read)) + if(e_i->is_po && + (graph[e_i->first].operation==abstract_eventt::operationt::Write && + graph[e_i->second].operation==abstract_eventt::operationt::Read)) { if( edges.insert(fence_inserter.add_edge(*e_i)).second ) ++fence_inserter.constraints_number; @@ -306,8 +307,9 @@ void cycles_visitort::poww_constraint( for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) { - if(e_i->is_po && (graph[e_i->first].operation==abstract_eventt::Write - && graph[e_i->second].operation==abstract_eventt::Write)) + if(e_i->is_po && + (graph[e_i->first].operation==abstract_eventt::operationt::Write && + graph[e_i->second].operation==abstract_eventt::operationt::Write)) { if( edges.insert(fence_inserter.add_edge(*e_i)).second ) ++fence_inserter.constraints_number; @@ -337,8 +339,9 @@ void cycles_visitort::porw_constraint( for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) { - if(e_i->is_po && (graph[e_i->first].operation==abstract_eventt::Read - && graph[e_i->second].operation==abstract_eventt::Write)) + if(e_i->is_po && + (graph[e_i->first].operation==abstract_eventt::operationt::Read && + graph[e_i->second].operation==abstract_eventt::operationt::Write)) { if( edges.insert(fence_inserter.add_edge(*e_i)).second ) ++fence_inserter.constraints_number; @@ -368,8 +371,9 @@ void cycles_visitort::porr_constraint( for(std::set::iterator e_i=C_j.unsafe_pairs.begin(); e_i!=C_j.unsafe_pairs.end(); ++e_i) { - if(e_i->is_po && (graph[e_i->first].operation==abstract_eventt::Read - && graph[e_i->second].operation==abstract_eventt::Read)) + if(e_i->is_po && + (graph[e_i->first].operation==abstract_eventt::operationt::Read && + graph[e_i->second].operation==abstract_eventt::operationt::Read)) { if( edges.insert(fence_inserter.add_edge(*e_i)).second ) ++fence_inserter.constraints_number; @@ -400,8 +404,8 @@ void cycles_visitort::com_constraint( it!=C_j.unsafe_pairs.end(); ++it) { - if(egraph[it->first].operation==abstract_eventt::Write - && egraph[it->second].operation==abstract_eventt::Read + if(egraph[it->first].operation==abstract_eventt::operationt::Write + && egraph[it->second].operation==abstract_eventt::operationt::Read && egraph[it->first].thread!=egraph[it->second].thread) if( edges.insert(fence_inserter.add_invisible_edge(*it)).second ) ++fence_inserter.constraints_number; diff --git a/src/musketeer/fence_inserter.h b/src/musketeer/fence_inserter.h index 8f5e6286407..4d867b1ea90 100644 --- a/src/musketeer/fence_inserter.h +++ b/src/musketeer/fence_inserter.h @@ -100,7 +100,7 @@ class fence_insertert void preprocess(); void solve(); - typedef enum {Fence=0, Dp=1, Lwfence=2, Branching=3, Ctlfence=4} fence_typet; + enum fence_typet { Fence=0, Dp=1, Lwfence=2, Branching=3, Ctlfence=4 }; virtual unsigned fence_cost(fence_typet e) const; std::string to_string(fence_typet f) const; diff --git a/src/musketeer/graph_visitor.cpp b/src/musketeer/graph_visitor.cpp index d7f94938819..a55a1bd22e5 100644 --- a/src/musketeer/graph_visitor.cpp +++ b/src/musketeer/graph_visitor.cpp @@ -173,8 +173,8 @@ void const_graph_visitort::graph_explore_BC( const abstract_eventt &e1=egraph[*it]; const abstract_eventt &e2=egraph[*next_it]; if(!porw || - (e1.operation==abstract_eventt::Read && - e2.operation==abstract_eventt::Write)) + (e1.operation==abstract_eventt::operationt::Read && + e2.operation==abstract_eventt::operationt::Write)) edges.insert(fence_inserter.add_edge(edget(*it, *next_it))); } assert(it!=old_path.end()); @@ -239,8 +239,8 @@ void const_graph_visitort::const_graph_explore_BC( { const abstract_eventt &e1=egraph[*it]; const abstract_eventt &e2=egraph[*next_it]; - if((e1.operation==abstract_eventt::Read - && e2.operation==abstract_eventt::Write)) + if((e1.operation==abstract_eventt::operationt::Read && + e2.operation==abstract_eventt::operationt::Write)) fence_inserter.add_edge(edget(*it, *next_it)); } // NEW @@ -312,8 +312,8 @@ void const_graph_visitort::graph_explore_AC( const abstract_eventt &e1=egraph[*next_it]; const abstract_eventt &e2=egraph[*it]; if(!porw || - (e1.operation==abstract_eventt::Read && - e2.operation==abstract_eventt::Write)) + (e1.operation==abstract_eventt::operationt::Read && + e2.operation==abstract_eventt::operationt::Write)) edges.insert(fence_inserter.add_edge(edget(*next_it, *it))); } assert(it!=old_path.end()); @@ -379,8 +379,8 @@ void const_graph_visitort::const_graph_explore_AC( { const abstract_eventt &e1=egraph[*next_it]; const abstract_eventt &e2=egraph[*it]; - if(e1.operation==abstract_eventt::Read && - e2.operation==abstract_eventt::Write) + if(e1.operation==abstract_eventt::operationt::Read && + e2.operation==abstract_eventt::operationt::Write) fence_inserter.add_edge(edget(*next_it, *it)); } // NEW @@ -478,9 +478,13 @@ void const_graph_visitort::CT( assert(test_first.operation!=test_second.operation); const event_idt first= - (test_first.operation==abstract_eventt::Write?edge.first:edge.second); + (test_first.operation==abstract_eventt::operationt::Write? + edge.first: + edge.second); const event_idt second= - (test_second.operation==abstract_eventt::Read?edge.second:edge.first); + (test_second.operation==abstract_eventt::operationt::Read? + edge.second: + edge.first); /* TODO: AC + restricts to C_1 U ... U C_n */ visited_nodes.clear(); @@ -539,9 +543,13 @@ void const_graph_visitort::CT_not_powr( assert(test_first.operation!=test_second.operation); const event_idt first= - (test_first.operation==abstract_eventt::Write?edge.first:edge.second); + (test_first.operation==abstract_eventt::operationt::Write? + edge.first: + edge.second); const event_idt second= - (test_second.operation==abstract_eventt::Read?edge.second:edge.first); + (test_second.operation==abstract_eventt::operationt::Read? + edge.second: + edge.first); /* TODO: AC + restricts to C_1 U ... U C_n */ visited_nodes.clear(); diff --git a/src/musketeer/infer_mode.h b/src/musketeer/infer_mode.h index 426653a1622..b163437985c 100644 --- a/src/musketeer/infer_mode.h +++ b/src/musketeer/infer_mode.h @@ -9,11 +9,11 @@ #ifndef CPROVER_MUSKETEER_INFER_MODE_H #define CPROVER_MUSKETEER_INFER_MODE_H -typedef enum +enum infer_modet { INFER=0, USER_DEF=1, USER_ASSERT=2 -} infer_modet; +}; #endif // CPROVER_MUSKETEER_INFER_MODE_H diff --git a/src/path-symex/build_goto_trace.cpp b/src/path-symex/build_goto_trace.cpp index 9116e802742..4e7eafc2c94 100644 --- a/src/path-symex/build_goto_trace.cpp +++ b/src/path-symex/build_goto_trace.cpp @@ -49,48 +49,48 @@ void build_goto_trace( switch(instruction.type) { case ASSIGN: - trace_step.type=goto_trace_stept::ASSIGNMENT; + trace_step.type=goto_trace_stept::typet::ASSIGNMENT; trace_step.full_lhs=step.full_lhs; trace_step.full_lhs_value=decision_procedure.get(step.ssa_lhs); break; case DECL: - trace_step.type=goto_trace_stept::DECL; + trace_step.type=goto_trace_stept::typet::DECL; trace_step.full_lhs=step.full_lhs; trace_step.lhs_object=ssa_exprt(step.full_lhs); trace_step.full_lhs_value=decision_procedure.get(step.ssa_lhs); break; case DEAD: - trace_step.type=goto_trace_stept::DEAD; + trace_step.type=goto_trace_stept::typet::DEAD; break; case ASSUME: - trace_step.type=goto_trace_stept::ASSUME; + trace_step.type=goto_trace_stept::typet::ASSUME; break; case FUNCTION_CALL: - trace_step.type=goto_trace_stept::FUNCTION_CALL; + trace_step.type=goto_trace_stept::typet::FUNCTION_CALL; break; case END_FUNCTION: - trace_step.type=goto_trace_stept::FUNCTION_RETURN; + trace_step.type=goto_trace_stept::typet::FUNCTION_RETURN; break; case START_THREAD: - trace_step.type=goto_trace_stept::SPAWN; + trace_step.type=goto_trace_stept::typet::SPAWN; break; case ATOMIC_BEGIN: - trace_step.type=goto_trace_stept::ATOMIC_BEGIN; + trace_step.type=goto_trace_stept::typet::ATOMIC_BEGIN; break; case ATOMIC_END: - trace_step.type=goto_trace_stept::ATOMIC_END; + trace_step.type=goto_trace_stept::typet::ATOMIC_END; break; default: - trace_step.type=goto_trace_stept::LOCATION; + trace_step.type=goto_trace_stept::typet::LOCATION; } goto_trace.add_step(trace_step); @@ -108,7 +108,7 @@ void build_goto_trace( trace_step.pc=state.get_instruction(); trace_step.thread_nr=state.get_current_thread(); trace_step.step_nr=step_nr; - trace_step.type=goto_trace_stept::ASSERT; + trace_step.type=goto_trace_stept::typet::ASSERT; const irep_idt &comment= instruction.source_location.get_comment(); diff --git a/src/path-symex/path_symex_state.cpp b/src/path-symex/path_symex_state.cpp index 3dfc319d6d6..ebb7dda863a 100644 --- a/src/path-symex/path_symex_state.cpp +++ b/src/path-symex/path_symex_state.cpp @@ -194,11 +194,12 @@ bool path_symex_statet::is_feasible( // check whether SAT switch(decision_procedure()) { - case decision_proceduret::D_SATISFIABLE: return true; + case decision_proceduret::resultt::D_SATISFIABLE: return true; - case decision_proceduret::D_UNSATISFIABLE: return false; + case decision_proceduret::resultt::D_UNSATISFIABLE: return false; - case decision_proceduret::D_ERROR: throw "error from decision procedure"; + case decision_proceduret::resultt::D_ERROR: + throw "error from decision procedure"; } return true; // not really reachable @@ -240,10 +241,10 @@ bool path_symex_statet::check_assertion( // check whether SAT switch(decision_procedure.dec_solve()) { - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: return false; // error - case decision_proceduret::D_UNSATISFIABLE: + case decision_proceduret::resultt::D_UNSATISFIABLE: return true; // no error default: diff --git a/src/pointer-analysis/goto_program_dereference.cpp b/src/pointer-analysis/goto_program_dereference.cpp index 2ccce3f7a47..3370abe7635 100644 --- a/src/pointer-analysis/goto_program_dereference.cpp +++ b/src/pointer-analysis/goto_program_dereference.cpp @@ -162,7 +162,7 @@ void goto_program_dereferencet::dereference_rec( op.pretty(); if(dereference.has_dereference(op)) - dereference_rec(op, guard, value_set_dereferencet::READ); + dereference_rec(op, guard, value_set_dereferencet::modet::READ); if(expr.id()==ID_or) { @@ -191,7 +191,7 @@ void goto_program_dereferencet::dereference_rec( throw msg; } - dereference_rec(expr.op0(), guard, value_set_dereferencet::READ); + dereference_rec(expr.op0(), guard, value_set_dereferencet::modet::READ); bool o1=dereference.has_dereference(expr.op1()); bool o2=dereference.has_dereference(expr.op2()); @@ -402,15 +402,17 @@ void goto_program_dereferencet::dereference_instruction( #endif goto_programt::instructiont &i=*target; - dereference_expr(i.guard, checks_only, value_set_dereferencet::READ); + dereference_expr(i.guard, checks_only, value_set_dereferencet::modet::READ); if(i.is_assign()) { if(i.code.operands().size()!=2) throw "assignment expects two operands"; - dereference_expr(i.code.op0(), checks_only, value_set_dereferencet::WRITE); - dereference_expr(i.code.op1(), checks_only, value_set_dereferencet::READ); + dereference_expr( + i.code.op0(), checks_only, value_set_dereferencet::modet::WRITE); + dereference_expr( + i.code.op1(), checks_only, value_set_dereferencet::modet::READ); } else if(i.is_function_call()) { @@ -418,17 +420,21 @@ void goto_program_dereferencet::dereference_instruction( if(function_call.lhs().is_not_nil()) dereference_expr( - function_call.lhs(), checks_only, value_set_dereferencet::WRITE); + function_call.lhs(), + checks_only, + value_set_dereferencet::modet::WRITE); dereference_expr( - function_call.function(), checks_only, value_set_dereferencet::READ); + function_call.function(), + checks_only, + value_set_dereferencet::modet::READ); dereference_expr( - function_call.op2(), checks_only, value_set_dereferencet::READ); + function_call.op2(), checks_only, value_set_dereferencet::modet::READ); } else if(i.is_return()) { Forall_operands(it, i.code) - dereference_expr(*it, checks_only, value_set_dereferencet::READ); + dereference_expr(*it, checks_only, value_set_dereferencet::modet::READ); } else if(i.is_other()) { @@ -439,12 +445,14 @@ void goto_program_dereferencet::dereference_instruction( if(i.code.operands().size()!=1) throw "expression expects one operand"; - dereference_expr(i.code.op0(), checks_only, value_set_dereferencet::READ); + dereference_expr( + i.code.op0(), checks_only, value_set_dereferencet::modet::READ); } else if(statement==ID_printf) { Forall_operands(it, i.code) - dereference_expr(*it, checks_only, value_set_dereferencet::READ); + dereference_expr( + *it, checks_only, value_set_dereferencet::modet::READ); } } } @@ -470,7 +478,7 @@ void goto_program_dereferencet::dereference_expression( valid_local_variables=&target->local_variables; #endif - dereference_expr(expr, false, value_set_dereferencet::READ); + dereference_expr(expr, false, value_set_dereferencet::modet::READ); } /*******************************************************************\ diff --git a/src/pointer-analysis/show_value_sets.cpp b/src/pointer-analysis/show_value_sets.cpp index c0b87599ca4..cd5f4c84e17 100644 --- a/src/pointer-analysis/show_value_sets.cpp +++ b/src/pointer-analysis/show_value_sets.cpp @@ -32,7 +32,7 @@ void show_value_sets( { switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml; convert(goto_functions, value_set_analysis, xml); @@ -40,7 +40,7 @@ void show_value_sets( } break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: value_set_analysis.output(goto_functions, std::cout); break; @@ -69,7 +69,7 @@ void show_value_sets( { switch(ui) { - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml; convert(goto_program, value_set_analysis, xml); @@ -77,7 +77,7 @@ void show_value_sets( } break; - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: value_set_analysis.output(goto_program, std::cout); break; diff --git a/src/pointer-analysis/value_set_dereference.cpp b/src/pointer-analysis/value_set_dereference.cpp index 04598ac67fa..411adddbe8e 100644 --- a/src/pointer-analysis/value_set_dereference.cpp +++ b/src/pointer-analysis/value_set_dereference.cpp @@ -660,7 +660,7 @@ void value_set_dereferencet::valid_check( { // always valid, but can't write - if(mode==WRITE) + if(mode==modet::WRITE) { dereference_callback.dereference_failure( "pointer dereference", diff --git a/src/pointer-analysis/value_set_dereference.h b/src/pointer-analysis/value_set_dereference.h index d797d37a23d..19dde8e0f16 100644 --- a/src/pointer-analysis/value_set_dereference.h +++ b/src/pointer-analysis/value_set_dereference.h @@ -48,7 +48,7 @@ class value_set_dereferencet virtual ~value_set_dereferencet() { } - typedef enum { READ, WRITE } modet; + enum class modet { READ, WRITE }; /*! * The method 'dereference' dereferences the diff --git a/src/solvers/cvc/cvc_dec.cpp b/src/solvers/cvc/cvc_dec.cpp index b7fd3a2c3e2..a30fdb2e614 100644 --- a/src/solvers/cvc/cvc_dec.cpp +++ b/src/solvers/cvc/cvc_dec.cpp @@ -209,13 +209,13 @@ decision_proceduret::resultt cvc_dect::read_cvcl_result() read_assert(in, line); } - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } else if(has_prefix(line, "Valid.")) - return D_UNSATISFIABLE; + return resultt::D_UNSATISFIABLE; } error() << "Unexpected result from CVC-Lite" << eom; - return D_ERROR; + return resultt::D_ERROR; } diff --git a/src/solvers/flattening/arrays.cpp b/src/solvers/flattening/arrays.cpp index 9f72a8e3475..10c29c2ae76 100644 --- a/src/solvers/flattening/arrays.cpp +++ b/src/solvers/flattening/arrays.cpp @@ -441,7 +441,7 @@ void arrayst::add_array_Ackermann_constraints() equal_exprt values_equal(index_expr1, index_expr2); // add constraint - lazy_constraintt lazy(ARRAY_ACKERMANN, + lazy_constraintt lazy(lazy_typet::ARRAY_ACKERMANN, or_exprt(literal_exprt(!indices_equal_lit), values_equal)); add_array_constraint(lazy, true); // added lazily @@ -634,7 +634,7 @@ void arrayst::add_array_constraints( assert(index_expr1.type()==index_expr2.type()); // add constraint - lazy_constraintt lazy(ARRAY_TYPECAST, + lazy_constraintt lazy(lazy_typet::ARRAY_TYPECAST, equal_exprt(index_expr1, index_expr2)); add_array_constraint(lazy, false); // added immediately } @@ -682,7 +682,8 @@ void arrayst::add_array_constraints_with( assert(false); } - lazy_constraintt lazy(ARRAY_WITH, equal_exprt(index_expr, value)); + lazy_constraintt lazy( + lazy_typet::ARRAY_WITH, equal_exprt(index_expr, value)); add_array_constraint(lazy, false); // added immediately } @@ -722,7 +723,7 @@ void arrayst::add_array_constraints_with( equal_exprt equality_expr(index_expr1, index_expr2); // add constraint - lazy_constraintt lazy(ARRAY_WITH, or_exprt(equality_expr, + lazy_constraintt lazy(lazy_typet::ARRAY_WITH, or_exprt(equality_expr, literal_exprt(guard_lit))); add_array_constraint(lazy, false); // added immediately @@ -862,7 +863,8 @@ void arrayst::add_array_constraints_array_of( assert(base_type_eq(index_expr.type(), expr.op0().type(), ns)); // add constraint - lazy_constraintt lazy(ARRAY_OF, equal_exprt(index_expr, expr.op0())); + lazy_constraintt lazy( + lazy_typet::ARRAY_OF, equal_exprt(index_expr, expr.op0())); add_array_constraint(lazy, false); // added immediately } } @@ -910,7 +912,7 @@ void arrayst::add_array_constraints_if( assert(index_expr1.type()==index_expr2.type()); // add implication - lazy_constraintt lazy(ARRAY_IF, + lazy_constraintt lazy(lazy_typet::ARRAY_IF, or_exprt(literal_exprt(!cond_lit), equal_exprt(index_expr1, index_expr2))); add_array_constraint(lazy, false); // added immediately @@ -939,8 +941,10 @@ void arrayst::add_array_constraints_if( assert(index_expr1.type()==index_expr2.type()); // add implication - lazy_constraintt lazy(ARRAY_IF, or_exprt(literal_exprt(cond_lit), - equal_exprt(index_expr1, index_expr2))); + lazy_constraintt lazy( + lazy_typet::ARRAY_IF, + or_exprt(literal_exprt(cond_lit), + equal_exprt(index_expr1, index_expr2))); add_array_constraint(lazy, false); // added immediately #if 0 // old code for adding, not significantly faster diff --git a/src/solvers/flattening/arrays.h b/src/solvers/flattening/arrays.h index 51a0799187a..3277c4671ec 100644 --- a/src/solvers/flattening/arrays.h +++ b/src/solvers/flattening/arrays.h @@ -68,14 +68,15 @@ class arrayst:public equalityt index_mapt index_map; // adds array constraints lazily - typedef enum lazy_type + enum class lazy_typet { ARRAY_ACKERMANN, ARRAY_WITH, ARRAY_IF, ARRAY_OF, ARRAY_TYPECAST - } lazy_typet; + }; + struct lazy_constraintt { lazy_typet type; diff --git a/src/solvers/flattening/boolbv.cpp b/src/solvers/flattening/boolbv.cpp index aaa63e69fd2..f261452c2b0 100644 --- a/src/solvers/flattening/boolbv.cpp +++ b/src/solvers/flattening/boolbv.cpp @@ -845,7 +845,7 @@ bool boolbvt::is_unbounded_array(const typet &type) const if(type.id()!=ID_array) return false; - if(unbounded_array==U_ALL) + if(unbounded_array==unbounded_arrayt::U_ALL) return true; const exprt &size=to_array_type(type).size(); @@ -854,7 +854,7 @@ bool boolbvt::is_unbounded_array(const typet &type) const if(to_integer(size, s)) return true; - if(unbounded_array==U_AUTO) + if(unbounded_array==unbounded_arrayt::U_AUTO) if(s>1000) // magic number! return true; diff --git a/src/solvers/flattening/boolbv.h b/src/solvers/flattening/boolbv.h index a092be8c3af..578521a6e3d 100644 --- a/src/solvers/flattening/boolbv.h +++ b/src/solvers/flattening/boolbv.h @@ -34,7 +34,7 @@ class boolbvt:public arrayst const namespacet &_ns, propt &_prop): arrayst(_ns, _prop), - unbounded_array(U_NONE), + unbounded_array(unbounded_arrayt::U_NONE), boolbv_width(_ns), bv_utils(_prop), functions(*this), @@ -71,7 +71,7 @@ class boolbvt:public arrayst using arrayst::literal; - typedef enum { U_NONE, U_ALL, U_AUTO } unbounded_arrayt; + enum class unbounded_arrayt { U_NONE, U_ALL, U_AUTO }; unbounded_arrayt unbounded_array; mp_integer get_value(const bvt &bv) diff --git a/src/solvers/flattening/boolbv_abs.cpp b/src/solvers/flattening/boolbv_abs.cpp index 0a9f7a9c4a5..7c93353b45b 100644 --- a/src/solvers/flattening/boolbv_abs.cpp +++ b/src/solvers/flattening/boolbv_abs.cpp @@ -46,13 +46,13 @@ bvt boolbvt::convert_abs(const exprt &expr) bvtypet bvtype=get_bvtype(expr.type()); - if(bvtype==IS_FIXED || - bvtype==IS_SIGNED || - bvtype==IS_UNSIGNED) + if(bvtype==bvtypet::IS_FIXED || + bvtype==bvtypet::IS_SIGNED || + bvtype==bvtypet::IS_UNSIGNED) { return bv_utils.absolute_value(op_bv); } - else if(bvtype==IS_FLOAT) + else if(bvtype==bvtypet::IS_FLOAT) { float_utilst float_utils(prop, to_floatbv_type(expr.type())); return float_utils.abs(op_bv); diff --git a/src/solvers/flattening/boolbv_add_sub.cpp b/src/solvers/flattening/boolbv_add_sub.cpp index 38a7effc5af..9bcb6281be6 100644 --- a/src/solvers/flattening/boolbv_add_sub.cpp +++ b/src/solvers/flattening/boolbv_add_sub.cpp @@ -74,8 +74,8 @@ bvt boolbvt::convert_add_sub(const exprt &expr) bv_utilst::representationt rep= (arithmetic_type.id()==ID_signedbv || - arithmetic_type.id()==ID_fixedbv)?bv_utilst::SIGNED: - bv_utilst::UNSIGNED; + arithmetic_type.id()==ID_fixedbv)?bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED; for(exprt::operandst::const_iterator it=operands.begin()+1; diff --git a/src/solvers/flattening/boolbv_bv_rel.cpp b/src/solvers/flattening/boolbv_bv_rel.cpp index 901cd31fa04..8b2984e2343 100644 --- a/src/solvers/flattening/boolbv_bv_rel.cpp +++ b/src/solvers/flattening/boolbv_bv_rel.cpp @@ -44,32 +44,33 @@ literalt boolbvt::convert_bv_rel(const exprt &expr) if(bv0.size()==bv1.size() && !bv0.empty() && bvtype0==bvtype1) { - if(bvtype0==IS_FLOAT) + if(bvtype0==bvtypet::IS_FLOAT) { float_utilst float_utils(prop, to_floatbv_type(op0.type())); if(rel==ID_le) - return float_utils.relation(bv0, float_utilst::LE, bv1); + return float_utils.relation(bv0, float_utilst::relt::LE, bv1); else if(rel==ID_lt) - return float_utils.relation(bv0, float_utilst::LT, bv1); + return float_utils.relation(bv0, float_utilst::relt::LT, bv1); else if(rel==ID_ge) - return float_utils.relation(bv0, float_utilst::GE, bv1); + return float_utils.relation(bv0, float_utilst::relt::GE, bv1); else if(rel==ID_gt) - return float_utils.relation(bv0, float_utilst::GT, bv1); + return float_utils.relation(bv0, float_utilst::relt::GT, bv1); else return SUB::convert_rest(expr); } else if((op0.type().id()==ID_range && op1.type()==op0.type()) || - bvtype0==IS_SIGNED || - bvtype0==IS_UNSIGNED || - bvtype0==IS_FIXED) + bvtype0==bvtypet::IS_SIGNED || + bvtype0==bvtypet::IS_UNSIGNED || + bvtype0==bvtypet::IS_FIXED) { literalt literal; bv_utilst::representationt rep= - ((bvtype0==IS_SIGNED) || (bvtype0==IS_FIXED))?bv_utilst::SIGNED: - bv_utilst::UNSIGNED; + ((bvtype0==bvtypet::IS_SIGNED) || (bvtype0==bvtypet::IS_FIXED))? + bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED; #if 1 @@ -95,8 +96,8 @@ literalt boolbvt::convert_bv_rel(const exprt &expr) return literal; #endif } - else if((bvtype0==IS_VERILOG_SIGNED || - bvtype0==IS_VERILOG_UNSIGNED) && + else if((bvtype0==bvtypet::IS_VERILOG_SIGNED || + bvtype0==bvtypet::IS_VERILOG_UNSIGNED) && op0.type()==op1.type()) { // extract number bits @@ -111,7 +112,7 @@ literalt boolbvt::convert_bv_rel(const exprt &expr) for(std::size_t i=0; i // new stuff -typedef enum +enum class bvtypet { IS_BV, IS_SIGNED, IS_UNSIGNED, IS_FLOAT, IS_FIXED, IS_C_BOOL, IS_VERILOG_SIGNED, IS_VERILOG_UNSIGNED, IS_RANGE, IS_UNKNOWN, IS_C_ENUM, IS_C_BIT_FIELD -} bvtypet; +}; bvtypet get_bvtype(const typet &type); diff --git a/src/solvers/flattening/boolbv_typecast.cpp b/src/solvers/flattening/boolbv_typecast.cpp index 5ffcd763f74..c0c2b9abb81 100644 --- a/src/solvers/flattening/boolbv_typecast.cpp +++ b/src/solvers/flattening/boolbv_typecast.cpp @@ -62,7 +62,7 @@ bool boolbvt::type_conversion( bvtypet dest_bvtype=get_bvtype(dest_type); bvtypet src_bvtype=get_bvtype(src_type); - if(src_bvtype==IS_C_BIT_FIELD) + if(src_bvtype==bvtypet::IS_C_BIT_FIELD) return type_conversion( c_bit_field_replacement_type(to_c_bit_field_type(src_type), ns), @@ -70,7 +70,7 @@ bool boolbvt::type_conversion( dest_type, dest); - if(dest_bvtype==IS_C_BIT_FIELD) + if(dest_bvtype==bvtypet::IS_C_BIT_FIELD) return type_conversion( src_type, @@ -144,10 +144,10 @@ bool boolbvt::type_conversion( switch(dest_bvtype) { - case IS_RANGE: - if(src_bvtype==IS_UNSIGNED || - src_bvtype==IS_SIGNED || - src_bvtype==IS_C_BOOL) + case bvtypet::IS_RANGE: + if(src_bvtype==bvtypet::IS_UNSIGNED || + src_bvtype==bvtypet::IS_SIGNED || + src_bvtype==bvtypet::IS_C_BOOL) { mp_integer dest_from=to_range_type(dest_type).get_from(); @@ -161,7 +161,7 @@ bool boolbvt::type_conversion( return false; } } - else if(src_bvtype==IS_RANGE) // range to range + else if(src_bvtype==bvtypet::IS_RANGE) // range to range { mp_integer src_from=to_range_type(src_type).get_from(); mp_integer dest_from=to_range_type(dest_type).get_from(); @@ -186,30 +186,30 @@ bool boolbvt::type_conversion( } break; - case IS_FLOAT: // to float + case bvtypet::IS_FLOAT: // to float { float_utilst float_utils(prop); switch(src_bvtype) { - case IS_FLOAT: // float to float + case bvtypet::IS_FLOAT: // float to float // we don't have a rounding mode here, // which is why we refuse. break; - case IS_SIGNED: // signed to float - case IS_C_ENUM: + case bvtypet::IS_SIGNED: // signed to float + case bvtypet::IS_C_ENUM: float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); dest=float_utils.from_signed_integer(src); return false; - case IS_UNSIGNED: // unsigned to float - case IS_C_BOOL: // _Bool to float + case bvtypet::IS_UNSIGNED: // unsigned to float + case bvtypet::IS_C_BOOL: // _Bool to float float_utils.spec=ieee_float_spect(to_floatbv_type(dest_type)); dest=float_utils.from_unsigned_integer(src); return false; - case IS_BV: + case bvtypet::IS_BV: assert(src_width==dest_width); dest=src; return false; @@ -236,8 +236,8 @@ bool boolbvt::type_conversion( } break; - case IS_FIXED: - if(src_bvtype==IS_FIXED) + case bvtypet::IS_FIXED: + if(src_bvtype==bvtypet::IS_FIXED) { // fixed to fixed @@ -278,16 +278,16 @@ bool boolbvt::type_conversion( return false; } - else if(src_bvtype==IS_BV) + else if(src_bvtype==bvtypet::IS_BV) { assert(src_width==dest_width); dest=src; return false; } - else if(src_bvtype==IS_UNSIGNED || - src_bvtype==IS_SIGNED || - src_bvtype==IS_C_BOOL || - src_bvtype==IS_C_ENUM) + else if(src_bvtype==bvtypet::IS_UNSIGNED || + src_bvtype==bvtypet::IS_SIGNED || + src_bvtype==bvtypet::IS_C_BOOL || + src_bvtype==bvtypet::IS_C_ENUM) { // integer to fixed @@ -305,7 +305,7 @@ bool boolbvt::type_conversion( l=src[i]; else { - if(src_bvtype==IS_SIGNED || src_bvtype==IS_C_ENUM) + if(src_bvtype==bvtypet::IS_SIGNED || src_bvtype==bvtypet::IS_C_ENUM) l=src[src_width-1]; // sign extension else l=const_literal(false); // zero extension @@ -336,17 +336,17 @@ bool boolbvt::type_conversion( } break; - case IS_UNSIGNED: - case IS_SIGNED: - case IS_C_ENUM: + case bvtypet::IS_UNSIGNED: + case bvtypet::IS_SIGNED: + case bvtypet::IS_C_ENUM: switch(src_bvtype) { - case IS_FLOAT: // float to integer + case bvtypet::IS_FLOAT: // float to integer // we don't have a rounding mode here, // which is why we refuse. break; - case IS_FIXED: // fixed to integer + case bvtypet::IS_FIXED: // fixed to integer { std::size_t op_fraction_bits= to_fixedbv_type(src_type).get_fraction_bits(); @@ -357,7 +357,7 @@ bool boolbvt::type_conversion( dest.push_back(src[i+op_fraction_bits]); else { - if(dest_bvtype==IS_SIGNED) + if(dest_bvtype==bvtypet::IS_SIGNED) dest.push_back(src[src_width-1]); // sign extension else dest.push_back(const_literal(false)); // zero extension @@ -377,17 +377,17 @@ bool boolbvt::type_conversion( return false; } - case IS_UNSIGNED: // integer to integer - case IS_SIGNED: - case IS_C_ENUM: - case IS_C_BOOL: + case bvtypet::IS_UNSIGNED: // integer to integer + case bvtypet::IS_SIGNED: + case bvtypet::IS_C_ENUM: + case bvtypet::IS_C_BOOL: { // We do sign extension for any source type // that is signed, independently of the // destination type. // E.g., ((short)(ulong)(short)-1)==-1 bool sign_extension= - src_bvtype==IS_SIGNED || src_bvtype==IS_C_ENUM; + src_bvtype==bvtypet::IS_SIGNED || src_bvtype==bvtypet::IS_C_ENUM; for(std::size_t i=0; itype().id()==ID_signedbv?bv_utilst::SIGNED: - bv_utilst::UNSIGNED; + it->type().id()==ID_signedbv?bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED; bvt op=convert_bv(*it); @@ -521,7 +522,8 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr) { bvt element_size_bv= bv_utils.build_constant(element_size, bv.size()); - bv=bv_utils.divider(bv, element_size_bv, bv_utilst::SIGNED); + bv=bv_utils.divider( + bv, element_size_bv, bv_utilst::representationt::SIGNED); } return bv; @@ -738,8 +740,8 @@ void bv_pointerst::offset_arithmetic( bvt bv_index=convert_bv(index); bv_utilst::representationt rep= - index.type().id()==ID_signedbv?bv_utilst::SIGNED: - bv_utilst::UNSIGNED; + index.type().id()==ID_signedbv?bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED; bv_index=bv_utils.extension(bv_index, offset_bits, rep); diff --git a/src/solvers/flattening/bv_utils.cpp b/src/solvers/flattening/bv_utils.cpp index dcecce593c4..7cb7aeeb875 100644 --- a/src/solvers/flattening/bv_utils.cpp +++ b/src/solvers/flattening/bv_utils.cpp @@ -225,7 +225,7 @@ bvt bv_utilst::extension( assert(old_size!=0); literalt extend_with= - (rep==SIGNED && !bv.empty())?bv[old_size-1]: + (rep==representationt::SIGNED && !bv.empty())?bv[old_size-1]: const_literal(false); for(std::size_t i=old_size; i=0 if // x is negative, always representable, and @@ -612,9 +612,9 @@ literalt bv_utilst::overflow_sub( return prop.lselect(op1_is_int_min, !op0_is_negative, - overflow_add(op0, negate(op1), SIGNED)); + overflow_add(op0, negate(op1), representationt::SIGNED)); } - else if(rep==UNSIGNED) + else if(rep==representationt::UNSIGNED) { // overflow is simply _negated_ carry-out return !carry_out(op0, inverted(op1), const_literal(true)); @@ -643,7 +643,7 @@ void bv_utilst::adder_no_overflow( { const bvt tmp_op=subtract?inverted(op):op; - if(rep==SIGNED) + if(rep==representationt::SIGNED) { // an overflow occurs if the signs of the two operands are the same // and the sign of the sum is the opposite @@ -659,7 +659,7 @@ void bv_utilst::adder_no_overflow( prop.l_set_to_false( prop.land(sign_the_same, prop.lxor(sum[sum.size()-1], old_sign))); } - else if(rep==UNSIGNED) + else if(rep==representationt::UNSIGNED) { literalt carry_out; adder(sum, tmp_op, const_literal(subtract), carry_out); @@ -746,15 +746,15 @@ bvt bv_utilst::shift(const bvt &src, const shiftt s, std::size_t dist) switch(s) { - case LEFT: + case shiftt::LEFT: l=(dist<=i?src[i-dist]:const_literal(false)); break; - case ARIGHT: + case shiftt::ARIGHT: l=(i+dist rem < op1 prop.l_set_to_true( - prop.limplies(is_not_zero, lt_or_le(false, rem, op1, UNSIGNED))); + prop.limplies( + is_not_zero, lt_or_le(false, rem, op1, representationt::UNSIGNED))); // op1!=0 => res <= op0 prop.l_set_to_true( - prop.limplies(is_not_zero, lt_or_le(true, res, op0, UNSIGNED))); + prop.limplies( + is_not_zero, lt_or_le(true, res, op0, representationt::UNSIGNED))); } @@ -1749,9 +1759,9 @@ literalt bv_utilst::lt_or_le( literalt result; - if(rep==SIGNED) + if(rep==representationt::SIGNED) result=prop.lxor(prop.lequal(top0, top1), carry); - else if(rep==UNSIGNED) + else if(rep==representationt::UNSIGNED) result=!carry; else assert(false); @@ -1803,7 +1813,7 @@ literalt bv_utilst::signed_less_than( const bvt &bv0, const bvt &bv1) { - return lt_or_le(false, bv0, bv1, SIGNED); + return lt_or_le(false, bv0, bv1, representationt::SIGNED); } /*******************************************************************\ diff --git a/src/solvers/flattening/bv_utils.h b/src/solvers/flattening/bv_utils.h index b14fc96b3c4..6c415b117d0 100644 --- a/src/solvers/flattening/bv_utils.h +++ b/src/solvers/flattening/bv_utils.h @@ -27,7 +27,7 @@ class bv_utilst public: explicit bv_utilst(propt &_prop):prop(_prop) { } - typedef enum { SIGNED, UNSIGNED } representationt; + enum class representationt { SIGNED, UNSIGNED }; bvt build_constant(const mp_integer &i, std::size_t width); @@ -67,7 +67,7 @@ class bv_utilst literalt overflow_sub(const bvt &op0, const bvt &op1, representationt rep); literalt carry_out(const bvt &op0, const bvt &op1, literalt carry_in); - typedef enum { LEFT, LRIGHT, ARIGHT } shiftt; + enum class shiftt { LEFT, LRIGHT, ARIGHT }; bvt shift(const bvt &op, const shiftt shift, std::size_t distance); bvt shift(const bvt &op, const shiftt shift, const bvt &distance); @@ -173,12 +173,12 @@ class bv_utilst bvt sign_extension(const bvt &bv, std::size_t new_size) { - return extension(bv, new_size, SIGNED); + return extension(bv, new_size, representationt::SIGNED); } bvt zero_extension(const bvt &bv, std::size_t new_size) { - return extension(bv, new_size, UNSIGNED); + return extension(bv, new_size, representationt::UNSIGNED); } bvt zeros(std::size_t new_size) const diff --git a/src/solvers/floatbv/float_bv.cpp b/src/solvers/floatbv/float_bv.cpp index 6a0e37fc1d8..0d07a9d8ee9 100644 --- a/src/solvers/floatbv/float_bv.cpp +++ b/src/solvers/floatbv/float_bv.cpp @@ -94,13 +94,13 @@ exprt float_bvt::convert(const exprt &expr) else if(expr.id()==ID_isnormal) return isnormal(expr.op0(), get_spec(expr.op0())); else if(expr.id()==ID_lt) - return relation(expr.op0(), LT, expr.op1(), get_spec(expr.op0())); + return relation(expr.op0(), relt::LT, expr.op1(), get_spec(expr.op0())); else if(expr.id()==ID_gt) - return relation(expr.op0(), GT, expr.op1(), get_spec(expr.op0())); + return relation(expr.op0(), relt::GT, expr.op1(), get_spec(expr.op0())); else if(expr.id()==ID_le) - return relation(expr.op0(), LE, expr.op1(), get_spec(expr.op0())); + return relation(expr.op0(), relt::LE, expr.op1(), get_spec(expr.op0())); else if(expr.id()==ID_ge) - return relation(expr.op0(), GE, expr.op1(), get_spec(expr.op0())); + return relation(expr.op0(), relt::GE, expr.op1(), get_spec(expr.op0())); else if(expr.id()==ID_sign) return sign_bit(expr.op0()); @@ -1034,12 +1034,12 @@ exprt float_bvt::relation( const exprt &src2, const ieee_float_spect &spec) { - if(rel==GT) - return relation(src2, LT, src1, spec); // swapped - else if(rel==GE) - return relation(src2, LE, src1, spec); // swapped + if(rel==relt::GT) + return relation(src2, relt::LT, src1, spec); // swapped + else if(rel==relt::GE) + return relation(src2, relt::LE, src1, spec); // swapped - assert(rel==EQ || rel==LT || rel==LE); + assert(rel==relt::EQ || rel==relt::LT || rel==relt::LE); // special cases: -0 and 0 are equal exprt is_zero1=is_zero(src1, spec); @@ -1051,7 +1051,7 @@ exprt float_bvt::relation( exprt isnan2=isnan(src2, spec); exprt nan=or_exprt(isnan1, isnan2); - if(rel==LT || rel==LE) + if(rel==relt::LT || rel==relt::LE) { exprt bitwise_equal=equal_exprt(src1, src2); @@ -1081,7 +1081,7 @@ exprt float_bvt::relation( sign_bit(src1), less_than2); - if(rel==LT) + if(rel==relt::LT) { exprt and_bv(ID_and, bool_typet()); and_bv.copy_to_operands(less_than3); @@ -1092,7 +1092,7 @@ exprt float_bvt::relation( return and_bv; } - else if(rel==LE) + else if(rel==relt::LE) { exprt or_bv(ID_or, bool_typet()); or_bv.copy_to_operands(less_than3); @@ -1104,7 +1104,7 @@ exprt float_bvt::relation( else assert(false); } - else if(rel==EQ) + else if(rel==relt::EQ) { exprt bitwise_equal=equal_exprt(src1, src2); diff --git a/src/solvers/floatbv/float_bv.h b/src/solvers/floatbv/float_bv.h index 74f31f8dc00..1ae6a63ffe2 100644 --- a/src/solvers/floatbv/float_bv.h +++ b/src/solvers/floatbv/float_bv.h @@ -93,7 +93,7 @@ class float_bvt const ieee_float_spect &dest_spec); // relations - typedef enum { LT, LE, EQ, GT, GE } relt; + enum class relt { LT, LE, EQ, GT, GE }; exprt relation( const exprt &, relt rel, diff --git a/src/solvers/floatbv/float_utils.cpp b/src/solvers/floatbv/float_utils.cpp index a772ae0b8a7..3660aced265 100644 --- a/src/solvers/floatbv/float_utils.cpp +++ b/src/solvers/floatbv/float_utils.cpp @@ -177,7 +177,8 @@ bvt float_utilst::to_integer( bvt offset=bv_utils.build_constant(fraction.size()-1, unpacked.exponent.size()); bvt distance=bv_utils.sub(offset, unpacked.exponent); - bvt shift_result=bv_utils.shift(fraction, bv_utilst::LRIGHT, distance); + bvt shift_result=bv_utils.shift( + fraction, bv_utilst::shiftt::LRIGHT, distance); // if the exponent is negative, we have zero anyways bvt result=shift_result; @@ -788,12 +789,12 @@ literalt float_utilst::relation( relt rel, const bvt &src2) { - if(rel==GT) - return relation(src2, LT, src1); // swapped - else if(rel==GE) - return relation(src2, LE, src1); // swapped + if(rel==relt::GT) + return relation(src2, relt::LT, src1); // swapped + else if(rel==relt::GE) + return relation(src2, relt::LE, src1); // swapped - assert(rel==EQ || rel==LT || rel==LE); + assert(rel==relt::EQ || rel==relt::LT || rel==relt::LE); // special cases: -0 and 0 are equal literalt is_zero1=is_zero(src1); @@ -805,7 +806,7 @@ literalt float_utilst::relation( literalt is_NaN2=is_NaN(src2); literalt NaN=prop.lor(is_NaN1, is_NaN2); - if(rel==LT || rel==LE) + if(rel==relt::LT || rel==relt::LE) { literalt bitwise_equal=bv_utils.equal(src1, src2); @@ -828,7 +829,7 @@ literalt float_utilst::relation( sign_bit(src1), less_than2); - if(rel==LT) + if(rel==relt::LT) { bvt and_bv; and_bv.push_back(less_than3); @@ -838,7 +839,7 @@ literalt float_utilst::relation( return prop.land(and_bv); } - else if(rel==LE) + else if(rel==relt::LE) { bvt or_bv; or_bv.push_back(less_than3); @@ -850,7 +851,7 @@ literalt float_utilst::relation( else assert(false); } - else if(rel==EQ) + else if(rel==relt::EQ) { literalt bitwise_equal=bv_utils.equal(src1, src2); @@ -1153,7 +1154,7 @@ void float_utilst::normalization_shift(bvt &fraction, bvt &exponent) // If so, shift the zeros out left by 'distance'. // Otherwise, leave as is. const bvt shifted= - bv_utils.shift(fraction, bv_utilst::LEFT, distance); + bv_utils.shift(fraction, bv_utilst::shiftt::LEFT, distance); fraction= bv_utils.select(prefix_is_zero, shifted, fraction); @@ -1769,7 +1770,7 @@ bvt float_utilst::sticky_right_shift( { if(dist[stage]!=const_literal(false)) { - bvt tmp=bv_utils.shift(result, bv_utilst::LRIGHT, d); + bvt tmp=bv_utils.shift(result, bv_utilst::shiftt::LRIGHT, d); bvt lost_bits; diff --git a/src/solvers/floatbv/float_utils.h b/src/solvers/floatbv/float_utils.h index daa9609cba7..0396700f193 100644 --- a/src/solvers/floatbv/float_utils.h +++ b/src/solvers/floatbv/float_utils.h @@ -132,7 +132,7 @@ class float_utilst bvt conversion(const bvt &src, const ieee_float_spect &dest_spec); // relations - typedef enum { LT, LE, EQ, GT, GE } relt; + enum class relt { LT, LE, EQ, GT, GE }; literalt relation(const bvt &src1, relt rel, const bvt &src2); // constants diff --git a/src/solvers/prop/aig_prop.h b/src/solvers/prop/aig_prop.h index d88b5e86a9e..7c5ecf6bba2 100644 --- a/src/solvers/prop/aig_prop.h +++ b/src/solvers/prop/aig_prop.h @@ -57,7 +57,7 @@ class aig_prop_baset:public propt { assert(0); return tvt::unknown(); } resultt prop_solve() override - { assert(0); return P_ERROR; } + { assert(0); return resultt::P_ERROR; } protected: aigt &dest; diff --git a/src/solvers/prop/cover_goals.cpp b/src/solvers/prop/cover_goals.cpp index 699177b25ad..b4f2e614bf3 100644 --- a/src/solvers/prop/cover_goals.cpp +++ b/src/solvers/prop/cover_goals.cpp @@ -142,10 +142,10 @@ decision_proceduret::resultt cover_goalst::operator()() switch(dec_result) { - case decision_proceduret::D_UNSATISFIABLE: // DONE + case decision_proceduret::resultt::D_UNSATISFIABLE: // DONE return dec_result; - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: // mark the goals we got, and notify observers mark(); break; @@ -155,8 +155,8 @@ decision_proceduret::resultt cover_goalst::operator()() return dec_result; } } - while(dec_result==decision_proceduret::D_SATISFIABLE && + while(dec_result==decision_proceduret::resultt::D_SATISFIABLE && number_covered()(type)<<24); } }; @@ -71,12 +71,12 @@ class qdimacs_cnft:public dimacs_cnft void add_existential_quantifier(const literalt l) { - add_quantifier(quantifiert(quantifiert::EXISTENTIAL, l)); + add_quantifier(quantifiert(quantifiert::typet::EXISTENTIAL, l)); } void add_universal_quantifier(const literalt l) { - add_quantifier(quantifiert(quantifiert::UNIVERSAL, l)); + add_quantifier(quantifiert(quantifiert::typet::UNIVERSAL, l)); } bool is_quantified(const literalt l) const; diff --git a/src/solvers/qbf/qdimacs_core.h b/src/solvers/qbf/qdimacs_core.h index 4f4a7c70a18..fd1684b2ac3 100644 --- a/src/solvers/qbf/qdimacs_core.h +++ b/src/solvers/qbf/qdimacs_core.h @@ -21,7 +21,7 @@ class qdimacs_coret:public qdimacs_cnft virtual tvt l_get(literalt a) const=0; virtual bool is_in_core(literalt l) const=0; - typedef enum { M_TRUE, M_FALSE, M_DONTCARE, M_COMPLEX } modeltypet; + enum modeltypet { M_TRUE, M_FALSE, M_DONTCARE, M_COMPLEX }; virtual modeltypet m_get(literalt a) const=0; typedef std::pair symbol_mapt; diff --git a/src/solvers/refinement/bv_refinement_loop.cpp b/src/solvers/refinement/bv_refinement_loop.cpp index 228de631637..3d39c16ac80 100644 --- a/src/solvers/refinement/bv_refinement_loop.cpp +++ b/src/solvers/refinement/bv_refinement_loop.cpp @@ -83,7 +83,7 @@ decision_proceduret::resultt bv_refinementt::dec_solve() status() << "BV-Refinement: iteration " << iteration << eom; // output the very same information in a structured fashion - if(ui==ui_message_handlert::XML_UI) + if(ui==ui_message_handlert::uit::XML_UI) { xmlt xml("refinement-iteration"); xml.data=std::to_string(iteration); @@ -92,27 +92,27 @@ decision_proceduret::resultt bv_refinementt::dec_solve() switch(prop_solve()) { - case D_SATISFIABLE: + case resultt::D_SATISFIABLE: check_SAT(); if(!progress) { status() << "BV-Refinement: got SAT, and it simulates => SAT" << eom; status() << "Total iterations: " << iteration << eom; - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } else status() << "BV-Refinement: got SAT, and it is spurious, refining" << eom; break; - case D_UNSATISFIABLE: + case resultt::D_UNSATISFIABLE: check_UNSAT(); if(!progress) { status() << "BV-Refinement: got UNSAT, and the proof passes => UNSAT" << eom; status() << "Total iterations: " << iteration << eom; - return D_UNSATISFIABLE; + return resultt::D_UNSATISFIABLE; } else status() << "BV-Refinement: got UNSAT, and the proof fails, refining" @@ -120,7 +120,7 @@ decision_proceduret::resultt bv_refinementt::dec_solve() break; default: - return D_ERROR; + return resultt::D_ERROR; } } } @@ -161,9 +161,9 @@ decision_proceduret::resultt bv_refinementt::prop_solve() switch(result) { - case propt::P_SATISFIABLE: return D_SATISFIABLE; - case propt::P_UNSATISFIABLE: return D_UNSATISFIABLE; - default: return D_ERROR; + case propt::resultt::P_SATISFIABLE: return resultt::D_SATISFIABLE; + case propt::resultt::P_UNSATISFIABLE: return resultt::D_UNSATISFIABLE; + default: return resultt::D_ERROR; } } diff --git a/src/solvers/refinement/refine_arithmetic.cpp b/src/solvers/refinement/refine_arithmetic.cpp index 3c59537900b..1f08874abfa 100644 --- a/src/solvers/refinement/refine_arithmetic.cpp +++ b/src/solvers/refinement/refine_arithmetic.cpp @@ -413,21 +413,24 @@ void bv_refinementt::check_SAT(approximationt &a) r=bv_utils.multiplier( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv? - bv_utilst::SIGNED:bv_utilst::UNSIGNED); + bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED); } else if(a.expr.id()==ID_div) { r=bv_utils.divider( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv? - bv_utilst::SIGNED:bv_utilst::UNSIGNED); + bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED); } else if(a.expr.id()==ID_mod) { r=bv_utils.remainder( a.op0_bv, a.op1_bv, a.expr.type().id()==ID_signedbv? - bv_utilst::SIGNED:bv_utilst::UNSIGNED); + bv_utilst::representationt::SIGNED: + bv_utilst::representationt::UNSIGNED); } else assert(0); diff --git a/src/solvers/refinement/refine_arrays.cpp b/src/solvers/refinement/refine_arrays.cpp index 2296f3c42ad..b6d528b5dc0 100644 --- a/src/solvers/refinement/refine_arrays.cpp +++ b/src/solvers/refinement/refine_arrays.cpp @@ -67,7 +67,7 @@ void bv_refinementt::arrays_overapproximated() { satcheck_no_simplifiert sat_check; bv_pointerst solver(ns, sat_check); - solver.unbounded_array=bv_pointerst::U_ALL; + solver.unbounded_array=bv_pointerst::unbounded_arrayt::U_ALL; exprt current=(*it).lazy; @@ -101,12 +101,12 @@ void bv_refinementt::arrays_overapproximated() exprt simplified=get(current); solver << simplified; - switch(sat_check.prop_solve()) + switch(static_cast(sat_check.prop_solve())) { - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: ++it; break; - case decision_proceduret::D_UNSATISFIABLE: + case decision_proceduret::resultt::D_UNSATISFIABLE: prop.l_set_to_true(convert(current)); nb_active++; lazy_array_constraints.erase(it++); diff --git a/src/solvers/refinement/string_constraint_generator_main.cpp b/src/solvers/refinement/string_constraint_generator_main.cpp index 85f79f8bcf6..796b0554696 100644 --- a/src/solvers/refinement/string_constraint_generator_main.cpp +++ b/src/solvers/refinement/string_constraint_generator_main.cpp @@ -687,6 +687,7 @@ exprt string_constraint_generatort::add_axioms_for_char_pointer( return char_pointer.op0(); // TODO: we do not know what to do in the other cases assert(false); + return exprt(); } /*******************************************************************\ diff --git a/src/solvers/refinement/string_refinement.cpp b/src/solvers/refinement/string_refinement.cpp index c205e710266..7adc902070d 100644 --- a/src/solvers/refinement/string_refinement.cpp +++ b/src/solvers/refinement/string_refinement.cpp @@ -614,7 +614,7 @@ decision_proceduret::resultt string_refinementt::dec_solve() // Initial try without index set decision_proceduret::resultt res=supert::dec_solve(); - if(res==D_SATISFIABLE) + if(res==resultt::D_SATISFIABLE) { if(!check_axioms()) { @@ -624,7 +624,7 @@ decision_proceduret::resultt string_refinementt::dec_solve() { debug() << "check_SAT: the model is correct" << eom; concretize_lengths(); - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } } @@ -639,7 +639,7 @@ decision_proceduret::resultt string_refinementt::dec_solve() switch(res) { - case D_SATISFIABLE: + case resultt::D_SATISFIABLE: if(!check_axioms()) { debug() << "check_SAT: got SAT but the model is not correct" << eom; @@ -648,7 +648,7 @@ decision_proceduret::resultt string_refinementt::dec_solve() { debug() << "check_SAT: the model is correct" << eom; concretize_lengths(); - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } debug() << "refining..." << eom; @@ -667,13 +667,13 @@ decision_proceduret::resultt string_refinementt::dec_solve() if(do_concretizing) { concretize_results(); - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } else { debug() << "check_SAT: the model is correct and " << "does not need concretizing" << eom; - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } } @@ -689,13 +689,13 @@ decision_proceduret::resultt string_refinementt::dec_solve() } break; default: - debug() << "check_SAT: default return " << res << eom; + debug() << "check_SAT: default return " << static_cast(res) << eom; return res; } } debug() << "string_refinementt::dec_solve reached the maximum number" << "of steps allowed" << eom; - return D_ERROR; + return resultt::D_ERROR; } /*******************************************************************\ @@ -1223,7 +1223,7 @@ bool string_refinementt::check_axioms() switch(solver()) { - case decision_proceduret::D_SATISFIABLE: + case decision_proceduret::resultt::D_SATISFIABLE: { exprt val=solver.get(axiom_in_model.univ_var()); debug() << "string constraint can be violated for " @@ -1232,7 +1232,7 @@ bool string_refinementt::check_axioms() violated[i]=val; } break; - case decision_proceduret::D_UNSATISFIABLE: + case decision_proceduret::resultt::D_UNSATISFIABLE: break; default: throw "failure in checking axiom"; diff --git a/src/solvers/sat/cnf.h b/src/solvers/sat/cnf.h index 49af573bda8..644d62999e4 100644 --- a/src/solvers/sat/cnf.h +++ b/src/solvers/sat/cnf.h @@ -63,7 +63,7 @@ class cnft:public propt class cnf_solvert:public cnft { public: - cnf_solvert():status(INIT), clause_counter(0) + cnf_solvert():status(statust::INIT), clause_counter(0) { } @@ -73,7 +73,7 @@ class cnf_solvert:public cnft } protected: - typedef enum { INIT, SAT, UNSAT, ERROR } statust; + enum class statust { INIT, SAT, UNSAT, ERROR }; statust status; size_t clause_counter; }; diff --git a/src/solvers/sat/cnf_clause_list.h b/src/solvers/sat/cnf_clause_list.h index ca9f652fd72..82c0cb6f572 100644 --- a/src/solvers/sat/cnf_clause_list.h +++ b/src/solvers/sat/cnf_clause_list.h @@ -33,7 +33,7 @@ class cnf_clause_listt:public cnft return tvt::unknown(); } - virtual resultt prop_solve() { return P_ERROR; } + virtual resultt prop_solve() { return resultt::P_ERROR; } virtual size_t no_clauses() const { return clauses.size(); } diff --git a/src/solvers/sat/dimacs_cnf.h b/src/solvers/sat/dimacs_cnf.h index 1dac83b4a89..de8763c4c29 100644 --- a/src/solvers/sat/dimacs_cnf.h +++ b/src/solvers/sat/dimacs_cnf.h @@ -50,7 +50,7 @@ class dimacs_cnf_dumpt:public cnft virtual resultt prop_solve() { - return P_ERROR; + return resultt::P_ERROR; } virtual tvt l_get(literalt) const diff --git a/src/solvers/sat/pbs_dimacs_cnf.cpp b/src/solvers/sat/pbs_dimacs_cnf.cpp index 073c16ad89b..5c45f8e0a09 100644 --- a/src/solvers/sat/pbs_dimacs_cnf.cpp +++ b/src/solvers/sat/pbs_dimacs_cnf.cpp @@ -247,9 +247,9 @@ propt::resultt pbs_dimacs_cnft::prop_solve() } if(result) - return P_SATISFIABLE; + return resultt::P_SATISFIABLE; else - return P_UNSATISFIABLE; + return resultt::P_UNSATISFIABLE; } /*******************************************************************\ diff --git a/src/solvers/sat/satcheck_minisat2.cpp b/src/solvers/sat/satcheck_minisat2.cpp index c17f7f553f8..eaccd29db64 100644 --- a/src/solvers/sat/satcheck_minisat2.cpp +++ b/src/solvers/sat/satcheck_minisat2.cpp @@ -210,7 +210,7 @@ Function: satcheck_minisat2_baset::prop_solve template propt::resultt satcheck_minisat2_baset::prop_solve() { - assert(status!=ERROR); + assert(status!=statust::ERROR); { messaget::status() << @@ -251,8 +251,8 @@ propt::resultt satcheck_minisat2_baset::prop_solve() messaget::status() << "SAT checker: instance is SATISFIABLE" << eom; assert(solver->model.size()!=0); - status=SAT; - return P_SATISFIABLE; + status=statust::SAT; + return resultt::P_SATISFIABLE; } else { @@ -262,15 +262,15 @@ propt::resultt satcheck_minisat2_baset::prop_solve() } } - status=UNSAT; - return P_UNSATISFIABLE; + status=statust::UNSAT; + return resultt::P_UNSATISFIABLE; } catch(Minisat::OutOfMemoryException) { messaget::error() << "SAT checker ran out of memory" << eom; - status=ERROR; - return P_ERROR; + status=statust::ERROR; + return resultt::P_ERROR; } } diff --git a/src/solvers/sat/satcheck_zchaff.h b/src/solvers/sat/satcheck_zchaff.h index 218c3d3c1c1..78a0d595740 100644 --- a/src/solvers/sat/satcheck_zchaff.h +++ b/src/solvers/sat/satcheck_zchaff.h @@ -37,7 +37,7 @@ class satcheck_zchaff_baset:public cnf_clause_listt protected: CSolver *solver; - typedef enum { INIT, SAT, UNSAT, ERROR } statust; + enum statust { INIT, SAT, UNSAT, ERROR }; statust status; }; diff --git a/src/solvers/smt1/smt1_conv.cpp b/src/solvers/smt1/smt1_conv.cpp index d7c89ed8921..e9b71d87956 100644 --- a/src/solvers/smt1/smt1_conv.cpp +++ b/src/solvers/smt1/smt1_conv.cpp @@ -88,7 +88,7 @@ decision_proceduret::resultt smt1_convt::dec_solve() { write_footer(); out.flush(); - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } /*******************************************************************\ diff --git a/src/solvers/smt1/smt1_conv.h b/src/solvers/smt1/smt1_conv.h index 5cdf736bda6..4a078a0d772 100644 --- a/src/solvers/smt1/smt1_conv.h +++ b/src/solvers/smt1/smt1_conv.h @@ -28,8 +28,17 @@ class member_exprt; class smt1_convt:public prop_convt { public: - typedef enum - { GENERIC, BOOLECTOR, CVC3, CVC4, MATHSAT, OPENSMT, YICES, Z3 } solvert; + enum class solvert + { + GENERIC, + BOOLECTOR, + CVC3, + CVC4, + MATHSAT, + OPENSMT, + YICES, + Z3 + }; smt1_convt( const namespacet &_ns, diff --git a/src/solvers/smt1/smt1_dec.cpp b/src/solvers/smt1/smt1_dec.cpp index e994ba109d2..fc01925d883 100644 --- a/src/solvers/smt1/smt1_dec.cpp +++ b/src/solvers/smt1/smt1_dec.cpp @@ -41,14 +41,14 @@ Function: smt1_dect::decision_procedure_text std::string smt1_dect::decision_procedure_text() const { return "SMT1 "+logic+" using "+ - (solver==GENERIC?"Generic": - solver==BOOLECTOR?"Boolector": - solver==CVC3?"CVC3": - solver==CVC4?"CVC3": - solver==MATHSAT?"MathSAT": - solver==OPENSMT?"OpenSMT": - solver==YICES?"Yices": - solver==Z3?"Z3": + (solver==solvert::GENERIC?"Generic": + solver==solvert::BOOLECTOR?"Boolector": + solver==solvert::CVC3?"CVC3": + solver==solvert::CVC4?"CVC3": + solver==solvert::MATHSAT?"MathSAT": + solver==solvert::OPENSMT?"OpenSMT": + solver==solvert::YICES?"Yices": + solver==solvert::Z3?"Z3": "(unknown)"); } @@ -125,7 +125,7 @@ decision_proceduret::resultt smt1_dect::dec_solve() switch(solver) { - case BOOLECTOR: + case solvert::BOOLECTOR: // -rwl0 disables rewriting, which makes things slower, // but in return values for arrays appear // command = "boolector -rwl0 --smt " @@ -136,34 +136,34 @@ decision_proceduret::resultt smt1_dect::dec_solve() + temp_result_filename; break; - case CVC3: + case solvert::CVC3: command = "cvc3 +model -lang smtlib -output-lang smtlib " + temp_out_filename + " > " + temp_result_filename; break; - case CVC4: + case solvert::CVC4: command = "cvc4 -L smt1 " + temp_out_filename + " > " + temp_result_filename; break; - case MATHSAT: + case solvert::MATHSAT: command = "mathsat -model -input=smt" " < "+temp_out_filename + " > "+temp_result_filename; break; - case OPENSMT: + case solvert::OPENSMT: command = "opensmt " + temp_out_filename + " > " + temp_result_filename; break; - case YICES: + case solvert::YICES: // command = "yices -smt -e " // Calling convention for older versions command = "yices-smt --full-model " // Calling for 2.2.1 + temp_out_filename @@ -171,7 +171,7 @@ decision_proceduret::resultt smt1_dect::dec_solve() + temp_result_filename; break; - case Z3: + case solvert::Z3: command = "z3 -smt " + temp_out_filename + " > " @@ -190,39 +190,39 @@ decision_proceduret::resultt smt1_dect::dec_solve() if(res<0) { error() << "error running SMT1 solver" << eom; - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } std::ifstream in(temp_result_filename.c_str()); switch(solver) { - case BOOLECTOR: + case solvert::BOOLECTOR: return read_result_boolector(in); - case CVC3: + case solvert::CVC3: return read_result_cvc3(in); - case CVC4: + case solvert::CVC4: error() << "no support for CVC4 with SMT1, use SMT2 instead" << eom; - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; - case MATHSAT: + case solvert::MATHSAT: return read_result_mathsat(in); - case OPENSMT: + case solvert::OPENSMT: return read_result_opensmt(in); - case YICES: + case solvert::YICES: return read_result_yices(in); - case Z3: + case solvert::Z3: return read_result_z3(in); - case GENERIC: + case solvert::GENERIC: default: error() << "Generic solver can't solve" << eom; - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } } @@ -311,14 +311,14 @@ decision_proceduret::resultt smt1_dect::read_result_boolector(std::istream &in) boolean_assignment[v]=(value=="1"); } - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } else if(line=="unsat") - return D_UNSATISFIABLE; + return resultt::D_UNSATISFIABLE; else error() << "Unexpected result from SMT-Solver: " << line << eom; - return D_ERROR; + return resultt::D_ERROR; } /*******************************************************************\ @@ -335,7 +335,7 @@ Function: smt1_dect::read_result_opensmt decision_proceduret::resultt smt1_dect::read_result_opensmt(std::istream &in) { - return D_ERROR; + return resultt::D_ERROR; } /*******************************************************************\ @@ -359,15 +359,15 @@ decision_proceduret::resultt smt1_dect::read_result_yices(std::istream &in) if(line=="sat") { // fixme: read values - return D_SATISFIABLE; + return resultt::D_SATISFIABLE; } else if(line=="unsat") - return D_UNSATISFIABLE; + return resultt::D_UNSATISFIABLE; } error() << "Unexpected result from SMT-Solver" << eom; - return D_ERROR; + return resultt::D_ERROR; } /*******************************************************************\ @@ -414,7 +414,7 @@ Function: smt1_dect::read_result_mathsat decision_proceduret::resultt smt1_dect::read_result_mathsat(std::istream &in) { std::string line; - decision_proceduret::resultt res = D_ERROR; + decision_proceduret::resultt res = resultt::D_ERROR; boolean_assignment.clear(); boolean_assignment.resize(no_boolean_variables, false); @@ -425,9 +425,9 @@ decision_proceduret::resultt smt1_dect::read_result_mathsat(std::istream &in) while(std::getline(in, line)) { if(line=="sat") - res=D_SATISFIABLE; + res=resultt::D_SATISFIABLE; else if(line=="unsat") - res=D_UNSATISFIABLE; + res=resultt::D_UNSATISFIABLE; else if(line.size()>=1 && line[0]=='(') { // (iff B0 true) @@ -496,7 +496,7 @@ Function: smt1_dect::read_result_z3 decision_proceduret::resultt smt1_dect::read_result_z3(std::istream &in) { std::string line; - decision_proceduret::resultt res = D_ERROR; + decision_proceduret::resultt res = resultt::D_ERROR; boolean_assignment.clear(); boolean_assignment.resize(no_boolean_variables, false); @@ -507,9 +507,9 @@ decision_proceduret::resultt smt1_dect::read_result_z3(std::istream &in) while(std::getline(in, line)) { if(line=="sat") - res = D_SATISFIABLE; + res = resultt::D_SATISFIABLE; else if(line=="unsat") - res = D_UNSATISFIABLE; + res = resultt::D_UNSATISFIABLE; else { std::size_t pos=line.find(" -> "); @@ -692,7 +692,7 @@ Function: smt1_dect::read_result_cvc3 decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) { std::string line; - decision_proceduret::resultt res = D_ERROR; + decision_proceduret::resultt res = resultt::D_ERROR; boolean_assignment.clear(); boolean_assignment.resize(no_boolean_variables, false); @@ -703,9 +703,9 @@ decision_proceduret::resultt smt1_dect::read_result_cvc3(std::istream &in) while(std::getline(in, line)) { if(line=="sat") - res = D_SATISFIABLE; + res = resultt::D_SATISFIABLE; else if(line=="unsat") - res = D_UNSATISFIABLE; + res = resultt::D_UNSATISFIABLE; else if(line.find("Current scope level")!=std::string::npos || line.find("Variable Assignment")!=std::string::npos) { diff --git a/src/solvers/smt2/smt2_conv.cpp b/src/solvers/smt2/smt2_conv.cpp index badc8646993..37a3647ed71 100644 --- a/src/solvers/smt2/smt2_conv.cpp +++ b/src/solvers/smt2/smt2_conv.cpp @@ -106,14 +106,14 @@ void smt2_convt::write_header() switch(solver) { - case GENERIC: break; - case BOOLECTOR: out << "; Generated for Boolector\n"; break; - case CVC3: out << "; Generated for CVC 3\n"; break; - case CVC4: out << "; Generated for CVC 4\n"; break; - case MATHSAT: out << "; Generated for MathSAT\n"; break; - case OPENSMT: out << "; Generated for OPENSMT\n"; break; - case YICES: out << "; Generated for Yices\n"; break; - case Z3: out << "; Generated for Z3\n"; break; + case solvert::GENERIC: break; + case solvert::BOOLECTOR: out << "; Generated for Boolector\n"; break; + case solvert::CVC3: out << "; Generated for CVC 3\n"; break; + case solvert::CVC4: out << "; Generated for CVC 4\n"; break; + case solvert::MATHSAT: out << "; Generated for MathSAT\n"; break; + case solvert::OPENSMT: out << "; Generated for OPENSMT\n"; break; + case solvert::YICES: out << "; Generated for Yices\n"; break; + case solvert::Z3: out << "; Generated for Z3\n"; break; } out << "(set-info :source \"" << notes << "\")" << "\n"; @@ -163,7 +163,7 @@ void smt2_convt::write_footer(std::ostream &out) out << "(check-sat)" << "\n"; out << "\n"; - if(solver!=BOOLECTOR) + if(solver!=solvert::BOOLECTOR) { for(const auto &id : smt2_identifiers) out << "(get-value (|" << id << "|))" << "\n"; @@ -241,7 +241,7 @@ decision_proceduret::resultt smt2_convt::dec_solve() { write_footer(out); out.flush(); - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } /*******************************************************************\ @@ -739,9 +739,9 @@ void smt2_convt::convert_byte_extract(const byte_extract_exprt &expr) { // we just run the flattener exprt flattened_expr=flatten_byte_extract(expr, ns); - unflatten(BEGIN, expr.type()); + unflatten(wheret::BEGIN, expr.type()); convert_expr(flattened_expr); - unflatten(END, expr.type()); + unflatten(wheret::END, expr.type()); } /*******************************************************************\ @@ -854,9 +854,9 @@ void smt2_convt::convert_byte_update(const byte_update_exprt &expr) exprt ext_value=typecast_exprt(expr.value(), one_mask.type()); exprt or_expr=bitor_exprt(and_expr, shl_exprt(ext_value, distance)); - unflatten(BEGIN, expr.type()); + unflatten(wheret::BEGIN, expr.type()); flatten2bv(or_expr); - unflatten(END, expr.type()); + unflatten(wheret::END, expr.type()); #endif } @@ -1972,7 +1972,7 @@ void smt2_convt::convert_expr(const exprt &expr) else if(expr.id()==ID_forall || expr.id()==ID_exists) { - if(solver==MATHSAT) + if(solver==solvert::MATHSAT) // NOLINTNEXTLINE(readability/throw) throw "MathSAT does not support quantifiers"; @@ -4111,7 +4111,7 @@ void smt2_convt::convert_index(const index_exprt &expr) std::size_t array_width=boolbv_width(array_type); assert(array_width!=0); - unflatten(BEGIN, array_type.subtype()); + unflatten(wheret::BEGIN, array_type.subtype()); std::size_t sub_width=boolbv_width(array_type.subtype()); std::size_t index_width=boolbv_width(expr.index().type()); @@ -4139,7 +4139,7 @@ void smt2_convt::convert_index(const index_exprt &expr) out << ")))"; // mult, bvlshr, extract - unflatten(END, array_type.subtype()); + unflatten(wheret::END, array_type.subtype()); } } else if(array_op_type.id()==ID_vector) @@ -4238,7 +4238,7 @@ void smt2_convt::convert_member(const member_exprt &expr) if(width==0) INVALIDEXPR("failed to get union member width"); - unflatten(BEGIN, expr.type()); + unflatten(wheret::BEGIN, expr.type()); out << "((_ extract " << (width-1) @@ -4246,7 +4246,7 @@ void smt2_convt::convert_member(const member_exprt &expr) convert_expr(struct_op); out << ")"; - unflatten(END, expr.type()); + unflatten(wheret::END, expr.type()); } else UNEXPECTEDCASE( @@ -4383,7 +4383,7 @@ void smt2_convt::unflatten( if(type.id()==ID_bool) { - if(where==BEGIN) + if(where==wheret::BEGIN) out << "(= "; // produces a bool else out << " #b1)"; @@ -4406,7 +4406,7 @@ void smt2_convt::unflatten( if(to_integer(vector_type.size(), size)) INVALIDEXPR("failed to convert vector size to constant"); - if(where==BEGIN) + if(where==wheret::BEGIN) out << "(let ((?ufop" << nesting << " "; else { @@ -4419,10 +4419,10 @@ void smt2_convt::unflatten( for(mp_integer i=0; i!=size; ++i, offset+=subtype_width) { out << " "; - unflatten(BEGIN, vector_type.subtype(), nesting+1); + unflatten(wheret::BEGIN, vector_type.subtype(), nesting+1); out << "((_ extract " << offset+subtype_width-1 << " " << offset << ") ?ufop" << nesting << ")"; - unflatten(END, vector_type.subtype(), nesting+1); + unflatten(wheret::END, vector_type.subtype(), nesting+1); } out << "))"; // mk-, let @@ -4438,7 +4438,7 @@ void smt2_convt::unflatten( if(use_datatypes) { // extract members - if(where==BEGIN) + if(where==wheret::BEGIN) out << "(let ((?ufop" << nesting << " "; else { @@ -4467,10 +4467,10 @@ void smt2_convt::unflatten( std::size_t member_width=boolbv_width(it->type()); out << " "; - unflatten(BEGIN, it->type(), nesting+1); + unflatten(wheret::BEGIN, it->type(), nesting+1); out << "((_ extract " << offset+member_width-1 << " " << offset << ") ?ufop" << nesting << ")"; - unflatten(END, it->type(), nesting+1); + unflatten(wheret::END, it->type(), nesting+1); offset+=member_width; } diff --git a/src/solvers/smt2/smt2_conv.h b/src/solvers/smt2/smt2_conv.h index c5127db59f0..bfd03b506e9 100644 --- a/src/solvers/smt2/smt2_conv.h +++ b/src/solvers/smt2/smt2_conv.h @@ -27,7 +27,7 @@ class member_exprt; class smt2_convt:public prop_convt { public: - typedef enum + enum class solvert { GENERIC, BOOLECTOR, @@ -37,7 +37,7 @@ class smt2_convt:public prop_convt OPENSMT, YICES, Z3 - } solvert; + }; smt2_convt( const namespacet &_ns, @@ -66,28 +66,28 @@ class smt2_convt:public prop_convt switch(solver) { - case GENERIC: + case solvert::GENERIC: break; - case BOOLECTOR: + case solvert::BOOLECTOR: break; - case CVC3: + case solvert::CVC3: break; - case CVC4: + case solvert::CVC4: break; - case MATHSAT: + case solvert::MATHSAT: break; - case OPENSMT: + case solvert::OPENSMT: break; - case YICES: + case solvert::YICES: break; - case Z3: + case solvert::Z3: use_array_of_bool=true; emit_set_logic=false; use_datatypes=true; @@ -249,7 +249,7 @@ class smt2_convt:public prop_convt // e.g., booleans, vectors, structs, arrays but also // floats when using the FPA theory. // unflatten() does the opposite. - typedef enum { BEGIN, END } wheret; + enum class wheret { BEGIN, END }; void flatten2bv(const exprt &); void unflatten(wheret, const typet &, unsigned nesting=0); diff --git a/src/solvers/smt2/smt2_dec.cpp b/src/solvers/smt2/smt2_dec.cpp index 451f9da0d0a..9a9c5d1fc62 100644 --- a/src/solvers/smt2/smt2_dec.cpp +++ b/src/solvers/smt2/smt2_dec.cpp @@ -43,14 +43,14 @@ std::string smt2_dect::decision_procedure_text() const return "SMT2 "+logic+ (use_FPA_theory?" (with FPA)":"")+ " using "+ - (solver==GENERIC?"Generic": - solver==BOOLECTOR?"Boolector": - solver==CVC3?"CVC3": - solver==CVC4?"CVC4": - solver==MATHSAT?"MathSAT": - solver==OPENSMT?"OpenSMT": - solver==YICES?"Yices": - solver==Z3?"Z3": + (solver==solvert::GENERIC?"Generic": + solver==solvert::BOOLECTOR?"Boolector": + solver==solvert::CVC3?"CVC3": + solver==solvert::CVC4?"CVC4": + solver==solvert::MATHSAT?"MathSAT": + solver==solvert::OPENSMT?"OpenSMT": + solver==solvert::YICES?"Yices": + solver==solvert::Z3?"Z3": "(unknown)"); } @@ -129,21 +129,21 @@ decision_proceduret::resultt smt2_dect::dec_solve() switch(solver) { - case BOOLECTOR: + case solvert::BOOLECTOR: command = "boolector --smt2 " + smt2_temp_file.temp_out_filename + " -m > " + smt2_temp_file.temp_result_filename; break; - case CVC3: + case solvert::CVC3: command = "cvc3 +model -lang smtlib -output-lang smtlib " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; - case CVC4: + case solvert::CVC4: // The flags --bitblast=eager --bv-div-zero-const help but only // work for pure bit-vector formulas. command = "cvc4 -L smt2 " @@ -152,7 +152,7 @@ decision_proceduret::resultt smt2_dect::dec_solve() + smt2_temp_file.temp_result_filename; break; - case MATHSAT: + case solvert::MATHSAT: // The options below were recommended by Alberto Griggio // on 10 July 2013 command = "mathsat -input=smt2" @@ -173,7 +173,7 @@ decision_proceduret::resultt smt2_dect::dec_solve() + " > "+smt2_temp_file.temp_result_filename; break; - case OPENSMT: + case solvert::OPENSMT: command = "opensmt " + smt2_temp_file.temp_out_filename + " > " @@ -181,7 +181,7 @@ decision_proceduret::resultt smt2_dect::dec_solve() break; - case YICES: + case solvert::YICES: // command = "yices -smt -e " // Calling convention for older versions command = "yices-smt2 " // Calling for 2.2.1 + smt2_temp_file.temp_out_filename @@ -189,7 +189,7 @@ decision_proceduret::resultt smt2_dect::dec_solve() + smt2_temp_file.temp_result_filename; break; - case Z3: + case solvert::Z3: command = "z3 -smt2 " + smt2_temp_file.temp_out_filename + " > " @@ -208,7 +208,7 @@ decision_proceduret::resultt smt2_dect::dec_solve() if(res<0) { error() << "error running SMT2 solver" << eom; - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } std::ifstream in(smt2_temp_file.temp_result_filename.c_str()); @@ -231,7 +231,7 @@ Function: smt2_dect::read_result decision_proceduret::resultt smt2_dect::read_result(std::istream &in) { std::string line; - decision_proceduret::resultt res=D_ERROR; + decision_proceduret::resultt res=resultt::D_ERROR; boolean_assignment.clear(); boolean_assignment.resize(no_boolean_variables, false); @@ -244,9 +244,9 @@ decision_proceduret::resultt smt2_dect::read_result(std::istream &in) irept parsed=smt2irep(in); if(parsed.id()=="sat") - res=D_SATISFIABLE; + res=resultt::D_SATISFIABLE; else if(parsed.id()=="unsat") - res=D_UNSATISFIABLE; + res=resultt::D_UNSATISFIABLE; else if(parsed.id()=="" && parsed.get_sub().size()==1 && parsed.get_sub().front().get_sub().size()==2) @@ -266,11 +266,11 @@ decision_proceduret::resultt smt2_dect::read_result(std::istream &in) { // We ignore errors after UNSAT because get-value after check-sat // returns unsat will give an error. - if(res!=D_UNSATISFIABLE) + if(res!=resultt::D_UNSATISFIABLE) { error() << "SMT2 solver returned error message:\n" << "\t\"" << parsed.get_sub()[1].id() <<"\"" << eom; - return decision_proceduret::D_ERROR; + return decision_proceduret::resultt::D_ERROR; } } } diff --git a/src/symex/path_search.cpp b/src/symex/path_search.cpp index fcbaebbc39a..8d8e684c2cb 100644 --- a/src/symex/path_search.cpp +++ b/src/symex/path_search.cpp @@ -156,7 +156,7 @@ path_searcht::resultt path_searcht::operator()( report_statistics(); - return number_of_failed_properties==0?SAFE:UNSAFE; + return number_of_failed_properties==0?resultt::SAFE:resultt::UNSAFE; } /*******************************************************************\ diff --git a/src/symex/symex_cover.cpp b/src/symex/symex_cover.cpp index e5a7195d924..cb0b81254c4 100644 --- a/src/symex/symex_cover.cpp +++ b/src/symex/symex_cover.cpp @@ -76,7 +76,7 @@ void symex_parse_optionst::report_cover( switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: { status() << "\n** coverage results:" << eom; @@ -101,7 +101,7 @@ void symex_parse_optionst::report_cover( break; } - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { for(const auto &prop_pair : property_map) { @@ -148,7 +148,7 @@ void symex_parse_optionst::report_cover( break; } - case ui_message_handlert::JSON_UI: + case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["results"].make_array(); @@ -208,7 +208,7 @@ void symex_parse_optionst::report_cover( << "%)" << eom; - if(get_ui()==ui_message_handlert::PLAIN) + if(get_ui()==ui_message_handlert::uit::PLAIN) { std::set tests; diff --git a/src/symex/symex_parse_options.cpp b/src/symex/symex_parse_options.cpp index 8001a5b8155..c7b284383c7 100644 --- a/src/symex/symex_parse_options.cpp +++ b/src/symex/symex_parse_options.cpp @@ -21,6 +21,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include #include #include @@ -177,9 +178,7 @@ int symex_parse_optionst::doit() eval_verbosity(); - goto_model.set_message_handler(get_message_handler()); - - if(goto_model(cmdline)) + if(initialize_goto_model(goto_model, cmdline, get_message_handler())) return 6; if(process_goto_program(options)) @@ -261,12 +260,12 @@ int symex_parse_optionst::doit() // do actual symex, for assertion checking switch(path_search(goto_model.goto_functions)) { - case safety_checkert::SAFE: + case safety_checkert::resultt::SAFE: report_properties(path_search.property_map); report_success(); return 0; - case safety_checkert::UNSAFE: + case safety_checkert::resultt::UNSAFE: report_properties(path_search.property_map); report_failure(); return 10; @@ -479,7 +478,7 @@ Function: symex_parse_optionst::report_properties void symex_parse_optionst::report_properties( const path_searcht::property_mapt &property_map) { - if(get_ui()==ui_message_handlert::PLAIN) + if(get_ui()==ui_message_handlert::uit::PLAIN) status() << "\n** Results:" << eom; for(path_searcht::property_mapt::const_iterator @@ -487,7 +486,7 @@ void symex_parse_optionst::report_properties( it!=property_map.end(); it++) { - if(get_ui()==ui_message_handlert::XML_UI) + if(get_ui()==ui_message_handlert::uit::XML_UI) { xmlt xml_result("result"); xml_result.set_attribute("claim", id2string(it->first)); @@ -561,10 +560,10 @@ void symex_parse_optionst::report_success() switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="SUCCESS"; @@ -597,12 +596,12 @@ void symex_parse_optionst::show_counterexample( switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: std::cout << '\n' << "Counterexample:" << '\n'; show_goto_trace(std::cout, ns, error_trace); break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml; convert(ns, error_trace, xml); @@ -633,10 +632,10 @@ void symex_parse_optionst::report_failure() switch(get_ui()) { - case ui_message_handlert::PLAIN: + case ui_message_handlert::uit::PLAIN: break; - case ui_message_handlert::XML_UI: + case ui_message_handlert::uit::XML_UI: { xmlt xml("cprover-status"); xml.data="FAILURE"; diff --git a/src/symex/symex_parse_options.h b/src/symex/symex_parse_options.h index 5e178eec14e..4a149e2147f 100644 --- a/src/symex/symex_parse_options.h +++ b/src/symex/symex_parse_options.h @@ -12,7 +12,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include +#include #include #include @@ -59,7 +59,7 @@ class symex_parse_optionst: protected: ui_message_handlert ui_message_handler; - get_goto_modelt goto_model; + goto_modelt goto_model; void get_command_line_options(optionst &options); bool process_goto_program(const optionst &options); diff --git a/src/util/decision_procedure.h b/src/util/decision_procedure.h index db609b1137e..a3c1cf05710 100644 --- a/src/util/decision_procedure.h +++ b/src/util/decision_procedure.h @@ -39,7 +39,7 @@ class decision_proceduret:public messaget { set_to(expr, false); } // solve the problem - typedef enum { D_SATISFIABLE, D_UNSATISFIABLE, D_ERROR } resultt; + enum class resultt { D_SATISFIABLE, D_UNSATISFIABLE, D_ERROR }; // will eventually be protected, use below call operator virtual resultt dec_solve()=0; diff --git a/src/util/find_symbols.cpp b/src/util/find_symbols.cpp index 03cd78f4347..b62ea77b368 100644 --- a/src/util/find_symbols.cpp +++ b/src/util/find_symbols.cpp @@ -11,7 +11,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "find_symbols.h" -typedef enum { F_TYPE, F_TYPE_NON_PTR, F_EXPR, F_BOTH } kindt; +enum class kindt { F_TYPE, F_TYPE_NON_PTR, F_EXPR, F_BOTH }; /*******************************************************************\ @@ -181,7 +181,7 @@ void find_symbols(kindt kind, const exprt &src, find_symbols_sett &dest) find_symbols(kind, src.type(), dest); - if(kind==F_BOTH || kind==F_EXPR) + if(kind==kindt::F_BOTH || kind==kindt::F_EXPR) if(src.id()==ID_symbol || src.id()==ID_next_symbol) dest.insert(src.get(ID_identifier)); @@ -211,7 +211,7 @@ Function: find_symbols void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest) { - if(kind!=F_TYPE_NON_PTR || + if(kind!=kindt::F_TYPE_NON_PTR || src.id()!=ID_pointer) { if(src.has_subtype()) @@ -287,7 +287,7 @@ Function: find_type_symbols void find_type_symbols(const exprt &src, find_symbols_sett &dest) { - find_symbols(F_TYPE, src, dest); + find_symbols(kindt::F_TYPE, src, dest); } /*******************************************************************\ @@ -304,7 +304,7 @@ Function: find_type_symbols void find_type_symbols(const typet &src, find_symbols_sett &dest) { - find_symbols(F_TYPE, src, dest); + find_symbols(kindt::F_TYPE, src, dest); } /*******************************************************************\ @@ -323,7 +323,7 @@ void find_non_pointer_type_symbols( const exprt &src, find_symbols_sett &dest) { - find_symbols(F_TYPE_NON_PTR, src, dest); + find_symbols(kindt::F_TYPE_NON_PTR, src, dest); } /*******************************************************************\ @@ -342,7 +342,7 @@ void find_non_pointer_type_symbols( const typet &src, find_symbols_sett &dest) { - find_symbols(F_TYPE_NON_PTR, src, dest); + find_symbols(kindt::F_TYPE_NON_PTR, src, dest); } /*******************************************************************\ @@ -359,7 +359,7 @@ Function: find_type_and_expr_symbols void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest) { - find_symbols(F_BOTH, src, dest); + find_symbols(kindt::F_BOTH, src, dest); } /*******************************************************************\ @@ -376,5 +376,5 @@ Function: find_type_and_expr_symbols void find_type_and_expr_symbols(const typet &src, find_symbols_sett &dest) { - find_symbols(F_BOTH, src, dest); + find_symbols(kindt::F_BOTH, src, dest); } diff --git a/src/util/format_spec.h b/src/util/format_spec.h index 495d364d5cf..796452a932d 100644 --- a/src/util/format_spec.h +++ b/src/util/format_spec.h @@ -23,14 +23,14 @@ class format_spect // eE: SCIENTIFIC // gG: AUTOMATIC - typedef enum { DECIMAL, SCIENTIFIC, AUTOMATIC } stylet; + enum class stylet { DECIMAL, SCIENTIFIC, AUTOMATIC }; stylet style; format_spect(): min_width(0), precision(6), zero_padding(false), - style(AUTOMATIC) + style(stylet::AUTOMATIC) { } @@ -44,12 +44,12 @@ class format_spect static format_spect scientific() { - return format_spect(SCIENTIFIC); + return format_spect(stylet::SCIENTIFIC); } static format_spect automatic() { - return format_spect(AUTOMATIC); + return format_spect(stylet::AUTOMATIC); } }; diff --git a/src/util/ieee_float.cpp b/src/util/ieee_float.cpp index 5220b05885c..73290f70654 100644 --- a/src/util/ieee_float.cpp +++ b/src/util/ieee_float.cpp @@ -151,35 +151,49 @@ std::string ieee_floatt::format(const format_spect &format_spec) const switch(format_spec.style) { - case format_spect::DECIMAL: + case format_spect::stylet::DECIMAL: result+=to_string_decimal(format_spec.precision); break; - case format_spect::SCIENTIFIC: + case format_spect::stylet::SCIENTIFIC: result+=to_string_scientific(format_spec.precision); break; - case format_spect::AUTOMATIC: + case format_spect::stylet::AUTOMATIC: { + // On Linux, the man page says: // "Style e is used if the exponent from its conversion // is less than -4 or greater than or equal to the precision." + // + // On BSD, it's + // "The argument is printed in style f (F) or in style e (E) + // whichever gives full precision in minimum space." mp_integer _exponent, _fraction; extract_base10(_fraction, _exponent); - if(_exponent>=0) + mp_integer adjusted_exponent=base10_digits(_fraction)+_exponent; + + if(adjusted_exponent>=format_spec.precision || + adjusted_exponent<-4) { - if(base10_digits(_fraction)+_exponent>=format_spec.precision) - result+=to_string_scientific(format_spec.precision); - else - result+=to_string_decimal(format_spec.precision); + result+=to_string_scientific(format_spec.precision); } - else // _exponent<0 + else { - if(true) // base10_digits(fraction)+_exponent<-4) - result+=to_string_scientific(format_spec.precision); - else - result+=to_string_decimal(format_spec.precision); + result+=to_string_decimal(format_spec.precision); + + // Implementations tested also appear to suppress trailing zeros + // and trailing dots. + + { + std::size_t trunc_pos=result.find_last_not_of('0'); + if(trunc_pos!=std::string::npos) + result.resize(trunc_pos+1); + } + + if(!result.empty() && result.back()=='.') + result.resize(result.size()-1); } } break; diff --git a/src/util/ieee_float.h b/src/util/ieee_float.h index 20239cd92aa..227427c8b5f 100644 --- a/src/util/ieee_float.h +++ b/src/util/ieee_float.h @@ -110,12 +110,12 @@ class ieee_floatt // ROUND_TO_EVEN is also known as "round to nearest, ties to even", and // is the IEEE default. // The numbering below is what x86 uses in the control word. - typedef enum + enum rounding_modet { ROUND_TO_EVEN=0, ROUND_TO_MINUS_INF=1, ROUND_TO_PLUS_INF=2, ROUND_TO_ZERO=3, UNKNOWN, NONDETERMINISTIC - } rounding_modet; + }; rounding_modet rounding_mode; diff --git a/src/util/irep_hash_container.cpp b/src/util/irep_hash_container.cpp index c79d7a921ba..5d17b3d3f9f 100644 --- a/src/util/irep_hash_container.cpp +++ b/src/util/irep_hash_container.cpp @@ -8,6 +8,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "irep_hash_container.h" #include "irep.h" +#include "irep_hash.h" /*******************************************************************\ @@ -41,6 +42,27 @@ size_t irep_hash_container_baset::number(const irept &irep) /*******************************************************************\ +Function: irep_hash_container_baset::vector_hasht::operator() + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + +size_t irep_hash_container_baset::vector_hasht::operator()( + const packedt &p) const +{ + size_t result=p.size(); // seed + for(auto elem : p) + result=hash_combine(result, elem); + return result; +} + +/*******************************************************************\ + Function: irep_hash_container_baset::pack Inputs: diff --git a/src/util/irep_hash_container.h b/src/util/irep_hash_container.h index 4b6c43454a9..6edaaf0c21c 100644 --- a/src/util/irep_hash_container.h +++ b/src/util/irep_hash_container.h @@ -12,7 +12,6 @@ Author: Daniel Kroening, kroening@kroening.com #include // for size_t #include -#include "irep_hash.h" #include "numbering.h" class irept; @@ -55,13 +54,7 @@ class irep_hash_container_baset struct vector_hasht { - size_t operator()(const packedt &p) const - { - size_t result=p.size(); // seed - for(auto elem : p) - result=hash_combine(result, elem); - return result; - } + size_t operator()(const packedt &p) const; }; typedef hash_numbering numberingt; diff --git a/src/util/irep_ids.def b/src/util/irep_ids.def index 6f7ea15034d..9f18ca1b3a5 100644 --- a/src/util/irep_ids.def +++ b/src/util/irep_ids.def @@ -1,3 +1,6 @@ +/// \file List of irep id names and values. +/// For an explanation of how this works, see irep_ids.h. + IREP_ID_TWO(empty_string, ) IREP_ID_ONE(let) IREP_ID_ONE(nil) @@ -332,6 +335,7 @@ IREP_ID_ONE(continuous_assign) IREP_ID_ONE(blocking_assign) IREP_ID_ONE(non_blocking_assign) IREP_ID_ONE(alignof) +IREP_ID_ONE(clang_builtin_convertvector) IREP_ID_ONE(gcc_builtin_va_arg) IREP_ID_ONE(gcc_builtin_types_compatible_p) IREP_ID_ONE(gcc_builtin_va_arg_next) diff --git a/src/util/irep_ids.h b/src/util/irep_ids.h index 50fc06314b5..c456840ef5f 100644 --- a/src/util/irep_ids.h +++ b/src/util/irep_ids.h @@ -15,6 +15,17 @@ Author: Reuben Thomas, reuben.thomas@me.com #include "dstring.h" #endif +/// \file The irep_ids are generated using a technique called +/// [X-macros](https://en.wikipedia.org/wiki/X_Macro). +/// The ids are defined in the file irep_ids.def, using a pair of macros +/// `IREP_ID_ONE` and `IREP_ID_TWO`. +/// Definitions of the form `IREP_ID_ONE(param)` will be converted into a +/// const extern irep_idt with the variable name `ID_param` and the string +/// value `"param"`. +/// Definitions of the form `IREP_ID_TWO(param, contents)` will be converted +/// into a const extern irep_idt with the variable name `ID_param` and the +/// string value `"contents"`. + enum class idt:unsigned { #define IREP_ID_ONE(the_id) id_##the_id, diff --git a/src/util/json.cpp b/src/util/json.cpp index 75a9b5d3f42..39769a8c5c2 100644 --- a/src/util/json.cpp +++ b/src/util/json.cpp @@ -10,7 +10,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "json.h" -const jsont jsont::null_json_object(jsont::J_NULL); +const jsont jsont::null_json_object(jsont::kindt::J_NULL); /*******************************************************************\ @@ -78,17 +78,17 @@ void jsont::output_rec(std::ostream &out, unsigned indent) const { switch(kind) { - case J_STRING: + case kindt::J_STRING: out << '"'; escape_string(value, out); out << '"'; break; - case J_NUMBER: + case kindt::J_NUMBER: out << value; break; - case J_OBJECT: + case kindt::J_OBJECT: out << '{'; for(objectt::const_iterator o_it=object.begin(); o_it!=object.end(); @@ -115,7 +115,7 @@ void jsont::output_rec(std::ostream &out, unsigned indent) const out << '}'; break; - case J_ARRAY: + case kindt::J_ARRAY: out << '['; if(array.empty()) @@ -149,11 +149,11 @@ void jsont::output_rec(std::ostream &out, unsigned indent) const out << ']'; break; - case J_TRUE: out << "true"; break; + case kindt::J_TRUE: out << "true"; break; - case J_FALSE: out << "false"; break; + case kindt::J_FALSE: out << "false"; break; - case J_NULL: out << "null"; break; + case kindt::J_NULL: out << "null"; break; } } diff --git a/src/util/json.h b/src/util/json.h index c6ddd1b1d19..f6fe381ff11 100644 --- a/src/util/json.h +++ b/src/util/json.h @@ -20,46 +20,55 @@ class json_arrayt; class jsont { public: - typedef enum { J_STRING, J_NUMBER, J_OBJECT, J_ARRAY, - J_TRUE, J_FALSE, J_NULL } kindt; + enum class kindt + { + J_STRING, + J_NUMBER, + J_OBJECT, + J_ARRAY, + J_TRUE, + J_FALSE, + J_NULL + }; + kindt kind; bool is_string() const { - return kind==J_STRING; + return kind==kindt::J_STRING; } bool is_number() const { - return kind==J_NUMBER; + return kind==kindt::J_NUMBER; } bool is_object() const { - return kind==J_OBJECT; + return kind==kindt::J_OBJECT; } bool is_array() const { - return kind==J_ARRAY; + return kind==kindt::J_ARRAY; } bool is_true() const { - return kind==J_TRUE; + return kind==kindt::J_TRUE; } bool is_false() const { - return kind==J_FALSE; + return kind==kindt::J_FALSE; } bool is_null() const { - return kind==J_NULL; + return kind==kindt::J_NULL; } - jsont():kind(J_NULL) + jsont():kind(kindt::J_NULL) { } @@ -72,13 +81,13 @@ class jsont static jsont json_boolean(bool value) { - return jsont(value?J_TRUE:J_FALSE); + return jsont(value?kindt::J_TRUE:kindt::J_FALSE); } void clear() { value.clear(); - kind=J_NULL; + kind=kindt::J_NULL; object.clear(); array.clear(); } @@ -130,7 +139,7 @@ inline std::ostream &operator<<(std::ostream &out, const jsont &src) class json_arrayt:public jsont { public: - json_arrayt():jsont(J_ARRAY) + json_arrayt():jsont(kindt::J_ARRAY) { } @@ -161,7 +170,7 @@ class json_stringt:public jsont { public: explicit json_stringt(const std::string &_value): - jsont(J_STRING, _value) + jsont(kindt::J_STRING, _value) { } }; @@ -170,7 +179,7 @@ class json_numbert:public jsont { public: explicit json_numbert(const std::string &_value): - jsont(J_NUMBER, _value) + jsont(kindt::J_NUMBER, _value) { } }; @@ -178,7 +187,7 @@ class json_numbert:public jsont class json_objectt:public jsont { public: - json_objectt():jsont(J_OBJECT) + json_objectt():jsont(kindt::J_OBJECT) { } @@ -200,30 +209,30 @@ class json_objectt:public jsont class json_truet:public jsont { public: - json_truet():jsont(J_TRUE) { } + json_truet():jsont(kindt::J_TRUE) { } }; class json_falset:public jsont { public: - json_falset():jsont(J_FALSE) { } + json_falset():jsont(kindt::J_FALSE) { } }; class json_nullt:public jsont { public: - json_nullt():jsont(J_NULL) { } + json_nullt():jsont(kindt::J_NULL) { } }; inline json_arrayt &jsont::make_array() { - kind=J_ARRAY; + kind=kindt::J_ARRAY; return static_cast(*this); } inline json_objectt &jsont::make_object() { - kind=J_OBJECT; + kind=kindt::J_OBJECT; return static_cast(*this); } diff --git a/src/util/ssa_expr.h b/src/util/ssa_expr.h index e18862fa9f9..578d854d687 100644 --- a/src/util/ssa_expr.h +++ b/src/util/ssa_expr.h @@ -42,7 +42,7 @@ class ssa_exprt:public symbol_exprt return static_cast(find(ID_expression)); } - const irep_idt &get_object_name() const + irep_idt get_object_name() const { object_descriptor_exprt ode; ode.object()=get_original_expr(); diff --git a/src/util/std_expr.h b/src/util/std_expr.h index 6c9ee03a69f..e40868c40b5 100644 --- a/src/util/std_expr.h +++ b/src/util/std_expr.h @@ -603,19 +603,81 @@ inline binary_relation_exprt &to_binary_relation_expr(exprt &expr) return static_cast(expr); } +/*! \brief A generic base class for multi-ary expressions +*/ +class multi_ary_exprt:public exprt +{ +public: + multi_ary_exprt() + { + } + + explicit multi_ary_exprt(const irep_idt &_id):exprt(_id) + { + } + + multi_ary_exprt( + const irep_idt &_id, + const typet &_type):exprt(_id, _type) + { + } + + multi_ary_exprt( + const exprt &_lhs, + const irep_idt &_id, + const exprt &_rhs): + exprt(_id, _lhs.type()) + { + copy_to_operands(_lhs, _rhs); + } + + multi_ary_exprt( + const exprt &_lhs, + const irep_idt &_id, + const exprt &_rhs, + const typet &_type): + exprt(_id, _type) + { + copy_to_operands(_lhs, _rhs); + } +}; + +/*! \brief Cast a generic exprt to a \ref multi_ary_exprt + * + * This is an unchecked conversion. \a expr must be known to be \ref + * multi_ary_exprt. + * + * \param expr Source expression + * \return Object of type \ref multi_ary_exprt + * + * \ingroup gr_std_expr +*/ +inline const multi_ary_exprt &to_multi_ary_expr(const exprt &expr) +{ + return static_cast(expr); +} + +/*! \copydoc to_multi_ary_expr(const exprt &) + * \ingroup gr_std_expr +*/ +inline multi_ary_exprt &to_multi_ary_expr(exprt &expr) +{ + return static_cast(expr); +} + /*! \brief The plus expression */ -class plus_exprt:public binary_exprt +class plus_exprt:public multi_ary_exprt { public: - plus_exprt():binary_exprt(ID_plus) + plus_exprt():multi_ary_exprt(ID_plus) { } plus_exprt( const exprt &_lhs, const exprt &_rhs): - binary_exprt(_lhs, ID_plus, _rhs) + multi_ary_exprt(_lhs, ID_plus, _rhs) { } @@ -623,7 +685,7 @@ class plus_exprt:public binary_exprt const exprt &_lhs, const exprt &_rhs, const typet &_type): - binary_exprt(_lhs, ID_plus, _rhs, _type) + multi_ary_exprt(_lhs, ID_plus, _rhs, _type) { } }; @@ -697,17 +759,17 @@ inline minus_exprt &to_minus_expr(exprt &expr) /*! \brief binary multiplication */ -class mult_exprt:public binary_exprt +class mult_exprt:public multi_ary_exprt { public: - mult_exprt():binary_exprt(ID_mult) + mult_exprt():multi_ary_exprt(ID_mult) { } mult_exprt( const exprt &_lhs, const exprt &_rhs): - binary_exprt(_lhs, ID_mult, _rhs) + multi_ary_exprt(_lhs, ID_mult, _rhs) { } }; @@ -1663,21 +1725,20 @@ inline floatbv_typecast_exprt &to_floatbv_typecast_expr(exprt &expr) /*! \brief boolean AND */ -class and_exprt:public exprt +class and_exprt:public multi_ary_exprt { public: - and_exprt():exprt(ID_and, bool_typet()) + and_exprt():multi_ary_exprt(ID_and, bool_typet()) { } and_exprt(const exprt &op0, const exprt &op1): - exprt(ID_and, bool_typet()) + multi_ary_exprt(op0, ID_and, op1, bool_typet()) { - copy_to_operands(op0, op1); } and_exprt(const exprt &op0, const exprt &op1, const exprt &op2): - exprt(ID_and, bool_typet()) + multi_ary_exprt(ID_and, bool_typet()) { copy_to_operands(op0, op1, op2); } @@ -1687,7 +1748,7 @@ class and_exprt:public exprt const exprt &op1, const exprt &op2, const exprt &op3): - exprt(ID_and, bool_typet()) + multi_ary_exprt(ID_and, bool_typet()) { exprt::operandst &op=operands(); op.resize(4); @@ -1772,20 +1833,20 @@ inline implies_exprt &to_implies_expr(exprt &expr) /*! \brief boolean OR */ -class or_exprt:public exprt +class or_exprt:public multi_ary_exprt { public: - or_exprt():exprt(ID_or, bool_typet()) + or_exprt():multi_ary_exprt(ID_or, bool_typet()) { } - or_exprt(const exprt &op0, const exprt &op1):exprt(ID_or, bool_typet()) + or_exprt(const exprt &op0, const exprt &op1): + multi_ary_exprt(op0, ID_or, op1, bool_typet()) { - copy_to_operands(op0, op1); } or_exprt(const exprt &op0, const exprt &op1, const exprt &op2): - exprt(ID_or, bool_typet()) + multi_ary_exprt(ID_or, bool_typet()) { copy_to_operands(op0, op1, op2); } @@ -1795,7 +1856,7 @@ class or_exprt:public exprt const exprt &op1, const exprt &op2, const exprt &op3): - exprt(ID_or, bool_typet()) + multi_ary_exprt(ID_or, bool_typet()) { exprt::operandst &op=operands(); op.resize(4); @@ -1855,15 +1916,15 @@ class bitnot_exprt:public unary_exprt /*! \brief Bit-wise OR */ -class bitor_exprt:public exprt +class bitor_exprt:public multi_ary_exprt { public: - bitor_exprt():exprt(ID_bitor) + bitor_exprt():multi_ary_exprt(ID_bitor) { } bitor_exprt(const exprt &_op0, const exprt &_op1): - exprt(ID_bitor, _op0.type()) + multi_ary_exprt(ID_bitor, _op0.type()) { copy_to_operands(_op0, _op1); } @@ -1896,17 +1957,16 @@ inline bitor_exprt &to_bitor_expr(exprt &expr) /*! \brief Bit-wise XOR */ -class bitxor_exprt:public exprt +class bitxor_exprt:public multi_ary_exprt { public: - bitxor_exprt():exprt(ID_bitxor) + bitxor_exprt():multi_ary_exprt(ID_bitxor) { } bitxor_exprt(const exprt &_op0, const exprt &_op1): - exprt(ID_bitxor, _op0.type()) + multi_ary_exprt(_op0, ID_bitxor, _op1, _op0.type()) { - copy_to_operands(_op0, _op1); } }; @@ -1937,15 +1997,15 @@ inline bitxor_exprt &to_bitxor_expr(exprt &expr) /*! \brief Bit-wise AND */ -class bitand_exprt:public exprt +class bitand_exprt:public multi_ary_exprt { public: - bitand_exprt():exprt(ID_bitand) + bitand_exprt():multi_ary_exprt(ID_bitand) { } bitand_exprt(const exprt &_op0, const exprt &_op1): - exprt(ID_bitand, _op0.type()) + multi_ary_exprt(ID_bitand, _op0.type()) { copy_to_operands(_op0, _op1); } diff --git a/src/util/tempfile.cpp b/src/util/tempfile.cpp index 9db2a68c370..023043e232f 100644 --- a/src/util/tempfile.cpp +++ b/src/util/tempfile.cpp @@ -164,5 +164,6 @@ Function: temporary_filet::~temporary_filet temporary_filet::~temporary_filet() { - unlink(name.c_str()); + if(!name.empty()) + unlink(name.c_str()); } diff --git a/src/util/tempfile.h b/src/util/tempfile.h index 0720045029e..0d11a1fbcfd 100644 --- a/src/util/tempfile.h +++ b/src/util/tempfile.h @@ -29,6 +29,14 @@ class temporary_filet { } + // Using the copy constructor would delete the file twice. + temporary_filet(const temporary_filet &)=delete; + + temporary_filet(temporary_filet &&other) + { + name.swap(other.name); + } + // get the name std::string operator()() const { diff --git a/src/util/ui_message.cpp b/src/util/ui_message.cpp index c8d908c20d7..25f6eac92dc 100644 --- a/src/util/ui_message.cpp +++ b/src/util/ui_message.cpp @@ -33,10 +33,10 @@ ui_message_handlert::ui_message_handlert( { switch(__ui) { - case PLAIN: + case uit::PLAIN: break; - case XML_UI: + case uit::XML_UI: std::cout << "" << "\n"; std::cout << "" << "\n"; @@ -49,7 +49,7 @@ ui_message_handlert::ui_message_handlert( } break; - case JSON_UI: + case uit::JSON_UI: { std::cout << "[\n"; json_objectt json_program; @@ -76,9 +76,9 @@ ui_message_handlert::ui_message_handlert( const class cmdlinet &cmdline, const std::string &program): ui_message_handlert( - cmdline.isset("xml-ui")?XML_UI: - cmdline.isset("json-ui")?JSON_UI: - PLAIN, + cmdline.isset("xml-ui")?uit::XML_UI: + cmdline.isset("json-ui")?uit::JSON_UI: + uit::PLAIN, program) { } @@ -99,15 +99,15 @@ ui_message_handlert::~ui_message_handlert() { switch(get_ui()) { - case XML_UI: + case uit::XML_UI: std::cout << "" << "\n"; break; - case JSON_UI: + case uit::JSON_UI: std::cout << "\n]\n"; break; - case PLAIN: + case uit::PLAIN: break; } } @@ -154,15 +154,15 @@ void ui_message_handlert::print( { switch(get_ui()) { - case PLAIN: + case uit::PLAIN: { console_message_handlert console_message_handler; console_message_handler.print(level, message); } break; - case XML_UI: - case JSON_UI: + case uit::XML_UI: + case uit::JSON_UI: { source_locationt location; location.make_nil(); @@ -195,13 +195,13 @@ void ui_message_handlert::print( { switch(get_ui()) { - case PLAIN: + case uit::PLAIN: message_handlert::print( level, message, sequence_number, location); break; - case XML_UI: - case JSON_UI: + case uit::XML_UI: + case uit::JSON_UI: { std::string tmp_message(message); @@ -240,14 +240,14 @@ void ui_message_handlert::ui_msg( { switch(get_ui()) { - case PLAIN: + case uit::PLAIN: break; - case XML_UI: + case uit::XML_UI: xml_ui_msg(type, msg1, msg2, location); break; - case JSON_UI: + case uit::JSON_UI: json_ui_msg(type, msg1, msg2, location); break; } diff --git a/src/util/ui_message.h b/src/util/ui_message.h index 80ee5c28ba9..59cc5c21009 100644 --- a/src/util/ui_message.h +++ b/src/util/ui_message.h @@ -14,7 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com class ui_message_handlert:public message_handlert { public: - typedef enum { PLAIN, XML_UI, JSON_UI } uit; + enum class uit { PLAIN, XML_UI, JSON_UI }; ui_message_handlert(uit, const std::string &program); ui_message_handlert(const class cmdlinet &, const std::string &program); diff --git a/src/util/unicode.cpp b/src/util/unicode.cpp index 1e280783aff..4c997f1a6c3 100644 --- a/src/util/unicode.cpp +++ b/src/util/unicode.cpp @@ -8,9 +8,9 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include #include #include +#include #include "unicode.h" @@ -20,6 +20,24 @@ Author: Daniel Kroening, kroening@kroening.com /*******************************************************************\ +Function: is_little_endian_arch + + Inputs: + + Outputs: True if the architecture is little_endian + + Purpose: Determine endianness of the architecture + +\*******************************************************************/ + +bool is_little_endian_arch() +{ + uint32_t i=1; + return reinterpret_cast(i); +} + +/*******************************************************************\ + Function: narrow Inputs: @@ -154,17 +172,17 @@ std::wstring widen(const std::string &s) /*******************************************************************\ -Function: utf32_to_utf8 +Function: utf8_append_code - Inputs: + Inputs: character to append, string to append to Outputs: - Purpose: + Purpose: Appends a unicode character to a utf8-encoded string \*******************************************************************/ -void utf32_to_utf8(unsigned int c, std::string &result) +static void utf8_append_code(unsigned int c, std::string &result) { if(c<=0x7f) result+=static_cast(c); @@ -192,9 +210,10 @@ void utf32_to_utf8(unsigned int c, std::string &result) Function: utf32_to_utf8 - Inputs: + Inputs: utf32-encoded wide string - Outputs: + Outputs: utf8-encoded string with the same unicode characters + as the input. Purpose: @@ -207,14 +226,14 @@ std::string utf32_to_utf8(const std::basic_string &s) result.reserve(s.size()); // at least that long for(const auto c : s) - utf32_to_utf8(c, result); + utf8_append_code(c, result); return result; } /*******************************************************************\ -Function: utf16_to_utf8 +Function: narrow_argv Inputs: @@ -224,43 +243,140 @@ Function: utf16_to_utf8 \*******************************************************************/ -std::string utf16_to_utf8(const std::basic_string &s) +const char **narrow_argv(int argc, const wchar_t **argv_wide) { - std::string result; + if(argv_wide==NULL) + return NULL; - result.reserve(s.size()); // at least that long + // the following never gets deleted + const char **argv_narrow=new const char *[argc+1]; + argv_narrow[argc]=0; - for(const auto c : s) - utf32_to_utf8(c, result); + for(int i=0; i> 8); +} - // the following never gets deleted - const char **argv_narrow=new const char *[argc+1]; - argv_narrow[argc]=0; - for(int i=0; i(a); + } + else // code is encoded as two UTF16 characters + { + // if this is valid unicode, we have + // code<0x10FFFF + // but let's not check it programmatically + + // encode the code in UTF16, possibly swapping bytes. + code=code-0x10000; + unsigned int i1=((code>>10) & 0x3ff) | 0xD800; + unsigned int a1=(swap_bytes)?do_swap_bytes(static_cast(i1)):i1; + result+=static_cast(a1); + unsigned int i2=(code & 0x3ff) | 0xDC00; + unsigned int a2=(swap_bytes)?do_swap_bytes(static_cast(i2)):i2; + result+=static_cast(a2); + } +} - return argv_narrow; + +/*******************************************************************\ + +Function: utf8_to_utf16 + + Inputs: String in UTF-8 format, bool value indicating whether the + endianness should be different from the architecture one. + + Outputs: String in UTF-16 format. The encoding follows the + endianness of the architecture iff swap_bytes is true. + + Purpose: + +\*******************************************************************/ +std::wstring utf8_to_utf16(const std::string& in, bool swap_bytes) +{ + std::wstring result; + result.reserve(in.size()); + std::string::size_type i=0; + while(i > converter; - return converter.from_bytes(in); + bool swap_bytes=is_little_endian_arch(); + return utf8_to_utf16(in, swap_bytes); } /*******************************************************************\ @@ -289,21 +405,14 @@ Function: utf8_to_utf16_little_endian Outputs: String in UTF-16LE format - Purpose: Note this requires g++-5 libstdc++ / libc++ / MSVC2010+ + Purpose: \*******************************************************************/ std::wstring utf8_to_utf16_little_endian(const std::string& in) { - const std::codecvt_mode mode=std::codecvt_mode::little_endian; - - // default largest value codecvt_utf8_utf16 reads without error is 0x10ffff - // see: http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16 - const unsigned long maxcode=0x10ffff; - - typedef std::codecvt_utf8_utf16 codecvt_utf8_utf16t; - std::wstring_convert converter; - return converter.from_bytes(in); + bool swap_bytes=!is_little_endian_arch(); + return utf8_to_utf16(in, swap_bytes); } /*******************************************************************\ diff --git a/src/util/unicode.h b/src/util/unicode.h index c4bcab617d4..15aafe8ae13 100644 --- a/src/util/unicode.h +++ b/src/util/unicode.h @@ -20,7 +20,6 @@ std::string narrow(const std::wstring &s); std::wstring widen(const std::string &s); std::string utf32_to_utf8(const std::basic_string &s); -std::string utf16_to_utf8(const std::basic_string &s); std::wstring utf8_to_utf16_big_endian(const std::string &); std::wstring utf8_to_utf16_little_endian(const std::string &); diff --git a/unit/.gitignore b/unit/.gitignore new file mode 100644 index 00000000000..aecf381fc5c --- /dev/null +++ b/unit/.gitignore @@ -0,0 +1,5 @@ +# Unit test binaries +miniBDD +sharing_node +string_utils +unit_tests diff --git a/unit/Makefile b/unit/Makefile index 049d3f84ac0..a1de1539ee7 100644 --- a/unit/Makefile +++ b/unit/Makefile @@ -1,78 +1,56 @@ -SRC = cpp_parser.cpp \ - cpp_scanner.cpp \ - elf_reader.cpp \ - float_utils.cpp \ - ieee_float.cpp \ - json.cpp \ - miniBDD.cpp \ - osx_fat_reader.cpp \ - sharing_map.cpp \ - sharing_node.cpp \ - smt2_parser.cpp \ - string_utils.cpp \ - wp.cpp \ +.PHONY: all cprover.dir test + +SRC = unit_tests.cpp \ + catch_example.cpp \ # Empty last line -INCLUDES= -I ../src/ +INCLUDES= -I ../src/ -I. include ../src/config.inc include ../src/common -LIBS = ../src/ansi-c/ansi-c$(LIBEXT) \ - ../src/cpp/cpp$(LIBEXT) \ - ../src/json/json$(LIBEXT) \ - ../src/linking/linking$(LIBEXT) \ - ../src/util/util$(LIBEXT) \ - ../src/big-int/big-int$(LIBEXT) \ - ../src/goto-programs/goto-programs$(LIBEXT) \ - ../src/pointer-analysis/pointer-analysis$(LIBEXT) \ - ../src/langapi/langapi$(LIBEXT) \ - ../src/assembler/assembler$(LIBEXT) \ - ../src/analyses/analyses$(LIBEXT) \ - ../src/solvers/solvers$(LIBEXT) \ +cprover.dir: + $(MAKE) $(MAKEARGS) -C ../src -CLEANFILES = $(SRC:.cpp=$(EXEEXT)) +LIBS += ../src/ansi-c/ansi-c$(LIBEXT) \ + ../src/cpp/cpp$(LIBEXT) \ + ../src/json/json$(LIBEXT) \ + ../src/linking/linking$(LIBEXT) \ + ../src/util/util$(LIBEXT) \ + ../src/big-int/big-int$(LIBEXT) \ + ../src/goto-programs/goto-programs$(LIBEXT) \ + ../src/pointer-analysis/pointer-analysis$(LIBEXT) \ + ../src/langapi/langapi$(LIBEXT) \ + ../src/assembler/assembler$(LIBEXT) \ + ../src/analyses/analyses$(LIBEXT) \ + ../src/solvers/solvers$(LIBEXT) \ + # Empty last line -all: $(SRC:.cpp=$(EXEEXT)) +TESTS = unit_tests$(EXEEXT) \ + miniBDD$(EXEEXT) \ + string_utils$(EXEEXT) \ + sharing_node$(EXEEXT) \ + # Empty last line -############################################################################### +CLEANFILES = $(TESTS) -cpp_parser$(EXEEXT): cpp_parser$(OBJEXT) - $(LINKBIN) +all: cprover.dir + $(MAKE) $(MAKEARGS) $(TESTS) -cpp_scanner$(EXEEXT): cpp_scanner$(OBJEXT) - $(LINKBIN) +test: all + $(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true -elf_reader$(EXEEXT): elf_reader$(OBJEXT) - $(LINKBIN) -float_utils$(EXEEXT): float_utils$(OBJEXT) - $(LINKBIN) - -ieee_float$(EXEEXT): ieee_float$(OBJEXT) - $(LINKBIN) +############################################################################### -json$(EXEEXT): json$(OBJEXT) +unit_tests$(EXEEXT): $(OBJ) $(LINKBIN) miniBDD$(EXEEXT): miniBDD$(OBJEXT) $(LINKBIN) -osx_fat_reader$(EXEEXT): osx_fat_reader$(OBJEXT) - $(LINKBIN) - -smt2_parser$(EXEEXT): smt2_parser$(OBJEXT) - $(LINKBIN) - -wp$(EXEEXT): wp$(OBJEXT) - $(LINKBIN) - string_utils$(EXEEXT): string_utils$(OBJEXT) $(LINKBIN) -sharing_map$(EXEEXT): sharing_map$(OBJEXT) - $(LINKBIN) - sharing_node$(EXEEXT): sharing_node$(OBJEXT) $(LINKBIN) - diff --git a/unit/catch.hpp b/unit/catch.hpp new file mode 100644 index 00000000000..45328b8545c --- /dev/null +++ b/unit/catch.hpp @@ -0,0 +1,11420 @@ +/* + * Catch v1.9.1 + * Generated: 2017-04-09 21:21:06.285364 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED + +#define TWOBLUECUBES_CATCH_HPP_INCLUDED + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// #included from: internal/catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic ignored "-Wglobal-constructors" +# pragma clang diagnostic ignored "-Wvariadic-macros" +# pragma clang diagnostic ignored "-Wc99-extensions" +# pragma clang diagnostic ignored "-Wunused-variable" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wc++98-compat" +# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic ignored "-Wvariadic-macros" +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wparentheses" + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpadded" +#endif +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +#endif + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// #included from: internal/catch_notimplemented_exception.h +#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED + +// #included from: catch_common.h +#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED + +// #included from: catch_compiler_capabilities.h +#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED + +// Detect a number of compiler features - mostly C++11/14 conformance - by compiler +// The following features are defined: +// +// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? +// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? +// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods +// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? +// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported +// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? +// CATCH_CONFIG_CPP11_OVERRIDE : is override supported? +// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) +// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported? +// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported? + +// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? + +// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 + +#ifdef __cplusplus + +# if __cplusplus >= 201103L +# define CATCH_CPP11_OR_GREATER +# endif + +# if __cplusplus >= 201402L +# define CATCH_CPP14_OR_GREATER +# endif + +#endif + +#ifdef __clang__ + +# if __has_feature(cxx_nullptr) +# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR +# endif + +# if __has_feature(cxx_noexcept) +# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +# endif + +# if defined(CATCH_CPP11_OR_GREATER) +# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) +# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + _Pragma( "clang diagnostic pop" ) + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic push" ) \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic pop" ) +# endif + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# endif + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE + +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Borland +#ifdef __BORLANDC__ + +#endif // __BORLANDC__ + +//////////////////////////////////////////////////////////////////////////////// +// EDG +#ifdef __EDG_VERSION__ + +#endif // __EDG_VERSION__ + +//////////////////////////////////////////////////////////////////////////////// +// Digital Mars +#ifdef __DMC__ + +#endif // __DMC__ + +//////////////////////////////////////////////////////////////////////////////// +// GCC +#ifdef __GNUC__ + +# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) +# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR +# endif + +// - otherwise more recent versions define __cplusplus >= 201103L +// and will get picked up below + +#endif // __GNUC__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#ifdef _MSC_VER + +#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH + +#if (_MSC_VER >= 1600) +# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR +# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR +#endif + +#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) +#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE +#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS +#endif + +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// + +// Use variadic macros if the compiler supports them +#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ + ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ + ( defined __GNUC__ && __GNUC__ >= 3 ) || \ + ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) + +#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS + +#endif + +// Use __COUNTER__ if the compiler supports it +#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \ + ( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \ + ( defined __clang__ && __clang_major__ >= 3 ) + +#define CATCH_INTERNAL_CONFIG_COUNTER + +#endif + +//////////////////////////////////////////////////////////////////////////////// +// C++ language feature support + +// catch all support for C++11 +#if defined(CATCH_CPP11_OR_GREATER) + +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) +# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR +# endif + +# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT +# endif + +# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +# endif + +# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM +# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM +# endif + +# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE +# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE +# endif + +# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS +# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS +# endif + +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) +# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG +# endif + +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) +# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE +# endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) +# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR +# endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) +# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE +# endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) +# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS +# endif + +#endif // __cplusplus >= 201103L + +// Now set the actual defines based on the above + anything the user has configured +#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_NULLPTR +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_NOEXCEPT +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_GENERATED_METHODS +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_IS_ENUM +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_TUPLE +#endif +#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) +# define CATCH_CONFIG_VARIADIC_MACROS +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_LONG_LONG +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_OVERRIDE +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_UNIQUE_PTR +#endif +// Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for +// analytics) because, at time of writing, __COUNTER__ is not properly handled by it. +// This does not affect compilation +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_SHUFFLE +#endif +# if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_TYPE_TRAITS +# endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +#endif + +// noexcept support: +#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) +# define CATCH_NOEXCEPT noexcept +# define CATCH_NOEXCEPT_IS(x) noexcept(x) +#else +# define CATCH_NOEXCEPT throw() +# define CATCH_NOEXCEPT_IS(x) +#endif + +// nullptr support +#ifdef CATCH_CONFIG_CPP11_NULLPTR +# define CATCH_NULL nullptr +#else +# define CATCH_NULL NULL +#endif + +// override support +#ifdef CATCH_CONFIG_CPP11_OVERRIDE +# define CATCH_OVERRIDE override +#else +# define CATCH_OVERRIDE +#endif + +// unique_ptr support +#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR +# define CATCH_AUTO_PTR( T ) std::unique_ptr +#else +# define CATCH_AUTO_PTR( T ) std::auto_ptr +#endif + +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr +#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) + +#include +#include + +namespace Catch { + + struct IConfig; + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { +#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; +#else + NonCopyable( NonCopyable const& info ); + NonCopyable& operator = ( NonCopyable const& ); +#endif + + protected: + NonCopyable() {} + virtual ~NonCopyable(); + }; + + class SafeBool { + public: + typedef void (SafeBool::*type)() const; + + static type makeSafe( bool value ) { + return value ? &SafeBool::trueValue : 0; + } + private: + void trueValue() const {} + }; + + template + inline void deleteAll( ContainerT& container ) { + typename ContainerT::const_iterator it = container.begin(); + typename ContainerT::const_iterator itEnd = container.end(); + for(; it != itEnd; ++it ) + delete *it; + } + template + inline void deleteAllValues( AssociativeContainerT& container ) { + typename AssociativeContainerT::const_iterator it = container.begin(); + typename AssociativeContainerT::const_iterator itEnd = container.end(); + for(; it != itEnd; ++it ) + delete it->second; + } + + bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); + bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); + bool contains( std::string const& s, std::string const& infix ); + void toLowerInPlace( std::string& s ); + std::string toLower( std::string const& s ); + std::string trim( std::string const& str ); + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); + + struct pluralise { + pluralise( std::size_t count, std::string const& label ); + + friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + + std::size_t m_count; + std::string m_label; + }; + + struct SourceLineInfo { + + SourceLineInfo(); + SourceLineInfo( char const* _file, std::size_t _line ); +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + SourceLineInfo(SourceLineInfo const& other) = default; + SourceLineInfo( SourceLineInfo && ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo& operator = ( SourceLineInfo && ) = default; +# endif + bool empty() const; + bool operator == ( SourceLineInfo const& other ) const; + bool operator < ( SourceLineInfo const& other ) const; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // This is just here to avoid compiler warnings with macro constants and boolean literals + inline bool isTrue( bool value ){ return value; } + inline bool alwaysTrue() { return true; } + inline bool alwaysFalse() { return false; } + + void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); + + void seedRng( IConfig const& config ); + unsigned int rngSeed(); + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() { + return std::string(); + } + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) +#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); + +namespace Catch { + + class NotImplementedException : public std::exception + { + public: + NotImplementedException( SourceLineInfo const& lineInfo ); + NotImplementedException( NotImplementedException const& ) {} + + virtual ~NotImplementedException() CATCH_NOEXCEPT {} + + virtual const char* what() const CATCH_NOEXCEPT; + + private: + std::string m_what; + SourceLineInfo m_lineInfo; + }; + +} // end namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) + +// #included from: internal/catch_context.h +#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED + +// #included from: catch_interfaces_generators.h +#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED + +#include + +namespace Catch { + + struct IGeneratorInfo { + virtual ~IGeneratorInfo(); + virtual bool moveNext() = 0; + virtual std::size_t getCurrentIndex() const = 0; + }; + + struct IGeneratorsForTest { + virtual ~IGeneratorsForTest(); + + virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; + virtual bool moveNext() = 0; + }; + + IGeneratorsForTest* createGeneratorsForTest(); + +} // end namespace Catch + +// #included from: catch_ptr.hpp +#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +namespace Catch { + + // An intrusive reference counting smart pointer. + // T must implement addRef() and release() methods + // typically implementing the IShared interface + template + class Ptr { + public: + Ptr() : m_p( CATCH_NULL ){} + Ptr( T* p ) : m_p( p ){ + if( m_p ) + m_p->addRef(); + } + Ptr( Ptr const& other ) : m_p( other.m_p ){ + if( m_p ) + m_p->addRef(); + } + ~Ptr(){ + if( m_p ) + m_p->release(); + } + void reset() { + if( m_p ) + m_p->release(); + m_p = CATCH_NULL; + } + Ptr& operator = ( T* p ){ + Ptr temp( p ); + swap( temp ); + return *this; + } + Ptr& operator = ( Ptr const& other ){ + Ptr temp( other ); + swap( temp ); + return *this; + } + void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } + T* get() const{ return m_p; } + T& operator*() const { return *m_p; } + T* operator->() const { return m_p; } + bool operator !() const { return m_p == CATCH_NULL; } + operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); } + + private: + T* m_p; + }; + + struct IShared : NonCopyable { + virtual ~IShared(); + virtual void addRef() const = 0; + virtual void release() const = 0; + }; + + template + struct SharedImpl : T { + + SharedImpl() : m_rc( 0 ){} + + virtual void addRef() const { + ++m_rc; + } + virtual void release() const { + if( --m_rc == 0 ) + delete this; + } + + mutable unsigned int m_rc; + }; + +} // end namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +namespace Catch { + + class TestCase; + class Stream; + struct IResultCapture; + struct IRunner; + struct IGeneratorsForTest; + struct IConfig; + + struct IContext + { + virtual ~IContext(); + + virtual IResultCapture* getResultCapture() = 0; + virtual IRunner* getRunner() = 0; + virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; + virtual bool advanceGeneratorsForCurrentTest() = 0; + virtual Ptr getConfig() const = 0; + }; + + struct IMutableContext : IContext + { + virtual ~IMutableContext(); + virtual void setResultCapture( IResultCapture* resultCapture ) = 0; + virtual void setRunner( IRunner* runner ) = 0; + virtual void setConfig( Ptr const& config ) = 0; + }; + + IContext& getCurrentContext(); + IMutableContext& getCurrentMutableContext(); + void cleanUpContext(); + Stream createStream( std::string const& streamName ); + +} + +// #included from: internal/catch_test_registry.hpp +#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED + +// #included from: catch_interfaces_testcase.h +#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED + +#include + +namespace Catch { + + class TestSpec; + + struct ITestCase : IShared { + virtual void invoke () const = 0; + protected: + virtual ~ITestCase(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +namespace Catch { + +template +class MethodTestCase : public SharedImpl { + +public: + MethodTestCase( void (C::*method)() ) : m_method( method ) {} + + virtual void invoke() const { + C obj; + (obj.*m_method)(); + } + +private: + virtual ~MethodTestCase() {} + + void (C::*m_method)(); +}; + +typedef void(*TestFunction)(); + +struct NameAndDesc { + NameAndDesc( const char* _name = "", const char* _description= "" ) + : name( _name ), description( _description ) + {} + + const char* name; + const char* description; +}; + +void registerTestCase + ( ITestCase* testCase, + char const* className, + NameAndDesc const& nameAndDesc, + SourceLineInfo const& lineInfo ); + +struct AutoReg { + + AutoReg + ( TestFunction function, + SourceLineInfo const& lineInfo, + NameAndDesc const& nameAndDesc ); + + template + AutoReg + ( void (C::*method)(), + char const* className, + NameAndDesc const& nameAndDesc, + SourceLineInfo const& lineInfo ) { + + registerTestCase + ( new MethodTestCase( method ), + className, + nameAndDesc, + lineInfo ); + } + + ~AutoReg(); + +private: + AutoReg( AutoReg const& ); + void operator= ( AutoReg const& ); +}; + +void registerTestCaseFunction + ( TestFunction function, + SourceLineInfo const& lineInfo, + NameAndDesc const& nameAndDesc ); + +} // end namespace Catch + +#ifdef CATCH_CONFIG_VARIADIC_MACROS + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ + static void TestName(); \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); } \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE( ... ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ \ + struct TestName : ClassName{ \ + void test(); \ + }; \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \ + } \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + void TestName::test() + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ + INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + +#else + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \ + static void TestName(); \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + static void TestName() + #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ + INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + namespace{ \ + struct TestCaseName : ClassName{ \ + void test(); \ + }; \ + Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \ + } \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + void TestCaseName::test() + #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ + INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc ) + + /////////////////////////////////////////////////////////////////////////////// + #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \ + CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); \ + CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + +#endif + +// #included from: internal/catch_capture.hpp +#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED + +// #included from: catch_result_builder.h +#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED + +// #included from: catch_result_type.h +#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED + +namespace Catch { + + // ResultWas::OfType enum + struct ResultWas { enum OfType { + Unknown = -1, + Ok = 0, + Info = 1, + Warning = 2, + + FailureBit = 0x10, + + ExpressionFailed = FailureBit | 1, + ExplicitFailure = FailureBit | 2, + + Exception = 0x100 | FailureBit, + + ThrewException = Exception | 1, + DidntThrowException = Exception | 2, + + FatalErrorCondition = 0x200 | FailureBit + + }; }; + + inline bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } + inline bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } + + // ResultDisposition::Flags enum + struct ResultDisposition { enum Flags { + Normal = 0x01, + + ContinueOnFailure = 0x02, // Failures fail test, but execution continues + FalseTest = 0x04, // Prefix expression with ! + SuppressFail = 0x08 // Failures are reported but do not fail the test + }; }; + + inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast( static_cast( lhs ) | static_cast( rhs ) ); + } + + inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } + inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } + inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + +} // end namespace Catch + +// #included from: catch_assertionresult.h +#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED + +#include + +namespace Catch { + + struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; + + struct DecomposedExpression + { + virtual ~DecomposedExpression() {} + virtual bool isBinaryExpression() const { + return false; + } + virtual void reconstructExpression( std::string& dest ) const = 0; + + // Only simple binary comparisons can be decomposed. + // If more complex check is required then wrap sub-expressions in parentheses. + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& ); + template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& ); + + private: + DecomposedExpression& operator = (DecomposedExpression const&); + }; + + struct AssertionInfo + { + AssertionInfo() {} + AssertionInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + std::string const& _capturedExpression, + ResultDisposition::Flags _resultDisposition ); + + std::string macroName; + SourceLineInfo lineInfo; + std::string capturedExpression; + ResultDisposition::Flags resultDisposition; + }; + + struct AssertionResultData + { + AssertionResultData() : decomposedExpression( CATCH_NULL ) + , resultType( ResultWas::Unknown ) + , negated( false ) + , parenthesized( false ) {} + + void negate( bool parenthesize ) { + negated = !negated; + parenthesized = parenthesize; + if( resultType == ResultWas::Ok ) + resultType = ResultWas::ExpressionFailed; + else if( resultType == ResultWas::ExpressionFailed ) + resultType = ResultWas::Ok; + } + + std::string const& reconstructExpression() const { + if( decomposedExpression != CATCH_NULL ) { + decomposedExpression->reconstructExpression( reconstructedExpression ); + if( parenthesized ) { + reconstructedExpression.insert( 0, 1, '(' ); + reconstructedExpression.append( 1, ')' ); + } + if( negated ) { + reconstructedExpression.insert( 0, 1, '!' ); + } + decomposedExpression = CATCH_NULL; + } + return reconstructedExpression; + } + + mutable DecomposedExpression const* decomposedExpression; + mutable std::string reconstructedExpression; + std::string message; + ResultWas::OfType resultType; + bool negated; + bool parenthesized; + }; + + class AssertionResult { + public: + AssertionResult(); + AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); + ~AssertionResult(); +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + AssertionResult( AssertionResult const& ) = default; + AssertionResult( AssertionResult && ) = default; + AssertionResult& operator = ( AssertionResult const& ) = default; + AssertionResult& operator = ( AssertionResult && ) = default; +# endif + + bool isOk() const; + bool succeeded() const; + ResultWas::OfType getResultType() const; + bool hasExpression() const; + bool hasMessage() const; + std::string getExpression() const; + std::string getExpressionInMacro() const; + bool hasExpandedExpression() const; + std::string getExpandedExpression() const; + std::string getMessage() const; + SourceLineInfo getSourceInfo() const; + std::string getTestMacroName() const; + void discardDecomposedExpression() const; + void expandDecomposedExpression() const; + + protected: + AssertionInfo m_info; + AssertionResultData m_resultData; + }; + +} // end namespace Catch + +// #included from: catch_matchers.hpp +#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED + +namespace Catch { +namespace Matchers { + namespace Impl { + + template struct MatchAllOf; + template struct MatchAnyOf; + template struct MatchNotOf; + + class MatcherUntypedBase { + public: + std::string toString() const { + if( m_cachedToString.empty() ) + m_cachedToString = describe(); + return m_cachedToString; + } + + protected: + virtual ~MatcherUntypedBase(); + virtual std::string describe() const = 0; + mutable std::string m_cachedToString; + private: + MatcherUntypedBase& operator = ( MatcherUntypedBase const& ); + }; + + template + struct MatcherMethod { + virtual bool match( ObjectT const& arg ) const = 0; + }; + template + struct MatcherMethod { + virtual bool match( PtrT* arg ) const = 0; + }; + + template + struct MatcherBase : MatcherUntypedBase, MatcherMethod { + + MatchAllOf operator && ( MatcherBase const& other ) const; + MatchAnyOf operator || ( MatcherBase const& other ) const; + MatchNotOf operator ! () const; + }; + + template + struct MatchAllOf : MatcherBase { + virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE { + for( std::size_t i = 0; i < m_matchers.size(); ++i ) { + if (!m_matchers[i]->match(arg)) + return false; + } + return true; + } + virtual std::string describe() const CATCH_OVERRIDE { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + for( std::size_t i = 0; i < m_matchers.size(); ++i ) { + if( i != 0 ) + description += " and "; + description += m_matchers[i]->toString(); + } + description += " )"; + return description; + } + + MatchAllOf& operator && ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + template + struct MatchAnyOf : MatcherBase { + + virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE { + for( std::size_t i = 0; i < m_matchers.size(); ++i ) { + if (m_matchers[i]->match(arg)) + return true; + } + return false; + } + virtual std::string describe() const CATCH_OVERRIDE { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + for( std::size_t i = 0; i < m_matchers.size(); ++i ) { + if( i != 0 ) + description += " or "; + description += m_matchers[i]->toString(); + } + description += " )"; + return description; + } + + MatchAnyOf& operator || ( MatcherBase const& other ) { + m_matchers.push_back( &other ); + return *this; + } + + std::vector const*> m_matchers; + }; + + template + struct MatchNotOf : MatcherBase { + + MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} + + virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE { + return !m_underlyingMatcher.match( arg ); + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "not " + m_underlyingMatcher.toString(); + } + MatcherBase const& m_underlyingMatcher; + }; + + template + MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { + return MatchAllOf() && *this && other; + } + template + MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { + return MatchAnyOf() || *this || other; + } + template + MatchNotOf MatcherBase::operator ! () const { + return MatchNotOf( *this ); + } + + } // namespace Impl + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + // - deprecated: prefer ||, && and ! + template + inline Impl::MatchNotOf Not( Impl::MatcherBase const& underlyingMatcher ) { + return Impl::MatchNotOf( underlyingMatcher ); + } + template + inline Impl::MatchAllOf AllOf( Impl::MatcherBase const& m1, Impl::MatcherBase const& m2 ) { + return Impl::MatchAllOf() && m1 && m2; + } + template + inline Impl::MatchAllOf AllOf( Impl::MatcherBase const& m1, Impl::MatcherBase const& m2, Impl::MatcherBase const& m3 ) { + return Impl::MatchAllOf() && m1 && m2 && m3; + } + template + inline Impl::MatchAnyOf AnyOf( Impl::MatcherBase const& m1, Impl::MatcherBase const& m2 ) { + return Impl::MatchAnyOf() || m1 || m2; + } + template + inline Impl::MatchAnyOf AnyOf( Impl::MatcherBase const& m1, Impl::MatcherBase const& m2, Impl::MatcherBase const& m3 ) { + return Impl::MatchAnyOf() || m1 || m2 || m3; + } + +} // namespace Matchers + +using namespace Matchers; +using Matchers::Impl::MatcherBase; + +} // namespace Catch + +namespace Catch { + + struct TestFailureException{}; + + template class ExpressionLhs; + + struct CopyableStream { + CopyableStream() {} + CopyableStream( CopyableStream const& other ) { + oss << other.oss.str(); + } + CopyableStream& operator=( CopyableStream const& other ) { + oss.str(std::string()); + oss << other.oss.str(); + return *this; + } + std::ostringstream oss; + }; + + class ResultBuilder : public DecomposedExpression { + public: + ResultBuilder( char const* macroName, + SourceLineInfo const& lineInfo, + char const* capturedExpression, + ResultDisposition::Flags resultDisposition, + char const* secondArg = "" ); + ~ResultBuilder(); + + template + ExpressionLhs operator <= ( T const& operand ); + ExpressionLhs operator <= ( bool value ); + + template + ResultBuilder& operator << ( T const& value ) { + m_stream.oss << value; + return *this; + } + + ResultBuilder& setResultType( ResultWas::OfType result ); + ResultBuilder& setResultType( bool result ); + + void endExpression( DecomposedExpression const& expr ); + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE; + + AssertionResult build() const; + AssertionResult build( DecomposedExpression const& expr ) const; + + void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); + void captureResult( ResultWas::OfType resultType ); + void captureExpression(); + void captureExpectedException( std::string const& expectedMessage ); + void captureExpectedException( Matchers::Impl::MatcherBase const& matcher ); + void handleResult( AssertionResult const& result ); + void react(); + bool shouldDebugBreak() const; + bool allowThrows() const; + + template + void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString ); + + void setExceptionGuard(); + void unsetExceptionGuard(); + + private: + AssertionInfo m_assertionInfo; + AssertionResultData m_data; + CopyableStream m_stream; + + bool m_shouldDebugBreak; + bool m_shouldThrow; + bool m_guardException; + }; + +} // namespace Catch + +// Include after due to circular dependency: +// #included from: catch_expression_lhs.hpp +#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED + +// #included from: catch_evaluate.hpp +#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4389) // '==' : signed/unsigned mismatch +#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) +#endif + +#include + +namespace Catch { +namespace Internal { + + enum Operator { + IsEqualTo, + IsNotEqualTo, + IsLessThan, + IsGreaterThan, + IsLessThanOrEqualTo, + IsGreaterThanOrEqualTo + }; + + template struct OperatorTraits { static const char* getName(){ return "*error*"; } }; + template<> struct OperatorTraits { static const char* getName(){ return "=="; } }; + template<> struct OperatorTraits { static const char* getName(){ return "!="; } }; + template<> struct OperatorTraits { static const char* getName(){ return "<"; } }; + template<> struct OperatorTraits { static const char* getName(){ return ">"; } }; + template<> struct OperatorTraits { static const char* getName(){ return "<="; } }; + template<> struct OperatorTraits{ static const char* getName(){ return ">="; } }; + + template + inline T& opCast(T const& t) { return const_cast(t); } + +// nullptr_t support based on pull request #154 from Konstantin Baumann +#ifdef CATCH_CONFIG_CPP11_NULLPTR + inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } +#endif // CATCH_CONFIG_CPP11_NULLPTR + + // So the compare overloads can be operator agnostic we convey the operator as a template + // enum, which is used to specialise an Evaluator for doing the comparison. + template + class Evaluator{}; + + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs) { + return bool( opCast( lhs ) == opCast( rhs ) ); + } + }; + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool( opCast( lhs ) != opCast( rhs ) ); + } + }; + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool( opCast( lhs ) < opCast( rhs ) ); + } + }; + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool( opCast( lhs ) > opCast( rhs ) ); + } + }; + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool( opCast( lhs ) >= opCast( rhs ) ); + } + }; + template + struct Evaluator { + static bool evaluate( T1 const& lhs, T2 const& rhs ) { + return bool( opCast( lhs ) <= opCast( rhs ) ); + } + }; + + template + bool applyEvaluator( T1 const& lhs, T2 const& rhs ) { + return Evaluator::evaluate( lhs, rhs ); + } + + // This level of indirection allows us to specialise for integer types + // to avoid signed/ unsigned warnings + + // "base" overload + template + bool compare( T1 const& lhs, T2 const& rhs ) { + return Evaluator::evaluate( lhs, rhs ); + } + + // unsigned X to int + template bool compare( unsigned int lhs, int rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned long lhs, int rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned char lhs, int rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + + // unsigned X to long + template bool compare( unsigned int lhs, long rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned long lhs, long rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + template bool compare( unsigned char lhs, long rhs ) { + return applyEvaluator( lhs, static_cast( rhs ) ); + } + + // int to unsigned X + template bool compare( int lhs, unsigned int rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( int lhs, unsigned long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( int lhs, unsigned char rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + + // long to unsigned X + template bool compare( long lhs, unsigned int rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( long lhs, unsigned long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( long lhs, unsigned char rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + + // pointer to long (when comparing against NULL) + template bool compare( long lhs, T* rhs ) { + return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); + } + template bool compare( T* lhs, long rhs ) { + return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); + } + + // pointer to int (when comparing against NULL) + template bool compare( int lhs, T* rhs ) { + return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); + } + template bool compare( T* lhs, int rhs ) { + return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); + } + +#ifdef CATCH_CONFIG_CPP11_LONG_LONG + // long long to unsigned X + template bool compare( long long lhs, unsigned int rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( long long lhs, unsigned long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( long long lhs, unsigned long long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( long long lhs, unsigned char rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + + // unsigned long long to X + template bool compare( unsigned long long lhs, int rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( unsigned long long lhs, long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( unsigned long long lhs, long long rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + template bool compare( unsigned long long lhs, char rhs ) { + return applyEvaluator( static_cast( lhs ), rhs ); + } + + // pointer to long long (when comparing against NULL) + template bool compare( long long lhs, T* rhs ) { + return Evaluator::evaluate( reinterpret_cast( lhs ), rhs ); + } + template bool compare( T* lhs, long long rhs ) { + return Evaluator::evaluate( lhs, reinterpret_cast( rhs ) ); + } +#endif // CATCH_CONFIG_CPP11_LONG_LONG + +#ifdef CATCH_CONFIG_CPP11_NULLPTR + // pointer to nullptr_t (when comparing against nullptr) + template bool compare( std::nullptr_t, T* rhs ) { + return Evaluator::evaluate( nullptr, rhs ); + } + template bool compare( T* lhs, std::nullptr_t ) { + return Evaluator::evaluate( lhs, nullptr ); + } +#endif // CATCH_CONFIG_CPP11_NULLPTR + +} // end of namespace Internal +} // end of namespace Catch + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// #included from: catch_tostring.h +#define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED + +#include +#include +#include +#include +#include + +#ifdef __OBJC__ +// #included from: catch_objc_arc.hpp +#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED + +#import + +#ifdef __has_feature +#define CATCH_ARC_ENABLED __has_feature(objc_arc) +#else +#define CATCH_ARC_ENABLED 0 +#endif + +void arcSafeRelease( NSObject* obj ); +id performOptionalSelector( id obj, SEL sel ); + +#if !CATCH_ARC_ENABLED +inline void arcSafeRelease( NSObject* obj ) { + [obj release]; +} +inline id performOptionalSelector( id obj, SEL sel ) { + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; + return nil; +} +#define CATCH_UNSAFE_UNRETAINED +#define CATCH_ARC_STRONG +#else +inline void arcSafeRelease( NSObject* ){} +inline id performOptionalSelector( id obj, SEL sel ) { +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" +#endif + if( [obj respondsToSelector: sel] ) + return [obj performSelector: sel]; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + return nil; +} +#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained +#define CATCH_ARC_STRONG __strong +#endif + +#endif + +#ifdef CATCH_CONFIG_CPP11_TUPLE +#include +#endif + +#ifdef CATCH_CONFIG_CPP11_IS_ENUM +#include +#endif + +namespace Catch { + +// Why we're here. +template +std::string toString( T const& value ); + +// Built in overloads + +std::string toString( std::string const& value ); +std::string toString( std::wstring const& value ); +std::string toString( const char* const value ); +std::string toString( char* const value ); +std::string toString( const wchar_t* const value ); +std::string toString( wchar_t* const value ); +std::string toString( int value ); +std::string toString( unsigned long value ); +std::string toString( unsigned int value ); +std::string toString( const double value ); +std::string toString( const float value ); +std::string toString( bool value ); +std::string toString( char value ); +std::string toString( signed char value ); +std::string toString( unsigned char value ); + +#ifdef CATCH_CONFIG_CPP11_LONG_LONG +std::string toString( long long value ); +std::string toString( unsigned long long value ); +#endif + +#ifdef CATCH_CONFIG_CPP11_NULLPTR +std::string toString( std::nullptr_t ); +#endif + +#ifdef __OBJC__ + std::string toString( NSString const * const& nsstring ); + std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); + std::string toString( NSObject* const& nsObject ); +#endif + +namespace Detail { + + extern const std::string unprintableString; + + #if !defined(CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK) + struct BorgType { + template BorgType( T const& ); + }; + + struct TrueType { char sizer[1]; }; + struct FalseType { char sizer[2]; }; + + TrueType& testStreamable( std::ostream& ); + FalseType testStreamable( FalseType ); + + FalseType operator<<( std::ostream const&, BorgType const& ); + + template + struct IsStreamInsertable { + static std::ostream &s; + static T const&t; + enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) }; + }; +#else + template + class IsStreamInsertable { + template + static auto test(int) + -> decltype( std::declval() << std::declval(), std::true_type() ); + + template + static auto test(...) -> std::false_type; + + public: + static const bool value = decltype(test(0))::value; + }; +#endif + +#if defined(CATCH_CONFIG_CPP11_IS_ENUM) + template::value + > + struct EnumStringMaker + { + static std::string convert( T const& ) { return unprintableString; } + }; + + template + struct EnumStringMaker + { + static std::string convert( T const& v ) + { + return ::Catch::toString( + static_cast::type>(v) + ); + } + }; +#endif + template + struct StringMakerBase { +#if defined(CATCH_CONFIG_CPP11_IS_ENUM) + template + static std::string convert( T const& v ) + { + return EnumStringMaker::convert( v ); + } +#else + template + static std::string convert( T const& ) { return unprintableString; } +#endif + }; + + template<> + struct StringMakerBase { + template + static std::string convert( T const& _value ) { + std::ostringstream oss; + oss << _value; + return oss.str(); + } + }; + + std::string rawMemoryToString( const void *object, std::size_t size ); + + template + inline std::string rawMemoryToString( const T& object ) { + return rawMemoryToString( &object, sizeof(object) ); + } + +} // end namespace Detail + +template +struct StringMaker : + Detail::StringMakerBase::value> {}; + +template +struct StringMaker { + template + static std::string convert( U* p ) { + if( !p ) + return "NULL"; + else + return Detail::rawMemoryToString( p ); + } +}; + +template +struct StringMaker { + static std::string convert( R C::* p ) { + if( !p ) + return "NULL"; + else + return Detail::rawMemoryToString( p ); + } +}; + +namespace Detail { + template + std::string rangeToString( InputIterator first, InputIterator last ); +} + +//template +//struct StringMaker > { +// static std::string convert( std::vector const& v ) { +// return Detail::rangeToString( v.begin(), v.end() ); +// } +//}; + +template +std::string toString( std::vector const& v ) { + return Detail::rangeToString( v.begin(), v.end() ); +} + +#ifdef CATCH_CONFIG_CPP11_TUPLE + +// toString for tuples +namespace TupleDetail { + template< + typename Tuple, + std::size_t N = 0, + bool = (N < std::tuple_size::value) + > + struct ElementPrinter { + static void print( const Tuple& tuple, std::ostream& os ) + { + os << ( N ? ", " : " " ) + << Catch::toString(std::get(tuple)); + ElementPrinter::print(tuple,os); + } + }; + + template< + typename Tuple, + std::size_t N + > + struct ElementPrinter { + static void print( const Tuple&, std::ostream& ) {} + }; + +} + +template +struct StringMaker> { + + static std::string convert( const std::tuple& tuple ) + { + std::ostringstream os; + os << '{'; + TupleDetail::ElementPrinter>::print( tuple, os ); + os << " }"; + return os.str(); + } +}; +#endif // CATCH_CONFIG_CPP11_TUPLE + +namespace Detail { + template + std::string makeString( T const& value ) { + return StringMaker::convert( value ); + } +} // end namespace Detail + +/// \brief converts any type to a string +/// +/// The default template forwards on to ostringstream - except when an +/// ostringstream overload does not exist - in which case it attempts to detect +/// that and writes {?}. +/// Overload (not specialise) this template for custom typs that you don't want +/// to provide an ostream overload for. +template +std::string toString( T const& value ) { + return StringMaker::convert( value ); +} + + namespace Detail { + template + std::string rangeToString( InputIterator first, InputIterator last ) { + std::ostringstream oss; + oss << "{ "; + if( first != last ) { + oss << Catch::toString( *first ); + for( ++first ; first != last ; ++first ) + oss << ", " << Catch::toString( *first ); + } + oss << " }"; + return oss.str(); + } +} + +} // end namespace Catch + +namespace Catch { + +template +class BinaryExpression; + +template +class MatchExpression; + +// Wraps the LHS of an expression and overloads comparison operators +// for also capturing those and RHS (if any) +template +class ExpressionLhs : public DecomposedExpression { +public: + ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {} + + ExpressionLhs& operator = ( const ExpressionLhs& ); + + template + BinaryExpression + operator == ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + template + BinaryExpression + operator != ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + template + BinaryExpression + operator < ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + template + BinaryExpression + operator > ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + template + BinaryExpression + operator <= ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + template + BinaryExpression + operator >= ( RhsT const& rhs ) { + return captureExpression( rhs ); + } + + BinaryExpression operator == ( bool rhs ) { + return captureExpression( rhs ); + } + + BinaryExpression operator != ( bool rhs ) { + return captureExpression( rhs ); + } + + void endExpression() { + m_truthy = m_lhs ? true : false; + m_rb + .setResultType( m_truthy ) + .endExpression( *this ); + } + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + dest = Catch::toString( m_truthy ); + } + +private: + template + BinaryExpression captureExpression( RhsT& rhs ) const { + return BinaryExpression( m_rb, m_lhs, rhs ); + } + + template + BinaryExpression captureExpression( bool rhs ) const { + return BinaryExpression( m_rb, m_lhs, rhs ); + } + +private: + ResultBuilder& m_rb; + T m_lhs; + bool m_truthy; +}; + +template +class BinaryExpression : public DecomposedExpression { +public: + BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs ) + : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {} + + BinaryExpression& operator = ( BinaryExpression& ); + + void endExpression() const { + m_rb + .setResultType( Internal::compare( m_lhs, m_rhs ) ) + .endExpression( *this ); + } + + virtual bool isBinaryExpression() const CATCH_OVERRIDE { + return true; + } + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + std::string lhs = Catch::toString( m_lhs ); + std::string rhs = Catch::toString( m_rhs ); + char delim = lhs.size() + rhs.size() < 40 && + lhs.find('\n') == std::string::npos && + rhs.find('\n') == std::string::npos ? ' ' : '\n'; + dest.reserve( 7 + lhs.size() + rhs.size() ); + // 2 for spaces around operator + // 2 for operator + // 2 for parentheses (conditionally added later) + // 1 for negation (conditionally added later) + dest = lhs; + dest += delim; + dest += Internal::OperatorTraits::getName(); + dest += delim; + dest += rhs; + } + +private: + ResultBuilder& m_rb; + LhsT m_lhs; + RhsT m_rhs; +}; + +template +class MatchExpression : public DecomposedExpression { +public: + MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString ) + : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {} + + virtual bool isBinaryExpression() const CATCH_OVERRIDE { + return true; + } + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + std::string matcherAsString = m_matcher.toString(); + dest = Catch::toString( m_arg ); + dest += ' '; + if( matcherAsString == Detail::unprintableString ) + dest += m_matcherString; + else + dest += matcherAsString; + } + +private: + ArgT m_arg; + MatcherT m_matcher; + char const* m_matcherString; +}; + +} // end namespace Catch + + +namespace Catch { + + template + inline ExpressionLhs ResultBuilder::operator <= ( T const& operand ) { + return ExpressionLhs( *this, operand ); + } + + inline ExpressionLhs ResultBuilder::operator <= ( bool value ) { + return ExpressionLhs( *this, value ); + } + + template + inline void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher, + char const* matcherString ) { + MatchExpression expr( arg, matcher, matcherString ); + setResultType( matcher.match( arg ) ); + endExpression( expr ); + } + +} // namespace Catch + +// #included from: catch_message.h +#define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED + +#include + +namespace Catch { + + struct MessageInfo { + MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ); + + std::string macroName; + SourceLineInfo lineInfo; + ResultWas::OfType type; + std::string message; + unsigned int sequence; + + bool operator == ( MessageInfo const& other ) const { + return sequence == other.sequence; + } + bool operator < ( MessageInfo const& other ) const { + return sequence < other.sequence; + } + private: + static unsigned int globalCount; + }; + + struct MessageBuilder { + MessageBuilder( std::string const& macroName, + SourceLineInfo const& lineInfo, + ResultWas::OfType type ) + : m_info( macroName, lineInfo, type ) + {} + + template + MessageBuilder& operator << ( T const& value ) { + m_stream << value; + return *this; + } + + MessageInfo m_info; + std::ostringstream m_stream; + }; + + class ScopedMessage { + public: + ScopedMessage( MessageBuilder const& builder ); + ScopedMessage( ScopedMessage const& other ); + ~ScopedMessage(); + + MessageInfo m_info; + }; + +} // end namespace Catch + +// #included from: catch_interfaces_capture.h +#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED + +#include + +namespace Catch { + + class TestCase; + class AssertionResult; + struct AssertionInfo; + struct SectionInfo; + struct SectionEndInfo; + struct MessageInfo; + class ScopedMessageBuilder; + struct Counts; + + struct IResultCapture { + + virtual ~IResultCapture(); + + virtual void assertionEnded( AssertionResult const& result ) = 0; + virtual bool sectionStarted( SectionInfo const& sectionInfo, + Counts& assertions ) = 0; + virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; + virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; + virtual void pushScopedMessage( MessageInfo const& message ) = 0; + virtual void popScopedMessage( MessageInfo const& message ) = 0; + + virtual std::string getCurrentTestName() const = 0; + virtual const AssertionResult* getLastResult() const = 0; + + virtual void exceptionEarlyReported() = 0; + + virtual void handleFatalErrorCondition( std::string const& message ) = 0; + }; + + IResultCapture& getResultCapture(); +} + +// #included from: catch_debugger.h +#define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED + +// #included from: catch_platform.h +#define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED + +#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) +# define CATCH_PLATFORM_MAC +#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) +# define CATCH_PLATFORM_IPHONE +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) +# define CATCH_PLATFORM_WINDOWS +# if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINES_NOMINMAX +# endif +# if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# endif +#endif + +#include + +namespace Catch{ + + bool isDebuggerActive(); + void writeToDebugConsole( std::string const& text ); +} + +#ifdef CATCH_PLATFORM_MAC + + // The following code snippet based on: + // http://cocoawithlove.com/2008/03/break-into-debugger.html + #if defined(__ppc64__) || defined(__ppc__) + #define CATCH_TRAP() \ + __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ + : : : "memory","r0","r3","r4" ) + #else + #define CATCH_TRAP() __asm__("int $3\n" : : ) + #endif + +#elif defined(CATCH_PLATFORM_LINUX) + // If we can use inline assembler, do it because this allows us to break + // directly at the location of the failing check instead of breaking inside + // raise() called from it, i.e. one stack frame below. + #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #define CATCH_TRAP() asm volatile ("int $3") + #else // Fall back to the generic way. + #include + + #define CATCH_TRAP() raise(SIGTRAP) + #endif +#elif defined(_MSC_VER) + #define CATCH_TRAP() __debugbreak() +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) void __stdcall DebugBreak(); + #define CATCH_TRAP() DebugBreak() +#endif + +#ifdef CATCH_TRAP + #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } +#else + #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); +#endif + +// #included from: catch_interfaces_runner.h +#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED + +namespace Catch { + class TestCase; + + struct IRunner { + virtual ~IRunner(); + virtual bool aborting() const = 0; + }; +} + +#if defined(CATCH_CONFIG_FAST_COMPILE) +/////////////////////////////////////////////////////////////////////////////// +// We can speedup compilation significantly by breaking into debugger lower in +// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER +// macro in each assertion +#define INTERNAL_CATCH_REACT( resultBuilder ) \ + resultBuilder.react(); + +/////////////////////////////////////////////////////////////////////////////// +// Another way to speed-up compilation is to omit local try-catch for REQUIRE* +// macros. +// This can potentially cause false negative, if the test code catches +// the exception before it propagates back up to the runner. +#define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ + __catchResult.setExceptionGuard(); \ + CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + ( __catchResult <= expr ).endExpression(); \ + CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + __catchResult.unsetExceptionGuard(); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::isTrue( false && static_cast( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look +// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. + +#define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ + __catchResult.setExceptionGuard(); \ + __catchResult.captureMatch( arg, matcher, #matcher ); \ + __catchResult.unsetExceptionGuard(); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) + +#else +/////////////////////////////////////////////////////////////////////////////// +// In the event of a failure works out if the debugger needs to be invoked +// and/or an exception thrown and takes appropriate action. +// This needs to be done as a macro so the debugger will stop in the user +// source code rather than in Catch library code +#define INTERNAL_CATCH_REACT( resultBuilder ) \ + if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ + resultBuilder.react(); +#endif + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ + try { \ + CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + ( __catchResult <= expr ).endExpression(); \ + CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ + } \ + catch( ... ) { \ + __catchResult.useActiveException( resultDisposition ); \ + } \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::isTrue( false && static_cast( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look + // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \ + if( Catch::getResultCapture().getLastResult()->succeeded() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \ + if( !Catch::getResultCapture().getLastResult()->succeeded() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ + try { \ + static_cast(expr); \ + __catchResult.captureResult( Catch::ResultWas::Ok ); \ + } \ + catch( ... ) { \ + __catchResult.useActiveException( resultDisposition ); \ + } \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \ + if( __catchResult.allowThrows() ) \ + try { \ + static_cast(expr); \ + __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ + } \ + catch( ... ) { \ + __catchResult.captureExpectedException( matcher ); \ + } \ + else \ + __catchResult.captureResult( Catch::ResultWas::Ok ); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr ", " #exceptionType, resultDisposition ); \ + if( __catchResult.allowThrows() ) \ + try { \ + static_cast(expr); \ + __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ + } \ + catch( exceptionType ) { \ + __catchResult.captureResult( Catch::ResultWas::Ok ); \ + } \ + catch( ... ) { \ + __catchResult.useActiveException( resultDisposition ); \ + } \ + else \ + __catchResult.captureResult( Catch::ResultWas::Ok ); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) + +/////////////////////////////////////////////////////////////////////////////// +#ifdef CATCH_CONFIG_VARIADIC_MACROS + #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ + __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ + __catchResult.captureResult( messageType ); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) +#else + #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ + __catchResult << log + ::Catch::StreamEndStop(); \ + __catchResult.captureResult( messageType ); \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) +#endif + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_INFO( macroName, log ) \ + Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ + do { \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ + try { \ + __catchResult.captureMatch( arg, matcher, #matcher ); \ + } catch( ... ) { \ + __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ + } \ + INTERNAL_CATCH_REACT( __catchResult ) \ + } while( Catch::alwaysFalse() ) + +// #included from: internal/catch_section.h +#define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED + +// #included from: catch_section_info.h +#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED + +// #included from: catch_totals.hpp +#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED + +#include + +namespace Catch { + + struct Counts { + Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {} + + Counts operator - ( Counts const& other ) const { + Counts diff; + diff.passed = passed - other.passed; + diff.failed = failed - other.failed; + diff.failedButOk = failedButOk - other.failedButOk; + return diff; + } + Counts& operator += ( Counts const& other ) { + passed += other.passed; + failed += other.failed; + failedButOk += other.failedButOk; + return *this; + } + + std::size_t total() const { + return passed + failed + failedButOk; + } + bool allPassed() const { + return failed == 0 && failedButOk == 0; + } + bool allOk() const { + return failed == 0; + } + + std::size_t passed; + std::size_t failed; + std::size_t failedButOk; + }; + + struct Totals { + + Totals operator - ( Totals const& other ) const { + Totals diff; + diff.assertions = assertions - other.assertions; + diff.testCases = testCases - other.testCases; + return diff; + } + + Totals delta( Totals const& prevTotals ) const { + Totals diff = *this - prevTotals; + if( diff.assertions.failed > 0 ) + ++diff.testCases.failed; + else if( diff.assertions.failedButOk > 0 ) + ++diff.testCases.failedButOk; + else + ++diff.testCases.passed; + return diff; + } + + Totals& operator += ( Totals const& other ) { + assertions += other.assertions; + testCases += other.testCases; + return *this; + } + + Counts assertions; + Counts testCases; + }; +} + +#include + +namespace Catch { + + struct SectionInfo { + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description = std::string() ); + + std::string name; + std::string description; + SourceLineInfo lineInfo; + }; + + struct SectionEndInfo { + SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) + : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) + {} + + SectionInfo sectionInfo; + Counts prevAssertions; + double durationInSeconds; + }; + +} // end namespace Catch + +// #included from: catch_timer.h +#define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED + +#ifdef CATCH_PLATFORM_WINDOWS +typedef unsigned long long uint64_t; +#else +#include +#endif + +namespace Catch { + + class Timer { + public: + Timer() : m_ticks( 0 ) {} + void start(); + unsigned int getElapsedMicroseconds() const; + unsigned int getElapsedMilliseconds() const; + double getElapsedSeconds() const; + + private: + uint64_t m_ticks; + }; + +} // namespace Catch + +#include + +namespace Catch { + + class Section : NonCopyable { + public: + Section( SectionInfo const& info ); + ~Section(); + + // This indicates whether the section should be executed or not + operator bool() const; + + private: + SectionInfo m_info; + + std::string m_name; + Counts m_assertions; + bool m_sectionIncluded; + Timer m_timer; + }; + +} // end namespace Catch + +#ifdef CATCH_CONFIG_VARIADIC_MACROS + #define INTERNAL_CATCH_SECTION( ... ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) +#else + #define INTERNAL_CATCH_SECTION( name, desc ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) +#endif + +// #included from: internal/catch_generators.hpp +#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED + +#include +#include +#include + +namespace Catch { + +template +struct IGenerator { + virtual ~IGenerator() {} + virtual T getValue( std::size_t index ) const = 0; + virtual std::size_t size () const = 0; +}; + +template +class BetweenGenerator : public IGenerator { +public: + BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} + + virtual T getValue( std::size_t index ) const { + return m_from+static_cast( index ); + } + + virtual std::size_t size() const { + return static_cast( 1+m_to-m_from ); + } + +private: + + T m_from; + T m_to; +}; + +template +class ValuesGenerator : public IGenerator { +public: + ValuesGenerator(){} + + void add( T value ) { + m_values.push_back( value ); + } + + virtual T getValue( std::size_t index ) const { + return m_values[index]; + } + + virtual std::size_t size() const { + return m_values.size(); + } + +private: + std::vector m_values; +}; + +template +class CompositeGenerator { +public: + CompositeGenerator() : m_totalSize( 0 ) {} + + // *** Move semantics, similar to auto_ptr *** + CompositeGenerator( CompositeGenerator& other ) + : m_fileInfo( other.m_fileInfo ), + m_totalSize( 0 ) + { + move( other ); + } + + CompositeGenerator& setFileInfo( const char* fileInfo ) { + m_fileInfo = fileInfo; + return *this; + } + + ~CompositeGenerator() { + deleteAll( m_composed ); + } + + operator T () const { + size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); + + typename std::vector*>::const_iterator it = m_composed.begin(); + typename std::vector*>::const_iterator itEnd = m_composed.end(); + for( size_t index = 0; it != itEnd; ++it ) + { + const IGenerator* generator = *it; + if( overallIndex >= index && overallIndex < index + generator->size() ) + { + return generator->getValue( overallIndex-index ); + } + index += generator->size(); + } + CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); + return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so + } + + void add( const IGenerator* generator ) { + m_totalSize += generator->size(); + m_composed.push_back( generator ); + } + + CompositeGenerator& then( CompositeGenerator& other ) { + move( other ); + return *this; + } + + CompositeGenerator& then( T value ) { + ValuesGenerator* valuesGen = new ValuesGenerator(); + valuesGen->add( value ); + add( valuesGen ); + return *this; + } + +private: + + void move( CompositeGenerator& other ) { + m_composed.insert( m_composed.end(), other.m_composed.begin(), other.m_composed.end() ); + m_totalSize += other.m_totalSize; + other.m_composed.clear(); + } + + std::vector*> m_composed; + std::string m_fileInfo; + size_t m_totalSize; +}; + +namespace Generators +{ + template + CompositeGenerator between( T from, T to ) { + CompositeGenerator generators; + generators.add( new BetweenGenerator( from, to ) ); + return generators; + } + + template + CompositeGenerator values( T val1, T val2 ) { + CompositeGenerator generators; + ValuesGenerator* valuesGen = new ValuesGenerator(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + generators.add( valuesGen ); + return generators; + } + + template + CompositeGenerator values( T val1, T val2, T val3 ){ + CompositeGenerator generators; + ValuesGenerator* valuesGen = new ValuesGenerator(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + valuesGen->add( val3 ); + generators.add( valuesGen ); + return generators; + } + + template + CompositeGenerator values( T val1, T val2, T val3, T val4 ) { + CompositeGenerator generators; + ValuesGenerator* valuesGen = new ValuesGenerator(); + valuesGen->add( val1 ); + valuesGen->add( val2 ); + valuesGen->add( val3 ); + valuesGen->add( val4 ); + generators.add( valuesGen ); + return generators; + } + +} // end namespace Generators + +using namespace Generators; + +} // end namespace Catch + +#define INTERNAL_CATCH_LINESTR2( line ) #line +#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) + +#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) + +// #included from: internal/catch_interfaces_exception.h +#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED + +#include +#include + +// #included from: catch_interfaces_registry_hub.h +#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED + +#include + +namespace Catch { + + class TestCase; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; + struct IReporterRegistry; + struct IReporterFactory; + struct ITagAliasRegistry; + + struct IRegistryHub { + virtual ~IRegistryHub(); + + virtual IReporterRegistry const& getReporterRegistry() const = 0; + virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; + virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0; + + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; + }; + + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(); + virtual void registerReporter( std::string const& name, Ptr const& factory ) = 0; + virtual void registerListener( Ptr const& factory ) = 0; + virtual void registerTest( TestCase const& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; + }; + + IRegistryHub& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); + std::string translateActiveException(); + +} + +namespace Catch { + + typedef std::string(*exceptionTranslateFunction)(); + + struct IExceptionTranslator; + typedef std::vector ExceptionTranslators; + + struct IExceptionTranslator { + virtual ~IExceptionTranslator(); + virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; + }; + + struct IExceptionTranslatorRegistry { + virtual ~IExceptionTranslatorRegistry(); + + virtual std::string translateActiveException() const = 0; + }; + + class ExceptionTranslatorRegistrar { + template + class ExceptionTranslator : public IExceptionTranslator { + public: + + ExceptionTranslator( std::string(*translateFunction)( T& ) ) + : m_translateFunction( translateFunction ) + {} + + virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE { + try { + if( it == itEnd ) + throw; + else + return (*it)->translate( it+1, itEnd ); + } + catch( T& ex ) { + return m_translateFunction( ex ); + } + } + + protected: + std::string(*m_translateFunction)( T& ); + }; + + public: + template + ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { + getMutableRegistryHub().registerTranslator + ( new ExceptionTranslator( translateFunction ) ); + } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ + static std::string translatorName( signature ); \ + namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\ + static std::string translatorName( signature ) + +#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) + +// #included from: internal/catch_approx.hpp +#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED + +#include +#include + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) +#include +#endif + +namespace Catch { +namespace Detail { + + class Approx { + public: + explicit Approx ( double value ) + : m_epsilon( std::numeric_limits::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 1.0 ), + m_value( value ) + {} + + Approx( Approx const& other ) + : m_epsilon( other.m_epsilon ), + m_margin( other.m_margin ), + m_scale( other.m_scale ), + m_value( other.m_value ) + {} + + static Approx custom() { + return Approx( 0 ); + } + + Approx operator()( double value ) { + Approx approx( value ); + approx.epsilon( m_epsilon ); + approx.margin( m_margin ); + approx.scale( m_scale ); + return approx; + } + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) + + template ::value>::type> + explicit Approx( T value ): Approx(static_cast(value)) + {} + + template ::value>::type> + friend bool operator == ( const T& lhs, Approx const& rhs ) { + // Thanks to Richard Harris for his help refining this formula + auto lhs_v = double(lhs); + bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale + (std::max)(std::fabs(lhs_v), std::fabs(rhs.m_value))); + if (relativeOK) { + return true; + } + return std::fabs(lhs_v - rhs.m_value) < rhs.m_margin; + } + + template ::value>::type> + friend bool operator == ( Approx const& lhs, const T& rhs ) { + return operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator != ( T lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + template ::value>::type> + friend bool operator != ( Approx const& lhs, T rhs ) { + return !operator==( rhs, lhs ); + } + + template ::value>::type> + friend bool operator <= ( T lhs, Approx const& rhs ) { + return double(lhs) < rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator <= ( Approx const& lhs, T rhs ) { + return lhs.m_value < double(rhs) || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( T lhs, Approx const& rhs ) { + return double(lhs) > rhs.m_value || lhs == rhs; + } + + template ::value>::type> + friend bool operator >= ( Approx const& lhs, T rhs ) { + return lhs.m_value > double(rhs) || lhs == rhs; + } +#else + friend bool operator == ( double lhs, Approx const& rhs ) { + // Thanks to Richard Harris for his help refining this formula + bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) ); + if (relativeOK) { + return true; + } + return std::fabs(lhs - rhs.m_value) < rhs.m_margin; + } + + friend bool operator == ( Approx const& lhs, double rhs ) { + return operator==( rhs, lhs ); + } + + friend bool operator != ( double lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + friend bool operator != ( Approx const& lhs, double rhs ) { + return !operator==( rhs, lhs ); + } + + friend bool operator <= ( double lhs, Approx const& rhs ) { + return lhs < rhs.m_value || lhs == rhs; + } + + friend bool operator <= ( Approx const& lhs, double rhs ) { + return lhs.m_value < rhs || lhs == rhs; + } + + friend bool operator >= ( double lhs, Approx const& rhs ) { + return lhs > rhs.m_value || lhs == rhs; + } + + friend bool operator >= ( Approx const& lhs, double rhs ) { + return lhs.m_value > rhs || lhs == rhs; + } +#endif + + Approx& epsilon( double newEpsilon ) { + m_epsilon = newEpsilon; + return *this; + } + + Approx& margin( double newMargin ) { + m_margin = newMargin; + return *this; + } + + Approx& scale( double newScale ) { + m_scale = newScale; + return *this; + } + + std::string toString() const { + std::ostringstream oss; + oss << "Approx( " << Catch::toString( m_value ) << " )"; + return oss.str(); + } + + private: + double m_epsilon; + double m_margin; + double m_scale; + double m_value; + }; +} + +template<> +inline std::string toString( Detail::Approx const& value ) { + return value.toString(); +} + +} // end namespace Catch + +// #included from: internal/catch_matchers_string.h +#define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED + +namespace Catch { +namespace Matchers { + + namespace StdString { + + struct CasedString + { + CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); + std::string adjustString( std::string const& str ) const; + std::string caseSensitivitySuffix() const; + + CaseSensitive::Choice m_caseSensitivity; + std::string m_str; + }; + + struct StringMatcherBase : MatcherBase { + StringMatcherBase( std::string const& operation, CasedString const& comparator ); + virtual std::string describe() const CATCH_OVERRIDE; + + CasedString m_comparator; + std::string m_operation; + }; + + struct EqualsMatcher : StringMatcherBase { + EqualsMatcher( CasedString const& comparator ); + virtual bool match( std::string const& source ) const CATCH_OVERRIDE; + }; + struct ContainsMatcher : StringMatcherBase { + ContainsMatcher( CasedString const& comparator ); + virtual bool match( std::string const& source ) const CATCH_OVERRIDE; + }; + struct StartsWithMatcher : StringMatcherBase { + StartsWithMatcher( CasedString const& comparator ); + virtual bool match( std::string const& source ) const CATCH_OVERRIDE; + }; + struct EndsWithMatcher : StringMatcherBase { + EndsWithMatcher( CasedString const& comparator ); + virtual bool match( std::string const& source ) const CATCH_OVERRIDE; + }; + + } // namespace StdString + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); + +} // namespace Matchers +} // namespace Catch + +// #included from: internal/catch_matchers_vector.h +#define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED + +namespace Catch { +namespace Matchers { + + namespace Vector { + + template + struct ContainsElementMatcher : MatcherBase, T> { + + ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} + + bool match(std::vector const &v) const CATCH_OVERRIDE { + return std::find(v.begin(), v.end(), m_comparator) != v.end(); + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "Contains: " + Catch::toString( m_comparator ); + } + + T const& m_comparator; + }; + + template + struct ContainsMatcher : MatcherBase, std::vector > { + + ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const CATCH_OVERRIDE { + // !TBD: see note in EqualsMatcher + if (m_comparator.size() > v.size()) + return false; + for (size_t i = 0; i < m_comparator.size(); ++i) + if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end()) + return false; + return true; + } + virtual std::string describe() const CATCH_OVERRIDE { + return "Contains: " + Catch::toString( m_comparator ); + } + + std::vector const& m_comparator; + }; + + template + struct EqualsMatcher : MatcherBase, std::vector > { + + EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + + bool match(std::vector const &v) const CATCH_OVERRIDE { + // !TBD: This currently works if all elements can be compared using != + // - a more general approach would be via a compare template that defaults + // to using !=. but could be specialised for, e.g. std::vector etc + // - then just call that directly + if (m_comparator.size() != v.size()) + return false; + for (size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != v[i]) + return false; + return true; + } + virtual std::string describe() const CATCH_OVERRIDE { + return "Equals: " + Catch::toString( m_comparator ); + } + std::vector const& m_comparator; + }; + + } // namespace Vector + + // The following functions create the actual matcher objects. + // This allows the types to be inferred + + template + Vector::ContainsMatcher Contains( std::vector const& comparator ) { + return Vector::ContainsMatcher( comparator ); + } + + template + Vector::ContainsElementMatcher VectorContains( T const& comparator ) { + return Vector::ContainsElementMatcher( comparator ); + } + + template + Vector::EqualsMatcher Equals( std::vector const& comparator ) { + return Vector::EqualsMatcher( comparator ); + } + +} // namespace Matchers +} // namespace Catch + +// #included from: internal/catch_interfaces_tag_alias_registry.h +#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED + +// #included from: catch_tag_alias.h +#define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED + +#include + +namespace Catch { + + struct TagAlias { + TagAlias( std::string const& _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} + + std::string tag; + SourceLineInfo lineInfo; + }; + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } +// #included from: catch_option.hpp +#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED + +namespace Catch { + + // An optional type + template + class Option { + public: + Option() : nullableValue( CATCH_NULL ) {} + Option( T const& _value ) + : nullableValue( new( storage ) T( _value ) ) + {} + Option( Option const& _other ) + : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL ) + {} + + ~Option() { + reset(); + } + + Option& operator= ( Option const& _other ) { + if( &_other != this ) { + reset(); + if( _other ) + nullableValue = new( storage ) T( *_other ); + } + return *this; + } + Option& operator = ( T const& _value ) { + reset(); + nullableValue = new( storage ) T( _value ); + return *this; + } + + void reset() { + if( nullableValue ) + nullableValue->~T(); + nullableValue = CATCH_NULL; + } + + T& operator*() { return *nullableValue; } + T const& operator*() const { return *nullableValue; } + T* operator->() { return nullableValue; } + const T* operator->() const { return nullableValue; } + + T valueOr( T const& defaultValue ) const { + return nullableValue ? *nullableValue : defaultValue; + } + + bool some() const { return nullableValue != CATCH_NULL; } + bool none() const { return nullableValue == CATCH_NULL; } + + bool operator !() const { return nullableValue == CATCH_NULL; } + operator SafeBool::type() const { + return SafeBool::makeSafe( some() ); + } + + private: + T* nullableValue; + char storage[sizeof(T)]; + }; + +} // end namespace Catch + +namespace Catch { + + struct ITagAliasRegistry { + virtual ~ITagAliasRegistry(); + virtual Option find( std::string const& alias ) const = 0; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; + + static ITagAliasRegistry const& get(); + }; + +} // end namespace Catch + +// These files are included here so the single_include script doesn't put them +// in the conditionally compiled sections +// #included from: internal/catch_test_case_info.h +#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED + +#include +#include + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +namespace Catch { + + struct ITestCase; + + struct TestCaseInfo { + enum SpecialProperties{ + None = 0, + IsHidden = 1 << 1, + ShouldFail = 1 << 2, + MayFail = 1 << 3, + Throws = 1 << 4, + NonPortable = 1 << 5 + }; + + TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::set const& _tags, + SourceLineInfo const& _lineInfo ); + + TestCaseInfo( TestCaseInfo const& other ); + + friend void setTags( TestCaseInfo& testCaseInfo, std::set const& tags ); + + bool isHidden() const; + bool throws() const; + bool okToFail() const; + bool expectedToFail() const; + + std::string name; + std::string className; + std::string description; + std::set tags; + std::set lcaseTags; + std::string tagsAsString; + SourceLineInfo lineInfo; + SpecialProperties properties; + }; + + class TestCase : public TestCaseInfo { + public: + + TestCase( ITestCase* testCase, TestCaseInfo const& info ); + TestCase( TestCase const& other ); + + TestCase withName( std::string const& _newName ) const; + + void invoke() const; + + TestCaseInfo const& getTestCaseInfo() const; + + void swap( TestCase& other ); + bool operator == ( TestCase const& other ) const; + bool operator < ( TestCase const& other ) const; + TestCase& operator = ( TestCase const& other ); + + private: + Ptr test; + }; + + TestCase makeTestCase( ITestCase* testCase, + std::string const& className, + std::string const& name, + std::string const& description, + SourceLineInfo const& lineInfo ); +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + + +#ifdef __OBJC__ +// #included from: internal/catch_objc.hpp +#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED + +#import + +#include + +// NB. Any general catch headers included here must be included +// in catch.hpp first to make sure they are included by the single +// header for non obj-usage + +/////////////////////////////////////////////////////////////////////////////// +// This protocol is really only here for (self) documenting purposes, since +// all its methods are optional. +@protocol OcFixture + +@optional + +-(void) setUp; +-(void) tearDown; + +@end + +namespace Catch { + + class OcMethod : public SharedImpl { + + public: + OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} + + virtual void invoke() const { + id obj = [[m_cls alloc] init]; + + performOptionalSelector( obj, @selector(setUp) ); + performOptionalSelector( obj, m_sel ); + performOptionalSelector( obj, @selector(tearDown) ); + + arcSafeRelease( obj ); + } + private: + virtual ~OcMethod() {} + + Class m_cls; + SEL m_sel; + }; + + namespace Detail{ + + inline std::string getAnnotation( Class cls, + std::string const& annotationName, + std::string const& testCaseName ) { + NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; + SEL sel = NSSelectorFromString( selStr ); + arcSafeRelease( selStr ); + id value = performOptionalSelector( cls, sel ); + if( value ) + return [(NSString*)value UTF8String]; + return ""; + } + } + + inline size_t registerTestMethods() { + size_t noTestMethods = 0; + int noClasses = objc_getClassList( CATCH_NULL, 0 ); + + Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); + objc_getClassList( classes, noClasses ); + + for( int c = 0; c < noClasses; c++ ) { + Class cls = classes[c]; + { + u_int count; + Method* methods = class_copyMethodList( cls, &count ); + for( u_int m = 0; m < count ; m++ ) { + SEL selector = method_getName(methods[m]); + std::string methodName = sel_getName(selector); + if( startsWith( methodName, "Catch_TestCase_" ) ) { + std::string testCaseName = methodName.substr( 15 ); + std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); + std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); + const char* className = class_getName( cls ); + + getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); + noTestMethods++; + } + } + free(methods); + } + } + return noTestMethods; + } + + namespace Matchers { + namespace Impl { + namespace NSStringMatchers { + + struct StringHolder : MatcherBase{ + StringHolder( NSString* substr ) : m_substr( [substr copy] ){} + StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} + StringHolder() { + arcSafeRelease( m_substr ); + } + + virtual bool match( NSString* arg ) const CATCH_OVERRIDE { + return false; + } + + NSString* m_substr; + }; + + struct Equals : StringHolder { + Equals( NSString* substr ) : StringHolder( substr ){} + + virtual bool match( NSString* str ) const CATCH_OVERRIDE { + return (str != nil || m_substr == nil ) && + [str isEqualToString:m_substr]; + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "equals string: " + Catch::toString( m_substr ); + } + }; + + struct Contains : StringHolder { + Contains( NSString* substr ) : StringHolder( substr ){} + + virtual bool match( NSString* str ) const { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location != NSNotFound; + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "contains string: " + Catch::toString( m_substr ); + } + }; + + struct StartsWith : StringHolder { + StartsWith( NSString* substr ) : StringHolder( substr ){} + + virtual bool match( NSString* str ) const { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == 0; + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "starts with: " + Catch::toString( m_substr ); + } + }; + struct EndsWith : StringHolder { + EndsWith( NSString* substr ) : StringHolder( substr ){} + + virtual bool match( NSString* str ) const { + return (str != nil || m_substr == nil ) && + [str rangeOfString:m_substr].location == [str length] - [m_substr length]; + } + + virtual std::string describe() const CATCH_OVERRIDE { + return "ends with: " + Catch::toString( m_substr ); + } + }; + + } // namespace NSStringMatchers + } // namespace Impl + + inline Impl::NSStringMatchers::Equals + Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } + + inline Impl::NSStringMatchers::Contains + Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } + + inline Impl::NSStringMatchers::StartsWith + StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } + + inline Impl::NSStringMatchers::EndsWith + EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } + + } // namespace Matchers + + using namespace Matchers; + +} // namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define OC_TEST_CASE( name, desc )\ ++(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ +{\ +return @ name; \ +}\ ++(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ +{ \ +return @ desc; \ +} \ +-(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) + +#endif + +#ifdef CATCH_IMPL + +// !TBD: Move the leak detector code into a separate header +#ifdef CATCH_CONFIG_WINDOWS_CRTDBG +#include +class LeakDetector { +public: + LeakDetector() { + int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + flag |= _CRTDBG_LEAK_CHECK_DF; + flag |= _CRTDBG_ALLOC_MEM_DF; + _CrtSetDbgFlag(flag); + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + // Change this to leaking allocation's number to break there + _CrtSetBreakAlloc(-1); + } +}; +#else +class LeakDetector {}; +#endif + +LeakDetector leakDetector; + +// #included from: internal/catch_impl.hpp +#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED + +// Collect all the implementation files together here +// These are the equivalent of what would usually be cpp files + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#endif + +// #included from: ../catch_session.hpp +#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED + +// #included from: internal/catch_commandline.hpp +#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED + +// #included from: catch_config.hpp +#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED + +// #included from: catch_test_spec_parser.hpp +#define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// #included from: catch_test_spec.hpp +#define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpadded" +#endif + +// #included from: catch_wildcard_pattern.hpp +#define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED + +#include + +namespace Catch +{ + class WildcardPattern { + enum WildcardPosition { + NoWildcard = 0, + WildcardAtStart = 1, + WildcardAtEnd = 2, + WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd + }; + + public: + + WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_wildcard( NoWildcard ), + m_pattern( adjustCase( pattern ) ) + { + if( startsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 1 ); + m_wildcard = WildcardAtStart; + } + if( endsWith( m_pattern, '*' ) ) { + m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); + m_wildcard = static_cast( m_wildcard | WildcardAtEnd ); + } + } + virtual ~WildcardPattern(); + virtual bool matches( std::string const& str ) const { + switch( m_wildcard ) { + case NoWildcard: + return m_pattern == adjustCase( str ); + case WildcardAtStart: + return endsWith( adjustCase( str ), m_pattern ); + case WildcardAtEnd: + return startsWith( adjustCase( str ), m_pattern ); + case WildcardAtBothEnds: + return contains( adjustCase( str ), m_pattern ); + } + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif + throw std::logic_error( "Unknown enum" ); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + } + private: + std::string adjustCase( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; + } + CaseSensitive::Choice m_caseSensitivity; + WildcardPosition m_wildcard; + std::string m_pattern; + }; +} + +#include +#include + +namespace Catch { + + class TestSpec { + struct Pattern : SharedImpl<> { + virtual ~Pattern(); + virtual bool matches( TestCaseInfo const& testCase ) const = 0; + }; + class NamePattern : public Pattern { + public: + NamePattern( std::string const& name ) + : m_wildcardPattern( toLower( name ), CaseSensitive::No ) + {} + virtual ~NamePattern(); + virtual bool matches( TestCaseInfo const& testCase ) const { + return m_wildcardPattern.matches( toLower( testCase.name ) ); + } + private: + WildcardPattern m_wildcardPattern; + }; + + class TagPattern : public Pattern { + public: + TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} + virtual ~TagPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const { + return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); + } + private: + std::string m_tag; + }; + + class ExcludedPattern : public Pattern { + public: + ExcludedPattern( Ptr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} + virtual ~ExcludedPattern(); + virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } + private: + Ptr m_underlyingPattern; + }; + + struct Filter { + std::vector > m_patterns; + + bool matches( TestCaseInfo const& testCase ) const { + // All patterns in a filter must match for the filter to be a match + for( std::vector >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) { + if( !(*it)->matches( testCase ) ) + return false; + } + return true; + } + }; + + public: + bool hasFilters() const { + return !m_filters.empty(); + } + bool matches( TestCaseInfo const& testCase ) const { + // A TestSpec matches if any filter matches + for( std::vector::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) + if( it->matches( testCase ) ) + return true; + return false; + } + + private: + std::vector m_filters; + + friend class TestSpecParser; + }; +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +namespace Catch { + + class TestSpecParser { + enum Mode{ None, Name, QuotedName, Tag, EscapedName }; + Mode m_mode; + bool m_exclusion; + std::size_t m_start, m_pos; + std::string m_arg; + std::vector m_escapeChars; + TestSpec::Filter m_currentFilter; + TestSpec m_testSpec; + ITagAliasRegistry const* m_tagAliases; + + public: + TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} + + TestSpecParser& parse( std::string const& arg ) { + m_mode = None; + m_exclusion = false; + m_start = std::string::npos; + m_arg = m_tagAliases->expandAliases( arg ); + m_escapeChars.clear(); + for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) + visitChar( m_arg[m_pos] ); + if( m_mode == Name ) + addPattern(); + return *this; + } + TestSpec testSpec() { + addFilter(); + return m_testSpec; + } + private: + void visitChar( char c ) { + if( m_mode == None ) { + switch( c ) { + case ' ': return; + case '~': m_exclusion = true; return; + case '[': return startNewMode( Tag, ++m_pos ); + case '"': return startNewMode( QuotedName, ++m_pos ); + case '\\': return escape(); + default: startNewMode( Name, m_pos ); break; + } + } + if( m_mode == Name ) { + if( c == ',' ) { + addPattern(); + addFilter(); + } + else if( c == '[' ) { + if( subString() == "exclude:" ) + m_exclusion = true; + else + addPattern(); + startNewMode( Tag, ++m_pos ); + } + else if( c == '\\' ) + escape(); + } + else if( m_mode == EscapedName ) + m_mode = Name; + else if( m_mode == QuotedName && c == '"' ) + addPattern(); + else if( m_mode == Tag && c == ']' ) + addPattern(); + } + void startNewMode( Mode mode, std::size_t start ) { + m_mode = mode; + m_start = start; + } + void escape() { + if( m_mode == None ) + m_start = m_pos; + m_mode = EscapedName; + m_escapeChars.push_back( m_pos ); + } + std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } + template + void addPattern() { + std::string token = subString(); + for( size_t i = 0; i < m_escapeChars.size(); ++i ) + token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); + m_escapeChars.clear(); + if( startsWith( token, "exclude:" ) ) { + m_exclusion = true; + token = token.substr( 8 ); + } + if( !token.empty() ) { + Ptr pattern = new T( token ); + if( m_exclusion ) + pattern = new TestSpec::ExcludedPattern( pattern ); + m_currentFilter.m_patterns.push_back( pattern ); + } + m_exclusion = false; + m_mode = None; + } + void addFilter() { + if( !m_currentFilter.m_patterns.empty() ) { + m_testSpec.m_filters.push_back( m_currentFilter ); + m_currentFilter = TestSpec::Filter(); + } + } + }; + inline TestSpec parseTestSpec( std::string const& arg ) { + return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); + } + +} // namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +// #included from: catch_interfaces_config.h +#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED + +#include +#include +#include + +namespace Catch { + + struct Verbosity { enum Level { + NoOutput = 0, + Quiet, + Normal + }; }; + + struct WarnAbout { enum What { + Nothing = 0x00, + NoAssertions = 0x01 + }; }; + + struct ShowDurations { enum OrNot { + DefaultForReporter, + Always, + Never + }; }; + struct RunTests { enum InWhatOrder { + InDeclarationOrder, + InLexicographicalOrder, + InRandomOrder + }; }; + struct UseColour { enum YesOrNo { + Auto, + Yes, + No + }; }; + + class TestSpec; + + struct IConfig : IShared { + + virtual ~IConfig(); + + virtual bool allowThrows() const = 0; + virtual std::ostream& stream() const = 0; + virtual std::string name() const = 0; + virtual bool includeSuccessfulResults() const = 0; + virtual bool shouldDebugBreak() const = 0; + virtual bool warnAboutMissingAssertions() const = 0; + virtual int abortAfter() const = 0; + virtual bool showInvisibles() const = 0; + virtual ShowDurations::OrNot showDurations() const = 0; + virtual TestSpec const& testSpec() const = 0; + virtual RunTests::InWhatOrder runOrder() const = 0; + virtual unsigned int rngSeed() const = 0; + virtual UseColour::YesOrNo useColour() const = 0; + virtual std::vector const& getSectionsToRun() const = 0; + + }; +} + +// #included from: catch_stream.h +#define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED + +// #included from: catch_streambuf.h +#define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED + +#include + +namespace Catch { + + class StreamBufBase : public std::streambuf { + public: + virtual ~StreamBufBase() CATCH_NOEXCEPT; + }; +} + +#include +#include +#include +#include + +namespace Catch { + + std::ostream& cout(); + std::ostream& cerr(); + + struct IStream { + virtual ~IStream() CATCH_NOEXCEPT; + virtual std::ostream& stream() const = 0; + }; + + class FileStream : public IStream { + mutable std::ofstream m_ofs; + public: + FileStream( std::string const& filename ); + virtual ~FileStream() CATCH_NOEXCEPT; + public: // IStream + virtual std::ostream& stream() const CATCH_OVERRIDE; + }; + + class CoutStream : public IStream { + mutable std::ostream m_os; + public: + CoutStream(); + virtual ~CoutStream() CATCH_NOEXCEPT; + + public: // IStream + virtual std::ostream& stream() const CATCH_OVERRIDE; + }; + + class DebugOutStream : public IStream { + CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf; + mutable std::ostream m_os; + public: + DebugOutStream(); + virtual ~DebugOutStream() CATCH_NOEXCEPT; + + public: // IStream + virtual std::ostream& stream() const CATCH_OVERRIDE; + }; +} + +#include +#include +#include +#include + +#ifndef CATCH_CONFIG_CONSOLE_WIDTH +#define CATCH_CONFIG_CONSOLE_WIDTH 80 +#endif + +namespace Catch { + + struct ConfigData { + + ConfigData() + : listTests( false ), + listTags( false ), + listReporters( false ), + listTestNamesOnly( false ), + showSuccessfulTests( false ), + shouldDebugBreak( false ), + noThrow( false ), + showHelp( false ), + showInvisibles( false ), + filenamesAsTags( false ), + abortAfter( -1 ), + rngSeed( 0 ), + verbosity( Verbosity::Normal ), + warnings( WarnAbout::Nothing ), + showDurations( ShowDurations::DefaultForReporter ), + runOrder( RunTests::InDeclarationOrder ), + useColour( UseColour::Auto ) + {} + + bool listTests; + bool listTags; + bool listReporters; + bool listTestNamesOnly; + + bool showSuccessfulTests; + bool shouldDebugBreak; + bool noThrow; + bool showHelp; + bool showInvisibles; + bool filenamesAsTags; + + int abortAfter; + unsigned int rngSeed; + + Verbosity::Level verbosity; + WarnAbout::What warnings; + ShowDurations::OrNot showDurations; + RunTests::InWhatOrder runOrder; + UseColour::YesOrNo useColour; + + std::string outputFilename; + std::string name; + std::string processName; + + std::vector reporterNames; + std::vector testsOrTags; + std::vector sectionsToRun; + }; + + class Config : public SharedImpl { + private: + Config( Config const& other ); + Config& operator = ( Config const& other ); + virtual void dummy(); + public: + + Config() + {} + + Config( ConfigData const& data ) + : m_data( data ), + m_stream( openStream() ) + { + if( !data.testsOrTags.empty() ) { + TestSpecParser parser( ITagAliasRegistry::get() ); + for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) + parser.parse( data.testsOrTags[i] ); + m_testSpec = parser.testSpec(); + } + } + + virtual ~Config() {} + + std::string const& getFilename() const { + return m_data.outputFilename ; + } + + bool listTests() const { return m_data.listTests; } + bool listTestNamesOnly() const { return m_data.listTestNamesOnly; } + bool listTags() const { return m_data.listTags; } + bool listReporters() const { return m_data.listReporters; } + + std::string getProcessName() const { return m_data.processName; } + + std::vector const& getReporterNames() const { return m_data.reporterNames; } + std::vector const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; } + + virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; } + + bool showHelp() const { return m_data.showHelp; } + + // IConfig interface + virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; } + virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); } + virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; } + virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; } + virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; } + virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; } + virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; } + virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; } + virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; } + virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; } + virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; } + virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; } + + private: + + IStream const* openStream() { + if( m_data.outputFilename.empty() ) + return new CoutStream(); + else if( m_data.outputFilename[0] == '%' ) { + if( m_data.outputFilename == "%debug" ) + return new DebugOutStream(); + else + throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename ); + } + else + return new FileStream( m_data.outputFilename ); + } + ConfigData m_data; + + CATCH_AUTO_PTR( IStream const ) m_stream; + TestSpec m_testSpec; + }; + +} // end namespace Catch + +// #included from: catch_clara.h +#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED + +// Use Catch's value for console width (store Clara's off to the side, if present) +#ifdef CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH +#undef CLARA_CONFIG_CONSOLE_WIDTH +#endif +#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + +// Declare Clara inside the Catch namespace +#define STITCH_CLARA_OPEN_NAMESPACE namespace Catch { +// #included from: ../external/clara.h + +// Version 0.0.2.4 + +// Only use header guard if we are not using an outer namespace +#if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE) + +#ifndef STITCH_CLARA_OPEN_NAMESPACE +#define TWOBLUECUBES_CLARA_H_INCLUDED +#define STITCH_CLARA_OPEN_NAMESPACE +#define STITCH_CLARA_CLOSE_NAMESPACE +#else +#define STITCH_CLARA_CLOSE_NAMESPACE } +#endif + +#define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE + +// ----------- #included from tbc_text_format.h ----------- + +// Only use header guard if we are not using an outer namespace +#if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE) +#ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE +#define TBC_TEXT_FORMAT_H_INCLUDED +#endif + +#include +#include +#include +#include +#include + +// Use optional outer namespace +#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE +namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE { +#endif + +namespace Tbc { + +#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH + const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + struct TextAttributes { + TextAttributes() + : initialIndent( std::string::npos ), + indent( 0 ), + width( consoleWidth-1 ), + tabChar( '\t' ) + {} + + TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } + TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } + TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } + TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } + + std::size_t initialIndent; // indent of first line, or npos + std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos + std::size_t width; // maximum width of text, including indent. Longer text will wrap + char tabChar; // If this char is seen the indent is changed to current pos + }; + + class Text { + public: + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) + : attr( _attr ) + { + std::string wrappableChars = " [({.,/|\\-"; + std::size_t indent = _attr.initialIndent != std::string::npos + ? _attr.initialIndent + : _attr.indent; + std::string remainder = _str; + + while( !remainder.empty() ) { + if( lines.size() >= 1000 ) { + lines.push_back( "... message truncated due to excessive size" ); + return; + } + std::size_t tabPos = std::string::npos; + std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); + std::size_t pos = remainder.find_first_of( '\n' ); + if( pos <= width ) { + width = pos; + } + pos = remainder.find_last_of( _attr.tabChar, width ); + if( pos != std::string::npos ) { + tabPos = pos; + if( remainder[width] == '\n' ) + width--; + remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); + } + + if( width == remainder.size() ) { + spliceLine( indent, remainder, width ); + } + else if( remainder[width] == '\n' ) { + spliceLine( indent, remainder, width ); + if( width <= 1 || remainder.size() != 1 ) + remainder = remainder.substr( 1 ); + indent = _attr.indent; + } + else { + pos = remainder.find_last_of( wrappableChars, width ); + if( pos != std::string::npos && pos > 0 ) { + spliceLine( indent, remainder, pos ); + if( remainder[0] == ' ' ) + remainder = remainder.substr( 1 ); + } + else { + spliceLine( indent, remainder, width-1 ); + lines.back() += "-"; + } + if( lines.size() == 1 ) + indent = _attr.indent; + if( tabPos != std::string::npos ) + indent += tabPos; + } + } + } + + void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { + lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); + _remainder = _remainder.substr( _pos ); + } + + typedef std::vector::const_iterator const_iterator; + + const_iterator begin() const { return lines.begin(); } + const_iterator end() const { return lines.end(); } + std::string const& last() const { return lines.back(); } + std::size_t size() const { return lines.size(); } + std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } + std::string toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + + inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } + + private: + std::string str; + TextAttributes attr; + std::vector lines; + }; + +} // end namespace Tbc + +#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TBC_TEXT_FORMAT_H_INCLUDED + +// ----------- end of #include from tbc_text_format.h ----------- +// ........... back in clara.h + +#undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE + +// ----------- #included from clara_compilers.h ----------- + +#ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED +#define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED + +// Detect a number of compiler features - mostly C++11/14 conformance - by compiler +// The following features are defined: +// +// CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported? +// CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported? +// CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods +// CLARA_CONFIG_CPP11_OVERRIDE : is override supported? +// CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) + +// CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported? + +// CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported? + +// In general each macro has a _NO_ form +// (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +// All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11 + +#ifdef __clang__ + +#if __has_feature(cxx_nullptr) +#define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR +#endif + +#if __has_feature(cxx_noexcept) +#define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT +#endif + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// GCC +#ifdef __GNUC__ + +#if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) +#define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR +#endif + +// - otherwise more recent versions define __cplusplus >= 201103L +// and will get picked up below + +#endif // __GNUC__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#ifdef _MSC_VER + +#if (_MSC_VER >= 1600) +#define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR +#define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR +#endif + +#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) +#define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT +#define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +#endif + +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// C++ language feature support + +// catch all support for C++11 +#if defined(__cplusplus) && __cplusplus >= 201103L + +#define CLARA_CPP11_OR_GREATER + +#if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) +#define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR +#endif + +#ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT +#define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT +#endif + +#ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +#define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +#endif + +#if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) +#define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE +#endif +#if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) +#define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR +#endif + +#endif // __cplusplus >= 201103L + +// Now set the actual defines based on the above + anything the user has configured +#if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11) +#define CLARA_CONFIG_CPP11_NULLPTR +#endif +#if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11) +#define CLARA_CONFIG_CPP11_NOEXCEPT +#endif +#if defined(CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_NO_CPP11) +#define CLARA_CONFIG_CPP11_GENERATED_METHODS +#endif +#if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11) +#define CLARA_CONFIG_CPP11_OVERRIDE +#endif +#if defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_UNIQUE_PTR) && !defined(CLARA_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_CPP11) +#define CLARA_CONFIG_CPP11_UNIQUE_PTR +#endif + +// noexcept support: +#if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT) +#define CLARA_NOEXCEPT noexcept +# define CLARA_NOEXCEPT_IS(x) noexcept(x) +#else +#define CLARA_NOEXCEPT throw() +# define CLARA_NOEXCEPT_IS(x) +#endif + +// nullptr support +#ifdef CLARA_CONFIG_CPP11_NULLPTR +#define CLARA_NULL nullptr +#else +#define CLARA_NULL NULL +#endif + +// override support +#ifdef CLARA_CONFIG_CPP11_OVERRIDE +#define CLARA_OVERRIDE override +#else +#define CLARA_OVERRIDE +#endif + +// unique_ptr support +#ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR +# define CLARA_AUTO_PTR( T ) std::unique_ptr +#else +# define CLARA_AUTO_PTR( T ) std::auto_ptr +#endif + +#endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED + +// ----------- end of #include from clara_compilers.h ----------- +// ........... back in clara.h + +#include +#include +#include + +#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) +#define CLARA_PLATFORM_WINDOWS +#endif + +// Use optional outer namespace +#ifdef STITCH_CLARA_OPEN_NAMESPACE +STITCH_CLARA_OPEN_NAMESPACE +#endif + +namespace Clara { + + struct UnpositionalTag {}; + + extern UnpositionalTag _; + +#ifdef CLARA_CONFIG_MAIN + UnpositionalTag _; +#endif + + namespace Detail { + +#ifdef CLARA_CONSOLE_WIDTH + const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + using namespace Tbc; + + inline bool startsWith( std::string const& str, std::string const& prefix ) { + return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix; + } + + template struct RemoveConstRef{ typedef T type; }; + template struct RemoveConstRef{ typedef T type; }; + template struct RemoveConstRef{ typedef T type; }; + template struct RemoveConstRef{ typedef T type; }; + + template struct IsBool { static const bool value = false; }; + template<> struct IsBool { static const bool value = true; }; + + template + void convertInto( std::string const& _source, T& _dest ) { + std::stringstream ss; + ss << _source; + ss >> _dest; + if( ss.fail() ) + throw std::runtime_error( "Unable to convert " + _source + " to destination type" ); + } + inline void convertInto( std::string const& _source, std::string& _dest ) { + _dest = _source; + } + char toLowerCh(char c) { + return static_cast( std::tolower( c ) ); + } + inline void convertInto( std::string const& _source, bool& _dest ) { + std::string sourceLC = _source; + std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh ); + if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" ) + _dest = true; + else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" ) + _dest = false; + else + throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" ); + } + + template + struct IArgFunction { + virtual ~IArgFunction() {} +#ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS + IArgFunction() = default; + IArgFunction( IArgFunction const& ) = default; +#endif + virtual void set( ConfigT& config, std::string const& value ) const = 0; + virtual bool takesArg() const = 0; + virtual IArgFunction* clone() const = 0; + }; + + template + class BoundArgFunction { + public: + BoundArgFunction() : functionObj( CLARA_NULL ) {} + BoundArgFunction( IArgFunction* _functionObj ) : functionObj( _functionObj ) {} + BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {} + BoundArgFunction& operator = ( BoundArgFunction const& other ) { + IArgFunction* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL; + delete functionObj; + functionObj = newFunctionObj; + return *this; + } + ~BoundArgFunction() { delete functionObj; } + + void set( ConfigT& config, std::string const& value ) const { + functionObj->set( config, value ); + } + bool takesArg() const { return functionObj->takesArg(); } + + bool isSet() const { + return functionObj != CLARA_NULL; + } + private: + IArgFunction* functionObj; + }; + + template + struct NullBinder : IArgFunction{ + virtual void set( C&, std::string const& ) const {} + virtual bool takesArg() const { return true; } + virtual IArgFunction* clone() const { return new NullBinder( *this ); } + }; + + template + struct BoundDataMember : IArgFunction{ + BoundDataMember( M C::* _member ) : member( _member ) {} + virtual void set( C& p, std::string const& stringValue ) const { + convertInto( stringValue, p.*member ); + } + virtual bool takesArg() const { return !IsBool::value; } + virtual IArgFunction* clone() const { return new BoundDataMember( *this ); } + M C::* member; + }; + template + struct BoundUnaryMethod : IArgFunction{ + BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {} + virtual void set( C& p, std::string const& stringValue ) const { + typename RemoveConstRef::type value; + convertInto( stringValue, value ); + (p.*member)( value ); + } + virtual bool takesArg() const { return !IsBool::value; } + virtual IArgFunction* clone() const { return new BoundUnaryMethod( *this ); } + void (C::*member)( M ); + }; + template + struct BoundNullaryMethod : IArgFunction{ + BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {} + virtual void set( C& p, std::string const& stringValue ) const { + bool value; + convertInto( stringValue, value ); + if( value ) + (p.*member)(); + } + virtual bool takesArg() const { return false; } + virtual IArgFunction* clone() const { return new BoundNullaryMethod( *this ); } + void (C::*member)(); + }; + + template + struct BoundUnaryFunction : IArgFunction{ + BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {} + virtual void set( C& obj, std::string const& stringValue ) const { + bool value; + convertInto( stringValue, value ); + if( value ) + function( obj ); + } + virtual bool takesArg() const { return false; } + virtual IArgFunction* clone() const { return new BoundUnaryFunction( *this ); } + void (*function)( C& ); + }; + + template + struct BoundBinaryFunction : IArgFunction{ + BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {} + virtual void set( C& obj, std::string const& stringValue ) const { + typename RemoveConstRef::type value; + convertInto( stringValue, value ); + function( obj, value ); + } + virtual bool takesArg() const { return !IsBool::value; } + virtual IArgFunction* clone() const { return new BoundBinaryFunction( *this ); } + void (*function)( C&, T ); + }; + + } // namespace Detail + + inline std::vector argsToVector( int argc, char const* const* const argv ) { + std::vector args( static_cast( argc ) ); + for( std::size_t i = 0; i < static_cast( argc ); ++i ) + args[i] = argv[i]; + + return args; + } + + class Parser { + enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional }; + Mode mode; + std::size_t from; + bool inQuotes; + public: + + struct Token { + enum Type { Positional, ShortOpt, LongOpt }; + Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {} + Type type; + std::string data; + }; + + Parser() : mode( None ), from( 0 ), inQuotes( false ){} + + void parseIntoTokens( std::vector const& args, std::vector& tokens ) { + const std::string doubleDash = "--"; + for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i ) + parseIntoTokens( args[i], tokens); + } + + void parseIntoTokens( std::string const& arg, std::vector& tokens ) { + for( std::size_t i = 0; i < arg.size(); ++i ) { + char c = arg[i]; + if( c == '"' ) + inQuotes = !inQuotes; + mode = handleMode( i, c, arg, tokens ); + } + mode = handleMode( arg.size(), '\0', arg, tokens ); + } + Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector& tokens ) { + switch( mode ) { + case None: return handleNone( i, c ); + case MaybeShortOpt: return handleMaybeShortOpt( i, c ); + case ShortOpt: + case LongOpt: + case SlashOpt: return handleOpt( i, c, arg, tokens ); + case Positional: return handlePositional( i, c, arg, tokens ); + default: throw std::logic_error( "Unknown mode" ); + } + } + + Mode handleNone( std::size_t i, char c ) { + if( inQuotes ) { + from = i; + return Positional; + } + switch( c ) { + case '-': return MaybeShortOpt; +#ifdef CLARA_PLATFORM_WINDOWS + case '/': from = i+1; return SlashOpt; +#endif + default: from = i; return Positional; + } + } + Mode handleMaybeShortOpt( std::size_t i, char c ) { + switch( c ) { + case '-': from = i+1; return LongOpt; + default: from = i; return ShortOpt; + } + } + + Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector& tokens ) { + if( std::string( ":=\0", 3 ).find( c ) == std::string::npos ) + return mode; + + std::string optName = arg.substr( from, i-from ); + if( mode == ShortOpt ) + for( std::size_t j = 0; j < optName.size(); ++j ) + tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) ); + else if( mode == SlashOpt && optName.size() == 1 ) + tokens.push_back( Token( Token::ShortOpt, optName ) ); + else + tokens.push_back( Token( Token::LongOpt, optName ) ); + return None; + } + Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector& tokens ) { + if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos ) + return mode; + + std::string data = arg.substr( from, i-from ); + tokens.push_back( Token( Token::Positional, data ) ); + return None; + } + }; + + template + struct CommonArgProperties { + CommonArgProperties() {} + CommonArgProperties( Detail::BoundArgFunction const& _boundField ) : boundField( _boundField ) {} + + Detail::BoundArgFunction boundField; + std::string description; + std::string detail; + std::string placeholder; // Only value if boundField takes an arg + + bool takesArg() const { + return !placeholder.empty(); + } + void validate() const { + if( !boundField.isSet() ) + throw std::logic_error( "option not bound" ); + } + }; + struct OptionArgProperties { + std::vector shortNames; + std::string longName; + + bool hasShortName( std::string const& shortName ) const { + return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end(); + } + bool hasLongName( std::string const& _longName ) const { + return _longName == longName; + } + }; + struct PositionalArgProperties { + PositionalArgProperties() : position( -1 ) {} + int position; // -1 means non-positional (floating) + + bool isFixedPositional() const { + return position != -1; + } + }; + + template + class CommandLine { + + struct Arg : CommonArgProperties, OptionArgProperties, PositionalArgProperties { + Arg() {} + Arg( Detail::BoundArgFunction const& _boundField ) : CommonArgProperties( _boundField ) {} + + using CommonArgProperties::placeholder; // !TBD + + std::string dbgName() const { + if( !longName.empty() ) + return "--" + longName; + if( !shortNames.empty() ) + return "-" + shortNames[0]; + return "positional args"; + } + std::string commands() const { + std::ostringstream oss; + bool first = true; + std::vector::const_iterator it = shortNames.begin(), itEnd = shortNames.end(); + for(; it != itEnd; ++it ) { + if( first ) + first = false; + else + oss << ", "; + oss << "-" << *it; + } + if( !longName.empty() ) { + if( !first ) + oss << ", "; + oss << "--" << longName; + } + if( !placeholder.empty() ) + oss << " <" << placeholder << ">"; + return oss.str(); + } + }; + + typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr; + + friend void addOptName( Arg& arg, std::string const& optName ) + { + if( optName.empty() ) + return; + if( Detail::startsWith( optName, "--" ) ) { + if( !arg.longName.empty() ) + throw std::logic_error( "Only one long opt may be specified. '" + + arg.longName + + "' already specified, now attempting to add '" + + optName + "'" ); + arg.longName = optName.substr( 2 ); + } + else if( Detail::startsWith( optName, "-" ) ) + arg.shortNames.push_back( optName.substr( 1 ) ); + else + throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" ); + } + friend void setPositionalArg( Arg& arg, int position ) + { + arg.position = position; + } + + class ArgBuilder { + public: + ArgBuilder( Arg* arg ) : m_arg( arg ) {} + + // Bind a non-boolean data member (requires placeholder string) + template + void bind( M C::* field, std::string const& placeholder ) { + m_arg->boundField = new Detail::BoundDataMember( field ); + m_arg->placeholder = placeholder; + } + // Bind a boolean data member (no placeholder required) + template + void bind( bool C::* field ) { + m_arg->boundField = new Detail::BoundDataMember( field ); + } + + // Bind a method taking a single, non-boolean argument (requires a placeholder string) + template + void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) { + m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); + m_arg->placeholder = placeholder; + } + + // Bind a method taking a single, boolean argument (no placeholder string required) + template + void bind( void (C::* unaryMethod)( bool ) ) { + m_arg->boundField = new Detail::BoundUnaryMethod( unaryMethod ); + } + + // Bind a method that takes no arguments (will be called if opt is present) + template + void bind( void (C::* nullaryMethod)() ) { + m_arg->boundField = new Detail::BoundNullaryMethod( nullaryMethod ); + } + + // Bind a free function taking a single argument - the object to operate on (no placeholder string required) + template + void bind( void (* unaryFunction)( C& ) ) { + m_arg->boundField = new Detail::BoundUnaryFunction( unaryFunction ); + } + + // Bind a free function taking a single argument - the object to operate on (requires a placeholder string) + template + void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) { + m_arg->boundField = new Detail::BoundBinaryFunction( binaryFunction ); + m_arg->placeholder = placeholder; + } + + ArgBuilder& describe( std::string const& description ) { + m_arg->description = description; + return *this; + } + ArgBuilder& detail( std::string const& detail ) { + m_arg->detail = detail; + return *this; + } + + protected: + Arg* m_arg; + }; + + class OptBuilder : public ArgBuilder { + public: + OptBuilder( Arg* arg ) : ArgBuilder( arg ) {} + OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {} + + OptBuilder& operator[]( std::string const& optName ) { + addOptName( *ArgBuilder::m_arg, optName ); + return *this; + } + }; + + public: + + CommandLine() + : m_boundProcessName( new Detail::NullBinder() ), + m_highestSpecifiedArgPosition( 0 ), + m_throwOnUnrecognisedTokens( false ) + {} + CommandLine( CommandLine const& other ) + : m_boundProcessName( other.m_boundProcessName ), + m_options ( other.m_options ), + m_positionalArgs( other.m_positionalArgs ), + m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), + m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) + { + if( other.m_floatingArg.get() ) + m_floatingArg.reset( new Arg( *other.m_floatingArg ) ); + } + + CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { + m_throwOnUnrecognisedTokens = shouldThrow; + return *this; + } + + OptBuilder operator[]( std::string const& optName ) { + m_options.push_back( Arg() ); + addOptName( m_options.back(), optName ); + OptBuilder builder( &m_options.back() ); + return builder; + } + + ArgBuilder operator[]( int position ) { + m_positionalArgs.insert( std::make_pair( position, Arg() ) ); + if( position > m_highestSpecifiedArgPosition ) + m_highestSpecifiedArgPosition = position; + setPositionalArg( m_positionalArgs[position], position ); + ArgBuilder builder( &m_positionalArgs[position] ); + return builder; + } + + // Invoke this with the _ instance + ArgBuilder operator[]( UnpositionalTag ) { + if( m_floatingArg.get() ) + throw std::logic_error( "Only one unpositional argument can be added" ); + m_floatingArg.reset( new Arg() ); + ArgBuilder builder( m_floatingArg.get() ); + return builder; + } + + template + void bindProcessName( M C::* field ) { + m_boundProcessName = new Detail::BoundDataMember( field ); + } + template + void bindProcessName( void (C::*_unaryMethod)( M ) ) { + m_boundProcessName = new Detail::BoundUnaryMethod( _unaryMethod ); + } + + void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { + typename std::vector::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; + std::size_t maxWidth = 0; + for( it = itBegin; it != itEnd; ++it ) + maxWidth = (std::max)( maxWidth, it->commands().size() ); + + for( it = itBegin; it != itEnd; ++it ) { + Detail::Text usage( it->commands(), Detail::TextAttributes() + .setWidth( maxWidth+indent ) + .setIndent( indent ) ); + Detail::Text desc( it->description, Detail::TextAttributes() + .setWidth( width - maxWidth - 3 ) ); + + for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { + std::string usageCol = i < usage.size() ? usage[i] : ""; + os << usageCol; + + if( i < desc.size() && !desc[i].empty() ) + os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' ) + << desc[i]; + os << "\n"; + } + } + } + std::string optUsage() const { + std::ostringstream oss; + optUsage( oss ); + return oss.str(); + } + + void argSynopsis( std::ostream& os ) const { + for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) { + if( i > 1 ) + os << " "; + typename std::map::const_iterator it = m_positionalArgs.find( i ); + if( it != m_positionalArgs.end() ) + os << "<" << it->second.placeholder << ">"; + else if( m_floatingArg.get() ) + os << "<" << m_floatingArg->placeholder << ">"; + else + throw std::logic_error( "non consecutive positional arguments with no floating args" ); + } + // !TBD No indication of mandatory args + if( m_floatingArg.get() ) { + if( m_highestSpecifiedArgPosition > 1 ) + os << " "; + os << "[<" << m_floatingArg->placeholder << "> ...]"; + } + } + std::string argSynopsis() const { + std::ostringstream oss; + argSynopsis( oss ); + return oss.str(); + } + + void usage( std::ostream& os, std::string const& procName ) const { + validate(); + os << "usage:\n " << procName << " "; + argSynopsis( os ); + if( !m_options.empty() ) { + os << " [options]\n\nwhere options are: \n"; + optUsage( os, 2 ); + } + os << "\n"; + } + std::string usage( std::string const& procName ) const { + std::ostringstream oss; + usage( oss, procName ); + return oss.str(); + } + + ConfigT parse( std::vector const& args ) const { + ConfigT config; + parseInto( args, config ); + return config; + } + + std::vector parseInto( std::vector const& args, ConfigT& config ) const { + std::string processName = args.empty() ? std::string() : args[0]; + std::size_t lastSlash = processName.find_last_of( "/\\" ); + if( lastSlash != std::string::npos ) + processName = processName.substr( lastSlash+1 ); + m_boundProcessName.set( config, processName ); + std::vector tokens; + Parser parser; + parser.parseIntoTokens( args, tokens ); + return populate( tokens, config ); + } + + std::vector populate( std::vector const& tokens, ConfigT& config ) const { + validate(); + std::vector unusedTokens = populateOptions( tokens, config ); + unusedTokens = populateFixedArgs( unusedTokens, config ); + unusedTokens = populateFloatingArgs( unusedTokens, config ); + return unusedTokens; + } + + std::vector populateOptions( std::vector const& tokens, ConfigT& config ) const { + std::vector unusedTokens; + std::vector errors; + for( std::size_t i = 0; i < tokens.size(); ++i ) { + Parser::Token const& token = tokens[i]; + typename std::vector::const_iterator it = m_options.begin(), itEnd = m_options.end(); + for(; it != itEnd; ++it ) { + Arg const& arg = *it; + + try { + if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) || + ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { + if( arg.takesArg() ) { + if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) + errors.push_back( "Expected argument to option: " + token.data ); + else + arg.boundField.set( config, tokens[++i].data ); + } + else { + arg.boundField.set( config, "true" ); + } + break; + } + } + catch( std::exception& ex ) { + errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); + } + } + if( it == itEnd ) { + if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) + unusedTokens.push_back( token ); + else if( errors.empty() && m_throwOnUnrecognisedTokens ) + errors.push_back( "unrecognised option: " + token.data ); + } + } + if( !errors.empty() ) { + std::ostringstream oss; + for( std::vector::const_iterator it = errors.begin(), itEnd = errors.end(); + it != itEnd; + ++it ) { + if( it != errors.begin() ) + oss << "\n"; + oss << *it; + } + throw std::runtime_error( oss.str() ); + } + return unusedTokens; + } + std::vector populateFixedArgs( std::vector const& tokens, ConfigT& config ) const { + std::vector unusedTokens; + int position = 1; + for( std::size_t i = 0; i < tokens.size(); ++i ) { + Parser::Token const& token = tokens[i]; + typename std::map::const_iterator it = m_positionalArgs.find( position ); + if( it != m_positionalArgs.end() ) + it->second.boundField.set( config, token.data ); + else + unusedTokens.push_back( token ); + if( token.type == Parser::Token::Positional ) + position++; + } + return unusedTokens; + } + std::vector populateFloatingArgs( std::vector const& tokens, ConfigT& config ) const { + if( !m_floatingArg.get() ) + return tokens; + std::vector unusedTokens; + for( std::size_t i = 0; i < tokens.size(); ++i ) { + Parser::Token const& token = tokens[i]; + if( token.type == Parser::Token::Positional ) + m_floatingArg->boundField.set( config, token.data ); + else + unusedTokens.push_back( token ); + } + return unusedTokens; + } + + void validate() const + { + if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() ) + throw std::logic_error( "No options or arguments specified" ); + + for( typename std::vector::const_iterator it = m_options.begin(), + itEnd = m_options.end(); + it != itEnd; ++it ) + it->validate(); + } + + private: + Detail::BoundArgFunction m_boundProcessName; + std::vector m_options; + std::map m_positionalArgs; + ArgAutoPtr m_floatingArg; + int m_highestSpecifiedArgPosition; + bool m_throwOnUnrecognisedTokens; + }; + +} // end namespace Clara + +STITCH_CLARA_CLOSE_NAMESPACE +#undef STITCH_CLARA_OPEN_NAMESPACE +#undef STITCH_CLARA_CLOSE_NAMESPACE + +#endif // TWOBLUECUBES_CLARA_H_INCLUDED +#undef STITCH_CLARA_OPEN_NAMESPACE + +// Restore Clara's value for console width, if present +#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#endif + +#include +#include + +namespace Catch { + + inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; } + inline void abortAfterX( ConfigData& config, int x ) { + if( x < 1 ) + throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" ); + config.abortAfter = x; + } + inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); } + inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); } + inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); } + + inline void addWarning( ConfigData& config, std::string const& _warning ) { + if( _warning == "NoAssertions" ) + config.warnings = static_cast( config.warnings | WarnAbout::NoAssertions ); + else + throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' ); + } + inline void setOrder( ConfigData& config, std::string const& order ) { + if( startsWith( "declared", order ) ) + config.runOrder = RunTests::InDeclarationOrder; + else if( startsWith( "lexical", order ) ) + config.runOrder = RunTests::InLexicographicalOrder; + else if( startsWith( "random", order ) ) + config.runOrder = RunTests::InRandomOrder; + else + throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' ); + } + inline void setRngSeed( ConfigData& config, std::string const& seed ) { + if( seed == "time" ) { + config.rngSeed = static_cast( std::time(0) ); + } + else { + std::stringstream ss; + ss << seed; + ss >> config.rngSeed; + if( ss.fail() ) + throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" ); + } + } + inline void setVerbosity( ConfigData& config, int level ) { + // !TBD: accept strings? + config.verbosity = static_cast( level ); + } + inline void setShowDurations( ConfigData& config, bool _showDurations ) { + config.showDurations = _showDurations + ? ShowDurations::Always + : ShowDurations::Never; + } + inline void setUseColour( ConfigData& config, std::string const& value ) { + std::string mode = toLower( value ); + + if( mode == "yes" ) + config.useColour = UseColour::Yes; + else if( mode == "no" ) + config.useColour = UseColour::No; + else if( mode == "auto" ) + config.useColour = UseColour::Auto; + else + throw std::runtime_error( "colour mode must be one of: auto, yes or no" ); + } + inline void forceColour( ConfigData& config ) { + config.useColour = UseColour::Yes; + } + inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) { + std::ifstream f( _filename.c_str() ); + if( !f.is_open() ) + throw std::domain_error( "Unable to load input file: " + _filename ); + + std::string line; + while( std::getline( f, line ) ) { + line = trim(line); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + addTestOrTags( config, line + ',' ); + } + } + } + + inline Clara::CommandLine makeCommandLineParser() { + + using namespace Clara; + CommandLine cli; + + cli.bindProcessName( &ConfigData::processName ); + + cli["-?"]["-h"]["--help"] + .describe( "display usage information" ) + .bind( &ConfigData::showHelp ); + + cli["-l"]["--list-tests"] + .describe( "list all/matching test cases" ) + .bind( &ConfigData::listTests ); + + cli["-t"]["--list-tags"] + .describe( "list all/matching tags" ) + .bind( &ConfigData::listTags ); + + cli["-s"]["--success"] + .describe( "include successful tests in output" ) + .bind( &ConfigData::showSuccessfulTests ); + + cli["-b"]["--break"] + .describe( "break into debugger on failure" ) + .bind( &ConfigData::shouldDebugBreak ); + + cli["-e"]["--nothrow"] + .describe( "skip exception tests" ) + .bind( &ConfigData::noThrow ); + + cli["-i"]["--invisibles"] + .describe( "show invisibles (tabs, newlines)" ) + .bind( &ConfigData::showInvisibles ); + + cli["-o"]["--out"] + .describe( "output filename" ) + .bind( &ConfigData::outputFilename, "filename" ); + + cli["-r"]["--reporter"] +// .placeholder( "name[:filename]" ) + .describe( "reporter to use (defaults to console)" ) + .bind( &addReporterName, "name" ); + + cli["-n"]["--name"] + .describe( "suite name" ) + .bind( &ConfigData::name, "name" ); + + cli["-a"]["--abort"] + .describe( "abort at first failure" ) + .bind( &abortAfterFirst ); + + cli["-x"]["--abortx"] + .describe( "abort after x failures" ) + .bind( &abortAfterX, "no. failures" ); + + cli["-w"]["--warn"] + .describe( "enable warnings" ) + .bind( &addWarning, "warning name" ); + +// - needs updating if reinstated +// cli.into( &setVerbosity ) +// .describe( "level of verbosity (0=no output)" ) +// .shortOpt( "v") +// .longOpt( "verbosity" ) +// .placeholder( "level" ); + + cli[_] + .describe( "which test or tests to use" ) + .bind( &addTestOrTags, "test name, pattern or tags" ); + + cli["-d"]["--durations"] + .describe( "show test durations" ) + .bind( &setShowDurations, "yes|no" ); + + cli["-f"]["--input-file"] + .describe( "load test names to run from a file" ) + .bind( &loadTestNamesFromFile, "filename" ); + + cli["-#"]["--filenames-as-tags"] + .describe( "adds a tag for the filename" ) + .bind( &ConfigData::filenamesAsTags ); + + cli["-c"]["--section"] + .describe( "specify section to run" ) + .bind( &addSectionToRun, "section name" ); + + // Less common commands which don't have a short form + cli["--list-test-names-only"] + .describe( "list all/matching test cases names only" ) + .bind( &ConfigData::listTestNamesOnly ); + + cli["--list-reporters"] + .describe( "list all reporters" ) + .bind( &ConfigData::listReporters ); + + cli["--order"] + .describe( "test case order (defaults to decl)" ) + .bind( &setOrder, "decl|lex|rand" ); + + cli["--rng-seed"] + .describe( "set a specific seed for random numbers" ) + .bind( &setRngSeed, "'time'|number" ); + + cli["--force-colour"] + .describe( "force colourised output (deprecated)" ) + .bind( &forceColour ); + + cli["--use-colour"] + .describe( "should output be colourised" ) + .bind( &setUseColour, "yes|no" ); + + return cli; + } + +} // end namespace Catch + +// #included from: internal/catch_list.hpp +#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED + +// #included from: catch_text.h +#define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED + +#define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH + +#define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch +// #included from: ../external/tbc_text_format.h +// Only use header guard if we are not using an outer namespace +#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +# endif +# else +# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED +# endif +#endif +#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#include +#include +#include + +// Use optional outer namespace +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { +#endif + +namespace Tbc { + +#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH + const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; +#else + const unsigned int consoleWidth = 80; +#endif + + struct TextAttributes { + TextAttributes() + : initialIndent( std::string::npos ), + indent( 0 ), + width( consoleWidth-1 ) + {} + + TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } + TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } + TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } + + std::size_t initialIndent; // indent of first line, or npos + std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos + std::size_t width; // maximum width of text, including indent. Longer text will wrap + }; + + class Text { + public: + Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) + : attr( _attr ) + { + const std::string wrappableBeforeChars = "[({<\t"; + const std::string wrappableAfterChars = "])}>-,./|\\"; + const std::string wrappableInsteadOfChars = " \n\r"; + std::string indent = _attr.initialIndent != std::string::npos + ? std::string( _attr.initialIndent, ' ' ) + : std::string( _attr.indent, ' ' ); + + typedef std::string::const_iterator iterator; + iterator it = _str.begin(); + const iterator strEnd = _str.end(); + + while( it != strEnd ) { + + if( lines.size() >= 1000 ) { + lines.push_back( "... message truncated due to excessive size" ); + return; + } + + std::string suffix; + std::size_t width = (std::min)( static_cast( strEnd-it ), _attr.width-static_cast( indent.size() ) ); + iterator itEnd = it+width; + iterator itNext = _str.end(); + + iterator itNewLine = std::find( it, itEnd, '\n' ); + if( itNewLine != itEnd ) + itEnd = itNewLine; + + if( itEnd != strEnd ) { + bool foundWrapPoint = false; + iterator findIt = itEnd; + do { + if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) { + itEnd = findIt+1; + itNext = findIt+1; + foundWrapPoint = true; + } + else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) { + itEnd = findIt; + itNext = findIt; + foundWrapPoint = true; + } + else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) { + itNext = findIt+1; + itEnd = findIt; + foundWrapPoint = true; + } + if( findIt == it ) + break; + else + --findIt; + } + while( !foundWrapPoint ); + + if( !foundWrapPoint ) { + // No good wrap char, so we'll break mid word and add a hyphen + --itEnd; + itNext = itEnd; + suffix = "-"; + } + else { + while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos ) + --itEnd; + } + } + lines.push_back( indent + std::string( it, itEnd ) + suffix ); + + if( indent.size() != _attr.indent ) + indent = std::string( _attr.indent, ' ' ); + it = itNext; + } + } + + typedef std::vector::const_iterator const_iterator; + + const_iterator begin() const { return lines.begin(); } + const_iterator end() const { return lines.end(); } + std::string const& last() const { return lines.back(); } + std::size_t size() const { return lines.size(); } + std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } + std::string toString() const { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + + inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { + for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); + it != itEnd; ++it ) { + if( it != _text.begin() ) + _stream << "\n"; + _stream << *it; + } + return _stream; + } + + private: + std::string str; + TextAttributes attr; + std::vector lines; + }; + +} // end namespace Tbc + +#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE +} // end outer namespace +#endif + +#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED +#undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE + +namespace Catch { + using Tbc::Text; + using Tbc::TextAttributes; +} + +// #included from: catch_console_colour.hpp +#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED + +namespace Catch { + + struct Colour { + enum Code { + None = 0, + + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, + + Bright = 0x10, + + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White, + + // By intention + FileName = LightGrey, + Warning = Yellow, + ResultError = BrightRed, + ResultSuccess = BrightGreen, + ResultExpectedFailure = Warning, + + Error = BrightRed, + Success = Green, + + OriginalExpression = Cyan, + ReconstructedExpression = Yellow, + + SecondaryText = LightGrey, + Headers = White + }; + + // Use constructed object for RAII guard + Colour( Code _colourCode ); + Colour( Colour const& other ); + ~Colour(); + + // Use static method for one-shot changes + static void use( Code _colourCode ); + + private: + bool m_moved; + }; + + inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; } + +} // end namespace Catch + +// #included from: catch_interfaces_reporter.h +#define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED + +#include +#include +#include + +namespace Catch +{ + struct ReporterConfig { + explicit ReporterConfig( Ptr const& _fullConfig ) + : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} + + ReporterConfig( Ptr const& _fullConfig, std::ostream& _stream ) + : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} + + std::ostream& stream() const { return *m_stream; } + Ptr fullConfig() const { return m_fullConfig; } + + private: + std::ostream* m_stream; + Ptr m_fullConfig; + }; + + struct ReporterPreferences { + ReporterPreferences() + : shouldRedirectStdOut( false ) + {} + + bool shouldRedirectStdOut; + }; + + template + struct LazyStat : Option { + LazyStat() : used( false ) {} + LazyStat& operator=( T const& _value ) { + Option::operator=( _value ); + used = false; + return *this; + } + void reset() { + Option::reset(); + used = false; + } + bool used; + }; + + struct TestRunInfo { + TestRunInfo( std::string const& _name ) : name( _name ) {} + std::string name; + }; + struct GroupInfo { + GroupInfo( std::string const& _name, + std::size_t _groupIndex, + std::size_t _groupsCount ) + : name( _name ), + groupIndex( _groupIndex ), + groupsCounts( _groupsCount ) + {} + + std::string name; + std::size_t groupIndex; + std::size_t groupsCounts; + }; + + struct AssertionStats { + AssertionStats( AssertionResult const& _assertionResult, + std::vector const& _infoMessages, + Totals const& _totals ) + : assertionResult( _assertionResult ), + infoMessages( _infoMessages ), + totals( _totals ) + { + if( assertionResult.hasMessage() ) { + // Copy message into messages list. + // !TBD This should have been done earlier, somewhere + MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); + builder << assertionResult.getMessage(); + builder.m_info.message = builder.m_stream.str(); + + infoMessages.push_back( builder.m_info ); + } + } + virtual ~AssertionStats(); + +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + AssertionStats( AssertionStats const& ) = default; + AssertionStats( AssertionStats && ) = default; + AssertionStats& operator = ( AssertionStats const& ) = default; + AssertionStats& operator = ( AssertionStats && ) = default; +# endif + + AssertionResult assertionResult; + std::vector infoMessages; + Totals totals; + }; + + struct SectionStats { + SectionStats( SectionInfo const& _sectionInfo, + Counts const& _assertions, + double _durationInSeconds, + bool _missingAssertions ) + : sectionInfo( _sectionInfo ), + assertions( _assertions ), + durationInSeconds( _durationInSeconds ), + missingAssertions( _missingAssertions ) + {} + virtual ~SectionStats(); +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + SectionStats( SectionStats const& ) = default; + SectionStats( SectionStats && ) = default; + SectionStats& operator = ( SectionStats const& ) = default; + SectionStats& operator = ( SectionStats && ) = default; +# endif + + SectionInfo sectionInfo; + Counts assertions; + double durationInSeconds; + bool missingAssertions; + }; + + struct TestCaseStats { + TestCaseStats( TestCaseInfo const& _testInfo, + Totals const& _totals, + std::string const& _stdOut, + std::string const& _stdErr, + bool _aborting ) + : testInfo( _testInfo ), + totals( _totals ), + stdOut( _stdOut ), + stdErr( _stdErr ), + aborting( _aborting ) + {} + virtual ~TestCaseStats(); + +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + TestCaseStats( TestCaseStats const& ) = default; + TestCaseStats( TestCaseStats && ) = default; + TestCaseStats& operator = ( TestCaseStats const& ) = default; + TestCaseStats& operator = ( TestCaseStats && ) = default; +# endif + + TestCaseInfo testInfo; + Totals totals; + std::string stdOut; + std::string stdErr; + bool aborting; + }; + + struct TestGroupStats { + TestGroupStats( GroupInfo const& _groupInfo, + Totals const& _totals, + bool _aborting ) + : groupInfo( _groupInfo ), + totals( _totals ), + aborting( _aborting ) + {} + TestGroupStats( GroupInfo const& _groupInfo ) + : groupInfo( _groupInfo ), + aborting( false ) + {} + virtual ~TestGroupStats(); + +# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + TestGroupStats( TestGroupStats const& ) = default; + TestGroupStats( TestGroupStats && ) = default; + TestGroupStats& operator = ( TestGroupStats const& ) = default; + TestGroupStats& operator = ( TestGroupStats && ) = default; +# endif + + GroupInfo groupInfo; + Totals totals; + bool aborting; + }; + + struct TestRunStats { + TestRunStats( TestRunInfo const& _runInfo, + Totals const& _totals, + bool _aborting ) + : runInfo( _runInfo ), + totals( _totals ), + aborting( _aborting ) + {} + virtual ~TestRunStats(); + +# ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS + TestRunStats( TestRunStats const& _other ) + : runInfo( _other.runInfo ), + totals( _other.totals ), + aborting( _other.aborting ) + {} +# else + TestRunStats( TestRunStats const& ) = default; + TestRunStats( TestRunStats && ) = default; + TestRunStats& operator = ( TestRunStats const& ) = default; + TestRunStats& operator = ( TestRunStats && ) = default; +# endif + + TestRunInfo runInfo; + Totals totals; + bool aborting; + }; + + class MultipleReporters; + + struct IStreamingReporter : IShared { + virtual ~IStreamingReporter(); + + // Implementing class must also provide the following static method: + // static std::string getDescription(); + + virtual ReporterPreferences getPreferences() const = 0; + + virtual void noMatchingTestCases( std::string const& spec ) = 0; + + virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; + virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; + virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; + + virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; + + // The return value indicates if the messages buffer should be cleared: + virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; + + virtual void sectionEnded( SectionStats const& sectionStats ) = 0; + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; + virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; + + virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + + virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; } + }; + + struct IReporterFactory : IShared { + virtual ~IReporterFactory(); + virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0; + virtual std::string getDescription() const = 0; + }; + + struct IReporterRegistry { + typedef std::map > FactoryMap; + typedef std::vector > Listeners; + + virtual ~IReporterRegistry(); + virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const = 0; + virtual FactoryMap const& getFactories() const = 0; + virtual Listeners const& getListeners() const = 0; + }; + + Ptr addReporter( Ptr const& existingReporter, Ptr const& additionalReporter ); + +} + +#include +#include + +namespace Catch { + + inline std::size_t listTests( Config const& config ) { + + TestSpec testSpec = config.testSpec(); + if( config.testSpec().hasFilters() ) + Catch::cout() << "Matching test cases:\n"; + else { + Catch::cout() << "All available test cases:\n"; + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + } + + std::size_t matchedTests = 0; + TextAttributes nameAttr, tagsAttr; + nameAttr.setInitialIndent( 2 ).setIndent( 4 ); + tagsAttr.setIndent( 6 ); + + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); + it != itEnd; + ++it ) { + matchedTests++; + TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); + Colour::Code colour = testCaseInfo.isHidden() + ? Colour::SecondaryText + : Colour::None; + Colour colourGuard( colour ); + + Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; + if( !testCaseInfo.tags.empty() ) + Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; + } + + if( !config.testSpec().hasFilters() ) + Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl; + else + Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl; + return matchedTests; + } + + inline std::size_t listTestsNamesOnly( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( !config.testSpec().hasFilters() ) + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + std::size_t matchedTests = 0; + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); + it != itEnd; + ++it ) { + matchedTests++; + TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); + if( startsWith( testCaseInfo.name, '#' ) ) + Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl; + else + Catch::cout() << testCaseInfo.name << std::endl; + } + return matchedTests; + } + + struct TagInfo { + TagInfo() : count ( 0 ) {} + void add( std::string const& spelling ) { + ++count; + spellings.insert( spelling ); + } + std::string all() const { + std::string out; + for( std::set::const_iterator it = spellings.begin(), itEnd = spellings.end(); + it != itEnd; + ++it ) + out += "[" + *it + "]"; + return out; + } + std::set spellings; + std::size_t count; + }; + + inline std::size_t listTags( Config const& config ) { + TestSpec testSpec = config.testSpec(); + if( config.testSpec().hasFilters() ) + Catch::cout() << "Tags for matching test cases:\n"; + else { + Catch::cout() << "All available tags:\n"; + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); + } + + std::map tagCounts; + + std::vector matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); + for( std::vector::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); + it != itEnd; + ++it ) { + for( std::set::const_iterator tagIt = it->getTestCaseInfo().tags.begin(), + tagItEnd = it->getTestCaseInfo().tags.end(); + tagIt != tagItEnd; + ++tagIt ) { + std::string tagName = *tagIt; + std::string lcaseTagName = toLower( tagName ); + std::map::iterator countIt = tagCounts.find( lcaseTagName ); + if( countIt == tagCounts.end() ) + countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; + countIt->second.add( tagName ); + } + } + + for( std::map::const_iterator countIt = tagCounts.begin(), + countItEnd = tagCounts.end(); + countIt != countItEnd; + ++countIt ) { + std::ostringstream oss; + oss << " " << std::setw(2) << countIt->second.count << " "; + Text wrapper( countIt->second.all(), TextAttributes() + .setInitialIndent( 0 ) + .setIndent( oss.str().size() ) + .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); + Catch::cout() << oss.str() << wrapper << '\n'; + } + Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; + return tagCounts.size(); + } + + inline std::size_t listReporters( Config const& /*config*/ ) { + Catch::cout() << "Available reporters:\n"; + IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); + IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it; + std::size_t maxNameLen = 0; + for(it = itBegin; it != itEnd; ++it ) + maxNameLen = (std::max)( maxNameLen, it->first.size() ); + + for(it = itBegin; it != itEnd; ++it ) { + Text wrapper( it->second->getDescription(), TextAttributes() + .setInitialIndent( 0 ) + .setIndent( 7+maxNameLen ) + .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); + Catch::cout() << " " + << it->first + << ':' + << std::string( maxNameLen - it->first.size() + 2, ' ' ) + << wrapper << '\n'; + } + Catch::cout() << std::endl; + return factories.size(); + } + + inline Option list( Config const& config ) { + Option listedCount; + if( config.listTests() ) + listedCount = listedCount.valueOr(0) + listTests( config ); + if( config.listTestNamesOnly() ) + listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); + if( config.listTags() ) + listedCount = listedCount.valueOr(0) + listTags( config ); + if( config.listReporters() ) + listedCount = listedCount.valueOr(0) + listReporters( config ); + return listedCount; + } + +} // end namespace Catch + +// #included from: internal/catch_run_context.hpp +#define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED + +// #included from: catch_test_case_tracker.hpp +#define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED + +#include +#include +#include +#include +#include + +CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS + +namespace Catch { +namespace TestCaseTracking { + + struct NameAndLocation { + std::string name; + SourceLineInfo location; + + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) + : name( _name ), + location( _location ) + {} + }; + + struct ITracker : SharedImpl<> { + virtual ~ITracker(); + + // static queries + virtual NameAndLocation const& nameAndLocation() const = 0; + + // dynamic queries + virtual bool isComplete() const = 0; // Successfully completed or failed + virtual bool isSuccessfullyCompleted() const = 0; + virtual bool isOpen() const = 0; // Started but not complete + virtual bool hasChildren() const = 0; + + virtual ITracker& parent() = 0; + + // actions + virtual void close() = 0; // Successfully complete + virtual void fail() = 0; + virtual void markAsNeedingAnotherRun() = 0; + + virtual void addChild( Ptr const& child ) = 0; + virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0; + virtual void openChild() = 0; + + // Debug/ checking + virtual bool isSectionTracker() const = 0; + virtual bool isIndexTracker() const = 0; + }; + + class TrackerContext { + + enum RunState { + NotStarted, + Executing, + CompletedCycle + }; + + Ptr m_rootTracker; + ITracker* m_currentTracker; + RunState m_runState; + + public: + + static TrackerContext& instance() { + static TrackerContext s_instance; + return s_instance; + } + + TrackerContext() + : m_currentTracker( CATCH_NULL ), + m_runState( NotStarted ) + {} + + ITracker& startRun(); + + void endRun() { + m_rootTracker.reset(); + m_currentTracker = CATCH_NULL; + m_runState = NotStarted; + } + + void startCycle() { + m_currentTracker = m_rootTracker.get(); + m_runState = Executing; + } + void completeCycle() { + m_runState = CompletedCycle; + } + + bool completedCycle() const { + return m_runState == CompletedCycle; + } + ITracker& currentTracker() { + return *m_currentTracker; + } + void setCurrentTracker( ITracker* tracker ) { + m_currentTracker = tracker; + } + }; + + class TrackerBase : public ITracker { + protected: + enum CycleState { + NotStarted, + Executing, + ExecutingChildren, + NeedsAnotherRun, + CompletedSuccessfully, + Failed + }; + class TrackerHasName { + NameAndLocation m_nameAndLocation; + public: + TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} + bool operator ()( Ptr const& tracker ) { + return + tracker->nameAndLocation().name == m_nameAndLocation.name && + tracker->nameAndLocation().location == m_nameAndLocation.location; + } + }; + typedef std::vector > Children; + NameAndLocation m_nameAndLocation; + TrackerContext& m_ctx; + ITracker* m_parent; + Children m_children; + CycleState m_runState; + public: + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : m_nameAndLocation( nameAndLocation ), + m_ctx( ctx ), + m_parent( parent ), + m_runState( NotStarted ) + {} + virtual ~TrackerBase(); + + virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE { + return m_nameAndLocation; + } + virtual bool isComplete() const CATCH_OVERRIDE { + return m_runState == CompletedSuccessfully || m_runState == Failed; + } + virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE { + return m_runState == CompletedSuccessfully; + } + virtual bool isOpen() const CATCH_OVERRIDE { + return m_runState != NotStarted && !isComplete(); + } + virtual bool hasChildren() const CATCH_OVERRIDE { + return !m_children.empty(); + } + + virtual void addChild( Ptr const& child ) CATCH_OVERRIDE { + m_children.push_back( child ); + } + + virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE { + Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) ); + return( it != m_children.end() ) + ? it->get() + : CATCH_NULL; + } + virtual ITracker& parent() CATCH_OVERRIDE { + assert( m_parent ); // Should always be non-null except for root + return *m_parent; + } + + virtual void openChild() CATCH_OVERRIDE { + if( m_runState != ExecutingChildren ) { + m_runState = ExecutingChildren; + if( m_parent ) + m_parent->openChild(); + } + } + + virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; } + virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; } + + void open() { + m_runState = Executing; + moveToThis(); + if( m_parent ) + m_parent->openChild(); + } + + virtual void close() CATCH_OVERRIDE { + + // Close any still open children (e.g. generators) + while( &m_ctx.currentTracker() != this ) + m_ctx.currentTracker().close(); + + switch( m_runState ) { + case NotStarted: + case CompletedSuccessfully: + case Failed: + throw std::logic_error( "Illogical state" ); + + case NeedsAnotherRun: + break;; + + case Executing: + m_runState = CompletedSuccessfully; + break; + case ExecutingChildren: + if( m_children.empty() || m_children.back()->isComplete() ) + m_runState = CompletedSuccessfully; + break; + + default: + throw std::logic_error( "Unexpected state" ); + } + moveToParent(); + m_ctx.completeCycle(); + } + virtual void fail() CATCH_OVERRIDE { + m_runState = Failed; + if( m_parent ) + m_parent->markAsNeedingAnotherRun(); + moveToParent(); + m_ctx.completeCycle(); + } + virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE { + m_runState = NeedsAnotherRun; + } + private: + void moveToParent() { + assert( m_parent ); + m_ctx.setCurrentTracker( m_parent ); + } + void moveToThis() { + m_ctx.setCurrentTracker( this ); + } + }; + + class SectionTracker : public TrackerBase { + std::vector m_filters; + public: + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ) + { + if( parent ) { + while( !parent->isSectionTracker() ) + parent = &parent->parent(); + + SectionTracker& parentSection = static_cast( *parent ); + addNextFilters( parentSection.m_filters ); + } + } + virtual ~SectionTracker(); + + virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; } + + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { + SectionTracker* section = CATCH_NULL; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isSectionTracker() ); + section = static_cast( childTracker ); + } + else { + section = new SectionTracker( nameAndLocation, ctx, ¤tTracker ); + currentTracker.addChild( section ); + } + if( !ctx.completedCycle() ) + section->tryOpen(); + return *section; + } + + void tryOpen() { + if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) + open(); + } + + void addInitialFilters( std::vector const& filters ) { + if( !filters.empty() ) { + m_filters.push_back(""); // Root - should never be consulted + m_filters.push_back(""); // Test Case - not a section filter + m_filters.insert( m_filters.end(), filters.begin(), filters.end() ); + } + } + void addNextFilters( std::vector const& filters ) { + if( filters.size() > 1 ) + m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() ); + } + }; + + class IndexTracker : public TrackerBase { + int m_size; + int m_index; + public: + IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ) + : TrackerBase( nameAndLocation, ctx, parent ), + m_size( size ), + m_index( -1 ) + {} + virtual ~IndexTracker(); + + virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; } + + static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) { + IndexTracker* tracker = CATCH_NULL; + + ITracker& currentTracker = ctx.currentTracker(); + if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) { + assert( childTracker ); + assert( childTracker->isIndexTracker() ); + tracker = static_cast( childTracker ); + } + else { + tracker = new IndexTracker( nameAndLocation, ctx, ¤tTracker, size ); + currentTracker.addChild( tracker ); + } + + if( !ctx.completedCycle() && !tracker->isComplete() ) { + if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun ) + tracker->moveNext(); + tracker->open(); + } + + return *tracker; + } + + int index() const { return m_index; } + + void moveNext() { + m_index++; + m_children.clear(); + } + + virtual void close() CATCH_OVERRIDE { + TrackerBase::close(); + if( m_runState == CompletedSuccessfully && m_index < m_size-1 ) + m_runState = Executing; + } + }; + + inline ITracker& TrackerContext::startRun() { + m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL ); + m_currentTracker = CATCH_NULL; + m_runState = Executing; + return *m_rootTracker; + } + +} // namespace TestCaseTracking + +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; + +} // namespace Catch + +CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + +// #included from: catch_fatal_condition.hpp +#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED + +namespace Catch { + + // Report the error condition + inline void reportFatal( std::string const& message ) { + IContext& context = Catch::getCurrentContext(); + IResultCapture* resultCapture = context.getResultCapture(); + resultCapture->handleFatalErrorCondition( message ); + } + +} // namespace Catch + +#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// +// #included from: catch_windows_h_proxy.h + +#define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED + +#ifdef CATCH_DEFINES_NOMINMAX +# define NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include +#else +#include +#endif + +#ifdef CATCH_DEFINES_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + + +# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + struct FatalConditionHandler { + void reset() {} + }; +} + +# else // CATCH_CONFIG_WINDOWS_SEH is defined + +namespace Catch { + + struct SignalDefs { DWORD id; const char* name; }; + extern SignalDefs signalDefs[]; + // There is no 1-1 mapping between signals and windows exceptions. + // Windows can easily distinguish between SO and SigSegV, + // but SigInt, SigTerm, etc are handled differently. + SignalDefs signalDefs[] = { + { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, + { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, + { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, + { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, + }; + + struct FatalConditionHandler { + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) { + reportFatal(signalDefs[i].name); + } + } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } + + FatalConditionHandler() { + isSet = true; + // 32k seems enough for Catch to handle stack overflow, + // but the value was found experimentally, so there is no strong guarantee + guaranteeSize = 32 * 1024; + exceptionHandlerHandle = CATCH_NULL; + // Register as first handler in current chain + exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); + // Pass in guarantee size to be filled + SetThreadStackGuarantee(&guaranteeSize); + } + + static void reset() { + if (isSet) { + // Unregister handler and restore the old guarantee + RemoveVectoredExceptionHandler(exceptionHandlerHandle); + SetThreadStackGuarantee(&guaranteeSize); + exceptionHandlerHandle = CATCH_NULL; + isSet = false; + } + } + + ~FatalConditionHandler() { + reset(); + } + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; + }; + + bool FatalConditionHandler::isSet = false; + ULONG FatalConditionHandler::guaranteeSize = 0; + PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL; + +} // namespace Catch + +# endif // CATCH_CONFIG_WINDOWS_SEH + +#else // Not Windows - assumed to be POSIX compatible ////////////////////////// + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) + +namespace Catch { + struct FatalConditionHandler { + void reset() {} + }; +} + +# else // CATCH_CONFIG_POSIX_SIGNALS is defined + +#include + +namespace Catch { + + struct SignalDefs { + int id; + const char* name; + }; + extern SignalDefs signalDefs[]; + SignalDefs signalDefs[] = { + { SIGINT, "SIGINT - Terminal interrupt signal" }, + { SIGILL, "SIGILL - Illegal instruction signal" }, + { SIGFPE, "SIGFPE - Floating point error signal" }, + { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, + { SIGTERM, "SIGTERM - Termination request signal" }, + { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } + }; + + struct FatalConditionHandler { + + static bool isSet; + static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)]; + static stack_t oldSigStack; + static char altStackMem[SIGSTKSZ]; + + static void handleSignal( int sig ) { + std::string name = ""; + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + SignalDefs &def = signalDefs[i]; + if (sig == def.id) { + name = def.name; + break; + } + } + reset(); + reportFatal(name); + raise( sig ); + } + + FatalConditionHandler() { + isSet = true; + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = SIGSTKSZ; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = { 0 }; + + sa.sa_handler = handleSignal; + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); + } + } + + ~FatalConditionHandler() { + reset(); + } + static void reset() { + if( isSet ) { + // Set signals back to previous values -- hopefully nobody overwrote them in the meantime + for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { + sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL); + } + // Return the old stack + sigaltstack(&oldSigStack, CATCH_NULL); + isSet = false; + } + } + }; + + bool FatalConditionHandler::isSet = false; + struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; + stack_t FatalConditionHandler::oldSigStack = {}; + char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; + +} // namespace Catch + +# endif // CATCH_CONFIG_POSIX_SIGNALS + +#endif // not Windows + +#include +#include + +namespace Catch { + + class StreamRedirect { + + public: + StreamRedirect( std::ostream& stream, std::string& targetString ) + : m_stream( stream ), + m_prevBuf( stream.rdbuf() ), + m_targetString( targetString ) + { + stream.rdbuf( m_oss.rdbuf() ); + } + + ~StreamRedirect() { + m_targetString += m_oss.str(); + m_stream.rdbuf( m_prevBuf ); + } + + private: + std::ostream& m_stream; + std::streambuf* m_prevBuf; + std::ostringstream m_oss; + std::string& m_targetString; + }; + + /////////////////////////////////////////////////////////////////////////// + + class RunContext : public IResultCapture, public IRunner { + + RunContext( RunContext const& ); + void operator =( RunContext const& ); + + public: + + explicit RunContext( Ptr const& _config, Ptr const& reporter ) + : m_runInfo( _config->name() ), + m_context( getCurrentMutableContext() ), + m_activeTestCase( CATCH_NULL ), + m_config( _config ), + m_reporter( reporter ), + m_shouldReportUnexpected ( true ) + { + m_context.setRunner( this ); + m_context.setConfig( m_config ); + m_context.setResultCapture( this ); + m_reporter->testRunStarting( m_runInfo ); + } + + virtual ~RunContext() { + m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); + } + + void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) { + m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) ); + } + void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) { + m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) ); + } + + Totals runTest( TestCase const& testCase ) { + Totals prevTotals = m_totals; + + std::string redirectedCout; + std::string redirectedCerr; + + TestCaseInfo testInfo = testCase.getTestCaseInfo(); + + m_reporter->testCaseStarting( testInfo ); + + m_activeTestCase = &testCase; + + do { + ITracker& rootTracker = m_trackerContext.startRun(); + assert( rootTracker.isSectionTracker() ); + static_cast( rootTracker ).addInitialFilters( m_config->getSectionsToRun() ); + do { + m_trackerContext.startCycle(); + m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) ); + runCurrentTest( redirectedCout, redirectedCerr ); + } + while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() ); + } + // !TBD: deprecated - this will be replaced by indexed trackers + while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); + + Totals deltaTotals = m_totals.delta( prevTotals ); + if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) { + deltaTotals.assertions.failed++; + deltaTotals.testCases.passed--; + deltaTotals.testCases.failed++; + } + m_totals.testCases += deltaTotals.testCases; + m_reporter->testCaseEnded( TestCaseStats( testInfo, + deltaTotals, + redirectedCout, + redirectedCerr, + aborting() ) ); + + m_activeTestCase = CATCH_NULL; + m_testCaseTracker = CATCH_NULL; + + return deltaTotals; + } + + Ptr config() const { + return m_config; + } + + private: // IResultCapture + + virtual void assertionEnded( AssertionResult const& result ) { + if( result.getResultType() == ResultWas::Ok ) { + m_totals.assertions.passed++; + } + else if( !result.isOk() ) { + m_totals.assertions.failed++; + } + + if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) ) + m_messages.clear(); + + // Reset working state + m_lastAssertionInfo = AssertionInfo( std::string(), m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); + m_lastResult = result; + } + + virtual bool sectionStarted ( + SectionInfo const& sectionInfo, + Counts& assertions + ) + { + ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) ); + if( !sectionTracker.isOpen() ) + return false; + m_activeSections.push_back( §ionTracker ); + + m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + + m_reporter->sectionStarting( sectionInfo ); + + assertions = m_totals.assertions; + + return true; + } + bool testForMissingAssertions( Counts& assertions ) { + if( assertions.total() != 0 ) + return false; + if( !m_config->warnAboutMissingAssertions() ) + return false; + if( m_trackerContext.currentTracker().hasChildren() ) + return false; + m_totals.assertions.failed++; + assertions.failed++; + return true; + } + + virtual void sectionEnded( SectionEndInfo const& endInfo ) { + Counts assertions = m_totals.assertions - endInfo.prevAssertions; + bool missingAssertions = testForMissingAssertions( assertions ); + + if( !m_activeSections.empty() ) { + m_activeSections.back()->close(); + m_activeSections.pop_back(); + } + + m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) ); + m_messages.clear(); + } + + virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) { + if( m_unfinishedSections.empty() ) + m_activeSections.back()->fail(); + else + m_activeSections.back()->close(); + m_activeSections.pop_back(); + + m_unfinishedSections.push_back( endInfo ); + } + + virtual void pushScopedMessage( MessageInfo const& message ) { + m_messages.push_back( message ); + } + + virtual void popScopedMessage( MessageInfo const& message ) { + m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() ); + } + + virtual std::string getCurrentTestName() const { + return m_activeTestCase + ? m_activeTestCase->getTestCaseInfo().name + : std::string(); + } + + virtual const AssertionResult* getLastResult() const { + return &m_lastResult; + } + + virtual void exceptionEarlyReported() { + m_shouldReportUnexpected = false; + } + + virtual void handleFatalErrorCondition( std::string const& message ) { + // Don't rebuild the result -- the stringification itself can cause more fatal errors + // Instead, fake a result data. + AssertionResultData tempResult; + tempResult.resultType = ResultWas::FatalErrorCondition; + tempResult.message = message; + AssertionResult result(m_lastAssertionInfo, tempResult); + + getResultCapture().assertionEnded(result); + + handleUnfinishedSections(); + + // Recreate section for test case (as we will lose the one that was in scope) + TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); + + Counts assertions; + assertions.failed = 1; + SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false ); + m_reporter->sectionEnded( testCaseSectionStats ); + + TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo(); + + Totals deltaTotals; + deltaTotals.testCases.failed = 1; + m_reporter->testCaseEnded( TestCaseStats( testInfo, + deltaTotals, + std::string(), + std::string(), + false ) ); + m_totals.testCases.failed++; + testGroupEnded( std::string(), m_totals, 1, 1 ); + m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) ); + } + + public: + // !TBD We need to do this another way! + bool aborting() const { + return m_totals.assertions.failed == static_cast( m_config->abortAfter() ); + } + + private: + + void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { + TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); + m_reporter->sectionStarting( testCaseSection ); + Counts prevAssertions = m_totals.assertions; + double duration = 0; + m_shouldReportUnexpected = true; + try { + m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, std::string(), ResultDisposition::Normal ); + + seedRng( *m_config ); + + Timer timer; + timer.start(); + if( m_reporter->getPreferences().shouldRedirectStdOut ) { + StreamRedirect coutRedir( Catch::cout(), redirectedCout ); + StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr ); + invokeActiveTestCase(); + } + else { + invokeActiveTestCase(); + } + duration = timer.getElapsedSeconds(); + } + catch( TestFailureException& ) { + // This just means the test was aborted due to failure + } + catch(...) { + // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions + // are reported without translation at the point of origin. + if (m_shouldReportUnexpected) { + makeUnexpectedResultBuilder().useActiveException(); + } + } + m_testCaseTracker->close(); + handleUnfinishedSections(); + m_messages.clear(); + + Counts assertions = m_totals.assertions - prevAssertions; + bool missingAssertions = testForMissingAssertions( assertions ); + + if( testCaseInfo.okToFail() ) { + std::swap( assertions.failedButOk, assertions.failed ); + m_totals.assertions.failed -= assertions.failedButOk; + m_totals.assertions.failedButOk += assertions.failedButOk; + } + + SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions ); + m_reporter->sectionEnded( testCaseSectionStats ); + } + + void invokeActiveTestCase() { + FatalConditionHandler fatalConditionHandler; // Handle signals + m_activeTestCase->invoke(); + fatalConditionHandler.reset(); + } + + private: + + ResultBuilder makeUnexpectedResultBuilder() const { + return ResultBuilder( m_lastAssertionInfo.macroName.c_str(), + m_lastAssertionInfo.lineInfo, + m_lastAssertionInfo.capturedExpression.c_str(), + m_lastAssertionInfo.resultDisposition ); + } + + void handleUnfinishedSections() { + // If sections ended prematurely due to an exception we stored their + // infos here so we can tear them down outside the unwind process. + for( std::vector::const_reverse_iterator it = m_unfinishedSections.rbegin(), + itEnd = m_unfinishedSections.rend(); + it != itEnd; + ++it ) + sectionEnded( *it ); + m_unfinishedSections.clear(); + } + + TestRunInfo m_runInfo; + IMutableContext& m_context; + TestCase const* m_activeTestCase; + ITracker* m_testCaseTracker; + ITracker* m_currentSectionTracker; + AssertionResult m_lastResult; + + Ptr m_config; + Totals m_totals; + Ptr m_reporter; + std::vector m_messages; + AssertionInfo m_lastAssertionInfo; + std::vector m_unfinishedSections; + std::vector m_activeSections; + TrackerContext m_trackerContext; + bool m_shouldReportUnexpected; + }; + + IResultCapture& getResultCapture() { + if( IResultCapture* capture = getCurrentContext().getResultCapture() ) + return *capture; + else + throw std::logic_error( "No result capture instance" ); + } + +} // end namespace Catch + +// #included from: internal/catch_version.h +#define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED + +namespace Catch { + + // Versioning information + struct Version { + Version( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ); + + unsigned int const majorVersion; + unsigned int const minorVersion; + unsigned int const patchNumber; + + // buildNumber is only used if branchName is not null + char const * const branchName; + unsigned int const buildNumber; + + friend std::ostream& operator << ( std::ostream& os, Version const& version ); + + private: + void operator=( Version const& ); + }; + + inline Version libraryVersion(); +} + +#include +#include +#include + +namespace Catch { + + Ptr createReporter( std::string const& reporterName, Ptr const& config ) { + Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() ); + if( !reporter ) { + std::ostringstream oss; + oss << "No reporter registered with name: '" << reporterName << "'"; + throw std::domain_error( oss.str() ); + } + return reporter; + } + + Ptr makeReporter( Ptr const& config ) { + std::vector reporters = config->getReporterNames(); + if( reporters.empty() ) + reporters.push_back( "console" ); + + Ptr reporter; + for( std::vector::const_iterator it = reporters.begin(), itEnd = reporters.end(); + it != itEnd; + ++it ) + reporter = addReporter( reporter, createReporter( *it, config ) ); + return reporter; + } + Ptr addListeners( Ptr const& config, Ptr reporters ) { + IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners(); + for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end(); + it != itEnd; + ++it ) + reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) ); + return reporters; + } + + Totals runTests( Ptr const& config ) { + + Ptr iconfig = config.get(); + + Ptr reporter = makeReporter( config ); + reporter = addListeners( iconfig, reporter ); + + RunContext context( iconfig, reporter ); + + Totals totals; + + context.testGroupStarting( config->name(), 1, 1 ); + + TestSpec testSpec = config->testSpec(); + if( !testSpec.hasFilters() ) + testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests + + std::vector const& allTestCases = getAllTestCasesSorted( *iconfig ); + for( std::vector::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end(); + it != itEnd; + ++it ) { + if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) ) + totals += context.runTest( *it ); + else + reporter->skipTest( *it ); + } + + context.testGroupEnded( iconfig->name(), totals, 1, 1 ); + return totals; + } + + void applyFilenamesAsTags( IConfig const& config ) { + std::vector const& tests = getAllTestCasesSorted( config ); + for(std::size_t i = 0; i < tests.size(); ++i ) { + TestCase& test = const_cast( tests[i] ); + std::set tags = test.tags; + + std::string filename = test.lineInfo.file; + std::string::size_type lastSlash = filename.find_last_of( "\\/" ); + if( lastSlash != std::string::npos ) + filename = filename.substr( lastSlash+1 ); + + std::string::size_type lastDot = filename.find_last_of( "." ); + if( lastDot != std::string::npos ) + filename = filename.substr( 0, lastDot ); + + tags.insert( "#" + filename ); + setTags( test, tags ); + } + } + + class Session : NonCopyable { + static bool alreadyInstantiated; + + public: + + struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; }; + + Session() + : m_cli( makeCommandLineParser() ) { + if( alreadyInstantiated ) { + std::string msg = "Only one instance of Catch::Session can ever be used"; + Catch::cerr() << msg << std::endl; + throw std::logic_error( msg ); + } + alreadyInstantiated = true; + } + ~Session() { + Catch::cleanUp(); + } + + void showHelp( std::string const& processName ) { + Catch::cout() << "\nCatch v" << libraryVersion() << "\n"; + + m_cli.usage( Catch::cout(), processName ); + Catch::cout() << "For more detail usage please see the project docs\n" << std::endl; + } + + int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { + try { + m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); + m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData ); + if( m_configData.showHelp ) + showHelp( m_configData.processName ); + m_config.reset(); + } + catch( std::exception& ex ) { + { + Colour colourGuard( Colour::Red ); + Catch::cerr() + << "\nError(s) in input:\n" + << Text( ex.what(), TextAttributes().setIndent(2) ) + << "\n\n"; + } + m_cli.usage( Catch::cout(), m_configData.processName ); + return (std::numeric_limits::max)(); + } + return 0; + } + + void useConfigData( ConfigData const& _configData ) { + m_configData = _configData; + m_config.reset(); + } + + int run( int argc, char const* const* const argv ) { + + int returnCode = applyCommandLine( argc, argv ); + if( returnCode == 0 ) + returnCode = run(); + return returnCode; + } + + int run() { + if( m_configData.showHelp ) + return 0; + + try + { + config(); // Force config to be constructed + + seedRng( *m_config ); + + if( m_configData.filenamesAsTags ) + applyFilenamesAsTags( *m_config ); + + // Handle list request + if( Option listed = list( config() ) ) + return static_cast( *listed ); + + return static_cast( runTests( m_config ).assertions.failed ); + } + catch( std::exception& ex ) { + Catch::cerr() << ex.what() << std::endl; + return (std::numeric_limits::max)(); + } + } + + Clara::CommandLine const& cli() const { + return m_cli; + } + std::vector const& unusedTokens() const { + return m_unusedTokens; + } + ConfigData& configData() { + return m_configData; + } + Config& config() { + if( !m_config ) + m_config = new Config( m_configData ); + return *m_config; + } + private: + Clara::CommandLine m_cli; + std::vector m_unusedTokens; + ConfigData m_configData; + Ptr m_config; + }; + + bool Session::alreadyInstantiated = false; + +} // end namespace Catch + +// #included from: catch_registry_hub.hpp +#define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED + +// #included from: catch_test_case_registry_impl.hpp +#define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED + +#include +#include +#include +#include + +namespace Catch { + + struct RandomNumberGenerator { + typedef std::ptrdiff_t result_type; + + result_type operator()( result_type n ) const { return std::rand() % n; } + +#ifdef CATCH_CONFIG_CPP11_SHUFFLE + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return 1000000; } + result_type operator()() const { return std::rand() % max(); } +#endif + template + static void shuffle( V& vector ) { + RandomNumberGenerator rng; +#ifdef CATCH_CONFIG_CPP11_SHUFFLE + std::shuffle( vector.begin(), vector.end(), rng ); +#else + std::random_shuffle( vector.begin(), vector.end(), rng ); +#endif + } + }; + + inline std::vector sortTests( IConfig const& config, std::vector const& unsortedTestCases ) { + + std::vector sorted = unsortedTestCases; + + switch( config.runOrder() ) { + case RunTests::InLexicographicalOrder: + std::sort( sorted.begin(), sorted.end() ); + break; + case RunTests::InRandomOrder: + { + seedRng( config ); + RandomNumberGenerator::shuffle( sorted ); + } + break; + case RunTests::InDeclarationOrder: + // already in declaration order + break; + } + return sorted; + } + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { + return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); + } + + void enforceNoDuplicateTestCases( std::vector const& functions ) { + std::set seenFunctions; + for( std::vector::const_iterator it = functions.begin(), itEnd = functions.end(); + it != itEnd; + ++it ) { + std::pair::const_iterator, bool> prev = seenFunctions.insert( *it ); + if( !prev.second ) { + std::ostringstream ss; + + ss << Colour( Colour::Red ) + << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n' + << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl; + + throw std::runtime_error(ss.str()); + } + } + } + + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ) { + std::vector filtered; + filtered.reserve( testCases.size() ); + for( std::vector::const_iterator it = testCases.begin(), itEnd = testCases.end(); + it != itEnd; + ++it ) + if( matchTest( *it, testSpec, config ) ) + filtered.push_back( *it ); + return filtered; + } + std::vector const& getAllTestCasesSorted( IConfig const& config ) { + return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); + } + + class TestRegistry : public ITestCaseRegistry { + public: + TestRegistry() + : m_currentSortOrder( RunTests::InDeclarationOrder ), + m_unnamedCount( 0 ) + {} + virtual ~TestRegistry(); + + virtual void registerTest( TestCase const& testCase ) { + std::string name = testCase.getTestCaseInfo().name; + if( name.empty() ) { + std::ostringstream oss; + oss << "Anonymous test case " << ++m_unnamedCount; + return registerTest( testCase.withName( oss.str() ) ); + } + m_functions.push_back( testCase ); + } + + virtual std::vector const& getAllTests() const { + return m_functions; + } + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const { + if( m_sortedFunctions.empty() ) + enforceNoDuplicateTestCases( m_functions ); + + if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { + m_sortedFunctions = sortTests( config, m_functions ); + m_currentSortOrder = config.runOrder(); + } + return m_sortedFunctions; + } + + private: + std::vector m_functions; + mutable RunTests::InWhatOrder m_currentSortOrder; + mutable std::vector m_sortedFunctions; + size_t m_unnamedCount; + std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised + }; + + /////////////////////////////////////////////////////////////////////////// + + class FreeFunctionTestCase : public SharedImpl { + public: + + FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} + + virtual void invoke() const { + m_fun(); + } + + private: + virtual ~FreeFunctionTestCase(); + + TestFunction m_fun; + }; + + inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) { + std::string className = classOrQualifiedMethodName; + if( startsWith( className, '&' ) ) + { + std::size_t lastColons = className.rfind( "::" ); + std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); + if( penultimateColons == std::string::npos ) + penultimateColons = 1; + className = className.substr( penultimateColons, lastColons-penultimateColons ); + } + return className; + } + + void registerTestCase + ( ITestCase* testCase, + char const* classOrQualifiedMethodName, + NameAndDesc const& nameAndDesc, + SourceLineInfo const& lineInfo ) { + + getMutableRegistryHub().registerTest + ( makeTestCase + ( testCase, + extractClassName( classOrQualifiedMethodName ), + nameAndDesc.name, + nameAndDesc.description, + lineInfo ) ); + } + void registerTestCaseFunction + ( TestFunction function, + SourceLineInfo const& lineInfo, + NameAndDesc const& nameAndDesc ) { + registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo ); + } + + /////////////////////////////////////////////////////////////////////////// + + AutoReg::AutoReg + ( TestFunction function, + SourceLineInfo const& lineInfo, + NameAndDesc const& nameAndDesc ) { + registerTestCaseFunction( function, lineInfo, nameAndDesc ); + } + + AutoReg::~AutoReg() {} + +} // end namespace Catch + +// #included from: catch_reporter_registry.hpp +#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED + +#include + +namespace Catch { + + class ReporterRegistry : public IReporterRegistry { + + public: + + virtual ~ReporterRegistry() CATCH_OVERRIDE {} + + virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const CATCH_OVERRIDE { + FactoryMap::const_iterator it = m_factories.find( name ); + if( it == m_factories.end() ) + return CATCH_NULL; + return it->second->create( ReporterConfig( config ) ); + } + + void registerReporter( std::string const& name, Ptr const& factory ) { + m_factories.insert( std::make_pair( name, factory ) ); + } + void registerListener( Ptr const& factory ) { + m_listeners.push_back( factory ); + } + + virtual FactoryMap const& getFactories() const CATCH_OVERRIDE { + return m_factories; + } + virtual Listeners const& getListeners() const CATCH_OVERRIDE { + return m_listeners; + } + + private: + FactoryMap m_factories; + Listeners m_listeners; + }; +} + +// #included from: catch_exception_translator_registry.hpp +#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED + +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry() { + deleteAll( m_translators ); + } + + virtual void registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( translator ); + } + + virtual std::string translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + return tryTranslators(); + } + @catch (NSException *exception) { + return Catch::toString( [exception description] ); + } +#else + return tryTranslators(); +#endif + } + catch( TestFailureException& ) { + throw; + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return "Unknown exception"; + } + } + + std::string tryTranslators() const { + if( m_translators.empty() ) + throw; + else + return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); + } + + private: + std::vector m_translators; + }; +} + +// #included from: catch_tag_alias_registry.h +#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED + +#include + +namespace Catch { + + class TagAliasRegistry : public ITagAliasRegistry { + public: + virtual ~TagAliasRegistry(); + virtual Option find( std::string const& alias ) const; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const; + void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ); + + private: + std::map m_registry; + }; + +} // end namespace Catch + +namespace Catch { + + namespace { + + class RegistryHub : public IRegistryHub, public IMutableRegistryHub { + + RegistryHub( RegistryHub const& ); + void operator=( RegistryHub const& ); + + public: // IRegistryHub + RegistryHub() { + } + virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE { + return m_reporterRegistry; + } + virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE { + return m_testCaseRegistry; + } + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE { + return m_exceptionTranslatorRegistry; + } + virtual ITagAliasRegistry const& getTagAliasRegistry() const CATCH_OVERRIDE { + return m_tagAliasRegistry; + } + + public: // IMutableRegistryHub + virtual void registerReporter( std::string const& name, Ptr const& factory ) CATCH_OVERRIDE { + m_reporterRegistry.registerReporter( name, factory ); + } + virtual void registerListener( Ptr const& factory ) CATCH_OVERRIDE { + m_reporterRegistry.registerListener( factory ); + } + virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE { + m_testCaseRegistry.registerTest( testInfo ); + } + virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) CATCH_OVERRIDE { + m_tagAliasRegistry.add( alias, tag, lineInfo ); + } + + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + TagAliasRegistry m_tagAliasRegistry; + }; + + // Single, global, instance + inline RegistryHub*& getTheRegistryHub() { + static RegistryHub* theRegistryHub = CATCH_NULL; + if( !theRegistryHub ) + theRegistryHub = new RegistryHub(); + return theRegistryHub; + } + } + + IRegistryHub& getRegistryHub() { + return *getTheRegistryHub(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return *getTheRegistryHub(); + } + void cleanUp() { + delete getTheRegistryHub(); + getTheRegistryHub() = CATCH_NULL; + cleanUpContext(); + } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } + +} // end namespace Catch + +// #included from: catch_notimplemented_exception.hpp +#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED + +#include + +namespace Catch { + + NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo ) + : m_lineInfo( lineInfo ) { + std::ostringstream oss; + oss << lineInfo << ": function "; + oss << "not implemented"; + m_what = oss.str(); + } + + const char* NotImplementedException::what() const CATCH_NOEXCEPT { + return m_what.c_str(); + } + +} // end namespace Catch + +// #included from: catch_context_impl.hpp +#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED + +// #included from: catch_stream.hpp +#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED + +#include +#include +#include + +namespace Catch { + + template + class StreamBufImpl : public StreamBufBase { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); + } + + ~StreamBufImpl() CATCH_NOEXCEPT { + sync(); + } + + private: + int overflow( int c ) { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast( c ) ) ); + else + sputc( static_cast( c ) ); + } + return 0; + } + + int sync() { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } + }; + + /////////////////////////////////////////////////////////////////////////// + + FileStream::FileStream( std::string const& filename ) { + m_ofs.open( filename.c_str() ); + if( m_ofs.fail() ) { + std::ostringstream oss; + oss << "Unable to open file: '" << filename << '\''; + throw std::domain_error( oss.str() ); + } + } + + std::ostream& FileStream::stream() const { + return m_ofs; + } + + struct OutputDebugWriter { + + void operator()( std::string const&str ) { + writeToDebugConsole( str ); + } + }; + + DebugOutStream::DebugOutStream() + : m_streamBuf( new StreamBufImpl() ), + m_os( m_streamBuf.get() ) + {} + + std::ostream& DebugOutStream::stream() const { + return m_os; + } + + // Store the streambuf from cout up-front because + // cout may get redirected when running tests + CoutStream::CoutStream() + : m_os( Catch::cout().rdbuf() ) + {} + + std::ostream& CoutStream::stream() const { + return m_os; + } + +#ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions + std::ostream& cout() { + return std::cout; + } + std::ostream& cerr() { + return std::cerr; + } +#endif +} + +namespace Catch { + + class Context : public IMutableContext { + + Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {} + Context( Context const& ); + void operator=( Context const& ); + + public: + virtual ~Context() { + deleteAllValues( m_generatorsByTestName ); + } + + public: // IContext + virtual IResultCapture* getResultCapture() { + return m_resultCapture; + } + virtual IRunner* getRunner() { + return m_runner; + } + virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) { + return getGeneratorsForCurrentTest() + .getGeneratorInfo( fileInfo, totalSize ) + .getCurrentIndex(); + } + virtual bool advanceGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + return generators && generators->moveNext(); + } + + virtual Ptr getConfig() const { + return m_config; + } + + public: // IMutableContext + virtual void setResultCapture( IResultCapture* resultCapture ) { + m_resultCapture = resultCapture; + } + virtual void setRunner( IRunner* runner ) { + m_runner = runner; + } + virtual void setConfig( Ptr const& config ) { + m_config = config; + } + + friend IMutableContext& getCurrentMutableContext(); + + private: + IGeneratorsForTest* findGeneratorsForCurrentTest() { + std::string testName = getResultCapture()->getCurrentTestName(); + + std::map::const_iterator it = + m_generatorsByTestName.find( testName ); + return it != m_generatorsByTestName.end() + ? it->second + : CATCH_NULL; + } + + IGeneratorsForTest& getGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + if( !generators ) { + std::string testName = getResultCapture()->getCurrentTestName(); + generators = createGeneratorsForTest(); + m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); + } + return *generators; + } + + private: + Ptr m_config; + IRunner* m_runner; + IResultCapture* m_resultCapture; + std::map m_generatorsByTestName; + }; + + namespace { + Context* currentContext = CATCH_NULL; + } + IMutableContext& getCurrentMutableContext() { + if( !currentContext ) + currentContext = new Context(); + return *currentContext; + } + IContext& getCurrentContext() { + return getCurrentMutableContext(); + } + + void cleanUpContext() { + delete currentContext; + currentContext = CATCH_NULL; + } +} + +// #included from: catch_console_colour_impl.hpp +#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED + +// #included from: catch_errno_guard.hpp +#define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED + +#include + +namespace Catch { + + class ErrnoGuard { + public: + ErrnoGuard():m_oldErrno(errno){} + ~ErrnoGuard() { errno = m_oldErrno; } + private: + int m_oldErrno; + }; + +} + +namespace Catch { + namespace { + + struct IColourImpl { + virtual ~IColourImpl() {} + virtual void use( Colour::Code _colourCode ) = 0; + }; + + struct NoColourImpl : IColourImpl { + void use( Colour::Code ) {} + + static IColourImpl* instance() { + static NoColourImpl s_instance; + return &s_instance; + } + }; + + } // anon namespace +} // namespace Catch + +#if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) +# ifdef CATCH_PLATFORM_WINDOWS +# define CATCH_CONFIG_COLOUR_WINDOWS +# else +# define CATCH_CONFIG_COLOUR_ANSI +# endif +#endif + +#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// + +namespace Catch { +namespace { + + class Win32ColourImpl : public IColourImpl { + public: + Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) + { + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); + originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); + originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); + } + + virtual void use( Colour::Code _colourCode ) { + switch( _colourCode ) { + case Colour::None: return setTextAttribute( originalForegroundAttributes ); + case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + case Colour::Red: return setTextAttribute( FOREGROUND_RED ); + case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); + case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); + case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); + case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); + case Colour::Grey: return setTextAttribute( 0 ); + + case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); + case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); + case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); + case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); + + case Colour::Bright: throw std::logic_error( "not a colour" ); + } + } + + private: + void setTextAttribute( WORD _textAttribute ) { + SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); + } + HANDLE stdoutHandle; + WORD originalForegroundAttributes; + WORD originalBackgroundAttributes; + }; + + IColourImpl* platformColourInstance() { + static Win32ColourImpl s_instance; + + Ptr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = !isDebuggerActive() + ? UseColour::Yes + : UseColour::No; + return colourMode == UseColour::Yes + ? &s_instance + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// + +#include + +namespace Catch { +namespace { + + // use POSIX/ ANSI console terminal codes + // Thanks to Adam Strzelecki for original contribution + // (http://github.com/nanoant) + // https://github.com/philsquared/Catch/pull/131 + class PosixColourImpl : public IColourImpl { + public: + virtual void use( Colour::Code _colourCode ) { + switch( _colourCode ) { + case Colour::None: + case Colour::White: return setColour( "[0m" ); + case Colour::Red: return setColour( "[0;31m" ); + case Colour::Green: return setColour( "[0;32m" ); + case Colour::Blue: return setColour( "[0;34m" ); + case Colour::Cyan: return setColour( "[0;36m" ); + case Colour::Yellow: return setColour( "[0;33m" ); + case Colour::Grey: return setColour( "[1;30m" ); + + case Colour::LightGrey: return setColour( "[0;37m" ); + case Colour::BrightRed: return setColour( "[1;31m" ); + case Colour::BrightGreen: return setColour( "[1;32m" ); + case Colour::BrightWhite: return setColour( "[1;37m" ); + + case Colour::Bright: throw std::logic_error( "not a colour" ); + } + } + static IColourImpl* instance() { + static PosixColourImpl s_instance; + return &s_instance; + } + + private: + void setColour( const char* _escapeCode ) { + Catch::cout() << '\033' << _escapeCode; + } + }; + + IColourImpl* platformColourInstance() { + ErrnoGuard guard; + Ptr config = getCurrentContext().getConfig(); + UseColour::YesOrNo colourMode = config + ? config->useColour() + : UseColour::Auto; + if( colourMode == UseColour::Auto ) + colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) ) + ? UseColour::Yes + : UseColour::No; + return colourMode == UseColour::Yes + ? PosixColourImpl::instance() + : NoColourImpl::instance(); + } + +} // end anon namespace +} // end namespace Catch + +#else // not Windows or ANSI /////////////////////////////////////////////// + +namespace Catch { + + static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } + +} // end namespace Catch + +#endif // Windows/ ANSI/ None + +namespace Catch { + + Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); } + Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast( _other ).m_moved = true; } + Colour::~Colour(){ if( !m_moved ) use( None ); } + + void Colour::use( Code _colourCode ) { + static IColourImpl* impl = platformColourInstance(); + impl->use( _colourCode ); + } + +} // end namespace Catch + +// #included from: catch_generators_impl.hpp +#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED + +#include +#include +#include + +namespace Catch { + + struct GeneratorInfo : IGeneratorInfo { + + GeneratorInfo( std::size_t size ) + : m_size( size ), + m_currentIndex( 0 ) + {} + + bool moveNext() { + if( ++m_currentIndex == m_size ) { + m_currentIndex = 0; + return false; + } + return true; + } + + std::size_t getCurrentIndex() const { + return m_currentIndex; + } + + std::size_t m_size; + std::size_t m_currentIndex; + }; + + /////////////////////////////////////////////////////////////////////////// + + class GeneratorsForTest : public IGeneratorsForTest { + + public: + ~GeneratorsForTest() { + deleteAll( m_generatorsInOrder ); + } + + IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) { + std::map::const_iterator it = m_generatorsByName.find( fileInfo ); + if( it == m_generatorsByName.end() ) { + IGeneratorInfo* info = new GeneratorInfo( size ); + m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); + m_generatorsInOrder.push_back( info ); + return *info; + } + return *it->second; + } + + bool moveNext() { + std::vector::const_iterator it = m_generatorsInOrder.begin(); + std::vector::const_iterator itEnd = m_generatorsInOrder.end(); + for(; it != itEnd; ++it ) { + if( (*it)->moveNext() ) + return true; + } + return false; + } + + private: + std::map m_generatorsByName; + std::vector m_generatorsInOrder; + }; + + IGeneratorsForTest* createGeneratorsForTest() + { + return new GeneratorsForTest(); + } + +} // end namespace Catch + +// #included from: catch_assertionresult.hpp +#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED + +namespace Catch { + + AssertionInfo::AssertionInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + std::string const& _capturedExpression, + ResultDisposition::Flags _resultDisposition ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + capturedExpression( _capturedExpression ), + resultDisposition( _resultDisposition ) + {} + + AssertionResult::AssertionResult() {} + + AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) + : m_info( info ), + m_resultData( data ) + {} + + AssertionResult::~AssertionResult() {} + + // Result was a success + bool AssertionResult::succeeded() const { + return Catch::isOk( m_resultData.resultType ); + } + + // Result was a success, or failure is suppressed + bool AssertionResult::isOk() const { + return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); + } + + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; + } + + bool AssertionResult::hasExpression() const { + return !m_info.capturedExpression.empty(); + } + + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); + } + + std::string AssertionResult::getExpression() const { + if( isFalseTest( m_info.resultDisposition ) ) + return '!' + m_info.capturedExpression; + else + return m_info.capturedExpression; + } + std::string AssertionResult::getExpressionInMacro() const { + if( m_info.macroName.empty() ) + return m_info.capturedExpression; + else + return m_info.macroName + "( " + m_info.capturedExpression + " )"; + } + + bool AssertionResult::hasExpandedExpression() const { + return hasExpression() && getExpandedExpression() != getExpression(); + } + + std::string AssertionResult::getExpandedExpression() const { + return m_resultData.reconstructExpression(); + } + + std::string AssertionResult::getMessage() const { + return m_resultData.message; + } + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; + } + + std::string AssertionResult::getTestMacroName() const { + return m_info.macroName; + } + + void AssertionResult::discardDecomposedExpression() const { + m_resultData.decomposedExpression = CATCH_NULL; + } + + void AssertionResult::expandDecomposedExpression() const { + m_resultData.reconstructExpression(); + } + +} // end namespace Catch + +// #included from: catch_test_case_info.hpp +#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED + +#include + +namespace Catch { + + inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { + if( startsWith( tag, '.' ) || + tag == "hide" || + tag == "!hide" ) + return TestCaseInfo::IsHidden; + else if( tag == "!throws" ) + return TestCaseInfo::Throws; + else if( tag == "!shouldfail" ) + return TestCaseInfo::ShouldFail; + else if( tag == "!mayfail" ) + return TestCaseInfo::MayFail; + else if( tag == "!nonportable" ) + return TestCaseInfo::NonPortable; + else + return TestCaseInfo::None; + } + inline bool isReservedTag( std::string const& tag ) { + return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] ); + } + inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { + if( isReservedTag( tag ) ) { + std::ostringstream ss; + ss << Colour(Colour::Red) + << "Tag name [" << tag << "] not allowed.\n" + << "Tag names starting with non alpha-numeric characters are reserved\n" + << Colour(Colour::FileName) + << _lineInfo << '\n'; + throw std::runtime_error(ss.str()); + } + } + + TestCase makeTestCase( ITestCase* _testCase, + std::string const& _className, + std::string const& _name, + std::string const& _descOrTags, + SourceLineInfo const& _lineInfo ) + { + bool isHidden( startsWith( _name, "./" ) ); // Legacy support + + // Parse out tags + std::set tags; + std::string desc, tag; + bool inTag = false; + for( std::size_t i = 0; i < _descOrTags.size(); ++i ) { + char c = _descOrTags[i]; + if( !inTag ) { + if( c == '[' ) + inTag = true; + else + desc += c; + } + else { + if( c == ']' ) { + TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); + if( prop == TestCaseInfo::IsHidden ) + isHidden = true; + else if( prop == TestCaseInfo::None ) + enforceNotReservedTag( tag, _lineInfo ); + + tags.insert( tag ); + tag.clear(); + inTag = false; + } + else + tag += c; + } + } + if( isHidden ) { + tags.insert( "hide" ); + tags.insert( "." ); + } + + TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); + return TestCase( _testCase, info ); + } + + void setTags( TestCaseInfo& testCaseInfo, std::set const& tags ) + { + testCaseInfo.tags = tags; + testCaseInfo.lcaseTags.clear(); + + std::ostringstream oss; + for( std::set::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) { + oss << '[' << *it << ']'; + std::string lcaseTag = toLower( *it ); + testCaseInfo.properties = static_cast( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); + testCaseInfo.lcaseTags.insert( lcaseTag ); + } + testCaseInfo.tagsAsString = oss.str(); + } + + TestCaseInfo::TestCaseInfo( std::string const& _name, + std::string const& _className, + std::string const& _description, + std::set const& _tags, + SourceLineInfo const& _lineInfo ) + : name( _name ), + className( _className ), + description( _description ), + lineInfo( _lineInfo ), + properties( None ) + { + setTags( *this, _tags ); + } + + TestCaseInfo::TestCaseInfo( TestCaseInfo const& other ) + : name( other.name ), + className( other.className ), + description( other.description ), + tags( other.tags ), + lcaseTags( other.lcaseTags ), + tagsAsString( other.tagsAsString ), + lineInfo( other.lineInfo ), + properties( other.properties ) + {} + + bool TestCaseInfo::isHidden() const { + return ( properties & IsHidden ) != 0; + } + bool TestCaseInfo::throws() const { + return ( properties & Throws ) != 0; + } + bool TestCaseInfo::okToFail() const { + return ( properties & (ShouldFail | MayFail ) ) != 0; + } + bool TestCaseInfo::expectedToFail() const { + return ( properties & (ShouldFail ) ) != 0; + } + + TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} + + TestCase::TestCase( TestCase const& other ) + : TestCaseInfo( other ), + test( other.test ) + {} + + TestCase TestCase::withName( std::string const& _newName ) const { + TestCase other( *this ); + other.name = _newName; + return other; + } + + void TestCase::swap( TestCase& other ) { + test.swap( other.test ); + name.swap( other.name ); + className.swap( other.className ); + description.swap( other.description ); + tags.swap( other.tags ); + lcaseTags.swap( other.lcaseTags ); + tagsAsString.swap( other.tagsAsString ); + std::swap( TestCaseInfo::properties, static_cast( other ).properties ); + std::swap( lineInfo, other.lineInfo ); + } + + void TestCase::invoke() const { + test->invoke(); + } + + bool TestCase::operator == ( TestCase const& other ) const { + return test.get() == other.test.get() && + name == other.name && + className == other.className; + } + + bool TestCase::operator < ( TestCase const& other ) const { + return name < other.name; + } + TestCase& TestCase::operator = ( TestCase const& other ) { + TestCase temp( other ); + swap( temp ); + return *this; + } + + TestCaseInfo const& TestCase::getTestCaseInfo() const + { + return *this; + } + +} // end namespace Catch + +// #included from: catch_version.hpp +#define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED + +namespace Catch { + + Version::Version + ( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ) + : majorVersion( _majorVersion ), + minorVersion( _minorVersion ), + patchNumber( _patchNumber ), + branchName( _branchName ), + buildNumber( _buildNumber ) + {} + + std::ostream& operator << ( std::ostream& os, Version const& version ) { + os << version.majorVersion << '.' + << version.minorVersion << '.' + << version.patchNumber; + // branchName is never null -> 0th char is \0 if it is empty + if (version.branchName[0]) { + os << '-' << version.branchName + << '.' << version.buildNumber; + } + return os; + } + + inline Version libraryVersion() { + static Version version( 1, 9, 1, "", 0 ); + return version; + } + +} + +// #included from: catch_message.hpp +#define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED + +namespace Catch { + + MessageInfo::MessageInfo( std::string const& _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) + : macroName( _macroName ), + lineInfo( _lineInfo ), + type( _type ), + sequence( ++globalCount ) + {} + + // This may need protecting if threading support is added + unsigned int MessageInfo::globalCount = 0; + + //////////////////////////////////////////////////////////////////////////// + + ScopedMessage::ScopedMessage( MessageBuilder const& builder ) + : m_info( builder.m_info ) + { + m_info.message = builder.m_stream.str(); + getResultCapture().pushScopedMessage( m_info ); + } + ScopedMessage::ScopedMessage( ScopedMessage const& other ) + : m_info( other.m_info ) + {} + + ScopedMessage::~ScopedMessage() { + if ( !std::uncaught_exception() ){ + getResultCapture().popScopedMessage(m_info); + } + } + +} // end namespace Catch + +// #included from: catch_legacy_reporter_adapter.hpp +#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED + +// #included from: catch_legacy_reporter_adapter.h +#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED + +namespace Catch +{ + // Deprecated + struct IReporter : IShared { + virtual ~IReporter(); + + virtual bool shouldRedirectStdout() const = 0; + + virtual void StartTesting() = 0; + virtual void EndTesting( Totals const& totals ) = 0; + virtual void StartGroup( std::string const& groupName ) = 0; + virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0; + virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0; + virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0; + virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0; + virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0; + virtual void NoAssertionsInSection( std::string const& sectionName ) = 0; + virtual void NoAssertionsInTestCase( std::string const& testName ) = 0; + virtual void Aborted() = 0; + virtual void Result( AssertionResult const& result ) = 0; + }; + + class LegacyReporterAdapter : public SharedImpl + { + public: + LegacyReporterAdapter( Ptr const& legacyReporter ); + virtual ~LegacyReporterAdapter(); + + virtual ReporterPreferences getPreferences() const; + virtual void noMatchingTestCases( std::string const& ); + virtual void testRunStarting( TestRunInfo const& ); + virtual void testGroupStarting( GroupInfo const& groupInfo ); + virtual void testCaseStarting( TestCaseInfo const& testInfo ); + virtual void sectionStarting( SectionInfo const& sectionInfo ); + virtual void assertionStarting( AssertionInfo const& ); + virtual bool assertionEnded( AssertionStats const& assertionStats ); + virtual void sectionEnded( SectionStats const& sectionStats ); + virtual void testCaseEnded( TestCaseStats const& testCaseStats ); + virtual void testGroupEnded( TestGroupStats const& testGroupStats ); + virtual void testRunEnded( TestRunStats const& testRunStats ); + virtual void skipTest( TestCaseInfo const& ); + + private: + Ptr m_legacyReporter; + }; +} + +namespace Catch +{ + LegacyReporterAdapter::LegacyReporterAdapter( Ptr const& legacyReporter ) + : m_legacyReporter( legacyReporter ) + {} + LegacyReporterAdapter::~LegacyReporterAdapter() {} + + ReporterPreferences LegacyReporterAdapter::getPreferences() const { + ReporterPreferences prefs; + prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); + return prefs; + } + + void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {} + void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) { + m_legacyReporter->StartTesting(); + } + void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) { + m_legacyReporter->StartGroup( groupInfo.name ); + } + void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) { + m_legacyReporter->StartTestCase( testInfo ); + } + void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) { + m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); + } + void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) { + // Not on legacy interface + } + + bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { + if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { + for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); + it != itEnd; + ++it ) { + if( it->type == ResultWas::Info ) { + ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal ); + rb << it->message; + rb.setResultType( ResultWas::Info ); + AssertionResult result = rb.build(); + m_legacyReporter->Result( result ); + } + } + } + m_legacyReporter->Result( assertionStats.assertionResult ); + return true; + } + void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { + if( sectionStats.missingAssertions ) + m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); + m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); + } + void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) { + m_legacyReporter->EndTestCase + ( testCaseStats.testInfo, + testCaseStats.totals, + testCaseStats.stdOut, + testCaseStats.stdErr ); + } + void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) { + if( testGroupStats.aborting ) + m_legacyReporter->Aborted(); + m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); + } + void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { + m_legacyReporter->EndTesting( testRunStats.totals ); + } + void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) { + } +} + +// #included from: catch_timer.hpp + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wc++11-long-long" +#endif + +#ifdef CATCH_PLATFORM_WINDOWS + +#else + +#include + +#endif + +namespace Catch { + + namespace { +#ifdef CATCH_PLATFORM_WINDOWS + uint64_t getCurrentTicks() { + static uint64_t hz=0, hzo=0; + if (!hz) { + QueryPerformanceFrequency( reinterpret_cast( &hz ) ); + QueryPerformanceCounter( reinterpret_cast( &hzo ) ); + } + uint64_t t; + QueryPerformanceCounter( reinterpret_cast( &t ) ); + return ((t-hzo)*1000000)/hz; + } +#else + uint64_t getCurrentTicks() { + timeval t; + gettimeofday(&t,CATCH_NULL); + return static_cast( t.tv_sec ) * 1000000ull + static_cast( t.tv_usec ); + } +#endif + } + + void Timer::start() { + m_ticks = getCurrentTicks(); + } + unsigned int Timer::getElapsedMicroseconds() const { + return static_cast(getCurrentTicks() - m_ticks); + } + unsigned int Timer::getElapsedMilliseconds() const { + return static_cast(getElapsedMicroseconds()/1000); + } + double Timer::getElapsedSeconds() const { + return getElapsedMicroseconds()/1000000.0; + } + +} // namespace Catch + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +// #included from: catch_common.hpp +#define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED + +#include +#include + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ) { + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; + } + bool endsWith( std::string const& s, std::string const& suffix ) { + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; + } + bool contains( std::string const& s, std::string const& infix ) { + return s.find( infix ) != std::string::npos; + } + char toLowerCh(char c) { + return static_cast( std::tolower( c ) ); + } + void toLowerInPlace( std::string& s ) { + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); + } + std::string toLower( std::string const& s ) { + std::string lc = s; + toLowerInPlace( lc ); + return lc; + } + std::string trim( std::string const& str ) { + static char const* whitespaceChars = "\n\r\t "; + std::string::size_type start = str.find_first_not_of( whitespaceChars ); + std::string::size_type end = str.find_last_not_of( whitespaceChars ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); + } + + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { + bool replaced = false; + std::size_t i = str.find( replaceThis ); + while( i != std::string::npos ) { + replaced = true; + str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); + if( i < str.size()-withThis.size() ) + i = str.find( replaceThis, i+withThis.size() ); + else + i = std::string::npos; + } + return replaced; + } + + pluralise::pluralise( std::size_t count, std::string const& label ) + : m_count( count ), + m_label( label ) + {} + + std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { + os << pluraliser.m_count << ' ' << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << 's'; + return os; + } + + SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){} + SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) + : file( _file ), + line( _line ) + {} + bool SourceLineInfo::empty() const { + return file[0] == '\0'; + } + bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const { + return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); + } + bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const { + return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); + } + + void seedRng( IConfig const& config ) { + if( config.rngSeed() != 0 ) + std::srand( config.rngSeed() ); + } + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { +#ifndef __GNUG__ + os << info.file << '(' << info.line << ')'; +#else + os << info.file << ':' << info.line; +#endif + return os; + } + + void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) { + std::ostringstream oss; + oss << locationInfo << ": Internal Catch error: '" << message << '\''; + if( alwaysTrue() ) + throw std::logic_error( oss.str() ); + } +} + +// #included from: catch_section.hpp +#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED + +namespace Catch { + + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description ) + : name( _name ), + description( _description ), + lineInfo( _lineInfo ) + {} + + Section::Section( SectionInfo const& info ) + : m_info( info ), + m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) + { + m_timer.start(); + } + + Section::~Section() { + if( m_sectionIncluded ) { + SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); + if( std::uncaught_exception() ) + getResultCapture().sectionEndedEarly( endInfo ); + else + getResultCapture().sectionEnded( endInfo ); + } + } + + // This indicates whether the section should be executed or not + Section::operator bool() const { + return m_sectionIncluded; + } + +} // end namespace Catch + +// #included from: catch_debugger.hpp +#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED + +#ifdef CATCH_PLATFORM_MAC + + #include + #include + #include + #include + #include + + namespace Catch{ + + // The following function is taken directly from the following technical note: + // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html + + // Returns true if the current process is being debugged (either + // running under the debugger or has a debugger attached post facto). + bool isDebuggerActive(){ + + int mib[4]; + struct kinfo_proc info; + size_t size; + + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + + info.kp_proc.p_flag = 0; + + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + + // Call sysctl. + + size = sizeof(info); + if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) { + Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; + return false; + } + + // We're being debugged if the P_TRACED flag is set. + + return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); + } + } // namespace Catch + +#elif defined(CATCH_PLATFORM_LINUX) + #include + #include + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + // Libstdc++ has a bug, where std::ifstream sets errno to 0 + // This way our users can properly assert over errno values + ErrnoGuard guard; + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch +#elif defined(_MSC_VER) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#elif defined(__MINGW32__) + extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); + namespace Catch { + bool isDebuggerActive() { + return IsDebuggerPresent() != 0; + } + } +#else + namespace Catch { + inline bool isDebuggerActive() { return false; } + } +#endif // Platform + +#ifdef CATCH_PLATFORM_WINDOWS + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + ::OutputDebugStringA( text.c_str() ); + } + } +#else + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + // !TBD: Need a version for Mac/ XCode and other IDEs + Catch::cout() << text; + } + } +#endif // Platform + +// #included from: catch_tostring.hpp +#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED + +namespace Catch { + +namespace Detail { + + const std::string unprintableString = "{?}"; + + namespace { + const int hexThreshold = 255; + + struct Endianness { + enum Arch { Big, Little }; + + static Arch which() { + union _{ + int asInt; + char asChar[sizeof (int)]; + } u; + + u.asInt = 1; + return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; + } + }; + } + + std::string rawMemoryToString( const void *object, std::size_t size ) + { + // Reverse order for little endian architectures + int i = 0, end = static_cast( size ), inc = 1; + if( Endianness::which() == Endianness::Little ) { + i = end-1; + end = inc = -1; + } + + unsigned char const *bytes = static_cast(object); + std::ostringstream os; + os << "0x" << std::setfill('0') << std::hex; + for( ; i != end; i += inc ) + os << std::setw(2) << static_cast(bytes[i]); + return os.str(); + } +} + +std::string toString( std::string const& value ) { + std::string s = value; + if( getCurrentContext().getConfig()->showInvisibles() ) { + for(size_t i = 0; i < s.size(); ++i ) { + std::string subs; + switch( s[i] ) { + case '\n': subs = "\\n"; break; + case '\t': subs = "\\t"; break; + default: break; + } + if( !subs.empty() ) { + s = s.substr( 0, i ) + subs + s.substr( i+1 ); + ++i; + } + } + } + return '"' + s + '"'; +} +std::string toString( std::wstring const& value ) { + + std::string s; + s.reserve( value.size() ); + for(size_t i = 0; i < value.size(); ++i ) + s += value[i] <= 0xff ? static_cast( value[i] ) : '?'; + return Catch::toString( s ); +} + +std::string toString( const char* const value ) { + return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" ); +} + +std::string toString( char* const value ) { + return Catch::toString( static_cast( value ) ); +} + +std::string toString( const wchar_t* const value ) +{ + return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); +} + +std::string toString( wchar_t* const value ) +{ + return Catch::toString( static_cast( value ) ); +} + +std::string toString( int value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ')'; + return oss.str(); +} + +std::string toString( unsigned long value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ')'; + return oss.str(); +} + +std::string toString( unsigned int value ) { + return Catch::toString( static_cast( value ) ); +} + +template +std::string fpToString( T value, int precision ) { + std::ostringstream oss; + oss << std::setprecision( precision ) + << std::fixed + << value; + std::string d = oss.str(); + std::size_t i = d.find_last_not_of( '0' ); + if( i != std::string::npos && i != d.size()-1 ) { + if( d[i] == '.' ) + i++; + d = d.substr( 0, i+1 ); + } + return d; +} + +std::string toString( const double value ) { + return fpToString( value, 10 ); +} +std::string toString( const float value ) { + return fpToString( value, 5 ) + 'f'; +} + +std::string toString( bool value ) { + return value ? "true" : "false"; +} + +std::string toString( char value ) { + if ( value == '\r' ) + return "'\\r'"; + if ( value == '\f' ) + return "'\\f'"; + if ( value == '\n' ) + return "'\\n'"; + if ( value == '\t' ) + return "'\\t'"; + if ( '\0' <= value && value < ' ' ) + return toString( static_cast( value ) ); + char chstr[] = "' '"; + chstr[1] = value; + return chstr; +} + +std::string toString( signed char value ) { + return toString( static_cast( value ) ); +} + +std::string toString( unsigned char value ) { + return toString( static_cast( value ) ); +} + +#ifdef CATCH_CONFIG_CPP11_LONG_LONG +std::string toString( long long value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ')'; + return oss.str(); +} +std::string toString( unsigned long long value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ')'; + return oss.str(); +} +#endif + +#ifdef CATCH_CONFIG_CPP11_NULLPTR +std::string toString( std::nullptr_t ) { + return "nullptr"; +} +#endif + +#ifdef __OBJC__ + std::string toString( NSString const * const& nsstring ) { + if( !nsstring ) + return "nil"; + return "@" + toString([nsstring UTF8String]); + } + std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) { + if( !nsstring ) + return "nil"; + return "@" + toString([nsstring UTF8String]); + } + std::string toString( NSObject* const& nsObject ) { + return toString( [nsObject description] ); + } +#endif + +} // end namespace Catch + +// #included from: catch_result_builder.hpp +#define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED + +namespace Catch { + + std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) { + return secondArg.empty() || secondArg == "\"\"" + ? capturedExpression + : capturedExpression + ", " + secondArg; + } + ResultBuilder::ResultBuilder( char const* macroName, + SourceLineInfo const& lineInfo, + char const* capturedExpression, + ResultDisposition::Flags resultDisposition, + char const* secondArg ) + : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ), + m_shouldDebugBreak( false ), + m_shouldThrow( false ), + m_guardException( false ) + {} + + ResultBuilder::~ResultBuilder() { +#if defined(CATCH_CONFIG_FAST_COMPILE) + if ( m_guardException ) { + m_stream.oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"; + captureResult( ResultWas::ThrewException ); + getCurrentContext().getResultCapture()->exceptionEarlyReported(); + } +#endif + } + + ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) { + m_data.resultType = result; + return *this; + } + ResultBuilder& ResultBuilder::setResultType( bool result ) { + m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; + return *this; + } + + void ResultBuilder::endExpression( DecomposedExpression const& expr ) { + AssertionResult result = build( expr ); + handleResult( result ); + } + + void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) { + m_assertionInfo.resultDisposition = resultDisposition; + m_stream.oss << Catch::translateActiveException(); + captureResult( ResultWas::ThrewException ); + } + + void ResultBuilder::captureResult( ResultWas::OfType resultType ) { + setResultType( resultType ); + captureExpression(); + } + + void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) { + if( expectedMessage.empty() ) + captureExpectedException( Matchers::Impl::MatchAllOf() ); + else + captureExpectedException( Matchers::Equals( expectedMessage ) ); + } + + void ResultBuilder::captureExpectedException( Matchers::Impl::MatcherBase const& matcher ) { + + assert( !isFalseTest( m_assertionInfo.resultDisposition ) ); + AssertionResultData data = m_data; + data.resultType = ResultWas::Ok; + data.reconstructedExpression = m_assertionInfo.capturedExpression; + + std::string actualMessage = Catch::translateActiveException(); + if( !matcher.match( actualMessage ) ) { + data.resultType = ResultWas::ExpressionFailed; + data.reconstructedExpression = actualMessage; + } + AssertionResult result( m_assertionInfo, data ); + handleResult( result ); + } + + void ResultBuilder::captureExpression() { + AssertionResult result = build(); + handleResult( result ); + } + + void ResultBuilder::handleResult( AssertionResult const& result ) + { + getResultCapture().assertionEnded( result ); + + if( !result.isOk() ) { + if( getCurrentContext().getConfig()->shouldDebugBreak() ) + m_shouldDebugBreak = true; + if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) ) + m_shouldThrow = true; + } + } + + void ResultBuilder::react() { +#if defined(CATCH_CONFIG_FAST_COMPILE) + if (m_shouldDebugBreak) { + /////////////////////////////////////////////////////////////////// + // To inspect the state during test, you need to go one level up the callstack + // To go back to the test and change execution, jump over the throw statement + /////////////////////////////////////////////////////////////////// + CATCH_BREAK_INTO_DEBUGGER(); + } +#endif + if( m_shouldThrow ) + throw Catch::TestFailureException(); + } + + bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; } + bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); } + + AssertionResult ResultBuilder::build() const + { + return build( *this ); + } + + // CAVEAT: The returned AssertionResult stores a pointer to the argument expr, + // a temporary DecomposedExpression, which in turn holds references to + // operands, possibly temporary as well. + // It should immediately be passed to handleResult; if the expression + // needs to be reported, its string expansion must be composed before + // the temporaries are destroyed. + AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const + { + assert( m_data.resultType != ResultWas::Unknown ); + AssertionResultData data = m_data; + + // Flip bool results if FalseTest flag is set + if( isFalseTest( m_assertionInfo.resultDisposition ) ) { + data.negate( expr.isBinaryExpression() ); + } + + data.message = m_stream.oss.str(); + data.decomposedExpression = &expr; // for lazy reconstruction + return AssertionResult( m_assertionInfo, data ); + } + + void ResultBuilder::reconstructExpression( std::string& dest ) const { + dest = m_assertionInfo.capturedExpression; + } + + void ResultBuilder::setExceptionGuard() { + m_guardException = true; + } + void ResultBuilder::unsetExceptionGuard() { + m_guardException = false; + } + +} // end namespace Catch + +// #included from: catch_tag_alias_registry.hpp +#define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED + +namespace Catch { + + TagAliasRegistry::~TagAliasRegistry() {} + + Option TagAliasRegistry::find( std::string const& alias ) const { + std::map::const_iterator it = m_registry.find( alias ); + if( it != m_registry.end() ) + return it->second; + else + return Option(); + } + + std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { + std::string expandedTestSpec = unexpandedTestSpec; + for( std::map::const_iterator it = m_registry.begin(), itEnd = m_registry.end(); + it != itEnd; + ++it ) { + std::size_t pos = expandedTestSpec.find( it->first ); + if( pos != std::string::npos ) { + expandedTestSpec = expandedTestSpec.substr( 0, pos ) + + it->second.tag + + expandedTestSpec.substr( pos + it->first.size() ); + } + } + return expandedTestSpec; + } + + void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) { + + if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) { + std::ostringstream oss; + oss << Colour( Colour::Red ) + << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" + << Colour( Colour::FileName ) + << lineInfo << '\n'; + throw std::domain_error( oss.str().c_str() ); + } + if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) { + std::ostringstream oss; + oss << Colour( Colour::Red ) + << "error: tag alias, \"" << alias << "\" already registered.\n" + << "\tFirst seen at " + << Colour( Colour::Red ) << find(alias)->lineInfo << '\n' + << Colour( Colour::Red ) << "\tRedefined at " + << Colour( Colour::FileName) << lineInfo << '\n'; + throw std::domain_error( oss.str().c_str() ); + } + } + + ITagAliasRegistry::~ITagAliasRegistry() {} + + ITagAliasRegistry const& ITagAliasRegistry::get() { + return getRegistryHub().getTagAliasRegistry(); + } + + RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { + getMutableRegistryHub().registerTagAlias( alias, tag, lineInfo ); + } + +} // end namespace Catch + +// #included from: catch_matchers_string.hpp + +namespace Catch { +namespace Matchers { + + namespace StdString { + + CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_str( adjustString( str ) ) + {} + std::string CasedString::adjustString( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No + ? toLower( str ) + : str; + } + std::string CasedString::caseSensitivitySuffix() const { + return m_caseSensitivity == CaseSensitive::No + ? " (case insensitive)" + : std::string(); + } + + StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) + : m_comparator( comparator ), + m_operation( operation ) { + } + + std::string StringMatcherBase::describe() const { + std::string description; + description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + + m_comparator.caseSensitivitySuffix().size()); + description += m_operation; + description += ": \""; + description += m_comparator.m_str; + description += "\""; + description += m_comparator.caseSensitivitySuffix(); + return description; + } + + EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} + + bool EqualsMatcher::match( std::string const& source ) const { + return m_comparator.adjustString( source ) == m_comparator.m_str; + } + + ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} + + bool ContainsMatcher::match( std::string const& source ) const { + return contains( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} + + bool StartsWithMatcher::match( std::string const& source ) const { + return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} + + bool EndsWithMatcher::match( std::string const& source ) const { + return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); + } + + } // namespace StdString + + StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); + } + +} // namespace Matchers +} // namespace Catch +// #included from: ../reporters/catch_reporter_multi.hpp +#define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED + +namespace Catch { + +class MultipleReporters : public SharedImpl { + typedef std::vector > Reporters; + Reporters m_reporters; + +public: + void add( Ptr const& reporter ) { + m_reporters.push_back( reporter ); + } + +public: // IStreamingReporter + + virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { + return m_reporters[0]->getPreferences(); + } + + virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->noMatchingTestCases( spec ); + } + + virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testRunStarting( testRunInfo ); + } + + virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testGroupStarting( groupInfo ); + } + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testCaseStarting( testInfo ); + } + + virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->sectionStarting( sectionInfo ); + } + + virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->assertionStarting( assertionInfo ); + } + + // The return value indicates if the messages buffer should be cleared: + virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { + bool clearBuffer = false; + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + clearBuffer |= (*it)->assertionEnded( assertionStats ); + return clearBuffer; + } + + virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->sectionEnded( sectionStats ); + } + + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testCaseEnded( testCaseStats ); + } + + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testGroupEnded( testGroupStats ); + } + + virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->testRunEnded( testRunStats ); + } + + virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { + for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); + it != itEnd; + ++it ) + (*it)->skipTest( testInfo ); + } + + virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE { + return this; + } + +}; + +Ptr addReporter( Ptr const& existingReporter, Ptr const& additionalReporter ) { + Ptr resultingReporter; + + if( existingReporter ) { + MultipleReporters* multi = existingReporter->tryAsMulti(); + if( !multi ) { + multi = new MultipleReporters; + resultingReporter = Ptr( multi ); + if( existingReporter ) + multi->add( existingReporter ); + } + else + resultingReporter = existingReporter; + multi->add( additionalReporter ); + } + else + resultingReporter = additionalReporter; + + return resultingReporter; +} + +} // end namespace Catch + +// #included from: ../reporters/catch_reporter_xml.hpp +#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED + +// #included from: catch_reporter_bases.hpp +#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED + +#include +#include +#include +#include + +namespace Catch { + + namespace { + // Because formatting using c++ streams is stateful, drop down to C is required + // Alternatively we could use stringstream, but its performance is... not good. + std::string getFormattedDuration( double duration ) { + // Max exponent + 1 is required to represent the whole part + // + 1 for decimal point + // + 3 for the 3 decimal places + // + 1 for null terminator + const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + char buffer[maxDoubleSize]; + + // Save previous errno, to prevent sprintf from overwriting it + ErrnoGuard guard; +#ifdef _MSC_VER + sprintf_s(buffer, "%.3f", duration); +#else + sprintf(buffer, "%.3f", duration); +#endif + return std::string(buffer); + } + } + + struct StreamingReporterBase : SharedImpl { + + StreamingReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + } + + virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { + return m_reporterPrefs; + } + + virtual ~StreamingReporterBase() CATCH_OVERRIDE; + + virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {} + + virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE { + currentTestRunInfo = _testRunInfo; + } + virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE { + currentGroupInfo = _groupInfo; + } + + virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE { + currentTestCaseInfo = _testInfo; + } + virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE { + m_sectionStack.push_back( _sectionInfo ); + } + + virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE { + m_sectionStack.pop_back(); + } + virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE { + currentTestCaseInfo.reset(); + } + virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE { + currentGroupInfo.reset(); + } + virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE { + currentTestCaseInfo.reset(); + currentGroupInfo.reset(); + currentTestRunInfo.reset(); + } + + virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE { + // Don't do anything with this by default. + // It can optionally be overridden in the derived class. + } + + Ptr m_config; + std::ostream& stream; + + LazyStat currentTestRunInfo; + LazyStat currentGroupInfo; + LazyStat currentTestCaseInfo; + + std::vector m_sectionStack; + ReporterPreferences m_reporterPrefs; + }; + + struct CumulativeReporterBase : SharedImpl { + template + struct Node : SharedImpl<> { + explicit Node( T const& _value ) : value( _value ) {} + virtual ~Node() {} + + typedef std::vector > ChildNodes; + T value; + ChildNodes children; + }; + struct SectionNode : SharedImpl<> { + explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {} + virtual ~SectionNode(); + + bool operator == ( SectionNode const& other ) const { + return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; + } + bool operator == ( Ptr const& other ) const { + return operator==( *other ); + } + + SectionStats stats; + typedef std::vector > ChildSections; + typedef std::vector Assertions; + ChildSections childSections; + Assertions assertions; + std::string stdOut; + std::string stdErr; + }; + + struct BySectionInfo { + BySectionInfo( SectionInfo const& other ) : m_other( other ) {} + BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} + bool operator() ( Ptr const& node ) const { + return node->stats.sectionInfo.lineInfo == m_other.lineInfo; + } + private: + void operator=( BySectionInfo const& ); + SectionInfo const& m_other; + }; + + typedef Node TestCaseNode; + typedef Node TestGroupNode; + typedef Node TestRunNode; + + CumulativeReporterBase( ReporterConfig const& _config ) + : m_config( _config.fullConfig() ), + stream( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = false; + } + ~CumulativeReporterBase(); + + virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { + return m_reporterPrefs; + } + + virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {} + virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {} + + virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {} + + virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { + SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); + Ptr node; + if( m_sectionStack.empty() ) { + if( !m_rootSection ) + m_rootSection = new SectionNode( incompleteStats ); + node = m_rootSection; + } + else { + SectionNode& parentNode = *m_sectionStack.back(); + SectionNode::ChildSections::const_iterator it = + std::find_if( parentNode.childSections.begin(), + parentNode.childSections.end(), + BySectionInfo( sectionInfo ) ); + if( it == parentNode.childSections.end() ) { + node = new SectionNode( incompleteStats ); + parentNode.childSections.push_back( node ); + } + else + node = *it; + } + m_sectionStack.push_back( node ); + m_deepestSection = node; + } + + virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {} + + virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { + assert( !m_sectionStack.empty() ); + SectionNode& sectionNode = *m_sectionStack.back(); + sectionNode.assertions.push_back( assertionStats ); + // AssertionResult holds a pointer to a temporary DecomposedExpression, + // which getExpandedExpression() calls to build the expression string. + // Our section stack copy of the assertionResult will likely outlive the + // temporary, so it must be expanded or discarded now to avoid calling + // a destroyed object later. + prepareExpandedExpression( sectionNode.assertions.back().assertionResult ); + return true; + } + virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { + assert( !m_sectionStack.empty() ); + SectionNode& node = *m_sectionStack.back(); + node.stats = sectionStats; + m_sectionStack.pop_back(); + } + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { + Ptr node = new TestCaseNode( testCaseStats ); + assert( m_sectionStack.size() == 0 ); + node->children.push_back( m_rootSection ); + m_testCases.push_back( node ); + m_rootSection.reset(); + + assert( m_deepestSection ); + m_deepestSection->stdOut = testCaseStats.stdOut; + m_deepestSection->stdErr = testCaseStats.stdErr; + } + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { + Ptr node = new TestGroupNode( testGroupStats ); + node->children.swap( m_testCases ); + m_testGroups.push_back( node ); + } + virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { + Ptr node = new TestRunNode( testRunStats ); + node->children.swap( m_testGroups ); + m_testRuns.push_back( node ); + testRunEndedCumulative(); + } + virtual void testRunEndedCumulative() = 0; + + virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {} + + virtual void prepareExpandedExpression( AssertionResult& result ) const { + if( result.isOk() ) + result.discardDecomposedExpression(); + else + result.expandDecomposedExpression(); + } + + Ptr m_config; + std::ostream& stream; + std::vector m_assertions; + std::vector > > m_sections; + std::vector > m_testCases; + std::vector > m_testGroups; + + std::vector > m_testRuns; + + Ptr m_rootSection; + Ptr m_deepestSection; + std::vector > m_sectionStack; + ReporterPreferences m_reporterPrefs; + + }; + + template + char const* getLineOfChars() { + static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; + if( !*line ) { + std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; + } + return line; + } + + struct TestEventListenerBase : StreamingReporterBase { + TestEventListenerBase( ReporterConfig const& _config ) + : StreamingReporterBase( _config ) + {} + + virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {} + virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE { + return false; + } + }; + +} // end namespace Catch + +// #included from: ../internal/catch_reporter_registrars.hpp +#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED + +namespace Catch { + + template + class LegacyReporterRegistrar { + + class ReporterFactory : public IReporterFactory { + virtual IStreamingReporter* create( ReporterConfig const& config ) const { + return new LegacyReporterAdapter( new T( config ) ); + } + + virtual std::string getDescription() const { + return T::getDescription(); + } + }; + + public: + + LegacyReporterRegistrar( std::string const& name ) { + getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); + } + }; + + template + class ReporterRegistrar { + + class ReporterFactory : public SharedImpl { + + // *** Please Note ***: + // - If you end up here looking at a compiler error because it's trying to register + // your custom reporter class be aware that the native reporter interface has changed + // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via + // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter. + // However please consider updating to the new interface as the old one is now + // deprecated and will probably be removed quite soon! + // Please contact me via github if you have any questions at all about this. + // In fact, ideally, please contact me anyway to let me know you've hit this - as I have + // no idea who is actually using custom reporters at all (possibly no-one!). + // The new interface is designed to minimise exposure to interface changes in the future. + virtual IStreamingReporter* create( ReporterConfig const& config ) const { + return new T( config ); + } + + virtual std::string getDescription() const { + return T::getDescription(); + } + }; + + public: + + ReporterRegistrar( std::string const& name ) { + getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); + } + }; + + template + class ListenerRegistrar { + + class ListenerFactory : public SharedImpl { + + virtual IStreamingReporter* create( ReporterConfig const& config ) const { + return new T( config ); + } + virtual std::string getDescription() const { + return std::string(); + } + }; + + public: + + ListenerRegistrar() { + getMutableRegistryHub().registerListener( new ListenerFactory() ); + } + }; +} + +#define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \ + namespace{ Catch::LegacyReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } + +#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ + namespace{ Catch::ReporterRegistrar catch_internal_RegistrarFor##reporterType( name ); } + +// Deprecated - use the form without INTERNAL_ +#define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \ + namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } + +#define CATCH_REGISTER_LISTENER( listenerType ) \ + namespace{ Catch::ListenerRegistrar catch_internal_RegistrarFor##listenerType; } + +// #included from: ../internal/catch_xmlwriter.hpp +#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED + +#include +#include +#include +#include + +namespace Catch { + + class XmlEncode { + public: + enum ForWhat { ForTextNodes, ForAttributes }; + + XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ) + : m_str( str ), + m_forWhat( forWhat ) + {} + + void encodeTo( std::ostream& os ) const { + + // Apostrophe escaping not necessary if we always use " to write attributes + // (see: http://www.w3.org/TR/xml/#syntax) + + for( std::size_t i = 0; i < m_str.size(); ++ i ) { + char c = m_str[i]; + switch( c ) { + case '<': os << "<"; break; + case '&': os << "&"; break; + + case '>': + // See: http://www.w3.org/TR/xml/#syntax + if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' ) + os << ">"; + else + os << c; + break; + + case '\"': + if( m_forWhat == ForAttributes ) + os << """; + else + os << c; + break; + + default: + // Escape control chars - based on contribution by @espenalb in PR #465 and + // by @mrpi PR #588 + if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) { + // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) + << static_cast( c ); + } + else + os << c; + } + } + } + + friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { + xmlEncode.encodeTo( os ); + return os; + } + + private: + std::string m_str; + ForWhat m_forWhat; + }; + + class XmlWriter { + public: + + class ScopedElement { + public: + ScopedElement( XmlWriter* writer ) + : m_writer( writer ) + {} + + ScopedElement( ScopedElement const& other ) + : m_writer( other.m_writer ){ + other.m_writer = CATCH_NULL; + } + + ~ScopedElement() { + if( m_writer ) + m_writer->endElement(); + } + + ScopedElement& writeText( std::string const& text, bool indent = true ) { + m_writer->writeText( text, indent ); + return *this; + } + + template + ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + private: + mutable XmlWriter* m_writer; + }; + + XmlWriter() + : m_tagIsOpen( false ), + m_needsNewline( false ), + m_os( Catch::cout() ) + { + writeDeclaration(); + } + + XmlWriter( std::ostream& os ) + : m_tagIsOpen( false ), + m_needsNewline( false ), + m_os( os ) + { + writeDeclaration(); + } + + ~XmlWriter() { + while( !m_tags.empty() ) + endElement(); + } + + XmlWriter& startElement( std::string const& name ) { + ensureTagClosed(); + newlineIfNecessary(); + m_os << m_indent << '<' << name; + m_tags.push_back( name ); + m_indent += " "; + m_tagIsOpen = true; + return *this; + } + + ScopedElement scopedElement( std::string const& name ) { + ScopedElement scoped( this ); + startElement( name ); + return scoped; + } + + XmlWriter& endElement() { + newlineIfNecessary(); + m_indent = m_indent.substr( 0, m_indent.size()-2 ); + if( m_tagIsOpen ) { + m_os << "/>"; + m_tagIsOpen = false; + } + else { + m_os << m_indent << ""; + } + m_os << std::endl; + m_tags.pop_back(); + return *this; + } + + XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { + if( !name.empty() && !attribute.empty() ) + m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; + return *this; + } + + XmlWriter& writeAttribute( std::string const& name, bool attribute ) { + m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; + return *this; + } + + template + XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { + std::ostringstream oss; + oss << attribute; + return writeAttribute( name, oss.str() ); + } + + XmlWriter& writeText( std::string const& text, bool indent = true ) { + if( !text.empty() ){ + bool tagWasOpen = m_tagIsOpen; + ensureTagClosed(); + if( tagWasOpen && indent ) + m_os << m_indent; + m_os << XmlEncode( text ); + m_needsNewline = true; + } + return *this; + } + + XmlWriter& writeComment( std::string const& text ) { + ensureTagClosed(); + m_os << m_indent << ""; + m_needsNewline = true; + return *this; + } + + void writeStylesheetRef( std::string const& url ) { + m_os << "\n"; + } + + XmlWriter& writeBlankLine() { + ensureTagClosed(); + m_os << '\n'; + return *this; + } + + void ensureTagClosed() { + if( m_tagIsOpen ) { + m_os << ">" << std::endl; + m_tagIsOpen = false; + } + } + + private: + XmlWriter( XmlWriter const& ); + void operator=( XmlWriter const& ); + + void writeDeclaration() { + m_os << "\n"; + } + + void newlineIfNecessary() { + if( m_needsNewline ) { + m_os << std::endl; + m_needsNewline = false; + } + } + + bool m_tagIsOpen; + bool m_needsNewline; + std::vector m_tags; + std::string m_indent; + std::ostream& m_os; + }; + +} +// #included from: catch_reenable_warnings.h + +#define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(pop) +# else +# pragma clang diagnostic pop +# endif +#elif defined __GNUC__ +# pragma GCC diagnostic pop +#endif + + +namespace Catch { + class XmlReporter : public StreamingReporterBase { + public: + XmlReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ), + m_xml(_config.stream()), + m_sectionDepth( 0 ) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + virtual ~XmlReporter() CATCH_OVERRIDE; + + static std::string getDescription() { + return "Reports test results as an XML document"; + } + + virtual std::string getStylesheetRef() const { + return std::string(); + } + + void writeSourceInfo( SourceLineInfo const& sourceInfo ) { + m_xml + .writeAttribute( "filename", sourceInfo.file ) + .writeAttribute( "line", sourceInfo.line ); + } + + public: // StreamingReporterBase + + virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE { + StreamingReporterBase::noMatchingTestCases( s ); + } + + virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE { + StreamingReporterBase::testRunStarting( testInfo ); + std::string stylesheetRef = getStylesheetRef(); + if( !stylesheetRef.empty() ) + m_xml.writeStylesheetRef( stylesheetRef ); + m_xml.startElement( "Catch" ); + if( !m_config->name().empty() ) + m_xml.writeAttribute( "name", m_config->name() ); + } + + virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { + StreamingReporterBase::testGroupStarting( groupInfo ); + m_xml.startElement( "Group" ) + .writeAttribute( "name", groupInfo.name ); + } + + virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { + StreamingReporterBase::testCaseStarting(testInfo); + m_xml.startElement( "TestCase" ) + .writeAttribute( "name", trim( testInfo.name ) ) + .writeAttribute( "description", testInfo.description ) + .writeAttribute( "tags", testInfo.tagsAsString ); + + writeSourceInfo( testInfo.lineInfo ); + + if ( m_config->showDurations() == ShowDurations::Always ) + m_testCaseTimer.start(); + m_xml.ensureTagClosed(); + } + + virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { + StreamingReporterBase::sectionStarting( sectionInfo ); + if( m_sectionDepth++ > 0 ) { + m_xml.startElement( "Section" ) + .writeAttribute( "name", trim( sectionInfo.name ) ) + .writeAttribute( "description", sectionInfo.description ); + writeSourceInfo( sectionInfo.lineInfo ); + m_xml.ensureTagClosed(); + } + } + + virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { } + + virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { + + AssertionResult const& result = assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + if( includeResults ) { + // Print any info messages in tags. + for( std::vector::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); + it != itEnd; + ++it ) { + if( it->type == ResultWas::Info ) { + m_xml.scopedElement( "Info" ) + .writeText( it->message ); + } else if ( it->type == ResultWas::Warning ) { + m_xml.scopedElement( "Warning" ) + .writeText( it->message ); + } + } + } + + // Drop out if result was successful but we're not printing them. + if( !includeResults && result.getResultType() != ResultWas::Warning ) + return true; + + // Print the expression if there is one. + if( result.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", result.succeeded() ) + .writeAttribute( "type", result.getTestMacroName() ); + + writeSourceInfo( result.getSourceInfo() ); + + m_xml.scopedElement( "Original" ) + .writeText( result.getExpression() ); + m_xml.scopedElement( "Expanded" ) + .writeText( result.getExpandedExpression() ); + } + + // And... Print a result applicable to each result type. + switch( result.getResultType() ) { + case ResultWas::ThrewException: + m_xml.startElement( "Exception" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::FatalErrorCondition: + m_xml.startElement( "FatalErrorCondition" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + case ResultWas::Info: + m_xml.scopedElement( "Info" ) + .writeText( result.getMessage() ); + break; + case ResultWas::Warning: + // Warning will already have been written + break; + case ResultWas::ExplicitFailure: + m_xml.startElement( "Failure" ); + writeSourceInfo( result.getSourceInfo() ); + m_xml.writeText( result.getMessage() ); + m_xml.endElement(); + break; + default: + break; + } + + if( result.hasExpression() ) + m_xml.endElement(); + + return true; + } + + virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { + StreamingReporterBase::sectionEnded( sectionStats ); + if( --m_sectionDepth > 0 ) { + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); + e.writeAttribute( "successes", sectionStats.assertions.passed ); + e.writeAttribute( "failures", sectionStats.assertions.failed ); + e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); + + m_xml.endElement(); + } + } + + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { + StreamingReporterBase::testCaseEnded( testCaseStats ); + XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); + e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); + + if ( m_config->showDurations() == ShowDurations::Always ) + e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + + if( !testCaseStats.stdOut.empty() ) + m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); + if( !testCaseStats.stdErr.empty() ) + m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); + + m_xml.endElement(); + } + + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { + StreamingReporterBase::testGroupEnded( testGroupStats ); + // TODO: Check testGroupStats.aborting and act accordingly. + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) + .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { + StreamingReporterBase::testRunEnded( testRunStats ); + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", testRunStats.totals.assertions.passed ) + .writeAttribute( "failures", testRunStats.totals.assertions.failed ) + .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); + m_xml.endElement(); + } + + private: + Timer m_testCaseTimer; + XmlWriter m_xml; + int m_sectionDepth; + }; + + INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) + +} // end namespace Catch + +// #included from: ../reporters/catch_reporter_junit.hpp +#define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED + +#include + +namespace Catch { + + namespace { + std::string getCurrentTimestamp() { + // Beware, this is not reentrant because of backward compatibility issues + // Also, UTC only, again because of backward compatibility (%z is C++11) + time_t rawtime; + std::time(&rawtime); + const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z"); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &rawtime); +#else + std::tm* timeInfo; + timeInfo = std::gmtime(&rawtime); +#endif + + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + + } + + class JunitReporter : public CumulativeReporterBase { + public: + JunitReporter( ReporterConfig const& _config ) + : CumulativeReporterBase( _config ), + xml( _config.stream() ) + { + m_reporterPrefs.shouldRedirectStdOut = true; + } + + virtual ~JunitReporter() CATCH_OVERRIDE; + + static std::string getDescription() { + return "Reports test results in an XML format that looks like Ant's junitreport target"; + } + + virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {} + + virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE { + CumulativeReporterBase::testRunStarting( runInfo ); + xml.startElement( "testsuites" ); + } + + virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { + suiteTimer.start(); + stdOutForSuite.str(""); + stdErrForSuite.str(""); + unexpectedExceptions = 0; + CumulativeReporterBase::testGroupStarting( groupInfo ); + } + + virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { + if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException ) + unexpectedExceptions++; + return CumulativeReporterBase::assertionEnded( assertionStats ); + } + + virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { + stdOutForSuite << testCaseStats.stdOut; + stdErrForSuite << testCaseStats.stdErr; + CumulativeReporterBase::testCaseEnded( testCaseStats ); + } + + virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { + double suiteTime = suiteTimer.getElapsedSeconds(); + CumulativeReporterBase::testGroupEnded( testGroupStats ); + writeGroup( *m_testGroups.back(), suiteTime ); + } + + virtual void testRunEndedCumulative() CATCH_OVERRIDE { + xml.endElement(); + } + + void writeGroup( TestGroupNode const& groupNode, double suiteTime ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); + TestGroupStats const& stats = groupNode.value; + xml.writeAttribute( "name", stats.groupInfo.name ); + xml.writeAttribute( "errors", unexpectedExceptions ); + xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); + xml.writeAttribute( "tests", stats.totals.assertions.total() ); + xml.writeAttribute( "hostname", "tbd" ); // !TBD + if( m_config->showDurations() == ShowDurations::Never ) + xml.writeAttribute( "time", "" ); + else + xml.writeAttribute( "time", suiteTime ); + xml.writeAttribute( "timestamp", getCurrentTimestamp() ); + + // Write test cases + for( TestGroupNode::ChildNodes::const_iterator + it = groupNode.children.begin(), itEnd = groupNode.children.end(); + it != itEnd; + ++it ) + writeTestCase( **it ); + + xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false ); + xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); + } + + void writeTestCase( TestCaseNode const& testCaseNode ) { + TestCaseStats const& stats = testCaseNode.value; + + // All test cases have exactly one section - which represents the + // test case itself. That section may have 0-n nested sections + assert( testCaseNode.children.size() == 1 ); + SectionNode const& rootSection = *testCaseNode.children.front(); + + std::string className = stats.testInfo.className; + + if( className.empty() ) { + if( rootSection.childSections.empty() ) + className = "global"; + } + writeSection( className, "", rootSection ); + } + + void writeSection( std::string const& className, + std::string const& rootName, + SectionNode const& sectionNode ) { + std::string name = trim( sectionNode.stats.sectionInfo.name ); + if( !rootName.empty() ) + name = rootName + '/' + name; + + if( !sectionNode.assertions.empty() || + !sectionNode.stdOut.empty() || + !sectionNode.stdErr.empty() ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); + if( className.empty() ) { + xml.writeAttribute( "classname", name ); + xml.writeAttribute( "name", "root" ); + } + else { + xml.writeAttribute( "classname", className ); + xml.writeAttribute( "name", name ); + } + xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) ); + + writeAssertions( sectionNode ); + + if( !sectionNode.stdOut.empty() ) + xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); + if( !sectionNode.stdErr.empty() ) + xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); + } + for( SectionNode::ChildSections::const_iterator + it = sectionNode.childSections.begin(), + itEnd = sectionNode.childSections.end(); + it != itEnd; + ++it ) + if( className.empty() ) + writeSection( name, "", **it ); + else + writeSection( className, name, **it ); + } + + void writeAssertions( SectionNode const& sectionNode ) { + for( SectionNode::Assertions::const_iterator + it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end(); + it != itEnd; + ++it ) + writeAssertion( *it ); + } + void writeAssertion( AssertionStats const& stats ) { + AssertionResult const& result = stats.assertionResult; + if( !result.isOk() ) { + std::string elementName; + switch( result.getResultType() ) { + case ResultWas::ThrewException: + case ResultWas::FatalErrorCondition: + elementName = "error"; + break; + case ResultWas::ExplicitFailure: + elementName = "failure"; + break; + case ResultWas::ExpressionFailed: + elementName = "failure"; + break; + case ResultWas::DidntThrowException: + elementName = "failure"; + break; + + // We should never see these here: + case ResultWas::Info: + case ResultWas::Warning: + case ResultWas::Ok: + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + elementName = "internalError"; + break; + } + + XmlWriter::ScopedElement e = xml.scopedElement( elementName ); + + xml.writeAttribute( "message", result.getExpandedExpression() ); + xml.writeAttribute( "type", result.getTestMacroName() ); + + std::ostringstream oss; + if( !result.getMessage().empty() ) + oss << result.getMessage() << '\n'; + for( std::vector::const_iterator + it = stats.infoMessages.begin(), + itEnd = stats.infoMessages.end(); + it != itEnd; + ++it ) + if( it->type == ResultWas::Info ) + oss << it->message << '\n'; + + oss << "at " << result.getSourceInfo(); + xml.writeText( oss.str(), false ); + } + } + + XmlWriter xml; + Timer suiteTimer; + std::ostringstream stdOutForSuite; + std::ostringstream stdErrForSuite; + unsigned int unexpectedExceptions; + }; + + INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + +} // end namespace Catch + +// #included from: ../reporters/catch_reporter_console.hpp +#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED + +#include +#include + +namespace Catch { + + struct ConsoleReporter : StreamingReporterBase { + ConsoleReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ), + m_headerPrinted( false ) + {} + + virtual ~ConsoleReporter() CATCH_OVERRIDE; + static std::string getDescription() { + return "Reports test results as plain lines of text"; + } + + virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { + stream << "No test cases matched '" << spec << '\'' << std::endl; + } + + virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { + } + + virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE { + AssertionResult const& result = _assertionStats.assertionResult; + + bool includeResults = m_config->includeSuccessfulResults() || !result.isOk(); + + // Drop out if result was successful but we're not printing them. + if( !includeResults && result.getResultType() != ResultWas::Warning ) + return false; + + lazyPrint(); + + AssertionPrinter printer( stream, _assertionStats, includeResults ); + printer.print(); + stream << std::endl; + return true; + } + + virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE { + m_headerPrinted = false; + StreamingReporterBase::sectionStarting( _sectionInfo ); + } + virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE { + if( _sectionStats.missingAssertions ) { + lazyPrint(); + Colour colour( Colour::ResultError ); + if( m_sectionStack.size() > 1 ) + stream << "\nNo assertions in section"; + else + stream << "\nNo assertions in test case"; + stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; + } + if( m_config->showDurations() == ShowDurations::Always ) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + if( m_headerPrinted ) { + m_headerPrinted = false; + } + StreamingReporterBase::sectionEnded( _sectionStats ); + } + + virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE { + StreamingReporterBase::testCaseEnded( _testCaseStats ); + m_headerPrinted = false; + } + virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE { + if( currentGroupInfo.used ) { + printSummaryDivider(); + stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; + printTotals( _testGroupStats.totals ); + stream << '\n' << std::endl; + } + StreamingReporterBase::testGroupEnded( _testGroupStats ); + } + virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE { + printTotalsDivider( _testRunStats.totals ); + printTotals( _testRunStats.totals ); + stream << std::endl; + StreamingReporterBase::testRunEnded( _testRunStats ); + } + + private: + + class AssertionPrinter { + void operator= ( AssertionPrinter const& ); + public: + AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) + : stream( _stream ), + stats( _stats ), + result( _stats.assertionResult ), + colour( Colour::None ), + message( result.getMessage() ), + messages( _stats.infoMessages ), + printInfoMessages( _printInfoMessages ) + { + switch( result.getResultType() ) { + case ResultWas::Ok: + colour = Colour::Success; + passOrFail = "PASSED"; + //if( result.hasMessage() ) + if( _stats.infoMessages.size() == 1 ) + messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; + break; + case ResultWas::ExpressionFailed: + if( result.isOk() ) { + colour = Colour::Success; + passOrFail = "FAILED - but was ok"; + } + else { + colour = Colour::Error; + passOrFail = "FAILED"; + } + if( _stats.infoMessages.size() == 1 ) + messageLabel = "with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "with messages"; + break; + case ResultWas::ThrewException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to unexpected exception with "; + if (_stats.infoMessages.size() == 1) + messageLabel += "message"; + if (_stats.infoMessages.size() > 1) + messageLabel += "messages"; + break; + case ResultWas::FatalErrorCondition: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "due to a fatal error condition"; + break; + case ResultWas::DidntThrowException: + colour = Colour::Error; + passOrFail = "FAILED"; + messageLabel = "because no exception was thrown where one was expected"; + break; + case ResultWas::Info: + messageLabel = "info"; + break; + case ResultWas::Warning: + messageLabel = "warning"; + break; + case ResultWas::ExplicitFailure: + passOrFail = "FAILED"; + colour = Colour::Error; + if( _stats.infoMessages.size() == 1 ) + messageLabel = "explicitly with message"; + if( _stats.infoMessages.size() > 1 ) + messageLabel = "explicitly with messages"; + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + passOrFail = "** internal error **"; + colour = Colour::Error; + break; + } + } + + void print() const { + printSourceInfo(); + if( stats.totals.assertions.total() > 0 ) { + if( result.isOk() ) + stream << '\n'; + printResultType(); + printOriginalExpression(); + printReconstructedExpression(); + } + else { + stream << '\n'; + } + printMessage(); + } + + private: + void printResultType() const { + if( !passOrFail.empty() ) { + Colour colourGuard( colour ); + stream << passOrFail << ":\n"; + } + } + void printOriginalExpression() const { + if( result.hasExpression() ) { + Colour colourGuard( Colour::OriginalExpression ); + stream << " "; + stream << result.getExpressionInMacro(); + stream << '\n'; + } + } + void printReconstructedExpression() const { + if( result.hasExpandedExpression() ) { + stream << "with expansion:\n"; + Colour colourGuard( Colour::ReconstructedExpression ); + stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n'; + } + } + void printMessage() const { + if( !messageLabel.empty() ) + stream << messageLabel << ':' << '\n'; + for( std::vector::const_iterator it = messages.begin(), itEnd = messages.end(); + it != itEnd; + ++it ) { + // If this assertion is a warning ignore any INFO messages + if( printInfoMessages || it->type != ResultWas::Info ) + stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n'; + } + } + void printSourceInfo() const { + Colour colourGuard( Colour::FileName ); + stream << result.getSourceInfo() << ": "; + } + + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + Colour::Code colour; + std::string passOrFail; + std::string messageLabel; + std::string message; + std::vector messages; + bool printInfoMessages; + }; + + void lazyPrint() { + + if( !currentTestRunInfo.used ) + lazyPrintRunInfo(); + if( !currentGroupInfo.used ) + lazyPrintGroupInfo(); + + if( !m_headerPrinted ) { + printTestCaseAndSectionHeader(); + m_headerPrinted = true; + } + } + void lazyPrintRunInfo() { + stream << '\n' << getLineOfChars<'~'>() << '\n'; + Colour colour( Colour::SecondaryText ); + stream << currentTestRunInfo->name + << " is a Catch v" << libraryVersion() << " host application.\n" + << "Run with -? for options\n\n"; + + if( m_config->rngSeed() != 0 ) + stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; + + currentTestRunInfo.used = true; + } + void lazyPrintGroupInfo() { + if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) { + printClosedHeader( "Group: " + currentGroupInfo->name ); + currentGroupInfo.used = true; + } + } + void printTestCaseAndSectionHeader() { + assert( !m_sectionStack.empty() ); + printOpenHeader( currentTestCaseInfo->name ); + + if( m_sectionStack.size() > 1 ) { + Colour colourGuard( Colour::Headers ); + + std::vector::const_iterator + it = m_sectionStack.begin()+1, // Skip first section (test case) + itEnd = m_sectionStack.end(); + for( ; it != itEnd; ++it ) + printHeaderString( it->name, 2 ); + } + + SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; + + if( !lineInfo.empty() ){ + stream << getLineOfChars<'-'>() << '\n'; + Colour colourGuard( Colour::FileName ); + stream << lineInfo << '\n'; + } + stream << getLineOfChars<'.'>() << '\n' << std::endl; + } + + void printClosedHeader( std::string const& _name ) { + printOpenHeader( _name ); + stream << getLineOfChars<'.'>() << '\n'; + } + void printOpenHeader( std::string const& _name ) { + stream << getLineOfChars<'-'>() << '\n'; + { + Colour colourGuard( Colour::Headers ); + printHeaderString( _name ); + } + } + + // if string has a : in first line will set indent to follow it on + // subsequent lines + void printHeaderString( std::string const& _string, std::size_t indent = 0 ) { + std::size_t i = _string.find( ": " ); + if( i != std::string::npos ) + i+=2; + else + i = 0; + stream << Text( _string, TextAttributes() + .setIndent( indent+i) + .setInitialIndent( indent ) ) << '\n'; + } + + struct SummaryColumn { + + SummaryColumn( std::string const& _label, Colour::Code _colour ) + : label( _label ), + colour( _colour ) + {} + SummaryColumn addRow( std::size_t count ) { + std::ostringstream oss; + oss << count; + std::string row = oss.str(); + for( std::vector::iterator it = rows.begin(); it != rows.end(); ++it ) { + while( it->size() < row.size() ) + *it = ' ' + *it; + while( it->size() > row.size() ) + row = ' ' + row; + } + rows.push_back( row ); + return *this; + } + + std::string label; + Colour::Code colour; + std::vector rows; + + }; + + void printTotals( Totals const& totals ) { + if( totals.testCases.total() == 0 ) { + stream << Colour( Colour::Warning ) << "No tests ran\n"; + } + else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) { + stream << Colour( Colour::ResultSuccess ) << "All tests passed"; + stream << " (" + << pluralise( totals.assertions.passed, "assertion" ) << " in " + << pluralise( totals.testCases.passed, "test case" ) << ')' + << '\n'; + } + else { + + std::vector columns; + columns.push_back( SummaryColumn( "", Colour::None ) + .addRow( totals.testCases.total() ) + .addRow( totals.assertions.total() ) ); + columns.push_back( SummaryColumn( "passed", Colour::Success ) + .addRow( totals.testCases.passed ) + .addRow( totals.assertions.passed ) ); + columns.push_back( SummaryColumn( "failed", Colour::ResultError ) + .addRow( totals.testCases.failed ) + .addRow( totals.assertions.failed ) ); + columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure ) + .addRow( totals.testCases.failedButOk ) + .addRow( totals.assertions.failedButOk ) ); + + printSummaryRow( "test cases", columns, 0 ); + printSummaryRow( "assertions", columns, 1 ); + } + } + void printSummaryRow( std::string const& label, std::vector const& cols, std::size_t row ) { + for( std::vector::const_iterator it = cols.begin(); it != cols.end(); ++it ) { + std::string value = it->rows[row]; + if( it->label.empty() ) { + stream << label << ": "; + if( value != "0" ) + stream << value; + else + stream << Colour( Colour::Warning ) << "- none -"; + } + else if( value != "0" ) { + stream << Colour( Colour::LightGrey ) << " | "; + stream << Colour( it->colour ) + << value << ' ' << it->label; + } + } + stream << '\n'; + } + + static std::size_t makeRatio( std::size_t number, std::size_t total ) { + std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; + return ( ratio == 0 && number > 0 ) ? 1 : ratio; + } + static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { + if( i > j && i > k ) + return i; + else if( j > k ) + return j; + else + return k; + } + + void printTotalsDivider( Totals const& totals ) { + if( totals.testCases.total() > 0 ) { + std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() ); + std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() ); + std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() ); + while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 ) + findMax( failedRatio, failedButOkRatio, passedRatio )++; + while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 ) + findMax( failedRatio, failedButOkRatio, passedRatio )--; + + stream << Colour( Colour::Error ) << std::string( failedRatio, '=' ); + stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' ); + if( totals.testCases.allPassed() ) + stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' ); + else + stream << Colour( Colour::Success ) << std::string( passedRatio, '=' ); + } + else { + stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); + } + stream << '\n'; + } + void printSummaryDivider() { + stream << getLineOfChars<'-'>() << '\n'; + } + + private: + bool m_headerPrinted; + }; + + INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter ) + +} // end namespace Catch + +// #included from: ../reporters/catch_reporter_compact.hpp +#define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED + +namespace Catch { + + struct CompactReporter : StreamingReporterBase { + + CompactReporter( ReporterConfig const& _config ) + : StreamingReporterBase( _config ) + {} + + virtual ~CompactReporter(); + + static std::string getDescription() { + return "Reports test results on a single line, suitable for IDEs"; + } + + virtual ReporterPreferences getPreferences() const { + ReporterPreferences prefs; + prefs.shouldRedirectStdOut = false; + return prefs; + } + + virtual void noMatchingTestCases( std::string const& spec ) { + stream << "No test cases matched '" << spec << '\'' << std::endl; + } + + virtual void assertionStarting( AssertionInfo const& ) {} + + virtual bool assertionEnded( AssertionStats const& _assertionStats ) { + AssertionResult const& result = _assertionStats.assertionResult; + + bool printInfoMessages = true; + + // Drop out if result was successful and we're not printing those + if( !m_config->includeSuccessfulResults() && result.isOk() ) { + if( result.getResultType() != ResultWas::Warning ) + return false; + printInfoMessages = false; + } + + AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); + printer.print(); + + stream << std::endl; + return true; + } + + virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE { + if (m_config->showDurations() == ShowDurations::Always) { + stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl; + } + } + + virtual void testRunEnded( TestRunStats const& _testRunStats ) { + printTotals( _testRunStats.totals ); + stream << '\n' << std::endl; + StreamingReporterBase::testRunEnded( _testRunStats ); + } + + private: + class AssertionPrinter { + void operator= ( AssertionPrinter const& ); + public: + AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) + : stream( _stream ) + , stats( _stats ) + , result( _stats.assertionResult ) + , messages( _stats.infoMessages ) + , itMessage( _stats.infoMessages.begin() ) + , printInfoMessages( _printInfoMessages ) + {} + + void print() { + printSourceInfo(); + + itMessage = messages.begin(); + + switch( result.getResultType() ) { + case ResultWas::Ok: + printResultType( Colour::ResultSuccess, passedString() ); + printOriginalExpression(); + printReconstructedExpression(); + if ( ! result.hasExpression() ) + printRemainingMessages( Colour::None ); + else + printRemainingMessages(); + break; + case ResultWas::ExpressionFailed: + if( result.isOk() ) + printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) ); + else + printResultType( Colour::Error, failedString() ); + printOriginalExpression(); + printReconstructedExpression(); + printRemainingMessages(); + break; + case ResultWas::ThrewException: + printResultType( Colour::Error, failedString() ); + printIssue( "unexpected exception with message:" ); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::FatalErrorCondition: + printResultType( Colour::Error, failedString() ); + printIssue( "fatal error condition with message:" ); + printMessage(); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::DidntThrowException: + printResultType( Colour::Error, failedString() ); + printIssue( "expected exception, got none" ); + printExpressionWas(); + printRemainingMessages(); + break; + case ResultWas::Info: + printResultType( Colour::None, "info" ); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::Warning: + printResultType( Colour::None, "warning" ); + printMessage(); + printRemainingMessages(); + break; + case ResultWas::ExplicitFailure: + printResultType( Colour::Error, failedString() ); + printIssue( "explicitly" ); + printRemainingMessages( Colour::None ); + break; + // These cases are here to prevent compiler warnings + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + printResultType( Colour::Error, "** internal error **" ); + break; + } + } + + private: + // Colour::LightGrey + + static Colour::Code dimColour() { return Colour::FileName; } + +#ifdef CATCH_PLATFORM_MAC + static const char* failedString() { return "FAILED"; } + static const char* passedString() { return "PASSED"; } +#else + static const char* failedString() { return "failed"; } + static const char* passedString() { return "passed"; } +#endif + + void printSourceInfo() const { + Colour colourGuard( Colour::FileName ); + stream << result.getSourceInfo() << ':'; + } + + void printResultType( Colour::Code colour, std::string const& passOrFail ) const { + if( !passOrFail.empty() ) { + { + Colour colourGuard( colour ); + stream << ' ' << passOrFail; + } + stream << ':'; + } + } + + void printIssue( std::string const& issue ) const { + stream << ' ' << issue; + } + + void printExpressionWas() { + if( result.hasExpression() ) { + stream << ';'; + { + Colour colour( dimColour() ); + stream << " expression was:"; + } + printOriginalExpression(); + } + } + + void printOriginalExpression() const { + if( result.hasExpression() ) { + stream << ' ' << result.getExpression(); + } + } + + void printReconstructedExpression() const { + if( result.hasExpandedExpression() ) { + { + Colour colour( dimColour() ); + stream << " for: "; + } + stream << result.getExpandedExpression(); + } + } + + void printMessage() { + if ( itMessage != messages.end() ) { + stream << " '" << itMessage->message << '\''; + ++itMessage; + } + } + + void printRemainingMessages( Colour::Code colour = dimColour() ) { + if ( itMessage == messages.end() ) + return; + + // using messages.end() directly yields compilation error: + std::vector::const_iterator itEnd = messages.end(); + const std::size_t N = static_cast( std::distance( itMessage, itEnd ) ); + + { + Colour colourGuard( colour ); + stream << " with " << pluralise( N, "message" ) << ':'; + } + + for(; itMessage != itEnd; ) { + // If this assertion is a warning ignore any INFO messages + if( printInfoMessages || itMessage->type != ResultWas::Info ) { + stream << " '" << itMessage->message << '\''; + if ( ++itMessage != itEnd ) { + Colour colourGuard( dimColour() ); + stream << " and"; + } + } + } + } + + private: + std::ostream& stream; + AssertionStats const& stats; + AssertionResult const& result; + std::vector messages; + std::vector::const_iterator itMessage; + bool printInfoMessages; + }; + + // Colour, message variants: + // - white: No tests ran. + // - red: Failed [both/all] N test cases, failed [both/all] M assertions. + // - white: Passed [both/all] N test cases (no assertions). + // - red: Failed N tests cases, failed M assertions. + // - green: Passed [both/all] N tests cases with M assertions. + + std::string bothOrAll( std::size_t count ) const { + return count == 1 ? std::string() : count == 2 ? "both " : "all " ; + } + + void printTotals( const Totals& totals ) const { + if( totals.testCases.total() == 0 ) { + stream << "No tests ran."; + } + else if( totals.testCases.failed == totals.testCases.total() ) { + Colour colour( Colour::ResultError ); + const std::string qualify_assertions_failed = + totals.assertions.failed == totals.assertions.total() ? + bothOrAll( totals.assertions.failed ) : std::string(); + stream << + "Failed " << bothOrAll( totals.testCases.failed ) + << pluralise( totals.testCases.failed, "test case" ) << ", " + "failed " << qualify_assertions_failed << + pluralise( totals.assertions.failed, "assertion" ) << '.'; + } + else if( totals.assertions.total() == 0 ) { + stream << + "Passed " << bothOrAll( totals.testCases.total() ) + << pluralise( totals.testCases.total(), "test case" ) + << " (no assertions)."; + } + else if( totals.assertions.failed ) { + Colour colour( Colour::ResultError ); + stream << + "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " + "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.'; + } + else { + Colour colour( Colour::ResultSuccess ); + stream << + "Passed " << bothOrAll( totals.testCases.passed ) + << pluralise( totals.testCases.passed, "test case" ) << + " with " << pluralise( totals.assertions.passed, "assertion" ) << '.'; + } + } + }; + + INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter ) + +} // end namespace Catch + +namespace Catch { + // These are all here to avoid warnings about not having any out of line + // virtual methods + NonCopyable::~NonCopyable() {} + IShared::~IShared() {} + IStream::~IStream() CATCH_NOEXCEPT {} + FileStream::~FileStream() CATCH_NOEXCEPT {} + CoutStream::~CoutStream() CATCH_NOEXCEPT {} + DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {} + StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {} + IContext::~IContext() {} + IResultCapture::~IResultCapture() {} + ITestCase::~ITestCase() {} + ITestCaseRegistry::~ITestCaseRegistry() {} + IRegistryHub::~IRegistryHub() {} + IMutableRegistryHub::~IMutableRegistryHub() {} + IExceptionTranslator::~IExceptionTranslator() {} + IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} + IReporter::~IReporter() {} + IReporterFactory::~IReporterFactory() {} + IReporterRegistry::~IReporterRegistry() {} + IStreamingReporter::~IStreamingReporter() {} + AssertionStats::~AssertionStats() {} + SectionStats::~SectionStats() {} + TestCaseStats::~TestCaseStats() {} + TestGroupStats::~TestGroupStats() {} + TestRunStats::~TestRunStats() {} + CumulativeReporterBase::SectionNode::~SectionNode() {} + CumulativeReporterBase::~CumulativeReporterBase() {} + + StreamingReporterBase::~StreamingReporterBase() {} + ConsoleReporter::~ConsoleReporter() {} + CompactReporter::~CompactReporter() {} + IRunner::~IRunner() {} + IMutableContext::~IMutableContext() {} + IConfig::~IConfig() {} + XmlReporter::~XmlReporter() {} + JunitReporter::~JunitReporter() {} + TestRegistry::~TestRegistry() {} + FreeFunctionTestCase::~FreeFunctionTestCase() {} + IGeneratorInfo::~IGeneratorInfo() {} + IGeneratorsForTest::~IGeneratorsForTest() {} + WildcardPattern::~WildcardPattern() {} + TestSpec::Pattern::~Pattern() {} + TestSpec::NamePattern::~NamePattern() {} + TestSpec::TagPattern::~TagPattern() {} + TestSpec::ExcludedPattern::~ExcludedPattern() {} + Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {} + + void Config::dummy() {} + + namespace TestCaseTracking { + ITracker::~ITracker() {} + TrackerBase::~TrackerBase() {} + SectionTracker::~SectionTracker() {} + IndexTracker::~IndexTracker() {} + } +} + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#endif + +#ifdef CATCH_CONFIG_MAIN +// #included from: internal/catch_default_main.hpp +#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED + +#ifndef __OBJC__ + +// Standard C/C++ main entry point +int main (int argc, char * argv[]) { + int result = Catch::Session().run( argc, argv ); + return ( result < 0xff ? result : 0xff ); +} + +#else // __OBJC__ + +// Objective-C entry point +int main (int argc, char * const argv[]) { +#if !CATCH_ARC_ENABLED + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; +#endif + + Catch::registerTestMethods(); + int result = Catch::Session().run( argc, (char* const*)argv ); + +#if !CATCH_ARC_ENABLED + [pool drain]; +#endif + + return ( result < 0xff ? result : 0xff ); +} + +#endif // __OBJC__ + +#endif + +#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED +# undef CLARA_CONFIG_MAIN +#endif + +////// + +// If this config identifier is defined then all CATCH macros are prefixed with CATCH_ +#ifdef CATCH_CONFIG_PREFIX_ALL + +#if defined(CATCH_CONFIG_FAST_COMPILE) +#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr ) +#else +#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr ) +#endif + +#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr ) +#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr ) + +#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr ) +#define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr ) + +#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr ) +#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr ) + +#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#if defined(CATCH_CONFIG_FAST_COMPILE) +#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#else +#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif + +#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) +#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) ) +#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) ) + +#ifdef CATCH_CONFIG_VARIADIC_MACROS + #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) + #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) + #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) + #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) + #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) + #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) + #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) + #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#else + #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) + #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) + #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) + #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description ) + #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) + #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg ) + #define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg ) + #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg ) +#endif +#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) + +#define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) +#define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) + +#define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) + +// "BDD-style" convenience wrappers +#ifdef CATCH_CONFIG_VARIADIC_MACROS +#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +#else +#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags ) +#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) +#endif +#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" ) +#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" ) +#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" ) +#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" ) +#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" ) + +// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required +#else + +#if defined(CATCH_CONFIG_FAST_COMPILE) +#define REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE", Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr ) + +#else +#define REQUIRE( expr ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr ) +#endif + +#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr ) +#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr ) +#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr ) +#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr ) + +#define CHECK( expr ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr ) +#define CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr ) + +#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr ) +#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr ) +#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr ) +#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr ) + +#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg ) + +#if defined(CATCH_CONFIG_FAST_COMPILE) +#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#else +#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg ) +#endif + +#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) +#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) +#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) ) +#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) ) + +#ifdef CATCH_CONFIG_VARIADIC_MACROS +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) +#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) +#else +#define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) + #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) + #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) + #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description ) + #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) + #define FAIL( msg ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg ) + #define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg ) + #define SUCCEED( msg ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg ) +#endif +#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) + +#define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) +#define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) + +#define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) + +#endif + +#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) + +// "BDD-style" convenience wrappers +#ifdef CATCH_CONFIG_VARIADIC_MACROS +#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) +#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) +#else +#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags ) +#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) +#endif +#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" ) +#define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" ) +#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" ) +#define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" ) +#define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" ) + +using Catch::Detail::Approx; + +#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED + diff --git a/unit/catch_example.cpp b/unit/catch_example.cpp new file mode 100644 index 00000000000..8a7b237fe71 --- /dev/null +++ b/unit/catch_example.cpp @@ -0,0 +1,25 @@ +/*******************************************************************\ + + Module: Example Catch Tests + + Author: DiffBlue Limited. All rights reserved. + +\*******************************************************************/ + +#include + +unsigned int Factorial(unsigned int number) +{ + return number>1?Factorial(number-1)*number:1; +} + +// This is an example unit test to demonstrate the build system and the +// catch unit test framework. The source code is taken from the documentation +// of catch. +TEST_CASE("Factorials are computed", "[core][factorial]") +{ + REQUIRE(Factorial(1)==1); + REQUIRE(Factorial(2)==2); + REQUIRE(Factorial(3)==6); + REQUIRE(Factorial(10)==3628800); +} diff --git a/unit/miniBDD.cpp b/unit/miniBDD.cpp index ecda45a4ff1..d0eba414184 100644 --- a/unit/miniBDD.cpp +++ b/unit/miniBDD.cpp @@ -18,7 +18,7 @@ void test1() mini_bddt x=mgr.Var("x"); mini_bddt y=mgr.Var("y"); mini_bddt z=mgr.Var("z"); - mini_bddt f=(x&y&z)|(!x&!y&z); + mini_bddt f=(x&y&z)|((!x)&(!y)&z); y.clear(); x.clear(); z.clear(); diff --git a/unit/unicode.cpp b/unit/unicode.cpp new file mode 100644 index 00000000000..9670856419f --- /dev/null +++ b/unit/unicode.cpp @@ -0,0 +1,94 @@ +/*******************************************************************\ + +Module: Unicode conversion tests. + +Author: Vojtech Forejt, forejtv@diffblue.com + +\*******************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +// This unit test compares our implementation with codecvt implementation, +// checking bit-by-bit equivalence of results. + +bool paranoid_wstr_equals(const std::wstring &a, const std::wstring &b) +{ + if(a.size() != b.size()) + return false; + const char + *pa=reinterpret_cast(&a[0]), + *pb=reinterpret_cast(&b[0]); + for(std::size_t i=0; ib.size())?a.size():b.size(); + const unsigned char + *pa=reinterpret_cast(&a[0]), + *pb=reinterpret_cast(&b[0]); + for(std::size_t i=0; i codecvt_utf8_utf16t; + std::wstring_convert converter; + std::wstring s2=converter.from_bytes(in); + + assert(paranoid_wstr_equals(s1, s2)); +} + +void compare_utf8_to_utf16_little_endian(std::string& in) +{ + std::wstring s1=utf8_to_utf16_little_endian(in); + + const std::codecvt_mode mode=std::codecvt_mode::little_endian; + const unsigned long maxcode=0x10ffff; + + typedef std::codecvt_utf8_utf16 codecvt_utf8_utf16t; + std::wstring_convert converter; + std::wstring s2=converter.from_bytes(in); + + assert(paranoid_wstr_equals(s1, s2)); +} + +int main() +{ + std::string s; + s=u8"\u0070\u00DF\u00E0\u00EF\u00F0\u00F7\u00F8"; + compare_utf8_to_utf16_big_endian(s); + compare_utf8_to_utf16_little_endian(s); + s=u8"$¢€𐍈"; + compare_utf8_to_utf16_big_endian(s); + compare_utf8_to_utf16_little_endian(s); + s=u8"𐐏𤭢"; + compare_utf8_to_utf16_big_endian(s); + compare_utf8_to_utf16_little_endian(s); + s=u8"дȚȨɌṡʒʸͼἨѶݔݺ→⅒⅀▤▞╢◍⛳⻥龍ンㄗㄸ"; + compare_utf8_to_utf16_big_endian(s); + compare_utf8_to_utf16_little_endian(s); +} + diff --git a/unit/unit_tests.cpp b/unit/unit_tests.cpp new file mode 100644 index 00000000000..a4ae333109f --- /dev/null +++ b/unit/unit_tests.cpp @@ -0,0 +1,10 @@ +/*******************************************************************\ + + Module: Catch Tests + + Author: DiffBlue Limited. All rights reserved. + +\*******************************************************************/ + +#define CATCH_CONFIG_MAIN +#include "catch.hpp"