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

Last change on this file since 210 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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