TempleOSTS_130707.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:45 +02:00
1 parent 17b71f1a2d
commit 1343005a29
617 files changed
+14399 -25130

No files matched your search

+14 -32
View File
@@ -182,23 +182,6 @@ U0 AsmStoreCodeU8At(CLex *lx,U8 b,I64 ip)
a->num_code_U8s=ip+1;
}
U0 AsmReserveCodeTo(CLex *lx,I64 ip)
{
CAsmCtrl *a=lx->a;
I64 i=ip>>ASM_CODE_BLK_BITS+1;
CAsmCodeBlk *tempc=&a->code;
while (i--) {
if (!tempc->next) {
tempc->next=CAlloc(sizeof(CAsmCodeBlk));
tempc->next->next=NULL;
}
tempc=tempc->next;
}
if (ip>a->num_code_U8s)
a->num_code_U8s=ip;
}
I64 AsmExpressionEval(CLex *lx)
{
U8 *exp;
@@ -279,10 +262,10 @@ U0 AsmLocalsResolve(CLex *lx)
Free(tempu);
tempu=tempu1;
}
HashTableDel(lx->local_hash_table);
lx->local_hash_table=lx->hash_table_lst->next=
HashTableDel(lx->htc.local_hash_table);
lx->htc.local_hash_table=lx->htc.hash_table_lst->next=
HashTableNew(16);
lx->local_hash_table->next=lx->glbl_hash_table;
lx->htc.local_hash_table->next=lx->htc.glbl_hash_table;
a->local_unresolved=NULL;
a->has_locals=FALSE;
}
@@ -311,7 +294,7 @@ U0 AsmGlblsResolve(CLex *lx,CExe *ex)
if (tempess->type & HTT_EXPORT_SYS_SYM &&
tempess->type & HTF_UNRESOLVED &&
!(tempess->type & HTF_IMPORT) &&
(tempf=HashFind(tempess->str,lx->hash_table_lst,HTT_FUN)) &&
(tempf=HashFind(tempess->str,lx->htc.hash_table_lst,HTT_FUN)) &&
!Bt(tempf->flags,Cf_EXTERN)) {
tempess->val=tempf->executable_addr;
tempess->type&=~HTF_UNRESOLVED;
@@ -373,8 +356,8 @@ U0 AsmGlblsResolve(CLex *lx,CExe *ex)
tempu=tempu1;
}
tempess=lx->glbl_hash_table->next_added;
while (tempess!=lx->glbl_hash_table) {
tempess=lx->htc.glbl_hash_table->next_added;
while (tempess!=lx->htc.glbl_hash_table) {
if (tempess->type & HTF_IMPORT && tempess->use_cnt) {
if (tempe=tempess->ie_lst) {
if (tempess->import_name)
@@ -1310,7 +1293,7 @@ U0 PrsAsmBlk(CLex *lx)
{
CAsmCtrl *a=lx->a;
I64 i,j,k,argcnt,
old_hash_mask=lx->hash_mask,
old_hash_mask=lx->htc.hash_mask,
old_flags=lx->flags & LF_ASM_EXPRESSIONS;
CHashOpcode *tempo;
CHashExport *tempess;
@@ -1318,7 +1301,7 @@ U0 PrsAsmBlk(CLex *lx)
a->seg_size=64;
lx->flags|=LF_ASM_EXPRESSIONS;
lx->hash_mask=lx->hash_mask&~(HTF_FLAGS_MASK|HTT_FILE|HTT_INTERNAL_TYPE|HTT_MODULE)|HTT_ASM_KEYWORD;
lx->htc.hash_mask=lx->htc.hash_mask&~(HTF_FLAGS_MASK|HTT_FILE|HTT_INTERNAL_TYPE|HTT_MODULE)|HTT_ASM_KEYWORD;
if (lx->token!='{')
LexExcept(lx,"ST_EXPECTING_LEFT_BRACE");
else
@@ -1340,7 +1323,7 @@ U0 PrsAsmBlk(CLex *lx)
tempess->str=lx->ident;
lx->ident=0;
tempess->type=HTT_EXPORT_SYS_SYM|HTF_UNRESOLVED;
HashAdd(tempess,lx->glbl_hash_table);
HashAdd(tempess,lx->htc.glbl_hash_table);
tempess->type|=HTF_IMPORT;
if (Lex(lx)==',')
Lex(lx); //skip ','
@@ -1352,7 +1335,7 @@ U0 PrsAsmBlk(CLex *lx)
Lex(lx); //skip ';';
break;
case AKW_MODULE_ORG:
if (lx->local_var_lst)
if (lx->htc.local_var_lst)
LexExcept(lx,"ST_NO_FUN_ASM_ORG");
if (a->module_org!=INVALID_PTR)
LexExcept(lx,"ST_JUST_ONE_ORG_ALLOWED");
@@ -1361,7 +1344,7 @@ U0 PrsAsmBlk(CLex *lx)
a->module_org=AsmExpressionEval(lx);
break;
case AKW_ALIGN:
if (lx->local_var_lst)
if (lx->htc.local_var_lst)
LexExcept(lx,"ST_NO_FUN_ASM_ALIGN");
i=AsmExpressionEval(lx);
if (Bsf(i)!=Bsr(i))
@@ -1470,10 +1453,10 @@ U0 PrsAsmBlk(CLex *lx)
if (*tempess->str=='@' && tempess->str[1]=='@') {
if (lx->token==TK_DBL_COLON)
LexExcept(lx,"ST_NO_LOCAL_GLBL_EXPORT");
HashAdd(tempess,lx->local_hash_table);
HashAdd(tempess,lx->htc.local_hash_table);
a->has_locals=TRUE;
} else
HashAdd(tempess,lx->glbl_hash_table);
HashAdd(tempess,lx->htc.glbl_hash_table);
if (lx->token==TK_DBL_COLON) {
tempess->type|=HTF_EXPORT;
SetSrcFileInfo(lx,tempess);
@@ -1489,8 +1472,7 @@ U0 PrsAsmBlk(CLex *lx)
}
}
AsmLocalsResolve(lx);
AsmReserveCodeTo(lx,a->ip);
lx->flags&=lx->flags&~LF_ASM_EXPRESSIONS|old_flags;
lx->hash_mask=old_hash_mask;
lx->htc.hash_mask=old_hash_mask;
}
File diff suppressed because it is too large. Load diff
+5 -5
View File
@@ -2,7 +2,7 @@ asm {
USE64
CMP_OPT_NOP:
#assert CIntermediateCode.ic_opcode==0
DU16 IC_NOP; //Must be at CIntermediateCode.ic_opcode offset
DU16 IC_NOP1; //Must be at CIntermediateCode.ic_opcode offset
DU8 sizeof(CIntermediateCode)-2 DUP(0);
// ************************************
@@ -122,28 +122,28 @@ _OPTNEXT3::
MOV RAX,RCX
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_END_EXP
JB @@05
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP1
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP2
JE @@05
STOSQ
@@05: MOV RAX,U64 8[RDX]
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_END_EXP
JB @@10
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP1
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP2
JE @@10
STOSQ
@@10: MOV RAX,U64 16[RDX]
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_END_EXP
JB @@15
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP1
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP2
JE @@15
STOSQ
@@15: MOV RAX,U64 24[RDX]
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_END_EXP
JB @@20
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP1
CMP U16 CIntermediateCode.ic_opcode[RAX],IC_NOP2
JE @@20
STOSQ
+140 -153
View File
@@ -1,17 +1,17 @@
//Intermediate compiler codes
#define IC_END 0x00
#define IC_START 0x01
#define IC_NOP 0x02
#define IC_NOP1 0x02
#define IC_END_EXP 0x03
#define IC_NOP1 0x04
#define IC_NOP2 0x04
#define IC_LABEL 0x05
#define IC_CALL_START 0x06
#define IC_CALL_END 0x07
#define IC_CALL_END2 0x08
#define IC_RETURN_VAL 0x09
#define IC_RETURN_VAL2 0x0A
#define IC_IMM 0x0B
#define IC_F64 0x0C
#define IC_IMM_U64 0x0B
#define IC_IMM_F64 0x0C
#define IC_STR_CONST 0x0D
#define IC_ABS_ADDR 0x0E
#define IC_ADDR_IMPORT 0x0F
@@ -33,7 +33,7 @@
#define IC_TO_F64 0x1D
#define IC_TO_BOOL 0x1E
#define IC_TOUPPER 0x1F
#define IC_NATIVE_TYPECAST 0x20
#define IC_HOLYC_TYPECAST 0x20
#define IC_ADDR 0x21
#define IC_COM 0x22
@@ -81,168 +81,155 @@
#define IC_OR_OR 0x43
#define IC_XOR_XOR 0x44
#define IC_COLON 0x45
#define IC_QUESTION 0x46
#define IC_ASSIGN 0x45
#define IC_ASSIGN_PP 0x46
#define IC_ASSIGN_MM 0x47
#define IC_ASSIGN 0x47
#define IC_ASSIGN_PP 0x48
#define IC_ASSIGN_MM 0x49
#define IC_SHL_EQUAL 0x48
#define IC_SHR_EQUAL 0x49
#define IC_MUL_EQUAL 0x4A
#define IC_DIV_EQUAL 0x4B
#define IC_MOD_EQUAL 0x4C
#define IC_AND_EQUAL 0x4D
#define IC_OR_EQUAL 0x4E
#define IC_XOR_EQUAL 0x4F
#define IC_ADD_EQUAL 0x50
#define IC_SUB_EQUAL 0x51
#define IC_SHL_EQUAL 0x4A
#define IC_SHR_EQUAL 0x4B
#define IC_MUL_EQUAL 0x4C
#define IC_DIV_EQUAL 0x4D
#define IC_MOD_EQUAL 0x4E
#define IC_AND_EQUAL 0x4F
#define IC_OR_EQUAL 0x50
#define IC_XOR_EQUAL 0x51
#define IC_ADD_EQUAL 0x52
#define IC_SUB_EQUAL 0x53
#define IC_JMP 0x52
#define IC_SWITCH 0x53
#define IC_NOBOUND_SWITCH 0x54
#define IC_JMP 0x54
#define IC_SWITCH 0x55
#define IC_NOBOUND_SWITCH 0x56
#define IC_ADD_RSP 0x55
#define IC_ADD_RSP1 0x56
#define IC_ENTER 0x57
#define IC_PUSH_REGS 0x58
#define IC_POP_REGS 0x59
#define IC_LEAVE 0x5A
#define IC_RET 0x5B
#define IC_ADD_RSP 0x57
#define IC_ADD_RSP1 0x58
#define IC_ENTER 0x59
#define IC_PUSH_REGS 0x5A
#define IC_POP_REGS 0x5B
#define IC_LEAVE 0x5C
#define IC_RET 0x5D
#define IC_CALL 0x5C
#define IC_CALL_INDIRECT 0x5D
#define IC_CALL_INDIRECT2 0x5E
#define IC_CALL_IMPORT 0x5F
#define IC_CALL_EXTERN 0x60
#define IC_IRQ 0x61
#define IC_CALL 0x5E
#define IC_CALL_INDIRECT 0x5F
#define IC_CALL_INDIRECT2 0x60
#define IC_CALL_IMPORT 0x61
#define IC_CALL_EXTERN 0x62
#define IC_IRQ 0x63
#define IC_ASM 0x62
#define IC_CLI 0x63
#define IC_STI 0x64
#define IC_PREEMPT 0x65
#define IC_CLD 0x66
#define IC_STD 0x67
#define IC_HLT 0x68
#define IC_PUSH 0x69
#define IC_POP 0x6A
#define IC_PUSHFD 0x6B
#define IC_POPFD 0x6C
#define IC_PAUSE 0x6D
#define IC_ASM 0x64
#define IC_CLI 0x65
#define IC_STI 0x66
#define IC_PREEMPT 0x67
#define IC_CLD 0x68
#define IC_STD 0x69
#define IC_HLT 0x6A
#define IC_PUSH 0x6B
#define IC_POP 0x6C
#define IC_PUSHFD 0x6D
#define IC_POPFD 0x6E
#define IC_PAUSE 0x6F
#define IC_CLFLUSH 0x6E
#define IC_INVLPG 0x6F
#define IC_CLFLUSH 0x70
#define IC_INVLPG 0x71
#define IC_IN_U8 0x70
#define IC_IN_U16 0x71
#define IC_IN_U32 0x72
#define IC_OUT_U8 0x73
#define IC_OUT_U16 0x74
#define IC_OUT_U32 0x75
#define IC_INU8 0x72
#define IC_INU16 0x73
#define IC_INU32 0x74
#define IC_OUTU8 0x75
#define IC_OUTU16 0x76
#define IC_OUTU32 0x77
#define IC_GET_FLAGS 0x76
#define IC_CARRY 0x77
#define IC_SET_FLAGS 0x78
#define IC_GET_RAX 0x79
#define IC_SET_RAX 0x7A
#define IC_GET_BASE_PTR 0x7B
#define IC_SET_BASE_PTR 0x7C
#define IC_GET_STK_PTR 0x7D
#define IC_SET_STK_PTR 0x7E
#define IC_RIP 0x7F
#define IC_GET_FLAGS 0x78
#define IC_CARRY 0x79
#define IC_SET_FLAGS 0x7A
#define IC_GET_RAX 0x7B
#define IC_SET_RAX 0x7C
#define IC_GET_BASE_PTR 0x7D
#define IC_SET_BASE_PTR 0x7E
#define IC_GET_STK_PTR 0x7F
#define IC_SET_STK_PTR 0x80
#define IC_RIP 0x81
#define IC_RDTSC 0x80
#define IC_HPET 0x81
#define IC_RDTSC 0x82
#define IC_HPET 0x83
#define IC_BT 0x82
#define IC_BTS 0x83
#define IC_BTR 0x84
#define IC_BTC 0x85
#define IC_LBTS 0x86
#define IC_LBTR 0x87
#define IC_LBTC 0x88
#define IC_BSF 0x89
#define IC_BSR 0x8A
#define IC_BT 0x84
#define IC_BTS 0x85
#define IC_BTR 0x86
#define IC_BTC 0x87
#define IC_BEQU 0x88
#define IC_LBTS 0x89
#define IC_LBTR 0x8A
#define IC_LBTC 0x8B
#define IC_LBEQU 0x8C
#define IC_BSF 0x8D
#define IC_BSR 0x8E
#define IC_QUE_INIT 0x8B
#define IC_QUE_INS 0x8C
#define IC_QUE_INS_REV 0x8D
#define IC_QUE_REM 0x8E
#define IC_QUE_INIT 0x8F
#define IC_QUE_INS 0x90
#define IC_QUE_INS_REV 0x91
#define IC_QUE_REM 0x92
#define IC_STRLEN 0x8F
#define IC_STRLEN 0x93
#define IC_MEMCPY 0x94
#define IC_BR_ZERO 0x90
#define IC_BR_NOT_ZERO 0x91
#define IC_MEMSET 0x95
#define IC_MEMSET_U16 0x96
#define IC_MEMSET_U32 0x97
#define IC_MEMSET_U64 0x98
#define IC_BR_NOT_EQUAL 0x92
#define IC_BR_EQUAL_EQUAL 0x93
#define IC_BR_GREATER_EQUAL 0x94
#define IC_BR_LESS_EQUAL 0x95
#define IC_BR_GREATER 0x96
#define IC_BR_LESS 0x97
#define IC_BR_NOT_EQUAL2 0x98
#define IC_BR_EQUAL_EQUAL2 0x99
#define IC_BR_GREATER_EQUAL2 0x9A
#define IC_BR_LESS_EQUAL2 0x9B
#define IC_BR_GREATER2 0x9C
#define IC_BR_LESS2 0x9D
#define IC_BR_AND_ZERO 0x9E
#define IC_BR_AND_NOT_ZERO 0x9F
#define IC_BR_MM_ZERO 0xA0
#define IC_BR_MM_NOT_ZERO 0xA1
#define IC_BR_AND_AND_ZERO 0xA2
#define IC_BR_AND_AND_NOT_ZERO 0xA3
#define IC_BR_OR_OR_ZERO 0xA4
#define IC_BR_OR_OR_NOT_ZERO 0xA5
#define IC_BR_ZERO 0x99
#define IC_BR_NOT_ZERO 0x9A
#define IC_BR_BT 0xA6
#define IC_BR_BTS 0xA7
#define IC_BR_BTR 0xA8
#define IC_BR_BTC 0xA9
#define IC_BR_LBTS 0xAA
#define IC_BR_LBTR 0xAB
#define IC_BR_LBTC 0xAC
#define IC_BR_NOT_BT 0xAD
#define IC_BR_NOT_BTS 0xAE
#define IC_BR_NOT_BTR 0xAF
#define IC_BR_NOT_BTC 0xB0
#define IC_BR_NOT_LBTS 0xB1
#define IC_BR_NOT_LBTR 0xB2
#define IC_BR_NOT_LBTC 0xB3
#define IC_BR_NOT_EQUAL 0x9B
#define IC_BR_EQUAL_EQUAL 0x9C
#define IC_BR_GREATER_EQUAL 0x9D
#define IC_BR_LESS_EQUAL 0x9E
#define IC_BR_GREATER 0x9F
#define IC_BR_LESS 0xA0
#define IC_BR_NOT_EQUAL2 0xA1
#define IC_BR_EQUAL_EQUAL2 0xA2
#define IC_BR_GREATER_EQUAL2 0xA3
#define IC_BR_LESS_EQUAL2 0xA4
#define IC_BR_GREATER2 0xA5
#define IC_BR_LESS2 0xA6
#define IC_BR_AND_ZERO 0xA7
#define IC_BR_AND_NOT_ZERO 0xA8
#define IC_BR_MM_ZERO 0xA9
#define IC_BR_MM_NOT_ZERO 0xAA
#define IC_BR_AND_AND_ZERO 0xAB
#define IC_BR_AND_AND_NOT_ZERO 0xAC
#define IC_BR_OR_OR_ZERO 0xAD
#define IC_BR_OR_OR_NOT_ZERO 0xAE
#define IC_SWAP_U8 0xB4
#define IC_SWAP_U16 0xB5
#define IC_SWAP_U32 0xB6
#define IC_SWAP_U64 0xB7
#define IC_BR_BT 0xAF
#define IC_BR_BTS 0xB0
#define IC_BR_BTR 0xB1
#define IC_BR_BTC 0xB2
#define IC_BR_LBTS 0xB3
#define IC_BR_LBTR 0xB4
#define IC_BR_LBTC 0xB5
#define IC_BR_NOT_BT 0xB6
#define IC_BR_NOT_BTS 0xB7
#define IC_BR_NOT_BTR 0xB8
#define IC_BR_NOT_BTC 0xB9
#define IC_BR_NOT_LBTS 0xBA
#define IC_BR_NOT_LBTR 0xBB
#define IC_BR_NOT_LBTC 0xBC
#define IC_SWAP_U8 0xBD
#define IC_SWAP_U16 0xBE
#define IC_SWAP_U32 0xBF
#define IC_SWAP_U64 0xC0
#define IC_ABS_I64 0xC1
#define IC_SIGN_I64 0xC2
#define IC_MIN_I64 0xC3
#define IC_MIN_U64 0xC4
#define IC_MAX_I64 0xC5
#define IC_MAX_U64 0xC6
#define IC_LIMIT_I64 0xC7
#define IC_LIMIT_U64 0xC8
#define IC_MOD_U64 0xC9
#define IC_SQR_I64 0xCA
#define IC_SQR_U64 0xCB
#define IC_SQR 0xCC
#define IC_ABS 0xCD
#define IC_SQRT 0xCE
#define IC_SIN 0xCF
#define IC_COS 0xD0
#define IC_TAN 0xD1
#define IC_ATAN 0xD2
#define IC_NUM_ENTRIES 0xD3
#define IC_ABS_I64 0xB8
#define IC_SIGN_I64 0xB9
#define IC_MIN_I64 0xBA
#define IC_MIN_U64 0xBB
#define IC_MAX_I64 0xBC
#define IC_MAX_U64 0xBD
#define IC_MOD_U64 0xBE
#define IC_SQR_I64 0xBF
#define IC_SQR_U64 0xC0
#define IC_SQR 0xC1
#define IC_ABS 0xC2
#define IC_SQRT 0xC3
#define IC_SIN 0xC4
#define IC_COS 0xC5
#define IC_TAN 0xC6
#define IC_ATAN 0xC7
#define IC_NUM_ENTRIES 0xC8
//Don't forget $LK,"IC_INIT_TABLE","FA:::/TempleOS/Compiler/CmpInit.CPP,IC_INIT_TABLE"$
#define KW_INCLUDE 0
@@ -357,10 +344,9 @@
#define PREC_AND_AND 0x30
#define PREC_XOR_XOR 0x34
#define PREC_OR_OR 0x38
#define PREC_QUEST 0x3C
#define PREC_ASSIGN 0x40
#define PREC_ASSIGN 0x3C
#define PREC_MAX 0x44
#define PREC_MAX 0x40
#define CPS_IS_PUBLIC 1
#define CPS_IS_INTERRUPT 2
@@ -399,3 +385,4 @@ class COptReg
I64 offset;
CMemberLst *m;
};
+5 -3
View File
@@ -6,7 +6,7 @@ import CDoc *DocNew(CTask *task=NULL);
import Bool DocRecalc(CDoc *doc,Bool has_cursor=FALSE,I64 recalc=DOC_RECALC_ALL);
import U0 DocDel(CDoc *doc);
import U0 DocRst(CDoc *doc,Bool is_old);
import CDocEntry *DocPutLine(CDocEntry *doc_e);
import CDocEntry *DocPutLine(CDoc *doc,CDocEntry *doc_e);
import I64 DocSize(CDoc *doc);
import U8 *Doc2PlainText(CDoc *doc,CDocEntry *doc_e);
import U0 HashRep(CHashTable *h=NULL,
@@ -18,7 +18,6 @@ extern Bool GetExpression(CLex *lx,U8 **_ex);
extern I64 PrsUnaryTerm(CLex *lx,CPrsStk *ps,CMemberLst **_local_var,CArrayDim **_tempad,
I64 *max_prec,I64 *unary_pre_prec,I64 *paren_prec);
extern I64 PrsUnaryModifier(CLex *lx,CPrsStk *ps,CMemberLst **_local_var,CArrayDim **_tempad,I64 *unary_post_prec);
extern U0 PrsDereference(CLex *lx);
extern U0 LexExcept(CLex *lx,U8 *name=NULL,CHashFun *fun_class=NULL);
extern CExe *CmpJoin(CLex *lx,CHashFun *locals,Bool first_lex,Bool asm_blk=FALSE,U8 *map_name=NULL,U8 mapfile_drv=0);
extern U0 CmpFixUpJITAsm(CLex *lx,CExe *ex,I64 ip2);
@@ -31,8 +30,11 @@ extern U0 PrsVarInit2(CLex *lx,U8 **_dst,CHashClass *tempc,CArrayDim *tempad,U8
extern CHashFun *PrsFunJoin(CLex *lx,
CHashClass *temp_return,U8 *name,I64 cps_flags);
extern Bool PrsStatement(CLex *lx,CHashFun *locals,I64 try_cnt=0,
CCodeBlkMisc *lb_break=NULL,Bool saved_prs_semicolon=TRUE,Bool if_else=FALSE);
CCodeBlkMisc *lb_break=NULL,Bool saved_prs_semicolon=TRUE);
extern CIntermediateCode *OptLag1(CIntermediateCode *tempi);
extern U0 OptSetNOP1(CIntermediateCode *tempi);
extern CHashClass *OptClassFwd(CHashClass *tempc);
extern CCodeBlkMisc *OptLabelFwd(CCodeBlkMisc *lb);
extern CIntermediateCode *OptPass012(CLex *lx,CHashFun *fun_class,Bool combined);
extern U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets);
extern U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type);
+14 -28
View File
@@ -89,8 +89,8 @@ U0 AsmHashLoad(Bool first)
size1=offset(CHashOpcode.ins)+sizeof(CInstruction)<<5;
tempo=MAlloc(size1);
lx=LexNew(TextFileRead("OpCodes.TXT"),0,StrNew("OpCodes.TXT.Z"));
lx->hash_table_lst=NULL;
lx=LexNew(TextFileRead("OpCodes.TXT"),0,"OpCodes.TXT.Z");
lx->htc.hash_table_lst=NULL;
Lex(lx);
while (lx->token) {
if (lx->token!=TK_IDENT)
@@ -227,7 +227,6 @@ U0 CmpLoadDefines()
DefineLoad("ST_MISSING_EXPRESSION","missing Expression at ");
DefineLoad("ST_MISSING_RIGHT_PAREN","missing ')' at ");
DefineLoad("ST_MISSING_RIGHT_BRACKET","missing ']' at ");
DefineLoad("ST_MISSING_COLON","missing ':' at");
DefineLoad("ST_UNDEFINED_SYM","undefined sym at ");
DefineLoad("ST_UNDEFINED_SYM_LINE","undefined sym at line:");
DefineLoad("ST_UNDEFINED_IDENTIFIER","undefined identifier at ");
@@ -315,6 +314,7 @@ U0 CmpLoadDefines()
DefineLoad("ST_UNNECESSARY_PARENTHESIS","Unnecessary parenthesis");
DefineLoad("ST_STATIC_UNION","Static unions are not implemented");
DefineLoad("ST_IMPORT_HASH_TABLE_NOT_ALLOWED","import_hash_table only allowed in AOT compiled #exe{} mode.");
DefineLoad("ST_STREAM_EXE_PUTS_NOT_ALLOWED","StreamExePutS only allowed in AOT compiled #exe{} mode.");
DefineLoad("ST_CANT_INIT_GLBL_ON_HEAP","Can't init glbl var on data heap in AOT module");
DefineLoad("ST_INVALID_ARRAY_SIZE","Invalid array size at ");
DefineLoad("ST_NO_FUN_ASM_ALIGN","ALIGN not allowed in fun asm blk ");
@@ -365,17 +365,17 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
// arg cnt,result cnt,deref/assign/cmp,nonconst,might not fill result
"00..END\0"
"00..START\0"
"00..NOP\0"
"10..END_EXP\0"
"00..NOP1\0"
"10..END_EXP\0"
"00..NOP2\0"
"00..LABEL\0"
"00..CALL_START\0"
"01..CALL_END\0"
"00..CALL_END2\0"
"10..RETURN_VAL\0"
"00..RETURN_VAL2\0"
"01..IMM\0"
"01..F64\0"
"01..IMM_U64\0"
"01..IMM_F64\0"
"01.NSTR_CONST\0"
"01.NABS_ADDR\0"
"01.NADDR_IMPORT\0"
@@ -395,7 +395,7 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"10..TO_F64\0"
"10..TO_BOOL\0"
"10..TOUPPER\0"
"11..NATIVE_TYPECAST\0"
"11..HOLYC_TYPECAST\0"
"11.NADDR\0"
"11..COM\0"
"11..NOT\0"
@@ -432,8 +432,6 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"21..AND_AND\0"
"21..OR_OR\0"
"21..XOR_XOR\0"
"31..COLON\0"
"00..QUESTION\0"
"21=NASSIGN\0"
"21=NASSIGN_PP\0"
"21=NASSIGN_MM\0"
@@ -477,12 +475,12 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"00.NPAUSE\0"
"10.NCLFLUSH\0"
"10.NINVLPG\0"
"10.NINU8\0"
"10.NINU16\0"
"10.NINU32\0"
"20.NOUTU8\0"
"20.NOUTU16\0"
"20.NOUTU32\0"
"10.NIN_U8\0"
"10.NIN_U16\0"
"10.NIN_U32\0"
"20.NOUT_U8\0"
"20.NOUT_U16\0"
"20.NOUT_U32\0"
"00.NGET_FLAGS\0"
"00.NCARRY\0"
"10.NSET_FLAGS\0"
@@ -499,11 +497,9 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"20.NBTS\0"
"20.NBTR\0"
"20.NBTC\0"
"30.NBEQU\0"
"20.NLBTS\0"
"20.NLBTR\0"
"20.NLBTC\0"
"30.NLBEQU\0"
"10.NBSF\0"
"10.NBSR\0"
"10.NQUE_INIT\0"
@@ -511,11 +507,6 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"20.NQUE_INS_REV\0"
"10.NQUE_REM\0"
"10.NSTRLEN\0"
"30.NMEMCPY\0"
"30.NMEMSET\0"
"30.NMEMSET_U16\0"
"30.NMEMSET_U32\0"
"30.NMEMSET_U64\0"
"10..BR_ZERO\0"
"10..BR_NOT_ZERO\0"
"20..BR_NOT_EQUAL\0"
@@ -562,8 +553,6 @@ $AN,"Anchor for inserting Compiler Defines","COMPILE_DEFINE"$
"20..MIN_U64\0"
"20..MAX_I64\0"
"20..MAX_U64\0"
"30..LIMIT_I64\0"
"30..LIMIT_U64\0"
"20..MOD_U64\0"
"10..SQRI64\0"
"10..SQRU64\0"
@@ -727,9 +716,6 @@ U0 CmpFillTables()
d4[TK_OR_OR] =PREC_OR_OR<<16+IC_OR_OR;
d4[':'] =(PREC_QUEST+ASSOCF_LEFT)<<16+IC_COLON;
d4['?'] =(PREC_QUEST+ASSOCF_LEFT)<<16+IC_QUESTION;
d4['='] =(PREC_ASSIGN+ASSOCF_RIGHT)<<16+IC_ASSIGN;
d4[TK_SHL_EQUAL]=(PREC_ASSIGN+ASSOCF_RIGHT)<<16+IC_SHL_EQUAL;
d4[TK_SHR_EQUAL]=(PREC_ASSIGN+ASSOCF_RIGHT)<<16+IC_SHR_EQUAL;
+61 -35
View File
@@ -1,4 +1,4 @@
U0 StreamPutS(U8 *st)
U0 StreamPutS(U8 *buf)
//Inss text into the stream of
//characters being compiled. Called
//from withing #exe{} block.
@@ -6,7 +6,7 @@ U0 StreamPutS(U8 *st)
CLex *lx=Fs->last_lex;
CStreamBlk *tempe=lx->last_stream_blk;
if (tempe!=&lx->next_stream_blk)
tempe->body=StrAdd(tempe->body,st);
tempe->body=StrAdd(tempe->body,buf);
else
PrintFErr("No exe{} blk\n");
}
@@ -17,7 +17,7 @@ U0 StreamPrintF(U8 *src,...)
//from withing #exe{} block.
{
U8 *buf=SPrintFJoin(NULL,src,argc,argv);
StreamPutS(buf);
StreamPutS(buf);
Free(buf);
}
@@ -37,7 +37,7 @@ U8 *CmpStatement(CLex *lx,I64 *type)
CBICAdd(lx,IC_RETURN_VAL2,0,NULL);
CBICAdd(lx,IC_RET,0,0);
CBICAdd(lx,IC_END,0,0);
if (result=CBCompile(lx,NULL,&size,NULL,NULL,type)) {
if (result=CBCompile(lx,NULL,&size,NULL,type)) {
if (lx->flags&LF_AOT_COMPILE) {
j=lx->a->ip;
k=(size+7)>>3;
@@ -65,12 +65,8 @@ CExe *CmpJoin(CLex *lx,CHashFun *locals,Bool first_lex,Bool asm_blk=FALSE,
CAsmCodeBlk *tempc;
CExeImportExport *tempe;
Bool okay=TRUE;
CHashTable *ht1=lx->hash_table_lst,
*ht2=lx->define_hash_table,
*ht3=lx->glbl_hash_table,
*ht4=lx->local_hash_table,
*asm_hash_alias=MAllocIdentical(asm_hash);
CHashFun *old_var_lst=lx->local_var_lst;
CLexHashTableContext *htc=MAlloc(sizeof(CLexHashTableContext));
CHashTable *asm_hash_alias=MAllocIdentical(asm_hash);
CExe *result=CAlloc(sizeof(CExe));
result->parent_exe=lx->exe_struct;
lx->exe_struct=result;
@@ -83,19 +79,20 @@ CExe *CmpJoin(CLex *lx,CHashFun *locals,Bool first_lex,Bool asm_blk=FALSE,
a->max_align=1;
a->module_org=INVALID_PTR;
lx->local_hash_table=HashTableNew(16);
lx->glbl_hash_table =HashTableNew(2048);
MemCpy(htc,&lx->htc,sizeof(CLexHashTableContext));
lx->htc.local_hash_table=HashTableNew(16);
lx->htc.glbl_hash_table =HashTableNew(2048);
asm_hash_alias->next=lx->local_hash_table;
lx->local_hash_table->next=lx->glbl_hash_table;
asm_hash_alias->next=lx->htc.local_hash_table;
lx->htc.local_hash_table->next=lx->htc.glbl_hash_table;
if (lx->flags&LF_AOT_COMPILE)
lx->define_hash_table=lx->glbl_hash_table;
lx->htc.define_hash_table=lx->htc.glbl_hash_table;
else
lx->glbl_hash_table->next=Fs->hash_table;
lx->hash_table_lst =asm_hash_alias;
lx->htc.glbl_hash_table->next=Fs->hash_table;
lx->htc.hash_table_lst =asm_hash_alias;
lx->local_var_lst=locals; //C+ local vars
lx->htc.local_var_lst=locals; //Holy C local vars
try {
if (first_lex)
Lex(lx);
@@ -134,9 +131,9 @@ CExe *CmpJoin(CLex *lx,CHashFun *locals,Bool first_lex,Bool asm_blk=FALSE,
result=NULL;
} else {
if (map_name && !cmp_do_not_write_to_dsk)
HashRep(lx->glbl_hash_table,HTG_ALL,map_name,"-r-p",mapfile_drv);
HashTableDel(lx->local_hash_table);
HashTableDel(lx->glbl_hash_table);
HashRep(lx->htc.glbl_hash_table,HTG_ALL,map_name,"-r-p",mapfile_drv);
HashTableDel(lx->htc.local_hash_table);
HashTableDel(lx->htc.glbl_hash_table);
if (!a->num_code_U8s)
result->code=NULL;
@@ -170,11 +167,8 @@ CExe *CmpJoin(CLex *lx,CHashFun *locals,Bool first_lex,Bool asm_blk=FALSE,
result->module_org=a->module_org;
lx->exe_struct=result->parent_exe;
}
lx->hash_table_lst =ht1,
lx->define_hash_table=ht2;
lx->glbl_hash_table =ht3;
lx->local_hash_table =ht4;
lx->local_var_lst=old_var_lst;
MemCpy(&lx->htc,htc,sizeof(CLexHashTableContext));
Free(htc);
Free(asm_hash_alias);
Free(a);
lx->a=old_a;
@@ -189,7 +183,7 @@ CExe *CmpBuf(U8 *buf,U8 *map_name=NULL,
CExe *result=NULL;
if (!is_first_compiler)
"$$FG,PURPLE$$**** Not First Compiler ****$$FG$$\n";
lx=LexNew(buf,LF_DONT_FREE_BUF,NULL);
lx=LexNew(buf,LF_DONT_FREE_BUF);
lx->flags|=LF_AOT_COMPILE;
QueIns(lx,Fs->last_lex);
result=CmpJoin(lx,NULL,TRUE,FALSE,map_name,mapfile_drv);
@@ -501,7 +495,7 @@ I64 Cmp(U8 *filename,U8 *map_name=NULL,U8 *out_name=NULL,U8 mapfile_drv=0)
*ptr++=EIE_END;
MemSet(ptr,0,16);
i=ptr-patch_table;
//$LK,"NATIVE_XSUM","FF:::/TempleOS/Kernel/KStart.CPP,NATIVE_XSUM"$ needs 16 ALIGN
//$LK,"TEMPLEOS_XSUM","FF:::/TempleOS/Kernel/KStart.CPP,TEMPLEOS_XSUM"$ needs 16 ALIGN
size=(sizeof(CBinFile)+code_U8s+i+15)&-16;
bfh=MAlloc(size);
bfh->jmp=0xEB+256*(sizeof(CBinFile)-2);
@@ -509,7 +503,7 @@ I64 Cmp(U8 *filename,U8 *map_name=NULL,U8 *out_name=NULL,U8 mapfile_drv=0)
bfh->type=0;
bfh->loader_patch_table_offset=sizeof(CBinFile)+code_U8s;
bfh->file_size=size;
bfh->xsum=NATIVE_XSUM;
bfh->xsum=TEMPLEOS_XSUM;
MemCpy(bfh(U8 *)+sizeof(CBinFile),ex->code,code_U8s);
MemCpy(bfh(U8 *)+sizeof(CBinFile)+code_U8s,patch_table,
size-code_U8s-sizeof(CBinFile));
@@ -533,18 +527,24 @@ I64 Cmp(U8 *filename,U8 *map_name=NULL,U8 *out_name=NULL,U8 mapfile_drv=0)
return error_cnt;
}
I64 ExePutS(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE)
I64 ExePutS(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE,CLexHashTableContext *htc=NULL)
{
I64 result;
Bool okay=TRUE;
CLex *lx;
if (!filename)
filename=sys_temp_filename;
lx=LexNew(buf,LF_DONT_FREE_BUF,FileNameAbs(filename));
lx=LexNew(buf,LF_DONT_FREE_BUF,filename);
if (just_load)
lx->flags|=LF_JUST_LOAD;
if (Fs->last_lex!=&Fs->next_lex)
if (Fs->last_lex!=&Fs->next_lex) {
lx->opts=Fs->last_lex->opts;
if (htc) {
lx->flags=lx->flags &~LF_ASM_EXPRESSIONS |
htc->old_flags&LF_ASM_EXPRESSIONS;
MemCpy(&lx->htc,htc,sizeof(CLexHashTableContext));
}
}
QueIns(lx,Fs->last_lex);
try {
Lex(lx);
@@ -592,7 +592,7 @@ I64 ExePutS2(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE)
CLex *lx;
if (!filename)
filename=sys_temp_filename;
lx=LexNew(buf,LF_DONT_FREE_BUF,FileNameAbs(filename));
lx=LexNew(buf,LF_DONT_FREE_BUF,filename);
if (just_load)
lx->flags|=LF_JUST_LOAD;
if (Fs->last_lex!=&Fs->next_lex)
@@ -643,7 +643,7 @@ I64 ExePutS3(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE)
CLex *lx;
if (!filename)
filename=sys_temp_filename;
lx=LexNew(buf,LF_DONT_FREE_BUF,FileNameAbs(filename));
lx=LexNew(buf,LF_DONT_FREE_BUF,filename);
if (just_load)
lx->flags|=LF_JUST_LOAD;
if (Fs->last_lex!=&Fs->next_lex)
@@ -677,6 +677,32 @@ I64 ExeFile3(U8 *name,Bool just_load=FALSE)
return result;
}
I64 StreamExePutS(U8 *buf)
{//Suppose you want a value from the stream to be used in an #exe block...
CLexHashTableContext *htc;
I64 result=0;
CLex *lx=Fs->last_lex;
if (lx==&Fs->next_lex) {
PutErr;
"Not Compiling\n";
} else {
if (!(lx->flags&LF_EXE_BLK))
LexExcept(lx,"ST_STREAM_EXE_PUTS_NOT_ALLOWED");
if (htc=lx->htc.next)
result=ExePutS(buf,,,htc);
}
return result;
}
I64 StreamExePrintF(U8 *fmt,...)
{
I64 result;
U8 *buf=SPrintFJoin(NULL,fmt,argc,argv);
result=StreamExePutS(buf);
Free(buf);
return result;
}
U0 CmpInit()
{
if (!sys_num_installed_compilers++) {
@@ -693,7 +719,7 @@ U0 CmpInit()
MemSet(&opt_nop,0,sizeof(CIntermediateCode));
opt_nop.ic_class=sys_internal_types[IT_I64];
opt_nop.ic_opcode=IC_NOP;
opt_nop.ic_opcode=IC_NOP1;
AsmHashLoad(is_first_compiler);
UnasmHashLoad;
}
-67
View File
@@ -1,67 +0,0 @@
CQueVectU8 *QueVectU8New(I64 min_index=0)
{
CQueVectU8 *result=MAlloc(sizeof(CQueVectU8));
result->next=result->last=result;
result->total_cnt=result->node_cnt=0;
result->min_index=min_index;
return result;
}
U0 QueVectU8Put(CQueVectU8 *v,I64 index,U8 ch)
{
CQueVectU8 *tempv;
index-=v->min_index;
if (index<0) return;
if (index<v->total_cnt) {
tempv=v;
do {
index-=tempv->node_cnt;
if (index<0) {
tempv->body[index+tempv->node_cnt]=ch;
return;
}
tempv=tempv->next;
} while (tempv!=v);
} else
index-=v->total_cnt;
while (TRUE) {
tempv=v->last;
if (tempv->node_cnt>=QUE_VECT_U8_CNT) {
tempv=MAlloc(sizeof(CQueVectU8));
tempv->node_cnt=0;
QueIns(tempv,v->last);
}
if (index--) {
tempv->body[tempv->node_cnt++]=0;
v->total_cnt++;
} else {
tempv->body[tempv->node_cnt++]=ch;
v->total_cnt++;
break;
}
}
}
U0 QueVectU8Del(CQueVectU8 *v)
{
if (v) {
QueDel(v);
Free(v);
}
}
I64 QueVectU8Get(CQueVectU8 *v,I64 index)
{
CQueVectU8 *tempv;
index-=v->min_index;
if (!(0<=index<v->total_cnt)) return 0;
tempv=v;
do {
index-=tempv->node_cnt;
if (index<0)
return tempv->body[index+tempv->node_cnt];
tempv=tempv->next;
} while (tempv!=v);
return 0;
}
+3 -30
View File
@@ -71,7 +71,7 @@ U0 CBPutICArg(CICArg *p)
U0 CBPutIC(CIntermediateCode *tempi)
{
I64 opcode=tempi->ic_opcode,i;
if (opcode>=IC_END_EXP && opcode!=IC_NOP1) {
if (opcode>=IC_END_EXP && opcode!=IC_NOP2) {
"%15ts %016X ",
DefineSub(opcode,"ST_INTERMEDIATE_CODE")+4,
tempi->ic_data;
@@ -84,17 +84,10 @@ U0 CBPutIC(CIntermediateCode *tempi)
',';
if (tempi->p2.type&TY_MASK)
CBPutICArg(&tempi->p2);
',';
if (tempi->p3.type&TY_MASK)
CBPutICArg(&tempi->p3);
'' CH_SPACE;
CBPutClass(tempi->ic_class);
if (tempi->ic_flags & ICF_LOCK)
"$$FG,BROWN$$lock$$FG$$ ";
if (tempi->ic_flags & ICF_P3_TO_F64)
"$$FG,LTBLUE$$p3d$$FG$$ ";
if (tempi->ic_flags & ICF_P3_TO_INT)
"$$FG,GREEN$$p3i$$FG$$ ";
if (tempi->ic_flags & ICF_P2_TO_F64)
"$$FG,LTBLUE$$p2d$$FG$$ ";
if (tempi->ic_flags & ICF_P2_TO_INT)
@@ -157,7 +150,6 @@ CIntermediateCode *CBICAdd(CLex *lx,
flags|=ICF_LOCK;
tempi->ic_flags=flags;
tempi->ic_line=lx->last_line_num;
tempi->ic_indent_level=lx->indent_level;
if (lx->opts & OPTF_PARSE_TRACE)
CBPutIC(tempi);
tempi++;
@@ -382,28 +374,12 @@ U0 CBCombine(CLex *lx)
}
}
CIndentInfo *CBIndents(CLex *lx)
{
CIndentInfo *result;
I64 i,num_lines=lx->max_line-lx->min_line+1;
result=CAlloc(offset(CIndentInfo.body)+sizeof(U8)*(num_lines+1));
result->min_line=lx->min_line;
result->max_line=lx->max_line;
for (i=0;i<num_lines;i++)
result->body[i]=QueVectU8Get(lx->indent_que_vect,i+lx->min_line);
return result;
}
U8 *CBCompile(CLex *lx,CHashFun *fun_class,
I64 *code_size,CDbgInfo **_dbg,CIndentInfo **_indent,I64 *type=NULL)
I64 *code_size,CDbgInfo **_dbg,I64 *type=NULL)
{
U8 *result;
COptReg register_offsets[NUM_REGS];
if (_dbg)
*_dbg=NULL;
if (_indent)
*_indent=NULL;
if (_dbg) *_dbg=NULL;
CBCombine(lx);
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT)) {
if (Bt(&lx->pass_trace_mask,0)) {
@@ -489,9 +465,6 @@ U8 *CBCompile(CLex *lx,CHashFun *fun_class,
*code_size=OptPass789A(lx,fun_class,register_offsets,result,_dbg);
compiled_bytes+=*code_size;
if (_indent && lx->indent_que_vect)
*_indent=CBIndents(lx);
LinkedLstDel(lx->cbh.cb_out_first);
CBMiscLstDel(lx);
if (Bt(&lx->opts,OPTf_COMPILE_TRACE)) {
Binary file not shown.
+9 -3
View File
@@ -15,6 +15,7 @@ public extern U8 *LexExtStr(CLex *lx,I64 *_size=NULL);
public extern U0 LexPutLine(CLex *lx,U8 *start);
public extern U0 LexPutPos(CLex *lx);
public extern U0 LexPutWarn(CLex *lx,U8 *name=NULL,CHashFun *fun_class=NULL);
public extern I64 PrsKeyWord(CLex *lx);
public extern U0 LexExcept(CLex *lx,U8 *name=NULL,CHashFun *fun_class=NULL);
public extern U8 *CmpExpression(CLex *lx,I64 *type=NULL);
public extern U8 *CmpStatement(CLex *lx,I64 *type);
@@ -26,12 +27,16 @@ extern U0 MemberLstDel(CHashClass *c);
public extern CMemberLstMeta *MemberMetaFind(U8 *st,CMemberLst *ml);
public extern CMemberLst *MemberFind(U8 *st,CHashClass *c);
public extern CMemberLst *MemberFind2(CHashClass *pattern,CHashClass *tempc);
public extern U0 LexIncludeDoc(CLex *lx,U8 *filename,CDoc *_doc);
public extern U0 LexAttachDoc(CLex *lx,CLexFile *tempf=NULL,
CDoc *doc=NULL,U8 *abs_filename=NULL,CDocEntry *doc_e=NULL,I64 col=0);
public extern CHashClass *OptClassFwd(CHashClass *tempc);
#help_index "Compiler/Directive"
#help_file "::/TempleOS/Doc/Directives"
public extern U0 StreamPutS(U8 *st);
public extern U0 StreamPutS(U8 *buf);
public extern U0 StreamPrintF(U8 *src,...);
public extern I64 StreamExePutS(U8 *buf);
public extern I64 StreamExePrintF(U8 *fmt,...);
public extern Bool PTrace(Bool val);
public extern Bool OTrace(Bool val);
public extern I64 OPassTraceMask(I64 i=0b1001111101);
@@ -58,7 +63,8 @@ public extern I64 HashTableSize2(CHashTable *table);
public extern I64 Cmp(U8 *filename,U8 *map_name=NULL,U8 *out_name=NULL,U8 mapfile_drv=0);
#help_index "Compiler"
public extern I64 ExePutS(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE);
public extern I64 ExePutS(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE,
CLexHashTableContext *htc=NULL);
public extern I64 ExePrintF(U8 *fmt,...);
public extern I64 ExeFile(U8 *name,Bool just_load=FALSE);
public extern I64 ExePutS2(U8 *buf,U8 *filename=NULL,Bool just_load=FALSE);
File diff suppressed because it is too large. Load diff
-1
View File
@@ -5,7 +5,6 @@
#include "CmpAsm"
#include "CmpExts"
#include "CmpGlbls"
#include "CmpQueVect"
#include "Unassembler"
#include "Directives"
#include "Lex"
+11 -10
View File
@@ -55,20 +55,21 @@ Bool IsReplaceSyms() {
U0 ImportHashTable(CHashTable *src)
{ //called from #exe {} in AOT modules
// See $LK-A,"::/TempleOS/Kernel/AOTAdam.HPP"$.
// See $LK-A,"::/TempleOS/Kernel/AOTAdam.HPP"$.
CLex *lx=Fs->last_lex;
if (lx==&Fs->next_lex) {
PutErr;
"Not Compiling\n";
}
if (!(lx->flags&LF_EXE_BLK))
LexExcept(lx,"ST_IMPORT_HASH_TABLE_NOT_ALLOWED");
while (src) {
if (lx->stream_parent_glbl_hash_table)
HashTableImport(src,lx->stream_parent_glbl_hash_table);
else
HashTableImport(src,lx->glbl_hash_table);
src=src->next;
} else {
if (!(lx->flags&LF_EXE_BLK))
LexExcept(lx,"ST_IMPORT_HASH_TABLE_NOT_ALLOWED");
while (src) {
if (lx->htc.next && lx->htc.next->glbl_hash_table)
HashTableImport(src,lx->htc.next->glbl_hash_table);
else if (lx->htc.glbl_hash_table)
HashTableImport(src,lx->htc.glbl_hash_table);
src=src->next;
}
}
}
File diff suppressed because it is too large. Load diff
+1 -4
View File
@@ -7,7 +7,6 @@ CHashSrcSym *HashEntryImportCopy(CHashSrcSym *temph)
result->index=NULL;
result->ie_lst=NULL;
result->debug=NULL;
result->indent=NULL;
if (temph->type & (HTT_FUN | HTT_CLASS)) {
result(CHashClass *)->member_lst =MemberLstCopy(temph);
result(CHashClass *)->member_lst2=temph(CHashClass *)->member_lst2;
@@ -111,10 +110,8 @@ I64 HashEntrySize2(CHashSrcSym *temph)
result+=MSize2(temph->index);
result+=MSize2(temph->import_name);
result+=LinkedLstSize(temph->ie_lst);
if (temph->type & (HTT_FUN | HTT_EXPORT_SYS_SYM)) {
if (temph->type & (HTT_FUN | HTT_EXPORT_SYS_SYM))
result+=MSize2(temph->debug);
result+=MSize2(temph->indent);
}
if (temph->type & HTT_CLASS)
result+=MemberLstSize(temph);
else if (temph->type & HTT_FUN) {
+56 -72
View File
@@ -18,7 +18,7 @@ U8 *CmpPmt(Bool dbl_semicolon=FALSE)
st=MGetS(GETSF_SHIFT_ESC_EXIT);
if (dbl_semicolon) {
i=StrLen(st);
result=MAlloc(i+4);
result=MAlloc(i+1+2);
MemCpy(result,st,i+1);
i--;
while (i>=0 && Bt(white_space_bitmap,result[i]))
@@ -26,8 +26,7 @@ U8 *CmpPmt(Bool dbl_semicolon=FALSE)
i++;
if (i>0 && result[i-1]==';')
result[i++]=';'; //The Lex goes one beyond
result[i++]=13;//#define goes to <cr>
result[i++]=10;
result[i++]='\n';//#define goes to '\n'
result[i]=0;
} else
result=StrNew(st);
@@ -43,20 +42,19 @@ CLex *LexNew(U8 *buf,I64 flags,U8 *filename=NULL)
QueInit(lx);
lx->flags=flags;
lx->opts=1<<OPTf_WARN_UNUSED_VAR;
lx->expression_start_line_num=lx->last_line_num=1;
lx->pass_trace_mask=0b10001111101;
lx->hash_mask=HTG_ALL-HTT_IMPORT_SYS_SYM-HTT_ASM_KEYWORD;
lx->define_hash_table=lx->hash_table_lst=lx->glbl_hash_table=lx->local_hash_table=Fs->hash_table;
lx->htc.hash_mask=HTG_ALL-HTT_IMPORT_SYS_SYM-HTT_ASM_KEYWORD;
lx->htc.define_hash_table=lx->htc.hash_table_lst=lx->htc.glbl_hash_table=lx->htc.local_hash_table=Fs->hash_table;
if (flags&LF_KEEP_AT_SIGN)
lx->alpha_numeric_bitmap=alpha_numeric_no_at_bitmap;
else
lx->alpha_numeric_bitmap=alpha_numeric_bitmap;
lx->cur_lfn=tempf;
QueInit(&lx->next_stream_blk);
if (!filename)
tempf->name=StrNew(sys_temp_filename);
if (filename)
tempf->name=FileNameAbs(filename);
else
tempf->name=filename;
tempf->name=StrNew(sys_temp_filename);
if (flags & LF_PMT)
buf=CAlloc(4);
tempf->buf=tempf->buf_ptr=tempf->line_start=lx->cur_buf_ptr=buf;
@@ -75,11 +73,11 @@ U0 LexDel(CLex *lx)
Free(tempf->name);
tempf--;
}
LinkedLstDel(lx->htc.next);
Free(tempf->name);
if (!(lx->flags & LF_DONT_FREE_BUF))
Free(tempf->buf);
Free(lx->ident);
QueVectU8Del(lx->indent_que_vect);
Free(lx->dollar);
Free(lx);
}
@@ -194,7 +192,7 @@ lgc_here2:
tempf->cur_entry=doc_e;
nobound_switch (doc_e->type_u8) {
case DOCT_TEXT:
if (doc_e->flags1 & ~(DOCG_BL_IV_UL|DOCEF1_WORD_WRAP|DOCEF1_HIGHLIGHT|DOCEF1_LOCK_TO_PAGE|DOCEF1_LOCK_TO_CENTER|DOCEF1_SKIP|DOCEF1_HARD_SKIP|DOCEF1_FILTER_SKIP) &&
if (doc_e->flags1 & ~(DOCEF1_DEFINE|DOCEF1_TAG_CB|DOCG_BL_IV_UL|DOCEF1_WORD_WRAP|DOCEF1_HIGHLIGHT|DOCEF1_LOCK_TO_PAGE|DOCEF1_LOCK_TO_CENTER|DOCEF1_SKIP|DOCEF1_HARD_SKIP|DOCEF1_FILTER_SKIP) &&
LexDollar(lx,doc,doc_e) && *(src=lx->dollar)) {
tempf->line_num=doc_e->y+1;
tempf->buf=tempf->buf_ptr=lx->cur_buf_ptr=src;
@@ -299,7 +297,8 @@ lgc_here2:
if (!cont) break;
}
if (doc_e==doc) {
DocDel(doc);
if (tempf!=&lx->lfns[0] || !(lx->flags&LF_DONT_FREE_BUF))
DocDel(doc);
tempf->doc=tempf->buf=NULL;
Free(tempf->name);
tempf->name=NULL;
@@ -327,7 +326,8 @@ lgc_here:
lx->cur_buf_ptr=tempf->line_start=
tempf->buf_ptr=tempf->buf=CmpPmt(TRUE);
} else {
lx->cur_buf_ptr=src-1;
if (src)
lx->cur_buf_ptr=src-1;
lx->last_U16=TK_EOF;
goto lgc_done;
}
@@ -374,8 +374,7 @@ U0 ExpressionDel(U8 *code)
Free(code);
}
U0 LexIncludeStr(CLex *lx,U8 *abs_fname,
U8 *src,Bool actual_file)
U0 LexIncludeStr(CLex *lx,U8 *abs_filename,U8 *src,Bool actual_file)
{
CLexFile *tempf;
LexBackupLastChar(lx);
@@ -386,7 +385,7 @@ U0 LexIncludeStr(CLex *lx,U8 *abs_fname,
tempf->line_start=src;
tempf->last_U16=0;
if (actual_file) {
tempf->name=StrNew(abs_fname);
tempf->name=StrNew(abs_filename);
tempf->flags=LFSF_IS_INCLUDED;
} else {
tempf->name=StrNew(sys_temp_filename);
@@ -405,14 +404,14 @@ I64 doc_stop_btypes[(DOCT_NUM_TYPES+63)/64]=
};
CDoc *LexDocRead(U8 *abs_fname,I64 flags)
CDoc *LexDocRead(U8 *abs_filename,I64 flags)
{
CDoc *doc=DocNew;
U8 *src;
I64 size=0;
doc->flags|=flags;
StrCpy(doc->filename.name,abs_fname);
src=FileRead(abs_fname,&size);
StrCpy(doc->filename.name,abs_filename);
src=FileRead(abs_filename,&size);
if (!src || !size) {
Free(src);
src=CAlloc(1);
@@ -423,27 +422,28 @@ CDoc *LexDocRead(U8 *abs_fname,I64 flags)
return doc;
}
U0 LexIncludeDoc(CLex *lx,U8 *abs_fname,CDoc *_doc)
{ //If doc==null load
Bool is_null;
CDocEntry *doc_e;
CLexFile *tempf;
CDoc *doc;
LexBackupLastChar(lx);
tempf=++lx->cur_lfn;
U0 LexAttachDoc(CLex *lx,CLexFile *tempf=NULL,
CDoc *doc=NULL,U8 *abs_filename=NULL,CDocEntry *doc_e=NULL,I64 col=0)
{//Give either doc or abs_filename.
if (!doc)
doc=LexDocRead(abs_filename,DOCF_DBL_DOLLARS);
if (!tempf) {
LexBackupLastChar(lx);
tempf=++lx->cur_lfn;
}
if (!doc_e)
doc_e=doc->root.next;
tempf->name=StrNew(doc->filename.name);
tempf->line_start=&lex_zeros;
if (_doc)
doc=_doc;
else
doc=LexDocRead(abs_fname,DOCF_DBL_DOLLARS);
tempf->doc=doc;
doc_e=doc->root.next;
while (doc_e!=doc) {
if (Bt(doc_stop_btypes,doc_e->type_u8))
break;
doc_e=doc_e->next;
col=doc_e->min_col;
}
if (doc_e!=doc) {
col=LimitI64(col,doc_e->min_col,doc_e->max_col);
tempf->line_start=doc_e;
tempf->line_num=doc_e->y+1;
if (doc_e->type_u8==DOCT_TEXT) {
@@ -455,23 +455,16 @@ U0 LexIncludeDoc(CLex *lx,U8 *abs_fname,CDoc *_doc)
tempf->buf=&lex_zeros;
tempf->buf_ptr=&lex_zeros;
}
is_null=FALSE;
} else
is_null=TRUE;
if (!abs_fname)
tempf->name=StrNew(sys_temp_filename);
else
tempf->name=StrNew(abs_fname);
if (is_null) {
// DocDel(lx); TODO
tempf->flags=LFSF_IS_INCLUDED|LFSF_IS_DOC;
} else { //TODO: DocDel(doc)?
col=0;
tempf->flags=LFSF_IS_INCLUDED;
tempf->buf=CAlloc(1);
tempf->buf_ptr=&lex_zeros;
tempf->line_num=1;
} else
tempf->flags=LFSF_IS_INCLUDED|LFSF_IS_DOC;
}
lx->cur_buf_ptr=tempf->buf_ptr+col;
tempf->last_U16=0;
lx->cur_buf_ptr=tempf->buf_ptr;
}
U0 LexPush(CLex *lx)
@@ -711,7 +704,7 @@ I64 LexInStr(CLex *lx,
buf[i++]='\n';
break;
case 'r':
buf[i++]=CH_CARRIAGE_RETURN;
buf[i++]='\r';
break;
case '"':
buf[i++]='"';
@@ -799,14 +792,6 @@ I64 Lex(CLex *lx)
CHash *temph;
Bool str_done,neg_e;
U8 *fbuf,*buf2,*buf3,buf[LEX_MAX_IDENT];
if (lx->cur_lfn==lx->fun_lfn && lx->indent_que_vect) {
i=lx->temp_indent_level;
// if (lx->flags&LF_INSIDE_EXPRESSION &&
// lx->fun_lfn->line_num>lx->expression_start_line_num)
// i+=2;
QueVectU8Put(lx->indent_que_vect,lx->last_line_num,i);
}
lx->temp_indent_level=lx->indent_level;
lx->last_line_num=lx->cur_lfn->line_num;
while (TRUE) {
lex_cont:
@@ -854,13 +839,13 @@ lex_ident:
}
buf[i++]=0;
temph=NULL;
if (lx->local_var_lst)
lx->local_var_entry=MemberFind(buf,lx->local_var_lst);
if (lx->htc.local_var_lst)
lx->local_var_entry=MemberFind(buf,lx->htc.local_var_lst);
else
lx->local_var_entry=NULL;
if (!lx->local_var_entry && lx->hash_table_lst)
if (!lx->local_var_entry && lx->htc.hash_table_lst)
temph=HashFind(buf,
lx->hash_table_lst,lx->hash_mask);
lx->htc.hash_table_lst,lx->htc.hash_mask);
if (temph)
j=temph->type;
else
@@ -1020,7 +1005,7 @@ lex_float_start:
k.u8[j]='\n';
break;
case 'r':
k.u8[j]=CH_CARRIAGE_RETURN;
k.u8[j]='\r';
break;
case '"':
k.u8[j]='"';
@@ -1086,7 +1071,6 @@ lex_octal:
default:
lx->flags|=LF_USE_LAST_U16;
k.u8[j]='\\';
break;
}
} else if (ch=='$$') {
ch=LexGetChar(lx);
@@ -1121,7 +1105,7 @@ lex_octal:
buf2=FileNameAbs(fbuf);
Free(fbuf);
if (Bt(&sys_run_level,RLf_DOC))
LexIncludeDoc(lx,buf2,NULL);
LexAttachDoc(lx,,,buf2);
else
LexIncludeStr(lx,buf2,TextFileRead(buf2),TRUE);
Free(buf2);
@@ -1144,10 +1128,10 @@ lex_octal:
do {
if (ch=='\\') {
if (ch=LexGetChar(lx)) {
if (ch!=CH_CARRIAGE_RETURN && ch!='\n') {
if (ch!='\r' && ch!='\n') {
buf[j++]='\\';
buf[j++]=ch;
} else if (ch==CH_CARRIAGE_RETURN && LexGetChar(lx)!='\n')
} else if (ch=='\r' && LexGetChar(lx)!='\n')
lx->flags|=LF_USE_LAST_U16;
} else {
buf[j++]='\\';
@@ -1206,9 +1190,9 @@ lex_octal:
temph(CHashDefineStr *)->data=buf2;
temph(CHashDefineStr *)->cnt=-1;
if (IsReplaceSyms)
HashReplace(temph,lx->define_hash_table);
HashReplace(temph,lx->htc.define_hash_table);
else
HashAdd(temph,lx->define_hash_table);
HashAdd(temph,lx->htc.define_hash_table);
}
lx->flags&=~LF_NO_DEFINES;
break;
@@ -1253,11 +1237,11 @@ lex_if:
case TK_IF: goto lex_if;
case TK_IFDEF: goto lex_ifdef;
case TK_IFNDEF: goto lex_ifndef;
case TK_IFAOT: goto lex_ifaot;
case TK_IFJIT: goto lex_ifjit;
case TK_IFAOT: goto lex_ifaot;
case TK_IFJIT: goto lex_ifjit;
case TK_ELSE: goto lex_else;
case TK_ENDIF: goto lex_cont;
default: goto lex_end;
default: goto lex_end;
}
} else {
lx->flags&=~LF_IN_IF;
@@ -1449,9 +1433,9 @@ lex_ifjit:
temph->type=HTT_HELP_FILE|HTF_PUBLIC;
SetSrcFileInfo(lx,temph);
if (IsReplaceSyms)
HashReplace(temph,lx->glbl_hash_table);
HashReplace(temph,lx->htc.glbl_hash_table);
else
HashAdd(temph,lx->glbl_hash_table);
HashAdd(temph,lx->htc.glbl_hash_table);
break;
}
break;
@@ -1631,15 +1615,15 @@ U8 *LexPutLine(CLex *lx,U8 *start)
U8 *ptr,ch;
if (!start) return NULL;
if (lx->cur_lfn->flags&LFSF_IS_DOC)
return DocPutLine(start);
return DocPutLine(lx->cur_lfn->doc,start);
else {
ptr=start;
while (ch=*ptr++) {
if (ch=='\n') {
if (*ptr==CH_CARRIAGE_RETURN)
if (*ptr=='\r')
ptr++;
break;
} else if (ch==CH_CARRIAGE_RETURN) {
} else if (ch=='\r') {
if (*ptr=='\n')
ptr++;
break;
+2 -2
View File
@@ -164,8 +164,8 @@ KEYWORD import 26;
KEYWORD _import 27;
KEYWORD ifdef 28;
KEYWORD ifndef 29;
KEYWORD ifaot 30;
KEYWORD ifjit 31;
KEYWORD ifaot 30;
KEYWORD ifjit 31;
KEYWORD endif 32;
KEYWORD assert 33;
KEYWORD reg 34;
File diff suppressed because it is too large. Load diff
+73 -106
View File
@@ -1,8 +1,7 @@
I64 CmpType(CHashClass *tempc)
{
if (tempc) {
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempc);
return tempc->sub_type;
}
return 0;
@@ -13,8 +12,7 @@ I64 CmpPType(CHashClass *tempc)
if (tempc) {
if (tempc->ptr_cnt)
tempc--;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempc);
return tempc->sub_type;
}
return 0;
@@ -28,7 +26,7 @@ U0 CmpF1PushPop(CIntermediateCode *tempi,CIntermediateCode *tempi2)
U0 CmpF2PushPop(CIntermediateCode *tempi,CIntermediateCode *tempi1,CIntermediateCode *tempi2)
{
if ((tempi2->ic_opcode==IC_MOV || tempi2->ic_opcode==IC_F64) &&
if ((tempi2->ic_opcode==IC_MOV || tempi2->ic_opcode==IC_IMM_F64) &&
!(tempi2->ic_flags&ICF_R_TO_F64) &&
(Bt(fpop_bitmap,tempi1->ic_opcode) || tempi1->ic_flags&ICF_R_TO_F64))
Bts(&tempi->ic_flags,ICf_DONT_PUSH_FLOAT0);
@@ -50,11 +48,11 @@ I64 OptMVCompare(OptMemberVar *mv1,OptMemberVar *mv2)
U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
{
CHashClass *tempc,*tempc1,*tempc2,*tempc3;
CHashClass *tempc,*tempc1,*tempc2;
CCodeBlkMisc *lb;
CIntermediateCode *tempi,*tempi1,*tempi2,*tempi3,
*tempil1,*tempil2,
*temp_lag[4];
CIntermediateCode *tempi,*tempi1,*tempi2,
*tempil1,*tempil2,
*temp_lag[4];
I64 code,i,j,l,member_cnt,used_reg_mask=0;
CMemberLst *tempm;
CPrsStk *ps=OptStart(lx,temp_lag);
@@ -71,17 +69,15 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
member_cnt=0;
tempm=fun_class->member_lst;
while (tempm) {
tempc=tempm->member_class;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempm->member_class);
if (0<=tempm->register<NUM_REGS) {
if (Bts(&used_reg_mask,tempm->register))
PrintFWarn("%S\n $$LK-A,\"FL:%s,%d\"$$ '%s' in '%s'\n","ST_REG_IN_USE",
lx->cur_lfn->name,lx->cur_lfn->line_num,tempm->str,fun_class->str);
lx->cur_lfn->name,lx->cur_lfn->line_num,tempm->str,fun_class->str);
register_offsets[tempm->register].offset=tempm->offset;
register_offsets[tempm->register].m=tempm;
} else if (tempc->sub_type!=IT_F64 && tempm->register!=CREG_NONE ||
tempm->register==CREG_ALLOC) {
tempm->register==CREG_ALLOC) {
if (tempm->register==CREG_ALLOC)
mv[member_cnt].score=MAX_I64/2; //big but not too big
mv[member_cnt].offset=tempm->offset;
@@ -89,7 +85,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
} else {
if (tempm->register==CREG_ALLOC)
PrintFWarn("%S\n $$LK-A,\"FL:%s,%d\"$$ '%s' in '%s'\n","ST_CANT_REG_VAR",
lx->cur_lfn->name,lx->cur_lfn->line_num,tempm->str,fun_class->str);
lx->cur_lfn->name,lx->cur_lfn->line_num,tempm->str,fun_class->str);
}
tempm=tempm->next;
}
@@ -100,7 +96,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
if (tempi->ic_opcode==IC_START)
tempi++;
while (code=tempi->ic_opcode) {
if (code!=IC_NOP) {
if (code!=IC_NOP1) {
OptNext(tempi,temp_lag);
tempil1=temp_lag[1];
tempil2=temp_lag[2];
@@ -109,17 +105,6 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case 9:
ps->ptr-=tempi->ic_data>>3;
break;
case 3:
tempi3=PrsPop(ps);
if (tempi3->ic_flags&ICF_R_TO_F64)
tempc3=sys_internal_types[IT_F64];
else if (tempi3->ic_flags & ICF_R_TO_INT)
tempc3=sys_internal_types[IT_I64];
else
tempc3=tempi->t.p3c;
tempi->p3.type=TY_STK+CmpType(tempc3);
tempi->p3.ptype=CmpPType(tempc3);
tempi->ic_flags|=ICF_P3_WAS_STK;
case 2:
tempi2=PrsPop(ps);
if (tempi2->ic_flags&ICF_R_TO_F64)
@@ -153,20 +138,20 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
PrsPush(ps,tempi);
}
nobound_switch (code) {
case IC_F64:
case IC_IMM_F64:
tempi->ic_flags&=~ICF_R_TO_F64;
if (tempi->ic_flags&ICF_R_TO_INT) {
tempi->ic_data=ToI64(tempi->ic_data(F64));
tempi->ic_flags&=~ICF_R_TO_INT;
tempi->ic_opcode=IC_IMM;
tempi->ic_opcode=IC_IMM_U64;
}
break;
case IC_IMM:
case IC_IMM_U64:
tempi->ic_flags&=~ICF_R_TO_INT;
if (tempi->ic_flags&ICF_R_TO_F64) {
tempi->ic_data(F64)=ToF64(tempi->ic_data);
tempi->ic_flags&=~ICF_R_TO_F64;
tempi->ic_opcode=IC_F64;
tempi->ic_opcode=IC_IMM_F64;
}
break;
case IC_STR_CONST:
@@ -183,7 +168,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
break;
case IC_REG:
case IC_COM:
case IC_NATIVE_TYPECAST:
case IC_HOLYC_TYPECAST:
case IC_NOT:
case IC_UNARY_MINUS:
break;
@@ -191,29 +176,29 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
tempi->p1.ptype=tempi->r.type&IT_MASK;
if (tempi1->ic_opcode==IC_LEA) {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP;
tempi->p1.reg=tempi1->p1.reg;
tempi->p1.disp=tempi1->p1.disp;
tempi->p1.type=TY_DISP+tempi->r.type&IT_MASK;
tempi->p1.ptype=tempi->r.ptype;
tempi->ic_opcode=IC_MOV;
OptSetNOP1(tempi1);
if (tempi->p1.reg==CREG_RBP)
for (i=0;i<member_cnt;i++)
if (mv[i].offset==tempi->p1.disp) {
mv[i].lea_balance--;
mv[i].score+=1+tempi->ic_indent_level;
mv[i].score++;
break;
}
} else if (tempil1->ic_opcode==IC_ADD_CONST) {
} else if (tempil1->ic_opcode==IC_ADD_CONST) {
if (tempil2->ic_opcode==IC_REG) {
tempi->ic_flags|=tempil2->ic_flags|tempil1->ic_flags;
tempil2->ic_opcode=IC_NOP;
tempil1->ic_opcode=IC_NOP;
tempi->p1.reg=tempil2->p1.reg;
tempi->p1.disp=tempi->ic_data;
tempi->p1.type=TY_DISP+tempi->r.type&IT_MASK;
tempi->p1.ptype=tempi->r.ptype;
tempi->ic_opcode=IC_MOV;
OptSetNOP1(tempil2);
OptSetNOP1(tempil1);
}
}
break;
@@ -225,12 +210,12 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_DEREF_PP:
case IC_DEREF_MM:
if (tempi1->ic_opcode==IC_LEA &&
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
for (i=0;i<member_cnt;i++)
if (mv[i].offset==tempi1->p1.disp) {
mv[i].lea_balance--;
mv[i].score+=1+tempi->ic_indent_level;
mv[i].score++;
break;
}
tempi->p1.ptype=tempi->r.type&IT_MASK;
@@ -258,17 +243,16 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
}
if (OptFixupBinaryOp2(&tempi1,&tempi2)) {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP;
if (tempi->t.p1t!=tempi2)
tempi->t.p1c=tempi->t.p2c;
tempi->ic_data=tempi1->ic_data;
tempi->ic_opcode=IC_ADD_CONST;
tempi->p1.ptype=tempi->r.type&IT_MASK;
tempi->p2.type=TY_NULL;
OptSetNOP1(tempi1);
if (tempil2->ic_opcode==IC_REG &&
tempil2->p1.reg==CREG_RBP) {
tempil2->p1.reg==CREG_RBP) {
tempi->ic_flags|=tempil2->ic_flags;
tempil2->ic_opcode=IC_NOP;
tempi->ic_opcode=IC_LEA;
tempi->p1.reg=CREG_RBP;
tempi->p1.type=TY_DISP+tempi->p1.type&IT_MASK;
@@ -276,10 +260,11 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
for (i=0;i<member_cnt;i++)
if (mv[i].offset==tempi->ic_data) {
mv[i].lea_balance++;
mv[i].score+=1+tempi->ic_indent_level;
mv[i].score++;
break;
}
}
OptSetNOP1(tempil2);
}
}
break;
case IC_SUB:
@@ -287,12 +272,12 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
CmpF2PushPop(tempi,tempi1,tempi2);
break;
}
if (tempi2->ic_opcode==IC_IMM) {
if (tempi2->ic_opcode==IC_IMM_U64) {
tempi->ic_flags|=tempi2->ic_flags;
tempi2->ic_opcode=IC_NOP;
tempi->ic_data=tempi2->ic_data;
tempi->ic_opcode=IC_SUB_CONST;
tempi->p2.type=TY_NULL;
OptSetNOP1(tempi2);
}
break;
case IC_LESS:
@@ -307,7 +292,6 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_AND_AND:
case IC_OR_OR:
case IC_XOR_XOR:
case IC_COLON:
break;
case IC_MUL_EQUAL:
@@ -326,15 +310,15 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_OR_EQUAL:
case IC_XOR_EQUAL:
if (tempi1->ic_opcode==IC_LEA &&
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
for (i=0;i<member_cnt;i++)
if (mv[i].offset==tempi1->p1.disp) {
mv[i].lea_balance--;
mv[i].score+=1+tempi->ic_indent_level;
mv[i].score++;
break;
}
tempi->p1.ptype=tempi->r.type&IT_MASK;
tempi->p1.ptype=tempi->r.type&IT_MASK;
tempi->r.ptype=CmpPType(tempi->t.p1c);
break;
case IC_RETURN_VAL:
@@ -397,11 +381,9 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_BTS:
case IC_BTR:
case IC_BTC:
case IC_BEQU:
case IC_LBTS:
case IC_LBTR:
case IC_LBTC:
case IC_LBEQU:
case IC_BSF:
case IC_BSR:
case IC_PREEMPT:
@@ -411,8 +393,6 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_TO_F64:
case IC_TO_BOOL:
case IC_ABS_I64:
case IC_LIMIT_I64:
case IC_LIMIT_U64:
case IC_MIN_I64:
case IC_MAX_I64:
case IC_MIN_U64:
@@ -428,46 +408,36 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_QUE_INS:
case IC_QUE_INS_REV:
case IC_QUE_REM:
case IC_MEMCPY:
case IC_MEMSET:
case IC_MEMSET_U16:
case IC_MEMSET_U32:
case IC_MEMSET_U64:
case IC_INU32:
case IC_INU16:
case IC_INU8:
case IC_IN_U32:
case IC_IN_U16:
case IC_IN_U8:
case IC_STRLEN:
case IC_OUTU32:
case IC_OUTU16:
case IC_OUTU8:
case IC_OUT_U32:
case IC_OUT_U16:
case IC_OUT_U8:
case IC_ASM:
break;
case IC_NOBOUND_SWITCH:
case IC_SWITCH:
lb=tempi->ic_data;
lb=lb->dft;
while (lb->fwd)
lb=lb->fwd;
lb=OptLabelFwd(tempi->ic_data(CCodeBlkMisc *)->dft);
lb->flags|=CBMF_USED;
break;
case IC_BR_ZERO:
case IC_BR_NOT_ZERO:
if (tempi1->ic_opcode==IC_IMM ||
tempi1->ic_opcode==IC_F64) {
tempi1->ic_opcode=IC_NOP;
tempi->p1.type=TY_NULL;
tempi1->r.type=TY_NULL;
if (code==IC_BR_ZERO ^^ tempi1->ic_data)
if (tempi1->ic_opcode==IC_IMM_U64 || tempi1->ic_opcode==IC_IMM_F64) {
if (code==IC_BR_ZERO ^^ tempi1->ic_data) {
OptSetNOP1(tempi1);
tempi->p1.type=TY_NULL;
tempi->ic_opcode=IC_JMP;
else {
tempi->ic_opcode=IC_NOP;
tempi->ic_class=NULL;
} else {
OptSetNOP1(tempi1);
OptSetNOP1(tempi);
break;
}
}
goto here1;
case IC_BR_AND_ZERO:
if (tempi1->ic_opcode==IC_IMM) {
if (tempi1->ic_opcode==IC_IMM_U64) {
i=Bsr(tempi1->ic_data);
if (0<=i==Bsf(tempi1->ic_data)) {
tempi1->ic_data=i;
@@ -476,7 +446,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
goto here1;
}
}
if (tempi2->ic_opcode==IC_IMM) {
if (tempi2->ic_opcode==IC_IMM_U64) {
i=Bsr(tempi2->ic_data);
if (0<=i==Bsf(tempi2->ic_data)) {
tempi2->ic_data=i;
@@ -486,7 +456,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
}
goto here1;
case IC_BR_AND_NOT_ZERO:
if (tempi1->ic_opcode==IC_IMM) {
if (tempi1->ic_opcode==IC_IMM_U64) {
i=Bsr(tempi1->ic_data);
if (0<=i==Bsf(tempi1->ic_data)) {
tempi1->ic_data=i;
@@ -495,7 +465,7 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
goto here1;
}
}
if (tempi2->ic_opcode==IC_IMM) {
if (tempi2->ic_opcode==IC_IMM_U64) {
i=Bsr(tempi2->ic_data);
if (0<=i==Bsf(tempi2->ic_data)) {
tempi2->ic_data=i;
@@ -507,12 +477,12 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_BR_MM_ZERO:
case IC_BR_MM_NOT_ZERO:
if (tempi1->ic_opcode==IC_LEA &&
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP)
for (i=0;i<member_cnt;i++)
if (mv[i].offset==tempi1->p1.disp) {
mv[i].lea_balance--;
mv[i].score+=1+tempi->ic_indent_level;
mv[i].score++;
break;
}
tempi->p1.ptype=CmpType(tempc);
@@ -548,19 +518,18 @@ U0 OptPass3(CLex *lx,CHashFun *fun_class,COptReg *register_offsets)
case IC_BR_NOT_LBTC:
case IC_JMP:
here1:
lb=tempi->ic_data;
if (!(tempi->ic_flags&ICF_PUSH_CMP))
while (lb->fwd)
lb=lb->fwd;
if (tempi->ic_flags&ICF_PUSH_CMP)
lb=tempi->ic_data;
else
lb=OptLabelFwd(tempi->ic_data);
lb->flags|=CBMF_USED;
break;
case IC_LEAVE:
case IC_RET:
break;
case IC_ADDR:
case IC_NOP:
case IC_NOP1:
case IC_END:
case IC_QUESTION:
case IC_IRQ:
case IC_END_EXP:
case IC_CALL_END:
@@ -570,7 +539,7 @@ here1:
case IC_POP_REGS:
case IC_LABEL:
break;
case IC_NOP1:
case IC_NOP2:
ps->ptr+=tempi->ic_data;
break;
@@ -583,7 +552,7 @@ here1:
if (fun_class) {
fun_class->used_reg_mask=fun_class->used_reg_mask&~(CREG_VARS_MASK|CREG_NON_PTR_MASK)|used_reg_mask;
if (!Bt(&lx->opts,OPTf_NO_REG_VAR) &&
!(lx->flags & LF_NO_REG_OPT)) {
!(lx->flags & LF_NO_REG_OPT)) {
QSort(mv,member_cnt,sizeof(OptMemberVar),&OptMVCompare);
while (member_cnt && !mv[member_cnt-1].score)
member_cnt--;
@@ -595,7 +564,7 @@ here1:
} else {
if (mv[i].m->register==CREG_ALLOC)
PrintFWarn("%S\n $$LK-A,\"FL:%s,%d\"$$ '%s' in '%s'\n","ST_CANT_REG_VAR",
lx->cur_lfn->name,lx->cur_lfn->line_num,mv[i].m->str,fun_class->str);
lx->cur_lfn->name,lx->cur_lfn->line_num,mv[i].m->str,fun_class->str);
}
}
if (j>0) {
@@ -603,12 +572,10 @@ here1:
l=0;
for (i=0;i<j && l<num_non_ptr_vars;i++) {
tempm=mv[i].m;
tempc=tempm->member_class;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempm->member_class);
if (!tempc->ptr_cnt && !tempm->dim.next) {
while (l<num_non_ptr_vars &&
Bts(&fun_class->used_reg_mask,to_non_ptr_vars_map[l]))
Bts(&fun_class->used_reg_mask,to_non_ptr_vars_map[l]))
l++;
if (l<num_non_ptr_vars) {
tempm->register=to_non_ptr_vars_map[l++];
@@ -616,8 +583,8 @@ here1:
register_offsets[tempm->register].m=tempm;
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT))
"Fun:%s\nReg %Z Var \"%s\" %08X[RBP]\n",
fun_class->str,tempm->register,"ST_U64_REGS",
tempm->str,register_offsets[tempm->register].offset;
fun_class->str,tempm->register,"ST_U64_REGS",
tempm->str,register_offsets[tempm->register].offset;
mv[i].offset=0; //flag as reg var
}
}
@@ -626,11 +593,11 @@ here1:
l=0;
for (i=0;i<j && l<num_reg_vars;i++) {
tempm=mv[i].m;
//if not just flagged as reg var
//if not just flagged as reg var
if (mv[i].offset && (!mv[i].m->dim.next||
tempm->offset>0 && StrCmp(tempm->str,"argv"))) {
tempm->offset>0 && StrCmp(tempm->str,"argv"))) {
while (l<num_reg_vars &&
Bts(&fun_class->used_reg_mask,to_reg_vars_map[l]))
Bts(&fun_class->used_reg_mask,to_reg_vars_map[l]))
l++;
if (l<num_reg_vars) {
tempm->register=to_reg_vars_map[l++];
@@ -638,7 +605,7 @@ here1:
register_offsets[tempm->register].m=tempm;
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT))
"Reg %Z Var \"%s\" %08X[RBP]\n",tempm->register,"ST_U64_REGS",
tempm->str,register_offsets[tempm->register].offset;
tempm->str,register_offsets[tempm->register].offset;
}
}
}
+98 -228
View File
@@ -3,7 +3,7 @@ Bool OptIC4(CIntermediateCode *tempi)
I64 i,ty,pt,ty1,pt1;
CIntermediateCode *tempil1,*tempil2;
if (tempi->ic_opcode<IC_IMM) return FALSE;
if (tempi->ic_opcode<IC_IMM_U64) return FALSE;
tempil1=tempi;
if (!(tempil2=OptLag1(tempil1)))
@@ -20,13 +20,11 @@ Bool OptIC4(CIntermediateCode *tempi)
if (MIN_I32<=i<=MAX_I32 &&
!Bt(&non_ptr_vars_mask,tempil2->p1.reg)) {
tempil1->ic_flags|=tempil2->ic_flags&ICF_NO_CVT_MASK;
tempil2->ic_opcode=IC_NOP;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
tempil1->ic_opcode=IC_LEA;
tempil1->p1.type=TY_DISP+tempil1->p1.type&IT_MASK;
tempil1->p1.reg=tempil2->p1.reg;
tempil1->p1.disp=i;
OptSetNOP1(tempil2);
return TRUE;
}
} else if (tempil2->ic_opcode==IC_SHL_CONST &&
@@ -36,9 +34,6 @@ Bool OptIC4(CIntermediateCode *tempi)
tempil2->p1.reg!=CREG_RSP &&
1<=tempil2->ic_data<=3) {
tempil1->ic_flags|=tempil2->ic_flags&ICF_NO_CVT_MASK;
tempil2->ic_opcode=IC_NOP;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
tempil1->ic_opcode=IC_LEA;
tempil1->p1.type=TY_SIB+tempil1->p1.type&IT_MASK;
tempil1->p1.reg=tempil2->p1.reg<<8+CREG_NONE;
@@ -49,52 +44,13 @@ Bool OptIC4(CIntermediateCode *tempi)
else
tempil1->p1.reg|=0xC000;
tempil1->p1.disp=i;
OptSetNOP1(tempil2);
return TRUE;
}
}
}
if (tempil2->ic_opcode==IC_MOV ||
tempil2->ic_opcode==IC_REG) {
if (tempil1->p3.type&TY_MASK==TY_STK) {
if (tempil2->ic_flags & ICF_R_TO_INT) {
if (tempil2->p1.type&TY_MASK==TY_IMM)
tempil2->p1.disp=tempil2->p1.disp(F64);
else
tempil1->ic_flags|=ICF_P3_TO_INT;
} else if (tempil2->ic_flags&ICF_R_TO_F64) {
if (tempil2->p1.type&TY_MASK==TY_IMM)
tempil2->p1.disp(F64)=tempil2->p1.disp;
else
tempil1->ic_flags|=ICF_P3_TO_F64;
}
ty=tempil1->p3.type&IT_MASK;
ty1=tempil2->p1.type&IT_MASK;
if (ty1 && ty1<ty)
ty=ty1;
ty1=tempil2->r.type&IT_MASK;
if (ty1 && ty1<ty)
ty=ty1;
tempil1->p3.type=tempil2->p1.type&TY_MASK+ty;
pt=tempil1->p3.ptype;
pt1=tempil2->p1.ptype;
if (pt1 && pt1<pt && pt!=IT_F64)
pt=pt1;
pt1=tempil2->r.ptype;
if (pt1 && pt1<pt && pt!=IT_F64)
pt=pt1;
tempil1->p3.ptype=pt;
tempil1->p3.reg=tempil2->p1.reg;
tempil1->p3.disp=tempil2->p1.disp;
tempil1->ic_flags|=tempil2->ic_flags&ICF_NO_CVT_MASK;
tempil2->ic_opcode=IC_NOP1;
tempil2->ic_data=1;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
return TRUE;
}
if (tempil1->p2.type&TY_MASK==TY_STK) {
if (tempil2->ic_flags & ICF_R_TO_INT) {
if (tempil2->p1.type&TY_MASK==TY_IMM)
@@ -129,10 +85,7 @@ Bool OptIC4(CIntermediateCode *tempi)
tempil1->p2.reg=tempil2->p1.reg;
tempil1->p2.disp=tempil2->p1.disp;
tempil1->ic_flags|=tempil2->ic_flags&ICF_NO_CVT_MASK;
tempil2->ic_opcode=IC_NOP1;
tempil2->ic_data=1;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
OptSetNOP2(tempil2);
return TRUE;
}
if (tempil1->p1.type&TY_MASK==TY_STK) {
@@ -172,10 +125,7 @@ Bool OptIC4(CIntermediateCode *tempi)
tempil1->p1.reg=tempil2->p1.reg;
tempil1->p1.disp=tempil2->p1.disp;
tempil1->ic_flags|=tempil2->ic_flags&ICF_NO_CVT_MASK;
tempil2->ic_opcode=IC_NOP1;
tempil2->ic_data=1;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
OptSetNOP2(tempil2);
return TRUE;
}
}
@@ -187,25 +137,22 @@ Bool OptIC4(CIntermediateCode *tempi)
if (MIN_I32<=i<=MAX_I32 &&
!Bt(&non_ptr_vars_mask,tempil2->p1.reg)) {
tempil1->ic_flags|=tempil2->ic_flags;
tempil2->ic_opcode=IC_NOP1;
tempil2->ic_data=-1;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
tempil1->ic_opcode=IC_MOV;
tempil1->p1.type=TY_DISP+tempil1->p1.ptype;
tempil1->p1.reg=tempil2->p1.reg;
tempil1->p1.disp=i;
OptSetNOP2(tempil2,-1);
return TRUE;
}
}
if (tempil2->ic_opcode==IC_LEA &&
tempil1->p1.type&TY_MASK==TY_STK) {
tempil1->ic_flags|=tempil2->ic_flags;
tempil2->ic_opcode=IC_NOP;
tempil1->ic_opcode=IC_MOV;
tempil1->p1.type=tempil2->p1.type&TY_MASK+tempil1->p1.ptype;
tempil1->p1.reg=tempil2->p1.reg;
tempil1->p1.disp=tempil2->p1.disp;
OptSetNOP1(tempil2);
return TRUE;
}
}
@@ -225,7 +172,7 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
{
CHashClass *tempc,*tempc1,*tempc2,*tempc3;
CIntermediateCode *tempi,*tempi1,*tempi2,*tempi3,*tempil1,*tempil2,*tempil3,
*temp_lag[4];
*temp_lag[4];
I64 code,i;
CPrsStk *ps=OptStart(lx,temp_lag);
Bool dead_code=FALSE;
@@ -240,7 +187,7 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
while (code=tempi->ic_opcode) {
OptNext2(tempi,temp_lag);
if (dead_code&&code!=IC_LABEL)
tempi->ic_opcode=IC_NOP;
OptSetNOP1(tempi);
else {
tempc=tempi->ic_class;
@@ -269,13 +216,13 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
break;
}
nobound_switch (code) {
case IC_IMM:
case IC_IMM_U64:
case IC_TYPE:
tempi->p1.type=TY_IMM+IT_I64;
tempi->p1.disp=tempi->ic_data;
tempi->ic_opcode=IC_MOV;
break;
case IC_F64:
case IC_IMM_F64:
tempi->p1.type=TY_IMM+IT_I64;
tempi->p1.disp=tempi->ic_data;
tempi->p1.ptype=IT_F64;
@@ -290,14 +237,14 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
case IC_RBP:
case IC_REG:
case IC_COM:
case IC_NATIVE_TYPECAST:
case IC_HOLYC_TYPECAST:
case IC_NOT:
case IC_UNARY_MINUS:
case IC_PUSH_CMP:
break;
case IC_MOV:
if (tempi->p1.type&TY_MASK==TY_DISP &&
tempi->p1.reg==CREG_RBP) {
tempi->p1.reg==CREG_RBP) {
i=CmpOffset2Reg(tempi->p1.disp,register_offsets);
if (i>=0) {
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
@@ -309,38 +256,36 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
case IC_DEREF:
if (tempi1->ic_opcode==IC_LEA) {
if (tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP) {
tempi1->p1.reg==CREG_RBP) {
i=CmpOffset2Reg(tempi1->p1.disp,register_offsets);
if (i>=0) {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP;
tempi->ic_opcode=IC_REG;
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=i;
tempi->p1.disp=0;
OptSetNOP1(tempi1);
}
}
} else if ((tempi1->ic_opcode==IC_ABS_ADDR ||
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
if (tempi1->ic_opcode==IC_ABS_ADDR)
tempi->p1.disp=tempi1->ic_data;
else
tempi->p1.disp=tempi1->p1.disp;
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
tempi->ic_opcode=IC_MOV;
tempi->p1.type=TY_RIP_DISP32+tempi->p1.ptype;
tempi->p1.reg=CREG_RIP;
OptSetNOP1(tempi1);
}
break;
case IC_BR_MM_ZERO:
case IC_BR_MM_NOT_ZERO:
//(branch ++ to zero is unlikely)
//(branch ++ to zero is unlikely)
case IC_DEREF_PP:
case IC_DEREF_MM:
case IC__PP:
@@ -349,53 +294,47 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
case IC_MM_:
if (tempi1->ic_opcode==IC_LEA) {
if (tempi1->p1.type&TY_MASK==TY_DISP &&
tempi1->p1.reg==CREG_RBP) {
tempi1->p1.reg==CREG_RBP) {
i=CmpOffset2Reg(tempi1->p1.disp,register_offsets);
if (i>=0) {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->r.type=TY_NULL;
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=i;
tempi->p1.disp=0;
tempi->ic_flags|=ICF_NOT_ADDR;
OptSetNOP2(tempi1);
} else
goto lea_gone;
} else {
lea_gone:
lea_gone:
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->r.type=TY_NULL;
tempi->p1.type=tempi1->p1.type;
tempi->p1.reg=tempi1->p1.reg;
tempi->p1.disp=tempi1->p1.disp;
tempi->ic_flags|=ICF_NOT_ADDR;
OptSetNOP2(tempi1);
}
} else if ((tempi1->ic_opcode==IC_ABS_ADDR ||
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
tempi->ic_flags|=tempi1->ic_flags;
if (tempi1->ic_opcode==IC_ABS_ADDR)
tempi->p1.disp=tempi1->ic_data;
else
tempi->p1.disp=tempi1->p1.disp;
tempi1->ic_opcode=IC_NOP;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
tempi->p1.type=TY_RIP_DISP32+tempi->p1.ptype;
tempi->p1.reg=CREG_RIP;
tempi->ic_flags|=ICF_NOT_ADDR;
OptSetNOP1(tempi1);
}
break;
case IC_ADD:
if (tempi1->ic_opcode==IC_MOV && tempi1->p1.type==TY_REG+IT_I64 ||
tempi1->ic_opcode==IC_REG) {
tempi1->ic_opcode==IC_REG) {
if (tempi2->ic_opcode==IC_MOV && tempi2->p1.type==TY_REG+IT_I64 ||
tempi2->ic_opcode==IC_REG) {
tempi2->ic_opcode==IC_REG) {
if (tempi2->p1.reg!=CREG_RSP) {
tempi->p1.disp=0;
tempi->p1.reg=tempi1->p1.reg+tempi2->p1.reg<<8;
@@ -404,14 +343,9 @@ U0 OptPass4(CLex *lx,COptReg *register_offsets,I64 *_type)
tempi->p1.disp=0;
tempi->p1.reg=tempi2->p1.reg+tempi1->p1.reg<<8;
sib:
tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
tempi->ic_flags|=tempi2->ic_flags&ICF_NO_CVT_MASK;
tempi2->ic_opcode=IC_NOP;
tempi->ic_flags|=(tempi1->ic_flags|tempi2->ic_flags)&ICF_NO_CVT_MASK;
OptSetNOP2(tempi1);
OptSetNOP1(tempi2);
tempi->ic_opcode=IC_LEA;
tempi->p1.type=TY_SIB+IT_I64;
@@ -420,7 +354,7 @@ sib:
tempi->p2.type=TY_NULL+tempi->p2.type&IT_MASK;
}
} else if (tempi2->ic_opcode==IC_SHL_CONST && tempi2->p1.type==TY_REG+IT_I64 &&
tempi2->ic_data<=3) {
tempi2->ic_data<=3) {
if (tempi2->p1.reg!=CREG_RSP) {
tempi->p1.disp=0;
tempi->p1.reg=tempi1->p1.reg+tempi2->p1.reg<<8;
@@ -437,7 +371,7 @@ sib:
if (tempi1->p1.reg==CREG_RBP && CmpOffset2Reg(tempi1->p1.disp,register_offsets)>=0)
break;
if (tempi2->ic_opcode==IC_MOV && tempi2->p1.type==TY_REG+IT_I64 ||
tempi2->ic_opcode==IC_REG) {
tempi2->ic_opcode==IC_REG) {
if (tempi2->p1.reg!=CREG_RSP) {
tempi->p1.disp=tempi1->p1.disp;
tempi->p1.reg=tempi1->p1.reg+tempi2->p1.reg<<8;
@@ -448,7 +382,7 @@ sib:
goto sib;
}
} else if (tempi2->ic_opcode==IC_SHL_CONST && tempi2->p1.type==TY_REG+IT_I64 &&
tempi2->ic_data<=3) {
tempi2->ic_data<=3) {
if (tempi2->p1.reg!=CREG_RSP) {
tempi->p1.disp=tempi1->p1.disp;
tempi->p1.reg=tempi1->p1.reg+tempi2->p1.reg<<8;
@@ -485,12 +419,11 @@ sib:
case IC_AND_AND:
case IC_OR_OR:
case IC_XOR_XOR:
case IC_COLON:
break;
case IC_ASSIGN_PP:
case IC_ASSIGN_MM:
//this val was stashed during pass012 for pointer arithmetic
tempi->ic_class2=tempi->t.p3c;
//this val was stashed during pass012 for pointer arithmetic
tempi->ic_class2=tempi->t.class2;
case IC_ASSIGN:
case IC_SHL_EQUAL:
case IC_SHR_EQUAL:
@@ -508,53 +441,40 @@ sib:
i=CmpOffset2Reg(tempi1->p1.disp,register_offsets);
if (i>=0) {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL;
tempi1->r.type=TY_NULL;
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=i;
tempi->p1.disp=0;
OptSetNOP2(tempi1);
} else {
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->r.type=TY_NULL;
tempi1->p1.type=TY_NULL;
tempi->p1.type=TY_DISP+tempi->p1.type&IT_MASK;
tempi->p1.reg=CREG_RBP;
tempi->p1.disp=tempi1->p1.disp;
OptSetNOP2(tempi1);
}
} else {
tempi->p1.type=tempi1->p1.type&TY_MASK+tempi->p1.type&IT_MASK;
tempi->ic_flags|=tempi1->ic_flags;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->r.type=TY_NULL;
tempi1->p1.type=TY_NULL;
tempi->p1.reg=tempi1->p1.reg;
tempi->p1.disp=tempi1->p1.disp;
OptSetNOP2(tempi1);
}
tempi->ic_flags|=ICF_NOT_ADDR;
}
} else if ((tempi1->ic_opcode==IC_ABS_ADDR ||
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
tempi1->ic_opcode==IC_MOV &&
tempi1->p1.type==TY_IMM+IT_I64 &&
0<=tempi1->p1.disp<=MAX_I32) &&
!(tempi1->ic_flags&ICF_NO_RIP)) {
tempi->ic_flags|=tempi1->ic_flags;
if (tempi1->ic_opcode==IC_ABS_ADDR)
tempi->p1.disp=tempi1->ic_data;
else
tempi->p1.disp=tempi1->p1.disp;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
tempi1->r.type=TY_NULL;
tempi->p1.type=TY_RIP_DISP32+tempi->p1.type&IT_MASK;
tempi->p1.reg=CREG_RIP;
tempi->ic_flags|=ICF_NOT_ADDR;
OptSetNOP2(tempi1);
}
break;
case IC_ADD_CONST:
@@ -631,8 +551,6 @@ sib:
case IC_TAN:
case IC_ATAN:
case IC_ABS_I64:
case IC_LIMIT_I64:
case IC_LIMIT_U64:
case IC_MIN_I64:
case IC_MAX_I64:
case IC_MIN_U64:
@@ -648,26 +566,20 @@ sib:
case IC_QUE_INS:
case IC_QUE_INS_REV:
case IC_QUE_REM:
case IC_MEMCPY:
case IC_MEMSET:
case IC_MEMSET_U16:
case IC_MEMSET_U32:
case IC_MEMSET_U64:
case IC_INU32:
case IC_INU16:
case IC_INU8:
case IC_IN_U32:
case IC_IN_U16:
case IC_IN_U8:
case IC_STRLEN:
case IC_OUTU32:
case IC_OUTU16:
case IC_OUTU8:
case IC_OUT_U32:
case IC_OUT_U16:
case IC_OUT_U8:
case IC_NOBOUND_SWITCH:
case IC_SWITCH:
case IC_RET:
case IC_END:
case IC_ADDR:
case IC_QUESTION:
case IC_IRQ:
case IC_NOP:
case IC_NOP1:
case IC_CALL_START:
case IC_LEAVE:
case IC_PUSH_REGS:
@@ -697,95 +609,53 @@ sib:
case IC_LBTS:
case IC_LBTR:
case IC_LBTC:
if (tempi2->ic_opcode==IC_ADDR &&
!(tempi->ic_flags&ICF_NOT_ADDR)) {
if (tempi2->p1.type&TY_MASK==TY_STK &&
tempi2->r.type&TY_MASK==TY_STK) {
if (!(tempil2=OptLag1(tempi2)) ||
tempil2->ic_opcode!=IC_ABS_ADDR &&
!(tempil2->ic_opcode==IC_MOV &&
tempil2->p1.type==TY_IMM+IT_I64 &&
0<=tempil2->p1.disp<=MAX_I32) ||
tempil2->ic_flags&ICF_NO_RIP)
tempil2=NULL;
else {
if (tempil2->ic_opcode==IC_ABS_ADDR)
tempi->p2.disp=tempil2->ic_data;
else
if (!(tempi->ic_flags&ICF_NOT_ADDR)) {
if (tempi2->ic_opcode==IC_ADDR) {
if (tempi2->p1.type&TY_MASK==TY_STK &&
tempi2->r.type&TY_MASK==TY_STK) {
if (!(tempil2=OptLag1(tempi2)) ||
tempil2->ic_opcode!=IC_ABS_ADDR &&
!(tempil2->ic_opcode==IC_MOV &&
tempil2->p1.type==TY_IMM+IT_I64 &&
0<=tempil2->p1.disp<=MAX_I32) ||
tempil2->ic_flags&ICF_NO_RIP)
tempil2=NULL;
else {
if (tempil2->ic_opcode==IC_ABS_ADDR)
tempi->p2.disp=tempil2->ic_data;
else
tempi->p2.disp=tempil2->p1.disp;
}
} else {
if (tempi2->p1.type==TY_IMM+IT_I64 &&
0<=tempi2->p1.disp<=MAX_I32 &&
!(tempi2->ic_flags&ICF_NO_RIP)) {
tempil2=tempi2;
tempi2=NULL;
tempi->p2.disp=tempil2->p1.disp;
} else
tempil2=NULL;
}
} else {
if (tempi2->p1.type==TY_IMM+IT_I64 &&
if (tempil2) {
if (tempi2) {
tempi->ic_flags|=tempi2->ic_flags;
OptSetNOP1(tempi2);
}
tempi->ic_flags|=tempil2->ic_flags|ICF_NOT_ADDR;
tempi->p2.type=TY_RIP_DISP32+tempi->p2.type&IT_MASK;
tempi->p2.reg=CREG_RIP;
OptSetNOP1(tempil2);
}
} else if (tempi2->ic_opcode==IC_MOV &&
tempi2->r.type&TY_MASK==TY_STK &&
tempi2->p1.type==TY_IMM+IT_I64 &&
0<=tempi2->p1.disp<=MAX_I32 &&
!(tempi2->ic_flags&ICF_NO_RIP)) {
tempil2=tempi2;
tempi2=NULL;
tempi->p2.disp=tempil2->p1.disp;
} else
tempil2=NULL;
}
if (tempil2) {
if (tempi2) {
tempi->ic_flags|=tempi2->ic_flags;
tempi2->ic_opcode=IC_NOP;
tempi2->ic_flags=0;
tempi2 ->p1.type=TY_NULL+tempi2 ->p1.type&IT_MASK;
tempi2 ->r .type=TY_NULL+tempi2 ->r .type&IT_MASK;
}
tempi->ic_flags|=tempil2->ic_flags|ICF_NOT_ADDR;
tempil2->ic_opcode=IC_NOP;
tempil2->ic_flags=0;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r .type=TY_NULL+tempil2->r .type&IT_MASK;
tempi->p2.disp=tempi2->p1.disp;
tempi->ic_flags|=tempi2->ic_flags|ICF_NOT_ADDR;
tempi->p2.type=TY_RIP_DISP32+tempi->p2.type&IT_MASK;
tempi->p2.reg=CREG_RIP;
}
}
break;
case IC_BEQU:
case IC_LBEQU:
if (tempi3->ic_opcode==IC_ADDR &&
!(tempi->ic_flags&ICF_NOT_ADDR)) {
if (tempi3->p1.type&TY_MASK==TY_STK &&
tempi3->r.type&TY_MASK==TY_STK) {
if (!(tempil3=OptLag1(tempi3)) ||
tempil3->ic_opcode!=IC_ABS_ADDR &&
!(tempil3->ic_opcode==IC_MOV &&
tempil3->p1.type==TY_IMM+IT_I64 &&
0<=tempil3->p1.disp<=MAX_I32) ||
tempil3->ic_flags&ICF_NO_RIP)
tempil3=NULL;
else {
if (tempil3->ic_opcode==IC_ABS_ADDR)
tempi->p3.disp=tempil3->ic_data;
else
tempi->p3.disp=tempil3->p1.disp;
}
} else {
if (tempi3->p1.type==TY_IMM+IT_I64 &&
0<=tempi3->p1.disp<=MAX_I32 &&
!(tempi3->ic_flags&ICF_NO_RIP)) {
tempil3=tempi3;
tempi3=NULL;
tempi->p3.disp=tempil3->p1.disp;
} else
tempil3=NULL;
}
if (tempil3) {
if (tempi3) {
tempi->ic_flags|=tempi3->ic_flags;
tempi3->ic_opcode=IC_NOP;
tempi3->ic_flags=0;
tempi3 ->p1.type=TY_NULL+tempi3 ->p1.type&IT_MASK;
tempi3 ->r .type=TY_NULL+tempi3 ->r .type&IT_MASK;
}
tempi->ic_flags|=tempil3->ic_flags|ICF_NOT_ADDR;
tempil3->ic_opcode=IC_NOP;
tempil3->ic_flags=0;
tempil3->p1.type=TY_NULL+tempil3->p1.type&IT_MASK;
tempil3->r .type=TY_NULL+tempil3->r .type&IT_MASK;
tempi->p3.type=TY_RIP_DISP32+tempi->p3.type&IT_MASK;
tempi->p3.reg=CREG_RIP;
OptSetNOP1(tempi2);
}
}
break;
@@ -818,7 +688,7 @@ sib:
case IC_JMP:
dead_code=TRUE;
break;
case IC_NOP1:
case IC_NOP2:
ps->ptr+=tempi->ic_data;
break;
case IC_CALL_END2:
@@ -827,7 +697,7 @@ sib:
case IC_END_EXP:
if (tempi->p1.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=CREG_RAX;
tempi->p1.disp=0;
+3 -53
View File
@@ -8,7 +8,7 @@ U0 OptPass5(CLex *lx)
if (tempi->ic_opcode==IC_START)
tempi++;
while (code=tempi->ic_opcode) {
if (code>IC_NOP1) {
if (code>IC_NOP2) {
if (tempi->ic_flags&ICF_TRACE) {
if (Bt(&lx->pass_trace_mask,5)) {
"%2d:",ps->ptr;
@@ -28,50 +28,6 @@ U0 OptPass5(CLex *lx)
ps->ptr--;
}
if (tempi->p3.type&TY_MASK==TY_STK) {
tempi1=PrsPop(ps);
if (tempi1->ic_opcode==IC_MOV ||
tempi1->ic_opcode==IC_REG) {
if (tempi1->ic_flags & ICF_R_TO_INT) {
if (tempi1->p1.type&TY_MASK==TY_IMM)
tempi1->p1.disp=tempi1->p1.disp(F64);
else
tempi->ic_flags|=ICF_P3_TO_INT;
} else if (tempi1->ic_flags&ICF_R_TO_F64) {
if (tempi1->p1.type&TY_MASK==TY_IMM)
tempi1->p1.disp(F64)=tempi1->p1.disp;
else
tempi->ic_flags|=ICF_P3_TO_F64;
}
ty=tempi->p3.type&IT_MASK;
ty1=tempi1->p1.type&IT_MASK;
if (ty1 && ty1<ty)
ty=ty1;
ty1=tempi1->r.type&IT_MASK;
if (ty1 && ty1<ty)
ty=ty1;
tempi->p3.type=tempi1->p1.type&TY_MASK+ty;
pt=tempi->p3.ptype;
pt1=tempi1->p1.ptype;
if (pt1 && pt1<pt && pt!=IT_F64)
pt=pt1;
pt1=tempi1->r.ptype;
if (pt1 && pt1<pt && pt!=IT_F64)
pt=pt1;
tempi->p3.ptype=pt;
tempi->p3.reg=tempi1->p1.reg;
tempi->p3.disp=tempi1->p1.disp;
tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
}
}
if (tempi->p2.type&TY_MASK==TY_STK) {
tempi1=PrsPop(ps);
if (tempi1->ic_opcode==IC_MOV ||
@@ -109,10 +65,7 @@ U0 OptPass5(CLex *lx)
tempi->p2.reg=tempi1->p1.reg;
tempi->p2.disp=tempi1->p1.disp;
tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
OptSetNOP2(tempi1);
}
}
@@ -156,10 +109,7 @@ U0 OptPass5(CLex *lx)
tempi->p1.reg=tempi1->p1.reg;
tempi->p1.disp=tempi1->p1.disp;
tempi->ic_flags|=tempi1->ic_flags&ICF_NO_CVT_MASK;
tempi1->ic_opcode=IC_NOP1;
tempi1->ic_data=1;
tempi1->p1.type=TY_NULL+tempi1->p1.type&IT_MASK;
tempi1->r.type=TY_NULL+tempi1->r.type&IT_MASK;
OptSetNOP2(tempi1);
}
}
if (tempi->r.type&TY_MASK==TY_STK)
+45 -74
View File
@@ -1,7 +1,7 @@
Bool OptIC6(CIntermediateCode *tempi)
{
CIntermediateCode *tempil1,*tempil2;
if (tempi->ic_opcode<IC_IMM) return FALSE;
if (tempi->ic_opcode<IC_IMM_U64) return FALSE;
tempil1=tempi;
if (!(tempil2=OptLag1(tempil1)))
return FALSE;
@@ -15,14 +15,11 @@ Bool OptIC6(CIntermediateCode *tempi)
if (tempil2->p1.type&TY_MASK==TY_REG) {
tempil1->ic_flags= tempil1->ic_flags & ~ICF_P1_WAS_STK |
tempil2->ic_flags;
tempil2->ic_opcode=IC_NOP1;
tempil2->p1.type=TY_NULL+tempil2->p1.type&IT_MASK;
tempil2->r.type=TY_NULL+tempil2->r.type&IT_MASK;
tempil1->ic_opcode=IC_MOV;
tempil1->p1.type=TY_DISP+tempil1->p1.ptype;
tempil1->p1.reg=tempil2->p1.reg;
tempil1->p1.disp=tempil2->ic_data;
tempil2->ic_data=-1;
OptSetNOP2(tempil2,-1);
return TRUE;
} else {
tempil2->ic_opcode=IC_MOV;
@@ -41,7 +38,7 @@ U0 OptPass6Lag(CLex *lx,
I64 i=*i_,j,k,l,code,clobbered_reg_mask=*_clobbered_reg_mask;
CHashFun *tempf;
code=tempi->ic_opcode;
if (code<=IC_NOP1)
if (code<=IC_NOP2)
return;
else {
if (tempi->ic_flags&ICF_TRACE) {
@@ -85,18 +82,6 @@ U0 OptPass6Lag(CLex *lx,
}
if (cmp_arg_cnt[code]==9)
i-=tempi->ic_data>>3;
if (tempi->p3.type&TY_MASK==TY_STK) {
i--;
if (i<num_stk) {
tempi->p3.type=TY_REG+tempi->p3.type&IT_MASK;
if (fun_num&1)
tempi->p3.reg=to_stk_temps_map_odd[i];
else
tempi->p3.reg=to_stk_temps_map_even[i];
tempi->p3.disp=0;
}
}
if (tempi->p2.type&TY_MASK==TY_STK) {
i--;
if (i<num_stk) {
@@ -146,16 +131,16 @@ U0 OptPass6Lag(CLex *lx,
U0 OptPass6(CLex *lx,CHashFun *fun_class)
{
CIntermediateCode *tempi,*tempil1,*tempif1,*tempif2,
*temp_lag[4],*old_tempil1=NULL;
*temp_lag[4],*old_tempil1=NULL;
CPrsStk *ps=OptStart(lx,temp_lag);
I64 i=0,code,num_stk,clobbered_reg_mask=CALWAYS_CLOBBERED_MASK,
fun_num=0;
fun_num=0;
if (fun_class)
fun_num=compiled_funs++;
if (Bt(&lx->opts,OPTf_NO_REG_VAR) ||
lx->flags&LF_NO_REG_OPT)
lx->flags&LF_NO_REG_OPT)
num_stk=0;
else
num_stk=num_stk_temps;
@@ -167,9 +152,9 @@ U0 OptPass6(CLex *lx,CHashFun *fun_class)
OptNext3(tempi,temp_lag);
tempil1=temp_lag[1];
if (tempil1->ic_opcode==IC_END_EXP) {
if (code!=IC_RETURN_VAL2 && code!=IC_NOP) {
if (code!=IC_RETURN_VAL2 && code!=IC_NOP1) {
if (!(temp_lag[2]->ic_flags&
(ICF_R_TO_F64|ICF_R_TO_INT|ICF_PUSH_RESULT|ICF_DEPEND_RESULT))) {
(ICF_R_TO_F64|ICF_R_TO_INT|ICF_PUSH_RESULT|ICF_DEPEND_RESULT))) {
temp_lag[2]->ic_flags|=ICF_NO_DEPEND_RESULT;
temp_lag[2]->r.type=TY_NULL+temp_lag[2]->r.type&IT_MASK;
tempil1->ic_flags|=ICF_NO_DEPEND_RESULT;
@@ -177,69 +162,55 @@ U0 OptPass6(CLex *lx,CHashFun *fun_class)
}
}
}
if (code<=IC_NOP1) {
} else {
if (tempi->p3.type&TY_MASK) {
if (tempi->p3.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
if (code<=IC_NOP2) {
} else {
if (tempi->p2.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
tempi->p3.type=TY_REG+tempi->p3.type&IT_MASK;
tempi->p3.reg=CREG_RAX;
tempi->p3.disp=0;
tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK;
tempil1->r.reg=CREG_RAX;
tempil1->r.disp=0;
}
}
} else {
if (tempi->p2.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
tempif2=NULL;
if (tempi->ic_opcode==IC_ASSIGN &&
tempif2=NULL;
if (tempi->ic_opcode==IC_ASSIGN &&
tempi->ic_flags&ICF_NOT_ADDR &&
tempil1->ic_opcode!=IC_CALL_END &&
tempil1->ic_opcode!=IC_CALL_END2 &&
tempil1->ic_opcode!=IC_SET_RAX &&
!(tempi->ic_flags&
(ICF_P2_TO_F64|ICF_P2_TO_INT)) &&
(ICF_P2_TO_F64|ICF_P2_TO_INT)) &&
!(tempil1->ic_flags&
(ICF_R_TO_F64|ICF_R_TO_INT))) {
if (tempif1=OptLead1(lx,tempi)) //predict NO_DEPEND
if (tempif2=OptLead1(lx,tempif1))
if (tempif1->ic_opcode==IC_END_EXP &&
(ICF_R_TO_F64|ICF_R_TO_INT))) {
if (tempif1=OptLead1(lx,tempi)) //predict NO_DEPEND
if (tempif2=OptLead1(lx,tempif1))
if (tempif1->ic_opcode==IC_END_EXP &&
tempif2->ic_opcode!=IC_RETURN_VAL2) {
tempi->ic_opcode=IC_NOP;
tempil1->r.type =tempi->p1.type&TY_MASK+tempi->p1.ptype;
tempil1->r.ptype=tempi->p1.ptype;
tempil1->r.reg =tempi->p1.reg;
tempil1->r.disp =tempi->p1.disp;
tempil1->ic_flags=tempil1->ic_flags&~(ICF_NO_DEPEND_RESULT|ICF_R_WAS_STK)|
tempil1->r.type =tempi->p1.type&TY_MASK+tempi->p1.ptype;
tempil1->r.ptype=tempi->p1.ptype;
tempil1->r.reg =tempi->p1.reg;
tempil1->r.disp =tempi->p1.disp;
tempil1->ic_flags=tempil1->ic_flags&~(ICF_NO_DEPEND_RESULT|ICF_R_WAS_STK)|
tempi->ic_flags&~(ICF_NOT_ADDR|ICF_P1_WAS_STK|ICF_P2_WAS_STK)|ICF_DEPEND_RESULT;
old_tempil1=NULL;
} else
tempif2=NULL;
}
if (!tempif2) {
tempi->p2.type=TY_REG+tempi->p2.type&IT_MASK;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK;
tempil1->r.reg=CREG_RAX;
tempil1->r.disp=0;
}
old_tempil1=NULL;
OptSetNOP1(tempi);
} else
tempif2=NULL;
}
} else if (tempi->p1.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=CREG_RAX;
tempi->p1.disp=0;
if (!tempif2) {
tempi->p2.type=TY_REG+tempi->p2.type&IT_MASK;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK;
tempil1->r.reg=CREG_RAX;
tempil1->r.disp=0;
}
}
} else if (tempi->p1.type&TY_MASK==TY_STK) {
if (tempil1->r.type&TY_MASK==TY_STK &&
!(tempil1->ic_flags&ICF_PUSH_RESULT)) {
tempi->p1.type=TY_REG+tempi->p1.type&IT_MASK;
tempi->p1.reg=CREG_RAX;
tempi->p1.disp=0;
tempil1->r.type=TY_REG+tempil1->r.type&IT_MASK;
tempil1->r.reg=CREG_RAX;
tempil1->r.disp=0;
}
}
if (tempi->ic_flags & ICF_PUSH_RESULT)
tempi->r.type==TY_STK+tempi->r.type&IT_MASK;
@@ -258,9 +229,9 @@ U0 OptPass6(CLex *lx,CHashFun *fun_class)
fun_class->used_reg_mask|=clobbered_reg_mask;
fun_class->clobbered_reg_mask=clobbered_reg_mask;
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT) &&
Bt(&lx->pass_trace_mask,6)) {
"Used Reg Mask:%04X\n",fun_class->used_reg_mask;
"Clobbered Reg Mask:%04X\n",clobbered_reg_mask;
Bt(&lx->pass_trace_mask,6)) {
"Used Reg Mask:%04X\n",fun_class->used_reg_mask;
"Clobbered Reg Mask:%04X\n",clobbered_reg_mask;
}
}
}
+130 -224
View File
@@ -30,8 +30,8 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
dbg=NULL;
if (Bt(&lx->flags,Lf_OPT_TRACE_PRESENT) &&
Bt(&lx->pass_trace_mask,lx->pass))
"$$BK,1$$$$FG,LTRED$$$$IV,1$$This code gets merged together and patched.\n$$FG$$$$IV,0$$$$BK,0$$";
Bt(&lx->pass_trace_mask,lx->pass))
"$$BK,1$$$$FG,LTRED$$$$IV,1$$This code gets merged together and patched.\n$$FG$$$$IV,0$$$$BK,0$$";
lx->last_float_op_ic=NULL;
@@ -58,11 +58,9 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
lx->dont_push_float=Btr(&tempi->ic_flags,ICf_DONT_PUSH_FLOAT0);
}
MemCpy(saved_p123,&tempi->p1,3*sizeof(CICArg));
if (cmp_arg_cnt[code]==2) {
if (tempi->p1.type&TY_MASK==TY_REG &&
if (cmp_arg_cnt[code]==2 && tempi->p1.type&TY_MASK==TY_REG &&
tempi->p1.reg==CREG_RAX)
tempi->ic_flags|=ICF_P1_FIRST;
}
tempi->ic_flags|=ICF_P1_FIRST;
tempi->ic_cnt=0;
tempi->ic_last_cnt=-1;
if (tempi->ic_flags & ICF_P1_FIRST) {
@@ -85,7 +83,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
if (tempi->ic_flags & ICF_P2_TO_F64) {
if (tempi->ic_flags&ICF_P1_FIRST) {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
@@ -98,7 +96,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
} else if (tempi->ic_flags & ICF_P2_TO_INT) {
if (tempi->ic_flags&ICF_P1_FIRST) {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
@@ -111,90 +109,30 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
}
} else {
if (tempi->p3.type&TY_MASK) {
if (tempi->ic_flags & ICF_P3_TO_F64) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p3.type,tempi->p3.reg,tempi->p3.disp,FALSE,CN_P3,ip2);
tempi->p3.type=TY_REG+IT_I64;
tempi->p3.reg=CREG_RAX;
tempi->p3.disp=0;
} else if (tempi->ic_flags & ICF_P3_TO_INT) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p3.type,tempi->p3.reg,tempi->p3.disp,TRUE,CN_P3,ip2);
tempi->p3.type=TY_REG+IT_I64;
tempi->p3.reg=CREG_RAX;
tempi->p3.disp=0;
if (tempi->p2.type&TY_MASK) {
if (tempi->ic_flags & ICF_P2_TO_F64) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,FALSE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
} else if (tempi->ic_flags & ICF_P2_TO_INT) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,TRUE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
}
if (tempi->ic_flags & (ICF_P3_TO_F64 | ICF_P3_TO_INT)) {
if (tempi->p2.type&TY_MASK) {
if (tempi->ic_flags & ICF_P2_TO_F64) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,FALSE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RDX;
tempi->p2.disp=0;
} else if (tempi->ic_flags & ICF_P2_TO_INT) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,TRUE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RDX;
tempi->p2.disp=0;
}
}
if (tempi->ic_flags & (ICF_P2_TO_F64 | ICF_P2_TO_INT)) {
if (tempi->p1.type&TY_MASK) { //TODO: RCX might cause problems
if (tempi->ic_flags & ICF_P1_TO_F64) {
ICFCvt(lx,tempi,CREG_RCX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,FALSE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RCX;
tempi->p1.disp=0;
} else if (tempi->ic_flags & ICF_P1_TO_INT) {
ICFCvt(lx,tempi,CREG_RCX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,TRUE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RCX;
tempi->p1.disp=0;
}
}
} else {
if (tempi->p1.type&TY_MASK) {
if (tempi->ic_flags & ICF_P1_TO_F64) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,FALSE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
} else if (tempi->ic_flags & ICF_P1_TO_INT) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,TRUE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
}
}
}
} else
goto p2_RAX_p1_RDX;
} else {
p2_RAX_p1_RDX:
if (tempi->p2.type&TY_MASK) {
if (tempi->ic_flags & ICF_P2_TO_F64) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,FALSE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
} else if (tempi->ic_flags & ICF_P2_TO_INT) {
ICFCvt(lx,tempi,CREG_RAX,tempi->p2.type,tempi->p2.reg,tempi->p2.disp,TRUE,CN_P2,ip2);
tempi->p2.type=TY_REG+IT_I64;
tempi->p2.reg=CREG_RAX;
tempi->p2.disp=0;
}
}
if (tempi->p1.type&TY_MASK) {
if (tempi->ic_flags & ICF_P1_TO_F64) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,FALSE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
} else if (tempi->ic_flags & ICF_P1_TO_INT) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,TRUE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
}
}
if (tempi->p1.type&TY_MASK) {
if (tempi->ic_flags & ICF_P1_TO_F64) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,FALSE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
} else if (tempi->ic_flags & ICF_P1_TO_INT) {
ICFCvt(lx,tempi,CREG_RDX,tempi->p1.type,tempi->p1.reg,tempi->p1.disp,TRUE,CN_P1,ip2);
tempi->p1.type=TY_REG+IT_I64;
tempi->p1.reg=CREG_RDX;
tempi->p1.disp=0;
}
}
}
@@ -203,7 +141,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
ICU16(tempi,0xB848);
ICU64(tempi,tempi->ic_data);
if (buf && lx->flags&LF_AOT_COMPILE &&
!(lx->flags&(LF_NO_ABSS|LF_ASM_EXPRESSIONS))) {
!(lx->flags&(LF_NO_ABSS|LF_ASM_EXPRESSIONS))) {
tempa=CAlloc(sizeof(CExeAbsAddr));
tempa->next=a->abss;
tempa->type=EAA_ADD_U64;
@@ -211,7 +149,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
tempa->ip=ip2+tempi->ic_cnt-8;
}
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_HEAP_GLBL:
@@ -219,14 +157,14 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
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?
!(lx->flags&(LF_NO_ABSS|LF_ASM_EXPRESSIONS))) { //is this necessary--flags?
temphgr=CAlloc(sizeof(CExeHeapGlblRef));
temphgr->next=temphg->references;
temphg->references=temphgr;
temphgr->ip=ip2+tempi->ic_cnt-8;
}
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_ADDR_IMPORT:
@@ -242,7 +180,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
ICU24(tempi,0xC06348);
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_STR_CONST:
@@ -253,7 +191,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
else
i=lb->addr+buf;
ICLea(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_RIP_DISP32+IT_PTR,0,i,lx,buf,ip2);
TY_RIP_DISP32+IT_PTR,0,i,lx,buf,ip2);
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_ASM:
@@ -283,16 +221,16 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
case IC_MOV_FS:
ICZero(tempi,CREG_RAX);
ICU8(tempi,0x64);
//It's ugly to use ic_class here
//It's ugly to use ic_class here
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_DISP+CmpType(tempi->ic_class),CREG_RAX,tempi->ic_data,ip2);
TY_DISP+CmpType(tempi->ic_class),CREG_RAX,tempi->ic_data,ip2);
break;
case IC_MOV_GS:
ICZero(tempi,CREG_RAX);
ICU8(tempi,0x65);
//It's ugly to use ic_class here
//It's ugly to use ic_class here
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_DISP+CmpType(tempi->ic_class),CREG_RAX,tempi->ic_data,ip2);
TY_DISP+CmpType(tempi->ic_class),CREG_RAX,tempi->ic_data,ip2);
break;
case IC_RIP:
ICU16(tempi,0xB848);
@@ -305,12 +243,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
tempa->ip=ip2+tempi->ic_cnt-8;
}
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_NATIVE_TYPECAST:
case IC_HOLYC_TYPECAST:
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
break;
case IC_COM:
ICUnaries(tempi,SLASH_OP_NOT,ip2);
@@ -327,7 +265,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
case IC_ADDR:
case IC_MOV:
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
break;
case IC_DEREF:
ICDeref(tempi,ip2);
@@ -364,20 +302,20 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_LEA:
ICLea(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,lx,buf,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,lx,buf,ip2);
break;
case IC_POWER:
ICFPow(lx,tempi,buf,ip2);
break;
case IC_SHL:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
break;
case IC_SHR:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_MUL:
if (tempi->ic_flags&ICF_USE_INT)
@@ -399,32 +337,32 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_AND:
ICAddEct(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x23,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x23,ip2);
break;
case IC_OR:
ICAddEct(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x0B,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x0B,ip2);
break;
case IC_XOR:
ICAddEct(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x33,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x33,ip2);
break;
case IC_ADD:
if (tempi->ic_flags&ICF_USE_INT)
ICAddEct(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x03,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x03,ip2);
else
ICFAdd(lx,tempi,buf,ip2);
break;
case IC_SUB:
if (tempi->ic_flags&ICF_USE_INT)
ICSub(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
else
ICFSub(lx,tempi,buf,ip2);
break;
@@ -467,9 +405,6 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
case IC_XOR_XOR:
ICXorXor(tempi,ip2);
break;
case IC_COLON:
ICColon(tempi,ip2);
break;
case IC_ASSIGN:
ICAssign(tempi,ip2);
break;
@@ -481,15 +416,15 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_SHL_EQUAL:
ICShiftEqual(tempi,tempi->p1.ptype,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
break;
case IC_SHR_EQUAL:
ICShiftEqual(tempi,tempi->p1.ptype,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_MUL_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
@@ -521,38 +456,38 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
case IC_ADD_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICAddSubEctEqual(tempi,tempi->p1.ptype,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x010000000003,ip2);
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x010000000003,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FADD,buf,ip2);
break;
case IC_SUB_EQUAL:
if (tempi->ic_flags&ICF_USE_INT)
ICAddSubEctEqual(tempi,tempi->p1.ptype,
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x29000000052B,ip2);
tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,0x29000000052B,ip2);
else
ICFOpEqual(lx,tempi,SLASH_OP_FSUB,buf,ip2);
break;
case IC_SHL_CONST:
ICShift(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
TY_IMM+IT_I64,0,tempi->ic_data,0xE0D1E0D3E0C1,0xE0D1E0D3E0C1,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
TY_IMM+IT_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->p1.type,tempi->p1.reg,tempi->p1.disp,
TY_IMM+IT_I64,0,tempi->ic_data,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,
TY_IMM+IT_I64,0,tempi->ic_data,0xE8D1E8D3E8C1,0xF8D1F8D3F8C1,ip2);
break;
case IC_ADD_CONST:
ICAddConst(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,tempi->ic_data,0x0003,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,tempi->ic_data,0x0003,ip2);
break;
case IC_SUB_CONST:
ICAddConst(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,tempi->ic_data,0x052B,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,tempi->ic_data,0x052B,ip2);
break;
case IC_ENTER:
if (tempi->ic_data<=MAX_I16)
@@ -560,7 +495,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
else {
ICPush(tempi,TY_REG+IT_I64,CREG_RBP,0,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RBP,0,
TY_REG+IT_I64,CREG_RSP,0,ip2);
TY_REG+IT_I64,CREG_RSP,0,ip2);
ICAddRSP(tempi,-tempi->ic_data);
}
if (fun_class) {
@@ -573,11 +508,9 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
for (i=0;i<NUM_REGS;i++)
if (register_offsets[i]>0 && register_offsets[i].offset!=MAX_I64) {
tempc=register_offsets[i].m->member_class;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(register_offsets[i].m->member_class);
ICMov(tempi,TY_REG+IT_I64,i,0,
TY_DISP+tempc->sub_type,CREG_RBP,register_offsets[i].offset,ip2);
TY_DISP+tempc->sub_type,CREG_RBP,register_offsets[i].offset,ip2);
}
}
break;
@@ -688,12 +621,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_INVLPG:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU24(tempi,0x38010F);
break;
case IC_CLFLUSH:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU24(tempi,0x38AE0F);
break;
case IC_PAUSE:
@@ -719,69 +652,65 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_GET_BASE_PTR:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
TY_REG+IT_I64,CREG_RBP,0,ip2);
TY_REG+IT_I64,CREG_RBP,0,ip2);
break;
case IC_SET_BASE_PTR:
ICMov(tempi,TY_REG+IT_I64,CREG_RBP,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
break;
case IC_GET_STK_PTR:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
TY_REG+IT_I64,CREG_RSP,0,ip2);
TY_REG+IT_I64,CREG_RSP,0,ip2);
break;
case IC_SET_STK_PTR:
ICMov(tempi,TY_REG+IT_I64,CREG_RSP,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
break;
case IC_RETURN_VAL2:
break;
case IC_RETURN_VAL:
case IC_SET_RAX:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
break;
case IC_GET_RAX:
break;
case IC_BT:
ICBitOps(tempi,&tempi->p1,&tempi->p2,tempi+1,
0xA30F,0x20BA0F,ip2);
0xA30F,0x20BA0F,ip2);
break;
case IC_BTS:
case IC_LBTS:
ICBitOps(tempi,&tempi->p1,&tempi->p2,tempi+1,
0xAB0F,0x28BA0F,ip2);
0xAB0F,0x28BA0F,ip2);
break;
case IC_BTR:
case IC_LBTR:
ICBitOps(tempi,&tempi->p1,&tempi->p2,tempi+1,
0xB30F,0x30BA0F,ip2);
0xB30F,0x30BA0F,ip2);
break;
case IC_BTC:
case IC_LBTC:
ICBitOps(tempi,&tempi->p1,&tempi->p2,tempi+1,
0xBB0F,0x38BA0F,ip2);
break;
case IC_BEQU:
case IC_LBEQU:
ICBEqu(tempi,tempi+1,ip2);
0xBB0F,0x38BA0F,ip2);
break;
case IC_BSF:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU32(tempi,0xC0BC0F48);
ICU16(tempi,0x0375);
ICU24(tempi,0xD0F748);
break;
case IC_BSR:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU32(tempi,0xC0BD0F48);
ICU16(tempi,0x0375);
ICU24(tempi,0xD0F748);
break;
case IC_SIGN_I64:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_SIGN_I64,TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_PREEMPT:
@@ -822,17 +751,11 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
break;
case IC_ABS_I64:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU24(tempi,0xC00B48);
ICU16(tempi,0x0379);
ICU24(tempi,0xD8F748);
break;
case IC_LIMIT_I64:
ICLimit(tempi,0x4F4C,ip2);
break;
case IC_LIMIT_U64:
ICLimit(tempi,0x4742,ip2);
break;
case IC_MIN_I64:
ICMinMax(tempi,0x4F,ip2);
break;
@@ -872,21 +795,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
case IC_QUE_REM:
ICQueRem(tempi,ip2);
break;
case IC_MEMCPY:
ICMemCpy(tempi,ip2);
break;
case IC_MEMSET:
case IC_MEMSET_U16:
case IC_MEMSET_U32:
case IC_MEMSET_U64:
ICMemSet(tempi,code-IC_MEMSET,ip2);
break;
case IC_STRLEN:
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICCopyTemplate(lx,tempi,CMP_TEMPLATE_STRLEN,TRUE,FALSE,FALSE,CN_MAIN);
break;
case IC_INU32:
case IC_IN_U32:
if (tempi->p1.type&TY_MASK==TY_IMM) {
ICU16(tempi,0xC033);
if (tempi->p1.disp<=MAX_U8)
@@ -897,12 +811,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU16(tempi,0xC033);
ICU8(tempi,0xED);
}
break;
case IC_INU16:
case IC_IN_U16:
if (tempi->p1.type&TY_MASK==TY_IMM) {
ICU16(tempi,0xC033);
if (tempi->p1.disp<=MAX_U8)
@@ -913,12 +827,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU16(tempi,0xC033);
ICU16(tempi,0xED00+OC_OP_SIZE_PREFIX);
}
break;
case IC_INU8:
case IC_IN_U8:
if (tempi->p1.type&TY_MASK==TY_IMM) {
ICU16(tempi,0xC033);
if (tempi->p1.disp<=MAX_U8)
@@ -929,15 +843,15 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICU16(tempi,0xC033);
ICU8(tempi,0xEC);
}
break;
case IC_OUTU32:
case IC_OUT_U32:
if (tempi->p2.type&TY_MASK==TY_IMM) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
if (tempi->p2.disp<=MAX_U8)
ICU16(tempi,0xE7+tempi->p2.disp<<8);
else {
@@ -947,22 +861,22 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
} else {
if (tempi->ic_flags & ICF_P1_FIRST) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
}
ICU8(tempi,0xEF);
}
break;
case IC_OUTU16:
case IC_OUT_U16:
if (tempi->p2.type&TY_MASK==TY_IMM) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
if (tempi->p2.disp<=MAX_U8)
ICU24(tempi,0xE700+OC_OP_SIZE_PREFIX+tempi->p2.disp<<16);
else {
@@ -972,22 +886,22 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
} else {
if (tempi->ic_flags & ICF_P1_FIRST) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
}
ICU16(tempi,0xEF00+OC_OP_SIZE_PREFIX);
}
break;
case IC_OUTU8:
case IC_OUT_U8:
if (tempi->p2.type&TY_MASK==TY_IMM) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
if (tempi->p2.disp<=MAX_U8)
ICU16(tempi,0xE6+tempi->p2.disp<<8);
else {
@@ -997,14 +911,14 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
} else {
if (tempi->ic_flags & ICF_P1_FIRST) {
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
} else {
ICMov(tempi,TY_REG+IT_I64,CREG_RDX,0,
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
tempi->p2.type,tempi->p2.reg,tempi->p2.disp,ip2);
ICMov(tempi,TY_REG+IT_I64,CREG_RAX,0,
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
tempi->p1.type,tempi->p1.reg,tempi->p1.disp,ip2);
}
ICU8(tempi,0xEE);
}
@@ -1166,17 +1080,11 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
ICU8(tempi,0xC3);
break;
case IC_JMP:
lb=OptLabelFwd(tempi->ic_data);
short_jmp=ToBool(tempi->ic_flags&ICF_SHORT_JMP);
lb=tempi->ic_data;
while (lb1=lb->fwd)
lb=lb1;
if (!buf) {
if (lb->addr!=INVALID_PTR) {
i=lb->addr-ip;
if (MIN_I8+5<i<MAX_I8-5)
short_jmp=TRUE;
}
}
if (!buf && lb->addr!=INVALID_PTR &&
MIN_I8+5<lb->addr-ip<MAX_I8-5)
short_jmp=TRUE;
if (short_jmp) {
tempi->ic_flags|=ICF_SHORT_JMP;
i=lb->addr-(ip+2);
@@ -1188,8 +1096,6 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_END:
break;
case IC_LABEL:
lb=tempi->ic_data;
lb->addr=ip;
@@ -1199,14 +1105,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
}
tempi->ic_flags&=~ICF_CODE_FINAL;
break;
case IC_QUESTION:
break;
case IC_IRQ:
ICU8(tempi,0xCD);
ICU8(tempi,tempi->ic_data);
break;
case IC_NOP:
case IC_NOP1:
case IC_NOP2:
case IC_PUSH_CMP:
break;
case IC_CALL_START:
@@ -1219,13 +1123,15 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
ICPopRegs(tempi,tempi->ic_data);
if (tempi->r.type&TY_MASK)
ICMov(tempi,tempi->r.type,tempi->r.reg,tempi->r.disp,
TY_REG+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
break;
case IC_POP_REGS:
ICPopRegs(tempi,tempi->ic_data);
break;
case IC_END_EXP:
break;
case IC_END:
break;
default:
OptMissing(lx,tempi);
@@ -1240,12 +1146,12 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
} else {
ICFCvt(lx,tempi,CREG_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+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
}
} else if (tempi->ic_flags & ICF_R_TO_INT) {
ICFCvt(lx,tempi,CREG_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+IT_I64,CREG_RAX,0,ip2);
TY_REG+IT_I64,CREG_RAX,0,ip2);
}
}
}
@@ -1264,7 +1170,7 @@ I64 OptPass789A(CLex *lx,CHashFun *fun_class,
MemCpy(buf+ip,tempi->ic_body,cnt);
}
skip_copy:
skip_copy:
if (dbg && lx->min_line<=tempi->ic_line<=lx->max_line) {
i=tempi->ic_line-lx->min_line;
if (!dbg->body[i])
+59 -131
View File
@@ -107,8 +107,7 @@ U0 PrsVarInit(CLex *lx,U8 **_dst,CHashClass *tempc,CArrayDim *tempad,U8 *data_ad
CExeImportExport *tempe;
Bool is_str;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempc);
if (tempm=tempc->member_lst) {
if (lx->token!='{')
LexExcept(lx,"ST_EXPECTING_LEFT_BRACE");
@@ -163,18 +162,18 @@ U0 PrsVarInit(CLex *lx,U8 **_dst,CHashClass *tempc,CArrayDim *tempad,U8 *data_ad
CBOutPtrsInit(lx);
CBICAdd(lx,IC_START,0,0); //So we can scan back an instruction
CBICAdd(lx,IC_ABS_ADDR,data_addr_ip,tempc+1);
CBICAdd(lx,IC_IMM,dst-*_base,tempc+1);
CBICAdd(lx,IC_IMM_U64,dst-*_base,tempc+1);
CBICAdd(lx,IC_ADD,0,tempc+1);
if (!PrsExpression(lx,NULL,TRUE))
throw(EXCEPT_COMPILER,10);
tempi=lx->cbh.cb_last_out_ptr;
if (tempi->ic_opcode==IC_END_EXP)
tempi->ic_opcode=IC_NOP;
tempi->ic_opcode=IC_NOP1;
CBICAdd(lx,IC_ASSIGN,0,tempc);
CBICAdd(lx,IC_END_EXP,0,tempc);
CBICAdd(lx,IC_RET,0,0);
CBICAdd(lx,IC_END,0,0);
if (ex=CBCompile(lx,NULL,&size,NULL,NULL)) {
if (ex=CBCompile(lx,NULL,&size,NULL)) {
tempe=CAlloc(sizeof(CExeImportExport));
tempe->type=EIE_MAIN;
tempe->ip=lx->a->ip;
@@ -223,8 +222,7 @@ U0 PrsVarInit2(CLex *lx,U8 **_dst,CHashClass *tempc,CArrayDim *tempad,U8 *data_a
U8 *st,*_b;
CVI2 root,*tempvi,*tempvi1;
CArrayDim *tempad1;
while (tempc->fwd_class)
tempc=tempc->fwd_class;
tempc=OptClassFwd(tempc);
if (tempad1=tempad->next) {
if (!tempc->ptr_cnt &&
(tempc->sub_type==IT_I8 || tempc->sub_type==IT_U8) &&
@@ -328,7 +326,7 @@ U0 PrsStaticInit(CLex *lx,CMemberLst *tempm,I64 pass)
if (tempi!=lx->cbh.cb_last_out_ptr) {
CBICAdd(lx,IC_RET,0,0);
CBICAdd(lx,IC_END,0,0);
if (ex=CBCompile(lx,NULL,&size,NULL,NULL)) {
if (ex=CBCompile(lx,NULL,&size,NULL)) {
if (pass==2) {
tempe=CAlloc(sizeof(CExeImportExport));
tempe->type=EIE_MAIN;
@@ -442,7 +440,7 @@ start:
if (PrsKeyWord(lx)==KW_UNION) {
Lex(lx);
tempc2=PrsClass(lx,TRUE,cps_flags,mode.u8[0]==PRS0_EXTERN);
tempc2=PrsClass(lx,TRUE,cps_flags,mode&255==PRS0_EXTERN);
tempc2->fwd_class=tempc1;
tempc1=tempc2;
if (_tempc1) *_tempc1=tempc1;
@@ -450,7 +448,7 @@ start:
goto start;
} else if (PrsKeyWord(lx)==KW_CLASS) {
Lex(lx);
tempc2=PrsClass(lx,FALSE,cps_flags,mode.u8[0]==PRS0_EXTERN);
tempc2=PrsClass(lx,FALSE,cps_flags,mode&255==PRS0_EXTERN);
tempc2->fwd_class=tempc1;
tempc1=tempc2;
if (_tempc1) *_tempc1=tempc1;
@@ -500,9 +498,7 @@ start:
tempad->next=tempad2;
}
tempc2=tempc1;
while (tempc2->fwd_class)
tempc2=tempc2->fwd_class;
tempc2=OptClassFwd(tempc1);
if (tempc2->ptr_cnt) {
tempc2-=tempc2->ptr_cnt;
if (tempc2->type&HTT_INTERNAL_TYPE && !tempc2->size)
@@ -592,15 +588,9 @@ U0 PrsVarLst(CLex *lx,CHashClass *tempc,
restart:
tempc1=temph;
LexPush(lx);
if (lx->token!=',' && mode.u8[1]==PRS1B_LOCAL_VAR) {
if (lx->token!=',' && mode.u8[1]==PRS1B_LOCAL_VAR)
Lex(lx); //skip type
lx->temp_indent_level=lx->indent_level=1;
lx->flags|=LF_INSIDE_EXPRESSION;
if (lx->fun_lfn)
lx->expression_start_line_num=lx->fun_lfn->line_num;
else
lx->expression_start_line_num=1;
} else
else
Lex(lx); //skip type or ','
tempm=MemberLstNew(register);
if (mode.u8[1]==PRS1B_STATIC_LOCAL_VAR) {
@@ -750,8 +740,7 @@ restart:
if (!ex)
throw(EXCEPT_COMPILER,8);
tempm->dft_val=Call(ex);
while (tempc2->fwd_class)
tempc2=tempc2->fwd_class;
tempc2=OptClassFwd(tempc2);
if (tempc2->sub_type==IT_F64) {
if (type!=IT_F64)
tempm->dft_val(F64)=tempm->dft_val;
@@ -820,10 +809,6 @@ restart:
}
}
pvl_done:
if (mode.u8[1]==PRS1B_LOCAL_VAR) {
lx->flags&=~LF_INSIDE_EXPRESSION;
lx->temp_indent_level=lx->indent_level=1;
}
lx->flags=lx->flags&~(LF_CLASS_IP|LF_DONT_MAKE_RESULT)|
old_flags& (LF_CLASS_IP|LF_DONT_MAKE_RESULT);
}
@@ -851,22 +836,22 @@ CHashClass *PrsClass(CLex *lx,Bool is_union,I64 cps_flags,Bool is_extern)
tempc->str=lx->ident;
lx->ident=NULL;
if (IsReplaceSyms)
HashReplace(tempc,lx->glbl_hash_table);
HashReplace(tempc,lx->htc.glbl_hash_table);
else
HashAdd(tempc,lx->glbl_hash_table);
HashAdd(tempc,lx->htc.glbl_hash_table);
LBts(tempc->flags,Cf_EXTERN);
SetSrcFileInfo(lx,tempc);
Lex(lx);
} else {
if (lx->flags&LF_AOT_COMPILE) {
if (tempc=HashFind(lx->ident,lx->glbl_hash_table,HTT_CLASS)) {
if (tempc=HashFind(lx->ident,lx->htc.glbl_hash_table,HTT_CLASS)) {
if (!Bt(tempc->flags,Cf_EXTERN))
tempc=NULL;
else if (tempc->use_cnt<3)
UnusedExternWarning(lx,tempc);
}
} else {
if (tempc=HashSingleTableFind(lx->ident,lx->glbl_hash_table,HTT_CLASS)) {
if (tempc=HashSingleTableFind(lx->ident,lx->htc.glbl_hash_table,HTT_CLASS)) {
if (!Bt(tempc->flags,Cf_EXTERN))
tempc=NULL;
else if (tempc->use_cnt<3)
@@ -878,9 +863,9 @@ CHashClass *PrsClass(CLex *lx,Bool is_union,I64 cps_flags,Bool is_extern)
tempc->str=lx->ident;
lx->ident=NULL;
if (IsReplaceSyms)
HashReplace(tempc,lx->glbl_hash_table);
HashReplace(tempc,lx->htc.glbl_hash_table);
else
HashAdd(tempc,lx->glbl_hash_table);
HashAdd(tempc,lx->htc.glbl_hash_table);
} else {
Free(tempc->src_link);
Free(tempc->index);
@@ -915,7 +900,7 @@ CHashFun *PrsFunJoin(CLex *lx,
CHashFun *tempf;
if (name) { //if not fun_ptr
if (lx->flags&LF_AOT_COMPILE) {
if (tempf=HashFind(name,lx->glbl_hash_table,HTT_FUN)) {
if (tempf=HashFind(name,lx->htc.glbl_hash_table,HTT_FUN)) {
if (tempf->type & HTF_IMPORT)
tempf=NULL;
else
@@ -923,7 +908,7 @@ CHashFun *PrsFunJoin(CLex *lx,
UnusedExternWarning(lx,tempf);
}
} else {
if (tempf=HashSingleTableFind(name,lx->glbl_hash_table,HTT_FUN)) {
if (tempf=HashSingleTableFind(name,lx->htc.glbl_hash_table,HTT_FUN)) {
if (!Bt(tempf->flags,Cf_EXTERN))
tempf=NULL;
else if (tempf->use_cnt<3)
@@ -950,9 +935,9 @@ CHashFun *PrsFunJoin(CLex *lx,
Bts(tempf->flags,Ff_NOARGPOP);
if (name) { //if not fun_ptr
if (IsReplaceSyms)
HashReplace(tempf,lx->glbl_hash_table);
HashReplace(tempf,lx->htc.glbl_hash_table);
else
HashAdd(tempf,lx->glbl_hash_table);
HashAdd(tempf,lx->htc.glbl_hash_table);
}
} else {
tempf->used_reg_mask=CALWAYS_CLOBBERED_MASK+CSTK_TEMPS_MASK;
@@ -989,19 +974,16 @@ U0 PrsFun(CLex *lx,
lx->fun_lfn=lx->cur_lfn;
lx->min_line=lx->max_line=lx->cur_lfn->line_num;
QueVectU8Del(lx->indent_que_vect);
lx->indent_que_vect=QueVectU8New(lx->min_line);
lx->flags&=~LF_NO_REG_OPT;
tempf=PrsFunJoin(lx,temp_return,name,cps_flags);
lx->local_var_lst=tempf;
lx->htc.local_var_lst=tempf;
CBPush(lx);
Btr(&lx->flags,Lf_OPT_TRACE_PRESENT);
CBOutPtrsInit(lx);
CBICAdd(lx,IC_START,0,0); //So we can scan back an instruction
lx->temp_indent_level=lx->indent_level=0;
CBICAdd(lx,IC_ENTER,0,0);
saved_leave_label=lx->lb_leave;
lx->lb_leave=CBMiscNew(lx,CBMT_LABEL);
@@ -1009,7 +991,6 @@ U0 PrsFun(CLex *lx,
PrsStatement(lx,tempf,0,NULL,FALSE);
if (tempf->return_class->size && !(lx->flags&LF_HAS_RETURN))
LexPutWarn(lx,"ST_SHOULD_RETURN_VAL");
lx->temp_indent_level=lx->indent_level=0;
CBICAdd(lx,IC_LABEL,lx->lb_leave,0);
lx->lb_leave=saved_leave_label;
CBICAdd(lx,IC_LEAVE,0,tempf->return_class);
@@ -1018,7 +999,7 @@ U0 PrsFun(CLex *lx,
if (lx->flags&LF_AOT_COMPILE) {
tempf->executable_addr=lx->a->ip;
tempf->type|=HTF_EXPORT;
r=CBCompile(lx,tempf,&size,&tempf->debug,&tempf->indent);
r=CBCompile(lx,tempf,&size,&tempf->debug);
if (r) {
j=(size+7)>>3;
for (i=0;i<j;i++)
@@ -1027,7 +1008,7 @@ U0 PrsFun(CLex *lx,
}
} else {
old_ctrace=Btr(&lx->opts,OPTf_COMPILE_TRACE);
tempf->executable_addr=CBCompile(lx,tempf,&size,&tempf->debug,&tempf->indent);
tempf->executable_addr=CBCompile(lx,tempf,&size,&tempf->debug);
if (old_ctrace) {
Bts(&lx->opts,OPTf_COMPILE_TRACE);
Un(tempf->executable_addr,size,64);
@@ -1036,7 +1017,7 @@ U0 PrsFun(CLex *lx,
}
LBtr(tempf->flags,Cf_EXTERN);
CBPop(lx);
lx->local_var_lst=NULL;
lx->htc.local_var_lst=NULL;
tempm=tempf->member_lst;
while (tempm) {
if (tempm->flags & MLF_NO_UNUSED_WARN) {
@@ -1048,9 +1029,6 @@ U0 PrsFun(CLex *lx,
lx->cur_lfn->name,lx->cur_lfn->line_num,tempm->str,tempf->str);
tempm=tempm->next;
}
QueVectU8Del(lx->indent_que_vect);
lx->indent_que_vect=NULL;
lx->fun_lfn=NULL;
}
@@ -1083,14 +1061,14 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
val=saved_val;
mode=saved_mode;
if (tempess && mode.u8[0]==PRS0_EXTERN && !(lx->flags&LF_AOT_COMPILE)) {
if (tempess && mode&255==PRS0_EXTERN && !(lx->flags&LF_AOT_COMPILE)) {
if (tempess->type & HTT_EXPORT_SYS_SYM) {
val=tempess->val;
mode=PRS0__EXTERN|PRS1_NULL;
}
}
if (lx->token=='(') {
switch (mode.u8[0]) {
switch (mode&255) {
case PRS0__INTERN:
tempf=PrsFunJoin(lx,tempc,st,cps_flags);
tempf->executable_addr=val;
@@ -1113,7 +1091,7 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
else {
tempf=PrsFunJoin(lx,tempc,st,cps_flags);
tempf->type|=HTF_IMPORT;
if (mode.u8[0]==PRS0__IMPORT)
if (mode&255==PRS0__IMPORT)
tempf->import_name=StrNew(val);
else
tempf->import_name=StrNew(st);
@@ -1138,7 +1116,7 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
j*=i;
has_alias=FALSE;
temphg=NULL;
switch (mode.u8[0]) {
switch (mode&255) {
case PRS0__EXTERN:
if (lx->flags&LF_AOT_COMPILE) {
tempg=CAlloc(sizeof(CHashGlblVar));
@@ -1158,7 +1136,7 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
else {
tempg=CAlloc(sizeof(CHashGlblVar));
tempg->type=HTT_GLBL_VAR | HTF_IMPORT;
if (mode.u8[0]==PRS0__IMPORT)
if (mode&255==PRS0__IMPORT)
tempg->import_name=StrNew(val);
else
tempg->import_name=StrNew(st);
@@ -1239,9 +1217,9 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
tempg->dim.total_cnt=i;
tempg->use_cnt=0;
SetSrcFileInfo(lx,tempg);
if (mode.u8[0]==PRS0_IMPORT || mode.u8[0]==PRS0__IMPORT)
if (mode&255==PRS0_IMPORT || mode&255==PRS0__IMPORT)
tempg->flags|=GVAF_IMPORT;
if (mode.u8[0]==PRS0_EXTERN)
if (mode&255==PRS0_EXTERN)
tempg->flags|=GVAF_EXTERN;
if (tempf_fun_ptr) {
tempg->fun_ptr=tempf_fun_ptr;
@@ -1250,9 +1228,9 @@ U0 PrsGlblVarLst(CLex *lx,I64 saved_mode,CHashClass *saved_tempc,
if (is_array)
tempg->flags|=GVAF_ARRAY;
if (IsReplaceSyms)
HashReplace(tempg,lx->glbl_hash_table);
HashReplace(tempg,lx->htc.glbl_hash_table);
else
HashAdd(tempg,lx->glbl_hash_table);
HashAdd(tempg,lx->htc.glbl_hash_table);
if (!(lx->flags&LF_AOT_COMPILE) && !(tempg->flags&GVAF_EXTERN))
SysSymImportsResolve(tempg->str);
if (lx->token=='=') {
@@ -1317,18 +1295,15 @@ U0 PrsIf(CLex *lx,CHashFun *locals,I64 try_cnt,
LexExcept(lx,"ST_MISSING_RIGHT_PAREN");
Lex(lx);
lb=CBMiscNew(lx,CBMT_LABEL);
lx->temp_indent_level++;
CBICAdd(lx,IC_BR_ZERO,lb,0);
PrsStatement(lx,locals,try_cnt,lb_break);
k=PrsKeyWord(lx);
if (k==KW_ELSE) {
lx->temp_indent_level--;
Lex(lx);
lx->temp_indent_level++;
lb1=CBMiscNew(lx,CBMT_LABEL);
CBICAdd(lx,IC_JMP,lb1,0);
CBICAdd(lx,IC_LABEL,lb,0);
PrsStatement(lx,locals,try_cnt,lb_break,TRUE,TRUE);
PrsStatement(lx,locals,try_cnt,lb_break,TRUE);
CBICAdd(lx,IC_LABEL,lb1,0);
} else
CBICAdd(lx,IC_LABEL,lb,0);
@@ -1385,7 +1360,6 @@ U0 PrsFor(CLex *lx,CHashFun *locals,I64 try_cnt)
CLexCodeBlkCtrl *tempcbh;
CCodeBlkMisc *lb,*lb_done;
lx->temp_indent_level=lx->indent_level--;
if (lx->token!='(')
LexExcept(lx,"ST_EXPECTING_LEFT_PAREN");
Lex(lx);
@@ -1413,11 +1387,9 @@ U0 PrsFor(CLex *lx,CHashFun *locals,I64 try_cnt)
LexExcept(lx,"ST_MISSING_RIGHT_PAREN");
Lex(lx);
lx->temp_indent_level=lx->indent_level++;
PrsStatement(lx,locals,try_cnt,lb_done);
CBAppend(lx,tempcbh);
CBICAdd(lx,IC_JMP,lb,0);
lx->temp_indent_level--;
CBICAdd(lx,IC_LABEL,lb_done,0);
}
@@ -1432,7 +1404,7 @@ U0 PrsSwitch(CLex *lx,Bool nobound,CHashFun *locals,I64 try_cnt)
CSwitchCase *header=NULL,*temps,*temps1;
CCodeBlkMisc *lb_break,*lb_dft,*mc_jt,*lb_entry,**jmp_table;
CIntermediateCode *tempi_sub,*tempi_cmp;
Bool dft_found=FALSE,first=TRUE;
Bool dft_found=FALSE;
I64 i,k,k2,lo=MAX_I64,hi=MIN_I64,range;
if (lx->token!='(')
@@ -1445,9 +1417,9 @@ U0 PrsSwitch(CLex *lx,Bool nobound,CHashFun *locals,I64 try_cnt)
mc_jt=CBMiscNew(lx,CBMT_JMP_TABLE);
if (!PrsExpression(lx,NULL,FALSE))
throw(EXCEPT_COMPILER,15);
tempi_sub=CBICAdd(lx,IC_IMM,0,sys_internal_types[IT_I64]);
tempi_sub=CBICAdd(lx,IC_IMM_U64,0,sys_internal_types[IT_I64]);
CBICAdd(lx,IC_SUB,0,sys_internal_types[IT_I64]);
tempi_cmp=CBICAdd(lx,IC_IMM,0,sys_internal_types[IT_I64]);
tempi_cmp=CBICAdd(lx,IC_IMM_U64,0,sys_internal_types[IT_I64]);
if (nobound)
CBICAdd(lx,IC_NOBOUND_SWITCH,mc_jt,0);
else
@@ -1457,7 +1429,6 @@ U0 PrsSwitch(CLex *lx,Bool nobound,CHashFun *locals,I64 try_cnt)
if (Lex(lx)!='{')
LexExcept(lx,"ST_EXPECTING_LEFT_BRACE");
Lex(lx);
lx->temp_indent_level=lx->indent_level++;
while (lx->token && lx->token!='}') {
k=PrsKeyWord(lx);
if (k==KW_CASE) {
@@ -1495,24 +1466,18 @@ U0 PrsSwitch(CLex *lx,Bool nobound,CHashFun *locals,I64 try_cnt)
LexExcept(lx,"ST_EXPECTING_COLON");
} else
LexExcept(lx,"ST_EXPECTING_COLON");
first=TRUE;
} else if (k==KW_DFT) {
Lex(lx);
CBICAdd(lx,IC_LABEL,lb_dft,0);
if (lx->token==':')
Lex(lx);
else
LexExcept(lx,"ST_EXPECTING_COLON");
dft_found=TRUE;
first=TRUE;
} else {
if (first) {
lx->temp_indent_level++;
first=FALSE;
}
} else
PrsStatement(lx,locals,try_cnt,lb_break);
}
}
lx->temp_indent_level=--lx->indent_level;
if (!dft_found)
CBICAdd(lx,IC_LABEL,lb_dft,0);
CBICAdd(lx,IC_LABEL,lb_break,0);
@@ -1523,9 +1488,9 @@ U0 PrsSwitch(CLex *lx,Bool nobound,CHashFun *locals,I64 try_cnt)
if (0<lo<=16)
lo=0;
range=hi-lo+1;
if (range<=0 || range>0x4000)
if (lo>hi || !(0<range<=0x4000))
LexExcept(lx,"ST_CASE_RANGE_ERROR");
jmp_table=MAlloc(sizeof(CCodeBlkMisc *)*range);
jmp_table=MAlloc((sizeof(CCodeBlkMisc *)*range+0x1FF)&~0x1FF);
MemSetU64(jmp_table,lb_dft,range);
tempi_sub->ic_data=lo;
tempi_cmp->ic_data=range;
@@ -1562,16 +1527,8 @@ U0 PrsNoUnusedWarn(CLex *lx)
U0 PrsStreamBlk(CLex *lx)
{
CHashTable *ht1=lx->hash_table_lst,
*ht2=lx->define_hash_table,
*ht3=lx->glbl_hash_table,
*ht4=lx->local_hash_table,
*ht5=lx->stream_parent_glbl_hash_table;
I64 old_hash_mask=lx->hash_mask,
old_flags=lx->flags & (LF_ASM_EXPRESSIONS | LF_EXE_BLK|LF_AOT_COMPILE);
CLexHashTableContext *htc=MAlloc(sizeof(CLexHashTableContext));
CStreamBlk *tempe=MAlloc(sizeof(CStreamBlk));
CHashFun *old_var_lst=lx->local_var_lst;
lx->local_var_lst=NULL;
tempe->body=StrNew("");
QueIns(tempe,lx->last_stream_blk);
@@ -1579,9 +1536,12 @@ U0 PrsStreamBlk(CLex *lx)
lx->cbh.cb_misc_lst=NULL;
lx->cbh.cb_misc_lst_end=&lx->cbh.cb_misc_lst;
lx->stream_parent_glbl_hash_table=lx->glbl_hash_table;
lx->hash_mask=HTG_ALL-HTT_IMPORT_SYS_SYM-HTT_ASM_KEYWORD;
lx->define_hash_table=lx->hash_table_lst=lx->glbl_hash_table=lx->local_hash_table=Fs->hash_table;
MemCpy(htc,&lx->htc,sizeof(CLexHashTableContext));
htc->old_flags=lx->flags;
lx->htc.next=htc;
lx->htc.local_var_lst=NULL;
lx->htc.hash_mask=HTG_ALL-HTT_IMPORT_SYS_SYM-HTT_ASM_KEYWORD;
lx->htc.define_hash_table=lx->htc.hash_table_lst=lx->htc.glbl_hash_table=lx->htc.local_hash_table=Fs->hash_table;
lx->flags=lx->flags & ~(LF_ASM_EXPRESSIONS|LF_AOT_COMPILE) | LF_EXE_BLK;
if (lx->token=='{')
Lex(lx);
@@ -1590,15 +1550,11 @@ U0 PrsStreamBlk(CLex *lx)
while (lx->token && lx->token!='}')
ExeCmdLine(lx);
lx->hash_table_lst =ht1,
lx->define_hash_table=ht2;
lx->glbl_hash_table =ht3;
lx->local_hash_table =ht4;
lx->stream_parent_glbl_hash_table=ht5;
MemCpy(&lx->htc,htc,sizeof(CLexHashTableContext));
lx->flags=lx->flags&~LF_EXE_BLK |
htc->old_flags & (LF_ASM_EXPRESSIONS|LF_EXE_BLK|LF_AOT_COMPILE);
Free(htc);
lx->local_var_lst=old_var_lst;
lx->hash_mask=old_hash_mask;
lx->flags= lx->flags&~LF_EXE_BLK | old_flags;
CBPop(lx);
QueRem(tempe);
if (*tempe->body)
@@ -1609,14 +1565,12 @@ U0 PrsStreamBlk(CLex *lx)
Lex(lx); //Skip "}"
}
U0 PrsTryBlk(CLex *lx,CHashFun *locals,I64 try_cnt)
{
CCodeBlkMisc *lb_catch,*lb_done,*lb_untry;
Bool has_brace;
CHashClass *tempc=sys_internal_types[IT_PTR];
CHashFun *temp_try=HashFind("SysTry",lx->hash_table_lst,HTT_FUN),
*temp_untry=HashFind("SysUntry",lx->hash_table_lst,HTT_FUN);
CHashFun *temp_try=HashFind("SysTry",lx->htc.hash_table_lst,HTT_FUN),
*temp_untry=HashFind("SysUntry",lx->htc.hash_table_lst,HTT_FUN);
if (!temp_try || !temp_untry)
LexExcept(lx,"ST_HEADER_FOR_SYSTRY");
@@ -1627,13 +1581,6 @@ U0 PrsTryBlk(CLex *lx,CHashFun *locals,I64 try_cnt)
lb_done =CBMiscNew(lx,CBMT_LABEL);
lb_untry=CBMiscNew(lx,CBMT_LABEL);
if (lx->token=='{')
has_brace=TRUE;
else {
lx->temp_indent_level=++lx->indent_level;
has_brace=FALSE;
}
CBICAdd(lx,IC_CALL_START,0,0);
CBICAdd(lx,IC_GET_LABEL,lb_untry,tempc,ICF_PUSH_RESULT);
CBICAdd(lx,IC_GET_LABEL,lb_catch,tempc,ICF_PUSH_RESULT);
@@ -1653,8 +1600,6 @@ U0 PrsTryBlk(CLex *lx,CHashFun *locals,I64 try_cnt)
CBICAdd(lx,IC_END_EXP,0,0);
PrsStatement(lx,locals,try_cnt+1);
if (!has_brace)
lx->temp_indent_level=lx->indent_level--;
CBICAdd(lx,IC_LABEL,lb_untry,0);
CBICAdd(lx,IC_CALL_START,0,0);
@@ -1675,22 +1620,14 @@ U0 PrsTryBlk(CLex *lx,CHashFun *locals,I64 try_cnt)
LexExcept(lx,"ST_MISSING_CATCH");
Lex(lx);
if (lx->token=='{')
has_brace=TRUE;
else {
lx->temp_indent_level=++lx->indent_level;
has_brace=FALSE;
}
CBICAdd(lx,IC_LABEL,lb_catch,0);
PrsStatement(lx,locals,try_cnt+1);
if (!has_brace)
lx->temp_indent_level=lx->indent_level--;
CBICAdd(lx,IC_RET,0,tempc);
CBICAdd(lx,IC_LABEL,lb_done,0);
}
Bool PrsStatement(CLex *lx,CHashFun *locals,I64 try_cnt=0,
CCodeBlkMisc *lb_break=NULL,Bool saved_prs_semicolon=TRUE,Bool if_else=FALSE)
CCodeBlkMisc *lb_break=NULL,Bool saved_prs_semicolon=TRUE)
{
Bool prs_exp,cont,prs_semicolon;
I64 i,cps_flags=0,last_cps_flags=0;
@@ -1700,7 +1637,6 @@ Bool PrsStatement(CLex *lx,CHashFun *locals,I64 try_cnt=0,
CHashFun *temp_untry;
CExe *tempex;
lx->temp_indent_level=lx->indent_level++;
do {
cps_flags&=~CPS_FUN_FLAGS;
cont=FALSE;
@@ -1712,12 +1648,10 @@ Bool PrsStatement(CLex *lx,CHashFun *locals,I64 try_cnt=0,
if (lx->token=='{') {
Lex(lx);
lx->braces_cnt++;
lx->temp_indent_level=lx->indent_level--;
while (lx->token!='}')
PrsStatement(lx,locals,try_cnt,lb_break);
lx->braces_cnt--;
lx->statement_cnt--;
lx->temp_indent_level=lx->indent_level++;
Lex(lx);
} else if (lx->token==TK_EOF) ;
else if (lx->token==';') {
@@ -1733,11 +1667,7 @@ Bool PrsStatement(CLex *lx,CHashFun *locals,I64 try_cnt=0,
nobound_switch (i) {
case KW_IF:
Lex(lx);
if (if_else)
lx->temp_indent_level=lx->indent_level--;
PrsIf(lx,locals,try_cnt,lb_break);
if (if_else)
lx->temp_indent_level=lx->indent_level++;
prs_semicolon=FALSE;
break;
case KW_FOR:
@@ -1898,7 +1828,7 @@ keyword_import:
LexExcept(lx,"ST_CANT_RETURN_VAL");
if (try_cnt) {
temp_untry=HashFind("SysUntry",
lx->hash_table_lst,HTT_FUN);
lx->htc.hash_table_lst,HTT_FUN);
for (i=0;i<try_cnt;i++) {
if (Bt(temp_untry->flags,Cf_EXTERN)) {
lx->abs_cnts.externs++;
@@ -2022,7 +1952,6 @@ keyword_import:
LexExcept(lx,"ST_DUP_GOTO_LABEL");
g_lb->flags|=CBMF_DEFINED;
Lex(lx); //skip ident
lx->temp_indent_level=0;
CBICAdd(lx,IC_LABEL,g_lb,0);
if (lx->token==':') //skip ident
Lex(lx); //skip colon
@@ -2051,6 +1980,5 @@ keyword_import:
}
last_cps_flags=cps_flags;
} while (lx->token==',' || cont);
lx->temp_indent_level=lx->indent_level--;
return cps_flags&CPS_IS_ASM;
}
+227 -274
View File
@@ -217,18 +217,32 @@ U0 UnasmHashLoad()
QSortI64(unasm_table,cnt,&InstEntriesCompare);
}
I64 StrStrBits(U8 *st)
{
if (StrStr(st,"8"))
return 8;
if (StrStr(st,"16"))
return 16;
if (StrStr(st,"32"))
return 32;
if (StrStr(st,"64"))
return 64;
return 0;
}
U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
//Unassembles one instruction
{
I64 disp,imm,opsize,opadd,
i,a1,a2,aa1,aa2,arg1_size=0,arg2_size=0,a1_size,a2_size,
ModrM=-1,SIB=-1,scale,r1,r2,
Mod=-1,RM1=-1,RM2=-1,REX=-1,REX_r=0,REX_x=0,REX_b=0;
I64 i,disp,imm,opsize,opadd,
a1,a2,reloced_a1,reloced_a2,
a1_size=0,a2_size=0,reloced_a1_size,reloced_a2_size,
ModrM=-1,SIB=-1,scale,r1,r2,
Mod=-1,RM1=-1,RM2=-1,REX=-1,REX_r=0,REX_x=0,REX_b=0;
Bool cont;
CInstruction *tempi,*tempi2;
CHashOpcode *tempo;
U8 *ip=*_ip,*ptr,*a1_st,*a2_st,*bin_data_area,*bin_data_area2,
buf2[256],buf3[256],seg_overrides[40],arg1_st[256],arg2_st[256];
U8 *ip=*_ip,*ptr,*reloced_a1_st,*reloced_a2_st,*bin_data_area1,*bin_data_area2,
buf2[256],line1[256],line2[256],a1_st[256],a2_st[256],seg_overrides[32];
if (_jmp_dst) *_jmp_dst=-1;
if (seg_size==16) {
@@ -241,41 +255,38 @@ U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
opsize=32;
opadd=64;
}
*arg1_st=0;
*arg2_st=0;
a1_st=arg1_st;
a2_st=arg2_st;
if (!IsRaw && PutSrcLink(ip,1,buf))
StrCat(buf,"\n");
*a1_st=0;
*a2_st=0;
if (!IsRaw && PutSrcLink(ip,1,line1))
StrCat(line1,"\n");
else
*buf=0;
*line1=0;
SPrintF(buf+StrLen(buf),"%24tP ",ip);
bin_data_area=buf+StrLen(buf);
SPrintF(line1+StrLen(line1),"%24tP ",ip);
bin_data_area1=line1+StrLen(line1);
for (i=0;i<6;i++) {
SPrintF(buf2,"%02X",ip[i]);
StrCat(buf,buf2);
StrCat(line1,buf2);
}
StrCat(buf," ");
StrCat(line1," ");
SPrintF(buf3,"%24tP ",ip+6);
bin_data_area2=buf3+StrLen(buf3);
SPrintF(line2,"%24tP ",ip+6);
bin_data_area2=line2+StrLen(line2);
for (i=6;i<12;i++) {
SPrintF(buf2,"%02X",ip[i]);
StrCat(buf3,buf2);
StrCat(line2,buf2);
}
*seg_overrides=0;
cont=TRUE;
do {
switch (*ip++) {
case 0x2E: StrCat(seg_overrides,"CS:"); break;
case 0x36: StrCat(seg_overrides,"SS:"); break;
case 0x3E: StrCat(seg_overrides,"DS:"); break;
case 0x26: StrCat(seg_overrides,"ES:"); break;
case 0x64: StrCat(seg_overrides,"FS:"); break;
case 0x65: StrCat(seg_overrides,"GS:"); break;
case 0x2E: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"CS:"); break;
case 0x36: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"SS:"); break;
case 0x3E: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"DS:"); break;
case 0x26: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"ES:"); break;
case 0x64: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"FS:"); break;
case 0x65: if (StrLen(seg_overrides)<24) StrCat(seg_overrides,"GS:"); break;
case OC_OP_SIZE_PREFIX:
if (opsize==16)
opsize=32;
@@ -384,186 +395,147 @@ U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
if (opsize==32 && seg_size==64) {
tempi2=InstEntryFind(ip,64);
if (tempi2!=tempi &&
tempi2->flags&IEF_REX_ONLY_R8_R15 ||
tempi2->flags&IEF_REX_XOR_LIKE&& ip[1]>>3&7==ip[1]&7)
tempi2->flags&IEF_REX_ONLY_R8_R15 ||
tempi2->flags&IEF_REX_XOR_LIKE&& ip[1]>>3&7==ip[1]&7)
tempi=tempi2;
}
ip+=tempi->opcode_cnt;
tempo=tempi(U8 *)-tempi->ins_entry_num*sizeof(CInstruction)-offset(CHashOpcode.ins);
if (just_ins)
*buf=0;
StrCat(buf,tempo->str);
*line1=0;
StrCat(line1,tempo->str);
a1=tempi->arg1;
a2=tempi->arg2;
aa1=a1;
aa2=a2;
ptr=DefineSub(a1,"ST_ARG_TYPES");
if (Bt(&uasm_signed_arg_mask,a1)) {
if (StrStr(ptr,"8")) {
arg1_size=1;
StrCat(arg1_st,"I8 ");
} else if (StrStr(ptr,"16")) {
arg1_size=2;
StrCat(arg1_st,"I16 ");
} else if (StrStr(ptr,"32")) {
arg1_size=4;
StrCat(arg1_st,"I32 ");
} else if (StrStr(ptr,"64")) {
arg1_size=8;
StrCat(arg1_st,"I64 ");
}
} else {
if (StrStr(ptr,"8")) {
arg1_size=1;
StrCat(arg1_st,"U8 ");
} else if (StrStr(ptr,"16")) {
arg1_size=2;
StrCat(arg1_st,"U16 ");
} else if (StrStr(ptr,"32")) {
arg1_size=4;
StrCat(arg1_st,"U32 ");
} else if (StrStr(ptr,"64")) {
arg1_size=8;
StrCat(arg1_st,"U64 ");
}
if (a1_size=StrStrBits(DefineSub(a1,"ST_ARG_TYPES"))) {
if (Bt(&uasm_signed_arg_mask,a1))
SPrintF(buf2,"I%d ",a1_size);
else
SPrintF(buf2,"U%d ",a1_size);
StrCat(a1_st,buf2);
}
ptr=DefineSub(a2,"ST_ARG_TYPES");
if (Bt(&uasm_signed_arg_mask,a2)) {
if (StrStr(ptr,"8")) {
arg2_size=1;
StrCat(arg2_st,"I8 ");
} else if (StrStr(ptr,"16")) {
arg2_size=2;
StrCat(arg2_st,"I16 ");
} else if (StrStr(ptr,"32")) {
arg2_size=4;
StrCat(arg2_st,"I32 ");
} else if (StrStr(ptr,"64")) {
arg2_size=8;
StrCat(arg2_st,"I64 ");
}
} else {
if (StrStr(ptr,"8")) {
arg2_size=1;
StrCat(arg2_st,"U8 ");
} else if (StrStr(ptr,"16")) {
arg2_size=2;
StrCat(arg2_st,"U16 ");
} else if (StrStr(ptr,"32")) {
arg2_size=4;
StrCat(arg2_st,"U32 ");
} else if (StrStr(ptr,"64")) {
arg2_size=8;
StrCat(arg2_st,"U64 ");
}
if (a2_size=StrStrBits(DefineSub(a2,"ST_ARG_TYPES"))) {
if (Bt(&uasm_signed_arg_mask,a2))
SPrintF(buf2,"I%d ",a2_size);
else
SPrintF(buf2,"U%d ",a2_size);
StrCat(a2_st,buf2);
}
a1_size=arg1_size;
a2_size=arg2_size;
if (tempi->flags & IEF_PLUS_OPCODE) {
ip--;
RM1=*ip++ - tempi->opcode[tempi->opcode_cnt-1]+REX_b;
*buf2=0;
ptr=NULL;
if (ARGT_R8<=a1<=ARGT_R64) {
if (a1_size==1) {
if (a1_size==8) {
if (REX!=-1)
SPrintF(buf2,"%Z",RM1,"ST_U8_REX_REGS");
ptr="ST_U8_REX_REGS";
else
SPrintF(buf2,"%Z",RM1,"ST_U8_REGS");
} else if (a1_size==2)
SPrintF(buf2,"%Z",RM1,"ST_U16_REGS");
else if (a1_size==4)
SPrintF(buf2,"%Z",RM1,"ST_U32_REGS");
else if (a1_size==8)
SPrintF(buf2,"%Z",RM1,"ST_U64_REGS");
StrCat(a1_st,buf2);
ptr="ST_U8_REGS";
} else if (a1_size==16)
ptr="ST_U16_REGS";
else if (a1_size==32)
ptr="ST_U32_REGS";
else if (a1_size==64)
ptr="ST_U64_REGS";
if (ptr)
StrCat(a1_st,DefineSub(RM1,ptr));
} else {
if (a2_size==1) {
if (a2_size==8) {
if (REX!=-1)
SPrintF(buf2,"%Z",RM1,"ST_U8_REX_REGS");
ptr="ST_U8_REX_REGS";
else
SPrintF(buf2,"%Z",RM1,"ST_U8_REGS");
} else if (a2_size==2)
SPrintF(buf2,"%Z",RM1,"ST_U16_REGS");
else if (a2_size==4)
SPrintF(buf2,"%Z",RM1,"ST_U32_REGS");
else if (a2_size==8)
SPrintF(buf2,"%Z",RM1,"ST_U64_REGS");
StrCat(a2_st,buf2);
ptr="ST_U8_REGS";
} else if (a2_size==16)
ptr="ST_U16_REGS";
else if (a2_size==32)
ptr="ST_U32_REGS";
else if (a2_size==64)
ptr="ST_U64_REGS";
if (ptr)
StrCat(a2_st,DefineSub(RM1,ptr));
}
}
if (ARGT_RM8<=a1<=ARGT_RM64 ||
ARGT_M8<=a1<=ARGT_M64 ||
ARGT_RM8<=a2<=ARGT_RM64 ||
ARGT_M8<=a2<=ARGT_M64) {
if (ARGT_RM8<=a2<=ARGT_RM64 ||
ARGT_M8<=a1<=ARGT_M64 ||
ARGT_RM8<=a2<=ARGT_RM64 ||
ARGT_M8<=a2<=ARGT_M64) {
a1_st=arg2_st;
a2_st=arg1_st;
a1_size=arg2_size;
a2_size=arg1_size;
aa1=a2;
aa2=a1;
if (ARGT_RM8<=a2<=ARGT_RM64 ||
ARGT_M8<=a2<=ARGT_M64) {
reloced_a1=a2;
reloced_a2=a1;
reloced_a1_size=a2_size;
reloced_a2_size=a1_size;
reloced_a1_st=a2_st;
reloced_a2_st=a1_st;
} else {
reloced_a1=a1;
reloced_a2=a2;
reloced_a1_size=a1_size;
reloced_a2_size=a2_size;
reloced_a1_st=a1_st;
reloced_a2_st=a2_st;
}
StrCat(a1_st,seg_overrides);
StrCat(reloced_a1_st,seg_overrides);
ModrM=*ip++;
Mod=ModrM>>6 & 3;
RM1=ModrM & 7+REX_b;
RM2=ModrM>>3 & 7+REX_r;
if (Mod<3 && RM1&7==4) {
if (Mod<3 && RM1&7==4)
SIB=*ip++;
}
if (Mod==1) {
disp=*ip(U8 *)++;
SPrintF(buf2,"%02X",disp);
StrCat(a1_st,buf2);
}
if (Mod==2) {
StrCat(reloced_a1_st,buf2);
} else if (Mod==2) {
disp=*ip(U32 *)++;
SPrintF(buf2,"%08X",disp);
StrCat(a1_st,buf2);
StrCat(reloced_a1_st,buf2);
}
if (tempi->slash_val<8)
RM2=-1;
else {
*buf2=0;
if (aa2==ARGT_SREG)
SPrintF(buf2,"%Z",RM2,"ST_SEG_REGS");
else if (!(ARGT_IMM8<=aa2<=ARGT_IMM64) &&
!(ARGT_UIMM8<=aa2<=ARGT_UIMM64)) {
if (a2_size==1) {
ptr=NULL;
if (reloced_a2==ARGT_SREG) {
if (RM2<=5)
ptr="ST_SEG_REGS";
} else if (!(ARGT_IMM8<=reloced_a2<=ARGT_IMM64) &&
!(ARGT_UIMM8<=reloced_a2<=ARGT_UIMM64)) {
if (reloced_a2_size==8) {
if (REX!=-1)
SPrintF(buf2,"%Z",RM2,"ST_U8_REX_REGS");
ptr="ST_U8_REX_REGS";
else
SPrintF(buf2,"%Z",RM2,"ST_U8_REGS");
}else if (a2_size==2)
SPrintF(buf2,"%Z",RM2,"ST_U16_REGS");
else if (a2_size==4)
SPrintF(buf2,"%Z",RM2,"ST_U32_REGS");
else if (a2_size==8)
SPrintF(buf2,"%Z",RM2,"ST_U64_REGS");
ptr="ST_U8_REGS";
} else if (reloced_a2_size==16)
ptr="ST_U16_REGS";
else if (reloced_a2_size==32)
ptr="ST_U32_REGS";
else if (reloced_a2_size==64)
ptr="ST_U64_REGS";
}
StrCat(a2_st,buf2);
if (ptr)
StrCat(reloced_a2_st,DefineSub(RM2,ptr));
}
if (RM1&7==5 && !Mod) {
disp=*ip(I32 *)++;
if (seg_size==64) {
disp+=ip;
if (aa2==ARGT_IMM8 || aa2==ARGT_UIMM8)
if (reloced_a2==ARGT_IMM8 || reloced_a2==ARGT_UIMM8)
disp++;
else if (aa2==ARGT_IMM16 || aa2==ARGT_UIMM16)
else if (reloced_a2==ARGT_IMM16 || reloced_a2==ARGT_UIMM16)
disp+=2;
else if (aa2==ARGT_IMM32 || aa2==ARGT_UIMM32)
else if (reloced_a2==ARGT_IMM32 || reloced_a2==ARGT_UIMM32)
disp+=4;
else if (aa2==ARGT_IMM64 || aa2==ARGT_UIMM64)
else if (reloced_a2==ARGT_IMM64 || reloced_a2==ARGT_UIMM64)
disp+=8;
}
SPrintF(buf2,"[%X] ",disp);
StrCat(a1_st,buf2);
StrCat(reloced_a1_st,buf2);
RM1=-1;
} else {
if (Mod<3) {
@@ -580,101 +552,62 @@ U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
scale=2;
else
scale=1;
if (seg_size==64)
ptr="ST_U64_REGS";
else
ptr="ST_U32_REGS";
if (r1==CREG_RBP && !Mod) {
disp=*ip(U32 *)++;
SPrintF(buf2,"%08X",disp);
StrCat(a1_st,buf2);
if (seg_size!=64)
SPrintF(buf2,"[%Z*%d]",r2,"ST_U32_REGS",scale);
else
SPrintF(buf2,"[%Z*%d]",r2,"ST_U64_REGS",scale);
StrCat(a1_st,buf2);
StrCat(reloced_a1_st,buf2);
SPrintF(buf2,"[%Z*%d]",r2,ptr,scale);
StrCat(reloced_a1_st,buf2);
} else if (r2==4) {
if (seg_size!=64)
SPrintF(buf2,"[%Z]",r1,"ST_U32_REGS");
else
SPrintF(buf2,"[%Z]",r1,"ST_U64_REGS");
StrCat(a1_st,buf2);
SPrintF(buf2,"[%Z]",r1,ptr);
StrCat(reloced_a1_st,buf2);
} else {
if (seg_size!=64)
SPrintF(buf2,"[%Z+%Z*%d]",r1,"ST_U32_REGS",
r2,"ST_U32_REGS",scale);
else
SPrintF(buf2,"[%Z+%Z*%d]",r1,"ST_U64_REGS",
r2,"ST_U64_REGS",scale);
StrCat(a1_st,buf2);
SPrintF(buf2,"[%Z+%Z*%d]",r1,ptr,r2,ptr,scale);
StrCat(reloced_a1_st,buf2);
}
} else {
*buf2=0;
if (opadd==16)
SPrintF(buf2,"[%Z]",RM1,"ST_U16_REGS");
ptr="ST_U16_REGS";
else if (opadd==32)
SPrintF(buf2,"[%Z]",RM1,"ST_U32_REGS");
ptr="ST_U32_REGS";
else
SPrintF(buf2,"[%Z]",RM1,"ST_U64_REGS");
StrCat(a1_st,buf2);
ptr="ST_U64_REGS";
SPrintF(buf2,"[%Z]",RM1,ptr);
StrCat(reloced_a1_st,buf2);
}
} else {
*buf2=0;
if (a1_size==1) {
ptr=NULL;
if (reloced_a1_size==8) {
if (REX!=-1)
SPrintF(buf2,"%Z",RM1,"ST_U8_REX_REGS");
ptr="ST_U8_REX_REGS";
else
SPrintF(buf2,"%Z",RM1,"ST_U8_REGS");
} else if (a1_size==2)
SPrintF(buf2,"%Z",RM1,"ST_U16_REGS");
else if (a1_size==4)
SPrintF(buf2,"%Z",RM1,"ST_U32_REGS");
else if (a1_size==8)
SPrintF(buf2,"%Z",RM1,"ST_U64_REGS");
StrCat(a1_st,buf2);
ptr="ST_U8_REGS";
} else if (reloced_a1_size==16)
ptr="ST_U16_REGS";
else if (reloced_a1_size==32)
ptr="ST_U32_REGS";
else if (reloced_a1_size==64)
ptr="ST_U64_REGS";
if (ptr)
StrCat(reloced_a1_st,DefineSub(RM1,ptr));
}
}
}
if (ARGT_MOFFS8<=a1<=ARGT_MOFFS64) {
StrCat(arg1_st,seg_overrides);
if (arg1_size==1) {
disp=*ip(U8 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg1_st,buf2);
} else if (opadd==16) {
disp=*ip(U16 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg1_st,buf2);
} else {
disp=*ip(U32 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg1_st,buf2);
}
}
if (ARGT_MOFFS8<=a2<=ARGT_MOFFS64) {
StrCat(arg2_st,seg_overrides);
if (arg2_size==1) {
disp=*ip(U8 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg2_st,buf2);
} else if (opadd==16) {
disp=*ip(U16 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg2_st,buf2);
} else {
disp=*ip(U32 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(arg2_st,buf2);
}
}
switch (a1) {
case ARGT_IMM8:
case ARGT_UIMM8:
imm=*ip(U8 *)++;
SPrintF(buf2,"%02X",imm);
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
if (tempi->opcode[0]==0xCD) {
if (ptr=DefineSub(imm,"ST_INT_NAMES")) {
StrCat(arg1_st," ");
StrCat(arg1_st,ptr);
StrCat(a1_st," ");
StrCat(a1_st,ptr);
}
}
break;
@@ -682,84 +615,94 @@ U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
case ARGT_UIMM16:
imm=*ip(U16 *)++;
SPrintF(buf2,"%04X",imm);
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_IMM32:
case ARGT_UIMM32:
imm=*ip(U32 *)++;
SPrintF(buf2,"%08X",imm);
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_IMM64:
case ARGT_UIMM64:
imm=*ip(I64 *)++;
SPrintF(buf2,"%016X",imm);
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_REL8:
disp=*ip(I8 *)++;
disp+=ip;
SPrintF(buf2,"%P ",disp);
if (_jmp_dst) *_jmp_dst=disp;
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_REL16:
disp=*ip(I16 *)++;
disp+=ip;
SPrintF(buf2,"%P ",disp);
if (_jmp_dst) *_jmp_dst=disp;
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_REL32:
disp=*ip(I32 *)++;
disp+=ip;
SPrintF(buf2,"%P ",disp);
if (_jmp_dst) *_jmp_dst=disp;
StrCat(arg1_st,buf2);
StrCat(a1_st,buf2);
break;
case ARGT_MOFFS8...ARGT_MOFFS64:
StrCat(a1_st,seg_overrides);
if (a1_size==8)
disp=*ip(U8 *)++;
else if (opadd==16)
disp=*ip(U16 *)++;
else
disp=*ip(U32 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(a1_st,buf2);
break;
case ARGT_CL:
StrCat(arg1_st,"CL");
StrCat(a1_st,"CL");
break;
case ARGT_AL:
StrCat(arg1_st,"AL");
StrCat(a1_st,"AL");
break;
case ARGT_AX:
StrCat(arg1_st,"AX");
StrCat(a1_st,"AX");
break;
case ARGT_EAX:
StrCat(arg1_st,"EAX");
StrCat(a1_st,"EAX");
break;
case ARGT_RAX:
StrCat(arg1_st,"RAX");
StrCat(a1_st,"RAX");
break;
case ARGT_DX:
StrCat(arg1_st,"DX");
StrCat(a1_st,"DX");
break;
case ARGT_SS:
StrCat(arg1_st,"SS");
StrCat(a1_st,"SS");
break;
case ARGT_DS:
StrCat(arg1_st,"DS");
StrCat(a1_st,"DS");
break;
case ARGT_ES:
StrCat(arg1_st,"ES");
StrCat(a1_st,"ES");
break;
case ARGT_FS:
StrCat(arg1_st,"FS");
StrCat(a1_st,"FS");
break;
case ARGT_GS:
StrCat(arg1_st,"GS");
StrCat(a1_st,"GS");
break;
case ARGT_CS:
StrCat(arg1_st,"CS");
StrCat(a1_st,"CS");
break;
case ARGT_ST0:
StrCat(arg1_st,"ST0");
StrCat(a1_st,"ST0");
break;
case ARGT_STI:
ip--;
SPrintF(buf2,"%Z",*ip++ - tempi->opcode[tempi->opcode_cnt-1],"ST_FSTK_REGS");
StrCat(arg1_st,buf2);
StrCat(a1_st,DefineSub(*ip++ - tempi->opcode[tempi->opcode_cnt-1],"ST_FSTK_REGS"));
break;
}
@@ -768,97 +711,107 @@ U0 Ui(U8 *buf,U8 **_ip,I64 seg_size=64,I64 *_jmp_dst=NULL,Bool just_ins=FALSE)
case ARGT_UIMM8:
imm=*ip(U8 *)++;
SPrintF(buf2,"%02X",imm);
StrCat(arg2_st,buf2);
StrCat(a2_st,buf2);
break;
case ARGT_IMM16:
case ARGT_UIMM16:
imm=*ip(U16 *)++;
SPrintF(buf2,"%04X",imm);
StrCat(arg2_st,buf2);
StrCat(a2_st,buf2);
break;
case ARGT_IMM32:
case ARGT_UIMM32:
imm=*ip(U32 *)++;
SPrintF(buf2,"%08X",imm);
StrCat(arg2_st,buf2);
StrCat(a2_st,buf2);
break;
case ARGT_IMM64:
case ARGT_UIMM64:
imm=*ip(I64 *)++;
SPrintF(buf2,"%016X",imm);
StrCat(arg2_st,buf2);
StrCat(a2_st,buf2);
break;
case ARGT_MOFFS8...ARGT_MOFFS64:
StrCat(a2_st,seg_overrides);
if (a2_size==8)
disp=*ip(U8 *)++;
else if (opadd==16)
disp=*ip(U16 *)++;
else
disp=*ip(U32 *)++;
SPrintF(buf2,"[%X]",disp);
StrCat(a2_st,buf2);
break;
case ARGT_CL:
StrCat(arg2_st,"CL");
StrCat(a2_st,"CL");
break;
case ARGT_AL:
StrCat(arg2_st,"AL");
StrCat(a2_st,"AL");
break;
case ARGT_AX:
StrCat(arg2_st,"AX");
StrCat(a2_st,"AX");
break;
case ARGT_EAX:
StrCat(arg2_st,"EAX");
StrCat(a2_st,"EAX");
break;
case ARGT_RAX:
StrCat(arg2_st,"RAX");
StrCat(a2_st,"RAX");
break;
case ARGT_DX:
StrCat(arg2_st,"DX");
StrCat(a2_st,"DX");
break;
case ARGT_SS:
StrCat(arg2_st,"SS");
StrCat(a2_st,"SS");
break;
case ARGT_DS:
StrCat(arg2_st,"DS");
StrCat(a2_st,"DS");
break;
case ARGT_ES:
StrCat(arg2_st,"ES");
StrCat(a2_st,"ES");
break;
case ARGT_FS:
StrCat(arg2_st,"FS");
StrCat(a2_st,"FS");
break;
case ARGT_GS:
StrCat(arg2_st,"GS");
StrCat(a2_st,"GS");
break;
case ARGT_CS:
StrCat(arg2_st,"CS");
StrCat(a2_st,"CS");
break;
case ARGT_ST0:
StrCat(arg2_st,"ST0");
StrCat(a2_st,"ST0");
break;
case ARGT_STI:
ip--;
SPrintF(buf2,"%Z",*ip++ - tempi->opcode[tempi->opcode_cnt-1],"ST_FSTK_REGS");
StrCat(arg2_st,buf2);
StrCat(a2_st,DefineSub(*ip++ - tempi->opcode[tempi->opcode_cnt-1],"ST_FSTK_REGS"));
break;
}
if (tempi->flags&IEF_ENDING_ZERO)
ip++;
if (*arg1_st) {
StrCat(buf,"\t");
StrCat(buf,arg1_st);
if (*a1_st) {
StrCat(line1,"\t");
StrCat(line1,a1_st);
}
if (*arg2_st) {
StrCat(buf,",");
StrCat(buf,arg2_st);
if (*a2_st) {
StrCat(line1,",");
StrCat(line1,a2_st);
}
StrCat(line1,"\n");
StrCat(line2,"\n");
if (!just_ins) {
for (i=ip-(*_ip)(I64);i<6;i++) {
bin_data_area[i<<1]=CH_SPACE;
bin_data_area[i<<1+1]=CH_SPACE;
bin_data_area1[i<<1]=CH_SPACE;
bin_data_area1[i<<1+1]=CH_SPACE;
}
for (i=ip-(*_ip)(I64);i<12;i++) {
bin_data_area2[(i-6)<<1]=CH_SPACE;
bin_data_area2[(i-6)<<1+1]=CH_SPACE;
}
}
StrCat(buf,"\n");
if (!just_ins && ip-(*_ip)(I64)>6) {
StrCat(buf,buf3);
StrCat(buf,"\n");
}
StrCpy(buf,line1);
if (!just_ins && ip-(*_ip)(I64)>6)
StrCat(buf,line2);
*_ip=ip;
}