1 //===- MIRYamlMapping.cpp - Describe mapping between MIR and YAML ---------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the mapping between various MIR data structures and
10 // their corresponding YAML representation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MIRYamlMapping.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/FormatVariadic.h"
20 using namespace llvm::yaml
;
22 FrameIndex::FrameIndex(int FI
, const llvm::MachineFrameInfo
&MFI
) {
23 IsFixed
= MFI
.isFixedObjectIndex(FI
);
25 FI
-= MFI
.getObjectIndexBegin();
29 // Returns the value and if the frame index is fixed or not.
30 Expected
<int> FrameIndex::getFI(const llvm::MachineFrameInfo
&MFI
) const {
33 if (unsigned(FI
) >= MFI
.getNumFixedObjects())
34 return make_error
<StringError
>(
35 formatv("invalid fixed frame index {0}", FI
).str(),
36 inconvertibleErrorCode());
37 FI
+= MFI
.getObjectIndexBegin();
39 if (unsigned(FI
+ MFI
.getNumFixedObjects()) >= MFI
.getNumObjects())
40 return make_error
<StringError
>(formatv("invalid frame index {0}", FI
).str(),
41 inconvertibleErrorCode());