Beispiel #1
0
 def _dump_partial_lines(self):  #what we've generated so far
     asmlines = []
     for block in self.blocklist:
         block.writecode(asmlines)
     asmlines = ['%s ;%d' % (asmlines[i], i+1) for i in range(len(asmlines))]
     asm_string = '\n'.join(asmlines)
     logger.dump(asm_string)
Beispiel #2
0
 def revealconst(self, T):
     if T is llmemory.Address:
         return self.addr
     elif isinstance(T, lltype.Ptr):
         return llmemory.cast_adr_to_ptr(self.addr, T)
     elif T is lltype.Signed:
         return llmemory.cast_adr_to_int(self.addr)
     else:
         msg = 'XXX not implemented'
         logger.dump(msg)
         assert 0, msg
Beispiel #3
0
 def revealconst(self, T):
     if T is llmemory.Address:
         return self.addr
     elif isinstance(T, lltype.Ptr):
         return llmemory.cast_adr_to_ptr(self.addr, T)
     elif T is lltype.Signed:
         return llmemory.cast_adr_to_int(self.addr)
     else:
         msg = 'XXX not implemented'
         logger.dump(msg)
         assert 0, msg
Beispiel #4
0
 def erasedType(T):
     if T is llmemory.Address:
         return llmemory.Address
     if isinstance(T, lltype.Primitive):
         return lltype.Signed
     elif isinstance(T, lltype.Ptr):
         return llmemory.GCREF
     else:
         msg = 'XXX not implemented'
         logger.dump(msg)
         assert 0, msg
Beispiel #5
0
    def add_incoming_link(self, sourceblock, sourcevars):
        # check the types for debugging
        sourcevartypes = [var.type for var in sourcevars]
        targetvartypes = [var.type for var in self.inputargs]
        if sourcevartypes != targetvartypes:
            logger.dump('assert fails on: sourcevartypes(%s) != targetvartypes(%s)' % (
                sourcevartypes, targetvartypes))
            self.rgenop._dump_partial_lines()
            assert sourcevartypes == targetvartypes

        # Check if the source block jumps to 'self' from multiple
        # positions: in this case we need an intermediate block...
        if sourceblock in self.phinodes:
            tmplabel = count.newlabel()
            tmpblock = BasicBlock(self.rgenop, tmplabel, targetvartypes)
            tmpblock.add_incoming_link(sourceblock, sourcevars)
            sourceblock = tmpblock
            sourcevars = tmpblock.inputargs

        # Add this source for the phi nodes
        self.phinodes[sourceblock] = list(sourcevars)
Beispiel #6
0
 def genconst(self, llvalue):
     T = lltype.typeOf(llvalue)
     if T is llmemory.Address:
         return AddrConst(llvalue)
     elif T is lltype.Bool:
         return BoolConst(lltype.cast_primitive(lltype.Bool, llvalue))
     elif T is lltype.Char:
         return CharConst(lltype.cast_primitive(lltype.Char, llvalue))
     elif T is lltype.Unsigned:
         return UIntConst(lltype.cast_primitive(lltype.Unsigned, llvalue))
     elif T is lltype.Float:
         return FloatConst(lltype.cast_primitive(lltype.Float, llvalue))
     elif isinstance(T, lltype.Primitive):
         return IntConst(lltype.cast_primitive(lltype.Signed, llvalue))
     elif isinstance(T, lltype.Ptr):
         lladdr = llmemory.cast_ptr_to_adr(llvalue)
         #if T.TO._gckind == 'gc':
         #    self.keepalive_gc_refs.append(lltype.cast_opaque_ptr(llmemory.GCREF, llvalue))
         return AddrConst(lladdr)
     else:
         msg = 'XXX not implemented'
         logger.dump(msg)
         assert 0, msg
Beispiel #7
0
    def end(self):
        log('   RLLVMGenOp.end')
        self.blocklist.append(EpilogueBlock())
        asmlines = []
        for block in self.blocklist:
            block.writecode(asmlines)
        if LINENO:
            asmlines = ['%s ;%d' % (asmlines[i], i+1) for i in range(len(asmlines))]
        asm_string = '\n'.join(asmlines)

        self.blocklist = None
        if PRINT_SOURCE:
            print asm_string
        logger.dump(asm_string)
        parse_ok = llvmjit.parse(asm_string)
        if not parse_ok:
            raise ParseException()
        llvmjit.transform(3) #optimize module (should be on functions actually)
        function   = llvmjit.getNamedFunction(self.name)
        entrypoint = llvmjit.getPointerToFunctionAsInt(function)
        # XXX or directly cast the ctypes ptr to int with:
        #   ctypes.cast(ptr, c_void_p).value
        self.funcsig[entrypoint] = self.funcsig[self.gv_entrypoint.value]
        self.gv_entrypoint.value = entrypoint