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
00042
00043
00044
00045
00047
00048
00049
00050
00051
00052
00053 #include <stddef.h>
00054 #include <stdlib.h>
00055 #include <stdarg.h>
00056 #include <stdio.h>
00057 #include <assert.h>
00058 #include <list>
00059 #include <vector>
00060 #include <string.h>
00061 #include "topcode.h"
00062 #include "targ_isa_properties.h"
00063 #include "gen_util.h"
00064 #include "isa_pack_gen.h"
00065
00066
00067
00068
00069
00070 #define MAX_OPNDS 6
00071 #define MAX_RESULTS 2
00072
00073 typedef enum {
00074 END = 0,
00075 OPND = 1,
00076 RESULT = OPND+MAX_OPNDS,
00077 } COMP_TYPE;
00078
00079 #define MAX_LISTING_OPERANDS (RESULT+MAX_RESULTS)
00080
00081 typedef struct isa_args_type {
00082 unsigned char name;
00083 int opnd_position;
00084 int inst_position;
00085 int width;
00086 } *ISA_ARGS_TYPE;
00087
00088 typedef struct isa_adj_type {
00089 int opnd_index;
00090 OPND_ADJ_TYPE padj;
00091 OPND_ADJ_TYPE uadj;
00092 } *ISA_ADJ_TYPE;
00093
00094
00095
00096 #define MAX_WORDS 20
00097
00098 struct isa_pack_type {
00099 const char* name;
00100 struct {
00101 std::list<ISA_ARGS_TYPE> operands;
00102 std::list<ISA_ARGS_TYPE> results;
00103 } word[MAX_WORDS];
00104 std::list<ISA_ADJ_TYPE> oadj;
00105 int max_word;
00106 int index;
00107 int adj_index;
00108 };
00109
00110
00111 struct op_assembly {
00112 isa_pack_type *desc;
00113 struct op_assembly *next;
00114 unsigned long long opcode_mask[MAX_WORDS];
00115 };
00116
00117 struct opnd_adj_type {
00118 const char *name;
00119 const char *adj;
00120 int code;
00121 };
00122
00123 static std::list<ISA_PACK_TYPE> all_packs;
00124 static std::list<OPND_ADJ_TYPE> all_oadj;
00125 static ISA_PACK_TYPE current_pack_desc;
00126 static op_assembly *op_packs[TOP_count+1];
00127 static std::list<op_assembly*> op_packs_list;
00128 static bool top_specified[TOP_count];
00129 static int inst_bits;
00130 static int inst_words;
00131 static int num_adj;
00132 static int mask_width;
00133
00134 static const char * const interface[] = {
00135 "/* ====================================================================",
00136 " * ====================================================================",
00137 " *",
00138 " * Description:",
00139 " *",
00140 " * A description of how to pack the operands of ISA instructions",
00141 " * into binary object code. The description exports the following:",
00142 " *",
00143 " * typedef ISA_PACK_INST",
00144 " * A scalar type large enough to hold an instruction.",
00145 " *",
00146 " * const INT ISA_PACK_INST_SIZE",
00147 " * The size, in bits, of an instruction.",
00148 " *",
00149 " * typedef (enum) ISA_PACK_COMP",
00150 " * An enumeration of the instruction components to be packed.",
00151 " *",
00152 " * typedef (struct) ISA_PACK_INFO",
00153 " * Describes how the operands of a particular instruction",
00154 " * are packed. The contents are private.",
00155 " *",
00156 " * const INT ISA_PACK_COMP_MAX",
00157 " * The maximum number of operands to be packed for any instruction.",
00158 " *",
00159 " * UINT64 ISA_PACK_Init_Mask(TOP topcode, INT iword)",
00160 " * Returns an initial bit mask to initialize the instruction word,",
00161 " * with index 'iword', for the instruction specified by 'topcode'",
00162 " *",
00163 " * INT ISA_PACK_Inst_Words(TOP topcode)",
00164 " * Returns the number of instruction words for the specified topcode.",
00165 " *",
00166 " * const ISA_PACK_INFO *ISA_PACK_Info(TOP topcode)",
00167 " * Returns a pointer to the first packing descriptions for",
00168 " * the instruction specified by 'topcode'. Increment",
00169 " * the returned pointer to access any additional packing",
00170 " * descriptions for the instruction. A packing description",
00171 " * with component ISA_PACK_COMP_end marks the end.",
00172 " *",
00173 " * INT ISA_PACK_INFO_Comp(const ISA_PACK_INFO *info)",
00174 " * Identifies the instruction component to be packed.",
00175 " *",
00176 " * INT ISA_PACK_INFO_OpndPos(const ISA_PACK_INFO *info)",
00177 " * The offset, in bits, to the start of the component in the",
00178 " * operand value.",
00179 " *",
00180 " * ISA_PACK_INFO_OpndPos is meaningless for ISA_PACK_COMP_end.",
00181 " *",
00182 " * INT ISA_PACK_INFO_InstPos(const ISA_PACK_INFO *info)",
00183 " * The offset, in bits, to the start of the component in the",
00184 " * instruction word.",
00185 " *",
00186 " * ISA_PACK_INFO_InstPos is meaningless for ISA_PACK_COMP_end.",
00187 " *",
00188 " * UINT64 ISA_PACK_INFO_Mask(const ISA_PACK_INFO *info)",
00189 " * A bit-mask that is as wide as the instruction field being",
00190 " * packed. The mask is normalized such that the lowest bit",
00191 " * of the mask is in bit-0.",
00192 " *",
00193 " * The mask is meaningless for ISA_PACK_COMP_end.",
00194 " *",
00195 " * typedef (struct) ISA_PACK_ADJ_INFO",
00196 " * Describes how the operands of a particular instruction",
00197 " * are to be adjust. The contents are private.",
00198 " *",
00199 " * const INT ISA_PACK_ADJ_END",
00200 " * A reserved ISA_PACK_ADJ_INFO code which indicates the end",
00201 " * of a sequence of adjustments.",
00202 " *",
00203 " * const ISA_PACK_ADJ_INFO *ISA_PACK_Adj_Info(TOP topcode)",
00204 " * Returns a pointer to the first operand adjustment description",
00205 " * for the instruction specified by 'topcode'. Increment",
00206 " * the returned pointer to access any additional adjustment",
00207 " * descriptions for the instruction. An adjustment description",
00208 " * with code ISA_PACK_ADJ_END marks the end.",
00209 " *",
00210 " * INT ISA_PACK_ADJ_INFO_Code(const ISA_PACK_ADJ_INFO *info, BOOL invert)",
00211 " * Identifies the adjustment to be made. If <invert> is FALSE,",
00212 " * the adjustment is for packing; otherwise if <invert> is TRUE,",
00213 " * the adjustment is for unpacking.",
00214 " *",
00215 " * INT ISA_PACK_ADJ_INFO_OpndIdx(const ISA_PACK_ADJ_INFO *info)",
00216 " * The index of the operand, i.e. the operand number, to be adjusted.",
00217 " *",
00218 " * void ISA_PACK_Adjust_Operands(const ISA_PACK_ADJ_INFO *info,",
00219 " * INT64 *opnd,",
00220 " * BOOL invert)",
00221 " * Apply adjustemnts to all operands of an instruction, as",
00222 " * specified by <info>. <opnd> is a pointer to an array of",
00223 " * of operand values for the instruction. If <invert> is FALSE,",
00224 " * the adjustment is for packing; otherwise if <invert> is TRUE,",
00225 " * the adjustment is for unpacking.",
00226 " *",
00227 " * ====================================================================",
00228 " * ====================================================================",
00229 " */",
00230 NULL
00231 };
00232
00233
00235 const char* Print_Name(int print_index)
00237 {
00238 static char *comp_name[MAX_LISTING_OPERANDS];
00239 static bool initialized;
00240
00241 if (!initialized) {
00242 int i;
00243 for (i = 0; i < MAX_LISTING_OPERANDS; ++i) {
00244 char buf[80];
00245 if (i == END) {
00246 comp_name[i] = "ISA_PACK_COMP_end";
00247 } else if (i == OPND) {
00248 comp_name[i] = "ISA_PACK_COMP_opnd";
00249 } else if (i > OPND && i < (OPND + MAX_OPNDS)) {
00250 sprintf(buf, "ISA_PACK_COMP_opnd+%d", i - OPND);
00251 comp_name[i] = strdup(buf);
00252 } else if (i == RESULT) {
00253 comp_name[i] = "ISA_PACK_COMP_result";
00254 } else {
00255 assert(i > RESULT && i < (RESULT + MAX_RESULTS));
00256 sprintf(buf, "ISA_PACK_COMP_result+%d", i - RESULT);
00257 comp_name[i] = strdup(buf);
00258 }
00259 }
00260 initialized = true;
00261 }
00262
00263 return comp_name[print_index];
00264 }
00265
00267 void ISA_Pack_Begin( const char* , int inst_bit_size )
00269
00271 {
00272 inst_bits = inst_bit_size;
00273 }
00274
00276 ISA_PACK_TYPE ISA_Pack_Type_Create ( const char* name)
00278
00280 {
00281 ISA_PACK_TYPE result = new isa_pack_type;
00282 result->name = name;
00283 result->max_word = 0;
00284 current_pack_desc = result;
00285 all_packs.push_back (current_pack_desc);
00286 return result;
00287 }
00288
00290 OPND_ADJ_TYPE Create_Operand_Adjustment(const char *name, const char *adj)
00292
00294 {
00295 OPND_ADJ_TYPE oadj = new opnd_adj_type;
00296 oadj->name = name;
00297 oadj->adj = adj;
00298 oadj->code = ++num_adj;
00299 all_oadj.push_back (oadj);
00300 return oadj;
00301 }
00302
00304 void Instruction_Pack_Group(ISA_PACK_TYPE pack_type, ...)
00306
00308 {
00309 va_list ap;
00310 TOP opcode;
00311
00312 int words = current_pack_desc->max_word + 1;
00313 if (words > inst_words) inst_words = words;
00314
00315 va_start(ap, pack_type);
00316 for (opcode = static_cast<TOP>(va_arg(ap, int));
00317 opcode != TOP_UNDEFINED;
00318 opcode = static_cast<TOP>(va_arg(ap, int)))
00319 {
00320 int i;
00321 op_assembly *op_pack = new op_assembly;
00322 for (i = 0; i < words; ++i) {
00323 unsigned long long opcode_mask;
00324 opcode_mask = inst_bits > 32 ? va_arg(ap,unsigned long long)
00325 : va_arg(ap,unsigned long);
00326 op_pack->opcode_mask[i] = opcode_mask;
00327 }
00328 for (i = words; i < MAX_WORDS; ++i) op_pack->opcode_mask[i] = 0;
00329 top_specified[(int)opcode] = true;
00330 op_packs_list.push_back(op_pack);
00331 op_pack->desc = current_pack_desc;
00332 op_packs[(int)opcode] = op_pack;
00333 }
00334 va_end(ap);
00335 }
00336
00338 void Adjust_Operand(int operand_index,
00339 OPND_ADJ_TYPE pack_adj,
00340 OPND_ADJ_TYPE unpack_adj)
00342
00344 {
00345 ISA_ADJ_TYPE curr_adj = new isa_adj_type;
00346
00347 if (operand_index >= MAX_OPNDS) {
00348 fprintf(stderr, "### Error: operand index (%d) exceeds %d\n",
00349 operand_index, MAX_OPNDS-1);
00350 exit(EXIT_FAILURE);
00351 }
00352 curr_adj->opnd_index = operand_index;
00353 curr_adj->padj = pack_adj;
00354 curr_adj->uadj = unpack_adj;
00355 current_pack_desc->oadj.push_back (curr_adj);
00356 }
00357
00359 void Operand (int operand_index,
00360 int opnd_position,
00361 int inst_position,
00362 int width)
00364
00366 {
00367 ISA_ARGS_TYPE curr_args_type = new isa_args_type;
00368 int w = current_pack_desc->max_word;
00369
00370 if (operand_index >= MAX_OPNDS) {
00371 fprintf(stderr, "### Error: operand index (%d) exceeds %d\n",
00372 operand_index, MAX_OPNDS-1);
00373 exit(EXIT_FAILURE);
00374 }
00375 curr_args_type->name = OPND + operand_index;
00376 curr_args_type->opnd_position = opnd_position;
00377 curr_args_type->inst_position = inst_position;
00378 curr_args_type->width = width;
00379 current_pack_desc->word[w].operands.push_back (curr_args_type);
00380
00381 if (width > mask_width) mask_width = width;
00382 }
00383
00385 void Result (int result_index, int bit_position, int width)
00387
00389 {
00390 ISA_ARGS_TYPE curr_args_type = new isa_args_type;
00391 int w = current_pack_desc->max_word;
00392
00393 if (result_index >= MAX_RESULTS) {
00394 fprintf(stderr, "### Error: result index (%d) exceeds %d\n",
00395 result_index, MAX_RESULTS-1);
00396 exit(EXIT_FAILURE);
00397 }
00398 curr_args_type->name = RESULT + result_index;
00399 curr_args_type->inst_position = bit_position;
00400 curr_args_type->opnd_position = 0;
00401 curr_args_type->width = width;
00402 current_pack_desc->word[w].results.push_back (curr_args_type);
00403
00404 if (width > mask_width) mask_width = width;
00405 }
00406
00407
00409 void Next_Word (void)
00411
00413 {
00414 ++current_pack_desc->max_word;
00415 if (current_pack_desc->max_word >= MAX_WORDS) {
00416 fprintf(stderr, "### Error: number of inst words (%d) exceeds MAX_WORDS\n",
00417 current_pack_desc->max_word+1);
00418 exit(EXIT_FAILURE);
00419 }
00420 }
00421
00423 void ISA_Pack_Is_Unused (void)
00425
00427 {
00428 int i;
00429 int top;
00430 current_pack_desc = new isa_pack_type;
00431 current_pack_desc->name = "dummy";
00432 current_pack_desc->max_word = 0;
00433 inst_words = 1;
00434 all_packs.push_back (current_pack_desc);
00435 for (top = 0; top < TOP_count; ++top) {
00436 bool is_dummy = TOP_is_dummy((TOP)top);
00437 bool is_simulated = TOP_is_simulated((TOP)top);
00438 if (!is_dummy && !is_simulated) {
00439 top_specified[top] = true;
00440 op_assembly *op_pack = new op_assembly;
00441 for (i = 0; i < MAX_WORDS; ++i) {
00442 op_pack->opcode_mask[i] = 0;
00443 }
00444 op_packs_list.push_back(op_pack);
00445 op_pack->desc = current_pack_desc;
00446 op_packs[top] = op_pack;
00447 }
00448 }
00449 }
00450
00452 static unsigned long long Mask(int width)
00453 {
00454 if (width > 64) {
00455 fprintf(stderr, "### Error: field width (%d) exceeds 64\n", width);
00456 exit(EXIT_FAILURE);
00457 } else if (width == 64) {
00458 return -1ULL;
00459 }
00460 return (1ULL << width) - 1;
00461 }
00462
00463
00465 void ISA_Pack_End(void)
00467
00469 {
00470 enum { isa_pack_adj_end = 0 };
00471 std::list<ISA_PACK_TYPE>::iterator isi;
00472 std::list<ISA_ARGS_TYPE>::iterator iai;
00473 std::list<ISA_ADJ_TYPE>::iterator ioi;
00474 std::list<OPND_ADJ_TYPE>::iterator ioai;
00475 #define FNAME "targ_isa_pack"
00476 char buf[1000];
00477 sprintf (buf, "%s.h", FNAME);
00478 FILE* hfile = fopen(buf, "w");
00479 sprintf (buf, "%s.c", FNAME);
00480 FILE* cfile = fopen(buf, "w");
00481 sprintf (buf, "%s.Exported", FNAME);
00482 FILE* efile = fopen(buf, "w");
00483 int w, i, index;
00484 const char * const isa_pack_index_format = " %3d, /* %s: %s */\n";
00485 const char * const isa_pack_words_format = " %3d, /* %s */\n";
00486 const char * const isa_pack_null_format =
00487 " { %-22s, %2d, %2d, %*d }, /* %s */\n";
00488 #ifdef TARG_IA64
00489 const char * const isa_pack_operand_format =
00490 " { %-22s, %2d, %2d, 0x%0*llxLL }, /* %s, OPND%d */\n";
00491 const char * const isa_pack_result_format =
00492 " { %-22s, %2d, %2d, 0x%0*llxLL }, /* %s, RESULT%d */\n";
00493 #else
00494 const char * const isa_pack_operand_format =
00495 " { %-22s, %2d, %2d, 0x%0*llx }, /* %s, OPND%d */\n";
00496 const char * const isa_pack_result_format =
00497 " { %-22s, %2d, %2d, 0x%0*llx }, /* %s, RESULT%d */\n";
00498 #endif
00499
00500 int init_digits;
00501 int mask_digits;
00502 int top;
00503 bool err;
00504 bool only_zero_opndpos;
00505 const char *info_index_type;
00506
00507 for (err = false, top = 0; top < TOP_count; ++top) {
00508 bool is_dummy = TOP_is_dummy((TOP)top);
00509 bool is_simulated = TOP_is_simulated((TOP)top);
00510 if (!top_specified[top]) {
00511 if (!is_simulated && !is_dummy) {
00512 fprintf(stderr, "### Error: no pack specification for %s\n",
00513 TOP_Name((TOP)top));
00514 err = true;
00515 }
00516 } else if (is_dummy) {
00517 fprintf(stderr, "### Error: pack specification for dummy op %s\n",
00518 TOP_Name((TOP)top));
00519 err = true;
00520 } else if (is_simulated) {
00521 fprintf(stderr, "### Error: pack specification for simulated op %s\n",
00522 TOP_Name((TOP)top));
00523 err = true;
00524 }
00525 }
00526 if (err) exit(EXIT_FAILURE);
00527
00528
00529 if (inst_bits > 32) {
00530 init_digits = 64 / 4;
00531 } else if (inst_bits > 16) {
00532 init_digits = 32 / 4;
00533 } else if (inst_bits > 8) {
00534 init_digits = 16 / 4;
00535 } else {
00536 init_digits = 8 / 4;
00537 }
00538
00539 if (mask_width > 32) {
00540 mask_digits = 64 / 4;
00541 } else if (mask_width > 16) {
00542 mask_digits = 32 / 4;
00543 } else if (mask_width > 8) {
00544 mask_digits = 16 / 4;
00545 } else {
00546 mask_digits = 8 / 4;
00547 }
00548
00549
00550
00551 only_zero_opndpos = true;
00552 for ( isi = all_packs.begin(); isi != all_packs.end(); ++index, ++isi ) {
00553 ISA_PACK_TYPE curr_ptype = *isi;
00554 for (w = 0; w <= curr_ptype->max_word; ++w) {
00555 for ( iai = curr_ptype->word[w].operands.begin();
00556 iai != curr_ptype->word[w].operands.end();
00557 ++iai)
00558 {
00559 ISA_ARGS_TYPE curr_atype = *iai;
00560 if (curr_atype->opnd_position != 0) only_zero_opndpos = false;
00561 }
00562 for ( iai = curr_ptype->word[w].results.begin();
00563 iai != curr_ptype->word[w].results.end();
00564 ++iai)
00565 {
00566 ISA_ARGS_TYPE curr_atype = *iai;
00567 if (curr_atype->opnd_position != 0) only_zero_opndpos = false;
00568 }
00569 }
00570 }
00571
00572 fprintf(cfile,"#include \"topcode.h\"\n");
00573 fprintf(cfile,"#include \"%s.h\"\n\n", FNAME);
00574
00575 sprintf (buf, "%s", FNAME);
00576 Emit_Header (hfile, buf, interface);
00577 fprintf(hfile,"#include \"topcode.h\"\n");
00578 if (inst_words == 1) fprintf(hfile,"#include \"targ_isa_properties.h\"\n");
00579
00580 fprintf(hfile, "\ntypedef mUINT%d ISA_PACK_INST;\n", init_digits * 4);
00581
00582 fprintf(hfile, "\n#define ISA_PACK_INST_SIZE (%d)\n", inst_bits);
00583
00584 fprintf(hfile, "\n#define ISA_PACK_MAX_INST_WORDS (%d)\n", inst_words);
00585
00586 fprintf(hfile, "\ntypedef enum {\n"
00587 " %-20s = %d, /* %s */\n"
00588 " %-20s = %d, /* %s */\n"
00589 " %-20s = %d, /* %s */\n"
00590 " %-20s = %d /* %s */\n"
00591 "} ISA_PACK_COMP;\n",
00592 Print_Name(END), END, "End of list marker",
00593 Print_Name(OPND), OPND, "OPND+n => operand n",
00594 Print_Name(RESULT), RESULT, "RESULT+n => result n",
00595 "ISA_PACK_COMP_MAX", MAX_LISTING_OPERANDS-1, "Last component");
00596
00597 fprintf(hfile, "\ntypedef struct {\n"
00598 " mUINT8 comp;\n"
00599 " mUINT8 opndpos;\n"
00600 " mUINT8 instpos;\n"
00601 " mUINT%d mask;\n"
00602 "} ISA_PACK_INFO;\n",
00603 mask_digits * 4);
00604
00605 fprintf(efile, "ISA_PACK_info\n");
00606
00607 fprintf(cfile, "\nconst ISA_PACK_INFO ISA_PACK_info[] = {\n");
00608
00609 fprintf (cfile, isa_pack_null_format, Print_Name(END), -1, -1, mask_digits, -1, "UNDEFINED");
00610 index = 1;
00611 for ( isi = all_packs.begin(); isi != all_packs.end(); ++isi ) {
00612 ISA_PACK_TYPE curr_ptype = *isi;
00613 curr_ptype->index = index;
00614 for (w = 0; w <= curr_ptype->max_word; ++w, ++index) {
00615 i = 0;
00616 for ( iai = curr_ptype->word[w].operands.begin();
00617 iai != curr_ptype->word[w].operands.end(); ++index, ++iai) {
00618 ISA_ARGS_TYPE curr_atype = *iai;
00619 fprintf (cfile, isa_pack_operand_format,
00620 Print_Name(curr_atype->name),
00621 curr_atype->opnd_position,
00622 curr_atype->inst_position,
00623 mask_digits, Mask(curr_atype->width),
00624 curr_ptype->name,
00625 i++);
00626 }
00627 i = 0;
00628 for ( iai = curr_ptype->word[w].results.begin();
00629 iai != curr_ptype->word[w].results.end(); ++index, ++iai) {
00630 ISA_ARGS_TYPE curr_atype = *iai;
00631 fprintf (cfile, isa_pack_result_format,
00632 Print_Name(curr_atype->name),
00633 curr_atype->opnd_position,
00634 curr_atype->inst_position,
00635 mask_digits, Mask(curr_atype->width),
00636 curr_ptype->name,
00637 i++);
00638 }
00639 fprintf (cfile, isa_pack_null_format,
00640 Print_Name(END),
00641 -1,
00642 -1,
00643 mask_digits, -1,
00644 curr_ptype->name);
00645 }
00646 }
00647 fprintf (cfile, "};\n\n");
00648
00649
00650 if (index < 1<<8) {
00651 info_index_type = "mUINT8";
00652 } else {
00653 assert (index < 1<<16);
00654 info_index_type = "mUINT16";
00655 }
00656
00657 fprintf(efile, "ISA_PACK_info_index\n");
00658
00659 fprintf(cfile, "\nconst %s ISA_PACK_info_index[%d] = {\n",
00660 info_index_type, TOP_count);
00661 for (top = 0; top < TOP_count; ++top ) {
00662 op_assembly *op_pack = op_packs[top];
00663 if (op_pack) {
00664 fprintf(cfile, isa_pack_index_format,
00665 op_pack->desc->index,
00666 TOP_Name((TOP)top),
00667 op_pack->desc->name);
00668 } else {
00669 fprintf(cfile, " %3d, /* %s */\n",
00670 0,
00671 TOP_Name((TOP)top));
00672 }
00673 }
00674 fprintf(cfile, "};\n");
00675
00676 fprintf(efile, "ISA_PACK_init_mask\n");
00677
00678 fprintf(cfile, "\nconst mUINT%d ISA_PACK_init_mask[%d][%d] = {\n",
00679 init_digits * 4,
00680 TOP_count,
00681 inst_words);
00682 for (top = 0; top < TOP_count; ++top ) {
00683 op_assembly *op_pack = op_packs[top];
00684 fprintf(cfile, " {");
00685 for (w = 0; w < inst_words; ++w) {
00686 fprintf(cfile, " 0x%0*" LL_FORMAT "xLL,",
00687 init_digits, op_pack ? op_pack->opcode_mask[w] : 0LL);
00688 }
00689 fprintf(cfile, " }, /* %s */\n", TOP_Name((TOP)top));
00690
00691 }
00692 fprintf(cfile, "};\n");
00693
00694 if (inst_words > 1) {
00695 fprintf(efile, "ISA_PACK_inst_words\n");
00696
00697 fprintf(cfile, "\nconst mUINT8 ISA_PACK_inst_words[%d] = {\n", TOP_count);
00698 for (top = 0; top < TOP_count; ++top ) {
00699 op_assembly *op_pack = op_packs[top];
00700 int words = op_pack ? op_pack->desc->max_word + 1
00701 : (TOP_is_dummy(top) ? 0 : 1);
00702 fprintf(cfile, isa_pack_words_format,
00703 words,
00704 TOP_Name((TOP)top));
00705 }
00706 fprintf(cfile, "};\n");
00707 }
00708
00709 fprintf(hfile, "\ninline UINT64 ISA_PACK_Init_Mask(TOP topcode, INT iword)\n"
00710 "{\n"
00711 " extern const mUINT%d ISA_PACK_init_mask[%d][%d];\n"
00712 " return ISA_PACK_init_mask[(INT)topcode][iword];\n"
00713 "}\n",
00714 init_digits * 4,
00715 TOP_count,
00716 inst_words);
00717
00718 fprintf(hfile, "\ninline INT ISA_PACK_Inst_Words(TOP topcode)\n"
00719 "{\n");
00720 if (inst_words == 1) {
00721 #if defined(TARG_SL)
00722 fprintf(hfile, " return TOP_is_dummy(topcode) ? 0 : (TOP_is_instr16(topcode) ? 1 : 2);\n");
00723 #else
00724 fprintf(hfile, " return TOP_is_dummy(topcode) ? 0 : 1;\n");
00725 #endif
00726 } else {
00727 fprintf(hfile, " extern const mUINT8 ISA_PACK_inst_words[%d];\n"
00728 " return ISA_PACK_inst_words[(INT)topcode];\n",
00729 TOP_count);
00730 }
00731 fprintf(hfile, "}\n");
00732
00733 fprintf(hfile, "\ninline const ISA_PACK_INFO *ISA_PACK_Info(TOP topcode)\n"
00734 "{\n"
00735 " extern const %s ISA_PACK_info_index[];\n"
00736 " extern const ISA_PACK_INFO ISA_PACK_info[];\n"
00737 " INT index = ISA_PACK_info_index[(INT)topcode];\n"
00738 " return index == 0 ? 0 : &ISA_PACK_info[index];\n"
00739 "}\n",
00740 info_index_type);
00741
00742 fprintf(hfile, "\ninline INT ISA_PACK_INFO_Comp(const ISA_PACK_INFO *info)\n"
00743 "{\n"
00744 " return info->comp;\n"
00745 "}\n");
00746
00747 fprintf(hfile, "\n%s"
00748 "inline INT ISA_PACK_INFO_OpndPos(const ISA_PACK_INFO *info)\n"
00749 "{\n"
00750 " return %s;\n"
00751 "}\n",
00752 only_zero_opndpos ? "/*ARGSUSED*/\n" : "",
00753 only_zero_opndpos ? "0" : "info->opndpos");
00754
00755 fprintf(hfile, "\ninline INT ISA_PACK_INFO_InstPos(const ISA_PACK_INFO *info)\n"
00756 "{\n"
00757 " return info->instpos;\n"
00758 "}\n");
00759
00760 fprintf(hfile, "\ninline UINT64 ISA_PACK_INFO_Mask(const ISA_PACK_INFO *info)\n"
00761 "{\n"
00762 " return info->mask;\n"
00763 "}\n");
00764
00765 fprintf(hfile, "\ntypedef struct {\n"
00766 " mUINT8 code[2];\n"
00767 " mUINT8 opndidx;\n"
00768 "} ISA_PACK_ADJ_INFO;\n");
00769
00770 fprintf(hfile, "\nenum { ISA_PACK_ADJ_END = %d };\n",
00771 isa_pack_adj_end);
00772
00773 fprintf(efile, "ISA_PACK_adj_info\n");
00774
00775 fprintf(cfile, "\nconst ISA_PACK_ADJ_INFO ISA_PACK_adj_info[] = {\n"
00776 " { { %2d, %2d }, -1 }, /* [ 0]: ISA_PACK_ADJ_END */\n",
00777 isa_pack_adj_end, isa_pack_adj_end);
00778 index = 1;
00779 for ( isi = all_packs.begin(); isi != all_packs.end(); ++isi ) {
00780 ISA_PACK_TYPE curr_ptype = *isi;
00781 i = 0;
00782 if (curr_ptype->oadj.begin() != curr_ptype->oadj.end()) {
00783 curr_ptype->adj_index = index;
00784 for ( ioi = curr_ptype->oadj.begin();
00785 ioi != curr_ptype->oadj.end();
00786 ++index, ++ioi)
00787 {
00788 ISA_ADJ_TYPE curr_adj = *ioi;
00789 fprintf(cfile, " { { %2d, %2d }, %2d }, /* [%2d]: %s (%s) operand %d*/\n",
00790 curr_adj->padj->code,
00791 curr_adj->uadj->code,
00792 curr_adj->opnd_index,
00793 index,
00794 curr_adj->padj->name,
00795 curr_adj->uadj->name,
00796 curr_adj->opnd_index);
00797 }
00798 fprintf (cfile, " { { %2d, %2d }, -1 }, /* [%2d]: ISA_PACK_ADJ_END */\n",
00799 isa_pack_adj_end, isa_pack_adj_end, index);
00800 ++index;
00801 } else {
00802 curr_ptype->adj_index = 0;
00803 }
00804 }
00805 fprintf(cfile, "};\n");
00806
00807 fprintf(hfile, "\ninline INT ISA_PACK_ADJ_INFO_Code(const ISA_PACK_ADJ_INFO *info, BOOL invert)\n"
00808 "{\n"
00809 " return info->code[invert];\n"
00810 "}\n");
00811
00812 fprintf(hfile, "\ninline INT ISA_PACK_ADJ_INFO_OpndIdx(const ISA_PACK_ADJ_INFO *info)\n"
00813 "{\n"
00814 " return info->opndidx;\n"
00815 "}\n");
00816
00817 fprintf(efile, "ISA_PACK_adj_info_index\n");
00818
00819 fprintf(cfile, "\nconst mUINT8 ISA_PACK_adj_info_index[] = {\n");
00820 for (top = 0; top < TOP_count; ++top ) {
00821 op_assembly *op_pack = op_packs[top];
00822 fprintf(cfile, " %2d, /* %s */\n",
00823 op_pack ? op_pack->desc->adj_index : 0,
00824 TOP_Name((TOP)top));
00825 }
00826 fprintf(cfile, "};\n");
00827
00828 fprintf(hfile, "\ninline const ISA_PACK_ADJ_INFO *ISA_PACK_Adj_Info(TOP topcode)\n"
00829 "{\n"
00830 " extern const ISA_PACK_ADJ_INFO ISA_PACK_adj_info[];\n"
00831 " extern const mUINT8 ISA_PACK_adj_info_index[];\n"
00832 " INT index = ISA_PACK_adj_info_index[(INT)topcode];\n"
00833 " return index == 0 ? 0 : &ISA_PACK_adj_info[index];\n"
00834 "}\n");
00835
00836 fprintf(hfile, "\nextern void ISA_PACK_Adjust_Operands(const ISA_PACK_ADJ_INFO *info,\n"
00837 " INT64 *opnd,\n"
00838 " BOOL invert);\n");
00839
00840 fprintf(efile, "ISA_PACK_Adjust_Operands\n");
00841
00842 fprintf(cfile, "\n"
00843 "void ISA_PACK_Adjust_Operands(const ISA_PACK_ADJ_INFO *info,\n"
00844 " INT64 *opnd,\n"
00845 " BOOL invert)\n"
00846 "{\n"
00847 " INT code;\n"
00848 "\n"
00849 " for (; (code = ISA_PACK_ADJ_INFO_Code(info, invert)) != ISA_PACK_ADJ_END; ++info) {\n"
00850 " INT index = ISA_PACK_ADJ_INFO_OpndIdx(info);\n"
00851 " INT64 O_VAL = opnd[index];\n"
00852 " switch (code) {\n");
00853 for ( ioai = all_oadj.begin(); ioai != all_oadj.end(); ++ioai ) {
00854 OPND_ADJ_TYPE curr_oadj = *ioai;
00855 fprintf(cfile, " case %2d: /* %s */\n"
00856 " O_VAL = (%s);\n"
00857 " break;\n",
00858 curr_oadj->code, curr_oadj->name,
00859 curr_oadj->adj);
00860 }
00861 fprintf(cfile, " }\n"
00862 " opnd[index] = O_VAL;\n"
00863 " }\n"
00864 "}\n");
00865
00866 Emit_Footer (hfile);
00867 }