Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
7646c40
new separation
kheradmand Dec 21, 2015
55c8925
small fix
kheradmand Dec 22, 2015
2a2a0bc
temp changes
kheradmand Dec 23, 2015
6bd014a
rvm compiler
xiaohe27 Apr 2, 2016
4d15bd9
update rvm-compiler.k
xiaohe27 Apr 2, 2016
7938d64
traversed rvm ast!
xiaohe27 Apr 2, 2016
6731297
migrate to latest k (ee3bdc2066c29d)
xiaohe27 Apr 2, 2016
cf1ddd8
print package declaration
xiaohe27 Apr 2, 2016
92e76c2
restructure the logic package
xiaohe27 Apr 2, 2016
f796d8a
add some new cells for rvm-compiler
xiaohe27 Apr 2, 2016
36a2a8c
print package decl
xiaohe27 Apr 2, 2016
06333db
spec name and params
xiaohe27 Apr 2, 2016
761b384
decl stub
xiaohe27 Apr 2, 2016
ade5b95
rules for adding events.
xiaohe27 Apr 2, 2016
adf6217
add events if not recorded
xiaohe27 Apr 2, 2016
756f0a4
rm empty list
xiaohe27 Apr 2, 2016
a85e0e2
add the output of rv-monitor on a fsm property for future reference
xiaohe27 Apr 3, 2016
c089065
code stub of extracting info from properties
xiaohe27 Apr 3, 2016
9fee253
debug
xiaohe27 Apr 3, 2016
37d1bf6
update
xiaohe27 Apr 3, 2016
2dfa95c
update
xiaohe27 Apr 3, 2016
ade6380
more test inputs
xiaohe27 Apr 3, 2016
65a5054
save work
xiaohe27 Apr 4, 2016
0feebdd
temp change
xiaohe27 Apr 4, 2016
157534e
store the ast node into cell and rely on the print function
xiaohe27 Apr 4, 2016
f558d0a
place different ast nodes into different cells
xiaohe27 Apr 6, 2016
194f91f
plan: develop a lib that takes kast as input, produces kast as output
xiaohe27 Apr 7, 2016
9824075
use K's Bool type in ltl-syntax
xiaohe27 Apr 7, 2016
050fee0
fsm and ere
xiaohe27 Apr 7, 2016
3c12bde
update fsm.k
xiaohe27 Apr 8, 2016
a9e7d16
not support alias at present
xiaohe27 Apr 8, 2016
cd94280
confirm mop compiler does not support alias either
xiaohe27 Apr 8, 2016
330be06
try to disambiguate
xiaohe27 Apr 8, 2016
f13ed1d
k-version
xiaohe27 Apr 8, 2016
05747e3
smt translation failure
xiaohe27 Apr 8, 2016
ab43d06
states number ok
xiaohe27 Apr 8, 2016
65b5d2a
save work
xiaohe27 Apr 8, 2016
c2053df
add comments
xiaohe27 Apr 8, 2016
4b021f7
test multiple state definition
xiaohe27 Apr 8, 2016
da82afc
restore formula cell in the second scan
xiaohe27 Apr 8, 2016
4452cdf
debug
xiaohe27 Apr 8, 2016
54514c4
debug
xiaohe27 Apr 8, 2016
e37e7f9
use nested cells to encode complex map
xiaohe27 Apr 9, 2016
ff85042
handle undefined event
xiaohe27 Apr 9, 2016
9a1ef8c
encode transition functions as int arrays, indexed by event names; ch…
xiaohe27 Apr 9, 2016
4669870
add more test rvm files
xiaohe27 Apr 9, 2016
61b0896
clean up
xiaohe27 Apr 9, 2016
2eb8ba4
print int array
xiaohe27 Apr 9, 2016
b019b71
debug
xiaohe27 Apr 9, 2016
3d391d6
get int array
xiaohe27 Apr 9, 2016
3c10aec
debug
xiaohe27 Apr 9, 2016
4bfe0c5
translate the transition functions to int arrays correctly
xiaohe27 Apr 9, 2016
fa8a2fc
todo
xiaohe27 Apr 9, 2016
97d319a
add some templates
xiaohe27 Apr 9, 2016
3ad70a4
update
xiaohe27 Apr 9, 2016
f9b0c0a
add c-monitor-template
xiaohe27 Apr 10, 2016
f7f1640
test: start from some structure, end with some other structure in k cell
xiaohe27 Apr 10, 2016
6cf8f41
test code g generation idea
xiaohe27 Apr 10, 2016
e50b6fc
add logic type cell to all rules in fsm.k
xiaohe27 Apr 10, 2016
5065a74
update template
xiaohe27 Apr 10, 2016
119e7f8
debug
xiaohe27 Apr 10, 2016
ce9d901
partial rewrite of ok
xiaohe27 Apr 12, 2016
6fe31cf
global init
xiaohe27 Apr 12, 2016
065d0c8
make monitor syntax simpler
xiaohe27 Apr 12, 2016
45f07ca
add rules of handling include stmts, global decl stmts to c-monitor-t…
xiaohe27 Apr 12, 2016
b7c3e39
update
xiaohe27 Apr 12, 2016
694fda7
debug
xiaohe27 Apr 12, 2016
f645cb9
generate local state vars initialization and reset function
xiaohe27 Apr 12, 2016
6d5fbec
debug
xiaohe27 Apr 12, 2016
5b66d86
debug
xiaohe27 Apr 12, 2016
caede60
debug ok
xiaohe27 Apr 13, 2016
af4c376
revise config structure to allow multiple properties
xiaohe27 Apr 13, 2016
e40114e
remove event number cell
xiaohe27 Apr 13, 2016
c49bd7e
make it compile
xiaohe27 Apr 13, 2016
3d88fae
debug
xiaohe27 Apr 13, 2016
251a867
debug
xiaohe27 Apr 13, 2016
74ca63a
add function to get size of properties
xiaohe27 Apr 14, 2016
1f8acf3
save work
xiaohe27 Apr 14, 2016
424494d
gen initial props cells
xiaohe27 Apr 14, 2016
3ad1b23
props are ranked
xiaohe27 Apr 14, 2016
01f628d
debug
xiaohe27 Apr 15, 2016
5934047
debug
xiaohe27 Apr 15, 2016
8af99a0
enable the reset rule when a formula has just been processed
xiaohe27 Apr 15, 2016
131d1ce
2 properties in one spec: final config ok: two sets of transition fun…
xiaohe27 Apr 15, 2016
7714199
save state maps for each property
xiaohe27 Apr 15, 2016
6d16670
identify the weaknesses of cur rv-monitor
xiaohe27 Apr 15, 2016
a548b90
identify the weaknesses of cur rv-monitor
xiaohe27 Apr 15, 2016
451377c
update comments in problems-identified.txt
xiaohe27 Apr 15, 2016
8815f15
re-arrange module structure
xiaohe27 Apr 15, 2016
4aeefcb
debug
xiaohe27 Apr 17, 2016
ba2d66c
debug multi-property
xiaohe27 Apr 17, 2016
a19fd06
import required module
xiaohe27 Apr 17, 2016
f754aa4
multi-property ok in windows
xiaohe27 Apr 17, 2016
96e6c5d
update k-version-info
xiaohe27 Apr 17, 2016
32d4c11
local state vars init
xiaohe27 Apr 18, 2016
f7563a5
local state vars init
xiaohe27 Apr 18, 2016
a8506f4
update reset func
xiaohe27 Apr 22, 2016
07875fc
make it kompile
xiaohe27 Apr 22, 2016
f421ff2
add a rule
xiaohe27 Apr 22, 2016
bdeae23
update the include section. New line can be inserted between each lis…
xiaohe27 Apr 22, 2016
ecc1596
make it compile
xiaohe27 Apr 23, 2016
1f12b32
get list of state transition function symbols
xiaohe27 Apr 23, 2016
53f17c7
re-order the state transition functions: from small to large
xiaohe27 Apr 23, 2016
a4e9f48
save work
xiaohe27 Apr 23, 2016
2f8fc30
save work
xiaohe27 Apr 23, 2016
ebfad40
add function for printing state transition function
xiaohe27 Apr 23, 2016
6211e39
debug
xiaohe27 Apr 23, 2016
d736eef
state transition function encoded as int array
xiaohe27 Apr 23, 2016
badf9c4
resolve symbol
xiaohe27 Apr 23, 2016
dcf5a75
fix bug in windows
xiaohe27 Apr 24, 2016
384955d
update
xiaohe27 Apr 24, 2016
379d807
local state vars initialization
xiaohe27 Apr 24, 2016
39469f0
event action module
xiaohe27 Apr 24, 2016
e96481a
make it compile
xiaohe27 Apr 24, 2016
671ae8d
define structures of event action method
xiaohe27 Apr 24, 2016
fc96f2c
update
xiaohe27 Apr 25, 2016
a0b77dc
code stub for printing event methods' params and action code
xiaohe27 Apr 25, 2016
e386b62
debug
xiaohe27 Apr 25, 2016
f2a502d
change the syntax of Dim, Dims and ArrayType
xiaohe27 Apr 25, 2016
8cb96d4
empty block ok
xiaohe27 Apr 26, 2016
ab534fb
print bubble successfully!
xiaohe27 Apr 26, 2016
f25820c
print event actions
xiaohe27 Apr 26, 2016
c1e0d85
code stub for gathering handler info
xiaohe27 Apr 26, 2016
358f6fb
debug
xiaohe27 Apr 26, 2016
77eaefa
add handler.txt
xiaohe27 Apr 26, 2016
346a924
update HandlerDecList syntax
xiaohe27 Apr 27, 2016
b7bf1ad
debug non-termination
xiaohe27 Apr 27, 2016
667444f
debug ok
xiaohe27 Apr 27, 2016
b3f000a
rewrite part of the main body to an abstract term
xiaohe27 Apr 27, 2016
081a63a
add more structures
xiaohe27 Apr 27, 2016
07c2543
update monitor state
xiaohe27 Apr 28, 2016
b60d3e8
update global state
xiaohe27 May 10, 2016
c4ffe32
global state var update successfully
xiaohe27 May 10, 2016
a74ae89
rewrite to handler code
xiaohe27 May 10, 2016
c437363
update the local states and global states
xiaohe27 May 10, 2016
8fb6632
function for generating handler code
xiaohe27 May 10, 2016
12cbb15
add code gen
xiaohe27 May 10, 2016
4d6448e
generate handler code
xiaohe27 May 11, 2016
15569c2
add decl bubble list to output code
xiaohe27 May 11, 2016
a1a11fe
generate the .c code successfully!
xiaohe27 May 11, 2016
f89bc64
re-organize the tests
xiaohe27 May 11, 2016
71364b3
re-structure the test
xiaohe27 May 11, 2016
9b00c3a
refactor
xiaohe27 May 11, 2016
f0a3143
fix a typo
xiaohe27 May 11, 2016
4fcf2d3
update
xiaohe27 May 11, 2016
4860212
update
xiaohe27 May 11, 2016
5847bf1
TODO:header template
xiaohe27 May 11, 2016
3a99692
generate header contents
xiaohe27 May 11, 2016
4795596
add scripts for tests
xiaohe27 May 11, 2016
01ce5bb
add seatbelt benchmark
xiaohe27 May 11, 2016
e701145
refactor
xiaohe27 May 11, 2016
7fd5a19
update make file
xiaohe27 May 11, 2016
a916fb7
make it compile
xiaohe27 May 11, 2016
bd21545
print import decl list
xiaohe27 May 12, 2016
368e451
add
xiaohe27 May 12, 2016
e862a60
#include statements generated successfully
xiaohe27 May 12, 2016
94db2fb
fix a bug
xiaohe27 May 12, 2016
e4d8fb8
make generated c code compile
xiaohe27 May 12, 2016
4a4f137
update make file
xiaohe27 May 12, 2016
5dde711
update make file: clean
xiaohe27 May 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
test/rvm/property-db
test/mop/property-db
*-kompiled/
*.bak
20 changes: 20 additions & 0 deletions ToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1. develop a template of c program.
2. rewrite the template to real c code string.

