[lldb][bytecode] Improvements to compiler generated Swift (#189425)
Following feedback from @benrimmington in https://github.com/apple/swift-collections/pull/607, this changes the following: 1. Uses `objectFormat()` compiler conditional instead of `os()` (see "Cross-platform object file format support" in [SE-0492](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0492-section-control.md#cross-platform-object-file-format-support)) 2. Uses a raw identifier for the generated Swift symbol name, instead of an escaped name (see [SE-0451](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0451-escaped-identifiers.md))
This commit is contained in:
parent
67c34294a6
commit
b66d98afb9
@ -295,11 +295,6 @@ class BytecodeSection:
|
||||
builder.emit_uleb(len(bc), "program size")
|
||||
builder.emit_bytes(bc, "program")
|
||||
|
||||
@property
|
||||
def _var_name(self):
|
||||
var_name = re.sub(r"\W", "_", self.type_name)
|
||||
return f"_{var_name}_formatter"
|
||||
|
||||
def write_c(self, output: TextIO) -> None:
|
||||
self.validate()
|
||||
|
||||
@ -322,7 +317,8 @@ class BytecodeSection:
|
||||
"__attribute__((used, section(FORMATTER_SECTION)))",
|
||||
file=output,
|
||||
)
|
||||
print(f"unsigned char {self._var_name}[] =", file=output)
|
||||
var_name = re.sub(r"\W", "_", self.type_name)
|
||||
print(f"unsigned char _{var_name}_formatter[] =", file=output)
|
||||
indent = " "
|
||||
for string, comment in builder.entries:
|
||||
print(f"{indent}// {comment}", file=output)
|
||||
@ -339,7 +335,7 @@ class BytecodeSection:
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
#if swift(>=6.3)
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
|
||||
#if objectFormat(MachO)
|
||||
@section("__DATA_CONST,__lldbformatters")
|
||||
#else
|
||||
@section(".lldbformatters")
|
||||
@ -349,7 +345,7 @@ class BytecodeSection:
|
||||
file=output,
|
||||
)
|
||||
print(
|
||||
f"let {self._var_name}: {builder.type_decl} = (",
|
||||
f"let `{self.type_name} formatter`: {builder.type_decl} = (",
|
||||
file=output,
|
||||
)
|
||||
indent = " "
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
#if swift(>=6.3)
|
||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
|
||||
#if objectFormat(MachO)
|
||||
@section("__DATA_CONST,__lldbformatters")
|
||||
#else
|
||||
@section(".lldbformatters")
|
||||
#endif
|
||||
@used
|
||||
let _RigidArray_formatter: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) = (
|
||||
let `RigidArray formatter`: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) = (
|
||||
// version
|
||||
0x01,
|
||||
// remaining record size
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user