metaSMT 2
|
00001 #pragma once 00002 /* 00003 * ===================================================================================== 00004 * 00005 * Filename: fmi.hpp 00006 * 00007 * Description: Representing the FMI Grammar 00008 * 00009 * Version: 1.0 00010 * Created: 02/08/2010 09:55:11 AM 00011 * Revision: none 00012 * Compiler: gcc 00013 * 00014 * Author: Stefan Frehse (sfrehse), sfrehse@informatik.uni-bremen.de 00015 * Company: University of Bremen, Germany 00016 * 00017 * ===================================================================================== 00018 */ 00019 00020 #include "../transform/fmiToQF_BV.hpp" 00021 00022 // Boost includes 00023 // 00024 #include <boost/proto/core.hpp> 00025 #include <boost/proto/debug.hpp> 00026 #include <boost/mpl/int.hpp> 00027 #include <boost/dynamic_bitset.hpp> 00028 00029 #include <vector> 00030 00031 namespace metaSMT { 00032 00043 namespace fmi 00044 { 00045 namespace proto = boost::proto; 00046 namespace mpl = boost::mpl; 00047 00048 struct grammar; 00049 00050 struct grammar_cases 00051 { 00052 template<typename Tag> 00053 struct case_ : proto::not_<proto::_> {}; 00054 }; 00055 00056 template<typename I> 00057 struct placeholder 00058 { 00059 typedef I arity; 00060 }; 00061 00062 template<typename Stream, typename I> 00063 Stream & operator<< (Stream & o, placeholder<I>) { 00064 o << "placeholder<" <<I::value << ">"; return o; 00065 } 00066 00067 // Terminal definition 00068 template<> 00069 struct grammar_cases::case_<proto::tag::terminal> : 00070 proto::or_< 00071 proto::terminal < placeholder <mpl::int_<0> > >, 00072 proto::terminal < placeholder <mpl::int_<1> > >, 00073 proto::terminal < placeholder <mpl::int_<2> > >, 00074 proto::terminal < placeholder <mpl::int_<3> > >, 00075 proto::terminal < placeholder <mpl::int_<4> > >, 00076 proto::terminal < placeholder <mpl::int_<5> > >, 00077 proto::terminal < placeholder <mpl::int_<6> > > 00078 //, proto::terminal< integral_wrapper < unsigned int > > 00079 > 00080 {}; 00081 00082 00083 // bitwise operator 00084 template<> 00085 struct grammar_cases::case_<proto::tag::bitwise_and> : proto::bitwise_and < grammar, grammar > {}; 00086 template<> 00087 struct grammar_cases::case_<proto::tag::bitwise_xor> : proto::bitwise_xor < grammar, grammar > {}; 00088 00089 // template<> 00090 // struct grammar_cases::case_<proto::tag::function> : 00091 // proto::function 00092 // < zero_extend_tag, 00093 // proto::terminal<integral_wrapper < unsigned int> > , 00094 // grammar > {}; 00095 00096 00097 template<> 00098 struct grammar_cases::case_<proto::tag::subscript> : proto::subscript < grammar, grammar > {}; 00099 00100 00101 template<> 00102 struct grammar_cases::case_<proto::tag::modulus_assign> : proto::modulus_assign < grammar, grammar > {}; 00103 00104 template<> 00105 struct grammar_cases::case_<proto::tag::not_equal_to> : proto::not_equal_to < grammar, grammar > {}; 00106 00107 template<> 00108 struct grammar_cases::case_<proto::tag::equal_to> : proto::equal_to < grammar, grammar > {}; 00109 00110 template<> 00111 struct grammar_cases::case_<proto::tag::shift_left> : proto::shift_left < grammar, grammar > {}; 00112 00113 00114 // template<> 00115 // struct grammar_cases::case_<proto::tag::function> : proto::function<ite_tag, grammar, grammar, grammar > {}; 00116 00117 00118 // template<> 00119 // struct grammar_cases::case_<proto::tag::if_else_> : proto::if_else_ < grammar, grammar, grammar > {}; 00120 00121 00122 struct grammar : 00123 //proto::switch_<grammar_cases> {}; 00124 proto::not_< proto::address_of< proto::_> > 00125 {}; 00126 00127 00128 00129 struct Solver {}; 00130 template<typename Stream> 00131 Stream & operator<< (Stream & o, Solver) { 00132 o << "generate"; return o; 00133 } 00134 00135 00136 template<typename T> 00137 struct constraint; 00138 00139 struct constraint_domain 00140 : proto::domain < proto::generator < constraint >, grammar > 00141 { }; 00142 00143 template<typename T> 00144 struct constraint : proto::extends <T, constraint<T>, constraint_domain> 00145 { 00146 typedef proto::extends<T, constraint<T>, constraint_domain> base_type; 00147 00148 constraint (T expr = T()) 00149 : base_type (expr) { } 00150 }; 00151 00152 // define variables 00153 typedef 00154 proto::result_of::make_expr< proto::tag::terminal, constraint_domain 00155 , logic::QF_BV::tag::var_tag 00156 > ::type bv; 00157 00158 template<typename Context> 00159 bv new_variable(Context &, unsigned width) { 00160 logic::QF_BV::tag::var_tag tag; 00161 tag.id = impl::new_var_id(); 00162 tag.width= width; 00163 return proto::make_expr< proto::tag::terminal, constraint_domain >( tag ); 00164 } 00165 00166 template<typename T1, typename T2> 00167 bv zero_extend (T1, T2, unsigned) {return bv();} 00168 00169 // define some placeholders 00170 typedef constraint<proto::terminal<placeholder<mpl::int_<0> > >::type> var0_type; 00171 typedef constraint<proto::terminal<placeholder<mpl::int_<1> > >::type> var1_type; 00172 typedef constraint<proto::terminal<placeholder<mpl::int_<2> > >::type> var2_type; 00173 typedef constraint<proto::terminal<placeholder<mpl::int_<3> > >::type> var3_type; 00174 typedef constraint<proto::terminal<placeholder<mpl::int_<4> > >::type> var4_type; 00175 typedef constraint<proto::terminal<placeholder<mpl::int_<5> > >::type> var5_type; 00176 00177 //typedef constraint<proto::terminal<zero_extend_tag>::type> zero_extend; 00178 00179 //typedef constraint<proto::terminal<ite_tag>::type > ite_; 00180 00181 // define default named placeholder 00182 var0_type const _0; 00183 var1_type const _1; 00184 var2_type const _2; 00185 var3_type const _3; 00186 var4_type const _4; 00187 var5_type const _5; 00188 00189 template<typename SolverVariant> 00190 std::vector<boost::dynamic_bitset<> > get_assignment_vector ( 00191 const Solver & solver, 00192 const std::vector<bv>& vars) 00193 { 00194 return std::vector< boost::dynamic_bitset<> > (); 00195 } 00196 00197 struct Generate { 00198 typedef void result_type; 00199 00200 template < typename Context, typename Expression > 00201 void operator() ( Context & ctx, Expression e ) { 00202 proto::display_expr( transform::fmiToQF_BV()(e) ); 00203 //assertion(ctx, transform::fmiToQF_BV()(e)); 00204 } 00205 // overload with params 00206 template < typename Context, typename Expression > 00207 void operator() ( Context & ctx, Expression e, bv arg0 ) 00208 { (*this)(ctx, e); } 00209 template < typename Context, typename Expression > 00210 void operator() ( Context & ctx, Expression e, bv arg0, bv arg1 ) 00211 { (*this)(ctx, e); } 00212 template < typename Context, typename Expression > 00213 void operator() ( Context & ctx, Expression e, bv arg0, bv arg1, bv arg2 ) 00214 { (*this)(ctx, e); } 00215 template < typename Context, typename Expression > 00216 void operator() ( Context & ctx, Expression e, bv arg0, bv arg1, bv arg2, bv arg3 ) 00217 { (*this)(ctx, e); } 00218 } generate; 00219 00220 template < typename Context, typename Expression > 00221 void assertion ( Context & ctx, Expression e ) { 00222 transform::fmiToQF_BV to_QF_BV; 00223 proto::display_expr( to_QF_BV (e) ); 00224 metaSMT::assertion( ctx, to_QF_BV(e) ); 00225 } 00226 00227 } /* fmi */ 00228 } /* metaSMT */ 00229 00230 00231 // vim: tabstop=2 shiftwidth=2 expandtab