3. handle the case where multiple formulas are inside one spec.

For each property, there will be a matrix of integers encoding the transition functions.

Each row of the matrix encodes an event transition function, and the row number is the index of the corresponding event.

So for each property, we can simple keep a matrix and two string arrays (one for events and one for states).

***
P.S. Need to consider the corner cases:
a) A defined event never occurs inside the formula.

b) Undefined event occurs in the formula.

c) Duplicate definitions for events/states.

d) Undefined state in the formula.
16 changes: 16 additions & 0 deletions problems-identified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. current rv-monitor for c part only supports one pair of property and handler
in one spec.

the part for java is better, but the generated code does not compile due to
re-define some vars in the same runtime monitor function (the method in which
event dispatching occurs).

***
In fact, even if the compile-time errors are corrected, the generated code for
multi-properties spec is still incorrect.

The transition functions for each property can be generated, but
the monitor is not keeping track of the states of multiple fsm.
It only keeps track of a single current state, which is not
the combination of states for each fsm, no matter how many
properties you have.
143 changes: 143 additions & 0 deletions src/c-monitor-code-template/c-monitor-event-action.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
require "../rvm/rvm-compiler-core.k"
require "c-monitor-template-syntax.k"
require "../helper/code-gen.k"
require "../helper/util.k"

