clang: lib/AST/ByteCode/Function.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CLANG_AST_INTERP_FUNCTION_H

16#define LLVM_CLANG_AST_INTERP_FUNCTION_H

17

23#include "llvm/ADT/PointerUnion.h"

24#include "llvm/Support/raw_ostream.h"

25

32

33

34

35

37public:

38

47

49

51

52 llvm::iterator_rangeLocalVectorTy::const\_iterator locals() const {

53 return llvm::make_range(Descriptors.begin(), Descriptors.end());

54 }

55

56 llvm::iterator_rangeLocalVectorTy::const\_reverse\_iterator

58 return llvm::reverse(Descriptors);

59 }

60

61private:

62

64};

65

67 llvm::PointerUnion<const FunctionDecl *, const BlockExpr *>;

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88class Function final {

89public:

99

100

102

104

105

107

109

110

112 return dyn_cast<const FunctionDecl *>(Source);

113 }

115 return dyn_cast<const BlockExpr *>(Source);

116 }

117

118

119

121 if (!Source || getDecl())

122 return "<>";

123

125 }

126

127

129

130

131 bool hasRVO() const { return HasRVO; }

132

134

135

136 llvm::iterator_range<llvm::SmallVector<Scope, 2>::const_iterator>

138 return llvm::make_range(Scopes.begin(), Scopes.end());

139 }

140

141

144 llvm::iterator_range<arg_reverse_iterator> args_reverse() const {

145 return llvm::reverse(ParamTypes);

146 }

147

148

150 const Scope &getScope(unsigned Idx) const { return Scopes[Idx]; }

151

152

154

155

157

158

162

163

165

167

171

172

173

177

178

179

183

184

186 if (const auto *MD = dyn_cast_if_present(

187 dyn_cast<const FunctionDecl *>(Source)))

189 return nullptr;

190 }

191

192

194

196

197

198 bool hasBody() const { return HasBody; }

199

200

202

204

205 unsigned getNumParams() const { return ParamTypes.size(); }

206

207

208

216

218 if (const auto *MD = dyn_cast_if_present(

219 dyn_cast<const FunctionDecl *>(Source)))

220 return MD->isExplicitObjectMemberFunction();

221 return false;

222 }

223

225 return ParamOffsets[ParamIndex];

226 }

227

229 return ParamTypes[ParamIndex];

230 }

231

232private:

233

236 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,

238 bool HasRVO, bool IsLambdaStaticInvoker);

239

240

241 void setCode(FunctionDeclTy Source, unsigned NewFrameSize,

244 this->Source = Source;

245 FrameSize = NewFrameSize;

246 Code = std::move(NewCode);

247 SrcMap = std::move(NewSrcMap);

248 Scopes = std::move(NewScopes);

249 IsValid = true;

250 HasBody = NewHasBody;

251 }

252

253 void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }

254 void setDefined(bool D) { Defined = D; }

255

256private:

260

261

263

265

267

268 unsigned FrameSize = 0;

269

270 unsigned ArgSize;

271

273

275

277

279

280 llvm::DenseMap<unsigned, ParamDescriptor> Params;

281

283

284 LLVM_PREFERRED_TYPE(bool)

285 unsigned IsValid : 1;

286

287

288 LLVM_PREFERRED_TYPE(bool)

289 unsigned IsFullyCompiled : 1;

290

291

292 LLVM_PREFERRED_TYPE(bool)

293 unsigned HasThisPointer : 1;

294

295

296

297 LLVM_PREFERRED_TYPE(bool)

298 unsigned HasRVO : 1;

299

300 LLVM_PREFERRED_TYPE(bool)

301 unsigned HasBody : 1;

302 LLVM_PREFERRED_TYPE(bool)

303 unsigned Defined : 1;

304 LLVM_PREFERRED_TYPE(bool)

305 unsigned Variadic : 1;

306 LLVM_PREFERRED_TYPE(bool)

307 unsigned Virtual : 1;

308 LLVM_PREFERRED_TYPE(bool)

309 unsigned Immediate : 1;

310 LLVM_PREFERRED_TYPE(bool)

311 unsigned Constexpr : 1;

312

313public:

314

316 void dump(llvm::raw_ostream &OS, CodePtr PC = {}) const;

317};

318

319}

320}

321

322#endif

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

BlockExpr - Adaptor class for mixing a BlockDecl with expressions.

Represents a C++ struct/union/class.

DeclContext * getParent()

getParent - Returns the containing DeclContext.

Represents a function declaration or definition.

std::string getQualifiedNameAsString() const

An emitter which links the program to bytecode for later use.

Pointer into the code segment.

friend class Program

Definition Function.h:257

FunctionKind

Definition Function.h:90

@ Ctor

Definition Function.h:92

@ Normal

Definition Function.h:91

@ LambdaStaticInvoker

Definition Function.h:94

@ CopyOrMoveOperator

Definition Function.h:96

@ LambdaCallOperator

Definition Function.h:95

@ Dtor

Definition Function.h:93

