• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLEBE_MDGEN_INCLUDE_MDGENERATOR_H
17 #define MAPLEBE_MDGEN_INCLUDE_MDGENERATOR_H
18 #include <fstream>
19 #include "mdrecord.h"
20 #include "mpl_logging.h"
21 
22 namespace MDGen {
23 class MDCodeGen {
24 public:
MDCodeGen(const MDClassRange & inputRange,const std::string & oFileDirArg)25     MDCodeGen(const MDClassRange &inputRange, const std::string &oFileDirArg)
26         : curKeeper(inputRange), outputFileDir(oFileDirArg)
27     {
28     }
29     virtual ~MDCodeGen() = default;
30 
GetOFileDir()31     const std::string &GetOFileDir() const
32     {
33         return outputFileDir;
34     }
SetTargetArchName(const std::string & archName)35     void SetTargetArchName(const std::string &archName) const
36     {
37         targetArchName = archName;
38     }
39 
40     void EmitCheckPtr(std::ofstream &outputFile, const std::string &emitName, const std::string &name,
41                       const std::string &ptrType) const;
42     void EmitFileHead(std::ofstream &outputFile, const std::string &headInfo) const;
43     MDClass GetSpecificClass(const std::string &className);
44 
45 protected:
46     MDClassRange curKeeper;
47 
48 private:
49     static std::string targetArchName;
50     std::string outputFileDir;
51 };
52 
53 class SchedInfoGen : public MDCodeGen {
54 public:
SchedInfoGen(const MDClassRange & inputRange,const std::string & oFileDirArg)55     SchedInfoGen(const MDClassRange &inputRange, const std::string &oFileDirArg) : MDCodeGen(inputRange, oFileDirArg) {}
~SchedInfoGen()56     ~SchedInfoGen() override
57     {
58         if (outFile.is_open()) {
59             outFile.close();
60         }
61     }
62 
63     void EmitArchDef();
64     const std::string &GetArchName();
65     void EmitUnitIdDef();
66     void EmitUnitDef();
67     void EmitUnitNameDef();
68     void EmitLatencyDef();
69     void EmitResvDef();
70     void EmitBypassDef();
71     void Run();
72 
73 private:
74     std::ofstream outFile;
75 };
76 } /* namespace MDGen */
77 
78 #endif /* MAPLEBE_MDGEN_INCLUDE_MDGENERATOR_H */