mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
MIR Serialization: Serialize the floating point immediate machine operands.
Reviewers: Duncan P. N. Exon Smith git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243780 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -150,6 +150,12 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
|
||||
.Case(".cfi_def_cfa", MIToken::kw_cfi_def_cfa)
|
||||
.Case("blockaddress", MIToken::kw_blockaddress)
|
||||
.Case("target-index", MIToken::kw_target_index)
|
||||
.Case("half", MIToken::kw_half)
|
||||
.Case("float", MIToken::kw_float)
|
||||
.Case("double", MIToken::kw_double)
|
||||
.Case("x86_fp80", MIToken::kw_x86_fp80)
|
||||
.Case("fp128", MIToken::kw_fp128)
|
||||
.Case("ppc_fp128", MIToken::kw_ppc_fp128)
|
||||
.Default(MIToken::Identifier);
|
||||
}
|
||||
|
||||
@@ -308,13 +314,48 @@ static Cursor maybeLexExternalSymbol(
|
||||
/*PrefixLength=*/1, ErrorCallback);
|
||||
}
|
||||
|
||||
static Cursor maybeLexIntegerLiteral(Cursor C, MIToken &Token) {
|
||||
static bool isValidHexFloatingPointPrefix(char C) {
|
||||
return C == 'H' || C == 'K' || C == 'L' || C == 'M';
|
||||
}
|
||||
|
||||
static Cursor maybeLexHexFloatingPointLiteral(Cursor C, MIToken &Token) {
|
||||
if (C.peek() != '0' || C.peek(1) != 'x')
|
||||
return None;
|
||||
Cursor Range = C;
|
||||
C.advance(2); // Skip '0x'
|
||||
if (isValidHexFloatingPointPrefix(C.peek()))
|
||||
C.advance();
|
||||
while (isxdigit(C.peek()))
|
||||
C.advance();
|
||||
Token = MIToken(MIToken::FloatingPointLiteral, Range.upto(C));
|
||||
return C;
|
||||
}
|
||||
|
||||
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token) {
|
||||
C.advance();
|
||||
// Skip over [0-9]*([eE][-+]?[0-9]+)?
|
||||
while (isdigit(C.peek()))
|
||||
C.advance();
|
||||
if ((C.peek() == 'e' || C.peek() == 'E') &&
|
||||
(isdigit(C.peek(1)) ||
|
||||
((C.peek(1) == '-' || C.peek(1) == '+') && isdigit(C.peek(2))))) {
|
||||
C.advance(2);
|
||||
while (isdigit(C.peek()))
|
||||
C.advance();
|
||||
}
|
||||
Token = MIToken(MIToken::FloatingPointLiteral, Range.upto(C));
|
||||
return C;
|
||||
}
|
||||
|
||||
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) {
|
||||
if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
|
||||
return None;
|
||||
auto Range = C;
|
||||
C.advance();
|
||||
while (isdigit(C.peek()))
|
||||
C.advance();
|
||||
if (C.peek() == '.')
|
||||
return lexFloatingPointLiteral(Range, C, Token);
|
||||
StringRef StrVal = Range.upto(C);
|
||||
Token = MIToken(MIToken::IntegerLiteral, StrVal, APSInt(StrVal));
|
||||
return C;
|
||||
@@ -378,7 +419,9 @@ StringRef llvm::lexMIToken(
|
||||
return R.remaining();
|
||||
if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
|
||||
return R.remaining();
|
||||
if (Cursor R = maybeLexIntegerLiteral(C, Token))
|
||||
if (Cursor R = maybeLexHexFloatingPointLiteral(C, Token))
|
||||
return R.remaining();
|
||||
if (Cursor R = maybeLexNumericalLiteral(C, Token))
|
||||
return R.remaining();
|
||||
if (Cursor R = maybeLexSymbol(C, Token))
|
||||
return R.remaining();
|
||||
|
@@ -54,6 +54,12 @@ struct MIToken {
|
||||
kw_cfi_def_cfa,
|
||||
kw_blockaddress,
|
||||
kw_target_index,
|
||||
kw_half,
|
||||
kw_float,
|
||||
kw_double,
|
||||
kw_x86_fp80,
|
||||
kw_fp128,
|
||||
kw_ppc_fp128,
|
||||
|
||||
// Identifier tokens
|
||||
Identifier,
|
||||
@@ -69,6 +75,7 @@ struct MIToken {
|
||||
|
||||
// Other tokens
|
||||
IntegerLiteral,
|
||||
FloatingPointLiteral,
|
||||
VirtualRegister,
|
||||
ConstantPoolItem,
|
||||
JumpTableIndex,
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "MIParser.h"
|
||||
#include "MILexer.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/AsmParser/SlotMapping.h"
|
||||
#include "llvm/CodeGen/MachineBasicBlock.h"
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
@@ -113,6 +114,7 @@ public:
|
||||
bool parseSubRegisterIndex(unsigned &SubReg);
|
||||
bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false);
|
||||
bool parseImmediateOperand(MachineOperand &Dest);
|
||||
bool parseFPImmediateOperand(MachineOperand &Dest);
|
||||
bool parseMBBReference(MachineBasicBlock *&MBB);
|
||||
bool parseMBBOperand(MachineOperand &Dest);
|
||||
bool parseStackObjectOperand(MachineOperand &Dest);
|
||||
@@ -528,6 +530,22 @@ bool MIParser::parseImmediateOperand(MachineOperand &Dest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
|
||||
auto Loc = Token.location();
|
||||
lex();
|
||||
if (Token.isNot(MIToken::FloatingPointLiteral))
|
||||
return error("expected a floating point literal");
|
||||
auto Source = StringRef(Loc, Token.stringValue().end() - Loc).str();
|
||||
lex();
|
||||
SMDiagnostic Err;
|
||||
const Constant *C =
|
||||
parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent());
|
||||
if (!C)
|
||||
return error(Loc + Err.getColumnNo(), Err.getMessage());
|
||||
Dest = MachineOperand::CreateFPImm(cast<ConstantFP>(C));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MIParser::getUnsigned(unsigned &Result) {
|
||||
assert(Token.hasIntegerValue() && "Expected a token with an integer value");
|
||||
const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1;
|
||||
@@ -860,6 +878,13 @@ bool MIParser::parseMachineOperand(MachineOperand &Dest) {
|
||||
return parseRegisterOperand(Dest);
|
||||
case MIToken::IntegerLiteral:
|
||||
return parseImmediateOperand(Dest);
|
||||
case MIToken::kw_half:
|
||||
case MIToken::kw_float:
|
||||
case MIToken::kw_double:
|
||||
case MIToken::kw_x86_fp80:
|
||||
case MIToken::kw_fp128:
|
||||
case MIToken::kw_ppc_fp128:
|
||||
return parseFPImmediateOperand(Dest);
|
||||
case MIToken::MachineBasicBlock:
|
||||
return parseMBBOperand(Dest);
|
||||
case MIToken::StackObject:
|
||||
|
@@ -513,6 +513,9 @@ void MIPrinter::print(const MachineOperand &Op, const TargetRegisterInfo *TRI) {
|
||||
case MachineOperand::MO_Immediate:
|
||||
OS << Op.getImm();
|
||||
break;
|
||||
case MachineOperand::MO_FPImmediate:
|
||||
Op.getFPImm()->printAsOperand(OS, /*PrintType=*/true, MST);
|
||||
break;
|
||||
case MachineOperand::MO_MachineBasicBlock:
|
||||
printMBBReference(*Op.getMBB());
|
||||
break;
|
||||
|
Reference in New Issue
Block a user