Files
swift-mirror/lib/IRGen/ClassLayout.cpp
Slava Pestov 9a6126b148 IRGen: Move fine-grained flags from ClassLayoutBuilder to ClassLayout
Another refactoring in preparation for adding the new type of class
metadata emitted when deploying to a target with a new Objective-C
runtime.

Progress on <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00

55 lines
1.8 KiB
C++

//===--- ClassLayout.cpp - Layout of class instances ---------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements algorithms for laying out class instances.
//
//===----------------------------------------------------------------------===//
#include "swift/AST/ASTContext.h"
#include "IRGenFunction.h"
#include "IRGenModule.h"
#include "ClassLayout.h"
#include "TypeInfo.h"
using namespace swift;
using namespace irgen;
ClassLayout::ClassLayout(const StructLayoutBuilder &builder,
ClassMetadataOptions options,
llvm::Type *classTy,
ArrayRef<VarDecl *> allStoredProps,
ArrayRef<FieldAccess> allFieldAccesses,
ArrayRef<ElementLayout> allElements)
: MinimumAlign(builder.getAlignment()),
MinimumSize(builder.getSize()),
IsFixedLayout(builder.isFixedLayout()),
Options(options),
Ty(classTy),
AllStoredProperties(allStoredProps),
AllFieldAccesses(allFieldAccesses),
AllElements(allElements) { }
Size ClassLayout::getInstanceStart() const {
if (AllElements.empty())
return getSize();
auto element = AllElements[0];
if (element.getKind() == ElementLayout::Kind::Fixed ||
element.getKind() == ElementLayout::Kind::Empty) {
// FIXME: assumes layout is always sequential!
return element.getByteOffset();
}
return Size(0);
}