I suspect that we should just make object allocation take a vm type instead (and convert the callers that need it to send a vm type instead of a bytecode type).
But that's for a later cleanup, we need this now. Signed-off-by: Vegard Nossum <vegard.nos...@gmail.com> --- include/vm/types.h | 1 + vm/types.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/include/vm/types.h b/include/vm/types.h index 204a6ee..34cdda4 100644 --- a/include/vm/types.h +++ b/include/vm/types.h @@ -21,6 +21,7 @@ extern enum vm_type get_method_return_type(char *); int count_arguments(const char *); enum vm_type bytecode_type_to_vmtype(int); +int vmtype_to_bytecode_type(enum vm_type); int get_vmtype_size(enum vm_type); const char *get_vm_type_name(enum vm_type); diff --git a/vm/types.c b/vm/types.c index 1e719a8..a1d8c64 100644 --- a/vm/types.c +++ b/vm/types.c @@ -1,3 +1,5 @@ +#include <assert.h> + #include "vm/system.h" #include "vm/types.h" #include "vm/die.h" @@ -149,9 +151,32 @@ static enum vm_type bytecode_type_to_vmtype_map[] = { enum vm_type bytecode_type_to_vmtype(int type) { + /* Note: The cast below is okay, because we _know_ that type is non- + * negative at that point. */ + assert(type >= 0); + assert((unsigned int) type < ARRAY_SIZE(bytecode_type_to_vmtype_map)); + return bytecode_type_to_vmtype_map[type]; } +static int vmtype_to_bytecode_type_map[] = { + [J_BOOLEAN] = T_BOOLEAN, + [J_CHAR] = T_CHAR, + [J_FLOAT] = T_FLOAT, + [J_DOUBLE] = T_DOUBLE, + [J_BYTE] = T_BYTE, + [J_SHORT] = T_SHORT, + [J_INT] = T_INT, + [J_LONG] = T_LONG, +}; + +int vmtype_to_bytecode_type(enum vm_type type) +{ + assert(type >= 0 && type < ARRAY_SIZE(vmtype_to_bytecode_type_map)); + + return vmtype_to_bytecode_type_map[type]; +} + int get_vmtype_size(enum vm_type type) { /* Currently we can load/store only multiples of machine word -- 1.6.0.4 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel