diff --git a/generator.c b/generator.c
index 4c3a984a6b226d5377ffb5fdcfa0ca5979ffd212..419a2b22c4c2dbb765a9656163f701c645637eb8 100644 (file)
--- a/generator.c
+++ b/generator.c
#include "oberon.h"
#include "generator.h"
#include "oberon.h"
#include "generator.h"
-#include <libgccjit.h>
-
static void printcontext(oberon_context_t * ctx, char * s)
{
/*
static void printcontext(oberon_context_t * ctx, char * s)
{
/*
// ALLOC
// =======================================================================
// ALLOC
// =======================================================================
+static void
+oberon_generator_open_block(gen_context_t * gen_context, gcc_jit_block * gcc_block)
+{
+ gen_block_t * block = malloc(sizeof *block);
+ memset(block, 0, sizeof *block);
+
+ block -> gcc_block = gcc_block;
+ block -> up = gen_context -> block;
+
+ gen_context -> block = block;
+}
+
+static void
+oberon_generator_close_block(gen_context_t * gen_context)
+{
+ gen_context -> block = gen_context -> block -> up;
+}
+
void
oberon_generator_init_context(oberon_context_t * ctx)
{
void
oberon_generator_init_context(oberon_context_t * ctx)
{
gcc_jit_field * gcc_field = NULL;
if(var -> class == OBERON_CLASS_VAR)
{
gcc_jit_field * gcc_field = NULL;
if(var -> class == OBERON_CLASS_VAR)
{
- gcc_lvalue = gcc_jit_context_new_global(
- gcc_context, NULL, GCC_JIT_GLOBAL_INTERNAL, gcc_type, name
- );
+ if(var -> local)
+ {
+ gen_proc_t * gen_func = var -> parent -> gen_proc;
+ gcc_jit_function * func = gen_func -> gcc_func;
+
+ gcc_lvalue = gcc_jit_function_new_local(func, NULL, gcc_type, name);
+ }
+ else
+ {
+ gcc_lvalue = gcc_jit_context_new_global(
+ gcc_context, NULL, GCC_JIT_GLOBAL_INTERNAL, gcc_type, name
+ );
+ }
}
else if(var -> class == OBERON_CLASS_PARAM)
{
}
else if(var -> class == OBERON_CLASS_PARAM)
{
void
oberon_generator_init_proc(oberon_context_t * ctx, oberon_object_t * proc)
{
void
oberon_generator_init_proc(oberon_context_t * ctx, oberon_object_t * proc)
{
- assert(proc -> class == OBERON_CLASS_PROC);
+ if(proc -> local)
+ {
+ oberon_error(ctx, "generator: local procedures not supported");
+ }
gen_context_t * gen_context = ctx -> gen_context;
gcc_jit_context * gcc_context = gen_context -> gcc_context;
gen_context_t * gen_context = ctx -> gen_context;
gcc_jit_context * gcc_context = gen_context -> gcc_context;
);
gcc_jit_block * gcc_block = gcc_jit_function_new_block(func, NULL);
);
gcc_jit_block * gcc_block = gcc_jit_function_new_block(func, NULL);
- gen_context -> gcc_block = gcc_block;
+ oberon_generator_open_block(gen_context, gcc_block);
}
void
}
void
printcontext(ctx, "oberon_generate_end_module");
gen_context_t * gen_context = ctx -> gen_context;
printcontext(ctx, "oberon_generate_end_module");
gen_context_t * gen_context = ctx -> gen_context;
- gcc_jit_block * gcc_block = gen_context -> gcc_block;
+ gcc_jit_block * gcc_block = gen_context -> block -> gcc_block;
gcc_jit_block_end_with_void_return(gcc_block, NULL);
gcc_jit_block_end_with_void_return(gcc_block, NULL);
- gen_context -> gcc_block = NULL;
+ oberon_generator_close_block(gen_context);
}
void
}
void
gcc_jit_function * func = gen_proc -> gcc_func;
gcc_jit_block * gcc_block = gcc_jit_function_new_block(func, NULL);
gcc_jit_function * func = gen_proc -> gcc_func;
gcc_jit_block * gcc_block = gcc_jit_function_new_block(func, NULL);
- // TODO make stack for block
- gen_context -> gcc_block = gcc_block;
+ oberon_generator_open_block(gen_context, gcc_block);
}
void
oberon_generate_call_proc(oberon_context_t * ctx, oberon_expr_t * desig)
{
gen_context_t * gen_context = ctx -> gen_context;
}
void
oberon_generate_call_proc(oberon_context_t * ctx, oberon_expr_t * desig)
{
gen_context_t * gen_context = ctx -> gen_context;
- gcc_jit_block * block = gen_context -> gcc_block;
+ gen_block_t * gen_block = gen_context -> block;
+ gcc_jit_block * block = gen_block -> gcc_block;
gcc_jit_rvalue * return_value;
return_value = rvalue_from_expr(ctx, desig);
gcc_jit_rvalue * return_value;
return_value = rvalue_from_expr(ctx, desig);
oberon_generate_end_proc(oberon_context_t * ctx)
{
gen_context_t * gen_context = ctx -> gen_context;
oberon_generate_end_proc(oberon_context_t * ctx)
{
gen_context_t * gen_context = ctx -> gen_context;
- gen_context -> gcc_block = NULL;
+ oberon_generator_close_block(gen_context);
}
void
oberon_generate_return(oberon_context_t * ctx, oberon_expr_t * expr)
{
gen_context_t * gen_context = ctx -> gen_context;
}
void
oberon_generate_return(oberon_context_t * ctx, oberon_expr_t * expr)
{
gen_context_t * gen_context = ctx -> gen_context;
- gcc_jit_block * gcc_block = gen_context -> gcc_block;
+ gen_block_t * gen_block = gen_context -> block;
+ gcc_jit_block * gcc_block = gen_block -> gcc_block;
if(expr == NULL)
{
if(expr == NULL)
{
@@ -584,7 +614,8 @@ oberon_generate_assign(oberon_context_t * ctx, oberon_expr_t * src, oberon_expr_
}
gen_context_t * gen_context = ctx -> gen_context;
}
gen_context_t * gen_context = ctx -> gen_context;
- gcc_jit_block * gcc_block = gen_context -> gcc_block;
+ gen_block_t * gen_block = gen_context -> block;
+ gcc_jit_block * gcc_block = gen_block -> gcc_block;
gcc_jit_block_add_assignment(gcc_block, NULL, left, right);
}
gcc_jit_block_add_assignment(gcc_block, NULL, left, right);
}