diff options
Diffstat (limited to 'llvm/tools/llvm-mc')
-rw-r--r-- | llvm/tools/llvm-mc/CMakeLists.txt | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-mc/Makefile | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-mc/llvm-mc.cpp | 29 |
3 files changed, 38 insertions, 3 deletions
diff --git a/llvm/tools/llvm-mc/CMakeLists.txt b/llvm/tools/llvm-mc/CMakeLists.txt index b21a4b1b918..d2e9e71b07b 100644 --- a/llvm/tools/llvm-mc/CMakeLists.txt +++ b/llvm/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/llvm/tools/llvm-mc/Makefile b/llvm/tools/llvm-mc/Makefile index 3c327dac1e9..ab9c5b6f608 100644 --- a/llvm/tools/llvm-mc/Makefile +++ b/llvm/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/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index b52edd1ed43..c7f3996c972 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/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) { |