Changeset 4049
- Timestamp:
- Aug 19, 2014, 5:24:07 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
proto/s2k/trunk/framework/input/test/s2k/proto/grep/grep_flow.s2k
r4009 r4049 33 33 * 34 34 * 35 * The Pablo compiler translates Pablo codeto C++ code as follows.35 * The \s2k{} compiler translates \s2k{} to \b2k{} to C++ code as follows. 36 36 * 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. 38 39 * 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. 40 42 * C/C++ structures are generated with `do_block', `do_final_blocks', `clear' 41 43 * member functions, as well as member variables to capture … … 48 50 49 51 /* 52 struct Input { 53 stream<8> data; 54 }; 55 */ 56 57 /* 50 58 struct Basis_bits{ 51 52 53 54 55 56 57 58 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; 59 67 }; 60 68 */ 61 69 62 70 struct Lex{ 63 64 65 66 67 71 stream a; 72 stream p; 73 stream l; 74 stream e; 75 stream LF; 68 76 }; 69 77 70 78 struct Output{ 71 72 73 74 79 stream match_follows; 80 stream lines; 81 stream line_starts; 82 stream line_ends; 75 83 }; 76 84 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 /* 86 Runtime.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 101 filter Source() { 102 103 103 } 104 104 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; 105 filter 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)); 112 131 } 113 132 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)); 133 filter 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; 131 140 } 132 141 133 // pgather 134 /* 135 filter Write(struct Output output) { 136 stream<8> lines = pgather<8>(output.lines); 137 write<8>(oaddr, lines); 142 filter 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)); 138 159 } 139 */ 160 filter 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 } 140 168 141 169 // 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); 170 filter 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); 147 174 } 148 */149 175 150 graph Main() {176 graph pipeline() { /* generates struct pipeline { void open(){} void process(){} void close(){} }; */ 151 177 152 178 // char * byte_data; … … 155 181 struct Output output; 156 182 157 // filter Read src;183 // filter Read read; /* Begins with a filter that contains bind calls, io.read<>. */ 158 184 filter Transpose transpose; 159 185 filter ClassifyBytes classifyBytes; 160 186 filter Match match; 161 187 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<>. */ 163 189 164 //read();190 // read(); 165 191 transpose(byte_data, basis_bits); 166 192 classifyBytes(basis_bits, lex); 167 193 match(lex, output); 168 194 matchLines(lex, output); 169 //write(output);195 // write(output); 170 196 171 197 }
Note: See TracChangeset
for help on using the changeset viewer.