1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16export namespace MemoryDotting { 17 export interface RecordInfo { 18 recordStage: string, 19 recordIndex: number 20 } 21 export const BINDE_SOURCE_FILE = 'binder(bindSourceFile: Bind)'; 22 export const CHECK_SOURCE_FILE = 'checker(checkSourceFile: Check)'; 23 export const EMIT_FILES = 'emitter(emitFiles: EmitEachOutputFile)'; 24 export const CREATE_SORUCE_FILE_PARSE = 'parser(createSourceFile: Parse)'; 25 export const BEFORE_PROGRAM = 'program(createProgram: beforeProgram)'; 26 export const TRANSFORM = 'transformer(transformNodes: Transform)'; 27 28 let memoryDottingCallback: ((stage: string) => RecordInfo) | undefined; 29 let memoryDottingStopCallback: ((recordInfo: RecordInfo) => void) | undefined; 30 31 export function recordStage(stage: string): RecordInfo | null { 32 if (memoryDottingCallback !== undefined) { 33 return memoryDottingCallback(stage); 34 } 35 return null; 36 } 37 38 export function stopRecordStage(recordInfo: RecordInfo | null): void { 39 if (memoryDottingStopCallback !== undefined && recordInfo !== null) { 40 memoryDottingStopCallback(recordInfo); 41 } 42 } 43 44 export function setMemoryDottingCallBack(recordCallback: (stage: string) => RecordInfo, stopCallback: (recordInfo: RecordInfo) => void): void { 45 if (recordCallback) { 46 memoryDottingCallback = recordCallback; 47 } 48 if (stopCallback) { 49 memoryDottingStopCallback = stopCallback; 50 } 51 } 52 53 export function clearCallBack(): void { 54 if (memoryDottingCallback !== undefined) { 55 memoryDottingCallback = undefined; 56 } 57 if (memoryDottingStopCallback !== undefined) { 58 memoryDottingStopCallback = undefined; 59 } 60 } 61} 62 63