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

Last change on this file since 277 was 263, checked in by dai_9181, 17 years ago
File size: 3.3 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
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}
22int CStackFrame::GetFrameSize( int localParamSize ){
23 int answer_sp;
24
25 answer_sp=lowest_sp-max_parm_size;
26
27 if(((answer_sp-localParamSize)%0x10)==0){
28 //関数のエントリポイントで128ビット境界ラインに合わせるため
29 return -(answer_sp-0x08);
30 }
31 return -(answer_sp-0x10);
32}
33int CStackFrame::GetNowSp(){
34 return now_sp;
35}
36void CStackFrame::mov_sp( int reg ){
37 //mov reg,rsp
38 compiler.codeGenerator.op_mov_RR( reg, REG_RSP );
39
40 //add reg,now_sp
41 pertialSchedules.push_back(
42 compiler.codeGenerator.op_add_RV( reg, now_sp, Schedule::None, true )
43 );
44}
45int CStackFrame::push(int reg){
46 now_sp-=sizeof(_int64);
47 if(lowest_sp>now_sp) lowest_sp=now_sp;
48
49 if(reg==REG_NON) return now_sp;
50
51 //mov qword ptr[rsp+offset],reg
52 pertialSchedules.push_back(
53 compiler.codeGenerator.op_mov_MR(sizeof(_int64),reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true)
54 );
55
56 return now_sp;
57}
58void CStackFrame::push(int xmm_reg,int varSize){
59 now_sp-=sizeof(_int64);
60 if(lowest_sp>now_sp) lowest_sp=now_sp;
61
62 if(varSize==sizeof(double)){
63 //movlpd qword ptr[rsp+offset],xmm_reg
64 pertialSchedules.push_back(
65 compiler.codeGenerator.op_movlpd_MR(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true )
66 );
67 }
68 if(varSize==sizeof(float)){
69 //movss dword ptr[rsp+offset],xmm_reg
70 pertialSchedules.push_back(
71 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32, Schedule::None, true )
72 );
73 }
74}
75void CStackFrame::ref_offset_data( int reg, int sp_offset ){
76 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用
77 pertialSchedules.push_back(
78 compiler.codeGenerator.op_mov_RM(sizeof(_int64),reg,REG_RSP,sp_offset,MOD_BASE_DISP32, Schedule::None, true )
79 );
80}
81void CStackFrame::ref(int reg){
82 ref_offset_data( reg, now_sp );
83}
84void CStackFrame::ref(int xmm_reg,int varSize){
85 if(varSize==sizeof(double)){
86 //movlpd xmm_reg,qword ptr[rsp+offset]
87 pertialSchedules.push_back(
88 compiler.codeGenerator.op_movlpd_RM(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true )
89 );
90 }
91 if(varSize==sizeof(float)){
92 //movss xmm_reg,dword ptr[rsp+offset]
93 pertialSchedules.push_back(
94 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32, Schedule::None, true )
95 );
96 }
97}
98void CStackFrame::pop(int reg){
99 if(reg!=REG_NON) ref(reg);
100
101 now_sp+=sizeof(_int64);
102}
103void CStackFrame::pop(int xmm_reg,int varSize){
104 ref(xmm_reg,varSize);
105
106 now_sp+=sizeof(_int64);
107}
108void CStackFrame::parameter_allocate(int size){
109 if(max_parm_size<size) max_parm_size=size;
110}
111void CStackFrame::RunningSchedule( int stackFrameSize ){
112 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, pertialSchedules )
113 {
114 compiler.codeGenerator.opfix_offset( pPertialSchedule, stackFrameSize );
115 }
116}
117
118void CStackFrame::error_check(){
119 if(now_sp){
120 SetError(300,NULL,cp);
121 }
122}
123
124//スタックフレーム管理用オブジェクトポインタ
125CStackFrame *pobj_sf;
Note: See TracBrowser for help on using the repository browser.