Changeset 357 in dev


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

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

Location:
trunk/abdev
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler32/Compile_Func.cpp

    r350 r357  
    1818    if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 )    return FUNC_DELEGATE_DYNAMICMETHOD_CALL;
    1919    if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 )     return FUNC_DELEGATE_STATICMETHOD_CALL;
     20    if( lstrcmpi( FuncName, "_System_GetNowScopeCatchAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS;
     21    if( lstrcmpi( FuncName, "_System_GetBp" ) == 0 )    return FUNC_SYSTEM_GET_BP;
    2022    if( lstrcmpi( FuncName, "GetDouble" ) == 0 )        return FUNC_GETDOUBLE;
    2123    if( lstrcmpi( FuncName, "GetSingle" ) == 0 )        return FUNC_GETSINGLE;
     
    575577    resultType = UserProc::CompilingUserProc().ReturnType();
    576578}
     579void Opcode_Func_System_Get_Bp()
     580{
     581    //mov eax,ebp
     582    compiler.codeGenerator.op_mov_RR(REG_EAX,REG_EBP);
     583}
    577584
    578585void Opcode_Func_GetPtrData(const char *Parameter,const int type){
     
    670677            Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
    671678            break;
     679        case FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS:
     680            if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeCatchAddress();
     681            resultType.SetBasicType( DEF_LONG );
     682            break;
     683        case FUNC_SYSTEM_GET_BP:
     684            if( isCallOn ) Opcode_Func_System_Get_Bp();
     685            resultType.SetBasicType( DEF_LONG );
     686            break;
    672687
    673688        case FUNC_GETDOUBLE:
  • trunk/abdev/BasicCompiler32/FunctionValue.h

    r325 r357  
    1717#define FUNC_DELEGATE_DYNAMICMETHOD_CALL    0x0621
    1818#define FUNC_DELEGATE_STATICMETHOD_CALL     0x0622
     19#define FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS 0x0623
     20#define FUNC_SYSTEM_GET_BP  0x0624
    1921
    2022//ポインタ
  • trunk/abdev/BasicCompiler32/MakePeHdr.cpp

    r355 r357  
    10791079    compiler.linker.SetImageBase( ImageBase );
    10801080    compiler.linker.ResolveDataTableSchedules( MemPos_DataSection );
     1081    compiler.linker.ResolveCatchAddressSchedules( MemPos_CodeSection );
    10811082    compiler.linker.ResolveDllProcSchedules( MemPos_CodeSection, MemPos_ImportSection, LookupSize, HintSize );
    10821083    compiler.linker.ResolveUserProcSchedules( MemPos_CodeSection );
  • trunk/abdev/BasicCompiler32/x86CodeGenerator.cpp

    r287 r357  
    175175    return pPertialSchedule;
    176176}
    177 void CodeGenerator::op_mov_RV(int reg,long offset, Schedule::Type scheduleType ){
     177const PertialSchedule *CodeGenerator::op_mov_RV(int reg,long offset, Schedule::Type scheduleType, bool isPertialSchedule ){
    178178    //mov reg,value
    179179
     
    182182
    183183    //DISP32
     184    const PertialSchedule *pPertialSchedule = NULL;
     185    if( isPertialSchedule )
     186    {
     187        pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) );
     188        pPertialSchedule = pertialSchedules.back();
     189    }
    184190    pNativeCode->PutEx( offset, scheduleType );
     191
     192    return pPertialSchedule;
    185193}
    186194void CodeGenerator::op_mov_RR(int reg1,int reg2){
  • trunk/abdev/BasicCompiler64/CodeGenerator.cpp

    r317 r357  
    157157///////////////////
    158158
    159 void CodeGenerator::op_mov_RV(int op_size,int reg,long i32data, Schedule::Type scheduleType ){
     159const PertialSchedule *CodeGenerator::op_mov_RV(int op_size,int reg,long i32data, Schedule::Type scheduleType, bool isPertialSchedule ){
    160160    //mov reg,i32data
    161161
     
    176176
    177177    //即値
     178    const PertialSchedule *pPertialSchedule = NULL;
     179    if( isPertialSchedule )
     180    {
     181        pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(long) ) );
     182        pPertialSchedule = pertialSchedules.back();
     183    }
    178184    pNativeCode->PutEx( i32data, scheduleType );
    179 }
    180 void CodeGenerator::op_mov_RV64(int reg,_int64 i64data){
     185
     186    return pPertialSchedule;
     187}
     188const PertialSchedule *CodeGenerator::op_mov_RV64( int reg, _int64 i64data, bool isPertialSchedule )
     189{
    181190    //mov reg,i64data
    182191
     
    188197
    189198    //即値
     199    const PertialSchedule *pPertialSchedule = NULL;
     200    if( isPertialSchedule )
     201    {
     202        pertialSchedules.push_back( new PertialSchedule( pNativeCode->GetSize(), sizeof(_int64) ) );
     203        pPertialSchedule = pertialSchedules.back();
     204    }
    190205    pNativeCode->Put( i64data );
     206
     207    return pPertialSchedule;
    191208}
    192209const PertialSchedule *CodeGenerator::op_mov_RM(int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType, bool isPertialSchedule ){
  • trunk/abdev/BasicCompiler64/Compile_Func.cpp

    r349 r357  
    1616    if( lstrcmpi( FuncName, "__delegate_dynamicmethod_call" ) == 0 )    return FUNC_DELEGATE_DYNAMICMETHOD_CALL;
    1717    if( lstrcmpi( FuncName, "__delegate_staticmethod_call" ) == 0 )     return FUNC_DELEGATE_STATICMETHOD_CALL;
     18    if( lstrcmpi( FuncName, "_System_GetNowScopeCatchAddresses" ) == 0 )return FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS;
    1819    if( lstrcmpi( FuncName, "GetDouble" ) == 0 )        return FUNC_GETDOUBLE;
    1920    if( lstrcmpi( FuncName, "GetSingle" ) == 0 )        return FUNC_GETSINGLE;
     
    441442}
    442443
     444void Opcode_Func_System_Get_Bp()
     445{
     446    //mov rax,rbp
     447    compiler.codeGenerator.op_mov_RR(REG_RAX,REG_RBP);
     448}
     449
    443450void Opcode_Func_GetPtrData( const char *Parameter, const int type ){
    444451    int reg=REG_RAX;
     
    492499            Opcode_Func_delegate_call( Parameter, resultType, false, isCallOn );
    493500            break;
     501        case FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS:
     502            if( isCallOn ) Exception::Opcode_Func_System_GetNowScopeCatchAddress();
     503            resultType.SetBasicType( DEF_LONG );
     504            break;
     505        case FUNC_SYSTEM_GET_BP:
     506            if( isCallOn ) Opcode_Func_System_Get_Bp();
     507            resultType.SetBasicType( DEF_LONG );
     508            break;
    494509
    495510        case FUNC_GETDOUBLE:
  • trunk/abdev/BasicCompiler64/FunctionValue.h

    r330 r357  
    1616#define FUNC_DELEGATE_DYNAMICMETHOD_CALL    0x0621
    1717#define FUNC_DELEGATE_STATICMETHOD_CALL     0x0622
     18#define FUNC_SYSTEM_GET_NOW_SCOPE_CATCH_ADDRESS 0x0623
     19#define FUNC_SYSTEM_GET_BP  0x0624
    1820
    1921//ポインタ
  • trunk/abdev/BasicCompiler64/MakePeHdr.cpp

    r355 r357  
    10771077    compiler.linker.SetImageBase( ImageBase );
    10781078    compiler.linker.ResolveDataTableSchedules( MemPos_DataSection );
     1079    compiler.linker.ResolveCatchAddressSchedules( MemPos_CodeSection );
    10791080    compiler.linker.ResolveDllProcSchedules( MemPos_CodeSection, MemPos_ImportSection, LookupSize, HintSize );
    10801081    compiler.linker.ResolveUserProcSchedules( MemPos_CodeSection );
  • trunk/abdev/BasicCompiler_Common/Debug.cpp

    r313 r357  
    630630
    631631                //"スレッド(&H%X)でアクセス違反がありました(EIP=&H%08X)。\r\n"
    632                 sprintf(temporary,STRING_DEBUG_THREAD_ACCESSVIOLATION,de.dwThreadId,(ULONG_PTR)de.u.Exception.ExceptionRecord.ExceptionAddress);
     632                sprintf(temporary,
     633                    STRING_DEBUG_THREAD_ACCESSVIOLATION,
     634                    de.dwThreadId,
     635                    (ULONG_PTR)de.u.Exception.ExceptionRecord.ExceptionAddress,
     636#ifdef _AMD64_
     637                    (ULONG_PTR)Context.Rsp
     638#else
     639                    (ULONG_PTR)Context.Esp
     640#endif
     641                    );
    633642                DebugMessage(temporary);
    634643
  • trunk/abdev/BasicCompiler_Common/Intermediate_Step1.cpp

    r355 r357  
    492492                        case 't':
    493493                        case 'T':
    494                             if(lstrcmpi(temp2,"Type")==0) sw1=1;
     494                            if(lstrcmpi(temp2,"Try")==0) sw1=1;
     495                            else if(lstrcmpi(temp2,"Type")==0) sw1=1;
    495496                            break;
    496497                        case 'w':
  • trunk/abdev/BasicCompiler_Common/common_msg_jpn.h

    r266 r357  
    4040#define STRING_DEBUG_PROCESSFINISH          "プログラムはコード &H%X で終了しました。\r\n"
    4141#define STRING_DEBUG_THREAD_INVALID_HANDLE  "スレッド(&H%X)でハンドル違反がありました(EIP=&H%08X)。\r\n"
    42 #define STRING_DEBUG_THREAD_ACCESSVIOLATION "スレッド(&H%X)でアクセス違反がありました(EIP=&H%08X)。\r\n"
     42#define STRING_DEBUG_THREAD_ACCESSVIOLATION "スレッド(&H%X)でアクセス違反がありました(EIP=&H%08X/ESP=&H%08X)。\r\n"
    4343#define STRING_DEBUG_BREAKPOINT             "スレッド(&H%X)のブレーク ポイント(EIP=&H%08X/ESP=&H%08X)。\r\n"
    4444#define STRING_DEBUG_DIVIDE_BY_ZERO         "0による除算が行われました。スレッド(&H%X) ブレーク ポイント(EIP=&H%08X)。\r\n"
  • trunk/abdev/BasicCompiler_Common/include/Binary.h

    r288 r357  
    122122        *(long *)( buffer + pos ) = newLongValue;
    123123    }
     124    void Overwrite( int pos, _int64 newInt64Value )
     125    {
     126        *(_int64 *)( buffer + pos ) = newInt64Value;
     127    }
    124128
    125129    void Put( const char *buffer, int size )
  • trunk/abdev/BasicCompiler_Common/include/CodeGenerator.h

    r317 r357  
    263263    void CheckUnresolveSchedule();
    264264
    265     void opfix( const PertialSchedule *pPertialSchedule, long newValue );
     265    void opfix( const PertialSchedule *pPertialSchedule, _int64 newValue );
    266266    void opfix_offset( const PertialSchedule *pPertialSchedule, long offset );
    267267    void opfix_JmpPertialSchedule( const PertialSchedule *pPertialSchedule );
     
    300300    const PertialSchedule *__op_format(int op_size,char op_prefix,char opcode1,char opcode2,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
    301301public:
    302     void op_mov_RV                  (int op_size,int reg,long i32data, Schedule::Type scheduleType = Schedule::None );
    303     void op_mov_RV64                (int reg,_int64 i64data);
     302    const PertialSchedule *op_mov_RV        (int op_size,int reg,long i32data, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
     303    const PertialSchedule *op_mov_RV64      ( int reg, _int64 i64data, bool isPertialSchedule = false );
    304304    const PertialSchedule *op_mov_RM        (int op_size,int reg,int base_reg,long offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
    305305    const PertialSchedule *op_mov_RM_ex     (int op_size,int reg,int base_reg1,int base_reg2,long offset,BOOL bUseOffset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
     
    381381public:
    382382    const PertialSchedule *op_mov_MV        ( int op_size, int base_reg, long offset, Schedule::Type offsetScheduleType, bool isPertialSchedule, long value, Schedule::Type valueScheduleType = Schedule::None );
    383     void op_mov_RV                          ( int reg,long offset, Schedule::Type scheduleType = Schedule::None );
     383    const PertialSchedule *op_mov_RV        ( int reg, long offset, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
    384384    void op_mov_RR                          ( int reg1,int reg2);
    385385    const PertialSchedule *op_mov_RM        ( int op_size,int reg,int base_reg,int offset,char mod, Schedule::Type scheduleType = Schedule::None, bool isPertialSchedule = false );
  • trunk/abdev/BasicCompiler_Common/include/Compiler.h

    r322 r357  
    99#include <Linker.h>
    1010#include <Delegate.h>
     11#include <Exception.h>
    1112
    1213class Compiler
  • trunk/abdev/BasicCompiler_Common/include/Exception.h

    r124 r357  
    99    void ThrowCommand( const char *Parameter );
    1010
     11    void Opcode_Func_System_GetNowScopeCatchAddress();
     12
    1113}
  • trunk/abdev/BasicCompiler_Common/include/Linker.h

    r355 r357  
    3131    void ResolveDataTableSchedules( long dataSectionBaseOffset );
    3232
     33    // Catchアドレス スケジュール
     34    void ResolveCatchAddressSchedules( long codeSectionBaseOffset );
     35
    3336    // DLL関数スケジュール
    3437    void ResolveDllProcSchedules( long codeSectionBaseOffset, long importSectionBaseOffset, long lookupSize, long hintSize );
  • trunk/abdev/BasicCompiler_Common/include/NativeCode.h

    r355 r357  
    1919        GlobalVar,      // グローバル変数スケジュール
    2020        DataTable,      // データテーブル スケジュール
     21        CatchAddress,   // Catchアドレス スケジュール
    2122        Relocation,     // リロケーション情報スケジュール
    2223        UserProc,       // ユーザ定義関数呼び出し側スケジュール
     
    5253        case UserProc:
    5354        case AddressOf:
     55        case CatchAddress:
    5456            ar & boost::serialization::make_nvp("pUserProc", const_cast<::UserProc *&>(pUserProc));
    5557            break;
     
    127129    const ::UserProc &GetUserProc() const
    128130    {
    129         if( !( type == Schedule::UserProc || type == Schedule::AddressOf ) )
     131        if( !( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress ) )
    130132        {
    131133            SetError();
     
    149151        }
    150152        type = Schedule::AddressOf;
     153    }
     154    void SpecifyCatchAddress()
     155    {
     156        if( type != Schedule::UserProc )
     157        {
     158            SetError();
     159        }
     160        type = Schedule::CatchAddress;
    151161    }
    152162};
     
    279289
    280290    void PutEx( const NativeCode &nativeCode );
    281     void PutEx( long l, Schedule::Type scheduleType )
    282     {
    283         if( scheduleType != Schedule::None )
    284         {
    285             schedules.push_back( Schedule( scheduleType, GetSize() ) );
    286         }
    287 
    288         Put( l );
    289     }
     291    void PutEx( long l, Schedule::Type scheduleType );
    290292    void PutUserProcSchedule( const UserProc *pUserProc, bool isCall );
     293    void PutCatchAddressSchedule( const UserProc *pUserProc, long codePos );
    291294    void PutDllProcSchedule( const DllProc *pDllProc );
    292295    void PutVtblSchedule( const CClass *pClass );
  • 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.