summaryrefslogtreecommitdiff
path: root/tools/llvm-mc/llvm-mc.cpp
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2009-09-04 21:45:34 +0000
committerKevin Enderby <enderby@apple.com>2009-09-04 21:45:34 +0000
commit9823ca971d5cb475401e59fde244caf5087c74a1 (patch)
tree96b87e75cf825093e41b7784be3f0042e50d587f /tools/llvm-mc/llvm-mc.cpp
parent68f195cc50a8b7722004c8f3ca3dcf624b524552 (diff)
downloadllvm-9823ca971d5cb475401e59fde244caf5087c74a1.tar.gz
llvm-9823ca971d5cb475401e59fde244caf5087c74a1.tar.bz2
llvm-9823ca971d5cb475401e59fde244caf5087c74a1.tar.xz
Added the AsmToken::Hash enum constant to MCAsmLexer.h in preparation of
supporting other targets. Changed the code to pass MCAsmInfo to the parser and the lexer. Then changed the lexer to use CommentString from MCAsmInfo instead of a literal '#' character. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81046 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/llvm-mc.cpp')
-rw-r--r--tools/llvm-mc/llvm-mc.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index 84131c7ca6..bf3c01794b 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -82,6 +82,18 @@ Action(cl::desc("Action to perform:"),
"Assemble a .s file (default)"),
clEnumValEnd));
+static const Target *GetTarget(const char *ProgName) {
+ // Get the target specific parser.
+ std::string Error;
+ const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
+ if (TheTarget)
+ return TheTarget;
+
+ errs() << ProgName << ": error: unable to get target for '" << TripleName
+ << "', see --version and --triple.\n";
+ return 0;
+}
+
static int AsLexInput(const char *ProgName) {
std::string ErrorMessage;
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
@@ -104,7 +116,14 @@ static int AsLexInput(const char *ProgName) {
// it later.
SrcMgr.setIncludeDirs(IncludeDirs);
- AsmLexer Lexer(SrcMgr);
+ const Target *TheTarget = GetTarget(ProgName);
+ if (!TheTarget)
+ return 1;
+
+ const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName);
+ assert(MAI && "Unable to create target asm info!");
+
+ AsmLexer Lexer(SrcMgr, *MAI);
bool Error = false;
@@ -162,18 +181,6 @@ static int AsLexInput(const char *ProgName) {
return Error;
}
-static const Target *GetTarget(const char *ProgName) {
- // Get the target specific parser.
- std::string Error;
- const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, Error);
- if (TheTarget)
- return TheTarget;
-
- errs() << ProgName << ": error: unable to get target for '" << TripleName
- << "', see --version and --triple.\n";
- return 0;
-}
-
static formatted_raw_ostream *GetOutputStream() {
if (OutputFilename == "")
OutputFilename = "-";
@@ -239,10 +246,10 @@ static int AssembleInput(const char *ProgName) {
OwningPtr<MCCodeEmitter> CE;
OwningPtr<MCStreamer> Str;
- if (FileType == OFT_AssemblyFile) {
- const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName);
- assert(MAI && "Unable to create target asm info!");
+ const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName);
+ assert(MAI && "Unable to create target asm info!");
+ if (FileType == OFT_AssemblyFile) {
AP.reset(TheTarget->createAsmPrinter(*Out, *TM, MAI, true));
if (ShowEncoding)
CE.reset(TheTarget->createCodeEmitter(*TM));
@@ -253,7 +260,7 @@ static int AssembleInput(const char *ProgName) {
Str.reset(createMachOStreamer(Ctx, *Out, CE.get()));
}
- AsmParser Parser(SrcMgr, Ctx, *Str.get());
+ AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI);
OwningPtr<TargetAsmParser> TAP(TheTarget->createAsmParser(Parser));
if (!TAP) {
errs() << ProgName