From: DeaDDooMER Date: Mon, 24 Jul 2017 19:47:00 +0000 (+0300) Subject: Добавлено получение указателей на сгенерированные процедуры и переменные X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=679da1b129ba6077d1c44ebdf260d3813afdcf65;p=dsw-obn.git Добавлено получение указателей на сгенерированные процедуры и переменные --- diff --git a/generator.c b/generator.c index 2442962..05873d1 100644 --- a/generator.c +++ b/generator.c @@ -671,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); +} diff --git a/generator.h b/generator.h index 085c2ca..08df5c8 100644 --- a/generator.h +++ b/generator.h @@ -37,4 +37,5 @@ void oberon_generate_return(oberon_context_t * ctx, oberon_expr_t * expr); void oberon_generate_code(oberon_context_t * ctx); void oberon_generator_dump(oberon_context_t * ctx, char * path); - +void * oberon_generator_get_procedure(oberon_context_t * ctx, const char * name); +void * oberon_generator_get_var(oberon_context_t * ctx, const char * name); diff --git a/oberon.c b/oberon.c index b0bb6aa..28a351a 100644 --- a/oberon.c +++ b/oberon.c @@ -2334,27 +2334,16 @@ register_default_types(oberon_context_t * ctx) } static void -oberon_new_intrinsic_function(oberon_context_t * ctx, char * name, GenerateFuncCallback generate) +oberon_new_intrinsic(oberon_context_t * ctx, char * name, GenerateFuncCallback f, GenerateProcCallback p) { oberon_object_t * proc; proc = oberon_define_object(ctx -> decl, name, OBERON_CLASS_PROC); proc -> sysproc = 1; - proc -> genfunc = generate; + proc -> genfunc = f; + proc -> genproc = p; proc -> type = oberon_new_type_ptr(OBERON_TYPE_PROCEDURE); } -/* -static void -oberon_new_intrinsic_procedure(oberon_context_t * ctx, char * name, GenerateProcCallback generate) -{ - oberon_object_t * proc; - proc = oberon_define_object(ctx -> decl, name, OBERON_CLASS_PROC); - proc -> sysproc = 1; - proc -> genproc = generate; - proc -> type = oberon_new_type_ptr(OBERON_TYPE_PROCEDURE); -} -*/ - static oberon_expr_t * oberon_make_abs_call(oberon_context_t * ctx, int num_args, oberon_expr_t * list_args) { @@ -2398,7 +2387,7 @@ oberon_create_context() oberon_generator_init_context(ctx); register_default_types(ctx); - oberon_new_intrinsic_function(ctx, "ABS", oberon_make_abs_call); + oberon_new_intrinsic(ctx, "ABS", oberon_make_abs_call, NULL); return ctx; } diff --git a/oberon.h b/oberon.h index 09a24c9..d481e13 100644 --- a/oberon.h +++ b/oberon.h @@ -11,32 +11,32 @@ typedef struct gen_context_s gen_context_t; struct gen_proc_s { - gcc_jit_function * gcc_func; + gcc_jit_function * gcc_func; }; struct gen_type_s { - gcc_jit_type * gcc_type; - gcc_jit_struct * gcc_struct; + gcc_jit_type * gcc_type; + gcc_jit_struct * gcc_struct; }; struct gen_var_s { - gcc_jit_lvalue * gcc_lvalue; - gcc_jit_param * gcc_param; - gcc_jit_field * gcc_field; + gcc_jit_lvalue * gcc_lvalue; + gcc_jit_param * gcc_param; + gcc_jit_field * gcc_field; }; struct gen_block_s { - gcc_jit_block * gcc_block; + gcc_jit_block * gcc_block; gen_block_t * up; }; struct gen_context_s { - gcc_jit_context * gcc_context; - gcc_jit_result * gcc_result; + gcc_jit_context * gcc_context; + gcc_jit_result * gcc_result; gen_block_t * block; unsigned record_count; }; diff --git a/test.c b/test.c index d828f4a..6b6d335 100644 --- a/test.c +++ b/test.c @@ -17,7 +17,7 @@ static const char source[] = "END RelBack;" "" "BEGIN;" - " i := 1;" + " i := ABS(-1);" " i := cb();" " RelBack;" "END Test."