22 auto It = NativePointerIndices.find(Ptr);
23 if (It != NativePointerIndices.end())
26 unsigned Idx = NativePointers.size();
27 NativePointers.push_back(Ptr);
28 NativePointerIndices[Ptr] = Idx;
33 return NativePointers[Idx];
37 const size_t CharWidth = S->getCharByteWidth();
38 const size_t BitWidth = CharWidth * Ctx.
getCharBit();
52 llvm_unreachable(
"unsupported character width");
57 allocateDescriptor(S, CharType, std::nullopt, S->getLength() + 1,
64 unsigned I = Globals.size();
66 auto *G =
new (Allocator, Sz) Global(Desc,
true,
68 G->block()->invokeCtor();
73 for (
unsigned I = 0, N = S->getLength(); I <= N; ++I) {
75 const uint32_t CodePoint = I == N ? 0 : S->getCodeUnit(I);
79 Field.deref<T>() = T::from(CodePoint, BitWidth);
84 Field.deref<T>() = T::from(CodePoint, BitWidth);
89 Field.deref<T>() = T::from(CodePoint, BitWidth);
93 llvm_unreachable(
"unsupported character type");
100 assert(Idx < Globals.size());
101 return Pointer(Globals[Idx]->block());
105 auto It = GlobalIndices.find(VD);
106 if (It != GlobalIndices.end())
110 std::optional<unsigned> Index;
111 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl()) {
112 auto It = GlobalIndices.find(
P);
113 if (It != GlobalIndices.end()) {
121 GlobalIndices[VD] = *Index;
134 GlobalIndices[VD] = *Idx;
148 auto It = DummyParams.find(PD);
149 if (It != DummyParams.end())
153 DummyParams[PD] = *Idx;
163 if (
auto *Var = dyn_cast<VarDecl>(VD)) {
165 IsExtern = !Var->getAnyInitializer();
171 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl())
172 GlobalIndices[
P] = *Idx;
188 const bool IsTemporary = D.dyn_cast<
const Expr *>();
199 unsigned I = Globals.size();
203 G->block()->invokeCtor();
205 Globals.push_back(G);
213 auto It = Funcs.find(F);
214 return It == Funcs.end() ? nullptr : It->second.get();
224 auto It = Records.find(RD);
225 if (It != Records.end()) {
232 Records.insert({RD,
nullptr});
235 unsigned BaseSize = 0;
237 unsigned VirtSize = 0;
243 return allocateDescriptor(BD, BR, std::nullopt,
false,
251 if (
auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
253 if (Spec.isVirtual())
260 Bases.push_back({BD, BaseSize, Desc, BR});
273 VirtBases.push_back({BD, VirtSize, Desc, BR});
290 const bool IsMutable = FD->isMutable();
292 if (std::optional<PrimType> T = Ctx.
classify(FT)) {
301 Fields.push_back({FD, BaseSize, Desc});
305 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
306 std::move(VirtBases), VirtSize, BaseSize);
313 bool IsConst,
bool IsTemporary,
314 bool IsMutable,
const Expr *Init) {
318 return allocateDescriptor(D,
Record, MDSize, IsConst, IsTemporary,
326 if (
auto CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
327 size_t NumElems = CAT->getSize().getZExtValue();
328 if (std::optional<PrimType> T = Ctx.
classify(ElemTy)) {
331 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems) {
334 return allocateDescriptor(D, *T, MDSize, NumElems, IsConst, IsTemporary,
340 D, ElemTy.
getTypePtr(), std::nullopt, IsConst, IsTemporary);
345 if (std::numeric_limits<unsigned>::max() / ElemSize <= NumElems)
347 return allocateDescriptor(D, ElemDesc, MDSize, NumElems, IsConst,
348 IsTemporary, IsMutable);
354 if (isa<IncompleteArrayType>(
ArrayType)) {
355 if (std::optional<PrimType> T = Ctx.
classify(ElemTy)) {
356 return allocateDescriptor(D, *T, IsTemporary,
360 IsConst, IsTemporary);
363 return allocateDescriptor(D, Desc, IsTemporary,
371 const Type *InnerTy = AT->getValueType().getTypePtr();
379 return allocateDescriptor(D, ElemTy, MDSize, 2, IsConst, IsTemporary,
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Represents a base class of a C++ class.
Complex values, per C99 6.2.5p11.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StringLiteral - This represents a string literal expression, e.g.
The base class of the type hierarchy.
const T * castAs() const
Member-template castAs<specific type>.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
const T * getAs() const
Member-template getAs<specific type>'.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
unsigned getCharBit() const
Returns CHAR_BIT.
ASTContext & getASTContext() const
Returns the AST context.
std::optional< PrimType > classify(QualType T) const
Classifies an expression.
A pointer to a memory block, live or dead.
Pointer narrow() const
Restricts the scope of an array element pointer.
Pointer atIndex(unsigned Idx) const
Offsets a pointer inside an array.
std::optional< unsigned > getOrCreateDummy(const ParmVarDecl *PD)
Returns or creates a dummy value for parameters.
std::optional< unsigned > getOrCreateGlobal(const ValueDecl *VD, const Expr *Init=nullptr)
Returns or creates a global an creates an index to it.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Block * getGlobal(unsigned Idx)
Returns the value of a global.
const void * getNativePointer(unsigned Idx)
Returns the value of a marshalled native pointer.
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, Descriptor::MetadataSize MDSize=std::nullopt, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
unsigned getOrCreateNativePointer(const void *Ptr)
Marshals a native pointer to an ID for embedding in bytecode.
unsigned createGlobalString(const StringLiteral *S)
Emits a string literal among global data.
std::optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
Pointer getPtrGlobal(unsigned Idx)
Returns a pointer to a global.
std::optional< unsigned > createGlobal(const ValueDecl *VD, const Expr *E)
Creates a global and returns its index.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
Structure/Class descriptor.
unsigned getSize() const
Returns the size of the record.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
PrimType
Enumeration of the primitive types of the VM.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Token to denote structures of unknown size.
Describes a memory block created by an allocation site.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
std::optional< unsigned > MetadataSize
Inline descriptor embedded in structures and arrays.
Mapping from primitive types to their representation.