MIR Serialization: Serialize machine instruction names.
[oota-llvm.git] / include / llvm / CodeGen / MIRYamlMapping.h
1 //===- MIRYAMLMapping.h - Describes the mapping between MIR and YAML ------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The MIR serialization library is currently a work in progress. It can't
11 // serialize machine functions at this time.
12 //
13 // This file implements the mapping between various MIR data structures and
14 // their corresponding YAML representation.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
19 #define LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
20
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/YAMLTraits.h"
23 #include <vector>
24
25 LLVM_YAML_IS_SEQUENCE_VECTOR(std::string)
26
27 namespace llvm {
28 namespace yaml {
29
30 struct MachineBasicBlock {
31   std::string Name;
32   unsigned Alignment = 0;
33   bool IsLandingPad = false;
34   bool AddressTaken = false;
35   // TODO: Serialize the successors and liveins.
36
37   std::vector<std::string> Instructions;
38 };
39
40 template <> struct MappingTraits<MachineBasicBlock> {
41   static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
42     YamlIO.mapOptional("name", MBB.Name,
43                        std::string()); // Don't print out an empty name.
44     YamlIO.mapOptional("alignment", MBB.Alignment);
45     YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
46     YamlIO.mapOptional("addressTaken", MBB.AddressTaken);
47     YamlIO.mapOptional("instructions", MBB.Instructions);
48   }
49 };
50
51 } // end namespace yaml
52 } // end namespace llvm
53
54 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineBasicBlock)
55
56 namespace llvm {
57 namespace yaml {
58
59 struct MachineFunction {
60   StringRef Name;
61   unsigned Alignment = 0;
62   bool ExposesReturnsTwice = false;
63   bool HasInlineAsm = false;
64
65   std::vector<MachineBasicBlock> BasicBlocks;
66 };
67
68 template <> struct MappingTraits<MachineFunction> {
69   static void mapping(IO &YamlIO, MachineFunction &MF) {
70     YamlIO.mapRequired("name", MF.Name);
71     YamlIO.mapOptional("alignment", MF.Alignment);
72     YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
73     YamlIO.mapOptional("hasInlineAsm", MF.HasInlineAsm);
74     YamlIO.mapOptional("body", MF.BasicBlocks);
75   }
76 };
77
78 } // end namespace yaml
79 } // end namespace llvm
80
81 #endif