Esempio n. 1
0
    def byteString(self):

        ret = u1(self.op.opcode)
        for arg in self.args:

            # TODO reconsider this, maybe just have local and global symbol tables
            if isinstance(arg, LabelRef):

                if not labelTable.has_key(arg):
                    raise UnknownLabel(arg)

                ret += u1(labelTable[arg])

            elif isinstance(arg, SymbolRef):

                name = arg.name
                if not symbolTable.has_key(name):

                    if log.getEffectiveLevel() <= ERROR:
                        log.error("Unknown symbol " + name + ": " + ` symbolTable `)
                    raise UnknownSymbol(name)

                if log.getEffectiveLevel() <= DEBUG:
                    log.debug(
                        "resolving symbol $" + name + " to " + ` symbolTable[name] ` + "(" + ` symbolTable ` + ")"
                    )

                for b in symbolTable[name]:  # list of bytes
                    ret += u1(b)

            else:
                ret += u1(arg)  # arg is an integer

        return ret
Esempio n. 2
0
 def write(self, stream):
     stream.write(u1(self.tag))
     stream.write(self.bytes)
Esempio n. 3
0
 def write(self, stream):
     stream.write(u1(self.tag))
     l = len(self.bytes)
     stream.write(u2(l))
     stream.write(self.bytes)
Esempio n. 4
0
    def write(self, stream):
        stream.write(u2(self.attribute_name_index))
        stream.write(u4(self.size - 6))

        stream.write(u2(len(self.line_number_table)))

        for entry in self.line_number_table:

            log.info('line number pair ' + `entry`)
            stream.write(u2(entry[0]))
            stream.write(u2(entry[1]))


SIZE_OF_EXCEPTION_TABLE_ENTRY = 8

EMPTY_METHOD = u1(jopcode.getOperation('return').opcode)

class Code_attribute(object):

    def __init__(self, owningClass, max_stack = 0, max_locals = 0, code = EMPTY_METHOD, exception_table = [], attributes = []):

        if log.getEffectiveLevel() <= DEBUG:
            log.debug('Code_attribute(' + `owningClass` + ', ' + `max_stack` + ', ' + `max_locals` + ', ' + `code` + ', ' + `exception_table` + ', ' + `attributes` + ')')

        self.attribute_name_index = owningClass.utf8Constant(ATTR_CODE)

        # Size of max_stack, max_locals, code_length, exception_table_length,
        # attributes_count = 12.
        # Size of attribute.name_index, length = 6
        # attributes that go on a code attribute must now support size member
        self.attribute_length = len(code) + SIZE_OF_EXCEPTION_TABLE_ENTRY * len (exception_table) + reduce(lambda x, y: x + y.size, attributes, 0) + 12