From 2a1be7826230a387b8f9ef6b75616b498de02f33 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Tue, 5 Jul 2022 20:43:15 +0800 Subject: [PATCH 1/3] Build es2panda for ark front-end Build es2panda for ark front-end with gn and code modification Signed-off-by: ctw-ian Change-Id: If17047a6c735318a9fc1efb20a8b2bfeb97bfe3d --- BUILD.gn | 22 + bundle.json | 4 +- es2panda/BUILD.gn | 480 +++++++++++++++++++ es2panda/aot/main.cpp | 8 +- es2panda/aot/options.cpp | 1 + es2panda/aot/options.h | 2 +- es2panda/compiler/base/condition.cpp | 5 - es2panda/compiler/base/destructuring.cpp | 10 +- es2panda/compiler/base/iterators.cpp | 1 - es2panda/compiler/core/emitter.cpp | 10 +- es2panda/compiler/core/pandagen.cpp | 145 +++--- es2panda/compiler/core/pandagen.h | 2 - es2panda/ir/expressions/binaryExpression.cpp | 1 - es2panda/ir/expressions/chainExpression.cpp | 2 +- es2panda/scripts/gen_isa.sh | 52 ++ es2panda/scripts/gen_keywords.sh | 46 ++ 16 files changed, 715 insertions(+), 76 deletions(-) create mode 100644 BUILD.gn create mode 100644 es2panda/BUILD.gn create mode 100755 es2panda/scripts/gen_isa.sh create mode 100755 es2panda/scripts/gen_keywords.sh diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 00000000000..7bf72fa8da9 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/runtime_core/ark_config.gni") +import("//build/ohos.gni") + +group("ets_frontend") { + deps = [ + "./ts2panda:ark_ts2abc_build", + "./es2panda:es2panda_build", + ] +} \ No newline at end of file diff --git a/bundle.json b/bundle.json index e881bff9c34..9c1f1915f7b 100644 --- a/bundle.json +++ b/bundle.json @@ -18,7 +18,9 @@ "third_party": [] }, "build": { - "sub_component": [], + "sub_component": [ + "//ark/ts2abc:ets_frontend" + ], "inner_kits": [], "test": [] } diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn new file mode 100644 index 00000000000..5f6431512f2 --- /dev/null +++ b/es2panda/BUILD.gn @@ -0,0 +1,480 @@ +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/runtime_core/ark_config.gni") +import("//build/ohos.gni") + +es2panda_src = [ + "es2panda.cpp", + "binder/binder.cpp", + "binder/declaration.cpp", + "binder/scope.cpp", + "binder/variable.cpp", + "compiler/base/catchTable.cpp", + "compiler/base/condition.cpp", + "compiler/base/destructuring.cpp", + "compiler/base/hoisting.cpp", + "compiler/base/iterators.cpp", + "compiler/base/lexenv.cpp", + "compiler/base/literals.cpp", + "compiler/base/lreference.cpp", + "compiler/core/compileQueue.cpp", + "compiler/core/compilerContext.cpp", + "compiler/core/compilerImpl.cpp", + "compiler/core/dynamicContext.cpp", + "compiler/core/emitter.cpp", + "compiler/core/envScope.cpp", + "compiler/core/function.cpp", + "compiler/core/inlineCache.cpp", + "compiler/core/labelTarget.cpp", + "compiler/core/moduleContext.cpp", + "compiler/core/pandagen.cpp", + "compiler/core/regAllocator.cpp", + "compiler/core/regScope.cpp", + "compiler/core/switchBuilder.cpp", + "compiler/debugger/debuginfoDumper.cpp", + "compiler/function/asyncFunctionBuilder.cpp", + "compiler/function/asyncGeneratorFunctionBuilder.cpp", + "compiler/function/functionBuilder.cpp", + "compiler/function/generatorFunctionBuilder.cpp", + "ir/astDump.cpp", + "ir/base/catchClause.cpp", + "ir/base/classDefinition.cpp", + "ir/base/classProperty.cpp", + "ir/base/decorator.cpp", + "ir/base/metaProperty.cpp", + "ir/base/methodDefinition.cpp", + "ir/base/property.cpp", + "ir/base/scriptFunction.cpp", + "ir/base/spreadElement.cpp", + "ir/base/templateElement.cpp", + "ir/expression.cpp", + "ir/expressions/arrayExpression.cpp", + "ir/expressions/arrowFunctionExpression.cpp", + "ir/expressions/assignmentExpression.cpp", + "ir/expressions/awaitExpression.cpp", + "ir/expressions/binaryExpression.cpp", + "ir/expressions/callExpression.cpp", + "ir/expressions/chainExpression.cpp", + "ir/expressions/classExpression.cpp", + "ir/expressions/conditionalExpression.cpp", + "ir/expressions/functionExpression.cpp", + "ir/expressions/identifier.cpp", + "ir/expressions/importExpression.cpp", + "ir/expressions/literal.cpp", + "ir/expressions/literals/bigIntLiteral.cpp", + "ir/expressions/literals/booleanLiteral.cpp", + "ir/expressions/literals/nullLiteral.cpp", + "ir/expressions/literals/numberLiteral.cpp", + "ir/expressions/literals/regExpLiteral.cpp", + "ir/expressions/literals/stringLiteral.cpp", + "ir/expressions/literals/taggedLiteral.cpp", + "ir/expressions/memberExpression.cpp", + "ir/expressions/newExpression.cpp", + "ir/expressions/objectExpression.cpp", + "ir/expressions/omittedExpression.cpp", + "ir/expressions/sequenceExpression.cpp", + "ir/expressions/superExpression.cpp", + "ir/expressions/taggedTemplateExpression.cpp", + "ir/expressions/templateLiteral.cpp", + "ir/expressions/thisExpression.cpp", + "ir/expressions/unaryExpression.cpp", + "ir/expressions/updateExpression.cpp", + "ir/expressions/yieldExpression.cpp", + "ir/module/exportAllDeclaration.cpp", + "ir/module/exportDefaultDeclaration.cpp", + "ir/module/exportNamedDeclaration.cpp", + "ir/module/exportSpecifier.cpp", + "ir/module/importDeclaration.cpp", + "ir/module/importDefaultSpecifier.cpp", + "ir/module/importNamespaceSpecifier.cpp", + "ir/module/importSpecifier.cpp", + "ir/statement.cpp", + "ir/statements/blockStatement.cpp", + "ir/statements/breakStatement.cpp", + "ir/statements/classDeclaration.cpp", + "ir/statements/continueStatement.cpp", + "ir/statements/debuggerStatement.cpp", + "ir/statements/doWhileStatement.cpp", + "ir/statements/emptyStatement.cpp", + "ir/statements/expressionStatement.cpp", + "ir/statements/forInStatement.cpp", + "ir/statements/forOfStatement.cpp", + "ir/statements/forUpdateStatement.cpp", + "ir/statements/functionDeclaration.cpp", + "ir/statements/ifStatement.cpp", + "ir/statements/labelledStatement.cpp", + "ir/statements/loopStatement.cpp", + "ir/statements/returnStatement.cpp", + "ir/statements/switchCaseStatement.cpp", + "ir/statements/switchStatement.cpp", + "ir/statements/throwStatement.cpp", + "ir/statements/tryStatement.cpp", + "ir/statements/variableDeclaration.cpp", + "ir/statements/variableDeclarator.cpp", + "ir/statements/whileStatement.cpp", + "ir/ts/tsAnyKeyword.cpp", + "ir/ts/tsArrayType.cpp", + "ir/ts/tsAsExpression.cpp", + "ir/ts/tsBigintKeyword.cpp", + "ir/ts/tsBooleanKeyword.cpp", + "ir/ts/tsClassImplements.cpp", + "ir/ts/tsConditionalType.cpp", + "ir/ts/tsConstructorType.cpp", + "ir/ts/tsEnumDeclaration.cpp", + "ir/ts/tsEnumMember.cpp", + "ir/ts/tsExternalModuleReference.cpp", + "ir/ts/tsFunctionType.cpp", + "ir/ts/tsImportEqualsDeclaration.cpp", + "ir/ts/tsImportType.cpp", + "ir/ts/tsIndexSignature.cpp", + "ir/ts/tsIndexedAccessType.cpp", + "ir/ts/tsInferType.cpp", + "ir/ts/tsInterfaceBody.cpp", + "ir/ts/tsInterfaceDeclaration.cpp", + "ir/ts/tsInterfaceHeritage.cpp", + "ir/ts/tsIntersectionType.cpp", + "ir/ts/tsLiteralType.cpp", + "ir/ts/tsMappedType.cpp", + "ir/ts/tsMethodSignature.cpp", + "ir/ts/tsModuleBlock.cpp", + "ir/ts/tsModuleDeclaration.cpp", + "ir/ts/tsNamedTupleMember.cpp", + "ir/ts/tsNeverKeyword.cpp", + "ir/ts/tsNonNullExpression.cpp", + "ir/ts/tsNullKeyword.cpp", + "ir/ts/tsNumberKeyword.cpp", + "ir/ts/tsObjectKeyword.cpp", + "ir/ts/tsParameterProperty.cpp", + "ir/ts/tsParenthesizedType.cpp", + "ir/ts/tsPrivateIdentifier.cpp", + "ir/ts/tsPropertySignature.cpp", + "ir/ts/tsQualifiedName.cpp", + "ir/ts/tsSignatureDeclaration.cpp", + "ir/ts/tsStringKeyword.cpp", + "ir/ts/tsThisType.cpp", + "ir/ts/tsTupleType.cpp", + "ir/ts/tsTypeAliasDeclaration.cpp", + "ir/ts/tsTypeAssertion.cpp", + "ir/ts/tsTypeLiteral.cpp", + "ir/ts/tsTypeOperator.cpp", + "ir/ts/tsTypeParameter.cpp", + "ir/ts/tsTypeParameterDeclaration.cpp", + "ir/ts/tsTypeParameterInstantiation.cpp", + "ir/ts/tsTypePredicate.cpp", + "ir/ts/tsTypeQuery.cpp", + "ir/ts/tsTypeReference.cpp", + "ir/ts/tsUndefinedKeyword.cpp", + "ir/ts/tsUnionType.cpp", + "ir/ts/tsUnknownKeyword.cpp", + "ir/ts/tsVoidKeyword.cpp", + "lexer/keywordsUtil.cpp", + "lexer/lexer.cpp", + "lexer/regexp/regexp.cpp", + "lexer/token/sourceLocation.cpp", + "lexer/token/token.cpp", + "parser/context/parserContext.cpp", + "parser/expressionParser.cpp", + "parser/parserImpl.cpp", + "parser/program/program.cpp", + "parser/statementParser.cpp", + "typescript/checker.cpp", + "typescript/core/binaryLikeExpression.cpp", + "typescript/core/destructuring.cpp", + "typescript/core/function.cpp", + "typescript/core/generics.cpp", + "typescript/core/helpers.cpp", + "typescript/core/object.cpp", + "typescript/core/typeCreation.cpp", + "typescript/core/typeElaboration.cpp", + "typescript/core/typeRelation.cpp", + "typescript/core/util.cpp", + "typescript/types/anyType.cpp", + "typescript/types/arrayType.cpp", + "typescript/types/bigintLiteralType.cpp", + "typescript/types/bigintType.cpp", + "typescript/types/booleanLiteralType.cpp", + "typescript/types/booleanType.cpp", + "typescript/types/constructorType.cpp", + "typescript/types/enumLiteralType.cpp", + "typescript/types/enumType.cpp", + "typescript/types/functionType.cpp", + "typescript/types/globalTypesHolder.cpp", + "typescript/types/indexInfo.cpp", + "typescript/types/interfaceType.cpp", + "typescript/types/neverType.cpp", + "typescript/types/nonPrimitiveType.cpp", + "typescript/types/nullType.cpp", + "typescript/types/numberLiteralType.cpp", + "typescript/types/numberType.cpp", + "typescript/types/objectDescriptor.cpp", + "typescript/types/objectLiteralType.cpp", + "typescript/types/objectType.cpp", + "typescript/types/signature.cpp", + "typescript/types/stringLiteralType.cpp", + "typescript/types/stringType.cpp", + "typescript/types/tupleType.cpp", + "typescript/types/type.cpp", + "typescript/types/typeParameter.cpp", + "typescript/types/typeReference.cpp", + "typescript/types/typeRelation.cpp", + "typescript/types/undefinedType.cpp", + "typescript/types/unionType.cpp", + "typescript/types/unknownType.cpp", + "typescript/types/voidType.cpp", + "util/bitset.cpp", + "util/helpers.cpp", + "util/ustring.cpp" +] + +config("es2abc_config_src") { + include_dirs = [ + "./", + "./binder", + "./util", + "./compiler/base", + "./compiler/core", + "./compiler/debugger", + "./compiler/function", + "./ir", + "./ir/base", + "./ir/expressions", + "./ir/module", + "./ir/statements", + "./ir/ts", + "./parser", + "./parser/context", + "./lexer", + "./lexer/token", + "./lexer/regexp", + "./typescript", + "./typescript/types" + ] + + cflags = [ "-fexceptions" ] +} + +config("es2abc_config_common") { + + configs = [ + "$ark_root:ark_config", + "$sdk_libc_secshared_config", + "$ark_root/libpandafile:arkfile_public_config", + "$ark_root/libpandabase:arkbase_public_config", + "$ark_root/runtime:arkruntime_public_config", + "$ark_root/assembler:arkassembler_public_config", + ":es2abc_config_src", + ] + + if (enable_bytecode_optimizer) { + defines = [ "ENABLE_BYTECODE_OPT" ] + configs += [ + "$ark_root/compiler:arkcompiler_public_config", + "$ark_root/bytecode_optimizer:bytecodeopt_public_config", + ] + } +} + +# generate headers for es2panda parser +generated_header_dir = "${target_out_dir}/gen" +action_foreach("gen_keywords_headers") { + template_files = [ + "keywords.h.erb", + "keywordsMap.h.erb", + ] + keywords_templates_dir = "./lexer/templates" + keywords_generator = "./lexer/scripts/keywords.rb" + + sources = [] + foreach(file, template_files) { + sources += [ rebase_path("${keywords_templates_dir}/${file}") ] + } + outputs = [ "${generated_header_dir}/{{source_name_part}}" ] + + script = "scripts/gen_keywords.sh" + inputs = [ "${keywords_generator}" ] + args = [ + "-g", rebase_path("${keywords_generator}"), + "-t", "{{source}}", + "-o", "{{source_name_part}}", + "-d", rebase_path("${generated_header_dir}"), + ] +} + +# generate headers for es2panda compiler +isa_gen = "${ark_root}/isa/gen.rb" +isa_gen_data = "$root_gen_dir/isa/isa.yaml" +isa_gen_require = "${ark_root}/isa/isapi.rb" +action_foreach("gen_isa_headers") { + + deps = [ "//ark/runtime_core/isa:isa_combine" ] + + template_files = [ + "isa.h.erb", + "formats.h.erb", + ] + keywords_templates_dir = "./compiler/templates" + + sources = [] + foreach(file, template_files) { + sources += [ rebase_path("${keywords_templates_dir}/${file}") ] + } + outputs = [ "${generated_header_dir}/{{source_name_part}}" ] + + script = "scripts/gen_isa.sh" + inputs = [ + "${isa_gen}", + "${isa_gen_data}", + "${isa_gen_require}" + ] + args = [ + "-g", rebase_path("${isa_gen}"), + "-t", "{{source}}", + "-a", rebase_path("${isa_gen_data}"), + "-o", "{{source_name_part}}", + "-d", rebase_path("${generated_header_dir}"), + "-r", rebase_path("${isa_gen_require}"), + ] +} + +ohos_static_library("es2panda_lib") { + sources = es2panda_src + use_exceptions = true + + configs = [ ":es2abc_config_common" ] + + include_dirs = [ + "${target_out_dir}", + "//third_party/icu/icu4c/source/common", + "//third_party/icu/icu4c/source/i18n", + "//third_party/icu/icu4c/source ", + ] + + deps = [ + ":gen_keywords_headers", + ":gen_isa_headers", + "$ark_root/assembler:libarkassembler_frontend_static", + "$ark_root/libpandabase:libarkbase_frontend_static", + "$ark_root/libpandafile:libarkfile_frontend_static", + "$ark_root/libziparchive:libarkziparchive_frontend_static", + "//third_party/icu/icu4c:static_icuuc", + ] + + cflags = [ + "-Wno-implicit-fallthrough", + ] +} + +ohos_executable("es2panda") { + use_exceptions = true + sources = [ + "aot/options.cpp", + "aot/main.cpp", + ] + + include_dirs = [ "./aot" ] + + configs = [ ":es2abc_config_common" ] + + deps = [ + ":es2panda_lib", + ] + + if (is_linux) { + if (build_public_version) { + ldflags = [ "-static-libstdc++" ] + } else { + libs = [ libcpp_static_lib ] + } + } + + if (enable_bytecode_optimizer) { + deps += [ + "$ark_root/bytecode_optimizer:libarkbytecodeopt_frontend_static", + "$ark_root/compiler:libarkcompiler_frontend_static", + ] + } + + output_name = "es2abc" + install_enable = true + subsystem_name = "ark" +} + +if (is_linux) { + ohos_copy("es2abc_build") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc" ] + outputs = [ "${target_out_dir}/es2abc-tmp" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc" + } + + ohos_copy("es2abc_build_ets") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc" ] + outputs = [ "${root_out_dir}/ark/ark/es2abc-ets" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc" + } +} + +if (is_mingw) { + ohos_copy("es2abc_build_win") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc.exe" ] + outputs = [ "${target_out_dir}/es2abc-tmp" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc.exe" + } + + ohos_copy("es2abc_build_win_ets") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc.exe" ] + outputs = [ "${root_out_dir}/ark/ark/es2abc-win-ets" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc.exe" + } +} + +if (is_mac) { + ohos_copy("es2abc_build_mac") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc" ] + outputs = [ "${target_out_dir}/es2abc-tmp" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc" + } + + ohos_copy("es2abc_build_mac_ets") { + deps = [ ":es2panda" ] + sources = [ "${root_out_dir}/ark/ark/es2abc" ] + outputs = [ "${root_out_dir}/ark/ark/es2abc-mac-ets" ] + module_source_dir = "${root_out_dir}/ark/ark" + module_install_name = "es2abc" + } +} + +group("es2panda_build") { + build_tool_linux = "//build/toolchain/linux:clang_x64" + if (host_os == "linux") { + deps = [ ":es2panda(${build_tool_linux})" ] + } + + if (host_os == "mac") { + deps = [ ":es2panda(//build/toolchain/mac:clang_x64)" ] + } +} + +group("es2panda_build_win") { + deps = [ ":es2panda(//build/toolchain/mingw:mingw_x86_64)" ] +} diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index 8dbd680977f..ad0dde48b47 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -14,12 +14,18 @@ */ #include +#ifdef ENABLE_BYTECODE_OPT #include #include +#else +#include +#include +#include +#endif #include #include #include -#include +#include #include #include diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 9be3f001c5b..9f72eac598d 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -18,6 +18,7 @@ #include #include +#include namespace panda::es2panda::aot { diff --git a/es2panda/aot/options.h b/es2panda/aot/options.h index af8c8e3093a..9b681e7f11c 100644 --- a/es2panda/aot/options.h +++ b/es2panda/aot/options.h @@ -17,7 +17,7 @@ #define ES2PANDA_AOT_OPTIONS_H #include -#include +#include #include #include diff --git a/es2panda/compiler/base/condition.cpp b/es2panda/compiler/base/condition.cpp index 644e9195fec..577d8c63e49 100644 --- a/es2panda/compiler/base/condition.cpp +++ b/es2panda/compiler/base/condition.cpp @@ -51,11 +51,9 @@ void Condition::Compile(PandaGen *pg, const ir::Expression *expr, Label *falseLa } case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { binExpr->Left()->Compile(pg); - pg->ToBoolean(binExpr); pg->BranchIfFalse(binExpr, falseLabel); binExpr->Right()->Compile(pg); - pg->ToBoolean(binExpr); pg->BranchIfFalse(binExpr, falseLabel); return; } @@ -63,11 +61,9 @@ void Condition::Compile(PandaGen *pg, const ir::Expression *expr, Label *falseLa auto *endLabel = pg->AllocLabel(); binExpr->Left()->Compile(pg); - pg->ToBoolean(binExpr); pg->BranchIfTrue(binExpr, endLabel); binExpr->Right()->Compile(pg); - pg->ToBoolean(binExpr); pg->BranchIfFalse(binExpr, falseLabel); pg->SetLabel(binExpr, endLabel); return; @@ -87,7 +83,6 @@ void Condition::Compile(PandaGen *pg, const ir::Expression *expr, Label *falseLa // General case including some binExpr i.E.(a+b) expr->Compile(pg); - pg->ToBoolean(expr); pg->BranchIfFalse(expr, falseLabel); } diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 7ff756529f3..5b3ac2e0c14 100644 --- a/es2panda/compiler/base/destructuring.cpp +++ b/es2panda/compiler/base/destructuring.cpp @@ -223,9 +223,15 @@ static void GenObject(PandaGen *pg, const ir::ObjectExpression *object, VReg rhs if (properties.empty() || properties.back()->IsRestElement()) { auto *notNullish = pg->AllocLabel(); + auto *nullish = pg->AllocLabel(); - pg->LoadAccumulator(object, rhs); - pg->BranchIfCoercible(object, notNullish); + pg->LoadConst(object, Constant::JS_NULL); + pg->Condition(object, lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL, rhs, nullish); + pg->LoadConst(object, Constant::JS_UNDEFINED); + pg->Condition(object, lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL, rhs, nullish); + pg->Branch(object, notNullish); + + pg->SetLabel(object, nullish); pg->ThrowObjectNonCoercible(object); pg->SetLabel(object, notNullish); diff --git a/es2panda/compiler/base/iterators.cpp b/es2panda/compiler/base/iterators.cpp index 1bf7ad88879..8ba4d12a112 100644 --- a/es2panda/compiler/base/iterators.cpp +++ b/es2panda/compiler/base/iterators.cpp @@ -70,7 +70,6 @@ void Iterator::Next() const void Iterator::Complete() const { pg_->LoadObjByName(node_, nextResult_, "done"); - pg_->ToBoolean(node_); } void Iterator::Value() const diff --git a/es2panda/compiler/core/emitter.cpp b/es2panda/compiler/core/emitter.cpp index 6e617cb41f1..c25c579fe24 100644 --- a/es2panda/compiler/core/emitter.cpp +++ b/es2panda/compiler/core/emitter.cpp @@ -119,11 +119,11 @@ void FunctionEmitter::GenBufferLiterals(const LiteralBuffer *buff) valueLit.value_ = literal->GetMethod().Mutf8(); break; } - case ir::LiteralTag::ASYNC_GENERATOR_METHOD: { - valueLit.tag_ = panda::panda_file::LiteralTag::ASYNCGENERATORMETHOD; - valueLit.value_ = literal->GetMethod().Mutf8(); - break; - } + // case ir::LiteralTag::ASYNC_GENERATOR_METHOD: { + // valueLit.tag_ = panda::panda_file::LiteralTag::ASYNCGENERATORMETHOD; + // valueLit.value_ = literal->GetMethod().Mutf8(); + // break; + // } case ir::LiteralTag::NULL_VALUE: { valueLit.tag_ = panda::panda_file::LiteralTag::NULLVALUE; valueLit.value_ = static_cast(0); diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 7d58fa71c45..5c4ea926691 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -415,7 +415,7 @@ void PandaGen::StoreGlobalVar(const ir::AstNode *node, const util::StringView &n void PandaGen::StoreGlobalLet(const ir::AstNode *node, const util::StringView &name) { - sa_.Emit(node, name); + sa_.Emit(node, name); strings_.insert(name); } @@ -646,7 +646,7 @@ void PandaGen::Unary(const ir::AstNode *node, lexer::TokenType op, VReg operand) break; } case lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK: { - sa_.Emit(node); + Negate(node); break; } case lexer::TokenType::PUNCTUATOR_PLUS_PLUS: { @@ -784,19 +784,25 @@ void PandaGen::Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs) void PandaGen::BranchIfUndefined(const ir::AstNode *node, Label *target) { - sa_.Emit(node); - BranchIfTrue(node, target); + VReg tmp = AllocReg(); + StoreAccumulator(node, tmp); + sa_.Emit(node); + ra_.Emit(node, tmp); + sa_.Emit(node, target); } void PandaGen::BranchIfNotUndefined(const ir::AstNode *node, Label *target) { - sa_.Emit(node); - BranchIfFalse(node, target); + VReg tmp = AllocReg(); + StoreAccumulator(node, tmp); + sa_.Emit(node); + ra_.Emit(node, tmp); + sa_.Emit(node, target); } void PandaGen::BranchIfTrue(const ir::AstNode *node, Label *target) { - sa_.Emit(node, target); + sa_.Emit(node, target); } void PandaGen::BranchIfNotTrue(const ir::AstNode *node, Label *target) @@ -807,13 +813,7 @@ void PandaGen::BranchIfNotTrue(const ir::AstNode *node, Label *target) void PandaGen::BranchIfFalse(const ir::AstNode *node, Label *target) { - sa_.Emit(node, target); -} - -void PandaGen::BranchIfCoercible(const ir::AstNode *node, Label *target) -{ - sa_.Emit(node); - BranchIfTrue(node, target); + sa_.Emit(node, target); } void PandaGen::EmitThrow(const ir::AstNode *node) @@ -823,12 +823,13 @@ void PandaGen::EmitThrow(const ir::AstNode *node) void PandaGen::EmitRethrow(const ir::AstNode *node) { - sa_.Emit(node); + // commented for compile workaround + // sa_.Emit(node); } void PandaGen::EmitReturn(const ir::AstNode *node) { - sa_.Emit(node); + sa_.Emit(node); } void PandaGen::EmitReturnUndefined(const ir::AstNode *node) @@ -888,25 +889,25 @@ void PandaGen::Call(const ir::AstNode *node, VReg startReg, size_t argCount) switch (argCount) { case 0: { // 0 args - ra_.Emit(node, callee); + ra_.Emit(node, callee); break; } case 1: { // 1 arg VReg arg0 = callee + 1; - ra_.Emit(node, callee, arg0); + ra_.Emit(node, callee, arg0); break; } case 2: { // 2 args VReg arg0 = callee + 1; VReg arg1 = arg0 + 1; - ra_.Emit(node, callee, arg0, arg1); + ra_.Emit(node, callee, arg0, arg1); break; } case 3: { // 3 args VReg arg0 = callee + 1; VReg arg1 = arg0 + 1; VReg arg2 = arg1 + 1; - ra_.Emit(node, callee, arg0, arg1, arg2); + ra_.Emit(node, callee, arg0, arg1, arg2); break; } default: { @@ -938,21 +939,22 @@ void PandaGen::LoadHomeObject(const ir::AstNode *node) void PandaGen::DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name) { + auto formal_param_cnt = FormalParametersCount(); if (realNode->IsAsync()) { if (realNode->IsGenerator()) { - ra_.Emit(node, name, LexEnv()); + // TODO(): async generator } else { - ra_.Emit(node, name, LexEnv()); + ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); } } else if (realNode->IsGenerator()) { - ra_.Emit(node, name, LexEnv()); + ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); } else if (realNode->IsArrow()) { LoadHomeObject(node); - ra_.Emit(node, name, LexEnv()); + ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); } else if (realNode->IsMethod()) { - ra_.Emit(node, name, LexEnv()); + ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); } else { - ra_.Emit(node, name, LexEnv()); + ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); } strings_.insert(name); @@ -980,12 +982,14 @@ void PandaGen::GetUnmappedArgs(const ir::AstNode *node) void PandaGen::Negate(const ir::AstNode *node) { - sa_.Emit(node); -} - -void PandaGen::ToBoolean(const ir::AstNode *node) -{ - sa_.Emit(node); + auto *falseLabel = AllocLabel(); + auto *endLabel = AllocLabel(); + BranchIfTrue(node, falseLabel); + LoadConst(node, Constant::JS_TRUE); + Branch(node, endLabel); + SetLabel(node, falseLabel); + LoadConst(node, Constant::JS_FALSE); + SetLabel(node, endLabel); } void PandaGen::ToNumber(const ir::AstNode *node, VReg arg) @@ -995,8 +999,9 @@ void PandaGen::ToNumber(const ir::AstNode *node, VReg arg) void PandaGen::GetMethod(const ir::AstNode *node, VReg obj, const util::StringView &name) { - ra_.Emit(node, name, obj); - strings_.insert(name); + // commented for compile workaround + // ra_.Emit(node, name, obj); + // strings_.insert(name); } void PandaGen::CreateGeneratorObj(const ir::AstNode *node, VReg funcObj) @@ -1006,32 +1011,38 @@ void PandaGen::CreateGeneratorObj(const ir::AstNode *node, VReg funcObj) void PandaGen::CreateAsyncGeneratorObj(const ir::AstNode *node, VReg funcObj) { - ra_.Emit(node, funcObj); + // commented for compile workaround + // ra_.Emit(node, funcObj); } void PandaGen::CreateIterResultObject(const ir::AstNode *node, bool done) { - ra_.Emit(node, static_cast(done)); + // commented for compile workaround + // ra_.Emit(node, static_cast(done)); } void PandaGen::SuspendGenerator(const ir::AstNode *node, VReg genObj) { - ra_.Emit(node, genObj); + // commented for compile workaround + // ra_.Emit(node, genObj); } void PandaGen::SuspendAsyncGenerator(const ir::AstNode *node, VReg asyncGenObj) { - ra_.Emit(node, asyncGenObj); + // commented for compile workaround + // ra_.Emit(node, asyncGenObj); } void PandaGen::GeneratorYield(const ir::AstNode *node, VReg genObj) { - ra_.Emit(node, genObj, static_cast(GeneratorState::SUSPENDED_YIELD)); + // commented for compile workaround + // ra_.Emit(node, genObj, static_cast(GeneratorState::SUSPENDED_YIELD)); } void PandaGen::GeneratorComplete(const ir::AstNode *node, VReg genObj) { - ra_.Emit(node, genObj, static_cast(GeneratorState::COMPLETED)); + // commented for compile workaround + // ra_.Emit(node, genObj, static_cast(GeneratorState::COMPLETED)); } void PandaGen::ResumeGenerator(const ir::AstNode *node, VReg genObj) @@ -1051,27 +1062,32 @@ void PandaGen::AsyncFunctionEnter(const ir::AstNode *node) void PandaGen::AsyncFunctionAwait(const ir::AstNode *node, VReg asyncFuncObj) { - ra_.Emit(node, asyncFuncObj); + // commented for compile workaround + // ra_.Emit(node, asyncFuncObj); } void PandaGen::AsyncFunctionResolve(const ir::AstNode *node, VReg asyncFuncObj) { - ra_.Emit(node, asyncFuncObj); + // commented for compile workaround + // ra_.Emit(node, asyncFuncObj); } void PandaGen::AsyncFunctionReject(const ir::AstNode *node, VReg asyncFuncObj) { - ra_.Emit(node, asyncFuncObj); + // commented for compile workaround + // ra_.Emit(node, asyncFuncObj); } void PandaGen::AsyncGeneratorResolve(const ir::AstNode *node, VReg asyncGenObj) { - ra_.Emit(node, asyncGenObj); + // commented for compile workaround + // ra_.Emit(node, asyncGenObj); } void PandaGen::AsyncGeneratorReject(const ir::AstNode *node, VReg asyncGenObj) { - ra_.Emit(node, asyncGenObj); + // commented for compile workaround + // ra_.Emit(node, asyncGenObj); } void PandaGen::GetTemplateObject(const ir::AstNode *node, VReg value) @@ -1243,7 +1259,9 @@ void PandaGen::StoreArraySpread(const ir::AstNode *node, VReg array, VReg index) void PandaGen::ThrowIfNotObject(const ir::AstNode *node) { - ra_.Emit(node); + // commented for compile workaround + VReg value = AllocReg(); + ra_.Emit(node, value); } void PandaGen::ThrowThrowNotExist(const ir::AstNode *node) @@ -1258,7 +1276,8 @@ void PandaGen::GetIterator(const ir::AstNode *node) void PandaGen::GetAsyncIterator(const ir::AstNode *node) { - sa_.Emit(node); + // commented for compile workaround + // sa_.Emit(node); } void PandaGen::CreateObjectWithExcludedKeys(const ir::AstNode *node, VReg obj, VReg argStart, size_t argCount) @@ -1284,21 +1303,24 @@ void PandaGen::CloseIterator(const ir::AstNode *node, VReg iter) void PandaGen::ImportModule(const ir::AstNode *node, const util::StringView &name) { - sa_.Emit(node, name); - strings_.insert(name); + // commented for compile workaround + // sa_.Emit(node, name); + // strings_.insert(name); } void PandaGen::DefineClassWithBuffer(const ir::AstNode *node, const util::StringView &ctorId, int32_t litIdx, VReg lexenv, VReg base) { - ra_.Emit(node, ctorId, litIdx, lexenv, base); + auto formal_param_cnt = FormalParametersCount(); + ra_.Emit(node, ctorId, litIdx, static_cast(formal_param_cnt), lexenv, base); strings_.insert(ctorId); } void PandaGen::LoadModuleVariable(const ir::AstNode *node, VReg module, const util::StringView &name) { - ra_.Emit(node, name, module); - strings_.insert(name); + // commented for compile workaround + // ra_.Emit(node, name, module); + // strings_.insert(name); } void PandaGen::StoreModuleVar(const ir::AstNode *node, const util::StringView &name) @@ -1386,7 +1408,9 @@ void PandaGen::LoadLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot) { - ra_.Emit(node, level, slot); + VReg value = AllocReg(); + StoreAccumulator(node, value); + ra_.Emit(node, level, slot, value); } void PandaGen::ThrowIfSuperNotCorrectCall(const ir::AstNode *node, int64_t num) @@ -1396,13 +1420,21 @@ void PandaGen::ThrowIfSuperNotCorrectCall(const ir::AstNode *node, int64_t num) void PandaGen::ThrowUndefinedIfHole(const ir::AstNode *node, const util::StringView &name) { - ra_.Emit(node, name); + VReg hole_reg = AllocReg(); + StoreAccumulator(node, hole_reg); + LoadAccumulatorString(node, name); + VReg name_reg = AllocReg(); + StoreAccumulator(node, name_reg); + ra_.Emit(node, hole_reg, name_reg); strings_.insert(name); } void PandaGen::ThrowConstAssignment(const ir::AstNode *node, const util::StringView &name) { - ra_.Emit(node, name); + LoadAccumulatorString(node, name); + VReg nameReg = AllocReg(); + StoreAccumulator(node, nameReg); + ra_.Emit(node, nameReg); strings_.insert(name); } @@ -1413,7 +1445,8 @@ void PandaGen::PopLexEnv(const ir::AstNode *node) void PandaGen::CopyLexEnv(const ir::AstNode *node) { - sa_.Emit(node); + // commented for compile workaround + // sa_.Emit(node); } void PandaGen::NewLexEnv(const ir::AstNode *node, uint32_t num) diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index eefd2e4b241..77d127c4238 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -255,7 +255,6 @@ public: void BranchIfTrue(const ir::AstNode *node, class Label *target); void BranchIfNotTrue(const ir::AstNode *node, class Label *target); void BranchIfFalse(const ir::AstNode *node, class Label *target); - void BranchIfCoercible(const ir::AstNode *node, class Label *target); void EmitThrow(const ir::AstNode *node); void EmitRethrow(const ir::AstNode *node); @@ -281,7 +280,6 @@ public: void GetUnmappedArgs(const ir::AstNode *node); void Negate(const ir::AstNode *node); - void ToBoolean(const ir::AstNode *node); void ToNumber(const ir::AstNode *node, VReg arg); void CreateGeneratorObj(const ir::AstNode *node, VReg funcObj); diff --git a/es2panda/ir/expressions/binaryExpression.cpp b/es2panda/ir/expressions/binaryExpression.cpp index 7423a2dfb2b..5621dfe8e52 100644 --- a/es2panda/ir/expressions/binaryExpression.cpp +++ b/es2panda/ir/expressions/binaryExpression.cpp @@ -56,7 +56,6 @@ void BinaryExpression::CompileLogical(compiler::PandaGen *pg) const // left -> acc -> lhs -> toboolean -> acc -> bool_lhs left_->Compile(pg); pg->StoreAccumulator(this, lhs); - pg->ToBoolean(this); if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { pg->BranchIfFalse(this, skipRight); diff --git a/es2panda/ir/expressions/chainExpression.cpp b/es2panda/ir/expressions/chainExpression.cpp index 0869146030a..16e2b3a2999 100644 --- a/es2panda/ir/expressions/chainExpression.cpp +++ b/es2panda/ir/expressions/chainExpression.cpp @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/es2panda/scripts/gen_isa.sh b/es2panda/scripts/gen_isa.sh new file mode 100755 index 00000000000..28ab703f1b0 --- /dev/null +++ b/es2panda/scripts/gen_isa.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +while getopts "g:t:a:o:d:r:h" arg +do + case "${arg}" in + "g") + GENERATOR=${OPTARG} + ;; + "t") + TEMPLATE=${OPTARG} + ;; + "a") + DATA=${OPTARG} + ;; + "o") + OUTPUT=${OPTARG} + ;; + "d") + OUTDIR=${OPTARG} + ;; + "r") + REQUIRE=${OPTARG} + ;; + "h") + echo "help" + ;; + ?) + echo "unkonw argument" + exit 1 + ;; + esac +done + +if [ ! -d ${OUTDIR} ]; then + mkdir -p ${OUTDIR} +fi +echo "${GENERATOR} --template ${TEMPLATE} --data ${DATA} --output ${OUTDIR}/${OUTPUT} --require ${REQUIRE}" +${GENERATOR} --template ${TEMPLATE} --data ${DATA} --output ${OUTDIR}/${OUTPUT} --require ${REQUIRE} diff --git a/es2panda/scripts/gen_keywords.sh b/es2panda/scripts/gen_keywords.sh new file mode 100755 index 00000000000..43f4069f464 --- /dev/null +++ b/es2panda/scripts/gen_keywords.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +while getopts "g:t:o:d:h" arg +do + case "${arg}" in + "g") + GENERATOR=${OPTARG} + ;; + "t") + TEMPLATE=${OPTARG} + ;; + "o") + OUTPUT=${OPTARG} + ;; + "d") + OUTDIR=${OPTARG} + ;; + "h") + echo "help" + ;; + ?) + echo "unkonw argument" + exit 1 + ;; + esac +done + +if [ ! -d ${OUTDIR} ]; then + mkdir -p ${OUTDIR} +fi + +ruby ${GENERATOR} ${TEMPLATE} ${OUTDIR}/${OUTPUT} -- Gitee From 40f3f027a4ed762ada6f77186ae796c3f97470fd Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Mon, 11 Jul 2022 11:25:22 +0800 Subject: [PATCH 2/3] Add es2abc_gen_abc template for framework Add es2abc_gen_abc template to generate abc files for framework Signed-off-by: ctw-ian Change-Id: I4dbe56fcdeb6f98e8dc0ab58266334a3375a071d --- es2panda/es2abc_config.gni | 102 +++++++++++++++++++++++ es2panda/scripts/generate_js_bytecode.py | 72 ++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 es2panda/es2abc_config.gni create mode 100755 es2panda/scripts/generate_js_bytecode.py diff --git a/es2panda/es2abc_config.gni b/es2panda/es2abc_config.gni new file mode 100644 index 00000000000..b785818b306 --- /dev/null +++ b/es2panda/es2abc_config.gni @@ -0,0 +1,102 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(ark_independent_build)) { + import("$build_root/ark.gni") + es2abc_root = "//ts2abc/es2panda" +} else { + import("//build/ohos.gni") + build_root = "//build" + es2abc_root = "//ark/ts2abc/es2panda" +} + + +toolchain_linux = "$build_root/toolchain/linux:clang_x64" +if (host_cpu == "arm64") { + toolchain_mac = "$build_root/toolchain/mac:clang_arm64" +} else { + toolchain_mac = "$build_root/toolchain/mac:clang_x64" +} +toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" + +es2abc_build_path = "" +es2abc_build_deps = "" +es2abc_out_root = "" + +if (host_toolchain == toolchain_mac) { + es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_mac)", + "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ] +} else if (host_toolchain == toolchain_win) { + es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_win)", + "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ] +} else { + es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_linux)", + "root_out_dir") + es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ] +} +es2abc_build_path = es2abc_out_root + "/ark/ark" + +# Generate abc. +# +# Mandatory arguments: +# plugin_path -- plugin js file path +# plugin_name -- name of js file, ex: BatteryPlugin.js +# generat_file -- name of generated file +# package_name -- name of generated file's package +# extra_dependencies -- a list of files that should be considered as dependencies, must be label +# out_puts +template("es2abc_gen_abc") { + assert(defined(invoker.src_js), "src_js is required!") + assert(defined(invoker.dst_file), "dst_file is required!") + assert(defined(invoker.out_puts), "out_puts is required!") + + print("${es2abc_build_path}") + extra_dependencies = [] + if (defined(invoker.extra_dependencies)) { + extra_dependencies += invoker.extra_dependencies + } + + action("$target_name") { + if (defined(invoker.extra_visibility)) { + visibility = invoker.extra_visibility + } + + print() + + script = "${es2abc_root}/scripts/generate_js_bytecode.py" # need to write a new python script + + deps = extra_dependencies + deps += es2abc_build_deps + + args = [ + "--src-js", + invoker.src_js, + "--dst-file", + invoker.dst_file, + "--frontend-tool-path", + rebase_path("${es2abc_build_path}"), + ] + + if (defined(invoker.extra_args)) { + args += invoker.extra_args + } + + if (defined(invoker.in_puts)) { + inputs = invoker.in_puts + } + + outputs = invoker.out_puts + } +} \ No newline at end of file diff --git a/es2panda/scripts/generate_js_bytecode.py b/es2panda/scripts/generate_js_bytecode.py new file mode 100755 index 00000000000..78cebf940d5 --- /dev/null +++ b/es2panda/scripts/generate_js_bytecode.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# coding: utf-8 + +""" +Copyright (c) 2021 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Generate javascript byte code using es2abc +""" + +import os +import subprocess +import platform +import argparse + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--src-js', + help = 'js source file') + parser.add_argument('--dst-file', + help = 'the converted target file') + parser.add_argument('--frontend-tool-path', + help = 'path of the frontend conversion tool') + parser.add_argument("--debug", action='store_true', + help='whether add debuginfo') + parser.add_argument("--module", action='store_true', + help='whether is module') + parser.add_argument("--commonjs", action='store_true', + help='whether is commonjs') + arguments = parser.parse_args() + return arguments + +def run_command(cmd, execution_path): + print(" ".join(cmd) + " | execution_path: " + execution_path) + proc = subprocess.Popen(cmd, cwd=execution_path) + proc.wait() + + +def gen_abc_info(input_arguments): + frontend_tool_path = input_arguments.frontend_tool_path + + (path, name) = os.path.split(frontend_tool_path) + + cmd = [os.path.join("./", name, "es2abc"), + '--output', input_arguments.dst_file, + input_arguments.src_js] + + if input_arguments.debug: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--debug-info') + if input_arguments.module: + src_index = cmd.index(input_arguments.src_js) + cmd.insert(src_index, '--module') + if input_arguments.commonjs: + src_index = cmd.index(input_arguments.src_js) + # insert commonjs option to cmd later + run_command(cmd, path) + + +if __name__ == '__main__': + gen_abc_info(parse_args()) \ No newline at end of file -- Gitee From 292795a7fbb05ec4f1fa2b85b35d852ff8187fba Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Tue, 12 Jul 2022 11:17:37 +0800 Subject: [PATCH 3/3] Declare common toolcahin names for ts2panda and es2panda 1. Declare common toolcahin names for ts2panda and es2panda in ets_frontend_config.gni 2. Fix of gn format and small modification Signed-off-by: ctw-ian Change-Id: I262c405fb9bf36be4aebf51770a16fbe825ac756 --- BUILD.gn | 12 +- bundle.json | 2 +- es2panda/BUILD.gn | 68 +++++------ es2panda/compiler/base/destructuring.cpp | 1 - es2panda/compiler/core/emitter.cpp | 12 +- es2panda/compiler/core/pandagen.cpp | 140 ++++++++++++++--------- es2panda/es2abc_config.gni | 35 ++---- es2panda/scripts/generate_js_bytecode.py | 2 +- ets_frontend_config.gni | 27 +++++ ts2panda/BUILD.gn | 16 +-- ts2panda/tests/BUILD.gn | 4 +- ts2panda/ts2abc_config.gni | 30 ++--- 12 files changed, 198 insertions(+), 151 deletions(-) create mode 100644 ets_frontend_config.gni diff --git a/BUILD.gn b/BUILD.gn index 7bf72fa8da9..98f9ae49d21 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//ark/runtime_core/ark_config.gni") +import("//arkcompiler/runtime_core/ark_config.gni") import("//build/ohos.gni") group("ets_frontend") { - deps = [ - "./ts2panda:ark_ts2abc_build", - "./es2panda:es2panda_build", - ] -} \ No newline at end of file + deps = [ + "./es2panda:es2panda_build", + "./ts2panda:ark_ts2abc_build", + ] +} diff --git a/bundle.json b/bundle.json index 9c1f1915f7b..0b9bb4fba46 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,7 @@ }, "build": { "sub_component": [ - "//ark/ts2abc:ets_frontend" + "//arkcompiler/ets_frontend:ets_frontend" ], "inner_kits": [], "test": [] diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index 5f6431512f2..31eda11e1fb 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -11,7 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//ark/runtime_core/ark_config.gni") +import("//arkcompiler/ets_frontend/ets_frontend_config.gni") +import("//arkcompiler/runtime_core/ark_config.gni") import("//build/ohos.gni") es2panda_src = [ @@ -234,7 +235,7 @@ es2panda_src = [ "typescript/types/voidType.cpp", "util/bitset.cpp", "util/helpers.cpp", - "util/ustring.cpp" + "util/ustring.cpp", ] config("es2abc_config_src") { @@ -258,14 +259,13 @@ config("es2abc_config_src") { "./lexer/token", "./lexer/regexp", "./typescript", - "./typescript/types" + "./typescript/types", ] cflags = [ "-fexceptions" ] } config("es2abc_config_common") { - configs = [ "$ark_root:ark_config", "$sdk_libc_secshared_config", @@ -300,14 +300,18 @@ action_foreach("gen_keywords_headers") { sources += [ rebase_path("${keywords_templates_dir}/${file}") ] } outputs = [ "${generated_header_dir}/{{source_name_part}}" ] - + script = "scripts/gen_keywords.sh" inputs = [ "${keywords_generator}" ] args = [ - "-g", rebase_path("${keywords_generator}"), - "-t", "{{source}}", - "-o", "{{source_name_part}}", - "-d", rebase_path("${generated_header_dir}"), + "-g", + rebase_path("${keywords_generator}"), + "-t", + "{{source}}", + "-o", + "{{source_name_part}}", + "-d", + rebase_path("${generated_header_dir}"), ] } @@ -316,34 +320,39 @@ isa_gen = "${ark_root}/isa/gen.rb" isa_gen_data = "$root_gen_dir/isa/isa.yaml" isa_gen_require = "${ark_root}/isa/isapi.rb" action_foreach("gen_isa_headers") { - - deps = [ "//ark/runtime_core/isa:isa_combine" ] + deps = [ "//arkcompiler/runtime_core/isa:isa_combine" ] template_files = [ "isa.h.erb", "formats.h.erb", ] keywords_templates_dir = "./compiler/templates" - + sources = [] foreach(file, template_files) { sources += [ rebase_path("${keywords_templates_dir}/${file}") ] } outputs = [ "${generated_header_dir}/{{source_name_part}}" ] - + script = "scripts/gen_isa.sh" inputs = [ "${isa_gen}", "${isa_gen_data}", - "${isa_gen_require}" + "${isa_gen_require}", ] args = [ - "-g", rebase_path("${isa_gen}"), - "-t", "{{source}}", - "-a", rebase_path("${isa_gen_data}"), - "-o", "{{source_name_part}}", - "-d", rebase_path("${generated_header_dir}"), - "-r", rebase_path("${isa_gen_require}"), + "-g", + rebase_path("${isa_gen}"), + "-t", + "{{source}}", + "-a", + rebase_path("${isa_gen_data}"), + "-o", + "{{source_name_part}}", + "-d", + rebase_path("${generated_header_dir}"), + "-r", + rebase_path("${isa_gen_require}"), ] } @@ -361,8 +370,8 @@ ohos_static_library("es2panda_lib") { ] deps = [ - ":gen_keywords_headers", ":gen_isa_headers", + ":gen_keywords_headers", "$ark_root/assembler:libarkassembler_frontend_static", "$ark_root/libpandabase:libarkbase_frontend_static", "$ark_root/libpandafile:libarkfile_frontend_static", @@ -370,25 +379,21 @@ ohos_static_library("es2panda_lib") { "//third_party/icu/icu4c:static_icuuc", ] - cflags = [ - "-Wno-implicit-fallthrough", - ] + cflags = [ "-Wno-implicit-fallthrough" ] } ohos_executable("es2panda") { use_exceptions = true sources = [ - "aot/options.cpp", "aot/main.cpp", + "aot/options.cpp", ] include_dirs = [ "./aot" ] configs = [ ":es2abc_config_common" ] - deps = [ - ":es2panda_lib", - ] + deps = [ ":es2panda_lib" ] if (is_linux) { if (build_public_version) { @@ -465,16 +470,15 @@ if (is_mac) { } group("es2panda_build") { - build_tool_linux = "//build/toolchain/linux:clang_x64" if (host_os == "linux") { - deps = [ ":es2panda(${build_tool_linux})" ] + deps = [ ":es2panda(${toolchain_linux})" ] } if (host_os == "mac") { - deps = [ ":es2panda(//build/toolchain/mac:clang_x64)" ] + deps = [ ":es2panda(${toolchain_mac})" ] } } group("es2panda_build_win") { - deps = [ ":es2panda(//build/toolchain/mingw:mingw_x86_64)" ] + deps = [ ":es2panda(${toolchain_win})" ] } diff --git a/es2panda/compiler/base/destructuring.cpp b/es2panda/compiler/base/destructuring.cpp index 5b3ac2e0c14..70d9ef0754d 100644 --- a/es2panda/compiler/base/destructuring.cpp +++ b/es2panda/compiler/base/destructuring.cpp @@ -71,7 +71,6 @@ static void GenRestElement(PandaGen *pg, const ir::SpreadElement *restElement, static void GenArray(PandaGen *pg, const ir::ArrayExpression *array) { - // RegScope rs(pg); DestructuringIterator iterator(pg, array); if (array->Elements().empty()) { diff --git a/es2panda/compiler/core/emitter.cpp b/es2panda/compiler/core/emitter.cpp index c25c579fe24..ac04127360e 100644 --- a/es2panda/compiler/core/emitter.cpp +++ b/es2panda/compiler/core/emitter.cpp @@ -75,7 +75,8 @@ void FunctionEmitter::GenBufferLiterals(const LiteralBuffer *buff) { auto &[idx, array] = literalBuffers_.emplace_back(); idx = buff->Index(); - array.reserve(buff->Literals().size() * 2); + constexpr size_t ARRAY_EXPANSION = 2; + array.reserve(buff->Literals().size() * ARRAY_EXPANSION); for (const auto *literal : buff->Literals()) { panda::pandasm::LiteralArray::Literal valueLit; @@ -119,11 +120,7 @@ void FunctionEmitter::GenBufferLiterals(const LiteralBuffer *buff) valueLit.value_ = literal->GetMethod().Mutf8(); break; } - // case ir::LiteralTag::ASYNC_GENERATOR_METHOD: { - // valueLit.tag_ = panda::panda_file::LiteralTag::ASYNCGENERATORMETHOD; - // valueLit.value_ = literal->GetMethod().Mutf8(); - // break; - // } + // TODO: support ir::LiteralTag::ASYNC_GENERATOR_METHOD case ir::LiteralTag::NULL_VALUE: { valueLit.tag_ = panda::panda_file::LiteralTag::NULLVALUE; valueLit.value_ = static_cast(0); @@ -181,10 +178,11 @@ static size_t GetIRNodeWholeLength(const IRNode *node) } size_t len = 1; + constexpr size_t BIT_WIDTH = 8; const auto format = MatchFormat(node, formats); for (auto fi : format.GetFormatItem()) { - len += fi.Bitwidth() / 8; + len += fi.Bitwidth() / BIT_WIDTH; } return len; diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 5c4ea926691..7cf1bb96f5a 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -784,6 +784,7 @@ void PandaGen::Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs) void PandaGen::BranchIfUndefined(const ir::AstNode *node, Label *target) { + RegScope rs(this); VReg tmp = AllocReg(); StoreAccumulator(node, tmp); sa_.Emit(node); @@ -793,6 +794,7 @@ void PandaGen::BranchIfUndefined(const ir::AstNode *node, Label *target) void PandaGen::BranchIfNotUndefined(const ir::AstNode *node, Label *target) { + RegScope rs(this); VReg tmp = AllocReg(); StoreAccumulator(node, tmp); sa_.Emit(node); @@ -823,8 +825,7 @@ void PandaGen::EmitThrow(const ir::AstNode *node) void PandaGen::EmitRethrow(const ir::AstNode *node) { - // commented for compile workaround - // sa_.Emit(node); + // TODO: rethrow in try-catch } void PandaGen::EmitReturn(const ir::AstNode *node) @@ -939,22 +940,22 @@ void PandaGen::LoadHomeObject(const ir::AstNode *node) void PandaGen::DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name) { - auto formal_param_cnt = FormalParametersCount(); + auto formalParamCnt = FormalParametersCount(); if (realNode->IsAsync()) { if (realNode->IsGenerator()) { // TODO(): async generator } else { - ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); + ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); } } else if (realNode->IsGenerator()) { - ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); + ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); } else if (realNode->IsArrow()) { LoadHomeObject(node); - ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); + ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); } else if (realNode->IsMethod()) { - ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); + ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); } else { - ra_.Emit(node, name, static_cast(formal_param_cnt), LexEnv()); + ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); } strings_.insert(name); @@ -999,9 +1000,11 @@ void PandaGen::ToNumber(const ir::AstNode *node, VReg arg) void PandaGen::GetMethod(const ir::AstNode *node, VReg obj, const util::StringView &name) { - // commented for compile workaround - // ra_.Emit(node, name, obj); - // strings_.insert(name); + /** + * TODO + * ra_.Emit(node, name, obj); + * strings_.insert(name); + */ } void PandaGen::CreateGeneratorObj(const ir::AstNode *node, VReg funcObj) @@ -1011,38 +1014,50 @@ void PandaGen::CreateGeneratorObj(const ir::AstNode *node, VReg funcObj) void PandaGen::CreateAsyncGeneratorObj(const ir::AstNode *node, VReg funcObj) { - // commented for compile workaround - // ra_.Emit(node, funcObj); + /* + * TODO: async generator + * ra_.Emit(node, funcObj); + */ } void PandaGen::CreateIterResultObject(const ir::AstNode *node, bool done) { - // commented for compile workaround - // ra_.Emit(node, static_cast(done)); + /* + * TODO: create iter result + * ra_.Emit(node, static_cast(done)); + */ } void PandaGen::SuspendGenerator(const ir::AstNode *node, VReg genObj) { - // commented for compile workaround - // ra_.Emit(node, genObj); + /* + * TODO: suspend generator + * ra_.Emit(node, genObj); + */ } void PandaGen::SuspendAsyncGenerator(const ir::AstNode *node, VReg asyncGenObj) { - // commented for compile workaround - // ra_.Emit(node, asyncGenObj); + /* + * TODO: suspend async generator + * ra_.Emit(node, asyncGenObj); + */ } void PandaGen::GeneratorYield(const ir::AstNode *node, VReg genObj) { - // commented for compile workaround - // ra_.Emit(node, genObj, static_cast(GeneratorState::SUSPENDED_YIELD)); + /* + * TODO: set generator yield + * ra_.Emit(node, genObj, static_cast(GeneratorState::SUSPENDED_YIELD)); + */ } void PandaGen::GeneratorComplete(const ir::AstNode *node, VReg genObj) { - // commented for compile workaround - // ra_.Emit(node, genObj, static_cast(GeneratorState::COMPLETED)); + /* + * TODO: set generator complete + * ra_.Emit(node, genObj, static_cast(GeneratorState::COMPLETED)); + */ } void PandaGen::ResumeGenerator(const ir::AstNode *node, VReg genObj) @@ -1062,32 +1077,42 @@ void PandaGen::AsyncFunctionEnter(const ir::AstNode *node) void PandaGen::AsyncFunctionAwait(const ir::AstNode *node, VReg asyncFuncObj) { - // commented for compile workaround - // ra_.Emit(node, asyncFuncObj); + /* + * TODO: async function await + * ra_.Emit(node, asyncFuncObj); + */ } void PandaGen::AsyncFunctionResolve(const ir::AstNode *node, VReg asyncFuncObj) { - // commented for compile workaround - // ra_.Emit(node, asyncFuncObj); + /* + * TODO: async function resolve + * ra_.Emit(node, asyncFuncObj); + */ } void PandaGen::AsyncFunctionReject(const ir::AstNode *node, VReg asyncFuncObj) { - // commented for compile workaround - // ra_.Emit(node, asyncFuncObj); + /* + * TODO: async function reject + * ra_.Emit(node, asyncFuncObj); + */ } void PandaGen::AsyncGeneratorResolve(const ir::AstNode *node, VReg asyncGenObj) { - // commented for compile workaround - // ra_.Emit(node, asyncGenObj); + /* + * TODO: async generator resolve + * ra_.Emit(node, asyncGenObj); + */ } void PandaGen::AsyncGeneratorReject(const ir::AstNode *node, VReg asyncGenObj) { - // commented for compile workaround - // ra_.Emit(node, asyncGenObj); + /* + * TODO: async generator reject + * ra_.Emit(node, asyncGenObj); + */ } void PandaGen::GetTemplateObject(const ir::AstNode *node, VReg value) @@ -1259,7 +1284,8 @@ void PandaGen::StoreArraySpread(const ir::AstNode *node, VReg array, VReg index) void PandaGen::ThrowIfNotObject(const ir::AstNode *node) { - // commented for compile workaround + // TODO: implement this method correctly + RegScope rs(this); VReg value = AllocReg(); ra_.Emit(node, value); } @@ -1276,8 +1302,10 @@ void PandaGen::GetIterator(const ir::AstNode *node) void PandaGen::GetAsyncIterator(const ir::AstNode *node) { - // commented for compile workaround - // sa_.Emit(node); + /* + * TODO: async iterator + * sa_.Emit(node); + */ } void PandaGen::CreateObjectWithExcludedKeys(const ir::AstNode *node, VReg obj, VReg argStart, size_t argCount) @@ -1303,24 +1331,28 @@ void PandaGen::CloseIterator(const ir::AstNode *node, VReg iter) void PandaGen::ImportModule(const ir::AstNode *node, const util::StringView &name) { - // commented for compile workaround - // sa_.Emit(node, name); - // strings_.insert(name); + /* + * TODO: module + * sa_.Emit(node, name); + * strings_.insert(name); + */ } void PandaGen::DefineClassWithBuffer(const ir::AstNode *node, const util::StringView &ctorId, int32_t litIdx, VReg lexenv, VReg base) { - auto formal_param_cnt = FormalParametersCount(); - ra_.Emit(node, ctorId, litIdx, static_cast(formal_param_cnt), lexenv, base); + auto formalParamCnt = FormalParametersCount(); + ra_.Emit(node, ctorId, litIdx, static_cast(formalParamCnt), lexenv, base); strings_.insert(ctorId); } void PandaGen::LoadModuleVariable(const ir::AstNode *node, VReg module, const util::StringView &name) { - // commented for compile workaround - // ra_.Emit(node, name, module); - // strings_.insert(name); + /* + * TODO: module + * ra_.Emit(node, name, module); + * strings_.insert(name); + */ } void PandaGen::StoreModuleVar(const ir::AstNode *node, const util::StringView &name) @@ -1408,6 +1440,8 @@ void PandaGen::LoadLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t void PandaGen::StoreLexicalVar(const ir::AstNode *node, uint32_t level, uint32_t slot) { + // TODO: need to reconsider this part + RegScope rs(this); VReg value = AllocReg(); StoreAccumulator(node, value); ra_.Emit(node, level, slot, value); @@ -1420,17 +1454,19 @@ void PandaGen::ThrowIfSuperNotCorrectCall(const ir::AstNode *node, int64_t num) void PandaGen::ThrowUndefinedIfHole(const ir::AstNode *node, const util::StringView &name) { - VReg hole_reg = AllocReg(); - StoreAccumulator(node, hole_reg); + RegScope rs(this); + VReg holeReg = AllocReg(); + StoreAccumulator(node, holeReg); LoadAccumulatorString(node, name); - VReg name_reg = AllocReg(); - StoreAccumulator(node, name_reg); - ra_.Emit(node, hole_reg, name_reg); + VReg nameReg = AllocReg(); + StoreAccumulator(node, nameReg); + ra_.Emit(node, holeReg, nameReg); strings_.insert(name); } void PandaGen::ThrowConstAssignment(const ir::AstNode *node, const util::StringView &name) { + RegScope rs(this); LoadAccumulatorString(node, name); VReg nameReg = AllocReg(); StoreAccumulator(node, nameReg); @@ -1445,8 +1481,10 @@ void PandaGen::PopLexEnv(const ir::AstNode *node) void PandaGen::CopyLexEnv(const ir::AstNode *node) { - // commented for compile workaround - // sa_.Emit(node); + /* + * TODO: copy lexenv + * sa_.Emit(node); + */ } void PandaGen::NewLexEnv(const ir::AstNode *node, uint32_t num) diff --git a/es2panda/es2abc_config.gni b/es2panda/es2abc_config.gni index b785818b306..008466806f5 100644 --- a/es2panda/es2abc_config.gni +++ b/es2panda/es2abc_config.gni @@ -11,39 +11,31 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//arkcompiler/ets_frontend/ets_frontend_config.gni") if (defined(ark_independent_build)) { import("$build_root/ark.gni") - es2abc_root = "//ts2abc/es2panda" + es2abc_root = "//ets_frontend/es2panda" } else { import("//build/ohos.gni") build_root = "//build" - es2abc_root = "//ark/ts2abc/es2panda" + es2abc_root = "//arkcompiler/ets_frontend/es2panda" } - -toolchain_linux = "$build_root/toolchain/linux:clang_x64" -if (host_cpu == "arm64") { - toolchain_mac = "$build_root/toolchain/mac:clang_arm64" -} else { - toolchain_mac = "$build_root/toolchain/mac:clang_x64" -} -toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" - es2abc_build_path = "" es2abc_build_deps = "" es2abc_out_root = "" if (host_toolchain == toolchain_mac) { - es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_mac)", - "root_out_dir") + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_mac)", "root_out_dir") es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_mac)" ] } else if (host_toolchain == toolchain_win) { - es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_win)", - "root_out_dir") + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_win)", "root_out_dir") es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_win)" ] } else { - es2abc_out_root = get_label_info("$es2abc_root:es2panda($toolchain_linux)", - "root_out_dir") + es2abc_out_root = + get_label_info("$es2abc_root:es2panda($toolchain_linux)", "root_out_dir") es2abc_build_deps = [ "$es2abc_root:es2panda($toolchain_linux)" ] } es2abc_build_path = es2abc_out_root + "/ark/ark" @@ -62,10 +54,9 @@ template("es2abc_gen_abc") { assert(defined(invoker.dst_file), "dst_file is required!") assert(defined(invoker.out_puts), "out_puts is required!") - print("${es2abc_build_path}") extra_dependencies = [] if (defined(invoker.extra_dependencies)) { - extra_dependencies += invoker.extra_dependencies + extra_dependencies += invoker.extra_dependencies } action("$target_name") { @@ -73,9 +64,7 @@ template("es2abc_gen_abc") { visibility = invoker.extra_visibility } - print() - - script = "${es2abc_root}/scripts/generate_js_bytecode.py" # need to write a new python script + script = "${es2abc_root}/scripts/generate_js_bytecode.py" deps = extra_dependencies deps += es2abc_build_deps @@ -99,4 +88,4 @@ template("es2abc_gen_abc") { outputs = invoker.out_puts } -} \ No newline at end of file +} diff --git a/es2panda/scripts/generate_js_bytecode.py b/es2panda/scripts/generate_js_bytecode.py index 78cebf940d5..f3afc4dfc80 100755 --- a/es2panda/scripts/generate_js_bytecode.py +++ b/es2panda/scripts/generate_js_bytecode.py @@ -64,7 +64,7 @@ def gen_abc_info(input_arguments): cmd.insert(src_index, '--module') if input_arguments.commonjs: src_index = cmd.index(input_arguments.src_js) - # insert commonjs option to cmd later + # insert commonjs option to cmd later run_command(cmd, path) diff --git a/ets_frontend_config.gni b/ets_frontend_config.gni new file mode 100644 index 00000000000..b4a3c1928a1 --- /dev/null +++ b/ets_frontend_config.gni @@ -0,0 +1,27 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(ark_independent_build)) { + ets_frontend_root = "//ets_frontend" +} else { + build_root = "//build" + ets_frontend_root = "//arkcompiler/ets_frontend" +} + +toolchain_linux = "$build_root/toolchain/linux:clang_x64" +if (host_cpu == "arm64") { + toolchain_mac = "$build_root/toolchain/mac:clang_arm64" +} else { + toolchain_mac = "$build_root/toolchain/mac:clang_x64" +} +toolchain_win = "$build_root/toolchain/mingw:mingw_x86_64" diff --git a/ts2panda/BUILD.gn b/ts2panda/BUILD.gn index b51922857af..815bcb1def6 100755 --- a/ts2panda/BUILD.gn +++ b/ts2panda/BUILD.gn @@ -223,21 +223,21 @@ group("ark_ts2abc_build") { deps = [] if (host_os != "mac") { deps += [ - "${ts2abc_root}:ts2abc_build(${buildtool_linux})", - "${ts2abc_root}:ts2abc_build_ets(${buildtool_linux})", + "${ts2abc_root}:ts2abc_build(${toolchain_linux})", + "${ts2abc_root}:ts2abc_build_ets(${toolchain_linux})", ] } else { deps += [ - "${ts2abc_root}:ts2abc_build_mac(${buildtool_mac})", - "${ts2abc_root}:ts2abc_build_mac_ets(${buildtool_mac})", + "${ts2abc_root}:ts2abc_build_mac(${toolchain_mac})", + "${ts2abc_root}:ts2abc_build_mac_ets(${toolchain_mac})", ] } } group("ark_ts2abc_build_win") { deps = [ - "${ts2abc_root}:ts2abc_build_win(${buildtool_win})", - "${ts2abc_root}:ts2abc_build_win_ets(${buildtool_win})", + "${ts2abc_root}:ts2abc_build_win(${toolchain_win})", + "${ts2abc_root}:ts2abc_build_win_ets(${toolchain_win})", ] } @@ -252,13 +252,13 @@ ohos_copy("copy_ts2abc_tests") { group("ts2abc_unittests") { if (host_os == "linux") { testonly = true - deps = [ "tests:ts2abc_tests(${buildtool_linux})" ] + deps = [ "tests:ts2abc_tests(${toolchain_linux})" ] } } group("ts2abc_type_adapter_unit_tests") { if (host_os == "linux") { testonly = true - deps = [ "${ts2abc_root}/ts2abc/tests/type_adapter_test:ts2abc_type_adapter_unit_tests(${buildtool_linux})" ] + deps = [ "${ts2abc_root}/ts2abc/tests/type_adapter_test:ts2abc_type_adapter_unit_tests(${toolchain_linux})" ] } } diff --git a/ts2panda/tests/BUILD.gn b/ts2panda/tests/BUILD.gn index 8f29fa28037..1da6e41ffb2 100644 --- a/ts2panda/tests/BUILD.gn +++ b/ts2panda/tests/BUILD.gn @@ -28,12 +28,12 @@ action("ts2abc_tests") { rebase_path("${node_modules}"), ] - if (host_toolchain == buildtool_linux) { + if (host_toolchain == toolchain_linux) { args += [ "--platform", "linux", ] - } else if (host_toolchain == buildtool_mac) { + } else if (host_toolchain == toolchain_mac) { args += [ "--platform", "mac", diff --git a/ts2panda/ts2abc_config.gni b/ts2panda/ts2abc_config.gni index 99cc458e35d..01d9002487e 100755 --- a/ts2panda/ts2abc_config.gni +++ b/ts2panda/ts2abc_config.gni @@ -10,7 +10,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import("//arkcompiler/ets_frontend/ets_frontend_config.gni") if (!defined(ark_independent_build)) { import("//build/ohos.gni") import("//build/test.gni") @@ -22,14 +22,6 @@ if (!defined(ark_independent_build)) { } declare_args() { - buildtool_linux = "$build_root/toolchain/linux:clang_x64" - if (host_cpu == "arm64") { - buildtool_mac = "$build_root/toolchain/mac:clang_arm64" - } else { - buildtool_mac = "$build_root/toolchain/mac:clang_x64" - } - buildtool_win = "$build_root/toolchain/mingw:mingw_x86_64" - nodejs_dir = "" node_path = "" node_modules = "" @@ -45,23 +37,23 @@ if (build_public_version) { nodejs_dir = "//prebuilts/ace-toolkit/nodejs" } -if (host_toolchain == buildtool_mac) { - ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_mac($buildtool_mac)" ] +if (host_toolchain == toolchain_mac) { + ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_mac($toolchain_mac)" ] ts2abc_build_path = - get_label_info("$ts2abc_root:ts2abc_build_mac($buildtool_mac)", + get_label_info("$ts2abc_root:ts2abc_build_mac($toolchain_mac)", "root_out_dir") + "/obj/arkcompiler/ets_frontend/ts2panda/build-mac" node_path = "${nodejs_dir}/node-v12.18.4-darwin-x64/bin/" -} else if (host_toolchain == buildtool_win) { - ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_win($buildtool_win)" ] +} else if (host_toolchain == toolchain_win) { + ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build_win($toolchain_win)" ] ts2abc_build_path = - get_label_info("$ts2abc_root:ts2abc_build_win($buildtool_win)", + get_label_info("$ts2abc_root:ts2abc_build_win($toolchain_win)", "root_out_dir") + "/obj/arkcompiler/ets_frontend/ts2panda/build_win" } else { - ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build($buildtool_linux)" ] + ts2abc_build_deps = [ "$ts2abc_root:ts2abc_build($toolchain_linux)" ] ts2abc_build_path = - get_label_info("$ts2abc_root:ts2abc_build($buildtool_linux)", + get_label_info("$ts2abc_root:ts2abc_build($toolchain_linux)", "root_out_dir") + "/obj/arkcompiler/ets_frontend/ts2panda/build" node_path = "${nodejs_dir}/node-v12.18.4-linux-x64/bin/" @@ -221,12 +213,12 @@ template("ts2abc_unittest") { "--gn-build", ] - if (host_toolchain == buildtool_linux) { + if (host_toolchain == toolchain_linux) { args += [ "--platform", "linux", ] - } else if (host_toolchain == buildtool_mac) { + } else if (host_toolchain == toolchain_mac) { args += [ "--platform", "mac", -- Gitee