add support for unattached ordering points
[cdsspec-compiler.git] / src / edu / uci / eecs / codeGenerator / CodeGeneratorUtils.java
index fffeae5971928535b3ea3ab4de76cfb48c6adca4..272f4aae6c68ad08ddda366f473ea0909620f14b 100644 (file)
@@ -169,6 +169,18 @@ public class CodeGeneratorUtils {
                code.addLine("#endif");
                code.addLine("");
 
+               // Declare _createOPDefineUnattached
+               code.addLine(ShortComment("Declare _createOPDefineUnattached"));
+               // void _createOPDefineUnattached();
+               code.addLine("void _createOPDefineUnattached();");
+               code.addLine("");
+
+               // Declare _createOPClearDefineUnattached
+               code.addLine(ShortComment("Declare _createOPClearDefineUnattached"));
+               // void _createOPClearDefineUnattached();
+               code.addLine("void _createOPClearDefineUnattached();");
+               code.addLine("");
+
                code.addLine(ShortComment("Declaration of some c-strings (CSTR)"));
 
                // Interface name strings
@@ -296,6 +308,31 @@ public class CodeGeneratorUtils {
                code.addLine("");
                code.addLine("");
 
+               // Define the fake ordering point operation
+               code.addLine(ShortComment("Define the fake ordering point operation"));
+               // atomic_int _FAKE_OP_;
+               code.addLine("atomic_int " + SpecNaming.FakeOP + ";");
+               code.addLine("");
+
+               // Define _createOPDefineUnattached
+               code.addLine(ShortComment("Define _createOPDefineUnattached"));
+               code.addLine("void " + SpecNaming.CreateOPDefineUnattachedFunc + "() {");
+               code.addLine(TabbedLine(ShortComment("A load acting as the fake OP")));
+               code.addLine(TabbedLine(SpecNaming.FakeOP
+                               + ".load(memory_order_relaxed);"));
+               code.addLine(TabbedLine(SpecNaming.CreateOPDefineAnnoFunc + "();"));
+               code.addLine("}");
+
+               // Define _createOPClearDefineUnattached
+               code.addLine(ShortComment("Define _createOPClearDefineUnattached"));
+               code.addLine("void " + SpecNaming.CreateOPClearDefineUnattachedFunc
+                               + "() {");
+               code.addLine(TabbedLine(ShortComment("A load acting as the fake OP")));
+               code.addLine(TabbedLine(SpecNaming.FakeOP
+                               + ".load(memory_order_relaxed);"));
+               code.addLine(TabbedLine(SpecNaming.CreateOPClearDefineAnnoFunc + "();"));
+               code.addLine("}");
+
                code.addLine(ShortComment("Definition of some c-strings (CSTR)"));
                code.addLine(ShortComment("A special empty string"));
                code.addLine(DeclareDefine(SpecNaming.CString, SpecNaming.EmptyCString,
@@ -571,11 +608,11 @@ public class CodeGeneratorUtils {
                                        construct.preCondition.align(1);
                                        code.addLine(TabbedLine(ShortComment("Execute PreCondition")));
                                        code.addLines(construct.preCondition);
-                                       
+
                                        // By default, we will return true for @PreCondition
                                        code.addLine(TabbedLine(ShortComment("By default @PreCondition returns true")));
                                        code.addLine(TabbedLine("return true;"));
-                                       
+
                                        code.addLine("}");
                                        code.addLine("");
 
@@ -603,7 +640,7 @@ public class CodeGeneratorUtils {
                                        // By default, we will return true for @PostCondition
                                        code.addLine(TabbedLine(ShortComment("By default @PostCondition returns true")));
                                        code.addLine(TabbedLine("return true;"));
-                                       
+
                                        code.addLine("}");
                                        code.addLine("");
                                }
@@ -639,6 +676,11 @@ public class CodeGeneratorUtils {
                code.addLine(ShortComment("Define INIT annotation instrumentation function"));
                code.addLine("void _createInitAnnotation() {");
 
+               // Init the fake ordering point place holder
+               code.addLine(TabbedLine(ShortComment("Init the fake ordering point place holder")));
+               code.addLine(TabbedLine(SpecNaming.FakeOP
+                               + ".store(1, memory_order_relaxed);"));
+
                // Init commutativity rules
                code.addLine(TabbedLine(ShortComment("Init commutativity rules")));
                code.addLine(TabbedLine(DeclareDefine("int",
@@ -917,6 +959,10 @@ public class CodeGeneratorUtils {
                case OPDefine:
                        code.addLine(prefixTabs + SpecNaming.CreateOPDefineAnnoFunc + "();");
                        break;
+               case OPDefineUnattached:
+                       code.addLine(prefixTabs + SpecNaming.CreateOPDefineUnattachedFunc
+                                       + "();");
+                       break;
                case PotentialOP:
                        code.addLine(prefixTabs + SpecNaming.CreatePotentialOPAnnoFunc
                                        + "(" + SpecNaming.AppendStr(label) + ");");
@@ -932,6 +978,10 @@ public class CodeGeneratorUtils {
                        code.addLine(prefixTabs + SpecNaming.CreateOPClearDefineAnnoFunc
                                        + "();");
                        break;
+               case OPClearDefineUnattached:
+                       code.addLine(prefixTabs
+                                       + SpecNaming.CreateOPClearDefineUnattachedFunc + "();");
+                       break;
                default:
                        break;
                }