edits
[cdsspec-compiler.git] / grammer / spec_compiler.jj
index 9950ad886f7926bd2712d192ad5fa2ccfa292db9..9195e13a6c70a479d44ade76a9d27658de8299a2 100644 (file)
                @DefineFunc:
        @Interface_cluster:
                ...
-       @Happens-before:
+       @Happens_before:
                ...
+       @Commutativity: // This is to define the admissibility condition
+               // Enq <-> Enq (_M1.q != _M2.q)
+               // Enq <-> Deq (_M1.q != _M2.q)
+               // Deq <-> Deq (_M1.q != _M2.q)
+               // Enq <-> Deq (_M1.q == _M2.q && _M2.__RET__ == NULL)
        @End
        
        b) Interface construct
        @Begin
        @Potential_commit_point_define: ...
        @Label: ...
+       @End
+
+               OR
+
+       @Begin
+       @Potential_additional_ordering_point_define: ...
+       @Label: ...
        @End
 
        d) Commit point define construct
        @Commit_point_define_check: ...
        @Label: ...
        @End
+
+               OR
+       
+       # Addition ordering point is used to order operations when there are "equal"
+       # commit point operations on the same location and that we cannot decide
+       # which operation goes first, we will use additional ordering point to order
+       # them (it's just similar to commit points). In implementation, we can just
+       # treat them as commit points with a special flag.
+
+       @Begin
+       @Additional_ordering_point_define: ...
+       @Potential_additional_ordering_point_label: ...
+       @Label: ...
+       @End
+       
+               OR
        
+       @Begin
+       @Additional_ordering_point_define: ...
+       @Label: ...
+       @End
+
                OR
 
        @Begin
-       @Commit_point_define: ...
-       @Potential_commit_point_label: ...
+       @Additional_ordering_point_define_check: ...
+       @Label: ...
+       @End
+
+       // Commit point clear (just as a normal commit point, but it is used to
+       // clear all commit points)
+       @Begin
+       @Commit_point_clear: ...
        @Label: ...
        @End
 
@@ -120,8 +159,10 @@ import edu.uci.eecs.specCompiler.specExtraction.Construct;
 import edu.uci.eecs.specCompiler.specExtraction.GlobalConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.PotentialCPDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.CommutativityRule;
 import edu.uci.eecs.specCompiler.specExtraction.CPDefineConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.CPClearConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
@@ -331,12 +372,16 @@ SKIP : {
        <DECLARE_VAR: "@DeclareVar:">
 |
        <INIT_VAR: "@InitVar:">
+|
+       <CLEANUP: "@Finalize:">
 |
        <DEFINE_FUNC: "@DefineFunc:">
 |
        <INTERFACE_CLUSTER: "@Interface_cluster:">
 |
        <HAPPENS_BEFORE: "@Happens_before:">
+|
+       <COMMUTATIVITY: "@Commutativity:">
 |
        <INTERFACE: "@Interface:">
 |
@@ -367,14 +412,24 @@ SKIP : {
        <POST_CHECK: "@Post_check:">
 |
        <POTENTIAL_COMMIT_POINT_DEFINE: "@Potential_commit_point_define:">
+|
+       <POTENTIAL_ADDITIONAL_ORDERING_POINT_DEFINE: "@Potential_additional_ordering_point_define:">
 |
        <LABEL: "@Label:">
 |
        <COMMIT_POINT_DEFINE_CHECK: "@Commit_point_define_check:">
+|
+       <ADDITIONAL_ORDERING_POINT_DEFINE_CHECK: "@Additional_ordering_point_define_check:">
 |
        <COMMIT_POINT_DEFINE: "@Commit_point_define:">
+|
+       <ADDITIONAL_ORDERING_POINT_DEFINE: "@Additional_ordering_point_define:">
+|
+       <COMMIT_POINT_CLEAR: "@Commit_point_clear:">
 |
        <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
+|
+       <POTENTIAL_ADDITIONAL_ORDERING_POINT_LABEL: "@Potential_additional_ordering_point_label:">
 }
 
 
@@ -421,6 +476,8 @@ SKIP : {
        <CLOSE_BRACE: "}">
 |
        <HB_SYMBOL: "->">
+|
+       <COMMUTATIVITY_SYMBOL: "<->">
 |
        <COMMA: ",">
 |
@@ -610,24 +667,6 @@ String Type() :
        }
 }
 
