11 // =======================================================================
13 // =======================================================================
16 oberon_generator_open_block(gen_context_t
* gen_context
, gcc_jit_block
* gcc_block
)
18 gen_block_t
* block
= malloc(sizeof *block
);
19 memset(block
, 0, sizeof *block
);
21 block
-> gcc_block
= gcc_block
;
22 block
-> up
= gen_context
-> block
;
24 gen_context
-> block
= block
;
28 oberon_generator_close_block(gen_context_t
* gen_context
)
30 gen_context
-> block
= gen_context
-> block
-> up
;
34 oberon_generator_init_context(oberon_context_t
* ctx
)
36 gen_context_t
* gen_context
= malloc(sizeof *gen_context
);
37 memset(gen_context
, 0, sizeof *gen_context
);
39 gcc_jit_context
* gcc_context
;
40 gcc_context
= gcc_jit_context_acquire();
42 ctx
-> gen_context
= gen_context
;
43 gen_context
-> gcc_context
= gcc_context
;
47 oberon_generator_destroy_context(oberon_context_t
* ctx
)
49 gen_context_t
* gen_context
= ctx
-> gen_context
;
50 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
52 gcc_jit_context_release(gcc_context
);
56 oberon_generator_init_type(oberon_context_t
* ctx
, oberon_type_t
* type
)
58 gen_type_t
* gen_type
= malloc(sizeof *gen_type
);
59 memset(gen_type
, 0, sizeof *gen_type
);
60 type
-> gen_type
= gen_type
;
62 gen_context_t
* gen_context
= ctx
-> gen_context
;
63 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
65 gcc_jit_type
* gcc_type
= NULL
;
66 gcc_jit_struct
* gcc_struct
= NULL
;
67 if(type
-> class == OBERON_TYPE_VOID
)
69 gcc_type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_VOID
);
71 else if(type
-> class == OBERON_TYPE_INTEGER
)
73 gcc_type
= gcc_jit_context_get_int_type(gcc_context
, type
-> size
, 1);
75 else if(type
-> class == OBERON_TYPE_BOOLEAN
)
77 gcc_type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_BOOL
);
79 else if(type
-> class == OBERON_TYPE_ARRAY
)
81 gen_type_t
* gen_base
= type
-> base
-> gen_type
;
82 gcc_jit_type
* gcc_base
= gen_base
-> gcc_type
;
83 gcc_type
= gcc_jit_context_new_array_type(gcc_context
, NULL
, gcc_base
, type
-> size
);
85 else if(type
-> class == OBERON_TYPE_RECORD
)
88 snprintf(name
, 32, "RECORD%u", gen_context
-> record_count
);
89 gen_context
-> record_count
+= 1;
91 gcc_struct
= gcc_jit_context_new_opaque_struct(gcc_context
, NULL
, name
);
92 gcc_type
= gcc_jit_struct_as_type(gcc_struct
);
94 else if(type
-> class == OBERON_TYPE_POINTER
)
96 gen_type_t
* gen_base
= type
-> base
-> gen_type
;
97 gcc_jit_type
* gcc_base
= gen_base
-> gcc_type
;
98 gcc_type
= gcc_jit_type_get_pointer(gcc_base
);
100 else if(type
-> class == OBERON_TYPE_PROCEDURE
)
102 int num_params
= type
-> num_decl
;
103 gcc_jit_type
* params
[num_params
];
104 oberon_object_t
* o
= type
-> decl
;
105 for(int i
= 0; i
< num_params
; i
++)
107 gen_type_t
* gen_type
= o
-> type
-> gen_type
;
108 params
[i
] = gen_type
-> gcc_type
;
112 gen_type_t
* base
= type
-> base
-> gen_type
;
113 gcc_jit_type
* result_type
= base
-> gcc_type
;
115 gcc_type
= gcc_jit_context_new_function_ptr_type(
116 gcc_context
, NULL
, result_type
, num_params
, params
, 0
121 oberon_error(ctx
, "oberon_generator_init_type: invalid type class %i", type
-> class);
125 gen_type
-> gcc_type
= gcc_type
;
126 gen_type
-> gcc_struct
= gcc_struct
;
130 oberon_generator_init_record(oberon_context_t
* ctx
, oberon_type_t
* type
)
132 assert(type
-> class == OBERON_TYPE_RECORD
);
134 gen_type_t
* gen_type
= type
-> gen_type
;
135 gcc_jit_struct
* gcc_struct
= gen_type
-> gcc_struct
;
137 // TODO type exstension
139 int num_fields
= type
-> num_decl
;
140 gcc_jit_field
* fields
[num_fields
];
141 oberon_object_t
* o
= type
-> decl
;
142 for(int i
= 0; i
< num_fields
; i
++)
144 assert(o
-> class == OBERON_CLASS_FIELD
);
145 gen_var_t
* var
= o
-> gen_var
;
146 fields
[i
] = var
-> gcc_field
;
150 gcc_jit_struct_set_fields (gcc_struct
, NULL
, num_fields
, fields
);
152 //gcc_struct = gcc_jit_context_new_struct_type(gcc_context, NULL, "", num_fields, fields);
156 oberon_generator_get_full_name(char * name
, int max_len
, oberon_object_t
* x
)
164 int add_module_prefix
;
167 case OBERON_CLASS_FIELD
:
168 case OBERON_CLASS_PARAM
:
169 case OBERON_CLASS_VAR_PARAM
:
170 /* В локальных областях префиксы излишни */
171 add_module_prefix
= 0;
174 add_module_prefix
= 1;
179 oberon_generator_get_full_name(parent
, 256, x
-> parent
);
181 if(strlen(parent
) > 0)
183 snprintf(name
, max_len
, "%s_%s", parent
, x
-> name
);
185 else if(add_module_prefix
)
187 snprintf(name
, max_len
, "%s_%s", x
-> module
-> name
, x
-> name
);
191 snprintf(name
, max_len
, "%s", x
-> name
);
196 oberon_generator_init_var(oberon_context_t
* ctx
, oberon_object_t
* var
)
198 gen_context_t
* gen_context
= ctx
-> gen_context
;
199 gen_type_t
* gen_type
= var
-> type
-> gen_type
;
201 gen_var_t
* gen_var
= malloc(sizeof *gen_var
);
202 memset(gen_var
, 0, sizeof *gen_var
);
203 var
-> gen_var
= gen_var
;
205 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
206 gcc_jit_type
* gcc_type
= gen_type
-> gcc_type
;
209 oberon_generator_get_full_name(name
, 256, var
);
211 gcc_jit_lvalue
* gcc_lvalue
= NULL
;
212 gcc_jit_param
* gcc_param
= NULL
;
213 gcc_jit_field
* gcc_field
= NULL
;
214 if(var
-> class == OBERON_CLASS_VAR
)
218 gen_proc_t
* gen_func
= var
-> parent
-> gen_proc
;
219 gcc_jit_function
* func
= gen_func
-> gcc_func
;
221 gcc_lvalue
= gcc_jit_function_new_local(func
, NULL
, gcc_type
, name
);
225 gcc_lvalue
= gcc_jit_context_new_global(
226 gcc_context
, NULL
, GCC_JIT_GLOBAL_EXPORTED
, gcc_type
, name
230 else if(var
-> class == OBERON_CLASS_PARAM
)
232 gcc_param
= gcc_jit_context_new_param(gcc_context
, NULL
, gcc_type
, name
);
233 gcc_lvalue
= gcc_jit_param_as_lvalue(gcc_param
);
235 else if(var
-> class == OBERON_CLASS_VAR_PARAM
)
237 gcc_type
= gcc_jit_type_get_pointer(gcc_type
);
238 gcc_param
= gcc_jit_context_new_param(gcc_context
, NULL
, gcc_type
, name
);
239 gcc_lvalue
= gcc_jit_param_as_lvalue(gcc_param
);
241 else if(var
-> class == OBERON_CLASS_FIELD
)
243 gcc_field
= gcc_jit_context_new_field(gcc_context
, NULL
, gcc_type
, name
);
247 oberon_error(ctx
, "oberon_generator_init_var: invalid class %i", var
-> class);
250 gen_var
-> gcc_lvalue
= gcc_lvalue
;
251 gen_var
-> gcc_param
= gcc_param
;
252 gen_var
-> gcc_field
= gcc_field
;
256 oberon_generator_init_proc(oberon_context_t
* ctx
, oberon_object_t
* proc
)
260 oberon_error(ctx
, "generator: local procedures not supported");
263 gen_context_t
* gen_context
= ctx
-> gen_context
;
264 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
266 gen_proc_t
* gen_proc
= malloc(sizeof *gen_proc
);
267 memset(gen_proc
, 0, sizeof *gen_proc
);
268 proc
-> gen_proc
= gen_proc
;
271 oberon_generator_get_full_name(name
, 256, proc
);
273 gen_type_t
* gen_result_type
= proc
-> type
-> base
-> gen_type
;
274 gcc_jit_type
* result_type
= gen_result_type
-> gcc_type
;
276 /* Строим список параметров */
277 int num_param
= proc
-> type
-> num_decl
;
278 oberon_object_t
* o
= proc
-> type
-> decl
;
279 gcc_jit_param
* params
[num_param
];
280 for(int i
= 0; i
< num_param
; i
++)
282 gen_var_t
* param_var
= o
-> gen_var
;
283 params
[i
] = param_var
-> gcc_param
;
287 gcc_jit_function
* gcc_func
;
288 gcc_func
= gcc_jit_context_new_function(
289 gcc_context
, NULL
, GCC_JIT_FUNCTION_EXPORTED
, result_type
, name
, num_param
, params
, 0
292 gen_proc
-> gcc_func
= gcc_func
;
295 // =======================================================================
297 // =======================================================================
299 static gcc_jit_rvalue
* rvalue_from_item(oberon_context_t
* ctx
, oberon_item_t
* item
);
300 static gcc_jit_rvalue
* rvalue_from_expr(oberon_context_t
* ctx
, oberon_expr_t
* expr
);
303 oberon_generate_begin_module(oberon_context_t
* ctx
)
305 gen_context_t
* gen_context
= ctx
-> gen_context
;
306 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
309 snprintf(name
, 256, "%s_BEGIN", ctx
-> mod
-> name
);
311 gcc_jit_type
* void_type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_VOID
);
312 gcc_jit_function
* func
= gcc_jit_context_new_function(
313 gcc_context
, NULL
, GCC_JIT_FUNCTION_EXPORTED
, void_type
, name
, 0, NULL
, 0
315 gcc_jit_block
* gcc_block
= gcc_jit_function_new_block(func
, NULL
);
317 oberon_generator_open_block(gen_context
, gcc_block
);
321 oberon_generate_end_module(oberon_context_t
* ctx
)
323 gen_context_t
* gen_context
= ctx
-> gen_context
;
324 gcc_jit_block
* gcc_block
= gen_context
-> block
-> gcc_block
;
326 gcc_jit_block_end_with_void_return(gcc_block
, NULL
);
328 oberon_generator_close_block(gen_context
);
332 oberon_generate_begin_proc(oberon_context_t
* ctx
, oberon_object_t
* proc
)
334 gen_context_t
* gen_context
= ctx
-> gen_context
;
335 gen_proc_t
* gen_proc
= proc
-> gen_proc
;
337 gcc_jit_function
* func
= gen_proc
-> gcc_func
;
338 gcc_jit_block
* gcc_block
= gcc_jit_function_new_block(func
, NULL
);
340 oberon_generator_open_block(gen_context
, gcc_block
);
344 oberon_generate_call_proc(oberon_context_t
* ctx
, oberon_expr_t
* desig
)
346 gen_context_t
* gen_context
= ctx
-> gen_context
;
347 gen_block_t
* gen_block
= gen_context
-> block
;
348 gcc_jit_block
* block
= gen_block
-> gcc_block
;
350 gcc_jit_rvalue
* return_value
;
351 return_value
= rvalue_from_expr(ctx
, desig
);
352 gcc_jit_block_add_eval(block
, NULL
, return_value
);
356 oberon_generate_end_proc(oberon_context_t
* ctx
)
358 gen_context_t
* gen_context
= ctx
-> gen_context
;
359 oberon_generator_close_block(gen_context
);
363 oberon_generate_return(oberon_context_t
* ctx
, oberon_expr_t
* expr
)
365 gen_context_t
* gen_context
= ctx
-> gen_context
;
366 gen_block_t
* gen_block
= gen_context
-> block
;
367 gcc_jit_block
* gcc_block
= gen_block
-> gcc_block
;
371 gcc_jit_block_end_with_void_return(gcc_block
, NULL
);
375 gcc_jit_rvalue
* r
= rvalue_from_expr(ctx
, expr
);
376 gcc_jit_block_end_with_return(gcc_block
, NULL
, r
);
380 static gcc_jit_lvalue
*
381 lvalue_from_item(oberon_context_t
* ctx
, oberon_item_t
* item
)
383 gen_context_t
* gen_context
= ctx
-> gen_context
;
384 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
386 gcc_jit_lvalue
* left
;
388 if(item
-> mode
== MODE_VAR
)
390 if(item
-> var
-> class == OBERON_CLASS_PROC
)
392 oberon_error(ctx
, "casting static procedure to pointer not supported by generator");
395 gen_var_t
* gen_var
= item
-> var
-> gen_var
;
396 left
= gen_var
-> gcc_lvalue
;
397 if(item
-> var
-> class == OBERON_CLASS_VAR_PARAM
)
399 gcc_jit_rvalue
* r
= gcc_jit_lvalue_as_rvalue(left
);
400 left
= gcc_jit_rvalue_dereference(r
, NULL
);
403 else if(item
-> mode
== MODE_INDEX
)
405 assert(item
-> num_args
== 1);
406 gcc_jit_rvalue
* parent
= rvalue_from_item(ctx
, item
-> parent
);
407 gcc_jit_rvalue
* index
= rvalue_from_expr(ctx
, item
-> args
);
408 left
= gcc_jit_context_new_array_access(gcc_context
, NULL
, parent
, index
);
410 else if(item
-> mode
== MODE_FIELD
)
412 printf("lvalue_from_item: %s\n", item
-> var
-> name
);
413 gen_var_t
* gen_var
= item
-> var
-> gen_var
;
414 gcc_jit_field
* gcc_field
= gen_var
-> gcc_field
;
416 gcc_jit_lvalue
* parent
= lvalue_from_item(ctx
, item
-> parent
);
417 left
= gcc_jit_lvalue_access_field(parent
, NULL
, gcc_field
);
419 else if(item
-> mode
== MODE_DEREF
)
421 gcc_jit_rvalue
* parent
= rvalue_from_item(ctx
, item
-> parent
);
422 left
= gcc_jit_rvalue_dereference(parent
, NULL
);
426 oberon_error(ctx
, "invalid lvalue expression");
432 static gcc_jit_lvalue
*
433 lvalue_from_expr(oberon_context_t
*ctx
, oberon_expr_t
* expr
)
435 gcc_jit_lvalue
* left
;
436 oberon_item_t
* item
;
440 item
= (oberon_item_t
*) expr
;
441 left
= lvalue_from_item(ctx
, item
);
445 oberon_error(ctx
, "invalid lvalue expression");
451 static gcc_jit_rvalue
*
452 rvalue_from_item(oberon_context_t
* ctx
, oberon_item_t
* item
)
454 gen_context_t
* gen_context
= ctx
-> gen_context
;
455 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
457 gcc_jit_rvalue
* right
;
458 if(item
-> mode
== MODE_VAR
)
460 gcc_jit_lvalue
* left
= lvalue_from_item(ctx
, item
);
461 right
= gcc_jit_lvalue_as_rvalue(left
);
463 else if(item
-> mode
== MODE_INTEGER
)
465 gcc_jit_type
* int_type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_INT
);
466 right
= gcc_jit_context_new_rvalue_from_int(gcc_context
, int_type
, item
-> integer
);
468 else if(item
-> mode
== MODE_BOOLEAN
)
470 gcc_jit_type
* bool_type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_BOOL
);
473 right
= gcc_jit_context_one(gcc_context
, bool_type
);
477 right
= gcc_jit_context_zero(gcc_context
, bool_type
);
480 else if(item
-> mode
== MODE_CALL
)
482 oberon_type_t
* signature
= item
-> var
-> type
;
483 gen_proc_t
* gen_proc
= item
-> var
-> gen_proc
;
485 int num_args
= item
-> num_args
;
486 gcc_jit_rvalue
*args
[num_args
];
488 oberon_expr_t
* expr
= item
-> args
;
489 oberon_object_t
* arg_param
= signature
-> decl
;
490 for(int i
= 0; i
< num_args
; i
++)
492 if(arg_param
-> class == OBERON_CLASS_VAR_PARAM
)
494 gcc_jit_lvalue
* left
= lvalue_from_expr(ctx
, expr
);
495 args
[i
] = gcc_jit_lvalue_get_address(left
, NULL
);
499 args
[i
] = rvalue_from_expr(ctx
, expr
);
502 arg_param
= arg_param
-> next
;
505 gcc_jit_rvalue
* fnptr
;
506 gcc_jit_function
* func
;
507 switch(item
-> var
-> class)
509 case OBERON_CLASS_PROC
:
510 func
= gen_proc
-> gcc_func
;
511 right
= gcc_jit_context_new_call(
512 gcc_context
, NULL
, func
, num_args
, args
515 case OBERON_CLASS_VAR
:
516 case OBERON_CLASS_VAR_PARAM
:
517 case OBERON_CLASS_PARAM
:
518 fnptr
= gcc_jit_lvalue_as_rvalue(item
-> var
-> gen_var
-> gcc_lvalue
);
519 right
= gcc_jit_context_new_call_through_ptr(
520 gcc_context
, NULL
, fnptr
, num_args
, args
528 else if(item
-> mode
== MODE_INDEX
)
530 gcc_jit_lvalue
* left
= lvalue_from_item(ctx
, item
);
531 right
= gcc_jit_lvalue_as_rvalue(left
);
533 else if(item
-> mode
== MODE_FIELD
)
535 gen_var_t
* gen_var
= item
-> var
-> gen_var
;
536 gcc_jit_field
* gcc_field
= gen_var
-> gcc_field
;
538 gcc_jit_rvalue
* parent
= rvalue_from_item(ctx
, item
-> parent
);
539 right
= gcc_jit_rvalue_access_field(parent
, NULL
, gcc_field
);
541 else if(item
-> mode
== MODE_DEREF
)
543 gcc_jit_lvalue
* left
= lvalue_from_item(ctx
, item
);
544 right
= gcc_jit_lvalue_as_rvalue(left
);
546 else if(item
-> mode
== MODE_NIL
)
548 gcc_jit_type
* type
= gcc_jit_context_get_type(gcc_context
, GCC_JIT_TYPE_VOID_PTR
);
549 right
= gcc_jit_context_null(gcc_context
, type
);
553 oberon_error(ctx
, "rvalue_from_item: invalid mode %i", item
-> mode
);
560 int type
; // 0 - unary, 1 - binary, 2 - comp
562 enum gcc_jit_unary_op unary_op
;
563 enum gcc_jit_binary_op binary_op
;
564 enum gcc_jit_comparison comp_op
;
567 { 0, .unary_op
= GCC_JIT_UNARY_OP_MINUS
},
568 { 0, .unary_op
= GCC_JIT_UNARY_OP_BITWISE_NEGATE
},
569 { 0, .unary_op
= GCC_JIT_UNARY_OP_LOGICAL_NEGATE
},
570 { 0, .unary_op
= GCC_JIT_UNARY_OP_ABS
},
572 { 1, .binary_op
= GCC_JIT_BINARY_OP_PLUS
},
573 { 1, .binary_op
= GCC_JIT_BINARY_OP_MINUS
},
574 { 1, .binary_op
= GCC_JIT_BINARY_OP_MULT
},
575 { 1, .binary_op
= GCC_JIT_BINARY_OP_DIVIDE
},
576 { 1, .binary_op
= GCC_JIT_BINARY_OP_MODULO
},
577 { 1, .binary_op
= GCC_JIT_BINARY_OP_BITWISE_AND
},
578 { 1, .binary_op
= GCC_JIT_BINARY_OP_BITWISE_XOR
},
579 { 1, .binary_op
= GCC_JIT_BINARY_OP_BITWISE_OR
},
580 { 1, .binary_op
= GCC_JIT_BINARY_OP_LOGICAL_AND
},
581 { 1, .binary_op
= GCC_JIT_BINARY_OP_LOGICAL_OR
},
583 { 2, .comp_op
= GCC_JIT_COMPARISON_EQ
},
584 { 2, .comp_op
= GCC_JIT_COMPARISON_NE
},
585 { 2, .comp_op
= GCC_JIT_COMPARISON_LT
},
586 { 2, .comp_op
= GCC_JIT_COMPARISON_LE
},
587 { 2, .comp_op
= GCC_JIT_COMPARISON_GT
},
588 { 2, .comp_op
= GCC_JIT_COMPARISON_GE
}
591 static gcc_jit_rvalue
*
592 rvalue_from_operator(oberon_context_t
* ctx
, oberon_oper_t
* operator)
594 gcc_jit_rvalue
* right
;
596 gen_context_t
* gen_context
= ctx
-> gen_context
;
597 gen_type_t
* gen_type
= operator -> result
-> gen_type
;
598 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
599 gcc_jit_type
* result_type
= gen_type
-> gcc_type
;
601 int expr_type
= op_table
[operator -> op
].type
;
604 enum gcc_jit_unary_op op
= op_table
[operator -> op
].unary_op
;
605 gcc_jit_rvalue
* l
= rvalue_from_expr(ctx
, operator -> left
);
606 right
= gcc_jit_context_new_unary_op(gcc_context
, NULL
, op
, result_type
, l
);
608 else if(expr_type
== 1)
610 enum gcc_jit_unary_op op
= op_table
[operator -> op
].binary_op
;
611 gcc_jit_rvalue
* l
= rvalue_from_expr(ctx
, operator -> left
);
612 gcc_jit_rvalue
* r
= rvalue_from_expr(ctx
, operator -> right
);
613 right
= gcc_jit_context_new_binary_op(gcc_context
, NULL
, op
, result_type
, l
, r
);
615 else if(expr_type
== 2)
617 enum gcc_jit_comparison op
= op_table
[operator -> op
].comp_op
;
618 gcc_jit_rvalue
* l
= rvalue_from_expr(ctx
, operator -> left
);
619 gcc_jit_rvalue
* r
= rvalue_from_expr(ctx
, operator -> right
);
620 right
= gcc_jit_context_new_comparison(gcc_context
, NULL
, op
, l
, r
);
624 oberon_error(ctx
, "rvalue_from_operator: wat");
630 static gcc_jit_rvalue
*
631 rvalue_from_expr(oberon_context_t
* ctx
, oberon_expr_t
* expr
)
633 gcc_jit_rvalue
* right
;
637 oberon_item_t
* item
= (oberon_item_t
*) expr
;
638 right
= rvalue_from_item(ctx
, item
);
642 oberon_oper_t
* operator = (oberon_oper_t
*) expr
;
643 right
= rvalue_from_operator(ctx
, operator);
650 oberon_generate_assign(oberon_context_t
* ctx
, oberon_expr_t
* src
, oberon_expr_t
* dst
)
652 gcc_jit_lvalue
* left
;
653 left
= lvalue_from_expr(ctx
, dst
);
655 gcc_jit_rvalue
* right
;
656 right
= rvalue_from_expr(ctx
, src
);
660 if(src
-> item
.mode
== MODE_NIL
)
662 gen_context_t
* gen_context
= ctx
-> gen_context
;
663 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
664 gen_type_t
* gen_type
= dst
-> result
-> gen_type
;
665 gcc_jit_type
* cast_to_type
= gen_type
-> gcc_type
;
666 right
= gcc_jit_context_new_cast(gcc_context
, NULL
, right
, cast_to_type
);
670 printf("oberon_generate_assign: class %i := class %i\n", dst
-> result
-> class, src
-> result
-> class);
672 gen_context_t
* gen_context
= ctx
-> gen_context
;
673 gen_block_t
* gen_block
= gen_context
-> block
;
674 gcc_jit_block
* gcc_block
= gen_block
-> gcc_block
;
675 gcc_jit_block_add_assignment(gcc_block
, NULL
, left
, right
);
679 oberon_generate_code(oberon_context_t
* ctx
)
681 gen_context_t
* gen_context
= ctx
-> gen_context
;
682 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
684 gcc_jit_result
* gcc_result
;
685 gcc_result
= gcc_jit_context_compile(gcc_context
);
687 gen_context
-> gcc_result
= gcc_result
;
689 // ctx -> mod -> begin = gcc_jit_result_get_code(gcc_result, "BEGIN");
693 oberon_generator_dump(oberon_context_t
* ctx
, char * path
)
695 gen_context_t
* gen_context
= ctx
-> gen_context
;
696 gcc_jit_context
* gcc_context
= gen_context
-> gcc_context
;
697 gcc_jit_context_dump_to_file(gcc_context
, path
, 0);
701 oberon_generator_get_procedure(oberon_context_t
* ctx
, const char * name
)
703 gen_context_t
* gen_context
= ctx
-> gen_context
;
704 gcc_jit_result
* gcc_result
= gen_context
-> gcc_result
;
706 return gcc_jit_result_get_code(gcc_result
, name
);
710 oberon_generator_get_var(oberon_context_t
* ctx
, const char * name
)
712 gen_context_t
* gen_context
= ctx
-> gen_context
;
713 gcc_jit_result
* gcc_result
= gen_context
-> gcc_result
;
715 return gcc_jit_result_get_global(gcc_result
, name
);