今回のテーマは、x86の時に付けたcodedump命令とcode命令がとても便利だったので、同じことをx64でもやることです(参考:HL-12a)。
(前略)
int phrCmpPutIcX64(int pid, String phr, int pc, int *pi, int lenExpr, int sub, int *err) → HL-17と同じなので省略
int codedump; [この行追加]
///////////////////////////////////////////////////////////////////////////////
int compile(String s)
{
(中略)
jp = 0;
putIcX64("41_57; 41_56; 41_55; 41_54; 41_53; 41_52;", 0, 0, 0, 0);
putIcX64("41_51; 41_50; 57; 56; 55; 54; 53; 52; 51; 50;", 0, 0, 0, 0);
putIcX64("%R_81_ec_f8_01_00_00; %R_bd_%0q;", var, 0, 0, 0);
+ dump0 = icq;
for (i = 0; i < 10; i++) {
tmp_flag[i] = 0;
}
tmpLabelNo = 0;
bd = lbd = 0;
for (pc = 0; pc < pc1; ) { // コンパイル開始.
(中略)
+ } else if (phrCmp(35, "code", pc)) {
+ for (pc++; tc[pc] != TcSemi; pc++) {
+ if (tc[pc] == TcComma) continue;
+ *icq = var[tc[pc]];
+ icq++;
+ }
+ ppc1 = pc + 1;
+ } else if (phrCmp(38, "codedump !!*0;", pc)) {
+ codedump = var[tc[wpc[0]]];
} else if (phrCmp( 8, "!!***0;", pc)) { // これはかなりマッチしやすいので最後にする.
e0 = expr(0);
} else
goto err;
tmpFree(e0);
tmpFree(e2);
if (e0 < 0 || e2 < 0) goto err;
pc = ppc1;
}
if (bd > 0) {
printf("block nesting error (bd=%d, lbd=%d, pc=%d, pc1=%d\n", bd, lbd, pc, pc1);
return -1;
}
+ dump1 = icq;
putIcX64("%R_81_c4_f8_01_00_00;", 0, 0, 0, 0);
putIcX64("58; 59; 5a; 5b; 5c; 5d; 5e; 5f; 41_58; 41_59;", 0, 0, 0, 0);
putIcX64("41_5a; 41_5b; 41_5c; 41_5d; 41_5e; 41_5f; c3;", 0, 0, 0, 0);
icq1 = icq;
(中略)
}
int run(String s)
{
if (compile(s) < 0)
return 1;
+ if (codedump == 0) {
void (*func)() = (void (*)()) ic;
t0 = clock();
func();
+ } else {
+ int i, i1 = dump1 - dump0;
+ for (i = 0; i < i1; i++) {
+ printf("%02x ", dump0[i]);
+ }
+ printf("\n(len=%d)\n", i1);
+ }
return 0;
}
(後略)