Ignore:
Timestamp:
Nov 5, 2007, 3:26:20 AM (17 years ago)
Author:
dai_9181
Message:

例外処理機構実装中...

Location:
trunk/abdev/BasicCompiler_Common/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/src/CommonCodeGenerator.cpp

    r276 r357  
    2020}
    2121
    22 void CodeGenerator::opfix( const PertialSchedule *pPertialSchedule, long newValue )
     22void CodeGenerator::opfix( const PertialSchedule *pPertialSchedule, _int64 newValue )
    2323{
    2424    bool isSuccessful = false;
     
    4141            else if( pPertialSchedule->GetTypeSize() == sizeof(long) )
    4242            {
     43                pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), static_cast<long>(newValue) );
     44            }
     45            else if( pPertialSchedule->GetTypeSize() == sizeof(_int64) )
     46            {
    4347                pNativeCode->Overwrite( pPertialSchedule->GetCodePos(), newValue );
    4448            }
  • trunk/abdev/BasicCompiler_Common/src/Exception.cpp

    r206 r357  
    11#include "stdafx.h"
     2
     3#ifdef _AMD64_
     4#include "../../BasicCompiler64/opcode.h"
     5#else
     6#include "../../BasicCompiler32/opcode.h"
     7#endif
    28
    39#include <Exception.h>
     
    511namespace Exception{
    612
     13class TryScope
     14{
     15public:
     16    const PertialSchedule *pPertialScheduleForCatchAddress;
     17    TryScope()
     18    {
     19    }
     20    ~TryScope()
     21    {
     22    }
    723
    8 void TryCommand(){
     24    void RegistPertialScheduleForCatchAddress( const PertialSchedule *pPertialScheduleForCatchAddress )
     25    {
     26        this->pPertialScheduleForCatchAddress = pPertialScheduleForCatchAddress;
     27    }
     28
     29    void AddCatch()
     30    {
     31    }
     32
     33    void EndTry()
     34    {
     35    }
     36};
     37typedef std::vector<TryScope> TryScopes;
     38
     39TryScopes tryScopes;
     40
     41void TryCommand()
     42{
     43    if( UserProc::IsGlobalAreaCompiling() )
     44    {
     45        SetError();
     46    }
     47
     48    tryScopes.push_back( TryScope() );
     49
     50    int backCp = cp;
     51
     52    char temporary[1024];
     53    lstrcpy( temporary, "_System_pobj_AllThreads->GetCurrentException()->BeginTryScope( _System_GetNowScopeCatchAddresses() As VoidPtr, _System_GetBp() As LONG_PTR, _System_GetSp() As LONG_PTR )" );
     54    MakeMiddleCode( temporary );
     55    ChangeOpcode( temporary );
     56
     57    cp = backCp;
    958}
    10 void CatchCommand(){
     59void CatchCommand()
     60{
     61    if( tryScopes.size() == 0 )
     62    {
     63        SetError(1,NULL,cp);
     64        return;
     65    }
     66
     67    compiler.codeGenerator.opfix( tryScopes.back().pPertialScheduleForCatchAddress, compiler.codeGenerator.GetNativeCodeSize() );
    1168}
    12 void FinallyCommand(){
     69void FinallyCommand()
     70{
    1371}
    14 void EndTryCommand(){
     72void EndTryCommand()
     73{
     74    if( tryScopes.size() == 0 )
     75    {
     76        SetError(1,NULL,cp);
     77        return;
     78    }
     79
     80    int backCp = cp;
     81
     82    char temporary[1024];
     83    lstrcpy( temporary, "_System_pobj_AllThreads->GetCurrentException()->EndTryScope()" );
     84    MakeMiddleCode( temporary );
     85    ChangeOpcode( temporary );
     86
     87    cp = backCp;
     88
     89    tryScopes.pop_back();
    1590}
    1691
    17 void ThrowCommand( const char *Parameter ){
     92void ThrowCommand( const char *Parameter )
     93{
     94    int backCp = cp;
     95
     96    char temporary[1024];
     97    lstrcpy( temporary, "_System_pobj_AllThreads->GetCurrentException()->_Throw()" );
     98    MakeMiddleCode( temporary );
     99    ChangeOpcode( temporary );
     100
     101    cp = backCp;
     102}
     103
     104void Opcode_Func_System_GetNowScopeCatchAddress()
     105{
     106    if( tryScopes.size() == 0 )
     107    {
     108        SetError(1,NULL,cp);
     109        return;
     110    }
     111
     112#ifdef _WIN64
     113    //mov rax,catchAddress
     114    const PertialSchedule *pPertialSchedule = compiler.codeGenerator.op_mov_RV( sizeof(long), REG_RAX, 0, Schedule::CatchAddress, true );
     115#else
     116    //mov eax,catchAddress
     117    const PertialSchedule *pPertialSchedule = compiler.codeGenerator.op_mov_RV( REG_EAX, 0, Schedule::CatchAddress, true );
     118#endif
     119
     120    tryScopes.back().RegistPertialScheduleForCatchAddress( pPertialSchedule );
     121
     122    /*
     123    int dataTableOffset = compiler.GetObjectModule().dataTable.Add( static_cast<LONG_PTR>(0) );
     124
     125#ifdef _WIN64
     126    //mov rax,dataTableOffset
     127    compiler.codeGenerator.op_mov_RV( sizeof(_int64), REG_RAX, dataTableOffset, Schedule::DataTable);
     128#else
     129    //mov eax,dataTableOffset
     130    compiler.codeGenerator.op_mov_RV( REG_EAX, dataTableOffset, Schedule::DataTable);
     131#endif
     132    */
    18133}
    19134
  • trunk/abdev/BasicCompiler_Common/src/Linker.cpp

    r355 r357  
    3737}
    3838
     39// Catchアドレス スケジュール
     40void Linker::ResolveCatchAddressSchedules( long codeSectionBaseOffset )
     41{
     42    BOOST_FOREACH( const Schedule &schedule, nativeCode.GetSchedules() )
     43    {
     44        if( schedule.GetType() == Schedule::CatchAddress )
     45        {
     46            nativeCode.Overwrite(
     47                schedule.GetOffset(),
     48                static_cast<long>( nativeCode.GetLong( schedule.GetOffset() ) + schedule.GetUserProc().GetBeginOpAddress() + imageBase + codeSectionBaseOffset )
     49            );
     50        }
     51    }
     52}
     53
    3954// DLL関数スケジュール
    4055void Linker::ResolveDllProcSchedules( long codeSectionBaseOffset, long importSectionBaseOffset, long lookupSize, long hintSize )
  • trunk/abdev/BasicCompiler_Common/src/NativeCode.cpp

    r287 r357  
    3939}
    4040
     41void NativeCode::PutEx( long l, Schedule::Type scheduleType )
     42{
     43    if( scheduleType == Schedule::CatchAddress )
     44    {
     45        PutCatchAddressSchedule( &UserProc::CompilingUserProc(), l );
     46    }
     47    else
     48    {
     49        if( scheduleType != Schedule::None )
     50        {
     51            schedules.push_back( Schedule( scheduleType, GetSize() ) );
     52        }
     53
     54        Put( l );
     55    }
     56}
     57
    4158void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
    4259{
     
    5168
    5269    Put( (long)0 );
     70}
     71
     72void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
     73{
     74    pUserProc->Using();
     75
     76    Schedule schedule( pUserProc, GetSize() );
     77    schedule.SpecifyCatchAddress();
     78    schedules.push_back( schedule );
     79
     80    Put( codePos );
    5381}
    5482
Note: See TracChangeset for help on using the changeset viewer.