VM: merge the compute_dlsym_toc_address() with the
compute_dlsym_address() method it makes the code slightly more cluttered but you get rid of a lot of special casing for the ppc platformdb4
parent
a53d5be683
commit
4efef7bfd9
|
@ -142,73 +142,43 @@ void factor_vm::update_word_references(code_block* compiled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look up an external library symbol referenced by a compiled code block */
|
/* Look up an external library symbol referenced by a compiled code
|
||||||
cell factor_vm::compute_dlsym_address(array* parameters, cell index) {
|
block */
|
||||||
|
cell factor_vm::compute_dlsym_address(array* parameters,
|
||||||
|
cell index,
|
||||||
|
bool toc) {
|
||||||
cell symbol = array_nth(parameters, index);
|
cell symbol = array_nth(parameters, index);
|
||||||
cell library = array_nth(parameters, index + 1);
|
cell library = array_nth(parameters, index + 1);
|
||||||
|
dll* d = to_boolean(library) ? untag<dll>(library) : NULL;
|
||||||
|
|
||||||
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
|
cell undef = (cell)factor::undefined_symbol;
|
||||||
|
undef = toc ? FUNCTION_TOC_POINTER(undef) : FUNCTION_CODE_POINTER(undef);
|
||||||
cell undefined_symbol = (cell)factor::undefined_symbol;
|
|
||||||
undefined_symbol = FUNCTION_CODE_POINTER(undefined_symbol);
|
|
||||||
if (d != NULL && !d->handle)
|
if (d != NULL && !d->handle)
|
||||||
return undefined_symbol;
|
return undef;
|
||||||
|
|
||||||
|
cell type = TAG(symbol);
|
||||||
|
if (type == BYTE_ARRAY_TYPE) {
|
||||||
|
|
||||||
switch (tagged<object>(symbol).type()) {
|
|
||||||
case BYTE_ARRAY_TYPE: {
|
|
||||||
symbol_char* name = alien_offset(symbol);
|
symbol_char* name = alien_offset(symbol);
|
||||||
cell sym = ffi_dlsym(d, name);
|
cell sym = ffi_dlsym_raw(d, name);
|
||||||
return sym ? sym : undefined_symbol;
|
sym = toc ? FUNCTION_TOC_POINTER(sym) : FUNCTION_CODE_POINTER(sym);
|
||||||
}
|
return sym ? sym : undef;
|
||||||
case ARRAY_TYPE: {
|
|
||||||
|
} else if (type == ARRAY_TYPE) {
|
||||||
|
|
||||||
array* names = untag<array>(symbol);
|
array* names = untag<array>(symbol);
|
||||||
for (cell i = 0; i < array_capacity(names); i++) {
|
for (cell i = 0; i < array_capacity(names); i++) {
|
||||||
symbol_char* name = alien_offset(array_nth(names, i));
|
symbol_char* name = alien_offset(array_nth(names, i));
|
||||||
cell sym = ffi_dlsym(d, name);
|
cell sym = ffi_dlsym_raw(d, name);
|
||||||
|
sym = toc ? FUNCTION_TOC_POINTER(sym) : FUNCTION_CODE_POINTER(sym);
|
||||||
if (sym)
|
if (sym)
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
return undefined_symbol;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef FACTOR_PPC
|
|
||||||
cell factor_vm::compute_dlsym_toc_address(array* parameters, cell index) {
|
|
||||||
cell symbol = array_nth(parameters, index);
|
|
||||||
cell library = array_nth(parameters, index + 1);
|
|
||||||
|
|
||||||
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
|
|
||||||
|
|
||||||
cell undefined_toc = (cell)factor::undefined_symbol;
|
|
||||||
undefined_toc = FUNCTION_TOC_POINTER(undefined_toc);
|
|
||||||
if (d != NULL && !d->handle)
|
|
||||||
return undefined_toc;
|
|
||||||
|
|
||||||
switch (tagged<object>(symbol).type()) {
|
|
||||||
case BYTE_ARRAY_TYPE: {
|
|
||||||
symbol_char* name = alien_offset(symbol);
|
|
||||||
cell toc = ffi_dlsym_toc(d, name);
|
|
||||||
return toc ? toc : undefined_toc;
|
|
||||||
}
|
|
||||||
case ARRAY_TYPE: {
|
|
||||||
array* names = untag<array>(symbol);
|
|
||||||
for (cell i = 0; i < array_capacity(names); i++) {
|
|
||||||
symbol_char* name = alien_offset(array_nth(names, i));
|
|
||||||
cell toc = ffi_dlsym_toc(d, name);
|
|
||||||
if (toc)
|
|
||||||
return toc;
|
|
||||||
}
|
|
||||||
return undefined_toc;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cell factor_vm::compute_vm_address(cell arg) {
|
cell factor_vm::compute_vm_address(cell arg) {
|
||||||
return (cell)this + untag_fixnum(arg);
|
return (cell)this + untag_fixnum(arg);
|
||||||
|
@ -220,7 +190,7 @@ cell factor_vm::lookup_external_address(relocation_type rel_type,
|
||||||
cell index) {
|
cell index) {
|
||||||
switch (rel_type) {
|
switch (rel_type) {
|
||||||
case RT_DLSYM:
|
case RT_DLSYM:
|
||||||
return compute_dlsym_address(parameters, index);
|
return compute_dlsym_address(parameters, index, false);
|
||||||
case RT_THIS:
|
case RT_THIS:
|
||||||
return compiled->entry_point();
|
return compiled->entry_point();
|
||||||
case RT_MEGAMORPHIC_CACHE_HITS:
|
case RT_MEGAMORPHIC_CACHE_HITS:
|
||||||
|
@ -237,7 +207,7 @@ cell factor_vm::lookup_external_address(relocation_type rel_type,
|
||||||
#endif
|
#endif
|
||||||
#ifdef FACTOR_PPC
|
#ifdef FACTOR_PPC
|
||||||
case RT_DLSYM_TOC:
|
case RT_DLSYM_TOC:
|
||||||
return compute_dlsym_toc_address(parameters, index);
|
return compute_dlsym_address(parameters, index, true);
|
||||||
#endif
|
#endif
|
||||||
case RT_INLINE_CACHE_MISS:
|
case RT_INLINE_CACHE_MISS:
|
||||||
return (cell)&factor::inline_cache_miss;
|
return (cell)&factor::inline_cache_miss;
|
||||||
|
|
|
@ -47,12 +47,6 @@ cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
|
||||||
return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
|
return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FACTOR_PPC
|
|
||||||
cell factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
|
|
||||||
return FUNCTION_TOC_POINTER(ffi_dlsym_raw(dll, symbol));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void factor_vm::ffi_dlclose(dll* dll) {
|
void factor_vm::ffi_dlclose(dll* dll) {
|
||||||
if (dlclose(dll->handle))
|
if (dlclose(dll->handle))
|
||||||
general_error(ERROR_FFI, false_object, false_object);
|
general_error(ERROR_FFI, false_object, false_object);
|
||||||
|
|
|
@ -576,10 +576,7 @@ struct factor_vm {
|
||||||
cell code_block_owner(code_block* compiled);
|
cell code_block_owner(code_block* compiled);
|
||||||
void update_word_references(code_block* compiled, bool reset_inline_caches);
|
void update_word_references(code_block* compiled, bool reset_inline_caches);
|
||||||
void undefined_symbol();
|
void undefined_symbol();
|
||||||
cell compute_dlsym_address(array* literals, cell index);
|
cell compute_dlsym_address(array* literals, cell index, bool toc);
|
||||||
#ifdef FACTOR_PPC
|
|
||||||
cell compute_dlsym_toc_address(array* literals, cell index);
|
|
||||||
#endif
|
|
||||||
cell compute_vm_address(cell arg);
|
cell compute_vm_address(cell arg);
|
||||||
cell lookup_external_address(relocation_type rel_type,
|
cell lookup_external_address(relocation_type rel_type,
|
||||||
code_block* compiled,
|
code_block* compiled,
|
||||||
|
@ -740,9 +737,6 @@ struct factor_vm {
|
||||||
void ffi_dlopen(dll* dll);
|
void ffi_dlopen(dll* dll);
|
||||||
cell ffi_dlsym(dll* dll, symbol_char* symbol);
|
cell ffi_dlsym(dll* dll, symbol_char* symbol);
|
||||||
cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
|
cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
|
||||||
#ifdef FACTOR_PPC
|
|
||||||
cell ffi_dlsym_toc(dll* dll, symbol_char* symbol);
|
|
||||||
#endif
|
|
||||||
void ffi_dlclose(dll* dll);
|
void ffi_dlclose(dll* dll);
|
||||||
void c_to_factor_toplevel(cell quot);
|
void c_to_factor_toplevel(cell quot);
|
||||||
void init_signals();
|
void init_signals();
|
||||||
|
|
Loading…
Reference in New Issue