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

Last change on this file since 274 was 263, checked in by dai_9181, 17 years ago
File size: 3.3 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
[263]41 pertialSchedules.push_back(
42 compiler.codeGenerator.op_add_RV( reg, now_sp, Schedule::None, true )
43 );
[64]44}
[20]45int CStackFrame::push(int reg){
[3]46 now_sp-=sizeof(_int64);
47 if(lowest_sp>now_sp) lowest_sp=now_sp;
48
[20]49 if(reg==REG_NON) return now_sp;
[3]50
51 //mov qword ptr[rsp+offset],reg
[263]52 pertialSchedules.push_back(
53 compiler.codeGenerator.op_mov_MR(sizeof(_int64),reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true)
54 );
[3]55
[20]56 return now_sp;
[3]57}
[66]58void CStackFrame::push(int xmm_reg,int varSize){
[3]59 now_sp-=sizeof(_int64);
60 if(lowest_sp>now_sp) lowest_sp=now_sp;
61
[66]62 if(varSize==sizeof(double)){
[3]63 //movlpd qword ptr[rsp+offset],xmm_reg
[263]64 pertialSchedules.push_back(
65 compiler.codeGenerator.op_movlpd_MR(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true )
66 );
[3]67 }
[66]68 if(varSize==sizeof(float)){
[3]69 //movss dword ptr[rsp+offset],xmm_reg
[263]70 pertialSchedules.push_back(
71 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32, Schedule::None, true )
72 );
[3]73 }
74}
[20]75void CStackFrame::ref_offset_data( int reg, int sp_offset ){
[3]76 //mov reg,qword ptr[rsp+offset] ※スタックフレームを利用
[263]77 pertialSchedules.push_back(
78 compiler.codeGenerator.op_mov_RM(sizeof(_int64),reg,REG_RSP,sp_offset,MOD_BASE_DISP32, Schedule::None, true )
79 );
[3]80}
[20]81void CStackFrame::ref(int reg){
82 ref_offset_data( reg, now_sp );
83}
[66]84void CStackFrame::ref(int xmm_reg,int varSize){
85 if(varSize==sizeof(double)){
[3]86 //movlpd xmm_reg,qword ptr[rsp+offset]
[263]87 pertialSchedules.push_back(
88 compiler.codeGenerator.op_movlpd_RM(xmm_reg,REG_RSP,now_sp,MOD_BASE_DISP32, Schedule::None, true )
89 );
[3]90 }
[66]91 if(varSize==sizeof(float)){
[3]92 //movss xmm_reg,dword ptr[rsp+offset]
[263]93 pertialSchedules.push_back(
94 compiler.codeGenerator.op_movss_MR( xmm_reg, REG_RSP, now_sp, MOD_BASE_DISP32, Schedule::None, true )
95 );
[3]96 }
97}
98void CStackFrame::pop(int reg){
99 if(reg!=REG_NON) ref(reg);
100
101 now_sp+=sizeof(_int64);
102}
[66]103void CStackFrame::pop(int xmm_reg,int varSize){
104 ref(xmm_reg,varSize);
[3]105
106 now_sp+=sizeof(_int64);
107}
108void CStackFrame::parameter_allocate(int size){
109 if(max_parm_size<size) max_parm_size=size;
110}
[220]111void CStackFrame::RunningSchedule( int stackFrameSize ){
[263]112 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, pertialSchedules )
113 {
114 compiler.codeGenerator.opfix_offset( pPertialSchedule, stackFrameSize );
[3]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.