Mercurial > hg > Applications > Grep
annotate regexParser/cerium/ppe/Exec.cc @ 275:8879eb8c64a8
remove segmentation fault
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Jan 2016 19:06:41 +0900 |
parents | 5aa9d01926f1 |
children | 99d635926ef3 |
rev | line source |
---|---|
266 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
272 | 5 #include "regexParser.h" |
6 #include "threadedSearch.h" | |
7 #include "FileMapReduce.h" | |
266 | 8 |
9 /* これは必須 */ | |
10 SchedDefineTask1(Exec,blockedGrep); | |
11 | |
272 | 12 static |
266 | 13 TSValue stateNothing(TSValue tsv) { |
14 return tsv; | |
15 } | |
16 | |
272 | 17 static |
266 | 18 TSValue stateSkip(TSValue tsv) { |
19 tsv.buff.matchBegin = tsv.buff.buffptr; | |
20 return tsv; | |
21 } | |
22 | |
272 | 23 static |
266 | 24 TSValue stateMatch(TSValue tsv) { |
25 ResultPtr r = NEW(Result); | |
26 r->begin = tsv.buff.matchBegin; | |
27 r->end = tsv.buff.buffptr; | |
28 *tsv.resultEnd = r; | |
29 r->next = NULL; | |
30 tsv.resultEnd = &r->next; | |
31 tsv.current = tsv.tg->stateList->tState; | |
32 tsv.buff.buffptr--; | |
33 tsv = stateSkip(tsv); | |
34 return tsv; | |
35 } | |
36 | |
272 | 37 TSValue blockSearch(TransitionGeneratorPtr tg,Buffer buff) { |
266 | 38 TSValue tsv; |
39 tsv.buff = buff; | |
40 tsv.tg = tg; | |
41 tsv.result = NULL; | |
42 tsv.resultEnd = &tsv.result; | |
271
6640b0d5bf13
remove anystate processing in sequential seqrch
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
266
diff
changeset
|
43 tsv.current = tg->anyState->tState; |
275
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
44 tsv.current->stateSkip = stateSkip; |
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
45 tsv.current->stateContinue = stateNothing; |
266 | 46 tsv.tg->stateSkip = stateSkip; |
47 tsv.tg->stateMatch = stateMatch; | |
48 tsv.tg->stateNothing = stateNothing; | |
49 unsigned char *end = buff.buffend; | |
50 buff.buffend = buff.buff+1; | |
51 tSearch(tsv); | |
52 tsv.blockBegin = tsv.current; | |
53 buff.buffend = end; | |
54 tSearch(tsv); | |
55 tsv.blockEnd = tsv.current; | |
272 | 56 if (tsv.blockEnd->state->bitState.bitContainer != 1) { |
266 | 57 ResultPtr r = NEW(Result); |
58 r->begin = tsv.buff.matchBegin; | |
59 r->end = NULL; | |
60 *tsv.resultEnd = r; | |
61 r->next = NULL; | |
62 tsv.resultEnd = &r->next; | |
63 } | |
64 return tsv; | |
65 } | |
66 | |
67 static int | |
68 blockedGrep(SchedTask *s, void *rbuf, void *wbuf) | |
69 { | |
70 long task_spwaned = (long)s->get_param(0); | |
71 long division_size = (long)s->get_param(1); | |
275
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
72 long length = (long)s->get_param(2); |
266 | 73 long out_size = (long)s->get_param(3); |
74 MapReduce *w = (MapReduce*)s->get_param(4); | |
75 long allocation = task_spwaned + (long)s->x; | |
272 | 76 unsigned char* i_data; |
77 unsigned long * o_data; | |
266 | 78 if (division_size) { |
272 | 79 i_data = (unsigned char*)s->get_input(rbuf,0) + allocation*division_size; |
80 o_data = (unsigned long *)s->get_output(wbuf,1) + allocation*out_size; | |
266 | 81 } else { |
272 | 82 i_data = (unsigned char*)s->get_input(0); |
83 o_data = (unsigned long *)s->get_output(0); | |
266 | 84 } |
85 TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global; | |
86 Buffer buff; | |
87 buff.buff = buff.buffptr = buff.matchBegin = i_data; | |
275
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
88 buff.buffend = buff.buff + length; |
272 | 89 TSValue tsv = blockSearch(tg,buff); |
90 o_data[0] = (unsigned long)tsv.result; | |
275
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
91 o_data[1] = (unsigned long)tsv.blockBegin->state; |
8879eb8c64a8
remove segmentation fault
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
272
diff
changeset
|
92 o_data[2] = (unsigned long)tsv.blockEnd->state; |
266 | 93 return 0; |
94 } |