54 static KEYWORD ModuleWords[] = {
55 {
"clear", (TFUN)0, CLEARMODULE, 0}
56 ,{
"end", (TFUN)0, ENDMODULE, 0}
57 ,{
"global", (TFUN)0, GLOBALMODULE, 0}
58 ,{
"sort", (TFUN)0, SORTMODULE, 0}
59 ,{
"store", (TFUN)0, STOREMODULE, 0}
62 static KEYWORD ModuleOptions[] = {
63 {
"inparallel", DoinParallel, 1, 1}
64 ,{
"local", DoModLocal, MODLOCAL, 0}
65 ,{
"maximum", DoModMax, MODMAX, 0}
66 ,{
"minimum", DoModMin, MODMIN, 0}
67 ,{
"noparallel", DoNoParallel, NOPARALLEL_USER,0}
68 ,{
"notinparallel", DonotinParallel,0, 1}
69 ,{
"parallel", DoParallel, PARALLELFLAG, 0}
70 ,{
"polyfun", DoPolyfun, POLYFUN, 0}
71 ,{
"polyratfun", DoPolyratfun, POLYFUN, 0}
72 ,{
"processbucketsize", DoProcessBucket,0, 0}
73 ,{
"sum", DoModSum, MODSUM, 0}
76 int ModuleInstruction(
int *moduletype,
int *specialtype)
80 int addit = 0, error = 0, i, j;
81 DUMMYUSE(specialtype);
83 AC.firstctypemessage = 0;
84 s = AP.preStart; SKIPBLANKS(s)
85 t = EndOfToken(s); c = *t; *t = 0;
86 AC.origin = FROMPOINTINSTRUCTION;
87 key = FindKeyWord(AP.preStart,ModuleWords,sizeof(ModuleWords)/sizeof(
KEYWORD));
89 MesPrint(
"@Unrecognized module terminator: %s",s);
92 while ( StrCmp((UBYTE *)key->name,(UBYTE *)
"end") ) key++;
95 *moduletype = key->type;
100 MesPrint(
"@Improper options field in . instruction");
105 if ( CoModOption(s) ) error = 1;
113 while ( *t && *t != ';' ) {
114 if ( *t ==
'\\' ) t++;
118 while ( u > s && u[-1] ==
' ' ) { u--; i--; }
119 if ( *u ==
'\\' ) { u++; i++; }
120 for ( j = COMMERCIALSIZE-1; j >= 0; j-- ) {
122 AC.Commercial[j] = *--u; i--;
123 if ( u > s && u[-1] ==
'\\' ) u--;
125 for ( ; j >= 0; j-- ) AC.Commercial[j] =
' ';
126 AC.Commercial[COMMERCIALSIZE] = 0;
129 if ( addit && *t !=
';' ) {
130 MesPrint(
"@Improper ending of . instruction");
143 int CoModuleOption(UBYTE *s)
147 int error = 0, polyflag = 0;
148 AC.origin = FROMMODULEOPTION;
153 option = FindKeyWord(s,ModuleOptions,
154 sizeof(ModuleOptions)/
sizeof(KEYWORD));
157 *t = c; t++; s = SkipAName(t);
162 MesPrint(
"@Unrecognized module option: %s",s);
171 if ( (option->func)(t) ) error = 1;
173 if ( StrCmp((UBYTE *)(option->name),(UBYTE *)("polyfun")) == 0
174 || StrCmp((UBYTE *)(option->name),(UBYTE *)("polyratfun")) == 0 ) {
178 if ( option->flags > 0 )
return(error);
182 while ( *tt ==
',' ) tt++;
183 if ( *tt !=
'$' )
break;
186 if ( *t ==
')' )
break;
187 if ( *t ==
'(' ) SKIPBRA3(t)
188 else if ( *t == '{
' ) SKIPBRA2(t)
189 else if ( *t == '[
' ) SKIPBRA1(t)
193 } while ( *s == ',
' );
195 MesPrint("@Unrecognized module option: %s",s);
205 To be called from a .instruction.
206 Only recognizes polyfun. The newer ones should be via the
207 ModuleOption statement.
210 int CoModOption(UBYTE *s)
214 AC.origin = FROMPOINTINSTRUCTION;
219 if ( StrICmp(s,(UBYTE *)"polyfun") == 0 ) {
222 if ( DoPolyfun(t) ) error = 1;
224 else if ( StrICmp(s,(UBYTE *)"polyratfun") == 0 ) {
227 if ( DoPolyratfun(t) ) error = 1;
230 MesPrint("@Unrecognized module option in .instruction: %s",s);
235 if ( *t == ',
' || *t == ')
' ) break;
236 if ( *t == '(
' ) SKIPBRA3(t)
237 else if ( *t == '{
' ) SKIPBRA2(t)
238 else if ( *t == '[
' ) SKIPBRA1(t)
242 } while ( *s == ',
' );
244 MesPrint("@Unrecognized module option in .instruction: %s",s);
255 VOID SetSpecialMode(int moduletype, int specialtype)
257 DUMMYUSE(moduletype); DUMMYUSE(specialtype);
272 int ExecModule(int moduletype)
274 return(DoExecute(moduletype,0));
291 Remark 27-oct-2005 by JV
292 This routine (and CleanUp in startup.c) may still need some work:
293 What to do with preprocessor variables
294 What to do with files we write to
301 while ( AC.CurrentStream->previous >= 0 )
302 AC.CurrentStream = CloseStream(AC.CurrentStream);
303 AP.PreSwitchLevel = AP.PreIfLevel = 0;
305 for ( j = NumProcedures-1; j >= 0; j-- ) {
306 if ( Procedures[j].name ) M_free(Procedures[j].name,"name of procedure");
307 if ( Procedures[j].p.buffer ) M_free(Procedures[j].p.buffer,"buffer of procedure");
311 while ( NumPre > AP.gNumPre ) {
313 M_free(PreVar[NumPre].name,"PreVar[NumPre].name");
314 PreVar[NumPre].name = PreVar[NumPre].value = 0;
318 for ( j = 0; j < NumExpressions; j++ ) {
319 AC.exprnames->namenode[Expressions[j].node].type = CDELETE;
323 CompactifyTree(AC.exprnames,EXPRNAMES);
325 AP.ComChar = AP.cComChar;
326 if ( AP.procedureExtension ) M_free(AP.procedureExtension,"procedureextension");
327 AP.procedureExtension = strDup1(AP.cprocedureExtension,"procedureextension");
329 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag;
330 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols;
331 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] = 'Z
';
332 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
333 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers;
334 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace;
335 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats;
336 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag;
337 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats;
338 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag;
339 if ( AC.ThreadsFlag && AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
340 AC.ThreadBucketSize = AM.gThreadBucketSize = AM.ggThreadBucketSize;
341 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing;
342 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch;
343 AC.ShortStatsMax = AM.gShortStatsMax = AM.ggShortStatsMax;
346 if ( DeleteStore(0) < 0 ) {
347 MesPrint("@Cannot restart the storage file");
361 int DoPolyfun(UBYTE *s)
365 WORD funnum, eqsign = 0;
366 if ( AC.origin == FROMPOINTINSTRUCTION ) {
367 if ( *s == 0 || *s == ',
' || *s == ')
' ) {
368 AR.PolyFun = 0; AR.PolyFunType = 0;
372 MesPrint("@Proper use in point instructions is: PolyFun[=functionname]");
379 AR.PolyFun = 0; AR.PolyFunType = 0;
382 if ( *s != '=
' && *s != ',
' ) {
383 MesPrint("@Proper use is: PolyFun[{ ,=}functionname]");
386 if ( *s == '=
' ) eqsign = 1;
393 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) {
394 if ( AC.origin != FROMPOINTINSTRUCTION && eqsign == 0 ) {
395 AR.PolyFun = 0; AR.PolyFunType = 0;
398 MesPrint("@ %s is not a properly declared function",s);
402 if ( functions[funnum].spec != 0 || functions[funnum].commute != 0 ) {
403 MesPrint("@The PolyFun must be a regular commuting function!");
407 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 1;
410 if ( *t && *t != ',
' && *t != ')
' ) {
412 MesPrint("@Improper ending of end-of-module instruction: %s",s);
424 int DoPolyratfun(UBYTE *s)
429 if ( AC.origin == FROMPOINTINSTRUCTION ) {
430 if ( *s == 0 || *s == ',
' || *s == ')
' ) {
431 AR.PolyFun = 0; AR.PolyFunType = 0;
435 MesPrint("@Proper use in point instructions is: PolyRatFun[=functionname]");
441 AR.PolyFun = 0; AR.PolyFunType = 0;
444 if ( *s != '=
' && *s != ',
' ) {
445 MesPrint("@Proper use is: PolyRatFun[{ ,=}functionname]");
454 if ( GetName(AC.varnames,s,&funnum,WITHAUTO) != CFUNCTION ) {
455 MesPrint("@ %s is not a properly declared function",s);
459 if ( functions[funnum].spec != 0 || functions[funnum].commute != 0 ) {
460 MesPrint("@The PolyRatFun must be a regular commuting function!");
464 AR.PolyFun = funnum+FUNCTION; AR.PolyFunType = 2;
465 AC.PolyRatFunChanged = 1;
468 if ( *t && *t != ',
' && *t != ')
' ) {
470 MesPrint("@Improper ending of end-of-module instruction: %s",s);
482 int DoNoParallel(UBYTE *s)
484 if ( *s == 0 || *s == ',
' || *s == ')
' ) {
485 AC.mparallelflag |= NOPARALLEL_USER;
488 MesPrint("@NoParallel should not have extra parameters");
497 int DoParallel(UBYTE *s)
499 if ( *s == 0 || *s == ',
' || *s == ')
' ) {
500 AC.mparallelflag &= ~NOPARALLEL_USER;
503 MesPrint("@Parallel should not have extra parameters");
512 int DoModSum(UBYTE *s)
514 while ( *s == ',
' ) s++;
516 MesPrint("@Module Sum should mention which $-variables");
519 s = DoModDollar(s,MODSUM);
520 if ( s && *s != 0 && *s != ')
' ) {
521 MesPrint("@Irregular end of Sum option of Module statement");
532 int DoModMax(UBYTE *s)
534 while ( *s == ',
' ) s++;
536 MesPrint("@Module Maximum should mention which $-variables");
539 s = DoModDollar(s,MODMAX);
540 if ( s && *s != 0 ) {
541 MesPrint("@Irregular end of Maximum option of Module statement");
552 int DoModMin(UBYTE *s)
554 while ( *s == ',
' ) s++;
556 MesPrint("@Module Minimum should mention which $-variables");
559 s = DoModDollar(s,MODMIN);
560 if ( s && *s != 0 ) {
561 MesPrint("@Irregular end of Minimum option of Module statement");
572 int DoModLocal(UBYTE *s)
574 while ( *s == ',
' ) s++;
576 MesPrint("@ModuleOption Local should mention which $-variables");
579 s = DoModDollar(s,MODLOCAL);
580 if ( s && *s != 0 ) {
581 MesPrint("@Irregular end of Local option of ModuleOption statement");
592 int DoProcessBucket(UBYTE *s)
595 while ( *s == ',
' || *s == '=
' ) s++;
597 if ( *s && *s != ' ' && *s != '\t
' ) {
598 MesPrint("&Numerical value expected for ProcessBucketSize");
601 AC.mProcessBucketSize = x;
610 UBYTE * DoModDollar(UBYTE *s, int type)
615 while ( *s == '$
' ) {
617 Read the name of the dollar
622 if ( FG.cTable[*s] == 0 ) {
623 while ( FG.cTable[*s] == 0 || FG.cTable[*s] == 1 ) s++;
625 number = GetDollar(name);
627 number = AddDollar(s,0,0,0);
628 Warning("&Undefined $-variable in module statement");
630 md = (MODOPTDOLLAR *)FromList(&AC.ModOptDolList);
634 if ( type == MODLOCAL ) {
636 DOLLARS dglobal, dlocal;
637 md->dstruct = (DOLLARS)Malloc1(
638 sizeof(struct DoLlArS)*AM.totalnumberofthreads,"Local DOLLARS");
640 Now copy the global dollar into the local copies.
641 This can be nontrivial if the value needs an allocation.
642 We don't really need the locks.
644 dglobal = Dollars + number;
645 for ( j = 0; j < AM.totalnumberofthreads; j++ ) {
646 dlocal = md->dstruct + j;
647 dlocal->index = dglobal->index;
648 dlocal->node = dglobal->node;
649 dlocal->type = dglobal->type;
650 dlocal->name = dglobal->name;
651 dlocal->size = dglobal->size;
652 dlocal->where = dglobal->where;
653 if ( dlocal->size > 0 ) {
654 dlocal->where = (WORD *)Malloc1((dlocal->size+1)*
sizeof(WORD),
"Local dollar value");
655 for ( i = 0; i < dlocal->size; i++ )
656 dlocal->where[i] = dglobal->where[i];
657 dlocal->where[dlocal->size] = 0;
659 dlocal->pthreadslockread = dummylock;
660 dlocal->pthreadslockwrite = dummylock;
661 dlocal->nfactors = dglobal->nfactors;
662 if ( dglobal->nfactors > 1 ) {
665 dlocal->factors = (
FACDOLLAR *)Malloc1(dglobal->nfactors*
sizeof(
FACDOLLAR),
"Dollar factors");
666 for ( i = 0; i < dglobal->nfactors; i++ ) {
667 nsize = dglobal->factors[i].size;
668 dlocal->factors[i].type = DOLUNDEFINED;
669 dlocal->factors[i].value = dglobal->factors[i].value;
670 if ( ( dlocal->factors[i].size = nsize ) > 0 ) {
671 dlocal->factors[i].where = t = (WORD *)Malloc1(
sizeof(WORD)*(nsize+1),
"DollarCopyFactor");
672 m = dglobal->factors[i].where;
677 dlocal->factors[i].where = 0;
681 else { dlocal->factors = 0; }
691 MesPrint(
"&Illegal name for $-variable in module option");
692 while ( *s !=
',' && *s != 0 && *s !=
')' ) s++;
694 while ( *s ==
',' ) s++;
711 int DoinParallel(UBYTE *s)
713 return(DoInParallel(s,1));
721 int DonotinParallel(UBYTE *s)
723 return(DoInParallel(s,0));
733 int DoExecStatement()
737 if ( system((
char *)(AP.preStart)) )
return(-1);
740 Error0(
"External programs not implemented on this computer/system");
750 int DoPipeStatement()
754 if ( OpenStream(AP.preStart,PIPESTREAM,0,PRENOACTION) == 0 )
return(-1);
757 Error0(
"Pipes not implemented on this computer/system");