clang 17.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 "Program.h"
11#include "Opcode.h"
12#include "clang/AST/Decl.h"
13#include "clang/AST/DeclCXX.h"
14
15using namespace clang;
16using namespace clang::interp;
17
18Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,
20 llvm::DenseMap<unsigned, ParamDescriptor> &&Params,
21 bool HasThisPointer, bool HasRVO)
22 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
23 ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
24 HasThisPointer(HasThisPointer), HasRVO(HasRVO) {}
25
26Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
27 auto It = Params.find(Offset);
28 assert(It != Params.end() && "Invalid parameter offset");
29 return It->second;
30}
31
32SourceInfo Function::getSource(CodePtr PC) const {
33 assert(PC >= getCodeBegin() && "PC does not belong to this function");
34 assert(PC <= getCodeEnd() && "PC Does not belong to this function");
35 unsigned Offset = PC - getCodeBegin();
36 using Elem = std::pair<unsigned, SourceInfo>;
37 auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first());
38 assert(It != SrcMap.end());
39 return It->second;
40}
41
42bool Function::isVirtual() const {
43 if (auto *M = dyn_cast<CXXMethodDecl>(F))
44 return M->isVirtual();
45 return false;
46}
StringRef P
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
unsigned Offset
Definition: Format.cpp:2774
Represents a function declaration or definition.
Definition: Decl.h:1919
Pointer into the code segment.
Definition: Source.h:26
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:76
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:70
Definition: Format.h:4608