Mercurial > projects > ldc
view tools/binding/llvm/c/Target.d @ 1499:df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
The idea is to separate the notion of const from 'this variable can always be
replaced with its initializer' in the frontend. To do that, I introduced
Declaration::isSameAsInitializer, which is overridden in VarDeclaration to
return false for constants that have a struct literal initializer.
So
{{{
const S s = S(5);
void foo() { auto ps = &s; }
// is no longer replaced by
void foo() { auto ps = &(S(5)); }
}}}
To make taking the address of a struct constant with a struct-initializer
outside of function scope possible, I made sure that AddrExp::optimize doesn't
try to run the argument's optimization with WANTinterpret - that'd again
replace the constant with a struct literal temporary.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 14 Jun 2009 19:49:58 +0200 |
parents | 1ba61de8796b |
children | 29b0f2d11c92 |
line wrap: on
line source
// Converted to the D programming language by Tomas Lindquist Olsen 2008 // Original file header: /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*\ |* *| |* The LLVM Compiler Infrastructure *| |* *| |* This file is distributed under the University of Illinois Open Source *| |* License. See LICENSE.TXT for details. *| |* *| |*===----------------------------------------------------------------------===*| |* *| |* This header declares the C interface to libLLVMTarget.a, which *| |* implements target information. *| |* *| |* Many exotic languages can interoperate with C code but have a harder time *| |* with C++ due to name mangling. So in addition to C, this interface enables *| |* tools written in such languages. *| |* *| \*===----------------------------------------------------------------------===*/ module llvm.c.Target; import llvm.c.Core; extern(C): enum { LLVMBigEndian, LLVMLittleEndian }; alias int LLVMByteOrdering; private { struct LLVM_OpaqueTargetData {} struct LLVM_OpaqueStructLayout {} } typedef LLVM_OpaqueTargetData* LLVMTargetDataRef; typedef LLVM_OpaqueStructLayout* LLVMStructLayoutRef; /*===-- Target Data -------------------------------------------------------===*/ /** Creates target data from a target layout string. See the constructor llvm::TargetData::TargetData. */ LLVMTargetDataRef LLVMCreateTargetData( /*const*/ char *StringRep); /** Adds target data information to a pass manager. This does not take ownership of the target data. See the method llvm::PassManagerBase::add. */ void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); /** Converts target data to a target layout string. The string must be disposed with LLVMDisposeMessage. See the constructor llvm::TargetData::TargetData. */ char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); /** Returns the byte order of a target, either LLVMBigEndian or LLVMLittleEndian. See the method llvm::TargetData::isLittleEndian. */ LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); /** Returns the pointer size in bytes for a target. See the method llvm::TargetData::getPointerSize. */ uint LLVMPointerSize(LLVMTargetDataRef); /** Returns the integer type that is the same size as a pointer on a target. See the method llvm::TargetData::getIntPtrType. */ LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); /** Computes the size of a type in bytes for a target. See the method llvm::TargetData::getTypeSizeInBits. */ ulong LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); /** Computes the storage size of a type in bytes for a target. See the method llvm::TargetData::getTypeStoreSize. */ ulong LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); /** Computes the ABI size of a type in bytes for a target. See the method llvm::TargetData::getABITypeSize. */ ulong LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); /** Computes the ABI alignment of a type in bytes for a target. See the method llvm::TargetData::getTypeABISize. */ uint LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); /** Computes the call frame alignment of a type in bytes for a target. See the method llvm::TargetData::getTypeABISize. */ uint LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); /** Computes the preferred alignment of a type in bytes for a target. See the method llvm::TargetData::getTypeABISize. */ uint LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); /** Computes the preferred alignment of a global variable in bytes for a target. See the method llvm::TargetData::getPreferredAlignment. */ uint LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, LLVMValueRef GlobalVar); /** Computes the structure element that contains the byte offset for a target. See the method llvm::StructLayout::getElementContainingOffset. */ uint LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, ulong Offset); /** Computes the byte offset of the indexed struct element for a target. See the method llvm::StructLayout::getElementContainingOffset. */ ulong LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, uint Element); /** Struct layouts are speculatively cached. If a TargetDataRef is alive when types are being refined and removed, this method must be called whenever a struct type is removed to avoid a dangling pointer in this cache. See the method llvm::TargetData::InvalidateStructLayoutInfo. */ void LLVMInvalidateStructLayout(LLVMTargetDataRef, LLVMTypeRef StructTy); /** Deallocates a TargetData. See the destructor llvm::TargetData::~TargetData. */ void LLVMDisposeTargetData(LLVMTargetDataRef);