Get rid of virtual inheritance for ARM TAI

llvm-svn: 56587
This commit is contained in:
Anton Korobeynikov 2008-09-24 22:22:27 +00:00
parent 237f087eb9
commit a9163feefe
3 changed files with 40 additions and 33 deletions

View File

@ -17,7 +17,7 @@
#include <cctype> #include <cctype>
using namespace llvm; using namespace llvm;
static const char *const arm_asm_table[] = { const char *const llvm::arm_asm_table[] = {
"{r0}", "r0", "{r0}", "r0",
"{r1}", "r1", "{r1}", "r1",
"{r2}", "r2", "{r2}", "r2",
@ -42,21 +42,10 @@ static const char *const arm_asm_table[] = {
"{cc}", "cc", "{cc}", "cc",
0,0}; 0,0};
ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) { TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>);
AsmTransCBE = arm_asm_table;
AlignmentIsInBytes = false;
Data64bitsDirective = 0;
CommentString = "@";
ConstantPoolSection = "\t.text\n";
COMMDirectiveTakesAlignment = false;
InlineAsmStart = "@ InlineAsm Start";
InlineAsmEnd = "@ InlineAsm End";
LCOMMDirective = "\t.lcomm\t";
}
ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM): ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
ARMTargetAsmInfo(TM), DarwinTargetAsmInfo(TM) { ARMTargetAsmInfo<DarwinTargetAsmInfo>(TM) {
Subtarget = &DTM->getSubtarget<ARMSubtarget>(); Subtarget = &DTM->getSubtarget<ARMSubtarget>();
GlobalPrefix = "_"; GlobalPrefix = "_";
@ -104,7 +93,7 @@ ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
} }
ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM): ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM):
ARMTargetAsmInfo(TM), ELFTargetAsmInfo(TM) { ARMTargetAsmInfo<ELFTargetAsmInfo>(TM) {
Subtarget = &ETM->getSubtarget<ARMSubtarget>(); Subtarget = &ETM->getSubtarget<ARMSubtarget>();
NeedsSet = false; NeedsSet = false;
@ -138,13 +127,15 @@ ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM):
/// Count the number of comma-separated arguments. /// Count the number of comma-separated arguments.
/// Do not try to detect errors. /// Do not try to detect errors.
unsigned ARMTargetAsmInfo::countArguments(const char* p) const { template <class BaseTAI>
unsigned ARMTargetAsmInfo<BaseTAI>::countArguments(const char* p) const {
unsigned count = 0; unsigned count = 0;
while (*p && isspace(*p) && *p != '\n') while (*p && isspace(*p) && *p != '\n')
p++; p++;
count++; count++;
while (*p && *p!='\n' && while (*p && *p!='\n' &&
strncmp(p, CommentString, strlen(CommentString))!=0) { strncmp(p, BaseTAI::CommentString,
strlen(BaseTAI::CommentString))!=0) {
if (*p==',') if (*p==',')
count++; count++;
p++; p++;
@ -154,7 +145,8 @@ unsigned ARMTargetAsmInfo::countArguments(const char* p) const {
/// Count the length of a string enclosed in quote characters. /// Count the length of a string enclosed in quote characters.
/// Do not try to detect errors. /// Do not try to detect errors.
unsigned ARMTargetAsmInfo::countString(const char* p) const { template <class BaseTAI>
unsigned ARMTargetAsmInfo<BaseTAI>::countString(const char* p) const {
unsigned count = 0; unsigned count = 0;
while (*p && isspace(*p) && *p!='\n') while (*p && isspace(*p) && *p!='\n')
p++; p++;
@ -166,7 +158,8 @@ unsigned ARMTargetAsmInfo::countString(const char* p) const {
} }
/// ARM-specific version of TargetAsmInfo::getInlineAsmLength. /// ARM-specific version of TargetAsmInfo::getInlineAsmLength.
unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const { template <class BaseTAI>
unsigned ARMTargetAsmInfo<BaseTAI>::getInlineAsmLength(const char *s) const {
// Make a lowercase-folded version of s for counting purposes. // Make a lowercase-folded version of s for counting purposes.
char *q, *s_copy = (char *)malloc(strlen(s) + 1); char *q, *s_copy = (char *)malloc(strlen(s) + 1);
strcpy(s_copy, s); strcpy(s_copy, s);
@ -192,7 +185,7 @@ unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
break; break;
} }
// Ignore everything from comment char(s) to EOL // Ignore everything from comment char(s) to EOL
if (strncmp(Str, CommentString, strlen(CommentString))==-0) if (strncmp(Str, BaseTAI::CommentString, strlen(BaseTAI::CommentString))==-0)
atInsnStart = false; atInsnStart = false;
// FIXME do something like the following for non-Darwin // FIXME do something like the following for non-Darwin
else if (*Str == '.' && Subtarget->isTargetDarwin()) { else if (*Str == '.' && Subtarget->isTargetDarwin()) {
@ -282,7 +275,7 @@ unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const {
Length += 4; // ARM Length += 4; // ARM
} }
} }
if (*Str == '\n' || *Str == SeparatorChar) if (*Str == '\n' || *Str == BaseTAI::SeparatorChar)
atInsnStart = true; atInsnStart = true;
} }
free(s_copy); free(s_copy);

View File

@ -14,19 +14,31 @@
#ifndef ARMTARGETASMINFO_H #ifndef ARMTARGETASMINFO_H
#define ARMTARGETASMINFO_H #define ARMTARGETASMINFO_H
#include "ARMTargetMachine.h"
#include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/ELFTargetAsmInfo.h" #include "llvm/Target/ELFTargetAsmInfo.h"
#include "llvm/Target/DarwinTargetAsmInfo.h" #include "llvm/Target/DarwinTargetAsmInfo.h"
#include "llvm/Support/Compiler.h"
#include "ARMSubtarget.h"
namespace llvm { namespace llvm {
// Forward declaration. extern const char *const arm_asm_table[];
class ARMTargetMachine;
struct ARMTargetAsmInfo : public virtual TargetAsmInfo { template <class BaseTAI>
explicit ARMTargetAsmInfo(const ARMTargetMachine &TM); struct ARMTargetAsmInfo : public BaseTAI {
explicit ARMTargetAsmInfo(const ARMTargetMachine &TM):
BaseTAI(TM) {
BaseTAI::AsmTransCBE = arm_asm_table;
BaseTAI::AlignmentIsInBytes = false;
BaseTAI::Data64bitsDirective = 0;
BaseTAI::CommentString = "@";
BaseTAI::ConstantPoolSection = "\t.text\n";
BaseTAI::COMMDirectiveTakesAlignment = false;
BaseTAI::InlineAsmStart = "@ InlineAsm Start";
BaseTAI::InlineAsmEnd = "@ InlineAsm End";
BaseTAI::LCOMMDirective = "\t.lcomm\t";
}
const ARMSubtarget *Subtarget; const ARMSubtarget *Subtarget;
@ -35,13 +47,15 @@ namespace llvm {
unsigned countString(const char *p) const; unsigned countString(const char *p) const;
}; };
struct ARMDarwinTargetAsmInfo : public virtual ARMTargetAsmInfo, typedef ARMTargetAsmInfo<TargetAsmInfo> ARMGenericTargetAsmInfo;
public virtual DarwinTargetAsmInfo {
EXTERN_TEMPLATE_INSTANTIATION(class ARMTargetAsmInfo<TargetAsmInfo>);
struct ARMDarwinTargetAsmInfo : public ARMTargetAsmInfo<DarwinTargetAsmInfo> {
explicit ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM); explicit ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM);
}; };
struct ARMELFTargetAsmInfo : public virtual ARMTargetAsmInfo, struct ARMELFTargetAsmInfo : public ARMTargetAsmInfo<ELFTargetAsmInfo> {
public virtual ELFTargetAsmInfo {
explicit ARMELFTargetAsmInfo(const ARMTargetMachine &TM); explicit ARMELFTargetAsmInfo(const ARMTargetMachine &TM);
}; };

View File

@ -120,7 +120,7 @@ const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
case ARMSubtarget::isELF: case ARMSubtarget::isELF:
return new ARMELFTargetAsmInfo(*this); return new ARMELFTargetAsmInfo(*this);
default: default:
return new ARMTargetAsmInfo(*this); return new ARMGenericTargetAsmInfo(*this);
} }
} }