| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*****************************************************************************/ |
| 6 | #ifndef _PHASE_H_ |
| 7 | #define _PHASE_H_ |
| 8 | |
| 9 | class Phase |
| 10 | { |
| 11 | public: |
| 12 | virtual void Run(); |
| 13 | |
| 14 | protected: |
| 15 | Phase(Compiler* _comp, const char* _name, Phases _phase = PHASE_NUMBER_OF) |
| 16 | : comp(_comp), name(_name), phase(_phase), doChecks(true) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | virtual void PrePhase(); |
| 21 | virtual void DoPhase() = 0; |
| 22 | virtual void PostPhase(); |
| 23 | |
| 24 | Compiler* comp; |
| 25 | const char* name; |
| 26 | Phases phase; |
| 27 | bool doChecks; |
| 28 | }; |
| 29 | |
| 30 | inline void Phase::Run() |
| 31 | { |
| 32 | PrePhase(); |
| 33 | DoPhase(); |
| 34 | PostPhase(); |
| 35 | } |
| 36 | |
| 37 | inline void Phase::PrePhase() |
| 38 | { |
| 39 | #ifdef DEBUG |
| 40 | if (VERBOSE) |
| 41 | { |
| 42 | printf("*************** In %s\n" , name); |
| 43 | printf("Trees before %s\n" , name); |
| 44 | comp->fgDispBasicBlocks(true); |
| 45 | } |
| 46 | |
| 47 | if (doChecks && comp->expensiveDebugCheckLevel >= 2) |
| 48 | { |
| 49 | // If everyone used the Phase class, this would duplicate the PostPhase() from the previous phase. |
| 50 | // But, not everyone does, so go ahead and do the check here, too. |
| 51 | comp->fgDebugCheckBBlist(); |
| 52 | comp->fgDebugCheckLinks(); |
| 53 | } |
| 54 | #endif // DEBUG |
| 55 | } |
| 56 | |
| 57 | inline void Phase::PostPhase() |
| 58 | { |
| 59 | #ifdef DEBUG |
| 60 | if (VERBOSE) |
| 61 | { |
| 62 | printf("*************** Exiting %s\n" , name); |
| 63 | printf("Trees after %s\n" , name); |
| 64 | comp->fgDispBasicBlocks(true); |
| 65 | } |
| 66 | #endif // DEBUG |
| 67 | |
| 68 | if (phase != PHASE_NUMBER_OF) |
| 69 | { |
| 70 | comp->EndPhase(phase); |
| 71 | } |
| 72 | |
| 73 | #ifdef DEBUG |
| 74 | if (doChecks) |
| 75 | { |
| 76 | comp->fgDebugCheckBBlist(); |
| 77 | comp->fgDebugCheckLinks(); |
| 78 | } |
| 79 | #endif // DEBUG |
| 80 | } |
| 81 | |
| 82 | #endif /* End of _PHASE_H_ */ |
| 83 | |