Changeset 1246


Ignore:
Timestamp:
Jul 30, 2011, 6:25:12 PM (8 years ago)
Author:
shermer
Message:

various small changes so as to bring the output into greater conformity to python/pablo.
The input bitstream variable naming changed, from Basis_bits.bit_i to bit[i].
Pebble now accepts a$b as array indexing in input, yielding a[b] on output.
Information about user structs and their fields is now gathered and printed.

Location:
proto/pebble/trunk
Files:
2 added
3 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • proto/pebble/trunk/inputs/xmlwf.pbl

    r1242 r1246  
    5656        CRLF = "\r\n"
    5757       
     58        # pebble converts a$x to a[x].
     59        #
    5860        # Convert CRs to LFs (flip bits 5, 6 and 7 with xor).
    59         basis_bits.bit_5 ^= [\r]
    60         basis_bits.bit_6 ^= [\r]
    61         basis_bits.bit_7 ^= [\r]
     61        bit$5 ^= [\r]
     62        bit$6 ^= [\r]
     63        bit$7 ^= [\r]
    6264}
    6365
     
    153155
    154156macro parse_refs {
    155 //      CallOuts = ref_callouts()   // need to set callouts to 0 TS
     157        GenRefs = 0
     158        DecRefs = 0
     159        HexRefs = 0
     160        delmask = 0
     161#       error = 0
    156162
    157163    GenRef2 = "&[^#]"
     
    187193
    188194macro parse_tags {
    189 //      callouts = tag_callouts()
     195        ElemNames = 0
     196        AttNames = 0
     197        AttVals = 0
     198        Tags = 0
     199        EmptyTagEnds = 0
     200        EndTags = 0
     201#       error = 0
    190202       
    191203        # Start the parallel parsing by inspecting the character
  • proto/pebble/trunk/src/incode/Instruction.java

    r1242 r1246  
    11package incode;
     2
     3import util.PStringBuilder;
    24
    35public class Instruction {
     
    1315                super();
    1416                this.operation = operation;
    15                 this.variable  = variable;
     17                this.variable  = translateArrayIndices(variable);
    1618               
    1719                operand = new String[3];
    18                 this.operand[0]  = operand1;
    19                 this.operand[1]  = operand2;
    20                 this.operand[2]  = operand3;
     20                this.operand[0]  = translateArrayIndices(operand1);
     21                this.operand[1]  = translateArrayIndices(operand2);
     22                this.operand[2]  = translateArrayIndices(operand3);
    2123               
    2224                toBeDeleted = false;
     
    3638                this(operation, null, null, null, null);
    3739        }
    38        
     40
     41        private String translateArrayIndices(String operand) {
     42                if(operand == null)
     43                        return null;
     44                int firstIndex = operand.indexOf('$');
     45                if(firstIndex == -1) {
     46                        return operand;
     47                }
     48               
     49                String base = operand.substring(0, firstIndex);
     50                String index = operand.substring(firstIndex+1);
     51               
     52                return base + '[' + index + ']';
     53        }
    3954        public void markForDeletion() {
    4055                toBeDeleted = true;
  • proto/pebble/trunk/src/incode/Pythonater.java

    r1242 r1246  
    11package incode;
    22
     3import java.io.PrintStream;
     4
     5import lexicalStream.LexicalCollector;
    36import symbolTable.StructType;
    47import symbolTable.SymbolInfo;
     
    1013        private static final int NUM_BITS_PER_CHAR = 8;
    1114
    12         static public String buildBasisBitStruct() {
     15        public static void apply(SymbolTable symbolTable, LexicalCollector headCollector, BasicBlock head) {
     16                printPythonStructs(headCollector, symbolTable, System.out);
     17                printMainPythonRoutine(head, System.out);
     18        }
     19
     20        ///////////////////////////////////////////////////////////////
     21        // structs
     22        ///////////////////////////////////////////////////////////////
     23        private static void printPythonStructs(LexicalCollector headCollector, SymbolTable symtab, PrintStream out) {
     24//              out.println(Pythonater.buildBasisBitStruct());
     25                out.println(buildUserStructs(symtab));
     26                out.println(headCollector.structs());
     27        }
     28        @SuppressWarnings("unused")
     29        private static String buildBasisBitStruct() {
    1330                PStringBuilder builder = new PStringBuilder(0);
    14                
     31
    1532                builder.appendLine("class %s():", BASIS_BITS_CLASS_NAME);
    1633                builder.indent();
     
    2037                return builder.toString();
    2138        }
    22         static public String buildUserStructs(SymbolTable symtab) {
     39        private static String buildUserStructs(SymbolTable symtab) {
    2340                String result = "";
    2441                for(String symbol: symtab.structNames()) {
     
    3249                SymbolInfo info = symtab.get(symbol);
    3350                StructType type = (StructType)(info.getType());
    34                
     51
    3552                builder.appendLine("class %s():", symbol);
    3653                builder.indent();
     
    4057                return builder.toString();
    4158        }
    42        
     59
     60
     61        ///////////////////////////////////////////////////////////////
     62        // code
     63        ///////////////////////////////////////////////////////////////
     64        public static void printMainPythonRoutine(BasicBlock head, PrintStream out) {
     65                out.println("def parabix_parse(u8data):");
     66                out.println("    (bit, EOF_mask) = bitutil.transpose_streams(u8data)");
     67                out.println("    lex = Lex()");                         // overkill (and error) if no lex, shift, and/or seq
     68                out.println("    shift = Shift()");
     69                out.println("    seq = Seq()");
     70
     71                String python = head.pythonate(1);
     72                out.println(python);
     73        }
     74
     75
    4376}
  • proto/pebble/trunk/src/main/Main.java

    r1242 r1246  
    22import incode.BasicBlock;
    33import incode.Pythonater;
    4 import incode.localOptimization.BackwardCopyPropagation;
    5 import incode.localOptimization.ReuseAvailableExpressions;
    6 import incode.localOptimization.UseAndNot;
    74
    85import java.io.IOException;
     
    129import parser.PebbleLexer;
    1310import parser.PebbleParser;
     11import semantic.StructAnalyzer;
     12import symbolTable.SymbolTable;
    1413
    1514import org.antlr.runtime.ANTLRFileStream;
     
    4948            AssumptionIncorporator.apply(tree);
    5049           
     50            SymbolTable symbolTable = StructAnalyzer.apply(tree);
    5151            LexicalCollector headCollector = ((ProgramBlockASTN)tree).getCollector();
     52            BasicBlock headBlock = ASTtoIncode.apply(tree);
    5253
    53             System.out.println(Pythonater.buildBasisBitStruct());
    54 //            System.out.println(Pythonater.buildUserStructs(symtab));
    55             System.out.println(headCollector.structs());
    56 
    57             BasicBlock head = ASTtoIncode.apply(tree);
    58             String python = head.pythonate(1);
    59             System.out.println(python);
     54            Pythonater.apply(symbolTable, headCollector, headBlock);
    6055           
    6156        } catch (RecognitionException e) {
     
    6358        }
    6459    }
    65     public static BasicBlock optimizeX(BasicBlock block) {
    66         return block;   
    67     }
    68     public static BasicBlock optimize(BasicBlock inBlock) {
    69         BasicBlock block = inBlock;
    70 //              System.out.println(block.toString() + "\n\n\n" );
    71                
    72                 block = ReuseAvailableExpressions.apply(block);
    73 //              System.out.println(block.toString() + "\n\n\n" );
    74                
    75                 block = BackwardCopyPropagation.apply(block);
    76 //              System.out.println(block.toString() + "\n\n\n" );
    77                
    78                 block = UseAndNot.apply(block);
    79 //              System.out.println(block.toString() + "\n\n\n" );
    80 
    81                 return block;
    82     }
    8360}
  • proto/pebble/trunk/src/parser/Pebble.g

    r1242 r1246  
    243243variableType returns [Type type]
    244244        :       'output' {$type = PrimitiveType.Output;}
    245         |       'error'  {$type = PrimitiveType.Error;}
     245        |       'errorStream'  {$type = PrimitiveType.Error;}
    246246        ;
    247247
     
    541541//              WARNING!  dot ('.') hacked into here for allowing structure-reference!
    542542//                                      clean it up!
    543         :       ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.')*
     543//              '$' included for array indexing.
     544        :       ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|'$')*
    544545        ;
    545546fragment
  • proto/pebble/trunk/src/symbolTable/readme.txt

    r1242 r1246  
    88
    99This package contains a rudimentary symbol table and type system
    10 for pebble.  This package is currently unused, but will be included
    11 in later versions.
     10for pebble.  This package is currently used only to store structs,
     11and struct information is only used for printing purposes, not for
     12semantic analysis.  The role of this package will expand in later
     13versions.
    1214
    1315
  • proto/pebble/trunk/src/util/range/ASTRangeCompiler.java

    r1242 r1246  
    4040
    4141        private static final int NBITS = 8;
    42         private static final String BIT_VARIABLE_NAME_BASE = "basis_bits.bit_";
    43 //              private static final String BIT_VARIABLE_NAME_BASE = "bit_";
     42        private static final String BIT_VARIABLE_NAME_BASE = "bit[%d]";
     43//      private static final String BIT_VARIABLE_NAME_BASE = "basis_bits.bit_%d";
    4444       
    4545       
     
    190190        static private String bitVariableName(int index) {
    191191                assert 0 <= index && index < NBITS;
    192                 return BIT_VARIABLE_NAME_BASE + reverseBitIndex(index);
     192                return String.format(BIT_VARIABLE_NAME_BASE, reverseBitIndex(index));
    193193        }
    194194        /**
Note: See TracChangeset for help on using the changeset viewer.