source: dev/BasicCompiler64/stack_frame.cpp@ 6

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