18 using namespace clang;
23 const size_t BitWidth = CharWidth * Ctx.
getCharBit();
37 llvm_unreachable(
"unsupported character width");
48 unsigned I = Globals.size();
50 auto *G =
new (Allocator, Sz) Global(Desc,
true,
56 for (
unsigned I = 0, N = S->
getLength(); I <= N; ++I) {
57 Pointer Field = Ptr.atIndex(I).narrow();
58 const uint32_t CodePoint = I == N ? 0 : S->
getCodeUnit(I);
62 Field.
deref<T>() = T::from(CodePoint, BitWidth);
67 Field.
deref<T>() = T::from(CodePoint, BitWidth);
72 Field.
deref<T>() = T::from(CodePoint, BitWidth);
76 llvm_unreachable(
"unsupported character type");
83 assert(Idx < Globals.size());
84 return Pointer(Globals[Idx]->block());
88 auto It = GlobalIndices.find(VD);
89 if (It != GlobalIndices.end())
94 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl()) {
95 auto It = GlobalIndices.find(
P);
96 if (It != GlobalIndices.end()) {
104 GlobalIndices[VD] = *Index;
116 GlobalIndices[VD] = *Idx;
130 auto It = DummyParams.find(PD);
131 if (It != DummyParams.end())
135 DummyParams[PD] = *Idx;
143 if (
auto *Var = dyn_cast<VarDecl>(VD)) {
144 IsStatic = !Var->hasLocalStorage();
145 IsExtern = !Var->getAnyInitializer();
151 for (
const Decl *
P = VD;
P;
P =
P->getPreviousDecl())
152 GlobalIndices[
P] = *Idx;
167 const bool IsTemporary = D.dyn_cast<
const Expr *>();
177 unsigned I = Globals.size();
181 G->block()->invokeCtor();
183 Globals.push_back(G);
190 auto It = Funcs.find(F);
191 return It == Funcs.end() ? nullptr : It->second.get();
214 auto It = Records.find(RD);
215 if (It != Records.end()) {
222 unsigned VirtSize = 0;
228 return allocateDescriptor(BD, BR,
false,
236 if (
auto *CD = dyn_cast<CXXRecordDecl>(RD)) {
238 if (Spec.isVirtual())
245 Bases.push_back({BD, Size, Desc, BR});
258 VirtBases.push_back({BD, VirtSize, Desc, BR});
275 const bool IsMutable = FD->isMutable();
286 Fields.push_back({FD, Size, Desc});
290 Record *R =
new (Allocator)
Record(RD, std::move(Bases), std::move(Fields),
291 std::move(VirtBases), VirtSize, Size);
292 Records.insert({RD, R});
297 bool IsConst,
bool IsTemporary,
302 return allocateDescriptor(D,
Record, IsConst, IsTemporary, IsMutable);
309 if (
auto CAT = dyn_cast<ConstantArrayType>(
ArrayType)) {
310 size_t NumElems = CAT->getSize().getZExtValue();
317 return allocateDescriptor(D, *T, NumElems, IsConst, IsTemporary,
329 return allocateDescriptor(D, Desc, NumElems, IsConst, IsTemporary,
336 if (isa<IncompleteArrayType>(
ArrayType)) {
338 return allocateDescriptor(D, *T, IsTemporary,
345 return allocateDescriptor(D, Desc, IsTemporary,
353 const Type *InnerTy = AT->getValueType().getTypePtr();
360 return allocateDescriptor(D, ElemTy, 2, IsConst, IsTemporary, IsMutable);
FunctionDecl * getDefinition()
Get the definition for this declaration.
Represents a function declaration or definition.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
A (possibly-)qualified type.
Mapping from primitive types to their representation.
unsigned createGlobalString(const StringLiteral *S)
Emits a string literal among global data.
Decl - This represents one declaration (or definition), e.g.
Descriptor * createDescriptor(const DeclTy &D, PrimType Type, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
Creates a descriptor for a primitive type.
The base class of the type hierarchy.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
llvm::Optional< unsigned > getCurrentDecl() const
Returns the current declaration ID.
QualType getElementType() const
for(auto typeArg :T->getTypeArgsAsWritten())
const T * getAs() const
Member-template getAs<specific type>'.
Represents a parameter to a function.
llvm::Optional< PrimType > classify(QualType T)
Classifies an expression.
Represents a struct/union/class.
A pointer to a memory block, live or dead.
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Compilation context for statements.
field_range fields() const
Represents a member of a struct/union/class.
Pointer getPtrGlobal(unsigned Idx)
Returns a pointer to a global.
Token to denote structures of unknown size.
__DEVICE__ int max(int __a, int __b)
unsigned getCharByteWidth() const
Structure/Class descriptor.
Inline descriptor embedded in structures and arrays.
unsigned getLength() const
PrimType
Enumeration of the primitive types of the VM.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Describes a memory block created by an allocation site.
unsigned getCharBit() const
Returns CHAR_BIT.
Function * getFunction(const FunctionDecl *F)
Returns a function.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Record * getOrCreateRecord(const RecordDecl *RD)
Returns a record or creates one if it does not exist.
const T * castAs() const
Member-template castAs<specific type>.
ASTContext & getASTContext() const
Returns the AST context.
uint32_t getCodeUnit(size_t i) const
Block * getGlobal(unsigned Idx)
Returns the value of a global.
llvm::Optional< unsigned > getOrCreateDummy(const ParmVarDecl *PD)
Returns or creates a dummy value for parameters.
bool isConstQualified() const
Determine whether this type is const-qualified.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
llvm::Expected< Function * > getOrCreateFunction(const FunctionDecl *F)
Returns a pointer to a function if it exists and can be compiled.
Dataflow Directional Tag Classes.
llvm::Optional< unsigned > createGlobal(const ValueDecl *VD)
Creates a global and returns its index.
T & deref() const
Dereferences the pointer, if it's live.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
unsigned InterpSize
Object size as used by the interpreter.
Represents a base class of a C++ class.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
llvm::Optional< unsigned > getOrCreateGlobal(const ValueDecl *VD)
Returns or creates a global an creates an index to it.
StringLiteral - This represents a string literal expression, e.g.
unsigned getSize() const
Returns the size of the record.