From 602ed42b99b7e049f650bbe26d972d86afe3a64d Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Tue, 15 Dec 2020 17:39:24 +0300 Subject: [PATCH] [Wasm] Move intrinsic generators to generators/wasm Reason: avoid kotlin-stdlib-gen dependency on kotlinStdlib() via wasm.ir --- generators/build.gradle.kts | 4 ++ .../wasm/WasmIntrinsicGenerator.kt | 45 +++++++++++-------- .../stdlib/wasm/src/generated/_WasmArrays.kt | 16 +++++-- .../stdlib/wasm/src/generated/_WasmOp.kt | 16 +++++-- .../tools/kotlin-stdlib-gen/build.gradle | 1 - .../src/generators/GenerateStandardLib.kt | 4 +- 6 files changed, 58 insertions(+), 28 deletions(-) rename libraries/tools/kotlin-stdlib-gen/src/generators/GenerateWasmOps.kt => generators/wasm/WasmIntrinsicGenerator.kt (80%) diff --git a/generators/build.gradle.kts b/generators/build.gradle.kts index 56404acce8e..ac1f859e942 100644 --- a/generators/build.gradle.kts +++ b/generators/build.gradle.kts @@ -24,6 +24,7 @@ fun extraSourceSet(name: String, extendMain: Boolean = true): Pair + val types = listOf( + "Byte", + "Char", + "Short", + "Int", + "Long", + "Float", + "Double" + ) + + types.forEach { primitive -> val isPacked = primitive in setOf( - PrimitiveType.Byte, - PrimitiveType.Short, - PrimitiveType.Char, + "Byte", + "Char", + "Short", ) - val isUnsigned = primitive.isUnsigned() || primitive == PrimitiveType.Char + val isUnsigned = primitive == "Char" writer.appendLine( wasmArrayForType( - primitive.name, + primitive, false, isPacked, isUnsigned ) ) @@ -113,4 +116,10 @@ fun wasmArrayForType( } """.trimIndent() +} + +fun main() { + val targetDir = File("libraries/stdlib/wasm/src/generated") + generateWasmOps(targetDir) + generateWasmArrays(targetDir) } \ No newline at end of file diff --git a/libraries/stdlib/wasm/src/generated/_WasmArrays.kt b/libraries/stdlib/wasm/src/generated/_WasmArrays.kt index b50a47da571..1e1d41b23a7 100644 --- a/libraries/stdlib/wasm/src/generated/_WasmArrays.kt +++ b/libraries/stdlib/wasm/src/generated/_WasmArrays.kt @@ -1,13 +1,23 @@ /* * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + * + * 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. */ package kotlin.wasm.internal // -// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt -// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// NOTE: THIS FILE IS AUTO-GENERATED by the generators/wasm/WasmIntrinsicGenerator.kt // @WasmArrayOf(Any::class, isNullable = true) diff --git a/libraries/stdlib/wasm/src/generated/_WasmOp.kt b/libraries/stdlib/wasm/src/generated/_WasmOp.kt index 36f58dca653..87e2f12b01a 100644 --- a/libraries/stdlib/wasm/src/generated/_WasmOp.kt +++ b/libraries/stdlib/wasm/src/generated/_WasmOp.kt @@ -1,13 +1,23 @@ /* * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + * + * 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. */ package kotlin.wasm.internal // -// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt -// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// NOTE: THIS FILE IS AUTO-GENERATED by the generators/wasm/WasmIntrinsicGenerator.kt // @ExcludedFromCodegen diff --git a/libraries/tools/kotlin-stdlib-gen/build.gradle b/libraries/tools/kotlin-stdlib-gen/build.gradle index c50f3f6dbe9..d1f953ec885 100644 --- a/libraries/tools/kotlin-stdlib-gen/build.gradle +++ b/libraries/tools/kotlin-stdlib-gen/build.gradle @@ -10,7 +10,6 @@ sourceSets { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$bootstrapKotlinVersion" compile "org.jetbrains.kotlin:kotlin-reflect:$bootstrapKotlinVersion" - compile project(":wasm:wasm.ir") } compileKotlin { diff --git a/libraries/tools/kotlin-stdlib-gen/src/generators/GenerateStandardLib.kt b/libraries/tools/kotlin-stdlib-gen/src/generators/GenerateStandardLib.kt index 9d84e3552b5..ea61e30f872 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/generators/GenerateStandardLib.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/generators/GenerateStandardLib.kt @@ -5,8 +5,8 @@ package generators -import java.io.* import templates.* +import java.io.File import kotlin.system.exitProcess /** @@ -71,8 +71,6 @@ fun main(args: Array) { } targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt") } - - targetBaseDirs[KotlinTarget.WASM]?.let { generateWasmBuiltIns(it) } } fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.requireExistingDir() }