Changeset 36 in dev for BasicCompiler64
- Timestamp:
- Jan 20, 2007, 4:55:26 AM (18 years ago)
- Location:
- BasicCompiler64
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/Compile_Calc.cpp
r11 r36 2 2 #include "Opcode.h" 3 3 4 void ChangeTypeToDouble_ToFpuReg(int OldType){5 //現在のスタックの内容を実数レジスタに保存する6 //NumOpeの直後専用7 if(OldType==DEF_DOUBLE){8 //fld qword ptr[esp]9 op_fld_ptr_esp(DEF_DOUBLE);10 11 //add esp,812 op_add_esp(8);13 }14 else if(OldType==DEF_SINGLE){15 //fld dword ptr[esp]16 op_fld_ptr_esp(DEF_SINGLE);17 18 //add esp,419 op_add_esp(4);20 }21 else if(OldType==DEF_LONG){22 //fild dword ptr[esp]23 op_fld_ptr_esp(DEF_LONG);24 25 //add esp,426 op_add_esp(4);27 }28 else if(OldType==DEF_DWORD){29 //pop eax30 op_pop(REG_EAX);31 32 //push 033 op_push_value(0);34 35 //push eax36 op_push(REG_EAX);37 38 //fild qword ptr[esp]39 OpBuffer[obp++]=(char)0xDF;40 OpBuffer[obp++]=(char)0x2C;41 OpBuffer[obp++]=(char)0x24;42 43 //add esp,844 op_add_esp(8);45 }46 }47 void ChangeTypeToDouble(int OldType){48 //現在のスタックの内容をdouble型に変換する49 //NumOpeの直後専用50 if(OldType==DEF_DOUBLE) return;51 else if(OldType==DEF_SINGLE){52 //fld dword ptr[esp]53 op_fld_ptr_esp(DEF_SINGLE);54 55 //sub esp,456 op_sub_esp(4);57 58 //fstp qword ptr[esp]59 OpBuffer[obp++]=(char)0xDD;60 OpBuffer[obp++]=(char)0x1C;61 OpBuffer[obp++]=(char)0x24;62 }63 else if(OldType==DEF_INT64||OldType==DEF_QWORD){64 //64ビット整数型65 66 //fild qword ptr[esp]67 op_fld_ptr_esp(DEF_INT64);68 69 //fstp qword ptr[esp]70 OpBuffer[obp++]=(char)0xDD;71 OpBuffer[obp++]=(char)0x1C;72 OpBuffer[obp++]=(char)0x24;73 }74 else if(IsWholeNumberType(OldType)){75 //その他整数型76 77 if(IsSignedType(OldType)){78 //符号あり79 80 if(OldType==DEF_INTEGER){81 //pop eax82 op_pop(REG_EAX);83 84 //movsx eax,ax85 OpBuffer[obp++]=(char)0x0F;86 OpBuffer[obp++]=(char)0xBF;87 OpBuffer[obp++]=(char)0xC0;88 89 //push eax90 op_push(REG_EAX);91 }92 else if(OldType==DEF_CHAR){93 //pop eax94 op_pop(REG_EAX);95 96 //movsx eax,al97 OpBuffer[obp++]=(char)0x0F;98 OpBuffer[obp++]=(char)0xBE;99 OpBuffer[obp++]=(char)0xC0;100 101 //push eax102 op_push(REG_EAX);103 }104 105 //fild dword ptr[esp]106 op_fld_ptr_esp(DEF_LONG);107 108 //sub esp,4109 op_sub_esp(4);110 }111 else{112 //符号なし113 114 //pop eax115 op_pop(REG_EAX);116 117 //push 0118 op_push_value(0);119 120 //push eax121 op_push(REG_EAX);122 123 //fild qword ptr[esp]124 OpBuffer[obp++]=(char)0xDF;125 OpBuffer[obp++]=(char)0x2C;126 OpBuffer[obp++]=(char)0x24;127 }128 129 //fstp qword ptr[esp]130 OpBuffer[obp++]=(char)0xDD;131 OpBuffer[obp++]=(char)0x1C;132 OpBuffer[obp++]=(char)0x24;133 }134 else SetError(9,NULL,cp);135 }136 void ChangeTypeToSingle(int OldType){137 //現在のスタックの内容をfloat型に変換する138 //NumOpeの直後専用139 if(OldType==DEF_SINGLE) return;140 else if(OldType==DEF_DOUBLE){141 //fld qword ptr[esp]142 op_fld_ptr_esp(DEF_DOUBLE);143 144 //add esp,4145 op_add_esp(4);146 147 //fstp dword ptr[esp]148 OpBuffer[obp++]=(char)0xD9;149 OpBuffer[obp++]=(char)0x1C;150 OpBuffer[obp++]=(char)0x24;151 }152 else if(OldType==DEF_INT64||OldType==DEF_QWORD){153 //64ビット整数型154 155 //fild qword ptr[esp]156 op_fld_ptr_esp(DEF_INT64);157 158 //add esp,4159 op_add_esp(4);160 161 //fstp dword ptr[esp]162 OpBuffer[obp++]=(char)0xD9;163 OpBuffer[obp++]=(char)0x1C;164 OpBuffer[obp++]=(char)0x24;165 }166 else if(IsWholeNumberType(OldType)){167 //その他整数型168 169 if(IsSignedType(OldType)){170 //符号あり171 172 if(OldType==DEF_INTEGER){173 //pop eax174 op_pop(REG_EAX);175 176 //movsx eax,ax177 OpBuffer[obp++]=(char)0x0F;178 OpBuffer[obp++]=(char)0xBF;179 OpBuffer[obp++]=(char)0xC0;180 181 //push eax182 op_push(REG_EAX);183 }184 else if(OldType==DEF_CHAR){185 //pop eax186 op_pop(REG_EAX);187 188 //movsx eax,al189 OpBuffer[obp++]=(char)0x0F;190 OpBuffer[obp++]=(char)0xBE;191 OpBuffer[obp++]=(char)0xC0;192 193 //push eax194 op_push(REG_EAX);195 }196 197 //fild dword ptr[esp]198 op_fld_ptr_esp(DEF_LONG);199 }200 else{201 //符号なし202 203 //fild dword ptr[esp]204 op_fld_ptr_esp(DEF_LONG);205 }206 207 //fstp dword ptr[esp]208 OpBuffer[obp++]=(char)0xD9;209 OpBuffer[obp++]=(char)0x1C;210 OpBuffer[obp++]=(char)0x24;211 }212 else SetError(9,NULL,cp);213 }214 void ChangeTypeToInt64(int OldType){215 //現在のスタックの内容をInt64型に変換する216 //NumOpeの直後専用217 if(Is64Type(OldType)) return;218 219 else if(OldType==DEF_DOUBLE){220 //fld qword ptr[esp]221 op_fld_ptr_esp(DEF_DOUBLE);222 223 //fistp qword ptr[esp]224 OpBuffer[obp++]=(char)0xDF;225 OpBuffer[obp++]=(char)0x3C;226 OpBuffer[obp++]=(char)0x24;227 }228 else if(OldType==DEF_SINGLE){229 //fld dword ptr[esp]230 op_fld_ptr_esp(DEF_SINGLE);231 232 //sub esp,4233 op_sub_esp(4);234 235 //fistp qword ptr[esp]236 OpBuffer[obp++]=(char)0xDF;237 OpBuffer[obp++]=(char)0x3C;238 OpBuffer[obp++]=(char)0x24;239 }240 else if(IsWholeNumberType(OldType)){241 //その他整数242 243 if(IsSignedType(OldType)){244 //符号あり245 246 //pop eax247 op_pop(REG_EAX);248 249 //cdq250 OpBuffer[obp++]=(char)0x99;251 252 //push edx253 op_push(REG_EDX);254 255 //push eax256 op_push(REG_EAX);257 }258 else{259 //符号なし260 261 //pop eax262 op_pop(REG_EAX);263 264 //push 0265 op_push_value(0);266 267 //push eax268 op_push(REG_EAX);269 }270 }271 else SetError(9,NULL,cp);272 }273 void ChangeTypeToLong(int OldType){274 //現在のスタックの内容をLong型に変換する275 //NumOpeの直後専用276 if(OldType==DEF_DOUBLE){277 //fld qword ptr[esp]278 op_fld_ptr_esp(DEF_DOUBLE);279 280 //add esp,4281 op_add_esp(4);282 283 //fistp dword ptr[esp]284 OpBuffer[obp++]=(char)0xDB;285 OpBuffer[obp++]=(char)0x1C;286 OpBuffer[obp++]=(char)0x24;287 }288 else if(OldType==DEF_SINGLE){289 //fld dword ptr[esp]290 op_fld_ptr_esp(DEF_SINGLE);291 292 //fistp dword ptr[esp]293 OpBuffer[obp++]=(char)0xDB;294 OpBuffer[obp++]=(char)0x1C;295 OpBuffer[obp++]=(char)0x24;296 }297 else if(OldType==DEF_INT64||OldType==DEF_QWORD){298 //pop eax299 op_pop(REG_EAX);300 301 //add esp,4302 op_add_esp(4);303 304 //push eax305 op_push(REG_EAX);306 }307 }308 void ChangeTypeToInteger(int OldType){309 //現在のスタックの内容をInteger型に変換する310 if(OldType==DEF_BYTE||OldType==DEF_CHAR||311 OldType==DEF_WORD||OldType==DEF_INTEGER) return;312 313 ChangeTypeToLong(OldType);314 315 //pop eax316 op_pop(REG_EAX);317 318 //and eax,0000FFFFh319 OpBuffer[obp++]=(char)0x25;320 *((long *)(OpBuffer+obp))=0x0000FFFF;321 obp+=sizeof(long);322 323 //push eax324 op_push(REG_EAX);325 }326 void ChangeTypeToByte(int OldType){327 //現在のスタックの内容をbyte型に変換する328 if(OldType==DEF_BYTE||OldType==DEF_CHAR) return;329 330 ChangeTypeToLong(OldType);331 332 //pop eax333 op_pop(REG_EAX);334 335 //and eax,000000FFh336 OpBuffer[obp++]=(char)0x25;337 *((long *)(OpBuffer+obp))=0x000000FF;338 obp+=sizeof(long);339 340 //push eax341 op_push(REG_EAX);342 }343 344 4 void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar){ 345 5 ///////////////////////////////////////////////// … … 347 7 ///////////////////////////////////////////////// 348 8 9 if(VarType==DEF_BOOLEAN){ 10 //bool 11 SetBooleanVariable(CalcType,pRelativeVar); 12 } 349 13 if(VarType==DEF_CHAR||VarType==DEF_BYTE){ 350 14 //8ビット変数へalレジスタの内容を格納する -
BasicCompiler64/Compile_Set_Var.cpp
r28 r36 298 298 } 299 299 } 300 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative){ 301 if(type==DEF_DOUBLE){ 302 //Double型 303 304 //cvttsd2si rax,xmm0 305 op_cvttsd2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 306 } 307 else if(type==DEF_SINGLE){ 308 //Single型 309 310 //cvttss2si rax,xmm0 311 op_cvttss2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 312 } 313 314 //cmp rax,0 315 op_cmp_value(GetTypeSize(type,-1),REG_RAX,0); 316 317 //setne al 318 op_setne( REG_RAX ); 319 320 SetWholeVariable( sizeof(char), DEF_BYTE, pRelative); 321 } 300 322 void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative){ 301 323 if(type==DEF_DOUBLE){ -
BasicCompiler64/Compile_Statement.cpp
r34 r36 293 293 void OpcodeWhile(char *Parameter){ 294 294 extern HANDLE hHeap; 295 int i2;296 295 297 296 //Continueアドレスのバックアップとセット -
BasicCompiler64/Compile_Var.cpp
r34 r36 864 864 else if(type==DEF_INTEGER||type==DEF_WORD) 865 865 *(WORD *)(initGlobalBuf+offset)=(WORD)i64data; 866 else if(type==DEF_CHAR||type==DEF_BYTE )866 else if(type==DEF_CHAR||type==DEF_BYTE||type==DEF_BOOLEAN) 867 867 *(BYTE *)(initGlobalBuf+offset)=(BYTE)i64data; 868 868 … … 1034 1034 obp+=sizeof(long)+sizeof(short); 1035 1035 } 1036 else if(type==DEF_CHAR||type==DEF_BYTE ){1036 else if(type==DEF_CHAR||type==DEF_BYTE||type==DEF_BOOLEAN){ 1037 1037 //mov byte ptr[rsp+offset],value 1038 1038 op_mov_MV(sizeof(char),REG_RSP,offset,USE_OFFSET,(int)i64data); -
BasicCompiler64/NumOpe_Logical.cpp
r3 r36 88 88 int reg; 89 89 90 if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){ 90 if( type[sp - 1] == DEF_BOOLEAN ){ 91 SetOneTermToReg_Whole32Calc(type[sp-1],®); 92 93 if( reg != REG_RAX ){ 94 //mov rax,qword ptr[rsp+offset] ※スタックフレームを利用 95 pobj_sf->pop(REG_RAX); 96 } 97 98 //cmp reg,0 99 op_cmp_value(GetTypeSize(type[sp-1],-1),reg,0); 100 101 //setne al 102 op_setne( REG_RAX ); 103 104 //and rax,000000FFh 105 op_and64_value(REG_RAX,(int)0xFF); 106 107 //neg 108 op_neg( REG_RAX ); 109 110 //sbb rax, rax 111 op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX ); 112 113 //add rax, 1 114 op_add64_value( REG_RAX, 1 ); 115 116 if( reg != REG_RAX ){ 117 //mov reg,rax 118 op_mov_RR( reg, REG_RAX ); 119 120 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用 121 pobj_sf->push(REG_RAX); 122 } 123 124 if(reg==REG_R14){ 125 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用 126 pobj_sf->push(REG_R14); 127 } 128 } 129 else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){ 91 130 SetOneTermToReg_Whole64Calc(type[sp-1],®); 92 131 -
BasicCompiler64/NumOpe_Relation.cpp
r3 r36 137 137 op_zero_reg(reg1); 138 138 139 //jmp 7( xorを飛び越す)139 //jmp 7(次のmovを飛び越す) 140 140 OpBuffer[obp++]=(char)0xEB; 141 141 OpBuffer[obp++]=(char)0x07; … … 143 143 144 144 /////////////////// 145 // T RUEをセット145 // Trueをセット 146 146 /////////////////// 147 147 148 //mov reg1, -1149 op_mov_RV(sizeof(_int64),reg1, -1);148 //mov reg1,1 149 op_mov_RV(sizeof(_int64),reg1,1); 150 150 151 151 … … 159 159 *pStackPointer=sp; 160 160 161 type[sp-1]=DEF_ LONG;161 type[sp-1]=DEF_BOOLEAN; 162 162 163 163 return 1; -
BasicCompiler64/NumOpe_TypeOperation.cpp
r3 r36 22 22 op_movsx64_FromReg8(reg,reg); 23 23 } 24 else if(type==DEF_BYTE ){24 else if(type==DEF_BYTE || type==DEF_BOOLEAN){ 25 25 //and reg,00000000000000FFh 26 26 op_and64_value(reg,(int)0x00FF); … … 40 40 op_movsx32_FromReg8(reg,reg); 41 41 } 42 else if(type==DEF_BYTE ){42 else if(type==DEF_BYTE || type==DEF_BOOLEAN){ 43 43 //and reg,000000FFh 44 44 op_and32_value(reg,(int)0xFF); -
BasicCompiler64/Opcode.h
r34 r36 243 243 244 244 //Compile_Calc.cpp 245 void ChangeTypeToDouble_ToFpuReg(int OldType);246 void ChangeTypeToDouble(int OldType);247 void ChangeTypeToSingle(int OldType);248 void ChangeTypeToInt64(int OldType);249 void ChangeTypeToLong(int OldType);250 void ChangeTypeToInteger(int OldType);251 void ChangeTypeToByte(int OldType);252 245 void SetVariableFromRax(int VarType,int CalcType,RELATIVE_VAR *pRelativeVar); 253 246 void OpcodeCalc(char *Command); … … 292 285 void SetDoubleVariable(int type,RELATIVE_VAR *pRelative); 293 286 void SetSingleVariable(int type,RELATIVE_VAR *pRelative); 287 void SetBooleanVariable(int type,RELATIVE_VAR *pRelative); 294 288 void SetWholeVariable(int var_size,int type,RELATIVE_VAR *pRelative); 295 289 … … 303 297 #define EXP_TYPE_VAR 4 304 298 int NumOpEx(char *Command,double *pDbl,DWORD *pdwType,RELATIVE_VAR *pRelativeVar); 305 306 //SetVar.cpp307 BOOL SetVariable(DWORD dwVarType,RELATIVE_VAR *pVarRelativeVar,308 DWORD dwExpType,DWORD dwType,void *data);309 299 310 300 //Compile_Calc_PushVar.cpp … … 475 465 void op_sub64_reg (int reg1,int reg2); 476 466 void op_sub32_reg (int reg1,int reg2); 467 void op_sbb_RR ( int op_size, int reg1, int reg2 ); 477 468 void op_imul_reg (int op_size,int reg1,int reg2); 478 469 void op_imul_value (int op_size,int reg,int i32data); … … 488 479 void op_xor_reg (int op_size,int reg1,int reg2); 489 480 void op_not_reg (int op_size,int reg); 481 void op_neg ( int reg ); 490 482 void op_test (int reg1,int reg2); 491 483 void op_cmp_reg (int op_size,int reg1,int reg2); 492 484 void op_cmp_value (int op_size,int reg,char byte_data); 485 void op_setne (int reg); 493 486 void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod); 494 487 void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod); -
BasicCompiler64/amd64_main.cpp
r19 r36 824 824 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2)); 825 825 } 826 void op_sbb_RR( int op_size, int reg1, int reg2 ){ 827 //sbb reg1,reg2 828 829 //rexプリフィックス 830 set_rex(0,reg1,0,reg2); 831 832 //オペコード 833 OpBuffer[obp++]=(char)0x1B; 834 835 //レジスタ 836 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2)); 837 } 826 838 827 839 … … 1283 1295 OpBuffer[obp++]=(char)(0xD0| REGISTER_OPERAND(reg)); 1284 1296 } 1297 void op_neg( int reg ){ 1298 //neg reg 1299 1300 //オペコード 1301 OpBuffer[obp++]=(char)0xF7; 1302 1303 //レジスタ 1304 OpBuffer[obp++]=(char)(0xD8| REGISTER_OPERAND(reg)); 1305 } 1285 1306 1286 1307 … … 1382 1403 //8ビット値 1383 1404 OpBuffer[obp++]=byte_data; 1405 } 1406 void op_setne( int reg ){ 1407 //オペコード 1408 OpBuffer[obp++]=(char)0x0F; 1409 OpBuffer[obp++]=(char)0x95; 1410 1411 //レジスタ 1412 OpBuffer[obp++]=(char)( 0xC0 | REGISTER_OPERAND(reg) ); 1384 1413 } 1385 1414 -
BasicCompiler64/varlist.cpp
r3 r36 129 129 temporary[1]=0; 130 130 sprintf(lptv->item.pszText,"%s %d(&H%X)'%s'",VarName,byteData,byteData,temporary); 131 } 132 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS); 133 } 134 else if(type==DEF_BOOLEAN){ 135 if(ReadProcessMemory(hDebugProcess,(void *)offset,&byteData,sizeof(BYTE),&stAccBytes)){ 136 if( byteData ) lstrcpy( temporary, "True" ); 137 else lstrcpy( temporary, "False" ); 138 139 wsprintf(lptv->item.pszText,"%s %s",VarName,temporary); 131 140 } 132 141 else sprintf(lptv->item.pszText,"%s %s",VarName,STRING_CANNOTACCESS);
Note:
See TracChangeset
for help on using the changeset viewer.