UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMProcedure.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
9#include "VVMBytecode.h"
11#include "VVMRegisterName.h"
12#include "VVMType.h"
13#include "VVMUniqueString.h"
14#include "VVMWriteBarrier.h"
15
16namespace Verse
17{
18/*
19This is laid out in memory with (64-bit) pointers followed by (8-byte aligned) instructions followed by (32-bit) integers:
20VProcedure
21FNamedParam NamedParam[0]
22FNamedParam NamedParam[1]
23...
24FNamedParam NamedParam[NumNamedParameters - 1]
25TWriteBarrier<VValue> Constant [0]
26TWriteBarrier<VValue> Constant [1]
27...
28TWriteBarrier<VValue> Constant [NumConstants - 1]
29FOp Ops
30 + NumOpBytes
31FValueOperand Operand [0]
32FValueOperand Operand [1]
33...
34FValueOperand Operand [NumOperands - 1]
35FLabelOffset Label [0]
36FLabelOffset Label [1]
37...
38FLabelOffset Label [NumLabels - 1]
39FUnwindEdge UnwindEdge[0]
40FUnwindEdge UnwindEdge[1]
41...
42FUnwindEdge UnwindEdge[NumUnwindEdges - 1]
43FOpLocation OpLocation[0]
44FOpLocation OpLocation[1]
45...
46FOpLocation OpLocation[NumOpLocations - 1]
47FRegisterName RegisterName[0]
48FRegisterName RegisterName[1]
49...
50FRegisterName RegisterName[NumRegisterNames - 1]
51*/
52struct VProcedure : VCell
53{
56
57 // Used by the debugger when checking breakpoints
59 // Used by the debugger when showing stack frames
61
62 uint32 NumRegisters;
64
65 // Sizes of trailing arrays
66 uint32 NumNamedParameters;
67 uint32 NumConstants;
74
76
77 // Trailing array layout computation
78
80 FNamedParam* GetNamedParamsEnd() { return GetNamedParamsBegin() + NumNamedParameters; }
81
82 TWriteBarrier<VValue>* GetConstantsBegin() { return BitCast<TWriteBarrier<VValue>*>(BitCast<std::byte*>(this) + GetLayout().ConstantsOffset); }
83 TWriteBarrier<VValue>* GetConstantsEnd() { return GetConstantsBegin() + NumConstants; }
84
85 FOp* GetPCForOffset(uint32 Offset) { return BitCast<FOp*>(BitCast<std::byte*>(this) + GetLayout().OpsOffset + Offset); }
86 FOp* GetOpsBegin() { return GetPCForOffset(0); }
87 FOp* GetOpsEnd() { return GetPCForOffset(NumOpBytes); }
88 bool ContainsPC(FOp* PC)
89 {
91 }
92
95
98
101
104
107
108 // In bytes.
109 uint32 BytecodeOffset(const FOp& Bytecode)
110 {
111 return BytecodeOffset(&Bytecode);
112 }
113
114 uint32 BytecodeOffset(const void* Data)
115 {
116 checkSlow(GetOpsBegin() <= Data && Data < GetOpsEnd());
117 return static_cast<uint32>(BitCast<char*>(Data) - BitCast<char*>(GetOpsBegin()));
118 }
119
120 const FLocation* GetLocation(const FOp& Op)
121 {
122 return GetLocation(BytecodeOffset(Op));
123 }
124
125 const FLocation* GetLocation(int32 OpOffset)
126 {
127 return Verse::GetLocation(GetOpLocationsBegin(), GetOpLocationsEnd(), OpOffset);
128 }
129
130 void SetConstant(FAllocationContext Context, FConstantIndex ConstantIndex, VValue Value)
131 {
132 checkSlow(ConstantIndex.Index < NumConstants);
134 }
135
136 VValue GetConstant(FConstantIndex ConstantIndex)
137 {
138 checkSlow(ConstantIndex.Index < NumConstants);
139 return GetConstantsBegin()[ConstantIndex.Index].Get();
140 }
141
143 FAllocationContext Context,
144 uint32 NumNamedParameters,
145 uint32 NumConstants,
152 {
153 FLayout Layout = CalcLayout(NumNamedParameters, NumConstants, NumOpBytes, NumOperands, NumLabels, NumUnwindEdges, NumOpLocations, NumRegisterNames);
154
155 return *new (Context.Allocate(FHeap::CensusSpace, Layout.TotalSize)) VProcedure(
156 Context,
157 NumNamedParameters,
158 NumConstants,
161 NumLabels,
165 }
166
167 void ConductCensusImpl();
168
169 static void SerializeLayout(FAllocationContext Context, VProcedure*& This, FStructuredArchiveVisitor& Visitor);
170 void SerializeImpl(FAllocationContext Context, FStructuredArchiveVisitor& Visitor);
171
172private:
174
175 struct FLayout
176 {
185 int32 TotalSize;
186 };
187
188 static FLayout CalcLayout(
189 uint32 NumNamedParameters,
190 uint32 NumConstants,
197 {
200
201 FLayout Layout;
202 Layout.NamedParamsOffset = StructBuilder.AddMember(sizeof(FNamedParam) * NumNamedParameters, alignof(FNamedParam));
203 Layout.ConstantsOffset = StructBuilder.AddMember(sizeof(TWriteBarrier<VValue>) * NumConstants, alignof(TWriteBarrier<VValue>));
204 Layout.OpsOffset = StructBuilder.AddMember(NumOpBytes, OpAlignment);
205 Layout.OperandsOffset = StructBuilder.AddMember(sizeof(FValueOperand) * NumOperands, alignof(FValueOperand));
206 Layout.LabelsOffset = StructBuilder.AddMember(sizeof(FLabelOffset) * NumLabels, alignof(FLabelOffset));
207 Layout.UnwindEdgesOffset = StructBuilder.AddMember(sizeof(FUnwindEdge) * NumUnwindEdges, alignof(FUnwindEdge));
208 Layout.OpLocationsOffset = StructBuilder.AddMember(sizeof(FOpLocation) * NumOpLocations, alignof(FOpLocation));
209 Layout.RegisterNamesOffset = StructBuilder.AddMember(sizeof(FRegisterName) * NumRegisterNames, alignof(FRegisterName));
210 Layout.TotalSize = StructBuilder.GetSize();
211
212 return Layout;
213 }
214
215 FLayout GetLayout() const
216 {
217 return CalcLayout(NumNamedParameters, NumConstants, NumOpBytes, NumOperands, NumLabels, NumUnwindEdges, NumOpLocations, NumRegisterNames);
218 }
219
221 FAllocationContext Context,
231 , NumNamedParameters(InNumNamedParameters)
232 , NumConstants(InNumConstants)
239 {
241 {
242 new (NamedParam) FNamedParam{};
243 }
245 {
247 }
248 for (FValueOperand* Operand = GetOperandsBegin(); Operand != GetOperandsEnd(); ++Operand)
249 {
250 new (Operand) FValueOperand{};
251 }
252 for (FLabelOffset* Label = GetLabelsBegin(); Label != GetLabelsEnd(); ++Label)
253 {
254 new (Label) FLabelOffset{};
255 }
257 {
258 new (UnwindEdge) FUnwindEdge{};
259 }
261 {
262 new (OpLocation) FOpLocation{};
263 }
265 {
267 }
268 }
269
270 template <typename FuncType>
271 void ForEachOpCode(FuncType&& Func);
272};
273} // namespace Verse
274#endif // WITH_VERSE_VM
#define checkSlow(expr)
Definition AssertionMacros.h:332
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition StructBuilder.h:14
constexpr int32 AddMember(int32 MemberSize, int32 MemberAlignment)
Definition StructBuilder.h:30
Definition Array.h:670
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool SerializeImpl(const UScriptStruct *InSourceEventType, const void *InSourceEventData, FLiveLinkSerializedFrameData &OutSerializedData)
Definition LiveLinkCompression.cpp:126
Definition Archive.h:36