Skip to content

Commit 84449cd

Browse files
authored
TSCUtility: deprecate Bitstream interfaces (#351)
The bitstream interfaces were only used by swift-driver. The implementation has been migrated into swift-driver, allowing us to now mark the interfaces as deprecated.
1 parent 008adcb commit 84449cd

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Sources/TSCUtility/Bits.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import Foundation
1212
import TSCBasic
1313

14+
@available(*, deprecated, message: "moved to swift-driver")
1415
struct Bits: RandomAccessCollection {
1516
var buffer: ByteString
1617

Sources/TSCUtility/Bitstream.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import Foundation
1212

1313
/// Represents the contents of a file encoded using the
1414
/// [LLVM bitstream container format](https://llvm.org/docs/BitCodeFormat.html#bitstream-container-format)
15+
@available(*, deprecated, message: "moved to swift-driver")
1516
public struct Bitcode {
1617
public let signature: Signature
1718
public let elements: [BitcodeElement]
1819
public let blockInfo: [UInt64: BlockInfo]
1920
}
2021

2122
/// A non-owning view of a bitcode element.
23+
@available(*, deprecated, message: "moved to swift-driver")
2224
public enum BitcodeElement {
2325
public struct Block {
2426
public var id: UInt64
@@ -47,6 +49,7 @@ public enum BitcodeElement {
4749
case record(Record)
4850
}
4951

52+
@available(*, deprecated, message: "moved to swift-driver")
5053
extension BitcodeElement.Record.Payload: CustomStringConvertible {
5154
public var description: String {
5255
switch self {
@@ -62,12 +65,14 @@ extension BitcodeElement.Record.Payload: CustomStringConvertible {
6265
}
6366
}
6467

68+
@available(*, deprecated, message: "moved to swift-driver")
6569
public struct BlockInfo {
6670
public var name: String = ""
6771
public var recordNames: [UInt64: String] = [:]
6872
}
6973

7074
extension Bitcode {
75+
@available(*, deprecated, message: "moved to swift-driver")
7176
public struct Signature: Equatable {
7277
private var value: UInt32
7378

@@ -88,6 +93,7 @@ extension Bitcode {
8893
}
8994

9095
/// A visitor which receives callbacks while reading a bitstream.
96+
@available(*, deprecated, message: "moved to swift-driver")
9197
public protocol BitstreamVisitor {
9298
/// Customization point to validate a bitstream's signature or "magic number".
9399
func validate(signature: Bitcode.Signature) throws
@@ -101,12 +107,14 @@ public protocol BitstreamVisitor {
101107
}
102108

103109
/// A top-level namespace for all bitstream-related structures.
110+
@available(*, deprecated, message: "moved to swift-driver")
104111
public enum Bitstream {}
105112

106113
extension Bitstream {
107114
/// An `Abbreviation` represents the encoding definition for a user-defined
108115
/// record. An `Abbreviation` is the primary form of compression available in
109116
/// a bitstream file.
117+
@available(*, deprecated, message: "moved to swift-driver")
110118
public struct Abbreviation {
111119
public enum Operand {
112120
/// A literal value (emitted as a VBR8 field).
@@ -174,6 +182,7 @@ extension Bitstream {
174182
/// a name is given to a block or record with `blockName` or
175183
/// `setRecordName`, debugging tools like `llvm-bcanalyzer` can be used to
176184
/// introspect the structure of blocks and records in the bitstream file.
185+
@available(*, deprecated, message: "moved to swift-driver")
177186
public enum BlockInfoCode: UInt8 {
178187
/// Indicates which block ID is being described.
179188
case setBID = 1
@@ -203,6 +212,7 @@ extension Bitstream {
203212
/// static let diagnostics = Self.firstApplicationID + 1
204213
/// }
205214
/// ```
215+
@available(*, deprecated, message: "moved to swift-driver")
206216
public struct BlockID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
207217
public var rawValue: UInt8
208218

@@ -240,6 +250,7 @@ extension Bitstream {
240250
/// abbreviation defined by `BitstreamWriter`. Always use
241251
/// `BitstreamWriter.defineBlockInfoAbbreviation(_:_:)`
242252
/// to register abbreviations.
253+
@available(*, deprecated, message: "moved to swift-driver")
243254
public struct AbbreviationID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
244255
public var rawValue: UInt64
245256

Sources/TSCUtility/BitstreamReader.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import TSCBasic
1414
extension Bitcode {
1515
/// Traverse a bitstream using the specified `visitor`, which will receive
1616
/// callbacks when blocks and records are encountered.
17+
@available(*, deprecated, message: "moved to swift-driver")
1718
public static func read<Visitor: BitstreamVisitor>(bytes: ByteString, using visitor: inout Visitor) throws {
1819
precondition(bytes.count > 4)
1920
var reader = BitstreamReader(buffer: bytes)
@@ -26,10 +27,12 @@ extension Bitcode {
2627
}
2728

2829
private extension Bits.Cursor {
30+
@available(*, deprecated, message: "moved to swift-driver")
2931
enum BitcodeError: Swift.Error {
3032
case vbrOverflow
3133
}
3234

35+
@available(*, deprecated, message: "moved to swift-driver")
3336
mutating func readVBR(_ width: Int) throws -> UInt64 {
3437
precondition(width > 1)
3538
let testBit = UInt64(1 << (width &- 1))
@@ -49,6 +52,7 @@ private extension Bits.Cursor {
4952
}
5053
}
5154

55+
@available(*, deprecated, message: "moved to swift-driver")
5256
private struct BitstreamReader {
5357
enum Error: Swift.Error {
5458
case invalidAbbrev

Sources/TSCUtility/BitstreamWriter.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
///
9191
/// The higher-level APIs will automatically ensure that `BitstreamWriter.data`
9292
/// is valid. Once serialization has completed, simply emit this data to a file.
93+
@available(*, deprecated, message: "moved to swift-driver")
9394
public final class BitstreamWriter {
9495
/// The buffer of data being written to.
9596
private(set) public var data: [UInt8]
@@ -159,6 +160,7 @@ public final class BitstreamWriter {
159160

160161
extension BitstreamWriter {
161162
/// Writes the provided UInt32 to the data stream directly.
163+
@available(*, deprecated, message: "moved to swift-driver")
162164
public func write(_ int: UInt32) {
163165
let index = data.count
164166

@@ -177,6 +179,7 @@ extension BitstreamWriter {
177179
/// - int: The integer containing the bits you'd like to write
178180
/// - width: The number of low-bits of the integer you're writing to the
179181
/// buffer
182+
@available(*, deprecated, message: "moved to swift-driver")
180183
public func writeVBR<IntType>(_ int: IntType, width: UInt8)
181184
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
182185
{
@@ -199,6 +202,7 @@ extension BitstreamWriter {
199202
/// - int: The integer containing the bits you'd like to write
200203
/// - width: The number of low-bits of the integer you're writing to the
201204
/// buffer
205+
@available(*, deprecated, message: "moved to swift-driver")
202206
public func write<IntType>(_ int: IntType, width: UInt8)
203207
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
204208
{
@@ -245,6 +249,7 @@ extension BitstreamWriter {
245249
currentBit = (currentBit + width) & 31
246250
}
247251

252+
@available(*, deprecated, message: "moved to swift-driver")
248253
public func alignIfNeeded() {
249254
guard currentBit > 0 else { return }
250255
write(currentValue)
@@ -254,11 +259,13 @@ extension BitstreamWriter {
254259
}
255260

256261
/// Writes a Bool as a 1-bit integer value.
262+
@available(*, deprecated, message: "moved to swift-driver")
257263
public func write(_ bool: Bool) {
258264
write(bool ? 1 as UInt : 0, width: 1)
259265
}
260266

261267
/// Writes the provided BitCode Abbrev operand to the stream.
268+
@available(*, deprecated, message: "moved to swift-driver")
262269
public func write(_ abbrevOp: Bitstream.Abbreviation.Operand) {
263270
write(abbrevOp.isLiteral) // the Literal bit.
264271
switch abbrevOp {
@@ -288,18 +295,21 @@ extension BitstreamWriter {
288295
}
289296

290297
/// Writes the specified abbreviaion value to the stream, as a 32-bit quantity.
298+
@available(*, deprecated, message: "moved to swift-driver")
291299
public func writeCode(_ code: Bitstream.AbbreviationID) {
292300
writeCode(code.rawValue)
293301
}
294302

295303
/// Writes the specified Code value to the stream, as a 32-bit quantity.
304+
@available(*, deprecated, message: "moved to swift-driver")
296305
public func writeCode<IntType>(_ code: IntType)
297306
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
298307
{
299308
write(code, width: codeBitWidth)
300309
}
301310

302311
/// Writes an ASCII character to the stream, as an 8-bit ascii value.
312+
@available(*, deprecated, message: "moved to swift-driver")
303313
public func writeASCII(_ character: Character) {
304314
precondition(character.unicodeScalars.count == 1, "character is not ASCII")
305315
let c = UInt8(ascii: character.unicodeScalars.first!)
@@ -312,6 +322,7 @@ extension BitstreamWriter {
312322
extension BitstreamWriter {
313323
/// Defines an abbreviation and returns the unique identifier for that
314324
/// abbreviation.
325+
@available(*, deprecated, message: "moved to swift-driver")
315326
public func defineAbbreviation(_ abbrev: Bitstream.Abbreviation) -> Bitstream.AbbreviationID {
316327
encodeAbbreviation(abbrev)
317328
currentAbbreviations.append(abbrev)
@@ -321,6 +332,7 @@ extension BitstreamWriter {
321332
}
322333

323334
/// Encodes the definition of an abbreviation to the stream.
335+
@available(*, deprecated, message: "moved to swift-driver")
324336
private func encodeAbbreviation(_ abbrev: Bitstream.Abbreviation) {
325337
writeCode(.defineAbbreviation)
326338
writeVBR(UInt(abbrev.operands.count), width: 5)
@@ -333,6 +345,7 @@ extension BitstreamWriter {
333345
// MARK: Writing Records
334346

335347
extension BitstreamWriter {
348+
@available(*, deprecated, message: "moved to swift-driver")
336349
public struct RecordBuffer {
337350
private(set) var values = [UInt32]()
338351

@@ -376,6 +389,7 @@ extension BitstreamWriter {
376389
}
377390

378391
/// Writes an unabbreviated record to the stream.
392+
@available(*, deprecated, message: "moved to swift-driver")
379393
public func writeRecord<CodeType>(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void)
380394
where CodeType: RawRepresentable, CodeType.RawValue == UInt8
381395
{
@@ -392,6 +406,7 @@ extension BitstreamWriter {
392406
/// Writes a record with the provided abbreviation ID and record contents.
393407
/// Optionally, emits the provided blob if the abbreviation referenced
394408
/// by that ID requires it.
409+
@available(*, deprecated, message: "moved to swift-driver")
395410
public func writeRecord(
396411
_ abbrevID: Bitstream.AbbreviationID,
397412
_ composeRecord: (inout RecordBuffer) -> Void,
@@ -455,12 +470,14 @@ extension BitstreamWriter {
455470
/// '0' .. '9' --- 52 .. 61
456471
/// '.' --- 62
457472
/// '_' --- 63
473+
@available(*, deprecated, message: "moved to swift-driver")
458474
private static let char6Map =
459475
Array(zip("abcdefghijklmnopqrstuvwxyz" +
460476
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
461477
"0123456789._", (0 as UInt)...))
462478

463479
/// Writes a char6-encoded value.
480+
@available(*, deprecated, message: "moved to swift-driver")
464481
public func writeChar6<IntType>(_ value: IntType)
465482
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
466483
{
@@ -472,6 +489,7 @@ extension BitstreamWriter {
472489
}
473490

474491
/// Writes a value with the provided abbreviation encoding.
492+
@available(*, deprecated, message: "moved to swift-driver")
475493
public func writeAbbrevField(_ op: Bitstream.Abbreviation.Operand, value: UInt32) {
476494
switch op {
477495
case .literal(let literalValue):
@@ -492,6 +510,7 @@ extension BitstreamWriter {
492510

493511
/// Writes a block, beginning with the provided block code and the
494512
/// abbreviation width
513+
@available(*, deprecated, message: "moved to swift-driver")
495514
public func writeBlock(
496515
_ blockID: Bitstream.BlockID,
497516
newAbbrevWidth: UInt8? = nil,
@@ -502,6 +521,7 @@ extension BitstreamWriter {
502521
endBlock()
503522
}
504523

524+
@available(*, deprecated, message: "moved to swift-driver")
505525
public func writeBlob<S>(_ bytes: S, includeSize: Bool = true)
506526
where S: Collection, S.Element == UInt8
507527
{
@@ -527,6 +547,7 @@ extension BitstreamWriter {
527547

528548
/// Writes the blockinfo block and allows emitting abbreviations
529549
/// and records in it.
550+
@available(*, deprecated, message: "moved to swift-driver")
530551
public func writeBlockInfoBlock(emitRecords: () -> Void) {
531552
writeBlock(.blockInfo, newAbbrevWidth: 2) {
532553
currentBlockID = nil
@@ -545,6 +566,7 @@ extension BitstreamWriter {
545566
/// - blockID: The ID of the block to emit.
546567
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
547568
/// - defineSubBlock: A closure that is called to define the contents of the new block.
569+
@available(*, deprecated, message: "moved to swift-driver")
548570
public func withSubBlock(
549571
_ blockID: Bitstream.BlockID,
550572
abbreviationBitWidth: UInt8? = nil,
@@ -566,6 +588,7 @@ extension BitstreamWriter {
566588
/// - Parameters:
567589
/// - blockID: The ID of the block to emit.
568590
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
591+
@available(*, deprecated, message: "moved to swift-driver")
569592
public func enterSubblock(
570593
_ blockID: Bitstream.BlockID,
571594
abbreviationBitWidth: UInt8? = nil
@@ -599,6 +622,7 @@ extension BitstreamWriter {
599622
}
600623

601624
/// Marks the end of a new block record.
625+
@available(*, deprecated, message: "moved to swift-driver")
602626
public func endBlock() {
603627
guard let block = blockScope.popLast() else {
604628
fatalError("endBlock() called with no block registered")
@@ -621,6 +645,7 @@ extension BitstreamWriter {
621645

622646
/// Defines an abbreviation within the blockinfo block for the provided
623647
/// block ID.
648+
@available(*, deprecated, message: "moved to swift-driver")
624649
public func defineBlockInfoAbbreviation(
625650
_ blockID: Bitstream.BlockID,
626651
_ abbrev: Bitstream.Abbreviation
@@ -634,6 +659,7 @@ extension BitstreamWriter {
634659
}
635660

636661

662+
@available(*, deprecated, message: "moved to swift-driver")
637663
private func overwriteBytes(_ int: UInt32, byteIndex: Int) {
638664
let i = int.littleEndian
639665
data.withUnsafeMutableBytes { ptr in
@@ -643,13 +669,15 @@ extension BitstreamWriter {
643669

644670
/// Gets the BlockInfo for the provided ID or creates it if it hasn't been
645671
/// created already.
672+
@available(*, deprecated, message: "moved to swift-driver")
646673
private func getOrCreateBlockInfo(_ id: UInt8) -> BlockInfo {
647674
if let blockInfo = blockInfoRecords[id] { return blockInfo }
648675
let info = BlockInfo()
649676
blockInfoRecords[id] = info
650677
return info
651678
}
652679

680+
@available(*, deprecated, message: "moved to swift-driver")
653681
private func `switch`(to blockID: Bitstream.BlockID) {
654682
if currentBlockID == blockID { return }
655683
writeRecord(Bitstream.BlockInfoCode.setBID) {

0 commit comments

Comments
 (0)