clang 18.0.0git
Function.cpp
Go to the documentation of this file.
1//===--- Function.h - Bytecode function for the VM --------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Function.h"
10#include "Opcode.h"
11#include "Program.h"
12#include "clang/AST/Decl.h"
13#include "clang/AST/DeclCXX.h"
15
16using namespace clang;
17using namespace clang::interp;
18
19Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,
21 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
23 bool HasThisPointer, bool HasRVO)
24 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
25 ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
26 ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
27 HasRVO(HasRVO) {}
28
29Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
30 auto It = Params.find(Offset);
31 assert(It != Params.end() && "Invalid parameter offset");
32 return It->second;
33}
34
35SourceInfo Function::getSource(CodePtr PC) const {
36 assert(PC >= getCodeBegin() && "PC does not belong to this function");
37 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
38 assert(hasBody() && "Function has no body");
39 unsigned Offset = PC - getCodeBegin();
40 using Elem = std::pair<unsigned, SourceInfo>;
41 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
42 assert(It != SrcMap.end());
43 return It->second;
44}
45
46bool Function::isVirtual() const {
47 if (const auto *M = dyn_cast<CXXMethodDecl>(F))
48 return M->isVirtual();
49 return false;
50}
51
52bool Function::needsRuntimeArgPop(const ASTContext &Ctx) const {
53 if (!isBuiltin())
54 return false;
55 return Ctx.BuiltinInfo.hasCustomTypechecking(getBuiltinID());
56}
StringRef P
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:632
bool hasCustomTypechecking(unsigned ID) const
Determines whether this builtin has custom typechecking.
Definition: Builtins.h:196
Represents a function declaration or definition.
Definition: Decl.h:1919
Pointer into the code segment.
Definition: Source.h:30
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:77
The program contains and links the bytecode for all functions.
Definition: Program.h:40
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:72
Definition: Format.h:5078