module C-MONITOR-EVENT-ACTION
imports RVM-COMPILER-CORE
imports C-MONITOR-TEMPLATE-SYNTAX
imports CODE-GEN
imports UTIL

rule <k> $main4 => $eventFuncs(size(EL)) </k>
<events> EL:List </events>
<states> _:Map => .Map </states>
<code> CL:List (.List => ListItem("\n")) </code>

rule <k> $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I)) </k>
when I >Int 0

rule <k> $eventFuncs(I:Int) => .K </k>
when I <=Int 0

rule <k> $eFunc(I:Int), $eventFuncs(0) => .K </k>
<methodBody> .K </methodBody>
<k2> .K </k2>

rule <k> $eFunc(I:Int), $eventFuncs(J:Int) => $eFunc(I +Int 1), $eventFuncs(J -Int 1) </k>
<methodBody> .K => $eFunc(I) </methodBody>
<tmpList> _ => .List </tmpList>
<code> CL:List (.List => ListItem("\n")) </code>
when J >Int 0

rule <methodBody> $eFunc(I:Int) => $methHeader(I) {$mbody} </methodBody>

//print method header
rule <methodBody> $methHeader(I:Int) {$mbody} => $mbody2 </methodBody>
<events> EL:List </events>
<specName> SN:String </specName>
//the params of each event, indexed by event id
<eventParams> EPs:List </eventParams>
//the list of event action code, indexed by event id.
<eventAction> EAs:List </eventAction>
<code> Code:List
//method header of event I.
(.List => ListItem(printMethodHeader(SN, getStringI(EL, I), getStringI(EPs, I))))

