Changeset 2939


Ignore:
Timestamp:
Mar 19, 2013, 3:16:20 PM (5 years ago)
Author:
ksherdy
Message:

Code clean up and comments.

Location:
proto/pabloj/trunk/src/compiler
Files:
3 added
6 edited
4 moved

Legend:

Unmodified
Added
Removed
  • proto/pabloj/trunk/src/compiler/codeGenerator/helpers/CodeFragments.java

    r2937 r2939  
    88
    99package compiler.codeGenerator.helpers;
    10 
    11 import compiler.lang.carry.CarrySetBuiltins2Lang;
    12 import compiler.lang.pabloS.Builtins2Lang;
    13 import compiler.transformer.visitors.*;
    1410
    1511public class CodeFragments {
  • proto/pabloj/trunk/src/compiler/codeGenerator/visitors/CPPUnparser.java

    r2937 r2939  
    4343import compiler.codeGenerator.helpers.CodeStore;
    4444import compiler.codeGenerator.helpers.UnparserUtil;
    45 import compiler.lang.carry.CarrySetBuiltins2CPP;
     45import compiler.lang.carry.CarryBuiltins2CPP;
    4646import compiler.symbolTable.CarryInfoSetSymbol;
    4747import compiler.symbolTable.SymbolTable;
     
    4949public class CPPUnparser extends Unparser {
    5050
    51         private CarrySetBuiltins2CPP carrySetBuiltins2CPP;
     51        private CarryBuiltins2CPP carrySetBuiltins2CPP;
    5252        private String stateIdentifier = null;
    5353       
     
    5656        public CPPUnparser(SymbolTable symbolTable) {
    5757                super.setSymbolTable(symbolTable);
    58                 carrySetBuiltins2CPP = new CarrySetBuiltins2CPP();
     58                carrySetBuiltins2CPP = new CarryBuiltins2CPP();
    5959        }
    6060
  • proto/pabloj/trunk/src/compiler/lang/carry/CarryBuiltins.java

    r2938 r2939  
    1010package compiler.lang.carry;
    1111
    12 public enum CarrySetBuiltins {
     12public enum CarryBuiltins {
    1313        LOCALCARRYDECLARE(2),                           
    1414        CARRYTEST(2),
     
    2323        private final int argCount;
    2424               
    25         CarrySetBuiltins(int argCount ) {
     25        CarryBuiltins(int argCount ) {
    2626                this.argCount = argCount;
    2727        }
  • proto/pabloj/trunk/src/compiler/lang/carry/CarryBuiltins2CPP.java

    r2938 r2939  
    1111import java.util.Map;
    1212
    13 public class CarrySetBuiltins2CPP extends CarrySetBuiltins2Lang {
     13public class CarryBuiltins2CPP extends CarryBuiltins2Lang {
    1414       
    15         private static Map<CarrySetBuiltins, String> carry2CPPCode;
     15        private static Map<CarryBuiltins, String> carry2CPPCode;
    1616       
    1717    static {
     
    1919        CARRYSETDECLAREFORMATSTRING = "CarryArray<%s,%s> %s";
    2020
    21         carry2CPPCode = new HashMap<CarrySetBuiltins, String>();
     21        carry2CPPCode = new HashMap<CarryBuiltins, String>();
    2222       
    23         carry2CPPCode.put(CarrySetBuiltins.LOCALCARRYDECLARE, "LocalCarryDeclare");
    24         carry2CPPCode.put(CarrySetBuiltins.CARRYTEST,"PabloJCarryTest");
    25         carry2CPPCode.put(CarrySetBuiltins.GETCARRYIN,"get_carry_in");
    26         carry2CPPCode.put(CarrySetBuiltins.GETPENDING64,"get_pending64");
    27         carry2CPPCode.put(CarrySetBuiltins.CARRYCOMBINE,"CarryCombine");
    28         carry2CPPCode.put(CarrySetBuiltins.CARRYQADJUST,"CarryQ_Adjust");
    29         carry2CPPCode.put(CarrySetBuiltins.CARRYDEQUEUEENQUEUE,"CarryDequeueEnqueue");
    30         carry2CPPCode.put(CarrySetBuiltins.CARRYFLIP,"carry_flip");
     23        carry2CPPCode.put(CarryBuiltins.LOCALCARRYDECLARE, "LocalCarryDeclare");
     24        carry2CPPCode.put(CarryBuiltins.CARRYTEST,"PabloJCarryTest");
     25        carry2CPPCode.put(CarryBuiltins.GETCARRYIN,"get_carry_in");
     26        carry2CPPCode.put(CarryBuiltins.GETPENDING64,"get_pending64");
     27        carry2CPPCode.put(CarryBuiltins.CARRYCOMBINE,"CarryCombine");
     28        carry2CPPCode.put(CarryBuiltins.CARRYQADJUST,"CarryQ_Adjust");
     29        carry2CPPCode.put(CarryBuiltins.CARRYDEQUEUEENQUEUE,"CarryDequeueEnqueue");
     30        carry2CPPCode.put(CarryBuiltins.CARRYFLIP,"carry_flip");
    3131        //carry2CPPCode.put(CarrySetBuiltins.VALUEOF,"cq[%s]");
    3232       
    33         for(CarrySetBuiltins op : CarrySetBuiltins.values()) {
     33        for(CarryBuiltins op : CarryBuiltins.values()) {
    3434                if(!carry2CPPCode.containsKey(op)) {
    35                                 throw new RuntimeException("CarrySet to CPP code mapping unimplemented :" + CarrySetBuiltins2CPP.class.getSimpleName());
     35                                throw new RuntimeException("CarrySet to CPP code mapping unimplemented :" + CarryBuiltins2CPP.class.getSimpleName());
    3636                }
    3737        }
     
    3939    }
    4040   
    41         public String getCode(CarrySetBuiltins op) {                   
     41        public String getCode(CarryBuiltins op) {                       
    4242                return carry2CPPCode.get(op);
    4343        }
  • proto/pabloj/trunk/src/compiler/lang/carry/CarryBuiltins2Lang.java

    r2938 r2939  
    77package compiler.lang.carry;
    88
    9 public abstract class CarrySetBuiltins2Lang {
    10         public abstract String getCode(CarrySetBuiltins op);
     9public abstract class CarryBuiltins2Lang {
     10        public abstract String getCode(CarryBuiltins op);
    1111       
    1212        public static final String CARRYQNAME                                   = "carryQ";
  • proto/pabloj/trunk/src/compiler/lang/idisa/BitBlock.java

    r2834 r2939  
     1/*
     2 * IDISA BitBlock builtins.
     3 *
     4 * TODO - Add IDISA support as needed.
     5 *
     6 * @author Ken Herdy <ksherdy at sfu dot ca>
     7 */
     8
    19package compiler.lang.idisa;
    210
     
    715        POPCOUNT("popcount", 1);
    816               
    9         private String name;
     17        private String lexeme;
    1018        private int argCount;
    1119       
    12         private BitBlock(String FuncName, int argCount) {
    13                 this.name = FuncName;
     20        private BitBlock(String lexeme, int argCount) {
     21                this.lexeme = lexeme;
    1422                this.argCount = argCount;
    1523        }
     
    1725        private static final String BITBLOCK = "bitblock";
    1826       
    19         public String IDISAName() { return BITBLOCK + "::" + name; }
     27        public String IDISALexeme() { return BITBLOCK + "::" + lexeme; }
    2028        public int argCount() { return argCount; }
    2129}
  • proto/pabloj/trunk/src/compiler/lang/idisa/SIMD.java

    r2834 r2939  
     1/*
     2 * IDISA SIMD builtins.
     3 *
     4 * TODO - Add IDISA support as needed.
     5 *
     6 * @author Ken Herdy <ksherdy at sfu dot ca>
     7 */
     8
    19package compiler.lang.idisa;
    210
     
    3644        CONSTANT("constant", 0);
    3745       
    38         private String name;
     46        private String lexeme;
    3947        private int argCount;
    4048       
    41         private SIMD(String name, int argCount) {
    42                 this.name = name;
     49        private SIMD(String lexeme, int argCount) {
     50                this.lexeme = lexeme;
    4351                this.argCount = argCount;
    4452        }
     
    4654        private static final String SIMD = "simd";
    4755       
    48         public String idisaName() { return (SIMD + "_" + name); }
    49         public String idisaName(int fieldWidth) { return (SIMD + "<" + Integer.toString(fieldWidth) + ">::" + name); }
    50         public String idisaConstantName(int fieldWidth, int constant) {
    51                 return (SIMD + "<" + Integer.toString(fieldWidth) + ">::" + CONSTANT.name + "<" + Integer.toString(constant) +">");
     56        public String idisaLexeme() { return (SIMD + "_" + lexeme); }
     57        public String idisaLexeme(String fieldWidth) { return (SIMD + "<" + fieldWidth + ">::" + lexeme); }
     58        public String idisaConstantLexeme(String constant, String fieldWidth) {
     59                return (SIMD + "<" + fieldWidth + ">::" + CONSTANT.lexeme + "<" + constant +">");
    5260        }
    5361        public int argCount() { return argCount; }
  • proto/pabloj/trunk/src/compiler/lang/pabloS/Builtins.java

    r2834 r2939  
     1/*
     2 * PabloS Builtins.
     3 *
     4 * @author Ken Herdy <ksherdy at sfu dot ca>
     5 */
    16package compiler.lang.pabloS;
    27
     
    611public enum Builtins {
    712
    8     ADVANCE(Carry.One, "Advance", 1),
    9     SCANTOFIRST(Carry.One, "ScanToFirst", 1),
    10     SCANTHRU(Carry.One, "ScanThru", 2),
    11     SCANTO(Carry.One, "ScanTo", 2),
    12     ADVANCETHENSCANTHRU(Carry.One, "AdvanceThenScanThru", 2),
    13     ADVANCETHENSCANTO(Carry.One, "AdvanceThenScanTo", 2),
    14     SPANUPTO(Carry.One, "SpanUpTo", 2),
    15     INCLUSIVESPAN(Carry.One, "InclusiveSpan", 2),
    16     EXCLUSIVESPAN(Carry.One, "ExclusiveSpan", 2),   
     13    ADVANCE(CarryType.One, "Advance", 1),
     14    SCANTOFIRST(CarryType.One, "ScanToFirst", 1),
     15    SCANTHRU(CarryType.One, "ScanThru", 2),
     16    SCANTO(CarryType.One, "ScanTo", 2),
     17    ADVANCETHENSCANTHRU(CarryType.One, "AdvanceThenScanThru", 2),
     18    ADVANCETHENSCANTO(CarryType.One, "AdvanceThenScanTo", 2),
     19    SPANUPTO(CarryType.One, "SpanUpTo", 2),
     20    INCLUSIVESPAN(CarryType.One, "InclusiveSpan", 2),
     21    EXCLUSIVESPAN(CarryType.One, "ExclusiveSpan", 2),   
    1722
    18     ADVANCE32(Carry.N, "Advance32", 1),
    19     ADVANCEN(Carry.N, "Advance", 2),
     23    ADVANCE32(CarryType.N, "Advance32", 1),
     24    ADVANCEN(CarryType.N, "Advance", 2),
    2025
    21     ATEOF(Carry.None, "atEOF", 1),
    22     INFILE(Carry.None, "inFile", 1),
    23     ASSERTZERO(Carry.None, "assert_0", 2),     
    24     EOFMASK(Carry.None, "EOF_mask", 0), // deprecated
     26    MASK(CarryType.None, "Mask", 1),
     27    MASKFW(CarryType.None, "Mask", 2),
     28   
     29    ATEOF(CarryType.None, "atEOF", 1),
     30    INFILE(CarryType.None, "inFile", 1),
     31    ASSERTZERO(CarryType.None, "assert_0", 2), 
     32    EOFMASK(CarryType.None, "EOF_mask", 0), // deprecated
    2533       
    26     PRINTBITBLOCK(Carry.None, "PrintBitBlock", 1),
    27     ASSERTBITBLOCKALIGN(Carry.None, "AssertBitBlockAlign", 1);
     34    PRINTBITBLOCK(CarryType.None, "PrintBitBlock", 1),
     35    ASSERTBITBLOCKALIGN(CarryType.None, "AssertBitBlockAlign", 1);
    2836   
    29     public enum Carry{One, N, None};   
     37    public enum CarryType{One, N, None};   
    3038   
    31     private final Carry type;
    32         private final String pabloName;
     39    private final CarryType carryType;
     40        private final String pabloSName;
    3341        private final int argCount;
    3442       
    35         private Builtins(Carry type, String pabloName, int argCount) {
    36                 this.type = type;
    37                 this.pabloName = pabloName;
     43        private Builtins(CarryType carryType, String pabloSName, int argCount) {
     44                this.carryType = carryType;
     45                this.pabloSName = pabloSName;
    3846                this.argCount = argCount;
    3947        }
    4048       
    41         public String pabloName() { return this.pabloName; }
     49        public String pabloSName() { return this.pabloSName; }
    4250        public int argCount() { return this.argCount; }
    4351
     
    4755               
    4856                for (Builtins operation : Builtins.values()) {
    49                         if (Carry.One == operation.type) {
     57                        if (CarryType.One == operation.carryType) {
    5058                                carryN.add(operation);
    5159                        }
     
    6068               
    6169                for (Builtins operation : Builtins.values()) {
    62                         if (Carry.N == operation.type) {
     70                        if (CarryType.N == operation.carryType) {
    6371                                carryN.add(operation);
    6472                        }
  • proto/pabloj/trunk/src/compiler/lang/pabloS/BuiltinsUtil.java

    r2834 r2939  
    2525   
    2626        // Advance(X)
    27         if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, Builtins.ADVANCE.pabloName())
    28                 && ArgsListNode.nChildren() == 1) {
     27        if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, Builtins.ADVANCE.pabloSName())
     28                && ArgsListNode.nChildren() == 1) { // TODO - update this check to include argument types, refactor to drop arg count
    2929            return true;
    3030        }
    3131
    3232        // Advance(X,n)
    33         if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, Builtins.ADVANCE.pabloName())
    34                 && ArgsListNode.nChildren() == 2) {     
     33        if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, Builtins.ADVANCE.pabloSName())
     34                && ArgsListNode.nChildren() == 2) {     // TODO - update this check to include argument types, refactor to drop arg count
    3535                        return true;
    3636        }
     
    4242       
    4343                for (Builtins builtin : Builtins.values()) {   
    44                 if (isQualifiedName(node, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloName())) {
     44                if (isQualifiedName(node, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloSName())) {
    4545                    return true;
    4646                }               
     
    5757                        int argCount = Accessors.funcCallArgCount((FuncCallNode)node);
    5858                       
    59                         if (isQualifiedName(identifier, BuiltinsUtil.BUILTIN_PACKAGE_NAME, carryOneOperation.pabloName())
     59                        if (isQualifiedName(identifier, BuiltinsUtil.BUILTIN_PACKAGE_NAME, carryOneOperation.pabloSName())
    6060                                && argCount == carryOneOperation.argCount()) {
    6161                    return true;
     
    7171                        int argCount = Accessors.funcCallArgCount((FuncCallNode) node);
    7272                       
    73                 if (isQualifiedName(identifier, BuiltinsUtil.BUILTIN_PACKAGE_NAME, carryNOperation.pabloName())
     73                if (isQualifiedName(identifier, BuiltinsUtil.BUILTIN_PACKAGE_NAME, carryNOperation.pabloSName())
    7474                        && argCount == carryNOperation.argCount()) {
    7575                        return true;
     
    100100
    101101        for (Builtins builtin : Builtins.values()) {
    102             if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloName())) {
     102            if (isQualifiedName(nameNode, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloSName())) {
    103103                return true;
    104104            }
     
    117117       
    118118        for (Builtins builtin : Builtins.values()) {   
    119             if (isCall(node, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloName(), builtin.argCount())) {
     119            if (isCall(node, BuiltinsUtil.BUILTIN_PACKAGE_NAME, builtin.pabloSName(), builtin.argCount())) {
    120120                return true;
    121121            }
  • proto/pabloj/trunk/src/compiler/lang/pabloS/PabloSBuiltins2CPP.java

    r2933 r2939  
     1/*
     2 * PabloS builtins to CPP direct mapping.
     3 *
     4 *TODO  -       (1) Map PabloS to the PabloB intermediate language.
     5 *              (2) Define PabloB builtins mapping to C,CPP, ... 
     6 *                      (3) In the interim this can be as simple as performing this transformation in the PabloB representation.
     7 *              i.e. Move this transformer to compiler.lang.pabloB
     8 *
     9 * @author Ken Herdy <ksherdy at sfu dot ca>
     10 */
     11
    112package compiler.lang.pabloS;
    213
     
    415import java.util.Map;
    516
    6 public class Builtins2CPP extends Builtins2Lang {
     17import compiler.lang.idisa.SIMD;
     18import compiler.lang.pabloS.Builtins.CarryType;
    719
    8         private static Map<Builtins, String> pablo2CPPCode;
     20public class PabloSBuiltins2CPP extends Builtins2Lang {
     21
     22        private static Map<Builtins, String> pabloS2CPPCode;
    923       
    1024    static {
    1125       
    12         pablo2CPPCode = new HashMap<Builtins, String>();
     26        pabloS2CPPCode = new HashMap<Builtins, String>();
    1327       
    14         pablo2CPPCode.put(Builtins.ADVANCE,"BitBlock_advance_ci_co");
    15         pablo2CPPCode.put(Builtins.SCANTOFIRST, "BitBlock_scantofirst");
    16         pablo2CPPCode.put(Builtins.SCANTHRU, "BitBlock_scanthru_ci_co");
    17         pablo2CPPCode.put(Builtins.SCANTO, "BitBlock_scanto_ci_co");
    18         pablo2CPPCode.put(Builtins.ADVANCETHENSCANTHRU, "BitBlock_advance_then_scanthru");
    19         pablo2CPPCode.put(Builtins.ADVANCETHENSCANTO, "BitBlock_advance_then_scanto");
    20         pablo2CPPCode.put(Builtins.SPANUPTO, "BitBlock_span_upto");
    21         pablo2CPPCode.put(Builtins.INCLUSIVESPAN, "BitBlock_inclusive_span");
    22         pablo2CPPCode.put(Builtins.EXCLUSIVESPAN, "BitBlock_exclusive_span");   
     28        pabloS2CPPCode.put(Builtins.ADVANCE,"BitBlock_advance_ci_co");
     29        pabloS2CPPCode.put(Builtins.SCANTOFIRST, "BitBlock_scantofirst");
     30        pabloS2CPPCode.put(Builtins.SCANTHRU, "BitBlock_scanthru_ci_co");
     31        pabloS2CPPCode.put(Builtins.SCANTO, "BitBlock_scanto_ci_co");
     32        pabloS2CPPCode.put(Builtins.ADVANCETHENSCANTHRU, "BitBlock_advance_then_scanthru");
     33        pabloS2CPPCode.put(Builtins.ADVANCETHENSCANTO, "BitBlock_advance_then_scanto");
     34        pabloS2CPPCode.put(Builtins.SPANUPTO, "BitBlock_span_upto");
     35        pabloS2CPPCode.put(Builtins.INCLUSIVESPAN, "BitBlock_inclusive_span");
     36        pabloS2CPPCode.put(Builtins.EXCLUSIVESPAN, "BitBlock_exclusive_span");   
    2337
    24         pablo2CPPCode.put(Builtins.ADVANCE32, "BitBlock_advance_n_<%s>");
    25         pablo2CPPCode.put(Builtins.ADVANCEN, "BitBlock_advance_n_<%s>");
     38        pabloS2CPPCode.put(Builtins.ADVANCE32, "BitBlock_advance_n_<%s>");
     39        pabloS2CPPCode.put(Builtins.ADVANCEN, "BitBlock_advance_n_<%s>");
    2640
    27         pablo2CPPCode.put(Builtins.ATEOF, "atEOF");
    28         pablo2CPPCode.put(Builtins.INFILE, "inFile");
    29         pablo2CPPCode.put(Builtins.ASSERTZERO, "assert_0_error");       
    30         pablo2CPPCode.put(Builtins.EOFMASK, "EOF_mask");
     41        pabloS2CPPCode.put(Builtins.MASK, SIMD.CONSTANT.idisaConstantLexeme("1", "%s"));
     42        pabloS2CPPCode.put(Builtins.MASKFW, SIMD.CONSTANT.idisaConstantLexeme("%s", "%s"));
    3143       
    32         pablo2CPPCode.put(Builtins.PRINTBITBLOCK, "print_register<BitBlock>");
    33         pablo2CPPCode.put(Builtins.ASSERTBITBLOCKALIGN, "ASSERT_BITBLOCK_ALIGN");       
     44        pabloS2CPPCode.put(Builtins.ATEOF, "atEOF");
     45        pabloS2CPPCode.put(Builtins.INFILE, "inFile");
     46        pabloS2CPPCode.put(Builtins.ASSERTZERO, "assert_0_error");     
     47        pabloS2CPPCode.put(Builtins.EOFMASK, "EOF_mask");
     48       
     49        pabloS2CPPCode.put(Builtins.PRINTBITBLOCK, "print_register<BitBlock>");
     50        pabloS2CPPCode.put(Builtins.ASSERTBITBLOCKALIGN, "ASSERT_BITBLOCK_ALIGN");     
    3451               
    3552        for(Builtins builtin : Builtins.values()) {
    36                 if(!pablo2CPPCode.containsKey(builtin)) {
    37                                 throw new RuntimeException("Builtin to CPP code mapping unimplemented in :" + Builtins2CPP.class.getSimpleName());
     53                if(!pabloS2CPPCode.containsKey(builtin)) {
     54                                throw new RuntimeException("PabloS builtin to CPP mapping not unimplemented in :" + PabloSBuiltins2CPP.class.getSimpleName());
    3855                }
    3956        }
     
    4158   
    4259        public String getCode(Builtins builtin) {                       
    43                 return pablo2CPPCode.get(builtin);
     60                return pabloS2CPPCode.get(builtin);
    4461        }
    4562       
Note: See TracChangeset for help on using the changeset viewer.