def tocode(self, dest='dest'):
     ret = ''
     if len(self.nextnodes) > 1:
         ret += '(' + self.nextnodes[0].tocode(dest)
         ret += op2mark.op2mark(self.operator)
         ret += self.nextnodes[1].tocode(dest) + ')'
     else:
         ret += '(' + op2mark.op2mark(self.operator)
         ret += self.nextnodes[0].tocode(dest) + ')'
     return ret
Exemple #2
0
 def visit_Operator(self, node):
     filename = getfilename(node)
     template = self.get_template(filename)
     order = op2order(node.__class__.__name__)
     lorder = op2order(node.left.__class__.__name__)
     rorder = op2order(node.right.__class__.__name__)
     left = self.visit(node.left)
     right = self.visit(node.right)
     if ((not isinstance(node.left,
                         (Sll, Srl, Sra, LessThan, GreaterThan, LessEq,
                          GreaterEq, Eq, NotEq, Eql, NotEql)))
             and (lorder is not None and lorder <= order)):
         left = del_paren(left)
     if ((not isinstance(node.right,
                         (Sll, Srl, Sra, LessThan, GreaterThan, LessEq,
                          GreaterEq, Eq, NotEq, Eql, NotEql)))
             and (rorder is not None and order > rorder)):
         right = del_paren(right)
     template_dict = {
         'left': left,
         'right': right,
         'op': op2mark(node.__class__.__name__),
     }
     rslt = template.render(template_dict)
     return rslt
Exemple #3
0
 def visit_Operator(self, node):
     filename = getfilename(node)
     template = self.get_template(filename)
     order = op2order(node.__class__.__name__)
     lorder = op2order(node.left.__class__.__name__)
     rorder = op2order(node.right.__class__.__name__)
     left = self.visit(node.left)
     right = self.visit(node.right)
     if ((not isinstance(node.left, (Sll, Srl, Sra,
                                     LessThan, GreaterThan, LessEq, GreaterEq,
                                     Eq, NotEq, Eql, NotEql))) and 
         (lorder is not None and lorder <= order)):
         left = del_paren(left)
     if ((not isinstance(node.right, (Sll, Srl, Sra,
                                      LessThan, GreaterThan, LessEq, GreaterEq,
                                      Eq, NotEq, Eql, NotEql))) and 
         (rorder is not None and order > rorder)):
         right = del_paren(right)
     template_dict = {
         'left' : left,
         'right' : right,
         'op' : op2mark(node.__class__.__name__),
         }
     rslt = template.render(template_dict)
     return rslt
Exemple #4
0
 def visit_UnaryOperator(self, node):
     filename = getfilename(node)
     template = self.env.get_template(filename)
     template_dict = {
         'right' : self.visit(node.right),
         'op' : op2mark(node.__class__.__name__),
         }
     rslt = template.render(template_dict)
     return rslt
Exemple #5
0
 def visit_UnaryOperator(self, node):
     filename = getfilename(node)
     template = self.env.get_template(filename)
     template_dict = {
         'right' : self.visit(node.right),
         'op' : op2mark(node.__class__.__name__),
         }
     rslt = template.render(template_dict)
     return rslt
def DFOperator_tocode(self):
    if self.is_algebra():  #if operator is algebra, nextnodes aren't sweeped.
        term_manager().set_is_under_algebra(True)
        code = self.tocode_org()
        term_manager().set_is_under_algebra(False)
        return code
    elif self.is_reduction():
        if isinstance(self.nextnodes[0], DFPartselect):
            term = self.nextnodes[0].var
            msb = eval_value(self.nextnodes[0].msb)
            lsb = eval_value(self.nextnodes[0].lsb)
        elif isinstance(self.nextnodes[0], DFTerminal):
            term = term_manager().get_term(str(self.nextnodes[0]))
            msb = eval_value(term.msb)
            lsb = eval_value(term.lsb)
        else:
            raise Exception('Unexpected exception.')
        mark = op2mark.op2mark(self.operator)
        return mark.join([term_manager().publish_new_name(str(term), i).replace('.', '_') for i in range(lsb, msb + 1)])
    else:
        return self.tocode_org()
def DFOperator_tocode(self):
    if self.is_algebra():  #if operator is algebra, nextnodes aren't sweeped.
        term_manager().set_is_under_algebra(True)
        code = self.tocode_org()
        term_manager().set_is_under_algebra(False)
        return code
    elif self.is_reduction():
        if isinstance(self.nextnodes[0], DFPartselect):
            term = self.nextnodes[0].var
            msb = eval_value(self.nextnodes[0].msb)
            lsb = eval_value(self.nextnodes[0].lsb)
        elif isinstance(self.nextnodes[0], DFTerminal):
            term = term_manager().get_term(str(self.nextnodes[0]))
            msb = eval_value(term.msb)
            lsb = eval_value(term.lsb)
        else:
            raise Exception('Unexpected exception.')
        mark = op2mark.op2mark(self.operator)
        return mark.join([
            term_manager().publish_new_name(str(term), i).replace('.', '_')
            for i in range(lsb, msb + 1)
        ])
    else:
        return self.tocode_org()