• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                             options.enableColumn);
39 
40     ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true);
41 
42     queue_ = new CompileFuncQueue(threadCount_, &context);
43     queue_->Schedule();
44 
45     /* Main thread can also be used instead of idling */
46     queue_->Consume();
47     queue_->Wait();
48 
49     if (context.IsMergeAbc()) {
50         context.GetEmitter()->GenRecordNameInfo();
51     }
52 
53     // For global optimization
54     // Constant local export module variable slot info is recorded in the emitter for now,
55     // emit it to the bytecode analysis result here.
56     if (options.requireGlobalOptimization) {
57         util::Helpers::SetConstantLocalExportSlots(std::string(program->RecordName()),
58             context.GetEmitter()->GetConstantLocalExportSlots());
59     }
60 
61     return context.GetEmitter()->Finalize(options.dumpDebugInfo, patchFixHelper_);
62 }
63 
DumpAsm(const panda::pandasm::Program * prog)64 void CompilerImpl::DumpAsm(const panda::pandasm::Program *prog)
65 {
66     Emitter::DumpAsm(prog);
67 }
68 
69 }  // namespace panda::es2panda::compiler
70