Move 222 compiler modules under cmd/compiler and remove the repeated compiler_ filename prefix. Update file imports, native symbol bindings, build rules, bootstrap metadata and seeds, retained fixtures and docs. Document the existing shared lowering pipeline and measured source-size baseline, with feature-preserving sharing priorities and separate speed acceptance criteria. No performance improvement is claimed for the move. Local tests: all 272 retained make check cases (0 reused); bootstrap update and independent make check-bootstrap reproduce all 95 roots at stage 2.
75 lines
3.2 KiB
Ziran
75 lines
3.2 KiB
Ziran
#import "native_test"
|
|
#import "check_support"
|
|
#import "std/byte_text_linux"
|
|
#import "std/json_document"
|
|
#import "std/text_tools"
|
|
using Vectors :: #import "std/vec"
|
|
|
|
BinaryIRHeader :: (test: *NativeTest, data: string) -> bool {
|
|
if !NativeAssert(test, data.count >= 8 && data[:4] == "ZIR\x00", "saved IR header is missing") { return false }
|
|
codec := NativeRead(test, CheckPath(test.repo, "cmd/compiler/ir/ir_serial.zi"))
|
|
lines := TextLines(codec)
|
|
prefix := "ZIR_FORMAT_VERSION :: "
|
|
version: s64 = -1
|
|
for line: lines {
|
|
if !TextHasPrefix(line, prefix) { continue }
|
|
document: JsonDocument
|
|
if !NativeAssert(test, version < 0 && JsonRead(*document, line[prefix.count:]), "duplicate or invalid IR format version") { return false }
|
|
value, valid := JsonInteger(*document, document.root)
|
|
if !NativeAssert(test, valid && value >= 0 && value <= 4294967295, "IR version is out of range") { return false }
|
|
version = value
|
|
}
|
|
if !NativeAssert(test, version >= 0, "IR format version declaration is missing") { return false }
|
|
for index: cast(s64)0..3 {
|
|
expected := cast(u8)(cast(u64)version >> cast(u64)(index * 8))
|
|
if !NativeAssert(test, data[4 + index] == expected, "saved IR version differs from serializer") { return false }
|
|
}
|
|
return !test.failed
|
|
}
|
|
|
|
BinaryOccurrences :: (data: string, pattern: string) -> s64 {
|
|
if pattern.count == 0 { return 0 }
|
|
count: s64; at: s64
|
|
while at <= data.count {
|
|
found := TextFind(data, pattern, at)
|
|
if found < 0 { break }; count += 1; at = found + pattern.count
|
|
}
|
|
return count
|
|
}
|
|
|
|
BinaryReplaceAt :: (test: *NativeTest, data: string, at: s64, count: s64, replacement: string) -> string {
|
|
if !NativeAssert(test, at >= 0 && count >= 0 && at <= data.count && count <= data.count - at, "binary mutation leaves its input") { return "" }
|
|
parts := string.[data[:at], replacement, data[at + count:]]
|
|
return TextDetach(TextJoin(parts[:], ""))
|
|
}
|
|
|
|
BinaryNumber :: (value: u64) -> string {
|
|
bytes: Vec(u8); remaining := value
|
|
while remaining >= 128 { VecPush(bytes, cast(u8)(remaining & cast(u64)127) | cast(u8)128); remaining >>= cast(u64)7 }
|
|
VecPush(bytes, cast(u8)remaining)
|
|
return TextDetach(BuilderFinish(bytes))
|
|
}
|
|
|
|
BinaryString :: (text: string) -> string { return CheckConcat(BinaryNumber(cast(u64)text.count * cast(u64)2), text) }
|
|
|
|
BinaryReadNumber :: (test: *NativeTest, data: string, start: s64) -> (value: u64, after: s64) {
|
|
value: u64; at := start; shift: u64
|
|
while at >= 0 && at < data.count && shift < 64 {
|
|
byte := data[at]; at += 1
|
|
if shift == 63 && byte > 1 { break }
|
|
value |= cast(u64)(byte & cast(u8)127) << shift
|
|
if byte < 128 { return value, at }; shift += 7
|
|
}
|
|
unused NativeAssert(test, false, "invalid binary variable-length number")
|
|
return cast(u64)0, -1
|
|
}
|
|
|
|
BinarySkipString :: (test: *NativeTest, data: string, start: s64) -> s64 {
|
|
tag, after := BinaryReadNumber(test, data, start)
|
|
if test.failed { return -1 }
|
|
if (tag & cast(u64)1) != 0 { return after }
|
|
length := tag >> cast(u64)1
|
|
if !NativeAssert(test, length <= cast(u64)(data.count - after), "binary string leaves its input") { return -1 }
|
|
return after + cast(s64)length
|
|
}
|