Scope & getScope(unsigned Idx)

Returns a specific scope.

Definition Function.h:149

CodePtr getCodeBegin() const

Returns a pointer to the start of the code.

Definition Function.h:106

bool isDestructor() const

Checks if the function is a destructor.

Definition Function.h:166

CodePtr getCodeEnd() const

Returns a pointer to the end of the code.

Definition Function.h:108

friend class ByteCodeEmitter

Definition Function.h:258

std::string getName() const

Returns the name of the function decl this code was generated for.

Definition Function.h:120

bool isVirtual() const

Checks if the function is virtual.

Definition Function.h:159

unsigned getNumParams() const

Definition Function.h:205

bool isDefined() const

Checks if the function is defined.

Definition Function.h:201

bool hasNonNullAttr() const

Definition Function.h:133

PrimType getParamType(unsigned ParamIndex) const

Definition Function.h:228

std::pair< PrimType, Descriptor * > ParamDescriptor

Definition Function.h:98

const CXXRecordDecl * getParentDecl() const

Returns the parent record decl, if any.

Definition Function.h:185

unsigned getFrameSize() const

Returns the size of the function's local stack.

Definition Function.h:101

bool isLambdaCallOperator() const

Returns whether this function is the call operator of a lambda record decl.

Definition Function.h:180

const BlockExpr * getExpr() const

Definition Function.h:114

bool isFullyCompiled() const

Checks if the function is fully done compiling.

Definition Function.h:193

bool isConstructor() const

Checks if the function is a constructor.

Definition Function.h:164

unsigned getParamOffset(unsigned ParamIndex) const

Definition Function.h:224

const FunctionDecl * getDecl() const

Returns the original FunctionDecl.

Definition Function.h:111

bool hasBody() const

Checks if the function already has a body attached.

Definition Function.h:198

bool hasThisPointer() const

Definition Function.h:195

SmallVectorImpl< PrimType >::const_reverse_iterator arg_reverse_iterator

Range over argument types.

Definition Function.h:142

void dump(CodePtr PC={}) const

Dumps the disassembled bytecode to llvm::errs().

void dump(llvm::raw_ostream &OS, CodePtr PC={}) const

llvm::iterator_range< arg_reverse_iterator > args_reverse() const

Definition Function.h:144

bool isConstexpr() const

Definition Function.h:161

const Scope & getScope(unsigned Idx) const

Definition Function.h:150

bool isThisPointerExplicit() const

Definition Function.h:217

unsigned getNumWrittenParams() const

Returns the number of parameter this function takes when it's called, i.e excluding the instance poin...

Definition Function.h:209

friend class Context

Definition Function.h:259

unsigned getWrittenArgSize() const

Definition Function.h:213

unsigned getArgSize() const

Returns the size of the argument stack.

Definition Function.h:103

bool isLambdaStaticInvoker() const

Returns whether this function is a lambda static invoker, which we generate custom byte code for.

Definition Function.h:174

bool isVariadic() const

Definition Function.h:203

SourceInfo getSource(CodePtr PC) const

Returns the source information at a given PC.

ParamDescriptor getParamDescriptor(unsigned Offset) const

Returns a parameter descriptor.

bool isValid() const

Checks if the function is valid to call.

Definition Function.h:156

bool isImmediate() const

Definition Function.h:160

bool isCopyOrMoveOperator() const

Checks if the function is copy or move operator.

Definition Function.h:168

llvm::iterator_range< llvm::SmallVector< Scope, 2 >::const_iterator > scopes() const

Range over the scope blocks.

Definition Function.h:137

bool hasRVO() const

Checks if the first argument is a RVO pointer.

Definition Function.h:131

A pointer to a memory block, live or dead.

The program contains and links the bytecode for all functions.

Describes a scope block.

Definition Function.h:36

llvm::SmallVector< Local, 8 > LocalVectorTy

Definition Function.h:48

llvm::iterator_range< LocalVectorTy::const_iterator > locals() const

Definition Function.h:52

Scope(LocalVectorTy &&Descriptors)

Definition Function.h:50

llvm::iterator_range< LocalVectorTy::const_reverse_iterator > locals_reverse() const

Definition Function.h:57

Describes the statement/declaration an opcode was generated from.

constexpr size_t align(size_t Size)

Aligns a size to the pointer alignment.

llvm::PointerUnion< const FunctionDecl *, const BlockExpr * > FunctionDeclTy

Definition Function.h:66

PrimType

Enumeration of the primitive types of the VM.

std::vector< std::pair< unsigned, SourceInfo > > SourceMap

size_t primSize(PrimType Type)

Returns the size of a primitive type in bytes.

The JSON file list parser is used to communicate input to InstallAPI.

Describes a memory block created by an allocation site.

Information about a local's storage.

Definition Function.h:39

unsigned Offset

Offset of the local in frame.

Definition Function.h:41

bool EnabledByDefault

If the cleanup for this local should be emitted.

Definition Function.h:45

Descriptor * Desc

Descriptor of the local.

Definition Function.h:43