Skip to content

Commit

Permalink
Add 'Builtin.mark_uninitialized'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyouko-taiga committed Jun 21, 2024
1 parent f6ee33c commit 5149cb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/FrontEnd/BuiltinFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public struct BuiltinFunction: Hashable {
let p = ParameterType(.let, ^freshVariable())
return .init(inputs: [.init(label: "of", type: ^p)], output: .builtin(.ptr))

case .markUninitialized:
let p = ParameterType(.let, ^freshVariable())
return .init(inputs: [.init(label: nil, type: ^p)], output: .void)

case .llvm(let s):
return s.type
}
Expand All @@ -37,6 +41,11 @@ extension BuiltinFunction {
/// measures may be needed to keep the argument alive during the pointer's use.
case addressOf

/// `Builtin.mark_uninitialized<T>(_ v: sink T) -> Void`
///
/// Marks `v` as being uninitialized.
case markUninitialized

}

}
Expand All @@ -49,6 +58,8 @@ extension BuiltinFunction.Name: CustomStringConvertible {
return n.description
case .addressOf:
return "address(of:)"
case .markUninitialized:
return "mark_uninitialized(_:)"
}
}

Expand All @@ -63,6 +74,8 @@ extension BuiltinFunction {
switch n {
case "address":
self.init(name: .addressOf)
case "mark_uninitialized":
self.init(name: .markUninitialized)
default:
self.init(native: n)
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/IR/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,11 @@ struct Emitter {
case .addressOf:
let source = emitLValue(arguments[0].value)
return insert(module.makeAddressToPointer(source, at: site))!

case .markUninitialized:
let source = emitLValue(arguments[0].value)
insert(module.makeMarkState(source, initialized: false, at: site))
return .void
}
}

Expand Down

0 comments on commit 5149cb8

Please sign in to comment.