Exemple #1
0
 def _compile_operations(self, c, operations, var2index):
     for op in operations:
         llimpl.compile_add(c, op.opnum)
         descr = op.descr
         if isinstance(descr, Descr):
             llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo)
         if self.is_oo and isinstance(descr, (OODescr, MethDescr)):
             # hack hack, not rpython
             c._obj.externalobj.operations[-1].descr = descr
         for x in op.args:
             if isinstance(x, history.Box):
                 llimpl.compile_add_var(c, var2index[x])
             elif isinstance(x, history.ConstInt):
                 llimpl.compile_add_int_const(c, x.value)
             elif isinstance(x, self.ts.ConstRef):
                 llimpl.compile_add_ref_const(c, x.value, self.ts.BASETYPE)
             elif isinstance(x, history.ConstAddr):
                 llimpl.compile_add_int_const(c, x.getint())
             elif isinstance(x, history.ConstFloat):
                 llimpl.compile_add_float_const(c, x.value)
             else:
                 raise Exception("%s args contain: %r" %
                                 (op.getopname(), x))
         if op.is_guard():
             faildescr = op.descr
             assert isinstance(faildescr, history.AbstractFailDescr)
             fail_index = faildescr.get_index()
             index = llimpl.compile_add_fail(c, fail_index)
             faildescr._compiled_fail = c, index
             for box in op.fail_args:
                 llimpl.compile_add_fail_arg(c, var2index[box])
         x = op.result
         if x is not None:
             if isinstance(x, history.BoxInt):
                 var2index[x] = llimpl.compile_add_int_result(c)
             elif isinstance(x, self.ts.BoxRef):
                 var2index[x] = llimpl.compile_add_ref_result(
                     c, self.ts.BASETYPE)
             elif isinstance(x, history.BoxFloat):
                 var2index[x] = llimpl.compile_add_float_result(c)
             else:
                 raise Exception("%s.result contain: %r" %
                                 (op.getopname(), x))
     op = operations[-1]
     assert op.is_final()
     if op.opnum == rop.JUMP:
         targettoken = op.descr
         assert isinstance(targettoken, history.LoopToken)
         compiled_version = targettoken._llgraph_compiled_version
         llimpl.compile_add_jump_target(c, compiled_version)
     elif op.opnum == rop.FINISH:
         faildescr = op.descr
         assert isinstance(faildescr, history.AbstractFailDescr)
         index = faildescr.get_index()
         llimpl.compile_add_fail(c, index)
     else:
         assert False, "unknown operation"
Exemple #2
0
 def _compile_operations(self, c, operations, var2index):
     for op in operations:
         llimpl.compile_add(c, op.opnum)
         descr = op.descr
         if isinstance(descr, Descr):
             llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo)
         if self.is_oo and isinstance(descr, (OODescr, MethDescr)):
             # hack hack, not rpython
             c._obj.externalobj.operations[-1].descr = descr
         for x in op.args:
             if isinstance(x, history.Box):
                 llimpl.compile_add_var(c, var2index[x])
             elif isinstance(x, history.ConstInt):
                 llimpl.compile_add_int_const(c, x.value)
             elif isinstance(x, self.ts.ConstRef):
                 llimpl.compile_add_ref_const(c, x.value, self.ts.BASETYPE)
             elif isinstance(x, history.ConstAddr):
                 llimpl.compile_add_int_const(c, x.getint())
             elif isinstance(x, history.ConstFloat):
                 llimpl.compile_add_float_const(c, x.value)
             else:
                 raise Exception("%s args contain: %r" % (op.getopname(),
                                                          x))
         if op.is_guard():
             faildescr = op.descr
             assert isinstance(faildescr, history.AbstractFailDescr)
             fail_index = faildescr.get_index()
             index = llimpl.compile_add_fail(c, fail_index)
             faildescr._compiled_fail = c, index
             for box in op.fail_args:
                 llimpl.compile_add_fail_arg(c, var2index[box])
         x = op.result
         if x is not None:
             if isinstance(x, history.BoxInt):
                 var2index[x] = llimpl.compile_add_int_result(c)
             elif isinstance(x, self.ts.BoxRef):
                 var2index[x] = llimpl.compile_add_ref_result(c, self.ts.BASETYPE)
             elif isinstance(x, history.BoxFloat):
                 var2index[x] = llimpl.compile_add_float_result(c)
             else:
                 raise Exception("%s.result contain: %r" % (op.getopname(),
                                                            x))
     op = operations[-1]
     assert op.is_final()
     if op.opnum == rop.JUMP:
         targettoken = op.descr
         assert isinstance(targettoken, history.LoopToken)
         compiled_version = targettoken._llgraph_compiled_version
         llimpl.compile_add_jump_target(c, compiled_version)
     elif op.opnum == rop.FINISH:
         faildescr = op.descr
         assert isinstance(faildescr, history.AbstractFailDescr)
         index = faildescr.get_index()
         llimpl.compile_add_fail(c, index)
     else:
         assert False, "unknown operation"
