def build_core(self): core = { 'header': { 'entries': None, # number of labeled objects (top-levels, behaviors, cclasses) 'names_size': None, # size in bytes of NAMES section 'st_size': None, # size of Symbols table 'ot_size': None }, # size of OBJECT TABLE in bytes 'names': [], 'index': [], # index of top level entities 'object_table': [], 'symbols': [], # Symbol references 'reloc_table': [] } self.core_compiled_module.fill(self.vmem) # -- HEADER and NAMES section labels = self.core_compiled_module.entry_labels() core['header']['entries'] = len(labels) # names :: [(string, alloc-size in bytes, self-ptr)] names_list = set([l + "\0" for l in labels] + [n + "\0" for n in self.vmem.external_names()]) core['names'] = [(name_t, bits.string_block_size(name_t)) for name_t in names_list] core['header']['names_size'] = sum([x[1] for x in core['names']]) index_size = core['header'][ 'entries'] * 2 * bits.WSIZE # *2: pair (name, entry), base = self.HEADER_SIZE + core['header']['names_size'] + index_size self.vmem.set_base(base) # - OBJECT TABLE core['object_table'] = self.vmem.object_table() # - HEADER ot_size core['header']['ot_size'] = len(core['object_table']) # symbols for pair in self.vmem.symbols_references(): core['symbols'].append(self.name_ptr_for_name(pair[0], core)) core['symbols'].append(pair[1]) core['header']['st_size'] = len(core['symbols']) * bits.WSIZE # reloc core['reloc_table'] = self.vmem.reloc_table() # - INDEX section for name in labels: core['index'].append(self.name_ptr_for_name(name, core)) # ptr to string core['index'].append(self.vmem.index_for(name)) # ptr to object return core
def __init__(self, etable, string): self.etable = etable string_with_term = string + "\0" # words_needed = int(math.ceil(len(string_with_term) / float(utils.WSIZE))) # to_fill = (words_needed * utils.WSIZE) - len(string_with_term) to_fill = bits.string_block_size(string_with_term) - len(string_with_term) # br() self.data = map(ord, string_with_term) + ([0] * to_fill)
def __init__(self, etable, string): self.etable = etable string_with_term = string + "\0" # words_needed = int(math.ceil(len(string_with_term) / float(utils.WSIZE))) # to_fill = (words_needed * utils.WSIZE) - len(string_with_term) to_fill = bits.string_block_size(string_with_term) - len(string_with_term) # br() self.data = map(ord, string_with_term) + ([0] * to_fill)
def build_core(self): core = { 'header': { 'entries': None, # number of labeled objects (top-levels, behaviors, cclasses) 'names_size': None, # size in bytes of NAMES section 'st_size': None, # size of Symbols table 'ot_size': None}, # size of OBJECT TABLE in bytes 'object_table': [], 'names': [], 'index': [], # index of top level entities # 'object_table': [], 'symbols': [], # Symbol references 'reloc_table': []} self.HEADER_SIZE = len(core['header']) * bits.WSIZE # bytes. 3 = entries, names_size, es_size, ot_size vmem = core_vmem.CoreVirtualMemory() # base = self.HEADER_SIZE + core['header']['names_size'] + index_size vmem.set_base(self.HEADER_SIZE) self.core_compiled_module.fill(vmem) # -- HEADER and NAMES section labels = self.core_compiled_module.entry_labels() core['header']['entries'] = len(labels) # names :: [(string, alloc-size in bytes, self-ptr)] names_list = sorted(set([l + "\0" for l in labels] + [n + "\0" for n in vmem.external_names()])) core['names'] = [(name_t, bits.string_block_size(name_t)) for name_t in names_list] core['header']['names_size'] = sum([x[1] for x in core['names']]) index_size = core['header']['entries'] * 2 * bits.WSIZE # *2: pair (name, entry), # - OBJECT TABLE core['object_table'] = vmem.object_table() # - HEADER ot_size core['header']['ot_size'] = len(core['object_table']) # symbols for pair in vmem.symbols_references(): core['symbols'].append(self.name_ptr_for_name(pair[0], core)) core['symbols'].append(pair[1]) core['header']['st_size'] = len(core['symbols']) * bits.WSIZE # reloc core['reloc_table'] = vmem.reloc_table() # - INDEX section for name in labels: core['index'].append(self.name_ptr_for_name(name, core)) # ptr to string core['index'].append(vmem.index_for(name)) # ptr to object return core
def create_mec_struct(self, vmem): mec = {'header': {'magic_number': None, 'ot_size': None, 'er_size': None, 'st_size': None, 'names_size': None}, 'object_table': [], # the loaded objects of this module 'names': [], 'external_references': [], # references to core objects 'symbol_table': [], # Symbol objects needed 'reloc_table': [] # addresses within the OT that need relocation on load } self.HEADER_SIZE = len(mec['header']) * bits.WSIZE #base = self.HEADER_SIZE + mec['header']['names_size'] vmem.set_base(self.HEADER_SIZE) bench("cmodule.fill", lambda: self.cmodule.fill(vmem)) mec['header']['magic_number'] = self.MAGIC_NUMBER # mec['names'] = [(name_t, bits.string_block_size(name_t)) for name_t in [name + '\0' for name in vmem.external_names()]] # labels = self.cmodule.entry_labels() names_list = [n + "\0" for n in vmem.external_names()] mec['object_table'] = vmem.object_table() mec['header']['ot_size'] = len(mec['object_table']) mec['names'] = [(name_t, bits.string_block_size(name_t)) for name_t in names_list] mec['header']['names_size'] = sum([x[1] for x in mec['names']]) ext_ref = vmem.external_references() for pair in ext_ref: mec['external_references'].append(self.name_ptr_for(pair[0], mec)) mec['external_references'].append(pair[1]) mec['header']['er_size'] = len(mec['external_references']) * bits.WSIZE sym_ref = vmem.symbols_references() for pair in sym_ref: mec['symbol_table'].append(self.name_ptr_for(pair[0], mec)) mec['symbol_table'].append(pair[1]) mec['header']['st_size'] = len(mec['symbol_table']) * bits.WSIZE mec['reloc_table'] = vmem.reloc_table() return mec
def create_mec_struct(self, vmem): mec = {'header': {'magic_number': None, 'ot_size': None, 'er_size': None, 'st_size': None, 'names_size': None, 'cfun_addr': None}, 'names': [], 'object_table': [], 'external_references': [], 'symbol_table': [], 'reloc_table': [] } self.HEADER_SIZE = len(mec['header']) * bits.WSIZE self.cmod.fill(vmem) mec['header']['magic_number'] = self.MAGIC_NUMBER names_list = set([n + "\0" for n in vmem.external_names()]) mec['names'] = [(name_t, bits.string_block_size(name_t)) for name_t in names_list] mec['header']['names_size'] = sum([x[1] for x in mec['names']]) base = self.HEADER_SIZE + mec['header']['names_size'] vmem.set_base(base) mec['object_table'] = vmem.object_table() mec['header']['ot_size'] = len(mec['object_table']) for pair in vmem.external_references(): mec['external_references'].append(self.name_ptr_for(pair[0], mec)) mec['external_references'].append(pair[1]) mec['header']['er_size'] = len(mec['external_references']) * bits.WSIZE for pair in vmem.symbols_references(): mec['symbol_table'].append(self.name_ptr_for(pair[0], mec)) mec['symbol_table'].append(pair[1]) mec['header']['st_size'] = len(mec['symbol_table']) * bits.WSIZE mec['reloc_table'] = vmem.reloc_table() mec['header']['cfun_addr'] = vmem.physical_address(self.cfun.oop) return mec
def append_string_instance(self, string): if string in self.string_table: return self.string_table[string] else: delegate = self.append_object_instance() self.append_int(pyutils.FRAME_TYPE_BVAR_OBJECT) self.append_int((3 * bits.WSIZE) + bits.string_block_size(string + "\0")) oop = self.append_external_ref('String') self.append_pointer_to(delegate) # delegate self.append_int(len(string)) self.append_string(string) self.string_table[string] = oop return oop
def append_symbol_instance(self, string): # We only need a dummy/word-sized placeholder here. # (actually, not event this. We only need to return a dummy cell. All we need # its the PointerCell's pointing to our dummy to construct the symbols_reference()) # In any case, the full data is only used by dump to display the text of the symbol delegate = self.append_object_instance() # Assumed to be object! if source change, this breaks self.append_int(pyutils.FRAME_TYPE_BVAR_OBJECT) self.append_int((3 * bits.WSIZE) + bits.string_block_size(string + "\0")) oop = self.append_label_ref(utils.class_label('Symbol')) # vt self.append_pointer_to(delegate) # delegate self.append_int(len(string)) self.append_string(string) self.symb_table[oop] = string return oop
def append_string_instance(self, string): if string in self.string_table: return self.string_table[string] else: delegate = self.append_object_instance() self.append_int(pyutils.FRAME_TYPE_BVAR_OBJECT) self.append_int((3 * bits.WSIZE) + bits.string_block_size(string + "\0")) oop = self.append_external_ref('String') self.append_pointer_to(delegate) # delegate self.append_int(len(string)) self.append_string(string) self.string_table[string] = oop return oop
def append_string_instance(self, string): if string in self.string_table: return self.string_table[string] else: delegate = self.append_object_instance( ) # Assumed to be object! if source change, this breaks self.append_int(pyutils.FRAME_TYPE_BVAR_OBJECT) self.append_int((3 * bits.WSIZE) + bits.string_block_size(string + "\0")) oop = self.append_label_ref(utils.class_label('String')) # vt self.append_pointer_to(delegate) # delegate self.append_int(len(string)) self.append_string(string) self.string_table[string] = oop return oop
def append_symbol_instance(self, string): # We only need a dummy/word-sized placeholder here. # (actually, not event this. We only need to return a dummy cell. All we need # its the PointerCell's pointing to our dummy to construct the symbols_reference()) # In any case, the full data is only used by dump to display the text of the symbol delegate = self.append_object_instance( ) # Assumed to be object! if source change, this breaks self.append_int(pyutils.FRAME_TYPE_BVAR_OBJECT) self.append_int((3 * bits.WSIZE) + bits.string_block_size(string + "\0")) oop = self.append_label_ref(utils.class_label('Symbol')) # vt self.append_pointer_to(delegate) # delegate self.append_int(len(string)) self.append_string(string) self.symb_table[oop] = string return oop