Permalink
Browse files

split analyzer in two separate passes

  • Loading branch information...
1 parent e050420 commit 46cf43eabf7e77841b2f0fb2617ad0b276fce6fc @mwolf76 committed Apr 6, 2013
Showing with 87 additions and 60 deletions.
  1. +83 −60 src/model/model_mgr.cc
  2. +4 −0 src/model/model_mgr.hh
View
@@ -240,19 +240,12 @@ ModelMgr::ModelMgr()
// // TODO: free memory for symbols... (they've been allocated using new)
// }
-void ModelMgr::analyze()
+void ModelMgr::first_pass()
{
Model& model(f_model);
+ const Modules& modules = model.modules();
try {
- const Modules& modules = model.modules();
-
- DEBUG << "-- first pass (binding)" << endl;
- // (binding) For each module m in M, A goes deep in the module
- // defs. Every variable decl is resolved either to a native type
- // (boolean, ranged int, ...) or to an instance. Due to (1) all
- // modules are defined so any unresolved symbol at this point is a
- // fatal. Native types are taken care of as well.
for (Modules::const_iterator mod_eye = modules.begin();
mod_eye != modules.end(); mod_eye ++ ) {
@@ -295,76 +288,106 @@ void ModelMgr::analyze()
// f_tm.set_type( FQExpr(ctx, varname), vartype);
}
}
+ } // for modules
- // (typechecking) For each module m in M, A inspects FSM exprs:
- // INVAR, TRANS, FAIRNESS have all to be boolean formulae; ASSIGNs
- // have to match lvalue type. The type for every expression is
- // inferred using the lazy walker strategy.
- DEBUG << "-- second pass (type checking)" << endl;
- for (Modules::const_iterator mod_eye = modules.begin();
- mod_eye != modules.end(); mod_eye ++ ) {
+ catch (AnalyzerException& ae) {
+ cerr << ae.what() << endl;
+ }
+}
- Module& module = dynamic_cast <Module&> (*mod_eye->second);
- DEBUG << "processing module '" << module << "' " << endl;
+void ModelMgr::second_pass()
+{
+ Model& model(f_model);
+ const Modules& modules = model.modules();
- // Remark: ctx name is MODULE name, not instance's
- // rationale: you may have several instances but they
- // all should refer to the same entry on the type map.
- Expr_ptr ctx = module.expr();
+ for (Modules::const_iterator mod_eye = modules.begin();
+ mod_eye != modules.end(); mod_eye ++ ) {
- // const ExprVector params = module.get_formalParams();
- // for (ExprVector::const_iterator param_eye = params.begin();
- // param_eye != params.end(); param_eye ++) {
+ Module& module = dynamic_cast <Module&> (*mod_eye->second);
+ DEBUG << "processing module '" << module << "' " << endl;
- // Expr_ptr pname = *param_eye;
- // tm.reset_type(FQExpr(ctx, pname));
- // }
+ // Remark: ctx name is MODULE name, not instance's
+ // rationale: you may have several instances but they
+ // all should refer to the same entry on the type map.
+ Expr_ptr ctx = module.expr();
- // TODO: isa decls currently not supported
- const ExprVector isadecls = module.get_isaDecls();
- assert (isadecls.size() == 0);
+ // type inference: defines
+ const Defines defines = module.get_localDefs();
+ for (Defines::const_iterator define_eye = defines.begin();
+ define_eye != defines.end(); define_eye ++) {
- // type inference: defines
- const Defines defines = module.get_localDefs();
- for (Defines::const_iterator define_eye = defines.begin();
- define_eye != defines.end(); define_eye ++) {
+ Define& define = dynamic_cast <Define&> (*define_eye->second);
- Define& define = dynamic_cast <Define&> (*define_eye->second);
+ Expr_ptr dname = define.expr();
+ FQExpr fqdn(ctx, dname);
- Expr_ptr dname = define.expr();
- FQExpr fqdn(ctx, dname);
+ Expr_ptr dbody = define.body();
+ FQExpr fqdb(ctx, dbody);
- Expr_ptr dbody = define.body();
- FQExpr fqdb(ctx, dbody);
+ // try to infer type
+ try {
+ Type_ptr tmp = type(fqdb);
+ }
+ catch (AnalyzerException& ae) {
+ cerr << "DEFINE " << fqdn << endl
+ << ae.what() << endl;
+ }
+ } // for defines
- Type_ptr tp = type(fqdb);
- } // for defines
+ // type inference: FSM
+ const ExprVector init = module.init();
+ for (ExprVector::const_iterator init_eye = init.begin();
+ init_eye != init.end(); init_eye ++) {
- // type inference: FSM
- const ExprVector init = module.init();
- for (ExprVector::const_iterator init_eye = init.begin();
- init_eye != init.end(); init_eye ++) {
+ Expr_ptr body = (*init_eye);
+ FQExpr fqdn(ctx, body);
- Expr_ptr body = (*init_eye);
- DEBUG << "processing INIT " << ctx << "::" << body << endl;
+ DEBUG << "processing INIT " << fqdn << endl;
+ try {
f_inferrer.process(ctx, body, TP_BOOLEAN);
- } // for init
+ }
+ catch (AnalyzerException& ae) {
+ cerr << "INIT " << fqdn << endl
+ << ae.what() << endl;
+ }
+
+ } // for init
- const ExprVector trans = module.trans();
- for (ExprVector::const_iterator trans_eye = trans.begin();
- trans_eye != trans.end(); trans_eye ++) {
+ const ExprVector trans = module.trans();
+ for (ExprVector::const_iterator trans_eye = trans.begin();
+ trans_eye != trans.end(); trans_eye ++) {
- Expr_ptr body = (*trans_eye);
- DEBUG << "processing TRANS " << ctx << "::" << body << endl;
+ Expr_ptr body = (*trans_eye);
+ FQExpr fqdn(ctx, body);
+ DEBUG << "processing TRANS " << fqdn << endl;
+ try {
f_inferrer.process(ctx, body, TP_BOOLEAN);
}
- } // for trans
-
- } // for modules
-
- catch (AnalyzerException& ae) {
- cerr << ae.what() << endl;
+ catch (AnalyzerException& ae) {
+ cerr << "TRANS " << fqdn << endl
+ << ae.what() << endl;
+ }
+ }
}
}
+
+void ModelMgr::analyze()
+{
+ DEBUG << "-- first pass (binding)" << endl;
+ // (binding) For each module m in M, A goes deep in the module
+ // defs. Every variable decl is resolved either to a native type
+ // (boolean, ranged int, ...) or to an instance. Due to (1) all
+ // modules are defined so any unresolved symbol at this point is a
+ // fatal. Native types are taken care of as well.
+ first_pass();
+
+ DEBUG << "-- second pass (type checking)" << endl;
+ // (typechecking) For each module m in M, A inspects FSM exprs:
+ // INVAR, TRANS, FAIRNESS have all to be boolean formulae; ASSIGNs
+ // have to match lvalue type. The type for every expression is
+ // inferred using the lazy walker strategy.
+ second_pass();
+}
+
View
@@ -84,6 +84,10 @@ private:
// ref to inferrer (used for model analysis)
Inferrer& f_inferrer;
+
+ // analyzer passes
+ void first_pass();
+ void second_pass();
};
#endif

0 comments on commit 46cf43e

Please sign in to comment.