clang 10.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
15 using namespace clang;
16 using namespace clang::interp;
17
18 Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize,
19 llvm::SmallVector<PrimType, 8> &&ParamTypes,
20 llvm::DenseMap<unsigned, ParamDescriptor> &&Params)
21 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
22 ParamTypes(std::move(ParamTypes)), Params(std::move(Params)) {}
23
24 CodePtr Function::getCodeBegin() const { return Code.data(); }
25
26 CodePtr Function::getCodeEnd() const { return Code.data() + Code.size(); }
27
28 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
29 auto It = Params.find(Offset);
30 assert(It != Params.end() && "Invalid parameter offset");
31 return It->second;
32 }
33
34 SourceInfo Function::getSource(CodePtr PC) const {
35 unsigned Offset = PC - getCodeBegin();
36 using Elem = std::pair<unsigned, SourceInfo>;
37 auto It = std::lower_bound(SrcMap.begin(), SrcMap.end(), Elem{Offset, {}},
38 [](Elem A, Elem B) { return A.first < B.first; });
39 if (It == SrcMap.end() || It->first != Offset)
40 llvm::report_fatal_error("missing source location");
41 return It->second;
42 }
43
44 bool Function::isVirtual() const {
45 if (auto *M = dyn_cast<CXXMethodDecl>(F))
46 return M->isVirtual();
47 return false;
48 }
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1783
clang::interp::CodePtr
Pointer into the code segment.
Definition: Source.h:25
P
StringRef P
Definition: ASTMatchersInternal.cpp:485
clang::interp::Function::ParamDescriptor
std::pair< PrimType, Descriptor * > ParamDescriptor
Definition: Function.h:61
clang::interp::Function::getSource
SourceInfo getSource(CodePtr PC) const
Returns the source information at a given PC.
Definition: Function.cpp:34
clang::interp::SourceInfo
Describes the statement/declaration an opcode was generated from.
Definition: Source.h:81
clang::interp::Function::getParamDescriptor
ParamDescriptor getParamDescriptor(unsigned Offset) const
Returns a parameter descriptor.
Definition: Function.cpp:28
std
Definition: Format.h:2445
clang::interp::Function::getCodeEnd
CodePtr getCodeEnd() const
Returns a pointer to the end of the code.
Definition: Function.cpp:26
clang::interp::Function::getCodeBegin
CodePtr getCodeBegin() const
Returns a pointer to the start of the code.
Definition: Function.cpp:24
Offset
unsigned Offset
Definition: Format.cpp:1827
clang::interp::Program
The program contains and links the bytecode for all functions.
Definition: Program.h:43
Program.h
Opcode.h
clang::interp::Function::isVirtual
bool isVirtual() const
Checks if the function is virtual.
Definition: Function.cpp:44
llvm::SmallVector< PrimType, 8 >
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
Function.h
DeclCXX.h
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
clang::interp
Definition: ASTContext.h:146