diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-17 22:38:58 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-17 22:38:58 +0000 |
commit | 137a2a4c442c8387d73193955a3ceb0756158714 (patch) | |
tree | 798dca05cc66cf81e982d211b009becd5d69df10 /tools | |
parent | dab416d0826c4448399e424d539b0c2fcc5a4737 (diff) | |
download | external_llvm-137a2a4c442c8387d73193955a3ceb0756158714.zip external_llvm-137a2a4c442c8387d73193955a3ceb0756158714.tar.gz external_llvm-137a2a4c442c8387d73193955a3ceb0756158714.tar.bz2 |
llvm-mc: Add -triple, and start fetching the target asm printer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76257 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-mc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-mc/Makefile | 10 | ||||
-rw-r--r-- | tools/llvm-mc/llvm-mc.cpp | 29 |
3 files changed, 38 insertions, 3 deletions
diff --git a/tools/llvm-mc/CMakeLists.txt b/tools/llvm-mc/CMakeLists.txt index b21a4b1..d2e9e71 100644 --- a/tools/llvm-mc/CMakeLists.txt +++ b/tools/llvm-mc/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLVM_LINK_COMPONENTS support MC) +set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} support MC) add_llvm_tool(llvm-mc llvm-mc.cpp diff --git a/tools/llvm-mc/Makefile b/tools/llvm-mc/Makefile index 3c327da..ab9c5b6 100644 --- a/tools/llvm-mc/Makefile +++ b/tools/llvm-mc/Makefile @@ -9,9 +9,15 @@ LEVEL = ../.. TOOLNAME = llvm-mc -LINK_COMPONENTS := support MC # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 -include $(LEVEL)/Makefile.common +# Include this here so we can get the configuration of the targets +# that have been configured for construction. We have to do this +# early so we can set up LINK_COMPONENTS before including Makefile.rules +include $(LEVEL)/Makefile.config + +LINK_COMPONENTS := $(TARGETS_TO_BUILD) MC support + +include $(LLVM_SRC_ROOT)/Makefile.rules diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index b52edd1..c7f3996 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -22,6 +22,8 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Signals.h" +#include "llvm/Target/TargetRegistry.h" +#include "llvm/Target/TargetSelect.h" #include "AsmParser.h" using namespace llvm; @@ -36,6 +38,11 @@ static cl::list<std::string> IncludeDirs("I", cl::desc("Directory of include files"), cl::value_desc("directory"), cl::Prefix); +static cl::opt<std::string> +Triple("triple", cl::desc("Target triple to assemble for," + "see -version for available targets"), + cl::init("")); + enum ActionType { AC_AsLex, AC_Assemble @@ -137,6 +144,23 @@ static int AsLexInput(const char *ProgName) { } static int AssembleInput(const char *ProgName) { + // Get the target specific parser. + std::string Error; + const Target *TheTarget = + TargetRegistry::getClosestStaticTargetForTriple(Triple, Error); + if (TheTarget == 0) { + errs() << ProgName << ": error: unable to get target for '" << Triple + << "', see --version and --triple.\n"; + return 1; + } + + TargetAsmParser *TAP = TheTarget->createAsmParser(); + if (!TAP) { + errs() << ProgName + << ": error: this target does not support assembly parsing.\n"; + return 1; + } + std::string ErrorMessage; MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage); @@ -174,6 +198,11 @@ int main(int argc, char **argv) { sys::PrintStackTraceOnErrorSignal(); PrettyStackTraceProgram X(argc, argv); llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + + // Initialize targets and assembly parsers. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllAsmParsers(); + cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); switch (Action) { |