From 64f156737831589fcc230ce8b91a87b6a5ec4a34 Mon Sep 17 00:00:00 2001 From: dong Date: Mon, 21 Aug 2023 16:32:23 +0800 Subject: [PATCH 1/2] Signed-off-by: dong Change-Id: I573f434e57c3a0d906b3043beb3ac442b4231c82 Change-Id: Ibd78eb484c0fee06fc125316aa2a307e81c93d5d --- es2panda/binder/variable.h | 5 ++ es2panda/compiler/core/emitter/emitter.cpp | 62 +++++++++++++--------- es2panda/compiler/core/emitter/emitter.h | 1 + 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/es2panda/binder/variable.h b/es2panda/binder/variable.h index 34bbc94bd2d..c43173b1162 100644 --- a/es2panda/binder/variable.h +++ b/es2panda/binder/variable.h @@ -115,6 +115,11 @@ public: return HasFlag(VariableFlags::LEXICAL_BOUND); } + bool IsHoistVar() const + { + return flags_ == VariableFlags::HOIST_VAR; + } + const util::StringView &Name() const; virtual void SetLexical(Scope *scope, util::PatchFix *patchFixHelper = nullptr) = 0; diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index b3e2062dfce..81c50993c89 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -250,7 +250,20 @@ void FunctionEmitter::GenFunctionSource() if (pg_->Context()->IsRecordSource() || (static_cast(pg_->RootNode()))->ShowSource()) { func_->source_code = SourceCode().Mutf8(); } - +} + +bool FunctionEmitter::NotHoistAndDecl(const IRNode *ins, const binder::Variable *variable) +{ + if (variable->IsHoistVar()) { + return false; + } else { + if (ins->Node() == nullptr || variable->Declaration() == nullptr || + variable->Declaration()->Node() == nullptr) { + return false; + } else { + return ins->Node() == variable->Declaration()->Node(); + } + } } void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) @@ -258,33 +271,34 @@ void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) const auto *startIns = scope->ScopeStart(); const auto *endIns = scope->ScopeEnd(); - uint32_t start = 0; - uint32_t count = 0; - - for (const auto *it : pg_->Insns()) { - if (startIns == it) { - start = count; - } else if (endIns == it) { - auto varsLength = static_cast(count - start + 1); - - for (const auto &[name, variable] : scope->Bindings()) { - if (!variable->IsLocalVariable() || variable->LexicalBound()) { - continue; - } - - auto &variableDebug = func_->local_variable_debug.emplace_back(); - variableDebug.name = name.Mutf8(); - variableDebug.signature = "any"; - variableDebug.signature_type = "any"; - variableDebug.reg = static_cast(variable->AsLocalVariable()->Vreg()); + for (const auto &[name, variable] : scope->Bindings()) { + if (!variable->IsLocalVariable() || variable->LexicalBound()) { + continue; + } + + auto &variableDebug = func_->local_variable_debug.emplace_back(); + variableDebug.name = name.Mutf8(); + variableDebug.signature = "any"; + variableDebug.signature_type = "any"; + variableDebug.reg = static_cast(variable->AsLocalVariable()->Vreg()); + + uint32_t start = 0; + uint32_t count = 0; + for (const auto *it : pg_->Insns()) { + if (startIns == it) { + start = count; + } + if (NotHoistAndDecl(it,variable)) { + start = count; + } + if (endIns == it) { + auto varsLength = static_cast(count - start + 1); variableDebug.start = start; variableDebug.length = static_cast(varsLength); + break; } - - break; + count++; } - - count++; } } diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 411f34656fb..cc593ce33ca 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -92,6 +92,7 @@ private: void GenLiteralBuffers(); void GenBufferLiterals(const LiteralBuffer *buff); void GenFunctionSource(); + bool NotHoistAndDecl(const IRNode *ins, const binder::Variable *variable); const PandaGen *pg_; panda::pandasm::Function *func_ {}; -- Gitee From febfdaffb335204c5c41e24892b0642ab04214a2 Mon Sep 17 00:00:00 2001 From: dong Date: Wed, 6 Sep 2023 10:16:33 +0800 Subject: [PATCH 2/2] Signed-off-by: dong Change-Id: I6d629d8990d7c79c2aebac7292cb61be7908750e --- es2panda/aot/options.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 6fd8a714695..fbf1f16049e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -334,6 +334,7 @@ bool Options::Parse(int argc, const char **argv) } if (opModule.GetValue()) { + opMergeAbc = opModule.GetValue(); scriptKind_ = es2panda::parser::ScriptKind::MODULE; } else if (opCommonjs.GetValue()) { scriptKind_ = es2panda::parser::ScriptKind::COMMONJS; -- Gitee