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

Last change on this file since 400 was 308, 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
[308]13StackFrame::StackFrame(){
[3]14 lowest_sp=0;
15 now_sp=0;
16 max_parm_size=0;
17}
[308]18StackFrame::~StackFrame(){
[3]19 //オブジェクト破棄時に不整合がないかをチェック(バグ回避)
20 error_check();
21}
[308]22int StackFrame::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}
[308]33int StackFrame::GetNowSp(){
[64]34 return now_sp;
35}
[308]36void StackFrame::mov_sp( int reg ){
[64]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}
[308]45int StackFrame::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}
[308]58void StackFrame::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}
[308]75void StackFrame::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}
[308]81void StackFrame::ref(int reg){
[20]82 ref_offset_data( reg, now_sp );
83}
[308]84void StackFrame::ref(int xmm_reg,int varSize){
[66]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}
[308]98void StackFrame::pop(int reg){
[3]99 if(reg!=REG_NON) ref(reg);
100
101 now_sp+=sizeof(_int64);
102}
[308]103void StackFrame::pop(int xmm_reg,int varSize){
[66]104 ref(xmm_reg,varSize);
[3]105
106 now_sp+=sizeof(_int64);
107}
[308]108void StackFrame::parameter_allocate(int size){
[3]109 if(max_parm_size<size) max_parm_size=size;
110}
[308]111void StackFrame::RunningSchedule( int stackFrameSize ){
[263]112 BOOST_FOREACH( const PertialSchedule *pPertialSchedule, pertialSchedules )
113 {
114 compiler.codeGenerator.opfix_offset( pPertialSchedule, stackFrameSize );
[3]115 }
116}
117
[308]118void StackFrame::error_check(){
[3]119 if(now_sp){
120 SetError(300,NULL,cp);
121 }
122}
123
124//スタックフレーム管理用オブジェクトポインタ
[308]125StackFrame *pobj_sf;
Note: See TracBrowser for help on using the repository browser.