TempleOSCD_150720.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:22 +02:00
1 parent 401601816c
commit f8c05f98f4
554 files changed
+26046 -24853

No files matched your search

+233 -188
View File
@@ -1,22 +1,22 @@
I64 OptPass789A(CLex *lx,COptReg *reg_offsets,U8 *buf,CDbgInfo **_dbg)
{/*lx->pass==7 is first time
lx->pass==8 is second time
lx->pass==9 is third time
lx->pass==9 is fourth time and repeated until size stops shrinking
I64 OptPass789A(CCmpCtrl *cc,COptReg *reg_offsets,U8 *buf,CDbgInfo **_dbg)
{/*cc->pass==7 is first time
cc->pass==8 is second time
cc->pass==9 is third time
cc->pass==9 is fourth time and repeated until size stops shrinking
size is now known
lx->pass==10 is final pass, code is placed into buf.
cc->pass==10 is final pass, code is placed into buf.
*/
CIntermediateCode *tempi,*tempi_next;
I64 i,cnt,num_lines=lx->max_line+1-lx->min_line,ip=0,ip2;
I64 i,cnt,num_lines=cc->max_line+1-cc->min_line,ip=0,ip2;
U8 *ptr;
CLexCodeMisc *lb;
CExe *tempx;
CExeAbsAddr *tempa;
CExeImportExport *tempe;
CExeHeapGlbl *temphg;
CExeHeapGlblRef *temphgr;
CCodeMisc *lb;
CAOT *tempaot;
CAOTAbsAddr *tempa;
CAOTImportExport *tempie;
CAOTHeapGlbl *temphg;
CAOTHeapGlblRef *temphgr;
CDbgInfo *dbg_info;
CAOTCtrl *a=lx->a;
CAOTCtrl *aotc=cc->aotc;
Bool short_jmp;
CICArg saved_p123[3];
CHashClass *tempc;
@@ -26,53 +26,57 @@ lx->pass==10 is final pass, code is placed into buf.
if (_dbg) {
*_dbg=dbg_info=CAlloc(offset(CDbgInfo.body)+sizeof(U32)*(num_lines+1));
dbg_info->min_line=lx->min_line;
dbg_info->max_line=lx->max_line;
if (lx->flags&LF_AOT_COMPILE)
dbg_info->body[0]=a->ip;
dbg_info->min_line=cc->min_line;
dbg_info->max_line=cc->max_line;
if (cc->flags&CCF_AOT_COMPILE)
dbg_info->body[0]=aotc->ip;
else
dbg_info->body[0]=buf;
} else
dbg_info=NULL;
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT) && Bt(&lx->otrace_mask,lx->pass))
"$$BK,1$$$$LTRED$$$$IV,1$$This code gets merged together and patched.\n$$FG$$$$IV,0$$$$BK,0$$";
if (Bt(&cc->flags,CCf_OPT_TRACE_PRESENT) && Bt(&cc->otrace_mask,cc->pass))
"$$BK,1$$$$LTRED$$$$IV,1$$This code gets merged together and patched.\n"
"$$FG$$$$IV,0$$$$BK,0$$";
lx->last_float_op_ic=NULL;
tempi=&lx->lcc.lcc_root;
cc->last_float_op_ic=NULL;
tempi=&cc->coc.coc_root;
tempi->ic_cnt=0;
tempi->ic_last_cnt=-1;
tempi=tempi->next;
while (tempi->ic_code) {
tempi_next=tempi->next;
if (tempi->ic_flags&ICF_TRACE && Bt(&lx->otrace_mask,lx->pass))
ICPut(lx,tempi);
if (tempi->ic_flags&ICF_TRACE && Bt(&cc->otrace_mask,cc->pass))
ICPut(cc,tempi);
ip2=ip;
if (lx->flags&LF_AOT_COMPILE)
ip2+=a->ip;
if (cc->flags&CCF_AOT_COMPILE)
ip2+=aotc->ip;
else
ip2+=buf;
lx->cur_ic_float_op_num=0;
cc->cur_ic_float_op_num=0;
if (!(tempi->ic_flags &ICF_CODE_FINAL)) {
tempi->ic_flags=tempi->ic_flags&~(ICF_PREVIOUS_DELETED|ICF_DONT_RESTORE)|ICF_CODE_FINAL;
if (lx->pass==7)
lx->dont_push_float=Btr(&tempi->ic_flags,ICf_DONT_PUSH_FLOAT0);
tempi->ic_flags=tempi->ic_flags&
~(ICF_PREVIOUS_DELETED|ICF_DONT_RESTORE)|ICF_CODE_FINAL;
if (cc->pass==7)
cc->dont_push_float=Btr(&tempi->ic_flags,ICf_DONT_PUSH_FLOAT0);
MemCpy(saved_p123,&tempi->a1,3*sizeof(CICArg));
if (intermediate_code_table[tempi->ic_code].arg_cnt==IS_2_ARG && tempi->a1.type&TY_MASK==TY_REG &&
tempi->a1.reg==REG_RAX)
if (intermediate_code_table[tempi->ic_code].arg_cnt==IS_2_ARG &&
tempi->a1.type&TY_MASK==TY_REG && tempi->a1.reg==REG_RAX)
tempi->ic_flags|=ICF_A1_FIRST;
tempi->ic_cnt=0;
tempi->ic_last_cnt=-1;
if (tempi->ic_flags & ICF_A1_FIRST) {
if (tempi->a1.type&TY_MASK) {
if (tempi->ic_flags & ICF_A1_TO_F64) {
ICFCvt(lx,tempi,REG_RDX,tempi->a1.type,tempi->a1.reg,tempi->a1.disp,FALSE,CN_A1,ip2);
ICFCvt(cc,tempi,REG_RDX,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,FALSE,CN_A1,ip2);
tempi->a1.type=TY_REG+RT_I64;
tempi->a1.reg=REG_RDX;
tempi->a1.disp=0;
tempi->ic_flags&=~ICF_A1_FIRST;
} else if (tempi->ic_flags & ICF_A1_TO_INT) {
ICFCvt(lx,tempi,REG_RDX,tempi->a1.type,tempi->a1.reg,tempi->a1.disp,TRUE,CN_A1,ip2);
ICFCvt(cc,tempi,REG_RDX,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,TRUE,CN_A1,ip2);
tempi->a1.type=TY_REG+RT_I64;
tempi->a1.reg=REG_RDX;
tempi->a1.disp=0;
@@ -89,7 +93,8 @@ lx->pass==10 is final pass, code is placed into buf.
tempi->a1.disp=0;
tempi->ic_flags&=~ICF_A1_FIRST;
}
ICFCvt(lx,tempi,REG_RAX,tempi->a2.type,tempi->a2.reg,tempi->a2.disp,FALSE,CN_A2,ip2);
ICFCvt(cc,tempi,REG_RAX,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,FALSE,CN_A2,ip2);
tempi->a2.type=TY_REG+RT_I64;
tempi->a2.reg=REG_RAX;
tempi->a2.disp=0;
@@ -102,7 +107,8 @@ lx->pass==10 is final pass, code is placed into buf.
tempi->a1.disp=0;
tempi->ic_flags&=~ICF_A1_FIRST;
}
ICFCvt(lx,tempi,REG_RAX,tempi->a2.type,tempi->a2.reg,tempi->a2.disp,TRUE,CN_A2,ip2);
ICFCvt(cc,tempi,REG_RAX,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,TRUE,CN_A2,ip2);
tempi->a2.type=TY_REG+RT_I64;
tempi->a2.reg=REG_RAX;
tempi->a2.disp=0;
@@ -111,12 +117,14 @@ lx->pass==10 is final pass, code is placed into buf.
} else {
if (tempi->a2.type&TY_MASK) {
if (tempi->ic_flags & ICF_A2_TO_F64) {
ICFCvt(lx,tempi,REG_RAX,tempi->a2.type,tempi->a2.reg,tempi->a2.disp,FALSE,CN_A2,ip2);
ICFCvt(cc,tempi,REG_RAX,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,FALSE,CN_A2,ip2);
tempi->a2.type=TY_REG+RT_I64;
tempi->a2.reg=REG_RAX;
tempi->a2.disp=0;
} else if (tempi->ic_flags & ICF_A2_TO_INT) {
ICFCvt(lx,tempi,REG_RAX,tempi->a2.type,tempi->a2.reg,tempi->a2.disp,TRUE,CN_A2,ip2);
ICFCvt(cc,tempi,REG_RAX,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,TRUE,CN_A2,ip2);
tempi->a2.type=TY_REG+RT_I64;
tempi->a2.reg=REG_RAX;
tempi->a2.disp=0;
@@ -124,12 +132,14 @@ lx->pass==10 is final pass, code is placed into buf.
}
if (tempi->a1.type&TY_MASK) {
if (tempi->ic_flags & ICF_A1_TO_F64) {
ICFCvt(lx,tempi,REG_RDX,tempi->a1.type,tempi->a1.reg,tempi->a1.disp,FALSE,CN_A1,ip2);
ICFCvt(cc,tempi,REG_RDX,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,FALSE,CN_A1,ip2);
tempi->a1.type=TY_REG+RT_I64;
tempi->a1.reg=REG_RDX;
tempi->a1.disp=0;
} else if (tempi->ic_flags & ICF_A1_TO_INT) {
ICFCvt(lx,tempi,REG_RDX,tempi->a1.type,tempi->a1.reg,tempi->a1.disp,TRUE,CN_A1,ip2);
ICFCvt(cc,tempi,REG_RDX,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,TRUE,CN_A1,ip2);
tempi->a1.type=TY_REG+RT_I64;
tempi->a1.reg=REG_RDX;
tempi->a1.disp=0;
@@ -142,12 +152,12 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_ABS_ADDR:
ICU16(tempi,0xB848);
ICU64(tempi,tempi->ic_data);
if (buf && lx->flags&LF_AOT_COMPILE &&
!(lx->flags&(LF_NO_ABSS|LF_ASM_EXPRESSIONS))) {
tempa=CAlloc(sizeof(CExeAbsAddr));
tempa->next=a->abss;
tempa->type=EAT_ADD_U64;
a->abss=tempa;
if (buf && cc->flags&CCF_AOT_COMPILE &&
!(cc->flags&(CCF_NO_ABSS|CCF_ASM_EXPRESSIONS))) {
tempa=CAlloc(sizeof(CAOTAbsAddr));
tempa->next=aotc->abss;
tempa->type=AAT_ADD_U64;
aotc->abss=tempa;
tempa->ip=ip2+tempi->ic_cnt-8;
}
break;
@@ -155,9 +165,10 @@ lx->pass==10 is final pass, code is placed into buf.
ICU16(tempi,0xB848);
ICU64(tempi,0);
temphg=tempi->ic_data;
if (buf && lx->flags&LF_AOT_COMPILE &&
!(lx->flags&(LF_NO_ABSS|LF_ASM_EXPRESSIONS))) {//is this necessary--flags?
temphgr=CAlloc(sizeof(CExeHeapGlblRef));
if (buf && cc->flags&CCF_AOT_COMPILE &&
//TODO:is this necessary--flags?
!(cc->flags&(CCF_NO_ABSS|CCF_ASM_EXPRESSIONS))) {
temphgr=CAlloc(sizeof(CAOTHeapGlblRef));
temphgr->next=temphg->references;
temphg->references=temphgr;
temphgr->ip=ip2+tempi->ic_cnt-8;
@@ -166,24 +177,25 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_ADDR_IMPORT:
ICU8(tempi,0xB8);
ICU32(tempi,0);
if (buf && !(lx->flags&LF_NO_ABSS)) {
if (buf && !(cc->flags&CCF_NO_ABSS)) {
tempg=tempi->ic_data;
tempe=CAlloc(sizeof(CExeImportExport));
tempe->type=EIT_IMM_U32;
tempe->ip=ip2+tempi->ic_cnt-4;
tempe->next=tempg->ie_lst;
tempg->ie_lst=tempe;
tempie=CAlloc(sizeof(CAOTImportExport));
tempie->type=IET_IMM_U32;
tempie->ip=ip2+tempi->ic_cnt-4;
tempie->next=tempg->ie_lst;
tempg->ie_lst=tempie;
}
ICU24(tempi,0xC06348);
break;
case IC_RIP:
ICU16(tempi,0xB848);
ICU64(tempi,ip2+tempi->ic_cnt-2);
if (lx->flags&LF_AOT_COMPILE && buf && !(lx->flags&LF_NO_ABSS)) {
tempa=CAlloc(sizeof(CExeAbsAddr));
tempa->next=a->abss;
tempa->type=EAT_ADD_U64;
a->abss=tempa;
if (cc->flags&CCF_AOT_COMPILE && buf &&
!(cc->flags&CCF_NO_ABSS)) {
tempa=CAlloc(sizeof(CAOTAbsAddr));
tempa->next=aotc->abss;
tempa->type=AAT_ADD_U64;
aotc->abss=tempa;
tempa->ip=ip2+tempi->ic_cnt-8;
}
break;
@@ -212,52 +224,64 @@ lx->pass==10 is final pass, code is placed into buf.
ICFlagBranch(tempi,ip,0x75850F,buf);
break;
case IC_BR_EQUAL_EQUAL:
ICCmpAndBranch(tempi,FALSE,ip,0x74840F,0x74840F,0x74840F,0x74840F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x74840F,0x74840F,
0x74840F,0x74840F,buf,ip2);
break;
case IC_BR_EQUAL_EQUAL2:
ICCmpAndBranch(tempi,TRUE,ip,0x74840F,0x74840F,0x74840F,0x74840F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x74840F,0x74840F,
0x74840F,0x74840F,buf,ip2);
break;
case IC_BR_NOT_EQUAL:
ICCmpAndBranch(tempi,FALSE,ip,0x75850F,0x75850F,0x75850F,0x75850F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x75850F,0x75850F,
0x75850F,0x75850F,buf,ip2);
break;
case IC_BR_NOT_EQUAL2:
ICCmpAndBranch(tempi,TRUE,ip,0x75850F,0x75850F,0x75850F,0x75850F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x75850F,0x75850F,
0x75850F,0x75850F,buf,ip2);
break;
case IC_BR_LESS:
if (tempi->ic_flags&ICF_USE_F64)
ICFCmpAndBranch(lx,tempi, ip,0x72820F,0x77870F,buf,ip2);
ICFCmpAndBranch(cc,tempi, ip,0x72820F,0x77870F,buf,ip2);
else
ICCmpAndBranch(tempi,FALSE,ip,0x72820F,0x7C8C0F,0x77870F,0x7F8F0F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x72820F,0x7C8C0F,
0x77870F,0x7F8F0F,buf,ip2);
break;
case IC_BR_LESS2:
ICCmpAndBranch(tempi,TRUE,ip,0x72820F,0x7C8C0F,0x77870F,0x7F8F0F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x72820F,0x7C8C0F,
0x77870F,0x7F8F0F,buf,ip2);
break;
case IC_BR_GREATER_EQUAL:
if (tempi->ic_flags&ICF_USE_F64)
ICFCmpAndBranch(lx,tempi, ip,0x73830F,0x76860F,buf,ip2);
ICFCmpAndBranch(cc,tempi, ip,0x73830F,0x76860F,buf,ip2);
else
ICCmpAndBranch(tempi,FALSE,ip,0x73830F,0x7D8D0F,0x76860F,0x7E8E0F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x73830F,0x7D8D0F,
0x76860F,0x7E8E0F,buf,ip2);
break;
case IC_BR_GREATER_EQUAL2:
ICCmpAndBranch(tempi,TRUE,ip,0x73830F,0x7D8D0F,0x76860F,0x7E8E0F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x73830F,0x7D8D0F,
0x76860F,0x7E8E0F,buf,ip2);
break;
case IC_BR_GREATER:
if (tempi->ic_flags&ICF_USE_F64)
ICFCmpAndBranch(lx,tempi, ip,0x77870F,0x72820F,buf,ip2);
ICFCmpAndBranch(cc,tempi, ip,0x77870F,0x72820F,buf,ip2);
else
ICCmpAndBranch(tempi,FALSE,ip,0x77870F,0x7F8F0F,0x72820F,0x7C8C0F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x77870F,0x7F8F0F,
0x72820F,0x7C8C0F,buf,ip2);
break;
case IC_BR_GREATER2:
ICCmpAndBranch(tempi,TRUE,ip,0x77870F,0x7F8F0F,0x72820F,0x7C8C0F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x77870F,0x7F8F0F,
0x72820F,0x7C8C0F,buf,ip2);
break;
case IC_BR_LESS_EQUAL:
if (tempi->ic_flags&ICF_USE_F64)
ICFCmpAndBranch(lx,tempi, ip,0x76860F,0x73830F,buf,ip2);
ICFCmpAndBranch(cc,tempi, ip,0x76860F,0x73830F,buf,ip2);
else
ICCmpAndBranch(tempi,FALSE,ip,0x76860F,0x7E8E0F,0x73830F,0x7D8D0F,buf,ip2);
ICCmpAndBranch(tempi,FALSE,ip,0x76860F,0x7E8E0F,
0x73830F,0x7D8D0F,buf,ip2);
break;
case IC_BR_LESS_EQUAL2:
ICCmpAndBranch(tempi,TRUE,ip,0x76860F,0x7E8E0F,0x73830F,0x7D8D0F,buf,ip2);
ICCmpAndBranch(tempi,TRUE,ip,0x76860F,0x7E8E0F,
0x73830F,0x7D8D0F,buf,ip2);
break;
case IC_BR_BT:
ICBrBitOps(tempi,ip,0xA30F,0x20BA0F,0x72820F,buf,ip2);
@@ -326,33 +350,33 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_STR_CONST:
case IC_GET_LABEL:
lb=tempi->ic_data;
if (lx->flags&LF_AOT_COMPILE)
i=lb->addr+a->ip;
if (cc->flags&CCF_AOT_COMPILE)
i=lb->addr+aotc->ip;
else
i=lb->addr+buf;
ICLea(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_RIP_DISP32+RT_PTR,0,i,lx,buf,ip2);
TY_RIP_DISP32+RT_PTR,0,i,cc,buf,ip2);
break;
case IC_ASM:
tempx=tempi->ic_data;
tempi->ic_cnt+=tempx->ex_U8s;
tempaot=tempi->ic_data;
tempi->ic_cnt+=tempaot->aot_U8s;
if (buf) {
MemCpy(buf+ip,tempx->buf,tempx->ex_U8s);
Free(tempx->buf);
tempx->buf=buf;
tempx->ip=ip;
tempx->ip2=ip2;
if (lx->flags&LF_AOT_COMPILE)
CmpFixUpAOTAsm(lx,tempx);
MemCpy(buf+ip,tempaot->buf,tempaot->aot_U8s);
Free(tempaot->buf);
tempaot->buf=buf;
tempaot->ip=ip;
tempaot->ip2=ip2;
if (cc->flags&CCF_AOT_COMPILE)
CmpFixUpAOTAsm(cc,tempaot);
else
CmpFixUpJITAsm(lx,tempx);
CmpFixUpJITAsm(cc,tempaot);
cnt=tempi->ic_cnt;
goto op789A_skip_copy;
}
break;
case IC_CALL:
i=tempi->ic_data-(ip2+5);
if (!(MIN_I32<=i<=MAX_I32) && !(lx->flags&LF_AOT_COMPILE)) {
if (!(MIN_I32<=i<=MAX_I32) && !(cc->flags&CCF_AOT_COMPILE)) {
ICU16(tempi,0xBB48);
ICU64(tempi,tempi->ic_data);
ICU16(tempi,0xD3FF);
@@ -374,14 +398,14 @@ lx->pass==10 is final pass, code is placed into buf.
break;
case IC_CALL_INDIRECT2:
ICU16(tempi,0xBB48);
if (lx->flags&LF_AOT_COMPILE) i=ip2+tempi->ic_cnt;
if (cc->flags&CCF_AOT_COMPILE) i=ip2+tempi->ic_cnt;
ICU64(tempi,tempi->ic_data);
ICU16(tempi,0x13FF);
if (buf && lx->flags&LF_AOT_COMPILE&& !(lx->flags&LF_NO_ABSS)) {
tempa=CAlloc(sizeof(CExeAbsAddr));
tempa->next=a->abss;
tempa->type=EAT_ADD_U64;
a->abss=tempa;
if (buf && cc->flags&CCF_AOT_COMPILE&& !(cc->flags&CCF_NO_ABSS)) {
tempa=CAlloc(sizeof(CAOTAbsAddr));
tempa->next=aotc->abss;
tempa->type=AAT_ADD_U64;
aotc->abss=tempa;
tempa->ip=i;
}
break;
@@ -391,11 +415,11 @@ lx->pass==10 is final pass, code is placed into buf.
ICU64(tempi,0);
if (buf) {
tempf=tempi->ic_data;
tempe=CAlloc(sizeof(CExeImportExport));
tempe->type=EIT_IMM_I64;
tempe->ip=ip2+tempi->ic_cnt-8;
tempe->next=tempf->ie_lst;
tempf->ie_lst=tempe;
tempie=CAlloc(sizeof(CAOTImportExport));
tempie->type=IET_IMM_I64;
tempie->ip=ip2+tempi->ic_cnt-8;
tempie->next=tempf->ie_lst;
tempf->ie_lst=tempie;
}
ICU16(tempi,0xD3FF);
} else {
@@ -403,11 +427,11 @@ lx->pass==10 is final pass, code is placed into buf.
ICU32(tempi,0);
if (buf) {
tempf=tempi->ic_data;
tempe=CAlloc(sizeof(CExeImportExport));
tempe->type=EIT_REL_I32;
tempe->ip=ip2+tempi->ic_cnt-4;
tempe->next=tempf->ie_lst;
tempf->ie_lst=tempe;
tempie=CAlloc(sizeof(CAOTImportExport));
tempie->type=IET_REL_I32;
tempie->ip=ip2+tempi->ic_cnt-4;
tempie->next=tempf->ie_lst;
tempf->ie_lst=tempie;
}
}
break;
@@ -415,11 +439,14 @@ lx->pass==10 is final pass, code is placed into buf.
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_LEAVE:
if (lx->htc.fun) {
if (Bt(&lx->htc.fun->flags,Ff_INTERRUPT))
ICPopRegs(tempi,REG_ALWAYS_CLOBBERED_MASK&~(1<<REG_RBP|1<<REG_RSP)|lx->htc.fun->used_reg_mask&(REG_VARS_MASK|REG_NON_PTR_MASK|REG_STK_TEMPS_MASK));
if (cc->htc.fun) {
if (Bt(&cc->htc.fun->flags,Ff_INTERRUPT))
ICPopRegs(tempi,REGG_C_CLOBBERED|cc->htc.fun->used_reg_mask&
(REGG_C_LOCAL_VARS|REGG_C_LOCAL_NON_PTR_VARS|
REGG_C_TEMP_CLOBBERED));
else
ICPopRegs(tempi,lx->htc.fun->used_reg_mask&(REG_VARS_MASK|REG_NON_PTR_MASK));
ICPopRegs(tempi,cc->htc.fun->used_reg_mask&
(REGG_C_LOCAL_VARS|REGG_C_LOCAL_NON_PTR_VARS));
}
if (tempi->ic_data<=MAX_I16) {
if (tempi->ic_data)
@@ -430,15 +457,16 @@ lx->pass==10 is final pass, code is placed into buf.
ICAddRSP(tempi,tempi->ic_data);
ICU8(tempi,0x5D); //POP RBP
}
if (lx->htc.fun && Bt(&lx->htc.fun->flags,Ff_INTERRUPT)) {
if (Bt(&lx->htc.fun->flags,Ff_HASERRCODE))
if (cc->htc.fun && Bt(&cc->htc.fun->flags,Ff_INTERRUPT)) {
if (Bt(&cc->htc.fun->flags,Ff_HASERRCODE))
ICAddRSP(tempi,8);
ICU16(tempi,0xCF48);
} else if (lx->htc.fun && lx->htc.fun->arg_cnt &&
(Bt(&lx->htc.fun->flags,Ff_RET1) || Bt(&lx->htc.fun->flags,Ff_ARGPOP)) &&
!Bt(&lx->htc.fun->flags,Ff_NOARGPOP)) {
} else if (cc->htc.fun && cc->htc.fun->arg_cnt &&
(Bt(&cc->htc.fun->flags,Ff_RET1) ||
Bt(&cc->htc.fun->flags,Ff_ARGPOP)) &&
!Bt(&cc->htc.fun->flags,Ff_NOARGPOP)) {
ICU8(tempi,0xC2);
ICU16(tempi,lx->htc.fun->arg_cnt<<3);
ICU16(tempi,cc->htc.fun->arg_cnt<<3);
} else
ICU8(tempi,0xC3);
break;
@@ -479,7 +507,7 @@ lx->pass==10 is final pass, code is placed into buf.
break;
case IC_UNARY_MINUS:
if (tempi->r.type&RT_MASK==RT_F64)
ICFUnaryMinus(lx,tempi,buf,ip2);
ICFUnaryMinus(cc,tempi,buf,ip2);
else
ICUnaries(tempi,SLASH_OP_NEG,ip2);
break;
@@ -501,60 +529,62 @@ lx->pass==10 is final pass, code is placed into buf.
if (tempi->ic_flags&ICF_USE_INT)
ICPostIncDec(tempi,SLASH_OP_INC,ip2);
else
ICFPostIncDec(lx,tempi,CMP_TEMPLATE_INC,ip2);
ICFPostIncDec(cc,tempi,CMP_TEMPLATE_INC,ip2);
break;
case IC__MM:
if (tempi->ic_flags&ICF_USE_INT)
ICPostIncDec(tempi,SLASH_OP_DEC,ip2);
else
ICFPostIncDec(lx,tempi,CMP_TEMPLATE_DEC,ip2);
ICFPostIncDec(cc,tempi,CMP_TEMPLATE_DEC,ip2);
break;
case IC_PP_:
if (tempi->ic_flags&ICF_USE_INT)
ICPreIncDec(tempi,SLASH_OP_INC,ip2);
else
ICFPreIncDec(lx,tempi,CMP_TEMPLATE_INC,ip2);
ICFPreIncDec(cc,tempi,CMP_TEMPLATE_INC,ip2);
break;
case IC_MM_:
if (tempi->ic_flags&ICF_USE_INT)
ICPreIncDec(tempi,SLASH_OP_DEC,ip2);
else
ICFPreIncDec(lx,tempi,CMP_TEMPLATE_DEC,ip2);
ICFPreIncDec(cc,tempi,CMP_TEMPLATE_DEC,ip2);
break;
case IC_LEA:
ICLea(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,lx,buf,ip2);
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,cc,buf,ip2);
break;
case IC_POWER:
ICFPow(lx,tempi,buf,ip2);
ICFPow(cc,tempi,buf,ip2);
break;
case IC_SHL:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
break;
case IC_SHR:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_MUL:
if (tempi->ic_flags&ICF_USE_INT)
ICMul(tempi,ip2);
else
ICFMul(lx,tempi,buf,ip2);
ICFMul(cc,tempi,buf,ip2);
break;
case IC_DIV:
if (tempi->ic_flags&ICF_USE_INT)
ICDiv(tempi,ip2);
else
ICFDiv(lx,tempi,buf,ip2);
ICFDiv(cc,tempi,buf,ip2);
break;
case IC_MOD:
if (tempi->ic_flags&ICF_USE_INT)
ICMod(tempi,ip2);
else
ICFMod(lx,tempi,ip2);
ICFMod(cc,tempi,ip2);
break;
case IC_AND:
ICAddEct(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
@@ -577,7 +607,7 @@ lx->pass==10 is final pass, code is placed into buf.
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0x03,ip2);
else
ICFAdd(lx,tempi,buf,ip2);
ICFAdd(cc,tempi,buf,ip2);
break;
case IC_SUB:
if (tempi->ic_flags&ICF_USE_INT)
@@ -585,7 +615,7 @@ lx->pass==10 is final pass, code is placed into buf.
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,ip2);
else
ICFSub(lx,tempi,buf,ip2);
ICFSub(cc,tempi,buf,ip2);
break;
case IC_EQUAL_EQUAL:
ICCmp(tempi,0x75,0x75,ip2);
@@ -597,25 +627,25 @@ lx->pass==10 is final pass, code is placed into buf.
if (tempi->ic_flags&ICF_USE_INT)
ICCmp(tempi,0x73,0x7D,ip2);
else
ICFCmp(lx,tempi,CMP_TEMPLATE_LESS,ip2);
ICFCmp(cc,tempi,CMP_TEMPLATE_LESS,ip2);
break;
case IC_GREATER_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICCmp(tempi,0x72,0x7C,ip2);
else
ICFCmp(lx,tempi,CMP_TEMPLATE_GREATER_EQUAL,ip2);
ICFCmp(cc,tempi,CMP_TEMPLATE_GREATER_EQUAL,ip2);
break;
case IC_GREATER:
if (tempi->ic_flags&ICF_USE_INT)
ICCmp(tempi,0x76,0x7E,ip2);
else
ICFCmp(lx,tempi,CMP_TEMPLATE_GREATER,ip2);
ICFCmp(cc,tempi,CMP_TEMPLATE_GREATER,ip2);
break;
case IC_LESS_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICCmp(tempi,0x77,0x7F,ip2);
else
ICFCmp(lx,tempi,CMP_TEMPLATE_LESS_EQUAL,ip2);
ICFCmp(cc,tempi,CMP_TEMPLATE_LESS_EQUAL,ip2);
break;
case IC_AND_AND:
ICAndAnd(tempi,ip2);
@@ -639,31 +669,33 @@ lx->pass==10 is final pass, code is placed into buf.
ICShiftEqual(tempi,tempi->a1.type_pointed,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
break;
case IC_SHR_EQUAL:
ICShiftEqual(tempi,tempi->a1.type_pointed,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_MUL_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICMulEqual(tempi,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FMUL,buf,ip2);
ICFOpEqual(cc,tempi,SLASH_OP_FMUL,buf,ip2);
break;
case IC_DIV_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICDivEqual(tempi,FALSE,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FDIV,buf,ip2);
ICFOpEqual(cc,tempi,SLASH_OP_FDIV,buf,ip2);
break;
case IC_MOD_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICDivEqual(tempi,TRUE,ip2);
else
ICFModEqual(lx,tempi,ip2);
ICFModEqual(cc,tempi,ip2);
break;
case IC_AND_EQUAL:
ICAndEqual(tempi,ip2);
@@ -679,54 +711,64 @@ lx->pass==10 is final pass, code is placed into buf.
ICAddSubEctEqual(tempi,tempi->a1.type_pointed,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0x010000000003,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0x010000000003,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FADD,buf,ip2);
ICFOpEqual(cc,tempi,SLASH_OP_FADD,buf,ip2);
break;
case IC_SUB_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICAddSubEctEqual(tempi,tempi->a1.type_pointed,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,0x29000000052B,ip2);
tempi->a2.type,tempi->a2.reg,tempi->a2.disp,
0x29000000052B,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FSUB,buf,ip2);
ICFOpEqual(cc,tempi,SLASH_OP_FSUB,buf,ip2);
break;
case IC_SHL_CONST:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
TY_IMM+RT_I64,0,tempi->ic_data,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
TY_IMM+RT_I64,0,tempi->ic_data,
0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
break;
case IC_SHR_CONST:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,
TY_IMM+RT_I64,0,tempi->ic_data,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
TY_IMM+RT_I64,0,tempi->ic_data,
0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_ADD_CONST:
ICAddSubEctImm(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,tempi->ic_data,0x0003,ip2);
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,tempi->ic_data,
0x0003,ip2);
break;
case IC_SUB_CONST:
ICAddSubEctImm(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,tempi->ic_data,0x052B,ip2);
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,tempi->ic_data,
0x052B,ip2);
break;
case IC_ENTER:
ICU32(tempi,0xEC8B4855);
if (tempi->ic_data)
ICAddRSP(tempi,-tempi->ic_data,FALSE);
if (lx->htc.fun) {
if (Bt(&lx->htc.fun->flags,Ff_INTERRUPT))
ICPushRegs(tempi,REG_ALWAYS_CLOBBERED_MASK&~(1<<REG_RBP|1<<REG_RSP)|lx->htc.fun->used_reg_mask&(REG_VARS_MASK|REG_NON_PTR_MASK|REG_STK_TEMPS_MASK));
if (cc->htc.fun) {
if (Bt(&cc->htc.fun->flags,Ff_INTERRUPT))
ICPushRegs(tempi,REGG_C_CLOBBERED|cc->htc.fun->used_reg_mask&
(REGG_C_LOCAL_VARS|REGG_C_LOCAL_NON_PTR_VARS|
REGG_C_TEMP_CLOBBERED));
else {
if (sys_var_init_flag&1 && i)
ICLocalVarInit(tempi);
ICPushRegs(tempi,lx->htc.fun->used_reg_mask&(REG_VARS_MASK|REG_NON_PTR_MASK));
ICPushRegs(tempi,cc->htc.fun->used_reg_mask
&(REGG_C_LOCAL_VARS|REGG_C_LOCAL_NON_PTR_VARS));
}
for (i=0;i<NUM_REGS;i++)
if (reg_offsets[i]>0 && reg_offsets[i].offset!=MAX_I64) {
tempc=OptClassFwd(reg_offsets[i].m->member_class);
ICMov(tempi,TY_REG+RT_I64,i,0,
TY_DISP+tempc->raw_type,REG_RBP,reg_offsets[i].offset,ip2);
TY_DISP+tempc->raw_type,
REG_RBP,reg_offsets[i].offset,ip2);
}
}
break;
@@ -767,10 +809,10 @@ lx->pass==10 is final pass, code is placed into buf.
ICU24(tempi,0x01E083); //AND EAX,1
break;
case IC_RDTSC:
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_RDTSC,TRUE,FALSE,FALSE,CN_MAIN);
ICCopyTemplate(cc,tempi,CMP_TEMPLATE_RDTSC,TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_HPET:
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_HPET,TRUE,FALSE,FALSE,CN_MAIN);
ICCopyTemplate(cc,tempi,CMP_TEMPLATE_HPET,TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_SET_RFLAGS:
ICPush(tempi,tempi->a1.type,tempi->a1.reg,tempi->a1.disp,ip2);
@@ -836,7 +878,8 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_SIGN_I64:
ICMov(tempi,TY_REG+RT_I64,REG_RAX,0,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,ip2);
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_SIGN_I64,TRUE,FALSE,FALSE,CN_MAIN);
ICCopyTemplate(cc,tempi,CMP_TEMPLATE_SIGN_I64,
TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_PREEMPT:
ICPreempt(tempi,ip2);
@@ -845,34 +888,34 @@ lx->pass==10 is final pass, code is placed into buf.
ICToUpper(tempi,ip2);
break;
case IC_TO_I64:
ICToI64(lx,tempi,ip2);
ICToI64(cc,tempi,ip2);
break;
case IC_TO_F64:
ICToF64(lx,tempi,ip2);
ICToF64(cc,tempi,ip2);
break;
case IC_TO_BOOL:
ICToBool(lx,tempi,ip2);
ICToBool(cc,tempi,ip2);
break;
case IC_SQR:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_SQR,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_SQR,ip2);
break;
case IC_ABS:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_ABS,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_ABS,ip2);
break;
case IC_SQRT:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_SQRT,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_SQRT,ip2);
break;
case IC_SIN:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_SIN,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_SIN,ip2);
break;
case IC_COS:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_COS,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_COS,ip2);
break;
case IC_TAN:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_TAN,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_TAN,ip2);
break;
case IC_ATAN:
ICFTemplateFun(lx,tempi,CMP_TEMPLATE_ATAN,ip2);
ICFTemplateFun(cc,tempi,CMP_TEMPLATE_ATAN,ip2);
break;
case IC_ABS_I64:
ICMov(tempi,TY_REG+RT_I64,REG_RAX,0,
@@ -923,7 +966,7 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_STRLEN:
ICMov(tempi,TY_REG+RT_I64,REG_RAX,0,
tempi->a1.type,tempi->a1.reg,tempi->a1.disp,ip2);
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_STRLEN,TRUE,FALSE,FALSE,CN_MAIN);
ICCopyTemplate(cc,tempi,CMP_TEMPLATE_STRLEN,TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_IN_U32:
if (tempi->a1.type&TY_MASK==TY_IMM) {
@@ -1049,10 +1092,10 @@ lx->pass==10 is final pass, code is placed into buf.
}
break;
case IC_NOBOUND_SWITCH:
ICSwitch(tempi,ip,TRUE,lx,buf,ip2);
ICSwitch(tempi,ip,TRUE,cc,buf,ip2);
break;
case IC_SWITCH:
ICSwitch(tempi,ip,FALSE,lx,buf,ip2);
ICSwitch(tempi,ip,FALSE,cc,buf,ip2);
break;
case IC_NOP1:
case IC_NOP2:
@@ -1077,9 +1120,9 @@ lx->pass==10 is final pass, code is placed into buf.
case IC_ADD_RSP1:
break;
default:
"Pass:%d Missing IC handler\n",lx->pass;
ICPut(lx,tempi);
LexExcept(lx,"Compiler Optimization Error at ");
"Pass:%d Missing IC handler\n",cc->pass;
ICPut(cc,tempi);
LexExcept(cc,"Compiler Optimization Error at ");
}
if (tempi->r.type&TY_MASK) {
if (tempi->ic_flags & ICF_R_TO_F64) {
@@ -1089,12 +1132,14 @@ lx->pass==10 is final pass, code is placed into buf.
ICU24(tempi,0x1BDD48);
ICU8(tempi,0x9B);
} else {
ICFCvt(lx,tempi,REG_RAX,tempi->r.type,tempi->r.reg,tempi->r.disp,FALSE,CN_R,ip2);
ICFCvt(cc,tempi,REG_RAX,tempi->r.type,tempi->r.reg,tempi->r.disp,
FALSE,CN_R,ip2);
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+RT_I64,REG_RAX,0,ip2);
}
} else if (tempi->ic_flags & ICF_R_TO_INT) {
ICFCvt(lx,tempi,REG_RAX,tempi->r.type,tempi->r.reg,tempi->r.disp,TRUE,CN_R,ip2);
ICFCvt(cc,tempi,REG_RAX,tempi->r.type,tempi->r.reg,tempi->r.disp,
TRUE,CN_R,ip2);
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+RT_I64,REG_RAX,0,ip2);
}
@@ -1102,19 +1147,19 @@ lx->pass==10 is final pass, code is placed into buf.
}
cnt=tempi->ic_cnt;
if (tempi->ic_flags&ICF_DEL_PREVIOUS_INS) {
if (lx->pass>8)
if (cc->pass>8)
cnt=tempi->ic_last_cnt;
tempi->ic_flags&=~ICF_DEL_PREVIOUS_INS;
}
if (cnt && buf)
MemCpy(buf+ip,tempi->ic_body,cnt);
op789A_skip_copy:
if (dbg_info && lx->min_line<=tempi->ic_line<=lx->max_line) {
i=tempi->ic_line-lx->min_line;
if (dbg_info && cc->min_line<=tempi->ic_line<=cc->max_line) {
i=tempi->ic_line-cc->min_line;
if (!dbg_info->body[i])
dbg_info->body[i]=ip2;
}
if (tempi->ic_flags&ICF_TRACE && Bt(&lx->otrace_mask,lx->pass) && cnt) {
if (tempi->ic_flags&ICF_TRACE && Bt(&cc->otrace_mask,cc->pass) && cnt) {
"$$RED$$";
if (buf)
Un(buf+ip,cnt,64);
@@ -1131,8 +1176,8 @@ op789A_next:
tempi=tempi_next;
}
lb=lx->lcc.lcc_next_misc;
while (lb!=&lx->lcc.lcc_next_misc) {
lb=cc->coc.coc_next_misc;
while (lb!=&cc->coc.coc_next_misc) {
switch (lb->type) {
case CMT_STR_CONST:
lb->addr=ip;
@@ -1156,13 +1201,13 @@ op789A_next:
} else {
if (buf)
for (i=0;i<lb->range;i++) {
if (lx->flags&LF_AOT_COMPILE && !(lx->flags&LF_NO_ABSS)) {
tempa=CAlloc(sizeof(CExeAbsAddr));
tempa->next=a->abss;
tempa->type=EAT_ADD_U32;
a->abss=tempa;
tempa->ip=a->ip+lb->addr+i<<2;
*ptr(U32 *)++=lb->jmp_table[i]->addr+a->ip;
if (cc->flags&CCF_AOT_COMPILE && !(cc->flags&CCF_NO_ABSS)) {
tempa=CAlloc(sizeof(CAOTAbsAddr));
tempa->next=aotc->abss;
tempa->type=AAT_ADD_U32;
aotc->abss=tempa;
tempa->ip=aotc->ip+lb->addr+i<<2;
*ptr(U32 *)++=lb->jmp_table[i]->addr+aotc->ip;
} else
*ptr(U32 *)++=lb->jmp_table[i]->addr+buf;
}
@@ -1179,8 +1224,8 @@ op789A_next:
lb=lb->next;
}
if (dbg_info) {
if (lx->flags&LF_AOT_COMPILE)
dbg_info->body[num_lines]=ip+a->ip;
if (cc->flags&CCF_AOT_COMPILE)
dbg_info->body[num_lines]=ip+aotc->ip;
else
dbg_info->body[num_lines]=ip+buf;
}