(.List => ListItem("{\n"))

(.List => ListItem(getStringI(EAs, I))) //the event I's action code
</code>

<header> HeaderCode:List (.List =>
ListItem(printMethodHeader(SN, getStringI(EL, I), getStringI(EPs, I)) +String ";"))
</header>

//store the current event name which will be used to infer event transition function.
<tmpList> .List => ListItem(getStringI(EL, I)) </tmpList>


//////////////////////////////////////////////////////////////////////////////
//state updates
rule <methodBody> $mbody2 => ($stateUpdates(PS) ;; $handlers) </methodBody>
<propSize> PS:Int </propSize>

rule <methodBody> ($stateUpdates(PS:Int) ;; $handlers) =>
$sUpdate(0) ,, $stateUpdates(PS) ;; $handlers
</methodBody>

rule <methodBody>
($sUpdate(I:Int) ,, $stateUpdates(PS:Int) ;; $handlers)
=> $handlers
</methodBody>
when PS <=Int 0

rule <methodBody>
($sUpdate(I:Int) ,, $stateUpdates(PS:Int) ;; $handlers) =>
($sUpdate(I +Int 1) ,, $stateUpdates(PS -Int 1) ;; $handlers)
</methodBody>

<k2> .K => $gsUpdate(I), $lsUpdates(getSize(SML, I)) </k2>
<stateNameMap> SML:List </stateNameMap>

//cache the state map of property I
<states> .Map => getMapI(SML, I) </states>

<propNum> _:Int => I </propNum> //the cur property rank is I
when PS >Int 0

//finish the state updates code
rule <methodBody>
($sUpdate(I:Int) ,, $stateUpdates(0) ;; $handlers) =>
$handlers
</methodBody>
<k2> .K </k2>

//generate global state update code
//when the property size > 1, the event transition function will have property rank as prefix
rule <k2> $gsUpdate(I:Int), $lsUpdates(J:Int) => $lsUpdates(J) </k2>
<specName> SN:String </specName>
<tmpList> ListItem(EN:String) </tmpList> //the tmpList stores the current event name
<code> C:List (.List => ListItem(
globalStateUpdate(globalStateVarI(I), propXEventE(SN, I, EN))
))
</code>
<propSize> PS:Int </propSize>
when PS >Int 1

//only a single property is defined
rule <k2> $gsUpdate(I:Int), $lsUpdates(J:Int) => $lsUpdates(J) </k2>
<specName> SN:String </specName>
<tmpList> ListItem(EN:String) </tmpList> //the tmpList stores the current event name
<code> C:List (.List => ListItem(
globalStateUpdate(globalStateVarI(I), propXEventE(SN, EN))
))
</code>
<propSize> PS:Int </propSize>
when PS <=Int 1

//update local states
rule <k2> $lsUpdate(I:Int) $lsUpdates(0) => .K </k2>
<states> M:Map => .Map </states>


rule <k2> $lsUpdates(I:Int) => $lsUpdate(0) $lsUpdates(I) </k2>

