X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=generator.c;h=05873d1303fa9bb214a3add0bf3374a3b408196d;hb=679da1b129ba6077d1c44ebdf260d3813afdcf65;hp=b17a8cd977cf450733a38fe9510b01db8754bd6f;hpb=7d4370a6cf1df8bacbead0511e4a9a1b6941003e;p=dsw-obn.git diff --git a/generator.c b/generator.c index b17a8cd..05873d1 100644 --- a/generator.c +++ b/generator.c @@ -363,6 +363,11 @@ lvalue_from_item(oberon_context_t * ctx, oberon_item_t * item) if(item -> mode == MODE_VAR) { + if(item -> var -> class == OBERON_CLASS_PROC) + { + oberon_error(ctx, "casting static procedure to pointer not supported by generator"); + } + gen_var_t * gen_var = item -> var -> gen_var; left = gen_var -> gcc_lvalue; if(item -> var -> class == OBERON_CLASS_VAR_PARAM) @@ -450,8 +455,6 @@ rvalue_from_item(oberon_context_t * ctx, oberon_item_t * item) } else if(item -> mode == MODE_CALL) { - assert(item -> var -> class == OBERON_CLASS_PROC); - oberon_type_t * signature = item -> var -> type; gen_proc_t * gen_proc = item -> var -> gen_proc; @@ -475,10 +478,28 @@ rvalue_from_item(oberon_context_t * ctx, oberon_item_t * item) arg_param = arg_param -> next; } - gcc_jit_function * func = gen_proc -> gcc_func; - right = gcc_jit_context_new_call( - gcc_context, NULL, func, num_args, args - ); + gcc_jit_rvalue * fnptr; + gcc_jit_function * func; + switch(item -> var -> class) + { + case OBERON_CLASS_PROC: + func = gen_proc -> gcc_func; + right = gcc_jit_context_new_call( + gcc_context, NULL, func, num_args, args + ); + break; + case OBERON_CLASS_VAR: + case OBERON_CLASS_VAR_PARAM: + case OBERON_CLASS_PARAM: + fnptr = gcc_jit_lvalue_as_rvalue(item -> var -> gen_var -> gcc_lvalue); + right = gcc_jit_context_new_call_through_ptr( + gcc_context, NULL, fnptr, num_args, args + ); + break; + default: + assert(0); + break; + } } else if(item -> mode == MODE_INDEX) { @@ -519,14 +540,19 @@ struct { enum gcc_jit_comparison comp_op; }; } op_table[] = { - { 0, .unary_op = GCC_JIT_UNARY_OP_LOGICAL_NEGATE }, { 0, .unary_op = GCC_JIT_UNARY_OP_MINUS }, + { 0, .unary_op = GCC_JIT_UNARY_OP_BITWISE_NEGATE }, + { 0, .unary_op = GCC_JIT_UNARY_OP_LOGICAL_NEGATE }, + { 0, .unary_op = GCC_JIT_UNARY_OP_ABS }, { 1, .binary_op = GCC_JIT_BINARY_OP_PLUS }, { 1, .binary_op = GCC_JIT_BINARY_OP_MINUS }, { 1, .binary_op = GCC_JIT_BINARY_OP_MULT }, { 1, .binary_op = GCC_JIT_BINARY_OP_DIVIDE }, { 1, .binary_op = GCC_JIT_BINARY_OP_MODULO }, + { 1, .binary_op = GCC_JIT_BINARY_OP_BITWISE_AND }, + { 1, .binary_op = GCC_JIT_BINARY_OP_BITWISE_XOR }, + { 1, .binary_op = GCC_JIT_BINARY_OP_BITWISE_OR }, { 1, .binary_op = GCC_JIT_BINARY_OP_LOGICAL_AND }, { 1, .binary_op = GCC_JIT_BINARY_OP_LOGICAL_OR }, @@ -617,6 +643,8 @@ oberon_generate_assign(oberon_context_t * ctx, oberon_expr_t * src, oberon_expr_ } } + printf("oberon_generate_assign: class %i := class %i\n", dst -> result -> class, src -> result -> class); + gen_context_t * gen_context = ctx -> gen_context; gen_block_t * gen_block = gen_context -> block; gcc_jit_block * gcc_block = gen_block -> gcc_block; @@ -643,3 +671,21 @@ oberon_generator_dump(oberon_context_t * ctx, char * path) gcc_jit_context * gcc_context = gen_context -> gcc_context; gcc_jit_context_dump_to_file(gcc_context, path, 0); } + +void * +oberon_generator_get_procedure(oberon_context_t * ctx, const char * name) +{ + gen_context_t * gen_context = ctx -> gen_context; + gcc_jit_result * gcc_result = gen_context -> gcc_result; + + return gcc_jit_result_get_code(gcc_result, name); +} + +void * +oberon_generator_get_var(oberon_context_t * ctx, const char * name) +{ + gen_context_t * gen_context = ctx -> gen_context; + gcc_jit_result * gcc_result = gen_context -> gcc_result; + + return gcc_jit_result_get_global(gcc_result, name); +}