mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
[mips] [IAS] Add support for the .insn directive.
Summary: This assembler directive marks the current label as an instruction label in microMIPS and MIPS16. This initial implementation works only for microMIPS. Reviewers: dsanders Reviewed By: dsanders Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8006 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235084 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -220,6 +220,7 @@ class MipsAsmParser : public MCTargetAsmParser {
|
|||||||
bool parseDirectiveNaN();
|
bool parseDirectiveNaN();
|
||||||
bool parseDirectiveSet();
|
bool parseDirectiveSet();
|
||||||
bool parseDirectiveOption();
|
bool parseDirectiveOption();
|
||||||
|
bool parseInsnDirective();
|
||||||
|
|
||||||
bool parseSetAtDirective();
|
bool parseSetAtDirective();
|
||||||
bool parseSetNoAtDirective();
|
bool parseSetNoAtDirective();
|
||||||
@@ -4045,6 +4046,23 @@ bool MipsAsmParser::parseDirectiveOption() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// parseInsnDirective
|
||||||
|
/// ::= .insn
|
||||||
|
bool MipsAsmParser::parseInsnDirective() {
|
||||||
|
// If this is not the end of the statement, report an error.
|
||||||
|
if (getLexer().isNot(AsmToken::EndOfStatement)) {
|
||||||
|
reportParseError("unexpected token, expected end of statement");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The actual label marking happens in
|
||||||
|
// MipsELFStreamer::createPendingLabelRelocs().
|
||||||
|
getTargetStreamer().emitDirectiveInsn();
|
||||||
|
|
||||||
|
getParser().Lex(); // Eat EndOfStatement token.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// parseDirectiveModule
|
/// parseDirectiveModule
|
||||||
/// ::= .module oddspreg
|
/// ::= .module oddspreg
|
||||||
/// ::= .module nooddspreg
|
/// ::= .module nooddspreg
|
||||||
@@ -4438,6 +4456,9 @@ bool MipsAsmParser::ParseDirective(AsmToken DirectiveID) {
|
|||||||
if (IDVal == ".llvm_internal_mips_reallow_module_directive")
|
if (IDVal == ".llvm_internal_mips_reallow_module_directive")
|
||||||
return parseInternalDirectiveReallowModule();
|
return parseInternalDirectiveReallowModule();
|
||||||
|
|
||||||
|
if (IDVal == ".insn")
|
||||||
|
return parseInsnDirective();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,8 +21,6 @@ void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
|
|||||||
|
|
||||||
MCContext &Context = getContext();
|
MCContext &Context = getContext();
|
||||||
const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
|
const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
|
||||||
MipsTargetELFStreamer *ELFTargetStreamer =
|
|
||||||
static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
|
|
||||||
|
|
||||||
for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
|
for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
|
||||||
const MCOperand &Op = Inst.getOperand(OpIndex);
|
const MCOperand &Op = Inst.getOperand(OpIndex);
|
||||||
@@ -34,6 +32,14 @@ void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
|
|||||||
RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
|
RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createPendingLabelRelocs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MipsELFStreamer::createPendingLabelRelocs() {
|
||||||
|
MipsTargetELFStreamer *ELFTargetStreamer =
|
||||||
|
static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
|
||||||
|
|
||||||
|
// FIXME: Also mark labels when in MIPS16 mode.
|
||||||
if (ELFTargetStreamer->isMicroMipsEnabled()) {
|
if (ELFTargetStreamer->isMicroMipsEnabled()) {
|
||||||
for (auto Label : Labels) {
|
for (auto Label : Labels) {
|
||||||
MCSymbolData &Data = getOrCreateSymbolData(Label);
|
MCSymbolData &Data = getOrCreateSymbolData(Label);
|
||||||
|
@@ -65,6 +65,9 @@ public:
|
|||||||
|
|
||||||
/// Emits all the option records stored up until the point it's called.
|
/// Emits all the option records stored up until the point it's called.
|
||||||
void EmitMipsOptionRecords();
|
void EmitMipsOptionRecords();
|
||||||
|
|
||||||
|
/// Mark labels as microMIPS, if necessary for the subtarget.
|
||||||
|
void createPendingLabelRelocs();
|
||||||
};
|
};
|
||||||
|
|
||||||
MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
|
MCELFStreamer *createMipsELFStreamer(MCContext &Context, MCAsmBackend &MAB,
|
||||||
|
@@ -54,6 +54,7 @@ void MipsTargetStreamer::emitDirectiveNaN2008() {}
|
|||||||
void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
|
void MipsTargetStreamer::emitDirectiveNaNLegacy() {}
|
||||||
void MipsTargetStreamer::emitDirectiveOptionPic0() {}
|
void MipsTargetStreamer::emitDirectiveOptionPic0() {}
|
||||||
void MipsTargetStreamer::emitDirectiveOptionPic2() {}
|
void MipsTargetStreamer::emitDirectiveOptionPic2() {}
|
||||||
|
void MipsTargetStreamer::emitDirectiveInsn() { forbidModuleDirective(); }
|
||||||
void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
void MipsTargetStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg) {}
|
unsigned ReturnReg) {}
|
||||||
void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
|
void MipsTargetStreamer::emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) {}
|
||||||
@@ -189,6 +190,11 @@ void MipsTargetAsmStreamer::emitDirectiveOptionPic2() {
|
|||||||
OS << "\t.option\tpic2\n";
|
OS << "\t.option\tpic2\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MipsTargetAsmStreamer::emitDirectiveInsn() {
|
||||||
|
MipsTargetStreamer::emitDirectiveInsn();
|
||||||
|
OS << "\t.insn\n";
|
||||||
|
}
|
||||||
|
|
||||||
void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg) {
|
unsigned ReturnReg) {
|
||||||
OS << "\t.frame\t$"
|
OS << "\t.frame\t$"
|
||||||
@@ -637,6 +643,12 @@ void MipsTargetELFStreamer::emitDirectiveOptionPic2() {
|
|||||||
MCA.setELFHeaderEFlags(Flags);
|
MCA.setELFHeaderEFlags(Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MipsTargetELFStreamer::emitDirectiveInsn() {
|
||||||
|
MipsTargetStreamer::emitDirectiveInsn();
|
||||||
|
MipsELFStreamer &MEF = static_cast<MipsELFStreamer &>(Streamer);
|
||||||
|
MEF.createPendingLabelRelocs();
|
||||||
|
}
|
||||||
|
|
||||||
void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg_) {
|
unsigned ReturnReg_) {
|
||||||
MCContext &Context = getStreamer().getAssembler().getContext();
|
MCContext &Context = getStreamer().getAssembler().getContext();
|
||||||
|
@@ -45,6 +45,7 @@ public:
|
|||||||
virtual void emitDirectiveNaNLegacy();
|
virtual void emitDirectiveNaNLegacy();
|
||||||
virtual void emitDirectiveOptionPic0();
|
virtual void emitDirectiveOptionPic0();
|
||||||
virtual void emitDirectiveOptionPic2();
|
virtual void emitDirectiveOptionPic2();
|
||||||
|
virtual void emitDirectiveInsn();
|
||||||
virtual void emitFrame(unsigned StackReg, unsigned StackSize,
|
virtual void emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg);
|
unsigned ReturnReg);
|
||||||
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
|
virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
|
||||||
@@ -160,6 +161,7 @@ public:
|
|||||||
void emitDirectiveNaNLegacy() override;
|
void emitDirectiveNaNLegacy() override;
|
||||||
void emitDirectiveOptionPic0() override;
|
void emitDirectiveOptionPic0() override;
|
||||||
void emitDirectiveOptionPic2() override;
|
void emitDirectiveOptionPic2() override;
|
||||||
|
void emitDirectiveInsn() override;
|
||||||
void emitFrame(unsigned StackReg, unsigned StackSize,
|
void emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg) override;
|
unsigned ReturnReg) override;
|
||||||
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
|
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
|
||||||
@@ -227,6 +229,7 @@ public:
|
|||||||
void emitDirectiveNaNLegacy() override;
|
void emitDirectiveNaNLegacy() override;
|
||||||
void emitDirectiveOptionPic0() override;
|
void emitDirectiveOptionPic0() override;
|
||||||
void emitDirectiveOptionPic2() override;
|
void emitDirectiveOptionPic2() override;
|
||||||
|
void emitDirectiveInsn() override;
|
||||||
void emitFrame(unsigned StackReg, unsigned StackSize,
|
void emitFrame(unsigned StackReg, unsigned StackSize,
|
||||||
unsigned ReturnReg) override;
|
unsigned ReturnReg) override;
|
||||||
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
|
void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
|
||||||
|
98
test/MC/Mips/insn-directive.s
Normal file
98
test/MC/Mips/insn-directive.s
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 | FileCheck %s --check-prefix=ASM
|
||||||
|
|
||||||
|
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -filetype=obj -o - | \
|
||||||
|
# RUN: llvm-readobj -symbols - | FileCheck %s --check-prefix=OBJ
|
||||||
|
|
||||||
|
.set micromips
|
||||||
|
|
||||||
|
.global f_mm_insn_data
|
||||||
|
.type f_mm_insn_data, @function
|
||||||
|
f_mm_insn_data:
|
||||||
|
.insn
|
||||||
|
.word 0x00e73910 # add $7, $7, $7
|
||||||
|
|
||||||
|
.global f_mm_insn_instr
|
||||||
|
.type f_mm_insn_instr, @function
|
||||||
|
f_mm_insn_instr:
|
||||||
|
.insn
|
||||||
|
add $7, $7, $7
|
||||||
|
|
||||||
|
.global o_mm_insn_data
|
||||||
|
.type o_mm_insn_data, @object
|
||||||
|
o_mm_insn_data:
|
||||||
|
.insn
|
||||||
|
.word 0x00e73910 # add $7, $7, $7
|
||||||
|
|
||||||
|
.global o_mm_insn_instr
|
||||||
|
.type o_mm_insn_instr, @object
|
||||||
|
o_mm_insn_instr:
|
||||||
|
.insn
|
||||||
|
add $7, $7, $7
|
||||||
|
|
||||||
|
.set nomicromips
|
||||||
|
|
||||||
|
.global f_normal_insn_data
|
||||||
|
.type f_normal_insn_data, @function
|
||||||
|
f_normal_insn_data:
|
||||||
|
.insn
|
||||||
|
.word 0x00e73820 # add $7, $7, $7
|
||||||
|
|
||||||
|
.global f_normal_insn_instr
|
||||||
|
.type f_normal_insn_instr, @function
|
||||||
|
f_normal_insn_instr:
|
||||||
|
.insn
|
||||||
|
add $7, $7, $7
|
||||||
|
|
||||||
|
.global o_normal_insn_data
|
||||||
|
.type o_normal_insn_data, @object
|
||||||
|
o_normal_insn_data:
|
||||||
|
.insn
|
||||||
|
.word 0x00e73820 # add $7, $7, $7
|
||||||
|
|
||||||
|
.global o_normal_insn_instr
|
||||||
|
.type o_normal_insn_instr, @object
|
||||||
|
o_normal_insn_instr:
|
||||||
|
.insn
|
||||||
|
add $7, $7, $7
|
||||||
|
|
||||||
|
# Verify that .insn causes the currently saved labels to be cleared by checking
|
||||||
|
# that foo doesn't get marked.
|
||||||
|
.set nomicromips
|
||||||
|
foo:
|
||||||
|
.insn
|
||||||
|
.word 0x00e73820 # add $7, $7, $7
|
||||||
|
|
||||||
|
.set micromips
|
||||||
|
bar:
|
||||||
|
add $7, $7, $7
|
||||||
|
|
||||||
|
# ASM: .insn
|
||||||
|
|
||||||
|
# OBJ: Symbols [
|
||||||
|
# OBJ: Name: foo
|
||||||
|
# OBJ: Other: 0
|
||||||
|
|
||||||
|
# OBJ: Name: f_mm_insn_data
|
||||||
|
# OBJ: Other: 128
|
||||||
|
|
||||||
|
# OBJ: Name: f_mm_insn_instr
|
||||||
|
# OBJ: Other: 128
|
||||||
|
|
||||||
|
# OBJ: Name: f_normal_insn_data
|
||||||
|
# OBJ: Other: 0
|
||||||
|
|
||||||
|
# OBJ: Name: f_normal_insn_instr
|
||||||
|
# OBJ: Other: 0
|
||||||
|
|
||||||
|
# OBJ: Name: o_mm_insn_data
|
||||||
|
# OBJ: Other: 128
|
||||||
|
|
||||||
|
# OBJ: Name: o_mm_insn_instr
|
||||||
|
# OBJ: Other: 128
|
||||||
|
|
||||||
|
# OBJ: Name: o_normal_insn_data
|
||||||
|
# OBJ: Other: 0
|
||||||
|
|
||||||
|
# OBJ: Name: o_normal_insn_instr
|
||||||
|
# OBJ: Other: 0
|
||||||
|
# OBJ: ]
|
Reference in New Issue
Block a user