From f4baeb51b265a419931f79eb9b96a4b8677b3c01 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 21 Jul 2015 22:28:27 +0000 Subject: MIR Serialization: Start serializing the CFI operands with .cfi_def_cfa_offset. This commit begins serialization of the CFI index machine operands by serializing one kind of CFI instruction - the .cfi_def_cfa_offset instruction. Reviewers: Duncan P. N. Exon Smith llvm-svn: 242845 --- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'llvm/lib/CodeGen/MIRParser/MIParser.cpp') diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index ca98ae3c97f..498ca0615d5 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -20,6 +20,7 @@ #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/Support/raw_ostream.h" @@ -111,6 +112,8 @@ public: bool parseConstantPoolIndexOperand(MachineOperand &Dest); bool parseJumpTableIndexOperand(MachineOperand &Dest); bool parseExternalSymbolOperand(MachineOperand &Dest); + bool parseCFIOffset(int &Offset); + bool parseCFIOperand(MachineOperand &Dest); bool parseMachineOperand(MachineOperand &Dest); private: @@ -572,6 +575,29 @@ bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) { return false; } +bool MIParser::parseCFIOffset(int &Offset) { + if (Token.isNot(MIToken::IntegerLiteral)) + return error("expected a cfi offset"); + if (Token.integerValue().getMinSignedBits() > 32) + return error("expected a 32 bit integer (the cfi offset is too large)"); + Offset = (int)Token.integerValue().getExtValue(); + lex(); + return false; +} + +bool MIParser::parseCFIOperand(MachineOperand &Dest) { + // TODO: Parse the other CFI operands. + assert(Token.is(MIToken::kw_cfi_def_cfa_offset)); + lex(); + int Offset; + if (parseCFIOffset(Offset)) + return true; + // NB: MCCFIInstruction::createDefCfaOffset negates the offset. + Dest = MachineOperand::CreateCFIIndex(MF.getMMI().addFrameInst( + MCCFIInstruction::createDefCfaOffset(nullptr, -Offset))); + return false; +} + bool MIParser::parseMachineOperand(MachineOperand &Dest) { switch (Token.kind()) { case MIToken::kw_implicit: @@ -602,6 +628,8 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) { case MIToken::ExternalSymbol: case MIToken::QuotedExternalSymbol: return parseExternalSymbolOperand(Dest); + case MIToken::kw_cfi_def_cfa_offset: + return parseCFIOperand(Dest); case MIToken::Error: return true; case MIToken::Identifier: -- cgit v1.2.3