Changeset 226 in dev for trunk/abdev
- Timestamp:
- Jul 22, 2007, 4:58:47 AM (17 years ago)
- Location:
- trunk/abdev
- Files:
-
- 3 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/BasicCompiler.vcproj
r224 r226 254 254 </File> 255 255 <File 256 RelativePath=".\MachineFixed.h" 257 > 258 </File> 259 <File 256 260 RelativePath="Opcode.h" 257 261 > … … 784 788 </File> 785 789 <File 790 RelativePath=".\CodeGenerator.cpp" 791 > 792 <FileConfiguration 793 Name="Debug|Win32" 794 > 795 <Tool 796 Name="VCCLCompilerTool" 797 ObjectFile="$(IntDir)\$(InputName)1.obj" 798 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc" 799 /> 800 </FileConfiguration> 801 <FileConfiguration 802 Name="Release|Win32" 803 > 804 <Tool 805 Name="VCCLCompilerTool" 806 ObjectFile="$(IntDir)\$(InputName)1.obj" 807 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc" 808 /> 809 </FileConfiguration> 810 </File> 811 <File 786 812 RelativePath=".\stack_frame.cpp" 787 813 > -
trunk/abdev/BasicCompiler64/CParameter.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 113 115 //call free 114 116 extern const UserProc *pSub_free; 115 op_call(pSub_free);117 compiler.codeGenerator.op_call(pSub_free); 116 118 } 117 119 else{ … … 132 134 133 135 //mov rcx,object_size 134 op_mov_RV(sizeof(_int64),REG_RCX,object_size);136 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,object_size); 135 137 136 138 //call calloc 137 139 extern const UserProc *pSub_calloc; 138 op_call(pSub_calloc);140 compiler.codeGenerator.op_call(pSub_calloc); 139 141 140 142 //mov r11,rax 141 op_mov_RR(REG_R11,REG_RAX);143 compiler.codeGenerator.op_mov_RR(REG_R11,REG_RAX); 142 144 143 145 //mov qword ptr[rsp+offset],r11 ※スタックフレームを利用 … … 179 181 180 182 //mov reg,r11 181 op_mov_RR(reg,REG_R11);183 compiler.codeGenerator.op_mov_RR(reg,REG_R11); 182 184 } 183 185 … … 317 319 318 320 //movd reg,temp_reg 319 op_movd_RX(reg,temp_reg);321 compiler.codeGenerator.op_movd_RX(reg,temp_reg); 320 322 } 321 323 } … … 430 432 //スタックフレームへコピー 431 433 //mov qword ptr[rsp+offset],rax 432 op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32);434 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32); 433 435 } 434 436 else if(xmm_temp_sw){ … … 436 438 437 439 //movlpd qword ptr[rsp+offset],xmm0 438 op_movlpd_MR(REG_XMM0,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32);440 compiler.codeGenerator.op_movlpd_MR(REG_XMM0,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32); 439 441 } 440 442 … … 467 469 if(obj_DBLockParms.array_LevelCount[i2]){ 468 470 //mov r14,qword ptr[rsp+offset] 469 op_mov_RM(sizeof(_int64),REG_R14,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32);471 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R14,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32); 470 472 471 473 //mov qword ptr[rsp+offset],r14 ※スタックフレームを利用 … … 503 505 504 506 //mov qword ptr[rsp+offset],r14 505 op_mov_MR(sizeof(_int64),REG_R14,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32);507 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R14,REG_RSP,i2*sizeof(_int64),MOD_BASE_DISP32); 506 508 } 507 509 } -
trunk/abdev/BasicCompiler64/Compile_Calc.cpp
r206 r226 247 247 248 248 // mov rcx, rax 249 op_mov_RR( REG_RCX, REG_RAX );249 compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RAX ); 250 250 251 251 // call System.[TypeClass]._Create 252 op_call( pUserProc );252 compiler.codeGenerator.op_call( pUserProc ); 253 253 254 254 calcType = pUserProc->ReturnType(); -
trunk/abdev/BasicCompiler64/Compile_Calc_PushVar.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 71 73 else{ 72 74 //mov r11,qword ptr[rsp+offset] 73 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);75 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 74 76 obp-=sizeof(long); 75 77 AddLocalVarAddrSchedule(); … … 155 157 else{ 156 158 //mov r11,qword ptr[rsp+offset] 157 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);159 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 158 160 obp-=sizeof(long); 159 161 AddLocalVarAddrSchedule(); … … 183 185 if(pRelativeVar->bOffsetOffset){ 184 186 //mov reg, ptr[r11+offset] 185 op_mov_RM(varSize,reg,REG_R11,(int)pRelativeVar->offset,MOD_BASE_DISP32);187 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_R11,(int)pRelativeVar->offset,MOD_BASE_DISP32); 186 188 obp-=sizeof(long); 187 189 pobj_GlobalVarSchedule->add(); … … 190 192 else{ 191 193 //mov reg, ptr[offset] 192 op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset,MOD_DISP32);194 compiler.codeGenerator.op_mov_RM(varSize,reg,0,(int)pRelativeVar->offset,MOD_DISP32); 193 195 obp-=sizeof(long); 194 196 pobj_GlobalVarSchedule->add(); … … 199 201 if(pRelativeVar->bOffsetOffset){ 200 202 //add r11,qword ptr[offset] 201 op_add_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);203 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32); 202 204 obp-=sizeof(long); 203 205 pobj_GlobalVarSchedule->add(); … … 206 208 else{ 207 209 //mov r11,qword ptr[offset] 208 op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);210 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32); 209 211 obp-=sizeof(long); 210 212 pobj_GlobalVarSchedule->add(); … … 217 219 if(pRelativeVar->bOffsetOffset){ 218 220 //mov reg, ptr[rsp+r11+offset] 219 op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET);221 compiler.codeGenerator.op_mov_RM_ex(varSize,reg,REG_RSP,REG_R11,(int)pRelativeVar->offset,USE_OFFSET); 220 222 obp-=sizeof(long); 221 223 AddLocalVarAddrSchedule(); … … 224 226 else{ 225 227 //mov reg, ptr[rsp+offset] 226 op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);228 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 227 229 obp-=sizeof(long); 228 230 AddLocalVarAddrSchedule(); … … 233 235 if(pRelativeVar->bOffsetOffset){ 234 236 //add r11,qword ptr[rsp+offset] 235 op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);237 compiler.codeGenerator.op_add_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 236 238 obp-=sizeof(long); 237 239 AddLocalVarAddrSchedule(); … … 240 242 else{ 241 243 //mov r11,qword ptr[rsp+offset] 242 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);244 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 243 245 obp-=sizeof(long); 244 246 AddLocalVarAddrSchedule(); … … 251 253 directmem: 252 254 //mov reg, ptr[r11] 253 op_mov_RM(varSize,reg,REG_R11,0,MOD_BASE);255 compiler.codeGenerator.op_mov_RM(varSize,reg,REG_R11,0,MOD_BASE); 254 256 } 255 257 } -
trunk/abdev/BasicCompiler64/Compile_CallProc.cpp
r206 r226 15 15 //call _System_GetEip 16 16 extern const UserProc *pSub_System_GetEip; 17 op_call(pSub_System_GetEip);17 compiler.codeGenerator.op_call(pSub_System_GetEip); 18 18 19 19 //mov rdx,rax 20 op_mov_RR(REG_RDX,REG_RAX);20 compiler.codeGenerator.op_mov_RR(REG_RDX,REG_RAX); 21 21 22 22 //mov rcx,rsp 23 op_mov_RR(REG_RCX,REG_RSP);23 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP); 24 24 25 25 //call _DebugSys_SaveContext 26 26 extern const UserProc *pSub_DebugSys_SaveContext; 27 op_call(pSub_DebugSys_SaveContext);27 compiler.codeGenerator.op_call(pSub_DebugSys_SaveContext); 28 28 } 29 29 … … 79 79 80 80 //mov rax,qword ptr[rax] 81 op_mov_RM(sizeof(_int64),REG_RAX,REG_RAX,0,MOD_BASE);81 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RAX,0,MOD_BASE); 82 82 83 83 //call rax … … 278 278 279 279 //mov rcx,object_size 280 op_mov_RV(sizeof(_int64),REG_RCX,object_size);280 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,object_size); 281 281 282 282 //call calloc 283 283 extern const UserProc *pSub_calloc; 284 op_call(pSub_calloc);284 compiler.codeGenerator.op_call(pSub_calloc); 285 285 286 286 //mov r13,rax 287 op_mov_RR(REG_R13,REG_RAX);287 compiler.codeGenerator.op_mov_RR(REG_R13,REG_RAX); 288 288 289 289 ///////////////////////////////////////////// … … 294 294 if( pUserProc->GetParentClassPtr() && isStatic == false ){ 295 295 //mov rdx,r13 296 op_mov_RR(REG_RDX,REG_R13);296 compiler.codeGenerator.op_mov_RR(REG_RDX,REG_R13); 297 297 } 298 298 else{ 299 299 //mov rcx,r13 300 op_mov_RR(REG_RCX,REG_R13);300 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_R13); 301 301 } 302 302 } … … 330 330 // 参照を実体ポインタにする 331 331 //mov rcx,qword ptr[rcx] 332 op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE);332 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); 333 333 } 334 334 } … … 355 355 356 356 //mov r11,qword ptr[rcx] 357 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE);357 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 358 358 359 359 i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); … … 378 378 379 379 //call ProcAddr 380 op_call(pUserProc);380 compiler.codeGenerator.op_call(pUserProc); 381 381 } 382 382 … … 445 445 446 446 //call dword ptr[ImportTable] 447 op_call( pDllProc );447 compiler.codeGenerator.op_call( pDllProc ); 448 448 449 449 /* 64コンパイラでは不要 -
trunk/abdev/BasicCompiler64/Compile_Func.cpp
r206 r226 64 64 65 65 //mov rax,TypeSize 66 op_mov_RV(sizeof(_int64),REG_RAX,typeSize);66 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); 67 67 68 68 return; … … 124 124 if(type.IsObjectPtr()){ 125 125 //mov rcx,qword ptr[rcx] 126 op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE);126 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RCX,0,MOD_BASE); 127 127 } 128 128 } … … 143 143 144 144 //mov r11,qword ptr[rcx] 145 op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE);145 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RCX,0,MOD_BASE); 146 146 147 147 int i2 = pobj_c->GetFuncNumInVtbl( pUserProc ); … … 149 149 //mov rax,qword ptr[r11+func_index] 150 150 if(i2*PTR_SIZE<=0x7F){ 151 op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,i2*PTR_SIZE,MOD_BASE_DISP8);151 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,i2*PTR_SIZE,MOD_BASE_DISP8); 152 152 } 153 153 else{ 154 op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,i2*PTR_SIZE,MOD_BASE_DISP32);154 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_R11,i2*PTR_SIZE,MOD_BASE_DISP32); 155 155 } 156 156 } … … 159 159 160 160 //mov rax,ProcAddr 161 op_mov_RV(sizeof(_int64),REG_RAX,0);161 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,0); 162 162 obp-=sizeof(long); 163 163 pobj_SubAddrSchedule->add(pUserProc,0); … … 178 178 179 179 //mov rax,size 180 op_mov_RV(sizeof(_int64),REG_RAX,typeSize);180 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,typeSize); 181 181 } 182 182 void Opcode_Func_VarPtr( const char *Parameter, Type &resultType, bool isCallOn ){ … … 209 209 210 210 //mov rax,qword ptr[rax] 211 op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );211 compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); 212 212 213 213 SetError(-120,NULL,cp); … … 244 244 245 245 //mov rax,qword ptr[rax] 246 op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );246 compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); 247 247 } 248 248 else{ … … 263 263 if(type==DEF_DOUBLE){ 264 264 //movlpd xmm0,qword ptr[rax] 265 op_movlpd_RM(REG_XMM0,REG_RAX,0,MOD_BASE);265 compiler.codeGenerator.op_movlpd_RM(REG_XMM0,REG_RAX,0,MOD_BASE); 266 266 } 267 267 else if(type==DEF_SINGLE){ 268 268 //movss xmm0,dword ptr[rax] 269 op_movss_RM(REG_XMM0,REG_RAX,0,MOD_BASE);269 compiler.codeGenerator.op_movss_RM(REG_XMM0,REG_RAX,0,MOD_BASE); 270 270 } 271 271 else{ 272 272 //mov rax,ptr[rax] 273 op_mov_RM(GetTypeSize(type,-1),REG_RAX,REG_RAX,0,MOD_BASE);273 compiler.codeGenerator.op_mov_RM(GetTypeSize(type,-1),REG_RAX,REG_RAX,0,MOD_BASE); 274 274 } 275 275 } -
trunk/abdev/BasicCompiler64/Compile_Object.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 113 115 //※添え字上限値であることを考慮 114 116 //add rax,1 115 op_add_RV(REG_RAX,1);117 compiler.codeGenerator.op_add_RV(REG_RAX,1); 116 118 117 119 //オブジェクトの個数をrbxに一時保持 118 120 //※rbxは関数が呼ばれても不変 119 121 //mov rbx,rax 120 op_mov_RR(REG_RBX,REG_RAX);122 compiler.codeGenerator.op_mov_RR(REG_RBX,REG_RAX); 121 123 122 124 //imul rax,size 123 op_imul_RV(sizeof(_int64),REG_RAX,typeSize);125 compiler.codeGenerator.op_imul_RV(sizeof(_int64),REG_RAX,typeSize); 124 126 125 127 //add rax,OBJECT_HEAD_SIZE 126 op_add_RV(REG_RAX,OBJECT_HEAD_SIZE);128 compiler.codeGenerator.op_add_RV(REG_RAX,OBJECT_HEAD_SIZE); 127 129 128 130 //mov rcx,rax 129 op_mov_RR(REG_RCX,REG_RAX);131 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RAX); 130 132 } 131 133 else{ … … 133 135 //※rbxは関数が呼ばれても不変 134 136 //mov rbx,1 135 op_mov_RV(sizeof(_int64),REG_RBX,1);137 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RBX,1); 136 138 137 139 //mov rcx,typeSize+OBJECT_HEAD_SIZE 138 op_mov_RV(sizeof(_int64),REG_RCX,typeSize+OBJECT_HEAD_SIZE);140 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,typeSize+OBJECT_HEAD_SIZE); 139 141 } 140 142 … … 145 147 //call _System_GC_malloc_ForObject 146 148 extern const UserProc *pSub_System_GC_malloc_ForObject; 147 op_call(pSub_System_GC_malloc_ForObject);149 compiler.codeGenerator.op_call(pSub_System_GC_malloc_ForObject); 148 150 } 149 151 else{ … … 153 155 //call _System_GC_malloc_ForObjectPtr 154 156 extern const UserProc *pSub_System_GC_malloc_ForObjectPtr; 155 op_call(pSub_System_GC_malloc_ForObjectPtr);157 compiler.codeGenerator.op_call(pSub_System_GC_malloc_ForObjectPtr); 156 158 } 157 159 … … 168 170 169 171 //mov qword ptr[rax],rbx(オブジェクトの個数) 170 op_mov_MR(sizeof(_int64),REG_RBX,REG_RAX,0,MOD_BASE);171 172 //add rax,PTR_SIZE 173 op_add_RV(REG_RAX,PTR_SIZE);172 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RBX,REG_RAX,0,MOD_BASE); 173 174 //add rax,PTR_SIZE 175 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 174 176 175 177 176 178 //mov qword ptr[rax],typeSize(オブジェクトのサイズ) 177 op_mov_MV(sizeof(_int64),REG_RAX,0,NON_OFFSET,typeSize);178 179 //add rax,PTR_SIZE 180 op_add_RV(REG_RAX,PTR_SIZE);179 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RAX,0,NON_OFFSET,typeSize); 180 181 //add rax,PTR_SIZE 182 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 181 183 182 184 … … 185 187 186 188 //mov rcx,DestructorProcAddr(デストラクタの関数ポインタ) 187 op_mov_RV(sizeof(_int64),REG_RCX,0);189 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,0); 188 190 obp-=sizeof(long); 189 191 pobj_SubAddrSchedule->add(&method->GetUserProc(),0); … … 192 194 193 195 //mov qword ptr[rax],rcx 194 op_mov_MR(sizeof(_int64),REG_RCX,REG_RAX,0,MOD_BASE);195 196 //add rax,PTR_SIZE 197 op_add_RV(REG_RAX,PTR_SIZE);196 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RAX,0,MOD_BASE); 197 198 //add rax,PTR_SIZE 199 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 198 200 199 201 200 202 // リザーブ領域 201 203 //add rax,PTR_SIZE 202 op_add_RV(REG_RAX,PTR_SIZE);204 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 203 205 204 206 … … 229 231 230 232 //sub rax,OBJECT_HEAD_SIZE 231 op_sub_RV(sizeof(_int64),REG_RAX,OBJECT_HEAD_SIZE);233 compiler.codeGenerator.op_sub_RV(sizeof(_int64),REG_RAX,OBJECT_HEAD_SIZE); 232 234 233 235 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用 … … 236 238 237 239 //mov rbx,qword ptr[rax](オブジェクトの個数) 238 op_mov_RM(sizeof(_int64),REG_RBX,REG_RAX,0,MOD_BASE);239 240 //add rax,PTR_SIZE 241 op_add_RV(REG_RAX,PTR_SIZE);240 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RBX,REG_RAX,0,MOD_BASE); 241 242 //add rax,PTR_SIZE 243 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 242 244 243 245 244 246 //mov rsi,qword ptr[rax](オブジェクトのサイズ) 245 op_mov_RM(sizeof(_int64),REG_RSI,REG_RAX,0,MOD_BASE);246 247 //add rax,PTR_SIZE 248 op_add_RV(REG_RAX,PTR_SIZE);247 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RSI,REG_RAX,0,MOD_BASE); 248 249 //add rax,PTR_SIZE 250 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 249 251 250 252 251 253 //mov rdi,qword ptr[rax](デストラクタの関数ポインタ) 252 op_mov_RM(sizeof(_int64),REG_RDI,REG_RAX,0,MOD_BASE);253 254 //add rax,PTR_SIZE 255 op_add_RV(REG_RAX,PTR_SIZE);254 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDI,REG_RAX,0,MOD_BASE); 255 256 //add rax,PTR_SIZE 257 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 256 258 257 259 258 260 // リザーブ領域 259 261 //add rax,PTR_SIZE 260 op_add_RV(REG_RAX,PTR_SIZE);262 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 261 263 262 264 263 265 //mov rcx,rax 264 op_mov_RR(REG_RCX,REG_RAX);266 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RAX); 265 267 266 268 … … 280 282 281 283 //add rcx,rsi 282 op_add64_reg(REG_RCX,REG_RSI);284 compiler.codeGenerator.op_add64_reg(REG_RCX,REG_RSI); 283 285 284 286 //sub rbx,1 285 op_sub_RV(sizeof(_int64),REG_RBX,1);287 compiler.codeGenerator.op_sub_RV(sizeof(_int64),REG_RBX,1); 286 288 287 289 //jnz ↑ … … 302 304 //call _System_GC_free_for_SweepingDelete 303 305 extern const UserProc *pSub_System_GC_free_for_SweepingDelete; 304 op_call(pSub_System_GC_free_for_SweepingDelete);306 compiler.codeGenerator.op_call(pSub_System_GC_free_for_SweepingDelete); 305 307 } 306 308 else{ 307 309 //call free 308 310 extern const UserProc *pSub_free; 309 op_call(pSub_free);311 compiler.codeGenerator.op_call(pSub_free); 310 312 } 311 313 } -
trunk/abdev/BasicCompiler64/Compile_ProcOp.cpp
r221 r226 15 15 if( userProc.GetName() == "_System_GetEip" ){ 16 16 //mov rax,qword ptr[rsp] 17 op_mov_RM(sizeof(_int64),REG_RAX,REG_RSP,0,MOD_BASE);17 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RAX,REG_RSP,0,MOD_BASE); 18 18 19 19 //ret 20 op_ret();20 compiler.codeGenerator.op_ret(); 21 21 } 22 22 else if( userProc.GetName() == "_System_InitDllGlobalVariables" ){ … … 27 27 if(!bDll){ 28 28 //ret 29 op_ret();29 compiler.codeGenerator.op_ret(); 30 30 31 31 return; … … 41 41 //sub rsp,スタックフレームサイズ 42 42 int StackFrameSchedule; 43 op_sub_rsp(0xFFFFFFFF);43 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 44 44 StackFrameSchedule=obp-sizeof(long); 45 45 … … 55 55 //_System_StartupProgramの呼び出し 56 56 extern const UserProc *pSub_System_StartupProgram; 57 op_call(pSub_System_StartupProgram);57 compiler.codeGenerator.op_call(pSub_System_StartupProgram); 58 58 59 59 //クラスに属する静的メンバを定義 … … 63 63 64 64 //add rsp,スタックフレームサイズ 65 op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));65 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0)); 66 66 67 67 //スタックフレームスケジュール(subコマンドに渡す値) … … 72 72 73 73 //ret 74 op_ret();74 compiler.codeGenerator.op_ret(); 75 75 } 76 76 else if( userProc.GetName() == "_System_InitStaticLocalVariables" ){ … … 79 79 //sub rsp,スタックフレームサイズ 80 80 int StackFrameSchedule; 81 op_sub_rsp(0xFFFFFFFF);81 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 82 82 StackFrameSchedule=obp-sizeof(long); 83 83 … … 100 100 101 101 //add rsp,スタックフレームサイズ 102 op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0));102 compiler.codeGenerator.op_add_RV(REG_RSP,pobj_sf->GetFrameSize(0)); 103 103 104 104 //スタックフレームスケジュール(subコマンドに渡す値) … … 106 106 107 107 //ret 108 op_ret();108 compiler.codeGenerator.op_ret(); 109 109 } 110 110 else if( userProc.GetName() == "_System_Call_Destructor_of_GlobalObject" ){ 111 111 //sub rsp,8(※RSPを16バイト境界にあわせるため) 112 op_sub_rsp(0x8);112 compiler.codeGenerator.op_sub_rsp(0x8); 113 113 114 114 … … 122 122 123 123 //add rsp,8 124 op_add_RV(REG_RSP,0x8);124 compiler.codeGenerator.op_add_RV(REG_RSP,0x8); 125 125 126 126 //ret 127 op_ret();127 compiler.codeGenerator.op_ret(); 128 128 } 129 129 else if( userProc.GetName() == "_System_GetSp" ){ 130 130 //mov rax,rsp 131 op_mov_RR(REG_RAX,REG_RSP);131 compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RSP); 132 132 133 133 //add rax,PTR_SIZE 134 op_add_RV(REG_RAX,PTR_SIZE);134 compiler.codeGenerator.op_add_RV(REG_RAX,PTR_SIZE); 135 135 136 136 //ret 137 op_ret();137 compiler.codeGenerator.op_ret(); 138 138 } 139 139 else if( userProc.GetName() == "_allrem" ){ … … 276 276 compiler.GetNamespaceSupporter().SetImportedNamespaces( pUserProc->GetImportedNamespaces() ); 277 277 278 // コード生成対象を選択 279 compiler.codeGenerator.Select( (const_cast<UserProc *>(pUserProc))->GetNativeCode() ); 280 278 281 if(pUserProc->IsSystem()){ 279 282 //////////////////// … … 408 411 if(param.IsReal()&¶m.IsRef() == false){ 409 412 //movsd qword ptr[rsp+0x20],xmm3 410 op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32);413 compiler.codeGenerator.op_movsd_MR(REG_XMM3,REG_RSP,0x20,MOD_BASE_DISP32); 411 414 } 412 415 else{ 413 416 //mov qword ptr[rsp+0x20],r9 414 op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32);417 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R9,REG_RSP,0x20,MOD_BASE_DISP32); 415 418 } 416 419 } … … 418 421 if(param.IsReal()&¶m.IsRef() == false){ 419 422 //movsd qword ptr[rsp+0x18],xmm2 420 op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32);423 compiler.codeGenerator.op_movsd_MR(REG_XMM2,REG_RSP,0x18,MOD_BASE_DISP32); 421 424 } 422 425 else{ 423 426 //mov qword ptr[rsp+0x18],r8 424 op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32);427 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_R8,REG_RSP,0x18,MOD_BASE_DISP32); 425 428 } 426 429 } … … 428 431 if(param.IsReal()&¶m.IsRef() == false){ 429 432 //movsd qword ptr[rsp+0x10],xmm1 430 op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32);433 compiler.codeGenerator.op_movsd_MR(REG_XMM1,REG_RSP,0x10,MOD_BASE_DISP32); 431 434 } 432 435 else{ 433 436 //mov qword ptr[rsp+0x10],rdx 434 op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32);437 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RDX,REG_RSP,0x10,MOD_BASE_DISP32); 435 438 } 436 439 } … … 438 441 if(param.IsReal()&¶m.IsRef() == false){ 439 442 //movsd qword ptr[rsp+0x8],xmm0 440 op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32);443 compiler.codeGenerator.op_movsd_MR(REG_XMM0,REG_RSP,0x8,MOD_BASE_DISP32); 441 444 } 442 445 else{ 443 446 //mov qword ptr[rsp+0x8],rcx 444 op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32);447 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RCX,REG_RSP,0x8,MOD_BASE_DISP32); 445 448 } 446 449 } … … 452 455 //sub rsp,スタックフレームサイズ 453 456 int StackFrameSchedule; 454 op_sub_rsp(0xFFFFFFFF);457 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 455 458 StackFrameSchedule=obp-sizeof(long); 456 459 … … 496 499 if(bDebugCompile&&bDebugSupportProc==0){ 497 500 //mov rdx, qword ptr[rsp+スタックフレームサイズ] 498 op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32);501 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RDX,REG_RSP,0,MOD_BASE_DISP32); 499 502 RspOffsetSchedule=obp-sizeof(long); 500 503 501 504 //mov rcx,rsp 502 op_mov_RR(REG_RCX,REG_RSP);505 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RSP); 503 506 504 507 //add rcx,スタックフレームサイズ+sizeof(_int64) ※ret用のサイズを考慮 505 op_add_RV(REG_RCX,0);508 compiler.codeGenerator.op_add_RV(REG_RCX,0); 506 509 RspOffsetSchedule2=obp-sizeof(long); 507 510 508 511 //call _DebugSys_StartProc 509 512 extern const UserProc *pSub_DebugSys_StartProc; 510 op_call(pSub_DebugSys_StartProc);513 compiler.codeGenerator.op_call(pSub_DebugSys_StartProc); 511 514 } 512 515 … … 582 585 583 586 //mov rax,offset 584 op_mov_RV(sizeof(_int64),REG_RAX,offset);587 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,offset); 585 588 obp-=sizeof(long); 586 589 pobj_DataTableSchedule->add(); … … 591 594 592 595 //mov qword ptr[rcx],rax 593 op_mov_MR(sizeof(_int64),REG_RAX,REG_RCX,0,MOD_BASE);596 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RCX,0,MOD_BASE); 594 597 } 595 598 } … … 695 698 //call _DebugSys_EndProc 696 699 extern const UserProc *pSub_DebugSys_EndProc; 697 op_call(pSub_DebugSys_EndProc);700 compiler.codeGenerator.op_call(pSub_DebugSys_EndProc); 698 701 } 699 702 … … 717 720 if( i3==DEF_OBJECT ){ 718 721 //mov rax,qword ptr[rax] 719 op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE );722 compiler.codeGenerator.op_mov_RM( sizeof(_int64), REG_RAX, REG_RAX, 0, MOD_BASE ); 720 723 } 721 724 } … … 763 766 764 767 //add rsp,スタックフレームサイズ 765 op_add_rsp(stackFrameAndLocalParamSize);768 compiler.codeGenerator.op_add_rsp(stackFrameAndLocalParamSize); 766 769 767 770 //ret 768 op_ret();771 compiler.codeGenerator.op_ret(); 769 772 770 773 -
trunk/abdev/BasicCompiler64/Compile_Set_Var.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 24 26 if( calcType.IsDouble() ){ 25 27 //movlsd RightTermReg,xmm0 26 op_movsd_RR(RightTermReg,REG_XMM0);28 compiler.codeGenerator.op_movsd_RR(RightTermReg,REG_XMM0); 27 29 } 28 30 else if( calcType.IsSingle() ){ 29 31 //movlss RightTermReg,xmm0 30 op_movss_RR(RightTermReg,REG_XMM0);32 compiler.codeGenerator.op_movss_RR(RightTermReg,REG_XMM0); 31 33 } 32 34 } … … 35 37 36 38 //mov RightTermReg,rax 37 op_mov_RR(RightTermReg,REG_RAX);39 compiler.codeGenerator.op_mov_RR(RightTermReg,REG_RAX); 38 40 } 39 41 … … 57 59 58 60 //mov rsi,RightTermReg 59 op_mov_RR(REG_RSI,RightTermReg);61 compiler.codeGenerator.op_mov_RR(REG_RSI,RightTermReg); 60 62 61 63 //mov rdi,VarReg 62 op_mov_RR(REG_RDI,VarReg);64 compiler.codeGenerator.op_mov_RR(REG_RDI,VarReg); 63 65 64 66 int object_size = varType.GetClass().GetSize(); 65 67 66 68 //mov rcx,object_size 67 op_mov_RV(sizeof(_int64),REG_RCX,object_size);69 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,object_size); 68 70 69 71 if(bUseHeap){ 70 72 //mov rax,rsi 71 op_mov_RR(REG_RAX,REG_RSI);73 compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RSI); 72 74 } 73 75 74 76 //rep movs byte ptr[rdi],byte ptr[rsi] 75 op_rep_movs(sizeof(BYTE));77 compiler.codeGenerator.op_rep_movs(sizeof(BYTE)); 76 78 77 79 if(bUseHeap){ 78 80 //mov rcx,rax 79 op_mov_RR(REG_RCX,REG_RAX);81 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_RAX); 80 82 81 83 //call free 82 84 extern const UserProc *pSub_free; 83 op_call(pSub_free);85 compiler.codeGenerator.op_call(pSub_free); 84 86 } 85 87 … … 165 167 else{ 166 168 //mov r11,qword ptr[rsp+offset] 167 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32);169 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32); 168 170 obp-=sizeof(long); 169 171 AddLocalVarAddrSchedule(); … … 256 258 else{ 257 259 //mov r11,qword ptr[rsp+offset] 258 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32);260 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32); 259 261 obp-=sizeof(long); 260 262 AddLocalVarAddrSchedule(); … … 289 291 290 292 //cvttsd2si rax,xmm0 291 op_cvttsd2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0);293 compiler.codeGenerator.op_cvttsd2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 292 294 } 293 295 else if(type==DEF_SINGLE){ … … 295 297 296 298 //cvttss2si rax,xmm0 297 op_cvttss2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0);299 compiler.codeGenerator.op_cvttss2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 298 300 } 299 301 300 302 //cmp rax,0 301 op_cmp_value(GetTypeSize(type,-1),REG_RAX,0);303 compiler.codeGenerator.op_cmp_value(GetTypeSize(type,-1),REG_RAX,0); 302 304 303 305 //setne al 304 op_setne( REG_RAX );306 compiler.codeGenerator.op_setne( REG_RAX ); 305 307 306 308 SetWholeVariable( sizeof(char), DEF_BYTE, pRelative); … … 311 313 312 314 //cvttsd2si rax,xmm0 313 op_cvttsd2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0);315 compiler.codeGenerator.op_cvttsd2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 314 316 } 315 317 else if(type==DEF_SINGLE){ … … 317 319 318 320 //cvttss2si rax,xmm0 319 op_cvttss2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0);321 compiler.codeGenerator.op_cvttss2si_xmm(sizeof(_int64),REG_RAX,REG_XMM0); 320 322 } 321 323 else{ … … 340 342 if(pRelative->bOffsetOffset){ 341 343 //mov ptr[r11+offset],rax/eax/ax/al 342 op_mov_MR(varSize,REG_RAX,REG_R11,(int)pRelative->offset,MOD_BASE_DISP32);344 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,REG_R11,(int)pRelative->offset,MOD_BASE_DISP32); 343 345 obp-=sizeof(long); 344 346 pobj_GlobalVarSchedule->add(); … … 347 349 else{ 348 350 //mov ptr[offset],rax/eax/ax/al 349 op_mov_MR(varSize,REG_RAX,0,(int)pRelative->offset,MOD_DISP32);351 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,0,(int)pRelative->offset,MOD_DISP32); 350 352 obp-=sizeof(long); 351 353 pobj_GlobalVarSchedule->add(); … … 356 358 if(pRelative->bOffsetOffset){ 357 359 //add r11,qword ptr[offset] 358 op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelative->offset, MOD_DISP32 );360 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelative->offset, MOD_DISP32 ); 359 361 obp-=sizeof(long); 360 362 pobj_GlobalVarSchedule->add(); … … 363 365 else{ 364 366 //mov r11,qword ptr[offset] 365 op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelative->offset,MOD_DISP32);367 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelative->offset,MOD_DISP32); 366 368 obp-=sizeof(long); 367 369 pobj_GlobalVarSchedule->add(); … … 374 376 if(pRelative->bOffsetOffset){ 375 377 //mov ptr[rsp+r11+offset],rax/eax/ax/al 376 op_mov_MR_ex(varSize,REG_RAX,REG_RSP,REG_R11,(int)pRelative->offset,USE_OFFSET);378 compiler.codeGenerator.op_mov_MR_ex(varSize,REG_RAX,REG_RSP,REG_R11,(int)pRelative->offset,USE_OFFSET); 377 379 obp-=sizeof(long); 378 380 AddLocalVarAddrSchedule(); … … 381 383 else{ 382 384 //mov ptr[rsp+offset],rax/eax/ax/al 383 op_mov_MR(varSize,REG_RAX,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32);385 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32); 384 386 obp-=sizeof(long); 385 387 AddLocalVarAddrSchedule(); … … 390 392 if(pRelative->bOffsetOffset){ 391 393 //add r11,qword ptr[rsp+offset] 392 op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (int)pRelative->offset, MOD_BASE_DISP32 );394 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_RSP, (int)pRelative->offset, MOD_BASE_DISP32 ); 393 395 obp-=sizeof(long); 394 396 AddLocalVarAddrSchedule(); … … 397 399 else{ 398 400 //mov r11,qword ptr[rsp+offset] 399 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32);401 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelative->offset,MOD_BASE_DISP32); 400 402 obp-=sizeof(long); 401 403 AddLocalVarAddrSchedule(); … … 409 411 410 412 //mov ptr[r11],rax/eax/ax/al 411 op_mov_MR(varSize,REG_RAX,REG_R11,0,MOD_BASE);412 } 413 } 413 compiler.codeGenerator.op_mov_MR(varSize,REG_RAX,REG_R11,0,MOD_BASE); 414 } 415 } -
trunk/abdev/BasicCompiler64/Compile_Statement.cpp
r224 r226 113 113 if( resultType.IsStruct() ){ 114 114 //mov r14,rax 115 op_mov_RR(REG_R14,REG_RAX);115 compiler.codeGenerator.op_mov_RR(REG_R14,REG_RAX); 116 116 117 117 FreeTempObject(REG_R14,&resultType.GetClass()); … … 166 166 167 167 //cmp rax,0 168 op_cmp_value(resultType.GetSize(),REG_RAX,0);168 compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0); 169 169 } 170 170 } … … 421 421 422 422 //cmp rax,0 423 op_cmp_value(resultType.GetSize(),REG_RAX,0);423 compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0); 424 424 425 425 //je [カウンタ減少の場合の判定] … … 451 451 452 452 //cmp rax,0 453 op_cmp_value(resultType.GetSize(),REG_RAX,0);453 compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0); 454 454 455 455 ErrorStep: … … 761 761 if(reg2!=REG_RDX){ 762 762 //mov rdx,reg2 763 op_mov_RR(REG_RDX,reg2);763 compiler.codeGenerator.op_mov_RR(REG_RDX,reg2); 764 764 } 765 765 … … 768 768 769 769 //call operator_proc ※ ==演算子 770 op_call(pUserProc);770 compiler.codeGenerator.op_call(pUserProc); 771 771 772 772 //test rax,rax 773 op_test(REG_RAX,REG_RAX);773 compiler.codeGenerator.op_test(REG_RAX,REG_RAX); 774 774 775 775 //jne ... … … 788 788 789 789 //comiss xmm_reg1,xmm_reg2 790 op_comisd(xmm_reg,REG_XMM4);790 compiler.codeGenerator.op_comisd(xmm_reg,REG_XMM4); 791 791 } 792 792 else if(type1.IsSingle()){ … … 800 800 801 801 //comiss xmm_reg1,xmm_reg2 802 op_comiss(xmm_reg,REG_XMM4);802 compiler.codeGenerator.op_comiss(xmm_reg,REG_XMM4); 803 803 } 804 804 else{ … … 811 811 812 812 //cmp reg2,r14 813 op_cmp_reg(GetTypeSize(i2,-1),reg2,REG_R14);813 compiler.codeGenerator.op_cmp_reg(GetTypeSize(i2,-1),reg2,REG_R14); 814 814 } 815 815 … … 893 893 //call _System_GetEip 894 894 extern const UserProc *pSub_System_GetEip; 895 op_call(pSub_System_GetEip);895 compiler.codeGenerator.op_call(pSub_System_GetEip); 896 896 897 897 //add rax,offset(Gosubステートメントの最終ポイント) 898 898 int schedule=obp,schedule2; 899 op_add_RV(REG_RAX,0);899 compiler.codeGenerator.op_add_RV(REG_RAX,0); 900 900 schedule2=obp-sizeof(long); 901 901 … … 1032 1032 1033 1033 //movsd qword ptr[reg_ptr],xmm0 1034 op_movsd_MR(REG_XMM0,reg_ptr,0,MOD_BASE);1034 compiler.codeGenerator.op_movsd_MR(REG_XMM0,reg_ptr,0,MOD_BASE); 1035 1035 } 1036 1036 else if(type==DEF_SINGLE){ … … 1038 1038 1039 1039 //movss dword ptr[reg_ptr],xmm0 1040 op_movss_MR(REG_XMM0,reg_ptr,0,MOD_BASE);1040 compiler.codeGenerator.op_movss_MR(REG_XMM0,reg_ptr,0,MOD_BASE); 1041 1041 } 1042 1042 else{ … … 1044 1044 1045 1045 //mov ptr[reg_ptr],rcx 1046 op_mov_MR(GetTypeSize(type,-1),REG_RCX,reg_ptr,0,MOD_BASE);1047 } 1048 } 1046 compiler.codeGenerator.op_mov_MR(GetTypeSize(type,-1),REG_RCX,reg_ptr,0,MOD_BASE); 1047 } 1048 } -
trunk/abdev/BasicCompiler64/Compile_Var.cpp
r224 r226 54 54 if(typeSize>=2){ 55 55 //imul reg,i2 56 op_imul_RV(sizeof(_int64),reg,typeSize);56 compiler.codeGenerator.op_imul_RV(sizeof(_int64),reg,typeSize); 57 57 } 58 58 } … … 72 72 73 73 //add r11,reg 74 op_add64_reg(REG_R11,reg);74 compiler.codeGenerator.op_add64_reg(REG_R11,reg); 75 75 } 76 76 void SetRelativeOffset( RELATIVE_VAR &relativeVar ){ 77 77 if(relativeVar.dwKind==VAR_DIRECTMEM){ 78 78 //mov r11,qword ptr[r11] 79 op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE);79 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE); 80 80 } 81 81 else{ … … 85 85 86 86 //mov r11,qword ptr[r12] 87 op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);87 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE); 88 88 } 89 89 } … … 139 139 140 140 //xor r12,r12 141 op_zero_reg(REG_R12);141 compiler.codeGenerator.op_zero_reg(REG_R12); 142 142 143 143 for(i=i3-1;i>=0;i--){ … … 173 173 174 174 //imul reg,i4 175 op_imul_RV(sizeof(_int64),reg,i4);175 compiler.codeGenerator.op_imul_RV(sizeof(_int64),reg,i4); 176 176 177 177 //add r12,reg 178 op_add64_reg(REG_R12,reg);178 compiler.codeGenerator.op_add64_reg(REG_R12,reg); 179 179 180 180 HeapDefaultFree(pParm[i]); … … 352 352 353 353 //mov r11,qword ptr[r11] 354 op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE);354 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R11,0,MOD_BASE); 355 355 } 356 356 else{ … … 652 652 //xor r11,r11(r11を0に初期化する) 653 653 //※r11は変数ベースアドレスからの相対オフセットを示す 654 op_zero_reg(REG_R11);654 compiler.codeGenerator.op_zero_reg(REG_R11); 655 655 656 656 pRelativeVar->bOffsetOffset=1; … … 701 701 702 702 //mov r11,qword ptr[r12] 703 op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);703 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE); 704 704 } 705 705 } … … 721 721 722 722 //mov r11,qword ptr[r12] 723 op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE);723 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_R12,0,MOD_BASE); 724 724 } 725 725 else{ … … 872 872 873 873 //mov rax,DataPos 874 op_mov_RV(sizeof(_int64),REG_RAX,i2);874 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,i2); 875 875 obp-=sizeof(long); 876 876 pobj_DataTableSchedule->add(); … … 878 878 879 879 //mov qword ptr[offset],rax 880 op_mov_MR(sizeof(_int64),REG_RAX,0,offset,MOD_DISP32);880 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,0,offset,MOD_DISP32); 881 881 obp-=sizeof(long); 882 882 pobj_GlobalVarSchedule->add(); … … 1002 1002 1003 1003 //mov rax,i64data 1004 op_mov64_ToReg(REG_RAX,i64data);1004 compiler.codeGenerator.op_mov64_ToReg(REG_RAX,i64data); 1005 1005 1006 1006 //mov qword ptr[rsp+offset],rax 1007 op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32);1007 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32); 1008 1008 obp-=sizeof(long); 1009 1009 AddLocalVarAddrSchedule(); … … 1015 1015 1016 1016 //mov dword ptr[rsp+offset],value 1017 op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,*(int *)&flt);1017 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,*(int *)&flt); 1018 1018 obp-=sizeof(long)+sizeof(long); 1019 1019 AddLocalVarAddrSchedule(); … … 1030 1030 1031 1031 //mov rax,i2 1032 op_mov_RV(sizeof(_int64),REG_RAX,i2);1032 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RAX,i2); 1033 1033 obp-=sizeof(long); 1034 1034 pobj_DataTableSchedule->add(); … … 1036 1036 1037 1037 //mov qword ptr[rsp+offset],rax 1038 op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32);1038 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32); 1039 1039 obp-=sizeof(long); 1040 1040 AddLocalVarAddrSchedule(); … … 1044 1044 if(i64data&0xFFFFFFFF00000000){ 1045 1045 //mov rax,i64data 1046 op_mov64_ToReg(REG_RAX,i64data);1046 compiler.codeGenerator.op_mov64_ToReg(REG_RAX,i64data); 1047 1047 1048 1048 //mov qword ptr[rsp+offset],rax 1049 op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32);1049 compiler.codeGenerator.op_mov_MR(sizeof(_int64),REG_RAX,REG_RSP,offset,MOD_BASE_DISP32); 1050 1050 obp-=sizeof(long); 1051 1051 AddLocalVarAddrSchedule(); … … 1054 1054 else{ 1055 1055 //mov qword ptr[rsp+offset],value 1056 op_mov_MV(sizeof(_int64),REG_RSP,offset,USE_OFFSET,(int)i64data);1056 compiler.codeGenerator.op_mov_MV(sizeof(_int64),REG_RSP,offset,USE_OFFSET,(int)i64data); 1057 1057 obp-=sizeof(long)+sizeof(long); 1058 1058 AddLocalVarAddrSchedule(); … … 1063 1063 else if( type.IsDWord() || type.IsLong() ){ 1064 1064 //mov dword ptr[rsp+offset],value 1065 op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,(int)i64data);1065 compiler.codeGenerator.op_mov_MV(sizeof(long),REG_RSP,offset,USE_OFFSET,(int)i64data); 1066 1066 obp-=sizeof(long)+sizeof(long); 1067 1067 AddLocalVarAddrSchedule(); … … 1070 1070 else if( type.IsWord() || type.IsInteger() ){ 1071 1071 //mov word ptr[rsp+offset],value 1072 op_mov_MV(sizeof(short),REG_RSP,offset,USE_OFFSET,(int)i64data);1072 compiler.codeGenerator.op_mov_MV(sizeof(short),REG_RSP,offset,USE_OFFSET,(int)i64data); 1073 1073 obp-=sizeof(long)+sizeof(short); 1074 1074 AddLocalVarAddrSchedule(); … … 1077 1077 else if( type.IsSByte() || type.IsByte() || type.IsBoolean() ){ 1078 1078 //mov byte ptr[rsp+offset],value 1079 op_mov_MV(sizeof(char),REG_RSP,offset,USE_OFFSET,(int)i64data);1079 compiler.codeGenerator.op_mov_MV(sizeof(char),REG_RSP,offset,USE_OFFSET,(int)i64data); 1080 1080 obp-=sizeof(long)+sizeof(char); 1081 1081 AddLocalVarAddrSchedule(); … … 1182 1182 1183 1183 //mov r8, 0 1184 op_zero_reg( REG_R8 );1184 compiler.codeGenerator.op_zero_reg( REG_R8 ); 1185 1185 1186 1186 //mov rdx, VarSize 1187 op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() );1187 compiler.codeGenerator.op_mov_RV( sizeof(_int64), REG_RDX, pVar->GetMemorySize() ); 1188 1188 1189 1189 //mov rcx, rsp 1190 op_mov_RR( REG_RCX, REG_RSP );1190 compiler.codeGenerator.op_mov_RR( REG_RCX, REG_RSP ); 1191 1191 1192 1192 //add rcx, offset 1193 op_add_RV( REG_RCX, -pVar->GetOffsetAddress() );1193 compiler.codeGenerator.op_add_RV( REG_RCX, -pVar->GetOffsetAddress() ); 1194 1194 obp-=sizeof(long); 1195 1195 AddLocalVarAddrSchedule(); … … 1199 1199 DllProc *pDllProc; 1200 1200 pDllProc=GetDeclareHash("FillMemory"); 1201 op_call( pDllProc );1201 compiler.codeGenerator.op_call( pDllProc ); 1202 1202 } 1203 1203 } … … 1240 1240 1241 1241 //mov reg,r11 1242 op_mov_RR(reg,REG_R11);1242 compiler.codeGenerator.op_mov_RR(reg,REG_R11); 1243 1243 } 1244 1244 else{ 1245 1245 //mov reg,offset 1246 op_mov64_ToReg(reg,(int)pRelativeVar->offset);1246 compiler.codeGenerator.op_mov64_ToReg(reg,(long)pRelativeVar->offset); 1247 1247 obp-=sizeof(long); 1248 1248 pobj_GlobalVarSchedule->add(); … … 1253 1253 if(pRelativeVar->bOffsetOffset){ 1254 1254 //add r11,qword ptr[offset] 1255 op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 );1255 compiler.codeGenerator.op_add_RM( sizeof(_int64), REG_R11, REG_NON, (int)pRelativeVar->offset, MOD_DISP32 ); 1256 1256 obp-=sizeof(long); 1257 1257 pobj_GlobalVarSchedule->add(); … … 1260 1260 else{ 1261 1261 //mov r11,qword ptr[offset] 1262 op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32);1262 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_NON,(int)pRelativeVar->offset,MOD_DISP32); 1263 1263 obp-=sizeof(long); 1264 1264 pobj_GlobalVarSchedule->add(); … … 1279 1279 1280 1280 //add r11,rsp 1281 op_add64_reg(REG_R11,REG_RSP);1281 compiler.codeGenerator.op_add64_reg(REG_R11,REG_RSP); 1282 1282 1283 1283 //mov reg,r11 1284 op_mov_RR(reg,REG_R11);1284 compiler.codeGenerator.op_mov_RR(reg,REG_R11); 1285 1285 } 1286 1286 else{ 1287 1287 //mov reg,rsp 1288 op_mov_RR(reg,REG_RSP);1288 compiler.codeGenerator.op_mov_RR(reg,REG_RSP); 1289 1289 1290 1290 //add reg,offset 1291 op_add_RV(reg,(int)pRelativeVar->offset);1291 compiler.codeGenerator.op_add_RV(reg,(int)pRelativeVar->offset); 1292 1292 obp-=sizeof(long); 1293 1293 AddLocalVarAddrSchedule(); … … 1308 1308 else{ 1309 1309 //mov r11,qword ptr[rsp+offset] 1310 op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32);1310 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_R11,REG_RSP,(int)pRelativeVar->offset,MOD_BASE_DISP32); 1311 1311 obp-=sizeof(long); 1312 1312 AddLocalVarAddrSchedule(); … … 1319 1319 directmem: 1320 1320 //mov reg,r11 1321 op_mov_RR(reg,REG_R11);1321 compiler.codeGenerator.op_mov_RR(reg,REG_R11); 1322 1322 } 1323 1323 } … … 1337 1337 // 変数領域に要するLONG_PTR単位の個数を引き渡す 1338 1338 //mov r8,count 1339 op_mov_RV(sizeof(_int64), REG_R8,pVar->GetMemorySize()/PTR_SIZE);1339 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_R8,pVar->GetMemorySize()/PTR_SIZE); 1340 1340 1341 1341 // ルートポインタを引き渡す 1342 1342 //mov rdx,offset 1343 op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar->GetOffsetAddress());1343 compiler.codeGenerator.op_mov_RV(sizeof(_int64), REG_RDX,(int)pVar->GetOffsetAddress()); 1344 1344 obp-=sizeof(long); 1345 1345 pobj_GlobalVarSchedule->add(); … … 1350 1350 1351 1351 // call AddGlobalRootPtr 1352 op_call( pUserProc_AddGlobalRootPtr );1352 compiler.codeGenerator.op_call( pUserProc_AddGlobalRootPtr ); 1353 1353 1354 1354 ReallocNativeCodeBuffer(); -
trunk/abdev/BasicCompiler64/MakePeHdr.cpp
r224 r226 391 391 pobj_sf=new CStackFrame(); 392 392 393 // コード生成対象を選択 394 compiler.codeGenerator.Select( compiler.globalNativeCode ); 395 393 396 trace_for_sourcecodestep( "★★★ グローバル領域のコンパイルを開始" ); 394 397 … … 399 402 //sub rsp,スタックフレームサイズ 400 403 int StackFrameSchedule; 401 op_sub_rsp(0xFFFFFFFF);404 compiler.codeGenerator.op_sub_rsp(0xFFFFFFFF); 402 405 StackFrameSchedule=obp-sizeof(long); 403 406 … … 411 414 412 415 //_System_StartupProgramの呼び出し 413 op_call(pSub_System_StartupProgram);416 compiler.codeGenerator.op_call(pSub_System_StartupProgram); 414 417 415 418 //クラスに属する静的メンバを定義 … … 445 448 //call _System_Call_Destructor_of_GlobalObject 446 449 extern const UserProc *pSub_System_Call_Destructor_of_GlobalObject; 447 op_call(pSub_System_Call_Destructor_of_GlobalObject);450 compiler.codeGenerator.op_call(pSub_System_Call_Destructor_of_GlobalObject); 448 451 449 452 450 453 //add rsp,スタックフレームサイズ 451 454 int stackFrameSize = pobj_sf->GetFrameSize(0); 452 op_add_RV( REG_RSP, stackFrameSize );455 compiler.codeGenerator.op_add_RV( REG_RSP, stackFrameSize ); 453 456 454 457 //xor rax,rax(raxを0に初期化する) 455 op_zero_reg(REG_RAX);458 compiler.codeGenerator.op_zero_reg(REG_RAX); 456 459 457 460 //ret 458 op_ret();461 compiler.codeGenerator.op_ret(); 459 462 460 463 //グローバル実行領域のコードサイズ -
trunk/abdev/BasicCompiler64/NumOpe.cpp
r224 r226 30 30 31 31 //mov reg,rax 32 op_mov_RR( reg, REG_RAX );32 compiler.codeGenerator.op_mov_RR( reg, REG_RAX ); 33 33 34 34 ///////////////////////////////////////////// … … 54 54 if(type==DEF_DOUBLE){ 55 55 //movsd xmm_reg,xmm0 56 op_movsd_RR(XmmReg,REG_XMM0);56 compiler.codeGenerator.op_movsd_RR(XmmReg,REG_XMM0); 57 57 } 58 58 else if(type==DEF_SINGLE){ 59 59 //movss xmm_reg,xmm0 60 op_movss_RR(XmmReg,REG_XMM0);60 compiler.codeGenerator.op_movss_RR(XmmReg,REG_XMM0); 61 61 } 62 62 } … … 70 70 else{ 71 71 //mov reg,rax 72 op_mov_RR(UseReg,REG_RAX);72 compiler.codeGenerator.op_mov_RR(UseReg,REG_RAX); 73 73 } 74 74 } … … 142 142 143 143 //オブジェクトポインタをr11にコピー 144 op_mov_RR( REG_R11, UseReg );144 compiler.codeGenerator.op_mov_RR( REG_R11, UseReg ); 145 145 146 146 RELATIVE_VAR relativeVar; … … 555 555 556 556 //mov reg,rax 557 op_mov_RR( *pReg, REG_RAX );557 compiler.codeGenerator.op_mov_RR( *pReg, REG_RAX ); 558 558 559 559 return true; … … 603 603 604 604 //mov reg,i2 605 op_mov_RV(sizeof(_int64),*pReg,i2);605 compiler.codeGenerator.op_mov_RV(sizeof(_int64),*pReg,i2); 606 606 obp-=sizeof(long); 607 607 pobj_DataTableSchedule->add(); … … 796 796 797 797 //mov reg,i2 798 op_mov_RV(sizeof(_int64),UseReg,i2);798 compiler.codeGenerator.op_mov_RV(sizeof(_int64),UseReg,i2); 799 799 obp-=sizeof(long); 800 800 pobj_DataTableSchedule->add(); … … 895 895 896 896 //xor reg,reg 897 op_zero_reg( UseReg );897 compiler.codeGenerator.op_zero_reg( UseReg ); 898 898 899 899 if(UseReg==REG_R14){ … … 971 971 if(XmmReg==REG_XMM4){ 972 972 //mov r14,i64data 973 op_mov64_ToReg(REG_R14,i64data);973 compiler.codeGenerator.op_mov64_ToReg(REG_R14,i64data); 974 974 975 975 … … 1004 1004 SetError(); // TODO: 未実装 1005 1005 //push term 1006 op_push_value(i32data);1006 //compiler.codeGenerator.op_push_value(i32data); 1007 1007 } 1008 1008 else{ … … 1026 1026 1027 1027 //mov reg,i64data 1028 op_mov64_ToReg(UseReg,i64data);1028 compiler.codeGenerator.op_mov64_ToReg(UseReg,i64data); 1029 1029 1030 1030 if(UseReg==REG_R14){ … … 1194 1194 1195 1195 //mov reg,i64data 1196 op_mov64_ToReg(UseReg,i64data);1196 compiler.codeGenerator.op_mov64_ToReg(UseReg,i64data); 1197 1197 } 1198 1198 -
trunk/abdev/BasicCompiler64/NumOpe_Arithmetic.cpp
r224 r226 104 104 if(idCalc==CALC_ADDITION){ 105 105 //add reg1,reg2 106 op_add64_reg(reg1,reg2);106 compiler.codeGenerator.op_add64_reg(reg1,reg2); 107 107 } 108 108 else if(idCalc==CALC_SUBTRACTION){ 109 109 //sub reg1,reg2 110 op_sub64_reg(reg1,reg2);110 compiler.codeGenerator.op_sub64_reg(reg1,reg2); 111 111 } 112 112 else if(idCalc==CALC_PRODUCT){ 113 113 //mul reg1,reg2 114 op_imul_RR(sizeof(_int64),reg1,reg2);114 compiler.codeGenerator.op_imul_RR(sizeof(_int64),reg1,reg2); 115 115 } 116 116 … … 127 127 if(idCalc==CALC_ADDITION){ 128 128 //add reg1,reg2 129 op_add32_reg(reg1,reg2);129 compiler.codeGenerator.op_add32_reg(reg1,reg2); 130 130 } 131 131 else if(idCalc==CALC_SUBTRACTION){ 132 132 //sub reg1,reg2 133 op_sub32_reg(reg1,reg2);133 compiler.codeGenerator.op_sub32_reg(reg1,reg2); 134 134 } 135 135 else if(idCalc==CALC_PRODUCT){ 136 136 //mul reg1,reg2 137 op_imul_RR(sizeof(long),reg1,reg2);137 compiler.codeGenerator.op_imul_RR(sizeof(long),reg1,reg2); 138 138 } 139 139 … … 181 181 if(reg2==REG_RAX||reg2==REG_RDX){ 182 182 //mov r15,reg2 183 op_mov_RR(REG_R15,reg2);183 compiler.codeGenerator.op_mov_RR(REG_R15,reg2); 184 184 185 185 reg2=REG_R15; … … 207 207 208 208 //mov rax,reg1 209 op_mov_RR(REG_RAX,reg1);209 compiler.codeGenerator.op_mov_RR(REG_RAX,reg1); 210 210 211 211 if(IsSignedType(type[sp-2])){ … … 222 222 223 223 //xor rdx,rdx 224 op_zero_reg(REG_RDX);224 compiler.codeGenerator.op_zero_reg(REG_RDX); 225 225 } 226 226 227 227 if(IsSignedType(AnswerType)){ 228 228 //idiv reg2 229 op_idiv64_reg(reg2);229 compiler.codeGenerator.op_idiv64_reg(reg2); 230 230 } 231 231 else{ 232 232 //div reg2 233 op_div64_reg(reg2);233 compiler.codeGenerator.op_div64_reg(reg2); 234 234 } 235 235 236 236 //mov reg1,rdx 237 op_mov_RR(reg1,REG_RDX);237 compiler.codeGenerator.op_mov_RR(reg1,REG_RDX); 238 238 239 239 } … … 357 357 if(reg2==REG_RAX||reg2==REG_RDX){ 358 358 //mov r15,reg2 359 op_mov_RR(REG_R15,reg2);359 compiler.codeGenerator.op_mov_RR(REG_R15,reg2); 360 360 361 361 reg2=REG_R15; … … 383 383 384 384 //mov rax,reg1 385 op_mov_RR(REG_RAX,reg1);385 compiler.codeGenerator.op_mov_RR(REG_RAX,reg1); 386 386 387 387 if(IsSignedType(type[sp-2])){ … … 398 398 399 399 //xor rdx,rdx 400 op_zero_reg(REG_RDX);400 compiler.codeGenerator.op_zero_reg(REG_RDX); 401 401 } 402 402 403 403 if(IsSignedType(AnswerType)){ 404 404 //idiv reg2 405 op_idiv64_reg(reg2);405 compiler.codeGenerator.op_idiv64_reg(reg2); 406 406 } 407 407 else{ 408 408 //div reg2 409 op_div64_reg(reg2);409 compiler.codeGenerator.op_div64_reg(reg2); 410 410 } 411 411 412 412 //mov reg1,rax 413 op_mov_RR(reg1,REG_RAX);413 compiler.codeGenerator.op_mov_RR(reg1,REG_RAX); 414 414 415 415 } … … 499 499 500 500 //imul reg,-1 501 op_imul_RV(sizeof(_int64),reg,-1);501 compiler.codeGenerator.op_imul_RV(sizeof(_int64),reg,-1); 502 502 503 503 if(reg==REG_R14){ … … 512 512 513 513 //imul reg,-1 514 op_imul_RV(sizeof(long),reg,-1);514 compiler.codeGenerator.op_imul_RV(sizeof(long),reg,-1); 515 515 516 516 if(reg==REG_R14){ … … 549 549 if(xmm_reg1==REG_XMM1){ 550 550 //movsd xmm0,xmm_reg1 551 op_movsd_RR(REG_XMM0,xmm_reg1);551 compiler.codeGenerator.op_movsd_RR(REG_XMM0,xmm_reg1); 552 552 553 553 //movsd xmm1,xmm_reg2 554 op_movsd_RR(REG_XMM1,xmm_reg2);554 compiler.codeGenerator.op_movsd_RR(REG_XMM1,xmm_reg2); 555 555 } 556 556 else{ 557 557 //movsd xmm1,xmm_reg2 558 op_movsd_RR(REG_XMM1,xmm_reg2);558 compiler.codeGenerator.op_movsd_RR(REG_XMM1,xmm_reg2); 559 559 560 560 //movsd xmm0,xmm_reg1 561 op_movsd_RR(REG_XMM0,xmm_reg1);561 compiler.codeGenerator.op_movsd_RR(REG_XMM0,xmm_reg1); 562 562 } 563 563 564 564 //call pow 565 565 extern const UserProc *pSub_pow; 566 op_call(pSub_pow);566 compiler.codeGenerator.op_call(pSub_pow); 567 567 568 568 //movsd xmm4,xmm0 569 op_movsd_RR(REG_XMM4,REG_XMM0);569 compiler.codeGenerator.op_movsd_RR(REG_XMM4,REG_XMM0); 570 570 571 571 … … 586 586 else{ 587 587 //movsd xmm_reg1,xmm4 588 op_movsd_RR(xmm_reg1,REG_XMM4);588 compiler.codeGenerator.op_movsd_RR(xmm_reg1,REG_XMM4); 589 589 } 590 590 … … 621 621 if(reg1==REG_RCX){ 622 622 //mov r15,rcx 623 op_mov_RR(REG_R15,REG_RCX);623 compiler.codeGenerator.op_mov_RR(REG_R15,REG_RCX); 624 624 625 625 reg1=REG_R15; … … 633 633 634 634 //mov rcx,reg2 635 op_mov_RR(REG_RCX,reg2);635 compiler.codeGenerator.op_mov_RR(REG_RCX,reg2); 636 636 637 637 if(idCalc==CALC_SHL){ … … 647 647 648 648 //shl reg1,cl 649 op_shl_reg(GetTypeSize(type[sp-2],-1),reg1);649 compiler.codeGenerator.op_shl_reg(GetTypeSize(type[sp-2],-1),reg1); 650 650 } 651 651 else if(idCalc==CALC_SHR){ … … 654 654 655 655 //sar 656 op_sar_reg(GetTypeSize(type[sp-2],-1),reg1);656 compiler.codeGenerator.op_sar_reg(GetTypeSize(type[sp-2],-1),reg1); 657 657 } 658 658 else{ … … 660 660 661 661 //shr 662 op_shr_reg(GetTypeSize(type[sp-2],-1),reg1);662 compiler.codeGenerator.op_shr_reg(GetTypeSize(type[sp-2],-1),reg1); 663 663 } 664 664 } … … 666 666 if(sw==0){ 667 667 //mov rcx,r15 668 op_mov_RR(REG_RCX,REG_R15);668 compiler.codeGenerator.op_mov_RR(REG_RCX,REG_R15); 669 669 } 670 670 else{ -
trunk/abdev/BasicCompiler64/NumOpe_Logical.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 28 30 if(idCalc==CALC_XOR){ 29 31 //xor reg1,reg2 30 op_xor_reg(sizeof(_int64),reg1,reg2);32 compiler.codeGenerator.op_xor_reg(sizeof(_int64),reg1,reg2); 31 33 } 32 34 else if(idCalc==CALC_OR){ 33 35 //or reg1,reg2 34 op_or_reg(sizeof(_int64),reg1,reg2);36 compiler.codeGenerator.op_or_reg(sizeof(_int64),reg1,reg2); 35 37 } 36 38 else if(idCalc==CALC_AND){ 37 39 //and reg1,reg2 38 op_and_reg(sizeof(_int64),reg1,reg2);40 compiler.codeGenerator.op_and_reg(sizeof(_int64),reg1,reg2); 39 41 } 40 42 … … 54 56 if(idCalc==CALC_ADDITION){ 55 57 //add reg1,reg2 56 op_xor_reg(sizeof(long),reg1,reg2);58 compiler.codeGenerator.op_xor_reg(sizeof(long),reg1,reg2); 57 59 } 58 60 else if(idCalc==CALC_OR){ 59 61 //or reg1,reg2 60 op_or_reg(sizeof(long),reg1,reg2);62 compiler.codeGenerator.op_or_reg(sizeof(long),reg1,reg2); 61 63 } 62 64 else if(idCalc==CALC_AND){ 63 65 //and reg1,reg2 64 op_and_reg(sizeof(long),reg1,reg2);66 compiler.codeGenerator.op_and_reg(sizeof(long),reg1,reg2); 65 67 } 66 68 … … 99 101 100 102 //cmp reg,0 101 op_cmp_value(GetTypeSize(type[sp-1],-1),reg,0);103 compiler.codeGenerator.op_cmp_value(GetTypeSize(type[sp-1],-1),reg,0); 102 104 103 105 //setne al 104 op_setne( REG_RAX );106 compiler.codeGenerator.op_setne( REG_RAX ); 105 107 106 108 //and rax,000000FFh 107 op_and64_value(REG_RAX,(int)0xFF);109 compiler.codeGenerator.op_and64_value(REG_RAX,(int)0xFF); 108 110 109 111 //neg 110 op_neg( REG_RAX );112 compiler.codeGenerator.op_neg( REG_RAX ); 111 113 112 114 //sbb rax, rax 113 op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX );115 compiler.codeGenerator.op_sbb_RR( sizeof(_int64), REG_RAX, REG_RAX ); 114 116 115 117 //add rax, 1 116 op_add_RV( REG_RAX, 1 );118 compiler.codeGenerator.op_add_RV( REG_RAX, 1 ); 117 119 118 120 if( reg != REG_RAX ){ 119 121 //mov reg,rax 120 op_mov_RR( reg, REG_RAX );122 compiler.codeGenerator.op_mov_RR( reg, REG_RAX ); 121 123 122 124 //mov qword ptr[rsp+offset],rax ※スタックフレームを利用 … … 133 135 134 136 //not reg 135 op_not_reg(sizeof(_int64),reg);137 compiler.codeGenerator.op_not_reg(sizeof(_int64),reg); 136 138 137 139 if(reg==REG_R14){ … … 144 146 145 147 //not reg 146 op_not_reg(sizeof(long),reg);148 compiler.codeGenerator.op_not_reg(sizeof(long),reg); 147 149 148 150 if(reg==REG_R14){ -
trunk/abdev/BasicCompiler64/NumOpe_Relation.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 24 26 if(AnswerType==DEF_DOUBLE){ 25 27 //comisd xmm_reg1,xmm_reg2 26 op_comisd(xmm_reg1,xmm_reg2);28 compiler.codeGenerator.op_comisd(xmm_reg1,xmm_reg2); 27 29 } 28 30 else if(AnswerType==DEF_SINGLE){ 29 31 //comiss xmm_reg1,xmm_reg2 30 op_comiss(xmm_reg1,xmm_reg2);32 compiler.codeGenerator.op_comiss(xmm_reg1,xmm_reg2); 31 33 } 32 34 … … 46 48 47 49 //cmp reg1,reg2 48 op_cmp_reg(sizeof(_int64),reg1,reg2);50 compiler.codeGenerator.op_cmp_reg(sizeof(_int64),reg1,reg2); 49 51 } 50 52 else{ … … 57 59 58 60 //cmp reg1,reg2 59 op_cmp_reg(sizeof(long),reg1,reg2);61 compiler.codeGenerator.op_cmp_reg(sizeof(long),reg1,reg2); 60 62 } 61 63 … … 137 139 138 140 //xor reg1,reg1 139 op_zero_reg(reg1);141 compiler.codeGenerator.op_zero_reg(reg1); 140 142 141 143 //jmp 7(次のmovを飛び越す) … … 149 151 150 152 //mov reg1,1 151 op_mov_RV(sizeof(_int64),reg1,1);153 compiler.codeGenerator.op_mov_RV(sizeof(_int64),reg1,1); 152 154 153 155 -
trunk/abdev/BasicCompiler64/NumOpe_TypeOperation.cpp
r224 r226 11 11 if(type==DEF_LONG){ 12 12 //movsxd reg64,reg32 13 op_movsxd(reg,reg);13 compiler.codeGenerator.op_movsxd(reg,reg); 14 14 } 15 15 else if(type==DEF_DWORD){ … … 18 18 else if(type==DEF_INTEGER || (Smoothie::IsUnicode()&&type==DEF_CHAR)){ 19 19 //movsx reg64,reg16 20 op_movsx64_FromReg16(reg,reg);20 compiler.codeGenerator.op_movsx64_FromReg16(reg,reg); 21 21 } 22 22 else if(type==DEF_WORD){ 23 23 //and reg,000000000000FFFFh 24 op_and64_value(reg,(int)0xFFFF);24 compiler.codeGenerator.op_and64_value(reg,(int)0xFFFF); 25 25 } 26 26 else if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){ 27 27 //movsx reg64,reg8 28 op_movsx64_FromReg8(reg,reg);28 compiler.codeGenerator.op_movsx64_FromReg8(reg,reg); 29 29 } 30 30 else if(type==DEF_BYTE || type==DEF_BOOLEAN){ 31 31 //and reg,00000000000000FFh 32 op_and64_value(reg,(int)0x00FF);32 compiler.codeGenerator.op_and64_value(reg,(int)0x00FF); 33 33 } 34 34 } … … 36 36 if(type==DEF_INTEGER || (Smoothie::IsUnicode()&&type==DEF_CHAR)){ 37 37 //movsx reg32,reg16 38 op_movsx32_FromReg16(reg,reg);38 compiler.codeGenerator.op_movsx32_FromReg16(reg,reg); 39 39 } 40 40 else if(type==DEF_WORD){ 41 41 //and reg,0000FFFFh 42 op_and32_value(reg,(int)0xFFFF);42 compiler.codeGenerator.op_and32_value(reg,(int)0xFFFF); 43 43 } 44 44 else if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){ 45 45 //movsx reg32,reg8 46 op_movsx32_FromReg8(reg,reg);46 compiler.codeGenerator.op_movsx32_FromReg8(reg,reg); 47 47 } 48 48 else if(type==DEF_BYTE || type==DEF_BOOLEAN){ 49 49 //and reg,000000FFh 50 op_and32_value(reg,(int)0xFF);50 compiler.codeGenerator.op_and32_value(reg,(int)0xFF); 51 51 } 52 52 } … … 54 54 if(type==DEF_SBYTE || (Smoothie::IsUnicode()==false&&type==DEF_CHAR)){ 55 55 //movsx reg16,reg8 56 op_movsx16_FromReg8(reg,reg);56 compiler.codeGenerator.op_movsx16_FromReg8(reg,reg); 57 57 } 58 58 else if(type==DEF_BYTE){ 59 59 //and reg,000000FFh 60 op_and32_value(reg,(int)0xFF);60 compiler.codeGenerator.op_and32_value(reg,(int)0xFF); 61 61 } 62 62 } … … 70 70 71 71 //cvtss2sd 72 op_cvtss2sd(xmm_reg,xmm_reg);72 compiler.codeGenerator.op_cvtss2sd(xmm_reg,xmm_reg); 73 73 } 74 74 else if(Is64Type(type)){ … … 76 76 77 77 //cvtsi2sd xmm_reg,reg 78 op_cvtsi2sd_reg(sizeof(_int64),xmm_reg,general_reg);78 compiler.codeGenerator.op_cvtsi2sd_reg(sizeof(_int64),xmm_reg,general_reg); 79 79 80 80 if(type==DEF_QWORD){ … … 82 82 83 83 //test reg,reg 84 op_test(general_reg,general_reg);84 compiler.codeGenerator.op_test(general_reg,general_reg); 85 85 86 86 //jge 9 … … 109 109 110 110 //cvtsi2sd xmm_reg,reg 111 op_cvtsi2sd_reg(sizeof(_int64),xmm_reg,general_reg);111 compiler.codeGenerator.op_cvtsi2sd_reg(sizeof(_int64),xmm_reg,general_reg); 112 112 } 113 113 else{ … … 118 118 119 119 //cvtsi2sd xmm_reg,reg 120 op_cvtsi2sd_reg(sizeof(long),xmm_reg,general_reg);120 compiler.codeGenerator.op_cvtsi2sd_reg(sizeof(long),xmm_reg,general_reg); 121 121 } 122 122 } … … 126 126 127 127 //cvtsd2ss 128 op_cvtsd2ss(xmm_reg,xmm_reg);128 compiler.codeGenerator.op_cvtsd2ss(xmm_reg,xmm_reg); 129 129 } 130 130 else if(type==DEF_SINGLE){ … … 135 135 136 136 //cvtsi2ss xmm_reg,reg 137 op_cvtsi2ss_reg(sizeof(_int64),xmm_reg,general_reg);137 compiler.codeGenerator.op_cvtsi2ss_reg(sizeof(_int64),xmm_reg,general_reg); 138 138 139 139 if(type==DEF_QWORD){ … … 141 141 142 142 //test reg,reg 143 op_test(general_reg,general_reg);143 compiler.codeGenerator.op_test(general_reg,general_reg); 144 144 145 145 //jge 9 … … 168 168 169 169 //cvtsi2ss xmm_reg,reg 170 op_cvtsi2ss_reg(sizeof(_int64),xmm_reg,general_reg);170 compiler.codeGenerator.op_cvtsi2ss_reg(sizeof(_int64),xmm_reg,general_reg); 171 171 } 172 172 else{ … … 177 177 178 178 //cvtsi2ss xmm_reg,reg 179 op_cvtsi2ss_reg(sizeof(long),xmm_reg,general_reg);179 compiler.codeGenerator.op_cvtsi2ss_reg(sizeof(long),xmm_reg,general_reg); 180 180 } 181 181 } … … 185 185 if(Is64Type(NewType)){ 186 186 //cvttsd2si reg,xmm_reg 187 op_cvttsd2si_xmm(sizeof(_int64),reg,xmm_reg);187 compiler.codeGenerator.op_cvttsd2si_xmm(sizeof(_int64),reg,xmm_reg); 188 188 } 189 189 else{ 190 190 //cvttsd2si reg,xmm_reg 191 op_cvttsd2si_xmm(sizeof(long),reg,xmm_reg);191 compiler.codeGenerator.op_cvttsd2si_xmm(sizeof(long),reg,xmm_reg); 192 192 } 193 193 } … … 195 195 if(Is64Type(NewType)){ 196 196 //cvttss2si reg,xmm_reg 197 op_cvttss2si_xmm(sizeof(_int64),reg,xmm_reg);197 compiler.codeGenerator.op_cvttss2si_xmm(sizeof(_int64),reg,xmm_reg); 198 198 } 199 199 else{ 200 200 //cvttss2si reg,xmm_reg 201 op_cvttss2si_xmm(sizeof(long),reg,xmm_reg);201 compiler.codeGenerator.op_cvttss2si_xmm(sizeof(long),reg,xmm_reg); 202 202 } 203 203 } -
trunk/abdev/BasicCompiler64/Opcode.h
r220 r226 3 3 #include <Type.h> 4 4 #include <Procedure.h> 5 6 7 //レジスタを示す定数 8 #define REG_EAX 1 9 #define REG_EBX 2 10 #define REG_ECX 3 11 #define REG_EDX 4 12 #define REG_ESP 5 13 #define REG_EBP 6 14 15 #define REGISTER_OPERAND(reg) (reg&0x07) 16 17 #define REG_NON -1 18 #define REG_RAX 0x00 //reg:000 19 #define REG_RCX 0x01 //reg:001 20 #define REG_RDX 0x02 //reg:010 21 #define REG_RBX 0x03 //reg:011 22 #define REG_RSP 0x04 //reg:100 23 #define REG_RBP 0x05 //reg:101 24 #define REG_RSI 0x06 //reg:110 25 #define REG_RDI 0x07 //reg:111 26 #define REG_R8 0x08 //reg:000(REXプリフィックス) 27 #define REG_R9 0x09 //reg:001(REXプリフィックス) 28 #define REG_R10 0x0A //reg:010(REXプリフィックス) 29 #define REG_R11 0x0B //reg:011(REXプリフィックス) 30 #define REG_R12 0x0C //reg:100(REXプリフィックス) 31 #define REG_R13 0x0D //reg:101(REXプリフィックス) 32 #define REG_R14 0x0E //reg:110(REXプリフィックス) 33 #define REG_R15 0x0F //reg:111(REXプリフィックス) 34 35 #define REG_XMM0 0x10 //reg:000 36 #define REG_XMM1 0x11 //reg:001 37 #define REG_XMM2 0x12 //reg:010 38 #define REG_XMM3 0x13 //reg:011 39 #define REG_XMM4 0x14 //reg:100 40 #define REG_XMM5 0x15 //reg:101 41 #define REG_XMM6 0x16 //reg:110 42 #define REG_XMM7 0x17 //reg:111 43 #define REG_XMM8 0x18 //reg:000 44 #define REG_XMM9 0x19 //reg:001 45 #define REG_XMM10 0x1A //reg:010 46 #define REG_XMM11 0x1B //reg:011 47 #define REG_XMM12 0x1C //reg:100 48 #define REG_XMM13 0x1D //reg:101 49 #define REG_XMM14 0x1E //reg:110 50 #define REG_XMM15 0x1F //reg:111 51 52 #define IS_XMM_REG(reg) (reg&0x10) 53 5 #include "MachineFixed.h" 54 6 55 7 … … 426 378 427 379 428 429 ////////////////////////////////430 // AMD64機械語生成に利用する関数郡431 ////////////////////////////////432 433 //Mod(モード)434 #define MOD_BASE (char)0x00435 #define MOD_DISP32 (char)0xFF436 #define MOD_BASE_DISP8 (char)0x40437 #define MOD_BASE_DISP32 (char)0x80438 #define MOD_REG (char)0xC0439 440 #define USE_OFFSET 1441 #define NON_OFFSET 0442 443 //amd64_main.cpp444 380 BOOL IsSafeReg(int reg); 445 void op_push(int reg);446 void op_push_value(long data);447 void op_pop(int reg);448 void op_mov_RV (int op_size,int reg,int i32data);449 void op_mov_RV64 (int reg,_int64 i64data);450 void op_mov_RM (int op_size,int reg,int base_reg,int offset,char mod);451 void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);452 void op_mov_MR (int op_size,int reg,int base_reg,int offset,char mod);453 void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset);454 void op_mov_MV (int op_size,int base_reg,int offset,BOOL bUseOffset,int i32data);455 void op_mov_RR (int reg1,int reg2);456 void op_mov64_ToReg (int reg,_int64 i64data);457 void op_mov64_ToReg (int reg,int i32data);458 void op_movsxd (int reg64,int reg32);459 void op_movsx64_FromReg16 (int reg64,int reg16);460 void op_movsx64_FromReg8 (int reg64,int reg8);461 void op_movsx32_FromReg16 (int reg32,int reg16);462 void op_movsx32_FromReg8 (int reg32,int reg8);463 void op_movsx16_FromReg8 (int reg32,int reg8);464 void op_inc (int reg);465 void op_dec (int reg);466 void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod);467 void op_add_RV (int reg,int offset);468 void op_add64_reg (int reg1,int reg2);469 void op_add32_reg (int reg1,int reg2);470 void op_sub_RV (int op_size,int reg,int i32data);471 void op_sub64_reg (int reg1,int reg2);472 void op_sub32_reg (int reg1,int reg2);473 void op_sbb_RR ( int op_size, int reg1, int reg2 );474 void op_imul_RR (int op_size,int reg1,int reg2);475 void op_imul_RV (int op_size,int reg,int i32data);476 void op_div64_reg (int reg);477 void op_idiv64_reg (int reg);478 void op_shl_reg (int op_size,int reg);479 void op_sar_reg (int op_size,int reg);480 void op_shr_reg (int op_size,int reg);481 void op_and_reg (int op_size,int reg1,int reg2);482 void op_and64_value (int reg,int offset);483 void op_and32_value (int reg,int offset);484 void op_or_reg (int op_size,int reg1,int reg2);485 void op_xor_reg (int op_size,int reg1,int reg2);486 void op_not_reg (int op_size,int reg);487 void op_neg ( int reg );488 void op_test (int reg1,int reg2);489 void op_cmp_reg (int op_size,int reg1,int reg2);490 void op_cmp_value (int op_size,int reg,char byte_data);491 void op_setne (int reg);492 void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod);493 void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod);494 void op_movsd_RR (int xmm_reg1,int xmm_reg2);495 void op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod);496 void op_movss_RR (int xmm_reg1,int xmm_reg2);497 void op_movss_RM (int xmm_reg,int base_reg,int offset,char mod);498 void op_movss_MR (int xmm_reg,int base_reg,int offset,char mod);499 void op_movd_RX (int reg,int xmm_reg);500 void op_cvtsd2ss (int xmm_reg1,int xmm_reg2);501 void op_cvtss2sd (int xmm_reg1,int xmm_reg2);502 void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg);503 void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg);504 void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg);505 void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg);506 void op_comisd (int xmm_reg1,int xmm_reg2);507 void op_comiss (int xmm_reg1,int xmm_reg2);508 void op_rep_movs (int op_size);509 void op_add_rsp(int num);510 void op_sub_rsp(int num);511 void op_add_esp(int num);512 void op_sub_esp(int num);513 void op_fld_ptr_esp(int type);514 void op_zero_reg(int reg);515 void op_call( const UserProc *pUserProc );516 void op_call( const DllProc *pDllProc );517 void op_ret(); -
trunk/abdev/BasicCompiler64/OperatorProc.cpp
r206 r226 2 2 3 3 #include <jenga/include/smoothie/LexicalAnalysis.h> 4 5 #include <Compiler.h> 4 6 5 7 #include "../BasicCompiler_Common/common.h" … … 17 19 if( method ){ 18 20 //mov rcx,reg 19 op_mov_RR(REG_RCX,reg);21 compiler.codeGenerator.op_mov_RR(REG_RCX,reg); 20 22 21 23 //call DestructorProcAddr 22 op_call( &method->GetUserProc() );24 compiler.codeGenerator.op_call( &method->GetUserProc() ); 23 25 } 24 26 25 27 //mov rcx,reg 26 op_mov_RR(REG_RCX,reg);28 compiler.codeGenerator.op_mov_RR(REG_RCX,reg); 27 29 28 30 //call free 29 31 extern const UserProc *pSub_free; 30 op_call(pSub_free);32 compiler.codeGenerator.op_call(pSub_free); 31 33 } 32 34 … … 119 121 120 122 //mov rcx,object_size 121 op_mov_RV(sizeof(_int64),REG_RCX,object_size);123 compiler.codeGenerator.op_mov_RV(sizeof(_int64),REG_RCX,object_size); 122 124 123 125 //call calloc 124 126 extern const UserProc *pSub_calloc; 125 op_call(pSub_calloc);127 compiler.codeGenerator.op_call(pSub_calloc); 126 128 127 129 //mov r13,rax 128 op_mov_RR(REG_R13,REG_RAX);130 compiler.codeGenerator.op_mov_RR(REG_R13,REG_RAX); 129 131 130 132 ///////////////////////////////////////////// … … 169 171 if(reg1==REG_RDX||reg1==REG_R8){ 170 172 //mov r14,reg1 171 op_mov_RR(REG_R14,reg1);173 compiler.codeGenerator.op_mov_RR(REG_R14,reg1); 172 174 reg1=REG_R14; 173 175 } … … 177 179 if( pUserProc->ReturnType().IsStruct() ){ 178 180 //mov r8,reg2 179 op_mov_RR(REG_R8,reg2);181 compiler.codeGenerator.op_mov_RR(REG_R8,reg2); 180 182 } 181 183 else{ 182 184 //mov rdx,reg2 183 op_mov_RR(REG_RDX,reg2);185 compiler.codeGenerator.op_mov_RR(REG_RDX,reg2); 184 186 } 185 187 } … … 187 189 if( pUserProc->ReturnType().IsStruct() ){ 188 190 //mov rdx,r13 189 op_mov_RR(REG_RDX,REG_R13);191 compiler.codeGenerator.op_mov_RR(REG_RDX,REG_R13); 190 192 } 191 193 192 194 //mov rcx,reg1 193 op_mov_RR(REG_RCX,reg1);195 compiler.codeGenerator.op_mov_RR(REG_RCX,reg1); 194 196 195 197 //call operator_proc 196 op_call(pUserProc);198 compiler.codeGenerator.op_call(pUserProc); 197 199 198 200 if( !pUserProc->ReturnType().IsNull() ){ … … 200 202 201 203 //mov r13,rax 202 op_mov_RR(REG_R13,REG_RAX);204 compiler.codeGenerator.op_mov_RR(REG_R13,REG_RAX); 203 205 } 204 206 … … 249 251 250 252 //mov reg1,r13 251 op_mov_RR(reg1,REG_R13);253 compiler.codeGenerator.op_mov_RR(reg1,REG_R13); 252 254 } 253 255 … … 338 340 339 341 //mov reg,rax 340 op_mov_RR(reg,REG_RAX);342 compiler.codeGenerator.op_mov_RR(reg,REG_RAX); 341 343 342 344 ///////////////////////////////////////////// -
trunk/abdev/BasicCompiler64/amd64_main.cpp
r206 r226 20 20 return 0; 21 21 } 22 23 24 25 //////////////////////26 // rexプリフィックス27 //////////////////////28 void set_rex(int op_size,int reg,int index_reg,int base_reg){29 char RexByte;30 31 if(reg==REG_NON&&index_reg==REG_NON){32 /////////////////////////////////////33 // レジスタをr/mのみに指定するとき34 /////////////////////////////////////35 36 if((base_reg&0x08)==0){37 if(op_size==sizeof(char)&&(base_reg&0x04)){38 // r/m に spl,bpl,sil,dilを指定するとき39 RexByte=0x40;40 }41 else RexByte=0;42 }43 else RexByte=(char)0x41;44 }45 else{46 /////////////////47 // 通常48 /////////////////49 50 if((reg&0x08)==0){51 //reg … rax~rdi52 53 if((index_reg&0x08)==0){54 if((base_reg&0x08)==0) RexByte=0;55 else RexByte=(char)0x41;56 }57 else{58 if((base_reg&0x08)==0) RexByte=(char)0x42;59 else RexByte=(char)0x43;60 }61 }62 else{63 //reg … r8~r1564 65 if((index_reg&0x08)==0){66 if((base_reg&0x08)==0) RexByte=(char)0x44;67 else RexByte=(char)0x45;68 }69 else{70 if((base_reg&0x08)==0) RexByte=(char)0x46;71 else RexByte=(char)0x47;72 }73 }74 }75 76 if(op_size==sizeof(_int64)){77 //64ビットオペランド78 RexByte|=0x48;79 }80 81 if(RexByte) OpBuffer[obp++]=RexByte;82 }83 84 85 86 /////////////////////////////////////////////////87 // ModR/Mバイト、SIBバイト、ディスプレースメント88 /////////////////////////////////////////////////89 90 //スケール91 #define SCALE_NON (char)0x0092 #define SCALE_2 (char)0x4093 #define SCALE_4 (char)0x8094 #define SCALE_8 (char)0xC095 96 //インデックスなし97 #define INDEX_NON 0x0498 99 void set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,int disp){100 if(mod==MOD_DISP32){101 //ModR/Mバイト102 OpBuffer[obp++]=(char)( REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(0x04));103 104 base_reg=0x05;105 index_reg=INDEX_NON;106 }107 else{108 //ModR/Mバイト109 OpBuffer[obp++]=(char)(mod | REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(base_reg));110 }111 112 113 //レジスタモードの場合は、ここで終了114 if(mod==MOD_REG) return;115 116 117 if(REGISTER_OPERAND(base_reg)==0x04||mod==MOD_DISP32){118 //////////////////////119 // SIBバイトを使う120 //////////////////////121 122 OpBuffer[obp++]=(char)(scale| REGISTER_OPERAND(index_reg)<<3 | REGISTER_OPERAND(base_reg));123 }124 125 //ディスプレースメントを必要としない場合は、ここで終了126 if(mod==MOD_BASE) return;127 128 129 //////////////////////////130 // ディスプレースメント131 //////////////////////////132 133 if(mod==MOD_BASE_DISP8) OpBuffer[obp++]=(char)disp;134 else{135 *((long *)(OpBuffer+obp))=disp;136 obp+=sizeof(long);137 }138 }139 140 141 142 void __op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,int offset,char mod){143 //命令プリフィックス144 if(op_prefix) OpBuffer[obp++]=op_prefix;145 146 //rexプリフィックス147 set_rex(op_size,reg,0,base_reg);148 149 //オペコード150 OpBuffer[obp++]=opcode1;151 if(opcode2) OpBuffer[obp++]=opcode2;152 153 //ModR/M, SIB, disp154 set_mod_rm_sib_disp(mod,reg,SCALE_NON,INDEX_NON,base_reg,offset);155 }156 157 158 159 160 //////////////////////////161 // スタック関連162 //////////////////////////163 164 void op_push(int reg){165 //スタックにレジスタの値をプッシュ166 167 if(REG_RAX<=reg&®<=REG_RDI){168 /* rax~rdi169 0101 0xxx */170 OpBuffer[obp++]=(char)(0x50| REGISTER_OPERAND(reg) );171 }172 if(REG_R8<=reg&®<=REG_R15){173 /* r8~r15174 0100 0001 0101 0xxx */175 OpBuffer[obp++]=(char)0x41;176 OpBuffer[obp++]=(char)(0x50| REGISTER_OPERAND(reg) );177 }178 }179 void op_push_value(long data){180 //スタックにリテラル値をプッシュ181 if(-128<=data&&data<=127){182 //push 8ビット値183 OpBuffer[obp++]=(char)0x6A;184 OpBuffer[obp++]=(char)data;185 }186 else{187 //push 32ビット値188 OpBuffer[obp++]=(char)0x68;189 *((long *)(OpBuffer+obp))=data;190 obp+=sizeof(long);191 }192 }193 void op_pop(int reg){194 //スタックの内容をレジスタにポップ195 if(REG_RAX<=reg&®<=REG_RDI){196 /* rax~rdi197 0101 1xxx */198 OpBuffer[obp++]=(char)(0x58| REGISTER_OPERAND(reg) );199 }200 if(REG_R8<=reg&®<=REG_R15){201 /* r8~r15202 0100 0001 0101 1xxx */203 OpBuffer[obp++]=(char)0x41;204 OpBuffer[obp++]=(char)(0x58| REGISTER_OPERAND(reg) );205 }206 }207 208 209 210 ///////////////////211 // mov関連212 ///////////////////213 214 void op_mov_RV(int op_size,int reg,int i32data){215 //mov reg,i32data216 217 //rexプリフィックス218 set_rex(op_size,REG_NON,REG_NON,reg);219 220 if(op_size==sizeof(_int64)){221 //オペコード222 OpBuffer[obp++]=(char)0xC7;223 224 //レジスタ225 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg) );226 }227 else{228 //レジスタ229 OpBuffer[obp++]=(char)(0xB8| REGISTER_OPERAND(reg) );230 }231 232 //即値233 *((long *)(OpBuffer+obp))=i32data;234 obp+=sizeof(long);235 }236 void op_mov_RV64(int reg,_int64 i64data){237 //mov reg,i64data238 239 //rexプリフィックス240 set_rex(sizeof(_int64),REG_NON,REG_NON,reg);241 242 //レジスタ243 OpBuffer[obp++]=(char)(0xB8| REGISTER_OPERAND(reg) );244 245 //即値246 *((_int64 *)(OpBuffer+obp))=i64data;247 obp+=sizeof(_int64);248 }249 void op_mov_RM(int op_size,int reg,int base_reg,int offset,char mod){250 //mov reg64,qword ptr[base_reg+offset]251 //mov reg32,dword ptr[base_reg+offset]252 //mov reg16,word ptr[base_reg+offset]253 //mov reg8,byte ptr[base_reg+offset]254 255 //16ビット演算の命令プリフィックス256 char op_prefix=0;257 if(op_size==sizeof(short)) op_prefix=(char)0x66;258 259 //オペコード260 char opcode;261 if(op_size==sizeof(char)) opcode=(char)0x8A;262 else opcode=(char)0x8B;263 264 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod);265 }266 void op_mov_RM_ex(int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset){267 //mov reg64,qword ptr[base_reg1+base_reg2+offset]268 //mov reg32,dword ptr[base_reg1+base_reg2+offset]269 //mov reg16,word ptr[base_reg1+base_reg2+offset]270 //mov reg8,byte ptr[base_reg1+base_reg2+offset]271 272 if(base_reg1==REG_RSP){273 //SIBバイトのindex部にrspは指定できない274 base_reg1=base_reg2;275 base_reg2=REG_RSP;276 }277 278 //16ビット演算のプリフィックス279 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;280 281 //rexプリフィックス282 set_rex(op_size,reg,base_reg1,base_reg2);283 284 //オペコード285 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0x8A;286 else OpBuffer[obp++]=(char)0x8B;287 288 if(bUseOffset){289 ///////////////////////////290 // オフセット値を使う291 ///////////////////////////292 293 //レジスタ294 OpBuffer[obp++]=(char)(0x84| REGISTER_OPERAND(reg)<<3);295 296 //ベースレジスタ297 OpBuffer[obp++]=(char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2));298 299 //オフセット値300 *((long *)(OpBuffer+obp))=offset;301 obp+=sizeof(long);302 }303 else{304 ///////////////////////////305 // オフセット値を使わない306 ///////////////////////////307 308 //レジスタ309 OpBuffer[obp++]=(char)(0x04| REGISTER_OPERAND(reg)<<3);310 311 //ベースレジスタ312 OpBuffer[obp++]=(char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2));313 }314 }315 void op_mov_MR(int op_size,int reg,int base_reg,int offset,char mod){316 //mov qword ptr[base_reg+offset],reg64317 //mov dword ptr[base_reg+offset],reg32318 //mov word ptr[base_reg+offset],reg16319 //mov byte ptr[base_reg+offset],reg8320 321 //16ビット演算の命令プリフィックス322 char op_prefix=0;323 if(op_size==sizeof(short)) op_prefix=(char)0x66;324 325 //オペコード326 char opcode;327 if(op_size==sizeof(char)) opcode=(char)0x88;328 else opcode=(char)0x89;329 330 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod);331 }332 void op_mov_MR_ex(int op_size,int reg,int base_reg1,int base_reg2,int offset,BOOL bUseOffset){333 //mov qword ptr[base_reg1+base_reg2+offset],reg64334 //mov dword ptr[base_reg1+base_reg2+offset],reg32335 //mov word ptr[base_reg1+base_reg2+offset],reg16336 //mov byte ptr[base_reg1+base_reg2+offset],reg8337 338 if(base_reg1==REG_RSP){339 //SIBバイトのindex部にrspは指定できない340 base_reg1=base_reg2;341 base_reg2=REG_RSP;342 }343 344 //16ビット演算のプリフィックス345 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;346 347 //rexプリフィックス348 set_rex(op_size,reg,base_reg1,base_reg2);349 350 //オペコード351 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0x88;352 else OpBuffer[obp++]=(char)0x89;353 354 if(bUseOffset==USE_OFFSET){355 //////////////////////////356 //オフセット値を使う357 //////////////////////////358 359 //レジスタ360 OpBuffer[obp++]=(char)(0x84| REGISTER_OPERAND(reg)<<3);361 362 //ベースレジスタ363 OpBuffer[obp++]=(char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2));364 365 //オフセット値366 *((long *)(OpBuffer+obp))=offset;367 obp+=sizeof(long);368 }369 else{370 //////////////////////////371 //オフセット値を使わない372 //////////////////////////373 374 //レジスタ375 OpBuffer[obp++]=(char)(0x04| REGISTER_OPERAND(reg)<<3);376 377 //ベースレジスタ378 OpBuffer[obp++]=(char)(REGISTER_OPERAND(base_reg1)<<3 | REGISTER_OPERAND(base_reg2));379 }380 }381 382 void op_mov_MV(int op_size,int base_reg,int offset,BOOL bUseOffset,int i32data){383 //mov ptr[base_reg+offset],i32data384 //mov ptr[base_reg ],i32data385 386 //16ビット演算のプリフィックス387 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;388 389 //rexプリフィックス390 set_rex(op_size,0,0,base_reg);391 392 //オペコード393 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0xC6;394 else OpBuffer[obp++]=(char)0xC7;395 396 if(bUseOffset==USE_OFFSET){397 //////////////////////////398 //オフセット値を使う399 //////////////////////////400 401 //ModR/M, SIB, disp402 set_mod_rm_sib_disp(MOD_BASE_DISP32,0,SCALE_NON,INDEX_NON,base_reg,offset);403 }404 else{405 //ModR/M, SIB, disp406 set_mod_rm_sib_disp(MOD_BASE,0,SCALE_NON,INDEX_NON,base_reg,0);407 }408 409 //即値410 if(op_size==sizeof(_int64)||op_size==sizeof(long)){411 //32/64ビット412 *((long *)(OpBuffer+obp))=i32data;413 obp+=sizeof(long);414 }415 else if(op_size==sizeof(short)){416 //16ビット417 *((short *)(OpBuffer+obp))=(short)i32data;418 obp+=sizeof(short);419 }420 else if(op_size==sizeof(char)){421 //16ビット422 *((char *)(OpBuffer+obp))=(char)i32data;423 obp++;424 }425 }426 427 void op_mov_RR(int reg1,int reg2){428 //mov reg1,reg2429 char RexByte=-1;430 431 if(reg1==reg2) return;432 433 if(REG_RAX<=reg1&®1<=REG_RDI){434 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;435 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;436 }437 if(REG_R8<=reg1&®1<=REG_R15){438 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;439 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;440 }441 442 if(RexByte==-1) SetError(300,NULL,cp);443 444 // [8bit rex] 1000 1011 11xx xbbb445 OpBuffer[obp++]=RexByte;446 OpBuffer[obp++]=(char)0x8B;447 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));448 }449 450 451 452 ///////////////////453 // mov64関連454 ///////////////////455 456 void op_mov64_ToReg(int reg,_int64 i64data){457 //mov reg,i64data458 459 if(REG_RAX<=reg&®<=REG_RDI){460 /* rax~rdi461 0100 1000 1011 1xxx [64bit data] */462 OpBuffer[obp++]=(char)0x48;463 OpBuffer[obp++]=(char)(0xB8| REGISTER_OPERAND(reg) );464 *((_int64 *)(OpBuffer+obp))=i64data;465 obp+=sizeof(_int64);466 }467 if(REG_R8<=reg&®<=REG_R15){468 /* r8~r15469 0100 1001 1011 1xxx [64bit data] */470 OpBuffer[obp++]=(char)0x49;471 OpBuffer[obp++]=(char)(0xB8| REGISTER_OPERAND(reg) );472 *((_int64 *)(OpBuffer+obp))=i64data;473 obp+=sizeof(_int64);474 }475 }476 void op_mov64_ToReg(int reg,int i32data){477 //mov reg,i32data478 479 if(REG_RAX<=reg&®<=REG_RDI){480 /* rax~rdi481 0100 1000 1100 0111 1100 0xxx [32bit data] */482 OpBuffer[obp++]=(char)0x48;483 OpBuffer[obp++]=(char)0xC7;484 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg) );485 *((long *)(OpBuffer+obp))=i32data;486 obp+=sizeof(long);487 }488 if(REG_R8<=reg&®<=REG_R15){489 /* r8~r15490 0100 1001 1100 0111 1100 0xxx [32bit data] */491 OpBuffer[obp++]=(char)0x49;492 OpBuffer[obp++]=(char)0xC7;493 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg) );494 *((long *)(OpBuffer+obp))=i32data;495 obp+=sizeof(long);496 }497 }498 void op_movsxd(int reg64,int reg32){499 //movsxd reg64,reg32500 char RexByte=-1;501 502 if(REG_RAX<=reg64&®64<=REG_RDI){503 if(REG_RAX<=reg32&®32<=REG_RDI) RexByte=(char)0x48;504 if(REG_R8<=reg32&®32<=REG_R15) RexByte=(char)0x49;505 }506 if(REG_R8<=reg64&®64<=REG_R15){507 if(REG_RAX<=reg32&®32<=REG_RDI) RexByte=(char)0x4C;508 if(REG_R8<=reg32&®32<=REG_R15) RexByte=(char)0x4D;509 }510 511 if(RexByte==-1) SetError(300,NULL,cp);512 513 //[8bit rex] 0110 0011 11rr rbbb514 OpBuffer[obp++]=RexByte;515 OpBuffer[obp++]=(char)0x63;516 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg64)<<3 | REGISTER_OPERAND(reg32));517 }518 void op_movsx64_FromReg16(int reg64,int reg16){519 //movsx reg64,reg16520 char RexByte=-1;521 522 if(REG_RAX<=reg64&®64<=REG_RDI){523 if(REG_RAX<=reg16&®16<=REG_RDI) RexByte=(char)0x48;524 if(REG_R8<=reg16&®16<=REG_R15) RexByte=(char)0x49;525 }526 if(REG_R8<=reg64&®64<=REG_R15){527 if(REG_RAX<=reg16&®16<=REG_RDI) RexByte=(char)0x4C;528 if(REG_R8<=reg16&®16<=REG_R15) RexByte=(char)0x4D;529 }530 531 if(RexByte==-1) SetError(300,NULL,cp);532 533 //[8bit rex] 0000 1111 1011 1111 11rr rbbb534 OpBuffer[obp++]=RexByte;535 OpBuffer[obp++]=(char)0x0F;536 OpBuffer[obp++]=(char)0xBF;537 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg64)<<3 | REGISTER_OPERAND(reg16));538 }539 void op_movsx64_FromReg8(int reg64,int reg8){540 //movsx reg64,reg8541 char RexByte=-1;542 543 if(REG_RAX<=reg64&®64<=REG_RDI){544 if(REG_RAX<=reg8&®8<=REG_RDI) RexByte=(char)0x48;545 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x49;546 }547 if(REG_R8<=reg64&®64<=REG_R15){548 if(REG_RAX<=reg8&®8<=REG_RDI) RexByte=(char)0x4C;549 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x4D;550 }551 552 if(RexByte==-1) SetError(300,NULL,cp);553 554 //[8bit rex] 0000 1111 1011 1110 11rr rbbb555 OpBuffer[obp++]=RexByte;556 OpBuffer[obp++]=(char)0x0F;557 OpBuffer[obp++]=(char)0xBE;558 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg64)<<3 | REGISTER_OPERAND(reg8));559 }560 561 562 563 //////////////////564 // mov32関連565 //////////////////566 567 void op_movsx32_FromReg16(int reg32,int reg16){568 //movsx reg32,reg16569 char RexByte=-1;570 571 if(REG_RAX<=reg32&®32<=REG_RDI){572 if(REG_RAX<=reg16&®16<=REG_RDI) RexByte=0;573 if(REG_R8<=reg16&®16<=REG_R15) RexByte=(char)0x41;574 }575 if(REG_R8<=reg32&®32<=REG_R15){576 if(REG_RAX<=reg16&®16<=REG_RDI) RexByte=(char)0x44;577 if(REG_R8<=reg16&®16<=REG_R15) RexByte=(char)0x45;578 }579 580 if(RexByte==-1) SetError(300,NULL,cp);581 582 //[8bit rex] 0000 1111 1011 1111 11rr rbbb583 if(RexByte) OpBuffer[obp++]=RexByte;584 OpBuffer[obp++]=(char)0x0F;585 OpBuffer[obp++]=(char)0xBF;586 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg32)<<3 | REGISTER_OPERAND(reg16));587 }588 void op_movsx32_FromReg8(int reg32,int reg8){589 //movsx reg32,reg8590 char RexByte=-1;591 592 if(REG_RAX<=reg32&®32<=REG_RDI){593 if(REG_RAX<=reg8&®8<=REG_RBX) RexByte=0;594 if(REG_RSP<=reg8&®8<=REG_RDI) RexByte=(char)0x40;595 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x41;596 }597 if(REG_R8<=reg32&®32<=REG_R15){598 if(REG_RAX<=reg8&®8<=REG_RDI) RexByte=(char)0x44;599 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x45;600 }601 602 if(RexByte==-1) SetError(300,NULL,cp);603 604 //[8bit rex] 0000 1111 1011 1110 11rr rbbb605 if(RexByte) OpBuffer[obp++]=RexByte;606 OpBuffer[obp++]=(char)0x0F;607 OpBuffer[obp++]=(char)0xBE;608 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg32)<<3 | REGISTER_OPERAND(reg8));609 }610 611 612 613 /////////////////////614 // mov16関連615 /////////////////////616 617 void op_movsx16_FromReg8(int reg32,int reg8){618 //movsx reg16,reg8619 char RexByte=-1;620 621 if(REG_RAX<=reg32&®32<=REG_RDI){622 if(REG_RAX<=reg8&®8<=REG_RBX) RexByte=0;623 if(REG_RSP<=reg8&®8<=REG_RDI) RexByte=(char)0x40;624 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x41;625 }626 if(REG_R8<=reg32&®32<=REG_R15){627 if(REG_RAX<=reg8&®8<=REG_RDI) RexByte=(char)0x44;628 if(REG_R8<=reg8&®8<=REG_R15) RexByte=(char)0x45;629 }630 631 if(RexByte==-1) SetError(300,NULL,cp);632 633 //0110 0110 [8bit rex] 0000 1111 1011 1110 11rr rbbb634 OpBuffer[obp++]=(char)0x66;635 if(RexByte) OpBuffer[obp++]=RexByte;636 OpBuffer[obp++]=(char)0x0F;637 OpBuffer[obp++]=(char)0xBE;638 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg32)<<3 | REGISTER_OPERAND(reg8));639 }640 641 642 643 //////////////////////////////////644 // インクリメント・デクリメント645 //////////////////////////////////646 647 void op_inc(int reg){648 //inc reg649 650 //16ビット演算の命令プリフィックス651 char op_prefix=0;652 653 //オペコード654 char opcode=(char)0xFF;655 656 __op_format(sizeof(_int64),op_prefix,opcode,0,0,reg,0,MOD_REG);657 }658 void op_dec(int reg){659 op_inc(reg);660 OpBuffer[obp-1]=OpBuffer[obp-1]|0x08;661 }662 663 664 665 /////////////////////666 // add関連667 /////////////////////668 669 void op_add_RM(int op_size,int reg,int base_reg,int offset,char mod){670 //add reg64,qword ptr[base_reg+offset]671 //add reg32,dword ptr[base_reg+offset]672 //add reg16,word ptr[base_reg+offset]673 //add reg8,byte ptr[base_reg+offset]674 675 //16ビット演算の命令プリフィックス676 char op_prefix=0;677 if(op_size==sizeof(short)) op_prefix=(char)0x66;678 679 //オペコード680 char opcode;681 if(op_size==sizeof(char)) opcode=(char)0x02;682 else opcode=(char)0x03;683 684 __op_format(op_size,op_prefix,opcode,0,reg,base_reg,offset,mod);685 }686 687 void op_add_RV(int reg,int offset){688 //add reg,offset689 char RexByte=-1;690 691 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0x48;692 if(REG_R8<=reg&®<=REG_R15) RexByte=0x49;693 694 if(RexByte==-1) SetError(300,NULL,cp);695 696 if(reg==REG_RAX){697 //raxのみ特殊698 699 // [8bit rex] 0000 0101 [32bit offset]700 OpBuffer[obp++]=(char)RexByte;701 OpBuffer[obp++]=(char)0x05;702 *((long *)(OpBuffer+obp))=offset;703 obp+=sizeof(long);704 }705 else{706 //rax以外707 708 //[8bit rex] 1000 0001 1100 0xxx [32bit offset]709 OpBuffer[obp++]=(char)RexByte;710 OpBuffer[obp++]=(char)0x81;711 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg));712 *((long *)(OpBuffer+obp))=offset;713 obp+=sizeof(long);714 }715 }716 void op_add64_reg(int reg1,int reg2){717 //add reg1,reg2718 char RexByte=-1;719 720 if(REG_RAX<=reg1&®1<=REG_RDI){721 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;722 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;723 }724 if(REG_R8<=reg1&®1<=REG_R15){725 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;726 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;727 }728 729 if(RexByte==-1) SetError(300,NULL,cp);730 731 //[8bit rex] 0000 0011 11rr rbbb732 OpBuffer[obp++]=(char)RexByte;733 OpBuffer[obp++]=(char)0x03;734 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));735 }736 void op_add32_reg(int reg1,int reg2){737 //add reg1,reg2738 char RexByte=-1;739 740 if(REG_RAX<=reg1&®1<=REG_RDI){741 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;742 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;743 }744 if(REG_R8<=reg1&®1<=REG_R15){745 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;746 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;747 }748 749 if(RexByte==-1) SetError(300,NULL,cp);750 751 //[8bit rex] 0000 0011 11rr rbbb752 if(RexByte) OpBuffer[obp++]=(char)RexByte;753 OpBuffer[obp++]=(char)0x03;754 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));755 }756 757 758 759 ////////////////////////760 // sub関連761 ////////////////////////762 763 void op_sub_RV(int op_size,int reg,int i32data){764 //sub reg,i32data765 766 //rexプリフィックス767 set_rex(op_size,REG_NON,REG_NON,reg);768 769 if(reg==REG_RAX){770 //raxのみ特殊771 OpBuffer[obp++]=(char)0x2D;772 }773 else{774 //オペコード775 OpBuffer[obp++]=(char)0x81;776 777 //レジスタ778 OpBuffer[obp++]=(char)(0xE8| REGISTER_OPERAND(reg) );779 }780 781 //即値782 *((long *)(OpBuffer+obp))=i32data;783 obp+=sizeof(long);784 }785 void op_sub64_reg(int reg1,int reg2){786 //sub reg1,reg2787 char RexByte=-1;788 789 if(REG_RAX<=reg1&®1<=REG_RDI){790 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;791 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;792 }793 if(REG_R8<=reg1&®1<=REG_R15){794 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;795 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;796 }797 798 if(RexByte==-1) SetError(300,NULL,cp);799 800 //[8bit rex] 0010 1011 11rr rbbb801 OpBuffer[obp++]=(char)RexByte;802 OpBuffer[obp++]=(char)0x2B;803 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));804 }805 void op_sub32_reg(int reg1,int reg2){806 //sub reg1,reg2807 char RexByte=-1;808 809 if(REG_RAX<=reg1&®1<=REG_RDI){810 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;811 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;812 }813 if(REG_R8<=reg1&®1<=REG_R15){814 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;815 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;816 }817 818 if(RexByte==-1) SetError(300,NULL,cp);819 820 //[8bit rex] 0010 1011 11rr rbbb821 if(RexByte) OpBuffer[obp++]=(char)RexByte;822 OpBuffer[obp++]=(char)0x2B;823 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));824 }825 void op_sbb_RR( int op_size, int reg1, int reg2 ){826 //sbb reg1,reg2827 828 //rexプリフィックス829 set_rex(0,reg1,0,reg2);830 831 //オペコード832 OpBuffer[obp++]=(char)0x1B;833 834 //レジスタ835 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));836 }837 838 839 840 ////////////////////////841 // imul関連842 ////////////////////////843 844 void op_imul_RR(int op_size,int reg1,int reg2){845 //imul reg1,reg2846 char RexByte=-1;847 848 if(op_size==sizeof(_int64)){849 if(REG_RAX<=reg1&®1<=REG_RDI){850 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;851 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;852 }853 if(REG_R8<=reg1&®1<=REG_R15){854 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;855 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;856 }857 }858 else{859 if(REG_RAX<=reg1&®1<=REG_RDI){860 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;861 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;862 }863 if(REG_R8<=reg1&®1<=REG_R15){864 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;865 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;866 }867 }868 869 if(RexByte==-1) SetError(300,NULL,cp);870 871 872 //rexプリフィックス873 if(RexByte) OpBuffer[obp++]=(char)RexByte;874 875 //オペコード876 OpBuffer[obp++]=(char)0x0F;877 OpBuffer[obp++]=(char)0xAF;878 879 //レジスタ880 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));881 }882 void op_imul_RV(int op_size,int reg,int i32data){883 //imul reg,i32data884 char RexByte=-1;885 886 if(op_size==sizeof(_int64)){887 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;888 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x4D;889 }890 else{891 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;892 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x45;893 }894 895 if(RexByte==-1) SetError(300,NULL,cp);896 897 898 //rexプリフィックス899 if(RexByte) OpBuffer[obp++]=(char)RexByte;900 901 if(-128<=i32data&&i32data<=127){902 //オペコード903 OpBuffer[obp++]=(char)0x6B;904 905 //レジスタ906 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(reg));907 908 //値909 OpBuffer[obp++]=(char)i32data;910 }911 else{912 //オペコード913 OpBuffer[obp++]=(char)0x69;914 915 //レジスタ916 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(reg));917 918 //値919 *((long *)(OpBuffer+obp))=i32data;920 obp+=sizeof(long);921 }922 }923 924 925 926 ////////////////////////927 // div、idiv関連928 ////////////////////////929 930 void op_div64_reg(int reg){931 //div reg932 char RexByte=-1;933 934 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;935 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;936 937 if(RexByte==-1) SetError(300,NULL,cp);938 939 //rexプリフィックス940 OpBuffer[obp++]=(char)RexByte;941 942 //オペコード943 OpBuffer[obp++]=(char)0xF7;944 945 //レジスタ946 OpBuffer[obp++]=(char)(0xF0| REGISTER_OPERAND(reg));947 }948 void op_idiv64_reg(int reg){949 //idiv reg950 char RexByte=-1;951 952 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;953 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;954 955 if(RexByte==-1) SetError(300,NULL,cp);956 957 //rexプリフィックス958 OpBuffer[obp++]=(char)RexByte;959 960 //オペコード961 OpBuffer[obp++]=(char)0xF7;962 963 //レジスタ964 OpBuffer[obp++]=(char)(0xF8| REGISTER_OPERAND(reg));965 }966 967 968 969 ////////////////////970 // ビットシフト関連971 ////////////////////972 973 void op_shl_reg(int op_size,int reg){974 //shl reg,cl975 char RexByte=-1;976 977 if(op_size==sizeof(_int64)){978 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;979 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;980 }981 else if(op_size==sizeof(char)){982 if(REG_RAX<=reg&®<=REG_RBX) RexByte=0;983 if(REG_RSP<=reg&®<=REG_RDI) RexByte=(char)0x40;984 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;985 }986 else{987 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;988 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;989 }990 991 if(RexByte==-1) SetError(300,NULL,cp);992 993 994 //16ビット演算のプリフィックス995 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;996 997 //rexプリフィックス998 if(RexByte) OpBuffer[obp++]=(char)RexByte;999 1000 //オペコード1001 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0xD2;1002 else OpBuffer[obp++]=(char)0xD3;1003 1004 //レジスタ1005 OpBuffer[obp++]=(char)(0xE0| REGISTER_OPERAND(reg));1006 }1007 void op_sar_reg(int op_size,int reg){1008 //sar reg,cl1009 char RexByte=-1;1010 1011 if(op_size==sizeof(_int64)){1012 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;1013 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;1014 }1015 else if(op_size==sizeof(char)){1016 if(REG_RAX<=reg&®<=REG_RBX) RexByte=0;1017 if(REG_RSP<=reg&®<=REG_RDI) RexByte=(char)0x40;1018 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1019 }1020 else{1021 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1022 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1023 }1024 1025 if(RexByte==-1) SetError(300,NULL,cp);1026 1027 1028 //16ビット演算のプリフィックス1029 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;1030 1031 //rexプリフィックス1032 if(RexByte) OpBuffer[obp++]=(char)RexByte;1033 1034 //オペコード1035 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0xD2;1036 else OpBuffer[obp++]=(char)0xD3;1037 1038 //レジスタ1039 OpBuffer[obp++]=(char)(0xF8| REGISTER_OPERAND(reg));1040 }1041 void op_shr_reg(int op_size,int reg){1042 //shr reg,cl1043 char RexByte=-1;1044 1045 if(op_size==sizeof(_int64)){1046 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;1047 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;1048 }1049 else if(op_size==sizeof(char)){1050 if(REG_RAX<=reg&®<=REG_RBX) RexByte=0;1051 if(REG_RSP<=reg&®<=REG_RDI) RexByte=(char)0x40;1052 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1053 }1054 else{1055 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1056 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1057 }1058 1059 if(RexByte==-1) SetError(300,NULL,cp);1060 1061 1062 //16ビット演算のプリフィックス1063 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;1064 1065 //rexプリフィックス1066 if(RexByte) OpBuffer[obp++]=(char)RexByte;1067 1068 //オペコード1069 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0xD2;1070 else OpBuffer[obp++]=(char)0xD3;1071 1072 //レジスタ1073 OpBuffer[obp++]=(char)(0xE8| REGISTER_OPERAND(reg));1074 }1075 1076 1077 1078 ////////////////////1079 // and 関連1080 ////////////////////1081 1082 void op_and_reg(int op_size,int reg1,int reg2){1083 //and reg1,reg21084 char RexByte=-1;1085 1086 if(op_size==sizeof(_int64)){1087 if(REG_RAX<=reg1&®1<=REG_RDI){1088 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;1089 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;1090 }1091 if(REG_R8<=reg1&®1<=REG_R15){1092 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;1093 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;1094 }1095 }1096 else{1097 if(REG_RAX<=reg1&®1<=REG_RDI){1098 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;1099 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;1100 }1101 if(REG_R8<=reg1&®1<=REG_R15){1102 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;1103 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;1104 }1105 }1106 1107 if(RexByte==-1) SetError(300,NULL,cp);1108 1109 1110 //rexプリフィックス1111 if(RexByte) OpBuffer[obp++]=(char)RexByte;1112 1113 //オペコード1114 OpBuffer[obp++]=(char)0x23;1115 1116 //レジスタ1117 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));1118 }1119 void op_and64_value(int reg,int offset){1120 //and reg,offset1121 char RexByte=-1;1122 1123 if(REG_RAX<=reg&®<=REG_RDI) (char)RexByte=0x48;1124 if(REG_R8<=reg&®<=REG_R15) (char)RexByte=0x49;1125 1126 if(RexByte==-1) SetError(300,NULL,cp);1127 1128 if(reg==REG_RAX){1129 //raxのみ特殊1130 1131 // [8bit rex] 0010 0101 [32bit offset]1132 OpBuffer[obp++]=(char)RexByte;1133 OpBuffer[obp++]=(char)0x25;1134 *((long *)(OpBuffer+obp))=offset;1135 obp+=sizeof(long);1136 }1137 else{1138 //rax以外1139 1140 //[8bit rex] 1000 0001 1100 0xxx [32bit offset]1141 OpBuffer[obp++]=(char)RexByte;1142 OpBuffer[obp++]=(char)0x81;1143 OpBuffer[obp++]=(char)(0xE0| REGISTER_OPERAND(reg));1144 *((long *)(OpBuffer+obp))=offset;1145 obp+=sizeof(long);1146 }1147 }1148 void op_and32_value(int reg,int offset){1149 //and reg,offset1150 char RexByte=-1;1151 1152 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1153 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1154 1155 if(RexByte==-1) SetError(300,NULL,cp);1156 1157 if(reg==REG_RAX){1158 //eaxのみ特殊1159 1160 // [8bit rex] 0010 0101 [32bit offset]1161 OpBuffer[obp++]=(char)0x25;1162 *((long *)(OpBuffer+obp))=offset;1163 obp+=sizeof(long);1164 }1165 else{1166 //eax以外1167 1168 //[8bit rex] 1000 0001 1100 0xxx [32bit offset]1169 if(RexByte) OpBuffer[obp++]=(char)RexByte;1170 OpBuffer[obp++]=(char)0x81;1171 OpBuffer[obp++]=(char)(0xE0| REGISTER_OPERAND(reg));1172 *((long *)(OpBuffer+obp))=offset;1173 obp+=sizeof(long);1174 }1175 }1176 1177 1178 1179 ////////////////////////1180 // or 関連1181 ////////////////////////1182 1183 void op_or_reg(int op_size,int reg1,int reg2){1184 //or reg1,reg21185 char RexByte=-1;1186 1187 if(op_size==sizeof(_int64)){1188 if(REG_RAX<=reg1&®1<=REG_RDI){1189 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;1190 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;1191 }1192 if(REG_R8<=reg1&®1<=REG_R15){1193 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;1194 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;1195 }1196 }1197 else{1198 if(REG_RAX<=reg1&®1<=REG_RDI){1199 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;1200 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;1201 }1202 if(REG_R8<=reg1&®1<=REG_R15){1203 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;1204 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;1205 }1206 }1207 1208 if(RexByte==-1) SetError(300,NULL,cp);1209 1210 1211 //rexプリフィックス1212 if(RexByte) OpBuffer[obp++]=(char)RexByte;1213 1214 //オペコード1215 OpBuffer[obp++]=(char)0x0B;1216 1217 //レジスタ1218 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));1219 }1220 1221 1222 1223 ////////////////////////1224 // xor 関連1225 ////////////////////////1226 1227 void op_xor_reg(int op_size,int reg1,int reg2){1228 //xor reg1,reg21229 char RexByte=-1;1230 1231 if(op_size==sizeof(_int64)){1232 if(REG_RAX<=reg1&®1<=REG_RDI){1233 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;1234 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;1235 }1236 if(REG_R8<=reg1&®1<=REG_R15){1237 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;1238 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;1239 }1240 }1241 else{1242 if(REG_RAX<=reg1&®1<=REG_RDI){1243 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;1244 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;1245 }1246 if(REG_R8<=reg1&®1<=REG_R15){1247 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;1248 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;1249 }1250 }1251 1252 if(RexByte==-1) SetError(300,NULL,cp);1253 1254 1255 //rexプリフィックス1256 if(RexByte) OpBuffer[obp++]=(char)RexByte;1257 1258 //オペコード1259 OpBuffer[obp++]=(char)0x33;1260 1261 //レジスタ1262 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));1263 }1264 1265 1266 1267 ///////////////////////1268 // not 関連1269 ///////////////////////1270 1271 void op_not_reg(int op_size,int reg){1272 //not reg1273 char RexByte=-1;1274 1275 if(op_size==sizeof(_int64)){1276 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;1277 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;1278 }1279 else{1280 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1281 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1282 }1283 1284 if(RexByte==-1) SetError(300,NULL,cp);1285 1286 1287 //rexプリフィックス1288 if(RexByte) OpBuffer[obp++]=(char)RexByte;1289 1290 //オペコード1291 OpBuffer[obp++]=(char)0xF7;1292 1293 //レジスタ1294 OpBuffer[obp++]=(char)(0xD0| REGISTER_OPERAND(reg));1295 }1296 void op_neg( int reg ){1297 //neg reg1298 1299 //オペコード1300 OpBuffer[obp++]=(char)0xF7;1301 1302 //レジスタ1303 OpBuffer[obp++]=(char)(0xD8| REGISTER_OPERAND(reg));1304 }1305 1306 1307 1308 ////////////////////1309 // test関連1310 ////////////////////1311 1312 void op_test(int reg1,int reg2){1313 //test reg1,reg21314 char RexByte=-1;1315 1316 if(REG_RAX<=reg1&®1<=REG_RDI){1317 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;1318 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;1319 }1320 if(REG_R8<=reg1&®1<=REG_R15){1321 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;1322 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;1323 }1324 1325 if(RexByte==-1) SetError(300,NULL,cp);1326 1327 //[8bit rex] 1000 0101 11rr rbbb1328 OpBuffer[obp++]=(char)RexByte;1329 OpBuffer[obp++]=(char)0x85;1330 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));1331 }1332 1333 1334 1335 /////////////////////1336 // cmp 関連1337 /////////////////////1338 1339 void op_cmp_reg(int op_size,int reg1,int reg2){1340 //cmp reg1,reg21341 char RexByte=-1;1342 1343 if(op_size==sizeof(_int64)){1344 if(REG_RAX<=reg1&®1<=REG_RDI){1345 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x48;1346 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x49;1347 }1348 if(REG_R8<=reg1&®1<=REG_R15){1349 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x4C;1350 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x4D;1351 }1352 }1353 else{1354 if(REG_RAX<=reg1&®1<=REG_RDI){1355 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=0;1356 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x41;1357 }1358 if(REG_R8<=reg1&®1<=REG_R15){1359 if(REG_RAX<=reg2&®2<=REG_RDI) RexByte=(char)0x44;1360 if(REG_R8<=reg2&®2<=REG_R15) RexByte=(char)0x45;1361 }1362 }1363 1364 if(RexByte==-1) SetError(300,NULL,cp);1365 1366 1367 //rexプリフィックス1368 if(RexByte) OpBuffer[obp++]=(char)RexByte;1369 1370 //オペコード1371 OpBuffer[obp++]=(char)0x3B;1372 1373 //レジスタ1374 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg1)<<3 | REGISTER_OPERAND(reg2));1375 }1376 void op_cmp_value(int op_size,int reg,char byte_data){1377 //cmp reg,byte_data1378 1379 if(op_size==sizeof(char)&®==REG_RAX){1380 //alレジスタの場合は特殊1381 OpBuffer[obp++]=(char)0x3C;1382 1383 //8ビット値1384 OpBuffer[obp++]=byte_data;1385 1386 return;1387 }1388 1389 //16ビット演算のプリフィックス1390 if(op_size==sizeof(short)) OpBuffer[obp++]=(char)0x66;1391 1392 //rexプリフィックス1393 set_rex(op_size,REG_NON,REG_NON,reg);1394 1395 //オペコード1396 if(op_size==sizeof(char)) OpBuffer[obp++]=(char)0x80;1397 else OpBuffer[obp++]=(char)0x83;1398 1399 //レジスタ1400 OpBuffer[obp++]=(char)(0xF8| REGISTER_OPERAND(reg));1401 1402 //8ビット値1403 OpBuffer[obp++]=byte_data;1404 }1405 void op_setne( int reg ){1406 //オペコード1407 OpBuffer[obp++]=(char)0x0F;1408 OpBuffer[obp++]=(char)0x95;1409 1410 //レジスタ1411 OpBuffer[obp++]=(char)( 0xC0 | REGISTER_OPERAND(reg) );1412 }1413 1414 1415 ////////////////////1416 // SSE2関連1417 ////////////////////1418 1419 void op_movlpd_MR(int xmm_reg,int base_reg,int offset,char mod){1420 //movlpd qword ptr[base_reg+offset],xmm_reg1421 __op_format(0,(char)0x66,(char)0x0F,(char)0x13,xmm_reg,base_reg,offset,mod);1422 }1423 void op_movlpd_RM(int xmm_reg,int base_reg,int offset,char mod){1424 //movlpd xmm_reg,qword ptr[base_reg+offset]1425 __op_format(0,(char)0x66,(char)0x0F,(char)0x12,xmm_reg,base_reg,offset,mod);1426 }1427 void op_movsd_RR(int xmm_reg1,int xmm_reg2){1428 if(xmm_reg1==xmm_reg2) return;1429 1430 //movsd xmm_reg1,xmm_reg21431 __op_format(0,(char)0xF2,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG);1432 }1433 void op_movsd_MR(int xmm_reg,int base_reg,int offset,char mod){1434 //movsd qword ptr[reg+offset],xmm_reg1435 //movsd qword ptr[reg],xmm_reg1436 __op_format(0,(char)0xF2,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod);1437 }1438 void op_movss_RR(int xmm_reg1,int xmm_reg2){1439 if(xmm_reg1==xmm_reg2) return;1440 1441 //movss xmm_reg1,xmm_reg21442 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg1,xmm_reg2,0,MOD_REG);1443 }1444 void op_movss_RM(int xmm_reg,int base_reg,int offset,char mod){1445 //movss xmm_reg,dword ptr[base_reg+offset]1446 __op_format(0,(char)0xF3,(char)0x0F,(char)0x10,xmm_reg,base_reg,offset,mod);1447 }1448 void op_movss_MR(int xmm_reg,int base_reg,int offset,char mod){1449 //movss dword ptr[reg+offset],xmm_reg1450 //movss dword ptr[reg],xmm_reg1451 __op_format(0,(char)0xF3,(char)0x0F,(char)0x11,xmm_reg,base_reg,offset,mod);1452 }1453 1454 void op_movd_RX(int reg,int xmm_reg){1455 __op_format(sizeof(_int64),(char)0x66,(char)0x0F,(char)0x7E,xmm_reg,reg,0,MOD_REG);1456 }1457 1458 void op_cvtsd2ss(int xmm_reg1,int xmm_reg2){1459 //cvtsd2ss xmm_reg1,xmm_reg21460 1461 //オペコード1462 OpBuffer[obp++]=(char)0xF2;1463 1464 //rexプリフィックス1465 set_rex(sizeof(long),xmm_reg1,0,xmm_reg2);1466 1467 //オペコード1468 OpBuffer[obp++]=(char)0x0F;1469 OpBuffer[obp++]=(char)0x5A;1470 1471 //レジスタ1472 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg1)<<3 | REGISTER_OPERAND(xmm_reg2));1473 }1474 void op_cvtss2sd(int xmm_reg1,int xmm_reg2){1475 //cvtss2sd xmm_reg1,xmm_reg21476 1477 //オペコード1478 OpBuffer[obp++]=(char)0xF3;1479 1480 //rexプリフィックス1481 set_rex(0,xmm_reg1,0,xmm_reg2);1482 1483 //オペコード1484 OpBuffer[obp++]=(char)0x0F;1485 OpBuffer[obp++]=(char)0x5A;1486 1487 //レジスタ1488 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg1)<<3 | REGISTER_OPERAND(xmm_reg2));1489 }1490 void op_cvttsd2si_xmm(int op_size,int reg,int xmm_reg){1491 //cvttsd2si reg,xmm_reg1492 1493 //オペコード1494 OpBuffer[obp++]=(char)0xF2;1495 1496 //rexプリフィックス1497 set_rex(op_size,reg,0,xmm_reg);1498 1499 //オペコード1500 OpBuffer[obp++]=(char)0x0F;1501 OpBuffer[obp++]=(char)0x2C;1502 1503 //レジスタ1504 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(xmm_reg));1505 }1506 void op_cvttss2si_xmm(int op_size,int reg,int xmm_reg){1507 //cvttss2si reg,xmm_reg1508 1509 //オペコード1510 OpBuffer[obp++]=(char)0xF3;1511 1512 //rexプリフィックス1513 set_rex(op_size,reg,0,xmm_reg);1514 1515 //オペコード1516 OpBuffer[obp++]=(char)0x0F;1517 OpBuffer[obp++]=(char)0x2C;1518 1519 //レジスタ1520 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(xmm_reg));1521 }1522 void op_cvtsi2sd_reg(int op_size,int xmm_reg,int reg){1523 //cvtsi2sd xmm_reg,reg1524 char RexByte=-1;1525 1526 if(op_size==sizeof(_int64)){1527 if(REG_XMM0<=xmm_reg&&xmm_reg<=REG_XMM7){1528 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;1529 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;1530 }1531 if(REG_XMM8<=xmm_reg&&xmm_reg<=REG_XMM15){1532 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x4C;1533 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x4D;1534 }1535 }1536 else{1537 if(REG_XMM0<=xmm_reg&&xmm_reg<=REG_XMM7){1538 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1539 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1540 }1541 if(REG_XMM8<=xmm_reg&&xmm_reg<=REG_XMM15){1542 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x44;1543 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x45;1544 }1545 }1546 1547 if(RexByte==-1) SetError(300,NULL,cp);1548 1549 1550 //オペコード1551 OpBuffer[obp++]=(char)0xF2;1552 1553 //rexプリフィックス1554 if(RexByte) OpBuffer[obp++]=(char)RexByte;1555 1556 //オペコード1557 OpBuffer[obp++]=(char)0x0F;1558 OpBuffer[obp++]=(char)0x2A;1559 1560 //レジスタ1561 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg)<<3 | REGISTER_OPERAND(reg));1562 }1563 void op_cvtsi2ss_reg(int op_size,int xmm_reg,int reg){1564 //cvtsi2ss xmm_reg,reg1565 char RexByte=-1;1566 1567 if(op_size==sizeof(_int64)){1568 if(REG_XMM0<=xmm_reg&&xmm_reg<=REG_XMM7){1569 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x48;1570 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x49;1571 }1572 if(REG_XMM8<=xmm_reg&&xmm_reg<=REG_XMM15){1573 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x4C;1574 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x4D;1575 }1576 }1577 else{1578 if(REG_XMM0<=xmm_reg&&xmm_reg<=REG_XMM7){1579 if(REG_RAX<=reg&®<=REG_RDI) RexByte=0;1580 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x41;1581 }1582 if(REG_XMM8<=xmm_reg&&xmm_reg<=REG_XMM15){1583 if(REG_RAX<=reg&®<=REG_RDI) RexByte=(char)0x44;1584 if(REG_R8<=reg&®<=REG_R15) RexByte=(char)0x45;1585 }1586 }1587 1588 if(RexByte==-1) SetError(300,NULL,cp);1589 1590 1591 //オペコード1592 OpBuffer[obp++]=(char)0xF3;1593 1594 //rexプリフィックス1595 if(RexByte) OpBuffer[obp++]=(char)RexByte;1596 1597 //オペコード1598 OpBuffer[obp++]=(char)0x0F;1599 OpBuffer[obp++]=(char)0x2A;1600 1601 //レジスタ1602 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg)<<3 | REGISTER_OPERAND(reg));1603 }1604 void op_comisd(int xmm_reg1,int xmm_reg2){1605 //comisd xmm_reg1,xmm_reg21606 1607 //オペコード1608 OpBuffer[obp++]=(char)0x66;1609 OpBuffer[obp++]=(char)0x0F;1610 OpBuffer[obp++]=(char)0x2F;1611 1612 //レジスタ1613 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg1)<<3 | REGISTER_OPERAND(xmm_reg2));1614 }1615 void op_comiss(int xmm_reg1,int xmm_reg2){1616 //comiss xmm_reg1,xmm_reg21617 1618 //オペコード1619 OpBuffer[obp++]=(char)0x0F;1620 OpBuffer[obp++]=(char)0x2F;1621 1622 //レジスタ1623 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(xmm_reg1)<<3 | REGISTER_OPERAND(xmm_reg2));1624 }1625 1626 1627 1628 /////////////////////1629 // ストリング関係1630 /////////////////////1631 1632 void op_rep_movs(int op_size){1633 if(op_size==sizeof(BYTE)){1634 //rep movs byte ptr[edi],byte ptr[esi]1635 OpBuffer[obp++]=(char)0xF3;1636 OpBuffer[obp++]=(char)0xA4;1637 }1638 else if(op_size==sizeof(short)){1639 //rep movs word ptr[edi],word ptr[esi]1640 OpBuffer[obp++]=(char)0xF3;1641 OpBuffer[obp++]=(char)0x66;1642 OpBuffer[obp++]=(char)0xA5;1643 }1644 else if(op_size==sizeof(long)){1645 //rep movs dword ptr[edi],dword ptr[esi]1646 OpBuffer[obp++]=(char)0xF3;1647 OpBuffer[obp++]=(char)0xA5;1648 }1649 }1650 1651 1652 1653 1654 void op_add_rsp(int num){1655 //スタックポインタの加算(pop方向)1656 1657 //add rsp,num1658 if(0xFFFFFF80&num){1659 OpBuffer[obp++]=(char)0x48;1660 OpBuffer[obp++]=(char)0x81;1661 OpBuffer[obp++]=(char)0xC4;1662 *((long *)(OpBuffer+obp))=num;1663 obp+=sizeof(long);1664 }1665 else{1666 //「-128 < num < 127」の場合1667 OpBuffer[obp++]=(char)0x48;1668 OpBuffer[obp++]=(char)0x83;1669 OpBuffer[obp++]=(char)0xC4;1670 OpBuffer[obp++]=(char)num;1671 }1672 }1673 void op_sub_rsp(int num){1674 //スタックポインタの減算(push方向)1675 1676 //sub rsp,num1677 if(0xFFFFFF80&num){1678 OpBuffer[obp++]=(char)0x48;1679 OpBuffer[obp++]=(char)0x81;1680 OpBuffer[obp++]=(char)0xEC;1681 *((long *)(OpBuffer+obp))=num;1682 obp+=sizeof(long);1683 }1684 else{1685 //「-128 < num < 127」の場合1686 OpBuffer[obp++]=(char)0x48;1687 OpBuffer[obp++]=(char)0x83;1688 OpBuffer[obp++]=(char)0xEC;1689 OpBuffer[obp++]=(char)num;1690 }1691 }1692 1693 1694 void op_add_esp(int num){1695 //スタックポインタの加算(pop方向)1696 1697 //add esp,num1698 if(0xFFFFFF80&num){1699 OpBuffer[obp++]=(char)0x81;1700 OpBuffer[obp++]=(char)0xC4;1701 *((long *)(OpBuffer+obp))=num;1702 obp+=sizeof(long);1703 }1704 else{1705 //「-128 < num < 127」の場合1706 OpBuffer[obp++]=(char)0x83;1707 OpBuffer[obp++]=(char)0xC4;1708 OpBuffer[obp++]=(char)num;1709 }1710 }1711 void op_sub_esp(int num){1712 //スタックポインタの減算(push方向)1713 1714 //sub esp,num1715 if(0xFFFFFF80&num){1716 OpBuffer[obp++]=(char)0x81;1717 OpBuffer[obp++]=(char)0xEC;1718 *((long *)(OpBuffer+obp))=num;1719 obp+=sizeof(long);1720 }1721 else{1722 //「-128 < num < 127」の場合1723 OpBuffer[obp++]=(char)0x83;1724 OpBuffer[obp++]=(char)0xEC;1725 OpBuffer[obp++]=(char)num;1726 }1727 }1728 1729 1730 1731 //////////////////////////////1732 // 浮動小数点関連1733 //////////////////////////////1734 1735 void op_fld_ptr_esp(int type){1736 //スタックポインタが示すバッファのデータを浮動小数点レジスタへロード1737 1738 if(type==DEF_DOUBLE){1739 //fld qword ptr[esp]1740 OpBuffer[obp++]=(char)0xDD;1741 OpBuffer[obp++]=(char)0x04;1742 OpBuffer[obp++]=(char)0x24;1743 }1744 else if(type==DEF_SINGLE){1745 //fld dword ptr[esp]1746 OpBuffer[obp++]=(char)0xD9;1747 OpBuffer[obp++]=(char)0x04;1748 OpBuffer[obp++]=(char)0x24;1749 }1750 else if(type==DEF_INT64){1751 //fild qword ptr[esp]1752 OpBuffer[obp++]=(char)0xDF;1753 OpBuffer[obp++]=(char)0x2C;1754 OpBuffer[obp++]=(char)0x24;1755 }1756 else if(type==DEF_LONG){1757 //fild dword ptr[esp]1758 OpBuffer[obp++]=(char)0xDB;1759 OpBuffer[obp++]=(char)0x04;1760 OpBuffer[obp++]=(char)0x24;1761 }1762 }1763 1764 1765 1766 //////////////////////////////1767 // レジスタ関連1768 //////////////////////////////1769 1770 void op_zero_reg(int reg){1771 //レジスタに0をセット1772 1773 if(REG_RAX<=reg&®<=REG_RDI){1774 /* rax~rdi1775 0100 1000 0011 0011 11 xxx xxx */1776 OpBuffer[obp++]=(char)0x48;1777 OpBuffer[obp++]=(char)0x33;1778 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(reg));1779 }1780 if(REG_R8<=reg&®<=REG_R15){1781 /* r8~r151782 0100 1101 0011 0011 11 xxx xxx */1783 OpBuffer[obp++]=(char)0x4D;1784 OpBuffer[obp++]=(char)0x33;1785 OpBuffer[obp++]=(char)(0xC0| REGISTER_OPERAND(reg)<<3 | REGISTER_OPERAND(reg));1786 }1787 }1788 1789 1790 1791 /////////////////////////////1792 // 関数呼び出し1793 /////////////////////////////1794 1795 void op_call( const UserProc *pUserProc ){1796 OpBuffer[obp++] = (char)0xE8;1797 pobj_SubAddrSchedule->add( pUserProc, 1 );1798 pUserProc->Using();1799 obp += sizeof(long);1800 }1801 void op_call( const DllProc *pDllProc ){1802 OpBuffer[obp++] = (char)0xFF;1803 OpBuffer[obp++] = (char)0x15;1804 pobj_ImportAddrSchedule->add(pDllProc);1805 obp += sizeof(long);1806 1807 pDllProc->Using();1808 }1809 void op_ret(){1810 OpBuffer[obp++]=(char)0xC3;1811 } -
trunk/abdev/BasicCompiler64/increment.cpp
r206 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 47 49 if(idCalc==CALC_ADDITION){ 48 50 //インクリメント 49 op_inc(REG_RAX);51 compiler.codeGenerator.op_inc(REG_RAX); 50 52 } 51 53 else if(idCalc==CALC_SUBTRACTION){ 52 54 //デクリメント 53 op_dec(REG_RAX);55 compiler.codeGenerator.op_dec(REG_RAX); 54 56 } 55 57 } -
trunk/abdev/BasicCompiler64/stack_frame.cpp
r220 r226 1 1 #include "stdafx.h" 2 3 #include <Compiler.h> 2 4 3 5 #include "../BasicCompiler_Common/common.h" … … 42 44 void CStackFrame::mov_sp( int reg ){ 43 45 //mov reg,rsp 44 op_mov_RR( reg, REG_RSP );46 compiler.codeGenerator.op_mov_RR( reg, REG_RSP ); 45 47 46 48 //add reg,now_sp 47 op_add_RV( reg, now_sp );49 compiler.codeGenerator.op_add_RV( reg, now_sp ); 48 50 49 51 //スケジュールをセット … … 59 61 60 62 //mov qword ptr[rsp+offset],reg 61 op_mov_MR(sizeof(_int64),reg,REG_RSP,now_sp,MOD_BASE_DISP32);63 compiler.codeGenerator.op_mov_MR(sizeof(_int64),reg,REG_RSP,now_sp,MOD_BASE_DISP32); 62 64 63 65 //スケジュールをセット … … 74 76 if(varSize==sizeof(double)){ 75 77 //movlpd qword ptr[rsp+offset],xmm_reg 76 op_movlpd_MR(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32);78 compiler.codeGenerator.op_movlpd_MR(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32); 77 79 } 78 80 if(varSize==sizeof(float)){ … … 94 96 void CStackFrame::ref_offset_data( int reg, int sp_offset ){ 95 97 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用 96 op_mov_RM(sizeof(_int64),reg,REG_RSP,sp_offset,MOD_BASE_DISP32);98 compiler.codeGenerator.op_mov_RM(sizeof(_int64),reg,REG_RSP,sp_offset,MOD_BASE_DISP32); 97 99 98 100 //スケジュールをセット … … 107 109 if(varSize==sizeof(double)){ 108 110 //movlpd xmm_reg,qword ptr[rsp+offset] 109 op_movlpd_RM(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32);111 compiler.codeGenerator.op_movlpd_RM(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32); 110 112 } 111 113 if(varSize==sizeof(float)){ -
trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h
r225 r226 32 32 33 33 #ifdef _AMD64_ 34 private: 35 void set_rex(int op_size,int reg,int index_reg,int base_reg); 36 void set_mod_rm_sib_disp(char mod,int reg,int scale,int index_reg,int base_reg,long disp); 37 void __op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod); 38 public: 39 void op_mov_RV (int op_size,int reg,long i32data); 40 void op_mov_RV64 (int reg,_int64 i64data); 41 void op_mov_RM (int op_size,int reg,int base_reg,long offset,char mod); 42 void op_mov_RM_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset); 43 void op_mov_MR (int op_size,int reg,int base_reg,long offset,char mod); 44 void op_mov_MR_ex (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset); 45 void op_mov_MV (int op_size,int base_reg,int offset,BOOL bUseOffset,long i32data); 46 void op_mov_RR (int reg1,int reg2); 47 void op_mov64_ToReg (int reg,_int64 i64data); 48 void op_mov64_ToReg (int reg,long i32data); 49 void op_movsxd (int reg64,int reg32); 50 void op_movsx64_FromReg16 (int reg64,int reg16); 51 void op_movsx64_FromReg8 (int reg64,int reg8); 52 void op_movsx32_FromReg16 (int reg32,int reg16); 53 void op_movsx32_FromReg8 (int reg32,int reg8); 54 void op_movsx16_FromReg8 (int reg32,int reg8); 55 void op_inc (int reg); 56 void op_dec (int reg); 57 void op_add_RM (int op_size,int reg,int base_reg,int offset,char mod); 58 void op_add_RV (int reg,long offset); 59 void op_add64_reg (int reg1,int reg2); 60 void op_add32_reg (int reg1,int reg2); 61 void op_sub_RV (int op_size,int reg,long i32data); 62 void op_sub64_reg (int reg1,int reg2); 63 void op_sub32_reg (int reg1,int reg2); 64 void op_sbb_RR ( int op_size, int reg1, int reg2 ); 65 void op_imul_RR (int op_size,int reg1,int reg2); 66 void op_imul_RV (int op_size,int reg,long i32data); 67 void op_div64_reg (int reg); 68 void op_idiv64_reg (int reg); 69 void op_shl_reg (int op_size,int reg); 70 void op_sar_reg (int op_size,int reg); 71 void op_shr_reg (int op_size,int reg); 72 void op_and_reg (int op_size,int reg1,int reg2); 73 void op_and64_value (int reg,long offset); 74 void op_and32_value (int reg,long offset); 75 void op_or_reg (int op_size,int reg1,int reg2); 76 void op_xor_reg (int op_size,int reg1,int reg2); 77 void op_not_reg (int op_size,int reg); 78 void op_neg ( int reg ); 79 void op_test (int reg1,int reg2); 80 void op_cmp_reg (int op_size,int reg1,int reg2); 81 void op_cmp_value (int op_size,int reg,char byte_data); 82 void op_setne (int reg); 83 void op_movlpd_MR (int xmm_reg,int base_reg,int offset,char mod); 84 void op_movlpd_RM (int xmm_reg,int base_reg,int offset,char mod); 85 void op_movsd_RR (int xmm_reg1,int xmm_reg2); 86 void op_movsd_MR (int xmm_reg,int base_reg,int offset,char mod); 87 void op_movss_RR (int xmm_reg1,int xmm_reg2); 88 void op_movss_RM (int xmm_reg,int base_reg,int offset,char mod); 89 void op_movss_MR (int xmm_reg,int base_reg,int offset,char mod); 90 void op_movd_RX (int reg,int xmm_reg); 91 void op_cvtsd2ss (int xmm_reg1,int xmm_reg2); 92 void op_cvtss2sd (int xmm_reg1,int xmm_reg2); 93 void op_cvttsd2si_xmm (int op_size,int reg,int xmm_reg); 94 void op_cvttss2si_xmm (int op_size,int reg,int xmm_reg); 95 void op_cvtsi2sd_reg (int op_size,int xmm_reg,int reg); 96 void op_cvtsi2ss_reg (int op_size,int xmm_reg,int reg); 97 void op_comisd (int xmm_reg1,int xmm_reg2); 98 void op_comiss (int xmm_reg1,int xmm_reg2); 99 void op_rep_movs (int op_size); 100 void op_add_rsp(long num); 101 void op_sub_rsp(long num); 102 void op_add_esp(long num); 103 void op_sub_esp(long num); 104 void op_fld_ptr_esp(int type); 105 void op_zero_reg(int reg); 106 void op_call( const UserProc *pUserProc ); 107 void op_call( const DllProc *pDllProc ); 108 void op_ret(); 109 34 110 #else 35 111 private: -
trunk/abdev/BasicCompiler_Common/include/NativeCode.h
r225 r226 132 132 extern char *OpBuffer; 133 133 extern int obp; 134 memcpy( OpBuffer , codeBuffer, size );134 memcpy( OpBuffer + obp, codeBuffer, size ); 135 135 obp += size; 136 136 } … … 139 139 Put( nativeCode.codeBuffer, nativeCode.size ); 140 140 } 141 void Put( char c)141 void Put( _int64 i64data ) 142 142 { 143 codeBuffer[size++] = c; 144 Realloc(); 145 146 147 148 // 未完成 149 extern char *OpBuffer; 150 extern int obp; 151 OpBuffer[obp++]=c; 143 Put( (const char *)(&i64data), sizeof(_int64) ); 152 144 } 153 145 void Put( long l, Schedule::Type scheduleType = Schedule::None ) … … 169 161 obp+=sizeof(long); 170 162 } 163 void Put( short s ) 164 { 165 Put( (const char *)(&s), sizeof(short) ); 166 } 167 void Put( char c ) 168 { 169 codeBuffer[size++] = c; 170 Realloc(); 171 172 173 174 // 未完成 175 extern char *OpBuffer; 176 extern int obp; 177 OpBuffer[obp++]=c; 178 } 171 179 }; -
trunk/abdev/BasicCompiler_Common/src/LexicalScopingImpl.cpp
r225 r226 98 98 99 99 //mov rcx,qword ptr[rsp+offset] 100 op_mov_RM(sizeof(_int64),REG_RCX,REG_RSP,100 compiler.codeGenerator.op_mov_RM(sizeof(_int64),REG_RCX,REG_RSP, 101 101 -pVar->GetOffsetAddress(), 102 102 MOD_BASE_DISP32);
Note:
See TracChangeset
for help on using the changeset viewer.