[KLIB] Add API to access file's part of data as ByteArray
It requires for computing fingerprint of IrFile in IC infra
This commit is contained in:
committed by
TeamCityServer
parent
e4c2d4937f
commit
7d8c86caf1
+10
@@ -84,6 +84,16 @@ class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
|
|||||||
override fun file(index: Int): ByteArray = icData[index].fileData
|
override fun file(index: Int): ByteArray = icData[index].fileData
|
||||||
|
|
||||||
override fun fileCount(): Int = icData.size
|
override fun fileCount(): Int = icData.size
|
||||||
|
|
||||||
|
override fun types(fileIndex: Int): ByteArray = icData[fileIndex].types
|
||||||
|
|
||||||
|
override fun signatures(fileIndex: Int): ByteArray = icData[fileIndex].signatures
|
||||||
|
|
||||||
|
override fun strings(fileIndex: Int): ByteArray = icData[fileIndex].strings
|
||||||
|
|
||||||
|
override fun declarations(fileIndex: Int): ByteArray = icData[fileIndex].declarations
|
||||||
|
|
||||||
|
override fun bodies(fileIndex: Int): ByteArray = icData[fileIndex].bodies
|
||||||
}
|
}
|
||||||
|
|
||||||
class CurrentModuleWithICDeserializer(
|
class CurrentModuleWithICDeserializer(
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ interface IrLibrary {
|
|||||||
fun debugInfo(index: Int, fileIndex: Int): ByteArray?
|
fun debugInfo(index: Int, fileIndex: Int): ByteArray?
|
||||||
fun file(index: Int): ByteArray
|
fun file(index: Int): ByteArray
|
||||||
fun fileCount(): Int
|
fun fileCount(): Int
|
||||||
|
|
||||||
|
fun types(fileIndex: Int): ByteArray
|
||||||
|
fun signatures(fileIndex: Int): ByteArray
|
||||||
|
fun strings(fileIndex: Int): ByteArray
|
||||||
|
fun declarations(fileIndex: Int): ByteArray
|
||||||
|
fun bodies(fileIndex: Int): ByteArray
|
||||||
}
|
}
|
||||||
|
|
||||||
val BaseKotlinLibrary.uniqueName: String
|
val BaseKotlinLibrary.uniqueName: String
|
||||||
|
|||||||
@@ -99,12 +99,12 @@ abstract class IrMultiArrayReader(private val buffer: ReadBuffer) {
|
|||||||
fun tableItemBytes(row: Int, column: Int): ByteArray {
|
fun tableItemBytes(row: Int, column: Int): ByteArray {
|
||||||
val rowOffset = indexToOffset[row]
|
val rowOffset = indexToOffset[row]
|
||||||
|
|
||||||
val collumnOffsets = indexIndexToOffset.getOrPut(row) {
|
val columnOffsets = indexIndexToOffset.getOrPut(row) {
|
||||||
readOffsets(rowOffset)
|
readOffsets(rowOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
val dataOffset = collumnOffsets[column]
|
val dataOffset = columnOffsets[column]
|
||||||
val dataSize = collumnOffsets[column + 1] - dataOffset
|
val dataSize = columnOffsets[column + 1] - dataOffset
|
||||||
val result = ByteArray(dataSize)
|
val result = ByteArray(dataSize)
|
||||||
|
|
||||||
buffer.position = rowOffset + dataOffset
|
buffer.position = rowOffset + dataOffset
|
||||||
@@ -155,6 +155,16 @@ abstract class IrMultiTableReader<K>(private val buffer: ReadBuffer, private val
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun tableItemBytes(idx: Int): ByteArray {
|
||||||
|
val rowOffset = indexToOffset[idx]
|
||||||
|
val nextOffset = indexToOffset[idx + 1]
|
||||||
|
val size = nextOffset - rowOffset
|
||||||
|
val result = ByteArray(size)
|
||||||
|
buffer.position = rowOffset
|
||||||
|
buffer.get(result, 0, size)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun tableItemBytes(row: Int, id: K): ByteArray {
|
fun tableItemBytes(row: Int, id: K): ByteArray {
|
||||||
|
|
||||||
val rowOffset = indexToOffset[row]
|
val rowOffset = indexToOffset[row]
|
||||||
|
|||||||
@@ -156,6 +156,26 @@ class IrMonoliticLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) :
|
|||||||
it.irFiles
|
it.irFiles
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun types(fileIndex: Int): ByteArray {
|
||||||
|
return types.tableItemBytes(fileIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun signatures(fileIndex: Int): ByteArray {
|
||||||
|
return signatures.tableItemBytes(fileIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun strings(fileIndex: Int): ByteArray {
|
||||||
|
return strings.tableItemBytes(fileIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun declarations(fileIndex: Int): ByteArray {
|
||||||
|
return combinedDeclarations.tableItemBytes(fileIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bodies(fileIndex: Int): ByteArray {
|
||||||
|
return bodies.tableItemBytes(fileIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : IrLibraryImpl(_access) {
|
class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : IrLibraryImpl(_access) {
|
||||||
@@ -188,13 +208,17 @@ class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : Ir
|
|||||||
return dataReader.tableItemBytes(index)
|
return dataReader.tableItemBytes(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun signature(index: Int, fileIndex: Int): ByteArray {
|
private fun signatureDataReader(fileIndex: Int): IrArrayFileReader {
|
||||||
val dataReader = fileToTypeMap.getOrPut(fileIndex) {
|
return fileToTypeMap.getOrPut(fileIndex) {
|
||||||
val fileDirectory = directories[fileIndex]
|
val fileDirectory = directories[fileIndex]
|
||||||
IrArrayFileReader(access.realFiles {
|
IrArrayFileReader(access.realFiles {
|
||||||
it.irSignatures(fileDirectory)
|
it.irSignatures(fileDirectory)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun signature(index: Int, fileIndex: Int): ByteArray {
|
||||||
|
val dataReader = signatureDataReader(fileIndex)
|
||||||
return dataReader.tableItemBytes(index)
|
return dataReader.tableItemBytes(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +270,26 @@ class IrPerFileLibraryImpl(_access: IrLibraryAccess<IrKotlinLibraryLayout>) : Ir
|
|||||||
override fun fileCount(): Int {
|
override fun fileCount(): Int {
|
||||||
return directories.size
|
return directories.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun types(fileIndex: Int): ByteArray {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun signatures(fileIndex: Int): ByteArray {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun strings(fileIndex: Int): ByteArray {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun declarations(fileIndex: Int): ByteArray {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bodies(fileIndex: Int): ByteArray {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KotlinLibraryImpl(
|
open class KotlinLibraryImpl(
|
||||||
|
|||||||
Reference in New Issue
Block a user