-void Test() :
-{
-       String str;     
-       FunctionHeader func;
-}
-{
-       /*
-       str = Type()
-       {
-               System.out.println(str);
-       }
-       */
-       func = FuncDecl() 
-       {
-               System.out.println(func);
-       }
-       
-}
 
 String ParameterizedName() :
 {
@@ -903,6 +942,10 @@ Construct ParseSpec() :
        LOOKAHEAD(2) res = Potential_commit_point_define() |
        LOOKAHEAD(2) res = Commit_point_define() |
        LOOKAHEAD(2) res = Commit_point_define_check() |
+       LOOKAHEAD(2) res = Potential_additional_ordering_point_define() |
+       LOOKAHEAD(2) res = Additional_ordering_point_define() |
+       LOOKAHEAD(2) res = Additional_ordering_point_define_check() |
+       LOOKAHEAD(2) res = Commit_point_clear() |
        LOOKAHEAD(2) res = Entry_point() |
        LOOKAHEAD(2) res = Class_begin() |
        LOOKAHEAD(2) res = Class_end() |
@@ -944,6 +987,7 @@ GlobalConstruct Global_construct() :
                        { res = new GlobalConstruct(_file, _content.size(), code, options); }
                        (Interface_clusters(res))?
                        (Happens_before(res))?
+                       (Commutativity(res))?
                <END>
        {
                res.unfoldInterfaceCluster();
@@ -953,7 +997,7 @@ GlobalConstruct Global_construct() :
 
 SequentialDefineSubConstruct Global_define() :
 {
-       ArrayList<String> initVar, defineFunc, code, declareStruct;
+       ArrayList<String> initVar, cleanup, defineFunc, code, declareStruct;
        ArrayList<ArrayList<String>> defineFuncs;
        ArrayList<VariableDeclaration> declareVars;
        ArrayList<ArrayList<String>> declareStructs;
@@ -963,7 +1007,8 @@ SequentialDefineSubConstruct Global_define() :
 {
        {
                declareVars = new ArrayList<VariableDeclaration>();
-               initVar = null;
+               initVar = new ArrayList<String>();
+               cleanup = new ArrayList<String>();
                defineFuncs = new ArrayList<ArrayList<String>>();
                declareStructs = new ArrayList<ArrayList<String>>();
        }
@@ -973,10 +1018,11 @@ SequentialDefineSubConstruct Global_define() :
                (<DECLARE_VAR> ((declareVar = TypeParam() <SEMI_COLON> {
                        declareVars.add(declareVar); } )*))?
        (<INIT_VAR> (code = C_CPP_CODE(null) { initVar = code; } ))?
+       (<CLEANUP> (code = C_CPP_CODE(null) { cleanup = code; } ))?
        (<DEFINE_FUNC> (defineFunc = C_CPP_CODE(null) { defineFuncs.add(defineFunc); }))*
        {
                SequentialDefineSubConstruct res = new
-                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, defineFuncs);
+                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, cleanup, defineFuncs);
                //System.out.println(res);
                return res;
        }
@@ -1032,6 +1078,29 @@ void Happens_before(GlobalConstruct inst) :
        )+
 }
 
+void Commutativity(GlobalConstruct inst) :
+{
+       String method1, method2, condition;
+       ArrayList<String> content;
+}
+{
+       {
+               content = new ArrayList<String>();
+       }
+
+       (
+       <COMMUTATIVITY>
+       method1 = <IDENTIFIER>.image  <COMMUTATIVITY_SYMBOL>
+       method2 = <IDENTIFIER>.image
+       <COLON>
+       content = C_CPP_CODE(null)
+       { condition = stringArray2String(content); }
+       {
+               inst.addCommutativityRule(method1, method2, condition);
+       }
+       )+
+}
+
 InterfaceConstruct Interface() :
 {
        InterfaceConstruct res;
@@ -1117,6 +1186,26 @@ PotentialCPDefineConstruct Potential_commit_point_define() :
        }
 }
 
+PotentialCPDefineConstruct Potential_additional_ordering_point_define() :
+{
+       PotentialCPDefineConstruct res;
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN>
+                       <POTENTIAL_ADDITIONAL_ORDERING_POINT_DEFINE> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               // Set the boolean flag isAdditionalOrderingPoint to be true
+               res = new PotentialCPDefineConstruct(_file, _content.size(), true, label, condition); 
+               return res;
+       }
+}
+
 
 CPDefineConstruct Commit_point_define() :
 {
@@ -1133,7 +1222,47 @@ CPDefineConstruct Commit_point_define() :
                        <LABEL> (label = <IDENTIFIER>.image)
                <END>
        {
-               res = new CPDefineConstruct(_file, _content.size(), label, potentialCPLabel, condition);
+               res = new CPDefineConstruct(_file, _content.size(), false, label, potentialCPLabel, condition);
+               return res;
+       }
+}
+
+CPDefineConstruct Additional_ordering_point_define() :
+{
+       CPDefineConstruct res;
+       String label, potentialCPLabel, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN>
+                       <ADDITIONAL_ORDERING_POINT_DEFINE> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
+                       <POTENTIAL_ADDITIONAL_ORDERING_POINT_LABEL> (potentialCPLabel = <IDENTIFIER>.image)
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               // Set the boolean flag isAdditionalOrderingPoint to be true
+               res = new CPDefineConstruct(_file, _content.size(), true, label, potentialCPLabel, condition);
+               return res;
+       }
+}
+
+CPClearConstruct Commit_point_clear() :
+{
+       CPClearConstruct res;   
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN> 
+                       <COMMIT_POINT_CLEAR> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               res = new CPClearConstruct(_file, _content.size(), label, condition);
                return res;
        }
 }
@@ -1153,7 +1282,27 @@ CPDefineCheckConstruct Commit_point_define_check() :
                        <LABEL> (label = <IDENTIFIER>.image)
                <END>
        {
-               res = new CPDefineCheckConstruct(_file, _content.size(), label, condition);
+               res = new CPDefineCheckConstruct(_file, _content.size(), false, label, condition);
+               return res;
+       }
+}
+
+CPDefineCheckConstruct Additional_ordering_point_define_check() :
+{
+       CPDefineCheckConstruct res;     
+       String label, condition;
+       ArrayList<String> content;
+}
+{
+
+       { res = null; }
+               <BEGIN> 
+                       <ADDITIONAL_ORDERING_POINT_DEFINE_CHECK> (content = C_CPP_CODE(null) { condition = stringArray2String(content); })
+                       <LABEL> (label = <IDENTIFIER>.image)
+               <END>
+       {
+               // Set the boolean flag isAdditionalOrderingPoint to be true
+               res = new CPDefineCheckConstruct(_file, _content.size(), true, label, condition);
                return res;
        }
 }