1 /**
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "compilerImpl.h"
17
18 #include <compiler/core/compileQueue.h>
19 #include <compiler/core/compilerContext.h>
20 #include <compiler/core/emitter/emitter.h>
21
22 namespace panda::es2panda::compiler {
23
~CompilerImpl()24 CompilerImpl::~CompilerImpl()
25 {
26 if (queue_ != nullptr) {
27 delete queue_;
28 queue_ = nullptr;
29 }
30 }
31
Compile(parser::Program * program,const es2panda::CompilerOptions & options,const std::string & debugInfoSourceFile,const std::string & pkgName)32 panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options,
33 const std::string &debugInfoSourceFile, const std::string &pkgName)
34 {
35 CompilerContext context(program->Binder(), options.isDebug, options.isDebuggerEvaluateExpressionMode,
36 options.mergeAbc, false, options.recordDebugSource,
37 debugInfoSourceFile, pkgName, program->RecordName(), patchFixHelper_);
38
39 ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true);
40
41 queue_ = new CompileFuncQueue(threadCount_, &context);
42 queue_->Schedule();
43
44 /* Main thread can also be used instead of idling */
45 queue_->Consume();
46 queue_->Wait();
47
48 if (context.IsMergeAbc()) {
49 context.GetEmitter()->GenRecordNameInfo();
50 }
51
52 // For global optimization
53 // Constant local export module variable slot info is recorded in the emitter for now,
54 // emit it to the bytecode analysis result here.
55 if (options.requireGlobalOptimization) {
56 util::Helpers::SetConstantLocalExportSlots(std::string(program->RecordName()),
57 context.GetEmitter()->GetConstantLocalExportSlots());
58 }
59
60 return context.GetEmitter()->Finalize(options.dumpDebugInfo, patchFixHelper_);
61 }
62
DumpAsm(const panda::pandasm::Program * prog)63 void CompilerImpl::DumpAsm(const panda::pandasm::Program *prog)
64 {
65 Emitter::DumpAsm(prog);
66 }
67
68 } // namespace panda::es2panda::compiler
69