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
00030 #include "messg.h"
00031 #include "rta.h"
00032 #include <cstdio>
00033
00034
00035 void Print_rta_hdr(FILE *f, const Rta_Hdr *hdr, const char *indent) {
00036 if (!f) f = stdout;
00037 if (!indent) indent = "";
00038
00039 fprintf(f, "%s", indent);
00040 fprintf(f, "Magic:0x%016llx ", Rta_hdr_magic(hdr));
00041 char *type, *target;
00042 switch (Rta_hdr_type(hdr)) {
00043 case RTA_DYNAMIC:
00044 type = "Dynamic"; break;
00045 case RTA_STATIC:
00046 type = "Static"; break;
00047 default:
00048 type = "Unknown";
00049 }
00050 switch (Rta_hdr_target(hdr)) {
00051 case RTA_X8664:
00052 target = "X86_64"; break;
00053 case RTA_X8632:
00054 target = "X86_32"; break;
00055 case RTA_IA64:
00056 target = "IA64"; break;
00057 case RTA_MIPS:
00058 target = "MIPS"; break;
00059 default:
00060 target = "Unknown";
00061 }
00062 fprintf(f, "%s, ", type);
00063 fprintf(f, "%s, ", target);
00064 fprintf(f, "Offset 0x%x, ", Rta_hdr_pu_off(hdr));
00065 fprintf(f, "NumPUs %d, ", Rta_hdr_pu_num(hdr));
00066 fprintf(f, "flags 0x%4x\n", Rta_hdr_flags(hdr));
00067 }
00068
00079 void Print_rta_pu_title(FILE *f, const char *indent)
00080 {
00081 if (!f) f = stdout;
00082 if (!indent) indent = "";
00083
00084 fprintf(f, "%s%16s", indent, "Address");
00085 fprintf(f, "%7s", " Size");
00086 fprintf(f, "%7s", "Flags");
00087 fprintf(f, "%6s", "MRegs");
00088 fprintf(f, "%6s", "Link");
00089 fprintf(f, " BB(%5s", "base");
00090 fprintf(f, "%6s", "Num");
00091 fprintf(f, "%6s", "Entry");
00092 fprintf(f, "%6s", "Exits");
00093 fprintf(f, "%11s","BbOff");
00094 fprintf(f, "%11s","CfgOff");
00095 fprintf(f, "%8s", " Name )\n");
00096 }
00097
00098 void Print_rta_pu(FILE *f, const Rta_Pu *pu, const char *indent) {
00099 if (!f) f = stdout;
00100 if (!indent) indent = "";
00101
00102 FmtAssert(Rta_pu_maxregs(pu) < 200, ("max regs too big %d\n", Rta_pu_maxregs(pu)));
00103
00104 fprintf(f, "%s%016llx ", indent, Rta_pu_start(pu));
00105 fprintf(f, "0x%04x 0x%04x ", Rta_pu_size(pu), Rta_pu_flags(pu));
00106 fprintf(f, "%3d %5d ", Rta_pu_maxregs(pu), Rta_pu_link(pu));
00107 fprintf(f, "%5d ", Rta_pu_bb_begin(pu));
00108 fprintf(f, "%5d %5d %5d", Rta_pu_bb_num(pu), Rta_pu_entry(pu), Rta_pu_exit(pu));
00109 fprintf(f, " 0x%08x", Rta_pu_bb_off(pu));
00110 fprintf(f, " 0x%08x", Rta_pu_cfg_off(pu));
00111 fprintf(f, " %4x\n", Rta_pu_name(pu));
00112 }
00113
00114 void Print_rta_bb_title(FILE *f, const char *indent) {
00115 if (!f) f = stdout;
00116 if (!indent) indent = "";
00117 fprintf(f, "%s%s", " Start", indent);
00118 fprintf(f, "%10s","Offset");
00119 fprintf(f, "%11s","Size");
00120 fprintf(f, "%6s", "#Ops");
00121 fprintf(f, "%6s", "Preds");
00122 fprintf(f, "%6s", "Succs");
00123 fprintf(f, "%7s\n", "Flags");
00124 }
00125
00135 void Print_rta_bb(FILE *f, UINT64 pc, const Rta_Bb *bb, INT i, const char *indent) {
00136 if (!f) f = stdout;
00137 if (!indent) indent = "";
00138
00139 fprintf(f, "%s[%5d] ", indent, i);
00140 fprintf(f, "0x%08x ", Rta_bb_start(bb)+pc);
00141 fprintf(f, "0x%08x ", Rta_bb_op_off(bb));
00142 fprintf(f, "0x%08x ", Rta_bb_size(bb));
00143 fprintf(f, "%5d ", Rta_bb_op_num(bb));
00144 fprintf(f, "%5d ", Rta_bb_plink(bb));
00145 fprintf(f, "%5d ", Rta_bb_slink(bb));
00146 fprintf(f, "0x%04x\n", Rta_bb_flags(bb));
00147 }
00148
00158 void Print_rta_idx_ent(FILE *f, const Rta_Idx_Ent *ent, const char *indent) {
00159 if (!f) f = stdout;
00160 if (!indent) indent = "";
00161
00162 fprintf(f, "%s", indent);
00163 fprintf(f, "PC range [0x%016llx, 0x%016llx), ", Rta_idx_ent_start(ent)
00164 , Rta_idx_ent_start(ent) + Rta_idx_ent_size(ent));
00165 fprintf(f, "Data Offset %u\n", Rta_idx_ent_data_off(ent));
00166 }
00167
00168 #ifdef RTA_TEST
00169
00170 INT main() {
00171
00172 printf("sizeof(Rta_Hdr) = %d\n", sizeof(Rta_Hdr));
00173 printf("sizeof(Rta_Pu) = %d\n", sizeof(Rta_Pu));
00174 printf("sizeof(Rta_Bb) = %d\n", sizeof(Rta_Bb));
00175 FmtAssert((sizeof(Rta_Hdr) % 8 == 0), ("Size of Rta_Hdr should align to 8 bytes."));
00176 FmtAssert((sizeof(Rta_Pu) % 8 == 0), ("Size of Rta_Pu should align to 8 bytes."));
00177 FmtAssert((sizeof(Rta_Bb) % 8 == 0), ("Size of Rta_Bb should align to 8 bytes."));
00178
00179 Rta_Hdr hdr = {V_1_0, RTA_STATIC, RTA_MIPS, 4, 99, 97};
00180
00181 Print_rta_hdr(NULL, &hdr, "++ ");
00182 Rta_hdr_set_magic(&hdr, V_1_0);
00183 Rta_hdr_set_target(&hdr, (RTA_TARGET)100);
00184 Print_rta_hdr(NULL, &hdr, NULL);
00185 printf("\n");
00186
00187 Rta_Pu pu = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233};
00188 Print_rta_pu(NULL, &pu, "Fibonacci: ");
00189 Rta_pu_set_exit(&pu, -Rta_pu_exit(&pu));
00190 Rta_pu_set_flags(&pu, -Rta_pu_flags(&pu));
00191 Rta_pu_set_link(&pu, -Rta_pu_link(&pu));
00192
00193 Print_rta_pu(NULL, &pu, "Neg: ");
00194 printf("\n");
00195
00196 Rta_Bb bb = {429, 132, 42, 14, 5, 2, 1};
00197 Print_rta_bb(NULL, 0xfedc000000000000LL, &bb, 0, "Catalan: ");
00198 printf("\n");
00199
00200 Rta_Idx_Ent ent = {0x8765432112345678LL, 0x100, 5};
00201 Print_rta_idx_ent(NULL, &ent, NULL);
00202
00203 printf("An assertion failure of null pointer should follow.\n");
00204 Rta_Hdr *c = NULL;
00205 Rta_hdr_set_magic(c, V_1_0);
00206 }
00207
00208 #endif // RTA_TEST