[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[357] | 3 | #ifdef _AMD64_
|
---|
| 4 | #include "../../BasicCompiler64/opcode.h"
|
---|
| 5 | #else
|
---|
| 6 | #include "../../BasicCompiler32/opcode.h"
|
---|
| 7 | #endif
|
---|
| 8 |
|
---|
[125] | 9 | #include <Exception.h>
|
---|
[52] | 10 |
|
---|
| 11 | namespace Exception{
|
---|
| 12 |
|
---|
[357] | 13 | class TryScope
|
---|
| 14 | {
|
---|
| 15 | public:
|
---|
| 16 | const PertialSchedule *pPertialScheduleForCatchAddress;
|
---|
| 17 | TryScope()
|
---|
| 18 | {
|
---|
| 19 | }
|
---|
| 20 | ~TryScope()
|
---|
| 21 | {
|
---|
| 22 | }
|
---|
[52] | 23 |
|
---|
[357] | 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 | };
|
---|
| 37 | typedef std::vector<TryScope> TryScopes;
|
---|
| 38 |
|
---|
| 39 | TryScopes tryScopes;
|
---|
| 40 |
|
---|
| 41 | void 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];
|
---|
[358] | 53 | lstrcpy( temporary, "ExceptionService.BeginTryScope( _System_GetNowScopeCatchAddresses() As VoidPtr, _System_GetBp() As LONG_PTR, _System_GetSp() As LONG_PTR )" );
|
---|
[357] | 54 | MakeMiddleCode( temporary );
|
---|
| 55 | ChangeOpcode( temporary );
|
---|
| 56 |
|
---|
| 57 | cp = backCp;
|
---|
[52] | 58 | }
|
---|
[357] | 59 | void 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() );
|
---|
[52] | 68 | }
|
---|
[357] | 69 | void FinallyCommand()
|
---|
| 70 | {
|
---|
[52] | 71 | }
|
---|
[357] | 72 | void 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();
|
---|
[52] | 90 | }
|
---|
| 91 |
|
---|
[357] | 92 | void 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;
|
---|
[52] | 102 | }
|
---|
| 103 |
|
---|
[357] | 104 | void Opcode_Func_System_GetNowScopeCatchAddress()
|
---|
| 105 | {
|
---|
| 106 | if( tryScopes.size() == 0 )
|
---|
| 107 | {
|
---|
| 108 | SetError(1,NULL,cp);
|
---|
| 109 | return;
|
---|
| 110 | }
|
---|
[52] | 111 |
|
---|
[357] | 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 | */
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
[52] | 136 | } // Exception
|
---|