Changeset 2436


Ignore:
Timestamp:
Oct 11, 2012, 4:37:54 PM (7 years ago)
Author:
ksherdy
Message:

Added enumerations for carry 1, carry n, no carry runtime support.

Location:
proto/pablo/src/compiler/lang/pablo/builtins
Files:
2 added
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • proto/pablo/src/compiler/lang/pablo/builtins/Carry1.java

    r2424 r2436  
    33public enum Carry1 {
    44
    5     ADVANCE("Advance", 1),
    6     SCANTOFIRST("ScanToFirst", 1),
    7     SCANTHRU("ScanThru", 2),
    8     SCANTO("ScanTo", 2),
    9     ADVANCETHENSCANTHRU("AdvanceThenScanThru", 2),
    10     ADVANCETHENSCANTO("AdvanceThenScanTo", 2),
    11     SPANUPTO("SpanUpTo", 2),
    12     INCLUSIVESPAN("InclusiveSpan", 2),
    13     EXCLUSIVESPANs("ExclusiveSpan", 2);
     5    ADVANCE("Advance", 1, "BitBlock_advance_ci_co"),
     6    SCANTOFIRST("ScanToFirst", 1, "BitBlock_scantofirst"),
     7    SCANTHRU("ScanThru", 2, "BitBlock_scanthru_ci_co"),
     8    SCANTO("ScanTo", 2, "BitBlock_scanto_ci_co"),
     9    ADVANCETHENSCANTHRU("AdvanceThenScanThru", 2, "BitBlock_advance_then_scanthru"),
     10    ADVANCETHENSCANTO("AdvanceThenScanTo", 2, "BitBlock_advance_then_scanto"),
     11    SPANUPTO("SpanUpTo", 2, "BitBlock_span_upto"),
     12    INCLUSIVESPAN("InclusiveSpan", 2, "BitBlock_inclusive_span"),
     13    EXCLUSIVESPAN("ExclusiveSpan", 2, "BitBlock_exclusive_span");
     14       
     15        private final String pabloName;
     16        private final int argCount;
     17        private final String cName;
    1418       
    15         private final String name;
    16         private final int argCount;
    17        
    18         private Carry1(String name, int argCount) {
    19                 this.name = name;
     19        private Carry1(String pabloName, int argCount, String cName) {
     20                this.pabloName = pabloName;
    2021                this.argCount = argCount;
     22                this.cName = cName;
    2123        }
    2224       
    23         public String functionName() { return name; }
    24         public int argCount() { return argCount; }     
     25        public String pabloName() { return this.pabloName; }
     26        public int argCount() { return this.argCount; }
     27        public String cName() { return this.cName; }
    2528       
    2629}
  • proto/pablo/src/compiler/lang/pablo/builtins/CarryN.java

    r2424 r2436  
    33public enum CarryN {
    44
    5     ADVANCE32("Advance32", 1),
    6     ADVANCE("Advance", 2);
    7 
    8         private final String name;
     5    ADVANCE32("Advance32", 1, "BitBlock_advance_n_<32>"),
     6    ADVANCE("Advance", 2, "BitBlock_advance_n_<%i>");
     7   
     8        private final String pabloName;
    99        private final int argCount;
     10        private final String cName;
    1011       
    11         private CarryN(String name, int argCount) {
    12                 this.name = name;
     12        private CarryN(String pabloName, int argCount, String cName) {
     13                this.pabloName = pabloName;
    1314                this.argCount = argCount;
     15                this.cName = cName;
    1416        }
    1517       
    16         public String functionName() { return name; }
    17         public int argCount() { return argCount; }     
     18        public String pabloName() { return this.pabloName; }
     19        public int argCount() { return this.argCount; }
     20        public String cName() { return this.cName; }
    1821       
    1922}
  • proto/pablo/src/compiler/lang/pablo/builtins/NoCarry.java

    r2427 r2436  
    11package compiler.lang.pablo.builtins;
    22
    3 import ast.ASTNode;
    4 import ast.CompoundVariableNode;
    5 import ast.FunctionInvocationNode;
    6 import ast.IdentifierNode;
     3public enum NoCarry {
    74
    8 import compiler.ast.Accessors;
     5    ATEOF("atEOF", 1, "atEOF"),
     6    INFILE("inFile", 1, "inFile"),
     7    STREAMSCAN("StreamScan", 2, "StreamScan");
     8   
     9        private final String pabloName;
     10        private final int argCount;
     11        private final String cName;
     12       
     13        private NoCarry(String pabloName, int argCount, String cName) {
     14                this.pabloName = pabloName;
     15                this.argCount = argCount;
     16                this.cName = cName;
     17        }
     18       
     19        public String pabloName() { return this.pabloName; }
     20        public int argCount() { return this.argCount; }
     21        public String cName() { return this.cName; }
     22       
     23}
    924
    10 public class Builtins {
    1125
    12     public static String BUILTIN_PACKAGE_NAME = "pablo";
    13                
    14     /** Returns true if the node represents a call to the
    15      *  given built-in 'Advance' function.
    16      * 
    17      * @param node                  node to be checked
    18      * @return                      whether the node is a call of the function
    19      */   
    20     public static boolean isAdvance(ASTNode node) {
    21         if(!(node instanceof FunctionInvocationNode)) {
    22             return false;
    23         }
    24        
    25         FunctionInvocationNode fNode = (FunctionInvocationNode)node;
    26         ASTNode nameNode = Accessors.functionName(fNode);
    27        
    28         if (isQualifiedName(nameNode, Builtins.BUILTIN_PACKAGE_NAME, "Advance")) {
    29             return true;
    30         }
    31    
    32         return false;       
    33     }
    34    
    35     /** Returns true if the node represents a call to the
    36      *  given built-in 'Advance N' functions.
    37      * 
    38      * @param node                  node to be checked
    39      * @return                      whether the node is a call of the function
    40      */   
    41     public static boolean isAdvanceN(ASTNode node) {
    42        
    43         for (CarryN builtin : CarryN.values()) {           
    44             if (isCall(node, Builtins.BUILTIN_PACKAGE_NAME, builtin.functionName(), builtin.argCount())) {
    45                 return true;
    46             }
    47         }       
    48    
    49         return false;       
    50     }
    51    
    52     /** Returns true if the node represents a call to the
    53      *  given built-in function.
    54      * 
    55      * @param node                  node to be checked
    56      * @return                      whether the node is a call of the function
    57      */
    58     public static boolean isBuiltInCallNoArgCount(ASTNode node) {
    59         if(!(node instanceof FunctionInvocationNode)) {
    60             return false;
    61         }
    62        
    63         FunctionInvocationNode fNode = (FunctionInvocationNode)node;
    64         ASTNode nameNode = Accessors.functionName(fNode);
    65 
    66         for (Carry1 builtin : Carry1.values()) {
    67             if (isQualifiedName(nameNode, Builtins.BUILTIN_PACKAGE_NAME, builtin.functionName())) {
    68                 return true;
    69             }
    70         }
    71        
    72         return false;
    73     }
    74    
    75     /** Returns true if the node represents a call to the
    76      *  given built-in function with the given number of arguments.
    77      * 
    78      * @param node                  node to be checked
    79      * @return                      whether the node is a call of the function with argNumToMatch arguments
    80      */
    81     public static boolean isBuiltInCall(ASTNode node) {
    82        
    83         for (Carry1 builtin : Carry1.values()) {   
    84             if (isCall(node, Builtins.BUILTIN_PACKAGE_NAME, builtin.functionName(), builtin.argCount())) {
    85                 return true;
    86             }
    87         }       
    88        
    89         return false;
    90     }
    91    
    92     /** Returns true if the node represents a call to the
    93      *  given function with the given number of arguments.
    94      *  If node does not have a packageName attached, it is assumed to match the given packageName.
    95      * 
    96      * @param node                  node to be checked
    97      * @param packageName           package name that must be matched.
    98      * @param functionName          name of function to be matched
    99      * @param numArgs               number of arguments to be matched
    100      * @return                      whether the node is a call of the function with argNumToMatch arguments
    101      */
    102     public static boolean isCall(ASTNode node, String packageName, String functionName, int numArgs) {
    103         if(!(node instanceof FunctionInvocationNode)) {
    104             return false;
    105         }
    106        
    107         FunctionInvocationNode fNode = (FunctionInvocationNode)node;
    108         ASTNode nameNode = Accessors.functionName(fNode);
    109 
    110         boolean nameMatches = isQualifiedName(nameNode, packageName, functionName);
    111         boolean numArgsMatches = Accessors.functionArgs(fNode).size() == numArgs;
    112        
    113         return nameMatches && numArgsMatches;
    114     }
    115    
    116    
    117     /** Determines if node represents the name of the function described by packageName, functionName.
    118      *  In particular, if node represents a simple (non-qualified) name, then it is compared with functionName.
    119      *  (Essentially, this assumes that the packageName is correct.)
    120      *  If node represents a compound (qualified) name, then it is compared with 'packageName.functionName'.
    121      * 
    122      * @param node
    123      * @param packageName
    124      * @param functionName
    125      * @return True if the node matches packageName.functionName.
    126      */
    127     public static boolean isQualifiedName(ASTNode node, String packageName, String functionName) {
    128         if(node instanceof IdentifierNode) {
    129             return Accessors.identifierLexeme(node) == functionName;
    130         }
    131         else if (node instanceof CompoundVariableNode) {
    132             ASTNode pckage = node.child(0);
    133             ASTNode member = node.child(1);
    134             return   (Accessors.identifierLexeme(pckage) == packageName) &&
    135                      (Accessors.identifierLexeme(member) == functionName);
    136         }
    137         return false;
    138     }
    139        
    140 }
     26 
Note: See TracChangeset for help on using the changeset viewer.