clang  19.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"
14 #include "clang/Basic/Builtins.h"
15 
16 using namespace clang;
17 using namespace clang::interp;
18 
19 Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,
21  llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
22  llvm::SmallVectorImpl<unsigned> &&ParamOffsets,
23  bool HasThisPointer, bool HasRVO, bool UnevaluatedBuiltin)
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), Variadic(F->isVariadic()),
28  IsUnevaluatedBuiltin(UnevaluatedBuiltin) {}
29 
30 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
31  auto It = Params.find(Offset);
32  assert(It != Params.end() && "Invalid parameter offset");
33  return It->second;
34 }
35 
37  assert(PC >= getCodeBegin() && "PC does not belong to this function");
38  assert(PC <= getCodeEnd() && "PC Does not belong to this function");
39  assert(hasBody() && "Function has no body");
40  unsigned Offset = PC - getCodeBegin();
41  using Elem = std::pair<unsigned, SourceInfo>;
42  auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
43  assert(It != SrcMap.end());
44  return It->second;
45 }
46 
47 bool Function::isVirtual() const {
48  if (const auto *M = dyn_cast<CXXMethodDecl>(F))
49  return M->isVirtual();
50  return false;
51 }
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....
unsigned Offset
Definition: Format.cpp:2978
SourceLocation Loc
Definition: SemaObjC.cpp:755
Represents a function declaration or definition.
Definition: Decl.h:1972
Pointer into the code segment.
Definition: Source.h:30
CodePtr getCodeBegin() const
Returns a pointer to the start of the code.
Definition: Function.h:87
CodePtr getCodeEnd() const
Returns a pointer to the end of the code.
Definition: Function.h:89
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:79
bool hasBody() const
Checks if the function already has a body attached.
Definition: Function.h:174
bool isVirtual() const
Checks if the function is virtual.
Definition: Function.cpp:47
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition: Function.cpp:36
The program contains and links the bytecode for all functions.
Definition: Program.h:39
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:72
The JSON file list parser is used to communicate input to InstallAPI.
Definition: Format.h:5433