Commit 02e9ded4 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add save/restore context function in simulator codegen

parent 6448acbe
......@@ -273,6 +273,10 @@ LD_LIBRARY_PATH=. opengeode-simulator
process_level_decl.append('end record;')
process_level_decl.append('{ctxt}: {ctxt}_Ty;'.format(ctxt=LPREFIX))
if simu:
# Exhaustive simulation needs a backup of the context to quickly undo
process_level_decl.append('{ctxt}_bk: {ctxt}_Ty;'.format(ctxt=LPREFIX))
process_level_decl.append('CS_Only : constant Integer := {};'
.format(len(process.transitions)))
......@@ -360,8 +364,8 @@ package {process_name} is'''.format(process_name=process_name,
dll_api = []
if simu:
ads_template.append('-- DLL Interface')
dll_api.append('-- DLL Interface to remotely change internal data')
ads_template.append('-- API for simulation via DLL')
dll_api.append('-- API to remotely change internal data')
# Add function allowing to trace current state as a string
process_level_decl.append("function get_state return chars_ptr "
"is (New_String(states'Image({ctxt}.state)))"
......@@ -378,6 +382,24 @@ package {process_name} is'''.format(process_name=process_name,
dll_api.append("end set_state;")
dll_api.append("")
# Save/restore state allow one step undo, as needed for model checking
save_state_decl = "procedure save_context"
restore_state_decl = "procedure restore_context"
ads_template.append("{};".format(save_state_decl))
ads_template.append('pragma Export(C, save_context, "_save_context");')
ads_template.append("{};".format(restore_state_decl))
ads_template.append('pragma Export(C, restore_context, "_restore_context");')
dll_api.append("{} is".format(save_state_decl))
dll_api.append("begin")
dll_api.append("{ctxt} := {ctxt}_bk;".format(ctxt=LPREFIX))
dll_api.append("end save_context;")
dll_api.append("")
dll_api.append("{} is".format(restore_state_decl))
dll_api.append("begin")
dll_api.append("{ctxt}_bk := {ctxt};".format(ctxt=LPREFIX))
dll_api.append("end restore_context;")
dll_api.append("")
# interface to get/set state aggregations XXX add to C generator
for substates in aggregates.viewvalues():
for each in substates:
......@@ -392,11 +414,12 @@ package {process_name} is'''.format(process_name=process_name,
# Functions to get gobal variables (length and value)
for var_name, (var_type, _) in process.variables.viewitems():
# Getters for local variables
process_level_decl.append("function l_{name}_size return integer "
"is ({prefix}.{name}'Size/8) with Export,"
" Convention => C,"
' Link_Name => "{name}_size";'
.format(prefix=LPREFIX, name=var_name))
# Removed size - this was needed by swig only, not ctypes
# process_level_decl.append("function l_{name}_size return integer "
# "is ({prefix}.{name}'Size/8) with Export,"
# " Convention => C,"
# ' Link_Name => "{name}_size";'
# .format(prefix=LPREFIX, name=var_name))
process_level_decl.append("function l_{name}_value"
" return access {sort} "
"is ({prefix}.{name}'access) with Export,"
......
......@@ -2,8 +2,8 @@
 
# Resource object code
#
# Created: Sat May 21 19:17:08 2016
# by: The Resource Compiler for PySide (Qt v4.8.6)
# Created: Thu Aug 18 19:27:22 2016
# by: The Resource Compiler for PySide (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
 
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1078,7 +1078,6 @@ primary
: TRUE^
| FALSE^
| STRING
| NULL^
| PLUS_INFINITY^
| MINUS_INFINITY^
| INT^
......@@ -1214,12 +1213,12 @@ variable_access
: variable_id
;
/*
operator_application
: operator_id '('active_expression_list ')'
;
/*
active_expression_list
: active_expression (',' expression_list)?
;
......@@ -1540,7 +1539,6 @@ REM : R E M;
TRUE : T R U E;
FALSE : F A L S E;
ASNFILENAME : A S N F I L E N A M E;
NULL : N U L L;
PLUS_INFINITY : P L U S '-' I N F I N I T Y;
MINUS_INFINITY : M I N U S '-' I N F I N I T Y;
MANTISSA : M A N T I S S A;
......
Markdown is supported
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