forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendApi.cpp
More file actions
201 lines (176 loc) · 5.56 KB
/
BackendApi.cpp
File metadata and controls
201 lines (176 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"
NativeCodeGenerator *
NewNativeCodeGenerator(Js::ScriptContext * scriptContext)
{
return HeapNew(NativeCodeGenerator, scriptContext);
}
void
DeleteNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
{
HeapDelete(nativeCodeGen);
}
void
CloseNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
{
nativeCodeGen->Close();
}
bool
IsClosedNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
{
return nativeCodeGen->IsClosed();
}
void SetProfileModeNativeCodeGen(NativeCodeGenerator *pNativeCodeGen, BOOL fSet)
{
pNativeCodeGen->SetProfileMode(fSet);
}
void UpdateNativeCodeGeneratorForDebugMode(NativeCodeGenerator* nativeCodeGen)
{
nativeCodeGen->UpdateQueueForDebugMode();
}
CriticalSection *GetNativeCodeGenCriticalSection(NativeCodeGenerator *pNativeCodeGen)
{
return pNativeCodeGen->Processor()->GetCriticalSection();
}
///----------------------------------------------------------------------------
///
/// GenerateFunction
///
/// This is the main entry point for the runtime to call the native code
/// generator for js function.
///
///----------------------------------------------------------------------------
void
GenerateFunction(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody * fn, Js::ScriptFunction * function)
{
nativeCodeGen->GenerateFunction(fn, function);
}
InProcCodeGenAllocators* GetForegroundAllocator(NativeCodeGenerator * nativeCodeGen, PageAllocator* pageallocator)
{
return nativeCodeGen->GetCodeGenAllocator(pageallocator);
}
#ifdef ENABLE_PREJIT
void
GenerateAllFunctions(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody *fn)
{
nativeCodeGen->GenerateAllFunctions(fn);
}
#endif
#ifdef IR_VIEWER
Js::Var
RejitIRViewerFunction(NativeCodeGenerator *nativeCodeGen, Js::FunctionBody *fn, Js::ScriptContext *scriptContext)
{
return nativeCodeGen->RejitIRViewerFunction(fn, scriptContext);
}
#endif
void
GenerateLoopBody(NativeCodeGenerator *nativeCodeGen, Js::FunctionBody *fn, Js::LoopHeader * loopHeader, Js::EntryPointInfo* info, uint localCount, Js::Var localSlots[])
{
nativeCodeGen->GenerateLoopBody(fn, loopHeader, info, localCount, localSlots);
}
void
NativeCodeGenEnterScriptStart(NativeCodeGenerator * nativeCodeGen)
{
if (nativeCodeGen)
{
nativeCodeGen->EnterScriptStart();
}
}
BOOL IsIntermediateCodeGenThunk(Js::JavascriptMethod codeAddress)
{
return NativeCodeGenerator::IsThunk(codeAddress);
}
BOOL IsAsmJsCodeGenThunk(Js::JavascriptMethod codeAddress)
{
return NativeCodeGenerator::IsAsmJsCodeGenThunk(codeAddress);
}
CheckCodeGenFunction GetCheckCodeGenFunction(Js::JavascriptMethod codeAddress)
{
return NativeCodeGenerator::GetCheckCodeGenFunction(codeAddress);
}
Js::JavascriptMethod GetCheckCodeGenThunk()
{
return NativeCodeGenerator::CheckCodeGenThunk;
}
#ifdef ASMJS_PLAT
Js::JavascriptMethod GetCheckAsmJsCodeGenThunk()
{
return NativeCodeGenerator::CheckAsmJsCodeGenThunk;
}
#endif
uint GetBailOutRegisterSaveSlotCount()
{
// REVIEW: not all registers are used, we are allocating more space then necessary.
return LinearScanMD::GetRegisterSaveSlotCount();
}
uint
GetBailOutReserveSlotCount()
{
return 1; //For arguments id
}
#if DBG
void CheckIsExecutable(Js::RecyclableObject * function, Js::JavascriptMethod entrypoint)
{
Js::ScriptContext * scriptContext = function->GetScriptContext();
// it's easy to call the default entry point from RecyclableObject.
AssertMsg((Js::JavascriptFunction::Is(function) && Js::JavascriptFunction::FromVar(function)->IsExternalFunction())
|| Js::CrossSite::IsThunk(entrypoint) || !scriptContext->IsActuallyClosed() ||
(scriptContext->GetThreadContext()->IsScriptActive() && !Js::JavascriptConversion::IsCallable(function)),
"Can't call function when the script context is closed");
if (scriptContext->GetThreadContext()->IsScriptActive())
{
return;
}
if (function->IsExternal())
{
return;
}
if (Js::JavascriptOperators::GetTypeId(function) == Js::TypeIds_HostDispatch)
{
AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
}
else if (Js::JavascriptFunction::Is(function))
{
if (((Js::JavascriptFunction*)function)->IsExternalFunction())
{
return;
}
else if (((Js::JavascriptFunction*)function)->IsWinRTFunction())
{
return;
}
else
{
AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
}
}
else
{
AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
}
}
#endif
#ifdef PROFILE_EXEC
void
CreateProfilerNativeCodeGen(NativeCodeGenerator * nativeCodeGen, Js::ScriptContextProfiler * profiler)
{
nativeCodeGen->CreateProfiler(profiler);
}
void
ProfilePrintNativeCodeGen(NativeCodeGenerator * nativeCodeGen)
{
nativeCodeGen->ProfilePrint();
}
void
SetProfilerFromNativeCodeGen(NativeCodeGenerator * toNativeCodeGen, NativeCodeGenerator * fromNativeCodeGen)
{
toNativeCodeGen->SetProfilerFromNativeCodeGen(fromNativeCodeGen);
}
#endif
void DeleteNativeCodeData(NativeCodeData * data)
{
delete data;
}