コード例 #1
0
ファイル: canon.py プロジェクト: Bookaa/gnofract4d.simplify
    def linearize_call(self, tree, children):
        eseq_in_children = False

        for child in children:
            if (isinstance(child, ir.ESeq)):
                eseq_in_children = True

        if eseq_in_children:
            # FIXME: assumes arguments & eseq contents commute
            stms = []
            i = 0
            for i in range(0, len(children)):
                child = children[i]
                if (isinstance(child, ir.ESeq)):
                    stms = stms + self.stms(child)
                    children[i] = child.children[-1]

            calltree = copy.copy(tree)
            calltree.children = children

            newtree = ir.ESeq(stms, calltree, calltree.node, calltree.datatype)
        else:
            newtree = copy.copy(tree)
            newtree.children = children
        return newtree
コード例 #2
0
ファイル: canon.py プロジェクト: Bookaa/gnofract4d.simplify
 def linearize_cast(self, tree, children):
     if isinstance(children[0], ir.ESeq):
         # cast(eseq(stms,e)) => eseq(stms,cast(e))
         eseq = children[0]
         stms = self.stms(eseq)
         e = eseq.children[-1]
         newtree = ir.ESeq(stms, ir.Cast(e, tree.node, tree.datatype),
                           eseq.node, tree.datatype)
     else:
         newtree = copy.copy(tree)
         newtree.children = children
     return newtree
コード例 #3
0
ファイル: canon.py プロジェクト: Bookaa/gnofract4d.simplify
 def linearize_binop(self, tree, children):
     if isinstance(children[0], ir.ESeq):
         # binop(eseq[stms,e1],e2) => eseq([stms,binop(e1,e2)])
         eseq = children[0]
         stms = self.stms(eseq)
         e1 = eseq.children[-1]
         assert (not isinstance(e1, ir.ESeq))
         e2 = children[1]
         newtree = ir.ESeq(
             stms, ir.Binop(tree.op, [e1, e2], tree.node, tree.datatype),
             eseq.node, eseq.datatype)
         newtree = self.linearize(newtree)
     elif isinstance(children[1], ir.ESeq):
         #binop(e1,eseq(stms,e2))
         # => eseq([stms,binop(e1,e2)]) IF commutes(e1,stms)
         # => eseq(move(temp(t),e1), eseq(stms,binop(t, e2)) otherwise
         eseq = children[1]
         e1 = children[0]
         e2 = eseq.children[-1]
         stms = self.stms(eseq)
         if commutes(e1, stms):
             newtree = ir.ESeq(
                 stms, ir.Binop(tree.op, [e1, e2], tree.node,
                                tree.datatype), eseq.node, eseq.datatype)
             newtree = self.linearize(newtree)
         else:
             t = ir.Var(self.symbols.newTemp(e1.datatype), e1.node,
                        e1.datatype)
             move = ir.Move(t, e1, e1.node, e1.datatype)
             binop = ir.Binop(tree.op, [t, e2], tree.node, tree.datatype)
             eseq = ir.ESeq(stms, binop, eseq.node, eseq.datatype)
             newtree = ir.ESeq([move], eseq, tree.node, tree.datatype)
             newtree = self.linearize(newtree)
     else:
         newtree = ir.Binop(tree.op, children, tree.node, tree.datatype)
     return newtree
コード例 #4
0
 def eseq(self, stms, exp):
     return ir.ESeq(stms, exp, self.fakeNode, Int)