• 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 MAPLE_IR_INCLUDE_BIN_MIR_FILE_H
17 #define MAPLE_IR_INCLUDE_BIN_MIR_FILE_H
18 #include <string>
19 #include "types_def.h"
20 
21 namespace maple {
22 const std::string kBinMirFileID = "HWCMPL";  // for magic in file header
23 constexpr uint8 kVersionMajor = 0;           // experimental version
24 constexpr uint8 kVersionMinor = 1;
25 constexpr int kMagicSize = 7;
26 
27 enum BinMirFileType {
28     kMjsvmFileTypeCmplV1,
29     kMjsvmFileTypeCmpl,  // kCmpl v2 is the release version of
30     kMjsvmFileTypeUnknown
31 };
32 
MakeVersionNum(uint8 major,uint8 minor)33 inline uint8 MakeVersionNum(uint8 major, uint8 minor)
34 {
35     uint8 mj = major & 0x0Fu;
36     uint8 mn = minor & 0x0Fu;
37     constexpr uint8 shiftNum = 4;
38     return (mj << shiftNum) | mn;
39 }
40 
41 // file header for binary format kMmpl, 8B in total
42 // Note the header is different with the specification
43 struct BinMIRFileHeader {
44     char magic[kMagicSize];  // “HWCMPL”, or "HWLOS_"
45     uint8 segNum;            // number of segments (e.g. one raw IR file is a segment unit)
46     uint8 type;              // enum of type of VM file (e.g. MapleIR, TE)
47     uint8 version;           // version of IR format (should be major.minor)
48 };
49 }  // namespace maple
50 #endif  // MAPLE_IR_INCLUDE_BIN_MIR_FILE_H
51