diff --git a/lib/MC/TargetAsmParser.cpp b/lib/MC/TargetAsmParser.cpp new file mode 100644 index 00000000000..05760c96cc6 --- /dev/null +++ b/lib/MC/TargetAsmParser.cpp @@ -0,0 +1,19 @@ +//===-- TargetAsmParser.cpp - Target Assembly Parser -----------------------==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Target/TargetAsmParser.h" +using namespace llvm; + +TargetAsmParser::TargetAsmParser(const Target &T) + : TheTarget(T) +{ +} + +TargetAsmParser::~TargetAsmParser() { +} diff --git a/test/MC/AsmParser/assignment.s b/test/MC/AsmParser/assignment.s index 4e6916ad25b..882fae8bae6 100644 --- a/test/MC/AsmParser/assignment.s +++ b/test/MC/AsmParser/assignment.s @@ -1,7 +1,7 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: a = 0 TEST0: a = 0 - \ No newline at end of file + diff --git a/test/MC/AsmParser/directive_abort.s b/test/MC/AsmParser/directive_abort.s index e5b0c9ad926..fefb8e24cc1 100644 --- a/test/MC/AsmParser/directive_abort.s +++ b/test/MC/AsmParser/directive_abort.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .abort "please stop assembing" diff --git a/test/MC/AsmParser/directive_align.s b/test/MC/AsmParser/directive_align.s index 2a1723c070d..c60be19e452 100644 --- a/test/MC/AsmParser/directive_align.s +++ b/test/MC/AsmParser/directive_align.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .p2align 1, 0 diff --git a/test/MC/AsmParser/directive_ascii.s b/test/MC/AsmParser/directive_ascii.s index 9f21e8cee35..67fcde3ef50 100644 --- a/test/MC/AsmParser/directive_ascii.s +++ b/test/MC/AsmParser/directive_ascii.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: TEST0: @@ -21,4 +21,4 @@ TEST2: TEST3: .asciz "B", "C" - \ No newline at end of file + diff --git a/test/MC/AsmParser/directive_comm.s b/test/MC/AsmParser/directive_comm.s index b074df83be0..6cc79371de8 100644 --- a/test/MC/AsmParser/directive_comm.s +++ b/test/MC/AsmParser/directive_comm.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .comm a,6,2 diff --git a/test/MC/AsmParser/directive_desc.s b/test/MC/AsmParser/directive_desc.s index 80acc2646cd..992455ccdc8 100644 --- a/test/MC/AsmParser/directive_desc.s +++ b/test/MC/AsmParser/directive_desc.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .desc foo,16 diff --git a/test/MC/AsmParser/directive_dump_and_load.s b/test/MC/AsmParser/directive_dump_and_load.s index 74c300d3be8..c810244ede7 100644 --- a/test/MC/AsmParser/directive_dump_and_load.s +++ b/test/MC/AsmParser/directive_dump_and_load.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .dump "somefile" diff --git a/test/MC/AsmParser/directive_fill.s b/test/MC/AsmParser/directive_fill.s index 1a43dbc8f43..95c7b46baf9 100644 --- a/test/MC/AsmParser/directive_fill.s +++ b/test/MC/AsmParser/directive_fill.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .byte 10 diff --git a/test/MC/AsmParser/directive_include.s b/test/MC/AsmParser/directive_include.s index 2721fee035e..c6526eb29a4 100644 --- a/test/MC/AsmParser/directive_include.s +++ b/test/MC/AsmParser/directive_include.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s -I %p | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s # CHECK: TESTA: # CHECK: TEST0: diff --git a/test/MC/AsmParser/directive_lcomm.s b/test/MC/AsmParser/directive_lcomm.s index 2247ed61c4f..afc61216c4f 100644 --- a/test/MC/AsmParser/directive_lcomm.s +++ b/test/MC/AsmParser/directive_lcomm.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .lcomm a,7,4 diff --git a/test/MC/AsmParser/directive_lsym.s b/test/MC/AsmParser/directive_lsym.s index a4437b9a89a..3d5403e975c 100644 --- a/test/MC/AsmParser/directive_lsym.s +++ b/test/MC/AsmParser/directive_lsym.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .lsym bar,foo diff --git a/test/MC/AsmParser/directive_org.s b/test/MC/AsmParser/directive_org.s index 4de82d5ad20..f4414c31cd2 100644 --- a/test/MC/AsmParser/directive_org.s +++ b/test/MC/AsmParser/directive_org.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .org 1, 0 diff --git a/test/MC/AsmParser/directive_set.s b/test/MC/AsmParser/directive_set.s index ce2649d53bb..89085668b89 100644 --- a/test/MC/AsmParser/directive_set.s +++ b/test/MC/AsmParser/directive_set.s @@ -1,7 +1,7 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .set a, 0 TEST0: .set a, 0 - \ No newline at end of file + diff --git a/test/MC/AsmParser/directive_space.s b/test/MC/AsmParser/directive_space.s index 52cf7b26836..a897654c07c 100644 --- a/test/MC/AsmParser/directive_space.s +++ b/test/MC/AsmParser/directive_space.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .byte 0 diff --git a/test/MC/AsmParser/directive_subsections_via_symbols.s b/test/MC/AsmParser/directive_subsections_via_symbols.s index 826b7f19232..38d69c94c13 100644 --- a/test/MC/AsmParser/directive_subsections_via_symbols.s +++ b/test/MC/AsmParser/directive_subsections_via_symbols.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .subsections_via_symbols diff --git a/test/MC/AsmParser/directive_symbol_attrs.s b/test/MC/AsmParser/directive_symbol_attrs.s index 41d22f8fcde..99ef3b8e13f 100644 --- a/test/MC/AsmParser/directive_symbol_attrs.s +++ b/test/MC/AsmParser/directive_symbol_attrs.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .globl a diff --git a/test/MC/AsmParser/directive_values.s b/test/MC/AsmParser/directive_values.s index 337bc6839d6..beac69a4aeb 100644 --- a/test/MC/AsmParser/directive_values.s +++ b/test/MC/AsmParser/directive_values.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .byte 0 diff --git a/test/MC/AsmParser/directive_zerofill.s b/test/MC/AsmParser/directive_zerofill.s index 2218aba0452..4b26f9b68c7 100644 --- a/test/MC/AsmParser/directive_zerofill.s +++ b/test/MC/AsmParser/directive_zerofill.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc %s | FileCheck %s +# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s # CHECK: TEST0: # CHECK: .zerofill __FOO,__bar,x,1 diff --git a/test/MC/AsmParser/exprs.s b/test/MC/AsmParser/exprs.s index 20de3a5e0ba..5fa4a371c3d 100644 --- a/test/MC/AsmParser/exprs.s +++ b/test/MC/AsmParser/exprs.s @@ -1,8 +1,8 @@ -// FIXME: For now this test just checks that llvm-mc works. Once we have .macro, +// FIXME: For now this test just checks that llvm-mc -triple i386-unknown-unknown works. Once we have .macro, // .if, and .abort we can write a better test (without resorting to miles of // greps). -// RUN: llvm-mc %s > %t +// RUN: llvm-mc -triple i386-unknown-unknown %s > %t .text g: @@ -59,4 +59,4 @@ m: n: nop - \ No newline at end of file + diff --git a/test/MC/AsmParser/x86_operands.s b/test/MC/AsmParser/x86_operands.s index 708f1bd3e88..1d31097f160 100644 --- a/test/MC/AsmParser/x86_operands.s +++ b/test/MC/AsmParser/x86_operands.s @@ -1,6 +1,6 @@ // FIXME: Actually test that we get the expected results. -// RUN: llvm-mc %s > %t +// RUN: llvm-mc -triple i386-unknown-unknown %s > %t # Immediates push $1 diff --git a/tools/llvm-mc/CMakeLists.txt b/tools/llvm-mc/CMakeLists.txt index b21a4b1b918..d2e9e71b07b 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 3c327dac1e9..ab9c5b6f608 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 b52edd1ed43..c7f3996c972 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 IncludeDirs("I", cl::desc("Directory of include files"), cl::value_desc("directory"), cl::Prefix); +static cl::opt +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) {