Changeset 4049 for proto/s2k


Ignore:
Timestamp:
Aug 19, 2014, 5:24:07 PM (5 years ago)
Author:
ksherdy
Message:

Minor updates to s2k source file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/s2k/trunk/framework/input/test/s2k/proto/grep/grep_flow.s2k

    r4009 r4049  
    3333 *
    3434 *
    35  * The Pablo compiler translates Pablo code to C++ code as follows.
     35 * The \s2k{} compiler translates \s2k{} to \b2k{} to C++ code as follows.
    3636 *
    37  * 1. \s2k{} stream structures to C/C++ structures, i.e., simple data containers.
     37 * 1. \s2k{} stream structures to \b2k{} bitblock structure
     38 *    to bitblock C/C++ structures, i.e., simple data containers.
    3839 *
    39  * 2. \s2k{} stream functions to C/C++ structures, i.e., objects with methods.
     40 * 2. \s2k{} stream filters to \b2k{} bitblock kernels to
     41 *    C/C++ structures, i.e., objects with methods.
    4042 *    C/C++ structures are generated with `do_block', `do_final_blocks', `clear'
    4143 *    member functions, as well as member variables to capture
     
    4850
    4951/*
     52struct Input {
     53  stream<8> data;
     54};
     55*/
     56
     57/*
    5058struct Basis_bits{
    51     stream bit_0;
    52     stream bit_1;
    53     stream bit_2;
    54     stream bit_3;
    55     stream bit_4;
    56     stream bit_5;
    57     stream bit_6;
    58     stream bit_7;
     59  stream bit_0;
     60  stream bit_1;
     61  stream bit_2;
     62  stream bit_3;
     63  stream bit_4;
     64  stream bit_5;
     65  stream bit_6;
     66  stream bit_7;
    5967};
    6068*/
    6169
    6270struct Lex{
    63     stream a;
    64     stream p;
    65     stream l;
    66     stream e;
    67     stream LF;
     71  stream a;
     72  stream p;
     73  stream l;
     74  stream e;
     75  stream LF;
    6876};
    6977
    7078struct Output{
    71     stream match_follows;
    72     stream lines;
    73     stream line_starts;
    74     stream line_ends;
     79  stream match_follows;
     80  stream lines;
     81  stream line_starts;
     82  stream line_ends;
    7583};
    7684
    77 filter ClassifyBytes(struct Basis_bits basis_bits, struct Lex lex) {
    78     stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0));
    79     stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3));
    80     stream temp3 = (temp1 & temp2);
    81     stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5);
    82     stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6));
    83     stream temp6 = (temp5 & (~ temp4));
    84     lex.a = (temp3 & temp6);
    85     stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
    86     stream temp8 = (temp1 & temp7);
    87     stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7);
    88     stream temp10 = (temp4 | temp9);
    89     lex.p = (temp8 & (~ temp10));
    90     stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5);
    91     stream temp12 = (temp11 & (~ temp9));
    92     lex.l = (temp3 & temp12);
    93     stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4));
    94     stream temp14 = (temp13 & temp5);
    95     lex.e = (temp3 & temp14);
    96     stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1);
    97     stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3);
    98     stream temp17 = (temp15 | temp16);
    99     stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5));
    100     stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7));
    101     stream temp20 = (temp18 & temp19);
    102     lex.LF = (temp20 & (~ temp17));
     85/*
     86Runtime.h
     87
     88  // Associates a C array with an \s2k{} stream variable.
     89  bind<char>(buffer, stream<8> s, int size);
     90 
     91  // Reads a C array into an \s2k{} variable.
     92  read<>(s);
     93 
     94  // Writes an \s2k{} variable to a C array.
     95  write<>(s);
     96
     97};
     98
     99*/
     100
     101filter Source() {
     102
    103103}
    104104
    105 filter Match(struct Lex lex, struct Output output) {
    106     stream cursor = flow.Advance(lex.a);
    107     cursor = flow.Advance((cursor & lex.p));
    108     cursor = flow.Advance((cursor & lex.p));
    109     cursor = flow.Advance((cursor & lex.l));
    110     cursor = flow.Advance((cursor & lex.e));
    111     output.match_follows = cursor;
     105filter ClassifyBytes(in struct Basis_bits basis_bits, out struct Lex lex) {
     106  stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0));
     107  stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3));
     108  stream temp3 = (temp1 & temp2);
     109  stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5);
     110  stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6));
     111  stream temp6 = (temp5 & (~ temp4));
     112  lex.a = (temp3 & temp6);
     113  stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
     114  stream temp8 = (temp1 & temp7);
     115  stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7);
     116  stream temp10 = (temp4 | temp9);
     117  lex.p = (temp8 & (~ temp10));
     118  stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5);
     119  stream temp12 = (temp11 & (~ temp9));
     120  lex.l = (temp3 & temp12);
     121  stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4));
     122  stream temp14 = (temp13 & temp5);
     123  lex.e = (temp3 & temp14);
     124  stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1);
     125  stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3);
     126  stream temp17 = (temp15 | temp16);
     127  stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5));
     128  stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7));
     129  stream temp20 = (temp18 & temp19);
     130  lex.LF = (temp20 & (~ temp17));
    112131}
    113132
    114 filter MatchLines(struct Lex lex, struct Output output) {
    115     stream all_line_starts = (flow.ScanToFirst((~ lex.LF)) | (flow.Advance(lex.LF) & (~ lex.LF)));
    116     stream all_line_ends = lex.LF;
    117     stream last_line_start = flow.ScanToFirst(all_line_starts);
    118     stream cursor = last_line_start;
    119     while (flow.inFile(cursor)) {
    120         if ((cursor & all_line_starts)) {
    121             last_line_start = cursor;
    122         }
    123         if ((cursor & output.match_follows)) {
    124             cursor = flow.ScanTo(cursor, lex.LF);
    125             output.lines |= flow.InclusiveSpan(last_line_start, cursor);
    126         }
    127         cursor = flow.AdvanceThenScanTo(cursor, (all_line_starts | output.match_follows));
    128     }
    129     output.line_starts = (output.lines & all_line_starts);
    130     output.line_ends = flow.ScanTo(output.line_starts, (output.lines & all_line_ends));
     133filter Match(in struct Lex lex, out struct Output output) {
     134  stream cursor = flow.Advance(lex.a);
     135  cursor = flow.Advance((cursor & lex.p));
     136  cursor = flow.Advance((cursor & lex.p));
     137  cursor = flow.Advance((cursor & lex.l));
     138  cursor = flow.Advance((cursor & lex.e));
     139  output.match_follows = cursor;
    131140}
    132141
    133 // pgather
    134 /*
    135 filter Write(struct Output output) {
    136   stream<8> lines = pgather<8>(output.lines);
    137   write<8>(oaddr, lines);
     142filter MatchLines(in struct Lex lex, out struct Output output) {
     143  stream all_line_starts = (flow.ScanToFirst((~ lex.LF)) | (flow.Advance(lex.LF) & (~ lex.LF)));
     144  stream all_line_ends = lex.LF;
     145  stream last_line_start = flow.ScanToFirst(all_line_starts);
     146  stream cursor = last_line_start;
     147  while (flow.inFile(cursor)) {
     148      if ((cursor & all_line_starts)) {
     149          last_line_start = cursor;
     150      }
     151      if ((cursor & output.match_follows)) {
     152          cursor = flow.ScanTo(cursor, lex.LF);
     153          output.lines |= flow.InclusiveSpan(last_line_start, cursor);
     154      }
     155      cursor = flow.AdvanceThenScanTo(cursor, (all_line_starts | output.match_follows));
     156  }
     157  output.line_starts = (output.lines & all_line_starts);
     158  output.line_ends = flow.ScanTo(output.line_starts, (output.lines & all_line_ends));
    138159}
    139 */
     160filter Read(out struct Output output) {
     161  //io.bind<char>(buffer, s76543210, 1024);
     162  //io.bind<BitBlock>(starts, output.starts, 1024/BITBLOCK_SIZE);
     163  //io.bind<BitBlock>(ends, output.ends, 1024/BITBLOCK_SIZE);
     164  //io.bind<BitBlock>(markers, output.markers, 1024/BITBLOCK_SIZE);
     165
     166  //io.read_buffer<char>(s76543210);
     167}
    140168
    141169// post-processing
    142 /*
    143 filter Write(struct Output output) {
    144   write<1>(oaddr, output.line_starts);
    145   write<1>(oaddr, output.line_ends);
    146   write<1>(oaddr, output.match_follows);
     170filter Write(out struct Output output) {
     171  //io.write<BitBlock>(output.line_starts);
     172  //io.write<BitBlock>(output.line_ends);
     173  //io.write<BitBlock>(output.match_follows);
    147174}
    148 */
    149175
    150 graph Main() {
     176graph pipeline() { /* generates struct pipeline { void open(){} void process(){} void close(){} }; */
    151177
    152178    // char * byte_data;
     
    155181    struct Output output;
    156182   
    157 //  filter Read src;
     183//  filter Read read; /* Begins with a filter that contains bind calls, io.read<>. */
    158184    filter Transpose transpose;
    159185    filter ClassifyBytes classifyBytes;
    160186    filter Match match;
    161187    filter MatchLines matchLines;
    162 //  filter Write snk; // bind<1>(output.line_starts, line_starts); bind<1>(output.line_ends, line_ends); bind<1>(output.match_follows, match_follows);
     188//  filter Write write; /* Ends with a filter that contains write calls, io.write<>. */
    163189
    164 // read();
     190    // read();
    165191    transpose(byte_data, basis_bits);
    166192    classifyBytes(basis_bits, lex);
    167193    match(lex, output);
    168194    matchLines(lex, output);
    169 // write(output);
     195    // write(output);
    170196   
    171197}
Note: See TracChangeset for help on using the changeset viewer.