00001 #ifndef STAT_PARSER_H
00002 #define STAT_PARSER_H
00003
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <math.h>
00007 #include <vector>
00008 #include <sstream>
00009
00017
00018
00019 #ifndef TRUE
00020 #define TRUE 1
00021 #endif
00022 #ifndef FALSE
00023 #define FALSE 0
00024 #endif
00025 #ifndef RETURN_OK
00026 #define RETURN_OK 0
00027 #endif
00028 #ifndef RETURN_ERROR
00029 #define RETURN_ERROR -1
00030 #endif
00031
00032
00033
00034 #define STAT_COORD_A "a"
00035 #define STAT_COORD_B "b"
00036 #define STAT_COORD_X "x"
00037 #define STAT_COORD_Y "y"
00038 #define STAT_COORD_Z "z"
00039 #define STAT_XMIN "xmin"
00040 #define STAT_XMAX "xmax"
00041 #define STAT_YMIN "ymin"
00042 #define STAT_YMAX "ymax"
00043 #define STAT_ZMIN "zmin"
00044 #define STAT_ZMAX "zmax"
00045 #define STAT_NX "nx"
00046 #define STAT_NY "ny"
00047 #define STAT_NZ "nz"
00048 #define STAT_NXF "nxfine"
00049 #define STAT_NYF "nyfine"
00050 #define STAT_NZF "nzfine"
00051
00052
00053 #define STAT_RAW 0
00054 #define STAT_AVERAGED 1
00055
00056 #define STAT_PRIMITIVE 0
00057 #define STAT_DERIVED 1
00058
00059
00060 void staterror (char const *msg);
00061 void staterror (char const * msg, int l, int c);
00062
00063 void stat_parser_set_debug(void);
00064 void stat_scanner_set_debug(void);
00065
00066 typedef double (*func_t1) (double);
00067 typedef double (*func_t2) (double, double);
00068
00069 typedef struct {
00070 int na;
00071 int ave;
00072 } stat_thread;
00073
00074 typedef struct {
00075 int na, nb;
00076 int avea, aveb;
00077 } stat_surface;
00078
00079 typedef struct {
00080 int dir, na, nb;
00081 double amin, amax, bmin, bmax, value;
00082 } stat_plane;
00083
00084 typedef union {
00085 stat_thread thread;
00086 stat_surface surface;
00087 stat_plane plane;
00088 double bndry[6];
00089 } stat_uop;
00090
00091 template<class data_type>
00092 class _symrec {
00093 public:
00094 int type;
00095 int src;
00096 char * name;
00097 union {
00098 int iptr;
00099 int ivalue;
00100 double dvalue;
00101 void* ptr;
00102 } vdata;
00103 int npoints;
00104 data_type* pdata;
00105 class _symrec<data_type> * prev, * next, *ref;
00106 };
00107
00108 #define YYPARSE_TEMPLATE_DEF template<class point_type, class data_type, int dim>
00109 #define YYPARSE_PARAM_TYPE StatParser<point_type,data_type,dim>
00110
00111 YYPARSE_TEMPLATE_DEF
00112 class StatParser {
00113
00114 private:
00115 int _exec;
00116
00117 public:
00118 typedef _symrec<data_type> symrec;
00119 typedef std::vector<symrec*> symvec;
00120
00121 protected:
00122
00123
00124 typedef struct {
00125 int type;
00126 stat_uop options;
00127 point_type * coords;
00128 symvec sym_coords;
00129 std::stringstream* out;
00130 } probe;
00131
00132 typedef std::vector<probe*> provec;
00133
00134
00135 typedef struct {
00136 int step;
00137 symvec sym_table;
00138 provec probe_table;
00139 } group;
00140
00141 typedef std::vector<group*> grpvec;
00142
00143
00144 symvec sym_table;
00145
00146 grpvec group_table;
00147
00148 symvec sym_stack;
00149
00150 void dump_token(symrec* ptr, symrec* ptr_org);
00151 void dump_sym(symvec &list);
00152 void dump_probe(provec &list);
00153 const char* token(int tok);
00154
00155 int delprobe(probe* ptr);
00156 int delgroup(group* ptr);
00157
00158 int clearsym(symvec &table);
00159 int cleargroup(grpvec &table);
00160 int clearprobe(provec &list);
00161
00162 int evalstack(symvec& stack, point_type& xc);
00163 symrec* clonestack(symvec& stack);
00164 void unlinksym(symrec* ptr);
00165 int buildcoords(probe * ptr);
00166 int clearcoords(probe * ptr);
00167
00168 symrec* allocsym(char const * sym_name);
00169 int freesym(symrec* ptr);
00170
00171 int vectorize(symrec* ptr, int Npoints);
00172 int unvectorize(symrec* ptr);
00173
00174 public:
00175
00176 StatParser () ;
00177 ~StatParser ();
00178
00179
00180 void dump_all();
00181
00182
00183 symrec * putsym(int sym_type, char const * sym_name);
00184
00185 int parse(char const * fname);
00186
00187 int parser_exec() { return _exec; };
00188 void parser_activate_exec() { _exec = 1; };
00189 void parser_deactivate_exec() { _exec = 0; };
00190
00191 symrec * getsym(char const * sym_name);
00192 int addgroup(void);
00193 int group_step(int);
00194 int group_add_probe(int probe_type, stat_uop & options);
00195 int group_add_keys(void);
00196 int searchtoken(int tok);
00197 int searchtoken(char const * psz);
00198 int counttoken(int tok);
00199
00200
00201 symrec * addsym(int sym_type, char const * sym_name = NULL);
00202 };
00203
00204
00205 #define YYPARSE_PARAM parg
00206
00207
00208 #define YYLEX_PARAM parg
00209
00210 #include "StatParser_parser.c"
00211 #include "StatParser_scanner.c"
00212 #include "StatParser.ipp"
00213
00214 #endif