rule <k2> $lsUpdate(I:Int) $lsUpdates(J:Int) => $lsUpdate(I +Int 1) $lsUpdates(J -Int 1) </k2>
<propNum> G:Int </propNum>
<specName> SN:String </specName>
<states> M:Map </states>
//the three args are local state var, global state var, state rank
//localStateVarI(spec name, property rank, state name)
<code> C:List (.List => ListItem(localStateUpdate( localStateVarI(SN, G, getStrKey(M, I)),
globalStateVarI(G), I)))
</code>
when J >Int 0

//handler code and closing parenthesis
rule <methodBody> $handlers => .K </methodBody>
<k2> .K </k2>
<handlersList> HDM:Map </handlersList>
<code> C:List (.List => getHandlerCode(HDM)) (.List => ListItem("\n}\n")) </code>

endmodule
89 changes: 89 additions & 0 deletions src/c-monitor-code-template/c-monitor-template-syntax.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require "domains.k"

module C-MONITOR-TEMPLATE-SYNTAX
imports DOMAINS

//the state transition function is encoded using int array.
syntax CTemplate ::= Include MainBody

syntax MainBody ::= GlobalStatesInit MainBody1

syntax MainBody1 ::= PropStatesInit MainBody2
syntax MainBody2 ::= ResetFunc MainBody3
syntax MainBody3 ::= StateTransitions MainBody4
syntax MainBody4 ::= EventMethods

syntax CTemplate ::= "$CMonitor"
syntax Include ::= "$incl"
syntax MainBody ::= "$main"
syntax MainBody1 ::= "$main1"
syntax MainBody2 ::= "$main2"
syntax MainBody3 ::= "$main3"
syntax MainBody4 ::= "$main4"


syntax GStateVar ::= "$gSVar" "(" Int ")"
syntax GlobalStatesInit ::= "$globalInit" "(" Int ")"
syntax GlobalStatesInit ::= GStateVar "," GlobalStatesInit

syntax StateVar ::= "$sVar" "(" Int "," Int ")" //prop rank, state rank
//args of $localInit: the prop rank, the number of states in the property
syntax LocalStatesInit ::= "$localInit" "(" Int "," Int ")"
syntax LocalStatesInit ::= StateVar "," LocalStatesInit

syntax PropStatesInit ::= "$pStates" "(" Int ")"
syntax PropStatesInit ::= LocalStatesInit ":" PropStatesInit


syntax ResetFunc ::= "$reset"

//the state functions are indexed by property rank and event rank
syntax StateTransitions ::= "$stateFuncs" "(" Int "," Int ")"
syntax StateFunc ::= "$sFunc" "(" Int "," Int ")"
syntax StateTransitions ::= StateFunc
| StateFunc "," StateTransitions
| "$emptyTransition"

syntax EventMethods ::= "$eventFuncs" "(" Int ")"
syntax EventMethod ::= "$eFunc" "(" Int ")"
syntax EventMethods ::= EventMethod | EventMethod "," EventMethods

//the structure of an event action method
//based on the configuration, the same method body prototype
//can be rewritten to different concrete method bodies.
syntax MethodHeader ::= "$methHeader" "(" Int ")"

syntax EventAction ::= "$eAction" "(" Int ")"

//update the states in each property.
syntax MonitorStateUpdates ::= "$stateUpdates" "(" Int ")"
syntax MonitorStateUpdate ::= "$sUpdate" "(" Int ")"
syntax MonitorStateUpdates ::= MonitorStateUpdate
| MonitorStateUpdate ",," MonitorStateUpdates

syntax HandlerActions ::= "$handlers"

syntax MethodBody ::= EventAction ";;" MethodBody2
syntax MethodBody2 ::= MonitorStateUpdates ";;" HandlerActions

syntax EventMethod ::= MethodHeader "{" MethodBody "}"

syntax MethodBody ::= "$mbody"
syntax MethodBody2 ::= "$mbody2"

//in the section of monitor state updates, there are two parts:
//1. update the current state of the monitor,
//2. update the state predicates for each state in the automata (whether that state is on)
syntax MonitorStateUpdate ::= GlobalStateUpdate "," LocalStateUpdates
//the int argument is the property rank of the state var
syntax GlobalStateUpdate ::= "$gsUpdate" "(" Int ")"

//the arg is the number of states in the current property
syntax LocalStateUpdates ::= "$lsUpdates" "(" Int ")"

//by querying the configuration, we can build the entry of state name (string) |-> state rank (int)
syntax LocalStateUpdate ::= "$lsUpdate" "(" Int ")"

syntax LocalStateUpdates ::= LocalStateUpdate | LocalStateUpdate LocalStateUpdates

endmodule
Loading