llvm-mc: Add -triple, and start fetching the target asm printer.

llvm-svn: 76257
This commit is contained in:
Daniel Dunbar 2009-07-17 22:38:58 +00:00
parent ec0fd7ebe5
commit ab1316fbaf
24 changed files with 82 additions and 28 deletions

View File

@ -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() {
}

View 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

View 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"

View 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

View 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"

View 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

View 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

View 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"

View 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

View 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:

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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) {