1
#ifndef ATLAS_GENPARSE_H
2
#define ATLAS_GENPARSE_H
11
{ASM_None=0, gas_x86_32, gas_x86_64, gas_sparc, gas_ppc, gas_parisc,
12
gas_mips, gas_arm, gas_s390};
13
static char *ASMNAM[NASMD] =
14
{"", "GAS_x8632", "GAS_x8664", "GAS_SPARC", "GAS_PPC", "GAS_PARISC",
15
"GAS_MIPS", "GAS_ARM", "GAS_S390"};
17
* Basic data structure for forming queues with some minimal info
19
typedef struct SIDNode ATL_sidnode_t;
20
struct SIDNode /* holds string, integer, and double */
28
#define SET_FLAG(bits_, flg_, val_) \
30
if (val_) (bits_) |= (1<<(flg_)); \
31
else (bits_) &= ~(1<<(flg_)); \
33
#define FLAG_IS_SET(field_, bit_) ( ((field_) & (1<<(bit_))) != 0 )
35
/* procedure 1 : allocates ATL_sidnode_t */
36
static ATL_sidnode_t *ATL_NewSIDNode(void)
39
sp = calloc(1, sizeof(ATL_sidnode_t));
44
/* procedure 2 : allocates ATL_sidnode_t */
45
static ATL_sidnode_t *ATL_FreeSIDNode(ATL_sidnode_t *die)
47
ATL_sidnode_t *sp=NULL;
59
static int GetL1CacheElts(char pre)
64
L1f = fopen("res/L1CacheSize", "r");
67
assert(system("make res/L1CacheSize\n") == 0);
68
L1f = fopen("res/L1CacheSize", "r");
71
assert(fscanf(L1f, "%d", &L1Size) == 1);
74
if (pre == 'c' || pre == 'd')
86
static char *DupString(char *str)
94
s = malloc(sizeof(char)*n);
102
static char *GetSingleQuoteString(char *str)
107
assert(str[0] == '\'');
108
for (i=1; str[i] && str[i] != '\''; i++);
110
sp = malloc(i*sizeof(char));
111
for (n=i,i=1; i < n; i++)
118
static int asmNames2bitfield(char *str)
120
* Takes str containing an assembly name list. The list is ended by the first
121
* white space or end of string. List items are seperated by ',', and there
122
* can be no whitespace in list.
123
* RETURNS: bitfield with bits set corresponding to assemblies, 0 on error.
127
int i, KeepOn, bits=0;
131
for (i=0; !isspace(str[i]) && str[i] != ',' && str[i] && i < 64; i++)
134
KeepOn = str[i] == ',';
137
return(0); /* no asm name > 63 in length */
138
for (i=0; i < NASMD; i++)
140
if (!strcmp(ASMNAM[i], asmname))
152
static int GetDoubleArr(char *str, int N, double *d)
154
* Reads in a list with form "%le,%le...,%le"; N-length d recieves doubles.
155
* RETURNS: the number of doubles found, or N, whichever is less
159
assert(sscanf(str, "%le", d) == 1);
162
str = strstr(str, ",");
166
assert(sscanf(str, "%le", d+i) == 1);
173
static char *GetLongerString(char *shrt, int newlen)
175
* Allocates new string of size newlen, copies shrt into it, and frees shrt.
180
sp = malloc(sizeof(char)*newlen);
187
else if (newlen >= 0)
193
static char *GetOneLine(FILE *fpin)
195
* RETURNS: string of one line from stream fpin, NULL if stream exhausted.
200
static char *ln, *sp;
205
ln = malloc(inc*sizeof(char));
209
if (!fgets(ln, len, fpin))
212
for (i=0; ln[i]; i++); /* find end of string */
214
while (ln[i-1] != '\n') /* if last char not \n, read rest of line */
217
ln = GetLongerString(ln, len);
218
if (!fgets(ln+i, inc, fpin))
220
for (; ln[i]; i++); /* find end of string */
226
static char *GetJoinedLines(FILE *fpin)
228
* Gets lines from file fpin; if last non-whitespace char is '\', joins lines
229
* RETURNS: line from file including joining, NULL if fpin exhausted
233
static char *join=NULL;
237
sp = ln = GetOneLine(fpin);
240
j = 0; /* current length of join string */
243
for (i=0; ln[i]; i++); /* find end of string */
244
if (!i) return(NULL);
245
for (i--; isspace(ln[i]) && i > 0; i--); /* find last non-wspace char */
246
while (ln[i] == '\\')
251
join = GetLongerString(join, jlen);
253
for (k=0; k < i; k++)
258
ln = GetOneLine(fpin); /* get new line that should be joined */
259
assert(ln); /* can't end file with continue */
260
for (i=0; ln[i]; i++); /* find end of new line */
261
for (i--; isspace(ln[i]) && i > 0; i--); /* find last non-wspc char */
269
join = GetLongerString(join, jlen);
271
for (k=0; k <= i; k++)
283
static char *GetGoodGcc()
285
* Gets gcc path and name along with mandatory flags (-g/-m64/-pg,etc) by
286
* querying Make.inc setting
289
static char gcc[2048];
294
assert(system("make res/goodgcc.txt > /dev/null 2>&1") == 0);
295
fpin = fopen("res/goodgcc.txt", "r");
297
assert(fscanf(fpin, "'%[^\']", gcc) == 1);
303
static char *GetKCFlags(char pre)
305
* Gets flags being used for <pre>KCFLAGS
316
i = system("rm -f res/kcflags.txt");
317
sprintf(ln, "grep \"%cKCFLAGS = \" Make.inc | sed s/%cKCFLAGS\\ =\\ // > res/kcflags.txt", toupper(pre), toupper(pre));
318
assert(system(ln) == 0);
319
fpin = fopen("res/kcflags.txt", "r");
321
assert(fgets(ln, 4096, fpin) != NULL);
324
* Get rid of trailing and leading whitespaces
326
for (i=0; ln[i]; i++);
327
for (i--; isspace(ln[i]); i--);
329
for (i=0; isspace(ln[i]); i++);
330
return(DupString(ln+i));
332
#endif /* end atlas_genparse.h guard */