llvm-mc: Add -triple, and start fetching the target asm printer.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 17 Jul 2009 22:38:58 +0000 (22:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 17 Jul 2009 22:38:58 +0000 (22:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76257 91177308-0d34-0410-b5e6-96231b3b80d8

24 files changed:
lib/MC/TargetAsmParser.cpp [new file with mode: 0644]
test/MC/AsmParser/assignment.s
test/MC/AsmParser/directive_abort.s
test/MC/AsmParser/directive_align.s
test/MC/AsmParser/directive_ascii.s
test/MC/AsmParser/directive_comm.s
test/MC/AsmParser/directive_desc.s
test/MC/AsmParser/directive_dump_and_load.s
test/MC/AsmParser/directive_fill.s
test/MC/AsmParser/directive_include.s
test/MC/AsmParser/directive_lcomm.s
test/MC/AsmParser/directive_lsym.s
test/MC/AsmParser/directive_org.s
test/MC/AsmParser/directive_set.s
test/MC/AsmParser/directive_space.s
test/MC/AsmParser/directive_subsections_via_symbols.s
test/MC/AsmParser/directive_symbol_attrs.s
test/MC/AsmParser/directive_values.s
test/MC/AsmParser/directive_zerofill.s
test/MC/AsmParser/exprs.s
test/MC/AsmParser/x86_operands.s
tools/llvm-mc/CMakeLists.txt
tools/llvm-mc/Makefile
tools/llvm-mc/llvm-mc.cpp

diff --git a/lib/MC/TargetAsmParser.cpp b/lib/MC/TargetAsmParser.cpp
new file mode 100644 (file)
index 0000000..05760c9
--- /dev/null
@@ -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() {
+}
index 4e6916ad25b8f49c82a1ec103cbcdb34e3fcc5a6..882fae8bae64b0376ff6a4f42f866d4f12a2c6b6 100644 (file)
@@ -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
+        
index e5b0c9ad926594fec372c9c15c445261df62eaf6..fefb8e24cc1a701f6d06849700868ce17da771a3 100644 (file)
@@ -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"
index 2a1723c070dc5f2430da9370d31afb3d76ad8983..c60be19e452b7ff2ce7b086d1fe57172f7a65f3a 100644 (file)
@@ -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
index 9f21e8cee35fb4c688b40e8f063a62f57a227ca8..67fcde3ef501cae04fc2b114077132f2c577510d 100644 (file)
@@ -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
+       
index b074df83be0538eb0440873b7ebf9f7d52b243eb..6cc79371de8c22b73885e7f7d1cf1705df05ec91 100644 (file)
@@ -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
index 80acc2646cdbfaa4d63d8ecf84f153111c963c27..992455ccdc895d69cf4b78497f5fe52ac21e8b43 100644 (file)
@@ -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
index 74c300d3be892a25b8f7082967455709d1ce3f50..c810244ede7ca0dbcdebd543eb82dad08fe9ea70 100644 (file)
@@ -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"
index 1a43dbc8f43c17f458acc2350f314306efe35045..95c7b46baf97d2105b3538060d199540a4bd60d3 100644 (file)
@@ -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
index 2721fee035e8b495c95616e495b244646cd54a7e..c6526eb29a420955ec36bcf783993ec14c3055cd 100644 (file)
@@ -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:
index 2247ed61c4f6ec74e7b2947a295fffd4a82d7e3b..afc61216c4fc9cfb99673f574fcb96e65f670029 100644 (file)
@@ -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
index a4437b9a89a82d116a9f50b83f0a53930bd63b52..3d5403e975c377a49852b790995304f3124b54f0 100644 (file)
@@ -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
index 4de82d5ad206122d8a7d19303006025ab8f5f691..f4414c31cd28d3226644d49ee9388171fad4e2eb 100644 (file)
@@ -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
index ce2649d53bb0289f1f1d00c7b50a42f35ff202e9..89085668b89bf79bb305a2722ba93dacb2b80e97 100644 (file)
@@ -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
+        
index 52cf7b268369e780ed21709b3c55e743b927fce8..a897654c07c480b7de6c74e466a712af0e8fab44 100644 (file)
@@ -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
index 826b7f1923246f58564b0d4522ee1f468287bab9..38d69c94c135f2cb85981d533bd46466c841e879 100644 (file)
@@ -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
index 41d22f8fcde463c0bdce095bb3689d14588f39a3..99ef3b8e13f6c43dc2c9ec5776018d35f0efb348 100644 (file)
@@ -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
index 337bc6839d60eb1909a3b2d6645ca79efd092fb1..beac69a4aeb1d72e1f0ba2b73a8b43af24fb76ba 100644 (file)
@@ -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
index 2218aba04529c0e425a32229b25f12a313381416..4b26f9b68c749174cb9e275909eade96f2dc47f8 100644 (file)
@@ -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
index 20de3a5e0ba8041081985aab18483ac64539c3c2..5fa4a371c3d077b41a57e40d41a78b8702c273e5 100644 (file)
@@ -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
+        
index 708f1bd3e8858463afe7a935498c6ca764eea38d..1d31097f1609865fe293f884fbd3698ff7a6eec5 100644 (file)
@@ -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
index b21a4b1b91899be4b1bdacb716cacd030060d2cf..d2e9e71b07baae52adf3a5ca45543404c0689cd9 100644 (file)
@@ -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
index 3c327dac1e977e668c3f27e4f3dbf14d9d3a7ec2..ab9c5b6f608da56ec5ae84d2874419e8863aa0f8 100644 (file)
@@ -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
index b52edd1ed4346e892423141a1521928910d127ff..c7f3996c9725649469d4926de74d239c73fc7622 100644 (file)
@@ -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) {