[llvm-commits] [llvm] r77404 - in /llvm/trunk: include/llvm/Target/Target.td lib/Target/X86/AsmParser/X86AsmParser.cpp lib/Target/X86/X86.td utils/TableGen/AsmMatcherEmitter.cpp utils/TableGen/CodeGenTarget.cpp utils/TableGen/CodeGenTarget.h
Daniel Dunbar
daniel at zuster.org
Tue Jul 28 17:02:19 PDT 2009
Author: ddunbar
Date: Tue Jul 28 19:02:19 2009
New Revision: 77404
URL: http://llvm.org/viewvc/llvm-project?rev=77404&view=rev
Log:
Match X86 register names to number.
Modified:
llvm/trunk/include/llvm/Target/Target.td
llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
llvm/trunk/lib/Target/X86/X86.td
llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
llvm/trunk/utils/TableGen/CodeGenTarget.cpp
llvm/trunk/utils/TableGen/CodeGenTarget.h
Modified: llvm/trunk/include/llvm/Target/Target.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/Target.td (original)
+++ llvm/trunk/include/llvm/Target/Target.td Tue Jul 28 19:02:19 2009
@@ -411,6 +411,27 @@
}
//===----------------------------------------------------------------------===//
+// AsmParser - This class can be implemented by targets that wish to implement
+// .s file parsing.
+//
+// Subtargets can have multiple different assembly parsers (e.g. AT&T vs Intel
+// syntax on X86 for example).
+//
+class AsmParser {
+ // AsmWriterClassName - This specifies the suffix to use for the asmwriter
+ // class. Generated AsmWriter classes are always prefixed with the target
+ // name.
+ string AsmParserClassName = "AsmParser";
+
+ // Variant - AsmParsers can be of multiple different variants. Variants are
+ // used to support targets that need to parser multiple formats for the
+ // assembly language.
+ int Variant = 0;
+}
+def DefaultAsmParser : AsmParser;
+
+
+//===----------------------------------------------------------------------===//
// AsmWriter - This class can be implemented by targets that need to customize
// the format of the .s file writer.
//
@@ -445,6 +466,9 @@
// InstructionSet - Instruction set description for this target.
InstrInfo InstructionSet;
+ // AssemblyParsers - The AsmParser instances available for this target.
+ list<AsmParser> AssemblyParsers = [DefaultAsmParser];
+
// AssemblyWriters - The AsmWriter instances available for this target.
list<AsmWriter> AssemblyWriters = [DefaultAsmWriter];
}
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmParser.cpp Tue Jul 28 19:02:19 2009
@@ -42,6 +42,13 @@
bool ParseOperand(X86Operand &Op);
bool ParseMemOperand(X86Operand &Op);
+
+ /// @name Auto-generated Match Functions
+ /// {
+
+ bool MatchRegisterName(const StringRef &Name, unsigned &RegNo);
+
+ /// }
public:
X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
@@ -118,10 +125,17 @@
//
bool X86ATTAsmParser::ParseRegister(X86Operand &Op) {
- assert(getLexer().is(AsmToken::Register) && "Invalid token kind!");
+ AsmToken Tok = getLexer().getTok();
+ assert(Tok.is(AsmToken::Register) && "Invalid token kind!");
- // FIXME: Decode register number.
- Op = X86Operand::CreateReg(123);
+ // FIXME: Validate register for the current architecture; we have to do
+ // validation later, so maybe there is no need for this here.
+ unsigned RegNo;
+ assert(Tok.getString().startswith("%") && "Invalid register name!");
+ if (MatchRegisterName(Tok.getString().substr(1), RegNo))
+ return Error(Tok.getLoc(), "invalid register name");
+
+ Op = X86Operand::CreateReg(RegNo);
getLexer().Lex(); // Eat register token.
return false;
@@ -308,3 +322,5 @@
RegisterAsmParser<X86ATTAsmParser> X(TheX86_32Target);
RegisterAsmParser<X86ATTAsmParser> Y(TheX86_64Target);
}
+
+#include "X86GenAsmMatcher.inc"
Modified: llvm/trunk/lib/Target/X86/X86.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86.td?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86.td (original)
+++ llvm/trunk/lib/Target/X86/X86.td Tue Jul 28 19:02:19 2009
@@ -178,6 +178,12 @@
// Assembly Printers
//===----------------------------------------------------------------------===//
+// Currently the X86 assembly parser only supports ATT syntax.
+def ATTAsmParser : AsmParser {
+ string AsmParserClassName = "ATTAsmParser";
+ int Variant = 0;
+}
+
// The X86 target supports two different syntaxes for emitting machine code.
// This is controlled by the -x86-asm-syntax={att|intel}
def ATTAsmWriter : AsmWriter {
@@ -189,10 +195,11 @@
int Variant = 1;
}
-
def X86 : Target {
// Information about the instructions...
let InstructionSet = X86InstrInfo;
+ let AssemblyParsers = [ATTAsmParser];
+
let AssemblyWriters = [ATTAsmWriter, IntelAsmWriter];
}
Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Tue Jul 28 19:02:19 2009
@@ -20,17 +20,17 @@
void AsmMatcherEmitter::run(raw_ostream &OS) {
CodeGenTarget Target;
const std::vector<CodeGenRegister> &Registers = Target.getRegisters();
+ Record *AsmParser = Target.getAsmParser();
+ std::string ClassName = AsmParser->getValueAsString("AsmParserClassName");
std::string Namespace = Registers[0].TheDef->getValueAsString("Namespace");
EmitSourceFileHeader("Assembly Matcher Source Fragment", OS);
- OS << "namespace llvm {\n\n";
// Emit the function to match a register name to number.
- if (!Namespace.empty())
- OS << "namespace " << Namespace << " {\n";
- OS << "bool MatchRegisterName(const std::string &Name, unsigned &RegNo) {\n";
+ OS << "bool " << Target.getName() << ClassName
+ << "::MatchRegisterName(const StringRef &Name, unsigned &RegNo) {\n";
// FIXME: TableGen should have a fast string matcher generator.
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
@@ -44,8 +44,4 @@
}
OS << " return true;\n";
OS << "}\n";
-
- if (!Namespace.empty())
- OS << "}\n";
- OS << "} // End llvm namespace \n";
}
Modified: llvm/trunk/utils/TableGen/CodeGenTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.cpp?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.cpp Tue Jul 28 19:02:19 2009
@@ -23,6 +23,10 @@
using namespace llvm;
static cl::opt<unsigned>
+AsmParserNum("asmparsernum", cl::init(0),
+ cl::desc("Make -gen-asm-parser emit assembly parser #N"));
+
+static cl::opt<unsigned>
AsmWriterNum("asmwriternum", cl::init(0),
cl::desc("Make -gen-asm-writer emit assembly writer #N"));
@@ -133,6 +137,15 @@
return TargetRec->getValueAsDef("InstructionSet");
}
+/// getAsmParser - Return the AssemblyParser definition for this target.
+///
+Record *CodeGenTarget::getAsmParser() const {
+ std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
+ if (AsmParserNum >= LI.size())
+ throw "Target does not have an AsmParser #" + utostr(AsmParserNum) + "!";
+ return LI[AsmParserNum];
+}
+
/// getAsmWriter - Return the AssemblyWriter definition for this target.
///
Record *CodeGenTarget::getAsmWriter() const {
Modified: llvm/trunk/utils/TableGen/CodeGenTarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.h?rev=77404&r1=77403&r2=77404&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.h Tue Jul 28 19:02:19 2009
@@ -87,6 +87,10 @@
///
Record *getInstructionSet() const;
+ /// getAsmParser - Return the AssemblyParser definition for this target.
+ ///
+ Record *getAsmParser() const;
+
/// getAsmWriter - Return the AssemblyWriter definition for this target.
///
Record *getAsmWriter() const;
More information about the llvm-commits
mailing list