Beispiel #1
0
def apply_fuse_lut(goal,rule,unif):
  law_var = tablib.LawVar(rule.law,rule.ident,tablib.LawVar.APPLY)
  stmts = []
  if isinstance(goal.variable, tablib.DSVar):
    var_name = goal.variable.var
    stmts.append(tablib.VADPSource(law_var,genoplib.Var(var_name)))
  else:
    stmts.append(tablib.VADPConn(law_var,goal.variable))

  inpexpr = unif.get_by_name('a')
  coeff,base_expr = genoplib.factor_coefficient(inpexpr)
  assert(not base_expr is None)
  expr = unif.get_by_name('e')
  repl = {'T': genoplib.Mult(genoplib.Const(1.0/coeff),  \
                             genoplib.Var("y")) \
  }
  rule_var = vadplib.LawVar(rule.law,rule.ident)
  cfg = tablib.VADPConfig(rule_var,rule.mode)
  cfg.bind('e',expr.substitute(repl))
  stmts.append(cfg)

  

  new_unif = unifylib.Unification()
  new_unif.set_by_name('a', base_expr)

  return new_unif,stmts
Beispiel #2
0
def apply_kirchoff(goal,rule,unif):
  law_var = tablib.LawVar(rule.law,rule.ident,tablib.LawVar.APPLY)
  stmt = []
  if isinstance(goal.variable, tablib.DSVar):
    var_name = goal.variable.var
    stmt.append(tablib.VADPSource(law_var,genoplib.Var(var_name)))
  else:
    stmt.append(tablib.VADPConn(law_var,goal.variable))
  return unif,stmt
Beispiel #3
0
    def apply(self, goal, rule, unif=None):
        assert (rule.law.name == self.name)
        law_var = rule.target.make_law_var(self.virt.output.name)
        stmt = []
        if isinstance(goal.variable, tablib.DSVar):
            var_name = goal.variable.var
            stmt.append(tablib.VADPSource(law_var, genoplib.Var(var_name)))
        else:
            stmt.append(tablib.VADPConn(law_var, goal.variable))

        return unif, stmt
Beispiel #4
0
    def apply(self, goal, rule, unif=None):
        assert (rule.law.name == self.name)
        stmt = []
        if isinstance(goal.variable, tablib.DSVar):
            var_name = goal.variable.var
            mp = tablib.MultiPortVar()
            stmt.append(tablib.VADPSink(mp, goal.expr))
            stmt.append(tablib.VADPSource(goal.var, mp))
        else:
            stmt.append(tablib.VADPSink(goal.variable, goal.expr))

        return unifylib.Unification(), stmt
Beispiel #5
0
    def simplify_once(self, vadp):
        target = None
        for stmt in filter(lambda stmt: not self.get_usage(stmt) is None,
                           vadp):
            target = stmt
            break

        if target is None:
            return False, vadp

        lawvar = self.get_law_var(target)
        sources = []
        sink = None
        new_vadp = []
        source_dsexprs = []
        sink_dsexprs = []
        for st in vadp:
            if self.is_same_usage(st, lawvar):
                usage = self.get_usage(st, target=lawvar)
                if usage == rulelib.Rule.Usage.VADP_CONN_SINK:
                    sources.append(st.source)

                elif usage == rulelib.Rule.Usage.VADP_CONN_SOURCE:
                    assert (sink is None)
                    sink = st.sink

                elif usage == rulelib.Rule.Usage.VADP_SOURCE:
                    source_dsexprs.append(st.dsexpr)
                    assert (sink is None)
                    sink = tablib.MultiPortVar()

                elif usage == rulelib.Rule.Usage.VADP_SINK:
                    sink_dsexprs.append(st.dsexpr)
                else:
                    raise Exception("unhandled: %s" % st)
            else:
                new_vadp.append(st)

        assert (not sink is None)
        for src in sources:
            new_vadp.append(tablib.VADPConn(src, sink))

        for dsexpr in source_dsexprs:
            new_vadp.append(tablib.VADPSource(sink, dsexpr))

        for dsexpr in sink_dsexprs:
            new_vadp.append(tablib.VADPSink(sink, dsexpr))

        return True, new_vadp