[Swift Export] initial infrastructure for Swift IR
New modules 'sir', 'sir-passes', and 'sir-analysis-api' were added under 'native:swift' for creating and manipulating Swift IR elements. * `sir` contains the implementation of Swift IR. * `sir-analysis-api` contains translation from Analysis API to SIR. * `sir-passses` contains transformation passes. This groundwork will allow to progress with the Swift IR.
This commit is contained in:
committed by
Space Team
parent
d15ee71b6c
commit
cc14f11e2a
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
description = "Infrastructure of transformations over SIR"
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
|
||||
api(project(":native:swift:sir"))
|
||||
|
||||
testImplementation(libs.junit4)
|
||||
testImplementation(projectTests(":compiler:tests-common"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.sir.passes
|
||||
|
||||
import org.jetbrains.kotlin.sir.SirElement
|
||||
|
||||
/**
|
||||
* Swift IR is supposed to be transformed by a series of passes.
|
||||
* This is a base interface that all such passes should implement.
|
||||
*/
|
||||
interface SirPass<out R, in T> {
|
||||
|
||||
/**
|
||||
* Executes the pass over the given [SirElement].
|
||||
*
|
||||
* @param element SIR element to be processed.
|
||||
* @param data Additional data that is required to run the pass.
|
||||
* @return The result of the pass.
|
||||
*/
|
||||
fun run(element: SirElement, data: T): R
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.sir.passes
|
||||
|
||||
import org.jetbrains.kotlin.sir.SirElement
|
||||
import org.jetbrains.sir.passes.SirPass
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SirPassTests {
|
||||
@Test
|
||||
fun smoke() {
|
||||
val elementDescription = "mySirElement"
|
||||
val mySirElement = object : SirElement {
|
||||
override fun toString(): String {
|
||||
return elementDescription
|
||||
}
|
||||
}
|
||||
val myPass = object : SirPass<String, Unit> {
|
||||
override fun run(element: SirElement, data: Unit): String {
|
||||
return element.toString()
|
||||
}
|
||||
}
|
||||
val result = myPass.run(mySirElement, Unit)
|
||||
assertEquals(elementDescription, result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user