# 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("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") import("//arkcompiler/ets_frontend/ets_frontend_config.gni") import("//arkcompiler/runtime_core/ark_config.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/base/optionalChain.cpp", "compiler/core/compileQueue.cpp", "compiler/core/compilerContext.cpp", "compiler/core/compilerImpl.cpp", "compiler/core/dynamicContext.cpp", "compiler/core/emitter/commonjs.cpp", "compiler/core/emitter/emitter.cpp", "compiler/core/emitter/moduleRecordEmitter.cpp", "compiler/core/emitter/typeExtractorEmitter.cpp", "compiler/core/envScope.cpp", "compiler/core/function.cpp", "compiler/core/inlineCache.cpp", "compiler/core/labelTarget.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/tsNamespaceExportDeclaration.cpp", "ir/ts/tsNeverKeyword.cpp", "ir/ts/tsNonNullExpression.cpp", "ir/ts/tsNullKeyword.cpp", "ir/ts/tsNumberKeyword.cpp", "ir/ts/tsObjectKeyword.cpp", "ir/ts/tsOptionalType.cpp", "ir/ts/tsParameterProperty.cpp", "ir/ts/tsParenthesizedType.cpp", "ir/ts/tsPrivateIdentifier.cpp", "ir/ts/tsPropertySignature.cpp", "ir/ts/tsQualifiedName.cpp", "ir/ts/tsRestType.cpp", "ir/ts/tsSignatureDeclaration.cpp", "ir/ts/tsStringKeyword.cpp", "ir/ts/tsSymbolKeyword.cpp", "ir/ts/tsTemplateLiteralType.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/commonjs.cpp", "parser/context/parserContext.cpp", "parser/expressionParser.cpp", "parser/module/sourceTextModuleRecord.cpp", "parser/parserImpl.cpp", "parser/program/program.cpp", "parser/statementParser.cpp", "parser/transformer/transformer.cpp", "typescript/checker.cpp", "typescript/core/binaryLikeExpression.cpp", "typescript/core/destructuringContext.cpp", "typescript/core/function.cpp", "typescript/core/helpers.cpp", "typescript/core/object.cpp", "typescript/core/typeCreation.cpp", "typescript/core/typeElaborationContext.cpp", "typescript/core/typeRelation.cpp", "typescript/core/util.cpp", "typescript/extractor/typeExtractor.cpp", "typescript/extractor/typeRecorder.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/symbolType.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/base64.cpp", "util/bitset.cpp", "util/concurrent.cpp", "util/dumper.cpp", "util/helpers.cpp", "util/patchFix.cpp", "util/moduleHelpers.cpp", "util/symbolTable.cpp", "util/ustring.cpp", "util/workerQueue.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", "./typescript/types/extractor", ] 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/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 = [ "//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}", ] 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 if (is_mac && current_cpu == "arm64") { use_rtti = true } configs = [ ":es2abc_config_common", "../merge_abc:panda_assembly_proto_public_config", ] include_dirs = [ "${target_out_dir}", "//third_party/icu/icu4c/source/common", "//third_party/icu/icu4c/source/i18n", "//third_party/icu/icu4c/source ", ] deps = [ ":gen_isa_headers", ":gen_keywords_headers", "$ark_third_party_root/icu/icu4c:static_icuuc", "../merge_abc:panda_assembly_proto_static", ] external_deps = [] if (!is_cross_platform_build) { external_deps += [ "runtime_core:libarkassembler_frontend_static", "runtime_core:libarkbase_frontend_static", "runtime_core:libarkfile_frontend_static", "runtime_core:libarkziparchive_frontend_static", ] if (enable_bytecode_optimizer) { external_deps += [ "runtime_core:libarkbytecodeopt_frontend_static", "runtime_core:libarkcompiler_frontend_static", ] } } else { deps += [ "$ark_root/assembler:libarkassembler_frontend_static", "$ark_root/libpandabase:libarkbase_frontend_static", "$ark_root/libpandafile:libarkfile_frontend_static", "$ark_root/libziparchive:libarkziparchive_frontend_static", ] if (enable_bytecode_optimizer) { deps += [ "$ark_root/bytecode_optimizer:libarkbytecodeopt_frontend_static", "$ark_root/compiler:libarkcompiler_frontend_static", ] } } cflags = [ "-Wno-c++20-designator", "-Wno-implicit-fallthrough", ] part_name = "ets_frontend" subsystem_name = "arkcompiler" } ohos_executable("es2panda") { use_exceptions = true if (is_mac && current_cpu == "arm64") { use_rtti = true } sources = [ "aot/emitFiles.cpp", "aot/main.cpp", "aot/options.cpp", ] include_dirs = [ "./aot" ] configs = [ ":es2abc_config_common", "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_public_config", ] deps = [ ":es2panda_lib", "//arkcompiler/ets_frontend/merge_abc:panda_assembly_proto_static", ] ldflags = [] if (is_linux) { if (build_public_version) { ldflags += [ "-Wl,-Bstatic" ] ldflags += [ "-lstdc++" ] ldflags += [ "-Wl,-Bdynamic" ] } else { libs = [ libcpp_static_lib ] } } output_name = "es2abc" install_enable = false part_name = "ets_frontend" subsystem_name = "arkcompiler" } if (is_linux) { ohos_copy("es2abc_build") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${target_out_dir}/es2abc-tmp" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc" } ohos_copy("es2abc_build_ets") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc-ets" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc" } } if (is_mingw) { ohos_copy("es2abc_build_win") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc.exe" ] outputs = [ "${target_out_dir}/es2abc-tmp" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc.exe" } ohos_copy("es2abc_build_win_ets") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc.exe" ] outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc-win-ets" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc.exe" } } if (is_mac) { ohos_copy("es2abc_build_mac") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${target_out_dir}/es2abc-tmp" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc" } ohos_copy("es2abc_build_mac_ets") { deps = [ ":es2panda" ] sources = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${root_out_dir}/arkcompiler/ets_frontend/es2abc-mac-ets" ] module_source_dir = "${root_out_dir}/arkcompiler/ets_frontend" module_install_name = "es2abc" } } if (is_linux) { ohos_copy("build_es2abc_for_hap") { deps = [ ":es2panda(${host_toolchain})" ] es2abc_root_out_dir = get_label_info(":es2panda_build($host_toolchain)", "root_out_dir") es2abc_target_out_dir = get_label_info(":es2panda_build($host_toolchain)", "target_out_dir") sources = [ "${es2abc_root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${es2abc_target_out_dir}/build/bin/es2abc" ] } } else if (is_mac) { ohos_copy("build_es2abc_for_hap") { deps = [ ":es2panda(${host_toolchain})" ] es2abc_root_out_dir = get_label_info(":es2panda_build($host_toolchain)", "root_out_dir") es2abc_target_out_dir = get_label_info(":es2panda_build($host_toolchain)", "target_out_dir") sources = [ "${es2abc_root_out_dir}/arkcompiler/ets_frontend/es2abc" ] outputs = [ "${es2abc_target_out_dir}/build-mac/bin/es2abc" ] } } ohos_copy("panda_es2abc") { sources = [ "${es2abc_root}/scripts/ts2abc.js" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name/" module_install_name = "" part_name = "ets_frontend" subsystem_name = "arkcompiler" } ohos_copy("panda_es2abc_ets") { sources = [ "${es2abc_root}/scripts/ts2abc.js" ] outputs = [ target_out_dir + "/$target_name/{{source_file_part}}" ] module_source_dir = target_out_dir + "/$target_name/" module_install_name = "" part_name = "ets_frontend" subsystem_name = "arkcompiler" } ohos_copy("es2abc_js_file") { sources = [ "${es2abc_root}/scripts/ts2abc.js" ] outputs = [ target_out_dir + "/{{source_file_part}}" ] part_name = "ets_frontend" subsystem_name = "arkcompiler" } group("es2panda_build") { if (host_os == "linux") { deps = [ ":es2panda(${toolchain_linux})" ] } if (host_os == "mac") { deps = [ ":es2panda(${toolchain_mac})" ] } } group("es2panda_build_win") { deps = [ ":es2panda(${toolchain_win})" ] } group("es2abc_tests") { deps = [ "./test:es2abc_base64_tests" ] deps += [ "./test:es2abc_compiler_tests" ] deps += [ "./test:es2abc_parser_tests" ] deps += [ "./test:es2abc_parser_tsc_tests" ] deps += [ "./test:es2abc_patch_tests" ] deps += [ "./test:es2abc_bytecode_tests" ] deps += [ "./test:es2abc_type_extractor_tests" ] }