source: dev/trunk/abdev/BasicCompiler64/stack_frame.cpp@ 244

Last change on this file since 244 was 232, checked in by dai_9181, 17 years ago
File size: 3.2 KB
RevLine 
[206]1#include "stdafx.h"
2
[226]3#include <Compiler.h>
4
[3]5#include "../BasicCompiler_Common/common.h"
6#include "Opcode.h"
7
8
9/////////////////////////
10// スタックフレーム管理
11/////////////////////////
12
13CStackFrame::CStackFrame(){
14 lowest_sp=0;
15 now_sp=0;
16 max_parm_size=0;
17}
18CStackFrame::~CStackFrame(){
19 //オブジェクト破棄時に不整合がないかをチェック(バグ回避)
20 error_check();
21}
[220]22int CStackFrame::GetFrameSize( int localParamSize ){
[3]23 int answer_sp;
24
25 answer_sp=lowest_sp-max_parm_size;
26
[232]27 if(((answer_sp-localParamSize)%0x10)==0){
[3]28 //関数のエントリポイントで128ビット境界ラインに合わせるため
[232]29 return -(answer_sp-0x08);
[3]30 }
[232]31 return -(answer_sp-0x10);
[3]32}
[64]33int CStackFrame::GetNowSp(){
34 return now_sp;
35}
36void CStackFrame::mov_sp( int reg ){
37 //mov reg,rsp
[226]38 compiler.codeGenerator.op_mov_RR( reg, REG_RSP );
[64]39
40 //add reg,now_sp
[226]41 compiler.codeGenerator.op_add_RV( reg, now_sp );
[64]42
43 //スケジュールをセット
44 obp-=sizeof(long);
45 add();
46 obp+=sizeof(long);
47}
[20]48int CStackFrame::push(int reg){
[3]49 now_sp-=sizeof(_int64);
50 if(lowest_sp>now_sp) lowest_sp=now_sp;
51
[20]52 if(reg==REG_NON) return now_sp;
[3]53
54 //mov qword ptr[rsp+offset],reg
[226]55 compiler.codeGenerator.op_mov_MR(sizeof(_int64),reg,REG_RSP,now_sp,MOD_BASE_DISP32);
[3]56
57 //スケジュールをセット
58 obp-=sizeof(long);
59 add();
60 obp+=sizeof(long);
[20]61
62 return now_sp;
[3]63}
[66]64void CStackFrame::push(int xmm_reg,int varSize){
[3]65 now_sp-=sizeof(_int64);
66 if(lowest_sp>now_sp) lowest_sp=now_sp;
67
[66]68 if(varSize==sizeof(double)){
[3]69 //movlpd qword ptr[rsp+offset],xmm_reg
[226]70 compiler.codeGenerator.op_movlpd_MR(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32);
[3]71 }
[66]72 if(varSize==sizeof(float)){
[3]73 //movss dword ptr[rsp+offset],xmm_reg
[228]74 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32 );
[3]75 }
76
77 //スケジュールをセット
78 obp-=sizeof(long);
79 add();
80 obp+=sizeof(long);
81}
[20]82void CStackFrame::ref_offset_data( int reg, int sp_offset ){
[3]83 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用
[226]84 compiler.codeGenerator.op_mov_RM(sizeof(_int64),reg,REG_RSP,sp_offset,MOD_BASE_DISP32);
[3]85
86 //スケジュールをセット
87 obp-=sizeof(long);
88 add();
89 obp+=sizeof(long);
90}
[20]91void CStackFrame::ref(int reg){
92 ref_offset_data( reg, now_sp );
93}
[66]94void CStackFrame::ref(int xmm_reg,int varSize){
95 if(varSize==sizeof(double)){
[3]96 //movlpd xmm_reg,qword ptr[rsp+offset]
[226]97 compiler.codeGenerator.op_movlpd_RM(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32);
[3]98 }
[66]99 if(varSize==sizeof(float)){
[3]100 //movss xmm_reg,dword ptr[rsp+offset]
[228]101 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32 );
[3]102 }
103
104 //スケジュールをセット
105 obp-=sizeof(long);
106 add();
107 obp+=sizeof(long);
108}
109void CStackFrame::pop(int reg){
110 if(reg!=REG_NON) ref(reg);
111
112 now_sp+=sizeof(_int64);
113}
[66]114void CStackFrame::pop(int xmm_reg,int varSize){
115 ref(xmm_reg,varSize);
[3]116
117 now_sp+=sizeof(_int64);
118}
119void CStackFrame::parameter_allocate(int size){
120 if(max_parm_size<size) max_parm_size=size;
121}
[220]122void CStackFrame::RunningSchedule( int stackFrameSize ){
123 for(int i=0;i<num;i++){
124 *((long *)(OpBuffer+pObpValues[i])) += stackFrameSize;
[3]125 }
126}
127
128void CStackFrame::error_check(){
129 if(now_sp){
130 SetError(300,NULL,cp);
131 }
132}
133
134//スタックフレーム管理用オブジェクトポインタ
135CStackFrame *pobj_sf;
Note: See TracBrowser for help on using the repository browser.