Charj: do .ci codegen for sdag, infer atomic sections
authorAaron Becker <akbecker@gmail.com>
Tue, 24 Aug 2010 23:12:36 +0000 (18:12 -0500)
committerAaron Becker <akbecker@gmail.com>
Tue, 24 Aug 2010 23:12:36 +0000 (18:12 -0500)
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjASTModifier2.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/SymbolDefiner.g

index c76a1835698075422e3a306eacd2daa4c29c9fe4..24b5960f8193a801a6d53e1015f7399d27cbdc42 100644 (file)
@@ -18,6 +18,7 @@ options {
 tokens {
 
     ENTRY                   = 'entry'           ;
+    SDAGENTRY               = 'sdagentry'       ;
     TRACED                  = 'traced'          ;
     PUBLIC                  = 'public'          ;
     PROTECTED               = 'protected'       ;
@@ -449,6 +450,7 @@ modifier
     :   PUBLIC
     |   PROTECTED
     |   ENTRY
+    |   SDAGENTRY
     |   TRACED
     |   PRIVATE
     |   ABSTRACT
index d411e3a6538ca0ad547a6295cf367112a7a196b9..92bb043d33d9c601cc3b45f2614e51b2ff797363 100644 (file)
@@ -375,6 +375,25 @@ funcMethodDecl_ci(modl, gtpl, ty, id, fpl, adl, block) ::=
 >>
 
 
+funcMethodDecl_sdag_ci(classSym, methodSym, modl, gtpl, ty, id, fpl, adl, block) ::=
+<<
+<modl><ty><gtpl> <id><fpl><adl>
+{
+    /* FIXME: macros aren't allowed in sdag code yet, so tracing doesn't work right
+    #if _CHARJ_TRACE_ALL_METHODS<if(methodSym.isTraced)> || _CHARJ_TRACE_TRACED_METHODS<endif>
+    int _charj_method_trace_timer = CkWallTimer();
+    #endif
+    */
+    <block>
+    /*
+    #if _CHARJ_TRACE_ALL_METHODS<if(methodSym.isTraced)> || _CHARJ_TRACE_TRACED_METHODS<endif>
+    traceUserBracketEvent(<methodSym.traceID>, _charj_method_trace_timer, CkWallTimer());
+    #endif
+    */
+};
+>>
+
+
 funcMethodDecl_cc(classSym, methodSym, modl, gtpl, ty, id, fpl, adl, block) ::=
 <<
 <modl><ty><gtpl> <classSym.Name>::<id><fpl><adl>
@@ -416,6 +435,13 @@ block_cc(bsl) ::=
 }
 >>
 
+block_sdag_ci(bsl) ::=
+<<
+atomic {
+    <bsl; separator="\n">
+}
+>>
+
 
 embed_cc(str, blk) ::=
 <<
index 38cdb0a1cb685ece4666eb792bd0b11e6ba1cef9..2e378bd18f2a04b0232381564a4273b55d002860 100644 (file)
@@ -200,6 +200,7 @@ accessModifier
 
 charjModifier returns [boolean isEntry] 
     :   ENTRY { $isEntry = true; }
+    |   SDAGENTRY { $isEntry = true; }
     |   TRACED
     ;
 
index 2d6199030e0e663fe777cc3d5b1cc8294ce5c149..3ce1af38404d193263b26e90feef8c21429245d8 100644 (file)
@@ -211,6 +211,7 @@ accessModifier
 
 charjModifier
     :   ENTRY
+    |   SDAGENTRY
     |   TRACED
     ;
 
index 22648b546d811703d44980ea90df27888f6ffcba..04b6c9d702c0da70ed7c4d5ae6c862d46f3f8c07 100644 (file)
@@ -225,12 +225,12 @@ classScopeDeclaration
 {
     boolean entry = false;
     boolean migrationCtor = false;
+    boolean sdagMethod = false;
 }
     :   ^(FUNCTION_METHOD_DECL m=modifierList? g=genericTypeParameterList? 
             ty=type IDENT f=formalParameterList
-            b=block?) {
-            currentMethod = (MethodSymbol)$IDENT.def;
-        }
+            { currentMethod = (MethodSymbol)$IDENT.def; }
+            b=block?)
         -> {emitCC()}? funcMethodDecl_cc(
                 classSym={currentClass},
                 methodSym={currentMethod},
@@ -251,10 +251,12 @@ classScopeDeclaration
         ->
     |   ^(ENTRY_FUNCTION_DECL m=modifierList? g=genericTypeParameterList? 
             ty=type IDENT f=formalParameterList a=domainExpression[null]? 
-            b=block?) {
-            currentMethod = (MethodSymbol)$IDENT.def;
-        }
-        -> {emitCC()}? funcMethodDecl_cc(
+            {
+                currentMethod = (MethodSymbol)$IDENT.def;
+                sdagMethod = currentMethod.hasSDAG;
+            }
+            b=block?) 
+        -> {emitCC() && !sdagMethod}? funcMethodDecl_cc(
                 classSym={currentClass},
                 methodSym={currentMethod},
                 modl={$m.st}, 
@@ -264,7 +266,7 @@ classScopeDeclaration
                 fpl={$f.st}, 
                 adl={$a.st},
                 block={$b.st})
-        -> {emitH()}? funcMethodDecl_h(
+        -> {emitH() && !sdagMethod}? funcMethodDecl_h(
                 modl={$m.st}, 
                 gtpl={$g.st}, 
                 ty={$ty.st},
@@ -272,7 +274,17 @@ classScopeDeclaration
                 fpl={$f.st}, 
                 adl={$a.st},
                 block={$b.st})
-        -> {emitCI()}? funcMethodDecl_ci(
+        -> {emitCI() && sdagMethod}? funcMethodDecl_sdag_ci(
+                classSym={currentClass},
+                methodSym={currentMethod},
+                modl={$m.st}, 
+                gtpl={$g.st}, 
+                ty={$ty.st},
+                id={$IDENT.text}, 
+                fpl={$f.st}, 
+                adl={$a.st},
+                block={$b.st})
+        -> {emitCI() && !sdagMethod}? funcMethodDecl_ci(
                 modl={$m.st}, 
                 gtpl={$g.st}, 
                 ty={$ty.st},
@@ -292,10 +304,11 @@ classScopeDeclaration
             type={$objectType.st},
             declList={$variableDeclaratorList.st})
         ->
-    |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList b=block)
-        {
-            currentMethod = (MethodSymbol)$IDENT.def;
-        }
+    |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList
+            {
+                currentMethod = (MethodSymbol)$IDENT.def;
+            }
+            b=block)
         -> {emitCC()}? ctorDecl_cc(
                 modl={$m.st},
                 gtpl={$g.st}, 
@@ -310,11 +323,13 @@ classScopeDeclaration
                 fpl={$f.st}, 
                 block={$b.st})
         ->
-    |   ^(ENTRY_CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList b=block)
-        {
-            currentMethod = (MethodSymbol)$IDENT.def;
-            migrationCtor = currentClass.migrationCtor == $ENTRY_CONSTRUCTOR_DECL;
-        }
+    |   ^(ENTRY_CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList
+            {
+                currentMethod = (MethodSymbol)$IDENT.def;
+                migrationCtor = currentClass.migrationCtor == $ENTRY_CONSTRUCTOR_DECL;
+            }
+            b=block)
+
         -> {emitCC()}? ctorDecl_cc(
                 modl={$m.st},
                 gtpl={$g.st}, 
@@ -507,6 +522,7 @@ accessModifier
 
 charjModifier
     :   ENTRY -> {%{$ENTRY.text}}
+    |   SDAGENTRY -> template() "entry"
     |   TRACED
     ;
 
@@ -638,8 +654,10 @@ block
 @init { boolean emptyBlock = true; }
     :   ^(BLOCK (b+=blockStatement)*)
         { emptyBlock = ($b == null || $b.size() == 0); }
-        -> {emitCC() && emptyBlock}? template(bsl={$b}) "{ }"
-        -> {emitCC()}? block_cc(bsl={$b})
+        -> {((emitCC() && (currentMethod == null || !currentMethod.hasSDAG)) ||
+            (emitCI() && (currentMethod != null && currentMethod.hasSDAG))) && emptyBlock}? template(bsl={$b}) "{ }"
+        -> {emitCC() && (currentMethod == null || !currentMethod.hasSDAG)}? block_cc(bsl={$b})
+        -> {emitCI() && (currentMethod != null && currentMethod.hasSDAG)}? block_sdag_ci(bsl={$b})
         ->
     ;
     
@@ -676,9 +694,13 @@ statement
 
 sdagStatement
     :   ^(OVERLAP block)
-        -> template(b={$block.st}) "/* !!overlap not implemented */"
-    |   ^(WHEN IDENT expression? (type IDENT)* block)
-        -> template(b={$block.st}) "/* !!when not implemented */"
+        -> template(b={$block.st}) "} overlap <b> atomic {"
+    |   ^(WHEN IDENT expression? (wa+=whenArgument)* block)
+        -> template(i={$IDENT}, e={$expression.st}, w={wa}, b={$block.st}) "} when <i> <if(e)>[<e>]<endif> <w> <b> atomic {"
+    ;
+
+whenArgument
+    : type IDENT -> template(t={$type.st}, i={$IDENT}) "(<t> <i>)"
     ;
 
 nonBlockStatement
index 9ac800950d543be2b92287e758d9d342c5c2c31e..0c1a5e20ee2ad8d50c8414ffe307e9e0e31dc73e 100644 (file)
@@ -88,6 +88,7 @@ boolean entry = false;
                 typeName.add(new TypeName("void"));
             }
             boolean isTraced = false;
+            boolean sdagEntry = false;
             if ($MODIFIER_LIST != null) {
                 CharjAST charj_mod = $MODIFIER_LIST.getChildOfType(CharjParser.CHARJ_MODIFIER_LIST);
                 if (charj_mod != null) {
@@ -95,6 +96,11 @@ boolean entry = false;
                     isTraced = (charj_mod != null);
                     if (isTraced) System.out.println("method " + $IDENT.text + " is traced");
                 }
+                charj_mod = $MODIFIER_LIST.getChildOfType(CharjParser.CHARJ_MODIFIER_LIST);
+                if (charj_mod != null) {
+                    charj_mod = charj_mod.getChildOfType(CharjParser.SDAGENTRY);
+                    sdagEntry = (charj_mod != null);
+                }
             }
             Type returnType = currentScope.resolveType(typeName);
             //System.out.println("Resolving type " + typeName + " in scope " + currentScope + "->" + returnType);
@@ -102,6 +108,7 @@ boolean entry = false;
             sym.isEntry = entry;
             sym.isTraced = isTraced;
             sym.definition = $enterMethod.start;
+            sym.hasSDAG = sdagEntry;
             sym.definitionTokenStream = input.getTokenStream();
             currentScope.define($IDENT.text, sym);
             $IDENT.def = sym;