From 7646c40259cb36b71db68bebec384b192e3eacd1 Mon Sep 17 00:00:00 2001 From: kheradmand Date: Mon, 21 Dec 2015 16:19:41 -0600 Subject: [PATCH 001/160] new separation --- src/common/java-bubble-syntax.k | 25 +++++++++++++------------ src/common/type-syntax.k | 2 +- src/logic/boolop-syntax.k | 2 +- src/logic/cfg-syntax.k | 2 +- src/logic/ere-syntax.k | 2 +- src/logic/fsm-syntax.k | 2 +- src/logic/ltl-syntax.k | 2 +- src/logic/srs-syntax.k | 2 +- src/mop/mop-compiler.k | 22 ++++++++++++++++++++-- 9 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/common/java-bubble-syntax.k b/src/common/java-bubble-syntax.k index 8eca60a..aa91e3d 100644 --- a/src/common/java-bubble-syntax.k +++ b/src/common/java-bubble-syntax.k @@ -4,15 +4,15 @@ module JAVA-BUBBLE-SYNTAX imports PACKAGE-SYNTAX //syntax NoBracket ::= r"[^{}]+" [token] //temp workaround for https://github.com/kframework/k/issues/1863 - syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] + syntax NoBracket //::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] syntax BalancedBracket ::= "{" BalancedBracket "}" [klabel('BBracketBlock)] | BalancedBracket BalancedBracket [left, klabel('BBracketCombination)] | NoBracket [klabel('BBracketAtom)] | "{" "}" [klabel('BBracketEmpty)] - syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] - | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] + syntax BlockBubble //::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] + // | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] syntax DecStart ::= IdModifier | IdModifier DecStart @@ -20,7 +20,7 @@ module JAVA-BUBBLE-SYNTAX syntax ClassDecBubble ::= DecStart BlockBubble - syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] + syntax ParamsBubble //::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] syntax MethodDecBubble ::= DecStart ParamsBubble BlockBubble @@ -33,15 +33,15 @@ module JAVA-BUBBLE-SYNTAX //syntax VarInitBubble ::= r"[^;]+" [token, avoid] //temp workaround for https://github.com/kframework/k/issues/1863 - syntax VarInitBubble ::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] + syntax VarInitBubble //::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] - syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] - | MethodDecBubble [token, klabel('DecBubbleMethod)] - | FieldDecBubble [token, klabel('DecBubbleField)] + syntax DecBubble //::= ClassDecBubble [token, klabel('DecBubbleClass)] + // | MethodDecBubble [token, klabel('DecBubbleMethod)] + // | FieldDecBubble [token, klabel('DecBubbleField)] //syntax NoParentheses ::= r"[^()]+" [token] //temp workaround for https://github.com/kframework/k/issues/1863 - syntax NoParentheses ::= r"[^()<][^()]*" [token, klabel('NoParentheses)] + syntax NoParentheses //::= r"[^()<][^()]*" [token, klabel('NoParentheses)] //| "<" [token, klabel('NoParenthesesSingleLT)] syntax BalancedParentheses ::= @@ -50,11 +50,12 @@ module JAVA-BUBBLE-SYNTAX | NoParentheses | "(" ")" - syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb + syntax BoolExpBubble //::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb - syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel('DecBubbleList)] + syntax DecBubbleList // ::= List{DecBubble, ""} [token, klabel('DecBubbleList)] syntax JavaModifier ::= "abstract" | "final" | "interface" | "native" | "private" | "protected" | "public" | "static" | "strict" | "synchronized" | "transient" | "volatile" -endmodule \ No newline at end of file +endmodule + diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index 083eb35..f674e52 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module TYPE-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax PackageName ::= IdList [klabel('PackageName)] syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] diff --git a/src/logic/boolop-syntax.k b/src/logic/boolop-syntax.k index 0388702..146c801 100644 --- a/src/logic/boolop-syntax.k +++ b/src/logic/boolop-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module BOOLOP-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax Not ::= "!" | "not" syntax And ::= "/\\" | "and" | "&&" syntax Or ::= "\\/" | "or" | "||" diff --git a/src/logic/cfg-syntax.k b/src/logic/cfg-syntax.k index 4310648..76eb7da 100644 --- a/src/logic/cfg-syntax.k +++ b/src/logic/cfg-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module CFG-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax LogicName ::= "cfg" diff --git a/src/logic/ere-syntax.k b/src/logic/ere-syntax.k index a74ff6d..ddf1814 100644 --- a/src/logic/ere-syntax.k +++ b/src/logic/ere-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module ERE-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax LogicName ::= "ere" diff --git a/src/logic/fsm-syntax.k b/src/logic/fsm-syntax.k index ba0af5b..8953572 100644 --- a/src/logic/fsm-syntax.k +++ b/src/logic/fsm-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module FSM-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax LogicName ::= "fsm" diff --git a/src/logic/ltl-syntax.k b/src/logic/ltl-syntax.k index da71423..4357e4b 100644 --- a/src/logic/ltl-syntax.k +++ b/src/logic/ltl-syntax.k @@ -2,7 +2,7 @@ require "domains.k" require "boolop-syntax.k" module LTL-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON imports BOOLOP-SYNTAX syntax LogicName ::= "ltl" diff --git a/src/logic/srs-syntax.k b/src/logic/srs-syntax.k index 6ce93f8..32306eb 100644 --- a/src/logic/srs-syntax.k +++ b/src/logic/srs-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module SRS-SYNTAX - imports DOMAINS-SYNTAX + imports DOMAINS-COMMON syntax LogicName ::= "srs" diff --git a/src/mop/mop-compiler.k b/src/mop/mop-compiler.k index a502403..4f6a590 100644 --- a/src/mop/mop-compiler.k +++ b/src/mop/mop-compiler.k @@ -3,10 +3,28 @@ require "domains.k" module MOP-COMPILER-SYNTAX imports MOP-SYNTAX + imports DOMAINS-SYNTAX + + syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] + syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] + syntax VarInitBubble ::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] + syntax NoParentheses ::= r"[^()<][^()]*" [token, klabel('NoParentheses)] + + syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb + + syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel('DecBubbleList)] + + syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] + | MethodDecBubble [token, klabel('DecBubbleMethod)] + | FieldDecBubble [token, klabel('DecBubbleField)] + + syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] + | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] endmodule module MOP-COMPILER - imports MOP-COMPILER-SYNTAX - imports DOMAINS + imports MOP-SYNTAX + configuration $PGM:MOP + rule ... `Spec:SpecDec => .K` ... endmodule \ No newline at end of file From 55c89254586f95b07dd0b21fc8f7e3d15f898d1c Mon Sep 17 00:00:00 2001 From: kheradmand Date: Tue, 22 Dec 2015 15:46:26 -0600 Subject: [PATCH 002/160] small fix --- src/common/type-syntax.k | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index f674e52..12f8753 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -5,7 +5,7 @@ module TYPE-SYNTAX syntax PackageName ::= IdList [klabel('PackageName)] syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] - syntax TypeName ::= Id [klabel('TypeName)] + syntax TypeName ::= Id [klabel('TypeName), avoid] //TODO: added avoid to resolve amb with K internal syntax in rules | PackageOrTypeName "." Id [strict(1), klabel('TypeName)] syntax IdList ::= List{Id,"."} [klabel('IdList)] From 2a2a0bca2b8a40b37544aeb1da7c89d913196463 Mon Sep 17 00:00:00 2001 From: kheradmand Date: Wed, 23 Dec 2015 00:04:52 -0600 Subject: [PATCH 003/160] temp changes --- src/common/type-syntax.k | 22 ++++++++++++++++------ src/mop/mop-compiler.k | 12 +++++++++++- src/mop/pointcut-syntax.k | 6 +++--- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index 12f8753..f3c242a 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -2,11 +2,21 @@ require "domains.k" module TYPE-SYNTAX imports DOMAINS-COMMON - syntax PackageName ::= IdList [klabel('PackageName)] - syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] - | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] - syntax TypeName ::= Id [klabel('TypeName), avoid] //TODO: added avoid to resolve amb with K internal syntax in rules - | PackageOrTypeName "." Id [strict(1), klabel('TypeName)] + //syntax PackageName ::= IdList [klabel('PackageName)] + //syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] + // | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] + //syntax TypeName ::= Id [klabel('TypeName), avoid] //TODO: added avoid to resolve amb with K internal syntax in rules + // | PackageOrTypeName "." Id [strict(1), klabel('TypeName)] + + syntax PackageName ::= Id [klabel('PackageNameSingle), avoid] + | PackageName "." Id [strict(1), klabel('PackageNameMulti), avoid] + syntax TypeName ::= Id [klabel('TypeNameSingle), avoid] + | TypeName "." Id [klabel('TypeNameMulti), avoid] + +//PackageName [klabel('TypeName)] + + + syntax IdList ::= List{Id,"."} [klabel('IdList)] @@ -25,4 +35,4 @@ module TYPE-SYNTAX //context 'FormalParamList(_,,HOLE) [result(Params)] -endmodule \ No newline at end of file +endmodule diff --git a/src/mop/mop-compiler.k b/src/mop/mop-compiler.k index 4f6a590..393bcfe 100644 --- a/src/mop/mop-compiler.k +++ b/src/mop/mop-compiler.k @@ -20,11 +20,21 @@ module MOP-COMPILER-SYNTAX syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] + + + + + + syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) + // r"(? $PGM:MOP - rule ... `Spec:SpecDec => .K` ... + rule `X:OptionalPackageDec => .K` ... endmodule \ No newline at end of file diff --git a/src/mop/pointcut-syntax.k b/src/mop/pointcut-syntax.k index 9e00118..3ecfec0 100644 --- a/src/mop/pointcut-syntax.k +++ b/src/mop/pointcut-syntax.k @@ -53,10 +53,10 @@ module ASPECTJ-POINTCUT-SYNTAX syntax ModifiersPattern ::= ModifierList | "!" ModifierList - syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) + syntax IdPattern// ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) // r"(? Date: Sat, 2 Apr 2016 00:54:20 -0500 Subject: [PATCH 004/160] rvm compiler --- src/mop/mop-syntax.k | 2 +- src/old/Example0.java | 3 - src/old/Test.java | 9 - src/old/class-syntax.k | 99 ----------- src/old/java/aux-strings.k | 23 --- src/old/java/class-syntax.k | 134 --------------- src/old/java/core-classes.k | 81 --------- src/old/java/core-functions.k | 296 -------------------------------- src/old/java/core-sorts.k | 217 ----------------------- src/old/java/exp-syntax.k | 142 --------------- src/old/java/interface-syntax.k | 69 -------- src/old/java/java-doc.k | 7 - src/old/java/java-syntax.k | 26 --- src/old/java/lexical-syntax.k | 105 ----------- src/old/java/list-syntax.k | 48 ------ src/old/java/literal-syntax.k | 58 ------- src/old/java/name-syntax.k | 21 --- src/old/java/optional-syntax.k | 44 ----- src/old/java/package-syntax.k | 19 -- src/old/java/primitive-types.k | 113 ------------ src/old/java/shared-syntax.k | 9 - src/old/java/stmt-syntax.k | 71 -------- src/old/java/subtyping.k | 161 ----------------- src/old/java/type-syntax.k | 62 ------- src/old/rvm-syntax.k | 45 ----- src/rvm/rvm-compiler.k | 41 +++++ src/rvm/rvm-syntax.k | 4 +- 27 files changed, 44 insertions(+), 1865 deletions(-) delete mode 100644 src/old/Example0.java delete mode 100644 src/old/Test.java delete mode 100644 src/old/class-syntax.k delete mode 100644 src/old/java/aux-strings.k delete mode 100644 src/old/java/class-syntax.k delete mode 100644 src/old/java/core-classes.k delete mode 100644 src/old/java/core-functions.k delete mode 100644 src/old/java/core-sorts.k delete mode 100644 src/old/java/exp-syntax.k delete mode 100644 src/old/java/interface-syntax.k delete mode 100644 src/old/java/java-doc.k delete mode 100644 src/old/java/java-syntax.k delete mode 100644 src/old/java/lexical-syntax.k delete mode 100644 src/old/java/list-syntax.k delete mode 100644 src/old/java/literal-syntax.k delete mode 100644 src/old/java/name-syntax.k delete mode 100644 src/old/java/optional-syntax.k delete mode 100644 src/old/java/package-syntax.k delete mode 100644 src/old/java/primitive-types.k delete mode 100644 src/old/java/shared-syntax.k delete mode 100644 src/old/java/stmt-syntax.k delete mode 100644 src/old/java/subtyping.k delete mode 100644 src/old/java/type-syntax.k delete mode 100644 src/old/rvm-syntax.k create mode 100644 src/rvm/rvm-compiler.k diff --git a/src/mop/mop-syntax.k b/src/mop/mop-syntax.k index 097161d..ca006ca 100644 --- a/src/mop/mop-syntax.k +++ b/src/mop/mop-syntax.k @@ -9,7 +9,7 @@ module MOP-SYNTAX //top level sort (aka CompilationUnit) - syntax MOP ::= OptionalPackageDec ImportDecList SpecDec [prefer, klabel('MOP)] + syntax MOP ::= OptionalPackageDec ImportDecList SpecDec //[prefer, klabel('MOP)] diff --git a/src/old/Example0.java b/src/old/Example0.java deleted file mode 100644 index 8dc6f9a..0000000 --- a/src/old/Example0.java +++ /dev/null @@ -1,3 +0,0 @@ - -public class Example0 { -} diff --git a/src/old/Test.java b/src/old/Test.java deleted file mode 100644 index 80f573d..0000000 --- a/src/old/Test.java +++ /dev/null @@ -1,9 +0,0 @@ - -public class Test { - private void create(){ - int i; - int j; - i = 0; - } - -} diff --git a/src/old/class-syntax.k b/src/old/class-syntax.k deleted file mode 100644 index 3edb9fc..0000000 --- a/src/old/class-syntax.k +++ /dev/null @@ -1,99 +0,0 @@ -//Work in progress - -module CLASS-SYNTAX - syntax ClassMemberDec ::= FieldDec | ClassDec | MethodDec | InterfaceDec | SemiColon - - -syntax ClassDecHead ::= - ClassModList "class" Id OptionalTypeParams OptionalSuper OptionalInterfaces - [klabel('ClassDecHead)] -syntax ClassBody ::= BlockBubble [klabel('ClassBody)] - -syntax ClassDec ::= ClassDecHead ClassBody [klabel('ClassDec)] -syntax ClassDec ::= EnumDec - -syntax ClassMod ::= "public" | "private" | "protected" | "abstract" | "final" | "static" | "strictfp" - - - -syntax Super ::= "extends" JavaClassType [klabel('SuperDec)] -syntax Interfaces ::= "implements" InterfaceTypeList [klabel('ImplementsDec)] - - - - - - -syntax SemiColon ::= ";" [klabel('SemiColon)] - - - - - -syntax EnumDecHead ::= AnnoClassModList "enum" Id OptionalInterfaces [klabel('EnumDecHead)] -syntax EnumBody ::= BlockBubble -syntax EnumDec ::= EnumDecHead EnumBody [klabel('EnumDec)] - - - -//@ \subsection{FieldDeclarations.sdf} -syntax FieldDec ::= FieldMod Type VarDecList ";" [klabel('FieldDec)] - -syntax VarDec ::= VarDecId [klabel('VarDec)] - | VarDecId "=" VarInit [klabel('VarDec)] - -syntax VarDecId ::= Id | Id Dims [klabel('ArrayVarDecId)] - -syntax VarInit ::= Exp | ArrayInit - -syntax FieldMod ::= Public - | Private - | Protected - | Final - | Static - | Transient - | Volatile - -syntax AnnoFieldMod ::= Anno | FieldMod - - -//@ \subsection{MethodDeclarations.sdf} -syntax MethodDecHead ::= - AnnoMethodModList OptionalTypeParams Type Id "(" Params ")" OptionalThrows - [klabel('MethodDecHead)] -syntax MethodBody ::= Block | ";" [klabel('NoMethodBody)] -syntax MethodDec ::= MethodDecHead MethodBody [klabel('MethodDec)] - -syntax Param ::= AnnoVarModList Type VarDecId [strict(2), klabel('Param)] -syntax Param ::= AnnoVarModList Type "..." VarDecId [klabel('VarArityParam)] - -syntax Throws ::= "throws" ExceptionTypeList [klabel('ThrowsDec)] - -syntax ExceptionType ::= JavaClassType - -syntax MethodMod ::= Public - | Private - | Protected - | Abstract - | Final - | Static - | Native - | Synchronized - | StrictFP - -syntax AnnoMethodMod ::= Anno | MethodMod - -syntax VarMod ::= Final - -syntax AnnoVarMod ::= Anno | VarMod - - -//@ \subsection{InstanceInitializers.sdf} -syntax InstanceInit ::= Block [klabel('InstanceInit)] - - -//@ \subsection{StaticInitializers.sdf} -syntax StaticInit ::= "static" Block [klabel('StaticInit)] -syntax Block - -endmodule \ No newline at end of file diff --git a/src/old/java/aux-strings.k b/src/old/java/aux-strings.k deleted file mode 100644 index 86398b5..0000000 --- a/src/old/java/aux-strings.k +++ /dev/null @@ -1,23 +0,0 @@ -module AUX-STRINGS -/*@ Auxiliary constructs related to Strings. Extension to string.k.*/ - -//@Retain the first Count chars in the string -syntax String ::= retainHead ( String, Int ) [function] -rule retainHead(Str:String, Count:Int) => substrString(Str, 0, Count) - -//@Retain the last Count chars in the string -syntax String ::= retainTail ( String, Int ) [function] -rule retainTail(Str:String, Count:Int) => substrString(Str, lengthString(Str) -Int Count, lengthString(Str)) - -//@Trim the first Count chars in the string -syntax String ::= trimHead ( String, Int ) [function] -rule trimHead(Str:String, Count:Int) => substrString(Str, Count, lengthString(Str)) - -//@Trim the last Count chars in the string -syntax String ::= trimTail ( String, Int ) [function] -rule trimTail(Str:String, Count:Int) => substrString(Str, 0, lengthString(Str) -Int Count) - -syntax String ::= lastChar ( String ) [function] -rule lastChar(Str:String) => retainTail(Str, 1) - -endmodule diff --git a/src/old/java/class-syntax.k b/src/old/java/class-syntax.k deleted file mode 100644 index 6f3ab3e..0000000 --- a/src/old/java/class-syntax.k +++ /dev/null @@ -1,134 +0,0 @@ -module CLASS-SYNTAX - imports EXP-SYNTAX - -//@ \subsection{ClassDeclarations.sdf} -syntax ClassDecHead ::= - AnnoClassModList "class" Id OptionalTypeParams OptionalSuper OptionalInterfaces - [klabel('ClassDecHead)] -syntax ClassBody ::= "{" ClassBodyDecList "}" [klabel('ClassBody)] - -syntax ClassDec ::= ClassDecHead ClassBody [klabel('ClassDec)] -syntax ClassDec ::= EnumDec - -syntax ClassMod ::= Public - | Private - | Protected - | Abstract - | Final - | Static - | StrictFP - -z - -syntax AnnoClassMod ::= Anno | ClassMod - -syntax Super ::= "extends" JavaClassType [klabel('SuperDec)] - -syntax Interfaces ::= "implements" InterfaceTypeList [klabel('ImplementsDec)] - -syntax ClassBodyDec ::= InstanceInit | StaticInit | ClassMemberDec | ConstrDec - -syntax ClassMemberDec ::= FieldDec | ClassDec | MethodDec | InterfaceDec | SemiColon - -syntax InterfaceDec - -syntax SemiColon ::= ";" [klabel('SemiColon)] - -//@ \subsection{ConstructorDeclarations.sdf} -syntax ConstrHead ::= - AnnoConstrModList OptionalTypeParams Id "(" Params ")" OptionalThrows - [klabel('ConstrDecHead)] -syntax ConstrBody ::= "{" OptionalConstrInv BlockStmList "}" [klabel('ConstrBody)] - -syntax ConstrDec ::= ConstrHead ConstrBody [klabel('ConstrDec)] - -syntax ConstrInv ::= OptionalTypeArgs "this" "(" Exps ")" ";" [klabel('AltConstrInv)] -syntax ConstrInv ::= OptionalTypeArgs "super" "(" Exps ")" ";" [klabel('SuperConstrInv)] -syntax ConstrInv ::= Exp "." OptionalTypeArgs "super" "(" Exps ")" ";" [klabel('QSuperConstrInv)] - -syntax ConstrMod ::= Public - | Private - | Protected - -syntax AnnoConstrMod ::= Anno | ConstrMod - - -//@ \subsection{EnumDeclarations.sdf} -syntax EnumDecHead ::= AnnoClassModList "enum" Id OptionalInterfaces [klabel('EnumDecHead)] -/* -Java allows , at the end of List. -This makes copy-pasting easier, especially with one element per line. -*/ -syntax EnumBody ::= "{" EnumConstList OptionalEnumBodyDecs"}" [klabel('EnumBody)] - | "{" EnumConstList "," OptionalEnumBodyDecs "}" [klabel('EnumBody)] - -syntax EnumDec ::= EnumDecHead EnumBody [klabel('EnumDec)] - -syntax EnumConst ::= Id OptionalEnumConstArgs OptionalClassBody [klabel('EnumConst)] - -syntax EnumConstArgs ::= "(" Exps ")" [bracket] - -syntax EnumBodyDecs ::= ";" ClassBodyDecList [klabel('EnumBodyDecs)] - - -//@ \subsection{FieldDeclarations.sdf} -syntax FieldDec ::= AnnoFieldModList Type VarDecList ";" [klabel('FieldDec)] - -syntax VarDec ::= VarDecId [klabel('VarDec)] - | VarDecId "=" VarInit [klabel('VarDec)] - -syntax VarDecId ::= Id | Id Dims [klabel('ArrayVarDecId)] - -syntax VarInit ::= Exp | ArrayInit - -syntax FieldMod ::= Public - | Private - | Protected - | Final - | Static - | Transient - | Volatile - -syntax AnnoFieldMod ::= Anno | FieldMod - - -//@ \subsection{MethodDeclarations.sdf} -syntax MethodDecHead ::= - AnnoMethodModList OptionalTypeParams Type Id "(" Params ")" OptionalThrows - [klabel('MethodDecHead)] -syntax MethodBody ::= Block | ";" [klabel('NoMethodBody)] -syntax MethodDec ::= MethodDecHead MethodBody [klabel('MethodDec)] - -syntax Param ::= AnnoVarModList Type VarDecId [strict(2), klabel('Param)] -syntax Param ::= AnnoVarModList Type "..." VarDecId [klabel('VarArityParam)] - -syntax Throws ::= "throws" ExceptionTypeList [klabel('ThrowsDec)] - -syntax ExceptionType ::= JavaClassType - -syntax MethodMod ::= Public - | Private - | Protected - | Abstract - | Final - | Static - | Native - | Synchronized - | StrictFP - -syntax AnnoMethodMod ::= Anno | MethodMod - -syntax VarMod ::= Final - -syntax AnnoVarMod ::= Anno | VarMod - - -//@ \subsection{InstanceInitializers.sdf} -syntax InstanceInit ::= Block [klabel('InstanceInit)] - - -//@ \subsection{StaticInitializers.sdf} -syntax StaticInit ::= "static" Block [klabel('StaticInit)] -syntax Block - -endmodule \ No newline at end of file diff --git a/src/old/java/core-classes.k b/src/old/java/core-classes.k deleted file mode 100644 index 0ea0804..0000000 --- a/src/old/java/core-classes.k +++ /dev/null @@ -1,81 +0,0 @@ -module CORE-CLASSES - imports CORE-SORTS - imports CORE-FUNCTIONS - imports AUX-STRINGS // for retainHead - imports EXP-SYNTAX //for definitions of sort Exp - imports STMT-SYNTAX //for definitions of sort Stmt - -//@ \subsection{Packages} - -/*@A Java package.*/ -syntax PackageId ::= packageId ( Id ) -syntax MKR ::= PackageId - -/*@ Converts a term of type ClassType into a term of type PackageId representing this class. - This is the package for this class' inner classes. -*/ -syntax KItem ::= toPackage ( ClassType ) [function] -rule toPackage(class Class:Id) => packageId(Class) - -/*@Returns the package of the given class*/ -syntax KItem ::= getPackage ( K ) [strict] -rule getPackage(class ClassId:Id) - => packageId( String2Id(retainHead( - Id2String(ClassId), - rfindString(Id2String(ClassId), ".", lengthString(Id2String(ClassId))) - )) ) - -//@ \subsection{Classes} - -//@ Converts a pair of PackagId, Id into a fully qualified class name -syntax ClassType ::= getClassType ( - PackageId, // the Package Id - Id // Simple class name - ) - [function] - -rule getClassType(packageId(PackKId:Id), SimpleClass:Id) - => class String2Id(Id2String(PackKId) +String "." +String Id2String(SimpleClass)) - -/*@Returns the top-level class enclosing this class*/ -syntax KItem ::= getTopLevel ( ClassType ) - -rule [getTopLevel-move-up]: - - getTopLevel(Class:ClassType) => getTopLevel(EnclosingClass) - ... - - Class - EnclosingClass:ClassType -when EnclosingClass =/=K noClass - -rule [getTopLevel]: - - getTopLevel(Class:ClassType) => Class - ... - - Class - noClass - -//@ Restore the content of with the given class -syntax KItem ::= restoreCrntClass ( - ClassType //old content of - ) - -rule [restoreAfterProcessLocalClass]: - restoreCrntClass(Class:ClassType) => . ... - _ => Class - -//@ Get the internal constructor name for a given class -syntax KItem ::= getConsName ( ClassType ) [function] -rule getConsName(class ClassId:Id) => String2Id("$cons$" +String Id2String(ClassId)) - - -//@ Since RawVal terms can easily be converted into TypedVal, they are also of sort Exp. -syntax Exp ::= TypedVal | RawVal - - - - - -endmodule diff --git a/src/old/java/core-functions.k b/src/old/java/core-functions.k deleted file mode 100644 index 25d2716..0000000 --- a/src/old/java/core-functions.k +++ /dev/null @@ -1,296 +0,0 @@ -module CORE-FUNCTIONS - imports CORE-SORTS - imports AUX-STRINGS - imports JAVA-SYNTAX - -//@ \subsection{Shortcuts for the most frequently used classes within the semantics} - -syntax ClassType ::= "classObject" - [function, latex(\terminal{Object})] -rule classObject => class String2Id("java.lang.Object") - -syntax ClassType ::= "classString" - [function, latex(\terminal{String})] -rule classString => class String2Id("java.lang.String") - -syntax ClassType ::= "classNullPointerException" - [function, latex(\terminal{NullPointerException})] -rule classNullPointerException => class String2Id("java.lang.NullPointerException") - -syntax ClassType ::= "classArrayImpl" [function] -rule classArrayImpl => class String2Id("java.lang.ArrayImpl") - -//@ \subsubsection{Computation terms produced during elaboration} -/*@ These auxiliary terms functions that should be threated as expressions in the elaboration phase. -*/ -syntax Exp ::= LHS -syntax LHS ::= AuxTermExp -/*@ Wrapper of a statement followed by an expression, to be used in a place where an expression is expected, -such as an anonymous class declaration. Is typed with the type of the expression. -At runtime is rewritten into the statement, that should evaluate into .K, followed by the expression, -that should evaluate to value.*/ -syntax AuxTermExp ::= stmtAndExp ( K, K ) - -syntax AuxTermExp ::= cast ( Type, K ) [strict] //strictness on 1-st arcument - for runtime produced terms - -/*@ Returns the type associated with various K terms. The implementation is scattered among various K files. - For a type - the type itself. For a typed expression - the type component. For some raw values - their most common - type. -*/ -syntax KItem ::= typeOf ( K ) [function] -rule typeOf(T:Type) => T -rule typeOf(_ :: T:Type) => T -rule typeOf(Str:String) => classString -rule typeOf(null) => nullType -rule typeOf(objectRef(_, Class:ClassType)) => Class -rule typeOf(arrayRef( arrayOf T:Type, _, _)) => arrayOf T - -/* Required by getTypes in elaboration phase, invoked by lookupMethod. */ -rule typeOf(cast(T:Type, _)) => T - -// Required for getTypes() -rule typeOf('Param(_:K,, T:Type,, _:Id)) => T - -/*@The default value for all types. Used for field initializers.*/ -syntax KItem ::= default ( Type ) [function] -rule default(IntT:IntType) => 0 :: IntT -rule default(FloatT:FloatType) => 0.0 :: FloatT -rule default(bool) => false :: bool -rule default(RT:RefType) => null :: RT - -/*@ Whenever naked RawVal reaches the top of computation, it have to be converted into TypedVal */ -rule Val:RawVal => toTypedVal(Val) [structural] - -/*@ Converts a RawVal into a TypedVal, by adding a default type for the given value. - Greatly simplifies many rules, because now we can use raw values in the RHS, instead of typed values. - - Have to be [function] for LTL -*/ -syntax KItem ::= toTypedVal ( RawVal ) [function] -rule toTypedVal(I:Int) => I :: int [structural] -rule toTypedVal(B:Bool) => B :: bool [structural] -rule toTypedVal(Str:String) => Str :: classString [structural] -rule toTypedVal(null) => null :: nullType [structural] -rule toTypedVal( objectRef(OL:Int, Class:ClassType) ) - => objectRef(OL:Int, Class:ClassType) :: Class [structural] - -rule toTypedVal(arrayRef(T:Type, L:Int, M:Int)) => arrayRef(T, L, M) :: T [structural] -rule toTypedVal(F:Float) => F :: float [structural] - -//@ Converts a KList of terms to Types. Uses typeOf underneath.todo repitition -syntax KItem ::= getTypes ( Exps ) [function] // a list of source expressions - | getTypes ( Types, Exps ) [function] - -rule getTypes( Ps:Exps ) => getTypes(types(.KList), Ps) -rule getTypes( types(Ts:KList), (T:Exp, Ps:Exps) ) => getTypes( types(Ts,,typeOf(T)), Ps ) -rule getTypes( types(Ts:KList), .Exps) => types(Ts) - -//@ Converts a TypedVals term to Types. Uses typeOf underneath. -syntax KItem ::= getTypes ( TypedVals ) [function] // a list of source values - | getTypes ( Types, TypedVals ) [function] - -rule getTypes( TVs:TypedVals) => getTypes(types(.KList), TVs) -rule getTypes( types(Ts:KList), (_ :: T:Type, TVs:TypedVals) ) => getTypes( types(Ts,,T), TVs ) -rule getTypes( types(Ts:KList), .TypedVals) => types(Ts) - -syntax KItem ::= getTypes ( Params ) [function] - | getTypes ( Types , Params ) [function] - -rule getTypes( Ps:Params ) => getTypes(types(.KList), Ps) -rule getTypes( types(Ts:KList), (_:AnnoVarModList T:Type _:Id , Ps:Params) ) => getTypes( types(Ts,,T), Ps ) -rule getTypes( types(Ts:KList), .Params) => types(Ts) - -//@ \subsubsection{Other auxiliary constructs} - -/*@ Generalized equality with strictness, suitable to compare not only TypedVal-s but any K terms. -*/ -syntax KItem ::= eqAux ( K, K ) [seqstrict] -rule eqAux(KR1:KResult, KR2:KResult) => KR1 ==K KR2 - -/*@ Alternative version of if, to be used whenever semantics needs an if logic. - The original 'If will only be used in the source programs.*/ -syntax KItem ::= ifAux ( K, K, K ) [strict(1)] -rule ifAux(true::bool, S:K, _) => S -rule ifAux(false::bool, _, S:K) => S - -syntax KItem ::= andAux(K, K) [strict(1)] -rule andAux(true::bool, E:K) => E -rule andAux(false::bool, _) => false - -syntax KItem ::= orAux(K, K) [strict(1)] -rule orAux(true::bool, _) => true -rule orAux(false::bool, E:K) => E - -//@ Replaces 'Plus in preprocessing phases -syntax KItem ::= plusAux( K, K ) [strict] -rule plusAux(Str1:String :: _, Str2:String :: _) => (Str1 +String Str2) :: classString - -/*@ A wrapper for maps. Allows holding maps inside an arbitrary expression where a K term is required. - Also used as part of mapUnion operation in PROCESS-CLASS-MEMBERS -*/ -syntax MKR ::= mapWrap ( Map ) - -/*@ The union of two maps. Arguments are of the form mapWrap(Map). In this operation, elements of the second map - overwrite elements of the first map if they collide. -*/ -syntax KItem ::= mapUnion ( - K, //mapWrap(Map) - K //mapWrap(Map) - ) - [strict] - -rule mapUnion(mapWrap( M1:Map => M1[K1 <- K2] ), mapWrap( _:Map (K1:K |-> K2:K => .Map) )) -rule mapUnion(mapWrap(M1:Map), mapWrap(.Map)) => mapWrap(M1) - -//@ Substracts from the given map the value given (match is on the value), may cause infinite loop if not used in the right place -syntax KItem ::= removeMapItemsByValue (Map,K) [function] - | removeMapItemsByValue (Map,K,Map) [function] - | removeMapItemsByValue (K,K,Map,K,Map) [function] - -rule removeMapItemsByValue(M:Map, V:K) => removeMapItemsByValue(M, V, .Map) -rule removeMapItemsByValue((Key:K |-> Value:K) Remains:Map, V:K, M:Map) => removeMapItemsByValue(Key, Value, Remains, V, M) -rule removeMapItemsByValue(Key:K, V, Remains:Map, V:K, M:Map) => removeMapItemsByValue(Remains, V, M) -rule removeMapItemsByValue(Key:K, Value:K, Remains:Map, V:K, M:Map) => removeMapItemsByValue(Remains, V, M (Key |-> Value)) -when Value =/=K V -rule removeMapItemsByValue(.Map, V:K, M:Map) => M - -//todo how to realise non-determinism: remove an arbitrary item with that value -syntax KItem ::= removeOneMapItemByValue (Map,K) [function] - | removeOneMapItemByValue (Map,K,Map) [function] - | removeOneMapItemByValue (K,K,Map,K,Map) [function] - -rule removeOneMapItemByValue(M:Map, V:K) => removeOneMapItemByValue(M, V, .Map) -rule removeOneMapItemByValue((Key:K |-> Value:K) Remains:Map, V:K, M:Map) => removeOneMapItemByValue(Key, Value, Remains, V, M) -rule removeOneMapItemByValue(Key:K, V, Remains:Map, V:K, M:Map) => Remains M -rule removeOneMapItemByValue(Key:K, Value:K, Remains:Map, V:K, M:Map) => removeOneMapItemByValue(Remains, V, M (Key |-> Value)) -when Value =/=K V -rule removeOneMapItemByValue(.Map, V:K, M:Map) => M - -//@ Find map items by partial key, not used now -syntax KItem ::= mapItemsByPartialKey (Map,K) [function] - | mapItemsByPartialKey (Map,K,Map) [function] - | mapItemsByPartialKey (K,K,Map,K,Map) [function] - -rule mapItemsByPartialKey(M:Map, V:K) => mapItemsByPartialKey(M, V, .Map) -rule mapItemsByPartialKey((Key:K |-> Value:K) Remains:Map, V:K, M:Map) => mapItemsByPartialKey(Key, Value, Remains, V, M) -rule mapItemsByPartialKey(sig(I:Id, T:Types), Value:K, Remains:Map, I, M:Map) - => mapItemsByPartialKey(Remains, I, M (sig(I,T) |-> Value)) -rule mapItemsByPartialKey(sig(I:Id, T:Types), Value:K, Remains:Map, V:K, M:Map) => mapItemsByPartialKey(Remains, V, M) -when I =/=K V -rule mapItemsByPartialKey(.Map, V:K, M:Map) => M - -syntax KItem ::= isEmpty( Map ) [function] -rule isEmpty(.Map) => true -rule isEmpty(_) => false [owise] - -/*@A wrapper for sets, similar to the one for maps.*/ -syntax MKR ::= setWrap ( Set ) - -/*The union of two sets. Arguments are of the form setWrap(Set).*/ -syntax KItem ::= setUnion ( - K, //setWrap(Set) - K //setWrap(Set) - ) - [strict] -rule setUnion(setWrap(S1:Set), setWrap(S2:Set)) => setWrap(S1 S2) - -syntax Set ::= getSet ( K ) [function] -rule getSet(setWrap(S1:Set)) => S1 - -/*@ the concatenation of two kr[KList] items */ -syntax KItem ::= klistConcat ( KRListWrap, KRListWrap ) [strict] -rule klistConcat(kr[KL1:KList], kr[KL2:KList]) => kr[KL1,,KL2] - -//@ Counts the number of elements in the KList list. Evaluates to an Int. -syntax KItem ::= length ( KListWrap ) [function] - | length ( Int, KListWrap ) [function] - -rule length([Ks:KList]) => length(0, [Ks]) -rule length(I:Int, [K:K,, Ks:KList]) => length(I +Int 1, [Ks]) -rule length(I:Int, [.KList]) => I - -//syntax KItem ::= getFirstKListElements( KListWrap ) [function] -// | getFirstKListElements( KListWrap, KListWrap ) [function] -// -//rule getFirstKListElements([Kl:KList]) => getFirstKListElements([Kl],,[.KList]) -//rule getFirstKListElements([Ho:K,, Hd:K,, Tl:KList], [Kl:KList]) => getFirstKListElements([Hd,,Tl],[Kl,,Ho]) -//rule getFirstKListElements([Hd:K,, .KList],, [Kl:KList]) => Kl -//rule getFirstKListElements([.KList],, [.KList]) => .KList - -syntax KItem ::= getLastKListElement( KListWrap ) [function] - -rule getLastKListElement([Ho:K,, Hd:K,, Tl:KList]) => getLastKListElement([Hd,,Tl]) -rule getLastKListElement([Hd:K,, .KList]) => Hd -rule getLastKListElement([.KList]) => .K - -syntax Params ::= addElementToParamsEnd (Params, Param) [function] -rule addElementToParamsEnd(.Params, P:Param) => P,.Params -rule addElementToParamsEnd((Hd:Param, Tl:Params), P:Param) => Hd,addElementToParamsEnd(Tl,P) - -syntax ClassBodyDecList ::= addElementToClassBodyDecListEnd (ClassBodyDecList, ClassBodyDec) [function] -rule addElementToClassBodyDecListEnd(.ClassBodyDecList, P:K) => 'ClassBodyDecList(P,, .ClassBodyDecList) -rule addElementToClassBodyDecListEnd('ClassBodyDecList(Hd:K,,Tl:K), P:K) => 'ClassBodyDecList(Hd,, addElementToClassBodyDecListEnd(Tl,P)) - -syntax ClassBodyDecList ::= appendClassBodyDecList(ClassBodyDecList, ClassBodyDecList) [function] -rule appendClassBodyDecList(CBDs:ClassBodyDecList, (Hd:ClassBodyDec Tl:ClassBodyDecList)) => - appendClassBodyDecList(addElementToClassBodyDecListEnd(CBDs, Hd), Tl) -rule appendClassBodyDecList(CBDs:ClassBodyDecList, .ClassBodyDecList) => CBDs - -syntax BlockStmList ::= addElementToBlockStmListEnd (BlockStmList, BlockStmt) [function] -rule addElementToBlockStmListEnd(.BlockStmList, P:K) => 'BlockStmList(P,, .BlockStmList) -rule addElementToBlockStmListEnd('BlockStmList(Hd:K,,Tl:K), P:K) => 'BlockStmList(Hd,, addElementToBlockStmListEnd(Tl,P)) - -syntax Exps ::= addElementToExpsEnd (Exps, Exp) [function] -rule addElementToExpsEnd(.Exps, P:Exp) => P,.Exps -rule addElementToExpsEnd((Hd:Exp, Tl:Exps), P:Exp) => Hd,addElementToExpsEnd(Tl,P) - -syntax Exps ::= appendExps(Exps, Exps) [function] -rule appendExps(AExps:Exps, (Hd:Exp, Tl:Exps)) => appendExps(addElementToExpsEnd(AExps, Hd), Tl) -rule appendExps(AExps:Exps, .Exps) => AExps - -/*@ \subsection{ClassType functions} */ - -//@ Converts a fully qualified class type into a simple name (Id) -syntax KItem ::= getSimpleName ( ClassType ) [function] -rule getSimpleName(class ClassId:Id) - => String2Id(trimHead( - Id2String(ClassId), - rfindString(Id2String(ClassId), ".", lengthString(Id2String(ClassId))) +Int 1 - )) - -/*@ \subsection{Identifiers}*/ - -// 'Id(Str:String) - -/*@Convert the AST representation of an Id into a K Id.*/ -rule 'Id(Str:String) => String2Id(Str) [structural, anywhere] - -/*@ \subsection{Other auxiliary constructs} */ - -/*@ \texttt{Generic guard.} - A generic computational guard (should be builtin): it allows the computation to continue only if a prefix - guard evaluates to true. -*/ -syntax KItem ::= "true?" -rule true::bool ~> true? => . [structural] - -//@ \subsection{Definition-wide rules} - -/*@ Represent a parser form for a sequence of terms. Is desugared into the pretty form [...]*/ -syntax KLabel ::= "'ListWrap" -rule 'ListWrap(Ks:KList) => [Ks] [structural, anywhere] -syntax KListWrap ::= "[" KList "]" [klabel('KListWrap), latex(\terminal{[} {#1} \terminal{]})] - - -//@ Sequence of terms and of any other statements. The first term is moved to the top of computation. -rule [S1:K,, Stmts:KList] => S1 ~> [Stmts] [structural] -rule [.KList] => .K [structural] - -rule 'ClassBodyDecList(Hd:K,,Tl:K) => Hd ~> Tl -rule .ClassBodyDecList => . - -//@ A wrapper over an arbitrary KList, wrapper being of type KResult. -syntax KRListWrap ::= "kr" "[" KList "]" [latex(\terminal{kr[} {#1} \terminal{]})] -syntax MKR ::= KRListWrap - -endmodule diff --git a/src/old/java/core-sorts.k b/src/old/java/core-sorts.k deleted file mode 100644 index d76c69c..0000000 --- a/src/old/java/core-sorts.k +++ /dev/null @@ -1,217 +0,0 @@ -//@ \section{Module CORE-SORTS} -module CORE-SORTS - imports TYPE-SYNTAX - -//@ \subsection{Computation phases} - -/*@ The computation Global Phase. See configuration documentation for details. -*/ -syntax GlobalPhase ::= - /* The content of is computed, of type - Map[PackageName -> Map[SimpleName -> FullyQualifiedName]] - */ - "ProcTypeNamesPhase" - - /* Primary processing of type declarations, including nested. - For each 'ClassDec a is saved, with the following cells: - - - - - - - - imports of the enclosing CU, for top-level classes only. - A class first registered in a cell is in the state StoredCPhase. - */ - | "ProcCompUnitsPhase" - - /* Resolve the fully qualified names of base classes an interfaces. Fills the content of: - - the base class - - the set of directly implemented interfaces - - the map from simple names to full names for use within this class. - */ - | "ProcClassDecsPhase" - - /* Saves into appropriate cells the list of transitively implemented interfaces, and all the - content about this class members. Computes the following cells: - - - - - - temporary cell, deleted after class body is processed. - - - */ - | "ProcClassMembersPhase" - - /* Elaborates the content of each code block. Specifically the content of the following cells: - - - The following transformations over expressions are performed: - - each name is resolved to its specific meaning - fully qualified class name, local variable name, static/instance - field of a specific class, etc. - - for each method call the precise signature is resolved. - - each unqualified method/constructor call is converted into a qualified one with the appropriate qualifier - (that might be empty) - - each expression is elaborated into a typed expression. - */ - | "ElaborationPhase" - - /* Folds the cells into a preprocessed Java program. The last step of elaboration semantics. - */ - | "FoldingPhase" - - /* Unfolds each class from its preprocessed 'ClassDec or 'InterfaceDec form back into a cell. - */ - | "UnfoldingPhase" - - /* When all preprocessing / elaboration phases are finished, the actual execution begins. - */ - | "ExecutionPhase" - -/*@ the class phase. See configuration documentation for details.*/ -syntax ClassPhase ::= - "DiscoveredCPhase" - | "StoredCPhase" - | "BasesResolvedCPhase" - | "DecsProcessedCPhase" - | "MembersProcessedCPhase" - | "FoldedCPhase" - | "UnfoldingStartedCPhase" - | "UnfoldedCPhase" - -/*@ - The state of a class in relation to static initialization. See static-init.k for more details. -*/ -syntax StaticInitStatus ::= "StaticUninitialized" - | StaticInitializing ( Int ) - | "StaticInitialized" - - -/*@ A method signature. Required to be KResult by rules in METHOD-INVOKE.*/ -syntax Signature ::= sig ( Id, Types ) -syntax MKR ::= Signature - -/*@ The member accessibility context of the current method - either static or instance.*/ -syntax ContextType ::= "staticCT" [latex(\terminal{static})] - | "instanceCT" [latex(\terminal{instance})] - -syntax MKR ::= ContextType - -//@ \subsection{Values} - -/* Represents a java value. May be either primitive - int, float, bool, of reference. The values nothing and undefined - are special cases required by the semantics. The value nothing is associated with the return type void. The value - undefined is the initial value of uninitialized local variables, before the first assignment. -*/ -syntax RawVal ::= Int | Float | Bool | RawRefVal - | "nothing" - | "undefined" [latex(\bot)] - -/*@ A reference value, in its four forms - as regular object, array, null or String. As mentioned previously - String values have special treatment in this semantics and are implemented as regular strings. - -The object closure has the following structure: -\begin{itemize} -\item OL:Int -- the object location -\item List -- the object content, of the form -\begin{verbatim} - ListItem(layer( - Class, - Env, - enclosingObjClosure::T - )) - ... -\end{verbatim} -\end{itemize} -*/ -syntax ObjectRef ::= objectRef ( - Int, //OL - object location - ClassType //LowestClass - the lowest class where we are allowed to search for method - // implementation, or actual object class if there are no restrictions. - ) - -/*@ The arrayRef has the following structure: -\begin{itemize} -\item Type -- type of the array -\item Int -- location of the first element -\item Int -- array length -\end{itemize} -*/ -syntax ArrayRef ::= arrayRef ( - Type, // Type of the array - Int, // Location of the first element - Int // Length - ) - -syntax RawRefVal ::= ObjectRef | ArrayRef | String | NullLiteral - -/*@ A typed value is a pair of of a raw value and a type. Anywhere during execution we will evaluated typed expressions - into typed values, never into raw values alone. -*/ -syntax TypedVal ::= RawVal "::" Type -syntax TypedVals ::= List{TypedVal, ","} [klabel('ExprList)] -syntax Exps ::= TypedVals - -/*@ The three most common forms of computation result are Typed value or Type. Those are most common results - we will encounter during elaboration. Other result types are more context-specific. -*/ -syntax MKR ::= TypedVal | Type - -/*@ Member access modes*/ -syntax AccessMode ::= Public | Protected | Private | "package" -syntax MKR ::= AccessMode - -syntax AnnoMethodModList ::= accCT(AccessMode, ContextType) -/*@ Types of routines represented by a method closure*/ -syntax MethodMetaType ::= "methodMMT" | "constructorMMT" - -/*@ The two possibilities for a type represented by an objectRef: class or interface.*/ -syntax ClassMetaType ::= "classCMT" [latex(\terminal{class})] - | "interfaceCMT" [latex(\terminal{interface})] - -syntax NoValue ::= "noValue" [latex({\dotCt{K}})] -syntax MKR ::= NoValue -syntax KResult ::= MKR -syntax ElabKResult ::= MKR - -/*@ Represents a reference to a method or constructor. */ -syntax MethodRef ::= methodRef( - Signature, //Method signature - RefType //Usually Class - class defining the method - // Could also be array type, because we may invoke methods over arrays. - ) - | "noMethodRef" [latex({\dotCt{K}})] -syntax MKR ::= MethodRef -syntax MethodName ::= MethodRef - -/*@ A list of types. Elements are of sort Type. Used especially to denote argument types of a method.*/ -syntax Types ::= types ( - KList // List of Type elements, when processed - ) -syntax MKR ::= Types - -//Location type of each store location - either local variable or field -syntax LocMetadata ::= "LocalLocMetadata" [latex(\terminal{Local})] - | "FieldLocMetadata" [latex(\terminal{Field})] - -//Denis' syntax -syntax ClassOrName ::= Id | ClassType -//Denis' syntax -syntax ClassType ::= "class" Id | "noClass" [latex({\dotCt{K}})] - -/* Denis' syntax: A reference type is either a class type, an array type, the null type or a String type. -The null type is specified by the JLS although inaccessible to the programmer. String objects and -types are not threated as regular objects in the present semantics for performance reasons. -*/ -syntax RefType ::= ClassType | "nullType" | "arrayOf" Type -//The sdf syntax of array is different from Denis' syntax ( arrayof ), so added anywhere rule here -rule 'ArrayType(T:Type) => arrayOf T [anywhere] - -rule 'ClassOrInterfaceType(TypeK:K,, _) => TypeK [anywhere] - -rule isBlock('Block(_)) => true - -syntax HeatedInterfaceTypeList ::= List{ClassType, ","} [klabel('InterfaceTypeList), strict] -syntax InterfaceTypeList ::= HeatedInterfaceTypeList -endmodule diff --git a/src/old/java/exp-syntax.k b/src/old/java/exp-syntax.k deleted file mode 100644 index 9779caf..0000000 --- a/src/old/java/exp-syntax.k +++ /dev/null @@ -1,142 +0,0 @@ -module EXP-SYNTAX - imports TYPE-SYNTAX - imports SHARED-SYNTAX - -syntax Exp ::= StmtExp -syntax StmtExp ::= PrefixPostfixExp | AssignExp | MethodInvokeExp | ClassInstanceCreationExp - -//@ \subsection{MethodInvocation.sdf} -syntax MethodInvokeExp ::= MethodSpec "(" Exps ")" [klabel('Invoke)] -syntax MethodSpec ::= MethodName [klabel('Method)] - | Exp "." OptionalTypeArgs Id [klabel('Method)] - | "super" "." OptionalTypeArgs Id [klabel('SuperMethod)] - | TypeName "." "super" "." OptionalTypeArgs Id [klabel('QSuperMethod)] - | AmbName "." TypeArgs Id [klabel('GenericMethod)] - - -//@ \subsection{ClassInstanceCreation.sdf} -syntax ClassInstanceCreationExp ::= - "new" OptionalTypeArgs ClassOrInterfaceType "(" Exps ")" OptionalClassBody - [klabel('NewInstance)] -syntax ClassInstanceCreationExp ::= - Exp "." "new" OptionalTypeArgs Id OptionalTypeArgs "(" Exps ")" OptionalClassBody - [klabel('QNewInstance)] - - -//@ \subsection{AssignmentOperators.sdf} -syntax LHS ::= ExprName | FieldAccess | ArrayAccess - -syntax AssignExp ::= LHS "=" Exp [klabel('Assign)] -syntax AssignExp ::= CompoundAssignExp - -syntax CompoundAssignExp ::= LHS "*=" Exp [klabel('AssignMul)] - | LHS "/=" Exp [klabel('AssignDiv)] - | LHS "%=" Exp [klabel('AssignRemain)] - | LHS "+=" Exp [klabel('AssignPlus)] - | LHS "-=" Exp [klabel('AssignMinus)] - | LHS "<<=" Exp [klabel('AssignLeftShift)] - | LHS ">>=" Exp [klabel('AssignRightShift)] - | LHS ">>>=" Exp [klabel('AssignURightShift)] - | LHS "&=" Exp [klabel('AssignAnd)] - | LHS "^=" Exp [klabel('AssignExcOr)] - | LHS "|=" Exp [klabel('AssignOr)] - - -//@ \subsection{UnaryOperators.sdf} -syntax Exp ::= "(" PrimType ")" Exp [klabel('CastPrim)] -syntax Exp ::= "(" RefType ")" Exp [klabel('CastRef)] - -syntax Exp ::= "~" Exp [strict, klabel('Complement)] - | "!" Exp [strict, klabel('Not)] - | "+" Exp [strict, klabel('Plus)] - | "-" Exp [strict, klabel('Minus)] - -//@ Operators with side effects - prefix, postfix ++/-- -syntax PrefixPostfixExp ::= "++" Exp [klabel('PreIncr)] - | "--" Exp [klabel('PreDecr)] - - -//@ \subsection{Postfix.sdf} -syntax PrefixPostfixExp ::= Exp "++" [klabel('PostIncr)] - | Exp "--" [klabel('PostDecr)] - - -//@ \subsection{BinaryOperators.sdf} -syntax Exp ::= Exp "*" Exp [seqstrict, klabel('Mul)] - | Exp "/" Exp [seqstrict, klabel('Div)] - | Exp "%" Exp [seqstrict, klabel('Remain)] - > Exp "+" Exp [seqstrict, klabel('Plus)] - | Exp "-" Exp [seqstrict, klabel('Minus)] - -syntax Exp ::= Exp "<<" Exp [seqstrict, klabel('LeftShift)] - | Exp ">>" Exp [seqstrict, klabel('RightShift)] - | Exp ">>>" Exp [seqstrict, klabel('URightShift)] - -syntax Exp ::= Exp ">" Exp [seqstrict, klabel('Gt)] -syntax Exp ::= Exp "<" Exp [seqstrict, klabel('Lt)] -syntax Exp ::= Exp ">=" Exp [seqstrict, klabel('GtEq)] - -syntax Exp ::= Exp "||" Exp [strict(1), klabel('LazyOr)] - | Exp "&&" Exp [strict(1), klabel('LazyAnd)] - | Exp "|" Exp [seqstrict, klabel('Or)] - | Exp "^" Exp [seqstrict, klabel('ExcOr)] - | Exp "&" Exp [seqstrict, klabel('And)] - -syntax Exp ::= Exp "?" Exp ":" Exp [klabel('Cond)] - -syntax Exp ::= Exp "instanceof" RefType [strict, klabel('InstanceOf)] - - -//@ \subsection{FieldAccess.sdf} -syntax Exp ::= FieldAccess -syntax FieldAccess ::= Exp "." Id [klabel('Field)] - | "super" "." Id [klabel('SuperField)] - | TypeName "." "super" "." Id [klabel('QSuperField)] - - -//@ \subsection{ArrayAccess.sdf} -syntax Exp ::= ArrayAccess -//syntax ArraySubscript ::= "[" Exp "]" [bracket] -syntax ArrayAccess ::= Exp "[" Exp "]" [seqstrict, klabel('ArrayAccess)] - - -//@ \subsection{ArrayCreation.sdf} -/* Either 'NewArray( T:ElemType,, ['Dim(N1),,'Dim('N2),, ...],, [...,, 'Dim(.KList),, ...] ) - Or 'NewArray( T:ElemType,, [...,, 'Dim(.KList),, ...],, 'ArrayInit(_) ) -*/ -syntax Exp ::= ArrayCreationExp -//todo:cannot put ArrayBaseType instead of Type below, because rules and aux functions use Type -syntax ArrayCreationExp ::= "new" Type DimExps Dims [strict(2), klabel('NewArray)] -syntax ArrayCreationExp ::= "new" Type Dims ArrayInit [klabel('NewArray)] - -syntax ArrayBaseType ::= PrimType - | TypeName - | TypeName "<" "?" ">" [klabel('UnboundWld)] - -syntax Dim ::= "[" "]" [klabel('Dim)] -syntax DimExp ::= "[" Exp "]" [strict, klabel('Dim)] - -//@ \subsection{ArrayInitializers.sdf} -syntax ArrayInit ::= "{" VarInits "}" [klabel('ArrayInit)] -syntax ArrayInit ::= "{" VarInits "," "}" [klabel('ArrayInit)] - - -//@ \subsection{Primary.sdf} -syntax Exp ::= Literal [klabel('Lit)] -syntax Literal ::= IntLiteral - | FloatLiteral - | BoolLiteral - | CharLiteral - | StringLiteral - | NullLiteral - | ClassLiteral - -syntax ClassLiteral ::= Type "." "class" [klabel('Class)] - | "void" "." "class" [klabel('VoidClass)] - -syntax Exp ::= "this" [klabel('This)] - | TypeName "." "this" [klabel('QThis)] - -syntax Exp ::= "(" Exp ")" [bracket] - -endmodule diff --git a/src/old/java/interface-syntax.k b/src/old/java/interface-syntax.k deleted file mode 100644 index a8de460..0000000 --- a/src/old/java/interface-syntax.k +++ /dev/null @@ -1,69 +0,0 @@ -module INTERFACE-SYNTAX - imports CLASS-SYNTAX - -//@ \subsection{AbstractMethodDeclarations.sdf} -syntax AbstractMethodDec ::= - AnnoAbstractMethodModList OptionalTypeParams Type Id "(" Params ")" OptionalThrows ";" - [klabel('AbstractMethodDec)] - -syntax AbstractMethodMod ::= Public | Abstract -syntax AnnoAbstractMethodMod ::= Anno | AbstractMethodMod - - -//@ \subsection{Annotations.sdf} -syntax Anno ::= "@" TypeName "(" ElemValPairList ")" [klabel('Anno)] - | "@" TypeName "(" ElemVal ")" [klabel('SingleElemAnno)] - | "@" TypeName [klabel('MarkerAnno)] - -syntax ElemVal ::= Exp - | Anno - | "{" ElemValList "}" [klabel('ElemValArrayInit)] - | "{" ElemValList "," "}" [klabel('ElemValArrayInit)] - -syntax ElemValPair ::= Id "=" ElemVal [klabel('ElemValPair)] - - -//@ \subsection{AnnotationTypes.sdf} -syntax AnnoDecHead ::= AnnoInterfaceModList "@" "interface" Id [klabel('AnnoDecHead)] - -syntax AnnoDec ::= AnnoDecHead "{" AnnoElemDecList "}" [klabel('AnnoDec)] - -syntax AnnoElemDec ::= ConstantDec | ClassDec | InterfaceDec | EnumDec | AnnoDec | SemiColon -syntax AnnoElemDec ::= AbstractMethodModList Type Id "(" ")" OptionalDefaultVal ";" - [klabel('AnnoMethodDec)] - -syntax DefaultVal ::= "default" ElemVal [klabel('DefaultVal)] - - -//@ \subsection{ConstantDeclarations.sdf} -syntax ConstantDec ::= AnnoConstantModList Type VarDecList ";" [klabel('ConstantDec)] - -syntax ConstantMod ::= Public - | Static - | Final - -syntax AnnoConstantMod ::= Anno | ConstantMod - - -//@ \subsection{InterfaceDeclarations.sdf} -syntax InterfaceDecHead ::= - AnnoInterfaceModList "interface" Id OptionalTypeParams OptionalExtendsInterfaces - [klabel('InterfaceDecHead)] - -syntax InterfaceDec ::= InterfaceDecHead "{" InterfaceMemberDecList "}"[klabel('InterfaceDec)] - -syntax ExtendsInterfaces ::= "extends" InterfaceTypeList [klabel('ExtendsInterfaces)] - -syntax InterfaceMemberDec ::= ConstantDec | AbstractMethodDec | ClassDec | InterfaceDec | SemiColon - -syntax InterfaceMod ::= Public - | Private - | Protected - | Abstract - | Final - | Static - | StrictFP - -syntax AnnoInterfaceMod ::= Anno | InterfaceMod - -endmodule \ No newline at end of file diff --git a/src/old/java/java-doc.k b/src/old/java/java-doc.k deleted file mode 100644 index c25347d..0000000 --- a/src/old/java/java-doc.k +++ /dev/null @@ -1,7 +0,0 @@ -/*! -%contains only markdown env. -\input{sty/custom-commands.tex} - -\usepackage{fullpage} - -*/ diff --git a/src/old/java/java-syntax.k b/src/old/java/java-syntax.k deleted file mode 100644 index d511c21..0000000 --- a/src/old/java/java-syntax.k +++ /dev/null @@ -1,26 +0,0 @@ -require "exp-syntax.k" -require "stmt-syntax.k" -require "list-syntax.k" -require "lexical-syntax.k" -require "literal-syntax.k" -require "name-syntax.k" -require "class-syntax.k" -require "interface-syntax.k" -require "package-syntax.k" -require "optional-syntax.k" -require "type-syntax.k" -require "shared-syntax.k" -module JAVA-SYNTAX - imports LIST-SYNTAX - imports STMT-SYNTAX - imports EXP-SYNTAX - imports LEXICAL-SYNTAX - imports LITERAL-SYNTAX - imports NAME-SYNTAX - imports CLASS-SYNTAX - imports INTERFACE-SYNTAX - imports PACKAGE-SYNTAX - imports OPTIONAL-SYNTAX - imports TYPE-SYNTAX - imports SHARED-SYNTAX -endmodule diff --git a/src/old/java/lexical-syntax.k b/src/old/java/lexical-syntax.k deleted file mode 100644 index 61d4a17..0000000 --- a/src/old/java/lexical-syntax.k +++ /dev/null @@ -1,105 +0,0 @@ -module LEXICAL-SYNTAX -//@ \subsection{Comments.sdf} -//no need to define because K provides fixed layout - -//@ \subsection{Identifiers.sdf} -syntax Id ::= ID [klabel('Id)] -syntax ID ::= Token{[A-Za-z\_\$][A-Za-z0-9\_\$]*} [onlyLabel] - -//@ \subsection{KeyWord.sdf(not needed?)} -/* -syntax Keyword ::= "abstract" - | "assert" - | "boolean" - | "break" - | "byte" - | "case" - | "catch" - | "char" - | "class" - | "const" - | "continue" - | "default" - | "do" - | "double" - | "else" - | "enum" - | "extends" - | "final" - | "finally" - | "float" - | "for" - | "goto" - | "if" - | "implements" - | "import" - | "instanceof" - | "int" - | "interface" - | "long" - | "native" - | "new" - | "package" - | "private" - | "protected" - | "public" - | "return" - | "short" - | "static" - | "strictfp" - | "super" - | "switch" - | "synchronized" - | "this" - | "throw" - | "throws" - | "transient" - | "try" - | "void" - | "volatile" - | "while" -*/ - -//@ \subsection{LineTerminators.sdf} -syntax EndOfFile -syntax CarriageReturn ::= Token{[\r]} [onlyLabel] -syntax LineTerminator ::= EndOfFile - | CarriageReturn - | Token{[\n]} [onlyLabel] - | Token{[\r][\n]} [onlyLabel] - - -//@ \subsection{Modifiers.sdf} -syntax Public ::= "public" [klabel('Public)] -syntax Private ::= "private" [klabel('Private)] -syntax Protected ::= "protected" [klabel('Protected)] -syntax Abstract ::= "abstract" [klabel('Abstract)] -syntax Final ::= "final" [klabel('Final)] -syntax Static ::= "static" [klabel('Static)] -syntax Native ::= "native" [klabel('Native)] -syntax Transient ::= "transient" [klabel('Transient)] -syntax Volatile ::= "volatile" [klabel('Volatile)] -syntax StrictFP ::= "strictfp" [klabel('StrictFP)] -syntax Synchronized ::= "synchronized" [klabel('Synchronized)] - -syntax Modifier ::= Public - | Private - | Protected - | Abstract - | Final - | Static - | Native - | Transient - | Volatile - | StrictFP - | Synchronized - -//@ \subsection{UnicodeEscape.sdf} -syntax UnicodeEscape ::= Token {[\\][u]+ [0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]} - [onlyLabel, klabel('UnicodeEscape)] -syntax UList ::= List{U,""} [klabel('UList)] -syntax U ::= "u" - -//@ \subsection{WhiteSpace.sdf} -//no need to define because K provides fixed layout -endmodule \ No newline at end of file diff --git a/src/old/java/list-syntax.k b/src/old/java/list-syntax.k deleted file mode 100644 index 43e2b12..0000000 --- a/src/old/java/list-syntax.k +++ /dev/null @@ -1,48 +0,0 @@ -module LIST-SYNTAX - -/*A module for list only, for the easy of implementation and management. - There are six lists ((formal)params, dims, dimexps, exps, varinits, catchclauses) - already defined before, because there is no automatic refactor for rename, and also those - defined are used in semantic rules, we leave them unchanged.*/ - -syntax InterfaceTypeList ::= List{InterfaceType,","} [klabel('InterfaceTypeList), strict] -syntax ExceptionTypeList ::= List{ExceptionType,","} [klabel('ExceptionTypeList)] -syntax IdList ::= List{Id,"."} [klabel('IdList)] -syntax TypeDecList ::= List{TypeDec,""} [klabel('TypeDecList)] -syntax VarDecList ::= List{VarDec,","} [klabel('VarDecList)] -syntax ImportDecList ::= List{ImportDec,""} [klabel('ImportDecList)] -syntax ActualTypeArgList ::= List{ActualTypeArg,","} [klabel('ActualTypeArgList)] -syntax ClassOrInterfaceTypeList ::= List{ClassOrInterfaceType, "&"} [klabel('ClassOrInterfaceTypeList)] -syntax TypeParamList ::= List{TypeParam,","} [klabel('TypeParamList)] -syntax AbstractMethodModList ::= List{AbstractMethodMod, ""} [klabel('AbstractMethodModList)] -syntax AnnoAbstractMethodModList ::= List{AnnoAbstractMethodMod, ""} [klabel('AnnoAbstractMethodModList)] -syntax AnnoMethodModList ::= List{AnnoMethodMod, ""} [klabel('AnnoMethodModList)] -syntax AnnoVarModList ::= List{AnnoVarMod, ""} [klabel('AnnoVarModList)] -syntax AnnoClassModList ::= List{AnnoClassMod, ""} [klabel('AnnoClassModList)] -syntax AnnoConstrModList ::= List{AnnoConstrMod, ""} [klabel('AnnoConstrModList)] -syntax AnnoConstantModList ::= List{AnnoConstantMod, ""} [klabel('AnnoConstantModList)] -syntax AnnoFieldModList ::= List{AnnoFieldMod, ""} [klabel('AnnoFieldModList)] -syntax AnnoInterfaceModList ::= List{AnnoInterfaceMod, ""} [klabel('AnnoInterfaceModList)] -syntax AnnoList ::= List{Anno, ""} [klabel('AnnoList)] -syntax AnnoElemDecList ::= List{AnnoElemDec, ""} [klabel('AnnoElemDecList)] -syntax InterfaceMemberDecList ::= List{InterfaceMemberDec, ""} [klabel('InterfaceMemberDecList)] -syntax ElemValPairList ::= List{ElemValPair,","} [klabel('ElemValPairList)] -syntax ElemValList ::= List{ElemVal,","} [klabel('ElemValList)] -syntax StringPartList ::= List{StringPart,""} [klabel('StringPartList)] -syntax EnumConstList ::= List{EnumConst, ","} [klabel('EnumConstList)] -syntax ClassBodyDecList ::= List{ClassBodyDec, ""} [klabel('ClassBodyDecList)] -syntax BlockStmList ::= List{BlockStmt, ""} [klabel('BlockStmList)] -syntax SwitchGroupList ::= List{SwitchGroup, ""} [klabel('SwitchGroupList)] -syntax SwitchLabelList ::= List{SwitchLabel, ""} [klabel('SwitchLabelList)] - -syntax Exps ::= List{Exp, ","} [klabel('ExprList), seqstrict] -syntax Dims ::= List{Dim,""} [klabel('DimList)] -syntax DimExps ::= List{DimExp,""} [klabel('DimExprList), strict] -syntax VarInits ::= List{VarInit, ","} [klabel('VarInitList)] -syntax CatchClauses ::= List{CatchClause,""} [klabel('CatchClauseList), strict] -syntax Params ::= List{Param, ","} [klabel('FormalParamList)] - -context 'FormalParamList(HOLE,,_) [result(Param)] -context 'FormalParamList(_,,HOLE) [result(Params)] - -endmodule \ No newline at end of file diff --git a/src/old/java/literal-syntax.k b/src/old/java/literal-syntax.k deleted file mode 100644 index 0cf2e03..0000000 --- a/src/old/java/literal-syntax.k +++ /dev/null @@ -1,58 +0,0 @@ -module LITERAL-SYNTAX - imports LEXICAL-SYNTAX - imports LIST-SYNTAX - -//@ \subsection{BooleanLiterals.sdf} -syntax BoolLiteral ::= Boolean [klabel('Bool)] -syntax Boolean ::= "true" [onlyLabel, klabel('True)] -syntax Boolean ::= "false" [onlyLabel, klabel('False)] - - -//@ \subsection{CharacterLiterals.sdf} todo -syntax SingleChar// ::= Token{[\r\n\'\\]}//don't understand ^? - -syntax CharContent ::= SingleChar [klabel('Single)] - | UnicodeEscape - | EscapeSeq -//Problem: Multiple lookahead not fully supported (does not appear when tested in small language) -syntax CharLiteral //::= "'" CharContent "'" [klabel('Char)] - - -//@ \subsection{EscapeSequences.sdf} -syntax EscapeSeq ::= OctaEscape | NamedEscape - -syntax NamedEscape ::= Token{"\\" [btnfr\"\'\\]} [onlyLabel, klabel('NamedEscape)] -syntax OctaEscape ::= Token{"\\" [0-7]} [onlyLabel, klabel('OctaEscape1)] - | Token{"\\" [0-3][0-7]} [onlyLabel, klabel('OctaEscape2)] - | Token{"\\" [4-7][0-7]} [onlyLabel, klabel('OctaEscape2)] - | Token{"\\" [0-3][0-7][0-7]} [onlyLabel, klabel('OctaEscape3)] - - -//@ \subsection{FloatingPointLiterals.sdf} todo -syntax FloatLiteral ::= Float [klabel('Float)] - - -//@ \subsection{IntegerLiterals.sdf} -syntax DeciLiteral ::= Token{[1-9][0-9]* [lL]?} [onlyLabel] -syntax HexaLiteral ::= Token{[0][xX][0-9a-fA-F]+ [lL]?} [onlyLabel] -syntax OctaLiteral ::= Token{[0][0-7]+ [lL]?} [onlyLabel] - -syntax IntLiteral ::= DeciLiteral [klabel('Deci)] - | HexaLiteral [klabel('Hexa)] - | OctaLiteral [klabel('Octa)] - - -//@ \subsection{NullLiteral.sdf} -syntax NullLiteral ::= "null" [klabel('Null)] - - -//@ \subsection{StringLiterals.sdf} todo -syntax StringLiteral ::= "\"" StringPartList "\"" [klabel('String)] - -syntax StringPart ::= StringChars [klabel('Chars)] - | UnicodeEscape - | EscapeSeq - -syntax StringChars //::= Token {~[\"\\\n\13]} - -endmodule \ No newline at end of file diff --git a/src/old/java/name-syntax.k b/src/old/java/name-syntax.k deleted file mode 100644 index 5f5342a..0000000 --- a/src/old/java/name-syntax.k +++ /dev/null @@ -1,21 +0,0 @@ -module NAME-SYNTAX - imports LITERAL-SYNTAX - -syntax PackageName ::= IdList [klabel('PackageName)] - -syntax AmbName ::= Id [klabel('AmbName)] - | AmbName "." Id [klabel('AmbName)] - -syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] - | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] - -syntax ExprName::= Id [klabel('ExprName)] - | AmbName "." Id [klabel('ExprName)] - -syntax TypeName ::= Id [klabel('TypeName)] - | PackageOrTypeName "." Id [strict(1), klabel('TypeName)] - -syntax MethodName ::= Id [klabel('MethodName)] - | AmbName "." Id [klabel('MethodName)] - -endmodule \ No newline at end of file diff --git a/src/old/java/optional-syntax.k b/src/old/java/optional-syntax.k deleted file mode 100644 index ef65842..0000000 --- a/src/old/java/optional-syntax.k +++ /dev/null @@ -1,44 +0,0 @@ -module OPTIONAL-SYNTAX -/* -When a particular term is optional in a production, it is represented as OptionalXXX. -Corresponding AST will contain 'Some() if the term exist, 'None(.KList) if not. -All Optionals are defined in this file for management simplicity. -*/ - -syntax None ::= "" [onlyLabel, klabel('None)] - -syntax OptionalId ::= Id [prefer, klabel('Some)] | None -syntax OptionalExp ::= Exp [prefer, klabel('Some)] | None -syntax OptionalWildcardBound ::= WildcardBound [prefer, klabel('Some)] | None -syntax OptionalTypeArgs ::= TypeArgs [prefer, klabel('Some)] | None -syntax OptionalTypeParams ::= TypeParams [prefer, klabel('Some)] | None -syntax OptionalTypeBound ::= TypeBound [prefer, klabel('Some)] | None -syntax OptionalThrows ::= Throws [prefer, klabel('Some)] | None -syntax OptionalDefaultVal ::= DefaultVal [prefer, klabel('Some)] | None -syntax OptionalExtendsInterfaces ::= ExtendsInterfaces [prefer, klabel('Some)] | None -syntax OptionalInterfaces ::= Interfaces [prefer, klabel('Some)] | None -syntax OptionalPackageDec ::= PackageDec [prefer, klabel('Some)] | None -syntax OptionalSuper ::= Super [prefer, klabel('Some)] | None -syntax OptionalConstrInv ::= ConstrInv [prefer, klabel('Some)] | None -syntax OptionalClassBody ::= ClassBody [prefer, klabel('Some)] | None -syntax OptionalEnumBodyDecs ::= EnumBodyDecs [prefer, klabel('Some)] | None -syntax OptionalEnumConstArgs ::= EnumConstArgs [prefer, klabel('Some)] | None - -syntax Id -syntax Exp -syntax WildcardBound -syntax TypeArgs -syntax TypeParams -syntax TypeBound -syntax Throws -syntax DefaultVal -syntax ExtendsInterfaces -syntax Interfaces -syntax PackageDec -syntax Super -syntax ConstrInv -syntax ClassBody -syntax EnumBodyDecs -syntax EnumConstArgs - -endmodule \ No newline at end of file diff --git a/src/old/java/package-syntax.k b/src/old/java/package-syntax.k deleted file mode 100644 index 69b2562..0000000 --- a/src/old/java/package-syntax.k +++ /dev/null @@ -1,19 +0,0 @@ -module PACKAGE-SYNTAX - imports CLASS-SYNTAX - -//@ \subsection{CompilationUnits.sdf} -//syntax CompilationUnit ::= OptionalPackageDec ImportDecList TypeDecList [klabel('CompilationUnit)] - -//@ \subsection{TypeDeclarations.sdf} -syntax TypeDec ::= ClassDec | InterfaceDec | SemiColon - -//@ \subsection{ImportDeclarations.sdf} -syntax ImportDec ::= "import" TypeName ";" [klabel('TypeImportDec)] - | "import" PackageName "." "*" ";" [klabel('TypeImportOnDemandDec)] - | "import" "static" TypeName "." Id ";" [klabel('StaticImportDec)] - | "import" "static" TypeName "." "*" ";" [klabel('StaticImportOnDemandDec)] - -//@ \subsection{PackageDeclarations.sdf} -syntax PackageDec ::= AnnoList "package" PackageName ";" [klabel('PackageDec)] - -endmodule \ No newline at end of file diff --git a/src/old/java/primitive-types.k b/src/old/java/primitive-types.k deleted file mode 100644 index e2ef48b..0000000 --- a/src/old/java/primitive-types.k +++ /dev/null @@ -1,113 +0,0 @@ -module PRIMITIVE-TYPES - imports SUBTYPING - -//@ \subsection{Integer types normalization} - -syntax Int ::= bitCount ( Type ) [function] -rule bitCount(byte) => 8 -rule bitCount(short) => 16 -rule bitCount(int) => 32 -rule bitCount(long) => 64 -rule bitCount(char) => 16 - -/*@ Symbolic execution limitation: this construct cannot be [function] - When conditionals are needed, implementation have to use 'If - the symbolically processed version of if. -*/ -syntax KItem ::= normalize ( TypedVal ) - -rule normalize(I:Int :: IntT:IntType) - => ifAux(isInRange(I::IntT), - I::IntT, - normalizeImpl(I::IntT) - ) -when IntT =/=K char - -rule normalize(I:Int :: char) - => ifAux(isInRange(I::char), - I :: char, - toUnsigned(normalizeImpl(I::char)) - ) - -rule normalize(I:Int :: FloatT:FloatType) => Int2Float(I,53,11)::FloatT - -rule normalize(F:Float :: IntT:IntType) => normalize(Float2Int(F) :: IntT:IntType) - -rule normalize(F:Float :: FloatT:FloatType) => F::FloatT - -//@ Symbolic execution limitation: this construct cannot be [function] -syntax KItem ::= isInRange ( TypedVal ) -rule isInRange(I:Int::byte) => ((I >=Int -128) andBool (I <=Int 127)) -rule isInRange(I:Int::short) => ((I >=Int -32768) andBool (I <=Int 32767)) -rule isInRange(I:Int::int) => ((I >=Int -2147483648) andBool (I <=Int 2147483647)) -rule isInRange(I:Int::long) => ((I >=Int -9223372036854775808) - andBool (I <=Int 9223372036854775807)) -rule isInRange(I:Int::char) => ((I >=Int 0) andBool (I <=Int 65535)) - -rule isInRange(RV:RawVal::_) => true -when notBool (isInt(RV) ==K true) - -/*@ Symbolic execution limitation: this construct cannot be [function] -*/ -syntax KItem ::= normalizeImpl ( TypedVal ) - -rule normalizeImpl(I:Int :: T:Type) - => normalizeSign((((I &Int ((1 < ifAux(I <=Int ((1 < ifAux(I >=Int 0, - I :: T, - I +Int (1 < ILT - -rule normalizeType(FT:FloatType) => FT - -rule normalizeType(IT:IntType) => int -when (IT =/=K int) andBool (IT =/=K long) - -/*@ Important! Binary normalizeType cannot be function because it uses sybtype in implementation. -*/ -syntax KItem ::= normalizeType ( Type, Type ) [function] - -rule normalizeType(NT1:IntType, NT2:IntType) => int -when (NT1 =/=K long) andBool (NT2 =/=K long) - -rule normalizeType(NT1:IntType, NT2:IntType) => long -when (NT1 ==K long) orBool (NT2 ==K long) - -rule normalizeType(T:Type, FT:FloatType) => ifAux(subtype(T, FT), FT, T) -rule normalizeType(FT:FloatType, T:Type) => ifAux(subtype(T, FT), FT, T) - -//not technically primitive types, but here is the most appropriate place to put the rules -rule normalizeType(Class:ClassType, _) => Class -when (Class ==K classString) - -rule normalizeType(_, Class:ClassType) => Class -when (Class ==K classString) - -//Other cases. Required by the rule CompoundAssign -rule normalizeType(T1:Type, T2:Type) => T1 -when notBool (isNumericType(T1) ==K true) andBool (T2 =/=K classString) - -rule normalizeType(bool, bool) => bool - -endmodule diff --git a/src/old/java/shared-syntax.k b/src/old/java/shared-syntax.k deleted file mode 100644 index dddcb08..0000000 --- a/src/old/java/shared-syntax.k +++ /dev/null @@ -1,9 +0,0 @@ -module SHARED-SYNTAX -/*previously defined elsewhere for ltl-support, now these syntax are also used for java, -although we don't incorporate ltl for now, let's keep this independent like this -*/ -syntax Exp ::= Exp "<=" Exp [seqstrict, klabel('LtEq)] - | Exp "==" Exp [seqstrict, klabel('Eq)] - | Exp "!=" Exp [klabel('NotEq)] - -endmodule diff --git a/src/old/java/stmt-syntax.k b/src/old/java/stmt-syntax.k deleted file mode 100644 index 9365bb5..0000000 --- a/src/old/java/stmt-syntax.k +++ /dev/null @@ -1,71 +0,0 @@ -module STMT-SYNTAX - imports CLASS-SYNTAX - -//@ \subsection{Blocks.sdf} -syntax BlockStmt ::= Stmt | LocalVarDecStmt | ClassDec [klabel('ClassDecStm)] -syntax Block ::= "{" BlockStmList "}" [klabel('Block)] - - -//@ \subsection{LocalVariableDeclaraions.sdf} -syntax LocalVarDecStmt ::= LocalVarDec ";" [prefer, klabel('LocalVarDecStm)] -syntax LocalVarDec ::= AnnoVarModList Type VarDecList [prefer, klabel('LocalVarDec)] - - -//@ \subsection{Statements.sdf} -syntax Stmt ::= StmtWithoutTrailing - | LabeledStmt - | IfThenElseStmt - | IfThenStmt - | WhileStmt - | ForStmt - -syntax StmtWithoutTrailing ::= Block - | EmptyStmt - | ExprStmt - | AssertStmt - | SwitchStmt - | DoStmt - | TryStmt - | StackConsumerStmt - | SynchronizedStmt - -syntax StackConsumerStmt ::= ThrowStmt | ContinueStmt | BreakStmt | ReturnStmt - -syntax IfThenElseStmt ::= "if" "(" Exp ")" Stmt "else" Stmt [strict(1), klabel('If)] -syntax IfThenStmt ::= "if" "(" Exp ")" Stmt [prefer, strict(1), klabel('If)] - -syntax WhileStmt ::= "while" "(" Exp ")" Stmt [strict(1),klabel('While)] - -syntax ForStmt ::= "for" "(" LocalVarDec ";" OptionalExp ";" Exps ")" Stmt [klabel('For)] -syntax ForStmt ::= "for" "(" Exps ";" OptionalExp ";" Exps ")" Stmt [klabel('For)] -syntax ForStmt ::= "for" "(" Param ":" Exp ")" Stmt [klabel('ForEach)] - -syntax LabeledStmt ::= Id ":" Stmt [klabel('Labeled)] - -syntax EmptyStmt ::= ";" [klabel('Empty)] - -syntax ExprStmt ::= Exp ";" [strict, klabel('ExprStm)] - -syntax AssertStmt ::= "assert" Exp ";" [strict, klabel('AssertStm)] - | "assert" Exp ":" Exp ";" [strict(1), klabel('AssertStm)] - -syntax SwitchStmt ::= "switch" "(" Exp ")" SwitchBlock [strict(1), klabel('Switch)] -syntax SwitchBlock ::= "{" SwitchGroupList SwitchLabelList "}" [klabel('SwitchBlock)] -syntax SwitchGroup ::= SwitchLabelList BlockStmList [klabel('SwitchGroup)] -syntax SwitchLabel ::= "case" Exp ":" [klabel('Case)] - | "default" ":" [klabel('Default)] - -syntax DoStmt ::= "do" Stmt "while" "(" Exp ")" ";" [strict(2), klabel('DoWhile)] - -syntax CatchClause ::= "catch" "(" Param ")" Block [klabel('Catch)] -syntax TryStmt ::= "try" Block CatchClauses "finally" Block [klabel('Try)] - | "try" Block CatchClauses [klabel('Try)] - -syntax ThrowStmt ::= "throw" Exp ";" [strict, klabel('Throw)] -syntax ContinueStmt ::= "continue" OptionalId ";" [klabel('Continue)] -syntax BreakStmt ::= "break" OptionalId ";" [klabel('Break)] -syntax ReturnStmt ::= "return" OptionalExp ";" [klabel('Return)] - -syntax SynchronizedStmt ::= "synchronized" "(" Exp ")" Block [strict(1), klabel('Synchronized)] - -endmodule diff --git a/src/old/java/subtyping.k b/src/old/java/subtyping.k deleted file mode 100644 index 791defe..0000000 --- a/src/old/java/subtyping.k +++ /dev/null @@ -1,161 +0,0 @@ -module SUBTYPING - imports CORE-CLASSES - -//@ Checks whether first type is a subtype of the second -syntax Exp ::= subtype ( - Type, - Type - ) - [strict] - -/*@ Checks whether the each type in the first list of types is a subtype -of the type at the same position in the second list. -If lists have different size, the function will evaluate to false. -Used in method call overloading resolution. -*/ -syntax KItem ::= subtypeList ( Types, Types ) - -rule [subtype-same-type-True]: - subtype( T:Type, T ) => true - [structural] - -/*@ \subsection{Subtyping among primitive types} */ - -rule subtype( byte, T:Type ) => (T ==K short) orBool (T ==K int) orBool (T ==K long) orBool (isFloatType(T) ==K true) -when T =/=K byte [structural] - -rule subtype( short, T:Type ) => (T ==K int) orBool (T ==K long) orBool (isFloatType(T) ==K true) - -when T =/=K short [structural] - -rule subtype( int, T:Type ) => (T ==K long orBool isFloatType(T) ==K true) -when T =/=K int [structural] - -rule subtype( long, T:Type ) => isFloatType(T) ==K true -when T =/=K long [structural] - -rule subtype( char, T:Type ) => (T ==K int) orBool (T ==K long) orBool (isFloatType(T) ==K true) -when T =/=K char [structural] - -rule subtype( float, T:Type ) => (T ==K double) -when T =/=K float [structural] - -rule subtype( double, T:Type ) => false -when T =/=K double [structural] - -rule subtype( bool, T:Type ) => false -when T =/=K bool [structural] - -/*@ \subsection{Subtyping among reference types} -The subclass relation introduces a subtyping relation. */ - -rule [subtype-ClassOfClassRed]: - subtype( Class1:ClassType, Class:ClassType ) - => subtype( Class2:ClassType, Class ) ... - - Class1 - Class2 - classCMT - ... - - - Class - classCMT - ... - -when - Class1 =/=K Class - [structural] - -rule [subtype-NoClassOfAnyFalse]: - subtype( noClass, _ ) => false - -//The case subtype (noClass, noClass) should never be encountered -//used by the rule [findQualifierOfType] -rule [subtype-AnyOfNoClassFalse]: - subtype( _, noClass ) => true - -rule [subtype-IInterfaceOfClass]: - subtype( Class1:ClassType, Class:ClassType ) => Class ==K classObject ... - - Class1 - interfaceCMT - ... - - - Class - classCMT - ... - -/* -K Limitation: This way don't seem to work: - Class1 - interfaceMetaT - Class - classMetaT -*/ - -rule [subtype-OfInterface]: - subtype( Class1:ClassType, Class2:ClassType ) => Class2 in ISet ... - - Class1 - ISet:Set - ... - - - Class2 - interfaceCMT - ... - - -rule [subType-ClassOfOtherFalse]: - subtype( _:ClassType, T:Type ) => false -when - notBool (isClassType(T) ==K true) - -rule [subtype-ArrayOfClass]: - subtype( arrayOf _, Class:ClassType ) => Class ==K classObject - -rule [subtype-ArrayOfOtherFalse]: - subtype( arrayOf _, T:Type ) => false -when - (getKLabel(T) =/=KLabel 'arrayOf_) - andBool notBool (isClassType(T) ==K true) - -rule [subtype-Null]: - subtype( nullType, T:Type ) => (isRefType(T) ==K true) - [structural] - -//@ Subtype -rule [subtype-ArrayOfArrayPrimitive]: - subtype( arrayOf T1:Type, arrayOf T2:Type ) => (T1 ==K T2) -when - notBool (isRefType(T1) ==K true) orBool notBool (isRefType(T2) ==K true) - -rule [subtype-ArrayOfArrayRef]: - subtype( arrayOf RefT1:RefType, arrayOf RefT2:RefType ) => subtype( RefT1, RefT2 ) - -//used by lookupQThis, when QThis is an inferred qualifier for unqualified new instance creation. -rule [subtype-OfNoClass]: - subtype( _, noClass ) => false - -/*@ \subsection{Subtyping lists of types}*/ - -rule [subtypeList]: - subtypeList(types(T1:Type,,Ts:KList), types(Tp1:Type,,Tps:KList)) - => andAux( subtype(T1,Tp1), subtypeList(types(Ts), types(Tps)) ) - [structural] - -rule [subtypeList-EmptyLeft]: - subtypeList(types(.KList), types(_:Type,,_)) => false - [structural] - -rule [subtypeList-EmptyRight]: - subtypeList(types(_:Type,,_) , types(.KList)) => false - [structural] - -rule [subtypeList-EmptyBoth]: - subtypeList(types(.KList), types(.KList)) => true - [structural] - -endmodule diff --git a/src/old/java/type-syntax.k b/src/old/java/type-syntax.k deleted file mode 100644 index 3c8542d..0000000 --- a/src/old/java/type-syntax.k +++ /dev/null @@ -1,62 +0,0 @@ -module TYPE-SYNTAX - imports NAME-SYNTAX - imports OPTIONAL-SYNTAX - -//@ \subsection{Main.sdf} -syntax Type ::= PrimType - | RefType -/*Denis' syntax: actually in sdf "void" together with Type compose ResultType, -since now "void" is Type, there is no need for another syntax of ResultType.*/ - | "void" [klabel('Void)] - -//@ \subsection{ParameterizedTypes.sdf} -syntax TypeArgs ::= "<" ActualTypeArgList ">" [klabel('TypeArgs)] - -syntax ActualTypeArg ::= Type - | "?" OptionalWildcardBound [klabel('Wildcard)] - -syntax WildcardBound ::= "extends" RefType [klabel('WildcardUpperBound)] - | "super" RefType [klabel('WildcardLowerBound)] - - -//@ \subsection{PrimitiveTypes.sdf} -syntax IntOrLongType ::= "int" [klabel('Int)] - | "long" [klabel('Long)] -syntax IntType ::= "byte" [klabel('Byte)] - | "short" [klabel('Short)] - | "char" [klabel('Char)] - | IntOrLongType - -syntax FloatType ::= "float" [klabel('Float)] - | "double" [klabel('Double)] -//sdf NumType -syntax NumericType ::= IntType | FloatType -syntax PrimType ::= NumericType | "bool" [klabel('Boolean)] //sdf "boolean" - - -//@ \subsection{ReferenceTypes.sdf} - /*@ A fully qualified class name, or noClass where no valid class could be computed.*/ -syntax ClassOrInterfaceType ::= TypeDecSpec OptionalTypeArgs [klabel('ClassOrInterfaceType)] - -syntax InterfaceType ::= TypeDecSpec OptionalTypeArgs [klabel('InterfaceType)] -//sdf ClassType, use another name JavaClassType to avoid conflict with Denis' ClassType syntax -syntax JavaClassType ::= TypeDecSpec OptionalTypeArgs [klabel('ClassType)] - -syntax TypeDecSpec ::= TypeName | TypeDecSpec TypeArgs "." Id [klabel('Member)] - -syntax TypeVar ::= TypeVarId [klabel('TypeVar)] - -syntax ArrayType ::= Type "[" "]" [strict, klabel('ArrayType)] - -syntax RefType ::= ClassOrInterfaceType | ArrayType - - -//@ \subsection{TypeVariables.sdf} -syntax TypeVarId ::= Id - -syntax TypeBound ::= "extends" ClassOrInterfaceTypeList [klabel('TypeBound)] - -syntax TypeParam ::= TypeVarId OptionalTypeBound [klabel('TypeParam)] -syntax TypeParams ::= "<" TypeParamList ">" [klabel('TypeParams)] - -endmodule \ No newline at end of file diff --git a/src/old/rvm-syntax.k b/src/old/rvm-syntax.k deleted file mode 100644 index 4dcc89e..0000000 --- a/src/old/rvm-syntax.k +++ /dev/null @@ -1,45 +0,0 @@ - -require "java/java-syntax.k" - -require "logic/ere-syntax.k" - -module RVM-SYNTAX - imports JAVA-SYNTAX - - imports ERE-SYNTAX - - syntax CompilationUnit ::= OptionalPackageDec ImportDecList SpecDec [klabel('CompilationUnit)] - - syntax SpecDec ::= SpecDecHead SpecBody - - syntax SpecDecHead ::= Id OptionalParams - - - syntax OptionalParams ::= Params [prefer, klabel('Some)] | None - - syntax SpecBody ::= "{" SpecBodyDecList "}" - - syntax SpecBodyDec ::= EventDec | PropertyDec - - syntax EventDec ::= EventDecHead EventBody [klabel('EventDec)] - - syntax EventBody ::= Block [klabel('EventBody)] - - syntax EventDecHead ::= "event" Id "(" Params ")" - - syntax PropertyDec ::= Property HandlerDecList - - syntax Property ::= LogicName ":" LogicFormula - - syntax HandlerDec ::= HandlerDecHead HandlerBody - - syntax HandlerDecHead ::= "@" LogicState - - syntax HandlerBody ::= Block - - - -syntax SpecBodyDecList ::= List{SpecBodyDec, ""} -syntax HandlerDecList ::= List{HandlerDec, ""} - -endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k new file mode 100644 index 0000000..e012369 --- /dev/null +++ b/src/rvm/rvm-compiler.k @@ -0,0 +1,41 @@ +require "rvm-syntax.k" +require "domains.k" + +module RVM-COMPILER-SYNTAX + imports RVM-SYNTAX + imports DOMAINS-SYNTAX + + syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] + syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] + syntax VarInitBubble ::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] + syntax NoParentheses ::= r"[^()<][^()]*" [token, klabel('NoParentheses)] + + syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb + + syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel('DecBubbleList)] + + syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] + | MethodDecBubble [token, klabel('DecBubbleMethod)] + | FieldDecBubble [token, klabel('DecBubbleField)] + + syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] + | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] + + + + + + syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) + // r"(? $PGM:RVM +// rule `X:OptionalPackageDec => .K` ... +rule `X:OptionalPackageDec Y:ImportDecList Z:SpecDec => X` +endmodule \ No newline at end of file diff --git a/src/rvm/rvm-syntax.k b/src/rvm/rvm-syntax.k index 25d3afa..14c5fc1 100644 --- a/src/rvm/rvm-syntax.k +++ b/src/rvm/rvm-syntax.k @@ -7,7 +7,7 @@ module RVM-SYNTAX //top level sort (aka CompilationUnit) - syntax RVM ::= OptionalPackageDec ImportDecList SpecDec + syntax RVM ::= OptionalPackageDec ImportDecList SpecDec [prefer, klabel('RVM)] syntax SpecDec ::= SpecDecHead SpecBody @@ -24,6 +24,6 @@ module RVM-SYNTAX //syntax SpecBodyDecList ::= List{SpecBodyDec, ""} -syntax EventDecList ::= List{EventDec, ""} +syntax EventDecList ::= List{EventDec, ""} [klabel('EventsDecList)] endmodule From 4d15bd9870353b3b1d2fbbe68b2cbe26e1371c81 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 01:04:48 -0500 Subject: [PATCH 005/160] update rvm-compiler.k --- src/rvm/rvm-compiler.k | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index e012369..84b94dc 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -35,7 +35,13 @@ endmodule module RVM-COMPILER imports RVM-SYNTAX - configuration $PGM:RVM + configuration $PGM:RVM + .K + .List + .Map + .Map + // rule `X:OptionalPackageDec => .K` ... -rule `X:OptionalPackageDec Y:ImportDecList Z:SpecDec => X` +rule `X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z` + _ => X _ => Y endmodule \ No newline at end of file From 7938d6416784a4340006160ee889fce74ee0c22a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 02:21:07 -0500 Subject: [PATCH 006/160] traversed rvm ast! --- src/rvm/rvm-compiler.k | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 84b94dc..2d20fff 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -1,9 +1,11 @@ require "rvm-syntax.k" require "domains.k" + module RVM-COMPILER-SYNTAX imports RVM-SYNTAX imports DOMAINS-SYNTAX + syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] @@ -36,12 +38,21 @@ module RVM-COMPILER imports RVM-SYNTAX configuration $PGM:RVM - .K - .List - .Map - .Map + "" + + .ImportDecList + + {} + + {} -// rule `X:OptionalPackageDec => .K` ... + rule `X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z` - _ => X _ => Y -endmodule \ No newline at end of file + _ => toString(X) + _ => Y + + + syntax String ::= toString(OptionalPackageDec) [function] + rule toString(P:OptionalPackageDec) => "package foo;" + +endmodule From 6731297cebb9099b47136f377cbe26fbaf468ce3 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 07:43:25 -0500 Subject: [PATCH 007/160] migrate to latest k (ee3bdc2066c29d) --- src/common/type-syntax.k | 2 +- src/logic/boolop-syntax.k | 2 +- src/logic/cfg-syntax.k | 2 +- src/logic/ere-syntax.k | 2 +- src/logic/fsm-syntax.k | 2 +- src/logic/ltl-syntax.k | 2 +- src/logic/srs-syntax.k | 2 +- src/rvm/rvm-compiler.k | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index f3c242a..0164234 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module TYPE-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX //syntax PackageName ::= IdList [klabel('PackageName)] //syntax PackageOrTypeName ::= Id [klabel('PackageOrTypeName)] // | PackageOrTypeName "." Id [strict(1), klabel('PackageOrTypeName)] diff --git a/src/logic/boolop-syntax.k b/src/logic/boolop-syntax.k index 146c801..0388702 100644 --- a/src/logic/boolop-syntax.k +++ b/src/logic/boolop-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module BOOLOP-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX syntax Not ::= "!" | "not" syntax And ::= "/\\" | "and" | "&&" syntax Or ::= "\\/" | "or" | "||" diff --git a/src/logic/cfg-syntax.k b/src/logic/cfg-syntax.k index 76eb7da..4310648 100644 --- a/src/logic/cfg-syntax.k +++ b/src/logic/cfg-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module CFG-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX syntax LogicName ::= "cfg" diff --git a/src/logic/ere-syntax.k b/src/logic/ere-syntax.k index ddf1814..a74ff6d 100644 --- a/src/logic/ere-syntax.k +++ b/src/logic/ere-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module ERE-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX syntax LogicName ::= "ere" diff --git a/src/logic/fsm-syntax.k b/src/logic/fsm-syntax.k index 8953572..ba0af5b 100644 --- a/src/logic/fsm-syntax.k +++ b/src/logic/fsm-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module FSM-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX syntax LogicName ::= "fsm" diff --git a/src/logic/ltl-syntax.k b/src/logic/ltl-syntax.k index 4357e4b..da71423 100644 --- a/src/logic/ltl-syntax.k +++ b/src/logic/ltl-syntax.k @@ -2,7 +2,7 @@ require "domains.k" require "boolop-syntax.k" module LTL-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX imports BOOLOP-SYNTAX syntax LogicName ::= "ltl" diff --git a/src/logic/srs-syntax.k b/src/logic/srs-syntax.k index 32306eb..6ce93f8 100644 --- a/src/logic/srs-syntax.k +++ b/src/logic/srs-syntax.k @@ -1,7 +1,7 @@ require "domains.k" module SRS-SYNTAX - imports DOMAINS-COMMON + imports DOMAINS-SYNTAX syntax LogicName ::= "srs" diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 2d20fff..0ee32bb 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -42,12 +42,12 @@ module RVM-COMPILER .ImportDecList - {} + .Map - {} + .Map -rule `X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z` +rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z _ => toString(X) _ => Y From cf1ddd8b8bd3afd642cfc19f8e07874453463113 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 08:10:44 -0500 Subject: [PATCH 008/160] print package declaration --- src/helper/print-ast.k | 17 +++++++++++++++++ src/rvm/rvm-compiler.k | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/helper/print-ast.k diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k new file mode 100644 index 0000000..0f24a95 --- /dev/null +++ b/src/helper/print-ast.k @@ -0,0 +1,17 @@ +require "../rvm/rvm-syntax.k" +require "domains.k" + +module PRINT-AST + imports RVM-SYNTAX + imports DOMAINS-SYNTAX + + syntax String ::= toString(OptionalPackageDec) [function] + rule toString(package X:PackageName ;) => "package " +String toString(X) +String ";" + rule toString(None:OptionalPackageDec) => "\n" + + syntax String ::= toString(PackageName) [function] + rule toString(X:Id) => Id2String(X) + rule toString(P:PackageName . X:Id) => toString(P) +String "." +String Id2String(X) + + +endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 0ee32bb..1cba83c 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -1,5 +1,6 @@ require "rvm-syntax.k" require "domains.k" +require "../helper/print-ast.k" module RVM-COMPILER-SYNTAX @@ -36,6 +37,7 @@ endmodule module RVM-COMPILER imports RVM-SYNTAX + imports PRINT-AST configuration $PGM:RVM "" @@ -52,7 +54,6 @@ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z _ => Y - syntax String ::= toString(OptionalPackageDec) [function] - rule toString(P:OptionalPackageDec) => "package foo;" + endmodule From 92e76c2e3a674f019d1646ce644c790cc5901d97 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 08:47:47 -0500 Subject: [PATCH 009/160] restructure the logic package --- src/common/property-syntax.k | 2 +- src/logic/{ => syntax}/boolop-syntax.k | 0 src/logic/{ => syntax}/cfg-syntax.k | 0 src/logic/{ => syntax}/ere-syntax.k | 0 src/logic/{ => syntax}/fsm-syntax.k | 0 src/logic/{ => syntax}/logic-syntax.k | 0 src/logic/{ => syntax}/ltl-syntax.k | 0 src/logic/{ => syntax}/srs-syntax.k | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename src/logic/{ => syntax}/boolop-syntax.k (100%) rename src/logic/{ => syntax}/cfg-syntax.k (100%) rename src/logic/{ => syntax}/ere-syntax.k (100%) rename src/logic/{ => syntax}/fsm-syntax.k (100%) rename src/logic/{ => syntax}/logic-syntax.k (100%) rename src/logic/{ => syntax}/ltl-syntax.k (100%) rename src/logic/{ => syntax}/srs-syntax.k (100%) diff --git a/src/common/property-syntax.k b/src/common/property-syntax.k index b2778dc..555071f 100644 --- a/src/common/property-syntax.k +++ b/src/common/property-syntax.k @@ -1,4 +1,4 @@ -require "../logic/logic-syntax.k" +require "../logic/syntax/logic-syntax.k" require "java-bubble-syntax.k" module PROPERTY-SYNTAX diff --git a/src/logic/boolop-syntax.k b/src/logic/syntax/boolop-syntax.k similarity index 100% rename from src/logic/boolop-syntax.k rename to src/logic/syntax/boolop-syntax.k diff --git a/src/logic/cfg-syntax.k b/src/logic/syntax/cfg-syntax.k similarity index 100% rename from src/logic/cfg-syntax.k rename to src/logic/syntax/cfg-syntax.k diff --git a/src/logic/ere-syntax.k b/src/logic/syntax/ere-syntax.k similarity index 100% rename from src/logic/ere-syntax.k rename to src/logic/syntax/ere-syntax.k diff --git a/src/logic/fsm-syntax.k b/src/logic/syntax/fsm-syntax.k similarity index 100% rename from src/logic/fsm-syntax.k rename to src/logic/syntax/fsm-syntax.k diff --git a/src/logic/logic-syntax.k b/src/logic/syntax/logic-syntax.k similarity index 100% rename from src/logic/logic-syntax.k rename to src/logic/syntax/logic-syntax.k diff --git a/src/logic/ltl-syntax.k b/src/logic/syntax/ltl-syntax.k similarity index 100% rename from src/logic/ltl-syntax.k rename to src/logic/syntax/ltl-syntax.k diff --git a/src/logic/srs-syntax.k b/src/logic/syntax/srs-syntax.k similarity index 100% rename from src/logic/srs-syntax.k rename to src/logic/syntax/srs-syntax.k From f796d8aa3ea58c141f046e18449cb432cf41b54f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 09:13:07 -0500 Subject: [PATCH 010/160] add some new cells for rvm-compiler --- src/rvm/rvm-compiler.k | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 1cba83c..c4d54e2 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -47,6 +47,11 @@ module RVM-COMPILER .Map .Map + + "" + .Params + .DecBubbleList + <> rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z From 36a2a8cbd303414eb2ca5423adf1c80a9931a1cb Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 13:08:56 -0500 Subject: [PATCH 011/160] print package decl --- src/helper/print-ast.k | 4 ++-- src/rvm/rvm-compiler.k | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 0f24a95..99e11d0 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -5,9 +5,9 @@ module PRINT-AST imports RVM-SYNTAX imports DOMAINS-SYNTAX - syntax String ::= toString(OptionalPackageDec) [function] + syntax String ::= toString(OptionalPackageDec) [function] rule toString(package X:PackageName ;) => "package " +String toString(X) +String ";" - rule toString(None:OptionalPackageDec) => "\n" + rule toString(None:OptionalPackageDec) => "\n" [owise] syntax String ::= toString(PackageName) [function] rule toString(X:Id) => Id2String(X) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index c4d54e2..7492fea 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -50,8 +50,8 @@ module RVM-COMPILER "" .Params - .DecBubbleList - <> + .List + rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z From 06333dbc796d5a26f99dd5e1a52d673b45cffbc2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 13:46:43 -0500 Subject: [PATCH 012/160] spec name and params --- src/helper/print-ast.k | 4 ++++ src/rvm/rvm-compiler.k | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 99e11d0..adc9791 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -5,6 +5,7 @@ module PRINT-AST imports RVM-SYNTAX imports DOMAINS-SYNTAX + //print package ast syntax String ::= toString(OptionalPackageDec) [function] rule toString(package X:PackageName ;) => "package " +String toString(X) +String ";" rule toString(None:OptionalPackageDec) => "\n" [owise] @@ -13,5 +14,8 @@ module PRINT-AST rule toString(X:Id) => Id2String(X) rule toString(P:PackageName . X:Id) => toString(P) +String "." +String Id2String(X) + //print declaration ast + syntax String ::= toString(DecBubbleList) [function] + rule toString(DB:DecBubbleList) => "foo dec bubble list" //TODO endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 7492fea..06fdd1a 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -50,7 +50,7 @@ module RVM-COMPILER "" .Params - .List + "" @@ -58,7 +58,12 @@ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z _ => toString(X) _ => Y +rule X:Id (Ps:Params) SB:SpecBody => SB + "" => Id2String(X) + .Params => Ps - +//rule {Decls:DecBubbleList Events:EventDecList Props:PropertyDecList} => +// Events Props +// _ => toString(Decls) endmodule From 761b384f60e59dcc796d148a4a07fadd01fa4470 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 14:02:02 -0500 Subject: [PATCH 013/160] decl stub --- src/rvm/rvm-compiler.k | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 06fdd1a..86b2c2c 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -62,8 +62,8 @@ rule X:Id (Ps:Params) SB:SpecBody => SB "" => Id2String(X) .Params => Ps -//rule {Decls:DecBubbleList Events:EventDecList Props:PropertyDecList} => -// Events Props -// _ => toString(Decls) +rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList} + "" => toString(Decls) + endmodule From ade5b9540c3a0a26795e86f4b6deefe2d35b5f42 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 14:42:22 -0500 Subject: [PATCH 014/160] rules for adding events. --- src/rvm/rvm-compiler.k | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 86b2c2c..2d78d60 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -39,14 +39,18 @@ module RVM-COMPILER imports RVM-SYNTAX imports PRINT-AST + syntax KResult ::= error + configuration $PGM:RVM "" .ImportDecList .Map + 0 .Map + 0 "" .Params @@ -54,16 +58,42 @@ module RVM-COMPILER +/** +* Store the package info and import list. +*/ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z _ => toString(X) _ => Y +/** +* Store the spec name and params. +*/ rule X:Id (Ps:Params) SB:SpecBody => SB "" => Id2String(X) .Params => Ps +/** +* Store the declarations info. +*/ rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList} "" => toString(Decls) +/** +* Extract and store the first event in the event list if we haven't encountered it before. +*/ +rule {(EM:EventModifier event X:Id (Ps:Params) Body:BlockBubble => .K) + Events:EventDecList Props:PropertyDecList} + (.Map => X |-> I) Cur:Map + I => I +Int 1 +when notBool X in keys(Cur) + +/** +* Report error if an event is defined multiple times. +*/ +rule {EM:EventModifier event X:Id (Ps:Params) ...} => error + Cur:Map +when X in keys(Cur) + +//No events left? endmodule From adf62175c9a063a754789c069f768ced1b422707 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 15:52:45 -0500 Subject: [PATCH 015/160] add events if not recorded --- src/logic/syntax/srs-syntax.k | 2 +- src/rvm/rvm-compiler.k | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/logic/syntax/srs-syntax.k b/src/logic/syntax/srs-syntax.k index 6ce93f8..af004c5 100644 --- a/src/logic/syntax/srs-syntax.k +++ b/src/logic/syntax/srs-syntax.k @@ -15,7 +15,7 @@ syntax SRSState ::= "succeed" | "fail" syntax Rule ::= SRSLeftHandSide "->" SRSRightHandSide -syntax SRSLeftHandSide ::= OptionalBegin SRSString OptionalEnd +syntax SRSLeftHandSide ::= OptionalBegin SRSString OptionalEnd [avoid] syntax SRSRightHandSide ::= SRSString | "#" SRSState | "#epsilon" syntax OptionalBegin ::= "^" | None diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 2d78d60..06fddb4 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -39,7 +39,7 @@ module RVM-COMPILER imports RVM-SYNTAX imports PRINT-AST - syntax KResult ::= error + syntax KResult ::= "error" configuration $PGM:RVM "" @@ -58,6 +58,7 @@ module RVM-COMPILER + /** * Store the package info and import list. */ @@ -81,18 +82,19 @@ rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList /** * Extract and store the first event in the event list if we haven't encountered it before. */ -rule {(EM:EventModifier event X:Id (Ps:Params) Body:BlockBubble => .K) - Events:EventDecList Props:PropertyDecList} - (.Map => X |-> I) Cur:Map - I => I +Int 1 -when notBool X in keys(Cur) +rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) + Events:EventDecList => Events) Props:PropertyDecList} + (.Map => (X |-> I)) Cur:Map + I:Int => I +Int 1 +when notBool (X in keys(Cur)) /** * Report error if an event is defined multiple times. */ -rule {EM:EventModifier event X:Id (Ps:Params) ...} => error - Cur:Map -when X in keys(Cur) +//rule ({(.K) EM:EventModifier event X:Id (Ps:Params) B:Body +//ED:EventDecList PD:PropertyDecList}) => .K +// Cur:Map +//when X in keys(Cur) //No events left? From 756f0a4765711bada080e5c157b9cc663cf0690c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 17:45:20 -0500 Subject: [PATCH 016/160] rm empty list --- src/rvm/rvm-compiler.k | 18 ++++++++++++------ test/rvm/Test-dupEvent.rvm | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 test/rvm/Test-dupEvent.rvm diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 06fddb4..2a586b7 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -56,6 +56,7 @@ module RVM-COMPILER .Params "" + .List @@ -90,12 +91,17 @@ when notBool (X in keys(Cur)) /** * Report error if an event is defined multiple times. +* In case of error, the execution will be terminated and the error info +* will be stored in cell. */ -//rule ({(.K) EM:EventModifier event X:Id (Ps:Params) B:Body -//ED:EventDecList PD:PropertyDecList}) => .K -// Cur:Map -//when X in keys(Cur) - -//No events left? +rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) + Events:EventDecList) Props:PropertyDecList} => .K + Cur:Map + (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List +when (X in keys(Cur)) + +//No events left +rule + {.K (.EventDecList) Props:PropertyDecList} => Props endmodule diff --git a/test/rvm/Test-dupEvent.rvm b/test/rvm/Test-dupEvent.rvm new file mode 100644 index 0000000..c2574ac --- /dev/null +++ b/test/rvm/Test-dupEvent.rvm @@ -0,0 +1,24 @@ +package rvm; + +import java.io.*; +Test (int o){ + event create(){ + int i; + } + event close(){ + int i; + } + + event create(){ + int k; + } + + ere: x & x + + @match { + int j; + } + + + +} From a85e0e29444172d37941e82d1fde08ccb3c7de9f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 20:14:00 -0500 Subject: [PATCH 017/160] add the output of rv-monitor on a fsm property for future reference --- test/rvm/fsm/HasNext.rvm | 48 ++++ test/rvm/fsm/HasNextRuntimeMonitor.java | 334 ++++++++++++++++++++++++ test/rvm/fsm/info-from-formula | 22 ++ test/rvm/fsm/rv-monitor-shell-result | 28 ++ 4 files changed, 432 insertions(+) create mode 100644 test/rvm/fsm/HasNext.rvm create mode 100644 test/rvm/fsm/HasNextRuntimeMonitor.java create mode 100644 test/rvm/fsm/info-from-formula create mode 100644 test/rvm/fsm/rv-monitor-shell-result diff --git a/test/rvm/fsm/HasNext.rvm b/test/rvm/fsm/HasNext.rvm new file mode 100644 index 0000000..11140cf --- /dev/null +++ b/test/rvm/fsm/HasNext.rvm @@ -0,0 +1,48 @@ +package rvm; +import java.io.*; +import java.util.*; + +// This property specifies that a program does +// not call the hasnext method before the next +// method of an iterator. +// This property is borrowed from tracematches +// (see ECOOP'07 http://abc.comlab.ox.ac.uk/papers) + +full-binding HasNext(Iterator i) { + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + alias match = unsafe + alias unmatch = safe + + @match { + System.out.println("next called without hasNext!"); + } + + @unmatch { + System.out.println("safe"); + } +} + + + + + + + + + diff --git a/test/rvm/fsm/HasNextRuntimeMonitor.java b/test/rvm/fsm/HasNextRuntimeMonitor.java new file mode 100644 index 0000000..7580cb7 --- /dev/null +++ b/test/rvm/fsm/HasNextRuntimeMonitor.java @@ -0,0 +1,334 @@ +package rvm; +import java.io.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.locks.*; +import java.lang.ref.*; +import com.runtimeverification.rvmonitor.java.rt.*; +import com.runtimeverification.rvmonitor.java.rt.ref.*; +import com.runtimeverification.rvmonitor.java.rt.table.*; +import com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractIndexingTree; +import com.runtimeverification.rvmonitor.java.rt.tablebase.SetEventDelegator; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple2; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple3; +import com.runtimeverification.rvmonitor.java.rt.tablebase.IDisableHolder; +import com.runtimeverification.rvmonitor.java.rt.tablebase.IMonitor; +import com.runtimeverification.rvmonitor.java.rt.tablebase.DisableHolder; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TerminatedMonitorCleaner; +import java.util.concurrent.atomic.AtomicInteger; + +final class HasNextMonitor_Set extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractMonitorSet { + + HasNextMonitor_Set(){ + this.size = 0; + this.elements = new HasNextMonitor[4]; + } + final void event_hasnext(Iterator i) { + int numAlive = 0 ; + for(int i_1 = 0; i_1 < this.size; i_1++){ + HasNextMonitor monitor = this.elements[i_1]; + if(!monitor.isTerminated()){ + elements[numAlive] = monitor; + numAlive++; + + final HasNextMonitor monitorfinalMonitor = monitor; + monitor.Prop_1_event_hasnext(i); + if(monitorfinalMonitor.Prop_1_Category_match) { + monitorfinalMonitor.Prop_1_handler_match(); + } + } + } + for(int i_1 = numAlive; i_1 < this.size; i_1++){ + this.elements[i_1] = null; + } + size = numAlive; + } + final void event_next(Iterator i) { + int numAlive = 0 ; + for(int i_1 = 0; i_1 < this.size; i_1++){ + HasNextMonitor monitor = this.elements[i_1]; + if(!monitor.isTerminated()){ + elements[numAlive] = monitor; + numAlive++; + + final HasNextMonitor monitorfinalMonitor = monitor; + monitor.Prop_1_event_next(i); + if(monitorfinalMonitor.Prop_1_Category_match) { + monitorfinalMonitor.Prop_1_handler_match(); + } + } + } + for(int i_1 = numAlive; i_1 < this.size; i_1++){ + this.elements[i_1] = null; + } + size = numAlive; + } +} + +class HasNextMonitor extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractAtomicMonitor implements Cloneable, com.runtimeverification.rvmonitor.java.rt.RVMObject { + protected Object clone() { + try { + HasNextMonitor ret = (HasNextMonitor) super.clone(); + ret.pairValue = new AtomicInteger(pairValue.get()); + return ret; + } + catch (CloneNotSupportedException e) { + throw new InternalError(e.toString()); + } + } + + static final int Prop_1_transition_hasnext[] = {2, 2, 2, 3};; + static final int Prop_1_transition_next[] = {1, 1, 0, 3};; + + volatile boolean Prop_1_Category_match = false; + + private AtomicInteger pairValue; + + HasNextMonitor() { + this.pairValue = new AtomicInteger(this.calculatePairValue(-1, 0) ) ; + + } + + @Override public final int getState() { + return this.getState(this.pairValue.get() ) ; + } + @Override public final int getLastEvent() { + return this.getLastEvent(this.pairValue.get() ) ; + } + private final int getState(int pairValue) { + return (pairValue & 3) ; + } + private final int getLastEvent(int pairValue) { + return (pairValue >> 2) ; + } + private final int calculatePairValue(int lastEvent, int state) { + return (((lastEvent + 1) << 2) | state) ; + } + + private final int handleEvent(int eventId, int[] table) { + int nextstate; + while (true) { + int oldpairvalue = this.pairValue.get() ; + int oldstate = this.getState(oldpairvalue) ; + nextstate = table [ oldstate ]; + int nextpairvalue = this.calculatePairValue(eventId, nextstate) ; + if (this.pairValue.compareAndSet(oldpairvalue, nextpairvalue) ) { + break; + } + } + return nextstate; + } + + final boolean Prop_1_event_hasnext(Iterator i) { + {} + + int nextstate = this.handleEvent(0, Prop_1_transition_hasnext) ; + this.Prop_1_Category_match = nextstate == 1; + + return true; + } + + final boolean Prop_1_event_next(Iterator i) { + {} + + int nextstate = this.handleEvent(1, Prop_1_transition_next) ; + this.Prop_1_Category_match = nextstate == 1; + + return true; + } + + final void Prop_1_handler_match (){ + { + System.out.println("next called without hasNext!"); + } + + } + + final void reset() { + this.pairValue.set(this.calculatePairValue(-1, 0) ) ; + + Prop_1_Category_match = false; + } + + // RVMRef_i was suppressed to reduce memory overhead + + //alive_parameters_0 = [Iterator i] + boolean alive_parameters_0 = true; + + @Override + protected final void terminateInternal(int idnum) { + int lastEvent = this.getLastEvent(); + + switch(idnum){ + case 0: + alive_parameters_0 = false; + break; + } + switch(lastEvent) { + case -1: + return; + case 0: + //hasnext + //alive_i + if(!(alive_parameters_0)){ + RVM_terminated = true; + return; + } + break; + + case 1: + //next + //alive_i + if(!(alive_parameters_0)){ + RVM_terminated = true; + return; + } + break; + + } + return; + } + + public static int getNumberOfEvents() { + return 2; + } + + public static int getNumberOfStates() { + return 4; + } + +} + +public final class HasNextRuntimeMonitor implements com.runtimeverification.rvmonitor.java.rt.RVMObject { + private static com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager HasNextMapManager; + static { + HasNextMapManager = new com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager(); + HasNextMapManager.start(); + } + + // Declarations for the Lock + static final ReentrantLock HasNext_RVMLock = new ReentrantLock(); + static final Condition HasNext_RVMLock_cond = HasNext_RVMLock.newCondition(); + + private static boolean HasNext_activated = false; + + // Declarations for Indexing Trees + private static Object HasNext_i_Map_cachekey_i; + private static HasNextMonitor HasNext_i_Map_cachevalue; + private static final MapOfMonitor HasNext_i_Map = new MapOfMonitor(0) ; + + public static int cleanUp() { + int collected = 0; + // indexing trees + collected += HasNext_i_Map.cleanUpUnnecessaryMappings(); + return collected; + } + + // Removing terminated monitors from partitioned sets + static { + TerminatedMonitorCleaner.start() ; + } + // Setting the behavior of the runtime library according to the compile-time option + static { + RuntimeOption.enableFineGrainedLock(false) ; + } + + public static final void hasnextEvent(Iterator i) { + HasNext_activated = true; + while (!HasNext_RVMLock.tryLock()) { + Thread.yield(); + } + + CachedWeakReference wr_i = null; + MapOfMonitor matchedLastMap = null; + HasNextMonitor matchedEntry = null; + boolean cachehit = false; + if ((i == HasNext_i_Map_cachekey_i) ) { + matchedEntry = HasNext_i_Map_cachevalue; + cachehit = true; + } + else { + wr_i = new CachedWeakReference(i) ; + { + // FindOrCreateEntry + MapOfMonitor itmdMap = HasNext_i_Map; + matchedLastMap = itmdMap; + HasNextMonitor node_i = HasNext_i_Map.getNodeEquivalent(wr_i) ; + matchedEntry = node_i; + } + } + // D(X) main:1 + if ((matchedEntry == null) ) { + if ((wr_i == null) ) { + wr_i = new CachedWeakReference(i) ; + } + // D(X) main:4 + HasNextMonitor created = new HasNextMonitor() ; + matchedEntry = created; + matchedLastMap.putNode(wr_i, created) ; + } + // D(X) main:8--9 + final HasNextMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_1_event_hasnext(i); + if(matchedEntryfinalMonitor.Prop_1_Category_match) { + matchedEntryfinalMonitor.Prop_1_handler_match(); + } + + if ((cachehit == false) ) { + HasNext_i_Map_cachekey_i = i; + HasNext_i_Map_cachevalue = matchedEntry; + } + + HasNext_RVMLock.unlock(); + } + + public static final void nextEvent(Iterator i) { + HasNext_activated = true; + while (!HasNext_RVMLock.tryLock()) { + Thread.yield(); + } + + CachedWeakReference wr_i = null; + MapOfMonitor matchedLastMap = null; + HasNextMonitor matchedEntry = null; + boolean cachehit = false; + if ((i == HasNext_i_Map_cachekey_i) ) { + matchedEntry = HasNext_i_Map_cachevalue; + cachehit = true; + } + else { + wr_i = new CachedWeakReference(i) ; + { + // FindOrCreateEntry + MapOfMonitor itmdMap = HasNext_i_Map; + matchedLastMap = itmdMap; + HasNextMonitor node_i = HasNext_i_Map.getNodeEquivalent(wr_i) ; + matchedEntry = node_i; + } + } + // D(X) main:1 + if ((matchedEntry == null) ) { + if ((wr_i == null) ) { + wr_i = new CachedWeakReference(i) ; + } + // D(X) main:4 + HasNextMonitor created = new HasNextMonitor() ; + matchedEntry = created; + matchedLastMap.putNode(wr_i, created) ; + } + // D(X) main:8--9 + final HasNextMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_1_event_next(i); + if(matchedEntryfinalMonitor.Prop_1_Category_match) { + matchedEntryfinalMonitor.Prop_1_handler_match(); + } + + if ((cachehit == false) ) { + HasNext_i_Map_cachekey_i = i; + HasNext_i_Map_cachevalue = matchedEntry; + } + + HasNext_RVMLock.unlock(); + } + +} diff --git a/test/rvm/fsm/info-from-formula b/test/rvm/fsm/info-from-formula new file mode 100644 index 0000000..7f4b8ce --- /dev/null +++ b/test/rvm/fsm/info-from-formula @@ -0,0 +1,22 @@ +events: hasnext next + +categories: unmatch match + +logic: fsm + +formula: +start[ + next -> unsafe + hasnext -> safe +] +safe[ + next -> start + hasnext -> safe +] +unsafe[ + next -> unsafe + hasnext -> safe +] +alias unmatch = safe +alias match = unsafe + diff --git a/test/rvm/fsm/rv-monitor-shell-result b/test/rvm/fsm/rv-monitor-shell-result new file mode 100644 index 0000000..5d88e98 --- /dev/null +++ b/test/rvm/fsm/rv-monitor-shell-result @@ -0,0 +1,28 @@ +properties={safe condition=$state$ == 2, match condition=$state$ == 1, state declaration=int $state$; +static final int $transition_hasnext$[] = {2, 2, 2, 3};; +static final int $transition_next$[] = {1, 1, 0, 3};; +, monitoring body=, monitored events for set=hasnext:{ + $monitor$.$state$ = $transition_hasnext$[$monitor$.$state$]; +} + +next:{ + $monitor$.$state$ = $transition_next$[$monitor$.$state$]; +} + +, match coenables={next=[[next], [next, hasnext]], hasnext=[[next], [next, hasnext]]} +, unsafe condition=$state$ == 1, monitored events=hasnext:{ + $state$ = $transition_hasnext$[$state$]; +} + +next:{ + $state$ = $transition_next$[$state$]; +} + +, match enables={next=[[], [next], [hasnext], [next, hasnext]], hasnext=[[], [next], [hasnext], [next, hasnext]]}, reset=$state$ = 0; +, start condition=$state$ == 0, fail condition=$state$ == 3 +, initialization=$state$ = 0; +, nonfail condition=$state$ != 3 +, state declaration for set=static final int $transition_hasnext$[] = {2, 2, 2, 3};; +static final int $transition_next$[] = {1, 1, 0, 3};; +} +startEvents=[next, hasnext] From c0890655209ae454d188421d4f832da492f502e2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 20:57:17 -0500 Subject: [PATCH 018/160] code stub of extracting info from properties --- src/helper/print-ast.k | 10 ++++++++++ src/rvm/rvm-compiler.k | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index adc9791..e146006 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -18,4 +18,14 @@ module PRINT-AST syntax String ::= toString(DecBubbleList) [function] rule toString(DB:DecBubbleList) => "foo dec bubble list" //TODO + //print logic name + syntax String ::= getLogicName(PropertyDec) [function] + + //print formula + syntax String ::= getFormula(PropertyDec) [function] + + //print handlers of the given property + syntax String ::= getHandlers(PropertyDec) [function] + + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 2a586b7..ddce9b3 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -49,13 +49,15 @@ module RVM-COMPILER .Map 0 - .Map - 0 - "" .Params "" + 0 + .List + .List + .List + .List @@ -104,4 +106,12 @@ when (X in keys(Cur)) rule {.K (.EventDecList) Props:PropertyDecList} => Props +//add the first property and corresponding handlers +rule Prop:PropertyDec Props:PropertyDecList => Props + I:Int => I +Int 1 + L:List (.List => ListItem(getLogicName(Prop))) + FL:List (.List => ListItem(getFormula(Prop))) + HL:List (.List => ListItem(getHandlers(Prop))) +//No properties left +//rule .PropertyDecList endmodule From 9fee2534310ea50cdc396c0041bd2661b89a778d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 21:10:04 -0500 Subject: [PATCH 019/160] debug --- src/helper/print-ast.k | 3 ++- test/rvm/Test.rvm | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index e146006..e97c546 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -16,7 +16,8 @@ module PRINT-AST //print declaration ast syntax String ::= toString(DecBubbleList) [function] - rule toString(DB:DecBubbleList) => "foo dec bubble list" //TODO + rule toString(.DecBubbleList) => "" + rule toString(DB:DecBubble DBL:DecBubbleList) => #tokenToString(DB) +String toString(DBL) //print logic name syntax String ::= getLogicName(PropertyDec) [function] diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 9ba5a1b..df9a370 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -2,6 +2,11 @@ package rvm; import java.io.*; Test (int o){ + static String x = "foo"; + class bar { + private int foo() { return 1; } + } + event create(){ int i; } From 37d1bf63634bf7c918df8c92b70ab60a3fafe07e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 22:03:30 -0500 Subject: [PATCH 020/160] update --- src/helper/print-ast.k | 8 ++++++-- src/rvm/rvm-compiler.k | 2 +- test/rvm/Test.rvm | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index e97c546..7f36979 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -16,8 +16,12 @@ module PRINT-AST //print declaration ast syntax String ::= toString(DecBubbleList) [function] - rule toString(.DecBubbleList) => "" - rule toString(DB:DecBubble DBL:DecBubbleList) => #tokenToString(DB) +String toString(DBL) + syntax String ::= toString(DecBubble) [function] + + rule toString(DB:DecBubble) => #tokenToString(DB) + +// rule toString(.DecBubbleList) => "" +// rule toString(DB:DecBubble DBL:DecBubbleList) => #tokenToString(DB) +String toString(DBL) //print logic name syntax String ::= getLogicName(PropertyDec) [function] diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index ddce9b3..b853927 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -28,7 +28,7 @@ module RVM-COMPILER-SYNTAX - syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) + syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) // r"(? Date: Sat, 2 Apr 2016 23:39:07 -0500 Subject: [PATCH 021/160] update --- src/helper/print-ast.k | 2 +- test/rvm/Test.rvm | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 7f36979..86ec8e5 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -20,7 +20,7 @@ module PRINT-AST rule toString(DB:DecBubble) => #tokenToString(DB) -// rule toString(.DecBubbleList) => "" + rule toString(.DecBubbleList) => "" // rule toString(DB:DecBubble DBL:DecBubbleList) => #tokenToString(DB) +String toString(DBL) //print logic name diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 3579a45..32fdeba 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -2,10 +2,6 @@ package rvm; import java.io.*; Test (int o){ - x = "foo"; //TODO: add type, and access modifier - class bar { - private int foo() { return 1; } - } event create(){ int i; @@ -20,6 +16,4 @@ Test (int o){ int j; } - - } From ade63809daa3117d8aa326f6e768ff6ba573877b Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 2 Apr 2016 23:39:50 -0500 Subject: [PATCH 022/160] more test inputs --- test/rvm/Test3.rvm | 22 ++++++++++++++++++++++ test/rvm/Test4.rvm | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/rvm/Test3.rvm create mode 100644 test/rvm/Test4.rvm diff --git a/test/rvm/Test3.rvm b/test/rvm/Test3.rvm new file mode 100644 index 0000000..3804dc3 --- /dev/null +++ b/test/rvm/Test3.rvm @@ -0,0 +1,22 @@ +package rvm; + +import java.io.*; +Test (int o){ + x = "foo"; + + event create(){ + int i; + } + event close(){ + int i; + } + + ere: x & x + + @match { + int j; + } + + + +} diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm new file mode 100644 index 0000000..29466a6 --- /dev/null +++ b/test/rvm/Test4.rvm @@ -0,0 +1,25 @@ +package rvm; + +import java.io.*; +Test (int o){ + x = "foo"; + class bar { + private int foo() { return 1; } + } + + event create(){ + int i; + } + event close(){ + int i; + } + + ere: x & x + + @match { + int j; + } + + + +} From 65a5054691dd68cae28858cb8a0d141ffc82dc4a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 3 Apr 2016 21:49:29 -0500 Subject: [PATCH 023/160] save work --- src/helper/print-ast.k | 9 --------- src/rvm/rvm-compiler.k | 10 +++++++--- test/rvm/Test.rvm | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 86ec8e5..bed50e5 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -14,15 +14,6 @@ module PRINT-AST rule toString(X:Id) => Id2String(X) rule toString(P:PackageName . X:Id) => toString(P) +String "." +String Id2String(X) - //print declaration ast - syntax String ::= toString(DecBubbleList) [function] - syntax String ::= toString(DecBubble) [function] - - rule toString(DB:DecBubble) => #tokenToString(DB) - - rule toString(.DecBubbleList) => "" -// rule toString(DB:DecBubble DBL:DecBubbleList) => #tokenToString(DB) +String toString(DBL) - //print logic name syntax String ::= getLogicName(PropertyDec) [function] diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index b853927..e0efae1 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -51,7 +51,7 @@ module RVM-COMPILER "" .Params - "" + .List 0 .List @@ -79,8 +79,12 @@ rule X:Id (Ps:Params) SB:SpecBody => SB /** * Store the declarations info. */ -rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList} - "" => toString(Decls) +rule {(Decl:DecBubble Decls:DecBubbleList => Decls) Events:EventDecList Props:PropertyDecList} + (.List => ListItem(#tokenToString(Decl))) DL:List + + + + /** * Extract and store the first event in the event list if we haven't encountered it before. diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 32fdeba..b063dd1 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -2,7 +2,7 @@ package rvm; import java.io.*; Test (int o){ - + event create(){ int i; } From 0feebddb60ab676635acbf84b8f62dff47756f71 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Mon, 4 Apr 2016 01:11:21 -0500 Subject: [PATCH 024/160] temp change --- src/rvm/rvm-compiler.k | 12 +++++++++--- test/rvm/Test3.rvm | 4 +--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index e0efae1..cffd5e2 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -15,7 +15,7 @@ module RVM-COMPILER-SYNTAX syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb - syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel('DecBubbleList)] + syntax DecBubbleList ::= List{DecBubble, ""} [klabel(DecBubbleListCons)] syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] | MethodDecBubble [token, klabel('DecBubbleMethod)] @@ -79,10 +79,16 @@ rule X:Id (Ps:Params) SB:SpecBody => SB /** * Store the declarations info. */ -rule {(Decl:DecBubble Decls:DecBubbleList => Decls) Events:EventDecList Props:PropertyDecList} - (.List => ListItem(#tokenToString(Decl))) DL:List +rule {(DecBubbleListCons(Decl:DecBubble, Decls:DecBubbleList) => Decls) Events:EventDecList +Props:PropertyDecList} +// (.List => ListItem(#tokenToString(Decl))) DL:List +rule {(DecBubbleListCons(Decl:DecBubble, DecBubbleListCons(Dec2:DecBubble, Decls:DecBubbleList) ) => Decls) +Events:EventDecList +Props:PropertyDecList} +//rule {(Decl:DecBubble Decls:DecBubbleList => Decls) Events:EventDecList +//Props:PropertyDecList} diff --git a/test/rvm/Test3.rvm b/test/rvm/Test3.rvm index 3804dc3..9ec05bf 100644 --- a/test/rvm/Test3.rvm +++ b/test/rvm/Test3.rvm @@ -2,9 +2,7 @@ package rvm; import java.io.*; Test (int o){ - x = "foo"; - - event create(){ + x=2;y=1;event create(){ int i; } event close(){ From 157534e4ddfb569d277260f0e5db0e6fc16f31f9 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Mon, 4 Apr 2016 08:41:48 -0500 Subject: [PATCH 025/160] store the ast node into cell and rely on the print function --- src/rvm/rvm-compiler.k | 18 +++++++----------- test/rvm/Test3.rvm | 6 +++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index cffd5e2..05da697 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -15,7 +15,7 @@ module RVM-COMPILER-SYNTAX syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb - syntax DecBubbleList ::= List{DecBubble, ""} [klabel(DecBubbleListCons)] + syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel(DecBubbleListCons)] syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] | MethodDecBubble [token, klabel('DecBubbleMethod)] @@ -44,14 +44,14 @@ module RVM-COMPILER configuration $PGM:RVM "" - .ImportDecList + .K .Map 0 "" .Params - .List + .K 0 .List @@ -66,8 +66,8 @@ module RVM-COMPILER * Store the package info and import list. */ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z - _ => toString(X) - _ => Y + "" => toString(X) + .K => Y /** * Store the spec name and params. @@ -79,13 +79,9 @@ rule X:Id (Ps:Params) SB:SpecBody => SB /** * Store the declarations info. */ -rule {(DecBubbleListCons(Decl:DecBubble, Decls:DecBubbleList) => Decls) Events:EventDecList -Props:PropertyDecList} -// (.List => ListItem(#tokenToString(Decl))) DL:List - -rule {(DecBubbleListCons(Decl:DecBubble, DecBubbleListCons(Dec2:DecBubble, Decls:DecBubbleList) ) => Decls) -Events:EventDecList +rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList} + .K => Decls //rule {(Decl:DecBubble Decls:DecBubbleList => Decls) Events:EventDecList //Props:PropertyDecList} diff --git a/test/rvm/Test3.rvm b/test/rvm/Test3.rvm index 9ec05bf..d4a5fc8 100644 --- a/test/rvm/Test3.rvm +++ b/test/rvm/Test3.rvm @@ -2,7 +2,11 @@ package rvm; import java.io.*; Test (int o){ - x=2;y=1;event create(){ + x=2; + c { int z = 10 ; } + y=1; + + event create(){ int i; } event close(){ From f558d0adb01c257fc7a5784a320b80856c36f5fa Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 6 Apr 2016 00:20:32 -0500 Subject: [PATCH 026/160] place different ast nodes into different cells --- src/helper/print-ast.k | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index bed50e5..ee0196b 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -14,14 +14,16 @@ module PRINT-AST rule toString(X:Id) => Id2String(X) rule toString(P:PackageName . X:Id) => toString(P) +String "." +String Id2String(X) - //print logic name - syntax String ::= getLogicName(PropertyDec) [function] + //get logic name + syntax LogicName ::= getLogicName(PropertyDec) [function] + rule getLogicName(LN:LogicName : F:LogicFormula HDL:HandlerDecList) => LN - //print formula - syntax String ::= getFormula(PropertyDec) [function] - - //print handlers of the given property - syntax String ::= getHandlers(PropertyDec) [function] + //get formula + syntax LogicFormula ::= getFormula(PropertyDec) [function] + rule getFormula(LN:LogicName : F:LogicFormula HDL:HandlerDecList) => F + //get handlers of the given property + syntax HandlerDecList ::= getHandlers(PropertyDec) [function] + rule getHandlers(LN:LogicName : F:LogicFormula HDL:HandlerDecList) => HDL endmodule \ No newline at end of file From 194f91f1027993f1d19748120f1716570fe039cd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 15:02:03 -0500 Subject: [PATCH 027/160] plan: develop a lib that takes kast as input, produces kast as output --- src/logic/semantics/fsm.k | 8 ++++++++ src/rvm/rvm-compiler.k | 16 ++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/logic/semantics/fsm.k diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k new file mode 100644 index 0000000..b281407 --- /dev/null +++ b/src/logic/semantics/fsm.k @@ -0,0 +1,8 @@ +require "../syntax/fsm-syntax.k" + +module FSM +imports FSM-SYNTAX + + + +endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 05da697..6e9b04d 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -54,9 +54,11 @@ module RVM-COMPILER .K 0 - .List - .List - .List + .K + .K + .HandlerDecList + + false .List @@ -115,9 +117,11 @@ rule //add the first property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props I:Int => I +Int 1 - L:List (.List => ListItem(getLogicName(Prop))) - FL:List (.List => ListItem(getFormula(Prop))) - HL:List (.List => ListItem(getHandlers(Prop))) + getLogicName(Prop) + getFormula(Prop) + getHandlers(Prop) + false => true + //No properties left //rule .PropertyDecList endmodule From 98240750afa9fa77620f4d8813cdfe87aee8a42d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 15:20:55 -0500 Subject: [PATCH 028/160] use K's Bool type in ltl-syntax --- src/logic/syntax/ltl-syntax.k | 5 ++--- src/rvm/rvm-compiler.k | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/logic/syntax/ltl-syntax.k b/src/logic/syntax/ltl-syntax.k index da71423..8bb109a 100644 --- a/src/logic/syntax/ltl-syntax.k +++ b/src/logic/syntax/ltl-syntax.k @@ -2,6 +2,7 @@ require "domains.k" require "boolop-syntax.k" module LTL-SYNTAX + imports BOOL-SYNTAX imports DOMAINS-SYNTAX imports BOOLOP-SYNTAX @@ -9,9 +10,7 @@ syntax LogicName ::= "ltl" syntax LogicFormula ::= LTLFormula -syntax LTLFormula ::= - "true" - | "false" +syntax LTLFormula ::= Bool | EventName | "(" LTLFormula ")" [bracket] > "[]" LTLFormula diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 6e9b04d..80f2590 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -117,9 +117,9 @@ rule //add the first property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props I:Int => I +Int 1 - getLogicName(Prop) - getFormula(Prop) - getHandlers(Prop) + .K => getLogicName(Prop) + .K => getFormula(Prop) + .HandlerDecList => getHandlers(Prop) false => true //No properties left From 050fee070f4fe75d7df9d45fd51f10ac2975d90c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 18:04:58 -0500 Subject: [PATCH 029/160] fsm and ere --- src/logic/semantics/ere.k | 16 ++++++++++ src/logic/semantics/fsm.k | 10 +++++- src/rvm/rvm-compiler-core.k | 58 +++++++++++++++++++++++++++++++++++ src/rvm/rvm-compiler.k | 61 ++++--------------------------------- test/rvm/Test.rvm | 2 ++ test/rvm/Test4.rvm | 2 +- 6 files changed, 92 insertions(+), 57 deletions(-) create mode 100644 src/logic/semantics/ere.k create mode 100644 src/rvm/rvm-compiler-core.k diff --git a/src/logic/semantics/ere.k b/src/logic/semantics/ere.k new file mode 100644 index 0000000..0438de3 --- /dev/null +++ b/src/logic/semantics/ere.k @@ -0,0 +1,16 @@ +require "../syntax/ere-syntax.k" + +require "../../rvm/rvm-compiler-core.k" + + +module ERE + imports RVM-COMPILER-CORE + imports ERE-SYNTAX + +//test rule +rule + ere + _:EREFormula => .K + true + +endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index b281407..d65e754 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -1,8 +1,16 @@ require "../syntax/fsm-syntax.k" +require "../../rvm/rvm-compiler-core.k" + module FSM -imports FSM-SYNTAX + imports FSM-SYNTAX + imports RVM-COMPILER-CORE + + imports ERE-SYNTAX +rule "fsm" + F:FSMFormula => .K + true endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k new file mode 100644 index 0000000..6d46f0c --- /dev/null +++ b/src/rvm/rvm-compiler-core.k @@ -0,0 +1,58 @@ +module RVM-COMPILER-SYNTAX + imports RVM-SYNTAX + imports DOMAINS-SYNTAX + + + syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] + syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] + syntax VarInitBubble ::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] + syntax NoParentheses ::= r"[^()<][^()]*" [token, klabel('NoParentheses)] + + syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb + + syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel(DecBubbleListCons)] + + syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] + | MethodDecBubble [token, klabel('DecBubbleMethod)] + | FieldDecBubble [token, klabel('DecBubbleField)] + + syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] + | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] + + + + + + syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) + // r"(? $PGM:RVM + "" + + .K + + .Map + 0 + + "" + .Params + .K + + 0 + .K + .K + .HandlerDecList + + false + + .List + + +endmodule diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 80f2590..f289a08 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -1,68 +1,18 @@ require "rvm-syntax.k" require "domains.k" +require "rvm-compiler-core.k" require "../helper/print-ast.k" - -module RVM-COMPILER-SYNTAX - imports RVM-SYNTAX - imports DOMAINS-SYNTAX - - - syntax NoBracket ::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] - syntax ParamsBubble ::= r"\\([^\\)]*\\)" [token, avoid, klabel('ParamsBubble)] - syntax VarInitBubble ::= r"[^<;][^;]*" [token, avoid, klabel('VarInitBubble)] - syntax NoParentheses ::= r"[^()<][^()]*" [token, klabel('NoParentheses)] - - syntax BoolExpBubble ::= BalancedParentheses [token, klabel('BoolExpBubble)] //TODO:removed prefer (for MOP production), check amb - - syntax DecBubbleList ::= List{DecBubble, ""} [token, klabel(DecBubbleListCons)] - - syntax DecBubble ::= ClassDecBubble [token, klabel('DecBubbleClass)] - | MethodDecBubble [token, klabel('DecBubbleMethod)] - | FieldDecBubble [token, klabel('DecBubbleField)] - - syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] - | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] - - - - - - syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) - // r"(? $PGM:RVM - "" - - .K - - .Map - 0 - - "" - .Params - .K - - 0 - .K - .K - .HandlerDecList - - false - - .List - + imports FSM + syntax KResult ::= "error" /** * Store the package info and import list. @@ -124,4 +74,5 @@ rule Prop:PropertyDec Props:PropertyDecList => Props //No properties left //rule .PropertyDecList + endmodule diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index b063dd1..71f3725 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -16,4 +16,6 @@ Test (int o){ int j; } + + } diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index 29466a6..9042446 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -14,7 +14,7 @@ Test (int o){ int i; } - ere: x & x + fsm: @match { int j; From 3c12bdebdb8402b2551f3de2df1164a39763ab50 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 22:15:09 -0500 Subject: [PATCH 030/160] update fsm.k --- src/logic/semantics/fsm.k | 4 ++-- test/rvm/Test.rvm | 24 +++++++++++++++++------- test/rvm/fsm/HasNext.rvm | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index d65e754..2f78e67 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -8,8 +8,8 @@ module FSM imports ERE-SYNTAX -rule "fsm" - F:FSMFormula => .K +rule fsm + _:FSMFormula => .K true diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 71f3725..4e530c0 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -3,14 +3,24 @@ package rvm; import java.io.*; Test (int o){ - event create(){ - int i; - } - event close(){ - int i; - } + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] - ere: x & x + alias match = unsafe, start @match { int j; diff --git a/test/rvm/fsm/HasNext.rvm b/test/rvm/fsm/HasNext.rvm index 11140cf..35a0fae 100644 --- a/test/rvm/fsm/HasNext.rvm +++ b/test/rvm/fsm/HasNext.rvm @@ -8,7 +8,7 @@ import java.util.*; // This property is borrowed from tracematches // (see ECOOP'07 http://abc.comlab.ox.ac.uk/papers) -full-binding HasNext(Iterator i) { +HasNext(Iterator i) { event hasnext(Iterator i) {} // after event next(Iterator i) {} // before From a9e7d16a18578ff4ed8f3867c9157e00a37d952b Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 22:24:55 -0500 Subject: [PATCH 031/160] not support alias at present --- src/rvm/rvm-compiler-core.k | 2 ++ test/rvm/Test.rvm | 2 +- test/rvm/fsm/HasNext.rvm | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 6d46f0c..df0069e 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -1,3 +1,5 @@ +require "rvm-syntax.k" + module RVM-COMPILER-SYNTAX imports RVM-SYNTAX imports DOMAINS-SYNTAX diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 4e530c0..3d9af22 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -20,7 +20,7 @@ Test (int o){ hasnext -> safe ] - alias match = unsafe, start + // alias match = unsafe, start @match { int j; diff --git a/test/rvm/fsm/HasNext.rvm b/test/rvm/fsm/HasNext.rvm index 35a0fae..96bce67 100644 --- a/test/rvm/fsm/HasNext.rvm +++ b/test/rvm/fsm/HasNext.rvm @@ -26,8 +26,8 @@ HasNext(Iterator i) { hasnext -> safe ] - alias match = unsafe - alias unmatch = safe + // alias match = unsafe + // alias unmatch = safe @match { System.out.println("next called without hasNext!"); From cd94280fb2d204b97cc14f093b16f2dc63f643a6 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 22:30:16 -0500 Subject: [PATCH 032/160] confirm mop compiler does not support alias either --- src/mop/mop-compiler.k | 1 - test/mop/test.mop | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mop/mop-compiler.k b/src/mop/mop-compiler.k index 393bcfe..c297f45 100644 --- a/src/mop/mop-compiler.k +++ b/src/mop/mop-compiler.k @@ -36,5 +36,4 @@ module MOP-COMPILER imports MOP-SYNTAX configuration $PGM:MOP - rule `X:OptionalPackageDec => .K` ... endmodule \ No newline at end of file diff --git a/test/mop/test.mop b/test/mop/test.mop index 518589f..2279185 100644 --- a/test/mop/test.mop +++ b/test/mop/test.mop @@ -22,6 +22,8 @@ PipedOutputStream_UnconnectedWrite(PipedOutputStream o) { write -> yes ] +//alias match = yes + @fail { } From 330be06005b1ccdb56561a4a6a25f4233209ff94 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 7 Apr 2016 23:35:58 -0500 Subject: [PATCH 033/160] try to disambiguate --- src/helper/print-ast.k | 12 ++++++++++++ src/logic/semantics/fsm.k | 5 +++-- src/rvm/rvm-compiler-core.k | 13 +++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index ee0196b..8436fe2 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -26,4 +26,16 @@ module PRINT-AST syntax HandlerDecList ::= getHandlers(PropertyDec) [function] rule getHandlers(LN:LogicName : F:LogicFormula HDL:HandlerDecList) => HDL + //get state name from an item + syntax String ::= getStateName(Item) [function] + syntax String ::= printStateName(StateName) [function] + + syntax TransitionList ::= getTransitionList(Item) [function] + + rule getStateName(SN:StateName[TL:TransitionList]) => printStateName(SN) + rule printStateName(SN:Id) => Id2String(SN) + + + rule getTransitionList(SN:StateName[TL:TransitionList]) => TL + endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 2f78e67..ef7f6b6 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -9,8 +9,9 @@ module FSM imports ERE-SYNTAX rule fsm - _:FSMFormula => .K + IT:Item IL:ItemList AL:AliasList => (IL AL) true - + (.Map => (getStateName(IT) |-> I)) CurMap + I:Int => I +Int 1 endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index df0069e..fa67845 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -40,7 +40,7 @@ module RVM-COMPILER-CORE .K - .Map + .Map //map an event to its number 0 "" @@ -48,12 +48,21 @@ module RVM-COMPILER-CORE .K 0 + +/////////////////////////////Logic Plugin cells starts//////////////////////////////////////////// + .K .K - .HandlerDecList false + .Map //map a state to its number + 0 + + .Map +/////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// + .HandlerDecList + .List From f13ed1dc1a3ffa5a6e3f3e31e9843916ff304753 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 01:29:38 -0500 Subject: [PATCH 034/160] k-version --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5c18354..11bd18c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ test/rvm/property-db test/mop/property-db *-kompiled/ +*.bak \ No newline at end of file From 05747e310c567e42ce79d33d9f5ac8b7b599acd4 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 02:04:59 -0500 Subject: [PATCH 035/160] smt translation failure --- src/logic/semantics/fsm.k | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index ef7f6b6..417d702 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -11,7 +11,7 @@ module FSM rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true - (.Map => (getStateName(IT) |-> I)) CurMap + CurMap[getStateName(IT) <- I] I:Int => I +Int 1 endmodule \ No newline at end of file From ab43d06b4c8f30a6147baf267868049a0216fd85 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 02:09:21 -0500 Subject: [PATCH 036/160] states number ok --- src/logic/semantics/fsm.k | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 417d702..1b46c20 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -11,7 +11,8 @@ module FSM rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true - CurMap[getStateName(IT) <- I] + CurMap:Map => CurMap[getStateName(IT) <- I] + I:Int => I +Int 1 endmodule \ No newline at end of file From 65b5d2af871dc43c3abc5f3935668192b6803b64 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 02:22:48 -0500 Subject: [PATCH 037/160] save work --- src/logic/semantics/fsm.k | 5 ++++- src/rvm/rvm-compiler-core.k | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 1b46c20..24c454d 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -12,7 +12,10 @@ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true CurMap:Map => CurMap[getStateName(IT) <- I] - + .K => getTransitionList(IT) I:Int => I +Int 1 + +rule (E:EventName -> SN:StateName) TL:TransitionList => TL + //... endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index fa67845..2f932da 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -59,7 +59,8 @@ module RVM-COMPILER-CORE .Map //map a state to its number 0 - .Map + .K + //the transition functions with the current state as input. /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// .HandlerDecList From c2053dfa600a8fdfa41e4654abf38f3686b1adea Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 07:49:47 -0500 Subject: [PATCH 038/160] add comments --- src/logic/semantics/fsm.k | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 24c454d..be10cac 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -15,6 +15,17 @@ rule fsm .K => getTransitionList(IT) I:Int => I +Int 1 +// when notBool (getStateName(IT) in keys(CurMap)) +// +// //We may or may not forbid the behavior of defining transitions for the same state +// //in multiple places +// +//rule fsm +// IT:Item IL:ItemList AL:AliasList +// true +// (.List => ListItem("State " +String getStateName(IT) +String +// " defined in multiple places")) ErrList:List +//when (getStateName(IT) in keys(CurMap)) rule (E:EventName -> SN:StateName) TL:TransitionList => TL //... From 4b021f7a8b5397fc49cafeb0e9b3a3e28f65b88b Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 08:08:38 -0500 Subject: [PATCH 039/160] test multiple state definition --- src/logic/semantics/fsm.k | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index be10cac..0f25598 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -15,18 +15,21 @@ rule fsm .K => getTransitionList(IT) I:Int => I +Int 1 -// when notBool (getStateName(IT) in keys(CurMap)) -// -// //We may or may not forbid the behavior of defining transitions for the same state -// //in multiple places -// -//rule fsm -// IT:Item IL:ItemList AL:AliasList -// true -// (.List => ListItem("State " +String getStateName(IT) +String -// " defined in multiple places")) ErrList:List -//when (getStateName(IT) in keys(CurMap)) - -rule (E:EventName -> SN:StateName) TL:TransitionList => TL +// if do not need this constraint, then comment the condition below as well as the next rule. + when notBool (getStateName(IT) in keys(CurMap)) + + //We may or may not forbid the behavior of defining transitions for the same state + //in multiple places + +rule fsm + IT:Item IL:ItemList AL:AliasList + CurMap:Map + true => false + (.List => ListItem("State " +String getStateName(IT) +String + " defined in multiple places")) ErrList:List +when (getStateName(IT) in keys(CurMap)) + +//rule (E:EventName -> SN:StateName) TL:TransitionList => TL +// //... endmodule \ No newline at end of file From da82afcb9b5733a429a9362747406609f31acf4a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 09:43:34 -0500 Subject: [PATCH 040/160] restore formula cell in the second scan --- src/logic/semantics/fsm.k | 23 +++++++++++++++++++---- src/rvm/rvm-compiler-core.k | 18 ++++++++++++++++-- src/rvm/rvm-compiler.k | 1 + 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 0f25598..99e7ab2 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -8,12 +8,14 @@ module FSM imports ERE-SYNTAX +/*First scan: Gathering the state ranks*/ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true CurMap:Map => CurMap[getStateName(IT) <- I] - .K => getTransitionList(IT) +// .K => getTransitionList(IT) I:Int => I +Int 1 + 0 // if do not need this constraint, then comment the condition below as well as the next rule. when notBool (getStateName(IT) in keys(CurMap)) @@ -25,11 +27,24 @@ rule fsm IT:Item IL:ItemList AL:AliasList CurMap:Map true => false + 0 (.List => ListItem("State " +String getStateName(IT) +String " defined in multiple places")) ErrList:List when (getStateName(IT) in keys(CurMap)) -//rule (E:EventName -> SN:StateName) TL:TransitionList => TL -// - //... + +/*2nd scan starts: restore the formula for the second scan*/ +rule .ItemList AL:AliasList => FC + FC:K + true + 0 => 1 + + + +/**consume the transition functions defined for the current state.*/ +//rule (E:EventName -> SN:StateName) TL:TransitionList => TL +// I:Int //cur state has rank I -Int 1 +// StateMap +// ... (E |-> +// (Func => Func[(I -Int 1) |-> StateMap[getStateName(SN)]]) ) ... endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 2f932da..4b34133 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -59,8 +59,22 @@ module RVM-COMPILER-CORE .Map //map a state to its number 0 - .K - //the transition functions with the current state as input. + //the raw transition defined in the rvm spec, indexed by states + .K + + //the state transformation function, indexed by events + .Map + + //we may need to traverse formula to get state numbers + //in the first scan, use this tmp cell for saving state transitions + //which will be restored in the second scan. + .K + 0 + + .K +///////////////////////Specific for FSM////////////////////////////////////////////////////// + + /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// .HandlerDecList diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index f289a08..4fbc105 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -69,6 +69,7 @@ rule Prop:PropertyDec Props:PropertyDecList => Props I:Int => I +Int 1 .K => getLogicName(Prop) .K => getFormula(Prop) + .K => getFormula(Prop) .HandlerDecList => getHandlers(Prop) false => true From 4452cdfc1e5e145835fa0223e2f4f96ecf5fa07f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 11:11:12 -0500 Subject: [PATCH 041/160] debug --- src/logic/semantics/fsm.k | 44 +++++++++++++++++++++++++++++++------ src/rvm/rvm-compiler-core.k | 3 +-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 99e7ab2..6e05392 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -13,7 +13,6 @@ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true CurMap:Map => CurMap[getStateName(IT) <- I] -// .K => getTransitionList(IT) I:Int => I +Int 1 0 @@ -32,19 +31,50 @@ rule fsm " defined in multiple places")) ErrList:List when (getStateName(IT) in keys(CurMap)) - +////////////////////////////////////////////////////////////////////////////////////////////////// /*2nd scan starts: restore the formula for the second scan*/ rule .ItemList AL:AliasList => FC FC:K true + _:Int => -1 0 => 1 +/*2nd scan: get the raw transition mapping associated with the current state +Inside the item: + +s0[e1 -> s1 +e2 -> s2] +The raw transitions associated with state s0 is: e1 -> s1, e2 -> s2. +*/ +rule fsm + IT:Item IL:ItemList AL:AliasList => (IL AL) + I:Int => I +Int 1 + .K => getTransitionList(IT) + 1 /**consume the transition functions defined for the current state.*/ -//rule (E:EventName -> SN:StateName) TL:TransitionList => TL -// I:Int //cur state has rank I -Int 1 -// StateMap -// ... (E |-> -// (Func => Func[(I -Int 1) |-> StateMap[getStateName(SN)]]) ) ... +rule (E:EventName -> SN:StateName) TL:TransitionList => TL + I:Int + StateMap:Map + BigMap:Map => BigMap[E:EventName <- + (I |-> lookup(StateMap, getStateName(SN)):Int):Map] + + 1 + when notBool (E in keys(BigMap)) + +rule (E:EventName -> SN:StateName) TL:TransitionList => TL + I:Int + StateMap:Map + BigMap:Map => BigMap[E <- + (lookup(BigMap, E)[I <- lookup(StateMap, getStateName(SN)):Int])] + + 1 + when E in keys(BigMap) + + + +rule .TransitionList => .K + 1 + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 4b34133..1883ec4 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -63,7 +63,7 @@ module RVM-COMPILER-CORE .K //the state transformation function, indexed by events - .Map + .Map //we may need to traverse formula to get state numbers //in the first scan, use this tmp cell for saving state transitions @@ -74,7 +74,6 @@ module RVM-COMPILER-CORE .K ///////////////////////Specific for FSM////////////////////////////////////////////////////// - /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// .HandlerDecList From 54514c448362c801bb1894479b7d308d48b8a3ed Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 8 Apr 2016 12:28:32 -0500 Subject: [PATCH 042/160] debug --- src/helper/print-ast.k | 4 ++++ src/logic/semantics/fsm.k | 27 ++++++++++++++++++++------- src/rvm/rvm-compiler-core.k | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 8436fe2..940a27a 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -26,6 +26,10 @@ module PRINT-AST syntax HandlerDecList ::= getHandlers(PropertyDec) [function] rule getHandlers(LN:LogicName : F:LogicFormula HDL:HandlerDecList) => HDL + //get event name in string + syntax String ::= getEventName(EventName) [function] + rule getEventName(E:Id) => Id2String(E) + //get state name from an item syntax String ::= getStateName(Item) [function] syntax String ::= printStateName(StateName) [function] diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 6e05392..3c512b1 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -54,21 +54,34 @@ rule fsm 1 /**consume the transition functions defined for the current state.*/ -rule (E:EventName -> SN:StateName) TL:TransitionList => TL - I:Int - StateMap:Map - BigMap:Map => BigMap[E:EventName <- - (I |-> lookup(StateMap, getStateName(SN)):Int):Map] +//rule (E:EventName -> SN:StateName) TL:TransitionList +// BigMap:Map => BigMap[getEventName(E) <- (.Map)] +// +// 1 +// when notBool (getEventName(E) in keys(BigMap)) + + +rule (E:EventName -> SN:StateName) TL:TransitionList + BigMap:Map => BigMap[E <- (.Map)] 1 when notBool (E in keys(BigMap)) + + rule (E:EventName -> SN:StateName) TL:TransitionList => TL I:Int StateMap:Map - BigMap:Map => BigMap[E <- - (lookup(BigMap, E)[I <- lookup(StateMap, getStateName(SN)):Int])] + +// .K => ((lookup(BigMap, E):Map [I <- lookup(StateMap, getStateName(SN)):Int]):Map) +// .K => BigMap[E] + //should be the problem of using lookup function, the klabel Map:lookup does not compile + //the lookup function seems not the one for lookup val in a map! + + BigMap:Map //=> BigMap[E <- ] + + 1 when E in keys(BigMap) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 1883ec4..6d12e52 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -72,6 +72,8 @@ module RVM-COMPILER-CORE 0 .K + + .K //additional computation cell ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// From e37e7f9462a831161c7233773866cf97e54a7049 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 07:54:14 -0500 Subject: [PATCH 043/160] use nested cells to encode complex map --- src/logic/semantics/fsm.k | 54 +++++++++++++++++++++---------------- src/rvm/rvm-compiler-core.k | 10 +++++-- src/rvm/rvm-compiler.k | 19 ++++++++++--- 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 3c512b1..64baa97 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -54,36 +54,44 @@ rule fsm 1 /**consume the transition functions defined for the current state.*/ -//rule (E:EventName -> SN:StateName) TL:TransitionList -// BigMap:Map => BigMap[getEventName(E) <- (.Map)] -// -// 1 -// when notBool (getEventName(E) in keys(BigMap)) - - rule (E:EventName -> SN:StateName) TL:TransitionList - BigMap:Map => BigMap[E <- (.Map)] - + Es:Set 1 - when notBool (E in keys(BigMap)) - + (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List + when notBool E in Es -rule (E:EventName -> SN:StateName) TL:TransitionList => TL - I:Int - StateMap:Map - -// .K => ((lookup(BigMap, E):Map [I <- lookup(StateMap, getStateName(SN)):Int]):Map) -// .K => BigMap[E] - //should be the problem of using lookup function, the klabel Map:lookup does not compile - //the lookup function seems not the one for lookup val in a map! +//rule (E:EventName -> SN:StateName) TL:TransitionList +// +// ... +// +// +// E +// ... +// +// +// ... +// +// 1 +// when notBool (E in keys(BigMap)) - BigMap:Map //=> BigMap[E <- ] - - 1 - when E in keys(BigMap) +//rule (E:EventName -> SN:StateName) TL:TransitionList => TL +// I:Int +// StateMap:Map +// +//// .K => ((lookup(BigMap, E):Map [I <- lookup(StateMap, getStateName(SN)):Int]):Map) +// .K => BigMap[E] +// //should be the problem of using lookup function, the klabel Map:lookup does not compile +// //the lookup function seems not the one for lookup val in a map! +// +// BigMap:Map +// +// +// +// 1 +// when E in keys(BigMap) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 6d12e52..76b44bf 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -40,7 +40,7 @@ module RVM-COMPILER-CORE .K - .Map //map an event to its number + .Set //map an event to its number 0 "" @@ -63,7 +63,13 @@ module RVM-COMPILER-CORE .K //the state transformation function, indexed by events - .Map + + + .K + -1 + .K + + //we may need to traverse formula to get state numbers //in the first scan, use this tmp cell for saving state transitions diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 4fbc105..7cf2fc8 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -45,9 +45,20 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - (.Map => (X |-> I)) Cur:Map + (.Set => SetItem(X)) Cur:Set + + + ... + + (.Bag => + X + I + ... + ) + + I:Int => I +Int 1 -when notBool (X in keys(Cur)) +when notBool (X in Cur) /** * Report error if an event is defined multiple times. @@ -56,9 +67,9 @@ when notBool (X in keys(Cur)) */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList) Props:PropertyDecList} => .K - Cur:Map + Cur:Set (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List -when (X in keys(Cur)) +when (X in Cur) //No events left rule From ff85042e7b5c24dde47a07cf34d104b3d06b6eba Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 08:01:33 -0500 Subject: [PATCH 044/160] handle undefined event --- src/logic/semantics/fsm.k | 1 + 1 file changed, 1 insertion(+) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 64baa97..b48726c 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -58,6 +58,7 @@ rule (E:EventName -> SN:StateName) TL:TransitionList Es:Set 1 (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List + true => false when notBool E in Es From 9a1ef8ca0738bf18cfe282d6ed437f794aa58555 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 08:52:03 -0500 Subject: [PATCH 045/160] encode transition functions as int arrays, indexed by event names; check unknown state --- src/logic/semantics/fsm.k | 56 ++++++++++++++++--------------------- src/rvm/rvm-compiler-core.k | 2 +- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index b48726c..39fae97 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -54,6 +54,7 @@ rule fsm 1 /**consume the transition functions defined for the current state.*/ +/*Handle unknown event*/ rule (E:EventName -> SN:StateName) TL:TransitionList Es:Set 1 @@ -61,38 +62,29 @@ rule (E:EventName -> SN:StateName) TL:TransitionList true => false when notBool E in Es - -//rule (E:EventName -> SN:StateName) TL:TransitionList -// -// ... -// -// -// E -// ... -// -// -// ... -// -// 1 -// when notBool (E in keys(BigMap)) - - - -//rule (E:EventName -> SN:StateName) TL:TransitionList => TL -// I:Int -// StateMap:Map -// -//// .K => ((lookup(BigMap, E):Map [I <- lookup(StateMap, getStateName(SN)):Int]):Map) -// .K => BigMap[E] -// //should be the problem of using lookup function, the klabel Map:lookup does not compile -// //the lookup function seems not the one for lookup val in a map! -// -// BigMap:Map -// -// -// -// 1 -// when E in keys(BigMap) +/*Handle unknown state*/ +rule (E:EventName -> SN:StateName) TL:TransitionList + SM:Map + 1 + (.List => ListItem("Undefined state " +String printStateName(SN))) ErrList:List + true => false + when notBool (printStateName(SN) in keys(SM)) + +rule (E:EventName -> SN:StateName) TL:TransitionList => TL + S1:Int + SM:Map (printStateName(SN):String |-> S2:Int):Map + + ... + + + E + (.Map => S1 |-> S2) M:Map + ... + + + ... + + 1 diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 76b44bf..7880a1c 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -67,7 +67,7 @@ module RVM-COMPILER-CORE .K -1 - .K + .Map From 46698702110effbb002f88ba4f8f062f411fb3e2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 08:53:37 -0500 Subject: [PATCH 046/160] add more test rvm files --- test/rvm/Test-undefinedEvent.rvm | 24 ++++++++++++++++++++++++ test/rvm/Test-undefinedState.rvm | 31 +++++++++++++++++++++++++++++++ version.txt | 2 ++ 3 files changed, 57 insertions(+) create mode 100644 test/rvm/Test-undefinedEvent.rvm create mode 100644 test/rvm/Test-undefinedState.rvm create mode 100644 version.txt diff --git a/test/rvm/Test-undefinedEvent.rvm b/test/rvm/Test-undefinedEvent.rvm new file mode 100644 index 0000000..6ab691e --- /dev/null +++ b/test/rvm/Test-undefinedEvent.rvm @@ -0,0 +1,24 @@ +package rvm; + +import java.io.*; +Test (int o){ + + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + foo -> safe //event foo is undefined, should report error. + + next -> unsafe + hasnext -> safe + ] + + + @match { + int j; + } + + + +} diff --git a/test/rvm/Test-undefinedState.rvm b/test/rvm/Test-undefinedState.rvm new file mode 100644 index 0000000..39e1144 --- /dev/null +++ b/test/rvm/Test-undefinedState.rvm @@ -0,0 +1,31 @@ +package rvm; + +import java.io.*; +Test (int o){ + + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> bar //state bar is undefined, should report error. + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + // alias match = unsafe, start + + @match { + int j; + } + + + +} diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..f129ba2 --- /dev/null +++ b/version.txt @@ -0,0 +1,2 @@ +K: [github](https://github.com/kframework/k) +ee3bdc2066c29d7a0c7f29ab85c7bcaf1332b173 \ No newline at end of file From 61b089670e3cd2b5c8e47c184f005cc6acf870e2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 09:10:14 -0500 Subject: [PATCH 047/160] clean up --- src/logic/semantics/fsm.k | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 39fae97..a07b902 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -6,8 +6,6 @@ module FSM imports FSM-SYNTAX imports RVM-COMPILER-CORE - imports ERE-SYNTAX - /*First scan: Gathering the state ranks*/ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) From 2eb8ba4400487f3ecc3f4be3e5ba203903cfd57a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 14:18:34 -0500 Subject: [PATCH 048/160] print int array --- src/helper/util.k | 17 +++++++++++++++++ src/logic/semantics/fsm.k | 9 +++++++++ src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 1 - 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/helper/util.k diff --git a/src/helper/util.k b/src/helper/util.k new file mode 100644 index 0000000..3d69db0 --- /dev/null +++ b/src/helper/util.k @@ -0,0 +1,17 @@ +module UTIL + +/*This function takes an int -> int map as input, sort it via keys and return the values as a list* +* If an event does not map a given state to any normal state, then it maps to error state, +and the error state is by default having rank 'size' of the number of normal states*/ +syntax List ::= toIntArray(Map) [function] +/*The second int is the size of the current map, the third is the size of the original complete map.*/ +syntax List ::= toIntArray(Map, Int, Int) [function] + +rule toIntArray(.Map) => ListItem(0) //if no normal state, then there is only one error state. + +rule toIntArray(M:Map) => toIntArray(M, size(M), size(M)) + +rule toIntArray(((Siz -Int I) |-> V:Int) M:Map, I:Int, Siz:Int) => + ListItem(V) toIntArray(M, I -Int 1, Siz) + +endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index a07b902..8dd3050 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -2,9 +2,12 @@ require "../syntax/fsm-syntax.k" require "../../rvm/rvm-compiler-core.k" +require "../../helper/util.k" + module FSM imports FSM-SYNTAX imports RVM-COMPILER-CORE + imports UTIL /*First scan: Gathering the state ranks*/ rule fsm @@ -89,4 +92,10 @@ rule (E:EventName -> SN:StateName) TL:TransitionList => TL .TransitionList => .K 1 +rule + ... + SM:Map + .List => toIntArray(SM) + + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 7880a1c..0656e06 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -66,8 +66,8 @@ module RVM-COMPILER-CORE .K - -1 .Map + .List diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 7cf2fc8..a2fa965 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -52,7 +52,6 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) (.Bag => X - I ... ) From b019b71abf1655d05bab97446129e9d267a64548 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 15:30:10 -0500 Subject: [PATCH 049/160] debug --- src/helper/util.k | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/helper/util.k b/src/helper/util.k index 3d69db0..a3a14f8 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -11,7 +11,12 @@ rule toIntArray(.Map) => ListItem(0) //if no normal state, then there is only on rule toIntArray(M:Map) => toIntArray(M, size(M), size(M)) -rule toIntArray(((Siz -Int I) |-> V:Int) M:Map, I:Int, Siz:Int) => - ListItem(V) toIntArray(M, I -Int 1, Siz) +//rule toIntArray(((Siz -Int I) |-> V:Int) M:Map, I:Int, Siz:Int) => +// ListItem(V) toIntArray(M, I -Int 1, Siz) + +rule toIntArray(M:Map, 0, Siz:Int) => Siz + +rule toIntArray(M:Map, I:Int, Siz:Int) => + M[Siz -Int I] toIntArray(M, I -Int 1, Siz) endmodule \ No newline at end of file From 3d391d68cac7ec610b1a46b9ac6942309bc23036 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 16:41:08 -0500 Subject: [PATCH 050/160] get int array --- src/helper/util.k | 14 +++++++------- src/logic/semantics/fsm.k | 5 ++++- test/helper/a.test | 1 + test/helper/test.k | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 test/helper/a.test create mode 100644 test/helper/test.k diff --git a/src/helper/util.k b/src/helper/util.k index a3a14f8..d8c26ff 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -9,14 +9,14 @@ syntax List ::= toIntArray(Map, Int, Int) [function] rule toIntArray(.Map) => ListItem(0) //if no normal state, then there is only one error state. -rule toIntArray(M:Map) => toIntArray(M, size(M), size(M)) +rule toIntArray(M:Map) => toIntArray(M, 0, size(M)) -//rule toIntArray(((Siz -Int I) |-> V:Int) M:Map, I:Int, Siz:Int) => -// ListItem(V) toIntArray(M, I -Int 1, Siz) - -rule toIntArray(M:Map, 0, Siz:Int) => Siz +rule toIntArray(M:Map, Cur:Int, Siz:Int) => ListItem(Siz) when Cur ==Int Siz rule toIntArray(M:Map, I:Int, Siz:Int) => - M[Siz -Int I] toIntArray(M, I -Int 1, Siz) + ListItem(M[I]) toIntArray(M, I +Int 1, Siz) + when I (E:EventName -> SN:StateName) TL:TransitionList => TL .TransitionList => .K 1 -rule +rule + .ItemList .AliasList + ... SM:Map .List => toIntArray(SM) + 1 endmodule \ No newline at end of file diff --git a/test/helper/a.test b/test/helper/a.test new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/helper/a.test @@ -0,0 +1 @@ +0 diff --git a/test/helper/test.k b/test/helper/test.k new file mode 100644 index 0000000..8f5f09c --- /dev/null +++ b/test/helper/test.k @@ -0,0 +1,22 @@ +require "../../src/helper/util.k" + +module TEST +imports UTIL + + +configuration + + $PGM:Int + false + .Map + .List + + +rule false => true + .Map => (((1 |-> 2):Map (2 |-> 0):Map) (0 |-> 1):Map):Map + +rule true + M:Map + .List => toIntArray(M) + +endmodule \ No newline at end of file From 3c10aec992b099d18625470b176b182f451a4bcd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 17:05:37 -0500 Subject: [PATCH 051/160] debug --- src/helper/util.k | 18 +++++++++++------- src/logic/semantics/fsm.k | 4 ++-- test/rvm/Test-partialFunction.rvm | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 test/rvm/Test-partialFunction.rvm diff --git a/src/helper/util.k b/src/helper/util.k index d8c26ff..d8b7722 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -3,20 +3,24 @@ module UTIL /*This function takes an int -> int map as input, sort it via keys and return the values as a list* * If an event does not map a given state to any normal state, then it maps to error state, and the error state is by default having rank 'size' of the number of normal states*/ -syntax List ::= toIntArray(Map) [function] -/*The second int is the size of the current map, the third is the size of the original complete map.*/ -syntax List ::= toIntArray(Map, Int, Int) [function] - -rule toIntArray(.Map) => ListItem(0) //if no normal state, then there is only one error state. +/*The int represents the number of the states*/ +syntax List ::= toIntArray(Map, Int) [function] +rule toIntArray(M:Map, I:Int) => toIntArray(M, 0, I) -rule toIntArray(M:Map) => toIntArray(M, 0, size(M)) +/*The second int is the index of the current state, the third is the number of states.*/ +syntax List ::= toIntArray(Map, Int, Int) [function] rule toIntArray(M:Map, Cur:Int, Siz:Int) => ListItem(Siz) when Cur ==Int Siz rule toIntArray(M:Map, I:Int, Siz:Int) => ListItem(M[I]) toIntArray(M, I +Int 1, Siz) - when I + ListItem(Siz) toIntArray(M, I +Int 1, Siz) + when I (E:EventName -> SN:StateName) TL:TransitionList => TL .TransitionList => .K 1 -rule +rule AllStatesMap:Map .ItemList .AliasList ... SM:Map - .List => toIntArray(SM) + .List => toIntArray(SM, size(AllStatesMap)) 1 diff --git a/test/rvm/Test-partialFunction.rvm b/test/rvm/Test-partialFunction.rvm new file mode 100644 index 0000000..a89277b --- /dev/null +++ b/test/rvm/Test-partialFunction.rvm @@ -0,0 +1,29 @@ +package rvm; + +import java.io.*; +Test (int o){ + + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + next -> unsafe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + ] + + // alias match = unsafe, start + + @match { + int j; + } + + + +} From 4bfe0c5ae71ae8454510b55886a32bf677d60b3a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 17:25:24 -0500 Subject: [PATCH 052/160] translate the transition functions to int arrays correctly --- src/helper/util.k | 2 +- src/logic/semantics/fsm.k | 3 +++ test/rvm/Test-partialFunction.rvm | 4 ++-- test/rvm/Test.rvm | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helper/util.k b/src/helper/util.k index d8b7722..f0576b8 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -14,7 +14,7 @@ rule toIntArray(M:Map, Cur:Int, Siz:Int) => ListItem(Siz) when Cur ==Int Siz rule toIntArray(M:Map, I:Int, Siz:Int) => ListItem(M[I]) toIntArray(M, I +Int 1, Siz) - when I (E:EventName -> SN:StateName) TL:TransitionList => TL .TransitionList => .K 1 +/*when all the computation related to the formula completes, +translate the transition function from map to int array*/ rule AllStatesMap:Map .ItemList .AliasList + .K ... SM:Map diff --git a/test/rvm/Test-partialFunction.rvm b/test/rvm/Test-partialFunction.rvm index a89277b..e4bbbbf 100644 --- a/test/rvm/Test-partialFunction.rvm +++ b/test/rvm/Test-partialFunction.rvm @@ -3,8 +3,8 @@ package rvm; import java.io.*; Test (int o){ - event hasnext(Iterator i) {} // after - event next(Iterator i) {} // before + event hasnext(Iterator i) {} // {3, 1, 3, 3} + event next(Iterator i) {} // {2, 0, 2, 3} fsm : start [ diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 3d9af22..2f19a29 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -3,8 +3,8 @@ package rvm; import java.io.*; Test (int o){ - event hasnext(Iterator i) {} // after - event next(Iterator i) {} // before + event hasnext(Iterator i) {} // {1, 1, 1, 3} + event next(Iterator i) {} // {2, 0, 2, 3} fsm : start [ From fa8a2fc779bc4d444e3605c6c378716927dfaadb Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 17:42:09 -0500 Subject: [PATCH 053/160] todo --- ToDo.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ToDo.txt diff --git a/ToDo.txt b/ToDo.txt new file mode 100644 index 0000000..d129b4a --- /dev/null +++ b/ToDo.txt @@ -0,0 +1,11 @@ +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). + From 97d319af4845eb23cd3f18fd0c55f59ccc79bda8 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 18:06:29 -0500 Subject: [PATCH 054/160] add some templates --- src/c-monitor-code-template/template.c.origin | 59 +++++++++++++++ src/c-monitor-code-template/template.c.try | 73 +++++++++++++++++++ src/c-monitor-code-template/template.h.origin | 10 +++ src/c-monitor-code-template/template.h.try | 10 +++ 4 files changed, 152 insertions(+) create mode 100644 src/c-monitor-code-template/template.c.origin create mode 100644 src/c-monitor-code-template/template.c.try create mode 100644 src/c-monitor-code-template/template.h.origin create mode 100644 src/c-monitor-code-template/template.h.try diff --git a/src/c-monitor-code-template/template.c.origin b/src/c-monitor-code-template/template.c.origin new file mode 100644 index 0000000..6b1ef77 --- /dev/null +++ b/src/c-monitor-code-template/template.c.origin @@ -0,0 +1,59 @@ +#include + + +#include +static int __RVC_state = 0; + + + +int __RVC_SeatBelt_safe = 0; +int __RVC_SeatBelt_unsafe = 0; + +void +__RVC_SeatBelt_reset(void) +{ + __RVC_state = 0; + } + +static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; +static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; + +void +__RVC_SeatBelt_seatBeltRemoved() +{ +{fprintf(stderr, "Seat belt removed.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTREMOVED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + +void +__RVC_SeatBelt_seatBeltAttached() +{ +{fprintf(stderr, "Seat belt attached.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + + diff --git a/src/c-monitor-code-template/template.c.try b/src/c-monitor-code-template/template.c.try new file mode 100644 index 0000000..543db91 --- /dev/null +++ b/src/c-monitor-code-template/template.c.try @@ -0,0 +1,73 @@ +$0 // #include + // #include + +$1 // "static int __RVC_state = 0;\n" + +$2 // "int __RVC_" + +$spec // spec name + +$u // underscore: "_" + +$4 // " = 0;\n" //init to 0 + +$state // will rewrite to: for each $i in #numOfStates { $state_i_init } + +$state_i //rewrite to the name of state i + +$state_i_init //rewrite to: $2 $spec $u $state_i $4 + + +////////////////////////////// + +_safe = 0; +int __RVC_SeatBelt_unsafe = 0; + +void +__RVC_SeatBelt_reset(void) +{ + __RVC_state = 0; + } + +static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; +static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; + +void +__RVC_SeatBelt_seatBeltRemoved() +{ +{fprintf(stderr, "Seat belt removed.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTREMOVED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + +void +__RVC_SeatBelt_seatBeltAttached() +{ +{fprintf(stderr, "Seat belt attached.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + + diff --git a/src/c-monitor-code-template/template.h.origin b/src/c-monitor-code-template/template.h.origin new file mode 100644 index 0000000..8c1dc40 --- /dev/null +++ b/src/c-monitor-code-template/template.h.origin @@ -0,0 +1,10 @@ +#ifndef __RVC_SEATBELT_MONITOR_H +#define __RVC_SEATBELT_MONITOR_H +void +__RVC_SeatBelt_reset(void); +void +__RVC_SeatBelt_seatBeltRemoved(); +void +__RVC_SeatBelt_seatBeltAttached(); + +#endif diff --git a/src/c-monitor-code-template/template.h.try b/src/c-monitor-code-template/template.h.try new file mode 100644 index 0000000..8c1dc40 --- /dev/null +++ b/src/c-monitor-code-template/template.h.try @@ -0,0 +1,10 @@ +#ifndef __RVC_SEATBELT_MONITOR_H +#define __RVC_SEATBELT_MONITOR_H +void +__RVC_SeatBelt_reset(void); +void +__RVC_SeatBelt_seatBeltRemoved(); +void +__RVC_SeatBelt_seatBeltAttached(); + +#endif From 3ad70a46567c03d05375c3e14febc5dea3d790e2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 18:28:02 -0500 Subject: [PATCH 055/160] update --- .../c-monitor-template-syntax.k | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/c-monitor-code-template/c-monitor-template-syntax.k diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k new file mode 100644 index 0000000..01f190c --- /dev/null +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -0,0 +1,11 @@ +module C-MONITOR-TEMPLATE-SYNTAX + +//the state transition function is encoded using int array. +syntax CTemplate ::= Include StateVarsInit ResetFunc StateTransitions EventActions + +syntax Include ::= "$incl" +syntax StateVarsInit ::= GlobalStateInit LocalStatesInit +syntax GlobalStateInit ::= "$globalInit" +syntax LocalStatesInit ::= "localInit" + +endmodule \ No newline at end of file From f9b0c0a529563a69ea07d6e1ff7531bcff61c56a Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 19:38:40 -0500 Subject: [PATCH 056/160] add c-monitor-template --- .../c-monitor-template-syntax.k | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 01f190c..76b3010 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -3,9 +3,19 @@ module C-MONITOR-TEMPLATE-SYNTAX //the state transition function is encoded using int array. syntax CTemplate ::= Include StateVarsInit ResetFunc StateTransitions EventActions +syntax CTemplate ::= "$CMonitor" + syntax Include ::= "$incl" syntax StateVarsInit ::= GlobalStateInit LocalStatesInit syntax GlobalStateInit ::= "$globalInit" -syntax LocalStatesInit ::= "localInit" +syntax LocalStatesInit ::= "$localInit" + +syntax ResetFunc ::= "$reset" + +syntax StateTransitions ::= "$stateFuncs" + +syntax EventActions ::= "$eventFuncs" + +rule $CMonitor => $incl $globalInit $localInit $reset $stateFuncs $eventFuncs endmodule \ No newline at end of file From f7f164017617d9eda81e2a220e5f1188e8e6def7 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 20:11:11 -0500 Subject: [PATCH 057/160] test: start from some structure, end with some other structure in k cell --- test/cmop/test.in | 1 + test/cmop/test.k | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/cmop/test.in create mode 100644 test/cmop/test.k diff --git a/test/cmop/test.in b/test/cmop/test.in new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/cmop/test.in @@ -0,0 +1 @@ +0 diff --git a/test/cmop/test.k b/test/cmop/test.k new file mode 100644 index 0000000..36c21d6 --- /dev/null +++ b/test/cmop/test.k @@ -0,0 +1,13 @@ +require "../../src/c-monitor-code-template/c-monitor-template-syntax.k" +module TEST +imports C-MONITOR-TEMPLATE-SYNTAX + +configuration + $PGM:Int + false + + +rule false => true + _:K => $CMonitor + +endmodule \ No newline at end of file From 6cf8f41792fbc2beeeca6e9fb740715b9707211e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 20:30:54 -0500 Subject: [PATCH 058/160] test code g generation idea --- .../c-monitor-template-syntax.k | 12 +++++++----- test/cmop/test.k | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 76b3010..044ae89 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -3,19 +3,21 @@ module C-MONITOR-TEMPLATE-SYNTAX //the state transition function is encoded using int array. syntax CTemplate ::= Include StateVarsInit ResetFunc StateTransitions EventActions -syntax CTemplate ::= "$CMonitor" +syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and states resp. syntax Include ::= "$incl" syntax StateVarsInit ::= GlobalStateInit LocalStatesInit syntax GlobalStateInit ::= "$globalInit" -syntax LocalStatesInit ::= "$localInit" +syntax LocalStatesInit ::= "$localInit" Int syntax ResetFunc ::= "$reset" -syntax StateTransitions ::= "$stateFuncs" +syntax StateTransitions ::= "$stateFuncs" Int -syntax EventActions ::= "$eventFuncs" +syntax EventActions ::= "$eventFuncs" Int -rule $CMonitor => $incl $globalInit $localInit $reset $stateFuncs $eventFuncs +rule $CMonitor NumOfEvents:Int NumOfStates:Int => + $incl $globalInit $localInit NumOfStates $reset + $stateFuncs NumOfStates $eventFuncs NumOfEvents endmodule \ No newline at end of file diff --git a/test/cmop/test.k b/test/cmop/test.k index 36c21d6..8e0dfc8 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -8,6 +8,6 @@ configuration rule false => true - _:K => $CMonitor + _:K => $CMonitor 2 3 endmodule \ No newline at end of file From e50b6fca9b4414b3f974e2cf4ca3ee1f14bb968e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 9 Apr 2016 23:59:04 -0500 Subject: [PATCH 059/160] add logic type cell to all rules in fsm.k --- src/logic/semantics/fsm.k | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index a15f8b5..e59818a 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -34,7 +34,9 @@ when (getStateName(IT) in keys(CurMap)) ////////////////////////////////////////////////////////////////////////////////////////////////// /*2nd scan starts: restore the formula for the second scan*/ -rule .ItemList AL:AliasList => FC +rule + fsm + .ItemList AL:AliasList => FC FC:K true _:Int => -1 @@ -56,7 +58,9 @@ rule fsm /**consume the transition functions defined for the current state.*/ /*Handle unknown event*/ -rule (E:EventName -> SN:StateName) TL:TransitionList +rule + fsm + (E:EventName -> SN:StateName) TL:TransitionList Es:Set 1 (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List @@ -64,14 +68,17 @@ rule (E:EventName -> SN:StateName) TL:TransitionList (E:EventName -> SN:StateName) TL:TransitionList +rule + fsm + (E:EventName -> SN:StateName) TL:TransitionList SM:Map 1 (.List => ListItem("Undefined state " +String printStateName(SN))) ErrList:List true => false when notBool (printStateName(SN) in keys(SM)) -rule (E:EventName -> SN:StateName) TL:TransitionList => TL +rule fsm + (E:EventName -> SN:StateName) TL:TransitionList => TL S1:Int SM:Map (printStateName(SN):String |-> S2:Int):Map @@ -89,12 +96,15 @@ rule (E:EventName -> SN:StateName) TL:TransitionList => TL .TransitionList => .K +rule + fsm + .TransitionList => .K 1 /*when all the computation related to the formula completes, translate the transition function from map to int array*/ -rule AllStatesMap:Map +rule fsm + AllStatesMap:Map .ItemList .AliasList .K From 5065a741f1a70139fe3c5fde94a1dae2a6312a94 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 10 Apr 2016 00:05:26 -0500 Subject: [PATCH 060/160] update template --- src/c-monitor-code-template/c-monitor-template-syntax.k | 5 +++-- src/c-monitor-code-template/c-monitor-template.k | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/c-monitor-code-template/c-monitor-template.k diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 044ae89..7b87b0e 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -17,7 +17,8 @@ syntax StateTransitions ::= "$stateFuncs" Int syntax EventActions ::= "$eventFuncs" Int rule $CMonitor NumOfEvents:Int NumOfStates:Int => - $incl $globalInit $localInit NumOfStates $reset - $stateFuncs NumOfStates $eventFuncs NumOfEvents + $incl $globalInit ($localInit NumOfStates):LocalStatesInit $reset + ($stateFuncs NumOfStates):StateTransitions ($eventFuncs NumOfEvents):EventActions + endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k new file mode 100644 index 0000000..2255df4 --- /dev/null +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -0,0 +1,6 @@ +module C-MONITOR-TEMPLATE +imports C-MONITOR-TEMPLATE-SYNTAX + + + +endmodule \ No newline at end of file From 119e7f836e5766627dec07190b321e0a2009adda Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 10 Apr 2016 01:43:31 -0500 Subject: [PATCH 061/160] debug --- .../c-monitor-template-syntax.k | 20 +++++++++++++------ .../c-monitor-template.k | 8 +++++++- src/c-monitor-code-template/import.k | 14 +++++++++++++ src/rvm/rvm-compiler-core.k | 6 ++++++ test/cmop/test.k | 11 ++++++++++ 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/c-monitor-code-template/import.k diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 7b87b0e..6c220e8 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -8,17 +8,25 @@ syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and s syntax Include ::= "$incl" syntax StateVarsInit ::= GlobalStateInit LocalStatesInit syntax GlobalStateInit ::= "$globalInit" -syntax LocalStatesInit ::= "$localInit" Int -syntax ResetFunc ::= "$reset" +syntax LocalStatesInit ::= "$localInit" "(" Int ")" +syntax LocalStatesInit ::= List{StateVar, ","} +syntax StateVar ::= "$sVar" "(" Int ")" -syntax StateTransitions ::= "$stateFuncs" Int -syntax EventActions ::= "$eventFuncs" Int +syntax ResetFunc ::= "#reset" + +syntax StateTransitions ::= "$stateFuncs" "(" Int ")" +syntax StateTransitions ::= List{StateFunc, ","} +syntax StateFunc ::= "$sFunc" "(" Int ")" + +syntax EventActions ::= "$eventFuncs" "(" Int ")" +syntax EventActions ::= List{EventFunc, ","} +syntax EventFunc ::= "eFunc" "(" Int ")" rule $CMonitor NumOfEvents:Int NumOfStates:Int => - $incl $globalInit ($localInit NumOfStates):LocalStatesInit $reset - ($stateFuncs NumOfStates):StateTransitions ($eventFuncs NumOfEvents):EventActions + $incl $globalInit ($localInit(NumOfStates)) #reset + ($stateFuncs(NumOfStates)) $eventFuncs(NumOfEvents) endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 2255df4..f88a2b0 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -1,5 +1,11 @@ +require "../rvm/rvm-compiler-core.k" +require "c-monitor-template-syntax.k" +require "import.k" + module C-MONITOR-TEMPLATE -imports C-MONITOR-TEMPLATE-SYNTAX + imports RVM-COMPILER-CORE + imports C-MONITOR-TEMPLATE-SYNTAX + imports IMPORT diff --git a/src/c-monitor-code-template/import.k b/src/c-monitor-code-template/import.k new file mode 100644 index 0000000..db59a52 --- /dev/null +++ b/src/c-monitor-code-template/import.k @@ -0,0 +1,14 @@ +require "../rvm/rvm-compiler-core.k" +require "c-monitor-template-syntax.k" + +module IMPORT + imports RVM-COMPILER-CORE + imports C-MONITOR-TEMPLATE-SYNTAX + + rule $incl => . ... + (.List => ListItem("#include \n" + +String "#include \n") ) + _:List + + +endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 0656e06..0fe858a 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -80,12 +80,18 @@ module RVM-COMPILER-CORE .K .K //additional computation cell + ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// .HandlerDecList .List + +///////////////////////////////Code Generation////////////////////////////////////////////////// + "c" //the default target language for the generated monitor code + .List + endmodule diff --git a/test/cmop/test.k b/test/cmop/test.k index 8e0dfc8..9e0dec4 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -1,13 +1,24 @@ require "../../src/c-monitor-code-template/c-monitor-template-syntax.k" + module TEST imports C-MONITOR-TEMPLATE-SYNTAX configuration $PGM:Int false + .List + rule false => true _:K => $CMonitor 2 3 + +rule ($incl $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit #reset:ResetFunc + ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) => + ($globalInit ($localInit(NumOfStates)) #reset + ($stateFuncs(NumOfStates)) ($eventFuncs(NumOfEvents))) + (.List => ListItem("#include \n" + +String "#include \n") ) + L:List endmodule \ No newline at end of file From ce9d90160b272dc52c93852a63968610699ef7ec Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 10:30:10 -0500 Subject: [PATCH 062/160] partial rewrite of ok --- .../c-monitor-template-syntax.k | 4 ++-- test/cmop/test.k | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 6c220e8..7dd6c86 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -14,7 +14,7 @@ syntax LocalStatesInit ::= List{StateVar, ","} syntax StateVar ::= "$sVar" "(" Int ")" -syntax ResetFunc ::= "#reset" +syntax ResetFunc ::= "$reset" syntax StateTransitions ::= "$stateFuncs" "(" Int ")" syntax StateTransitions ::= List{StateFunc, ","} @@ -25,7 +25,7 @@ syntax EventActions ::= List{EventFunc, ","} syntax EventFunc ::= "eFunc" "(" Int ")" rule $CMonitor NumOfEvents:Int NumOfStates:Int => - $incl $globalInit ($localInit(NumOfStates)) #reset + $incl $globalInit ($localInit(NumOfStates)) $reset ($stateFuncs(NumOfStates)) $eventFuncs(NumOfEvents) diff --git a/test/cmop/test.k b/test/cmop/test.k index 9e0dec4..287d3bd 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -7,18 +7,27 @@ configuration $PGM:Int false .List - + .K rule false => true _:K => $CMonitor 2 3 -rule ($incl $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit #reset:ResetFunc - ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) => - ($globalInit ($localInit(NumOfStates)) #reset - ($stateFuncs(NumOfStates)) ($eventFuncs(NumOfEvents))) +rule ( ($incl => .) $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit +$reset:ResetFunc + ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) (.List => ListItem("#include \n" +String "#include \n") ) L:List + + _:K => $incl +//rule ($incl $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit +//$reset:ResetFunc +// ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) => +// ($globalInit ($localInit(NumOfStates)) $reset +// ($stateFuncs(NumOfStates)) ($eventFuncs(NumOfEvents))) +// (.List => ListItem("#include \n" +// +String "#include \n") ) +// L:List endmodule \ No newline at end of file From 6fe31cf1e5d3c0aa773ddaddcc366691ee368674 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 10:50:03 -0500 Subject: [PATCH 063/160] global init --- src/c-monitor-code-template/template.c.origin | 3 +-- test/cmop/test.k | 15 +++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/c-monitor-code-template/template.c.origin b/src/c-monitor-code-template/template.c.origin index 6b1ef77..b42e3ff 100644 --- a/src/c-monitor-code-template/template.c.origin +++ b/src/c-monitor-code-template/template.c.origin @@ -1,7 +1,6 @@ #include - - #include + static int __RVC_state = 0; diff --git a/test/cmop/test.k b/test/cmop/test.k index 287d3bd..2451ebf 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -7,7 +7,6 @@ configuration $PGM:Int false .List - .K rule false => true @@ -21,13 +20,9 @@ $reset:ResetFunc +String "#include \n") ) L:List - _:K => $incl -//rule ($incl $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit -//$reset:ResetFunc -// ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) => -// ($globalInit ($localInit(NumOfStates)) $reset -// ($stateFuncs(NumOfStates)) ($eventFuncs(NumOfEvents))) -// (.List => ListItem("#include \n" -// +String "#include \n") ) -// L:List +rule . ($globalInit:GlobalStateInit => .) ($localInit(NumOfStates)):LocalStatesInit + $reset:ResetFunc + ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions + + (.List => ListItem("static int __RVC_state = 0;\n")) L:List endmodule \ No newline at end of file From 065d0c806b3f945098ba925d2ac5c24bb5f2f5f5 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 11:16:59 -0500 Subject: [PATCH 064/160] make monitor syntax simpler --- .../c-monitor-template-syntax.k | 11 +++++++---- test/cmop/test.k | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 7dd6c86..edbe2a7 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -1,13 +1,16 @@ module C-MONITOR-TEMPLATE-SYNTAX //the state transition function is encoded using int array. -syntax CTemplate ::= Include StateVarsInit ResetFunc StateTransitions EventActions +syntax CTemplate ::= Include MainBody + +syntax MainBody ::= GlobalVarDecls MainBody1 + +syntax MainBody1 ::= LocalStatesInit ResetFunc StateTransitions EventActions syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and states resp. syntax Include ::= "$incl" -syntax StateVarsInit ::= GlobalStateInit LocalStatesInit -syntax GlobalStateInit ::= "$globalInit" +syntax GlobalVarDecls ::= "$globalInit" syntax LocalStatesInit ::= "$localInit" "(" Int ")" syntax LocalStatesInit ::= List{StateVar, ","} @@ -27,6 +30,6 @@ syntax EventFunc ::= "eFunc" "(" Int ")" rule $CMonitor NumOfEvents:Int NumOfStates:Int => $incl $globalInit ($localInit(NumOfStates)) $reset ($stateFuncs(NumOfStates)) $eventFuncs(NumOfEvents) - + when NumOfEvents >Int 0 andBool NumOfStates >Int 0 endmodule \ No newline at end of file diff --git a/test/cmop/test.k b/test/cmop/test.k index 2451ebf..6c130a3 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -12,17 +12,20 @@ configuration rule false => true _:K => $CMonitor 2 3 - -rule ( ($incl => .) $globalInit:GlobalStateInit ($localInit(NumOfStates)):LocalStatesInit -$reset:ResetFunc - ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions) - (.List => ListItem("#include \n" +rule $incl M:MainBody => M + (.List => ListItem("#include \n" +String "#include \n") ) L:List -rule . ($globalInit:GlobalStateInit => .) ($localInit(NumOfStates)):LocalStatesInit - $reset:ResetFunc - ($stateFuncs(NumOfStates)):StateTransitions ($eventFuncs(NumOfEvents)):EventActions +//rewrite the global var declarations. +rule G:GlobalVarDecls M:MainBody1 => M (.List => ListItem("static int __RVC_state = 0;\n")) L:List + + +//rule ($localInit(1) => $sVar(0)) +// +//rule $localInit(I:Int) => $sVar(I -Int 1), $localInit(I -Int 1) +//when I >Int 1 + endmodule \ No newline at end of file From 45f07caf37acddc1b48b6fad2c2fb72bd7b4d236 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 11:38:56 -0500 Subject: [PATCH 065/160] add rules of handling include stmts, global decl stmts to c-monitor-template.k --- .../c-monitor-template-syntax.k | 8 +++---- .../c-monitor-template.k | 22 +++++++++++++++++++ src/c-monitor-code-template/import.k | 14 ------------ test/cmop/test.k | 13 +++++++---- 4 files changed, 35 insertions(+), 22 deletions(-) delete mode 100644 src/c-monitor-code-template/import.k diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index edbe2a7..74f1eb8 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -5,17 +5,17 @@ syntax CTemplate ::= Include MainBody syntax MainBody ::= GlobalVarDecls MainBody1 -syntax MainBody1 ::= LocalStatesInit ResetFunc StateTransitions EventActions +syntax MainBody1 ::= LocalStatesInit MainBody2 +syntax MainBody2 ::= ResetFunc StateTransitions EventActions syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and states resp. syntax Include ::= "$incl" syntax GlobalVarDecls ::= "$globalInit" -syntax LocalStatesInit ::= "$localInit" "(" Int ")" -syntax LocalStatesInit ::= List{StateVar, ","} syntax StateVar ::= "$sVar" "(" Int ")" - +syntax LocalStatesInit ::= "$localInit" "(" Int ")" +syntax LocalStatesInit ::= StateVar "," LocalStatesInit syntax ResetFunc ::= "$reset" diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index f88a2b0..c593582 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -8,5 +8,27 @@ module C-MONITOR-TEMPLATE imports IMPORT +rule false => true + _:K => $CMonitor 2 3 +//generate the include part. +//TODO: incorporate the user provided includes +rule $incl M:MainBody => M + (.List => ListItem("#include \n" + +String "#include \n") ) + L:List + +//rewrite the global var declarations. +rule G:GlobalVarDecls M:MainBody1 => M + + (.List => ListItem("static int __RVC_state = 0;\n")) L:List + + +rule ($localInit(1) M:MainBody2) => + (($sVar(0)) M) + +rule ($localInit(I:Int) M:MainBody2) => + (($sVar(I -Int 1), $localInit(I -Int 1)) M) + +when I >Int 1 endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/import.k b/src/c-monitor-code-template/import.k deleted file mode 100644 index db59a52..0000000 --- a/src/c-monitor-code-template/import.k +++ /dev/null @@ -1,14 +0,0 @@ -require "../rvm/rvm-compiler-core.k" -require "c-monitor-template-syntax.k" - -module IMPORT - imports RVM-COMPILER-CORE - imports C-MONITOR-TEMPLATE-SYNTAX - - rule $incl => . ... - (.List => ListItem("#include \n" - +String "#include \n") ) - _:List - - -endmodule \ No newline at end of file diff --git a/test/cmop/test.k b/test/cmop/test.k index 6c130a3..8c048a2 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -12,6 +12,8 @@ configuration rule false => true _:K => $CMonitor 2 3 +//generate the include part. +//TODO: incorporate the user provided includes rule $incl M:MainBody => M (.List => ListItem("#include \n" +String "#include \n") ) @@ -23,9 +25,12 @@ rule G:GlobalVarDecls M:MainBody1 => M (.List => ListItem("static int __RVC_state = 0;\n")) L:List -//rule ($localInit(1) => $sVar(0)) -// -//rule $localInit(I:Int) => $sVar(I -Int 1), $localInit(I -Int 1) -//when I >Int 1 +rule ($localInit(1) M:MainBody2) => + (($sVar(0)) M) + +rule ($localInit(I:Int) M:MainBody2) => + (($sVar(I -Int 1), $localInit(I -Int 1)) M) + +when I >Int 1 endmodule \ No newline at end of file From b7c3e3942a2448485ea5c28441f9890c670774a7 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 11:54:34 -0500 Subject: [PATCH 066/160] update --- src/c-monitor-code-template/c-monitor-template.k | 7 ++++++- .../{template.c.origin => seatbelt.c.origin} | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) rename src/c-monitor-code-template/{template.c.origin => seatbelt.c.origin} (100%) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index c593582..e123a47 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -23,7 +23,7 @@ rule G:GlobalVarDecls M:MainBody1 => M (.List => ListItem("static int __RVC_state = 0;\n")) L:List - +//handling the local state vars initializations. rule ($localInit(1) M:MainBody2) => (($sVar(0)) M) @@ -31,4 +31,9 @@ rule ($localInit(I:Int) M:MainBody2) => (($sVar(I -Int 1), $localInit(I -Int 1)) M) when I >Int 1 + +rule ($sVar()) + + .Map + endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/template.c.origin b/src/c-monitor-code-template/seatbelt.c.origin similarity index 100% rename from src/c-monitor-code-template/template.c.origin rename to src/c-monitor-code-template/seatbelt.c.origin index b42e3ff..d8700e9 100644 --- a/src/c-monitor-code-template/template.c.origin +++ b/src/c-monitor-code-template/seatbelt.c.origin @@ -2,7 +2,8 @@ #include static int __RVC_state = 0; - +static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; +static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; int __RVC_SeatBelt_safe = 0; @@ -14,8 +15,7 @@ __RVC_SeatBelt_reset(void) __RVC_state = 0; } -static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; -static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; + void __RVC_SeatBelt_seatBeltRemoved() From 694fda7cf2cf5edda026a9f715e7dd381068ad83 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 12:11:13 -0500 Subject: [PATCH 067/160] debug --- src/c-monitor-code-template/c-monitor-template.k | 10 ++++------ src/rvm/rvm-compiler-core.k | 2 +- test/cmop/test.k | 14 +++++++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index e123a47..27e82b4 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -1,12 +1,9 @@ require "../rvm/rvm-compiler-core.k" require "c-monitor-template-syntax.k" -require "import.k" module C-MONITOR-TEMPLATE imports RVM-COMPILER-CORE imports C-MONITOR-TEMPLATE-SYNTAX - imports IMPORT - rule false => true _:K => $CMonitor 2 3 @@ -32,8 +29,9 @@ rule ($localInit(I:Int) M:MainBody2) => when I >Int 1 -rule ($sVar()) - - .Map +rule ($sVar(I:Int), $localInit(J:Int)) M:MainBody2 => + ($localInit(J:Int)) M + ... SN:String |-> I ... + L:List (.List => ListItem(SN)) endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 0fe858a..17b3124 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -56,7 +56,7 @@ module RVM-COMPILER-CORE false - .Map //map a state to its number + .Map //map a state name(string) to its rank 0 //the raw transition defined in the rvm spec, indexed by states diff --git a/test/cmop/test.k b/test/cmop/test.k index 8c048a2..799a748 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -7,10 +7,13 @@ configuration $PGM:Int false .List + .Map rule false => true _:K => $CMonitor 2 3 + .Map => (("Safe" |-> 0) ("Unsafe" |-> 1) + ("good" |-> 2) ("bad" |-> 3)) //generate the include part. //TODO: incorporate the user provided includes @@ -25,12 +28,17 @@ rule G:GlobalVarDecls M:MainBody1 => M (.List => ListItem("static int __RVC_state = 0;\n")) L:List -rule ($localInit(1) M:MainBody2) => - (($sVar(0)) M) +rule ($localInit(0) M:MainBody2) => + M rule ($localInit(I:Int) M:MainBody2) => (($sVar(I -Int 1), $localInit(I -Int 1)) M) -when I >Int 1 +when I >=Int 1 +rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => + (($localInit(J:Int)) M) + + ... (SN:String |-> I) ... + L:List (.List => ListItem(SN)) endmodule \ No newline at end of file From f645cb9f1c8d56c86ee4343bb21501c65601c4c9 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 16:21:15 -0500 Subject: [PATCH 068/160] generate local state vars initialization and reset function --- .../c-monitor-template-syntax.k | 3 ++- .../c-monitor-template.k | 20 +++++++++------ src/helper/print-ast.k | 8 +++++- src/helper/util.k | 10 ++++++++ src/rvm/rvm-compiler-core.k | 1 + src/rvm/rvm-compiler.k | 3 +++ test/cmop/test.k | 25 +++++++++++++++---- 7 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 74f1eb8..90e725f 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -6,7 +6,8 @@ syntax CTemplate ::= Include MainBody syntax MainBody ::= GlobalVarDecls MainBody1 syntax MainBody1 ::= LocalStatesInit MainBody2 -syntax MainBody2 ::= ResetFunc StateTransitions EventActions +syntax MainBody2 ::= ResetFunc MainBody3 +syntax MainBody3 ::= StateTransitions EventActions syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and states resp. diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 27e82b4..73ca95b 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -21,17 +21,23 @@ rule G:GlobalVarDecls M:MainBody1 => M (.List => ListItem("static int __RVC_state = 0;\n")) L:List //handling the local state vars initializations. -rule ($localInit(1) M:MainBody2) => - (($sVar(0)) M) +rule ($localInit(0) M:MainBody2) => M + L:List => .List //the local state vars are stored in tmp cell + C:List (.List => L) rule ($localInit(I:Int) M:MainBody2) => (($sVar(I -Int 1), $localInit(I -Int 1)) M) -when I >Int 1 +when I >=Int 1 -rule ($sVar(I:Int), $localInit(J:Int)) M:MainBody2 => - ($localInit(J:Int)) M +rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => + (($localInit(J:Int)) M) + + StateMap:Map + (.List => ListItem(getStrKey(StateMap, I))) L:List + +rule $reset M:MainBody3 => M + SN:String + Code:List (.List => ListItem(printResetFunc(SN))) - ... SN:String |-> I ... - L:List (.List => ListItem(SN)) endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 940a27a..ef5a25d 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -39,7 +39,13 @@ module PRINT-AST rule getStateName(SN:StateName[TL:TransitionList]) => printStateName(SN) rule printStateName(SN:Id) => Id2String(SN) - rule getTransitionList(SN:StateName[TL:TransitionList]) => TL + +/*Return the string of reset function, given the name of the specification*/ +syntax String ::= printResetFunc(String) [function] + +rule printResetFunc(SpecName:String) => "void __RVC_" +String SpecName +String "_reset(void)\n" ++String "{\n__RVC_state = 0;\n}" + endmodule \ No newline at end of file diff --git a/src/helper/util.k b/src/helper/util.k index f0576b8..20cb072 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -21,6 +21,16 @@ rule toIntArray(M:Map, I:Int, Siz:Int) => rule toIntArray(M:Map, I:Int, Siz:Int) => ListItem(Siz) toIntArray(M, I +Int 1, Siz) when I V:Int) M:Map, V) => S + +rule getStrKey((_:String |-> V1:Int) M:Map, V2:Int) => getStrKey(M, V2) +when V1 =/=Int V2 + endmodule diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 17b3124..c2bd248 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -91,6 +91,7 @@ module RVM-COMPILER-CORE ///////////////////////////////Code Generation////////////////////////////////////////////////// "c" //the default target language for the generated monitor code .List + .List //temporary cell for manipulation. diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index a2fa965..71bbba3 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -5,10 +5,13 @@ require "../helper/print-ast.k" require "../logic/semantics/fsm.k" +require "../../src/helper/util.k" + module RVM-COMPILER imports RVM-SYNTAX imports RVM-COMPILER-CORE imports PRINT-AST + imports UTIL imports FSM diff --git a/test/cmop/test.k b/test/cmop/test.k index 799a748..9a775db 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -1,13 +1,22 @@ require "../../src/c-monitor-code-template/c-monitor-template-syntax.k" +require "../../src/helper/util.k" +require "../../src/helper/print-ast.k" + module TEST imports C-MONITOR-TEMPLATE-SYNTAX +imports UTIL +imports PRINT-AST configuration $PGM:Int false .List .Map + .List //temporary cell for manipulation. + + "HasNext" + rule false => true @@ -18,14 +27,14 @@ rule false => true //generate the include part. //TODO: incorporate the user provided includes rule $incl M:MainBody => M - (.List => ListItem("#include \n" + L:List (.List => ListItem("#include \n" +String "#include \n") ) - L:List + //rewrite the global var declarations. rule G:GlobalVarDecls M:MainBody1 => M - (.List => ListItem("static int __RVC_state = 0;\n")) L:List + L:List (.List => ListItem("static int __RVC_state = 0;\n")) rule ($localInit(0) M:MainBody2) => @@ -39,6 +48,12 @@ when I >=Int 1 rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => (($localInit(J:Int)) M) - ... (SN:String |-> I) ... - L:List (.List => ListItem(SN)) + StateMap:Map + (.List => ListItem(getStrKey(StateMap, I))) L:List + +rule $reset M:MainBody3 => M + SN:String + L:List => .List //the local state vars are stored in tmp cell + Code:List (.List => L) (.List => ListItem(printResetFunc(SN))) + endmodule \ No newline at end of file From 6d5fbec95602db2db837f82640eed31939b808da Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 16:52:07 -0500 Subject: [PATCH 069/160] debug --- src/c-monitor-code-template/c-monitor-template.k | 9 +++++++-- src/logic/semantics/fsm.k | 2 ++ src/rvm/logic-plugins-shell.k | 7 +++++++ src/rvm/rvc.k | 11 +++++++++++ src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 9 +++------ 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/rvm/logic-plugins-shell.k create mode 100644 src/rvm/rvc.k diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 73ca95b..527fb76 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -5,8 +5,13 @@ module C-MONITOR-TEMPLATE imports RVM-COMPILER-CORE imports C-MONITOR-TEMPLATE-SYNTAX -rule false => true - _:K => $CMonitor 2 3 +rule + "c" + true + EN:Int + SN:Int +//the number SN is the index of the last state, so the number of states is SN plus one. + _:K => $CMonitor EN (SN +Int 1) //the two arguments are num of events and states resp. //generate the include part. //TODO: incorporate the user provided includes diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index e59818a..60531dc 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -113,5 +113,7 @@ rule fsm .List => toIntArray(SM, size(AllStatesMap)) 1 + true => false + endmodule \ No newline at end of file diff --git a/src/rvm/logic-plugins-shell.k b/src/rvm/logic-plugins-shell.k new file mode 100644 index 0000000..7995140 --- /dev/null +++ b/src/rvm/logic-plugins-shell.k @@ -0,0 +1,7 @@ +require "../logic/semantics/fsm.k" + +module LOGIC-PLUGINS-SHELL + imports FSM + + +endmodule \ No newline at end of file diff --git a/src/rvm/rvc.k b/src/rvm/rvc.k new file mode 100644 index 0000000..26aa0f3 --- /dev/null +++ b/src/rvm/rvc.k @@ -0,0 +1,11 @@ +require "rvm-compiler.k" +require "logic-plugins-shell.k" +require "../c-monitor-code-template/c-monitor-template.k" + +module RVC + imports RVM-COMPILER + imports LOGIC-PLUGINS-SHELL + + imports C-MONITOR-TEMPLATE + +endmodule diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index c2bd248..7ab1417 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -92,7 +92,7 @@ module RVM-COMPILER-CORE "c" //the default target language for the generated monitor code .List .List //temporary cell for manipulation. - + false endmodule diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 71bbba3..b984ab9 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -2,9 +2,6 @@ require "rvm-syntax.k" require "domains.k" require "rvm-compiler-core.k" require "../helper/print-ast.k" - -require "../logic/semantics/fsm.k" - require "../../src/helper/util.k" module RVM-COMPILER @@ -13,8 +10,6 @@ module RVM-COMPILER imports PRINT-AST imports UTIL - imports FSM - syntax KResult ::= "error" /** @@ -87,6 +82,8 @@ rule Prop:PropertyDec Props:PropertyDecList => Props false => true //No properties left -//rule .PropertyDecList +rule .PropertyDecList => . + false + false => true endmodule From 5b66d86a4db84d02794044fc622a432153988b2f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 17:53:12 -0500 Subject: [PATCH 070/160] debug --- src/c-monitor-code-template/c-monitor-template.k | 4 +++- src/logic/semantics/fsm.k | 13 +++++++++++-- src/rvm/rvc.k | 13 +++++++++++-- src/rvm/rvm-compiler-core.k | 1 + src/rvm/rvm-compiler.k | 7 +++++++ 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 527fb76..2c245cb 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -7,7 +7,9 @@ module C-MONITOR-TEMPLATE rule "c" - true + false + + true => false EN:Int SN:Int //the number SN is the index of the last state, so the number of states is SN plus one. diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 60531dc..931c6a8 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -107,13 +107,22 @@ rule fsm AllStatesMap:Map .ItemList .AliasList .K + + N:Int => N +Int 1 + ... SM:Map .List => toIntArray(SM, size(AllStatesMap)) 1 - true => false - + true + +/*All the event transition functions have been generated, +stop the plugin*/ +rule N:Int + E:Int + true => false +when N ==Int E endmodule \ No newline at end of file diff --git a/src/rvm/rvc.k b/src/rvm/rvc.k index 26aa0f3..1c07738 100644 --- a/src/rvm/rvc.k +++ b/src/rvm/rvc.k @@ -2,10 +2,19 @@ require "rvm-compiler.k" require "logic-plugins-shell.k" require "../c-monitor-code-template/c-monitor-template.k" +module RVC-SYNTAX + imports RVM-SYNTAX + +endmodule + module RVC - imports RVM-COMPILER - imports LOGIC-PLUGINS-SHELL + imports RVC-SYNTAX + + imports RVM-COMPILER-CORE + imports PRINT-AST + imports UTIL + imports LOGIC-PLUGINS-SHELL imports C-MONITOR-TEMPLATE endmodule diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 7ab1417..171a0c4 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -64,6 +64,7 @@ module RVM-COMPILER-CORE //the state transformation function, indexed by events + 0 .K .Map diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index b984ab9..e600225 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -4,12 +4,19 @@ require "rvm-compiler-core.k" require "../helper/print-ast.k" require "../../src/helper/util.k" +//// +require "logic-plugins-shell.k" +require "../c-monitor-code-template/c-monitor-template.k" + module RVM-COMPILER imports RVM-SYNTAX imports RVM-COMPILER-CORE imports PRINT-AST imports UTIL + imports LOGIC-PLUGINS-SHELL + imports C-MONITOR-TEMPLATE + syntax KResult ::= "error" /** From caede607e0526a7b1834a478d4a444b03258881c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 22:31:33 -0500 Subject: [PATCH 071/160] debug ok --- src/rvm/rvm-compiler-core.k | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 171a0c4..fda2275 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -62,9 +62,10 @@ module RVM-COMPILER-CORE //the raw transition defined in the rvm spec, indexed by states .K + 0 + //the state transformation function, indexed by events - 0 .K .Map From af4c376308435d05a4903c0bc0f55288eb01a7ad Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 12 Apr 2016 22:48:05 -0500 Subject: [PATCH 072/160] revise config structure to allow multiple properties --- src/logic/semantics/fsm.k | 4 ++-- src/rvm/rvm-compiler-core.k | 15 ++++++++++----- src/rvm/rvm-compiler.k | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 931c6a8..32003da 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -81,7 +81,7 @@ rule fsm (E:EventName -> SN:StateName) TL:TransitionList => TL S1:Int SM:Map (printStateName(SN):String |-> S2:Int):Map - + ... @@ -91,7 +91,7 @@ rule fsm ... - + 1 diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index fda2275..048121d 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -65,13 +65,18 @@ module RVM-COMPILER-CORE 0 //the state transformation function, indexed by events - + - .K - .Map - .List + "" + + + -1 + .Map + .List + + - + //we may need to traverse formula to get state numbers //in the first scan, use this tmp cell for saving state transitions diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index e600225..94cfa7e 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -52,14 +52,14 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} (.Set => SetItem(X)) Cur:Set - + ... (.Bag => X ... ) - + I:Int => I +Int 1 when notBool (X in Cur) From e40114e94c1d5bf1a3ec2b96b026c5f354d6afdd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 07:09:54 -0500 Subject: [PATCH 073/160] remove event number cell --- ToDo.txt | 9 +++++++++ src/c-monitor-code-template/c-monitor-template.k | 4 ++-- src/logic/semantics/fsm.k | 4 ++-- src/rvm/rvm-compiler-core.k | 3 +-- src/rvm/rvm-compiler.k | 3 +-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ToDo.txt b/ToDo.txt index d129b4a..50ed25a 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -9,3 +9,12 @@ Each row of the matrix encodes an event transition function, and the row number 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. \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 2c245cb..af783b6 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -10,10 +10,10 @@ rule false true => false - EN:Int + EL:List SN:Int //the number SN is the index of the last state, so the number of states is SN plus one. - _:K => $CMonitor EN (SN +Int 1) //the two arguments are num of events and states resp. + _:K => $CMonitor size(EL) (SN +Int 1) //the two arguments are num of events and states resp. //generate the include part. //TODO: incorporate the user provided includes diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 32003da..0b71101 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -121,8 +121,8 @@ rule fsm /*All the event transition functions have been generated, stop the plugin*/ rule N:Int - E:Int + EL:List true => false -when N ==Int E +when N ==Int endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 048121d..cc2a65d 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -40,8 +40,7 @@ module RVM-COMPILER-CORE .K - .Set //map an event to its number - 0 + .List //map an event to its number "" .Params diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 94cfa7e..f858959 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -50,7 +50,7 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - (.Set => SetItem(X)) Cur:Set + L:List (.List => ListItem(Id2String(X))) ... @@ -61,7 +61,6 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) ) - I:Int => I +Int 1 when notBool (X in Cur) /** From c49bd7e0a93cfda92c107f1ed12297c8c5df9dac Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 07:25:15 -0500 Subject: [PATCH 074/160] make it compile --- src/logic/semantics/fsm.k | 6 +++--- src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 0b71101..743e902 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -61,11 +61,11 @@ rule fsm rule fsm (E:EventName -> SN:StateName) TL:TransitionList - Es:Set + EL:List 1 (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List true => false - when notBool E in Es + when notBool E in EL /*Handle unknown state*/ rule @@ -123,6 +123,6 @@ stop the plugin*/ rule N:Int EL:List true => false -when N ==Int +when N ==Int size(EL) endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index cc2a65d..6f06749 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -66,7 +66,7 @@ module RVM-COMPILER-CORE //the state transformation function, indexed by events - "" + .K -1 diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index f858959..b745225 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -50,7 +50,7 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - L:List (.List => ListItem(Id2String(X))) + L:List (.List => ListItem(X)) ... @@ -61,7 +61,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) ) -when notBool (X in Cur) +when notBool (X in L) /** * Report error if an event is defined multiple times. @@ -70,9 +70,9 @@ when notBool (X in Cur) */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList) Props:PropertyDecList} => .K - Cur:Set + EL:List (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List -when (X in Cur) +when (X in EL) //No events left rule From 3d88fae6ac675d76fa00f50a222a14bb3ae54f05 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 08:29:28 -0500 Subject: [PATCH 075/160] debug --- .../c-monitor-template.k | 6 +-- src/logic/semantics/fsm.k | 53 ++++++++++++++++--- src/rvm/rvm-compiler-core.k | 4 +- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index af783b6..834bebe 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -11,9 +11,9 @@ rule true => false EL:List - SN:Int -//the number SN is the index of the last state, so the number of states is SN plus one. - _:K => $CMonitor size(EL) (SN +Int 1) //the two arguments are num of events and states resp. + SM:Map +//this rule currently only handle the single property spec... + _:K => $CMonitor size(EL) size(SM) //the two arguments are num of events and states resp. //generate the include part. //TODO: incorporate the user provided includes diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 743e902..18d3d47 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -13,8 +13,7 @@ module FSM rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) true - CurMap:Map => CurMap[getStateName(IT) <- I] - I:Int => I +Int 1 + CurMap:Map => CurMap[getStateName(IT) <- size(CurMap)] 0 // if do not need this constraint, then comment the condition below as well as the next rule. @@ -39,7 +38,7 @@ rule .ItemList AL:AliasList => FC FC:K true - _:Int => -1 + _:Int => -1 0 => 1 /*2nd scan: get the raw transition mapping associated with the current state @@ -52,7 +51,7 @@ The raw transitions associated with state s0 is: e1 -> s1, e2 -> s2. */ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) - I:Int => I +Int 1 + I:Int => I +Int 1 .K => getTransitionList(IT) 1 @@ -77,24 +76,64 @@ rule true => false when notBool (printStateName(SN) in keys(SM)) +//////////////////////////////////////////////////////////////////// +/*Update the event transition function for event E and property P.*/ rule fsm + P:Int + (E:EventName -> SN:StateName) TL:TransitionList => TL - S1:Int + S1:Int SM:Map (printStateName(SN):String |-> S2:Int):Map ... E - (.Map => S1 |-> S2) M:Map + + ... + + + P + (.Map => (S1 |-> S2):Map) M:Map + ... + + ... + ... - 1 + 1 [prefer] +/*The first time that event E is involved in the property P*/ +rule fsm + P:Int + (E:EventName -> SN:StateName) TL:TransitionList => TL + S1:Int + SM:Map (printStateName(SN):String |-> S2:Int):Map + + ... + + + E + + ... + (.Bag => + + P + (.Map => (S1 |-> S2):Map) M:Map + ... + ) + + + + + ... + + 1 [avoid] +////////////////////////////////////////////////////////////////////////// rule fsm diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 6f06749..8996d5b 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -46,7 +46,7 @@ module RVM-COMPILER-CORE .Params .K - 0 + -1 /////////////////////////////Logic Plugin cells starts//////////////////////////////////////////// @@ -56,7 +56,7 @@ module RVM-COMPILER-CORE false .Map //map a state name(string) to its rank - 0 + 0 //the raw transition defined in the rvm spec, indexed by states .K From 251a867f4a1b472a77ad74b448e59b523b5015e0 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 08:47:46 -0500 Subject: [PATCH 076/160] debug --- src/logic/semantics/fsm.k | 134 +++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 18d3d47..a1c79a9 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -78,61 +78,61 @@ rule //////////////////////////////////////////////////////////////////// /*Update the event transition function for event E and property P.*/ -rule fsm - P:Int - - (E:EventName -> SN:StateName) TL:TransitionList => TL - S1:Int - SM:Map (printStateName(SN):String |-> S2:Int):Map - - ... - - - E - - ... - - - P - (.Map => (S1 |-> S2):Map) M:Map - ... - - - ... - - - - ... - - 1 [prefer] +//rule fsm +// P:Int +// +// (E:EventName -> SN:StateName) TL:TransitionList => TL +// S1:Int +// SM:Map (printStateName(SN):String |-> S2:Int):Map +// +// ... +// +// +// E +// +// ... +// +// +// P +// (.Map => (S1 |-> S2):Map) M:Map +// ... +// +// +// ... +// +// +// +// ... +// +// 1 [prefer] /*The first time that event E is involved in the property P*/ -rule fsm - P:Int - - (E:EventName -> SN:StateName) TL:TransitionList => TL - S1:Int - SM:Map (printStateName(SN):String |-> S2:Int):Map - - ... - - - E - - ... - (.Bag => - - P - (.Map => (S1 |-> S2):Map) M:Map - ... - ) - - - - - ... - - 1 [avoid] +//rule fsm +// P:Int +// +// (E:EventName -> SN:StateName) TL:TransitionList => TL +// S1:Int +// SM:Map (printStateName(SN):String |-> S2:Int):Map +// +// ... +// +// +// E +// +// ... +// (.Bag => +// +// P +// (.Map => (S1 |-> S2):Map) M:Map +// ... +// ) +// +// +// +// +// ... +// +// 1 [avoid] ////////////////////////////////////////////////////////////////////////// rule @@ -142,20 +142,20 @@ rule /*when all the computation related to the formula completes, translate the transition function from map to int array*/ -rule fsm - AllStatesMap:Map - .ItemList .AliasList - .K - - N:Int => N +Int 1 - - - ... - SM:Map - .List => toIntArray(SM, size(AllStatesMap)) - - 1 - true +//rule fsm +// AllStatesMap:Map +// .ItemList .AliasList +// .K +// +// N:Int => N +Int 1 +// +// +// ... +// SM:Map +// .List => toIntArray(SM, size(AllStatesMap)) +// +// 1 +// true /*All the event transition functions have been generated, stop the plugin*/ From 74ca63aefae8c6610cc434e2a84ee945aa50fb63 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 21:22:17 -0500 Subject: [PATCH 077/160] add function to get size of properties --- src/helper/print-ast.k | 5 +++++ src/rvm/rvm-compiler-core.k | 3 ++- src/rvm/rvm-compiler.k | 1 + test/rvm/Test4.rvm | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index ef5a25d..4386b10 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -48,4 +48,9 @@ syntax String ::= printResetFunc(String) [function] rule printResetFunc(SpecName:String) => "void __RVC_" +String SpecName +String "_reset(void)\n" +String "{\n__RVC_state = 0;\n}" +syntax Int ::= sizeOf(PropertyDecList) [function] +rule sizeOf(.PropertyDecList) => 0 +rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) + + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 8996d5b..ae4de6e 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -46,7 +46,8 @@ module RVM-COMPILER-CORE .Params .K - -1 + -1 //the property rank + 0 //the number of properties /////////////////////////////Logic Plugin cells starts//////////////////////////////////////////// diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index b745225..3635fd9 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -77,6 +77,7 @@ when (X in EL) //No events left rule {.K (.EventDecList) Props:PropertyDecList} => Props + I:Int => sizeOf(Props) //add the first property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index 9042446..640b606 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -14,12 +14,42 @@ Test (int o){ int i; } - fsm: + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] - @match { + @start { int j; } + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + @unsafe { + int k; + } + } From 1f8acf3216939545cf894286f03c60d198c92a40 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 22:07:27 -0500 Subject: [PATCH 078/160] save work --- src/logic/semantics/fsm.k | 2 ++ src/rvm/rvm-compiler.k | 49 +++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index a1c79a9..c976ab5 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -53,6 +53,7 @@ rule fsm IT:Item IL:ItemList AL:AliasList => (IL AL) I:Int => I +Int 1 .K => getTransitionList(IT) + true 1 /**consume the transition functions defined for the current state.*/ @@ -138,6 +139,7 @@ rule rule fsm .TransitionList => .K + true 1 /*when all the computation related to the formula completes, diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 3635fd9..0799437 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -39,9 +39,8 @@ rule X:Id (Ps:Params) SB:SpecBody => SB rule {(Decls:DecBubbleList => .K) Events:EventDecList Props:PropertyDecList} .K => Decls + I:Int => sizeOf(Props) -//rule {(Decl:DecBubble Decls:DecBubbleList => Decls) Events:EventDecList -//Props:PropertyDecList} @@ -55,14 +54,51 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) ... - (.Bag => - X - ... - ) + (.Bag => + + X + + + -1 + .Map + .List + + + + ) + PS:Int + .K => PS -Int 1 when notBool (X in L) + +//construct cells +rule + ... + + + + X + + ... + (.Bag => + -1 + .Map + .List + ) + + + + ... + + PS:Int => PS -Int 1 +when PS >Int 0 + +rule 0 => PS + PS:Int => .K +when PS >Int 0 + /** * Report error if an event is defined multiple times. * In case of error, the execution will be terminated and the error info @@ -77,7 +113,6 @@ when (X in EL) //No events left rule {.K (.EventDecList) Props:PropertyDecList} => Props - I:Int => sizeOf(Props) //add the first property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props From 424494d0c0de9949a9d725122b772fcf7d5bd532 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 22:27:21 -0500 Subject: [PATCH 079/160] gen initial props cells --- src/rvm/rvm-compiler.k | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 0799437..4590ddb 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -73,7 +73,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) when notBool (X in L) -//construct cells +//construct initial props cells rule ... @@ -95,9 +95,7 @@ rule PS:Int => PS -Int 1 when PS >Int 0 -rule 0 => PS - PS:Int => .K -when PS >Int 0 +rule 0 => .K /** * Report error if an event is defined multiple times. From 3ad1b23b4f37334dd2550d6af13bcfdf10cdb74c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 13 Apr 2016 22:48:53 -0500 Subject: [PATCH 080/160] props are ranked --- src/logic/semantics/fsm.k | 113 +++++++++++++++----------------------- src/rvm/rvm-compiler.k | 6 +- test/rvm/Test4.rvm | 8 +-- 3 files changed, 48 insertions(+), 79 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index c976ab5..55d558d 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -79,62 +79,35 @@ rule //////////////////////////////////////////////////////////////////// /*Update the event transition function for event E and property P.*/ -//rule fsm -// P:Int -// -// (E:EventName -> SN:StateName) TL:TransitionList => TL -// S1:Int -// SM:Map (printStateName(SN):String |-> S2:Int):Map -// -// ... -// -// -// E -// -// ... -// -// -// P -// (.Map => (S1 |-> S2):Map) M:Map -// ... -// -// -// ... -// -// -// -// ... -// -// 1 [prefer] - -/*The first time that event E is involved in the property P*/ -//rule fsm -// P:Int -// -// (E:EventName -> SN:StateName) TL:TransitionList => TL -// S1:Int -// SM:Map (printStateName(SN):String |-> S2:Int):Map -// -// ... -// -// -// E -// -// ... -// (.Bag => -// -// P -// (.Map => (S1 |-> S2):Map) M:Map -// ... -// ) -// -// -// -// -// ... -// -// 1 [avoid] -////////////////////////////////////////////////////////////////////////// +rule fsm + P:Int + + (E:EventName -> SN:StateName) TL:TransitionList => TL + S1:Int + SM:Map (printStateName(SN):String |-> S2:Int):Map + + ... + + + E + + ... + + + P + (.Map => (S1 |-> S2):Map) M:Map + ... + + + ... + + + + ... + + 1 [prefer] + +//////////////////////////////////////////////// rule fsm @@ -144,20 +117,20 @@ rule /*when all the computation related to the formula completes, translate the transition function from map to int array*/ -//rule fsm -// AllStatesMap:Map -// .ItemList .AliasList -// .K -// -// N:Int => N +Int 1 -// -// -// ... -// SM:Map -// .List => toIntArray(SM, size(AllStatesMap)) -// -// 1 -// true +rule fsm + AllStatesMap:Map + .ItemList .AliasList + .K + + N:Int => N +Int 1 + + + ... + SM:Map + .List => toIntArray(SM, size(AllStatesMap)) + + 1 + true /*All the event transition functions have been generated, stop the plugin*/ diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 4590ddb..ea5814f 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -59,7 +59,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) X - -1 + PS -Int 1 .Map .List @@ -81,12 +81,12 @@ rule X - ... (.Bag => - -1 + PS -Int 1 .Map .List ) + ... diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index 640b606..e667e08 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -7,12 +7,8 @@ Test (int o){ private int foo() { return 1; } } - event create(){ - int i; - } - event close(){ - int i; - } + event hasnext(Iterator i) {} // {1, 1, 1, 3} + event next(Iterator i) {} // {2, 0, 2, 3} fsm : start [ From 01f628df62561abb0508061469be12bb0626bcfe Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 14 Apr 2016 22:51:32 -0500 Subject: [PATCH 081/160] debug --- src/logic/semantics/fsm.k | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 55d558d..d4ee95a 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -65,7 +65,7 @@ rule 1 (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List true => false - when notBool E in EL + when notBool (E in EL) /*Handle unknown state*/ rule @@ -133,10 +133,13 @@ rule fsm true /*All the event transition functions have been generated, -stop the plugin*/ -rule N:Int +stop the processing of the current property*/ +rule N:Int => 0 EL:List true => false + _ => .Map + _ => 0 + _ => .K when N ==Int size(EL) endmodule \ No newline at end of file From 59340475bd0715cb93073193eaa403217add6296 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 14 Apr 2016 23:06:02 -0500 Subject: [PATCH 082/160] debug --- src/logic/semantics/fsm.k | 6 +++--- src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index d4ee95a..6e4532f 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -58,17 +58,17 @@ rule fsm /**consume the transition functions defined for the current state.*/ /*Handle unknown event*/ -rule +rule _ => .K fsm (E:EventName -> SN:StateName) TL:TransitionList EL:List 1 (.List => ListItem("Undefined event " +String getEventName(E))) ErrList:List true => false - when notBool (E in EL) + when notBool (getEventName(E) in EL) /*Handle unknown state*/ -rule +rule _ => .K fsm (E:EventName -> SN:StateName) TL:TransitionList SM:Map diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index ae4de6e..391aef5 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -40,7 +40,7 @@ module RVM-COMPILER-CORE .K - .List //map an event to its number + .List //list of event name strings "" .Params diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index ea5814f..c11181d 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -49,7 +49,7 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - L:List (.List => ListItem(X)) + L:List (.List => ListItem(Id2String(X))) ... @@ -70,7 +70,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) PS:Int .K => PS -Int 1 -when notBool (X in L) +when notBool (Id2String(X) in L) //construct initial props cells @@ -106,7 +106,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList) Props:PropertyDecList} => .K EL:List (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List -when (X in EL) +when (Id2String(X) in EL) //No events left rule From 8af99a05c66a5b0f3a4607e7f0e52884128c32c9 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 14 Apr 2016 23:37:05 -0500 Subject: [PATCH 083/160] enable the reset rule when a formula has just been processed --- src/logic/semantics/fsm.k | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 6e4532f..9a677ac 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -121,11 +121,13 @@ rule fsm AllStatesMap:Map .ItemList .AliasList .K + PN:Int N:Int => N +Int 1 ... + PN SM:Map .List => toIntArray(SM, size(AllStatesMap)) @@ -137,9 +139,9 @@ stop the processing of the current property*/ rule N:Int => 0 EL:List true => false - _ => .Map - _ => 0 - _ => .K + _:Map => .Map + _:Int => 0 + _:K => .K when N ==Int size(EL) endmodule \ No newline at end of file From 131d1cee51238b24f744cd71dd9469608973e6b6 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 14 Apr 2016 23:54:43 -0500 Subject: [PATCH 084/160] 2 properties in one spec: final config ok: two sets of transition functions computed correctly --- src/logic/semantics/fsm.k | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 9a677ac..9da278c 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -135,13 +135,19 @@ rule fsm true /*All the event transition functions have been generated, -stop the processing of the current property*/ +stop the processing of the current property, +reset the cells and wait for the processing of the next property*/ rule N:Int => 0 + _:K => .K EL:List true => false _:Map => .Map _:Int => 0 + _:K => .K _:K => .K + + //TODO: process the handlers cell + _:HandlerDecList => .HandlerDecList when N ==Int size(EL) endmodule \ No newline at end of file From 77141998c2253a50c783d8f70080965b07f6bc32 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 15 Apr 2016 00:40:55 -0500 Subject: [PATCH 085/160] save state maps for each property --- src/c-monitor-code-template/c-monitor-template.k | 3 +++ src/logic/semantics/fsm.k | 3 ++- src/rvm/rvm-compiler-core.k | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 834bebe..fd58e1b 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -11,6 +11,9 @@ rule true => false EL:List + + PN:Int + SM:Map //this rule currently only handle the single property spec... _:K => $CMonitor size(EL) size(SM) //the two arguments are num of events and states resp. diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 9da278c..fcd4e66 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -141,11 +141,12 @@ rule N:Int => 0 _:K => .K EL:List true => false - _:Map => .Map + SM:Map => .Map _:Int => 0 _:K => .K _:K => .K + SL:List (.List => ListItem(SM)) //TODO: process the handlers cell _:HandlerDecList => .HandlerDecList when N ==Int size(EL) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 391aef5..1309b1c 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -56,7 +56,12 @@ module RVM-COMPILER-CORE false - .Map //map a state name(string) to its rank +//map a state name(string) to its integer rank, temporary working cell + .Map + +//states name mapping (string -> int, the map in cell), indexed by property rank. + .List + 0 //the raw transition defined in the rvm spec, indexed by states From 6d16670392188268830ce846b6325733774ca171 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 15 Apr 2016 08:54:07 -0500 Subject: [PATCH 086/160] identify the weaknesses of cur rv-monitor --- src/rvm/rvm-compiler-core.k | 2 +- test/rvm/__RVC_SeatBelt_Monitor.c | 58 ++++ test/rvm/__RVC_SeatBelt_Monitor.h | 10 + test/rvm/seatbelt_multi.rvm | 35 +++ test/rvm/seatbelt_multiRuntimeMonitor.java | 341 +++++++++++++++++++++ 5 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 test/rvm/__RVC_SeatBelt_Monitor.c create mode 100644 test/rvm/__RVC_SeatBelt_Monitor.h create mode 100644 test/rvm/seatbelt_multi.rvm create mode 100644 test/rvm/seatbelt_multiRuntimeMonitor.java diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 1309b1c..1afb001 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -36,7 +36,7 @@ module RVM-COMPILER-CORE imports RVM-SYNTAX configuration $PGM:RVM - "" + "" .K diff --git a/test/rvm/__RVC_SeatBelt_Monitor.c b/test/rvm/__RVC_SeatBelt_Monitor.c new file mode 100644 index 0000000..4342d48 --- /dev/null +++ b/test/rvm/__RVC_SeatBelt_Monitor.c @@ -0,0 +1,58 @@ +#include + +#include +static int __RVC_state = 0; + + + +int __RVC_SeatBelt_safe = 0; +int __RVC_SeatBelt_unsafe = 0; + +void +__RVC_SeatBelt_reset(void) +{ + __RVC_state = 0; + } + +static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; +static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; + +void +__RVC_SeatBelt_seatBeltRemoved() +{ +{fprintf(stderr, "Seat belt removed.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTREMOVED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + +void +__RVC_SeatBelt_seatBeltAttached() +{ +{fprintf(stderr, "Seat belt attached.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + + diff --git a/test/rvm/__RVC_SeatBelt_Monitor.h b/test/rvm/__RVC_SeatBelt_Monitor.h new file mode 100644 index 0000000..8c1dc40 --- /dev/null +++ b/test/rvm/__RVC_SeatBelt_Monitor.h @@ -0,0 +1,10 @@ +#ifndef __RVC_SEATBELT_MONITOR_H +#define __RVC_SEATBELT_MONITOR_H +void +__RVC_SeatBelt_reset(void); +void +__RVC_SeatBelt_seatBeltRemoved(); +void +__RVC_SeatBelt_seatBeltAttached(); + +#endif diff --git a/test/rvm/seatbelt_multi.rvm b/test/rvm/seatbelt_multi.rvm new file mode 100644 index 0000000..dc218ad --- /dev/null +++ b/test/rvm/seatbelt_multi.rvm @@ -0,0 +1,35 @@ +//#include + +SeatBelt() { + event seatBeltRemoved(){fprintf(stderr, "Seat belt removed.\n");} + + event seatBeltAttached() {fprintf(stderr, "Seat belt attached.\n");} + + fsm : unsafe [ + seatBeltAttached -> safe + ] + safe [ + seatBeltRemoved -> unsafe + ] + + @safe { + fprintf(stderr, "set max speed to user input.\n"); + } + + @unsafe { + fprintf(stderr, "set max speed to 10 mph.\n"); + } + + + fsm : unsafe2 [ + seatBeltAttached -> safe2 + ] + safe2 [ + seatBeltRemoved -> unsafe2 + ] + + @safe2 { + fprintf(stderr, "It's safe.\n"); + } + +} diff --git a/test/rvm/seatbelt_multiRuntimeMonitor.java b/test/rvm/seatbelt_multiRuntimeMonitor.java new file mode 100644 index 0000000..9e7ec8b --- /dev/null +++ b/test/rvm/seatbelt_multiRuntimeMonitor.java @@ -0,0 +1,341 @@ + +import java.util.concurrent.*; +import java.util.concurrent.locks.*; +import java.util.*; +import java.lang.ref.*; +import com.runtimeverification.rvmonitor.java.rt.*; +import com.runtimeverification.rvmonitor.java.rt.ref.*; +import com.runtimeverification.rvmonitor.java.rt.table.*; +import com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractIndexingTree; +import com.runtimeverification.rvmonitor.java.rt.tablebase.SetEventDelegator; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple2; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple3; +import com.runtimeverification.rvmonitor.java.rt.tablebase.IDisableHolder; +import com.runtimeverification.rvmonitor.java.rt.tablebase.IMonitor; +import com.runtimeverification.rvmonitor.java.rt.tablebase.DisableHolder; +import com.runtimeverification.rvmonitor.java.rt.tablebase.TerminatedMonitorCleaner; +import java.util.concurrent.atomic.AtomicInteger; + +final class SeatBeltMonitor_Set extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractMonitorSet { + + SeatBeltMonitor_Set(){ + this.size = 0; + this.elements = new SeatBeltMonitor[4]; + } + final void event_seatBeltRemoved() { + int numAlive = 0 ; + for(int i = 0; i < this.size; i++){ + SeatBeltMonitor monitor = this.elements[i]; + if(!monitor.isTerminated()){ + elements[numAlive] = monitor; + numAlive++; + + final SeatBeltMonitor monitorfinalMonitor = monitor; + monitor.Prop_1_event_seatBeltRemoved(); + if(monitorfinalMonitor.Prop_1_Category_safe) { + monitorfinalMonitor.Prop_1_handler_safe(); + } + if(monitorfinalMonitor.Prop_1_Category_unsafe) { + monitorfinalMonitor.Prop_1_handler_unsafe(); + } + final SeatBeltMonitor monitorfinalMonitor = monitor; + monitor.Prop_2_event_seatBeltRemoved(); + if(monitorfinalMonitor.Prop_2_Category_safe2) { + monitorfinalMonitor.Prop_2_handler_safe2(); + } + } + } + for(int i = numAlive; i < this.size; i++){ + this.elements[i] = null; + } + size = numAlive; + } + final void event_seatBeltAttached() { + int numAlive = 0 ; + for(int i = 0; i < this.size; i++){ + SeatBeltMonitor monitor = this.elements[i]; + if(!monitor.isTerminated()){ + elements[numAlive] = monitor; + numAlive++; + + final SeatBeltMonitor monitorfinalMonitor = monitor; + monitor.Prop_1_event_seatBeltAttached(); + if(monitorfinalMonitor.Prop_1_Category_safe) { + monitorfinalMonitor.Prop_1_handler_safe(); + } + if(monitorfinalMonitor.Prop_1_Category_unsafe) { + monitorfinalMonitor.Prop_1_handler_unsafe(); + } + final SeatBeltMonitor monitorfinalMonitor = monitor; + monitor.Prop_2_event_seatBeltAttached(); + if(monitorfinalMonitor.Prop_2_Category_safe2) { + monitorfinalMonitor.Prop_2_handler_safe2(); + } + } + } + for(int i = numAlive; i < this.size; i++){ + this.elements[i] = null; + } + size = numAlive; + } +} + +class SeatBeltMonitor extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractAtomicMonitor implements Cloneable, com.runtimeverification.rvmonitor.java.rt.RVMObject { + protected Object clone() { + try { + SeatBeltMonitor ret = (SeatBeltMonitor) super.clone(); + ret.pairValue = new AtomicInteger(pairValue.get()); + return ret; + } + catch (CloneNotSupportedException e) { + throw new InternalError(e.toString()); + } + } + + static final int Prop_1_transition_seatBeltRemoved[] = {2, 0, 2};; + static final int Prop_1_transition_seatBeltAttached[] = {1, 2, 2};; + + static final int Prop_2_transition_seatBeltRemoved[] = {2, 0, 2};; + static final int Prop_2_transition_seatBeltAttached[] = {1, 2, 2};; + + volatile boolean Prop_1_Category_safe = false; + volatile boolean Prop_1_Category_unsafe = false; + volatile boolean Prop_2_Category_safe2 = false; + + private AtomicInteger pairValue; + + SeatBeltMonitor() { + this.pairValue = new AtomicInteger(this.calculatePairValue(-1, 0) ) ; + + this.pairValue = new AtomicInteger(this.calculatePairValue(-1, 0) ) ; + + } + + @Override public final int getState() { + return this.getState(this.pairValue.get() ) ; + } + @Override public final int getLastEvent() { + return this.getLastEvent(this.pairValue.get() ) ; + } + private final int getState(int pairValue) { + return (pairValue & 0) ; + } + private final int getLastEvent(int pairValue) { + return (pairValue >> 0) ; + } + private final int calculatePairValue(int lastEvent, int state) { + return (((lastEvent + 1) << 0) | state) ; + } + + private final int handleEvent(int eventId, int[] table) { + int nextstate; + while (true) { + int oldpairvalue = this.pairValue.get() ; + int oldstate = this.getState(oldpairvalue) ; + nextstate = table [ oldstate ]; + int nextpairvalue = this.calculatePairValue(eventId, nextstate) ; + if (this.pairValue.compareAndSet(oldpairvalue, nextpairvalue) ) { + break; + } + } + return nextstate; + } + + final boolean Prop_1_event_seatBeltRemoved() { + + int nextstate = this.handleEvent(0, Prop_1_transition_seatBeltRemoved) ; + this.Prop_1_Category_safe = nextstate == 1; + this.Prop_1_Category_unsafe = nextstate == 0; + + return true; + } + + final boolean Prop_1_event_seatBeltAttached() { + + int nextstate = this.handleEvent(1, Prop_1_transition_seatBeltAttached) ; + this.Prop_1_Category_safe = nextstate == 1; + this.Prop_1_Category_unsafe = nextstate == 0; + + return true; + } + + final boolean Prop_2_event_seatBeltRemoved() { + {fprintf(stderr, "Seat belt removed.\n");} + + int nextstate = this.handleEvent(0, Prop_2_transition_seatBeltRemoved) ; + this.Prop_2_Category_safe2 = nextstate == 1; + + return true; + } + + final boolean Prop_2_event_seatBeltAttached() { + {fprintf(stderr, "Seat belt attached.\n");} + + int nextstate = this.handleEvent(1, Prop_2_transition_seatBeltAttached) ; + this.Prop_2_Category_safe2 = nextstate == 1; + + return true; + } + + final void Prop_1_handler_safe (){ + { + fprintf(stderr, "set max speed to user input.\n"); + } + + } + + final void Prop_1_handler_unsafe (){ + { + fprintf(stderr, "set max speed to 10 mph.\n"); + } + + } + + final void Prop_2_handler_safe2 (){ + { + fprintf(stderr, "It's safe.\n"); + } + + } + + final void reset() { + this.pairValue.set(this.calculatePairValue(-1, 0) ) ; + + Prop_1_Category_safe = false; + Prop_1_Category_unsafe = false; + this.pairValue.set(this.calculatePairValue(-1, 0) ) ; + + Prop_2_Category_safe2 = false; + } + + @Override + protected final void terminateInternal(int idnum) { + int lastEvent = this.getLastEvent(); + + switch(idnum){ + } + switch(lastEvent) { + case -1: + return; + case 0: + //seatBeltRemoved + return; + case 1: + //seatBeltAttached + return; + } + return; + } + + public static int getNumberOfEvents() { + return 2; + } + + public static int getNumberOfStates() { + return -1; + } + +} + +public final class seatbelt_multiRuntimeMonitor implements com.runtimeverification.rvmonitor.java.rt.RVMObject { + private static com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager seatbelt_multiMapManager; + static { + seatbelt_multiMapManager = new com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager(); + seatbelt_multiMapManager.start(); + } + + // Declarations for the Lock + static final ReentrantLock seatbelt_multi_RVMLock = new ReentrantLock(); + static final Condition seatbelt_multi_RVMLock_cond = seatbelt_multi_RVMLock.newCondition(); + + private static boolean SeatBelt_activated = false; + + // Declarations for Indexing Trees + private static final SeatBeltMonitor SeatBelt__Map = new SeatBeltMonitor() ; + + public static int cleanUp() { + int collected = 0; + // indexing trees + return collected; + } + + // Removing terminated monitors from partitioned sets + static { + TerminatedMonitorCleaner.start() ; + } + // Setting the behavior of the runtime library according to the compile-time option + static { + RuntimeOption.enableFineGrainedLock(false) ; + } + + public static final void seatBeltRemovedEvent() { + SeatBelt_activated = true; + while (!seatbelt_multi_RVMLock.tryLock()) { + Thread.yield(); + } + + SeatBeltMonitor matchedEntry = null; + { + // FindOrCreateEntry + matchedEntry = SeatBelt__Map; + } + // D(X) main:1 + if ((matchedEntry == null) ) { + // D(X) main:4 + SeatBeltMonitor created = new SeatBeltMonitor() ; + matchedEntry = created; + } + // D(X) main:8--9 + final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_1_event_seatBeltRemoved(); + if(matchedEntryfinalMonitor.Prop_1_Category_safe) { + matchedEntryfinalMonitor.Prop_1_handler_safe(); + } + if(matchedEntryfinalMonitor.Prop_1_Category_unsafe) { + matchedEntryfinalMonitor.Prop_1_handler_unsafe(); + } + final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_2_event_seatBeltRemoved(); + if(matchedEntryfinalMonitor.Prop_2_Category_safe2) { + matchedEntryfinalMonitor.Prop_2_handler_safe2(); + } + + seatbelt_multi_RVMLock.unlock(); + } + + public static final void seatBeltAttachedEvent() { + SeatBelt_activated = true; + while (!seatbelt_multi_RVMLock.tryLock()) { + Thread.yield(); + } + + SeatBeltMonitor matchedEntry = null; + { + // FindOrCreateEntry + matchedEntry = SeatBelt__Map; + } + // D(X) main:1 + if ((matchedEntry == null) ) { + // D(X) main:4 + SeatBeltMonitor created = new SeatBeltMonitor() ; + matchedEntry = created; + } + // D(X) main:8--9 + final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_1_event_seatBeltAttached(); + if(matchedEntryfinalMonitor.Prop_1_Category_safe) { + matchedEntryfinalMonitor.Prop_1_handler_safe(); + } + if(matchedEntryfinalMonitor.Prop_1_Category_unsafe) { + matchedEntryfinalMonitor.Prop_1_handler_unsafe(); + } + final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; + matchedEntry.Prop_2_event_seatBeltAttached(); + if(matchedEntryfinalMonitor.Prop_2_Category_safe2) { + matchedEntryfinalMonitor.Prop_2_handler_safe2(); + } + + seatbelt_multi_RVMLock.unlock(); + } + +} From a548b90c16c57519b581f61e9bcf36bd86649015 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 15 Apr 2016 08:54:18 -0500 Subject: [PATCH 087/160] identify the weaknesses of cur rv-monitor --- problems-identified.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 problems-identified.txt diff --git a/problems-identified.txt b/problems-identified.txt new file mode 100644 index 0000000..0f4456b --- /dev/null +++ b/problems-identified.txt @@ -0,0 +1,7 @@ +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). + From 451377c2bd9324617bce4c7b32f91110e79c6d06 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 15 Apr 2016 09:17:05 -0500 Subject: [PATCH 088/160] update comments in problems-identified.txt --- problems-identified.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/problems-identified.txt b/problems-identified.txt index 0f4456b..d73aea5 100644 --- a/problems-identified.txt +++ b/problems-identified.txt @@ -5,3 +5,12 @@ 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. \ No newline at end of file From 8815f1510af7ba5da997a3dc096a794f5d258f72 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 15 Apr 2016 10:57:30 -0500 Subject: [PATCH 089/160] re-arrange module structure --- src/rvm/rvc.k | 9 +++++---- src/rvm/rvm-compiler.k | 6 ------ test/cmop/rvc/Test.rvm | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 test/cmop/rvc/Test.rvm diff --git a/src/rvm/rvc.k b/src/rvm/rvc.k index 1c07738..0db3b06 100644 --- a/src/rvm/rvc.k +++ b/src/rvm/rvc.k @@ -1,20 +1,21 @@ +require "rvm-syntax.k" require "rvm-compiler.k" require "logic-plugins-shell.k" require "../c-monitor-code-template/c-monitor-template.k" module RVC-SYNTAX - imports RVM-SYNTAX + imports RVM-COMPILER-SYNTAX endmodule module RVC imports RVC-SYNTAX - imports RVM-COMPILER-CORE - imports PRINT-AST - imports UTIL + + imports RVM-COMPILER imports LOGIC-PLUGINS-SHELL imports C-MONITOR-TEMPLATE + endmodule diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index c11181d..4829cdc 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -5,18 +5,12 @@ require "../helper/print-ast.k" require "../../src/helper/util.k" //// -require "logic-plugins-shell.k" -require "../c-monitor-code-template/c-monitor-template.k" - module RVM-COMPILER imports RVM-SYNTAX imports RVM-COMPILER-CORE imports PRINT-AST imports UTIL - imports LOGIC-PLUGINS-SHELL - imports C-MONITOR-TEMPLATE - syntax KResult ::= "error" /** diff --git a/test/cmop/rvc/Test.rvm b/test/cmop/rvc/Test.rvm new file mode 100644 index 0000000..2f19a29 --- /dev/null +++ b/test/cmop/rvc/Test.rvm @@ -0,0 +1,31 @@ +package rvm; + +import java.io.*; +Test (int o){ + + event hasnext(Iterator i) {} // {1, 1, 1, 3} + event next(Iterator i) {} // {2, 0, 2, 3} + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + // alias match = unsafe, start + + @match { + int j; + } + + + +} From 4aeefcbfe4b237a993968e93d43871d9787611f4 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 16 Apr 2016 21:54:36 -0500 Subject: [PATCH 090/160] debug --- .../c-monitor-template-syntax.k | 28 ++++---- .../c-monitor-template.k | 64 +++++++++++-------- src/helper/code-gen.k | 11 ++++ 3 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 src/helper/code-gen.k diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 90e725f..f491fe5 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -1,23 +1,34 @@ +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 ::= GlobalVarDecls MainBody1 +syntax MainBody ::= GlobalStatesInit MainBody1 -syntax MainBody1 ::= LocalStatesInit MainBody2 +syntax MainBody1 ::= PropStatesInit MainBody2 syntax MainBody2 ::= ResetFunc MainBody3 syntax MainBody3 ::= StateTransitions EventActions -syntax CTemplate ::= "$CMonitor" Int Int //the two ints are num of events and states resp. +syntax CTemplate ::= "$CMonitor" syntax Include ::= "$incl" -syntax GlobalVarDecls ::= "$globalInit" -syntax StateVar ::= "$sVar" "(" Int ")" -syntax LocalStatesInit ::= "$localInit" "(" Int ")" +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" "(" List ")" +syntax PropStatesInit ::= LocalStatesInit ":" PropStatesInit + + syntax ResetFunc ::= "$reset" syntax StateTransitions ::= "$stateFuncs" "(" Int ")" @@ -28,9 +39,4 @@ syntax EventActions ::= "$eventFuncs" "(" Int ")" syntax EventActions ::= List{EventFunc, ","} syntax EventFunc ::= "eFunc" "(" Int ")" -rule $CMonitor NumOfEvents:Int NumOfStates:Int => - $incl $globalInit ($localInit(NumOfStates)) $reset - ($stateFuncs(NumOfStates)) $eventFuncs(NumOfEvents) - when NumOfEvents >Int 0 andBool NumOfStates >Int 0 - endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index fd58e1b..261acd3 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -8,15 +8,24 @@ module C-MONITOR-TEMPLATE rule "c" false - true => false - EL:List + _:K => $CMonitor + + +rule //TODO:debug + "c" + false + EL:List + + SNM:List + + $CMonitor => + $incl $globalInit(size(SNM)) ($pStates(SNM)) $reset + ($stateFuncs(size(EL) *Int size(SNM))) $eventFuncs(size(EL)) + + when size(EL) >Int 0 - PN:Int - SM:Map -//this rule currently only handle the single property spec... - _:K => $CMonitor size(EL) size(SM) //the two arguments are num of events and states resp. //generate the include part. //TODO: incorporate the user provided includes @@ -26,28 +35,31 @@ rule $incl M:MainBody => M L:List //rewrite the global var declarations. -rule G:GlobalVarDecls M:MainBody1 => M +rule $globalInit(0) M:MainBody1 => M + +rule $globalInit(I:Int) M:MainBody1 => $globalInit(I -Int 1) M - (.List => ListItem("static int __RVC_state = 0;\n")) L:List + (.List => ListItem(getGlobalStateVarInit(I -Int 1))) L:List +when I >Int 0 //handling the local state vars initializations. -rule ($localInit(0) M:MainBody2) => M - L:List => .List //the local state vars are stored in tmp cell - C:List (.List => L) - -rule ($localInit(I:Int) M:MainBody2) => - (($sVar(I -Int 1), $localInit(I -Int 1)) M) - -when I >=Int 1 - -rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => - (($localInit(J:Int)) M) - - StateMap:Map - (.List => ListItem(getStrKey(StateMap, I))) L:List - -rule $reset M:MainBody3 => M - SN:String - Code:List (.List => ListItem(printResetFunc(SN))) +//rule ($localInit(0) M:MainBody2) => M +// L:List => .List //the local state vars are stored in tmp cell +// C:List (.List => L) +// +//rule ($localInit(I:Int) M:MainBody2) => +// (($sVar(I -Int 1), $localInit(I -Int 1)) M) +// +//when I >=Int 1 +// +//rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => +// (($localInit(J:Int)) M) +// +// StateMap:Map +// (.List => ListItem(getStrKey(StateMap, I))) L:List +// +//rule $reset M:MainBody3 => M +// SN:String +// Code:List (.List => ListItem(printResetFunc(SN))) endmodule \ No newline at end of file diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k new file mode 100644 index 0000000..0c642e0 --- /dev/null +++ b/src/helper/code-gen.k @@ -0,0 +1,11 @@ +require "../rvm/rvm-syntax.k" +require "domains.k" + +module CODE-GEN + imports RVM-SYNTAX + imports DOMAINS-SYNTAX + + syntax String ::= getGlobalStateVarInit(Int) [function] + rule getGlobalStateVarInit(I:Int) => "static int Prop_" +String + Int2String(I) +String "_RVC_state = 0;\n" +endmodule \ No newline at end of file From ba2d66c14da19cb373330001370449d91b09e55d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 17 Apr 2016 12:27:07 -0500 Subject: [PATCH 091/160] debug multi-property --- .../c-monitor-template-syntax.k | 6 +++- .../c-monitor-template.k | 28 ++++++++++--------- src/helper/util.k | 5 ++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index f491fe5..0f83e08 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -13,8 +13,12 @@ syntax MainBody2 ::= ResetFunc MainBody3 syntax MainBody3 ::= StateTransitions EventActions syntax CTemplate ::= "$CMonitor" - syntax Include ::= "$incl" +syntax MainBody ::= "$main" +syntax MainBody1 ::= "$main1" +syntax MainBody2 ::= "$main2" +syntax MainBody3 ::= "$main3" + syntax GStateVar ::= "$gSVar" "(" Int ")" syntax GlobalStatesInit ::= "$globalInit" "(" Int ")" diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 261acd3..b7da20c 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -1,9 +1,13 @@ require "../rvm/rvm-compiler-core.k" require "c-monitor-template-syntax.k" +require "../helper/code-gen.k" +require "../helper/util.k" module C-MONITOR-TEMPLATE imports RVM-COMPILER-CORE imports C-MONITOR-TEMPLATE-SYNTAX + imports CODE-GEN + imports UTIL rule "c" @@ -12,34 +16,32 @@ rule _:K => $CMonitor -rule //TODO:debug +rule "c" false - EL:List - - SNM:List $CMonitor => - $incl $globalInit(size(SNM)) ($pStates(SNM)) $reset - ($stateFuncs(size(EL) *Int size(SNM))) $eventFuncs(size(EL)) + $incl $main - when size(EL) >Int 0 - - //generate the include part. //TODO: incorporate the user provided includes -rule $incl M:MainBody => M +rule $incl $main => $main (.List => ListItem("#include \n" +String "#include \n") ) L:List +///////// + rule $main => $globalInit(getSize(L)) $main1 + L:List + + //rewrite the global var declarations. -rule $globalInit(0) M:MainBody1 => M +rule $globalInit(0) $main1 => $main1 -rule $globalInit(I:Int) M:MainBody1 => $globalInit(I -Int 1) M +rule ($globalInit(I:Int) $main1) => ($globalInit(I -Int 1) $main1) - (.List => ListItem(getGlobalStateVarInit(I -Int 1))) L:List + L:List (.List => ListItem(getGlobalStateVarInit(I -Int 1))) when I >Int 0 //handling the local state vars initializations. diff --git a/src/helper/util.k b/src/helper/util.k index 20cb072..812aaf4 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -31,6 +31,11 @@ rule getStrKey((S:String |-> V:Int) M:Map, V) => S rule getStrKey((_:String |-> V1:Int) M:Map, V2:Int) => getStrKey(M, V2) when V1 =/=Int V2 +/*Get the size of a list of maps*/ +syntax Int ::= getSize(List) [function] +rule getSize(.List) => 0 +rule getSize(ListItem(_:Map) L:List) => 1 +Int getSize(L) + endmodule From a19fd0684bd6e146656e275df87910118bf322d5 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 17 Apr 2016 15:04:37 -0500 Subject: [PATCH 092/160] import required module --- src/logic/semantics/fsm.k | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index fcd4e66..d9731ae 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -1,12 +1,13 @@ require "../syntax/fsm-syntax.k" - require "../../rvm/rvm-compiler-core.k" +require "../../helper/print-ast.k" require "../../helper/util.k" module FSM imports FSM-SYNTAX imports RVM-COMPILER-CORE + imports PRINT-AST imports UTIL /*First scan: Gathering the state ranks*/ From f754aa4d5df86bd36e99b7854ed8d832f8bccc77 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 17 Apr 2016 16:56:18 -0500 Subject: [PATCH 093/160] multi-property ok in windows --- src/helper/util.k | 8 ++++++++ src/rvm/rvm-compiler.k | 16 +++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/helper/util.k b/src/helper/util.k index 812aaf4..9ef65d0 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -36,6 +36,14 @@ syntax Int ::= getSize(List) [function] rule getSize(.List) => 0 rule getSize(ListItem(_:Map) L:List) => 1 +Int getSize(L) +/*test whether the given item is the last item of the list*/ +syntax Bool ::= isLastItem(List, Id) [function] +rule isLastItem(.List, T:Id) => false +rule isLastItem(ListItem(X:Id), Y:Id) => Id2String(X) ==String Id2String(Y) +rule isLastItem(ListItem(X:Id) L:List, Y:Id) => isLastItem(L, Y) + + + endmodule diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 4829cdc..588f54f 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -43,7 +43,7 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - L:List (.List => ListItem(Id2String(X))) + L:List (.List => ListItem(X)) ... @@ -64,16 +64,17 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) PS:Int .K => PS -Int 1 -when notBool (Id2String(X) in L) +when notBool (X in L) //construct initial props cells -rule +rule + L:List + ... - - X + X:Id (.Bag => PS -Int 1 @@ -87,7 +88,8 @@ rule ... PS:Int => PS -Int 1 -when PS >Int 0 +when PS >Int 0 andBool isLastItem(L, X) + rule 0 => .K @@ -100,7 +102,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList) Props:PropertyDecList} => .K EL:List (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List -when (Id2String(X) in EL) +when (X in EL) //No events left rule From 96e6c5d10e16c07533b398f405c04afb13c1618c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 17 Apr 2016 17:03:26 -0500 Subject: [PATCH 094/160] update k-version-info --- version.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/version.txt b/version.txt index f129ba2..453c3ae 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,4 @@ K: [github](https://github.com/kframework/k) -ee3bdc2066c29d7a0c7f29ab85c7bcaf1332b173 \ No newline at end of file +ee3bdc2066c29d7a0c7f29ab85c7bcaf1332b173 + +Mar 31: stable From 32d4c1158d27ec1ddb96a340bcd9dfb9b42d0f43 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 17 Apr 2016 21:12:01 -0500 Subject: [PATCH 095/160] local state vars init --- .../c-monitor-template-syntax.k | 2 +- src/c-monitor-code-template/c-monitor-template.k | 16 ++++++++++++++-- src/helper/util.k | 11 ++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 0f83e08..a1237a3 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -29,7 +29,7 @@ syntax StateVar ::= "$sVar" "(" Int "," Int ")" //prop rank, state rank syntax LocalStatesInit ::= "$localInit" "(" Int "," Int ")" syntax LocalStatesInit ::= StateVar "," LocalStatesInit -syntax PropStatesInit ::= "$pStates" "(" List ")" +syntax PropStatesInit ::= "$pStates" "(" Int ")" syntax PropStatesInit ::= LocalStatesInit ":" PropStatesInit diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index b7da20c..b31604b 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -32,8 +32,8 @@ rule $incl $main => $main L:List ///////// - rule $main => $globalInit(getSize(L)) $main1 - L:List + rule $main => $globalInit(PS) $main1 + PS:Int //rewrite the global var declarations. @@ -44,6 +44,18 @@ rule ($globalInit(I:Int) $main1) => ($globalInit(I -Int 1) $main1) L:List (.List => ListItem(getGlobalStateVarInit(I -Int 1))) when I >Int 0 +rule $main1 => $pStates(0) $main2 + +rule $pStates(I:Int) $main2 => $main2 + PN:Int //the number of properties + when I >=Int PN + +rule $pStates(I:Int) $main2 => ($localInit(I, getSize(L, I)) : $pStates(I +Int 1)) + $main2 + PN:Int //the number of properties + L:List + when I ($localInit(0) M:MainBody2) => M // L:List => .List //the local state vars are stored in tmp cell diff --git a/src/helper/util.k b/src/helper/util.k index 9ef65d0..1bb871f 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -32,9 +32,14 @@ rule getStrKey((_:String |-> V1:Int) M:Map, V2:Int) => getStrKey(M, V2) when V1 =/=Int V2 /*Get the size of a list of maps*/ -syntax Int ::= getSize(List) [function] -rule getSize(.List) => 0 -rule getSize(ListItem(_:Map) L:List) => 1 +Int getSize(L) +syntax Int ::= getSize(List, Int) [function] +rule getSize(.List, I:Int) => 0 +rule getSize(ListItem(M:Map), 0) => size(M) +rule getSize(ListItem(M:Map), I:Int) => 0 when I =/=Int 0 + +rule getSize(ListItem(M:Map) L:List, 0) => size(M) +rule getSize(ListItem(M:Map) L:List, I:Int) => getSize(L, I -Int 1) when I >Int 0 +rule getSize(ListItem(M:Map) L:List, I:Int) => 0 when I Date: Mon, 18 Apr 2016 07:42:30 -0500 Subject: [PATCH 096/160] local state vars init --- .../c-monitor-template.k | 39 ++++++++++--------- src/helper/util.k | 13 +++++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index b31604b..b2a726d 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -54,26 +54,27 @@ rule $pStates(I:Int) $main2 => ($localInit(I, getSize(L, I)) : $pStates(I +I $main2 PN:Int //the number of properties L:List + _:Map => getMapI(L, I) when I ($localInit(0) M:MainBody2) => M -// L:List => .List //the local state vars are stored in tmp cell -// C:List (.List => L) -// -//rule ($localInit(I:Int) M:MainBody2) => -// (($sVar(I -Int 1), $localInit(I -Int 1)) M) -// -//when I >=Int 1 -// -//rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => -// (($localInit(J:Int)) M) -// -// StateMap:Map -// (.List => ListItem(getStrKey(StateMap, I))) L:List -// -//rule $reset M:MainBody3 => M -// SN:String -// Code:List (.List => ListItem(printResetFunc(SN))) +//*handling the local state vars initializations. */ +rule ($localInit(R:Int, 0):$pStates(I:Int) $main2) => ($pStates(I) $main2) + L:List => .List //the local state vars are stored in tmp cell + C:List (.List => L) + +rule ($localInit(R:Int, I:Int):$pStates(P:Int) $main2) => + (($sVar(R, I -Int 1), $localInit(R, I -Int 1)):$pStates(P) $main2) + +when I >=Int 1 + +rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => + (($localInit(R, J):$pStates(P)) $main2) + + StateMap:Map + (.List => ListItem(getStrKey(StateMap, I))) L:List + +rule $reset M:MainBody3 => M + SN:String + Code:List (.List => ListItem(printResetFunc(SN))) endmodule \ No newline at end of file diff --git a/src/helper/util.k b/src/helper/util.k index 1bb871f..29b1ce3 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -47,6 +47,19 @@ rule isLastItem(.List, T:Id) => false rule isLastItem(ListItem(X:Id), Y:Id) => Id2String(X) ==String Id2String(Y) rule isLastItem(ListItem(X:Id) L:List, Y:Id) => isLastItem(L, Y) +//get the no. i map in the map list +syntax Map ::= getMapI(List, Int) [function] +rule getMapI(.List, I:Int) => .Map +rule getMapI(ListItem(M:Map), 0) => M +rule getMapI(ListItem(M:Map), I:Int) => .Map when I =/=Int 0 + +rule getMapI(ListItem(M:Map) L:List, 0) => M +rule getMapI(ListItem(M:Map) L:List, I:Int) => .Map when I + getMapI(L, I -Int 1) when I >Int 0 + + + endmodule From a8506f4a18f9869b2d0cd3cda7adf2f464700a04 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 02:40:22 -0500 Subject: [PATCH 097/160] update reset func --- .../c-monitor-template.k | 6 ++--- src/helper/code-gen.k | 25 +++++++++++++++++-- src/helper/print-ast.k | 7 ------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index b2a726d..39c1eb7 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -73,8 +73,8 @@ rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => StateMap:Map (.List => ListItem(getStrKey(StateMap, I))) L:List -rule $reset M:MainBody3 => M +rule $reset $main3 => $main3 SN:String - Code:List (.List => ListItem(printResetFunc(SN))) - + Code:List (.List => ListItem(printResetFunc(SN, S))) + S:Int endmodule \ No newline at end of file diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 0c642e0..c3a2ead 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -5,7 +5,28 @@ module CODE-GEN imports RVM-SYNTAX imports DOMAINS-SYNTAX +//the code for resetting global state var i +syntax String ::= resetGlobalStateI(Int) [function] +rule resetGlobalStateI(I:Int) => "Prop_" +String + Int2String(I) +String "_RVC_state = 0;\n" + syntax String ::= getGlobalStateVarInit(Int) [function] - rule getGlobalStateVarInit(I:Int) => "static int Prop_" +String - Int2String(I) +String "_RVC_state = 0;\n" + rule getGlobalStateVarInit(I:Int) => "static int " +String resetGlobalStateI(I) + + /*Return the string of reset function, given the name of the specification, + and the number of properties*/ + syntax String ::= printResetFunc(String, Int) [function] + + rule printResetFunc(SpecName:String, 0) => "" + + rule printResetFunc(SpecName:String, I:Int) => "void __RVC_" +String SpecName + +String "_reset(void)\n" +String "{\n" +String resetGlobalStates(I) +String "}" + when I =/=Int 0 + + syntax String ::= resetGlobalStates(Int) [function] + rule resetGlobalStates(I:Int) => "" when I <=Int 0 + rule resetGlobalStates(1) => resetGlobalStateI(0) + rule resetGlobalStates(I:Int) => resetGlobalStates(I -Int 1) +String + resetGlobalStateI(I -Int 1) when I >Int 1 + endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 4386b10..7283ccb 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -41,13 +41,6 @@ module PRINT-AST rule getTransitionList(SN:StateName[TL:TransitionList]) => TL - -/*Return the string of reset function, given the name of the specification*/ -syntax String ::= printResetFunc(String) [function] - -rule printResetFunc(SpecName:String) => "void __RVC_" +String SpecName +String "_reset(void)\n" -+String "{\n__RVC_state = 0;\n}" - syntax Int ::= sizeOf(PropertyDecList) [function] rule sizeOf(.PropertyDecList) => 0 rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) From 07875fc2204213a5e96deb0061e530bc48c34c7e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 02:54:53 -0500 Subject: [PATCH 098/160] make it kompile --- src/c-monitor-code-template/c-monitor-template.k | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 39c1eb7..060e345 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -75,6 +75,6 @@ rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => rule $reset $main3 => $main3 SN:String - Code:List (.List => ListItem(printResetFunc(SN, S))) - S:Int + P:Int + Code:List (.List => ListItem(printResetFunc(SN, P):String)) endmodule \ No newline at end of file From f421ff2cb5459bf91aa2429030f93bd2973a7171 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 03:02:47 -0500 Subject: [PATCH 099/160] add a rule --- src/c-monitor-code-template/c-monitor-template.k | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 060e345..9041bf5 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -73,6 +73,8 @@ rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => StateMap:Map (.List => ListItem(getStrKey(StateMap, I))) L:List +rule $main2 => $reset $main3 + rule $reset $main3 => $main3 SN:String P:Int From bdeae2374c271c333a2d3f6645382307967b8cde Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 15:32:25 -0500 Subject: [PATCH 100/160] update the include section. New line can be inserted between each list item, increasing its portability --- src/c-monitor-code-template/c-monitor-template.k | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 9041bf5..4d383ad 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -27,9 +27,9 @@ rule //generate the include part. //TODO: incorporate the user provided includes rule $incl $main => $main - (.List => ListItem("#include \n" - +String "#include \n") ) - L:List + L:List (.List => ListItem("#include ") + ListItem("#include ") ) + ///////// rule $main => $globalInit(PS) $main1 From ecc15966c21d45a0e1e706b4b617b7d1c3698bec Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 20:40:43 -0500 Subject: [PATCH 101/160] make it compile --- .../c-monitor-template-syntax.k | 9 ++++++--- .../c-monitor-template.k | 8 ++++++++ src/helper/print-ast.k | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index a1237a3..2693c4c 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -10,7 +10,8 @@ syntax MainBody ::= GlobalStatesInit MainBody1 syntax MainBody1 ::= PropStatesInit MainBody2 syntax MainBody2 ::= ResetFunc MainBody3 -syntax MainBody3 ::= StateTransitions EventActions +syntax MainBody3 ::= StateTransitions MainBody4 +syntax MainBody4 ::= EventActions syntax CTemplate ::= "$CMonitor" syntax Include ::= "$incl" @@ -18,6 +19,7 @@ syntax MainBody ::= "$main" syntax MainBody1 ::= "$main1" syntax MainBody2 ::= "$main2" syntax MainBody3 ::= "$main3" +syntax MainBody4 ::= "$main4" syntax GStateVar ::= "$gSVar" "(" Int ")" @@ -35,9 +37,10 @@ syntax PropStatesInit ::= LocalStatesInit ":" PropStatesInit syntax ResetFunc ::= "$reset" -syntax StateTransitions ::= "$stateFuncs" "(" Int ")" +//the state functions are indexed by property rank and event rank +syntax StateTransitions ::= "$stateFuncs" "(" Int "," Int ")" syntax StateTransitions ::= List{StateFunc, ","} -syntax StateFunc ::= "$sFunc" "(" Int ")" +syntax StateFunc ::= "$sFunc" "(" Int "," Int ")" syntax EventActions ::= "$eventFuncs" "(" Int ")" syntax EventActions ::= List{EventFunc, ","} diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 4d383ad..0e39311 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -79,4 +79,12 @@ rule $reset $main3 => $main3 SN:String P:Int Code:List (.List => ListItem(printResetFunc(SN, P):String)) + +//rewrite $main3 to state transitions and $main4 +rule + P:Int + L:List + $main3 => ($stateFuncs(P, size(L)) $main4) + + endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 7283ccb..131fa8b 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -1,9 +1,11 @@ require "../rvm/rvm-syntax.k" +require "../c-monitor-code-template/c-monitor-template-syntax.k" require "domains.k" module PRINT-AST imports RVM-SYNTAX imports DOMAINS-SYNTAX + imports C-MONITOR-TEMPLATE-SYNTAX //print package ast syntax String ::= toString(OptionalPackageDec) [function] @@ -45,5 +47,20 @@ syntax Int ::= sizeOf(PropertyDecList) [function] rule sizeOf(.PropertyDecList) => 0 rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) +//given the number of properties and events, generate a list of state transition functions, +//indexed by property rank and event rank +//the first two args are the current prop rank and event rank, the third arg is the +//total number of events. +syntax StateTransitions ::= getListofStateFuncs(Int, Int, Int) [function] +rule getListofStateFuncs(I:Int, J:Int, EN:Int) => .List +when I <=Int 0 + +rule getListofStateFuncs(I:Int, J:Int, EN:Int) => getListofStateFuncs(I -Int 1, EN, EN) +when I >Int 0 andBool J <=Int 0 + +rule getListofStateFuncs(I:Int, J:Int, EN:Int) => +($sFunc(I -Int 1, J -Int 1):StateFunc, getListofStateFuncs(I, J -Int 1, EN)) +when I >Int 0 andBool J >Int 0 + endmodule \ No newline at end of file From 1f12b3284a3bdafcd8eb9703c454cdba73da90b2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 20:53:03 -0500 Subject: [PATCH 102/160] get list of state transition function symbols --- src/c-monitor-code-template/c-monitor-template.k | 1 + 1 file changed, 1 insertion(+) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 0e39311..a6d2ebc 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -86,5 +86,6 @@ rule L:List $main3 => ($stateFuncs(P, size(L)) $main4) +rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(P, E, E) $main4) endmodule \ No newline at end of file From 53f17c74bcd28635c3d6fa6ea44fc1abf7a51636 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 21:12:53 -0500 Subject: [PATCH 103/160] re-order the state transition functions: from small to large --- .../c-monitor-template.k | 2 +- src/helper/print-ast.k | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index a6d2ebc..d660f2d 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -86,6 +86,6 @@ rule L:List $main3 => ($stateFuncs(P, size(L)) $main4) -rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(P, E, E) $main4) +rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(0, 0, P, E) $main4) endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 131fa8b..6062636 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -49,18 +49,18 @@ rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) //given the number of properties and events, generate a list of state transition functions, //indexed by property rank and event rank -//the first two args are the current prop rank and event rank, the third arg is the -//total number of events. -syntax StateTransitions ::= getListofStateFuncs(Int, Int, Int) [function] -rule getListofStateFuncs(I:Int, J:Int, EN:Int) => .List -when I <=Int 0 - -rule getListofStateFuncs(I:Int, J:Int, EN:Int) => getListofStateFuncs(I -Int 1, EN, EN) -when I >Int 0 andBool J <=Int 0 - -rule getListofStateFuncs(I:Int, J:Int, EN:Int) => -($sFunc(I -Int 1, J -Int 1):StateFunc, getListofStateFuncs(I, J -Int 1, EN)) -when I >Int 0 andBool J >Int 0 +//the first two args are the current prop rank and event rank, the third and fourth args are the +//total number of properties and events resp. +syntax StateTransitions ::= getListofStateFuncs(Int, Int, Int, Int) [function] +rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => .List +when I >=Int PN + +rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => getListofStateFuncs(I +Int 1, 0, PN, EN) +when I =Int EN + +rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => +($sFunc(I, J):StateFunc , getListofStateFuncs(I, J +Int 1, PN, EN)) +when I Date: Fri, 22 Apr 2016 22:28:03 -0500 Subject: [PATCH 104/160] save work --- src/helper/code-gen.k | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index c3a2ead..b2c6560 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -5,13 +5,16 @@ module CODE-GEN imports RVM-SYNTAX imports DOMAINS-SYNTAX +syntax String ::= staticIntPrefix(String) [function] +rule staticIntPrefix(S:String) => "static int " +String S + //the code for resetting global state var i syntax String ::= resetGlobalStateI(Int) [function] rule resetGlobalStateI(I:Int) => "Prop_" +String Int2String(I) +String "_RVC_state = 0;\n" syntax String ::= getGlobalStateVarInit(Int) [function] - rule getGlobalStateVarInit(I:Int) => "static int " +String resetGlobalStateI(I) + rule getGlobalStateVarInit(I:Int) => staticIntPrefix(resetGlobalStateI(I)) /*Return the string of reset function, given the name of the specification, and the number of properties*/ @@ -29,4 +32,10 @@ rule resetGlobalStateI(I:Int) => "Prop_" +String rule resetGlobalStates(I:Int) => resetGlobalStates(I -Int 1) +String resetGlobalStateI(I -Int 1) when I >Int 1 +/*Return the state transition function for property X, event E*/ +syntax String ::= propXEventE(Int, String) [function] +syntax String ::= printIntArr(List) [function] +syntax String ::= stateTransitionPropXEventE(Int, String, List) [function] + + endmodule \ No newline at end of file From 2f8fc30a63284b633ea455e7e6c9d4466e305a93 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Fri, 22 Apr 2016 23:20:29 -0500 Subject: [PATCH 105/160] save work --- src/helper/code-gen.k | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index b2c6560..bdbfc11 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -8,10 +8,15 @@ module CODE-GEN syntax String ::= staticIntPrefix(String) [function] rule staticIntPrefix(S:String) => "static int " +String S +syntax String ::= const(String) [function] +rule const(S:String) => "const " +String S + +syntax String ::= propPrefix(Int) [function] +rule propPrefix(I:Int) => "Prop_" +String Int2String(I) +String "_" + //the code for resetting global state var i syntax String ::= resetGlobalStateI(Int) [function] -rule resetGlobalStateI(I:Int) => "Prop_" +String - Int2String(I) +String "_RVC_state = 0;\n" +rule resetGlobalStateI(I:Int) => propPrefix(I) +String "RVC_state = 0;\n" syntax String ::= getGlobalStateVarInit(Int) [function] rule getGlobalStateVarInit(I:Int) => staticIntPrefix(resetGlobalStateI(I)) @@ -32,10 +37,16 @@ rule resetGlobalStateI(I:Int) => "Prop_" +String rule resetGlobalStates(I:Int) => resetGlobalStates(I -Int 1) +String resetGlobalStateI(I -Int 1) when I >Int 1 -/*Return the state transition function for property X, event E*/ -syntax String ::= propXEventE(Int, String) [function] +/*Return the state transition function for Spec S, property X, event E, given that +the spec does not have multiple properties*/ +syntax String ::= propXEventE(String, Int, String) [function] +/*The version for spec without extra properties: spec name s and event name e*/ +syntax String ::= propXEventE(String, String) [function] + syntax String ::= printIntArr(List) [function] -syntax String ::= stateTransitionPropXEventE(Int, String, List) [function] +syntax String ::= stateTransitionPropXEventE(Int, String, String, List) [function] + +//rule propXEventE(S:String, X:Int, E:String) => endmodule \ No newline at end of file From ebfad40d639e9defa9512e74073d3baa40ebee21 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 08:03:28 -0500 Subject: [PATCH 106/160] add function for printing state transition function --- src/helper/code-gen.k | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index bdbfc11..27a30cb 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -11,12 +11,12 @@ rule staticIntPrefix(S:String) => "static int " +String S syntax String ::= const(String) [function] rule const(S:String) => "const " +String S -syntax String ::= propPrefix(Int) [function] -rule propPrefix(I:Int) => "Prop_" +String Int2String(I) +String "_" +syntax String ::= propertyPrefix(Int) [function] +rule propertyPrefix(I:Int) => "Prop_" +String Int2String(I) +String "_" //the code for resetting global state var i syntax String ::= resetGlobalStateI(Int) [function] -rule resetGlobalStateI(I:Int) => propPrefix(I) +String "RVC_state = 0;\n" +rule resetGlobalStateI(I:Int) => propertyPrefix(I) +String "RVC_state = 0;\n" syntax String ::= getGlobalStateVarInit(Int) [function] rule getGlobalStateVarInit(I:Int) => staticIntPrefix(resetGlobalStateI(I)) @@ -37,16 +37,41 @@ rule resetGlobalStateI(I:Int) => propPrefix(I) +String "RVC_state = 0;\n" rule resetGlobalStates(I:Int) => resetGlobalStates(I -Int 1) +String resetGlobalStateI(I -Int 1) when I >Int 1 -/*Return the state transition function for Spec S, property X, event E, given that -the spec does not have multiple properties*/ +///////////////////Get the code of state transition functions/////////////////////// + +/*Return the state transition function for Spec S, property X, event E*/ syntax String ::= propXEventE(String, Int, String) [function] -/*The version for spec without extra properties: spec name s and event name e*/ +/*The version for spec which only has one property: the args are spec name s and event name e*/ syntax String ::= propXEventE(String, String) [function] +rule propXEventE(SpecName:String, X:Int, EventName:String) => + SpecName +String "_" +String propertyPrefix(X) +String EventName + +rule propXEventE(SpecName:String, EventName:String) => + SpecName +String "_" +String EventName + syntax String ::= printIntArr(List) [function] -syntax String ::= stateTransitionPropXEventE(Int, String, String, List) [function] +syntax String ::= addCurlyBraces(String) [function] +syntax String ::= printIntSeq(List) [function] + +rule addCurlyBraces(S:String) => "{" +String S +String "}" + +rule printIntSeq(.List) => "" +rule printIntSeq(ListItem(I:Int)) => Int2String(I) +rule printIntSeq(ListItem(I:Int) L:List) => Int2String(I) +String ", " +String printIntSeq(L) +rule printIntArr(L:List) => addCurlyBraces(printIntSeq(L)) + +syntax String ::= stateTransitionPropXEventE(String, Int, String, List) [function] +//only one property in the spec +syntax String ::= stateTransitionPropXEventE(String, String, List) [function] -//rule propXEventE(S:String, X:Int, E:String) => +rule stateTransitionPropXEventE(Spec:String, X:Int, Event:String, L:List) + => const(staticIntPrefix(propXEventE(Spec, X, Event))) +String "[] = " +String + printIntArr(L) +String ";" +rule stateTransitionPropXEventE(Spec:String, Event:String, L:List) + => const(staticIntPrefix(propXEventE(Spec, Event))) +String "[] = " +String + printIntArr(L) +String ";" + endmodule \ No newline at end of file From 6211e396820da72fd5c35f1d4695ef767e01e716 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 11:16:39 -0500 Subject: [PATCH 107/160] debug --- .../c-monitor-template.k | 47 +++++++++++++++++++ src/helper/code-gen.k | 19 ++++---- src/helper/print-ast.k | 2 +- src/helper/util.k | 12 ++++- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index d660f2d..a555852 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -88,4 +88,51 @@ rule rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(0, 0, P, E) $main4) +//gen the state transition function from the structure + rule (.StateTransitions $main4) => $main4 + +//print transition function (multiple properties in one spec) + rule + (($sFunc(I:Int, J:Int):StateFunc, L:StateTransitions) $main4) => (L $main4) + EL:List + X:Id + + ... + + I + M:Map + IA:List + + ... + + SN:String + PS:Int + Code:List (.List => + ListItem(stateTransitionPropXEventE(SN, I, Id2String(X), IA))) +when + //getStringI(EL, J) ==String Id2String(X) andBool + PS >Int 1 + +//single property + rule + (($sFunc(I:Int, J:Int):StateFunc, L:StateTransitions) $main4) => (L $main4) + EL:List + X:Id + + ... + + I + M:Map + IA:List + + ... + + SN:String + PS:Int + Code:List (.List => + ListItem(stateTransitionPropXEventE(SN, Id2String(X), IA))) +when getStringI(EL, J) ==String Id2String(X) + andBool PS <=Int 1 + + endmodule \ No newline at end of file diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 27a30cb..8e93985 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -6,10 +6,10 @@ module CODE-GEN imports DOMAINS-SYNTAX syntax String ::= staticIntPrefix(String) [function] -rule staticIntPrefix(S:String) => "static int " +String S +rule staticIntPrefix(Str:String) => "static int " +String Str -syntax String ::= const(String) [function] -rule const(S:String) => "const " +String S +syntax String ::= constPrefix(String) [function] +rule constPrefix(Str:String) => "const " +String Str syntax String ::= propertyPrefix(Int) [function] rule propertyPrefix(I:Int) => "Prop_" +String Int2String(I) +String "_" @@ -54,24 +54,25 @@ syntax String ::= printIntArr(List) [function] syntax String ::= addCurlyBraces(String) [function] syntax String ::= printIntSeq(List) [function] -rule addCurlyBraces(S:String) => "{" +String S +String "}" +rule addCurlyBraces(Str:String) => ("{" +String Str +String "}") rule printIntSeq(.List) => "" rule printIntSeq(ListItem(I:Int)) => Int2String(I) rule printIntSeq(ListItem(I:Int) L:List) => Int2String(I) +String ", " +String printIntSeq(L) rule printIntArr(L:List) => addCurlyBraces(printIntSeq(L)) +//args are spec name, property rank, event name and transition function array syntax String ::= stateTransitionPropXEventE(String, Int, String, List) [function] //only one property in the spec syntax String ::= stateTransitionPropXEventE(String, String, List) [function] rule stateTransitionPropXEventE(Spec:String, X:Int, Event:String, L:List) - => const(staticIntPrefix(propXEventE(Spec, X, Event))) +String "[] = " +String - printIntArr(L) +String ";" + => (constPrefix(staticIntPrefix(propXEventE(Spec, X, Event))) + +String "[]= " +String printIntArr(L) +String ";") rule stateTransitionPropXEventE(Spec:String, Event:String, L:List) - => const(staticIntPrefix(propXEventE(Spec, Event))) +String "[] = " +String - printIntArr(L) +String ";" + => (constPrefix(staticIntPrefix(propXEventE(Spec, Event))) +String "[] = " + +String printIntArr(L) +String ";") + - endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 6062636..8c8ed5a 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -52,7 +52,7 @@ rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) //the first two args are the current prop rank and event rank, the third and fourth args are the //total number of properties and events resp. syntax StateTransitions ::= getListofStateFuncs(Int, Int, Int, Int) [function] -rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => .List +rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => .StateTransitions when I >=Int PN rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => getListofStateFuncs(I +Int 1, 0, PN, EN) diff --git a/src/helper/util.k b/src/helper/util.k index 29b1ce3..7acba92 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -58,8 +58,16 @@ rule getMapI(ListItem(M:Map) L:List, I:Int) => .Map when I getMapI(L, I -Int 1) when I >Int 0 - - +//get the no. i string in a string list +syntax String ::= getStringI(List, Int) [function] +rule getStringI(.List, I:Int) => "" +rule getStringI(ListItem(Str:String), 0) => Str +rule getStringI(ListItem(Str:String), I:Int) => "" when I =/=Int 0 + +rule getStringI(ListItem(Str:String) L:List, 0) => Str +rule getStringI(ListItem(Str:String) L:List, I:Int) => "" when I + getStringI(L, I -Int 1) when I >Int 0 endmodule From d736eef6563b053788473830620fb1c087e34139 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 16:37:27 -0500 Subject: [PATCH 108/160] state transition function encoded as int array --- .../c-monitor-template-syntax.k | 4 +++- src/c-monitor-code-template/c-monitor-template.k | 2 +- src/helper/print-ast.k | 2 +- src/helper/util.k | 12 ++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 2693c4c..e3e2579 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -39,8 +39,10 @@ syntax ResetFunc ::= "$reset" //the state functions are indexed by property rank and event rank syntax StateTransitions ::= "$stateFuncs" "(" Int "," Int ")" -syntax StateTransitions ::= List{StateFunc, ","} syntax StateFunc ::= "$sFunc" "(" Int "," Int ")" +syntax StateTransitions ::= StateFunc + | StateFunc "," StateTransitions + | "$emptyTransition" syntax EventActions ::= "$eventFuncs" "(" Int ")" syntax EventActions ::= List{EventFunc, ","} diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index a555852..f805011 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -110,7 +110,7 @@ rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(0, 0, P, E) Code:List (.List => ListItem(stateTransitionPropXEventE(SN, I, Id2String(X), IA))) when - //getStringI(EL, J) ==String Id2String(X) andBool + (getStringI(EL, J) ==String Id2String(X)) andBool PS >Int 1 //single property diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 8c8ed5a..bcd4a2b 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -52,7 +52,7 @@ rule sizeOf(Prop:PropertyDec Props:PropertyDecList) => 1 +Int sizeOf(Props) //the first two args are the current prop rank and event rank, the third and fourth args are the //total number of properties and events resp. syntax StateTransitions ::= getListofStateFuncs(Int, Int, Int, Int) [function] -rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => .StateTransitions +rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => $emptyTransition when I >=Int PN rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => getListofStateFuncs(I +Int 1, 0, PN, EN) diff --git a/src/helper/util.k b/src/helper/util.k index 7acba92..7a439e8 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -58,15 +58,15 @@ rule getMapI(ListItem(M:Map) L:List, I:Int) => .Map when I getMapI(L, I -Int 1) when I >Int 0 -//get the no. i string in a string list +//get the no. i id name in an id list syntax String ::= getStringI(List, Int) [function] rule getStringI(.List, I:Int) => "" -rule getStringI(ListItem(Str:String), 0) => Str -rule getStringI(ListItem(Str:String), I:Int) => "" when I =/=Int 0 +rule getStringI(ListItem(X:Id), 0) => Id2String(X) +rule getStringI(ListItem(X:Id), I:Int) => "" when I =/=Int 0 -rule getStringI(ListItem(Str:String) L:List, 0) => Str -rule getStringI(ListItem(Str:String) L:List, I:Int) => "" when I +rule getStringI(ListItem(X:Id) L:List, 0) => Id2String(X) +rule getStringI(ListItem(X:Id) L:List, I:Int) => "" when I getStringI(L, I -Int 1) when I >Int 0 From badf9c49d771bba0819b4f89cae3f5b002ee630e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 16:40:17 -0500 Subject: [PATCH 109/160] resolve symbol --- src/c-monitor-code-template/c-monitor-template.k | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index f805011..dfd7dcb 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -89,7 +89,7 @@ rule rule ($stateFuncs(P:Int, E:Int) $main4) => (getListofStateFuncs(0, 0, P, E) $main4) //gen the state transition function from the structure - rule (.StateTransitions $main4) => $main4 + rule ($emptyTransition $main4) => $main4 //print transition function (multiple properties in one spec) rule From dcf5a75355a6e3e2f2d73e62254529d2366da2dd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 20:05:13 -0500 Subject: [PATCH 110/160] fix bug in windows --- src/helper/util.k | 14 +++++++------- src/rvm/rvm-compiler.k | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/helper/util.k b/src/helper/util.k index 7a439e8..db7ae45 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -44,8 +44,8 @@ rule getSize(ListItem(M:Map) L:List, I:Int) => 0 when I false -rule isLastItem(ListItem(X:Id), Y:Id) => Id2String(X) ==String Id2String(Y) -rule isLastItem(ListItem(X:Id) L:List, Y:Id) => isLastItem(L, Y) +rule isLastItem(ListItem(X:String), Y:Id) => X ==String Id2String(Y) +rule isLastItem(ListItem(X:String) L:List, Y:Id) => isLastItem(L, Y) //get the no. i map in the map list syntax Map ::= getMapI(List, Int) [function] @@ -61,12 +61,12 @@ rule getMapI(ListItem(M:Map) L:List, I:Int) => //get the no. i id name in an id list syntax String ::= getStringI(List, Int) [function] rule getStringI(.List, I:Int) => "" -rule getStringI(ListItem(X:Id), 0) => Id2String(X) -rule getStringI(ListItem(X:Id), I:Int) => "" when I =/=Int 0 +rule getStringI(ListItem(X:String), 0) => X +rule getStringI(ListItem(X:String), I:Int) => "" when I =/=Int 0 -rule getStringI(ListItem(X:Id) L:List, 0) => Id2String(X) -rule getStringI(ListItem(X:Id) L:List, I:Int) => "" when I +rule getStringI(ListItem(X:String) L:List, 0) => X +rule getStringI(ListItem(X:String) L:List, I:Int) => "" when I getStringI(L, I -Int 1) when I >Int 0 diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 588f54f..92b3782 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -43,14 +43,14 @@ Props:PropertyDecList} */ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} - L:List (.List => ListItem(X)) + L:List (.List => ListItem(Id2String(X))) ... (.Bag => - X + X:Id PS -Int 1 @@ -64,7 +64,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) PS:Int .K => PS -Int 1 -when notBool (X in L) +when notBool (Id2String(X) in L) //construct initial props cells @@ -102,7 +102,7 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList) Props:PropertyDecList} => .K EL:List (.List => ListItem("Duplicate event " +String Id2String(X))) ErrList:List -when (X in EL) +when (Id2String(X) in EL) //No events left rule From 384955d1d9910b33492b85a9bd13d078c47bb66f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 21:22:59 -0500 Subject: [PATCH 111/160] update --- .../c-monitor-template.k | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index dfd7dcb..96fcdc1 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -32,18 +32,20 @@ rule $incl $main => $main ///////// - rule $main => $globalInit(PS) $main1 - PS:Int - - //rewrite the global var declarations. -rule $globalInit(0) $main1 => $main1 + rule $main => $globalInit(0) $main1 -rule ($globalInit(I:Int) $main1) => ($globalInit(I -Int 1) $main1) +rule $globalInit(P:Int) $main1 => $main1 + PS:Int +when P >=Int PS + +rule ($globalInit(I:Int) $main1) => ($globalInit(I +Int 1) $main1) - L:List (.List => ListItem(getGlobalStateVarInit(I -Int 1))) -when I >Int 0 + L:List (.List => ListItem(getGlobalStateVarInit(I))) + PS:Int +when I $pStates(0) $main2 rule $pStates(I:Int) $main2 => $main2 From 379d8075cd762559b6fd36dd42f25964777df2cd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sat, 23 Apr 2016 21:56:26 -0500 Subject: [PATCH 112/160] local state vars initialization --- .../c-monitor-template.k | 6 +++++- src/helper/code-gen.k | 11 ++++++++++ test/rvm/Test4.rvm | 20 +++++++++---------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 96fcdc1..e2ac1f6 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -73,7 +73,11 @@ rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => (($localInit(R, J):$pStates(P)) $main2) StateMap:Map - (.List => ListItem(getStrKey(StateMap, I))) L:List + SpecName:String +//localStateVarInit(SpecName:String, R:Int, StateName:String) +//state name: getStrKey(StateMap, I) + (.List => ListItem(localStateVarInit(SpecName, R, getStrKey(StateMap, I)))) + L:List rule $main2 => $reset $main3 diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 8e93985..d6f04bd 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -37,6 +37,17 @@ rule resetGlobalStateI(I:Int) => propertyPrefix(I) +String "RVC_state = 0;\n" rule resetGlobalStates(I:Int) => resetGlobalStates(I -Int 1) +String resetGlobalStateI(I -Int 1) when I >Int 1 +//////////////////////////////////////////////////////////////////////////////////// +///////////////The code for local state var initialization +//the three args are spec name, property rank and state name +syntax String ::= localStateVarI(String, Int, String) [function] +rule localStateVarI(SpecName:String, P:Int, StateName:String) => + SpecName +String "_" +String propertyPrefix(P) +String StateName + +syntax String ::= localStateVarInit(String, Int, String) [function] +rule localStateVarInit(SpecName:String, P:Int, StateName:String) => + ("int " +String localStateVarI(SpecName:String, P:Int, StateName:String) + +String " = 0;") ///////////////////Get the code of state transition functions/////////////////////// /*Return the state transition function for Spec S, property X, event E*/ diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index e667e08..135cd74 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -30,20 +30,20 @@ Test (int o){ fsm : - start [ - next -> unsafe - hasnext -> safe + start2 [ + next -> unsafe2 + hasnext -> safe2 ] - safe [ - next -> start - hasnext -> safe + safe2 [ + next -> start2 + hasnext -> safe2 ] - unsafe [ - next -> unsafe - hasnext -> safe + unsafe2 [ + next -> unsafe2 + hasnext -> safe2 ] - @unsafe { + @unsafe2 { int k; } From 39469f0b3f5e54a5fe33bff7630febac44dde6a2 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 14:01:29 -0500 Subject: [PATCH 113/160] event action module --- .../c-monitor-event-action.k | 24 +++++++++++++++++++ .../c-monitor-template-syntax.k | 6 +++-- .../c-monitor-template.k | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/c-monitor-code-template/c-monitor-event-action.k diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k new file mode 100644 index 0000000..b815971 --- /dev/null +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -0,0 +1,24 @@ +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 $main4 => $eventFuncs(size(EL)) + EL:List + + rule $eventFuncs(I:Int) => $eFunc(0) $eventFuncs(I -Int 1) + when I >Int 0 + + rule $eventFuncs(I:Int) => .K + when I <=Int 0 + + rule $eFunc(I:Int) $eventFuncs(0) => .K + EL:List + when I >=Int size(EL) +endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index e3e2579..78c875e 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -45,7 +45,9 @@ syntax StateTransitions ::= StateFunc | "$emptyTransition" syntax EventActions ::= "$eventFuncs" "(" Int ")" -syntax EventActions ::= List{EventFunc, ","} -syntax EventFunc ::= "eFunc" "(" Int ")" +syntax EventFunc ::= "$eFunc" "(" Int ")" +syntax EventActions ::= EventFunc + | EventFunc "," EventActions + | "$emptyEventActions" endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index e2ac1f6..35f8fd0 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -3,9 +3,13 @@ require "c-monitor-template-syntax.k" require "../helper/code-gen.k" require "../helper/util.k" +require "c-monitor-event-action.k" + module C-MONITOR-TEMPLATE imports RVM-COMPILER-CORE imports C-MONITOR-TEMPLATE-SYNTAX + imports C-MONITOR-EVENT-ACTION + imports CODE-GEN imports UTIL From e96481a78dc17a128feb2eb7c9fe7f1b33035f10 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 14:15:10 -0500 Subject: [PATCH 114/160] make it compile --- src/c-monitor-code-template/c-monitor-event-action.k | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index b815971..57cdaef 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -12,13 +12,13 @@ module C-MONITOR-EVENT-ACTION rule $main4 => $eventFuncs(size(EL)) EL:List - rule $eventFuncs(I:Int) => $eFunc(0) $eventFuncs(I -Int 1) + rule $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I -Int 1)) when I >Int 0 rule $eventFuncs(I:Int) => .K when I <=Int 0 - rule $eFunc(I:Int) $eventFuncs(0) => .K + rule $eFunc(I:Int), $eventFuncs(0) => .K EL:List when I >=Int size(EL) endmodule \ No newline at end of file From 671ae8de98d4ae6d7086e13a3566ae5873050de1 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 18:06:25 -0500 Subject: [PATCH 115/160] define structures of event action method --- .../c-monitor-event-action.k | 12 +++++-- .../c-monitor-template-syntax.k | 33 +++++++++++++++---- src/rvm/rvm-compiler-core.k | 1 + 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 57cdaef..17750da 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -12,13 +12,19 @@ module C-MONITOR-EVENT-ACTION rule $main4 => $eventFuncs(size(EL)) EL:List - rule $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I -Int 1)) + rule $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I)) when I >Int 0 rule $eventFuncs(I:Int) => .K when I <=Int 0 rule $eFunc(I:Int), $eventFuncs(0) => .K - EL:List - when I >=Int size(EL) + + rule $eFunc(I:Int), $eventFuncs(J:Int) => $eFunc(I +Int 1), $eventFuncs(J -Int 1) + .K => $eFunc(I) + _ => .List + when J >Int 0 + + rule $eFunc(I:Int) => $methHeader(I) {$mbody} + endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 78c875e..07b4557 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -11,7 +11,7 @@ syntax MainBody ::= GlobalStatesInit MainBody1 syntax MainBody1 ::= PropStatesInit MainBody2 syntax MainBody2 ::= ResetFunc MainBody3 syntax MainBody3 ::= StateTransitions MainBody4 -syntax MainBody4 ::= EventActions +syntax MainBody4 ::= EventMethods syntax CTemplate ::= "$CMonitor" syntax Include ::= "$incl" @@ -44,10 +44,31 @@ syntax StateTransitions ::= StateFunc | StateFunc "," StateTransitions | "$emptyTransition" -syntax EventActions ::= "$eventFuncs" "(" Int ")" -syntax EventFunc ::= "$eFunc" "(" Int ")" -syntax EventActions ::= EventFunc - | EventFunc "," EventActions - | "$emptyEventActions" +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 ")" + +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" + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 1afb001..a1f4c1e 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -104,6 +104,7 @@ module RVM-COMPILER-CORE "c" //the default target language for the generated monitor code .List .List //temporary cell for manipulation. + .K false From fc96f2ccb023f6d6014d51e1e11e540ef1d0645e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 20:10:34 -0500 Subject: [PATCH 116/160] update --- src/c-monitor-code-template/c-monitor-event-action.k | 4 ++++ src/helper/util.k | 2 +- src/rvm/rvm-compiler-core.k | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 17750da..d07129f 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -27,4 +27,8 @@ module C-MONITOR-EVENT-ACTION rule $eFunc(I:Int) => $methHeader(I) {$mbody} + //print method header + rule $methHeader(I:Int) {$mbody} => $mbody + EL:List + endmodule \ No newline at end of file diff --git a/src/helper/util.k b/src/helper/util.k index db7ae45..0a4ff67 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -58,7 +58,7 @@ rule getMapI(ListItem(M:Map) L:List, I:Int) => .Map when I getMapI(L, I -Int 1) when I >Int 0 -//get the no. i id name in an id list +//get the no. i id name in a string list syntax String ::= getStringI(List, Int) [function] rule getStringI(.List, I:Int) => "" rule getStringI(ListItem(X:String), 0) => X diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index a1f4c1e..664d89a 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -41,6 +41,10 @@ module RVM-COMPILER-CORE .K .List //list of event name strings + //the params of each event, indexed by event id + .List + //the list of event action code, indexed by event id. + .List "" .Params From a0b77dc52b5bbcbdeba9fcf4c5572843141d094f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 20:54:37 -0500 Subject: [PATCH 117/160] code stub for printing event methods' params and action code --- .../c-monitor-event-action.k | 4 ++-- src/helper/print-ast.k | 18 ++++++++++++++++++ src/rvm/rvm-compiler.k | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index d07129f..33e6d69 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -28,7 +28,7 @@ module C-MONITOR-EVENT-ACTION rule $eFunc(I:Int) => $methHeader(I) {$mbody} //print method header - rule $methHeader(I:Int) {$mbody} => $mbody - EL:List +// rule $methHeader(I:Int) {$mbody} => $mbody +// EL:List endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index bcd4a2b..63449b8 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -62,5 +62,23 @@ rule getListofStateFuncs(I:Int, J:Int, PN:Int, EN:Int) => ($sFunc(I, J):StateFunc , getListofStateFuncs(I, J +Int 1, PN, EN)) when I "" +rule Params2Str(P:Param) => Param2Str(P) +rule Params2Str(P:Param, Ps:Params) => Param2Str(P) +String ", " +String Params2Str(Ps) + +rule Param2Str(P:Param) => "SingleParam!" //TODO + +/** +Print the method body. +*/ +syntax String ::= Block2Str(BlockBubble) [function] + +rule Block2Str(B:BlockBubble) => "BlockStmt!" //TODO endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 92b3782..0a745a2 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -45,6 +45,11 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} L:List (.List => ListItem(Id2String(X))) +//the params of each event, indexed by event id + EP:List (.List => ListItem(Params2Str(Ps))) +//the list of event action code, indexed by event id. + EA:List (.List => ListItem(Block2Str(Body))) + ... From e386b6297adce94acc7705a21bda75d3f4e43caa Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 22:05:20 -0500 Subject: [PATCH 118/160] debug --- src/common/type-syntax.k | 2 +- src/helper/print-ast.k | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index 0164234..1628ee9 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -22,7 +22,7 @@ module TYPE-SYNTAX syntax Dim ::= "[" "]" syntax Dims ::= List{Dim, ""} - syntax ArrayType ::= Type "[" "]" + syntax ArrayType ::= Type "[]" // "[" "]" syntax Type ::= TypeName | ArrayType syntax VarDecId ::= Id Dims diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 63449b8..375cb11 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -67,12 +67,35 @@ when I "" rule Params2Str(P:Param) => Param2Str(P) +rule Params2Str(P:Param, .Params) => Param2Str(P) rule Params2Str(P:Param, Ps:Params) => Param2Str(P) +String ", " +String Params2Str(Ps) -rule Param2Str(P:Param) => "SingleParam!" //TODO +rule Param2Str(T:Type V:VarDecId) => Type2Str(T) +String " " +String VarDecId2Str(V) + +//Type ::= TypeName | ArrayType +syntax String ::= TypeName2String(TypeName) [function] +syntax String ::= ArrayType2String(ArrayType) [function] + +rule Type2Str(T:TypeName) => TypeName2String(T) +rule Type2Str(AT:ArrayType) => ArrayType2String(AT) + +rule TypeName2String(X:Id) => Id2String(X) +rule TypeName2String(T:TypeName . X:Id) => TypeName2String(T) +String "." +String Id2String(X) + +rule ArrayType2String(T:Type []) => Type2Str(T) +String "[]" + +//VarDecId ::= Id Dims +syntax String ::= Dims2Str(Dims) +rule VarDecId2Str(X:Id .Dims) => Id2String(X) +rule VarDecId2Str(X:Id Ds:Dims) => Id2String(X) +String Dims2Str(Ds) +rule Dims2Str(.Dims) => "" +rule Dims2Str(D:Dim) => "[]" +rule Dims2Str(D:Dim Ds:Dims) => "[]" +String Dims2Str(Ds) /** Print the method body. From f2a502df631e7f104f0e393192d399ea83b2a8c6 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Sun, 24 Apr 2016 22:15:07 -0500 Subject: [PATCH 119/160] change the syntax of Dim, Dims and ArrayType --- src/common/type-syntax.k | 8 ++++---- src/helper/print-ast.k | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/type-syntax.k b/src/common/type-syntax.k index 1628ee9..a23a3c3 100644 --- a/src/common/type-syntax.k +++ b/src/common/type-syntax.k @@ -20,12 +20,12 @@ module TYPE-SYNTAX syntax IdList ::= List{Id,"."} [klabel('IdList)] - syntax Dim ::= "[" "]" - syntax Dims ::= List{Dim, ""} - syntax ArrayType ::= Type "[]" // "[" "]" + syntax Dim ::= "[]" + syntax Dims ::= Dim | Dim Dims + syntax ArrayType ::= Type Dim // "[" "]" syntax Type ::= TypeName | ArrayType - syntax VarDecId ::= Id Dims + syntax VarDecId ::= Id | Id Dims syntax Param ::= Type VarDecId syntax Params ::= List{Param, ","} [klabel('FormalParamList)] diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 375cb11..765d5bb 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -91,9 +91,8 @@ rule ArrayType2String(T:Type []) => Type2Str(T) +String "[]" //VarDecId ::= Id Dims syntax String ::= Dims2Str(Dims) -rule VarDecId2Str(X:Id .Dims) => Id2String(X) +rule VarDecId2Str(X:Id) => Id2String(X) rule VarDecId2Str(X:Id Ds:Dims) => Id2String(X) +String Dims2Str(Ds) -rule Dims2Str(.Dims) => "" rule Dims2Str(D:Dim) => "[]" rule Dims2Str(D:Dim Ds:Dims) => "[]" +String Dims2Str(Ds) From 8cb96d4894173e4badaadf6ef45a3d7afc9af0ae Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 05:30:09 -0500 Subject: [PATCH 120/160] empty block ok --- .../c-monitor-event-action.k | 2 +- .../c-monitor-template.k | 11 +++--- src/common/java-bubble-syntax.k | 4 ++- src/rvm/rvm-compiler-core.k | 12 ++++--- src/rvm/rvm-compiler.k | 36 ++++++++++++++----- test/cmop/test.k | 6 ++-- test/rvm/Test4.rvm | 2 +- 7 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 33e6d69..2772219 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -22,7 +22,7 @@ module C-MONITOR-EVENT-ACTION rule $eFunc(I:Int), $eventFuncs(J:Int) => $eFunc(I +Int 1), $eventFuncs(J -Int 1) .K => $eFunc(I) - _ => .List + _ => .List when J >Int 0 rule $eFunc(I:Int) => $methHeader(I) {$mbody} diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 35f8fd0..8abe71d 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -16,8 +16,9 @@ module C-MONITOR-TEMPLATE rule "c" false - true => false - _:K => $CMonitor + X:Int + X:Int => X +Int 1 + .K => $CMonitor rule @@ -65,7 +66,7 @@ rule $pStates(I:Int) $main2 => ($localInit(I, getSize(L, I)) : $pStates(I +I //*handling the local state vars initializations. */ rule ($localInit(R:Int, 0):$pStates(I:Int) $main2) => ($pStates(I) $main2) - L:List => .List //the local state vars are stored in tmp cell + L:List => .List //the local state vars are stored in tmp cell C:List (.List => L) rule ($localInit(R:Int, I:Int):$pStates(P:Int) $main2) => @@ -80,8 +81,8 @@ rule (($sVar(R:Int, I:Int), $localInit(R, J:Int)):$pStates(P:Int) $main2) => SpecName:String //localStateVarInit(SpecName:String, R:Int, StateName:String) //state name: getStrKey(StateMap, I) - (.List => ListItem(localStateVarInit(SpecName, R, getStrKey(StateMap, I)))) - L:List + (.List => ListItem(localStateVarInit(SpecName, R, getStrKey(StateMap, I)))) + L:List rule $main2 => $reset $main3 diff --git a/src/common/java-bubble-syntax.k b/src/common/java-bubble-syntax.k index aa91e3d..1f760e3 100644 --- a/src/common/java-bubble-syntax.k +++ b/src/common/java-bubble-syntax.k @@ -5,11 +5,13 @@ module JAVA-BUBBLE-SYNTAX //syntax NoBracket ::= r"[^{}]+" [token] //temp workaround for https://github.com/kframework/k/issues/1863 syntax NoBracket //::= r"[^<{}][^{}]*" [token, klabel('NoBracket)] + syntax EmptyBlock ::= "{" "}" [token, klabel(EmptyBlockLabel)] + syntax BalancedBracket ::= "{" BalancedBracket "}" [klabel('BBracketBlock)] | BalancedBracket BalancedBracket [left, klabel('BBracketCombination)] | NoBracket [klabel('BBracketAtom)] - | "{" "}" [klabel('BBracketEmpty)] + | EmptyBlock syntax BlockBubble //::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] // | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 664d89a..ba9dc8f 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -19,7 +19,7 @@ module RVM-COMPILER-SYNTAX | FieldDecBubble [token, klabel('DecBubbleField)] syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] - | "{" "}" [prefer, token, klabel('BlockBubbleEmpty)] + | EmptyBlock @@ -35,7 +35,11 @@ endmodule module RVM-COMPILER-CORE imports RVM-SYNTAX - configuration $PGM:RVM + configuration + 0 + + $PGM:RVM + "" .K @@ -107,9 +111,9 @@ module RVM-COMPILER-CORE ///////////////////////////////Code Generation////////////////////////////////////////////////// "c" //the default target language for the generated monitor code .List - .List //temporary cell for manipulation. + "" + .List //temporary cell for manipulation. .K - false endmodule diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 0a745a2..b2dbefd 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -41,14 +41,17 @@ Props:PropertyDecList} /** * Extract and store the first event in the event list if we haven't encountered it before. */ -rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) +rule + 0 + {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} L:List (.List => ListItem(Id2String(X))) //the params of each event, indexed by event id EP:List (.List => ListItem(Params2Str(Ps))) -//the list of event action code, indexed by event id. - EA:List (.List => ListItem(Block2Str(Body))) + + .K => Body + "" ... @@ -71,7 +74,6 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) when notBool (Id2String(X) in L) - //construct initial props cells rule L:List @@ -95,9 +97,27 @@ rule PS:Int => PS -Int 1 when PS >Int 0 andBool isLastItem(L, X) - rule 0 => .K +//////////////////////////////////////////////////////////////////////////////////////// +/*Convert the method body bubble into string*/ +rule 0 +// BB:BlockBubble => .K + EB:EmptyBlock => .K + BodyStr:String => BodyStr +String "{}" + +//////////////////////////////////////////////////////////////////////////////////////// +//Save the method body to the event action list +rule + 0 + .K + BodyStr:String => "" +//the list of event action code, indexed by event id. + EA:List (.List => ListItem(BodyStr)) +when notBool (BodyStr ==String "") +//////////////////////////////////////////////////////////////////////////////////////// + + /** * Report error if an event is defined multiple times. * In case of error, the execution will be terminated and the error info @@ -112,8 +132,9 @@ when (Id2String(X) in EL) //No events left rule {.K (.EventDecList) Props:PropertyDecList} => Props + .K -//add the first property and corresponding handlers +//add the property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props I:Int => I +Int 1 .K => getLogicName(Prop) @@ -121,10 +142,9 @@ rule Prop:PropertyDec Props:PropertyDecList => Props .K => getFormula(Prop) .HandlerDecList => getHandlers(Prop) false => true + X:Int => X +Int 1 //No properties left rule .PropertyDecList => . false - false => true - endmodule diff --git a/test/cmop/test.k b/test/cmop/test.k index 9a775db..752065c 100644 --- a/test/cmop/test.k +++ b/test/cmop/test.k @@ -13,7 +13,7 @@ configuration false .List .Map - .List //temporary cell for manipulation. + .List //temporary cell for manipulation. "HasNext" @@ -49,11 +49,11 @@ rule (($sVar(I:Int), $localInit(J:Int)) M:MainBody2) => (($localInit(J:Int)) M) StateMap:Map - (.List => ListItem(getStrKey(StateMap, I))) L:List + (.List => ListItem(getStrKey(StateMap, I))) L:List rule $reset M:MainBody3 => M SN:String - L:List => .List //the local state vars are stored in tmp cell + L:List => .List //the local state vars are stored in tmp cell Code:List (.List => L) (.List => ListItem(printResetFunc(SN))) endmodule \ No newline at end of file diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index 135cd74..e783c50 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -8,7 +8,7 @@ Test (int o){ } event hasnext(Iterator i) {} // {1, 1, 1, 3} - event next(Iterator i) {} // {2, 0, 2, 3} + event next(Iterator i) { int i = 0; } // {2, 0, 2, 3} fsm : start [ From ab534fba6a3ba6e211851411150f1dc308669f5f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 09:53:56 -0500 Subject: [PATCH 121/160] print bubble successfully! --- src/common/java-bubble-syntax.k | 2 +- src/helper/print-ast.k | 5 ++--- src/rvm/rvm-compiler-core.k | 5 +---- src/rvm/rvm-compiler.k | 23 +---------------------- test/rvm/Test4.rvm | 3 ++- 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/common/java-bubble-syntax.k b/src/common/java-bubble-syntax.k index 1f760e3..84c2fc6 100644 --- a/src/common/java-bubble-syntax.k +++ b/src/common/java-bubble-syntax.k @@ -8,7 +8,7 @@ module JAVA-BUBBLE-SYNTAX syntax EmptyBlock ::= "{" "}" [token, klabel(EmptyBlockLabel)] syntax BalancedBracket ::= - "{" BalancedBracket "}" [klabel('BBracketBlock)] + "{" BalancedBracket "}" [klabel(BBracketBlockLabel)] | BalancedBracket BalancedBracket [left, klabel('BBracketCombination)] | NoBracket [klabel('BBracketAtom)] | EmptyBlock diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 765d5bb..22bed1c 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -99,8 +99,7 @@ rule Dims2Str(D:Dim Ds:Dims) => "[]" +String Dims2Str(Ds) /** Print the method body. */ -syntax String ::= Block2Str(BlockBubble) [function] - -rule Block2Str(B:BlockBubble) => "BlockStmt!" //TODO +syntax String ::= Block2Str(BlockBubble) +[function, hook(STRING.token2string), klabel(Block2StringFunc)] endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index ba9dc8f..d658d13 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -18,13 +18,11 @@ module RVM-COMPILER-SYNTAX | MethodDecBubble [token, klabel('DecBubbleMethod)] | FieldDecBubble [token, klabel('DecBubbleField)] - syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel('BlockBubble)] + syntax BlockBubble ::= "{" BalancedBracket "}" [prefer, token, klabel(BlockBubbleLabel)] | EmptyBlock - - syntax IdPattern ::= //id with * and .. wildcards (it can start with * but not with .. , same about end) // r"(? "c" //the default target language for the generated monitor code .List - "" .List //temporary cell for manipulation. .K diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index b2dbefd..3c4aeff 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -46,13 +46,11 @@ rule {.K ((EM:EventModifier event (X:Id) (Ps:Params) Body:BlockBubble) Events:EventDecList => Events) Props:PropertyDecList} L:List (.List => ListItem(Id2String(X))) + EA:List (.List => ListItem(Block2Str(Body))) //the params of each event, indexed by event id EP:List (.List => ListItem(Params2Str(Ps))) - .K => Body - "" - ... @@ -99,24 +97,6 @@ when PS >Int 0 andBool isLastItem(L, X) rule 0 => .K -//////////////////////////////////////////////////////////////////////////////////////// -/*Convert the method body bubble into string*/ -rule 0 -// BB:BlockBubble => .K - EB:EmptyBlock => .K - BodyStr:String => BodyStr +String "{}" - -//////////////////////////////////////////////////////////////////////////////////////// -//Save the method body to the event action list -rule - 0 - .K - BodyStr:String => "" -//the list of event action code, indexed by event id. - EA:List (.List => ListItem(BodyStr)) -when notBool (BodyStr ==String "") -//////////////////////////////////////////////////////////////////////////////////////// - /** * Report error if an event is defined multiple times. @@ -132,7 +112,6 @@ when (Id2String(X) in EL) //No events left rule {.K (.EventDecList) Props:PropertyDecList} => Props - .K //add the property and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index e783c50..df73059 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -8,7 +8,8 @@ Test (int o){ } event hasnext(Iterator i) {} // {1, 1, 1, 3} - event next(Iterator i) { int i = 0; } // {2, 0, 2, 3} + event next(Iterator i) { int i = 0; {i--;} int j=i+ 2 ; +{{{}}} } // {2, 0, 2, 3} fsm : start [ From f25820c4e3be1aa5adba0a289a2660961a4f8079 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 10:54:46 -0500 Subject: [PATCH 122/160] print event actions --- .../c-monitor-event-action.k | 25 +++++++++++++++++-- src/c-monitor-code-template/seatbelt.c.origin | 3 +-- src/helper/code-gen.k | 6 +++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 2772219..0f7d795 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -28,7 +28,28 @@ module C-MONITOR-EVENT-ACTION rule $eFunc(I:Int) => $methHeader(I) {$mbody} //print method header -// rule $methHeader(I:Int) {$mbody} => $mbody -// EL:List + rule $methHeader(I:Int) {$mbody} => .K + EL:List + SN:String + //the params of each event, indexed by event id + EPs:List + //the list of event action code, indexed by event id. + EAs:List + 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 + + //TODO state updates + //TODO handler code + + (.List => ListItem("\n}\n")) + + + + endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/seatbelt.c.origin b/src/c-monitor-code-template/seatbelt.c.origin index d8700e9..e31d420 100644 --- a/src/c-monitor-code-template/seatbelt.c.origin +++ b/src/c-monitor-code-template/seatbelt.c.origin @@ -36,8 +36,7 @@ if(__RVC_SeatBelt_unsafe) }} } -void -__RVC_SeatBelt_seatBeltAttached() +void __RVC_SeatBelt_seatBeltAttached() { {fprintf(stderr, "Seat belt attached.\n");} __RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index d6f04bd..10bc06d 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -85,5 +85,11 @@ rule stateTransitionPropXEventE(Spec:String, Event:String, L:List) => (constPrefix(staticIntPrefix(propXEventE(Spec, Event))) +String "[] = " +String printIntArr(L) +String ";") +////////////print method header given the spec name, event name and args +syntax String ::= printMethodHeader(String, String, String) [function] +rule printMethodHeader(SpecName:String, EventName:String, Args:String) + => "void __RVC_" +String SpecName +String "_" +String + EventName +String "(" +String Args +String ")" + endmodule \ No newline at end of file From c1e0d8534e6341651fbdc74b5e44fb518a84ef2e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 11:35:08 -0500 Subject: [PATCH 123/160] code stub for gathering handler info --- .../c-monitor-template-syntax.k | 1 + src/logic/semantics/fsm.k | 11 ++++++++--- src/rvm/rvm-compiler-core.k | 6 +++++- src/rvm/rvm-compiler.k | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 07b4557..c3280c6 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -55,6 +55,7 @@ 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 diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index d9731ae..011dda9 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -108,6 +108,12 @@ rule fsm 1 [prefer] +//////////////////////////////////////////////// +///////////collect the handler info + + + + //////////////////////////////////////////////// rule @@ -146,10 +152,9 @@ rule N:Int => 0 _:Int => 0 _:K => .K _:K => .K - + .K SL:List (.List => ListItem(SM)) - //TODO: process the handlers cell - _:HandlerDecList => .HandlerDecList + when N ==Int size(EL) endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index d658d13..f95d975 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -102,7 +102,11 @@ module RVM-COMPILER-CORE ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// - .HandlerDecList + //list of maps indexed by property rank. + //the map element maps state rank to handler code string + .List + + .K .List diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 3c4aeff..e625e4c 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -113,13 +113,14 @@ when (Id2String(X) in EL) rule {.K (.EventDecList) Props:PropertyDecList} => Props -//add the property and corresponding handlers +//add the property formula and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props I:Int => I +Int 1 .K => getLogicName(Prop) .K => getFormula(Prop) .K => getFormula(Prop) - .HandlerDecList => getHandlers(Prop) + .K => getHandlers(Prop) + HL:List (.List => ListItem(.Map)) false => true X:Int => X +Int 1 From 358f6fb8c42619ad32429fbbddb5d5a7cc751b2c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 14:37:05 -0500 Subject: [PATCH 124/160] debug --- src/common/property-syntax.k | 3 ++- src/logic/semantics/fsm.k | 30 +++++++++++++++++++++++++++--- src/rvm/rvm-compiler-core.k | 2 +- test/rvm/Test4.rvm | 4 ++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/common/property-syntax.k b/src/common/property-syntax.k index 555071f..5fd968d 100644 --- a/src/common/property-syntax.k +++ b/src/common/property-syntax.k @@ -11,6 +11,7 @@ module PROPERTY-SYNTAX syntax HandlerDecHead ::= "@" LogicState syntax HandlerBody ::= BlockBubble - syntax HandlerDecList ::= List{HandlerDec, ""} [klabel('HandlerDecList)] + syntax HandlerDecList ::= List{HandlerDec, ""} [klabel(HandlerDecListCons)] + syntax PropertyDecList ::= List{PropertyDec, ""} [klabel('PropertyDecList)] endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 011dda9..0da2932 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -111,9 +111,33 @@ rule fsm //////////////////////////////////////////////// ///////////collect the handler info - - - +//rule +// fsm => ere +// .HandlerDecList => .K +// true +// 1 +// +//rule +// fsm => ere +// HandlerDecListCons(HD:HandlerDec, HDL:HandlerDecList) => HDL +// true +// 1 + +//rule (@ StateName:Id HandlerCode:BlockBubble) => .K +// L:List ListItem(M:Map (.Map => +//(Id2String(StateName) |-> Block2Str(HandlerCode)))) +// +//rule (@fail HandlerCode:BlockBubble) => .K +// L:List ListItem(M:Map (.Map => +//("fail" |-> Block2Str(HandlerCode)))) +// +//rule (@ StateName:Id HandlerCode:BlockBubble) HDL:HandlerDecList => HDL +// L:List ListItem(M:Map (.Map => +//(Id2String(StateName) |-> Block2Str(HandlerCode)))) +// +//rule (@fail HandlerCode:BlockBubble) HDL:HandlerDecList => HDL +// L:List ListItem(M:Map (.Map => +//("fail" |-> Block2Str(HandlerCode)))) //////////////////////////////////////////////// rule diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index f95d975..d7f7378 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -103,7 +103,7 @@ module RVM-COMPILER-CORE /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// //list of maps indexed by property rank. - //the map element maps state rank to handler code string + //the map element maps state name to handler code string .List .K diff --git a/test/rvm/Test4.rvm b/test/rvm/Test4.rvm index df73059..0ed8714 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/Test4.rvm @@ -29,6 +29,10 @@ Test (int o){ int j; } + @unsafe { + System.err.println("It is not safe"); + } + fsm : start2 [ From 77eaefada902ffc19bae8018675ddf83656d688c Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 15:18:38 -0500 Subject: [PATCH 125/160] add handler.txt --- test/rvm/handler.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/rvm/handler.txt diff --git a/test/rvm/handler.txt b/test/rvm/handler.txt new file mode 100644 index 0000000..b7b8fc5 --- /dev/null +++ b/test/rvm/handler.txt @@ -0,0 +1,7 @@ + @start { + int j; + } + + @unsafe { + System.err.println("It is not safe"); + } From 346a92442b3693f8a78edc7f06ccfac0894a18f1 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 26 Apr 2016 22:39:32 -0500 Subject: [PATCH 126/160] update HandlerDecList syntax --- src/common/property-syntax.k | 6 ++++-- test/rvm/Test.rvm | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/property-syntax.k b/src/common/property-syntax.k index 5fd968d..fa723c8 100644 --- a/src/common/property-syntax.k +++ b/src/common/property-syntax.k @@ -4,14 +4,16 @@ require "java-bubble-syntax.k" module PROPERTY-SYNTAX imports LOGIC-SYNTAX imports JAVA-BUBBLE-SYNTAX - syntax PropertyDec ::= Property HandlerDecList + syntax PropertyDec ::= Property | Property HandlerDecList syntax Property ::= LogicName ":" LogicFormula syntax HandlerDec ::= HandlerDecHead HandlerBody syntax HandlerDecHead ::= "@" LogicState syntax HandlerBody ::= BlockBubble - syntax HandlerDecList ::= List{HandlerDec, ""} [klabel(HandlerDecListCons)] + syntax HandlerDecList ::= HandlerDec | HandlerDec HandlerDecList + + //List{HandlerDec, ""} [klabel(HandlerDecListCons)] syntax PropertyDecList ::= List{PropertyDec, ""} [klabel('PropertyDecList)] endmodule \ No newline at end of file diff --git a/test/rvm/Test.rvm b/test/rvm/Test.rvm index 2f19a29..eb60775 100644 --- a/test/rvm/Test.rvm +++ b/test/rvm/Test.rvm @@ -22,7 +22,7 @@ Test (int o){ // alias match = unsafe, start - @match { + @safe { int j; } From b7bf1ad8401fb70d2ef4fab871c7790175448485 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 27 Apr 2016 02:52:14 -0500 Subject: [PATCH 127/160] debug non-termination --- src/common/property-syntax.k | 4 +--- src/helper/print-ast.k | 8 ++++++++ src/logic/semantics/fsm.k | 33 ++++++--------------------------- src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 3 +-- 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/common/property-syntax.k b/src/common/property-syntax.k index fa723c8..9456f91 100644 --- a/src/common/property-syntax.k +++ b/src/common/property-syntax.k @@ -11,9 +11,7 @@ module PROPERTY-SYNTAX syntax HandlerDecHead ::= "@" LogicState syntax HandlerBody ::= BlockBubble - syntax HandlerDecList ::= HandlerDec | HandlerDec HandlerDecList - - //List{HandlerDec, ""} [klabel(HandlerDecListCons)] + syntax HandlerDecList ::= List{HandlerDec, ""} [klabel(HandlerDecListFunc)] syntax PropertyDecList ::= List{PropertyDec, ""} [klabel('PropertyDecList)] endmodule \ No newline at end of file diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 22bed1c..04f5a19 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -102,4 +102,12 @@ Print the method body. syntax String ::= Block2Str(BlockBubble) [function, hook(STRING.token2string), klabel(Block2StringFunc)] +/**Get the state name from a handler dec head.*/ +syntax String ::= getStateNameOf(LogicState) [function] +rule getStateNameOf(fail) => "fail" +rule getStateNameOf(X:Id) => Id2String(X) + +/*Get the string of handler code*/ +syntax String ::= getHandlerCodeStr(HandlerBody) [function] +rule getHandlerCodeStr(BB:BlockBubble) => Block2Str(BB) endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 0da2932..32ad548 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -111,33 +111,12 @@ rule fsm //////////////////////////////////////////////// ///////////collect the handler info -//rule -// fsm => ere -// .HandlerDecList => .K -// true -// 1 -// -//rule -// fsm => ere -// HandlerDecListCons(HD:HandlerDec, HDL:HandlerDecList) => HDL -// true -// 1 - -//rule (@ StateName:Id HandlerCode:BlockBubble) => .K -// L:List ListItem(M:Map (.Map => -//(Id2String(StateName) |-> Block2Str(HandlerCode)))) -// -//rule (@fail HandlerCode:BlockBubble) => .K -// L:List ListItem(M:Map (.Map => -//("fail" |-> Block2Str(HandlerCode)))) -// -//rule (@ StateName:Id HandlerCode:BlockBubble) HDL:HandlerDecList => HDL -// L:List ListItem(M:Map (.Map => -//(Id2String(StateName) |-> Block2Str(HandlerCode)))) -// -//rule (@fail HandlerCode:BlockBubble) HDL:HandlerDecList => HDL -// L:List ListItem(M:Map (.Map => -//("fail" |-> Block2Str(HandlerCode)))) +rule .HandlerDecList => .K + +rule (@LS:LogicState HB:HandlerBody) HDL:HandlerDecList => HDL + L:List (.List => ListItem(getStateNameOf(LS) |-> getHandlerCodeStr(HB) ) ) + + //////////////////////////////////////////////// rule diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index d7f7378..db866d0 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -102,7 +102,7 @@ module RVM-COMPILER-CORE ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// - //list of maps indexed by property rank. + //list of maps //the map element maps state name to handler code string .List diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index e625e4c..77c57a6 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -120,11 +120,10 @@ rule Prop:PropertyDec Props:PropertyDecList => Props .K => getFormula(Prop) .K => getFormula(Prop) .K => getHandlers(Prop) - HL:List (.List => ListItem(.Map)) false => true X:Int => X +Int 1 //No properties left -rule .PropertyDecList => . +rule .PropertyDecList => . false endmodule From 667444f5e240bffb4408cfbb50b910b4cc84e59f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 27 Apr 2016 03:05:52 -0500 Subject: [PATCH 128/160] debug ok --- src/logic/semantics/fsm.k | 4 ++-- src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 32ad548..a7188a7 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -111,7 +111,7 @@ rule fsm //////////////////////////////////////////////// ///////////collect the handler info -rule .HandlerDecList => .K +//rule .HandlerDecList => .K rule (@LS:LogicState HB:HandlerBody) HDL:HandlerDecList => HDL L:List (.List => ListItem(getStateNameOf(LS) |-> getHandlerCodeStr(HB) ) ) @@ -155,7 +155,7 @@ rule N:Int => 0 _:Int => 0 _:K => .K _:K => .K - .K + .HandlerDecList SL:List (.List => ListItem(SM)) when N ==Int size(EL) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index db866d0..1074b53 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -106,7 +106,7 @@ module RVM-COMPILER-CORE //the map element maps state name to handler code string .List - .K + .HandlerDecList .List diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 77c57a6..57f817a 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -119,7 +119,7 @@ rule Prop:PropertyDec Props:PropertyDecList => Props .K => getLogicName(Prop) .K => getFormula(Prop) .K => getFormula(Prop) - .K => getHandlers(Prop) + .HandlerDecList => getHandlers(Prop) false => true X:Int => X +Int 1 From b3f000a47a579558bc96b266028e8471ff7d2f99 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 27 Apr 2016 08:58:00 -0500 Subject: [PATCH 129/160] rewrite part of the main body to an abstract term --- src/c-monitor-code-template/c-monitor-event-action.k | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 0f7d795..85e0149 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -28,7 +28,7 @@ module C-MONITOR-EVENT-ACTION rule $eFunc(I:Int) => $methHeader(I) {$mbody} //print method header - rule $methHeader(I:Int) {$mbody} => .K + rule $methHeader(I:Int) {$mbody} => $mbody2 EL:List SN:String //the params of each event, indexed by event id @@ -42,14 +42,10 @@ module C-MONITOR-EVENT-ACTION (.List => ListItem("{\n")) (.List => ListItem(getStringI(EAs, I))) //the event I's action code + //TODO state updates //TODO handler code - - (.List => ListItem("\n}\n")) - - - - +// (.List => ListItem("\n}\n")) //the closing curly brace endmodule \ No newline at end of file From 081a63ad7b58a3c9d917f8ba6469f8ed2dccf2a7 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 27 Apr 2016 17:31:14 -0500 Subject: [PATCH 130/160] add more structures --- .../c-monitor-template-syntax.k | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index c3280c6..84cfd7e 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -59,7 +59,7 @@ syntax EventAction ::= "$eAction" "(" Int ")" syntax MonitorStateUpdates ::= "$stateUpdates" "(" Int ")" syntax MonitorStateUpdate ::= "$sUpdate" "(" Int ")" syntax MonitorStateUpdates ::= MonitorStateUpdate - | MonitorStateUpdate "," MonitorStateUpdates + | MonitorStateUpdate ",," MonitorStateUpdates syntax HandlerActions ::= "$handlers" @@ -71,5 +71,18 @@ 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 ")" + +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 \ No newline at end of file From 07c25430d0a4fd90e68002054acfcd42ab2c9260 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 27 Apr 2016 20:44:49 -0500 Subject: [PATCH 131/160] update monitor state --- .../c-monitor-event-action.k | 26 ++++++++++++++++++- .../c-monitor-template-syntax.k | 1 + src/helper/util.k | 2 +- src/rvm/rvm-compiler-core.k | 7 ++--- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 85e0149..7baae3f 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -44,7 +44,31 @@ module C-MONITOR-EVENT-ACTION (.List => ListItem(getStringI(EAs, I))) //the event I's action code - //TODO state updates +////////////////////////////////////////////////////////////////////////////// + //state updates + rule $mbody2 => ($stateUpdates(PS) ;; $handlers) + PS:Int + + rule ($stateUpdates(PS:Int) ;; $handlers) => + $sUpdate(0) ,, $stateUpdates(PS) ;; $handlers + + + rule + ($sUpdate(I:Int) ,, $stateUpdates(PS:Int) ;; $handlers) + => $handlers + + when PS <=Int 0 + + rule + ($sUpdate(I:Int) ,, $stateUpdates(PS:Int) ;; $handlers) => + ($sUpdate(I +Int 1) ,, $stateUpdates(PS -Int 1) ;; $handlers) + + + .K => $gsUpdate(I), $lsUpdates(getSize(SML, I)) + SML:List +when PS >Int 0 + + //TODO handler code // (.List => ListItem("\n}\n")) //the closing curly brace diff --git a/src/c-monitor-code-template/c-monitor-template-syntax.k b/src/c-monitor-code-template/c-monitor-template-syntax.k index 84cfd7e..4c52ff8 100644 --- a/src/c-monitor-code-template/c-monitor-template-syntax.k +++ b/src/c-monitor-code-template/c-monitor-template-syntax.k @@ -78,6 +78,7 @@ 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) diff --git a/src/helper/util.k b/src/helper/util.k index 0a4ff67..2600ee1 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -31,7 +31,7 @@ rule getStrKey((S:String |-> V:Int) M:Map, V) => S rule getStrKey((_:String |-> V1:Int) M:Map, V2:Int) => getStrKey(M, V2) when V1 =/=Int V2 -/*Get the size of a list of maps*/ +/*Get the size of the i-th map in the map list*/ syntax Int ::= getSize(List, Int) [function] rule getSize(.List, I:Int) => 0 rule getSize(ListItem(M:Map), 0) => size(M) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 1074b53..94b9c86 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -65,7 +65,8 @@ module RVM-COMPILER-CORE //map a state name(string) to its integer rank, temporary working cell .Map -//states name mapping (string -> int, the map in cell), indexed by property rank. +// Each ListItem is a map from states name to state rank (string -> int), +//indexed by property rank .List 0 @@ -97,8 +98,6 @@ module RVM-COMPILER-CORE .K - .K //additional computation cell - ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// @@ -115,6 +114,8 @@ module RVM-COMPILER-CORE .List .List //temporary cell for manipulation. .K + .K //additional computation cell + endmodule From b60d3e8d163cfe14effecb01536cb43274b864a3 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 13:47:40 -0500 Subject: [PATCH 132/160] update global state --- src/c-monitor-code-template/c-monitor-event-action.k | 11 +++++++++++ src/helper/code-gen.k | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 7baae3f..2b6ff3a 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -43,6 +43,7 @@ module C-MONITOR-EVENT-ACTION (.List => ListItem(getStringI(EAs, I))) //the event I's action code + .List => ListItem(getStringI(EL, I)) ////////////////////////////////////////////////////////////////////////////// //state updates @@ -68,6 +69,16 @@ module C-MONITOR-EVENT-ACTION SML:List when PS >Int 0 +//generate global state update code +rule $gsUpdate(I), $lsUpdates(getSize(SML, I)) => $lsUpdates(getSize(SML, I)) + SN:String + ListItem(EN:String) + C:List (.List => ListItem(globalStateUpdate( +globalStateVarI(I), propXEventE(SN, I, EN)))) + + +//TODO:generate local states update code + //TODO handler code // (.List => ListItem("\n}\n")) //the closing curly brace diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 10bc06d..396d6ad 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -14,9 +14,12 @@ rule constPrefix(Str:String) => "const " +String Str syntax String ::= propertyPrefix(Int) [function] rule propertyPrefix(I:Int) => "Prop_" +String Int2String(I) +String "_" +syntax String ::= globalStateVarI(Int) [function] +rule globalStateVarI(I:Int) => propertyPrefix(I) +String "RVC_state" + //the code for resetting global state var i syntax String ::= resetGlobalStateI(Int) [function] -rule resetGlobalStateI(I:Int) => propertyPrefix(I) +String "RVC_state = 0;\n" +rule resetGlobalStateI(I:Int) => globalStateVarI(I) +String " = 0;\n" syntax String ::= getGlobalStateVarInit(Int) [function] rule getGlobalStateVarInit(I:Int) => staticIntPrefix(resetGlobalStateI(I)) @@ -91,5 +94,9 @@ rule printMethodHeader(SpecName:String, EventName:String, Args:String) => "void __RVC_" +String SpecName +String "_" +String EventName +String "(" +String Args +String ")" +////////////the two args are global state var name and transition function name +syntax String ::= globalStateUpdate(String, String) [function] +rule globalStateUpdate(GSV:String, TF:String) => + GSV +String " = " +String TF +String "[" +String GSV +String "];" endmodule \ No newline at end of file From c4ffe324da3b2ee6494bbd36af30988f70416e15 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 14:20:34 -0500 Subject: [PATCH 133/160] global state var update successfully --- .../c-monitor-event-action.k | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 2b6ff3a..482c24c 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -43,6 +43,7 @@ module C-MONITOR-EVENT-ACTION (.List => ListItem(getStringI(EAs, I))) //the event I's action code + //store the current event name which will be used to infer event transition function. .List => ListItem(getStringI(EL, I)) ////////////////////////////////////////////////////////////////////////////// @@ -70,12 +71,27 @@ module C-MONITOR-EVENT-ACTION when PS >Int 0 //generate global state update code -rule $gsUpdate(I), $lsUpdates(getSize(SML, I)) => $lsUpdates(getSize(SML, I)) - SN:String - ListItem(EN:String) - C:List (.List => ListItem(globalStateUpdate( -globalStateVarI(I), propXEventE(SN, I, EN)))) - +//when the property size > 1, the event transition function will have property rank as prefix +rule $gsUpdate(I:Int), $lsUpdates(J:Int) => $lsUpdates(J) + SN:String + ListItem(EN:String) //the tmpList stores the current event name + C:List (.List => ListItem( +globalStateUpdate(globalStateVarI(I), propXEventE(SN, I, EN)) +)) + + PS:Int +when PS >Int 1 + +//only a single property is defined +rule $gsUpdate(I:Int), $lsUpdates(J:Int) => $lsUpdates(J) + SN:String + ListItem(EN:String) //the tmpList stores the current event name + C:List (.List => ListItem( +globalStateUpdate(globalStateVarI(I), propXEventE(SN, EN)) +)) + + PS:Int +when PS <=Int 1 //TODO:generate local states update code From a74ae89d2cfbe04611a0ee85ad21ac890a5ff9a4 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 14:33:27 -0500 Subject: [PATCH 134/160] rewrite to handler code --- src/c-monitor-code-template/c-monitor-event-action.k | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 482c24c..533f8f0 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -70,6 +70,13 @@ module C-MONITOR-EVENT-ACTION SML:List when PS >Int 0 +//finish the state updates code + rule + ($sUpdate(I:Int) ,, $stateUpdates(0) ;; $handlers) => + $handlers + + .K + //generate global state update code //when the property size > 1, the event transition function will have property rank as prefix rule $gsUpdate(I:Int), $lsUpdates(J:Int) => $lsUpdates(J) @@ -94,7 +101,7 @@ globalStateUpdate(globalStateVarI(I), propXEventE(SN, EN)) when PS <=Int 1 //TODO:generate local states update code - +rule $lsUpdates(0) => .K //TODO handler code // (.List => ListItem("\n}\n")) //the closing curly brace From c4373636b4a18ac9f47726a765bfa25c47991241 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 16:14:16 -0500 Subject: [PATCH 135/160] update the local states and global states --- .../c-monitor-event-action.k | 24 +++++++++++++++++-- src/helper/code-gen.k | 5 ++++ src/rvm/rvm-compiler.k | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 533f8f0..ab6f09d 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -11,6 +11,7 @@ module C-MONITOR-EVENT-ACTION rule $main4 => $eventFuncs(size(EL)) EL:List + _:Map => .Map rule $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I)) when I >Int 0 @@ -61,13 +62,18 @@ module C-MONITOR-EVENT-ACTION when PS <=Int 0 - rule + rule ($sUpdate(I:Int) ,, $stateUpdates(PS:Int) ;; $handlers) => ($sUpdate(I +Int 1) ,, $stateUpdates(PS -Int 1) ;; $handlers) .K => $gsUpdate(I), $lsUpdates(getSize(SML, I)) SML:List + + //cache the state map of property I + .Map => getMapI(SML, I) + + _:Int => I //the cur property rank is I when PS >Int 0 //finish the state updates code @@ -100,8 +106,22 @@ globalStateUpdate(globalStateVarI(I), propXEventE(SN, EN)) PS:Int when PS <=Int 1 +//update local states +rule $lsUpdate(I:Int) $lsUpdates(0) => .K + M:Map => .Map + + +rule $lsUpdates(I:Int) => $lsUpdate(0) $lsUpdates(I) + +rule $lsUpdate(I:Int) $lsUpdates(J:Int) => $lsUpdate(I +Int 1) $lsUpdates(J -Int 1) + G:Int + M:Map +//the three args are local state var, global state var, state rank + C:List (.List => ListItem(localStateUpdate(getStrKey(M, I), globalStateVarI(G), I))) + +when J >Int 0 + //TODO:generate local states update code -rule $lsUpdates(0) => .K //TODO handler code // (.List => ListItem("\n}\n")) //the closing curly brace diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 396d6ad..0b94ab3 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -99,4 +99,9 @@ syntax String ::= globalStateUpdate(String, String) [function] rule globalStateUpdate(GSV:String, TF:String) => GSV +String " = " +String TF +String "[" +String GSV +String "];" +/////////////the three args are local state var, global state var, state rank +syntax String ::= localStateUpdate(String, String, Int) [function] +rule localStateUpdate(LSV:String, GSV:String, SR:Int) => + LSV +String " = " +String GSV +String " == " +String Int2String(SR) + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 57f817a..5e63a74 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -126,4 +126,5 @@ rule Prop:PropertyDec Props:PropertyDecList => Props //No properties left rule .PropertyDecList => . false + M:Map => .Map endmodule From 8fb6632c35c2c8b115cdb376b3713fdc631736be Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 16:52:10 -0500 Subject: [PATCH 136/160] function for generating handler code --- src/helper/code-gen.k | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 0b94ab3..5ffa435 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -104,4 +104,29 @@ syntax String ::= localStateUpdate(String, String, Int) [function] rule localStateUpdate(LSV:String, GSV:String, SR:Int) => LSV +String " = " +String GSV +String " == " +String Int2String(SR) +//////////////////////////////////////////////////////////////////////////////// +//generate the event handler code +//the complete code will be generated by structural induction. +//given the , in the form of a list of maps of (string |-> string) +//return the sequence of handler code string +syntax List ::= getHandlerCode(List) [function] +syntax List ::= getHandlerCodeFromMap(Map) [function] + +rule getHandlerCode(.List) => .List + +rule getHandlerCode(ListItem(M:Map)) => getHandlerCodeFromMap(M) + +rule getHandlerCode(ListItem(M:Map) L:List) => getHandlerCodeFromMap(M) getHandlerCode(L) + +//handling map +rule getHandlerCodeFromMap(.Map) => .List + +rule getHandlerCodeFromMap(K:String |-> V:String) => ListItem("if (" +String K +String ") {\n" + +String V +String "\n}") + +rule getHandlerCodeFromMap((K:String |-> V:String) M:Map) => +ListItem("if (" +String K +String "){\n" +String V +String "\n}") +getHandlerCodeFromMap(M) + + endmodule \ No newline at end of file From 12cbb15feb25ad440d62c87604830107c0afa414 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 17:06:13 -0500 Subject: [PATCH 137/160] add code gen --- src/logic/semantics/fsm.k | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index a7188a7..6809e2c 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -111,12 +111,15 @@ rule fsm //////////////////////////////////////////////// ///////////collect the handler info -//rule .HandlerDecList => .K - rule (@LS:LogicState HB:HandlerBody) HDL:HandlerDecList => HDL - L:List (.List => ListItem(getStateNameOf(LS) |-> getHandlerCodeStr(HB) ) ) + P:Int + SN:String + L:List (.List => ListItem(localStateVarI(SN, P, getStateNameOf(LS)):String + |-> (getHandlerCodeStr(HB)):String ) ) +/////////////the three args are spec name, property rank and state name +// localStateVarI(SN, P, getStateNameOf(LS)) //////////////////////////////////////////////// rule From 4d6448e6f08cc38fceeda72eb3782ab025e2860d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 19:08:26 -0500 Subject: [PATCH 138/160] generate handler code --- src/c-monitor-code-template/c-monitor-event-action.k | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index ab6f09d..0b15b34 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -126,4 +126,9 @@ when J >Int 0 //TODO handler code // (.List => ListItem("\n}\n")) //the closing curly brace +rule $handlers => .K + .K + HL:List + C:List (.List => getHandlerCode(HL)) + endmodule \ No newline at end of file From 15569c29b851688bb993d8d0250174078a33a8da Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 19:54:08 -0500 Subject: [PATCH 139/160] add decl bubble list to output code --- src/c-monitor-code-template/c-monitor-template.k | 7 +++++++ src/helper/print-ast.k | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 8abe71d..45da1d2 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -36,6 +36,13 @@ rule $incl $main => $main ListItem("#include ") ) +//incorporate the user provided declarations +rule $main + DBL:DecBubbleList => .K + L:List (.List => + ListItem(declBubbleList2String(DBL))) + + ///////// //rewrite the global var declarations. rule $main => $globalInit(0) $main1 diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 04f5a19..58b327f 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -110,4 +110,8 @@ rule getStateNameOf(X:Id) => Id2String(X) /*Get the string of handler code*/ syntax String ::= getHandlerCodeStr(HandlerBody) [function] rule getHandlerCodeStr(BB:BlockBubble) => Block2Str(BB) + +/*Print the Decl list as string*/ +syntax String ::= declBubbleList2String(DecBubbleList) [function, hook(STRING.token2string)] + endmodule \ No newline at end of file From a1a11fefe60b79d1fb1a08d0fabe330b37c17b2d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 20:37:47 -0500 Subject: [PATCH 140/160] generate the .c code successfully! --- .../c-monitor-event-action.k | 12 +-- .../c-monitor-template.k | 13 ++- src/helper/util.k | 6 ++ src/rvm/rvc.k | 1 - ..._RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor} | 0 test/rvm/__RVC_Test_Monitor.c | 96 +++++++++++++++++++ 6 files changed, 120 insertions(+), 8 deletions(-) rename test/rvm/{__RVC_SeatBelt_Monitor.c => __RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor} (100%) create mode 100644 test/rvm/__RVC_Test_Monitor.c diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 0b15b34..f7a4f71 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -12,6 +12,7 @@ module C-MONITOR-EVENT-ACTION rule $main4 => $eventFuncs(size(EL)) EL:List _:Map => .Map + CL:List (.List => ListItem("\n")) rule $eventFuncs(I:Int) => ($eFunc(0), $eventFuncs(I)) when I >Int 0 @@ -20,10 +21,13 @@ module C-MONITOR-EVENT-ACTION when I <=Int 0 rule $eFunc(I:Int), $eventFuncs(0) => .K + .K + .K rule $eFunc(I:Int), $eventFuncs(J:Int) => $eFunc(I +Int 1), $eventFuncs(J -Int 1) .K => $eFunc(I) _ => .List + CL:List (.List => ListItem("\n")) when J >Int 0 rule $eFunc(I:Int) => $methHeader(I) {$mbody} @@ -121,14 +125,10 @@ rule $lsUpdate(I:Int) $lsUpdates(J:Int) => $lsUpdate(I +Int 1) $lsUpdates(J when J >Int 0 -//TODO:generate local states update code - - //TODO handler code -// (.List => ListItem("\n}\n")) //the closing curly brace - +//handler code and closing parenthesis rule $handlers => .K .K HL:List - C:List (.List => getHandlerCode(HL)) + C:List (.List => getHandlerCode(HL)) (.List => ListItem("\n}\n")) endmodule \ No newline at end of file diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 45da1d2..c556eb0 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -33,7 +33,7 @@ rule //TODO: incorporate the user provided includes rule $incl $main => $main L:List (.List => ListItem("#include ") - ListItem("#include ") ) + ListItem("#include \n") ) //incorporate the user provided declarations @@ -152,5 +152,16 @@ when when getStringI(EL, J) ==String Id2String(X) andBool PS <=Int 1 +////////////////////////////////////////////////////////////////////////////////// +//generate the output monitor file + rule 3 => 4 + //the output file name + .K => "__RVC_" +String SN +String "_Monitor.c" + .K + SN:String + + rule 4 + OutFileName:String => #write(#open(OutFileName), StringList2String(CL)) + CL:List => .List endmodule \ No newline at end of file diff --git a/src/helper/util.k b/src/helper/util.k index 2600ee1..ecbb01f 100644 --- a/src/helper/util.k +++ b/src/helper/util.k @@ -69,6 +69,12 @@ rule getStringI(ListItem(X:String) L:List, I:Int) => "" when I getStringI(L, I -Int 1) when I >Int 0 +//convert a list of strings into a single string +syntax String ::= StringList2String(List) [function] +rule StringList2String(.List) => "\n" +rule StringList2String(ListItem(S:String)) => S +String "\n" +rule StringList2String(ListItem(S:String) L:List) => S +String "\n" +String StringList2String(L) + endmodule diff --git a/src/rvm/rvc.k b/src/rvm/rvc.k index 0db3b06..e638b7c 100644 --- a/src/rvm/rvc.k +++ b/src/rvm/rvc.k @@ -17,5 +17,4 @@ module RVC imports LOGIC-PLUGINS-SHELL imports C-MONITOR-TEMPLATE - endmodule diff --git a/test/rvm/__RVC_SeatBelt_Monitor.c b/test/rvm/__RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor similarity index 100% rename from test/rvm/__RVC_SeatBelt_Monitor.c rename to test/rvm/__RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor diff --git a/test/rvm/__RVC_Test_Monitor.c b/test/rvm/__RVC_Test_Monitor.c new file mode 100644 index 0000000..78fae57 --- /dev/null +++ b/test/rvm/__RVC_Test_Monitor.c @@ -0,0 +1,96 @@ +#include +#include + +x = "foo"; + class bar { + private int foo() { return 1; } + } + + +static int Prop_0_RVC_state = 0; + +static int Prop_1_RVC_state = 0; + +int Test_Prop_0_start = 0; +int Test_Prop_0_safe = 0; +int Test_Prop_0_unsafe = 0; +int Test_Prop_1_start2 = 0; +int Test_Prop_1_safe2 = 0; +int Test_Prop_1_unsafe2 = 0; +void __RVC_Test_reset(void) +{ +Prop_0_RVC_state = 0; +Prop_1_RVC_state = 0; +} +const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; +const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; + + + + +void __RVC_Test_hasnext(Iterator i) +{ + +{} +Prop_0_RVC_state = Test_Prop_0_hasnext[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +Prop_1_RVC_state = Test_Prop_1_hasnext[Prop_1_RVC_state]; +start2 = Prop_1_RVC_state == 0 +safe2 = Prop_1_RVC_state == 1 +unsafe2 = Prop_1_RVC_state == 2 +if (Test_Prop_0_start){ +{ + int j; + } +} +if (Test_Prop_0_unsafe){ +{ + System.err.println("It is not safe"); + } +} +if (Test_Prop_1_unsafe2){ +{ + int k; + } +} + +} + + + +void __RVC_Test_next(Iterator i) +{ + +{ int i = 0; {i--;} int j=i+ 2 ; +{{{}}} } +Prop_0_RVC_state = Test_Prop_0_next[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +Prop_1_RVC_state = Test_Prop_1_next[Prop_1_RVC_state]; +start2 = Prop_1_RVC_state == 0 +safe2 = Prop_1_RVC_state == 1 +unsafe2 = Prop_1_RVC_state == 2 +if (Test_Prop_0_start){ +{ + int j; + } +} +if (Test_Prop_0_unsafe){ +{ + System.err.println("It is not safe"); + } +} +if (Test_Prop_1_unsafe2){ +{ + int k; + } +} + +} + + From f89bc64f472a48a918b7cd05d0ff992c74cf6146 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 21:13:10 -0500 Subject: [PATCH 141/160] re-organize the tests --- test/rvm/fsm/rvc/HasNext.rvm | 43 +++ test/rvm/fsm/rvc/Test2.rvm | 55 +++ test/rvm/fsm/{ => rvj}/HasNext.rvm | 0 .../fsm/{ => rvj}/HasNextRuntimeMonitor.java | 0 test/rvm/{ => fsm/rvj}/Test.rvm | 0 test/rvm/{ => fsm/rvj}/Test2.rvm | 0 test/rvm/{ => fsm/rvj}/Test3.rvm | 0 test/rvm/{ => fsm/rvj}/Test4.rvm | 2 +- test/rvm/fsm/{ => rvj}/info-from-formula | 0 .../rvm/fsm/{ => rvj}/rv-monitor-shell-result | 0 test/rvm/seatbelt_multiRuntimeMonitor.java | 341 ------------------ 11 files changed, 99 insertions(+), 342 deletions(-) create mode 100644 test/rvm/fsm/rvc/HasNext.rvm create mode 100644 test/rvm/fsm/rvc/Test2.rvm rename test/rvm/fsm/{ => rvj}/HasNext.rvm (100%) rename test/rvm/fsm/{ => rvj}/HasNextRuntimeMonitor.java (100%) rename test/rvm/{ => fsm/rvj}/Test.rvm (100%) rename test/rvm/{ => fsm/rvj}/Test2.rvm (100%) rename test/rvm/{ => fsm/rvj}/Test3.rvm (100%) rename test/rvm/{ => fsm/rvj}/Test4.rvm (97%) rename test/rvm/fsm/{ => rvj}/info-from-formula (100%) rename test/rvm/fsm/{ => rvj}/rv-monitor-shell-result (100%) delete mode 100644 test/rvm/seatbelt_multiRuntimeMonitor.java diff --git a/test/rvm/fsm/rvc/HasNext.rvm b/test/rvm/fsm/rvc/HasNext.rvm new file mode 100644 index 0000000..16cd3cb --- /dev/null +++ b/test/rvm/fsm/rvc/HasNext.rvm @@ -0,0 +1,43 @@ +package rvm; + +// This property specifies that a program does +// not call the hasnext method before the next +// method of an iterator. +// This property is borrowed from tracematches +// (see ECOOP'07 http://abc.comlab.ox.ac.uk/papers) + +HasNext(Iterator i) { + event hasnext(Iterator i) {} // after + event next(Iterator i) {} // before + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + // alias match = unsafe + // alias unmatch = safe + + @match { +fprintf(stderr, "next called without hasNext!\n"); + } + +} + + + + + + + + + diff --git a/test/rvm/fsm/rvc/Test2.rvm b/test/rvm/fsm/rvc/Test2.rvm new file mode 100644 index 0000000..6119658 --- /dev/null +++ b/test/rvm/fsm/rvc/Test2.rvm @@ -0,0 +1,55 @@ +package rvm; + +Test (int o){ + int foo = 2; + + + event hasnext(Iterator i) {} // {1, 1, 1, 3} + event next(Iterator i) { int i = 0; {i--;} int j=i+ 2 ; +{{{}}} } // {2, 0, 2, 3} + + fsm : + start [ + next -> unsafe + hasnext -> safe + ] + safe [ + next -> start + hasnext -> safe + ] + unsafe [ + next -> unsafe + hasnext -> safe + ] + + @start { + int j; +fprintf(stderr, "Start!\n"); + } + + @unsafe { + fprintf(stderr, "It's not safe.\n"); + } + + + fsm : + start2 [ + next -> unsafe2 + hasnext -> safe2 + ] + safe2 [ + next -> start2 + hasnext -> safe2 + ] + unsafe2 [ + next -> unsafe2 + hasnext -> safe2 + ] + + @unsafe2 { + int k; +fprintf(stderr, "It's in state unsafe2.\n"); + } + + +} diff --git a/test/rvm/fsm/HasNext.rvm b/test/rvm/fsm/rvj/HasNext.rvm similarity index 100% rename from test/rvm/fsm/HasNext.rvm rename to test/rvm/fsm/rvj/HasNext.rvm diff --git a/test/rvm/fsm/HasNextRuntimeMonitor.java b/test/rvm/fsm/rvj/HasNextRuntimeMonitor.java similarity index 100% rename from test/rvm/fsm/HasNextRuntimeMonitor.java rename to test/rvm/fsm/rvj/HasNextRuntimeMonitor.java diff --git a/test/rvm/Test.rvm b/test/rvm/fsm/rvj/Test.rvm similarity index 100% rename from test/rvm/Test.rvm rename to test/rvm/fsm/rvj/Test.rvm diff --git a/test/rvm/Test2.rvm b/test/rvm/fsm/rvj/Test2.rvm similarity index 100% rename from test/rvm/Test2.rvm rename to test/rvm/fsm/rvj/Test2.rvm diff --git a/test/rvm/Test3.rvm b/test/rvm/fsm/rvj/Test3.rvm similarity index 100% rename from test/rvm/Test3.rvm rename to test/rvm/fsm/rvj/Test3.rvm diff --git a/test/rvm/Test4.rvm b/test/rvm/fsm/rvj/Test4.rvm similarity index 97% rename from test/rvm/Test4.rvm rename to test/rvm/fsm/rvj/Test4.rvm index 0ed8714..bb08c27 100644 --- a/test/rvm/Test4.rvm +++ b/test/rvm/fsm/rvj/Test4.rvm @@ -2,7 +2,7 @@ package rvm; import java.io.*; Test (int o){ - x = "foo"; + String x = "foo"; class bar { private int foo() { return 1; } } diff --git a/test/rvm/fsm/info-from-formula b/test/rvm/fsm/rvj/info-from-formula similarity index 100% rename from test/rvm/fsm/info-from-formula rename to test/rvm/fsm/rvj/info-from-formula diff --git a/test/rvm/fsm/rv-monitor-shell-result b/test/rvm/fsm/rvj/rv-monitor-shell-result similarity index 100% rename from test/rvm/fsm/rv-monitor-shell-result rename to test/rvm/fsm/rvj/rv-monitor-shell-result diff --git a/test/rvm/seatbelt_multiRuntimeMonitor.java b/test/rvm/seatbelt_multiRuntimeMonitor.java deleted file mode 100644 index 9e7ec8b..0000000 --- a/test/rvm/seatbelt_multiRuntimeMonitor.java +++ /dev/null @@ -1,341 +0,0 @@ - -import java.util.concurrent.*; -import java.util.concurrent.locks.*; -import java.util.*; -import java.lang.ref.*; -import com.runtimeverification.rvmonitor.java.rt.*; -import com.runtimeverification.rvmonitor.java.rt.ref.*; -import com.runtimeverification.rvmonitor.java.rt.table.*; -import com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractIndexingTree; -import com.runtimeverification.rvmonitor.java.rt.tablebase.SetEventDelegator; -import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple2; -import com.runtimeverification.rvmonitor.java.rt.tablebase.TableAdopter.Tuple3; -import com.runtimeverification.rvmonitor.java.rt.tablebase.IDisableHolder; -import com.runtimeverification.rvmonitor.java.rt.tablebase.IMonitor; -import com.runtimeverification.rvmonitor.java.rt.tablebase.DisableHolder; -import com.runtimeverification.rvmonitor.java.rt.tablebase.TerminatedMonitorCleaner; -import java.util.concurrent.atomic.AtomicInteger; - -final class SeatBeltMonitor_Set extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractMonitorSet { - - SeatBeltMonitor_Set(){ - this.size = 0; - this.elements = new SeatBeltMonitor[4]; - } - final void event_seatBeltRemoved() { - int numAlive = 0 ; - for(int i = 0; i < this.size; i++){ - SeatBeltMonitor monitor = this.elements[i]; - if(!monitor.isTerminated()){ - elements[numAlive] = monitor; - numAlive++; - - final SeatBeltMonitor monitorfinalMonitor = monitor; - monitor.Prop_1_event_seatBeltRemoved(); - if(monitorfinalMonitor.Prop_1_Category_safe) { - monitorfinalMonitor.Prop_1_handler_safe(); - } - if(monitorfinalMonitor.Prop_1_Category_unsafe) { - monitorfinalMonitor.Prop_1_handler_unsafe(); - } - final SeatBeltMonitor monitorfinalMonitor = monitor; - monitor.Prop_2_event_seatBeltRemoved(); - if(monitorfinalMonitor.Prop_2_Category_safe2) { - monitorfinalMonitor.Prop_2_handler_safe2(); - } - } - } - for(int i = numAlive; i < this.size; i++){ - this.elements[i] = null; - } - size = numAlive; - } - final void event_seatBeltAttached() { - int numAlive = 0 ; - for(int i = 0; i < this.size; i++){ - SeatBeltMonitor monitor = this.elements[i]; - if(!monitor.isTerminated()){ - elements[numAlive] = monitor; - numAlive++; - - final SeatBeltMonitor monitorfinalMonitor = monitor; - monitor.Prop_1_event_seatBeltAttached(); - if(monitorfinalMonitor.Prop_1_Category_safe) { - monitorfinalMonitor.Prop_1_handler_safe(); - } - if(monitorfinalMonitor.Prop_1_Category_unsafe) { - monitorfinalMonitor.Prop_1_handler_unsafe(); - } - final SeatBeltMonitor monitorfinalMonitor = monitor; - monitor.Prop_2_event_seatBeltAttached(); - if(monitorfinalMonitor.Prop_2_Category_safe2) { - monitorfinalMonitor.Prop_2_handler_safe2(); - } - } - } - for(int i = numAlive; i < this.size; i++){ - this.elements[i] = null; - } - size = numAlive; - } -} - -class SeatBeltMonitor extends com.runtimeverification.rvmonitor.java.rt.tablebase.AbstractAtomicMonitor implements Cloneable, com.runtimeverification.rvmonitor.java.rt.RVMObject { - protected Object clone() { - try { - SeatBeltMonitor ret = (SeatBeltMonitor) super.clone(); - ret.pairValue = new AtomicInteger(pairValue.get()); - return ret; - } - catch (CloneNotSupportedException e) { - throw new InternalError(e.toString()); - } - } - - static final int Prop_1_transition_seatBeltRemoved[] = {2, 0, 2};; - static final int Prop_1_transition_seatBeltAttached[] = {1, 2, 2};; - - static final int Prop_2_transition_seatBeltRemoved[] = {2, 0, 2};; - static final int Prop_2_transition_seatBeltAttached[] = {1, 2, 2};; - - volatile boolean Prop_1_Category_safe = false; - volatile boolean Prop_1_Category_unsafe = false; - volatile boolean Prop_2_Category_safe2 = false; - - private AtomicInteger pairValue; - - SeatBeltMonitor() { - this.pairValue = new AtomicInteger(this.calculatePairValue(-1, 0) ) ; - - this.pairValue = new AtomicInteger(this.calculatePairValue(-1, 0) ) ; - - } - - @Override public final int getState() { - return this.getState(this.pairValue.get() ) ; - } - @Override public final int getLastEvent() { - return this.getLastEvent(this.pairValue.get() ) ; - } - private final int getState(int pairValue) { - return (pairValue & 0) ; - } - private final int getLastEvent(int pairValue) { - return (pairValue >> 0) ; - } - private final int calculatePairValue(int lastEvent, int state) { - return (((lastEvent + 1) << 0) | state) ; - } - - private final int handleEvent(int eventId, int[] table) { - int nextstate; - while (true) { - int oldpairvalue = this.pairValue.get() ; - int oldstate = this.getState(oldpairvalue) ; - nextstate = table [ oldstate ]; - int nextpairvalue = this.calculatePairValue(eventId, nextstate) ; - if (this.pairValue.compareAndSet(oldpairvalue, nextpairvalue) ) { - break; - } - } - return nextstate; - } - - final boolean Prop_1_event_seatBeltRemoved() { - - int nextstate = this.handleEvent(0, Prop_1_transition_seatBeltRemoved) ; - this.Prop_1_Category_safe = nextstate == 1; - this.Prop_1_Category_unsafe = nextstate == 0; - - return true; - } - - final boolean Prop_1_event_seatBeltAttached() { - - int nextstate = this.handleEvent(1, Prop_1_transition_seatBeltAttached) ; - this.Prop_1_Category_safe = nextstate == 1; - this.Prop_1_Category_unsafe = nextstate == 0; - - return true; - } - - final boolean Prop_2_event_seatBeltRemoved() { - {fprintf(stderr, "Seat belt removed.\n");} - - int nextstate = this.handleEvent(0, Prop_2_transition_seatBeltRemoved) ; - this.Prop_2_Category_safe2 = nextstate == 1; - - return true; - } - - final boolean Prop_2_event_seatBeltAttached() { - {fprintf(stderr, "Seat belt attached.\n");} - - int nextstate = this.handleEvent(1, Prop_2_transition_seatBeltAttached) ; - this.Prop_2_Category_safe2 = nextstate == 1; - - return true; - } - - final void Prop_1_handler_safe (){ - { - fprintf(stderr, "set max speed to user input.\n"); - } - - } - - final void Prop_1_handler_unsafe (){ - { - fprintf(stderr, "set max speed to 10 mph.\n"); - } - - } - - final void Prop_2_handler_safe2 (){ - { - fprintf(stderr, "It's safe.\n"); - } - - } - - final void reset() { - this.pairValue.set(this.calculatePairValue(-1, 0) ) ; - - Prop_1_Category_safe = false; - Prop_1_Category_unsafe = false; - this.pairValue.set(this.calculatePairValue(-1, 0) ) ; - - Prop_2_Category_safe2 = false; - } - - @Override - protected final void terminateInternal(int idnum) { - int lastEvent = this.getLastEvent(); - - switch(idnum){ - } - switch(lastEvent) { - case -1: - return; - case 0: - //seatBeltRemoved - return; - case 1: - //seatBeltAttached - return; - } - return; - } - - public static int getNumberOfEvents() { - return 2; - } - - public static int getNumberOfStates() { - return -1; - } - -} - -public final class seatbelt_multiRuntimeMonitor implements com.runtimeverification.rvmonitor.java.rt.RVMObject { - private static com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager seatbelt_multiMapManager; - static { - seatbelt_multiMapManager = new com.runtimeverification.rvmonitor.java.rt.map.RVMMapManager(); - seatbelt_multiMapManager.start(); - } - - // Declarations for the Lock - static final ReentrantLock seatbelt_multi_RVMLock = new ReentrantLock(); - static final Condition seatbelt_multi_RVMLock_cond = seatbelt_multi_RVMLock.newCondition(); - - private static boolean SeatBelt_activated = false; - - // Declarations for Indexing Trees - private static final SeatBeltMonitor SeatBelt__Map = new SeatBeltMonitor() ; - - public static int cleanUp() { - int collected = 0; - // indexing trees - return collected; - } - - // Removing terminated monitors from partitioned sets - static { - TerminatedMonitorCleaner.start() ; - } - // Setting the behavior of the runtime library according to the compile-time option - static { - RuntimeOption.enableFineGrainedLock(false) ; - } - - public static final void seatBeltRemovedEvent() { - SeatBelt_activated = true; - while (!seatbelt_multi_RVMLock.tryLock()) { - Thread.yield(); - } - - SeatBeltMonitor matchedEntry = null; - { - // FindOrCreateEntry - matchedEntry = SeatBelt__Map; - } - // D(X) main:1 - if ((matchedEntry == null) ) { - // D(X) main:4 - SeatBeltMonitor created = new SeatBeltMonitor() ; - matchedEntry = created; - } - // D(X) main:8--9 - final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; - matchedEntry.Prop_1_event_seatBeltRemoved(); - if(matchedEntryfinalMonitor.Prop_1_Category_safe) { - matchedEntryfinalMonitor.Prop_1_handler_safe(); - } - if(matchedEntryfinalMonitor.Prop_1_Category_unsafe) { - matchedEntryfinalMonitor.Prop_1_handler_unsafe(); - } - final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; - matchedEntry.Prop_2_event_seatBeltRemoved(); - if(matchedEntryfinalMonitor.Prop_2_Category_safe2) { - matchedEntryfinalMonitor.Prop_2_handler_safe2(); - } - - seatbelt_multi_RVMLock.unlock(); - } - - public static final void seatBeltAttachedEvent() { - SeatBelt_activated = true; - while (!seatbelt_multi_RVMLock.tryLock()) { - Thread.yield(); - } - - SeatBeltMonitor matchedEntry = null; - { - // FindOrCreateEntry - matchedEntry = SeatBelt__Map; - } - // D(X) main:1 - if ((matchedEntry == null) ) { - // D(X) main:4 - SeatBeltMonitor created = new SeatBeltMonitor() ; - matchedEntry = created; - } - // D(X) main:8--9 - final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; - matchedEntry.Prop_1_event_seatBeltAttached(); - if(matchedEntryfinalMonitor.Prop_1_Category_safe) { - matchedEntryfinalMonitor.Prop_1_handler_safe(); - } - if(matchedEntryfinalMonitor.Prop_1_Category_unsafe) { - matchedEntryfinalMonitor.Prop_1_handler_unsafe(); - } - final SeatBeltMonitor matchedEntryfinalMonitor = matchedEntry; - matchedEntry.Prop_2_event_seatBeltAttached(); - if(matchedEntryfinalMonitor.Prop_2_Category_safe2) { - matchedEntryfinalMonitor.Prop_2_handler_safe2(); - } - - seatbelt_multi_RVMLock.unlock(); - } - -} From 71364b36221bfeb4fac13adbd250ca4d9a48a049 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 22:26:39 -0500 Subject: [PATCH 142/160] re-structure the test --- .../c-monitor-template.k | 8 +- src/rvm/rvm-compiler.k | 4 +- test/rvm/fsm/rvc/HasNext.rvm | 13 +-- test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c | 53 ++++++++++ test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 97 +++++++++++++++++++ .../rv-monitor-output/__RVC_HasNext_Monitor.c | 47 +++++++++ .../rv-monitor-output/__RVC_HasNext_Monitor.h | 10 ++ 7 files changed, 217 insertions(+), 15 deletions(-) create mode 100644 test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c create mode 100644 test/rvm/fsm/rvc/__RVC_Test_Monitor.c create mode 100644 test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c create mode 100644 test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index c556eb0..288c04c 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -16,8 +16,7 @@ module C-MONITOR-TEMPLATE rule "c" false - X:Int - X:Int => X +Int 1 + 1 => 2 .K => $CMonitor @@ -154,13 +153,14 @@ when getStringI(EL, J) ==String Id2String(X) ////////////////////////////////////////////////////////////////////////////////// //generate the output monitor file - rule 3 => 4 + rule 2 => 3 //the output file name .K => "__RVC_" +String SN +String "_Monitor.c" .K + .K SN:String - rule 4 + rule 3 OutFileName:String => #write(#open(OutFileName), StringList2String(CL)) CL:List => .List diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 5e63a74..d904538 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -112,6 +112,8 @@ when (Id2String(X) in EL) //No events left rule {.K (.EventDecList) Props:PropertyDecList} => Props + 0 => 1 + //add the property formula and corresponding handlers rule Prop:PropertyDec Props:PropertyDecList => Props @@ -121,10 +123,10 @@ rule Prop:PropertyDec Props:PropertyDecList => Props .K => getFormula(Prop) .HandlerDecList => getHandlers(Prop) false => true - X:Int => X +Int 1 //No properties left rule .PropertyDecList => . false M:Map => .Map + endmodule diff --git a/test/rvm/fsm/rvc/HasNext.rvm b/test/rvm/fsm/rvc/HasNext.rvm index 16cd3cb..35efe4f 100644 --- a/test/rvm/fsm/rvc/HasNext.rvm +++ b/test/rvm/fsm/rvc/HasNext.rvm @@ -1,14 +1,9 @@ package rvm; -// This property specifies that a program does -// not call the hasnext method before the next -// method of an iterator. -// This property is borrowed from tracematches -// (see ECOOP'07 http://abc.comlab.ox.ac.uk/papers) HasNext(Iterator i) { - event hasnext(Iterator i) {} // after - event next(Iterator i) {} // before + event hasnext(Iterator i) {} + event next(Iterator i) {} fsm : start [ @@ -24,10 +19,8 @@ HasNext(Iterator i) { hasnext -> safe ] - // alias match = unsafe - // alias unmatch = safe - @match { + @unsafe { fprintf(stderr, "next called without hasNext!\n"); } diff --git a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c new file mode 100644 index 0000000..788e29e --- /dev/null +++ b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c @@ -0,0 +1,53 @@ +#include +#include + + +static int Prop_0_RVC_state = 0; + +int HasNext_Prop_0_start = 0; +int HasNext_Prop_0_safe = 0; +int HasNext_Prop_0_unsafe = 0; +void __RVC_HasNext_reset(void) +{ +Prop_0_RVC_state = 0; +} +const static int HasNext_hasnext[] = {1, 1, 1, 3, }; +const static int HasNext_next[] = {2, 0, 2, 3, }; + + + + +void __RVC_HasNext_hasnext(Iterator i) +{ + +{} +Prop_0_RVC_state = HasNext_hasnext[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +if (HasNext_Prop_0_unsafe) { +{ +fprintf(stderr, "next called without hasNext!\n"); + } +} + +} + + + +void __RVC_HasNext_next(Iterator i) +{ + +{} +Prop_0_RVC_state = HasNext_next[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +if (HasNext_Prop_0_unsafe) { +{ +fprintf(stderr, "next called without hasNext!\n"); + } +} + +} + diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c new file mode 100644 index 0000000..4709cfa --- /dev/null +++ b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c @@ -0,0 +1,97 @@ +#include +#include + +int foo = 2; + + + +static int Prop_0_RVC_state = 0; + +static int Prop_1_RVC_state = 0; + +int Test_Prop_0_start = 0; +int Test_Prop_0_safe = 0; +int Test_Prop_0_unsafe = 0; +int Test_Prop_1_start2 = 0; +int Test_Prop_1_safe2 = 0; +int Test_Prop_1_unsafe2 = 0; +void __RVC_Test_reset(void) +{ +Prop_0_RVC_state = 0; +Prop_1_RVC_state = 0; +} +const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; +const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; + + + + +void __RVC_Test_hasnext(Iterator i) +{ + +{} +Prop_0_RVC_state = Test_Prop_0_hasnext[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +Prop_1_RVC_state = Test_Prop_1_hasnext[Prop_1_RVC_state]; +start2 = Prop_1_RVC_state == 0 +safe2 = Prop_1_RVC_state == 1 +unsafe2 = Prop_1_RVC_state == 2 +if (Test_Prop_0_start) { +{ + int j; +fprintf(stderr, "Start!\n"); + } +} +if (Test_Prop_0_unsafe) { +{ + fprintf(stderr, "It's not safe.\n"); + } +} +if (Test_Prop_1_unsafe2) { +{ + int k; +fprintf(stderr, "It's in state unsafe2.\n"); + } +} + +} + + + +void __RVC_Test_next(Iterator i) +{ + +{ int i = 0; {i--;} int j=i+ 2 ; +{{{}}} } +Prop_0_RVC_state = Test_Prop_0_next[Prop_0_RVC_state]; +start = Prop_0_RVC_state == 0 +safe = Prop_0_RVC_state == 1 +unsafe = Prop_0_RVC_state == 2 +Prop_1_RVC_state = Test_Prop_1_next[Prop_1_RVC_state]; +start2 = Prop_1_RVC_state == 0 +safe2 = Prop_1_RVC_state == 1 +unsafe2 = Prop_1_RVC_state == 2 +if (Test_Prop_0_start) { +{ + int j; +fprintf(stderr, "Start!\n"); + } +} +if (Test_Prop_0_unsafe) { +{ + fprintf(stderr, "It's not safe.\n"); + } +} +if (Test_Prop_1_unsafe2) { +{ + int k; +fprintf(stderr, "It's in state unsafe2.\n"); + } +} + +} + diff --git a/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c new file mode 100644 index 0000000..6693696 --- /dev/null +++ b/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c @@ -0,0 +1,47 @@ +package rvm; + + + +#include +static int __RVC_state = 0; + + + +int __RVC_HasNext_unsafe = 0; + +void +__RVC_HasNext_reset(void) +{ + __RVC_state = 0; + } + +static int __RVC_HASNEXT_NEXT[] = {2, 0, 2, }; +static int __RVC_HASNEXT_HASNEXT[] = {1, 1, 1, }; + +void +__RVC_HasNext_next(Iterator i) +{ +{} +__RVC_state = __RVC_HASNEXT_NEXT[__RVC_state]; + __RVC_HasNext_unsafe = __RVC_state == 2; +if(__RVC_HasNext_unsafe) +{ +{ +fprintf(stderr, "next called without hasNext!\n"); + }} +} + +void +__RVC_HasNext_hasnext(Iterator i) +{ +{} +__RVC_state = __RVC_HASNEXT_HASNEXT[__RVC_state]; + __RVC_HasNext_unsafe = __RVC_state == 2; +if(__RVC_HasNext_unsafe) +{ +{ +fprintf(stderr, "next called without hasNext!\n"); + }} +} + + diff --git a/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h b/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h new file mode 100644 index 0000000..9dcb49c --- /dev/null +++ b/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h @@ -0,0 +1,10 @@ +#ifndef __RVC_HASNEXT_MONITOR_H +#define __RVC_HASNEXT_MONITOR_H +void +__RVC_HasNext_reset(void); +void +__RVC_HasNext_next(Iterator i); +void +__RVC_HasNext_hasnext(Iterator i); + +#endif From 9b00c3aef619624a1a3932ab3a4e14e4fac79fbe Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 23:29:58 -0500 Subject: [PATCH 143/160] refactor --- .../c-monitor-event-action.k | 2 +- src/helper/code-gen.k | 21 +++++++------------ src/logic/semantics/fsm.k | 2 +- src/rvm/rvm-compiler-core.k | 3 +-- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index f7a4f71..7b42bde 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -128,7 +128,7 @@ when J >Int 0 //handler code and closing parenthesis rule $handlers => .K .K - HL:List + HDM:Map C:List (.List => getHandlerCode(HL)) (.List => ListItem("\n}\n")) endmodule \ No newline at end of file diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 5ffa435..e0910b6 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -107,26 +107,19 @@ rule localStateUpdate(LSV:String, GSV:String, SR:Int) => //////////////////////////////////////////////////////////////////////////////// //generate the event handler code //the complete code will be generated by structural induction. -//given the , in the form of a list of maps of (string |-> string) -//return the sequence of handler code string -syntax List ::= getHandlerCode(List) [function] -syntax List ::= getHandlerCodeFromMap(Map) [function] - -rule getHandlerCode(.List) => .List - -rule getHandlerCode(ListItem(M:Map)) => getHandlerCodeFromMap(M) - -rule getHandlerCode(ListItem(M:Map) L:List) => getHandlerCodeFromMap(M) getHandlerCode(L) +//given the , in the form of a map of (string |-> string) +//return the map of state name to handler code string +syntax List ::= getHandlerCode(Map) [function] //handling map -rule getHandlerCodeFromMap(.Map) => .List +rule getHandlerCode(.Map) => .List -rule getHandlerCodeFromMap(K:String |-> V:String) => ListItem("if (" +String K +String ") {\n" +rule getHandlerCode(K:String |-> V:String) => ListItem("if (" +String K +String ") {\n" +String V +String "\n}") -rule getHandlerCodeFromMap((K:String |-> V:String) M:Map) => +rule getHandlerCode((K:String |-> V:String) M:Map) => ListItem("if (" +String K +String "){\n" +String V +String "\n}") -getHandlerCodeFromMap(M) +getHandlerCode(M) endmodule \ No newline at end of file diff --git a/src/logic/semantics/fsm.k b/src/logic/semantics/fsm.k index 6809e2c..e557435 100644 --- a/src/logic/semantics/fsm.k +++ b/src/logic/semantics/fsm.k @@ -114,7 +114,7 @@ rule fsm rule (@LS:LogicState HB:HandlerBody) HDL:HandlerDecList => HDL P:Int SN:String - L:List (.List => ListItem(localStateVarI(SN, P, getStateNameOf(LS)):String + HDM:Map (.Map => (localStateVarI(SN, P, getStateNameOf(LS)):String |-> (getHandlerCodeStr(HB)):String ) ) diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 94b9c86..19d8333 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -101,9 +101,8 @@ module RVM-COMPILER-CORE ///////////////////////Specific for FSM////////////////////////////////////////////////////// /////////////////////////////////Logic Plugin cells ends/////////////////////////////////////////// - //list of maps //the map element maps state name to handler code string - .List + .Map .HandlerDecList From f0a3143670e3d104e1a9e04eb6960d2dd47482a9 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Tue, 10 May 2016 23:49:56 -0500 Subject: [PATCH 144/160] fix a typo --- .../c-monitor-event-action.k | 2 +- test/rvm/__RVC_Test_Monitor.c | 96 ------------------- test/rvm/fsm/rvc/{Test2.rvm => Test.rvm} | 0 test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c | 2 +- test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 24 ++--- test/rvm/handler.txt | 7 -- test/rvm/seatbelt_multi.rvm | 35 ------- 7 files changed, 12 insertions(+), 154 deletions(-) delete mode 100644 test/rvm/__RVC_Test_Monitor.c rename test/rvm/fsm/rvc/{Test2.rvm => Test.rvm} (100%) delete mode 100644 test/rvm/handler.txt delete mode 100644 test/rvm/seatbelt_multi.rvm diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 7b42bde..3bffcd4 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -129,6 +129,6 @@ when J >Int 0 rule $handlers => .K .K HDM:Map - C:List (.List => getHandlerCode(HL)) (.List => ListItem("\n}\n")) + C:List (.List => getHandlerCode(HDM)) (.List => ListItem("\n}\n")) endmodule \ No newline at end of file diff --git a/test/rvm/__RVC_Test_Monitor.c b/test/rvm/__RVC_Test_Monitor.c deleted file mode 100644 index 78fae57..0000000 --- a/test/rvm/__RVC_Test_Monitor.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include - -x = "foo"; - class bar { - private int foo() { return 1; } - } - - -static int Prop_0_RVC_state = 0; - -static int Prop_1_RVC_state = 0; - -int Test_Prop_0_start = 0; -int Test_Prop_0_safe = 0; -int Test_Prop_0_unsafe = 0; -int Test_Prop_1_start2 = 0; -int Test_Prop_1_safe2 = 0; -int Test_Prop_1_unsafe2 = 0; -void __RVC_Test_reset(void) -{ -Prop_0_RVC_state = 0; -Prop_1_RVC_state = 0; -} -const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; -const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; - - - - -void __RVC_Test_hasnext(Iterator i) -{ - -{} -Prop_0_RVC_state = Test_Prop_0_hasnext[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -Prop_1_RVC_state = Test_Prop_1_hasnext[Prop_1_RVC_state]; -start2 = Prop_1_RVC_state == 0 -safe2 = Prop_1_RVC_state == 1 -unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_start){ -{ - int j; - } -} -if (Test_Prop_0_unsafe){ -{ - System.err.println("It is not safe"); - } -} -if (Test_Prop_1_unsafe2){ -{ - int k; - } -} - -} - - - -void __RVC_Test_next(Iterator i) -{ - -{ int i = 0; {i--;} int j=i+ 2 ; -{{{}}} } -Prop_0_RVC_state = Test_Prop_0_next[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -Prop_1_RVC_state = Test_Prop_1_next[Prop_1_RVC_state]; -start2 = Prop_1_RVC_state == 0 -safe2 = Prop_1_RVC_state == 1 -unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_start){ -{ - int j; - } -} -if (Test_Prop_0_unsafe){ -{ - System.err.println("It is not safe"); - } -} -if (Test_Prop_1_unsafe2){ -{ - int k; - } -} - -} - - diff --git a/test/rvm/fsm/rvc/Test2.rvm b/test/rvm/fsm/rvc/Test.rvm similarity index 100% rename from test/rvm/fsm/rvc/Test2.rvm rename to test/rvm/fsm/rvc/Test.rvm diff --git a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c index 788e29e..ec0e029 100644 --- a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c @@ -1,7 +1,6 @@ #include #include - static int Prop_0_RVC_state = 0; int HasNext_Prop_0_start = 0; @@ -51,3 +50,4 @@ fprintf(stderr, "next called without hasNext!\n"); } + diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c index 4709cfa..f792830 100644 --- a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c @@ -1,10 +1,6 @@ #include #include -int foo = 2; - - - static int Prop_0_RVC_state = 0; static int Prop_1_RVC_state = 0; @@ -40,15 +36,15 @@ Prop_1_RVC_state = Test_Prop_1_hasnext[Prop_1_RVC_state]; start2 = Prop_1_RVC_state == 0 safe2 = Prop_1_RVC_state == 1 unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_start) { +if (Test_Prop_0_unsafe){ { - int j; -fprintf(stderr, "Start!\n"); + fprintf(stderr, "It's not safe.\n"); } } -if (Test_Prop_0_unsafe) { +if (Test_Prop_0_start){ { - fprintf(stderr, "It's not safe.\n"); + int j; +fprintf(stderr, "Start!\n"); } } if (Test_Prop_1_unsafe2) { @@ -75,15 +71,15 @@ Prop_1_RVC_state = Test_Prop_1_next[Prop_1_RVC_state]; start2 = Prop_1_RVC_state == 0 safe2 = Prop_1_RVC_state == 1 unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_start) { +if (Test_Prop_0_unsafe){ { - int j; -fprintf(stderr, "Start!\n"); + fprintf(stderr, "It's not safe.\n"); } } -if (Test_Prop_0_unsafe) { +if (Test_Prop_0_start){ { - fprintf(stderr, "It's not safe.\n"); + int j; +fprintf(stderr, "Start!\n"); } } if (Test_Prop_1_unsafe2) { diff --git a/test/rvm/handler.txt b/test/rvm/handler.txt deleted file mode 100644 index b7b8fc5..0000000 --- a/test/rvm/handler.txt +++ /dev/null @@ -1,7 +0,0 @@ - @start { - int j; - } - - @unsafe { - System.err.println("It is not safe"); - } diff --git a/test/rvm/seatbelt_multi.rvm b/test/rvm/seatbelt_multi.rvm deleted file mode 100644 index dc218ad..0000000 --- a/test/rvm/seatbelt_multi.rvm +++ /dev/null @@ -1,35 +0,0 @@ -//#include - -SeatBelt() { - event seatBeltRemoved(){fprintf(stderr, "Seat belt removed.\n");} - - event seatBeltAttached() {fprintf(stderr, "Seat belt attached.\n");} - - fsm : unsafe [ - seatBeltAttached -> safe - ] - safe [ - seatBeltRemoved -> unsafe - ] - - @safe { - fprintf(stderr, "set max speed to user input.\n"); - } - - @unsafe { - fprintf(stderr, "set max speed to 10 mph.\n"); - } - - - fsm : unsafe2 [ - seatBeltAttached -> safe2 - ] - safe2 [ - seatBeltRemoved -> unsafe2 - ] - - @safe2 { - fprintf(stderr, "It's safe.\n"); - } - -} From 4fcf2d389ef2a6a40c75e3b2729ce972ba8cb43e Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 00:09:06 -0500 Subject: [PATCH 145/160] update --- src/helper/code-gen.k | 6 +++++- test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index e0910b6..a7be694 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -72,7 +72,11 @@ rule addCurlyBraces(Str:String) => ("{" +String Str +String "}") rule printIntSeq(.List) => "" rule printIntSeq(ListItem(I:Int)) => Int2String(I) -rule printIntSeq(ListItem(I:Int) L:List) => Int2String(I) +String ", " +String printIntSeq(L) +rule printIntSeq(ListItem(I:Int) ListItem(J:Int)) => + Int2String(I) +String ", " +String Int2String(J) +rule printIntSeq(ListItem(I:Int) ListItem(J:Int) L:List) => +Int2String(I) +String ", " +String Int2String(J) +String ", " +String printIntSeq(L) + rule printIntArr(L:List) => addCurlyBraces(printIntSeq(L)) //args are spec name, property rank, event name and transition function array diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c index f792830..da0e0c1 100644 --- a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c @@ -16,10 +16,10 @@ void __RVC_Test_reset(void) Prop_0_RVC_state = 0; Prop_1_RVC_state = 0; } -const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; -const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; +const static int Test_Prop_0_hasnext[]= {1, 11, 3}; +const static int Test_Prop_0_next[]= {2, 02, 3}; +const static int Test_Prop_1_hasnext[]= {1, 11, 3}; +const static int Test_Prop_1_next[]= {2, 02, 3}; @@ -91,3 +91,9 @@ fprintf(stderr, "It's in state unsafe2.\n"); } +.\n"); + } +} + +} + From 4860212a9dbcdc5df6437f55b2f23f03908e84f7 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 00:13:33 -0500 Subject: [PATCH 146/160] update --- test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c | 7 +++++-- test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 11 +++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c index ec0e029..7ad0a76 100644 --- a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c @@ -10,8 +10,8 @@ void __RVC_HasNext_reset(void) { Prop_0_RVC_state = 0; } -const static int HasNext_hasnext[] = {1, 1, 1, 3, }; -const static int HasNext_next[] = {2, 0, 2, 3, }; +const static int HasNext_hasnext[] = {1, 1, 1, 3}; +const static int HasNext_next[] = {2, 0, 2, 3}; @@ -51,3 +51,6 @@ fprintf(stderr, "next called without hasNext!\n"); } +} + + diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c index da0e0c1..f383c0d 100644 --- a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c @@ -16,10 +16,10 @@ void __RVC_Test_reset(void) Prop_0_RVC_state = 0; Prop_1_RVC_state = 0; } -const static int Test_Prop_0_hasnext[]= {1, 11, 3}; -const static int Test_Prop_0_next[]= {2, 02, 3}; -const static int Test_Prop_1_hasnext[]= {1, 11, 3}; -const static int Test_Prop_1_next[]= {2, 02, 3}; +const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3}; +const static int Test_Prop_0_next[]= {2, 0, 2, 3}; +const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3}; +const static int Test_Prop_1_next[]= {2, 0, 2, 3}; @@ -91,8 +91,7 @@ fprintf(stderr, "It's in state unsafe2.\n"); } -.\n"); - } +} } } From 5847bf170d65204e7cecb30a50fde48c799c83ea Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 12:06:50 -0500 Subject: [PATCH 147/160] TODO:header template --- src/helper/code-gen.k | 8 ++++++++ src/rvm/rvm-compiler-core.k | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index a7be694..8d32b0d 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -125,5 +125,13 @@ rule getHandlerCode((K:String |-> V:String) M:Map) => ListItem("if (" +String K +String "){\n" +String V +String "\n}") getHandlerCode(M) +//wrap the given content with the C's header file's template +//two args are: 1) main part of the header file, 2) spec name +//the wrapper code will be generated based on the spec name +syntax String ::= addCTemplate(String, String) +rule addCTemplate(Content:String, SpecName:String) + => "#ifndef __RVC_" +String SpecName +String "_MONITOR_H\n" + +String "#define __RVC_" +String SpecName +String "_MONITOR_H\n\n" ++String Content +String "\n\n#endif" endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 19d8333..363d5a4 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -115,6 +115,8 @@ module RVM-COMPILER-CORE .K .K //additional computation cell + ///////specific for monitor code in language C +
.List
endmodule From 3a996922b9dd588bd10ead5ae3a910b78930b909 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 12:27:13 -0500 Subject: [PATCH 148/160] generate header contents --- .../c-monitor-event-action.k | 6 +++++ .../c-monitor-template.k | 2 ++ src/helper/code-gen.k | 8 +++++-- test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 22 +++++++++---------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 3bffcd4..2f183c3 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -48,9 +48,15 @@ module C-MONITOR-EVENT-ACTION (.List => ListItem(getStringI(EAs, I))) //the event I's action code + +
HeaderCode:List (.List => + ListItem(printMethodHeader(SN, getStringI(EL, I), getStringI(EPs, I)) +String ";")) +
+ //store the current event name which will be used to infer event transition function. .List => ListItem(getStringI(EL, I)) + ////////////////////////////////////////////////////////////////////////////// //state updates rule $mbody2 => ($stateUpdates(PS) ;; $handlers) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 288c04c..d5b1b63 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -96,6 +96,8 @@ rule $reset $main3 => $main3 SN:String P:Int Code:List (.List => ListItem(printResetFunc(SN, P):String)) +
Header:List (.List => +ListItem(printResetFuncHeader(SN, P) +String ";"))
//rewrite $main3 to state transitions and $main4 rule diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 8d32b0d..1925c7d 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -27,11 +27,15 @@ rule resetGlobalStateI(I:Int) => globalStateVarI(I) +String " = 0;\n" /*Return the string of reset function, given the name of the specification, and the number of properties*/ syntax String ::= printResetFunc(String, Int) [function] + syntax String ::= printResetFuncHeader(String, Int) [function] + +rule printResetFuncHeader(SpecName:String, I:Int) => "void __RVC_" +String SpecName + +String "_reset(void)" rule printResetFunc(SpecName:String, 0) => "" - rule printResetFunc(SpecName:String, I:Int) => "void __RVC_" +String SpecName - +String "_reset(void)\n" +String "{\n" +String resetGlobalStates(I) +String "}" + rule printResetFunc(SpecName:String, I:Int) => printResetFuncHeader(SpecName, I) + +String "\n{\n" +String resetGlobalStates(I) +String "}\n" when I =/=Int 0 syntax String ::= resetGlobalStates(Int) [function] diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c index f383c0d..68031db 100644 --- a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c +++ b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c @@ -1,6 +1,10 @@ #include #include +int foo = 2; + + + static int Prop_0_RVC_state = 0; static int Prop_1_RVC_state = 0; @@ -16,10 +20,11 @@ void __RVC_Test_reset(void) Prop_0_RVC_state = 0; Prop_1_RVC_state = 0; } -const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3}; -const static int Test_Prop_0_next[]= {2, 0, 2, 3}; -const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3}; -const static int Test_Prop_1_next[]= {2, 0, 2, 3}; + +const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; +const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; +const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; @@ -47,7 +52,7 @@ if (Test_Prop_0_start){ fprintf(stderr, "Start!\n"); } } -if (Test_Prop_1_unsafe2) { +if (Test_Prop_1_unsafe2){ { int k; fprintf(stderr, "It's in state unsafe2.\n"); @@ -82,7 +87,7 @@ if (Test_Prop_0_start){ fprintf(stderr, "Start!\n"); } } -if (Test_Prop_1_unsafe2) { +if (Test_Prop_1_unsafe2){ { int k; fprintf(stderr, "It's in state unsafe2.\n"); @@ -91,8 +96,3 @@ fprintf(stderr, "It's in state unsafe2.\n"); } -} -} - -} - From 479559649b51fa6c978f3f00d3a948207c1a3464 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 12:52:17 -0500 Subject: [PATCH 149/160] add scripts for tests --- .../c-monitor-template.k | 18 +++- src/helper/code-gen.k | 2 +- test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c | 56 ----------- test/rvm/fsm/rvc/__RVC_Test_Monitor.c | 98 ------------------- test/rvm/fsm/rvc/runHasNext.sh | 3 + test/rvm/fsm/rvc/runTest.sh | 3 + 6 files changed, 20 insertions(+), 160 deletions(-) delete mode 100644 test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c delete mode 100644 test/rvm/fsm/rvc/__RVC_Test_Monitor.c create mode 100644 test/rvm/fsm/rvc/runHasNext.sh create mode 100644 test/rvm/fsm/rvc/runTest.sh diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index d5b1b63..6c85804 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -154,16 +154,24 @@ when getStringI(EL, J) ==String Id2String(X) andBool PS <=Int 1 ////////////////////////////////////////////////////////////////////////////////// -//generate the output monitor file +//generate the output monitor file and header file rule 2 => 3 - //the output file name + //the output c file name and header file name are stored in cell and resp. .K => "__RVC_" +String SN +String "_Monitor.c" - .K + .K => "__RVC_" +String SN +String "_Monitor.h" .K - SN:String + SN:String rule 3 - OutFileName:String => #write(#open(OutFileName), StringList2String(CL)) + OutCFileName:String => #write(#open(OutCFileName), StringList2String(CL)) CL:List => .List + //generate the output header file + OutHFileName:String => #write(#open(OutHFileName), + addCTemplate(StringList2String(HL), SN)) +
HL:List => .List
+ SN:String + +////////////////////////////////////////////////////////////////////////////////// + endmodule \ No newline at end of file diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 1925c7d..1a75409 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -132,7 +132,7 @@ getHandlerCode(M) //wrap the given content with the C's header file's template //two args are: 1) main part of the header file, 2) spec name //the wrapper code will be generated based on the spec name -syntax String ::= addCTemplate(String, String) +syntax String ::= addCTemplate(String, String) [function] rule addCTemplate(Content:String, SpecName:String) => "#ifndef __RVC_" +String SpecName +String "_MONITOR_H\n" +String "#define __RVC_" +String SpecName +String "_MONITOR_H\n\n" diff --git a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c deleted file mode 100644 index 7ad0a76..0000000 --- a/test/rvm/fsm/rvc/__RVC_HasNext_Monitor.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -static int Prop_0_RVC_state = 0; - -int HasNext_Prop_0_start = 0; -int HasNext_Prop_0_safe = 0; -int HasNext_Prop_0_unsafe = 0; -void __RVC_HasNext_reset(void) -{ -Prop_0_RVC_state = 0; -} -const static int HasNext_hasnext[] = {1, 1, 1, 3}; -const static int HasNext_next[] = {2, 0, 2, 3}; - - - - -void __RVC_HasNext_hasnext(Iterator i) -{ - -{} -Prop_0_RVC_state = HasNext_hasnext[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -if (HasNext_Prop_0_unsafe) { -{ -fprintf(stderr, "next called without hasNext!\n"); - } -} - -} - - - -void __RVC_HasNext_next(Iterator i) -{ - -{} -Prop_0_RVC_state = HasNext_next[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -if (HasNext_Prop_0_unsafe) { -{ -fprintf(stderr, "next called without hasNext!\n"); - } -} - -} - - -} - - diff --git a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c b/test/rvm/fsm/rvc/__RVC_Test_Monitor.c deleted file mode 100644 index 68031db..0000000 --- a/test/rvm/fsm/rvc/__RVC_Test_Monitor.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include - -int foo = 2; - - - -static int Prop_0_RVC_state = 0; - -static int Prop_1_RVC_state = 0; - -int Test_Prop_0_start = 0; -int Test_Prop_0_safe = 0; -int Test_Prop_0_unsafe = 0; -int Test_Prop_1_start2 = 0; -int Test_Prop_1_safe2 = 0; -int Test_Prop_1_unsafe2 = 0; -void __RVC_Test_reset(void) -{ -Prop_0_RVC_state = 0; -Prop_1_RVC_state = 0; -} - -const static int Test_Prop_0_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_0_next[]= {2, 0, 2, 3, }; -const static int Test_Prop_1_hasnext[]= {1, 1, 1, 3, }; -const static int Test_Prop_1_next[]= {2, 0, 2, 3, }; - - - - -void __RVC_Test_hasnext(Iterator i) -{ - -{} -Prop_0_RVC_state = Test_Prop_0_hasnext[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -Prop_1_RVC_state = Test_Prop_1_hasnext[Prop_1_RVC_state]; -start2 = Prop_1_RVC_state == 0 -safe2 = Prop_1_RVC_state == 1 -unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_unsafe){ -{ - fprintf(stderr, "It's not safe.\n"); - } -} -if (Test_Prop_0_start){ -{ - int j; -fprintf(stderr, "Start!\n"); - } -} -if (Test_Prop_1_unsafe2){ -{ - int k; -fprintf(stderr, "It's in state unsafe2.\n"); - } -} - -} - - - -void __RVC_Test_next(Iterator i) -{ - -{ int i = 0; {i--;} int j=i+ 2 ; -{{{}}} } -Prop_0_RVC_state = Test_Prop_0_next[Prop_0_RVC_state]; -start = Prop_0_RVC_state == 0 -safe = Prop_0_RVC_state == 1 -unsafe = Prop_0_RVC_state == 2 -Prop_1_RVC_state = Test_Prop_1_next[Prop_1_RVC_state]; -start2 = Prop_1_RVC_state == 0 -safe2 = Prop_1_RVC_state == 1 -unsafe2 = Prop_1_RVC_state == 2 -if (Test_Prop_0_unsafe){ -{ - fprintf(stderr, "It's not safe.\n"); - } -} -if (Test_Prop_0_start){ -{ - int j; -fprintf(stderr, "Start!\n"); - } -} -if (Test_Prop_1_unsafe2){ -{ - int k; -fprintf(stderr, "It's in state unsafe2.\n"); - } -} - -} - diff --git a/test/rvm/fsm/rvc/runHasNext.sh b/test/rvm/fsm/rvc/runHasNext.sh new file mode 100644 index 0000000..3ea0e9e --- /dev/null +++ b/test/rvm/fsm/rvc/runHasNext.sh @@ -0,0 +1,3 @@ +kompile -d . ../../../../src/rvm/rvc.k + +krun HasNext.rvm diff --git a/test/rvm/fsm/rvc/runTest.sh b/test/rvm/fsm/rvc/runTest.sh new file mode 100644 index 0000000..60f0242 --- /dev/null +++ b/test/rvm/fsm/rvc/runTest.sh @@ -0,0 +1,3 @@ +kompile -d . ../../../../src/rvm/rvc.k + +krun Test.rvm From 01ce5bbd8b86d63cb909b1f3e325d04de78c00de Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 13:03:11 -0500 Subject: [PATCH 150/160] add seatbelt benchmark --- test/rvm/fsm/rvc/{ => HasNext}/HasNext.rvm | 0 test/rvm/fsm/rvc/{ => HasNext}/Test.rvm | 0 test/rvm/fsm/rvc/{ => HasNext}/runHasNext.sh | 0 test/rvm/fsm/rvc/{ => HasNext}/runTest.sh | 0 .../rv-monitor-output/__RVC_HasNext_Monitor.c | 0 .../rv-monitor-output/__RVC_HasNext_Monitor.h | 0 test/rvm/fsm/rvc/SeatBelt/Makefile | 17 +++++ test/rvm/fsm/rvc/SeatBelt/README | 33 ++++++++++ .../fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c | 59 ++++++++++++++++++ .../rvc/SeatBelt}/__RVC_SeatBelt_Monitor.h | 0 test/rvm/fsm/rvc/SeatBelt/expectedOutput | 12 ++++ .../__RVC_SeatBelt_Monitor.c} | 0 .../__RVC_SeatBelt_Monitor.h | 10 +++ test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm | 23 +++++++ test/rvm/fsm/rvc/SeatBelt/test1 | Bin 0 -> 9062 bytes test/rvm/fsm/rvc/SeatBelt/test2 | Bin 0 -> 9062 bytes test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.c | 10 +++ .../fsm/rvc/SeatBelt/test_1/seatbelt.output | 6 ++ test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.c | 8 +++ .../fsm/rvc/SeatBelt/test_2/seatbelt.output | 2 + .../fsm/rvc/SeatBelt/tests/test.expected.err | 10 +++ .../fsm/rvc/SeatBelt/tests/test.expected.out | 2 + 22 files changed, 192 insertions(+) rename test/rvm/fsm/rvc/{ => HasNext}/HasNext.rvm (100%) rename test/rvm/fsm/rvc/{ => HasNext}/Test.rvm (100%) rename test/rvm/fsm/rvc/{ => HasNext}/runHasNext.sh (100%) mode change 100644 => 100755 rename test/rvm/fsm/rvc/{ => HasNext}/runTest.sh (100%) mode change 100644 => 100755 rename test/rvm/fsm/rvc/{ => HasNext}/rv-monitor-output/__RVC_HasNext_Monitor.c (100%) rename test/rvm/fsm/rvc/{ => HasNext}/rv-monitor-output/__RVC_HasNext_Monitor.h (100%) create mode 100644 test/rvm/fsm/rvc/SeatBelt/Makefile create mode 100644 test/rvm/fsm/rvc/SeatBelt/README create mode 100644 test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c rename test/rvm/{ => fsm/rvc/SeatBelt}/__RVC_SeatBelt_Monitor.h (100%) create mode 100644 test/rvm/fsm/rvc/SeatBelt/expectedOutput rename test/rvm/{__RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor => fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.c} (100%) create mode 100644 test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h create mode 100644 test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm create mode 100755 test/rvm/fsm/rvc/SeatBelt/test1 create mode 100755 test/rvm/fsm/rvc/SeatBelt/test2 create mode 100644 test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.c create mode 100644 test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.output create mode 100644 test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.c create mode 100644 test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.output create mode 100644 test/rvm/fsm/rvc/SeatBelt/tests/test.expected.err create mode 100644 test/rvm/fsm/rvc/SeatBelt/tests/test.expected.out diff --git a/test/rvm/fsm/rvc/HasNext.rvm b/test/rvm/fsm/rvc/HasNext/HasNext.rvm similarity index 100% rename from test/rvm/fsm/rvc/HasNext.rvm rename to test/rvm/fsm/rvc/HasNext/HasNext.rvm diff --git a/test/rvm/fsm/rvc/Test.rvm b/test/rvm/fsm/rvc/HasNext/Test.rvm similarity index 100% rename from test/rvm/fsm/rvc/Test.rvm rename to test/rvm/fsm/rvc/HasNext/Test.rvm diff --git a/test/rvm/fsm/rvc/runHasNext.sh b/test/rvm/fsm/rvc/HasNext/runHasNext.sh old mode 100644 new mode 100755 similarity index 100% rename from test/rvm/fsm/rvc/runHasNext.sh rename to test/rvm/fsm/rvc/HasNext/runHasNext.sh diff --git a/test/rvm/fsm/rvc/runTest.sh b/test/rvm/fsm/rvc/HasNext/runTest.sh old mode 100644 new mode 100755 similarity index 100% rename from test/rvm/fsm/rvc/runTest.sh rename to test/rvm/fsm/rvc/HasNext/runTest.sh diff --git a/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c b/test/rvm/fsm/rvc/HasNext/rv-monitor-output/__RVC_HasNext_Monitor.c similarity index 100% rename from test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.c rename to test/rvm/fsm/rvc/HasNext/rv-monitor-output/__RVC_HasNext_Monitor.c diff --git a/test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h b/test/rvm/fsm/rvc/HasNext/rv-monitor-output/__RVC_HasNext_Monitor.h similarity index 100% rename from test/rvm/fsm/rvc/rv-monitor-output/__RVC_HasNext_Monitor.h rename to test/rvm/fsm/rvc/HasNext/rv-monitor-output/__RVC_HasNext_Monitor.h diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile b/test/rvm/fsm/rvc/SeatBelt/Makefile new file mode 100644 index 0000000..96fcfe3 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile @@ -0,0 +1,17 @@ +all: test1 test2 + +__RVC_SeatBelt_Monitor.c: seatbelt.rvm + ../../../../bin/rv-monitor -c seatbelt.rvm + +test1: __RVC_SeatBelt_Monitor.c + gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o test1 + +test2: __RVC_SeatBelt_Monitor.c + gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o test2 + +clean: + rm -f test1 test2 __RVC_* + +test: all + -@./test1 + -@./test2 diff --git a/test/rvm/fsm/rvc/SeatBelt/README b/test/rvm/fsm/rvc/SeatBelt/README new file mode 100644 index 0000000..c102019 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/README @@ -0,0 +1,33 @@ +Linux: +To run test_1 +../../../../bin/rv-monitor -c seatbelt.rvm + +gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o seatbelt + +./seatbelt + + +To run test_2 +../../../../bin/rv-monitor -c seatbelt.rvm + +gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o seatbelt + +./seatbelt + + + +Windows: +To run test_1 +../../../../bin/rv-monitor -c seatbelt.rvm + +gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o seatbelt.exe + +seatbelt.exe + + +To run test_2 +../../../../bin/rv-monitor -c seatbelt.rvm + +gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o seatbelt.exe + +seatbelt.exe diff --git a/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c b/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c new file mode 100644 index 0000000..6b1ef77 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c @@ -0,0 +1,59 @@ +#include + + +#include +static int __RVC_state = 0; + + + +int __RVC_SeatBelt_safe = 0; +int __RVC_SeatBelt_unsafe = 0; + +void +__RVC_SeatBelt_reset(void) +{ + __RVC_state = 0; + } + +static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; +static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; + +void +__RVC_SeatBelt_seatBeltRemoved() +{ +{fprintf(stderr, "Seat belt removed.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTREMOVED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + +void +__RVC_SeatBelt_seatBeltAttached() +{ +{fprintf(stderr, "Seat belt attached.\n");} +__RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; + __RVC_SeatBelt_safe = __RVC_state == 1; + __RVC_SeatBelt_unsafe = __RVC_state == 0; +if(__RVC_SeatBelt_safe) +{ +{ + fprintf(stderr, "set max speed to user input.\n"); + }} +if(__RVC_SeatBelt_unsafe) +{ +{ + fprintf(stderr, "set max speed to 10 mph.\n"); + }} +} + + diff --git a/test/rvm/__RVC_SeatBelt_Monitor.h b/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h similarity index 100% rename from test/rvm/__RVC_SeatBelt_Monitor.h rename to test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h diff --git a/test/rvm/fsm/rvc/SeatBelt/expectedOutput b/test/rvm/fsm/rvc/SeatBelt/expectedOutput new file mode 100644 index 0000000..b8a4e4e --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/expectedOutput @@ -0,0 +1,12 @@ +Test 1 +Test 1 +Seat belt attached. +set max speed to user input. +Seat belt removed. +set max speed to 10 mph. +Seat belt attached. +set max speed to user input. +Test 2 +Test 2 +Seat belt attached. +set max speed to user input. diff --git a/test/rvm/__RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor b/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.c similarity index 100% rename from test/rvm/__RVC_SeatBelt_Monitor.c-GEN-BY-RV-Monitor rename to test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.c diff --git a/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h b/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h new file mode 100644 index 0000000..8c1dc40 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h @@ -0,0 +1,10 @@ +#ifndef __RVC_SEATBELT_MONITOR_H +#define __RVC_SEATBELT_MONITOR_H +void +__RVC_SeatBelt_reset(void); +void +__RVC_SeatBelt_seatBeltRemoved(); +void +__RVC_SeatBelt_seatBeltAttached(); + +#endif diff --git a/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm b/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm new file mode 100644 index 0000000..0c9f0be --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm @@ -0,0 +1,23 @@ +#include + +SeatBelt { + event seatBeltRemoved(){fprintf(stderr, "Seat belt removed.\n");} + + event seatBeltAttached() {fprintf(stderr, "Seat belt attached.\n");} + + fsm : unsafe [ + seatBeltAttached -> safe + ] + safe [ + seatBeltRemoved -> unsafe + ] + + @safe { + fprintf(stderr, "set max speed to user input.\n"); + } + + @unsafe { + fprintf(stderr, "set max speed to 10 mph.\n"); + } + +} diff --git a/test/rvm/fsm/rvc/SeatBelt/test1 b/test/rvm/fsm/rvc/SeatBelt/test1 new file mode 100755 index 0000000000000000000000000000000000000000..9ba74a2193220f6dff309caa96b1b58132ff54a6 GIT binary patch literal 9062 zcmeHMeQaCR6~DIQG)-E^4P`SF+9y^-V2epI+NB`IbJDa9ByCCEGRE3xCw3Zdj-A=h zrDYO}NXr(LvTEw4ZW3rh+u$E2v_DXVv^8BSI&G5{HcdhrllT}YEki0FL)jQ)zjNO? z_VbIYp-KB|+$i_l^E)5+-1F{--@D)JAKd2m`IHpD`l2Fkw!zepQ!6#KMzf6dsFli8 z>(x5d2qcJqQ%i_CEuo9-T4)pN1wb3{-{W_H9>1v@La%XPB~&6LO8r%f$xVlDY<5_o zN*Nj;JBl?N(ky6FH-wrTN0O=75leRMY}d|qLgzU!p)x)i8~rEPU&3#KBiBKk`lLrb^thT>~x`Q6Uh{dYV7`E*3Kx)A_c2tr;4^U zk;>+Q9GEEN8L`y%!GYdBt2^2q-9#Ny9{l=`ILZh8VIFHvsq)p?m8214ez7&FTa+`N zdYYH`DR(kwNFebO?p{|B9@h%s)Snc?g}eQ?yKs80QsUEpYlYeB^F`vR>kG5syWSd@d0~Hi z=GFN0UoY)S44j`;O{R*UKYL;Yk@HUnO||eO6yF8&vx@=f$7g;OKYQ_xxNkoG!eSZ5&yiyM=pSGl zpLyP~f0ga0ZvRKKfycCF4=fiRL?HW~5557&_wF2xH$Hv)sU|4c>nkCw-E+pkE(86g z`F$6@0h87Z>Ou*Wd?1;pU>=`2`y4%+Us7hyti_lYUioNg3DSq^OXncfT`ar^3#Ub^ z$7!8IYu_CCKOelC0gh#a z>&e;HXJ==EAFL$sL)1rS1$$FtuV~C(k6wO*CXMRaN-v$%ON;L17gfC{SdUh$6U`3N zd+kG{R*wL_9%LQbWgMMx(m4a2W5F^BDdM<}cns{ZU=p<};sFibg}NH?7LDDkF&%LP z%{md^t9xmw>RrMECOuEYT{_~iXzPX}2vcGDV}8c&iOnp<_72RvAKNo9^QTy1@c8xP zjRvOR@eZQ92XB16>(BAC9|mY;Ej;!wJoBS(+3Us0;LOFrnfJHC$I{xD;?r}!_?9=z z7iq!Ww=edU*uL2Qm^C+6?etx&L%l|MN&2vBBr+x2=xSEGGb!5`$>eOKn3*UX%%r2u zs+6&fiPRyZG?~ey4ZC2JOPQjP%}!g`J<}_OLS`=16AN|5LhZdF zqc;?Res8Er=WP{ocnN;o`#QP&q+JJrU(I}k-=}CFrJ~OP(7%7QR3QG8-y~A`ZMrMq@ba!R>v#BO z<&+_&EleX!uVgBu@*5Su0jS8H7uQ_%99hBqrqZAqDq1=`VW&nw?V>}+rIpRwnc}31<_mTv8tWbCuu}(^JCH9&N6J~e za%R&iO5Av=G_IoQ!+H2~s9kg<2Q$S|wvex3EXazPT#5|1HJP(jG@H+&wljxNkAZ=# zkWSet70rxWW5v`&#u`tweu3CBRw?gzj=DzeV>-`i1?QAOVrn1h&;|?@vt&9Dv-vp=BECVMr z=X^t;v5UQ|%e}y8FA#g#Uv}{ZA^QotS(d;35MbI@;+OUNINQrUDe+4`Lca!k+8czI z{oxt5H@M?QPj&%3I9Wny_{bS zJW$!kMW5XYtA51xlK(KDe_^(tsAxJ3ul-XVd-={c#rA{$!Two~{XF+S&-MvQj;kgTE_*r8BmBM8tMBDsge`?A{nM8ZD#pjO{|j_!?uose zXY##vp2siqQ~H;A@CIz%{mb{WMH&=}=sR4M7yL~K-1drpPsj(lPBCOEc0%9t*mtsh zCkJR;#$MomqCvi7{Peks%C5`U%eb`?DmuI=es7#&zflyKayqpQL3Ax3eY1)tHh0t{ z1}yZj+K;Rqx4ry;H28-WeHEg!M)D^6H?7Zl{Tl`ZDBC@xVF0_W zoRe;00FlV~SBp1Pe#h40L7Y>j8`A9nX0)6`Zeai?t(-5lc$1QIqZVJO-a;%$}pidy^%CHqe; zz83pQ(hcc$KwXJ@oqG7ElTUg7 z+O11xt`A>lyz$ffm0zt^m-xIBn<(Q(&=g417~@F~eh+XT;!N_mWPOZje0e^Pv!5xC zpC4%b<m8_}cwf^#Xbp&`Do-f^IP?0_I zByhTSN_+D26mUap)>h|OU(N-|+lyL%`MiA%IQ9GcMpHY|-yG2jAb>FPEPkYyX5bXh zxF;S1IQd!4e&pQQr19nZ!)+QDuT}bG;MA{oeH{R9RMjf2gTUALBdUkv5y3R!_@yHI zkIbv@0;f3Xx`;|f*GfGBJdANodi*@e`tm!I)z!~f-~}!XrK>TE{VPnR@U~xoxQO^Yv;CYyZaMXBGx!=+5i PM6b!Sex7{aUu*wwk)>cz literal 0 HcmV?d00001 diff --git a/test/rvm/fsm/rvc/SeatBelt/test2 b/test/rvm/fsm/rvc/SeatBelt/test2 new file mode 100755 index 0000000000000000000000000000000000000000..7ccc48fb68c7d706869ee68fb758ae3380b91afe GIT binary patch literal 9062 zcmeHMZ){uD6~DIQCQVz%EoBQWG*7H-;ZIB(XqT>HJm*jQ!jiU2-7?0)vlG8G-ux%C zpG(_GTSOX!6$%KUsq6#VrfIMbOx-?I71LICspvlJLl~NbG?+RDD1{+qP*~W2?04?F z$9{fsB{XT@dM)2`&+nXb@44sQKkwc9gT8@XexFZp@{6wu;>r!Wgq&Q6$+ePISeIBS zbg@Zn6f1xP@zm-~Ddytxs+^ z5gvSW^L^(o7_VKk>f-aHPkK~`>=zY$VLxH?{BOSD(d&1-H^ajNNNv) zC}wKtNuK?u*zuSl0sBw5dtSAwel-H8_Bd%S++BaW3#aGG$(Z^_lQ9!Ku}TxhblDEh z-wKH_b-roV(OBB{5JXEi9Y@~MrlUmsI0-LZTtd3(81dx7r8&vxiKnJ7mBDX)x4-n# z14ij}W9p5CeX;%v<%^BFFfN>%kmSPiL0!y03&qQ0Ep5F*oVgc{9xys69>&yS$SA$} zpnrJw3^hm&ULHP6qNR&1ZIgtZA&&LWEe4=(lzwlVd;4y~H)p)GScLHlq-ae43C2e0 zMaTYiWj}e>N6i`@)7k^Doc}%?8GbSN79ijIv(#T>>aLSbP_Q>uTv&hLtcFzv`b%@e zm%ay+mNs#z07`Wrm?vRwl+L|C&*pa&nX{MC+4;YHy0ir8L-nPzkjf_J&%3? zw8*&%59?lKeGNdT?vJVNX;{w$carerOvAK}pp=5Qft?9{5&6`jujQ$7%jt3{*doET z$fwJUEv+QQ50E3mo6yQ%QKTN+P-!LHgjU*QD=$^`PAff{osKsV()-sZ2&3!)>UvV? z(2C;d7^L$ubY_Aj5|YP;^!OOqnV^l_!>NO}m zkH>w|V?4*`z0uNA^k9GK!{~wj(x0QTffF}9vO>cUJJCUO|G>>}ZvBgK?vnt`ocZ5= zjAuIiuDz+H?Kt{}b-(oXKV_%=?L*78;+ci2isnnl5~wM^oOR+zA?q-N)|V!_I5 zsq942t|#5PMaxW#LsG3PVcUt(aakGs^=%C7q`j&Me+`{E2^t3-2OUIE%Aik!UIhIG zC@nVkV;E?lVGMa4bQ1It8s|v#lqva+4GG_ouy5n)#-=BHjbXxRGg$b~($X!Ypi+H( zAvQx!`jgPtNjDVU6>7bwWz~aClj80TJ8!vT^Nj?P4welu4WH$n8x4gY_V=t=;opsx z9eEP+UqLR{WR`zTilse0xt~D(Yf!;*|MM05p8>uDeXl2{w$J1L2gof@(H#mu?(Yk= zJ{IT;X(t-`LhX+RjnI~dR~VtLsm8&Oo(^?ILtCPu_U@3@9cqPscc@9mZ8c)JfO_2P zHdT2wU5&ui2waT-MPL%|OO)b@N(Px)ek*jf62u#HSz4p`H}JMViS|EA{C&02VdXwR z#SMyYRo_$mB2W7Sr4K$`$`L*3*NIf#P4@*Hp1*aeWL(mI$MMPlK5g~3oQ5YAI3HHxNls1R91w&K({QYeVXXfBhnvbHyr{}WI1iek^> zx67}CtDdXyypkX?9&gNl0R^0T!3Q)KI3Kqvu zpqR2fuSavrp4TI8-`oG=9(!KjTGfMc+f!e>_KyK0zsNsIydT7sJ+JeQwD#&E>OpvEsDH{uI7_DV3IwkHXv zpmqg&hX0KM)y4g%<0?w~u3*pomP*KI^CthjezN^$R#a4lQ`!(j*8<$OQjx?~4K=ZW z5_(u!508DfJ-+@ceLu~0eIKt*Ov(cn611| zx`hFF!uww>-cWgut;K`br*tVMUUgvA^ zRh9L-7GEuRU9QE~RPKpt@sQwkv=(m>ygt_A;mZ9+Exs1(nC^yTIe?RTUZ>o`fVf8R z`csRq$9fWXL$VwY*WzBM9{xGO>ww!RAn+By^V=l|h*rV#)&*lURPPOHaqq6^%)tin zPx&tG)}=kyhtnIc|MY$37i+|V+V9vVqHry!GbCwL;c*XsFK{3HjH`a}{1}t?@_3$5 z^-Ox|d0Of(e=cW$*X!5p74TPOJ=ck}@`v}!d5O0QUE#bAG{RvY;!o$hlo+Re)NA)k zQXi{Uvrg)jv`ym6<4g+m>WNYV7>C~RHYDp=KCbRp`rdJymHNxa)p6kK@OGQt8@p(n+FCVvm2Ttw&W`!;*l4p`A1>is!aprosm1f}N z&$!1Q4LH^Fks2qw?`)I!^7Ub-#JScg{U&f~*E_!s0oST(mC|A0YyGXFOZmfsDZ=rl z!s`!@t0#ezpLAVB$&$GcKLs8}za~8OJgfBiJyWTRUn+fXd|pucbPq*|-{;N(*CbM# zy{z$J`s;0X9dK>Ay0{JaI(#w3J?lm%)r0=>eISn$F`Bmvb`duU zqqwQOr)S6<=-(eRO@T{I>rkqIuXWSTn4{@j)+&fPkZC4!=Am?MB#}0gb}nBq6U8F} zpTHAo%f>Ci_8njDM9p=SO!^piKCMlBF6WO5=VLrs%w&$j#KoEP4PT>Lz}*I2ZAiC= z4)&OILD3Ds9LzyCm#+wL6)W#$rBYus*4;M{Gxw{)P~YI*gMGbdt*$s4i$!}3Dc>~| z9qcpv_Vgk)PN2A4<6Bagz4z^j4)*sz%O#N)!ou7=u(vxpVD8Quc^b&n%V zOP*b*5OAx-tkbR&7)J9JE|3Jf>AC8z^#IS@?L*BaIAn#KIiAQS;lA0w7oH|lSrd0r zh+j1t6hF9^1*qa@;($e!oy+xm4x2-2oc5#>g#retrz12{XkZLEcVOzG-s>v@$`6+! R%>%tA&hmMx`~F({{{p|WWNrWe literal 0 HcmV?d00001 diff --git a/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.c b/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.c new file mode 100644 index 0000000..cef6242 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.c @@ -0,0 +1,10 @@ +#include "../__RVC_SeatBelt_Monitor.h" +#include + +int main() { + fprintf(stdout, "Test 1\n"); + fprintf(stderr, "Test 1\n"); + __RVC_SeatBelt_seatBeltAttached(); + __RVC_SeatBelt_seatBeltRemoved(); + __RVC_SeatBelt_seatBeltAttached(); +} diff --git a/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.output b/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.output new file mode 100644 index 0000000..ca9b3c7 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/test_1/seatbelt.output @@ -0,0 +1,6 @@ +Seat belt atatched. +Seat belt removed. +Seat belt atatched. +set max speed to user input. +set max speed to 10 mph. +set max speed to user input. diff --git a/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.c b/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.c new file mode 100644 index 0000000..19cb2c6 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.c @@ -0,0 +1,8 @@ +#include "../__RVC_SeatBelt_Monitor.h" +#include + +int main() { + fprintf(stdout, "Test 2\n"); + fprintf(stderr, "Test 2\n"); + __RVC_SeatBelt_seatBeltAttached(); +} diff --git a/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.output b/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.output new file mode 100644 index 0000000..d696f85 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/test_2/seatbelt.output @@ -0,0 +1,2 @@ +Seat belt attached. +set max speed to user input. diff --git a/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.err b/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.err new file mode 100644 index 0000000..0851f11 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.err @@ -0,0 +1,10 @@ +Test 1 +Seat belt attached. +set max speed to user input. +Seat belt removed. +set max speed to 10 mph. +Seat belt attached. +set max speed to user input. +Test 2 +Seat belt attached. +set max speed to user input. diff --git a/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.out b/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.out new file mode 100644 index 0000000..998c014 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/tests/test.expected.out @@ -0,0 +1,2 @@ +Test 1 +Test 2 From e701145783b08c69f7b5c08772f4e719fb728de3 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 13:13:27 -0500 Subject: [PATCH 151/160] refactor --- test/rvm/fsm/rvc/SeatBelt/Makefile | 17 ++++++++++------- .../fsm/rvc/SeatBelt/Makefile_rvc_java_backend | 17 +++++++++++++++++ .../__RVC_SeatBelt_Monitor.c | 0 .../__RVC_SeatBelt_Monitor.h | 0 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 test/rvm/fsm/rvc/SeatBelt/Makefile_rvc_java_backend rename test/rvm/fsm/rvc/SeatBelt/{rv-monitor-output => rv-monitor-generated-monitor-code}/__RVC_SeatBelt_Monitor.c (100%) rename test/rvm/fsm/rvc/SeatBelt/{rv-monitor-output => rv-monitor-generated-monitor-code}/__RVC_SeatBelt_Monitor.h (100%) diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile b/test/rvm/fsm/rvc/SeatBelt/Makefile index 96fcfe3..2024d4d 100644 --- a/test/rvm/fsm/rvc/SeatBelt/Makefile +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile @@ -1,17 +1,20 @@ -all: test1 test2 +all: compile test1 test2 + +compile: rvc.k + kompile -d . ../../../../../src/rvm/rvc.k __RVC_SeatBelt_Monitor.c: seatbelt.rvm - ../../../../bin/rv-monitor -c seatbelt.rvm + krun seatbelt.rvm test1: __RVC_SeatBelt_Monitor.c - gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o test1 + gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o test1_k test2: __RVC_SeatBelt_Monitor.c - gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o test2 + gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o test2_k clean: - rm -f test1 test2 __RVC_* + rm -f test1_k test2_k __RVC_* test: all - -@./test1 - -@./test2 + -@./test1_k + -@./test2_k diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile_rvc_java_backend b/test/rvm/fsm/rvc/SeatBelt/Makefile_rvc_java_backend new file mode 100644 index 0000000..96fcfe3 --- /dev/null +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile_rvc_java_backend @@ -0,0 +1,17 @@ +all: test1 test2 + +__RVC_SeatBelt_Monitor.c: seatbelt.rvm + ../../../../bin/rv-monitor -c seatbelt.rvm + +test1: __RVC_SeatBelt_Monitor.c + gcc test_1/seatbelt.c __RVC_SeatBelt_Monitor.c -o test1 + +test2: __RVC_SeatBelt_Monitor.c + gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o test2 + +clean: + rm -f test1 test2 __RVC_* + +test: all + -@./test1 + -@./test2 diff --git a/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.c b/test/rvm/fsm/rvc/SeatBelt/rv-monitor-generated-monitor-code/__RVC_SeatBelt_Monitor.c similarity index 100% rename from test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.c rename to test/rvm/fsm/rvc/SeatBelt/rv-monitor-generated-monitor-code/__RVC_SeatBelt_Monitor.c diff --git a/test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h b/test/rvm/fsm/rvc/SeatBelt/rv-monitor-generated-monitor-code/__RVC_SeatBelt_Monitor.h similarity index 100% rename from test/rvm/fsm/rvc/SeatBelt/rv-monitor-output/__RVC_SeatBelt_Monitor.h rename to test/rvm/fsm/rvc/SeatBelt/rv-monitor-generated-monitor-code/__RVC_SeatBelt_Monitor.h From 7fd5a1943422af0c79510cf4fcf02379fdf5d64d Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 13:27:40 -0500 Subject: [PATCH 152/160] update make file --- test/rvm/fsm/rvc/SeatBelt/Makefile | 2 +- .../fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c | 59 ------------------- .../fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h | 10 ---- 3 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c delete mode 100644 test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile b/test/rvm/fsm/rvc/SeatBelt/Makefile index 2024d4d..6d7c9db 100644 --- a/test/rvm/fsm/rvc/SeatBelt/Makefile +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile @@ -1,6 +1,6 @@ all: compile test1 test2 -compile: rvc.k +compile: ../../../../../src/rvm/rvc.k kompile -d . ../../../../../src/rvm/rvc.k __RVC_SeatBelt_Monitor.c: seatbelt.rvm diff --git a/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c b/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c deleted file mode 100644 index 6b1ef77..0000000 --- a/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.c +++ /dev/null @@ -1,59 +0,0 @@ -#include - - -#include -static int __RVC_state = 0; - - - -int __RVC_SeatBelt_safe = 0; -int __RVC_SeatBelt_unsafe = 0; - -void -__RVC_SeatBelt_reset(void) -{ - __RVC_state = 0; - } - -static int __RVC_SEATBELT_SEATBELTREMOVED[] = {-1,0, }; -static int __RVC_SEATBELT_SEATBELTATTACHED[] = {1, -1,}; - -void -__RVC_SeatBelt_seatBeltRemoved() -{ -{fprintf(stderr, "Seat belt removed.\n");} -__RVC_state = __RVC_SEATBELT_SEATBELTREMOVED[__RVC_state]; - __RVC_SeatBelt_safe = __RVC_state == 1; - __RVC_SeatBelt_unsafe = __RVC_state == 0; -if(__RVC_SeatBelt_safe) -{ -{ - fprintf(stderr, "set max speed to user input.\n"); - }} -if(__RVC_SeatBelt_unsafe) -{ -{ - fprintf(stderr, "set max speed to 10 mph.\n"); - }} -} - -void -__RVC_SeatBelt_seatBeltAttached() -{ -{fprintf(stderr, "Seat belt attached.\n");} -__RVC_state = __RVC_SEATBELT_SEATBELTATTACHED[__RVC_state]; - __RVC_SeatBelt_safe = __RVC_state == 1; - __RVC_SeatBelt_unsafe = __RVC_state == 0; -if(__RVC_SeatBelt_safe) -{ -{ - fprintf(stderr, "set max speed to user input.\n"); - }} -if(__RVC_SeatBelt_unsafe) -{ -{ - fprintf(stderr, "set max speed to 10 mph.\n"); - }} -} - - diff --git a/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h b/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h deleted file mode 100644 index 8c1dc40..0000000 --- a/test/rvm/fsm/rvc/SeatBelt/__RVC_SeatBelt_Monitor.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __RVC_SEATBELT_MONITOR_H -#define __RVC_SEATBELT_MONITOR_H -void -__RVC_SeatBelt_reset(void); -void -__RVC_SeatBelt_seatBeltRemoved(); -void -__RVC_SeatBelt_seatBeltAttached(); - -#endif From a916fb720469a9e60beac61dafa56351e9486ede Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Wed, 11 May 2016 14:53:43 -0500 Subject: [PATCH 153/160] make it compile --- src/common/package-syntax.k | 5 +++++ src/helper/print-ast.k | 15 ++++++++------- src/rvm/rvm-compiler.k | 2 +- test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/common/package-syntax.k b/src/common/package-syntax.k index 46192f5..6bf299f 100644 --- a/src/common/package-syntax.k +++ b/src/common/package-syntax.k @@ -8,6 +8,11 @@ syntax ImportDec ::= "import" TypeName ";" [klabel('TypeImport | "import" "static" TypeName "." Id ";" [klabel('StaticImportDec)] | "import" "static" TypeName "." "*" ";" [klabel('StaticImportOnDemandDec)] +// //for c code + | "#include" "<" Id ".h" ">" [klabel('CInclude1)] + | "#include" "\"" Id ".h" "\"" [klabel('CInclude2)] + + syntax PackageDec ::= "package" PackageName ";" [klabel('PackageDec)] syntax OptionalPackageDec ::= PackageDec | None syntax None diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 58b327f..218db72 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -8,13 +8,14 @@ module PRINT-AST imports C-MONITOR-TEMPLATE-SYNTAX //print package ast - syntax String ::= toString(OptionalPackageDec) [function] - rule toString(package X:PackageName ;) => "package " +String toString(X) +String ";" - rule toString(None:OptionalPackageDec) => "\n" [owise] - - syntax String ::= toString(PackageName) [function] - rule toString(X:Id) => Id2String(X) - rule toString(P:PackageName . X:Id) => toString(P) +String "." +String Id2String(X) + syntax String ::= PackageDec2String(OptionalPackageDec) [function] + rule PackageDec2String(package X:PackageName ;) => "package " +String PackageName2String(X) + +String ";" + rule PackageDec2String(None:OptionalPackageDec) => "\n" + + syntax String ::= PackageName2String(PackageName) [function] + rule PackageName2String(X:Id) => Id2String(X) + rule PackageName2String(P:PackageName . X:Id) => PackageName2String(P) +String "." +String Id2String(X) //get logic name syntax LogicName ::= getLogicName(PropertyDec) [function] diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index d904538..518784d 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -17,7 +17,7 @@ module RVM-COMPILER * Store the package info and import list. */ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z - "" => toString(X) + "" => PackageDec2String(X) .K => Y /** diff --git a/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm b/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm index 0c9f0be..bd07116 100644 --- a/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm +++ b/test/rvm/fsm/rvc/SeatBelt/seatbelt.rvm @@ -1,6 +1,6 @@ #include -SeatBelt { +SeatBelt() { event seatBeltRemoved(){fprintf(stderr, "Seat belt removed.\n");} event seatBeltAttached() {fprintf(stderr, "Seat belt attached.\n");} From bd215454b480e31d7a34491c892f5ed2b129e08f Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 01:08:00 -0500 Subject: [PATCH 154/160] print import decl list --- src/c-monitor-code-template/c-monitor-template.k | 5 +++-- src/helper/print-ast.k | 6 ++++++ src/rvm/rvm-compiler-core.k | 2 +- src/rvm/rvm-compiler.k | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/c-monitor-code-template/c-monitor-template.k b/src/c-monitor-code-template/c-monitor-template.k index 6c85804..be439fa 100644 --- a/src/c-monitor-code-template/c-monitor-template.k +++ b/src/c-monitor-code-template/c-monitor-template.k @@ -31,9 +31,10 @@ rule //generate the include part. //TODO: incorporate the user provided includes rule $incl $main => $main - L:List (.List => ListItem("#include ") - ListItem("#include \n") ) + L:List (.List => ListItem(IDL) + ListItem("#include \n\n") ) + IDL:String //incorporate the user provided declarations rule $main diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 218db72..4e54f5a 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -115,4 +115,10 @@ rule getHandlerCodeStr(BB:BlockBubble) => Block2Str(BB) /*Print the Decl list as string*/ syntax String ::= declBubbleList2String(DecBubbleList) [function, hook(STRING.token2string)] +/*Print import decl list as a string*/ +syntax String ::= importList2String(ImportDecList) [function] +syntax String ::= importDecl2String(ImportDec) [function] + +rule importList2String(.ImportDecList) + endmodule \ No newline at end of file diff --git a/src/rvm/rvm-compiler-core.k b/src/rvm/rvm-compiler-core.k index 363d5a4..c925135 100644 --- a/src/rvm/rvm-compiler-core.k +++ b/src/rvm/rvm-compiler-core.k @@ -40,7 +40,7 @@ module RVM-COMPILER-CORE "" - .K + "" .List //list of event name strings //the params of each event, indexed by event id diff --git a/src/rvm/rvm-compiler.k b/src/rvm/rvm-compiler.k index 518784d..5b3acf9 100644 --- a/src/rvm/rvm-compiler.k +++ b/src/rvm/rvm-compiler.k @@ -18,7 +18,7 @@ module RVM-COMPILER */ rule X:OptionalPackageDec Y:ImportDecList Z:SpecDec => Z "" => PackageDec2String(X) - .K => Y + "" => importList2String(Y) /** * Store the spec name and params. From 368e451e39155947e4548271227b53f26ea49453 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 01:20:17 -0500 Subject: [PATCH 155/160] add --- src/helper/print-ast.k | 7 ++++++- test/rvm/fsm/rvc/HasNext/Makefile | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/rvm/fsm/rvc/HasNext/Makefile diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index 4e54f5a..f77364c 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -119,6 +119,11 @@ syntax String ::= declBubbleList2String(DecBubbleList) [function, hook(STRING.to syntax String ::= importList2String(ImportDecList) [function] syntax String ::= importDecl2String(ImportDec) [function] -rule importList2String(.ImportDecList) +rule importList2String(.ImportDecList) => "" +rule importList2String(I:ImportDec) => importDecl2String(I) +rule importList2String(I:ImportDec IDL:ImportDecList) => importDecl2String(I) +String "\n" + +String importList2String(IDL) + +rule importDecl2String(I:ImportDec) => "fake import" endmodule \ No newline at end of file diff --git a/test/rvm/fsm/rvc/HasNext/Makefile b/test/rvm/fsm/rvc/HasNext/Makefile new file mode 100644 index 0000000..bb4c71f --- /dev/null +++ b/test/rvm/fsm/rvc/HasNext/Makefile @@ -0,0 +1,5 @@ +all: clean + +clean: + rm __RVC_*_Monitor* + From e862a60be7887445de14861cc16b8116c653fb14 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 02:00:51 -0500 Subject: [PATCH 156/160] #include statements generated successfully --- src/common/package-syntax.k | 3 ++- src/helper/print-ast.k | 17 ++++++++++++++--- test/rvm/fsm/rvc/HasNext/Test.rvm | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/common/package-syntax.k b/src/common/package-syntax.k index 6bf299f..8634c04 100644 --- a/src/common/package-syntax.k +++ b/src/common/package-syntax.k @@ -10,7 +10,8 @@ syntax ImportDec ::= "import" TypeName ";" [klabel('TypeImport // //for c code | "#include" "<" Id ".h" ">" [klabel('CInclude1)] - | "#include" "\"" Id ".h" "\"" [klabel('CInclude2)] + | "#include" String [klabel('CInclude2)] +// | "#include" "\"" Id ".h" "\"" [klabel('CInclude2)] syntax PackageDec ::= "package" PackageName ";" [klabel('PackageDec)] diff --git a/src/helper/print-ast.k b/src/helper/print-ast.k index f77364c..c5c1b6e 100644 --- a/src/helper/print-ast.k +++ b/src/helper/print-ast.k @@ -119,11 +119,22 @@ syntax String ::= declBubbleList2String(DecBubbleList) [function, hook(STRING.to syntax String ::= importList2String(ImportDecList) [function] syntax String ::= importDecl2String(ImportDec) [function] -rule importList2String(.ImportDecList) => "" -rule importList2String(I:ImportDec) => importDecl2String(I) +rule importList2String(.ImportDecList) => "\n" +rule importList2String(I:ImportDec) => importDecl2String(I) +String "\n" rule importList2String(I:ImportDec IDL:ImportDecList) => importDecl2String(I) +String "\n" +String importList2String(IDL) -rule importDecl2String(I:ImportDec) => "fake import" +rule importDecl2String(import TN:TypeName ;) => "import " +String TypeName2String(TN) +String ";" +rule importDecl2String(import PN:PackageName .*;) => "import " +String PackageName2String(PN) + +String ".*;" +rule importDecl2String(import static TN:TypeName . X:Id ;) => "import static " +String + TypeName2String(TN) +String "." +String Id2String(X) +String ";" + +rule importDecl2String(import static TN:TypeName . * ;) => "import static " +String + TypeName2String(TN) +String ".*;" + +rule importDecl2String(#include ) => "#include <" +String Id2String(X) +String ".h>" + +rule importDecl2String(#include Str:String) => "#include \"" +String Str +String "\"" endmodule \ No newline at end of file diff --git a/test/rvm/fsm/rvc/HasNext/Test.rvm b/test/rvm/fsm/rvc/HasNext/Test.rvm index 6119658..5da5e06 100644 --- a/test/rvm/fsm/rvc/HasNext/Test.rvm +++ b/test/rvm/fsm/rvc/HasNext/Test.rvm @@ -1,5 +1,9 @@ package rvm; +#include +#include "string.h" +#include + Test (int o){ int foo = 2; From 94db2fb6588f63bfc5c225cf6d1caf3ebcd1f9cd Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 02:19:25 -0500 Subject: [PATCH 157/160] fix a bug --- src/c-monitor-code-template/c-monitor-event-action.k | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/c-monitor-code-template/c-monitor-event-action.k b/src/c-monitor-code-template/c-monitor-event-action.k index 2f183c3..7112844 100644 --- a/src/c-monitor-code-template/c-monitor-event-action.k +++ b/src/c-monitor-code-template/c-monitor-event-action.k @@ -125,9 +125,12 @@ rule $lsUpdates(I:Int) => $lsUpdate(0) $lsUpdates(I) rule $lsUpdate(I:Int) $lsUpdates(J:Int) => $lsUpdate(I +Int 1) $lsUpdates(J -Int 1) G:Int + SN:String M:Map //the three args are local state var, global state var, state rank - C:List (.List => ListItem(localStateUpdate(getStrKey(M, I), globalStateVarI(G), I))) +//localStateVarI(spec name, property rank, state name) + C:List (.List => ListItem(localStateUpdate( localStateVarI(SN, G, getStrKey(M, I)), +globalStateVarI(G), I))) when J >Int 0 From e4d8fb897263c0af26b1f186b9f98414cb2ff181 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 02:34:59 -0500 Subject: [PATCH 158/160] make generated c code compile --- src/helper/code-gen.k | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/code-gen.k b/src/helper/code-gen.k index 1a75409..f64c856 100644 --- a/src/helper/code-gen.k +++ b/src/helper/code-gen.k @@ -110,7 +110,7 @@ rule globalStateUpdate(GSV:String, TF:String) => /////////////the three args are local state var, global state var, state rank syntax String ::= localStateUpdate(String, String, Int) [function] rule localStateUpdate(LSV:String, GSV:String, SR:Int) => - LSV +String " = " +String GSV +String " == " +String Int2String(SR) + LSV +String " = " +String GSV +String " == " +String Int2String(SR) +String ";" //////////////////////////////////////////////////////////////////////////////// //generate the event handler code From 4a4f13732fab63600c0b66c6f16160c4c3114767 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 02:51:01 -0500 Subject: [PATCH 159/160] update make file --- test/rvm/fsm/rvc/SeatBelt/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile b/test/rvm/fsm/rvc/SeatBelt/Makefile index 6d7c9db..004af09 100644 --- a/test/rvm/fsm/rvc/SeatBelt/Makefile +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile @@ -15,6 +15,8 @@ test2: __RVC_SeatBelt_Monitor.c clean: rm -f test1_k test2_k __RVC_* -test: all - -@./test1_k - -@./test2_k +test: test1_k test2_k + -@./test1_k 1> actualOut 2> actualErr + -@./test2_k 1>> actualOut 2>> actualErr + diff tests/test.expected.out actualOut + diff tests/test.expected.err actualErr From 5dde7115555385cc66cd1671409982029cc37d94 Mon Sep 17 00:00:00 2001 From: xiaohe27 Date: Thu, 12 May 2016 02:52:07 -0500 Subject: [PATCH 160/160] update make file: clean --- test/rvm/fsm/rvc/SeatBelt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/rvm/fsm/rvc/SeatBelt/Makefile b/test/rvm/fsm/rvc/SeatBelt/Makefile index 004af09..836d9d9 100644 --- a/test/rvm/fsm/rvc/SeatBelt/Makefile +++ b/test/rvm/fsm/rvc/SeatBelt/Makefile @@ -13,7 +13,7 @@ test2: __RVC_SeatBelt_Monitor.c gcc test_2/seatbelt.c __RVC_SeatBelt_Monitor.c -o test2_k clean: - rm -f test1_k test2_k __RVC_* + rm -f test1_k test2_k __RVC_* actualOut actualErr test: test1_k test2_k -@./test1_k 1> actualOut 2> actualErr