| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <Compiler.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "../BasicCompiler_Common/common.h"
|
|---|
| 6 | #include "Opcode.h"
|
|---|
| 7 |
|
|---|
| 8 | void GetStackData_ToRegister(int *type,int sp){
|
|---|
| 9 | /*NumOpeポーランドのスタック蓄積による演算内容(2つのデータ)を
|
|---|
| 10 | レジスタedx:eax、ecx:ebxに取得する*/
|
|---|
| 11 |
|
|---|
| 12 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 13 | //fld qword ptr[esp]
|
|---|
| 14 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 15 |
|
|---|
| 16 | //fistp qword ptr[esp]
|
|---|
| 17 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 18 |
|
|---|
| 19 | //pop ebx
|
|---|
| 20 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 21 |
|
|---|
| 22 | //pop ecx
|
|---|
| 23 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 24 | }
|
|---|
| 25 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 26 | //fld dword ptr[esp]
|
|---|
| 27 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 28 |
|
|---|
| 29 | //sub esp,4
|
|---|
| 30 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 31 |
|
|---|
| 32 | //fistp qword ptr[esp]
|
|---|
| 33 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 34 |
|
|---|
| 35 | //pop ebx
|
|---|
| 36 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 37 |
|
|---|
| 38 | //pop ecx
|
|---|
| 39 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 40 | }
|
|---|
| 41 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 42 | //pop ebx
|
|---|
| 43 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 44 |
|
|---|
| 45 | //pop ecx
|
|---|
| 46 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 47 | }
|
|---|
| 48 | else{
|
|---|
| 49 | //pop eax
|
|---|
| 50 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 51 |
|
|---|
| 52 | if(IsSignedType(type[sp-1])){
|
|---|
| 53 | //符号拡張
|
|---|
| 54 | //edx:eax ← eax
|
|---|
| 55 |
|
|---|
| 56 | //cdq
|
|---|
| 57 | compiler.codeGenerator.op_cdq();
|
|---|
| 58 | }
|
|---|
| 59 | else{
|
|---|
| 60 | //ビット拡張
|
|---|
| 61 | //edx:eax ← eax
|
|---|
| 62 |
|
|---|
| 63 | //xor edx,edx
|
|---|
| 64 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | //mov ebx,eax
|
|---|
| 68 | compiler.codeGenerator.op_mov_RR( REG_EBX, REG_EAX );
|
|---|
| 69 |
|
|---|
| 70 | //mov ecx,edx
|
|---|
| 71 | compiler.codeGenerator.op_mov_RR( REG_ECX, REG_EDX );
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | //第1項を64ビットに対応させる
|
|---|
| 75 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 76 | //fld qword ptr[esp]
|
|---|
| 77 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 78 |
|
|---|
| 79 | //fistp qword ptr[esp]
|
|---|
| 80 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 81 |
|
|---|
| 82 | //pop eax
|
|---|
| 83 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 84 |
|
|---|
| 85 | //pop edx
|
|---|
| 86 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 87 | }
|
|---|
| 88 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 89 | //fld dword ptr[esp]
|
|---|
| 90 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 91 |
|
|---|
| 92 | //sub esp,4
|
|---|
| 93 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 94 |
|
|---|
| 95 | //fistp qword ptr[esp]
|
|---|
| 96 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 97 |
|
|---|
| 98 | //pop eax
|
|---|
| 99 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 100 |
|
|---|
| 101 | //pop edx
|
|---|
| 102 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 103 | }
|
|---|
| 104 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 105 | //pop eax
|
|---|
| 106 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 107 |
|
|---|
| 108 | //pop edx
|
|---|
| 109 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 110 | }
|
|---|
| 111 | else{
|
|---|
| 112 | //pop eax
|
|---|
| 113 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 114 |
|
|---|
| 115 | if(IsSignedType(type[sp-2])){
|
|---|
| 116 | //符号拡張
|
|---|
| 117 | //edx:eax ← eax
|
|---|
| 118 |
|
|---|
| 119 | //cdq
|
|---|
| 120 | compiler.codeGenerator.op_cdq();
|
|---|
| 121 | }
|
|---|
| 122 | else{
|
|---|
| 123 | //ビット拡張
|
|---|
| 124 | //edx:eax ← eax
|
|---|
| 125 |
|
|---|
| 126 | //xor edx,edx
|
|---|
| 127 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void FormatStackData_To64bit(int *type,int sp){
|
|---|
| 133 | //NumOpeポーランドのスタック蓄積による演算内容(2つのデータ)を64ビット整数型にする
|
|---|
| 134 |
|
|---|
| 135 | GetStackData_ToRegister(type,sp);
|
|---|
| 136 |
|
|---|
| 137 | //push ecx
|
|---|
| 138 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 139 |
|
|---|
| 140 | //push ebx
|
|---|
| 141 | compiler.codeGenerator.op_push(REG_EBX);
|
|---|
| 142 |
|
|---|
| 143 | //push edx
|
|---|
| 144 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 145 |
|
|---|
| 146 | //push eax
|
|---|
| 147 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | BOOL CalcTwoTerm_Arithmetic(int idCalc,int *type,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 151 | /* value[sp-2] = value[sp-2] + value[sp-1]
|
|---|
| 152 | value[sp-2] = value[sp-2] - value[sp-1]
|
|---|
| 153 | value[sp-2] = value[sp-2] * value[sp-1] */
|
|---|
| 154 |
|
|---|
| 155 | int sp;
|
|---|
| 156 | sp=*pStackPointer;
|
|---|
| 157 |
|
|---|
| 158 | int AnswerType;
|
|---|
| 159 | AnswerType=NeutralizationType(type[sp-2],index_stack[sp-2],type[sp-1],index_stack[sp-1]);
|
|---|
| 160 |
|
|---|
| 161 | if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
|
|---|
| 162 | type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
|
|---|
| 163 | /////////////
|
|---|
| 164 | // 実数演算
|
|---|
| 165 | /////////////
|
|---|
| 166 |
|
|---|
| 167 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 168 | //fld qword ptr[esp]
|
|---|
| 169 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 170 |
|
|---|
| 171 | //add esp,8
|
|---|
| 172 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 173 | }
|
|---|
| 174 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 175 | //fld dword ptr[esp]
|
|---|
| 176 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 177 |
|
|---|
| 178 | //add esp,4
|
|---|
| 179 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 180 | }
|
|---|
| 181 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 182 | //64ビット整数値
|
|---|
| 183 |
|
|---|
| 184 | //fild qword ptr[esp]
|
|---|
| 185 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 186 |
|
|---|
| 187 | //add esp,8
|
|---|
| 188 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 189 | }
|
|---|
| 190 | else{
|
|---|
| 191 | //その他整数型
|
|---|
| 192 |
|
|---|
| 193 | //fild dword ptr[esp]
|
|---|
| 194 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 195 |
|
|---|
| 196 | //add esp,4
|
|---|
| 197 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 201 | //fld qword ptr[esp]
|
|---|
| 202 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 203 | }
|
|---|
| 204 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 205 | //fld dword ptr[esp]
|
|---|
| 206 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 207 | }
|
|---|
| 208 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 209 | //64ビット整数値
|
|---|
| 210 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 211 | }
|
|---|
| 212 | else{
|
|---|
| 213 | //その他整数型
|
|---|
| 214 |
|
|---|
| 215 | //fild dword ptr[esp]
|
|---|
| 216 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | if(GetTypeSize(type[sp-2],-1)==sizeof(_int64)){
|
|---|
| 220 | if(AnswerType==DEF_SINGLE){
|
|---|
| 221 | //add esp,4
|
|---|
| 222 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 | else{
|
|---|
| 226 | if(AnswerType==DEF_DOUBLE){
|
|---|
| 227 | //sub esp,4
|
|---|
| 228 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | if(idCalc==CALC_ADDITION){
|
|---|
| 233 | //faddp st(1),st
|
|---|
| 234 | compiler.codeGenerator.PutOld(
|
|---|
| 235 | (char)0xDE,
|
|---|
| 236 | (char)0xC1
|
|---|
| 237 | );
|
|---|
| 238 | }
|
|---|
| 239 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 240 | //fsubrp st(1),st
|
|---|
| 241 | compiler.codeGenerator.PutOld(
|
|---|
| 242 | (char)0xDE,
|
|---|
| 243 | (char)0xE1
|
|---|
| 244 | );
|
|---|
| 245 | }
|
|---|
| 246 | else if(idCalc==CALC_PRODUCT){
|
|---|
| 247 | //fmulp st(1),st
|
|---|
| 248 | compiler.codeGenerator.PutOld(
|
|---|
| 249 | (char)0xDE,
|
|---|
| 250 | (char)0xC9
|
|---|
| 251 | );
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | if(AnswerType==DEF_DOUBLE){
|
|---|
| 255 | //fstp qword ptr[esp]
|
|---|
| 256 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
|---|
| 257 | }
|
|---|
| 258 | else{
|
|---|
| 259 | //fstp dword ptr[esp]
|
|---|
| 260 | compiler.codeGenerator.op_fstp_basereg( DEF_SINGLE, REG_ESP );
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|
| 263 | else if(Is64Type(type[sp-2])||Is64Type(type[sp-1])){
|
|---|
| 264 | //////////////////////
|
|---|
| 265 | // 64ビット整数演算
|
|---|
| 266 | //////////////////////
|
|---|
| 267 |
|
|---|
| 268 | if(idCalc==CALC_PRODUCT){
|
|---|
| 269 | if(!((type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD)&&
|
|---|
| 270 | (type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD))){
|
|---|
| 271 | //2つの項のどちらかが64ビット整数でないとき
|
|---|
| 272 | FormatStackData_To64bit(type,sp);
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | //call _allmul
|
|---|
| 276 | extern const UserProc *pSub_allmul;
|
|---|
| 277 | compiler.codeGenerator.op_call(pSub_allmul);
|
|---|
| 278 |
|
|---|
| 279 | //push edx
|
|---|
| 280 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 281 |
|
|---|
| 282 | //push eax
|
|---|
| 283 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 284 | }
|
|---|
| 285 | else{
|
|---|
| 286 | if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 287 | //第2項が64ビット整数値のとき
|
|---|
| 288 |
|
|---|
| 289 | //pop ebx
|
|---|
| 290 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 291 |
|
|---|
| 292 | //pop ecx
|
|---|
| 293 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 294 | }
|
|---|
| 295 | else{
|
|---|
| 296 | //第2項がその他整数値のとき
|
|---|
| 297 |
|
|---|
| 298 | //pop eax
|
|---|
| 299 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 300 |
|
|---|
| 301 | if(IsSignedType(type[sp-1])){
|
|---|
| 302 | //符号拡張
|
|---|
| 303 | //edx:eax ← eax
|
|---|
| 304 |
|
|---|
| 305 | //cdq
|
|---|
| 306 | compiler.codeGenerator.op_cdq();
|
|---|
| 307 | }
|
|---|
| 308 | else{
|
|---|
| 309 | //ビット拡張
|
|---|
| 310 | //edx:eax ← eax
|
|---|
| 311 |
|
|---|
| 312 | //xor edx,edx
|
|---|
| 313 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | //mov ebx,eax
|
|---|
| 317 | compiler.codeGenerator.op_mov_RR( REG_EBX, REG_EAX );
|
|---|
| 318 |
|
|---|
| 319 | //mov ecx,edx
|
|---|
| 320 | compiler.codeGenerator.op_mov_RR( REG_ECX, REG_EDX );
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 324 | //第1項が64ビット整数値のとき
|
|---|
| 325 |
|
|---|
| 326 | if(idCalc==CALC_ADDITION){
|
|---|
| 327 | //add dword ptr[esp],ebx
|
|---|
| 328 | compiler.codeGenerator.PutOld(
|
|---|
| 329 | (char)0x01,
|
|---|
| 330 | (char)0x1C,
|
|---|
| 331 | (char)0x24
|
|---|
| 332 | );
|
|---|
| 333 |
|
|---|
| 334 | //adc dword ptr[esp+sizeof(long)],ecx
|
|---|
| 335 | compiler.codeGenerator.PutOld(
|
|---|
| 336 | (char)0x11,
|
|---|
| 337 | (char)0x4C,
|
|---|
| 338 | (char)0x24,
|
|---|
| 339 | (char)0x04
|
|---|
| 340 | );
|
|---|
| 341 | }
|
|---|
| 342 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 343 | //sub dword ptr[esp],ebx
|
|---|
| 344 | compiler.codeGenerator.PutOld(
|
|---|
| 345 | (char)0x29,
|
|---|
| 346 | (char)0x1C,
|
|---|
| 347 | (char)0x24
|
|---|
| 348 | );
|
|---|
| 349 |
|
|---|
| 350 | //sbb dword ptr[esp+sizeof(long)],ecx
|
|---|
| 351 | compiler.codeGenerator.PutOld(
|
|---|
| 352 | (char)0x19,
|
|---|
| 353 | (char)0x4C,
|
|---|
| 354 | (char)0x24,
|
|---|
| 355 | (char)0x04
|
|---|
| 356 | );
|
|---|
| 357 | }
|
|---|
| 358 | }
|
|---|
| 359 | else{
|
|---|
| 360 | //第1項がその他整数値のとき
|
|---|
| 361 |
|
|---|
| 362 | //pop eax
|
|---|
| 363 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 364 |
|
|---|
| 365 | if(IsSignedType(type[sp-2])){
|
|---|
| 366 | //符号拡張
|
|---|
| 367 | //edx:eax ← eax
|
|---|
| 368 |
|
|---|
| 369 | //cdq
|
|---|
| 370 | compiler.codeGenerator.op_cdq();
|
|---|
| 371 | }
|
|---|
| 372 | else{
|
|---|
| 373 | //ビット拡張
|
|---|
| 374 | //edx:eax ← eax
|
|---|
| 375 |
|
|---|
| 376 | //xor edx,edx
|
|---|
| 377 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 378 | }
|
|---|
| 379 |
|
|---|
| 380 | if(idCalc==CALC_ADDITION){
|
|---|
| 381 | //add ebx,eax
|
|---|
| 382 | compiler.codeGenerator.op_add_RR( REG_EBX, REG_EAX );
|
|---|
| 383 |
|
|---|
| 384 | //adc ecx,edx
|
|---|
| 385 | compiler.codeGenerator.op_adc_RR( REG_ECX, REG_EDX );
|
|---|
| 386 | }
|
|---|
| 387 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 388 | //sub ebx,eax
|
|---|
| 389 | compiler.codeGenerator.op_sub_RR( REG_EBX, REG_EAX );
|
|---|
| 390 |
|
|---|
| 391 | //sbb ecx,edx
|
|---|
| 392 | compiler.codeGenerator.op_sub_RR( REG_ECX, REG_EDX );
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | //push ecx
|
|---|
| 396 | compiler.codeGenerator.op_push(REG_ECX);
|
|---|
| 397 |
|
|---|
| 398 | //push ebx
|
|---|
| 399 | compiler.codeGenerator.op_push(REG_EBX);
|
|---|
| 400 | }
|
|---|
| 401 | }
|
|---|
| 402 | }
|
|---|
| 403 | else{
|
|---|
| 404 | //////////////////////////
|
|---|
| 405 | //32ビット以下の整数演算
|
|---|
| 406 | //////////////////////////
|
|---|
| 407 |
|
|---|
| 408 | //pop ebx
|
|---|
| 409 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 410 |
|
|---|
| 411 | //pop eax
|
|---|
| 412 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 413 |
|
|---|
| 414 | //sub esp,4
|
|---|
| 415 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 416 |
|
|---|
| 417 | if(idCalc==CALC_ADDITION){
|
|---|
| 418 | //add eax,ebx
|
|---|
| 419 | compiler.codeGenerator.op_add_RR( REG_EAX, REG_EBX );
|
|---|
| 420 | }
|
|---|
| 421 | else if(idCalc==CALC_SUBTRACTION){
|
|---|
| 422 | //sub eax,ebx
|
|---|
| 423 | compiler.codeGenerator.op_sub_RR( REG_EAX, REG_EBX );
|
|---|
| 424 | }
|
|---|
| 425 | else if(idCalc==CALC_PRODUCT){
|
|---|
| 426 | //imul eax,ebx(64ビット演算ではないので、符号を考慮しない)
|
|---|
| 427 | compiler.codeGenerator.op_imul_RR( REG_EAX, REG_EBX );
|
|---|
| 428 | }
|
|---|
| 429 |
|
|---|
| 430 | //mov dword ptr[esp],eax
|
|---|
| 431 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | sp--;
|
|---|
| 435 | type[sp-1]=AnswerType;
|
|---|
| 436 |
|
|---|
| 437 | *pStackPointer=sp;
|
|---|
| 438 |
|
|---|
| 439 | return 1;
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | BOOL Calc_Mod(int *type,int *pStackPointer){
|
|---|
| 443 | //value[sp-2]%=value[sp-1]
|
|---|
| 444 | //剰余演算
|
|---|
| 445 |
|
|---|
| 446 | int sp;
|
|---|
| 447 | sp=*pStackPointer;
|
|---|
| 448 |
|
|---|
| 449 | if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD||
|
|---|
| 450 | type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 451 | ////////////////
|
|---|
| 452 | // 64ビット演算
|
|---|
| 453 | ////////////////
|
|---|
| 454 |
|
|---|
| 455 | //第2項を64ビットに対応させる
|
|---|
| 456 | FormatStackData_To64bit(type,sp);
|
|---|
| 457 |
|
|---|
| 458 | if(IsSignedType(type[sp-2])==0&&IsSignedType(type[sp-1])==0){
|
|---|
| 459 | //符号なし演算
|
|---|
| 460 |
|
|---|
| 461 | //call _aullrem
|
|---|
| 462 | extern const UserProc *pSub_aullrem;
|
|---|
| 463 | compiler.codeGenerator.op_call(pSub_aullrem);
|
|---|
| 464 | }
|
|---|
| 465 | else{
|
|---|
| 466 | //符号あり演算
|
|---|
| 467 |
|
|---|
| 468 | //call _allrem
|
|---|
| 469 | extern const UserProc *pSub_allrem;
|
|---|
| 470 | compiler.codeGenerator.op_call(pSub_allrem);
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | //push edx
|
|---|
| 474 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 475 |
|
|---|
| 476 | //push eax
|
|---|
| 477 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 478 |
|
|---|
| 479 | sp--;
|
|---|
| 480 | if(type[sp-1]==DEF_QWORD&&type[sp]==DEF_QWORD) type[sp-1]=DEF_QWORD;
|
|---|
| 481 | else type[sp-1]=DEF_INT64;
|
|---|
| 482 | }
|
|---|
| 483 | else{
|
|---|
| 484 | ////////////////
|
|---|
| 485 | // 32ビット演算
|
|---|
| 486 | ////////////////
|
|---|
| 487 |
|
|---|
| 488 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 489 | //fld qword ptr[esp]
|
|---|
| 490 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 491 |
|
|---|
| 492 | //add esp,4
|
|---|
| 493 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 494 |
|
|---|
| 495 | //fistp dword ptr[esp]
|
|---|
| 496 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 497 | }
|
|---|
| 498 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 499 | //fld dword ptr[esp]
|
|---|
| 500 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 501 |
|
|---|
| 502 | //fistp dword ptr[esp]
|
|---|
| 503 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | //pop ebx
|
|---|
| 507 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 508 |
|
|---|
| 509 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 510 | //fld qword ptr[esp]
|
|---|
| 511 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 512 |
|
|---|
| 513 | //add esp,4
|
|---|
| 514 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 515 |
|
|---|
| 516 | //fistp dword ptr[esp]
|
|---|
| 517 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 518 | }
|
|---|
| 519 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 520 | //fld dword ptr[esp]
|
|---|
| 521 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 522 |
|
|---|
| 523 | //fistp dword ptr[esp]
|
|---|
| 524 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | //pop eax
|
|---|
| 528 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 529 |
|
|---|
| 530 | //sub esp,4
|
|---|
| 531 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 532 |
|
|---|
| 533 | if(type[sp-2]==DEF_DWORD&&type[sp-1]==DEF_DWORD){
|
|---|
| 534 | //xor edx,edx
|
|---|
| 535 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 536 |
|
|---|
| 537 | //div ebx (eax=eax/ebx...edx)
|
|---|
| 538 | compiler.codeGenerator.op_div_R( REG_EBX );
|
|---|
| 539 | }
|
|---|
| 540 | else{
|
|---|
| 541 | //cdq
|
|---|
| 542 | compiler.codeGenerator.op_cdq();
|
|---|
| 543 |
|
|---|
| 544 | //idiv ebx (eax=eax/ebx...edx)
|
|---|
| 545 | compiler.codeGenerator.op_idiv_R( REG_EBX );
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | //mov dword ptr[esp],edx
|
|---|
| 549 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EDX, REG_ESP, 0, MOD_BASE );
|
|---|
| 550 |
|
|---|
| 551 | sp--;
|
|---|
| 552 | type[sp-1]=DEF_LONG;
|
|---|
| 553 | }
|
|---|
| 554 |
|
|---|
| 555 | *pStackPointer=sp;
|
|---|
| 556 |
|
|---|
| 557 | return 1;
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | BOOL Calc_Divide(int *type,int *pStackPointer,int BaseType){
|
|---|
| 561 | //value[sp-2]/=value[sp-1];
|
|---|
| 562 | //除算
|
|---|
| 563 |
|
|---|
| 564 | int sp;
|
|---|
| 565 | sp=*pStackPointer;
|
|---|
| 566 |
|
|---|
| 567 | ///////////////////////
|
|---|
| 568 | // 浮動小数点演算のみ
|
|---|
| 569 | ///////////////////////
|
|---|
| 570 |
|
|---|
| 571 | int AnswerType;
|
|---|
| 572 | if(type[sp-2]==DEF_DOUBLE||type[sp-1]==DEF_DOUBLE||BaseType==DEF_DOUBLE) AnswerType=DEF_DOUBLE;
|
|---|
| 573 | else AnswerType=DEF_SINGLE;
|
|---|
| 574 |
|
|---|
| 575 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 576 | //fld qword ptr[esp]
|
|---|
| 577 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 578 |
|
|---|
| 579 | //add esp,8
|
|---|
| 580 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 581 | }
|
|---|
| 582 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 583 | //fld dword ptr[esp]
|
|---|
| 584 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 585 |
|
|---|
| 586 | //add esp,4
|
|---|
| 587 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 588 | }
|
|---|
| 589 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 590 | //64ビット整数値
|
|---|
| 591 |
|
|---|
| 592 | //fild qword ptr[esp]
|
|---|
| 593 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 594 |
|
|---|
| 595 | //add esp,8
|
|---|
| 596 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 597 | }
|
|---|
| 598 | else if(type[sp-1]==DEF_DWORD){
|
|---|
| 599 | //pop eax
|
|---|
| 600 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 601 |
|
|---|
| 602 | //push 0
|
|---|
| 603 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 604 |
|
|---|
| 605 | //push eax
|
|---|
| 606 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 607 |
|
|---|
| 608 | //fild qword ptr[esp]
|
|---|
| 609 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 610 |
|
|---|
| 611 | //add esp,8
|
|---|
| 612 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 613 | }
|
|---|
| 614 | else{
|
|---|
| 615 | //fild dword ptr[esp]
|
|---|
| 616 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 617 |
|
|---|
| 618 | //add esp,4
|
|---|
| 619 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 623 | //fld qword ptr[esp]
|
|---|
| 624 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 625 | }
|
|---|
| 626 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 627 | //fld dword ptr[esp]
|
|---|
| 628 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 629 | }
|
|---|
| 630 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 631 | //64ビット整数値
|
|---|
| 632 |
|
|---|
| 633 | //fild qword ptr[esp]
|
|---|
| 634 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 635 | }
|
|---|
| 636 | else if(type[sp-2]==DEF_DWORD){
|
|---|
| 637 | //pop eax
|
|---|
| 638 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 639 |
|
|---|
| 640 | //push 0
|
|---|
| 641 | compiler.codeGenerator.op_push_V(0);
|
|---|
| 642 |
|
|---|
| 643 | //push eax
|
|---|
| 644 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 645 |
|
|---|
| 646 | //fild qword ptr[esp]
|
|---|
| 647 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 648 | }
|
|---|
| 649 | else{ //Long
|
|---|
| 650 | //fild dword ptr[esp]
|
|---|
| 651 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 652 | }
|
|---|
| 653 | //↓ここだけ例外DWord
|
|---|
| 654 | if(GetTypeSize(type[sp-2],-1)==sizeof(_int64)||type[sp-2]==DEF_DWORD){
|
|---|
| 655 | if(AnswerType==DEF_SINGLE){
|
|---|
| 656 | //add esp,4
|
|---|
| 657 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 658 | }
|
|---|
| 659 | }
|
|---|
| 660 | else{
|
|---|
| 661 | if(AnswerType==DEF_DOUBLE){
|
|---|
| 662 | //sub esp,4
|
|---|
| 663 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 664 | }
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 | //fdivrp st(1),st
|
|---|
| 668 | compiler.codeGenerator.PutOld(
|
|---|
| 669 | (char)0xDE,
|
|---|
| 670 | (char)0xF1
|
|---|
| 671 | );
|
|---|
| 672 |
|
|---|
| 673 | sp--;
|
|---|
| 674 | if(AnswerType==DEF_DOUBLE){
|
|---|
| 675 | //fstp qword ptr[esp]
|
|---|
| 676 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
|---|
| 677 |
|
|---|
| 678 | type[sp-1]=DEF_DOUBLE;
|
|---|
| 679 | }
|
|---|
| 680 | else{
|
|---|
| 681 | //fstp dword ptr[esp]
|
|---|
| 682 | compiler.codeGenerator.op_fstp_basereg( DEF_SINGLE, REG_ESP );
|
|---|
| 683 |
|
|---|
| 684 | type[sp-1]=DEF_SINGLE;
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | *pStackPointer=sp;
|
|---|
| 688 |
|
|---|
| 689 | return 1;
|
|---|
| 690 | }
|
|---|
| 691 |
|
|---|
| 692 | BOOL Calc_IntDivide(int *type,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 693 | //value[sp-2]/=value[sp-1]
|
|---|
| 694 | //除算(整数)
|
|---|
| 695 |
|
|---|
| 696 | int sp;
|
|---|
| 697 | sp=*pStackPointer;
|
|---|
| 698 |
|
|---|
| 699 | if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD||
|
|---|
| 700 | type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 701 | ////////////////
|
|---|
| 702 | // 64ビット演算
|
|---|
| 703 | ////////////////
|
|---|
| 704 |
|
|---|
| 705 | //2つの項を64ビットに対応させる
|
|---|
| 706 | FormatStackData_To64bit(type,sp);
|
|---|
| 707 |
|
|---|
| 708 | if(IsSignedType(type[sp-2])==0&&IsSignedType(type[sp-1])==0){
|
|---|
| 709 | //符号なし演算
|
|---|
| 710 |
|
|---|
| 711 | //call _aulldiv
|
|---|
| 712 | extern const UserProc *pSub_aulldiv;
|
|---|
| 713 | compiler.codeGenerator.op_call(pSub_aulldiv);
|
|---|
| 714 | }
|
|---|
| 715 | else{
|
|---|
| 716 | //符号あり演算
|
|---|
| 717 |
|
|---|
| 718 | //call _alldiv
|
|---|
| 719 | extern const UserProc *pSub_alldiv;
|
|---|
| 720 | compiler.codeGenerator.op_call(pSub_alldiv);
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | //push edx
|
|---|
| 724 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 725 |
|
|---|
| 726 | //push eax
|
|---|
| 727 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 728 |
|
|---|
| 729 | sp--;
|
|---|
| 730 | if(type[sp-1]==DEF_QWORD&&type[sp]==DEF_QWORD) type[sp-1]=DEF_QWORD;
|
|---|
| 731 | else type[sp-1]=DEF_INT64;
|
|---|
| 732 | }
|
|---|
| 733 | else{
|
|---|
| 734 | ////////////////
|
|---|
| 735 | // 32ビット演算
|
|---|
| 736 | ////////////////
|
|---|
| 737 |
|
|---|
| 738 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 739 | //fld qword ptr[esp]
|
|---|
| 740 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 741 |
|
|---|
| 742 | //add esp,4
|
|---|
| 743 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 744 |
|
|---|
| 745 | //fistp dword ptr[esp]
|
|---|
| 746 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 747 | }
|
|---|
| 748 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 749 | //fld dword ptr[esp]
|
|---|
| 750 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 751 |
|
|---|
| 752 | //fistp dword ptr[esp]
|
|---|
| 753 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | //pop ebx
|
|---|
| 757 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 758 |
|
|---|
| 759 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 760 | //fld qword ptr[esp]
|
|---|
| 761 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 762 |
|
|---|
| 763 | //add esp,4
|
|---|
| 764 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 765 |
|
|---|
| 766 | //fistp dword ptr[esp]
|
|---|
| 767 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 768 | }
|
|---|
| 769 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 770 | //fld dword ptr[esp]
|
|---|
| 771 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 772 |
|
|---|
| 773 | //fistp dword ptr[esp]
|
|---|
| 774 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | //pop eax
|
|---|
| 778 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 779 |
|
|---|
| 780 | //sub esp,4
|
|---|
| 781 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 782 |
|
|---|
| 783 | if((type[sp-2]==DEF_DWORD&&type[sp-1]==DEF_DWORD)||
|
|---|
| 784 | (IS_POSITIVE_LITERAL(index_stack[sp-2])&&type[sp-1]==DEF_DWORD)||
|
|---|
| 785 | (type[sp-2]==DEF_DWORD&&IS_POSITIVE_LITERAL(index_stack[sp-1]))){
|
|---|
| 786 | //xor edx,edx
|
|---|
| 787 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 788 |
|
|---|
| 789 | //div ebx (eax=eax/ebx...edx)
|
|---|
| 790 | compiler.codeGenerator.op_div_R( REG_EBX );
|
|---|
| 791 | }
|
|---|
| 792 | else{
|
|---|
| 793 | //cdq
|
|---|
| 794 | compiler.codeGenerator.op_cdq();
|
|---|
| 795 |
|
|---|
| 796 | //idiv ebx (eax=eax/ebx...edx)
|
|---|
| 797 | compiler.codeGenerator.op_idiv_R( REG_EBX );
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 | //mov dword ptr[esp],eax
|
|---|
| 801 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 802 |
|
|---|
| 803 | sp--;
|
|---|
| 804 |
|
|---|
| 805 | //整数以外の型だったときはLong型にする
|
|---|
| 806 | if(!IsWholeNumberType(type[sp-1])) type[sp-1]=DEF_LONG;
|
|---|
| 807 | }
|
|---|
| 808 |
|
|---|
| 809 | *pStackPointer=sp;
|
|---|
| 810 | return 1;
|
|---|
| 811 | }
|
|---|
| 812 |
|
|---|
| 813 | BOOL Calc_MinusMark(int *type,int sp){
|
|---|
| 814 | //value[sp-1]=-value[sp-1]
|
|---|
| 815 | //符号反転
|
|---|
| 816 |
|
|---|
| 817 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 818 | //fld qword ptr[esp]
|
|---|
| 819 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 820 |
|
|---|
| 821 | //push -1
|
|---|
| 822 | compiler.codeGenerator.op_push_V(-1);
|
|---|
| 823 |
|
|---|
| 824 | //fild dword ptr[esp]
|
|---|
| 825 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 826 |
|
|---|
| 827 | //add esp,4
|
|---|
| 828 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 829 |
|
|---|
| 830 | //fmulp st(1),st
|
|---|
| 831 | compiler.codeGenerator.PutOld(
|
|---|
| 832 | (char)0xDE,
|
|---|
| 833 | (char)0xC9
|
|---|
| 834 | );
|
|---|
| 835 |
|
|---|
| 836 | //fstp qword ptr[esp]
|
|---|
| 837 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
|---|
| 838 | }
|
|---|
| 839 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 840 | //fld dword ptr[esp]
|
|---|
| 841 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 842 |
|
|---|
| 843 | //push -1
|
|---|
| 844 | compiler.codeGenerator.op_push_V(-1);
|
|---|
| 845 |
|
|---|
| 846 | //fild dword ptr[esp]
|
|---|
| 847 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 848 |
|
|---|
| 849 | //add esp,4
|
|---|
| 850 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 851 |
|
|---|
| 852 | //fmulp st(1),st
|
|---|
| 853 | compiler.codeGenerator.PutOld(
|
|---|
| 854 | (char)0xDE,
|
|---|
| 855 | (char)0xC9
|
|---|
| 856 | );
|
|---|
| 857 |
|
|---|
| 858 | //fstp dword ptr[esp]
|
|---|
| 859 | compiler.codeGenerator.op_fstp_basereg( DEF_SINGLE, REG_ESP );
|
|---|
| 860 | }
|
|---|
| 861 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 862 | //pop eax
|
|---|
| 863 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 864 |
|
|---|
| 865 | //neg eax
|
|---|
| 866 | compiler.codeGenerator.op_neg( REG_EAX );
|
|---|
| 867 |
|
|---|
| 868 | //pop edx
|
|---|
| 869 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 870 |
|
|---|
| 871 | //adc edx,0
|
|---|
| 872 | compiler.codeGenerator.op_adc_RV8(REG_EDX,0);
|
|---|
| 873 |
|
|---|
| 874 | //neg edx
|
|---|
| 875 | compiler.codeGenerator.op_neg( REG_EDX );
|
|---|
| 876 |
|
|---|
| 877 | //push edx
|
|---|
| 878 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 879 |
|
|---|
| 880 | //push eax
|
|---|
| 881 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 882 |
|
|---|
| 883 | type[sp-1]=DEF_INT64; //QWordはInt64へ
|
|---|
| 884 | }
|
|---|
| 885 | else if(IsWholeNumberType(type[sp-1])){
|
|---|
| 886 | //pop eax
|
|---|
| 887 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 888 |
|
|---|
| 889 | //imul eax,-1
|
|---|
| 890 | compiler.codeGenerator.op_imul_RV8( REG_EAX, -1 );
|
|---|
| 891 |
|
|---|
| 892 | //push eax
|
|---|
| 893 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 894 |
|
|---|
| 895 | type[sp-1]=GetSignedType(type[sp-1]);
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | return 1;
|
|---|
| 899 | }
|
|---|
| 900 |
|
|---|
| 901 | BOOL Calc_Power(int *type,int *pStackPointer){
|
|---|
| 902 | //べき乗(実数演算のみ)
|
|---|
| 903 |
|
|---|
| 904 | int sp;
|
|---|
| 905 | sp=*pStackPointer;
|
|---|
| 906 |
|
|---|
| 907 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 908 | //fld qword ptr[esp]
|
|---|
| 909 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 910 |
|
|---|
| 911 | //add esp,8
|
|---|
| 912 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 913 | }
|
|---|
| 914 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 915 | //fld dword ptr[esp]
|
|---|
| 916 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 917 |
|
|---|
| 918 | //add esp,4
|
|---|
| 919 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 920 | }
|
|---|
| 921 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 922 | //64ビット整数値
|
|---|
| 923 |
|
|---|
| 924 | //fild qword ptr[esp]
|
|---|
| 925 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 926 |
|
|---|
| 927 | //add esp,8
|
|---|
| 928 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 929 | }
|
|---|
| 930 | else{
|
|---|
| 931 | //32ビット整数値
|
|---|
| 932 |
|
|---|
| 933 | //fild dword ptr[esp]
|
|---|
| 934 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 935 |
|
|---|
| 936 | //add esp,4
|
|---|
| 937 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 941 | //fld qword ptr[esp]
|
|---|
| 942 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 943 | }
|
|---|
| 944 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 945 | //fld dword ptr[esp]
|
|---|
| 946 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 947 |
|
|---|
| 948 | //sub esp,4
|
|---|
| 949 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 950 | }
|
|---|
| 951 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 952 | //64ビット整数値
|
|---|
| 953 |
|
|---|
| 954 | //fild qword ptr[esp]
|
|---|
| 955 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 956 | }
|
|---|
| 957 | else{
|
|---|
| 958 | //32ビット整数値
|
|---|
| 959 |
|
|---|
| 960 | //fild dword ptr[esp]
|
|---|
| 961 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 962 |
|
|---|
| 963 | //sub esp,4
|
|---|
| 964 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 965 | }
|
|---|
| 966 |
|
|---|
| 967 | //sub esp,8
|
|---|
| 968 | compiler.codeGenerator.op_sub_esp(8);
|
|---|
| 969 |
|
|---|
| 970 | //fstp qword ptr[esp]
|
|---|
| 971 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
|---|
| 972 |
|
|---|
| 973 | //fstp qword ptr[esp+8]
|
|---|
| 974 | compiler.codeGenerator.op_fstp_base_offset(DEF_DOUBLE,REG_ESP,8);
|
|---|
| 975 |
|
|---|
| 976 | //call pow
|
|---|
| 977 | extern const UserProc *pSub_pow;
|
|---|
| 978 | compiler.codeGenerator.op_call(pSub_pow);
|
|---|
| 979 |
|
|---|
| 980 | //sub esp,8
|
|---|
| 981 | compiler.codeGenerator.op_sub_esp(8);
|
|---|
| 982 |
|
|---|
| 983 | //fstp qword ptr[esp]
|
|---|
| 984 | compiler.codeGenerator.op_fstp_basereg( DEF_DOUBLE, REG_ESP );
|
|---|
| 985 |
|
|---|
| 986 | sp--;
|
|---|
| 987 | type[sp-1]=DEF_DOUBLE;
|
|---|
| 988 |
|
|---|
| 989 | *pStackPointer=sp;
|
|---|
| 990 | return 1;
|
|---|
| 991 | }
|
|---|
| 992 |
|
|---|
| 993 | BOOL Calc_Cast(int *type,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 994 | //キャスト
|
|---|
| 995 |
|
|---|
| 996 | int sp;
|
|---|
| 997 | sp=*pStackPointer;
|
|---|
| 998 |
|
|---|
| 999 | int CastType;
|
|---|
| 1000 | CastType=type[sp-1];
|
|---|
| 1001 | if((CastType&FLAG_CAST)==0){
|
|---|
| 1002 | SetError(47,NULL,cp);
|
|---|
| 1003 | return 0;
|
|---|
| 1004 | }
|
|---|
| 1005 | CastType=CastType&(~FLAG_CAST);
|
|---|
| 1006 |
|
|---|
| 1007 | if(IsPtrType(CastType)){
|
|---|
| 1008 | ChangeTypeToLong(type[sp-2]);
|
|---|
| 1009 | }
|
|---|
| 1010 | else if(IsRealNumberType(CastType)){
|
|---|
| 1011 | if(CastType==DEF_DOUBLE) ChangeTypeToDouble(type[sp-2]);
|
|---|
| 1012 | else if(CastType==DEF_SINGLE) ChangeTypeToSingle(type[sp-2]);
|
|---|
| 1013 | }
|
|---|
| 1014 | else ChangeTypeToWhole(type[sp-2],CastType);
|
|---|
| 1015 |
|
|---|
| 1016 | type[sp-2]=CastType;
|
|---|
| 1017 | index_stack[sp-2]=index_stack[sp-1];
|
|---|
| 1018 |
|
|---|
| 1019 | sp--;
|
|---|
| 1020 |
|
|---|
| 1021 | *pStackPointer=sp;
|
|---|
| 1022 | return 1;
|
|---|
| 1023 | }
|
|---|
| 1024 |
|
|---|
| 1025 | BOOL Calc_SHL(int *type,int *pStackPointer){
|
|---|
| 1026 | //左ビットシフト
|
|---|
| 1027 | //value[sp-2]=value[sp-2]<<value[sp-1]
|
|---|
| 1028 |
|
|---|
| 1029 | int sp;
|
|---|
| 1030 | sp=*pStackPointer;
|
|---|
| 1031 |
|
|---|
| 1032 | if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 1033 | ////////////////
|
|---|
| 1034 | // 64ビット演算
|
|---|
| 1035 | ////////////////
|
|---|
| 1036 |
|
|---|
| 1037 | //2項目は32ビット整数として利用
|
|---|
| 1038 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 1039 | //fld qword ptr[esp]
|
|---|
| 1040 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1041 |
|
|---|
| 1042 | //add esp,4
|
|---|
| 1043 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1044 |
|
|---|
| 1045 | //fistp dword ptr[esp]
|
|---|
| 1046 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1047 |
|
|---|
| 1048 | //pop ecx
|
|---|
| 1049 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1050 | }
|
|---|
| 1051 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 1052 | //fld dword ptr[esp]
|
|---|
| 1053 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1054 |
|
|---|
| 1055 | //fistp dword ptr[esp]
|
|---|
| 1056 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1057 |
|
|---|
| 1058 | //pop ecx
|
|---|
| 1059 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1060 | }
|
|---|
| 1061 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1062 | //pop ecx
|
|---|
| 1063 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1064 |
|
|---|
| 1065 | //add esp,4
|
|---|
| 1066 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1067 | }
|
|---|
| 1068 | else{
|
|---|
| 1069 | //pop ecx
|
|---|
| 1070 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1071 | }
|
|---|
| 1072 |
|
|---|
| 1073 | //第1項を64ビットに対応させる
|
|---|
| 1074 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 1075 | //fld qword ptr[esp]
|
|---|
| 1076 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1077 |
|
|---|
| 1078 | //fistp qword ptr[esp]
|
|---|
| 1079 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 1080 |
|
|---|
| 1081 | //pop eax
|
|---|
| 1082 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1083 |
|
|---|
| 1084 | //pop edx
|
|---|
| 1085 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1086 | }
|
|---|
| 1087 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 1088 | //fld dword ptr[esp]
|
|---|
| 1089 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1090 |
|
|---|
| 1091 | //sub esp,4
|
|---|
| 1092 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1093 |
|
|---|
| 1094 | //fistp qword ptr[esp]
|
|---|
| 1095 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 1096 |
|
|---|
| 1097 | //pop eax
|
|---|
| 1098 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1099 |
|
|---|
| 1100 | //pop edx
|
|---|
| 1101 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1102 | }
|
|---|
| 1103 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 1104 | //pop eax
|
|---|
| 1105 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1106 |
|
|---|
| 1107 | //pop edx
|
|---|
| 1108 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1109 | }
|
|---|
| 1110 | else{
|
|---|
| 1111 | //pop eax
|
|---|
| 1112 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1113 |
|
|---|
| 1114 | if(IsSignedType(type[sp-2])){
|
|---|
| 1115 | //符号拡張
|
|---|
| 1116 | //edx:eax ← eax
|
|---|
| 1117 |
|
|---|
| 1118 | //cdq
|
|---|
| 1119 | compiler.codeGenerator.op_cdq();
|
|---|
| 1120 | }
|
|---|
| 1121 | else{
|
|---|
| 1122 | //ビット拡張
|
|---|
| 1123 | //edx:eax ← eax
|
|---|
| 1124 |
|
|---|
| 1125 | //xor edx,edx
|
|---|
| 1126 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 1127 | }
|
|---|
| 1128 | }
|
|---|
| 1129 |
|
|---|
| 1130 | //call _allshl
|
|---|
| 1131 | extern const UserProc *pSub_allshl;
|
|---|
| 1132 | compiler.codeGenerator.op_call(pSub_allshl);
|
|---|
| 1133 |
|
|---|
| 1134 | //push edx
|
|---|
| 1135 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 1136 |
|
|---|
| 1137 | //push eax
|
|---|
| 1138 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 1139 |
|
|---|
| 1140 | sp--;
|
|---|
| 1141 | }
|
|---|
| 1142 | else{
|
|---|
| 1143 | ////////////////
|
|---|
| 1144 | // 32ビット演算
|
|---|
| 1145 | ////////////////
|
|---|
| 1146 |
|
|---|
| 1147 | //2項目は32ビット整数として利用
|
|---|
| 1148 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 1149 | //fld qword ptr[esp]
|
|---|
| 1150 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1151 |
|
|---|
| 1152 | //add esp,4
|
|---|
| 1153 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1154 |
|
|---|
| 1155 | //fistp dword ptr[esp]
|
|---|
| 1156 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1157 |
|
|---|
| 1158 | //pop ecx
|
|---|
| 1159 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1160 | }
|
|---|
| 1161 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 1162 | //fld dword ptr[esp]
|
|---|
| 1163 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1164 |
|
|---|
| 1165 | //fistp dword ptr[esp]
|
|---|
| 1166 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1167 |
|
|---|
| 1168 | //pop ecx
|
|---|
| 1169 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1170 | }
|
|---|
| 1171 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1172 | //pop ecx
|
|---|
| 1173 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1174 |
|
|---|
| 1175 | //add esp,4
|
|---|
| 1176 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1177 | }
|
|---|
| 1178 | else{
|
|---|
| 1179 | //pop ecx
|
|---|
| 1180 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1181 | }
|
|---|
| 1182 |
|
|---|
| 1183 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 1184 | //fld qword ptr[esp]
|
|---|
| 1185 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1186 |
|
|---|
| 1187 | //add esp,4
|
|---|
| 1188 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1189 |
|
|---|
| 1190 | //fistp dword ptr[esp]
|
|---|
| 1191 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1192 | }
|
|---|
| 1193 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 1194 | //fld dword ptr[esp]
|
|---|
| 1195 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1196 |
|
|---|
| 1197 | //fistp dword ptr[esp]
|
|---|
| 1198 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1199 | }
|
|---|
| 1200 |
|
|---|
| 1201 | //pop eax
|
|---|
| 1202 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1203 |
|
|---|
| 1204 | //sub esp,4
|
|---|
| 1205 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1206 |
|
|---|
| 1207 | //shl eax,cl
|
|---|
| 1208 | compiler.codeGenerator.PutOld(
|
|---|
| 1209 | (char)0xD3,
|
|---|
| 1210 | (char)0xE0
|
|---|
| 1211 | );
|
|---|
| 1212 |
|
|---|
| 1213 | //mov dword ptr[esp],eax
|
|---|
| 1214 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1215 |
|
|---|
| 1216 | sp--;
|
|---|
| 1217 |
|
|---|
| 1218 | //32ビット型にする
|
|---|
| 1219 | if(IsSignedType(type[sp-1])) type[sp-1]=DEF_LONG;
|
|---|
| 1220 | else type[sp-1]=DEF_DWORD;
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | *pStackPointer=sp;
|
|---|
| 1224 | return 1;
|
|---|
| 1225 | }
|
|---|
| 1226 |
|
|---|
| 1227 | BOOL Calc_SHR(int *type,int *pStackPointer){
|
|---|
| 1228 | //右ビットシフト
|
|---|
| 1229 | //value[sp-2]=value[sp-2]>>value[sp-1]
|
|---|
| 1230 |
|
|---|
| 1231 | int sp;
|
|---|
| 1232 | sp=*pStackPointer;
|
|---|
| 1233 |
|
|---|
| 1234 | if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 1235 | ////////////////
|
|---|
| 1236 | // 64ビット演算
|
|---|
| 1237 | ////////////////
|
|---|
| 1238 |
|
|---|
| 1239 | //2項目は32ビット整数として利用
|
|---|
| 1240 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 1241 | //fld qword ptr[esp]
|
|---|
| 1242 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1243 |
|
|---|
| 1244 | //add esp,4
|
|---|
| 1245 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1246 |
|
|---|
| 1247 | //fistp dword ptr[esp]
|
|---|
| 1248 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1249 |
|
|---|
| 1250 | //pop ecx
|
|---|
| 1251 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1252 | }
|
|---|
| 1253 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 1254 | //fld dword ptr[esp]
|
|---|
| 1255 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1256 |
|
|---|
| 1257 | //fistp dword ptr[esp]
|
|---|
| 1258 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1259 |
|
|---|
| 1260 | //pop ecx
|
|---|
| 1261 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1262 | }
|
|---|
| 1263 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1264 | //pop ecx
|
|---|
| 1265 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1266 |
|
|---|
| 1267 | //add esp,4
|
|---|
| 1268 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1269 | }
|
|---|
| 1270 | else{
|
|---|
| 1271 | //pop ecx
|
|---|
| 1272 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1273 | }
|
|---|
| 1274 |
|
|---|
| 1275 | //第1項を64ビットに対応させる
|
|---|
| 1276 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 1277 | //fld qword ptr[esp]
|
|---|
| 1278 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1279 |
|
|---|
| 1280 | //fistp qword ptr[esp]
|
|---|
| 1281 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 1282 |
|
|---|
| 1283 | //pop eax
|
|---|
| 1284 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1285 |
|
|---|
| 1286 | //pop edx
|
|---|
| 1287 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1288 | }
|
|---|
| 1289 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 1290 | //fld dword ptr[esp]
|
|---|
| 1291 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1292 |
|
|---|
| 1293 | //sub esp,4
|
|---|
| 1294 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1295 |
|
|---|
| 1296 | //fistp qword ptr[esp]
|
|---|
| 1297 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(_int64) );
|
|---|
| 1298 |
|
|---|
| 1299 | //pop eax
|
|---|
| 1300 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1301 |
|
|---|
| 1302 | //pop edx
|
|---|
| 1303 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1304 | }
|
|---|
| 1305 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 1306 | //pop eax
|
|---|
| 1307 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1308 |
|
|---|
| 1309 | //pop edx
|
|---|
| 1310 | compiler.codeGenerator.op_pop(REG_EDX);
|
|---|
| 1311 | }
|
|---|
| 1312 | else{
|
|---|
| 1313 | //pop eax
|
|---|
| 1314 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1315 |
|
|---|
| 1316 | if(IsSignedType(type[sp-2])){
|
|---|
| 1317 | //符号拡張
|
|---|
| 1318 | //edx:eax ← eax
|
|---|
| 1319 |
|
|---|
| 1320 | //cdq
|
|---|
| 1321 | compiler.codeGenerator.op_cdq();
|
|---|
| 1322 | }
|
|---|
| 1323 | else{
|
|---|
| 1324 | //ビット拡張
|
|---|
| 1325 | //edx:eax ← eax
|
|---|
| 1326 |
|
|---|
| 1327 | //xor edx,edx
|
|---|
| 1328 | compiler.codeGenerator.op_zero_reg(REG_EDX);
|
|---|
| 1329 | }
|
|---|
| 1330 | }
|
|---|
| 1331 |
|
|---|
| 1332 | if(type[sp-2]==DEF_QWORD){
|
|---|
| 1333 | //符号なし演算
|
|---|
| 1334 |
|
|---|
| 1335 | //call _aullshr
|
|---|
| 1336 | extern const UserProc *pSub_aullshr;
|
|---|
| 1337 | compiler.codeGenerator.op_call(pSub_aullshr);
|
|---|
| 1338 | }
|
|---|
| 1339 | else{
|
|---|
| 1340 | //符号あり演算
|
|---|
| 1341 |
|
|---|
| 1342 | //call _allshr
|
|---|
| 1343 | extern const UserProc *pSub_allshr;
|
|---|
| 1344 | compiler.codeGenerator.op_call(pSub_allshr);
|
|---|
| 1345 | }
|
|---|
| 1346 |
|
|---|
| 1347 | //push edx
|
|---|
| 1348 | compiler.codeGenerator.op_push(REG_EDX);
|
|---|
| 1349 |
|
|---|
| 1350 | //push eax
|
|---|
| 1351 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 1352 |
|
|---|
| 1353 | sp--;
|
|---|
| 1354 | }
|
|---|
| 1355 | else{
|
|---|
| 1356 | ////////////////
|
|---|
| 1357 | // 32ビット演算
|
|---|
| 1358 | ////////////////
|
|---|
| 1359 |
|
|---|
| 1360 | //2項目は32ビット整数として利用
|
|---|
| 1361 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 1362 | //fld qword ptr[esp]
|
|---|
| 1363 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1364 |
|
|---|
| 1365 | //add esp,4
|
|---|
| 1366 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1367 |
|
|---|
| 1368 | //fistp dword ptr[esp]
|
|---|
| 1369 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1370 |
|
|---|
| 1371 | //pop ecx
|
|---|
| 1372 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1373 | }
|
|---|
| 1374 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 1375 | //fld dword ptr[esp]
|
|---|
| 1376 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1377 |
|
|---|
| 1378 | //fistp dword ptr[esp]
|
|---|
| 1379 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1380 |
|
|---|
| 1381 | //pop ecx
|
|---|
| 1382 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1383 | }
|
|---|
| 1384 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1385 | //pop ecx
|
|---|
| 1386 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1387 |
|
|---|
| 1388 | //add esp,4
|
|---|
| 1389 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1390 | }
|
|---|
| 1391 | else{
|
|---|
| 1392 | //pop ecx
|
|---|
| 1393 | compiler.codeGenerator.op_pop(REG_ECX);
|
|---|
| 1394 | }
|
|---|
| 1395 |
|
|---|
| 1396 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 1397 | //fld qword ptr[esp]
|
|---|
| 1398 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1399 |
|
|---|
| 1400 | //add esp,4
|
|---|
| 1401 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1402 |
|
|---|
| 1403 | //fistp dword ptr[esp]
|
|---|
| 1404 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1405 | }
|
|---|
| 1406 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 1407 | //fld dword ptr[esp]
|
|---|
| 1408 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1409 |
|
|---|
| 1410 | //fistp dword ptr[esp]
|
|---|
| 1411 | compiler.codeGenerator.op_fistp_ptr_esp( sizeof(long) );
|
|---|
| 1412 | }
|
|---|
| 1413 |
|
|---|
| 1414 | //pop eax
|
|---|
| 1415 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1416 |
|
|---|
| 1417 | //sub esp,4
|
|---|
| 1418 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1419 |
|
|---|
| 1420 | if(type[sp-2]==DEF_DWORD){
|
|---|
| 1421 | //shr eax,cl
|
|---|
| 1422 | compiler.codeGenerator.PutOld(
|
|---|
| 1423 | (char)0xD3,
|
|---|
| 1424 | (char)0xE8
|
|---|
| 1425 | );
|
|---|
| 1426 | }
|
|---|
| 1427 | else{
|
|---|
| 1428 | //sar eax,cl
|
|---|
| 1429 | compiler.codeGenerator.PutOld(
|
|---|
| 1430 | (char)0xD3,
|
|---|
| 1431 | (char)0xF8
|
|---|
| 1432 | );
|
|---|
| 1433 | }
|
|---|
| 1434 |
|
|---|
| 1435 | //mov dword ptr[esp],eax
|
|---|
| 1436 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1437 |
|
|---|
| 1438 | sp--;
|
|---|
| 1439 |
|
|---|
| 1440 | //整数以外の型だったときはLong型にする
|
|---|
| 1441 | if(!IsWholeNumberType(type[sp-1])) type[sp-1]=DEF_LONG;
|
|---|
| 1442 | }
|
|---|
| 1443 |
|
|---|
| 1444 | *pStackPointer=sp;
|
|---|
| 1445 | return 1;
|
|---|
| 1446 | }
|
|---|