Exemple #3
0
    def _compile_operations(self, c, operations, var2index):
        for op in operations:
            llimpl.compile_add(c, op.getopnum())
            descr = op.getdescr()
            if isinstance(descr, Descr):
                llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo, descr.arg_types)
            if isinstance(descr, history.LoopToken) and op.getopnum() != rop.JUMP:
                llimpl.compile_add_loop_token(c, descr)
            if self.is_oo and isinstance(descr, (OODescr, MethDescr)):
                # hack hack, not rpython
                c._obj.externalobj.operations[-1].setdescr(descr)
            for i in range(op.numargs()):
                x = op.getarg(i)
                if isinstance(x, history.Box):
                    llimpl.compile_add_var(c, var2index[x])
                elif isinstance(x, history.ConstInt):
                    llimpl.compile_add_int_const(c, x.value)
                elif isinstance(x, self.ts.ConstRef):
                    llimpl.compile_add_ref_const(c, x.value, self.ts.BASETYPE)
                elif isinstance(x, history.ConstFloat):
                    llimpl.compile_add_float_const(c, x.value)
                else:
                    raise Exception("'%s' args contain: %r" % (op.getopname(),
                                                               x))
            if op.is_guard():
                faildescr = op.getdescr()
                assert isinstance(faildescr, history.AbstractFailDescr)
                faildescr._fail_args_types = []
                for box in op.getfailargs():
                    if box is None:
                        type = history.HOLE
                    else:
                        type = box.type
                    faildescr._fail_args_types.append(type)
                fail_index = self.get_fail_descr_number(faildescr)
                index = llimpl.compile_add_fail(c, fail_index)
                faildescr._compiled_fail = c, index
                for box in op.getfailargs():
                    if box is not None:
                        llimpl.compile_add_fail_arg(c, var2index[box])
                    else:
                        llimpl.compile_add_fail_arg(c, -1)

            x = op.result
            if x is not None:
                if isinstance(x, history.BoxInt):
                    var2index[x] = llimpl.compile_add_int_result(c)
                elif isinstance(x, self.ts.BoxRef):
                    var2index[x] = llimpl.compile_add_ref_result(c, self.ts.BASETYPE)
                elif isinstance(x, history.BoxFloat):
                    var2index[x] = llimpl.compile_add_float_result(c)
                else:
                    raise Exception("%s.result contain: %r" % (op.getopname(),
                                                               x))
        op = operations[-1]
        assert op.is_final()
        if op.getopnum() == rop.JUMP:
            targettoken = op.getdescr()
            assert isinstance(targettoken, history.LoopToken)
            compiled_version = targettoken.compiled_loop_token.compiled_version
            llimpl.compile_add_jump_target(c, compiled_version)
        elif op.getopnum() == rop.FINISH:
            faildescr = op.getdescr()
            index = self.get_fail_descr_number(faildescr)
            llimpl.compile_add_fail(c, index)
        else:
            assert False, "unknown operation"
Exemple #4
0
    def _compile_operations(self, c, operations, var2index, clt):
        for op in operations:
            llimpl.compile_add(c, op.getopnum())
            descr = op.getdescr()
            if isinstance(descr, Descr):
                llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo,
                                         descr.arg_types, descr.extrainfo,
                                         descr.width)
            if isinstance(descr, history.JitCellToken):
                assert op.getopnum() != rop.JUMP
                llimpl.compile_add_loop_token(c, descr)
            if isinstance(descr,
                          history.TargetToken) and op.getopnum() == rop.LABEL:
                llimpl.compile_add_target_token(c, descr, clt)
            if self.is_oo and isinstance(descr, (OODescr, MethDescr)):
                # hack hack, not rpython
                c._obj.externalobj.operations[-1].setdescr(descr)
            for i in range(op.numargs()):
                x = op.getarg(i)
                if isinstance(x, history.Box):
                    llimpl.compile_add_var(c, var2index[x])
                elif isinstance(x, history.ConstInt):
                    llimpl.compile_add_int_const(c, x.value)
                elif isinstance(x, self.ts.ConstRef):
                    llimpl.compile_add_ref_const(c, x.value, self.ts.BASETYPE)
                elif isinstance(x, history.ConstFloat):
                    llimpl.compile_add_float_const(c, x.value)
                elif isinstance(x, Descr):
                    llimpl.compile_add_descr_arg(c, x.ofs, x.typeinfo,
                                                 x.arg_types)
                else:
                    raise Exception("'%s' args contain: %r" %
                                    (op.getopname(), x))
            if op.is_guard():
                faildescr = op.getdescr()
                assert isinstance(faildescr, history.AbstractFailDescr)
                faildescr._fail_args_types = []
                for box in op.getfailargs():
                    if box is None:
                        type = history.HOLE
                    else:
                        type = box.type
                    faildescr._fail_args_types.append(type)
                fail_index = self.get_fail_descr_number(faildescr)
                index = llimpl.compile_add_fail(c, fail_index)
                faildescr._compiled_fail = c, index
                for box in op.getfailargs():
                    if box is not None:
                        llimpl.compile_add_fail_arg(c, var2index[box])
                    else:
                        llimpl.compile_add_fail_arg(c, -1)

            x = op.result
            if x is not None:
                if isinstance(x, history.BoxInt):
                    var2index[x] = llimpl.compile_add_int_result(c)
                elif isinstance(x, self.ts.BoxRef):
                    var2index[x] = llimpl.compile_add_ref_result(
                        c, self.ts.BASETYPE)
                elif isinstance(x, history.BoxFloat):
                    var2index[x] = llimpl.compile_add_float_result(c)
                else:
                    raise Exception("%s.result contain: %r" %
                                    (op.getopname(), x))
        op = operations[-1]
        assert op.is_final()
        if op.getopnum() == rop.JUMP:
            targettoken = op.getdescr()
            llimpl.compile_add_jump_target(c, targettoken, clt)
        elif op.getopnum() == rop.FINISH:
            faildescr = op.getdescr()
            index = self.get_fail_descr_number(faildescr)
            llimpl.compile_add_fail(c, index)
        else:
            assert False, "unknown operation"