• 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 #include <getopt.h>
17 #include "mdparser.h"
18 #include "mdgenerator.h"
19 
20 using namespace MDGen;
21 namespace {
22 bool isGenSched = false;
23 std::string schedSrcPath = "";
24 std::string oFileDir = "";
25 }  // namespace
26 
PrintHelpAndExit()27 static int PrintHelpAndExit()
28 {
29     maple::LogInfo::MapleLogger() << "Maplegen is usd to process md files and "
30                                   << "generate architecture specific information in def files\n"
31                                   << "usage: ./mplgen xxx.md outputdirectroy\n";
32     return 1;
33 }
34 
ParseCommandLine(int argc,char ** argv)35 void ParseCommandLine(int argc, char **argv)
36 {
37     int opt;
38     int gOptionIndex = 0;
39     std::string optStr = "s:o:";
40     static struct option longOptions[] = {
41         {"genSchdInfo", required_argument, NULL, 's'}, {"outDirectory", required_argument, NULL, 'o'}, {0, 0, 0, 0}};
42     while ((opt = getopt_long(argc, argv, optStr.c_str(), longOptions, &gOptionIndex)) != -1) {
43         switch (opt) {
44             case 's':
45                 isGenSched = true;
46                 schedSrcPath = optarg;
47                 break;
48             case 'o':
49                 oFileDir = optarg;
50                 break;
51             default:
52                 break;
53         }
54     }
55 }
56 
GenSchedFiles(const std::string & fileName,const std::string & fileDir)57 bool GenSchedFiles(const std::string &fileName, const std::string &fileDir)
58 {
59     maple::MemPool *schedInfoMemPool = memPoolCtrler.NewMemPool("schedInfoMp", false /* isLcalPool */);
60     MDClassRange moduleData("Schedule");
61     MDParser parser(moduleData, schedInfoMemPool);
62     if (!parser.ParseFile(fileName)) {
63         delete schedInfoMemPool;
64         return false;
65     }
66     SchedInfoGen schedEmiiter(moduleData, fileDir);
67     schedEmiiter.Run();
68     delete schedInfoMemPool;
69     return true;
70 }
71 
main(int argc,char ** argv)72 int main(int argc, char **argv)
73 {
74     constexpr int minimumArgNum = 2;
75     if (argc <= minimumArgNum) {
76         return PrintHelpAndExit();
77     }
78     ParseCommandLine(argc, argv);
79     if (isGenSched) {
80         if (!GenSchedFiles(schedSrcPath, oFileDir)) {
81             return 1;
82         }
83     }
84     return 0;
85 }
86