Changeset 36 in dev for BasicCompiler64/Compile_Calc.cpp
- Timestamp:
- Jan 20, 2007, 4:55:26 AM (18 years ago)
- File:
-
- 1 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レジスタの内容を格納する
Note:
See TracChangeset
for help on using the changeset viewer.