-
Notifications
You must be signed in to change notification settings - Fork 6
/
chill_ast.hh
2365 lines (1739 loc) · 94.9 KB
/
chill_ast.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _CHILL_AST_H_
#define _CHILL_AST_H_
#define CHILL_INDENT_AMOUNT 2
#include "chill_io.hh"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <vector> // std::vector
#include <ir_enums.hh> // for IR_CONDITION_*
using std::vector;
using std::string;
char *parseUnderlyingType( char *sometype );
char *parseArrayParts( char *sometype );
bool isRestrict( const char *sometype );
char *splitTypeInfo( char *underlyingtype );
char *ulhack( char *brackets ); // change "1024UL" to "1024"
char *restricthack( char *typeinfo ); // remove __restrict__ , MODIFIES the argument!
enum CHILL_ASTNODE_TYPE {
CHILLAST_NODETYPE_UNKNOWN=0,
CHILLAST_NODETYPE_SOURCEFILE,
CHILLAST_NODETYPE_TYPEDEFDECL,
CHILLAST_NODETYPE_VARDECL,
// CHILLAST_NODETYPE_PARMVARDECL, not used any more
CHILLAST_NODETYPE_FUNCTIONDECL,
CHILLAST_NODETYPE_RECORDDECL, // struct or union (or class)
CHILLAST_NODETYPE_MACRODEFINITION,
CHILLAST_NODETYPE_COMPOUNDSTMT,
CHILLAST_NODETYPE_LOOP, // AKA ForStmt
CHILLAST_NODETYPE_TERNARYOPERATOR,
CHILLAST_NODETYPE_BINARYOPERATOR,
CHILLAST_NODETYPE_UNARYOPERATOR,
CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR,
CHILLAST_NODETYPE_MEMBEREXPR, // structs/unions
CHILLAST_NODETYPE_DECLREFEXPR,
CHILLAST_NODETYPE_INTEGERLITERAL,
CHILLAST_NODETYPE_FLOATINGLITERAL,
CHILLAST_NODETYPE_IMPLICITCASTEXPR,
CHILLAST_NODETYPE_RETURNSTMT,
CHILLAST_NODETYPE_CALLEXPR,
CHILLAST_NODETYPE_DECLSTMT,
CHILLAST_NODETYPE_PARENEXPR,
CHILLAST_NODETYPE_CSTYLECASTEXPR,
CHILLAST_NODETYPE_CSTYLEADDRESSOF,
CHILLAST_NODETYPE_IFSTMT,
CHILLAST_NODETYPE_SIZEOF,
CHILLAST_NODETYPE_MALLOC,
CHILLAST_NODETYPE_FREE,
CHILLAST_NODETYPE_PREPROCESSING, // comments, #define, #include, whatever else works
CHILLAST_NODETYPE_NOOP, // NO OP
// CUDA specific
CHILLAST_NODETYPE_CUDAMALLOC,
CHILLAST_NODETYPE_CUDAFREE,
CHILLAST_NODETYPE_CUDAMEMCPY,
CHILLAST_NODETYPE_CUDAKERNELCALL,
CHILLAST_NODETYPE_CUDASYNCTHREADS,
CHILLAST_NODETYPE_NULL // explicit non-statement
// TODO
} ;
#define CHILLAST_NODETYPE_FORSTMT CHILLAST_NODETYPE_LOOP
#define CHILLAST_NODETYPE_TRANSLATIONUNIT CHILLAST_NODETYPE_SOURCEFILE
enum CHILL_FUNCTION_TYPE {
CHILL_FUNCTION_CPU = 0,
CHILL_FUNCTION_GPU
};
enum CHILL_MEMBER_EXP_TYPE {
CHILL_MEMBER_EXP_DOT = 0,
CHILL_MEMBER_EXP_ARROW
};
enum CHILL_PREPROCESSING_TYPE {
CHILL_PREPROCESSING_TYPEUNKNOWN = 0,
CHILL_PREPROCESSING_COMMENT,
CHILL_PREPROCESSING_POUNDDEFINE,
CHILL_PREPROCESSING_POUNDINCLUDE,
CHILL_PREPROCESSING_PRAGMA // unused so far
};
enum CHILL_PREPROCESSING_POSITION { // when tied to another statement
CHILL_PREPROCESSING_POSITIONUNKNOWN = 0,
CHILL_PREPROCESSING_LINEBEFORE, // previous line
CHILL_PREPROCESSING_LINEAFTER, // next line
CHILL_PREPROCESSING_TOTHERIGHT, // for this kind of comment, on same line
CHILL_PREPROCESSING_IMMEDIATELYBEFORE // on same line
};
extern const char* Chill_AST_Node_Names[]; // WARNING MUST BE KEPT IN SYNC WITH BELOW LIST
// fwd declarations
class chillAST_node; // the generic node. specific types derive from this
class chillAST_NULL; // empty
class chillAST_SourceFile; // ast for an entire source file (translationunit)
class chillAST_TypedefDecl;
class chillAST_VarDecl;
//class chillAST_ParmVarDecl;
class chillAST_FunctionDecl;
class chillAST_RecordDecl; // structs and unions (and classes?)
class chillAST_MacroDefinition;
class chillAST_CompoundStmt; // just a bunch of other statements
class chillAST_ForStmt; // AKA a LOOP
class chillAST_TernaryOperator;
class chillAST_BinaryOperator;
class chillAST_ArraySubscriptExpr;
class chillAST_MemberExpr;
class chillAST_DeclRefExpr;
class chillAST_IntegerLiteral;
class chillAST_FloatingLiteral;
class chillAST_UnaryOperator;
class chillAST_ImplicitCastExpr;
class chillAST_CStyleCastExpr;
class chillAST_CStyleAddressOf;
class chillAST_ReturnStmt;
class chillAST_CallExpr;
class chillAST_ParenExpr;
class chillAST_Sizeof;
class chillAST_Malloc;
class chillAST_Free;
class chillAST_NoOp;
class chillAST_CudaMalloc;
class chillAST_CudaFree;
class chillAST_CudaMemcpy;
class chillAST_CudaKernelCall;
class chillAST_CudaSyncthreads;
class chillAST_Preprocessing;
typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; // typedef
typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; // typedef
bool symbolTableHasVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl
chillAST_VarDecl *symbolTableFindVariableNamed( chillAST_SymbolTable *table, const char *name ); // fwd decl TODO too many similar named functions
void printSymbolTable( chillAST_SymbolTable *st ); // fwd decl
void printSymbolTableMoreInfo( chillAST_SymbolTable *st ); // fwd decl
chillAST_node *lessthanmacro( chillAST_node *left, chillAST_node *right); // fwd declaration
chillAST_SymbolTable *addSymbolToTable( chillAST_SymbolTable *st, chillAST_VarDecl *vd ); // fwd decl
chillAST_TypedefTable *addTypedefToTable( chillAST_TypedefTable *tt, chillAST_TypedefDecl *td ); // fwd decl
bool streq( const char *a, const char *b); // fwd decl
void chillindent( int i, FILE *fp ); // fwd declaration
void insertNewDeclAtLocationOfOldIfNeeded( chillAST_VarDecl *newdecl, chillAST_VarDecl *olddecl);
chillAST_DeclRefExpr *buildDeclRefExpr( chillAST_VarDecl *);
// an actual chill ast.
// nodes based on clang AST which are in turn based on C++
class chillAST_node { // generic node. a tree of these is the AST. this is virtual (can't instantiate)
public:
static int chill_scalar_counter; // for manufactured scalars
static int chill_array_counter ; // for manufactured arrays
static int chill_pointer_counter ; // for manufactured arrays
CHILL_ASTNODE_TYPE asttype;
bool isSourceFile() { return (asttype == CHILLAST_NODETYPE_SOURCEFILE); };
bool isTypeDefDecl() { return (asttype == CHILLAST_NODETYPE_TYPEDEFDECL); };
bool isVarDecl() { return (asttype == CHILLAST_NODETYPE_VARDECL); };
bool isFunctionDecl() { return (asttype == CHILLAST_NODETYPE_FUNCTIONDECL); };
bool isRecordDecl() { return (asttype == CHILLAST_NODETYPE_RECORDDECL); };
bool isMacroDefinition() { return (asttype == CHILLAST_NODETYPE_MACRODEFINITION); };
bool isCompoundStmt() { return (asttype == CHILLAST_NODETYPE_COMPOUNDSTMT); };
bool isLoop() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA ForStmt
bool isForStmt() { return (asttype == CHILLAST_NODETYPE_LOOP); }; // AKA Loop
bool isIfStmt() { return (asttype == CHILLAST_NODETYPE_IFSTMT); };
bool isTernaryOperator() { return (asttype == CHILLAST_NODETYPE_TERNARYOPERATOR);};
bool isBinaryOperator() { return (asttype == CHILLAST_NODETYPE_BINARYOPERATOR); };
bool isUnaryOperator() { return (asttype == CHILLAST_NODETYPE_UNARYOPERATOR); };
bool isArraySubscriptExpr() { return (asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR); };
bool isMemberExpr() { return (asttype == CHILLAST_NODETYPE_MEMBEREXPR); };
bool isDeclRefExpr() { return (asttype == CHILLAST_NODETYPE_DECLREFEXPR); };
bool isIntegerLiteral() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL); };
bool isFloatingLiteral() { return (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); };
bool isImplicitCastExpr() { return (asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR); };
bool isReturnStmt() { return (asttype == CHILLAST_NODETYPE_RETURNSTMT); };
bool isCallExpr() { return (asttype == CHILLAST_NODETYPE_CALLEXPR); };
bool isParenExpr() { return (asttype == CHILLAST_NODETYPE_PARENEXPR); };
bool isSizeof() { return (asttype == CHILLAST_NODETYPE_SIZEOF); };
bool isMalloc() { return (asttype == CHILLAST_NODETYPE_MALLOC); };
bool isFree() { return (asttype == CHILLAST_NODETYPE_FREE); };
bool isPreprocessing() { return (asttype == CHILLAST_NODETYPE_PREPROCESSING); };
bool isNoOp() { return (asttype == CHILLAST_NODETYPE_NOOP); };
bool isNull() { return (asttype == CHILLAST_NODETYPE_NULL); };
bool isCStyleCastExpr() { return (asttype == CHILLAST_NODETYPE_CSTYLECASTEXPR); };
bool isCStyleAddressOf() { return (asttype == CHILLAST_NODETYPE_CSTYLEADDRESSOF); };
bool isCudaMalloc() { return (asttype == CHILLAST_NODETYPE_CUDAMALLOC); };
bool isCudaFree() { return (asttype == CHILLAST_NODETYPE_CUDAFREE); };
bool isCudaMemcpy() { return (asttype == CHILLAST_NODETYPE_CUDAMEMCPY); };
bool isCudaKERNELCALL() { return (asttype == CHILLAST_NODETYPE_CUDAKERNELCALL); };
bool isCudaSYNCTHREADS() { return (asttype == CHILLAST_NODETYPE_CUDASYNCTHREADS); };
bool isDeclStmt() { return (asttype == CHILLAST_NODETYPE_DECLSTMT); }; // doesn't exist
bool isConstant() { return (asttype == CHILLAST_NODETYPE_INTEGERLITERAL) || (asttype == CHILLAST_NODETYPE_FLOATINGLITERAL); }
virtual bool isAssignmentOp() { return false; };
virtual bool isComparisonOp() { return false; };
virtual bool isNotLeaf() { return false; };
virtual bool isLeaf() { return true; };
virtual bool isParmVarDecl() { return false; };
virtual bool isPlusOp() { return false; };
virtual bool isMinusOp() { return false; };
virtual bool isPlusMinusOp() { return false; };
virtual bool isMultDivOp() { return false; };
virtual bool isAStruct() { return false; };
virtual bool isAUnion() { return false; };
virtual bool hasSymbolTable() { return false; } ; // most nodes do NOT have a symbol table
virtual bool hasTypedefTable() { return false; } ; // most nodes do NOT have a typedef table
virtual chillAST_SymbolTable *getSymbolTable() { return NULL; } // most nodes do NOT have a symbol table
virtual chillAST_VarDecl *findVariableNamed( const char *name ); // recursive
chillAST_RecordDecl *findRecordDeclNamed( const char *name ); // recursive
// void addDecl( chillAST_VarDecl *vd); // recursive, adds to first symbol table it can find
// TODO decide how to hide some data
chillAST_node *parent;
bool isFromSourceFile; // false = #included
char *filename; // file this node is from
void segfault() { debug_fprintf(stderr, "segfaulting on purpose\n"); int *i=0; int j = i[0]; }; // seg fault
int getNumChildren() { return children.size(); };
vector<chillAST_node*> children;
vector<chillAST_node*> getChildren() { return children; } ; // not usually useful
void setChildren( vector<chillAST_node*>&c ) { children = c; } ; // does not set parent. probably should
chillAST_node *getChild( int which) { return children[which]; };
void setChild( int which, chillAST_node *n ) { children[which] = n; children[which]->parent = this; } ;
char *metacomment; // for compiler internals, formerly a comment
void setMetaComment( char *c ) { metacomment = strdup(c); };
vector<chillAST_Preprocessing*> preprocessinginfo;
virtual void addChild( chillAST_node* c) {
//if (c->isFunctionDecl()) debug_fprintf(stderr, "addchild FunctionDecl\n");
c->parent = this;
// check to see if it's already there
for (int i=0; i<children.size(); i++) {
if (c == children[i]) {
//debug_fprintf(stderr, "addchild ALREADY THERE\n");
return; // already there
}
}
children.push_back(c);
} ; // not usually useful
virtual void insertChild(int i, chillAST_node* node) {
//debug_fprintf(stderr, "%s inserting child of type %s at location %d\n", getTypeString(), node->getTypeString(), i);
node->parent = this;
children.insert( children.begin()+i, node );
};
virtual void removeChild(int i) {
children.erase( children.begin()+i );
};
int findChild( chillAST_node *c ) {
for (int i=0; i<children.size(); i++) {
if (children[i] == c) return i;
}
return -1;
}
virtual void replaceChild( chillAST_node *old, chillAST_node *newchild ) {
debug_fprintf(stderr,"(%s) forgot to implement replaceChild() ... using generic\n" ,Chill_AST_Node_Names[asttype]);
debug_fprintf(stderr, "%d children\n", children.size());
for (int i=0; i<children.size(); i++) {
if (children[i] == old) {
children[i] = newchild;
newchild->setParent( this );
return;
}
}
debug_fprintf(stderr, "%s %p generic replaceChild called with oldchild that was not a child\n",
getTypeString(), this) ;
debug_fprintf(stderr, "printing\n");
print(); debug_fprintf(stderr, "\nchild: ");
if (!old) debug_fprintf(stderr, "oldchild NULL!\n");
old->print(); debug_fprintf(stderr, "\nnew: ");
newchild->print(); debug_fprintf(stderr, "\n");
segfault(); // make easier for gdb
};
virtual void loseLoopWithLoopVar( char *var ) {
// walk tree. If a loop has this loop variable, replace the loop with the loop body,
// removing the loop. The loop will be spread across a bunch of cores that will each
// calculate their own loop variable.
// things that can not have loops as substatements can have a null version of this method
// things that have more complicated sets of "children" will have specialized versions
// this is the generic version of the method. It just recurses among its children.
// ForStmt is the only one that can actually remove itself. When it does, it will
// potentially change the children vector, which is not the simple array it might appear.
// so you have to make a copy of the vector to traverse
vector<chillAST_node*> dupe = children; // simple enough?
//debug_fprintf(stderr, "node XXX has %d children\n", dupe.size());
//debug_fprintf(stderr, "generic node %s has %d children\n", getTypeString(), dupe.size());
for (int i=0; i<dupe.size(); i++) { // recurse on all children
dupe[i]->loseLoopWithLoopVar( var );
}
}
virtual int evalAsInt() {
debug_fprintf(stderr,"(%s) can't be evaluated as an integer??\n", Chill_AST_Node_Names[asttype]);
print(); debug_fprintf(stderr, "\n");
segfault();
}
virtual const char* getUnderlyingType() {
debug_fprintf(stderr,"(%s) forgot to implement getUnderlyingType()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
debug_fprintf(stderr, "\n\n");
segfault();
};
virtual chillAST_VarDecl* getUnderlyingVarDecl() {
debug_fprintf(stderr,"(%s) forgot to implement getUnderlyingVarDecl()\n", Chill_AST_Node_Names[asttype]);
dump();
print();
debug_fprintf(stderr, "\n\n");
segfault();
};
virtual chillAST_node *findref(){// find the SINGLE constant or data reference at this node or below
debug_fprintf(stderr,"(%s) forgot to implement findref()\n" ,Chill_AST_Node_Names[asttype]);
dump();
print();
debug_fprintf(stderr, "\n\n");
segfault();
};
virtual void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {
debug_fprintf(stderr,"(%s) forgot to implement gatherArrayRefs()\n" ,Chill_AST_Node_Names[asttype]);
dump();
print();
debug_fprintf(stderr, "\n\n");
};
// TODO we MIGHT want the VarDecl // NOTHING IMPLEMENTS THIS? ???
virtual void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) {
debug_fprintf(stderr,"(%s) forgot to implement gatherScalarRefs()\n" ,Chill_AST_Node_Names[asttype]);
dump();
print();
debug_fprintf(stderr, "\n\n");
};
virtual void gatherLoopIndeces( std::vector<chillAST_VarDecl*> &indeces ) { // recursive walk parent links, looking for loops, and grabbing the declRefExpr in the loop init and cond.
// you can quit when you get to certain nodes
//debug_fprintf(stderr, "%s::gatherLoopIndeces()\n", getTypeString());
if (isSourceFile() || isFunctionDecl() ) return; // end of the line
// just for debugging
//if (parent) {
// debug_fprintf(stderr, "%s has parent of type %s\n", getTypeString(), parent->getTypeString());
//}
//else debug_fprintf(stderr, "this %s %p has no parent???\n", getTypeString(), this);
if (!parent) return; // should not happen, but be careful
// for most nodes, this just recurses upwards
//debug_fprintf(stderr, "%s::gatherLoopIndeces() %p recursing up\n", this);
parent->gatherLoopIndeces( indeces );
}
chillAST_ForStmt* findContainingLoop() { // recursive walk parent links, looking for loops
//debug_fprintf(stderr, "%s::findContainingLoop() ", getTypeString());
//if (parent) debug_fprintf(stderr, "parents is a %s\n", parent->getTypeString());
//else debug_fprintf(stderr, "no parent\n");
// do not check SELF type, as we may want to find the loop containing a loop
if (!parent) return NULL;
if (parent->isForStmt()) return (chillAST_ForStmt*)parent;
return parent->findContainingLoop(); // recurse upwards
}
chillAST_node* findContainingNonLoop() { // recursive walk parent links, avoiding loops
debug_fprintf(stderr, "%s::findContainingNonLoop() ", getTypeString());
//if (parent) debug_fprintf(stderr, "parent is a %s\n", parent->getTypeString());
//else debug_fprintf(stderr, "no parent\n");
// do not check SELF type, as we may want to find the loop containing a loop
if (!parent) return NULL;
if (parent->isCompoundStmt() && parent->getParent()->isForStmt()) return parent->getParent()->findContainingNonLoop(); // keep recursing
if (parent->isForStmt()) return parent->findContainingNonLoop(); // keep recursing
return (chillAST_node*)parent; // return non-loop
}
// TODO gather loop init and cond (and if cond) like gatherloopindeces
virtual void gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ){ // both scalar and arrays
debug_fprintf(stderr,"(%s) forgot to implement gatherDeclRefExpr()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {
debug_fprintf(stderr,"(%s) forgot to implement gatherVarUsage()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherVarLHSUsage( vector<chillAST_VarDecl*> &decls ) {
debug_fprintf(stderr,"(%s) forgot to implement gatherVarLHSUsage()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherVarDecls( vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
debug_fprintf(stderr,"(%s) forgot to implement gatherVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherVarDeclsMore( vector<chillAST_VarDecl*> &decls ) { // even if the decl itself is not in the ast.
debug_fprintf(stderr,"(%s) forgot to implement gatherVarDeclsMore()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
debug_fprintf(stderr,"(%s) forgot to implement gatherScalarVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual void gatherArrayVarDecls( vector<chillAST_VarDecl*> &decls ) { // ACTUAL Declaration
debug_fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual chillAST_VarDecl *findArrayDecl( const char *name ) { // scoping TODO
if (!hasSymbolTable()) return parent->findArrayDecl( name ); // most things
else
debug_fprintf(stderr,"(%s) forgot to implement gatherArrayVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
}
virtual void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {
debug_fprintf(stderr,"(%s) forgot to implement replaceVarDecls()\n" ,Chill_AST_Node_Names[asttype]);
};
virtual bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ) {
// this just looks for ForStmts with preferred index metacomment attached
debug_fprintf(stderr,"(%s) forgot to implement findLoopIndexesToReplace()\n" ,Chill_AST_Node_Names[asttype]);
return false;
}
virtual chillAST_node* constantFold() { // hacky. TODO. make nice
debug_fprintf(stderr,"(%s) forgot to implement constantFold()\n" ,Chill_AST_Node_Names[asttype]);
exit(-1); ;
};
virtual chillAST_node* clone() { // makes a deep COPY (?)
debug_fprintf(stderr,"(%s) forgot to implement clone()\n" ,Chill_AST_Node_Names[asttype]);
exit(-1); ;
};
virtual void dump( int indent=0, FILE *fp = stderr ) {
fflush(fp);
fprintf(fp,"(%s) forgot to implement dump()\n" ,Chill_AST_Node_Names[asttype]); };// print ast
virtual void print( int indent=0, FILE *fp = stderr ) {
fflush(fp);
//debug_fprintf(stderr, "generic chillAST_node::print() called!\n");
//debug_fprintf(stderr, "asttype is %d\n", asttype);
fprintf(fp, "\n");
chillindent(indent, fp);
fprintf(fp,"(%s) forgot to implement print()\n" ,Chill_AST_Node_Names[asttype]);
};// print CODE
virtual void printName( int indent=0, FILE *fp = stderr ) {
fflush(fp);
//debug_fprintf(stderr, "generic chillAST_node::printName() called!\n");
//debug_fprintf(stderr, "asttype is %d\n", asttype);
fprintf(fp, "\n");
chillindent(indent, fp);
fprintf(fp,"(%s) forgot to implement printName()\n" ,Chill_AST_Node_Names[asttype]);
};// print CODE
virtual char *stringRep(int indent=0 ) { // the ast's print version
fflush(stdout);
// chillindent(indent, fp); TODO
debug_fprintf(stderr,"(%s) forgot to implement stringRep()\n" ,Chill_AST_Node_Names[asttype]);
segfault();
}
virtual void printonly( int indent=0, FILE *fp = stderr ) { print( indent, fp); };
//virtual void printString( std::string &s ) {
// debug_fprintf(stderr,"(%s) forgot to implement printString()\n" ,Chill_AST_Node_Names[asttype]);
//}
virtual void get_top_level_loops( std::vector<chillAST_ForStmt *> &loops) {
int n = children.size();
//debug_fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n);
for (int i=0; i<n; i++) {
//debug_fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
if (children[i]->isForStmt()) {
loops.push_back( ((chillAST_ForStmt *)(children[i])) );
}
}
//debug_fprintf(stderr, "found %d top level loops\n", loops.size());
}
virtual void repairParentChild() { // for nodes where all subnodes are children
int n = children.size();
for (int i=0; i<n; i++) {
if (children[i]->parent != this) {
debug_fprintf(stderr, "fixing child %s that didn't know its parent\n", children[i]->getTypeString());
children[i]->parent = this;
}
}
}
virtual void get_deep_loops( std::vector<chillAST_ForStmt *> &loops) { // this is probably broken - returns ALL loops under it
int n = children.size();
//debug_fprintf(stderr, "get_deep_loops of a %s with %d children\n", getTypeString(), n);
for (int i=0; i<n; i++) {
//debug_fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
children[i]->get_deep_loops( loops );
}
//debug_fprintf(stderr, "found %d deep loops\n", loops.size());
}
// generic for chillAST_node with children
virtual void find_deepest_loops( std::vector<chillAST_ForStmt *> &loops) { // returns DEEPEST nesting of loops
std::vector<chillAST_ForStmt *>deepest; // deepest below here
int n = children.size();
//debug_fprintf(stderr, "find_deepest_loops of a %s with %d children\n", getTypeString(), n);
for (int i=0; i<n; i++) {
std::vector<chillAST_ForStmt *> subloops; // loops below here among a child of mine
//debug_fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString());
children[i]->find_deepest_loops( subloops );
if (subloops.size() > deepest.size()) {
deepest = subloops;
}
}
// append deepest we see at this level to loops
for ( int i=0; i<deepest.size(); i++) {
loops.push_back( deepest[i] );
}
//debug_fprintf(stderr, "found %d deep loops\n", loops.size());
}
const char *getTypeString() { return Chill_AST_Node_Names[asttype]; } ;
int getType() { return asttype; };
void setParent( chillAST_node *p) { parent = p; } ;
chillAST_node *getParent() { return parent; } ;
chillAST_SourceFile *getSourceFile() {
if (isSourceFile()) return ((chillAST_SourceFile *)this);
if (parent != NULL) return parent->getSourceFile();
debug_fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", this, this->getTypeString());
this->print(); printf("\n\n"); fflush(stdout);
exit(-1);
}
virtual chillAST_node *findDatatype( char *t ) {
//debug_fprintf(stderr, "%s looking for datatype %s\n", getTypeString(), t);
if (parent != NULL) return parent->findDatatype(t); // most nodes do this
return NULL;
}
virtual chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ) {
if (!parent) {
debug_fprintf(stderr, "%s with no parent addVariableToSymbolTable()\n", getTypeString());
exit(-1);
}
//debug_fprintf(stderr, "%s::addVariableToSymbolTable() (default) headed up\n", getTypeString());
return parent->addVariableToSymbolTable( vd ); // default, defer to parent
}
virtual void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
parent->addTypedefToTypedefTable( tdd ); // default, defer to parent
}
void walk_parents() {
debug_fprintf(stderr, "wp: (%s) ", getTypeString());
print(); printf("\n"); fflush(stdout);
if (isSourceFile()) { debug_fprintf(stderr, "(top sourcefile)\n\n"); return;}
if (parent) parent->walk_parents();
else debug_fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString());
return;
}
virtual chillAST_node *getEnclosingStatement( int level = 0 );
virtual chillAST_VarDecl *multibase() {
debug_fprintf(stderr,"(%s) forgot to implement multibase()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
virtual chillAST_node *multibase2() {
debug_fprintf(stderr,"(%s) forgot to implement multibase2()\n", Chill_AST_Node_Names[asttype]);
exit(-1);
}
virtual void gatherStatements( std::vector<chillAST_node*> &statements ) {
debug_fprintf(stderr,"(%s) forgot to implement gatherStatements()\n" ,Chill_AST_Node_Names[asttype]);
dump();fflush(stdout);
print();
debug_fprintf(stderr, "\n\n");
}
virtual bool isSameAs( chillAST_node *other ){ // for tree comparison
debug_fprintf(stderr,"(%s) forgot to implement isSameAs()\n" ,Chill_AST_Node_Names[asttype]);
dump(); fflush(stdout);
print();
debug_fprintf(stderr, "\n\n"); }
void printPreprocBEFORE( int indent, FILE *fp );
void printPreprocAFTER( int indent, FILE *fp );
};
class chillAST_NULL: public chillAST_node { // NOOP?
public:
chillAST_NULL(chillAST_node *p = NULL) { parent = p; asttype = CHILLAST_NODETYPE_NULL; };
void print( int indent=0, FILE *fp = stderr ) {
chillindent( indent, fp );
fprintf(fp, "/* (NULL statement); */ ");
fflush(fp);
}
void dump( int indent=0, FILE *fp = stderr ) {
chillindent( indent, fp );
fprintf(fp, "(NULL statement) "); fflush(fp);
}
};
class chillAST_Preprocessing: public chillAST_node {
public:
// variables that are special for this type of node
CHILL_PREPROCESSING_POSITION position;
CHILL_PREPROCESSING_TYPE pptype;
char *blurb;
// constructors
chillAST_Preprocessing(); // not sure what this is good for
chillAST_Preprocessing( CHILL_PREPROCESSING_POSITION pos, CHILL_PREPROCESSING_TYPE t, char *text );
// other methods particular to this type of node
// required methods that I can't seem to get to inherit
void print( int indent=0, FILE *fp = stderr ); // print CODE in chill_ast.cc
//void dump( int indent=0, FILE *fp = stderr ); // print ast in chill_ast.cc
};
//typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.
class chillAST_TypedefDecl: public chillAST_node {
private:
bool isStruct;
bool isUnion;
char *structname; // get rid of this?
public:
char *newtype; // the new type name ??
char *underlyingtype; // float, int, "struct bubba" ?
char *arraypart; // string like "[1234][56]" ??
chillAST_RecordDecl *rd; // if it's a struct, point to the recorddecl ??
// TODO what if "typedef int[10] tenints; " ??
void setStructInfo( chillAST_RecordDecl *arrdee ) { rd = arrdee; };
chillAST_RecordDecl * getStructDef();
bool isAStruct() { return isStruct; };
bool isAUnion() { return isUnion; };
void setStruct(bool tf) { isStruct = tf; debug_fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
void setUnion( bool tf) { isUnion = tf; };
void setStructName( const char *newname) { structname = strdup(newname); };
char *getStructName( ) { return structname; };
bool nameis( const char *n ) { return !strcmp(n, structname); };
// special for struct/unions rethink TODO
vector<chillAST_VarDecl *> subparts;
chillAST_VarDecl *findSubpart( const char *name );
//TODO hide data, set/get type and alias
chillAST_TypedefDecl();
chillAST_TypedefDecl(char *t, char *nt, chillAST_node *p);
chillAST_TypedefDecl(char *t, char *nt, char *a, chillAST_node *par);
const char* getUnderlyingType() { debug_fprintf(stderr, "TypedefDecl getUnderLyingType()\n"); return underlyingtype; };
//virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; }; // ??
void dump( int indent=0, FILE *fp = stderr ) {
fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); };
void print( int indent=0, FILE *fp = stderr ) ;
//void printString( std::string &s );
};
class chillAST_VarDecl: public chillAST_node {
public:
char *vartype; // should probably be an enum, except it's used for unnamed structs too
chillAST_RecordDecl *vardef;// the thing that says what the struct looks like
chillAST_TypedefDecl *typedefinition; // NULL for float, int, etc.
chillAST_RecordDecl * getStructDef(); // TODO make vardef private?
//bool insideAStruct; // this variable is itself part of a struct
char *underlyingtype;
char *varname;
char *arraypart; // [ 12 ] [ 34 ] if that is how it was defined
char *arraypointerpart;
char *arraysetpart;
void splitarraypart();
int numdimensions;
int *arraysizes; // TODO
bool knownArraySizes; // if this float *a or float a[128] ? true means we know ALL dimensions
int cudamallocsize; // usually specified in lua/python transformation file
bool isRestrict; // C++ __restrict__
bool isShared; // CUDA __shared__
bool isDevice; // CUDA __device__
bool isStruct;
int isAParameter;
bool byreference;
void setByReference( bool tf ) { byreference = tf; debug_fprintf(stderr, "byref %d\n", tf); };
bool isABuiltin; // if variable is builtin, we don't need to declare it
void *uniquePtr; // DO NOT REFERENCE THROUGH THIS! just used to differentiate declarations
bool isArray() { return (numdimensions != 0); };
bool isAStruct() { return (isStruct || (typedefinition && typedefinition->isAStruct())); }
void setStruct( bool b ) {isStruct = b;/*debug_fprintf(stderr,"vardecl %s IS A STRUCT\n",varname);*/ };
bool isPointer() { return isArray() && !knownArraySizes; } //
bool knowAllDimensions() { return knownArraySizes; } ;
chillAST_node *init;
void setInit( chillAST_node *i ) { init = i; i->setParent(this); };
bool hasInit() { return init != NULL; };
chillAST_node *getInit() { return init; };
chillAST_VarDecl();
chillAST_VarDecl( const char *t, const char *n, const char *a, chillAST_node *p);
chillAST_VarDecl( const char *t, const char *n, const char *a, void *ptr, chillAST_node *p);
chillAST_VarDecl( chillAST_TypedefDecl *tdd, const char *n, const char *arraypart, chillAST_node *par);
chillAST_VarDecl( chillAST_RecordDecl *astruct, const char *n, const char *arraypart, chillAST_node *par);
void dump( int indent=0, FILE *fp = stderr );
void print( int indent=0, FILE *fp = stderr );
void printName( int indent=0, FILE *fp = stderr );
bool isParmVarDecl() { return( isAParameter == 1 ); };
bool isBuiltin() { return( isABuiltin == 1 ); }; // designate variable as a builtin
void setLocation( void *ptr ) { uniquePtr = ptr; } ;
void gatherVarDecls ( vector<chillAST_VarDecl*> &decls );
void gatherVarDeclsMore ( vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
void gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls );
void gatherArrayVarDecls ( vector<chillAST_VarDecl*> &decls );
void gatherVarUsage( vector<chillAST_VarDecl*> &decls ) {}; // does nothing
void gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs ) {}; // does nothing
void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) {};
bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
const char* getUnderlyingType() { /* debug_fprintf(stderr, "VarDecl getUnderLyingType()\n"); */return underlyingtype; };
virtual chillAST_VarDecl* getUnderlyingVarDecl() { return this; };
chillAST_node* constantFold();
chillAST_node* clone();
};
class chillAST_DeclRefExpr: public chillAST_node {
public:
// variables that are special for this type of node
char *declarationType;
char *declarationName;
chillAST_node *decl; // the declaration of this variable or function ... uhoh
//char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions
// constructors
chillAST_DeclRefExpr();
chillAST_DeclRefExpr( const char *variablename, chillAST_node *p);
chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *p);
chillAST_DeclRefExpr( const char *vartype, const char *variablename, chillAST_node *dec, chillAST_node *p);
chillAST_DeclRefExpr( chillAST_VarDecl *vd, chillAST_node *p=NULL);
chillAST_DeclRefExpr( chillAST_FunctionDecl *fd, chillAST_node *p=NULL);
// other methods particular to this type of node
bool operator!=( chillAST_DeclRefExpr &other ) { return decl != other.decl ; };
bool operator==( chillAST_DeclRefExpr &other ) { return decl == other.decl ; }; // EXACT SAME VARECL BY ADDRESS
chillAST_node *getDecl() { return decl; };
chillAST_VarDecl *getVarDecl() {
if (!decl) return NULL; // should never happen
if (decl->isVarDecl()) return (chillAST_VarDecl *)decl;
return NULL;
};
chillAST_FunctionDecl *getFunctionDecl() {
if (!decl) return NULL; // should never happen
if (decl->isFunctionDecl()) return (chillAST_FunctionDecl *)decl;
return NULL;
};
// required methods that I can't seem to get to inherit
void print( int indent=0, FILE *fp = stderr ); // print CODE
void dump( int indent=0, FILE *fp = stderr ); // print ast
char *stringRep(int indent=0 );
chillAST_node* constantFold();
chillAST_node* clone();
void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ) {}; // do nothing
void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento );
// this is the AST node where these 2 differ
void gatherVarDecls ( vector<chillAST_VarDecl*> &decls ) {}; // does nothing, to get the cvardecl using this method, the actual vardecl must be in the AST
void gatherVarDeclsMore ( vector<chillAST_VarDecl*> &decls ); // returns the decl this declrefexpr references, even if the decl is not in the AST
void gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls );
void gatherArrayVarDecls ( vector<chillAST_VarDecl*> &decls );
void gatherVarUsage( vector<chillAST_VarDecl*> &decls );
void gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs );
void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false ){ return false; }; // no loops under here
chillAST_node *findref(){return this;}// find the SINGLE constant or data reference at this node or below
const char* getUnderlyingType() {debug_fprintf(stderr, "DeclRefExpr getUnderLyingType()\n"); return decl->getUnderlyingType();};
virtual chillAST_VarDecl* getUnderlyingVarDecl() { return decl->getUnderlyingVarDecl(); } // functions?? TODO
chillAST_VarDecl* multibase();
chillAST_node *multibase2() { return (chillAST_node *)multibase(); }
};
class chillAST_CompoundStmt: public chillAST_node {
public:
// variables that are special for this type of node
chillAST_SymbolTable *symbol_table; // symbols defined inside this compound statement
chillAST_TypedefTable *typedef_table;
bool hasSymbolTable() { return true; } ;
bool hasTypeDefTable() { return true; } ;
chillAST_node *findDatatype( char *t ) {
debug_fprintf(stderr, "chillAST_CompoundStmt::findDatatype( %s )\n", t);
if (typedef_table) {
for (int i=0; i< typedef_table->size(); i++) {
chillAST_TypedefDecl *tdd = (*typedef_table)[i];
if (tdd->nameis( t )) return tdd;
}
}
if (parent) return parent->findDatatype(t);
return NULL; // should not happen
}
chillAST_SymbolTable *getSymbolTable() { return symbol_table; }
chillAST_SymbolTable* addVariableToSymbolTable( chillAST_VarDecl *vd ) { // chillAST_CompoundStmt method
//debug_fprintf(stderr, "\nchillAST_CompoundStmt addVariableToSymbolTable( %s )\n", vd->varname);
symbol_table = addSymbolToTable( symbol_table, vd );
//printSymbolTable( symbol_table );
return symbol_table;
}
void addTypedefToTypedefTable( chillAST_TypedefDecl *tdd ) {
typedef_table = addTypedefToTable( typedef_table, tdd );
}
// constructors
chillAST_CompoundStmt(); // never has any args ???
// other methods particular to this type of node
// required methods
void replaceChild( chillAST_node *old, chillAST_node *newchild );
void dump( int indent=0, FILE *fp = stderr );
void print( int indent=0, FILE *fp = stderr );
chillAST_node* constantFold();
chillAST_node* clone();
void gatherVarDecls ( vector<chillAST_VarDecl*> &decls );
void gatherVarDeclsMore ( vector<chillAST_VarDecl*> &decls ) { gatherVarDecls(decls); } ;
void gatherScalarVarDecls( vector<chillAST_VarDecl*> &decls );
void gatherArrayVarDecls ( vector<chillAST_VarDecl*> &decls );
void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento );
void gatherScalarRefs( std::vector<chillAST_DeclRefExpr*> &refs, bool writtento ) ;
void gatherVarUsage( vector<chillAST_VarDecl*> &decls );
void gatherDeclRefExprs( vector<chillAST_DeclRefExpr *>&refs );
void replaceVarDecls( chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl);
bool findLoopIndexesToReplace( chillAST_SymbolTable *symtab, bool forcesync=false );
void loseLoopWithLoopVar( char *var ); // special case this for not for debugging
void gatherStatements( std::vector<chillAST_node*> &statements );
};
class chillAST_RecordDecl: public chillAST_node { // declaration of the shape of a struct or union
private:
char *name; // could be NULL? for unnamed structs?
char *originalname;
bool isStruct;
bool isUnion;
vector<chillAST_VarDecl *> subparts;
public:
chillAST_RecordDecl();
chillAST_RecordDecl( const char *nam, chillAST_node *p );
chillAST_RecordDecl( const char *nam, const char *orig, chillAST_node *p );
void setName( const char *newname) { name = strdup(newname); };
char *getName( ) { return name; };
bool isAUnion() { return isUnion; };
bool isAStruct() { return isStruct; };
bool isUnnamed;
void setUnnamed( bool b ) { isUnnamed = b; };
void setStruct(bool tf) { isStruct = tf; };
//debug_fprintf(stderr, "%s isStruct %d\n", structname, isStruct); };
void setUnion( bool tf) { isUnion = tf; };
chillAST_SymbolTable *addVariableToSymbolTable( chillAST_VarDecl *vd ); // RecordDecl does NOTHING
int numSubparts() { return subparts.size(); };
void addSubpart( chillAST_VarDecl *s ) { subparts.push_back(s); };
chillAST_VarDecl *findSubpart( const char *name );
chillAST_VarDecl *findSubpartByType( const char *typ );
void dump( int indent=0, FILE *fp = stderr );
void print( int indent=0, FILE *fp = stderr ) ;
void printStructure( int indent=0, FILE *fp = stderr ) ;
};