From d00d4159d4fb7208cd4207a3d1e4ccf5bc02f74f Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 11 Jun 2009 22:13:00 +0000 Subject: [PATCH] Use forward declarations and move TargetELFWriterInfo impl to a new file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73209 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/TargetELFWriterInfo.h | 20 +++++--------- lib/Target/CMakeLists.txt | 3 ++- lib/Target/TargetELFWriterInfo.cpp | 33 +++++++++++++++++++++++ lib/Target/X86/X86ELFWriterInfo.cpp | 3 ++- 4 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 lib/Target/TargetELFWriterInfo.cpp diff --git a/include/llvm/Target/TargetELFWriterInfo.h b/include/llvm/Target/TargetELFWriterInfo.h index 809846a0fbe..60378265552 100644 --- a/include/llvm/Target/TargetELFWriterInfo.h +++ b/include/llvm/Target/TargetELFWriterInfo.h @@ -14,11 +14,10 @@ #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H #define LLVM_TARGET_TARGETELFWRITERINFO_H -#include "llvm/Target/TargetData.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Function.h" - namespace llvm { + class Function; + class TargetData; + class TargetMachine; //===--------------------------------------------------------------------===// // TargetELFWriterInfo @@ -50,21 +49,14 @@ namespace llvm { EM_X86_64 = 62 // AMD64 }; - explicit TargetELFWriterInfo(TargetMachine &tm) : TM(tm) {} - virtual ~TargetELFWriterInfo() {} + explicit TargetELFWriterInfo(TargetMachine &tm); + virtual ~TargetELFWriterInfo(); unsigned short getEMachine() const { return EMachine; } /// getFunctionAlignment - Returns the alignment for function 'F', targets /// with different alignment constraints should overload this method - virtual unsigned getFunctionAlignment(const Function *F) const { - const TargetData *TD = TM.getTargetData(); - unsigned FnAlign = F->getAlignment(); - unsigned TDAlign = TD->getPointerABIAlignment(); - unsigned Align = std::max(FnAlign, TDAlign); - assert(!(Align & (Align-1)) && "Alignment is not a power of two!"); - return Align; - } + virtual unsigned getFunctionAlignment(const Function *F) const; }; } // end llvm namespace diff --git a/lib/Target/CMakeLists.txt b/lib/Target/CMakeLists.txt index 1cf0a91078f..7cffd0e53c1 100644 --- a/lib/Target/CMakeLists.txt +++ b/lib/Target/CMakeLists.txt @@ -5,6 +5,7 @@ add_llvm_library(LLVMTarget Target.cpp TargetAsmInfo.cpp TargetData.cpp + TargetELFWriterInfo.cpp TargetFrameInfo.cpp TargetInstrInfo.cpp TargetMachOWriterInfo.cpp @@ -14,4 +15,4 @@ add_llvm_library(LLVMTarget TargetSubtarget.cpp ) -# TODO: Support other targets besides X86. See Makefile. \ No newline at end of file +# TODO: Support other targets besides X86. See Makefile. diff --git a/lib/Target/TargetELFWriterInfo.cpp b/lib/Target/TargetELFWriterInfo.cpp new file mode 100644 index 00000000000..255a22c37cb --- /dev/null +++ b/lib/Target/TargetELFWriterInfo.cpp @@ -0,0 +1,33 @@ +//===-- lib/Target/TargetELFWriterInfo.cpp - ELF Writer Info --0-*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the TargetELFWriterInfo class. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Function.h" +#include "llvm/Target/TargetELFWriterInfo.h" +#include "llvm/Target/TargetData.h" +#include "llvm/Target/TargetMachine.h" +using namespace llvm; + +TargetELFWriterInfo::TargetELFWriterInfo(TargetMachine &tm) : TM(tm) {} + +TargetELFWriterInfo::~TargetELFWriterInfo() {} + +/// getFunctionAlignment - Returns the alignment for function 'F', targets +/// with different alignment constraints should overload this method +unsigned TargetELFWriterInfo::getFunctionAlignment(const Function *F) const { + const TargetData *TD = TM.getTargetData(); + unsigned FnAlign = F->getAlignment(); + unsigned TDAlign = TD->getPointerABIAlignment(); + unsigned Align = std::max(FnAlign, TDAlign); + assert(!(Align & (Align-1)) && "Alignment is not a power of two!"); + return Align; +} diff --git a/lib/Target/X86/X86ELFWriterInfo.cpp b/lib/Target/X86/X86ELFWriterInfo.cpp index 09c318513d7..d84034b9ed4 100644 --- a/lib/Target/X86/X86ELFWriterInfo.cpp +++ b/lib/Target/X86/X86ELFWriterInfo.cpp @@ -12,8 +12,9 @@ //===----------------------------------------------------------------------===// #include "X86ELFWriterInfo.h" +#include "llvm/Function.h" +#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/DerivedTypes.h" using namespace llvm; X86ELFWriterInfo::X86ELFWriterInfo(TargetMachine &TM) -- 2.34.1