Commit 92a7695e authored by dbarbera's avatar dbarbera
Browse files

Added timer reset/set generation

parent f68a5d5d
......@@ -95,6 +95,7 @@ class Scope:
if self.parent:
return self.parent.resolve(name)
else:
print name
raise NameError
......@@ -108,7 +109,8 @@ def generate(ast):
@generate.register(ogAST.Process)
def _process(process):
''' Generate LLVM IR code '''
LOG.info('Generating LLVM IR code for process ' + str(process.processName))
process_name = str(process.processName)
LOG.info('Generating LLVM IR code for process ' + process_name)
global g
g = GlobalState(process)
......@@ -138,6 +140,14 @@ def _process(process):
global_var.initializer = core.Constant.null(var_ty)
g.scope.define(str(name).lower(), global_var)
# Declare timer set/reset functions
for timer in process.timers:
func_name = '%s_RI_set_%s' % (process_name, str(timer))
# TODO: Should be uint?
decl_func(func_name, g.void, [g.i32_ptr])
func_name = '%s_RI_reset_%s' % (process_name, str(timer))
decl_func(func_name, g.void, [])
# Initialize output signals
for signal in process.output_signals:
if 'type' in signal:
......@@ -380,12 +390,28 @@ def _generate_writeln(params):
def _generate_reset_timer(params):
''' Generate the code for the reset timer operator '''
raise NotImplementedError
timer_id = params[0]
reset_func_name = '%s_RI_reset_%s' % (g.name, timer_id.value[0])
reset_func = g.funcs[reset_func_name.lower()]
g.builder.call(reset_func, [])
def _generate_set_timer(params):
''' Generate the code for the set timer operator '''
raise NotImplementedError
timer_expr, timer_id = params
set_func_name = '%s_RI_set_%s' % (g.name, timer_id.value[0])
set_func = g.funcs[set_func_name.lower()]
expr_val = expression(timer_expr)
if type(timer_expr) in [ogAST.PrimPath, ogAST.PrimVariable]:
expr_val = g.builder.load(expr_val)
tmp_ptr = g.builder.alloca(expr_val.type)
g.builder.store(expr_val, tmp_ptr)
g.builder.call(set_func, [tmp_ptr])
@generate.register(ogAST.TaskAssign)
......@@ -946,6 +972,14 @@ def _get_string_cons(str):
return gvar_val
def decl_func(name, return_ty, param_tys):
''' Declare a function '''
func_ty = core.Type.function(return_ty, param_tys)
func = core.Function.new(g.module, func_ty, name)
g.funcs[name.lower()] = func
return func
# TODO: Refactor this into the helper module
def find_basic_type(a_type):
''' Return the ASN.1 basic type of a_type '''
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment