• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef ECMASCRIPT_COMPILER_AOT_FILE_TESTS_AOT_FILE_GENERATOR_MOCK_H
17 #define ECMASCRIPT_COMPILER_AOT_FILE_TESTS_AOT_FILE_GENERATOR_MOCK_H
18 
19 #include <unordered_map>
20 #include "ecmascript/compiler/aot_compilation_env.h"
21 #include "ecmascript/compiler/aot_file/elf_builder.h"
22 #include "ecmascript/compiler/file_generators.h"
23 #include "ecmascript/mem/c_string.h"
24 
25 namespace panda::ecmascript::kungfu {
26 class AOTFileGeneratorMock : public AOTFileGenerator {
27 public:
AOTFileGeneratorMock(CompilerLog * log,AotMethodLogList * logList,AOTCompilationEnv * env,const std::string & triple,bool isEnableLiteCG,size_t anFileMaxByteSize)28     AOTFileGeneratorMock(CompilerLog *log, AotMethodLogList *logList, AOTCompilationEnv *env, const std::string &triple,
29                          bool isEnableLiteCG, size_t anFileMaxByteSize)
30         : AOTFileGenerator(log, logList, env, triple, isEnableLiteCG, anFileMaxByteSize)
31     {
32     }
33 
34 public:
SaveAndGetAOTFileSize(const std::string & filename,const std::string & appSignature,size_t & anFileSize,std::unordered_map<CString,uint32_t> & fileNameToChecksumMap)35     bool SaveAndGetAOTFileSize(const std::string &filename, const std::string &appSignature, size_t &anFileSize,
36                                std::unordered_map<CString, uint32_t> &fileNameToChecksumMap)
37     {
38         bool ret = SaveAOTFile(filename, appSignature, fileNameToChecksumMap);
39         ElfBuilder testBuilder(aotInfo_.GetModuleSectionDes(), aotInfo_.GetDumpSectionNames(), false,
40                                Triple::TRIPLE_AMD64);
41         anFileSize = testBuilder.CalculateTotalFileSize();
42         return ret;
43     }
44 };
45 }  // namespace panda::ecmascript::kungfu
46 
47 #endif  // ECMASCRIPT_COMPILER_AOT_FILE_TESTS_AOT_FILE_GENERATOR_MOCK_H