Merging r257977:
[oota-llvm.git] / lib / CodeGen / MIRParser / MIParser.h
1 //===- MIParser.h - Machine Instructions Parser ---------------------------===//
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 // This file declares the function that parses the machine instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
15 #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/StringRef.h"
19
20 namespace llvm {
21
22 class BasicBlock;
23 class MachineBasicBlock;
24 class MachineInstr;
25 class MachineFunction;
26 class MDNode;
27 struct SlotMapping;
28 class SMDiagnostic;
29 class SourceMgr;
30
31 struct PerFunctionMIParsingState {
32   DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
33   DenseMap<unsigned, unsigned> VirtualRegisterSlots;
34   DenseMap<unsigned, int> FixedStackObjectSlots;
35   DenseMap<unsigned, int> StackObjectSlots;
36   DenseMap<unsigned, unsigned> ConstantPoolSlots;
37   DenseMap<unsigned, unsigned> JumpTableSlots;
38 };
39
40 /// Parse the machine basic block definitions, and skip the machine
41 /// instructions.
42 ///
43 /// This function runs the first parsing pass on the machine function's body.
44 /// It parses only the machine basic block definitions and creates the machine
45 /// basic blocks in the given machine function.
46 ///
47 /// The machine instructions aren't parsed during the first pass because all
48 /// the machine basic blocks aren't defined yet - this makes it impossible to
49 /// resolve the machine basic block references.
50 ///
51 /// Return true if an error occurred.
52 bool parseMachineBasicBlockDefinitions(MachineFunction &MF, StringRef Src,
53                                        PerFunctionMIParsingState &PFS,
54                                        const SlotMapping &IRSlots,
55                                        SMDiagnostic &Error);
56
57 /// Parse the machine instructions.
58 ///
59 /// This function runs the second parsing pass on the machine function's body.
60 /// It skips the machine basic block definitions and parses only the machine
61 /// instructions and basic block attributes like liveins and successors.
62 ///
63 /// The second parsing pass assumes that the first parsing pass already ran
64 /// on the given source string.
65 ///
66 /// Return true if an error occurred.
67 bool parseMachineInstructions(MachineFunction &MF, StringRef Src,
68                               const PerFunctionMIParsingState &PFS,
69                               const SlotMapping &IRSlots, SMDiagnostic &Error);
70
71 bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
72                        MachineFunction &MF, StringRef Src,
73                        const PerFunctionMIParsingState &PFS,
74                        const SlotMapping &IRSlots, SMDiagnostic &Error);
75
76 bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
77                                  MachineFunction &MF, StringRef Src,
78                                  const PerFunctionMIParsingState &PFS,
79                                  const SlotMapping &IRSlots,
80                                  SMDiagnostic &Error);
81
82 bool parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM,
83                                    MachineFunction &MF, StringRef Src,
84                                    const PerFunctionMIParsingState &PFS,
85                                    const SlotMapping &IRSlots,
86                                    SMDiagnostic &Error);
87
88 bool parseStackObjectReference(int &FI, SourceMgr &SM, MachineFunction &MF,
89                                StringRef Src,
90                                const PerFunctionMIParsingState &PFS,
91                                const SlotMapping &IRSlots, SMDiagnostic &Error);
92
93 bool parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF,
94                  StringRef Src, const PerFunctionMIParsingState &PFS,
95                  const SlotMapping &IRSlots, SMDiagnostic &Error);
96
97 } // end namespace llvm
98
99 #endif