diff options
author | Morgan Deters <mdeters@cs.nyu.edu> | 2013-04-23 23:03:37 -0400 |
---|---|---|
committer | Morgan Deters <mdeters@cs.nyu.edu> | 2013-04-23 23:16:58 -0400 |
commit | b25991f4c2779c34b51cd51b943290a4a3d2a9fd (patch) | |
tree | aaec41cf29cc3574288c6110ba246f361d84ec3a /src | |
parent | a006e7b92327668b76a1ab993007f42fe91052c3 (diff) |
Theory "alternates" support
* This is a feature that Dejan and I want for the upcoming tutorial.
It allows rapid prototyping of new decision procedure implementations
(which we may choose to demonstrate), and a new --use-theory command-line
option to select from different available implementations. It has no
affect on the current set of theories, as no "alternates" are defined.
* Also update the new-theory script, which was broken and incomplete.
Diffstat (limited to 'src')
-rw-r--r-- | src/expr/metakind_template.h | 17 | ||||
-rwxr-xr-x | src/expr/mkexpr | 21 | ||||
-rwxr-xr-x | src/expr/mkkind | 21 | ||||
-rwxr-xr-x | src/expr/mkmetakind | 44 | ||||
-rw-r--r-- | src/smt/smt_engine.cpp | 9 | ||||
-rwxr-xr-x | src/theory/mkrewriter | 20 | ||||
-rwxr-xr-x | src/theory/mktheorytraits | 43 | ||||
-rw-r--r-- | src/theory/options | 4 | ||||
-rw-r--r-- | src/theory/options_handlers.h | 17 | ||||
-rw-r--r-- | src/theory/theory_traits_template.h | 15 |
10 files changed, 195 insertions, 16 deletions
diff --git a/src/expr/metakind_template.h b/src/expr/metakind_template.h index 10b67b4d6..22d7baac3 100644 --- a/src/expr/metakind_template.h +++ b/src/expr/metakind_template.h @@ -325,6 +325,23 @@ ${metakind_ubchildren} }/* CVC4::kind::metakind namespace */ }/* CVC4::kind namespace */ + +#line 330 "${template}" + +namespace theory { + +static inline bool useTheoryValidate(std::string theory) { +${use_theory_validations} + return false; +} + +static const char *const useTheoryHelp = "\ +The following options are valid alternate implementations for use with\n\ +the --use-theory option:\n\ +\n\ +${theory_alternate_doc}"; + +}/* CVC4::theory namespace */ }/* CVC4 namespace */ #endif /* __CVC4__NODE_MANAGER_NEEDS_CONSTANT_MAP */ diff --git a/src/expr/mkexpr b/src/expr/mkexpr index ca89dfc91..8c94db3cc 100755 --- a/src/expr/mkexpr +++ b/src/expr/mkexpr @@ -70,10 +70,15 @@ seen_theory=false seen_theory_builtin=false function theory { - # theory T header + # theory ID T header lineno=${BASH_LINENO[0]} + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + # this script doesn't care about the theory class information, but # makes does make sure it's there seen_theory=true @@ -93,6 +98,20 @@ function theory { fi } +function alternate { + # alternate ID name T header + + lineno=${BASH_LINENO[0]} + + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + + seen_theory=true + seen_endtheory=true +} + function rewriter { # rewriter class header lineno=${BASH_LINENO[0]} diff --git a/src/expr/mkkind b/src/expr/mkkind index f8432466d..02e0f50bf 100755 --- a/src/expr/mkkind +++ b/src/expr/mkkind @@ -77,10 +77,15 @@ theory_enum= theory_descriptions= function theory { - # theory T header + # theory ID T header lineno=${BASH_LINENO[0]} + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + # this script doesn't care about the theory class information, but # makes does make sure it's there seen_theory=true @@ -106,6 +111,20 @@ function theory { " } +function alternate { + # alternate ID name T header + + lineno=${BASH_LINENO[0]} + + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + + seen_theory=true + seen_endtheory=true +} + function properties { # rewriter class header lineno=${BASH_LINENO[0]} diff --git a/src/expr/mkmetakind b/src/expr/mkmetakind index 160a74eac..d8192e432 100755 --- a/src/expr/mkmetakind +++ b/src/expr/mkmetakind @@ -50,14 +50,22 @@ metakind_ubchildren= metakind_lbchildren= metakind_operatorKinds= +use_theory_validations= +theory_alternate_doc= + seen_theory=false seen_theory_builtin=false function theory { - # theory T header + # theory ID T header lineno=${BASH_LINENO[0]} + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + # this script doesn't care about the theory class information, but # makes does make sure it's there seen_theory=true @@ -81,6 +89,34 @@ function theory { // #include \"theory/$b/$2\"" } +function alternate { + # alternate ID name T header + + lineno=${BASH_LINENO[0]} + + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + + seen_theory=true + seen_endtheory=true + + theory_id="$1" + name="$2" + theory_class="$3" + theory_header="$4" + theory_includes="${theory_includes}#include \"$theory_header\" +" + + use_theory_validations="${use_theory_validations} + if(theory == \"$name\") { + return true; + }" + theory_alternate_doc="$theory_alternate_doc$name - alternate implementation for $theory_id\\n\\ +" +} + function properties { # properties prop* lineno=${BASH_LINENO[0]} @@ -366,6 +402,10 @@ check_builtin_theory_seen nl -ba -s' ' "$template" | grep '^ *[0-9][0-9]* # *line' | awk '{OFS="";if($1+1!=$3) print "'"$template"':",$1,": warning: incorrect annotation \"#line ",$3,"\" (it should be \"#line ",($1+1),"\")"}' >&2 +if [ -z "$theory_alternate_doc" ]; then + theory_alternate_doc="[none defined]" +fi + text=$(cat "$template") for var in \ metakind_includes \ @@ -378,6 +418,8 @@ for var in \ metakind_ubchildren \ metakind_lbchildren \ metakind_operatorKinds \ + use_theory_validations \ + theory_alternate_doc \ template \ ; do eval text="\${text//\\\$\\{$var\\}/\${$var}}" diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp index 864b444df..cc11147ed 100644 --- a/src/smt/smt_engine.cpp +++ b/src/smt/smt_engine.cpp @@ -603,12 +603,9 @@ SmtEngine::SmtEngine(ExprManager* em) throw() : d_theoryEngine = new TheoryEngine(d_context, d_userContext, d_private->d_iteRemover, const_cast<const LogicInfo&>(d_logic)); // Add the theories -#ifdef CVC4_FOR_EACH_THEORY_STATEMENT -#undef CVC4_FOR_EACH_THEORY_STATEMENT -#endif -#define CVC4_FOR_EACH_THEORY_STATEMENT(THEORY) \ - d_theoryEngine->addTheory<TheoryTraits<THEORY>::theory_class>(THEORY); - CVC4_FOR_EACH_THEORY; + for(TheoryId id = theory::THEORY_FIRST; id < theory::THEORY_LAST; ++id) { + TheoryConstructor::addTheory(d_theoryEngine, id); + } // global push/pop around everything, to ensure proper destruction // of context-dependent data structures diff --git a/src/theory/mkrewriter b/src/theory/mkrewriter index 2d8012bfb..084a624f7 100755 --- a/src/theory/mkrewriter +++ b/src/theory/mkrewriter @@ -52,13 +52,13 @@ seen_theory=false seen_theory_builtin=false function theory { - # theory T header + # theory ID T header lineno=${BASH_LINENO[0]} if $seen_theory; then - echo "$kf:$lineno: theory declaration can only appear once" >&2 - exit 1; + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 fi # this script doesn't care about the theory class information, but @@ -82,6 +82,20 @@ function theory { theory_id="$1" } +function alternate { + # alternate ID name T header + + lineno=${BASH_LINENO[0]} + + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + + seen_theory=true + seen_endtheory=true +} + function properties { # properties prop* lineno=${BASH_LINENO[0]} diff --git a/src/theory/mktheorytraits b/src/theory/mktheorytraits index 3edc7c140..97ede32d5 100755 --- a/src/theory/mktheorytraits +++ b/src/theory/mktheorytraits @@ -40,6 +40,7 @@ template=$1; shift theory_traits= theory_includes= +theory_constructors= theory_for_each_macro="#define CVC4_FOR_EACH_THEORY \\ " @@ -72,13 +73,13 @@ seen_theory=false seen_theory_builtin=false function theory { - # theory T header + # theory ID T header lineno=${BASH_LINENO[0]} if $seen_theory; then - echo "$kf:$lineno: theory declaration can only appear once" >&2 - exit 1; + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 fi # this script doesn't care about the theory class information, but @@ -109,6 +110,30 @@ function theory { " } +function alternate { + # alternate ID name T header + + lineno=${BASH_LINENO[0]} + + if $seen_theory; then + echo "$kf:$lineno: error: multiple theories defined in one file !?" >&2 + exit 1 + fi + + seen_theory=true + seen_endtheory=true + + theory_header="$4" + theory_includes="${theory_includes}#include \"$theory_header\" +" + + eval "alternate_for_$1=\"\${alternate_for_$1} + if(options::theoryAlternates()[\\\"$2\\\"]) { + engine->addTheory< $3 >($1); + return; + }\"" +} + function rewriter { # rewriter class header lineno=${BASH_LINENO[0]} @@ -128,10 +153,17 @@ function endtheory { seen_endtheory=true + theory_constructors="${theory_constructors} + case $theory_id: +\$alternate_for_$theory_id + engine->addTheory< $theory_class >($theory_id); + return; +" + theory_traits="${theory_traits} template<> struct TheoryTraits<${theory_id}> { - typedef ${theory_class} theory_class; + // typedef ${theory_class} theory_class; typedef ${rewriter_class} rewriter_class; static const bool isStableInfinite = ${theory_stable_infinite}; @@ -368,6 +400,8 @@ check_builtin_theory_seen ## output +eval "theory_constructors=\"$theory_constructors\"" + # generate warnings about incorrect #line annotations in templates nl -ba -s' ' "$template" | grep '^ *[0-9][0-9]* # *line' | awk '{OFS="";if($1+1!=$3) print "'"$template"':",$1,": warning: incorrect annotation \"#line ",$3,"\" (it should be \"#line ",($1+1),"\")"}' >&2 @@ -377,6 +411,7 @@ for var in \ theory_traits \ theory_for_each_macro \ theory_includes \ + theory_constructors \ template \ type_enumerator_includes \ mk_type_enumerator_type_constant_cases \ diff --git a/src/theory/options b/src/theory/options index 5a523f0fa..5d752fca1 100644 --- a/src/theory/options +++ b/src/theory/options @@ -8,4 +8,8 @@ module THEORY "theory/options.h" Theory layer expert-option theoryOfMode --theoryof-mode=MODE CVC4::theory::TheoryOfMode :handler CVC4::theory::stringToTheoryOfMode :handler-include "theory/options_handlers.h" :default CVC4::theory::THEORY_OF_TYPE_BASED :include "theory/theoryof_mode.h" mode for theoryof +option - use-theory --use-theory=NAME argument :handler CVC4::theory::useTheory :handler-include "theory/options_handlers.h" + use alternate theory implementation NAME (--use-theory=help for a list) +option theoryAlternates ::std::map<std::string,bool> :include <map> :read-write + endmodule diff --git a/src/theory/options_handlers.h b/src/theory/options_handlers.h index 268fd46fd..def304d8b 100644 --- a/src/theory/options_handlers.h +++ b/src/theory/options_handlers.h @@ -19,6 +19,8 @@ #ifndef __CVC4__THEORY__OPTIONS_HANDLERS_H #define __CVC4__THEORY__OPTIONS_HANDLERS_H +#include "expr/metakind.h" + namespace CVC4 { namespace theory { @@ -46,6 +48,21 @@ inline TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg, } } +inline void useTheory(std::string option, std::string optarg, SmtEngine* smt) { + if(optarg == "help") { + puts(useTheoryHelp); + exit(1); + } + if(useTheoryValidate(optarg)) { + std::map<std::string, bool> m = options::theoryAlternates(); + m[optarg] = true; + options::theoryAlternates.set(m); + } else { + throw OptionException(std::string("unknown option for ") + option + ": `" + + optarg + "'. Try --use-theory help."); + } +} + }/* CVC4::theory namespace */ }/* CVC4 namespace */ diff --git a/src/theory/theory_traits_template.h b/src/theory/theory_traits_template.h index d4f961eb7..326c6c913 100644 --- a/src/theory/theory_traits_template.h +++ b/src/theory/theory_traits_template.h @@ -21,6 +21,7 @@ #include "cvc4_private.h" #include "theory/theory.h" +#include "theory/options.h" ${theory_includes} @@ -34,5 +35,19 @@ ${theory_traits} ${theory_for_each_macro} +#line 39 "${template}" + +struct TheoryConstructor { + static void addTheory(TheoryEngine* engine, TheoryId id) { + switch(id) { + +${theory_constructors} + + default: + Unhandled(id); + } + } +};/* struct CVC4::theory::TheoryConstructor */ + }/* CVC4::theory namespace */ }/* CVC4 namespace */ |