mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-13 09:33:50 +00:00
add facilities to start factoring instruction metadata parsing
out of each opcode's handler. Change ret over so far. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92298 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
628c13ad76
commit
f1bc7ce7b3
@ -2813,10 +2813,26 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ParseInstruction(Inst, BB, PFS)) return true;
|
switch (ParseInstruction(Inst, BB, PFS)) {
|
||||||
|
default: assert(0 && "Unknown ParseInstruction result!");
|
||||||
if (EatIfPresent(lltok::comma))
|
case InstError: return true;
|
||||||
ParseOptionalCustomMetadata();
|
case InstNormal:
|
||||||
|
// With a normal result, we check to see if the instruction is followed by
|
||||||
|
// a comma and metadata.
|
||||||
|
if (EatIfPresent(lltok::comma))
|
||||||
|
if (ParseOptionalCustomMetadata())
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case InstExtraComma:
|
||||||
|
// If the instruction parser ate an extra comma at the end of it, it
|
||||||
|
// *must* be followed by metadata.
|
||||||
|
if (Lex.getKind() != lltok::MetadataVar)
|
||||||
|
return TokError("expected metadata after comma");
|
||||||
|
// Parse it.
|
||||||
|
if (ParseOptionalCustomMetadata())
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Set metadata attached with this instruction.
|
// Set metadata attached with this instruction.
|
||||||
for (SmallVector<std::pair<unsigned, MDNode *>, 2>::iterator
|
for (SmallVector<std::pair<unsigned, MDNode *>, 2>::iterator
|
||||||
@ -2839,8 +2855,8 @@ bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
|
|||||||
|
|
||||||
/// ParseInstruction - Parse one of the many different instructions.
|
/// ParseInstruction - Parse one of the many different instructions.
|
||||||
///
|
///
|
||||||
bool LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
||||||
PerFunctionState &PFS) {
|
PerFunctionState &PFS) {
|
||||||
lltok::Kind Token = Lex.getKind();
|
lltok::Kind Token = Lex.getKind();
|
||||||
if (Token == lltok::Eof)
|
if (Token == lltok::Eof)
|
||||||
return TokError("found end of file when expecting more instructions");
|
return TokError("found end of file when expecting more instructions");
|
||||||
@ -3008,8 +3024,8 @@ bool LLParser::ParseCmpPredicate(unsigned &P, unsigned Opc) {
|
|||||||
/// ::= 'ret' TypeAndValue (',' !dbg, !1)*
|
/// ::= 'ret' TypeAndValue (',' !dbg, !1)*
|
||||||
/// ::= 'ret' TypeAndValue (',' TypeAndValue)+ (',' !dbg, !1)*
|
/// ::= 'ret' TypeAndValue (',' TypeAndValue)+ (',' !dbg, !1)*
|
||||||
/// [[obsolete: LLVM 3.0]]
|
/// [[obsolete: LLVM 3.0]]
|
||||||
bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
|
int LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
|
||||||
PerFunctionState &PFS) {
|
PerFunctionState &PFS) {
|
||||||
PATypeHolder Ty(Type::getVoidTy(Context));
|
PATypeHolder Ty(Type::getVoidTy(Context));
|
||||||
if (ParseType(Ty, true /*void allowed*/)) return true;
|
if (ParseType(Ty, true /*void allowed*/)) return true;
|
||||||
|
|
||||||
@ -3021,10 +3037,11 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
|
|||||||
Value *RV;
|
Value *RV;
|
||||||
if (ParseValue(Ty, RV, PFS)) return true;
|
if (ParseValue(Ty, RV, PFS)) return true;
|
||||||
|
|
||||||
|
bool ExtraComma = false;
|
||||||
if (EatIfPresent(lltok::comma)) {
|
if (EatIfPresent(lltok::comma)) {
|
||||||
// Parse optional custom metadata, e.g. !dbg
|
// Parse optional custom metadata, e.g. !dbg
|
||||||
if (Lex.getKind() == lltok::MetadataVar) {
|
if (Lex.getKind() == lltok::MetadataVar) {
|
||||||
if (ParseOptionalCustomMetadata()) return true;
|
ExtraComma = true;
|
||||||
} else {
|
} else {
|
||||||
// The normal case is one return value.
|
// The normal case is one return value.
|
||||||
// FIXME: LLVM 3.0 remove MRV support for 'ret i32 1, i32 2', requiring
|
// FIXME: LLVM 3.0 remove MRV support for 'ret i32 1, i32 2', requiring
|
||||||
@ -3051,7 +3068,7 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Inst = ReturnInst::Create(Context, RV);
|
Inst = ReturnInst::Create(Context, RV);
|
||||||
return false;
|
return ExtraComma ? InstExtraComma : InstNormal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -316,12 +316,14 @@ namespace llvm {
|
|||||||
bool ParseFunctionBody(Function &Fn);
|
bool ParseFunctionBody(Function &Fn);
|
||||||
bool ParseBasicBlock(PerFunctionState &PFS);
|
bool ParseBasicBlock(PerFunctionState &PFS);
|
||||||
|
|
||||||
// Instruction Parsing.
|
// Instruction Parsing. Each instruction parsing routine can return with a
|
||||||
bool ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
// normal result, an error result, or return having eaten an extra comma.
|
||||||
PerFunctionState &PFS);
|
enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
|
||||||
|
int ParseInstruction(Instruction *&Inst, BasicBlock *BB,
|
||||||
|
PerFunctionState &PFS);
|
||||||
bool ParseCmpPredicate(unsigned &Pred, unsigned Opc);
|
bool ParseCmpPredicate(unsigned &Pred, unsigned Opc);
|
||||||
|
|
||||||
bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
|
int ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
|
||||||
bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
|
bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
|
||||||
bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
|
bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
|
||||||
bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
|
bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user