| 1 | #include "stdafx.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <Compiler.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "../BasicCompiler_Common/common.h"
|
|---|
| 6 | #include "Opcode.h"
|
|---|
| 7 |
|
|---|
| 8 | void AutoExtendToBigType( int *type_stack,int sp, int reg1, int reg2 ){
|
|---|
| 9 | /*
|
|---|
| 10 | int bigSize = GetTypeSize( type_stack[sp-1], -1 );
|
|---|
| 11 | if( bigSize != GetTypeSize( type_stack[sp-2], -1 ) ){
|
|---|
| 12 | int extReg = reg2;
|
|---|
| 13 | int oldType = type_stack[sp-2];
|
|---|
| 14 | if( bigSize < GetTypeSize( type_stack[sp-2], -1 ) ){
|
|---|
| 15 | bigSize = GetTypeSize( type_stack[sp-2], -1 );
|
|---|
| 16 | extReg = reg1;
|
|---|
| 17 | oldType = type_stack[sp-1];
|
|---|
| 18 | }
|
|---|
| 19 | if( bigSize == 2 ){
|
|---|
| 20 | ExtendTypeTo16( oldType, extReg );
|
|---|
| 21 | }
|
|---|
| 22 | else if( bigSize == 4 ){
|
|---|
| 23 | ExtendTypeTo32( oldType, extReg );
|
|---|
| 24 | }
|
|---|
| 25 | else{
|
|---|
| 26 | SetError();
|
|---|
| 27 | }
|
|---|
| 28 | }*/
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | BOOL Calc_Relation_PE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 33 | //value[sp-2]<=value[sp-1]
|
|---|
| 34 |
|
|---|
| 35 | int sp;
|
|---|
| 36 | sp=*pStackPointer;
|
|---|
| 37 |
|
|---|
| 38 | int AnswerType;
|
|---|
| 39 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
|---|
| 40 |
|
|---|
| 41 | if(IsRealNumberType(AnswerType)){
|
|---|
| 42 | //////////////
|
|---|
| 43 | // 実数演算
|
|---|
| 44 | //////////////
|
|---|
| 45 |
|
|---|
| 46 | if(type_stack[sp-1]==DEF_DOUBLE){
|
|---|
| 47 | //fld qword ptr[esp]
|
|---|
| 48 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 49 |
|
|---|
| 50 | //add esp,8
|
|---|
| 51 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 52 | }
|
|---|
| 53 | else if(type_stack[sp-1]==DEF_SINGLE){
|
|---|
| 54 | //fld dword ptr[esp]
|
|---|
| 55 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 56 |
|
|---|
| 57 | //add esp,4
|
|---|
| 58 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 59 | }
|
|---|
| 60 | else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
|
|---|
| 61 | //64ビット整数値
|
|---|
| 62 |
|
|---|
| 63 | //fild qword ptr[esp]
|
|---|
| 64 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 65 |
|
|---|
| 66 | //add esp,8
|
|---|
| 67 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 68 | }
|
|---|
| 69 | else{
|
|---|
| 70 | //その他整数型
|
|---|
| 71 |
|
|---|
| 72 | //fild dword ptr[esp]
|
|---|
| 73 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 74 |
|
|---|
| 75 | //add esp,4
|
|---|
| 76 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | if(type_stack[sp-2]==DEF_DOUBLE){
|
|---|
| 80 | //fld qword ptr[esp]
|
|---|
| 81 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 82 |
|
|---|
| 83 | //add esp,4
|
|---|
| 84 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 85 | }
|
|---|
| 86 | else if(type_stack[sp-2]==DEF_SINGLE){
|
|---|
| 87 | //fld dword ptr[esp]
|
|---|
| 88 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 89 | }
|
|---|
| 90 | else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
|
|---|
| 91 | //64ビット整数値
|
|---|
| 92 |
|
|---|
| 93 | //fild qword ptr[esp]
|
|---|
| 94 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 95 |
|
|---|
| 96 | //add esp,4
|
|---|
| 97 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 98 | }
|
|---|
| 99 | else{
|
|---|
| 100 | //その他整数型
|
|---|
| 101 |
|
|---|
| 102 | //fild dword ptr[esp]
|
|---|
| 103 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | //fcompp
|
|---|
| 107 | compiler.codeGenerator.op_fcompp();
|
|---|
| 108 |
|
|---|
| 109 | //fnstsw ax
|
|---|
| 110 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 111 |
|
|---|
| 112 | //mov ecx,1
|
|---|
| 113 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 114 |
|
|---|
| 115 | //test ah,41h
|
|---|
| 116 | compiler.codeGenerator.op_test_ah( (char)0x41 );
|
|---|
| 117 |
|
|---|
| 118 | //jne 5
|
|---|
| 119 | compiler.codeGenerator.PutOld(
|
|---|
| 120 | (char)0x75,
|
|---|
| 121 | (char)0x02
|
|---|
| 122 | );
|
|---|
| 123 |
|
|---|
| 124 | //xor ecx,ecx(ecxを0にする)
|
|---|
| 125 | compiler.codeGenerator.op_zero_reg(REG_ECX);
|
|---|
| 126 |
|
|---|
| 127 | //mov dword ptr[esp],ecx
|
|---|
| 128 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 129 | }
|
|---|
| 130 | else if(Is64Type(AnswerType)){
|
|---|
| 131 | ////////////////////
|
|---|
| 132 | // 64ビット整数演算
|
|---|
| 133 | ////////////////////
|
|---|
| 134 | int TrueSchedule,
|
|---|
| 135 | FalseSchedule1,
|
|---|
| 136 | FalseSchedule2;
|
|---|
| 137 |
|
|---|
| 138 | // 第1項 <= 第2項
|
|---|
| 139 |
|
|---|
| 140 | //第1項 edx:eax
|
|---|
| 141 | //第2項 ecx:ebx
|
|---|
| 142 | GetStackData_ToRegister(type_stack,sp);
|
|---|
| 143 |
|
|---|
| 144 | //cmp edx,ecx
|
|---|
| 145 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 146 |
|
|---|
| 147 | if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
|
|---|
| 148 | //符号なし演算
|
|---|
| 149 |
|
|---|
| 150 | //ja FalseSchedule1(偽へジャンプ)
|
|---|
| 151 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 152 | }
|
|---|
| 153 | else{
|
|---|
| 154 | //符号あり演算
|
|---|
| 155 |
|
|---|
| 156 | //jg FalseSchedule1(偽へジャンプ)
|
|---|
| 157 | OpBuffer[obp++]=(char)0x7F;
|
|---|
| 158 | }
|
|---|
| 159 | FalseSchedule1=obp;
|
|---|
| 160 | obp++;
|
|---|
| 161 |
|
|---|
| 162 | if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
|
|---|
| 163 | //符号なし演算
|
|---|
| 164 |
|
|---|
| 165 | //jb TrueSchedule(真へジャンプ)
|
|---|
| 166 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 167 | }
|
|---|
| 168 | else{
|
|---|
| 169 | //符号あり演算
|
|---|
| 170 |
|
|---|
| 171 | //jl TrueSchedule(真へジャンプ)
|
|---|
| 172 | OpBuffer[obp++]=(char)0x7C;
|
|---|
| 173 | }
|
|---|
| 174 | TrueSchedule=obp;
|
|---|
| 175 | obp++;
|
|---|
| 176 |
|
|---|
| 177 | //cmp eax,ebx
|
|---|
| 178 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 179 |
|
|---|
| 180 | //ja FalseSchedule2(偽へジャンプ)
|
|---|
| 181 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 182 | FalseSchedule2=obp;
|
|---|
| 183 | obp++;
|
|---|
| 184 |
|
|---|
| 185 | //TrueScheduleのジャンプ先の設定
|
|---|
| 186 | OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
|
|---|
| 187 |
|
|---|
| 188 | //mov eax,1
|
|---|
| 189 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 190 |
|
|---|
| 191 | //jmp 2(演算終了位置へジャンプ)
|
|---|
| 192 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 193 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 194 |
|
|---|
| 195 | //FalseScheduleのジャンプ先の設定
|
|---|
| 196 | OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
|
|---|
| 197 | OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
|
|---|
| 198 |
|
|---|
| 199 | //xor eax,eax(eaxを0にする)
|
|---|
| 200 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 201 |
|
|---|
| 202 | //push eax
|
|---|
| 203 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 204 | }
|
|---|
| 205 | else{
|
|---|
| 206 | ////////////////////
|
|---|
| 207 | // 32ビット整数演算
|
|---|
| 208 | ////////////////////
|
|---|
| 209 |
|
|---|
| 210 | //pop ebx
|
|---|
| 211 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 212 |
|
|---|
| 213 | //pop eax
|
|---|
| 214 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 215 |
|
|---|
| 216 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 217 | AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
|
|---|
| 218 |
|
|---|
| 219 | //sub esp,4
|
|---|
| 220 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 221 |
|
|---|
| 222 | //mov ecx,1
|
|---|
| 223 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 224 |
|
|---|
| 225 | //cmp eax,ebx
|
|---|
| 226 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 227 |
|
|---|
| 228 | if(IsSignedType(type_stack[sp-2])==0&&IsSignedType(type_stack[sp-1])==0){
|
|---|
| 229 | //符号なし演算
|
|---|
| 230 |
|
|---|
| 231 | //jbe 2(次のxorを飛び越す)
|
|---|
| 232 | OpBuffer[obp++]=(char)0x76;
|
|---|
| 233 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 234 | }
|
|---|
| 235 | else{
|
|---|
| 236 | //符号あり演算
|
|---|
| 237 |
|
|---|
| 238 | //jle 2(次のxorを飛び越す)
|
|---|
| 239 | OpBuffer[obp++]=(char)0x7E;
|
|---|
| 240 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | //xor ecx,ecx
|
|---|
| 244 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 245 |
|
|---|
| 246 | //mov dword ptr[esp],ecx
|
|---|
| 247 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | sp--;
|
|---|
| 251 | type_stack[sp-1]=DEF_BOOLEAN;
|
|---|
| 252 |
|
|---|
| 253 | *pStackPointer=sp;
|
|---|
| 254 | return 1;
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | BOOL Calc_Relation_QE(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 258 | //value[sp-2]>=value[sp-1]
|
|---|
| 259 |
|
|---|
| 260 | int sp;
|
|---|
| 261 | sp=*pStackPointer;
|
|---|
| 262 |
|
|---|
| 263 | int AnswerType;
|
|---|
| 264 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
|---|
| 265 |
|
|---|
| 266 | if(IsRealNumberType(AnswerType)){
|
|---|
| 267 | //浮動小数点演算
|
|---|
| 268 | if(type_stack[sp-1]==DEF_DOUBLE){
|
|---|
| 269 | //fld qword ptr[esp]
|
|---|
| 270 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 271 |
|
|---|
| 272 | //add esp,8
|
|---|
| 273 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 274 | }
|
|---|
| 275 | else if(type_stack[sp-1]==DEF_SINGLE){
|
|---|
| 276 | //fld dword ptr[esp]
|
|---|
| 277 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 278 |
|
|---|
| 279 | //add esp,4
|
|---|
| 280 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 281 | }
|
|---|
| 282 | else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
|
|---|
| 283 | //64ビット整数値
|
|---|
| 284 |
|
|---|
| 285 | //fild qword ptr[esp]
|
|---|
| 286 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 287 |
|
|---|
| 288 | //add esp,8
|
|---|
| 289 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 290 | }
|
|---|
| 291 | else{
|
|---|
| 292 | //その他整数型
|
|---|
| 293 |
|
|---|
| 294 | //fild dword ptr[esp]
|
|---|
| 295 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 296 |
|
|---|
| 297 | //add esp,4
|
|---|
| 298 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | if(type_stack[sp-2]==DEF_DOUBLE){
|
|---|
| 302 | //fld qword ptr[esp]
|
|---|
| 303 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 304 |
|
|---|
| 305 | //add esp,4
|
|---|
| 306 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 307 | }
|
|---|
| 308 | else if(type_stack[sp-2]==DEF_SINGLE){
|
|---|
| 309 | //fld dword ptr[esp]
|
|---|
| 310 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 311 | }
|
|---|
| 312 | else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
|
|---|
| 313 | //64ビット整数値
|
|---|
| 314 |
|
|---|
| 315 | //fild qword ptr[esp]
|
|---|
| 316 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 317 |
|
|---|
| 318 | //add esp,4
|
|---|
| 319 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 320 | }
|
|---|
| 321 | else{
|
|---|
| 322 | //その他整数型
|
|---|
| 323 |
|
|---|
| 324 | //fild dword ptr[esp]
|
|---|
| 325 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | //fcompp
|
|---|
| 329 | OpBuffer[obp++]=(char)0xDE;
|
|---|
| 330 | OpBuffer[obp++]=(char)0xD9;
|
|---|
| 331 |
|
|---|
| 332 | //fnstsw ax
|
|---|
| 333 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 334 |
|
|---|
| 335 | //mov ecx,1
|
|---|
| 336 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 337 |
|
|---|
| 338 | //test ah,1
|
|---|
| 339 | compiler.codeGenerator.op_test_ah( (char)0x01 );
|
|---|
| 340 |
|
|---|
| 341 | //je 2(次のxorを飛び越す)
|
|---|
| 342 | OpBuffer[obp++]=(char)0x74;
|
|---|
| 343 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 344 |
|
|---|
| 345 | //xor ecx,ecx
|
|---|
| 346 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 347 |
|
|---|
| 348 | //mov dword ptr[esp],ecx
|
|---|
| 349 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 350 | }
|
|---|
| 351 | else if(Is64Type(AnswerType)){
|
|---|
| 352 | ////////////////////
|
|---|
| 353 | // 64ビット整数演算
|
|---|
| 354 | ////////////////////
|
|---|
| 355 | int TrueSchedule,
|
|---|
| 356 | FalseSchedule1,
|
|---|
| 357 | FalseSchedule2;
|
|---|
| 358 |
|
|---|
| 359 | // 第1項 >= 第2項
|
|---|
| 360 |
|
|---|
| 361 | //第1項 edx:eax
|
|---|
| 362 | //第2項 ecx:ebx
|
|---|
| 363 | GetStackData_ToRegister(type_stack,sp);
|
|---|
| 364 |
|
|---|
| 365 | //cmp edx,ecx
|
|---|
| 366 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 367 |
|
|---|
| 368 | if(IsSignedType(AnswerType)){
|
|---|
| 369 | //符号あり演算
|
|---|
| 370 |
|
|---|
| 371 | //jl FalseSchedule1(偽へジャンプ)
|
|---|
| 372 | OpBuffer[obp++]=(char)0x7C;
|
|---|
| 373 | }
|
|---|
| 374 | else{
|
|---|
| 375 | //符号なし演算
|
|---|
| 376 |
|
|---|
| 377 | //jb FalseSchedule1(偽へジャンプ)
|
|---|
| 378 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 379 | }
|
|---|
| 380 | FalseSchedule1=obp;
|
|---|
| 381 | obp++;
|
|---|
| 382 |
|
|---|
| 383 | if(IsSignedType(AnswerType)){
|
|---|
| 384 | //符号あり演算
|
|---|
| 385 |
|
|---|
| 386 | //jg TrueSchedule(真へジャンプ)
|
|---|
| 387 | OpBuffer[obp++]=(char)0x7F;
|
|---|
| 388 | }
|
|---|
| 389 | else{
|
|---|
| 390 | //符号なし演算
|
|---|
| 391 |
|
|---|
| 392 | //ja TrueSchedule(真へジャンプ)
|
|---|
| 393 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 394 | }
|
|---|
| 395 | TrueSchedule=obp;
|
|---|
| 396 | obp++;
|
|---|
| 397 |
|
|---|
| 398 | //cmp eax,ebx
|
|---|
| 399 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 400 |
|
|---|
| 401 | //jb FalseSchedule2(偽へジャンプ)
|
|---|
| 402 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 403 | FalseSchedule2=obp;
|
|---|
| 404 | obp++;
|
|---|
| 405 |
|
|---|
| 406 | //TrueScheduleのジャンプ先の設定
|
|---|
| 407 | OpBuffer[TrueSchedule]=obp-(TrueSchedule+1);
|
|---|
| 408 |
|
|---|
| 409 | //mov eax,1
|
|---|
| 410 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 411 |
|
|---|
| 412 | //jmp 2(演算終了位置へジャンプ)
|
|---|
| 413 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 414 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 415 |
|
|---|
| 416 | //FalseScheduleのジャンプ先の設定
|
|---|
| 417 | OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
|
|---|
| 418 | OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
|
|---|
| 419 |
|
|---|
| 420 | //xor eax,eax(eaxを0にする)
|
|---|
| 421 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 422 |
|
|---|
| 423 | //push eax
|
|---|
| 424 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 425 | }
|
|---|
| 426 | else{
|
|---|
| 427 | ////////////////////
|
|---|
| 428 | // 32ビット整数演算
|
|---|
| 429 | ////////////////////
|
|---|
| 430 |
|
|---|
| 431 | //pop ebx
|
|---|
| 432 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 433 |
|
|---|
| 434 | //pop eax
|
|---|
| 435 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 436 |
|
|---|
| 437 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 438 | AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
|
|---|
| 439 |
|
|---|
| 440 | //sub esp,4
|
|---|
| 441 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 442 |
|
|---|
| 443 | //mov ecx,1
|
|---|
| 444 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 445 |
|
|---|
| 446 | //cmp eax,ebx
|
|---|
| 447 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 448 |
|
|---|
| 449 | if(IsSignedType(AnswerType)){
|
|---|
| 450 | //符号あり演算
|
|---|
| 451 |
|
|---|
| 452 | //jge 2(次のxorを飛び越す)符号有り
|
|---|
| 453 | OpBuffer[obp++]=(char)0x7D;
|
|---|
| 454 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 455 | }
|
|---|
| 456 | else{
|
|---|
| 457 | //符号なし演算
|
|---|
| 458 |
|
|---|
| 459 | //jae 2(次のxorを飛び越す)
|
|---|
| 460 | OpBuffer[obp++]=(char)0x73;
|
|---|
| 461 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | //xor ecx,ecx
|
|---|
| 465 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 466 |
|
|---|
| 467 | //mov dword ptr[esp],ecx
|
|---|
| 468 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | sp--;
|
|---|
| 472 | type_stack[sp-1]=DEF_BOOLEAN;
|
|---|
| 473 |
|
|---|
| 474 | *pStackPointer=sp;
|
|---|
| 475 | return 1;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | BOOL Calc_Relation_P(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 479 | //value[sp-2]<value[sp-1]
|
|---|
| 480 |
|
|---|
| 481 | int sp;
|
|---|
| 482 | sp=*pStackPointer;
|
|---|
| 483 |
|
|---|
| 484 | int AnswerType;
|
|---|
| 485 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
|---|
| 486 |
|
|---|
| 487 | if(IsRealNumberType(AnswerType)){
|
|---|
| 488 | //////////////
|
|---|
| 489 | // 実数演算
|
|---|
| 490 | //////////////
|
|---|
| 491 |
|
|---|
| 492 | if(type_stack[sp-1]==DEF_DOUBLE){
|
|---|
| 493 | //fld qword ptr[esp]
|
|---|
| 494 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 495 |
|
|---|
| 496 | //add esp,8
|
|---|
| 497 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 498 | }
|
|---|
| 499 | else if(type_stack[sp-1]==DEF_SINGLE){
|
|---|
| 500 | //fld dword ptr[esp]
|
|---|
| 501 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 502 |
|
|---|
| 503 | //add esp,4
|
|---|
| 504 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 505 | }
|
|---|
| 506 | else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
|
|---|
| 507 | //64ビット整数値
|
|---|
| 508 |
|
|---|
| 509 | //fild qword ptr[esp]
|
|---|
| 510 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 511 |
|
|---|
| 512 | //add esp,8
|
|---|
| 513 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 514 | }
|
|---|
| 515 | else{
|
|---|
| 516 | //その他整数型
|
|---|
| 517 |
|
|---|
| 518 | //fild dword ptr[esp]
|
|---|
| 519 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 520 |
|
|---|
| 521 | //add esp,4
|
|---|
| 522 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | if(type_stack[sp-2]==DEF_DOUBLE){
|
|---|
| 526 | //fld qword ptr[esp]
|
|---|
| 527 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 528 |
|
|---|
| 529 | //add esp,4
|
|---|
| 530 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 531 | }
|
|---|
| 532 | else if(type_stack[sp-2]==DEF_SINGLE){
|
|---|
| 533 | //fld dword ptr[esp]
|
|---|
| 534 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 535 | }
|
|---|
| 536 | else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
|
|---|
| 537 | //64ビット整数値
|
|---|
| 538 |
|
|---|
| 539 | //fild qword ptr[esp]
|
|---|
| 540 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 541 |
|
|---|
| 542 | //add esp,4
|
|---|
| 543 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 544 | }
|
|---|
| 545 | else{
|
|---|
| 546 | //その他整数型
|
|---|
| 547 |
|
|---|
| 548 | //fild dword ptr[esp]
|
|---|
| 549 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 550 | }
|
|---|
| 551 |
|
|---|
| 552 | //fcompp
|
|---|
| 553 | compiler.codeGenerator.op_fcompp();
|
|---|
| 554 |
|
|---|
| 555 | //fnstsw ax
|
|---|
| 556 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 557 |
|
|---|
| 558 | //mov ecx,1
|
|---|
| 559 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 560 |
|
|---|
| 561 | //test ah,01h
|
|---|
| 562 | compiler.codeGenerator.op_test_ah( (char)0x41 );
|
|---|
| 563 |
|
|---|
| 564 | //jne 2
|
|---|
| 565 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 566 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 567 |
|
|---|
| 568 | //xor ecx,ecx
|
|---|
| 569 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 570 |
|
|---|
| 571 | //mov dword ptr[esp],ecx
|
|---|
| 572 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 573 | }
|
|---|
| 574 | else if(Is64Type(AnswerType)){
|
|---|
| 575 | ////////////////////
|
|---|
| 576 | // 64ビット整数演算
|
|---|
| 577 | ////////////////////
|
|---|
| 578 | int TrueSchedule1,
|
|---|
| 579 | TrueSchedule2,
|
|---|
| 580 | FalseSchedule;
|
|---|
| 581 |
|
|---|
| 582 | // 第1項 < 第2項
|
|---|
| 583 |
|
|---|
| 584 | //第1項 edx:eax
|
|---|
| 585 | //第2項 ecx:ebx
|
|---|
| 586 | GetStackData_ToRegister(type_stack,sp);
|
|---|
| 587 |
|
|---|
| 588 | //cmp edx,ecx
|
|---|
| 589 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 590 |
|
|---|
| 591 | if(IsSignedType(AnswerType)){
|
|---|
| 592 | //符号あり演算
|
|---|
| 593 |
|
|---|
| 594 | //jl TrueSchedule1(真へジャンプ)
|
|---|
| 595 | OpBuffer[obp++]=(char)0x7C;
|
|---|
| 596 | }
|
|---|
| 597 | else{
|
|---|
| 598 | //符号なし演算
|
|---|
| 599 |
|
|---|
| 600 | //jb TrueSchedule1(真へジャンプ)
|
|---|
| 601 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 602 | }
|
|---|
| 603 | TrueSchedule1=obp;
|
|---|
| 604 | obp++;
|
|---|
| 605 |
|
|---|
| 606 | if(IsSignedType(AnswerType)){
|
|---|
| 607 | //符号あり演算
|
|---|
| 608 |
|
|---|
| 609 | //jg FalseSchedule(偽へジャンプ)
|
|---|
| 610 | OpBuffer[obp++]=(char)0x7F;
|
|---|
| 611 | }
|
|---|
| 612 | else{
|
|---|
| 613 | //符号なし演算
|
|---|
| 614 |
|
|---|
| 615 | //ja FalseSchedule(偽へジャンプ)
|
|---|
| 616 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 617 | }
|
|---|
| 618 | FalseSchedule=obp;
|
|---|
| 619 | obp++;
|
|---|
| 620 |
|
|---|
| 621 | //cmp eax,ebx
|
|---|
| 622 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 623 |
|
|---|
| 624 | //jb TrueSchedule2(真へジャンプ)
|
|---|
| 625 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 626 | TrueSchedule2=obp;
|
|---|
| 627 | obp++;
|
|---|
| 628 |
|
|---|
| 629 | //FalseScheduleのジャンプ先の設定
|
|---|
| 630 | OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
|
|---|
| 631 |
|
|---|
| 632 | //xor eax,eax(eaxを0にする)
|
|---|
| 633 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 634 |
|
|---|
| 635 | //jmp 5(演算終了位置へジャンプ)
|
|---|
| 636 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 637 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 638 |
|
|---|
| 639 | //TrueScheduleのジャンプ先の設定
|
|---|
| 640 | OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
|
|---|
| 641 | OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
|
|---|
| 642 |
|
|---|
| 643 | //mov eax,1
|
|---|
| 644 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 645 |
|
|---|
| 646 | //push eax
|
|---|
| 647 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 648 | }
|
|---|
| 649 | else{
|
|---|
| 650 | ///////////////////
|
|---|
| 651 | //32ビット整数演算
|
|---|
| 652 | ///////////////////
|
|---|
| 653 |
|
|---|
| 654 | //pop ebx
|
|---|
| 655 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 656 |
|
|---|
| 657 | //pop eax
|
|---|
| 658 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 659 |
|
|---|
| 660 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 661 | AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
|
|---|
| 662 |
|
|---|
| 663 | //sub esp,4
|
|---|
| 664 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 665 |
|
|---|
| 666 | //mov ecx,1
|
|---|
| 667 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 668 |
|
|---|
| 669 | //cmp eax,ebx
|
|---|
| 670 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 671 |
|
|---|
| 672 | if(IsSignedType(AnswerType)){
|
|---|
| 673 | //符号あり演算
|
|---|
| 674 |
|
|---|
| 675 | //jl 2(次のxorを飛び越す)
|
|---|
| 676 | OpBuffer[obp++]=(char)0x7C;
|
|---|
| 677 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 678 | }
|
|---|
| 679 | else{
|
|---|
| 680 | //符号なし演算
|
|---|
| 681 |
|
|---|
| 682 | //jb 2(次のxorを飛び越す)
|
|---|
| 683 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 684 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | //xor ecx,ecx
|
|---|
| 688 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 689 |
|
|---|
| 690 | //mov dword ptr[esp],ecx
|
|---|
| 691 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | sp--;
|
|---|
| 695 | type_stack[sp-1]=DEF_BOOLEAN;
|
|---|
| 696 |
|
|---|
| 697 | *pStackPointer=sp;
|
|---|
| 698 | return 1;
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | BOOL Calc_Relation_Q(int *type_stack,LONG_PTR *index_stack,int *pStackPointer){
|
|---|
| 702 | //value[sp-2]>value[sp-1]
|
|---|
| 703 |
|
|---|
| 704 | int sp;
|
|---|
| 705 | sp=*pStackPointer;
|
|---|
| 706 |
|
|---|
| 707 | int AnswerType;
|
|---|
| 708 | AnswerType=NeutralizationType(type_stack[sp-2],index_stack[sp-2],type_stack[sp-1],index_stack[sp-1]);
|
|---|
| 709 |
|
|---|
| 710 | if(IsRealNumberType(AnswerType)){
|
|---|
| 711 | //////////////
|
|---|
| 712 | // 実数演算
|
|---|
| 713 | //////////////
|
|---|
| 714 |
|
|---|
| 715 | if(type_stack[sp-1]==DEF_DOUBLE){
|
|---|
| 716 | //fld qword ptr[esp]
|
|---|
| 717 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 718 |
|
|---|
| 719 | //add esp,8
|
|---|
| 720 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 721 | }
|
|---|
| 722 | else if(type_stack[sp-1]==DEF_SINGLE){
|
|---|
| 723 | //fld dword ptr[esp]
|
|---|
| 724 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 725 |
|
|---|
| 726 | //add esp,4
|
|---|
| 727 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 728 | }
|
|---|
| 729 | else if(type_stack[sp-1]==DEF_INT64||type_stack[sp-1]==DEF_QWORD){
|
|---|
| 730 | //64ビット整数値
|
|---|
| 731 |
|
|---|
| 732 | //fild qword ptr[esp]
|
|---|
| 733 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 734 |
|
|---|
| 735 | //add esp,8
|
|---|
| 736 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 737 | }
|
|---|
| 738 | else{ //Long、DWord
|
|---|
| 739 | //fild dword ptr[esp]
|
|---|
| 740 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 741 |
|
|---|
| 742 | //add esp,4
|
|---|
| 743 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 744 | }
|
|---|
| 745 |
|
|---|
| 746 | if(type_stack[sp-2]==DEF_DOUBLE){
|
|---|
| 747 | //fld qword ptr[esp]
|
|---|
| 748 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 749 |
|
|---|
| 750 | //add esp,4
|
|---|
| 751 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 752 | }
|
|---|
| 753 | else if(type_stack[sp-2]==DEF_SINGLE){
|
|---|
| 754 | //fld dword ptr[esp]
|
|---|
| 755 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 756 | }
|
|---|
| 757 | else if(type_stack[sp-2]==DEF_INT64||type_stack[sp-2]==DEF_QWORD){
|
|---|
| 758 | //64ビット整数値
|
|---|
| 759 |
|
|---|
| 760 | //fild qword ptr[esp]
|
|---|
| 761 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 762 |
|
|---|
| 763 | //add esp,4
|
|---|
| 764 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 765 | }
|
|---|
| 766 | else{ //Long、DWord
|
|---|
| 767 | //fild dword ptr[esp]
|
|---|
| 768 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 769 | }
|
|---|
| 770 |
|
|---|
| 771 | //fcompp
|
|---|
| 772 | compiler.codeGenerator.op_fcompp();
|
|---|
| 773 |
|
|---|
| 774 | //fnstsw ax
|
|---|
| 775 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 776 |
|
|---|
| 777 | //mov ecx,1
|
|---|
| 778 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 779 |
|
|---|
| 780 | //test ah,41
|
|---|
| 781 | compiler.codeGenerator.op_test_ah( (char)0x41 );
|
|---|
| 782 |
|
|---|
| 783 | //je 2(次のxorを飛び越す)
|
|---|
| 784 | OpBuffer[obp++]=(char)0x74;
|
|---|
| 785 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 786 |
|
|---|
| 787 | //xor ecx,ecx
|
|---|
| 788 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 789 |
|
|---|
| 790 | //mov dword ptr[esp],ecx
|
|---|
| 791 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 792 | }
|
|---|
| 793 | else if(Is64Type(AnswerType)){
|
|---|
| 794 | ////////////////////
|
|---|
| 795 | // 64ビット整数演算
|
|---|
| 796 | ////////////////////
|
|---|
| 797 | int FalseSchedule,
|
|---|
| 798 | TrueSchedule1,
|
|---|
| 799 | TrueSchedule2;
|
|---|
| 800 |
|
|---|
| 801 | // 第1項 > 第2項
|
|---|
| 802 |
|
|---|
| 803 | //第1項 edx:eax
|
|---|
| 804 | //第2項 ecx:ebx
|
|---|
| 805 | GetStackData_ToRegister(type_stack,sp);
|
|---|
| 806 |
|
|---|
| 807 | //cmp edx,ecx
|
|---|
| 808 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 809 |
|
|---|
| 810 | if(IsSignedType(AnswerType)){
|
|---|
| 811 | //符号有り
|
|---|
| 812 |
|
|---|
| 813 | //jg TrueSchedule1(真へジャンプ)
|
|---|
| 814 | OpBuffer[obp++]=(char)0x7F;
|
|---|
| 815 | }
|
|---|
| 816 | else{
|
|---|
| 817 | //符号無し
|
|---|
| 818 |
|
|---|
| 819 | //ja TrueSchedule1(真へジャンプ)
|
|---|
| 820 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 821 | }
|
|---|
| 822 | TrueSchedule1=obp;
|
|---|
| 823 | obp++;
|
|---|
| 824 |
|
|---|
| 825 | if(IsSignedType(AnswerType)){
|
|---|
| 826 | //符号有り
|
|---|
| 827 |
|
|---|
| 828 | //jl FalseSchedule(偽へジャンプ)
|
|---|
| 829 | OpBuffer[obp++]=(char)0x7C;
|
|---|
| 830 | }
|
|---|
| 831 | else{
|
|---|
| 832 | //符号無し
|
|---|
| 833 |
|
|---|
| 834 | //jb FalseSchedule(偽へジャンプ)
|
|---|
| 835 | OpBuffer[obp++]=(char)0x72;
|
|---|
| 836 | }
|
|---|
| 837 | FalseSchedule=obp;
|
|---|
| 838 | obp++;
|
|---|
| 839 |
|
|---|
| 840 | //cmp eax,ebx
|
|---|
| 841 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 842 |
|
|---|
| 843 | //ja TrueSchedule2(真へジャンプ)
|
|---|
| 844 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 845 | TrueSchedule2=obp;
|
|---|
| 846 | obp++;
|
|---|
| 847 |
|
|---|
| 848 | //FalseScheduleのジャンプ先の設定
|
|---|
| 849 | OpBuffer[FalseSchedule]=obp-(FalseSchedule+1);
|
|---|
| 850 |
|
|---|
| 851 | //xor eax,eax(eaxを0にする)
|
|---|
| 852 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 853 |
|
|---|
| 854 | //jmp 5(演算終了位置へジャンプ)
|
|---|
| 855 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 856 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 857 |
|
|---|
| 858 | //TrueScheduleのジャンプ先の設定
|
|---|
| 859 | OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
|
|---|
| 860 | OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
|
|---|
| 861 |
|
|---|
| 862 | //mov eax,1
|
|---|
| 863 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 864 |
|
|---|
| 865 | //push eax
|
|---|
| 866 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 867 | }
|
|---|
| 868 | else{
|
|---|
| 869 | ////////////////////
|
|---|
| 870 | // 32ビット整数演算
|
|---|
| 871 | ////////////////////
|
|---|
| 872 |
|
|---|
| 873 | //pop ebx
|
|---|
| 874 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 875 |
|
|---|
| 876 | //pop eax
|
|---|
| 877 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 878 |
|
|---|
| 879 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 880 | AutoExtendToBigType( type_stack, sp, REG_EAX, REG_EBX );
|
|---|
| 881 |
|
|---|
| 882 | //sub esp,4
|
|---|
| 883 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 884 |
|
|---|
| 885 | //mov ecx,1
|
|---|
| 886 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 887 |
|
|---|
| 888 | //cmp eax,ebx
|
|---|
| 889 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 890 |
|
|---|
| 891 | if(IsSignedType(AnswerType)){
|
|---|
| 892 | //jg 2(次のxorを飛び越す)
|
|---|
| 893 | OpBuffer[obp++]=(char)0x7F;
|
|---|
| 894 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 895 | }
|
|---|
| 896 | else{
|
|---|
| 897 | //ja 2(次のxorを飛び越す)
|
|---|
| 898 | OpBuffer[obp++]=(char)0x77;
|
|---|
| 899 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 900 | }
|
|---|
| 901 |
|
|---|
| 902 | //xor ecx,ecx
|
|---|
| 903 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 904 |
|
|---|
| 905 | //mov dword ptr[esp],ecx
|
|---|
| 906 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | sp--;
|
|---|
| 910 | type_stack[sp-1]=DEF_BOOLEAN;
|
|---|
| 911 |
|
|---|
| 912 | *pStackPointer=sp;
|
|---|
| 913 | return 1;
|
|---|
| 914 | }
|
|---|
| 915 |
|
|---|
| 916 | BOOL Calc_Relation_NotEqual(int *type,int *pStackPointer){
|
|---|
| 917 | //value[sp-2]<>value[sp-1]
|
|---|
| 918 |
|
|---|
| 919 | int sp;
|
|---|
| 920 | sp=*pStackPointer;
|
|---|
| 921 |
|
|---|
| 922 | if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
|
|---|
| 923 | type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
|
|---|
| 924 | //////////////
|
|---|
| 925 | // 実数演算
|
|---|
| 926 | //////////////
|
|---|
| 927 |
|
|---|
| 928 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 929 | //fld qword ptr[esp]
|
|---|
| 930 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 931 |
|
|---|
| 932 | //add esp,8
|
|---|
| 933 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 934 | }
|
|---|
| 935 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 936 | //fld dword ptr[esp]
|
|---|
| 937 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 938 |
|
|---|
| 939 | //add esp,4
|
|---|
| 940 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 941 | }
|
|---|
| 942 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 943 | //64ビット整数値
|
|---|
| 944 |
|
|---|
| 945 | //fild qword ptr[esp]
|
|---|
| 946 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 947 |
|
|---|
| 948 | //add esp,8
|
|---|
| 949 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 950 | }
|
|---|
| 951 | else{ //Long、DWord
|
|---|
| 952 | //fild dword ptr[esp]
|
|---|
| 953 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 954 |
|
|---|
| 955 | //add esp,4
|
|---|
| 956 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 957 | }
|
|---|
| 958 |
|
|---|
| 959 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 960 | //fld qword ptr[esp]
|
|---|
| 961 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 962 |
|
|---|
| 963 | //add esp,4
|
|---|
| 964 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 965 | }
|
|---|
| 966 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 967 | //fld dword ptr[esp]
|
|---|
| 968 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 969 | }
|
|---|
| 970 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 971 | //64ビット整数値
|
|---|
| 972 |
|
|---|
| 973 | //fild qword ptr[esp]
|
|---|
| 974 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 975 |
|
|---|
| 976 | //add esp,4
|
|---|
| 977 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 978 | }
|
|---|
| 979 | else{ //Long、DWord
|
|---|
| 980 | //fild dword ptr[esp]
|
|---|
| 981 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 982 | }
|
|---|
| 983 |
|
|---|
| 984 | //fcompp
|
|---|
| 985 | compiler.codeGenerator.op_fcompp();
|
|---|
| 986 |
|
|---|
| 987 | //fnstsw ax
|
|---|
| 988 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 989 |
|
|---|
| 990 | //mov ecx,1
|
|---|
| 991 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 992 |
|
|---|
| 993 | //test ah,40
|
|---|
| 994 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 995 |
|
|---|
| 996 | //je 2
|
|---|
| 997 | OpBuffer[obp++]=(char)0x74;
|
|---|
| 998 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 999 |
|
|---|
| 1000 | //xor ecx,ecx
|
|---|
| 1001 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 1002 |
|
|---|
| 1003 | //mov dword ptr[esp],ecx
|
|---|
| 1004 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1005 | }
|
|---|
| 1006 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
|
|---|
| 1007 | type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1008 | ////////////////////
|
|---|
| 1009 | // 64ビット整数演算
|
|---|
| 1010 | ////////////////////
|
|---|
| 1011 | int TrueSchedule1,
|
|---|
| 1012 | TrueSchedule2;
|
|---|
| 1013 |
|
|---|
| 1014 | // 第1項 <> 第2項
|
|---|
| 1015 |
|
|---|
| 1016 | //第1項 edx:eax
|
|---|
| 1017 | //第2項 ecx:ebx
|
|---|
| 1018 | GetStackData_ToRegister(type,sp);
|
|---|
| 1019 |
|
|---|
| 1020 | //cmp eax,ebx
|
|---|
| 1021 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 1022 |
|
|---|
| 1023 | //jnz TrueSchedule1(真へジャンプ)
|
|---|
| 1024 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 1025 | TrueSchedule1=obp;
|
|---|
| 1026 | obp++;
|
|---|
| 1027 |
|
|---|
| 1028 | //cmp edx,ecx
|
|---|
| 1029 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 1030 |
|
|---|
| 1031 | //jnz TrueSchedule2(真へジャンプ)
|
|---|
| 1032 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 1033 | TrueSchedule2=obp;
|
|---|
| 1034 | obp++;
|
|---|
| 1035 |
|
|---|
| 1036 | //xor eax,eax(eaxを0にする)
|
|---|
| 1037 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 1038 |
|
|---|
| 1039 | //jmp 5(演算終了位置へジャンプ)
|
|---|
| 1040 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 1041 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 1042 |
|
|---|
| 1043 | //TrueScheduleのジャンプ先の設定
|
|---|
| 1044 | OpBuffer[TrueSchedule1]=obp-(TrueSchedule1+1);
|
|---|
| 1045 | OpBuffer[TrueSchedule2]=obp-(TrueSchedule2+1);
|
|---|
| 1046 |
|
|---|
| 1047 | //mov eax,1
|
|---|
| 1048 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 1049 |
|
|---|
| 1050 | //push eax
|
|---|
| 1051 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 1052 | }
|
|---|
| 1053 | else{
|
|---|
| 1054 | ////////////////////
|
|---|
| 1055 | // 32ビット整数演算
|
|---|
| 1056 | ////////////////////
|
|---|
| 1057 |
|
|---|
| 1058 | //pop eax
|
|---|
| 1059 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1060 |
|
|---|
| 1061 | //pop ebx
|
|---|
| 1062 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1063 |
|
|---|
| 1064 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 1065 | AutoExtendToBigType( type, sp, REG_EAX, REG_EBX );
|
|---|
| 1066 |
|
|---|
| 1067 | //sub esp,4
|
|---|
| 1068 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1069 |
|
|---|
| 1070 | //xor eax,ebx
|
|---|
| 1071 | OpBuffer[obp++]=(char)0x33;
|
|---|
| 1072 | OpBuffer[obp++]=(char)0xC3;
|
|---|
| 1073 |
|
|---|
| 1074 | //jz 5(次のmovを飛び越す)
|
|---|
| 1075 | OpBuffer[obp++]=(char)0x74;
|
|---|
| 1076 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 1077 |
|
|---|
| 1078 | //mov eax,1
|
|---|
| 1079 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 1080 |
|
|---|
| 1081 | //mov dword ptr[esp],eax
|
|---|
| 1082 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1083 | }
|
|---|
| 1084 |
|
|---|
| 1085 | sp--;
|
|---|
| 1086 | type[sp-1]=DEF_BOOLEAN;
|
|---|
| 1087 |
|
|---|
| 1088 | *pStackPointer=sp;
|
|---|
| 1089 | return 1;
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|
| 1092 | BOOL Calc_Relation_Equal(int *type,int *pStackPointer){
|
|---|
| 1093 | //value[sp-2]=value[sp-1]
|
|---|
| 1094 |
|
|---|
| 1095 | int sp;
|
|---|
| 1096 | sp=*pStackPointer;
|
|---|
| 1097 |
|
|---|
| 1098 | if(type[sp-2]==DEF_DOUBLE||type[sp-2]==DEF_SINGLE||
|
|---|
| 1099 | type[sp-1]==DEF_DOUBLE||type[sp-1]==DEF_SINGLE){
|
|---|
| 1100 | //////////////
|
|---|
| 1101 | // 実数演算
|
|---|
| 1102 | //////////////
|
|---|
| 1103 |
|
|---|
| 1104 | if(type[sp-1]==DEF_DOUBLE){
|
|---|
| 1105 | //fld qword ptr[esp]
|
|---|
| 1106 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1107 |
|
|---|
| 1108 | //add esp,8
|
|---|
| 1109 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 1110 | }
|
|---|
| 1111 | else if(type[sp-1]==DEF_SINGLE){
|
|---|
| 1112 | //fld dword ptr[esp]
|
|---|
| 1113 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1114 |
|
|---|
| 1115 | //add esp,4
|
|---|
| 1116 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1117 | }
|
|---|
| 1118 | else if(type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1119 | //64ビット整数値
|
|---|
| 1120 |
|
|---|
| 1121 | //fild qword ptr[esp]
|
|---|
| 1122 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 1123 |
|
|---|
| 1124 | //add esp,8
|
|---|
| 1125 | compiler.codeGenerator.op_add_esp(8);
|
|---|
| 1126 | }
|
|---|
| 1127 | else{ //Long、DWord
|
|---|
| 1128 | //fild dword ptr[esp]
|
|---|
| 1129 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 1130 |
|
|---|
| 1131 | //add esp,4
|
|---|
| 1132 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1133 | }
|
|---|
| 1134 |
|
|---|
| 1135 | if(type[sp-2]==DEF_DOUBLE){
|
|---|
| 1136 | //fld qword ptr[esp]
|
|---|
| 1137 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
|---|
| 1138 |
|
|---|
| 1139 | //add esp,4
|
|---|
| 1140 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1141 | }
|
|---|
| 1142 | else if(type[sp-2]==DEF_SINGLE){
|
|---|
| 1143 | //fld dword ptr[esp]
|
|---|
| 1144 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
|---|
| 1145 | }
|
|---|
| 1146 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD){
|
|---|
| 1147 | //64ビット整数値
|
|---|
| 1148 |
|
|---|
| 1149 | //fild qword ptr[esp]
|
|---|
| 1150 | compiler.codeGenerator.op_fld_ptr_esp(DEF_INT64);
|
|---|
| 1151 |
|
|---|
| 1152 | //add esp,4
|
|---|
| 1153 | compiler.codeGenerator.op_add_esp(4);
|
|---|
| 1154 | }
|
|---|
| 1155 | else{ //Long、DWord
|
|---|
| 1156 | //fild dword ptr[esp]
|
|---|
| 1157 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
|---|
| 1158 | }
|
|---|
| 1159 |
|
|---|
| 1160 | //fcompp
|
|---|
| 1161 | compiler.codeGenerator.op_fcompp();
|
|---|
| 1162 |
|
|---|
| 1163 | //fnstsw ax
|
|---|
| 1164 | compiler.codeGenerator.op_fnstsw_ax();
|
|---|
| 1165 |
|
|---|
| 1166 | //mov ecx,1
|
|---|
| 1167 | compiler.codeGenerator.op_mov_RV( REG_ECX, 1 );
|
|---|
| 1168 |
|
|---|
| 1169 | //test ah,40
|
|---|
| 1170 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
|---|
| 1171 |
|
|---|
| 1172 | //jne 2(次のxorを飛び越す)
|
|---|
| 1173 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 1174 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 1175 |
|
|---|
| 1176 | //xor ecx,ecx
|
|---|
| 1177 | compiler.codeGenerator.op_xor_RR( REG_ECX );
|
|---|
| 1178 |
|
|---|
| 1179 | //mov dword ptr[esp],ecx
|
|---|
| 1180 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1181 | }
|
|---|
| 1182 | else if(type[sp-2]==DEF_INT64||type[sp-2]==DEF_QWORD||
|
|---|
| 1183 | type[sp-1]==DEF_INT64||type[sp-1]==DEF_QWORD){
|
|---|
| 1184 | ////////////////////
|
|---|
| 1185 | // 64ビット整数演算
|
|---|
| 1186 | ////////////////////
|
|---|
| 1187 | int FalseSchedule1,
|
|---|
| 1188 | FalseSchedule2;
|
|---|
| 1189 |
|
|---|
| 1190 | // 第1項 == 第2項
|
|---|
| 1191 |
|
|---|
| 1192 | //第1項 edx:eax
|
|---|
| 1193 | //第2項 ecx:ebx
|
|---|
| 1194 | GetStackData_ToRegister(type,sp);
|
|---|
| 1195 |
|
|---|
| 1196 | //cmp eax,ebx
|
|---|
| 1197 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
|---|
| 1198 |
|
|---|
| 1199 | //jnz FalseSchedule1(偽へジャンプ)
|
|---|
| 1200 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 1201 | FalseSchedule1=obp;
|
|---|
| 1202 | obp++;
|
|---|
| 1203 |
|
|---|
| 1204 | //cmp edx,ecx
|
|---|
| 1205 | compiler.codeGenerator.op_cmp_RR( REG_EDX, REG_ECX );
|
|---|
| 1206 |
|
|---|
| 1207 | //jnz FalseSchedule2(偽へジャンプ)
|
|---|
| 1208 | OpBuffer[obp++]=(char)0x75;
|
|---|
| 1209 | FalseSchedule2=obp;
|
|---|
| 1210 | obp++;
|
|---|
| 1211 |
|
|---|
| 1212 | //mov eax,1
|
|---|
| 1213 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 1214 |
|
|---|
| 1215 | //jmp 2(演算終了位置へジャンプ)
|
|---|
| 1216 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 1217 | OpBuffer[obp++]=(char)0x02;
|
|---|
| 1218 |
|
|---|
| 1219 | //FalseScheduleのジャンプ先の設定
|
|---|
| 1220 | OpBuffer[FalseSchedule1]=obp-(FalseSchedule1+1);
|
|---|
| 1221 | OpBuffer[FalseSchedule2]=obp-(FalseSchedule2+1);
|
|---|
| 1222 |
|
|---|
| 1223 | //xor eax,eax(eaxを0にする)
|
|---|
| 1224 | compiler.codeGenerator.op_zero_reg(REG_EAX);
|
|---|
| 1225 |
|
|---|
| 1226 | //push eax
|
|---|
| 1227 | compiler.codeGenerator.op_push(REG_EAX);
|
|---|
| 1228 | }
|
|---|
| 1229 | else{
|
|---|
| 1230 | ////////////////////
|
|---|
| 1231 | // 32ビット整数演算
|
|---|
| 1232 | ////////////////////
|
|---|
| 1233 |
|
|---|
| 1234 | //pop eax
|
|---|
| 1235 | compiler.codeGenerator.op_pop(REG_EAX);
|
|---|
| 1236 |
|
|---|
| 1237 | //pop ebx
|
|---|
| 1238 | compiler.codeGenerator.op_pop(REG_EBX);
|
|---|
| 1239 |
|
|---|
| 1240 | // どちらかのサイズが足りない場合は自動拡張する
|
|---|
| 1241 | AutoExtendToBigType( type, sp, REG_EAX, REG_EBX );
|
|---|
| 1242 |
|
|---|
| 1243 | //sub esp,4
|
|---|
| 1244 | compiler.codeGenerator.op_sub_esp(4);
|
|---|
| 1245 |
|
|---|
| 1246 | //xor eax,ebx
|
|---|
| 1247 | OpBuffer[obp++]=(char)0x33;
|
|---|
| 1248 | OpBuffer[obp++]=(char)0xC3;
|
|---|
| 1249 |
|
|---|
| 1250 | //jz 4(次のxorとjmpを飛び越す)
|
|---|
| 1251 | OpBuffer[obp++]=(char)0x74;
|
|---|
| 1252 | OpBuffer[obp++]=(char)0x04;
|
|---|
| 1253 |
|
|---|
| 1254 | //xor eax,eax
|
|---|
| 1255 | OpBuffer[obp++]=(char)0x33;
|
|---|
| 1256 | OpBuffer[obp++]=(char)0xC0;
|
|---|
| 1257 |
|
|---|
| 1258 | //jmp 5
|
|---|
| 1259 | OpBuffer[obp++]=(char)0xEB;
|
|---|
| 1260 | OpBuffer[obp++]=(char)0x05;
|
|---|
| 1261 |
|
|---|
| 1262 | //mov eax,1
|
|---|
| 1263 | compiler.codeGenerator.op_mov_RV( REG_EAX, 1 );
|
|---|
| 1264 |
|
|---|
| 1265 | //mov dword ptr[esp],eax
|
|---|
| 1266 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | sp--;
|
|---|
| 1270 | type[sp-1]=DEF_BOOLEAN;
|
|---|
| 1271 |
|
|---|
| 1272 | *pStackPointer=sp;
|
|---|
| 1273 | return 1;
|
|---|
| 1274 | }
|
|---|