mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 22:24:07 +00:00
Add infrastructure to allow post instruction printing action triggers.
We'll eventually use this to print comments in asm files and do other fun things. This adds interfaces to the AsmPrinter and changes TableGen to invoke the postInstructionAction when appropriate. It also add parameters to TargetAsmInfo to control comment layout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -34,6 +34,7 @@ namespace llvm {
|
|||||||
class MachineConstantPoolEntry;
|
class MachineConstantPoolEntry;
|
||||||
class MachineConstantPoolValue;
|
class MachineConstantPoolValue;
|
||||||
class MachineModuleInfo;
|
class MachineModuleInfo;
|
||||||
|
class MCInst;
|
||||||
class DwarfWriter;
|
class DwarfWriter;
|
||||||
class Mangler;
|
class Mangler;
|
||||||
class Section;
|
class Section;
|
||||||
@ -332,6 +333,17 @@ namespace llvm {
|
|||||||
/// debug tables.
|
/// debug tables.
|
||||||
void printDeclare(const MachineInstr *MI) const;
|
void printDeclare(const MachineInstr *MI) const;
|
||||||
|
|
||||||
|
/// postInstructionAction - Handling printing of items after the
|
||||||
|
/// instruction iteself has been printed (e.g. comments)
|
||||||
|
void postInstructionAction(const MachineInstr &MI) const {
|
||||||
|
postInstructionActionImpl(MI);
|
||||||
|
EmitComments(MI);
|
||||||
|
}
|
||||||
|
void postInstructionAction(const MCInst &MI) const {
|
||||||
|
postInstructionActionImpl(MI);
|
||||||
|
EmitComments(MI);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// EmitZeros - Emit a block of zeros.
|
/// EmitZeros - Emit a block of zeros.
|
||||||
///
|
///
|
||||||
@ -408,6 +420,14 @@ namespace llvm {
|
|||||||
void EmitGlobalConstantFP(const ConstantFP* CFP, unsigned AddrSpace);
|
void EmitGlobalConstantFP(const ConstantFP* CFP, unsigned AddrSpace);
|
||||||
void EmitGlobalConstantLargeInt(const ConstantInt* CI, unsigned AddrSpace);
|
void EmitGlobalConstantLargeInt(const ConstantInt* CI, unsigned AddrSpace);
|
||||||
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
|
GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
|
||||||
|
|
||||||
|
/// EmitComments - Pretty-print comments for instructions
|
||||||
|
void EmitComments(const MachineInstr &MI) const;
|
||||||
|
/// EmitComments - Pretty-print comments for instructions
|
||||||
|
void EmitComments(const MCInst &MI) const;
|
||||||
|
|
||||||
|
virtual void postInstructionActionImpl(const MachineInstr &MI) const {}
|
||||||
|
virtual void postInstructionActionImpl(const MCInst &MI) const {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,6 +214,10 @@ namespace llvm {
|
|||||||
/// measure inline asm instructions.
|
/// measure inline asm instructions.
|
||||||
char SeparatorChar; // Defaults to ';'
|
char SeparatorChar; // Defaults to ';'
|
||||||
|
|
||||||
|
/// CommentColumn - This indicates the comment num (zero-based) at
|
||||||
|
/// which asm comments should be printed.
|
||||||
|
unsigned CommentColumn; // Defaults to 60
|
||||||
|
|
||||||
/// CommentString - This indicates the comment character used by the
|
/// CommentString - This indicates the comment character used by the
|
||||||
/// assembler.
|
/// assembler.
|
||||||
const char *CommentString; // Defaults to "#"
|
const char *CommentString; // Defaults to "#"
|
||||||
@ -693,6 +697,9 @@ namespace llvm {
|
|||||||
char getSeparatorChar() const {
|
char getSeparatorChar() const {
|
||||||
return SeparatorChar;
|
return SeparatorChar;
|
||||||
}
|
}
|
||||||
|
const unsigned getCommentColumn() const {
|
||||||
|
return CommentColumn;
|
||||||
|
}
|
||||||
const char *getCommentString() const {
|
const char *getCommentString() const {
|
||||||
return CommentString;
|
return CommentString;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "llvm/Analysis/DebugInfo.h"
|
#include "llvm/Analysis/DebugInfo.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
#include "llvm/Support/FormattedStream.h"
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Target/TargetAsmInfo.h"
|
#include "llvm/Target/TargetAsmInfo.h"
|
||||||
@ -1748,3 +1749,15 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
|
|||||||
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
||||||
llvm_unreachable();
|
llvm_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// EmitComments - Pretty-print comments for instructions
|
||||||
|
void AsmPrinter::EmitComments(const MachineInstr &MI) const
|
||||||
|
{
|
||||||
|
// No comments in MachineInstr yet
|
||||||
|
}
|
||||||
|
|
||||||
|
/// EmitComments - Pretty-print comments for instructions
|
||||||
|
void AsmPrinter::EmitComments(const MCInst &MI) const
|
||||||
|
{
|
||||||
|
// No comments in MCInst yet
|
||||||
|
}
|
||||||
|
@ -43,6 +43,7 @@ TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
|
|||||||
MaxInstLength = 4;
|
MaxInstLength = 4;
|
||||||
PCSymbol = "$";
|
PCSymbol = "$";
|
||||||
SeparatorChar = ';';
|
SeparatorChar = ';';
|
||||||
|
CommentColumn = 60;
|
||||||
CommentString = "#";
|
CommentString = "#";
|
||||||
GlobalPrefix = "";
|
GlobalPrefix = "";
|
||||||
PrivateGlobalPrefix = ".";
|
PrivateGlobalPrefix = ".";
|
||||||
|
@ -259,8 +259,6 @@ AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
|
|||||||
LastEmitted = VarEnd;
|
LastEmitted = VarEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AddLiteralString("\\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// MatchesAllButOneOp - If this instruction is exactly identical to the
|
/// MatchesAllButOneOp - If this instruction is exactly identical to the
|
||||||
@ -357,7 +355,6 @@ static void EmitInstructions(std::vector<AsmWriterInst> &Insts,
|
|||||||
}
|
}
|
||||||
O << "\n";
|
O << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
O << " break;\n";
|
O << " break;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,8 +382,12 @@ FindUniqueOperandCommands(std::vector<std::string> &UniqueOperandCommands,
|
|||||||
Command = " " + Inst->Operands[0].getCode() + "\n";
|
Command = " " + Inst->Operands[0].getCode() + "\n";
|
||||||
|
|
||||||
// If this is the last operand, emit a return.
|
// If this is the last operand, emit a return.
|
||||||
if (Inst->Operands.size() == 1)
|
if (Inst->Operands.size() == 1) {
|
||||||
|
Command += " postInstructionAction(*MI);\n";
|
||||||
|
// Print the final newline
|
||||||
|
Command += " O << \"\\n\";\n";
|
||||||
Command += " return true;\n";
|
Command += " return true;\n";
|
||||||
|
}
|
||||||
|
|
||||||
// Check to see if we already have 'Command' in UniqueOperandCommands.
|
// Check to see if we already have 'Command' in UniqueOperandCommands.
|
||||||
// If not, add it.
|
// If not, add it.
|
||||||
@ -452,8 +453,12 @@ FindUniqueOperandCommands(std::vector<std::string> &UniqueOperandCommands,
|
|||||||
std::string Command = " " + FirstInst->Operands[Op].getCode() + "\n";
|
std::string Command = " " + FirstInst->Operands[Op].getCode() + "\n";
|
||||||
|
|
||||||
// If this is the last operand, emit a return after the code.
|
// If this is the last operand, emit a return after the code.
|
||||||
if (FirstInst->Operands.size() == Op+1)
|
if (FirstInst->Operands.size() == Op+1) {
|
||||||
|
Command += " postInstructionAction(*MI);\n";
|
||||||
|
// Print the final newline
|
||||||
|
Command += " O << \"\\n\";\n";
|
||||||
Command += " return true;\n";
|
Command += " return true;\n";
|
||||||
|
}
|
||||||
|
|
||||||
UniqueOperandCommands[CommandIdx] += Command;
|
UniqueOperandCommands[CommandIdx] += Command;
|
||||||
InstOpsUsed[CommandIdx]++;
|
InstOpsUsed[CommandIdx]++;
|
||||||
@ -564,7 +569,8 @@ void AsmWriterEmitter::run(raw_ostream &O) {
|
|||||||
// For the first operand check, add a default value for instructions with
|
// For the first operand check, add a default value for instructions with
|
||||||
// just opcode strings to use.
|
// just opcode strings to use.
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
UniqueOperandCommands.push_back(" return true;\n");
|
// Do the post instruction processing and print the final newline
|
||||||
|
UniqueOperandCommands.push_back(" postInstructionAction(*MI);\n O << \"\\n\";\n return true;\n");
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,6 +745,9 @@ void AsmWriterEmitter::run(raw_ostream &O) {
|
|||||||
EmitInstructions(Instructions, O);
|
EmitInstructions(Instructions, O);
|
||||||
|
|
||||||
O << " }\n";
|
O << " }\n";
|
||||||
|
O << " postInstructionAction(*MI);\n";
|
||||||
|
// Print the final newline
|
||||||
|
O << " O << \"\\n\";\n";
|
||||||
O << " return true;\n";
|
O << " return true;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user