clang 10.0.0git

Classes | Public Member Functions | Friends | List of all members
clang::interp::Program Class Reference

The program contains and links the bytecode for all functions. More...

`#include "/work/www-prereleases/10.0.0/rc1/docsbuild/clang/lib/AST/Interp/Program.h"`

## Classes
class | DeclScope
| Context to manage declaration lifetimes. More...

## Public Member Functions
| Program (Context &Ctx)
unsigned | createGlobalString (const StringLiteral *S)
| Emits a string literal among global data. More...
Pointer | getPtrGlobal (unsigned Idx)
| Returns a pointer to a global. More...
Block * | getGlobal (unsigned Idx)
| Returns the value of a global. More...
llvm::Optional< unsigned > | getGlobal (const ValueDecl *VD)
| Finds a global's index. More...
llvm::Optional< unsigned > | getOrCreateGlobal (const ValueDecl *VD)
| Returns or creates a global an creates an index to it. More...
llvm::Optional< unsigned > | getOrCreateDummy (const ParmVarDecl *PD)
| Returns or creates a dummy value for parameters. More...
llvm::Optional< unsigned > | createGlobal (const ValueDecl *VD)
| Creates a global and returns its index. More...
llvm::Optional< unsigned > | createGlobal (const Expr *E)
| Creates a global from a lifetime-extended temporary. More...
template<typename... Ts>
Function * | createFunction (const FunctionDecl *Def, Ts &&... Args)
| Creates a new function from a code range. More...
template<typename... Ts>
Function * | createFunction (Ts &&... Args)
| Creates an anonymous function. More...
Function * | getFunction (const FunctionDecl *F)
| Returns a function. More...
llvm::Expected< Function * > | getOrCreateFunction (const FunctionDecl *F)
| Returns a pointer to a function if it exists and can be compiled. More...
Record * | getOrCreateRecord (const RecordDecl *RD)
| Returns a record or creates one if it does not exist. More...
Descriptor * | createDescriptor (const DeclTy &D, PrimType Type, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
| Creates a descriptor for a primitive type. More...
Descriptor * | createDescriptor (const DeclTy &D, const Type *Ty, bool IsConst=false, bool IsTemporary=false, bool IsMutable=false)
| Creates a descriptor for a composite type. More...
llvm::Optional< unsigned > | getCurrentDecl () const
| Returns the current declaration ID. More...
void | dump () const
| Dumps the disassembled bytecode to `llvm::errs()`. More...
void | dump (llvm::raw_ostream &OS) const

## Friends
class | DeclScope

## Detailed Description

The program contains and links the bytecode for all functions.

Definition at line 43 of file Program.h.

## Constructor & Destructor Documentation

## ◆ Program()

clang::interp::Program::Program | ( | Context & | Ctx | ) |
| inline

Definition at line 45 of file Program.h.

References createGlobalString().

## Member Function Documentation

## ◆ createDescriptor() [1/2]

Descriptor* clang::interp::Program::createDescriptor | ( | const DeclTy & | D,
|  | PrimType | Type,
|  | bool | IsConst = `false`,
|  | bool | IsTemporary = `false`,
|  | bool | IsMutable = `false`
| ) |  |
| inline

Creates a descriptor for a primitive type.

Definition at line 101 of file Program.h.

Referenced by clang::interp::ByteCodeEmitter::compileFunc(), createDescriptor(), createGlobal(), and getOrCreateRecord().

## ◆ createDescriptor() [2/2]

Descriptor * Program::createDescriptor | ( | const DeclTy & | D,
|  | const Type * | Ty,
|  | bool | IsConst = `false`,
|  | bool | IsTemporary = `false`,
|  | bool | IsMutable = `false`
| ) |  |

Creates a descriptor for a composite type.

Definition at line 296 of file Program.cpp.

References clang::interp::Context::classify(), createDescriptor(), clang::interp::Descriptor::getAllocSize(), clang::Type::getAs(), clang::Type::getAsArrayTypeUnsafe(), clang::ArrayType::getElementType(), getOrCreateRecord(), clang::QualType::getTypePtr(), max(), and clang::interp::primSize().

## ◆ createFunction() [1/2]

template<typename... Ts>

Function* clang::interp::Program::createFunction | ( | const FunctionDecl * | Def,
|  | Ts &&... | Args
| ) |  |
| inline

Creates a new function from a code range.

Definition at line 76 of file Program.h.

Referenced by clang::interp::ByteCodeEmitter::compileFunc().

## ◆ createFunction() [2/2]

template<typename... Ts>

Function* clang::interp::Program::createFunction | ( | Ts &&... | Args | ) |
| inline

Creates an anonymous function.

Definition at line 83 of file Program.h.

References getFunction(), getOrCreateFunction(), and getOrCreateRecord().

## ◆ createGlobal() [1/2]

llvm::Optional< unsigned > Program::createGlobal | ( | const ValueDecl * | VD | ) |

Creates a global and returns its index.

Definition at line 141 of file Program.cpp.

References clang::ValueDecl::getType(), IsStatic, and P.

Referenced by createGlobal(), getGlobal(), getOrCreateDummy(), and getOrCreateGlobal().

## ◆ createGlobal() [2/2]

llvm::Optional< unsigned > Program::createGlobal | ( | const Expr * | E | ) |

Creates a global from a lifetime-extended temporary.

Definition at line 158 of file Program.cpp.

References clang::interp::Context::classify(), createDescriptor(), createGlobal(), clang::interp::Descriptor::getAllocSize(), getCurrentDecl(), clang::Expr::getType(), clang::QualType::getTypePtr(), clang::QualType::isConstQualified(), and IsStatic.

## ◆ createGlobalString()

unsigned Program::createGlobalString | ( | const StringLiteral * | S | ) |

Emits a string literal among global data.

Definition at line 21 of file Program.cpp.

Referenced by Program().

## ◆ dump() [1/2]

LLVM_DUMP_METHOD void Program::dump | ( |  | ) | const

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

Definition at line 60 of file Disasm.cpp.

References clang::interp::Function::dump().

## ◆ dump() [2/2]

LLVM_DUMP_METHOD void Program::dump | ( | llvm::raw_ostream & | OS | ) | const

Definition at line 62 of file Disasm.cpp.

## ◆ getCurrentDecl()

llvm::Optional<unsigned> clang::interp::Program::getCurrentDecl | ( |  | ) | const
| inline

Returns the current declaration ID.

Definition at line 124 of file Program.h.

Referenced by createGlobal().

## ◆ getFunction()

Function * Program::getFunction | ( | const FunctionDecl * | F | ) |

Returns a function.

Definition at line 188 of file Program.cpp.

References clang::FunctionDecl::getDefinition().

Referenced by createFunction(), and getOrCreateFunction().

## ◆ getGlobal() [1/2]

Block* clang::interp::Program::getGlobal | ( | unsigned | Idx | ) |
| inline

Returns the value of a global.

Definition at line 54 of file Program.h.

References createGlobal(), getOrCreateDummy(), and getOrCreateGlobal().

Referenced by clang::interp::GetGlobal(), getOrCreateGlobal(), and clang::interp::InitGlobal().

## ◆ getGlobal() [2/2]

llvm::Optional< unsigned > Program::getGlobal | ( | const ValueDecl * | VD | ) |

Finds a global's index.

Definition at line 87 of file Program.cpp.

## ◆ getOrCreateDummy()

llvm::Optional< unsigned > Program::getOrCreateDummy | ( | const ParmVarDecl * | PD | ) |

Returns or creates a dummy value for parameters.

Definition at line 122 of file Program.cpp.

References clang::Type::castAs(), createGlobal(), clang::interp::Context::getASTContext(), clang::ValueDecl::getType(), clang::if(), and clang::ArrayType::Normal.

Referenced by getGlobal().

## ◆ getOrCreateFunction()

llvm::Expected< Function * > Program::getOrCreateFunction | ( | const FunctionDecl * | F | ) |

Returns a pointer to a function if it exists and can be compiled.

If a function couldn't be compiled, an error is returned. If a function was not yet defined, a null pointer is returned.

Definition at line 194 of file Program.cpp.

References clang::FunctionDecl::getDefinition(), and getFunction().

Referenced by createFunction().

## ◆ getOrCreateGlobal()

llvm::Optional< unsigned > Program::getOrCreateGlobal | ( | const ValueDecl * | VD | ) |

Returns or creates a global an creates an index to it.

Definition at line 111 of file Program.cpp.

References createGlobal(), and getGlobal().

Referenced by getGlobal().

## ◆ getOrCreateRecord()

Record * Program::getOrCreateRecord | ( | const RecordDecl * | RD | ) |

Returns a record or creates one if it does not exist.

Definition at line 207 of file Program.cpp.

References clang::interp::align(), clang::interp::Context::classify(), createDescriptor(), clang::RecordDecl::fields(), clang::interp::Descriptor::getAllocSize(), clang::RecordDecl::getDefinition(), clang::interp::Record::getSize(), clang::QualType::getTypePtr(), and clang::QualType::isConstQualified().

Referenced by createDescriptor(), and createFunction().

## ◆ getPtrGlobal()

Pointer Program::getPtrGlobal | ( | unsigned | Idx | ) |

Returns a pointer to a global.

Definition at line 82 of file Program.cpp.

Referenced by clang::interp::GetPtrGlobal().

## Friends And Related Function Documentation

## ◆ DeclScope

friend class DeclScope
| friend

Definition at line 131 of file Program.h.

The documentation for this class was generated from the following files:

- lib/AST/Interp/Program.h
- lib/AST/Interp/Disasm.cpp
- lib/AST/Interp/Program.cpp