forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsmJsCodeGenerator.cpp
More file actions
49 lines (44 loc) · 2.25 KB
/
Copy pathAsmJsCodeGenerator.cpp
File metadata and controls
49 lines (44 loc) · 2.25 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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "RuntimeLanguagePch.h"
#ifdef ASMJS_PLAT
#include "CodeGenAllocators.h"
namespace Js
{
AsmJsCodeGenerator::AsmJsCodeGenerator( ScriptContext* scriptContext ) :
mScriptContext( scriptContext )
,mPageAllocator(scriptContext->GetThreadContext()->GetPageAllocator())
{
//use the same foreground allocator as NativeCodeGen
mForegroundAllocators = GetForegroundAllocator(scriptContext->GetNativeCodeGenerator(),mPageAllocator);
mEncoder.SetPageAllocator( mPageAllocator );
mEncoder.SetCodeGenAllocator( mForegroundAllocators );
}
void AsmJsCodeGenerator::CodeGen( FunctionBody* functionBody )
{
AsmJsFunctionInfo* asmInfo = functionBody->GetAsmJsFunctionInfo();
Assert( asmInfo );
void* address = mEncoder.Encode( functionBody );
if( address )
{
FunctionEntryPointInfo* funcEntrypointInfo = (FunctionEntryPointInfo*)functionBody->GetDefaultEntryPointInfo();
EntryPointInfo* entrypointInfo = (EntryPointInfo*)funcEntrypointInfo;
Assert(entrypointInfo->GetIsAsmJSFunction());
//set entrypointinfo address and nativeAddress with TJ address
Js::JavascriptMethod method = reinterpret_cast<Js::JavascriptMethod>(address);
entrypointInfo->jsMethod = method;
entrypointInfo->SetTJNativeAddress(method, mScriptContext->GetNativeCodeGenerator());
#if ENABLE_DEBUG_CONFIG_OPTIONS
funcEntrypointInfo->SetIsTJMode(true);
#endif
if (!PreReservedVirtualAllocWrapper::IsInRange((void*)mScriptContext->GetThreadContext()->GetPreReservedRegionAddr(), (void*)address))
{
Assert(entrypointInfo->GetCodeSize() < (uint64)((uint64)1 << 32));
mScriptContext->GetJitFuncRangeCache()->AddFuncRange((void*)address, (uint)entrypointInfo->GetCodeSize());
}
}
}
}
#endif