Changeset 436 in dev for trunk/abdev/BasicCompiler64
- Timestamp:
- Mar 15, 2008, 3:33:36 PM (17 years ago)
- Location:
- trunk/abdev/BasicCompiler64
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler64/CParameter.cpp
r331 r436 65 65 int reg = REG_RAX; 66 66 Type calcType; 67 NumOpe( ®, Parms[i2], dummyType, calcType ); 67 bool isNeedHeapFreeStructure; 68 NumOpe( ®, Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure ); 68 69 69 70 if( !calcType.IsStruct() ){ … … 86 87 i2); 87 88 88 if( result ){ 89 if( result ) 90 { 89 91 useTempParameters[i2] = true; 92 isNeedFreeStructures[i2] = isNeedHeapFreeStructure; 90 93 useTempObject = true; 91 94 … … 109 112 // 構造体の一時メモリ 110 113 111 //メモリを解放する 112 113 pobj_sf->pop( REG_RCX ); 114 115 //call free 116 extern const UserProc *pSub_free; 117 compiler.codeGenerator.op_call(pSub_free); 118 } 119 else{ 114 if( isNeedFreeStructures[i2] ) 115 { 116 //メモリを解放する 117 118 pobj_sf->pop( REG_RCX ); 119 120 //call free 121 extern const UserProc *pSub_free; 122 compiler.codeGenerator.op_call(pSub_free); 123 } 124 else 125 { 126 pobj_sf->pop(); 127 } 128 } 129 else 130 { 120 131 pobj_sf->pop(); 121 132 pobj_sf->pop(); … … 148 159 149 160 Type calcType; 150 BOOL bUseHeap;161 bool isNeedHeapFreeStructure; 151 162 int temp_reg=REG_RAX; 152 163 NumOpe( &temp_reg, … … 154 165 baseType, 155 166 calcType, 156 & bUseHeap);167 &isNeedHeapFreeStructure ); 157 168 158 169 … … 169 180 baseType, 170 181 calcType, 171 &RelativeVar, bUseHeap);182 &RelativeVar,isNeedHeapFreeStructure); 172 183 173 184 … … 282 293 temp_reg=reg; 283 294 284 BOOL bCalcUseHeap;285 295 Type calcType; 286 if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &bCalcUseHeap ) ){ 296 bool isNeedHeapFreeStructure; 297 if( !NumOpe( &temp_reg, Parms[i2], dummyType, calcType, &isNeedHeapFreeStructure ) ){ 287 298 break; 288 299 } … … 294 305 !dummyType.GetClass().IsEqualsOrSubClass( &calcType.GetClass() ) ){ 295 306 //キャスト演算子のオーバーロードに対応する 296 CallCastOperatorProc( reg, calcType, bCalcUseHeap,dummyType );307 CallCastOperatorProc( reg, calcType, isNeedHeapFreeStructure,dummyType ); 297 308 } 298 309 } -
trunk/abdev/BasicCompiler64/Compile_Calc.cpp
r417 r436 190 190 //NumOpe...(rax、またはxmm0に答えが格納される) 191 191 int reg=REG_RAX; 192 BOOL bCalcUseHeap;193 192 Type calcType; 194 if( !NumOpe(®,Command+i+1,varType,calcType,&bCalcUseHeap) ){ 193 bool isNeedHeapFreeStructure; 194 if( !NumOpe(®,Command+i+1,varType,calcType,&isNeedHeapFreeStructure) ){ 195 195 return; 196 196 } … … 222 222 if( varType.IsStruct() ){ 223 223 //構造体インスタンスへの代入 224 SetStructVariableFromRax(varType,calcType,&VarRelativeVar, bCalcUseHeap);224 SetStructVariableFromRax(varType,calcType,&VarRelativeVar,isNeedHeapFreeStructure); 225 225 return; 226 226 } … … 235 235 if( !isUpCast ){ 236 236 //キャスト演算子のオーバーロードに対応する 237 CallCastOperatorProc(REG_RAX,calcType, bCalcUseHeap,varType);237 CallCastOperatorProc(REG_RAX,calcType,isNeedHeapFreeStructure,varType); 238 238 } 239 239 } … … 269 269 ///////////////////////////////////////////////// 270 270 SetVariableFromRax(varType,calcType.GetBasicType(),&VarRelativeVar); 271 272 273 // コード生成過程で発生した構造体の一時メモリを破棄する 274 compiler.codeGenerator.op_FreeTempStructure(); 271 275 } -
trunk/abdev/BasicCompiler64/Compile_CallProc.cpp
r420 r436 322 322 if(lstrcmpi(ObjectName,"Super")==0) goto InClassMember; 323 323 else{ 324 bool isLiteral ;324 bool isLiteral, isNeedHeapFreeStructure = false; 325 325 Type baseType( DEF_OBJECT, *pUserProc->GetParentClassPtr() ) , resultType; 326 if( !TermOpe( ObjectName, baseType, resultType, isLiteral, NULL, NULL, false, !pMethod->IsConst() ) )326 if( !TermOpe( ObjectName, baseType, resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, !pMethod->IsConst() ) ) 327 327 { 328 328 return false; 329 } 330 if( !resultType.IsObject() ) 331 { 332 SetError(); 329 333 } 330 334 -
trunk/abdev/BasicCompiler64/Compile_Statement.cpp
r425 r436 95 95 96 96 Type resultType; 97 bool isLiteral; 98 BOOL bUseHeap; 99 bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, NULL, true ); 97 bool isLiteral, isNeedHeapFreeStructure = false; 98 bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, true ); 100 99 101 100 delete pobj_reg; -
trunk/abdev/BasicCompiler64/Compile_Var.cpp
r425 r436 142 142 int reg=REG_NON; 143 143 Type type; 144 BOOL bUseHeap; 145 NumOpe( ®, pParm[i], Type( DEF_LONG ), type, &bUseHeap ); 146 if( type.IsObject() ){ 144 bool isNeedHeapFreeStructure; 145 NumOpe( ®, pParm[i], Type( DEF_LONG ), type, &isNeedHeapFreeStructure ); 146 if( type.IsObject() ) 147 { 147 148 //キャスト演算子のオーバーロードに対応する 148 149 CallCastOperatorProc(reg, 149 150 type, 150 bUseHeap, Type(DEF_LONG) );151 isNeedHeapFreeStructure, Type(DEF_LONG) ); 151 152 type.SetBasicType( DEF_LONG ); 152 153 } 153 154 154 if( !type.IsWhole() ){ 155 if( !type.IsWhole() ) 156 { 155 157 SetError(46,NULL,cp); 156 158 } -
trunk/abdev/BasicCompiler64/MakePeHdr.cpp
r423 r436 33 33 *pSub_System_GC_malloc_ForObjectPtr, 34 34 *pSub_System_GC_free_for_SweepingDelete, 35 *pSub_System_AddNeedFreeTempStructure, 36 *pSub_System_FreeTempStructure, 35 37 *pSubStaticMethod_System_TypeBase_InitializeUserTypes, 36 38 *pSubStaticMethod_System_TypeBase_InitializeUserTypesForBaseType; … … 266 268 if( pSub_System_GC_free_for_SweepingDelete = GetSubHash( "_System_GC_free_for_SweepingDelete",1 ) ) 267 269 pSub_System_GC_free_for_SweepingDelete->Using(); 270 271 if( pSub_System_AddNeedFreeTempStructure = GetSubHash( "_System_AddNeedFreeTempStructure",1 ) ) 272 { 273 pSub_System_AddNeedFreeTempStructure->Using(); 274 } 275 if( pSub_System_FreeTempStructure = GetSubHash( "_System_FreeTempStructure",1 ) ) 276 { 277 pSub_System_FreeTempStructure->Using(); 278 } 268 279 269 280 if( pSubStaticMethod_System_TypeBase_InitializeUserTypes = GetSubHash( "ActiveBasic.Core._System_TypeBase.InitializeUserTypes",1 ) ){ -
trunk/abdev/BasicCompiler64/NumOpe.cpp
r430 r436 130 130 return true; 131 131 } 132 bool TermMemberOpe( const Type &leftType, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar )132 bool TermMemberOpe( const Type &leftType, bool &isNeedHeapFreeStructure, const Type &baseType, Type &resultType, const char *termFull, const char *termLeft, const char *member, bool &isVariable, RELATIVE_VAR &relativeVar ) 133 133 { 134 134 const CClass &objClass = leftType.GetClass(); … … 218 218 // メンバが見つかったとき 219 219 220 if( isNeedHeapFreeStructure ) 221 { 222 if( !leftType.IsStruct() ) 223 { 224 SetError(); 225 } 226 227 pobj_reg->LockReg(); 228 229 // 親となる構造体が一時メモリに存在していた場合、後ほど解放する必要がある 230 compiler.codeGenerator.op_AddNeedFreeTempStructure( useReg ); 231 isNeedHeapFreeStructure = false; 232 233 pobj_reg->UnlockReg(); 234 } 235 220 236 //オブジェクトポインタをr11にコピー 221 237 compiler.codeGenerator.op_mov_RR( REG_R11, useReg ); … … 267 283 bool dummyIsVariable; 268 284 RELATIVE_VAR dummyRelativeVar; 269 TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar );285 TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, methodName, dummyIsVariable, dummyRelativeVar ); 270 286 271 287 // 戻り値のオブジェクトインスタンスのインデクサを呼び出す … … 274 290 sprintf( temp2, "%s.%s", termLeft, methodName ); 275 291 Type classType = resultType; 276 return TermMemberOpe( classType, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar );292 return TermMemberOpe( classType, isNeedHeapFreeStructure, baseType, resultType, termFull, temp2, temporary, isVariable, relativeVar ); 277 293 } 278 294 … … 344 360 return false; 345 361 } 346 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess )362 bool _TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool &isVariable, RELATIVE_VAR &relativeVar, bool isWriteAccess ) 347 363 { 348 364 char parameter[VN_SIZE]; … … 385 401 } 386 402 387 if( !TermOpe( termLeft, baseType, leftType, isLiteral, pbUseHeap, &isClassName ) ){403 if( !TermOpe( termLeft, baseType, leftType, isLiteral, isNeedHeapFreeStructure, &isClassName ) ){ 388 404 goto globalArea; 389 405 } … … 403 419 } 404 420 405 return TermMemberOpe( leftType, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar );421 return TermMemberOpe( leftType, isNeedHeapFreeStructure, baseType, resultType, termFull, termLeft, member, isVariable, relativeVar ); 406 422 } 407 423 globalArea: … … 500 516 }//////////////////////////////////////////// 501 517 502 if(resultType.IsStruct()){ 518 if(resultType.IsStruct()) 519 { 503 520 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 504 521 //※後にfreeする必要あり 505 522 // TODO: 解放はGCに任せる 506 *pbUseHeap = 1;523 isNeedHeapFreeStructure = true; 507 524 } 508 525 … … 628 645 }//////////////////////////////////////////// 629 646 630 if(resultType.IsStruct()){ 647 if(resultType.IsStruct()) 648 { 631 649 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 632 650 //※後にfreeする必要あり 633 651 // TODO: 解放はGCに任せる 634 *pbUseHeap = 1;652 isNeedHeapFreeStructure = true; 635 653 } 636 654 … … 648 666 } 649 667 650 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, BOOL *pbUseHeap, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess )668 bool TermOpe( const char *term, const Type &baseType, Type &resultType, bool &isLiteral, bool &isNeedHeapFreeStructure, bool *pIsClassName, bool isProcedureCallOnly, bool isWriteAccess ) 651 669 { 652 670 bool isInitRegSwitch = false; … … 665 683 RELATIVE_VAR relativeVar; 666 684 bool isVariable = false; 667 bool result = _TermOpe( term, baseType, resultType, isLiteral, pbUseHeap, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess );685 bool result = _TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructure, pIsClassName, isProcedureCallOnly, isVariable, relativeVar, isWriteAccess ); 668 686 669 687 if( isVariable ) … … 705 723 pobj_reg = new CRegister( REG_NON ); 706 724 707 bool isLiteral, isVariable = false ;708 bool result = _TermOpe( term, Type(), resultType, isLiteral, NULL, NULL, false, isVariable, relativeVar, isWriteAccess );725 bool isLiteral, isVariable = false, isNeedHeapFreeStructure = false; 726 bool result = _TermOpe( term, Type(), resultType, isLiteral, isNeedHeapFreeStructure, NULL, false, isVariable, relativeVar, isWriteAccess ); 709 727 710 728 if( !isVariable ) … … 731 749 const Type &baseType, 732 750 Type &resultType, 733 BOOL *pbUseHeap)751 bool *pbIsNeedHeapFreeStructure ) 734 752 { 735 753 int i,i2,i3; … … 892 910 LONG_PTR index_stack[255]; 893 911 bool isNothing_stack[255]; 894 BOOL bUseHeap[255];912 bool isNeedHeapFreeStructureStack[255]; 895 913 _int64 i64data; 896 914 int UseReg,XmmReg; … … 916 934 else{ 917 935 //オーバーロードされたオペレータを呼び出す 918 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack, bUseHeap,sp);936 i2=CallOperatorProc(idCalc,baseType,type_stack,index_stack,isNeedHeapFreeStructureStack,sp); 919 937 if(i2==0){ 920 938 if(idCalc==CALC_EQUAL) lstrcpy(temp2,"=="); … … 938 956 index_stack[sp]=-1; 939 957 isNothing_stack[sp] = false; 940 bUseHeap[sp]=0;958 isNeedHeapFreeStructureStack[sp] = false; 941 959 942 960 UseReg=pobj_reg->GetNextReg(); … … 1041 1059 1042 1060 bool isLiteral; 1043 if( TermOpe( term, baseType, resultType, isLiteral, &bUseHeap[sp] ) ){1061 if( TermOpe( term, baseType, resultType, isLiteral, isNeedHeapFreeStructureStack[sp] ) ){ 1044 1062 if(resultType.IsNull()){ 1045 1063 //戻り値が存在しないとき … … 1346 1364 } 1347 1365 1348 if(pbUseHeap) *pbUseHeap=bUseHeap[0]; 1366 if( pbIsNeedHeapFreeStructure ) 1367 { 1368 *pbIsNeedHeapFreeStructure = isNeedHeapFreeStructureStack[0]; 1369 } 1349 1370 1350 1371 if(IsRealNumberType(type_stack[0])) … … 1386 1407 const Type &baseType, 1387 1408 Type &resultType, 1388 BOOL *pbUseHeap)1409 bool *pbIsNeedHeapFreeStructure ) 1389 1410 { 1390 1411 bool isInitRegSwitch = false; … … 1403 1424 1404 1425 1405 bool result = _numope( pReg, expression, baseType, resultType, pb UseHeap);1426 bool result = _numope( pReg, expression, baseType, resultType, pbIsNeedHeapFreeStructure ); 1406 1427 1407 1428 -
trunk/abdev/BasicCompiler64/Opcode.h
r425 r436 191 191 Type &resultType, 192 192 bool &isLiteral, 193 BOOL *pbUseHeap,193 bool &isNeedHeapFreeStructure, 194 194 bool *pIsClassName = NULL, 195 195 bool isProcedureCallOnly = false, … … 199 199 const Type &baseType, 200 200 Type &resultType, 201 BOOL *pbUseHeap= NULL );201 bool *pbIsNeedHeapFreeStructure = NULL ); 202 202 203 203 //NumOpe_Arithmetic.cpp … … 276 276 bool useTempObject; 277 277 bool useTempParameters[255]; 278 bool isNeedFreeStructures[255]; 278 279 int StackOffsetOfTempObject[255]; 279 280 … … 337 338 //OperatorProc.cpp 338 339 void FreeTempObject(int reg,const CClass *pobj_c); 339 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack, BOOL *bUseHeap,int &sp);340 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp); 340 341 void CallCastOperatorProc(int reg,Type &calcType,BOOL bCalcUseHeap,const Type &toType); 341 342 void CallIndexerGetterProc(int reg, const Type &classType, const char *ObjectName,char *Parameter,Type &resultType, DWORD dwProcFlags = 0 ); -
trunk/abdev/BasicCompiler64/OperatorProc.cpp
r425 r436 31 31 } 32 32 33 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack, BOOL *bUseHeap,int &sp)33 int CallOperatorProc(BYTE idCalc, const Type &baseType, int *type_stack,LONG_PTR *index_stack,bool isNeedHeapFreeStructureStack[],int &sp) 34 34 { 35 35 Type leftType( type_stack[sp-2], index_stack[sp-2] ); … … 101 101 if( pUserProc->RealParams()[1]->IsStruct() &&pUserProc->RealParams()[1]->IsRef() == false ){ 102 102 //一時オブジェクトはメソッド内で破棄される 103 bUseHeap[sp-1]=0;103 isNeedHeapFreeStructureStack[sp-1] = false; 104 104 } 105 105 } … … 153 153 154 154 //ヒープ解放用に退避 155 if( bUseHeap[sp-1]){155 if(isNeedHeapFreeStructureStack[sp-1]){ 156 156 //mov qword ptr[rsp+offset],reg2 ※スタックフレームを利用 157 157 pobj_sf->push(reg2); 158 158 } 159 if( bUseHeap[sp-2]){159 if(isNeedHeapFreeStructureStack[sp-2]){ 160 160 //mov qword ptr[rsp+offset],reg1 ※スタックフレームを利用 161 161 pobj_sf->push(reg1); … … 213 213 214 214 215 if( bUseHeap[sp-2]||bUseHeap[sp-1]){216 215 if( isNeedHeapFreeStructureStack[sp-2] || isNeedHeapFreeStructureStack[sp-1] ) 216 { 217 217 ////////////////////////////////////////////////////// 218 218 ///// レジスタ資源のバックアップ … … 220 220 ////////////////////////////////////////////////////// 221 221 222 if(bUseHeap[sp-2]){ 222 if( isNeedHeapFreeStructureStack[sp-2] ) 223 { 223 224 //mov r14,qword ptr[rsp+offset] ※スタックフレームを利用 224 225 pobj_sf->pop(REG_R14); … … 226 227 FreeTempObject(REG_R14,(CClass *)index_stack[sp-2]); 227 228 } 228 if(bUseHeap[sp-1]){ 229 if( isNeedHeapFreeStructureStack[sp-1] ) 230 { 229 231 //mov r14,qword ptr[rsp+offset] ※スタックフレームを利用 230 232 pobj_sf->pop(REG_R14); … … 258 260 index_stack[sp-1]=pUserProc->ReturnType().GetIndex(); 259 261 260 if( pUserProc->ReturnType().IsStruct() ){ 262 if( pUserProc->ReturnType().IsStruct() ) 263 { 261 264 //構造体が戻ったときはヒープ領域にインスタンスが格納されている 262 265 //※後にfreeする必要あり 263 bUseHeap[sp-1]=1; 264 } 265 else bUseHeap[sp-1]=0; 266 isNeedHeapFreeStructureStack[sp-1] = true; 267 } 268 else 269 { 270 isNeedHeapFreeStructureStack[sp-1] = false; 271 } 266 272 267 273 return 1; … … 271 277 int type_stack[10]; 272 278 LONG_PTR index_stack[10]; 273 BOOLarray_bUseHeap[10];279 bool array_bUseHeap[10]; 274 280 int sp=2; 275 281 int iRet;
Note:
See TracChangeset
for help on using the changeset viewer.