00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "ekapi_ia64.h"
00043 #include "ekapi_util.h"
00044
00045
00046
00047
00048
00049
00050 int EKAPI_Op2Opndsgrp(void *pknobs, int index)
00051 {
00052 char *str_knob, *str;
00053 int ID,grpid = -1;
00054
00055 str_knob = KAPI_attribute4index( pknobs, "opcode", index);
00056 FmtAssert(str_knob, ("KNOBS Files opcode's operands group no %d line!", index));
00057
00058
00059
00060 ID = atoi(strtok( str_knob, "," ));
00061 assert(ID == index);
00062
00063 strtok( NULL, "," );
00064 strtok( NULL, "," );
00065 strtok( NULL, "," );
00066
00067
00068 str = StrTrim(strtok( NULL, "," ));
00069 grpid = atoi(str);
00070
00071 free(str_knob);
00072 Is_True(grpid < KAPI_count4attribute(pknobs, "opndsgrp"),
00073 ("operands group id %d beyond bundary", grpid)
00074 );
00075 return grpid;
00076 }
00077
00078
00079
00080 int EKAPI_OpndGrpCount(void *pknobs)
00081 {
00082 return KAPI_count4attribute(pknobs, "opndsgrp");
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 void EKAPI_GetOperandInfo4Grp(void *pknobs, int grpindex,EKAPI_OPNDGRP_INFO *info)
00094 {
00095 char *str_knob, *str;
00096 char str_source[20], str_use[20], str_result[20];
00097 int ID,iknob, max_src, max_dest;
00098 int num_source = 0, num_result=0;
00099 BOOL src_true =0;
00100
00101 str_knob = KAPI_attribute4index(pknobs, "opndsgrp", grpindex);
00102 str = StrTrim(strtok(str_knob, ","));
00103 ID = atoi(str);
00104 Is_True(ID == grpindex,
00105 ("KNOBS FILE ERROR:opndsgrp line %d is consist with ID %d", grpindex, ID)
00106 );
00107
00108 max_src = EKAPI_GetSrcOpndsMax(pknobs);
00109 max_dest = EKAPI_GetDestOpndsMax(pknobs);
00110
00111
00112 while (str = StrTrim(strtok(NULL, ",")))
00113 {
00114 strcpy(str_use, "");
00115 strcpy(str_source, "OT_");
00116 strcpy(str_result, "OT_");
00117 switch (str[0])
00118 {
00119 case '?':
00120
00121
00122
00123
00124 case '-':
00125
00126 iknob = strlen(str) - strlen(strstr(str, "/")) + 1;
00127 Is_True(iknob < strlen(str),
00128 ("KNOBS FILE syntax Error:find not '/' in source operands %s",
00129 str)
00130 );
00131 strcat(str_use, str+iknob);
00132 str[iknob-1] = '\0';
00133 strcat(str_source, str+1);
00134 num_source++;
00135 src_true = 1;
00136 break;
00137
00138 case '+':
00139 strcat(str_result, str+1);
00140 num_result++;
00141 src_true = 0;
00142 break;
00143 default: free(str_knob);
00144 FmtAssert(0,
00145 ("KNOBS FILE syntax Error: Unknown Charecter of opndsgrp in line %d", grpindex)
00146 );
00147
00148
00149 }
00150 if (src_true) {
00151 ID = KAPI_EnumIndex(pknobs, "ot_t", str_source);
00152 Is_True(ID>=0,
00153 ("KNOBS FILE syntax Error:Unknown operand type id %d", ID)
00154 );
00155
00156
00157 FmtAssert(num_source <= max_src,
00158 ("source operands number %d violate MAX_OPND_SRC %d of knobfiles", num_source, max_src)
00159 );
00160 info->source[num_source-1] = ID;
00161 info->opnduse[num_source-1]= KAPI_EnumIndex(pknobs, "ou_t", str_use);
00162 }
00163 else {
00164 FmtAssert(num_result <= max_dest,
00165 ("source operands number too many to violate MAX_OPND_DEST of knobfiles")
00166 );
00167 info->result[num_result-1] = KAPI_EnumIndex(pknobs, "ot_t", str_result);
00168 }
00169 }
00170 info->num_source = num_source;
00171 info->num_result = num_result;
00172 free(str_knob);
00173 }
00174
00175
00176 int EKAPI_GetSrcOpndsMax(void *pknobs)
00177 {
00178 return KAPI_GetIntegerVariable(pknobs, "MAX_OPND_SRC", -1);
00179 }
00180
00181
00182 int EKAPI_GetDestOpndsMax(void *pknobs)
00183 {
00184 return KAPI_GetIntegerVariable(pknobs, "MAX_OPND_DEST", -1);
00185 }
00186
00187
00188 int *EKAPI_Src4Opndgrp(EKAPI_OPNDGRP_INFO info)
00189 {
00190 return info.source;
00191 }
00192
00193
00194 int *EKAPI_Use4Opndgrp(EKAPI_OPNDGRP_INFO info)
00195 {
00196 return info.opnduse;
00197 }
00198
00199
00200 int EKAPI_SrcOpndCount(EKAPI_OPNDGRP_INFO info )
00201 {
00202 return info.num_source;
00203 }
00204
00205
00206 int EKAPI_ResultOpndCount(EKAPI_OPNDGRP_INFO info )
00207 {
00208 return info.num_result;
00209 }
00210
00211
00212 int *EKAPI_Result4Opndgrp(EKAPI_OPNDGRP_INFO info )
00213 {
00214 return info.result;
00215 }
00216
00217
00218 int EKAPI_OpndTypeCount(void *pknobs)
00219 {
00220 return KAPI_EnumCardinality(pknobs, "ot_t");
00221 }
00222
00223
00224 char *EKAPI_OpndTypeName(void *pknobs, int index)
00225 {
00226 return KAPI_EnumName(pknobs, index, "ot_t");
00227 }
00228
00229
00230 int EKAPI_OpndUseCount(void *pknobs)
00231 {
00232 return KAPI_EnumCardinality(pknobs, "ou_t");
00233 }
00234
00235
00236 char *EKAPI_OpndUseName(void *pknobs, int index)
00237 {
00238 return KAPI_EnumName(pknobs, index, "ou_t");
00239 }
00240
00241
00242
00243
00244
00245
00246 int EKAPI_RegClass4otid(void *pknobs, int otid)
00247 {
00248 char *str_knob,*str;
00249 int count, rcid=-1;
00250 count = EKAPI_OpndTypeCount(pknobs);
00251 Is_True(otid<count,
00252 ("KNOBS FILE ERROR:operand type id required beyond count of Operand Type ")
00253 );
00254
00255 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00256
00257 str = StrTrim(strtok(str_knob, ","));
00258 if (strcmp(str, "UNDEFINED") != 0) {
00259 rcid = EKAPI_RegClassid4name(pknobs, str);
00260 free(str_knob);
00261 Is_True(rcid>=0, ("KNOBS FILE: Unknowned string in regclass field of opndtype;"));
00262 }
00263 else {
00264 free(str_knob);
00265 rcid = -1;
00266 }
00267
00268 return rcid;
00269 }
00270
00271
00272
00273
00274
00275 int EKAPI_RegSubclass4otid(void *pknobs, int otid)
00276 {
00277 char *str_knob,*str;
00278 int count, rsubcid=-1;
00279
00280 count = EKAPI_OpndTypeCount(pknobs);
00281 Is_True(otid<count, ("operand type id required beyond count of Operand Type "));
00282
00283 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00284
00285
00286 strtok(str_knob, ",");
00287 str = StrTrim(strtok(NULL, ","));
00288
00289 if (strcmp(str, "UNDEFINED") != 0) {
00290 rsubcid = EKAPI_RegSubclassid4name(pknobs, str);
00291 free(str_knob);
00292 Is_True(rsubcid>=0, ("KNOBS FILE: Unknowned string in regsubclass field of opndtype;"));
00293 }
00294 else {
00295 free(str_knob);
00296 rsubcid = -1;
00297 }
00298 return rsubcid;
00299 }
00300
00301
00302
00303
00304
00305 int EKAPI_LitClass4otid(void *pknobs, int otid)
00306 {
00307 char *str_knob,*str;
00308 int count, lcid=-1;
00309
00310 count = EKAPI_OpndTypeCount(pknobs);
00311 Is_True(otid<count, ("operand type id required beyond count of Operand Type "));
00312
00313 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00314
00315
00316 strtok(str_knob, ",");
00317 str = strtok(NULL, ",");
00318 str = StrTrim(strtok(NULL, ","));
00319
00320 if (strcmp(str, "UNDEFINED") != 0) {
00321 lcid = EKAPI_LitClassid4name(pknobs, str);
00322 free(str_knob);
00323 Is_True(lcid>=0, ("KNOBS FILE: Unknowned string in lclass field of opndtype;"));
00324 }
00325 else {
00326 free(str_knob);
00327 lcid = -1;
00328 }
00329 return lcid;
00330 }
00331
00332
00333
00334
00335
00336 int EKAPI_EnumClass4otid(void *pknobs, int otid)
00337 {
00338 char *str_knob,*str;
00339 int count, ecid=-1;
00340
00341 count = EKAPI_OpndTypeCount(pknobs);
00342 Is_True(otid<count, ("operand type id required beyond count of Operand Type "));
00343
00344 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00345
00346
00347 strtok(str_knob, ",");
00348 strtok(NULL, ",");
00349 strtok(NULL, ",");
00350 str = StrTrim(strtok(NULL, ","));
00351
00352 if (strcmp(str, "UNDEFINED") != 0) {
00353 ecid = EKAPI_EnumClassid4name(pknobs, str);
00354 free(str_knob);
00355 Is_True(ecid>=0, ("KNOBS FILE: Unknowned string in eclass field of opndtype;"));
00356 }
00357 else {
00358 free(str_knob);
00359 ecid = -1;
00360 }
00361 return ecid;
00362 }
00363
00364
00365
00366
00367
00368 int EKAPI_Size4otid(void *pknobs, int otid)
00369 {
00370 char *str_knob,*str;
00371 int count, size=0;
00372
00373 count = EKAPI_OpndTypeCount(pknobs);
00374 Is_True(otid<count, ("operand type id required beyond count of Operand Type "));
00375
00376 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00377
00378
00379 strtok(str_knob, ",");
00380 strtok(NULL, ",");
00381 strtok(NULL, ",");
00382 strtok(NULL, ",");
00383 str = StrTrim(strtok(NULL, ","));
00384
00385 size = atoi(str);
00386 free(str_knob);
00387 return size;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 int EKAPI_Flag4otid(void *pknobs, int otid)
00402 {
00403 char *str_knob,*str=NULL;
00404 int count=0, flag=0, span;
00405
00406
00407 if ( (EKAPI_RegClass4otid(pknobs, otid)>=0) ||
00408 (EKAPI_RegSubclass4otid(pknobs, otid)>=0) ) {
00409 flag = 1;
00410 }
00411
00412
00413 count = EKAPI_OpndTypeCount(pknobs);
00414 Is_True(otid<count, ("operand type id required beyond count of Operand Type "));
00415
00416 str_knob = KAPI_GetStringVariable(pknobs, "opndtype", otid);
00417
00418
00419 strtok(str_knob, ",");
00420 strtok(NULL, ",");
00421 strtok(NULL, ",");
00422 strtok(NULL, ",");
00423 strtok(NULL, ",");
00424
00425 span = 1;
00426 while( str = StrTrim(strtok(NULL, ",")))
00427 {
00428
00429 if (strcasecmp(str,"true")==0) {
00430 flag |= 1 << span;
00431 }
00432 span++;
00433 if ( (strcasecmp(str, "false")!=0) && (strcasecmp(str, "true")!=0) ) {
00434 free(str_knob);
00435 Is_True(0, ("KNOBS FILE: UNKNOWN String in flag component of operand type"));
00436 }
00437
00438 }
00439
00440 free(str_knob);
00441 return flag;
00442 }
00443
00444
00445 int EKAPI_GetRelocatableOpnd(void *pknobs, int opid)
00446 {
00447 char op[100]="%";
00448 int index;
00449 char *name = EKAPI_OpName4id(pknobs, opid);
00450 strcat(op, name);
00451 free(name);
00452
00453 index = KAPI_ArrayIndex(pknobs, "relocatable", op);
00454
00455
00456 if (index >= 0) {
00457 return KAPI_GetIntegerVariable(pknobs, "relocatable", index);
00458 }
00459 else {
00460 return -1;
00461 }
00462 }