Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
///
|
|
|
|
|
/// Functionality for reading/writing elements (geometry, text labels,
|
|
|
|
|
/// structure references) and associated properties.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
use crate::records::{
|
|
|
|
|
DATATYPE, PATHTYPE, BOXTYPE, NODETYPE, TEXTTYPE,
|
|
|
|
|
LAYER, XY, WIDTH, COLROW, PRESENTATION, STRING,
|
|
|
|
|
STRANS, MAG, ANGLE, PROPATTR, PROPVALUE,
|
|
|
|
|
ENDEL, BGNEXTN, ENDEXTN, SNAME,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::records;
|
|
|
|
|
use crate::record::{RecordHeader, Record};
|
2026-11-16 21:28:54 -08:00
|
|
|
use crate::basic::{IResult, decode_utf8, fail, take_bytes};
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
|
|
|
|
|
use std::string::String;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use arrow_array::builder::{
|
|
|
|
|
StructBuilder, FixedSizeListBuilder, ListBuilder, StringBuilder, ArrayBuilder, BooleanBuilder,
|
|
|
|
|
Int32Builder, Int16Builder, UInt64Builder, UInt32Builder, UInt8Builder, Float64Builder,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
pub(crate) type DListBuilder = ListBuilder<Box<dyn ArrayBuilder>>;
|
|
|
|
|
pub(crate) type FListBuilder = FixedSizeListBuilder<Box<dyn ArrayBuilder>>;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
|
|
|
|
|
struct PropertyRecord {
|
|
|
|
|
key: i16,
|
|
|
|
|
value: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct BoundaryRecord {
|
|
|
|
|
layer_id: u32,
|
|
|
|
|
vertices: Vec<i32>,
|
|
|
|
|
properties: Vec<PropertyRecord>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct BoundaryBatchRecord {
|
|
|
|
|
layer_id: u32,
|
|
|
|
|
vertices: Vec<i32>,
|
|
|
|
|
vertex_offsets: Vec<u32>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct RectBatchRecord {
|
|
|
|
|
layer_id: u32,
|
|
|
|
|
rects: Vec<i32>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct SRefRecord {
|
|
|
|
|
target_id: u32,
|
|
|
|
|
invert_y: bool,
|
|
|
|
|
scale: f64,
|
|
|
|
|
angle_rad: f64,
|
|
|
|
|
xy: u64,
|
|
|
|
|
properties: Vec<PropertyRecord>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ARefRecord {
|
|
|
|
|
target_id: u32,
|
|
|
|
|
invert_y: bool,
|
|
|
|
|
scale: f64,
|
|
|
|
|
angle_rad: f64,
|
|
|
|
|
xy: u64,
|
|
|
|
|
xy0: u64,
|
|
|
|
|
xy1: u64,
|
|
|
|
|
counts: u32,
|
|
|
|
|
properties: Vec<PropertyRecord>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2026-11-16 20:44:48 -08:00
|
|
|
pub(crate) struct ScanRefRecord {
|
|
|
|
|
pub(crate) target_id: u32,
|
|
|
|
|
pub(crate) invert_y: bool,
|
|
|
|
|
pub(crate) scale: f64,
|
|
|
|
|
pub(crate) angle_rad: f64,
|
|
|
|
|
pub(crate) xy: u64,
|
|
|
|
|
pub(crate) xy0: u64,
|
|
|
|
|
pub(crate) xy1: u64,
|
|
|
|
|
pub(crate) counts: u32,
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum RefRecord {
|
|
|
|
|
SRef(SRefRecord),
|
|
|
|
|
ARef(ARefRecord),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const UNIT_COUNTS: u32 = (1_u32 << 16) | 1_u32;
|
|
|
|
|
const ZERO_XY: u64 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn layer_id_for(
|
|
|
|
|
layer: i16,
|
|
|
|
|
dtype: i16,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> u32 {
|
|
|
|
|
let layer32 = ((layer as u16 as u32) << 16) | (dtype as u16 as u32);
|
|
|
|
|
let next_id = layers.len();
|
|
|
|
|
*layers.entry(layer32).or_insert(next_id.try_into().unwrap())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn insert_layer(
|
|
|
|
|
layer: i16,
|
|
|
|
|
dtype: i16,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
struct_builder: &mut StructBuilder,
|
|
|
|
|
field_index: usize,
|
|
|
|
|
) {
|
|
|
|
|
let id = layer_id_for(layer, dtype, layers);
|
|
|
|
|
let layer_builder = struct_builder.field_builder::<UInt32Builder>(field_index).unwrap();
|
|
|
|
|
layer_builder.append_value(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
pub(crate) fn read_elements<'a>(
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
input: &'a [u8],
|
|
|
|
|
cell_builder: &mut StructBuilder,
|
|
|
|
|
names: &mut HashMap<String, u32>,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let mut input = input;
|
|
|
|
|
let mut boundaries = Vec::<BoundaryRecord>::new();
|
|
|
|
|
let mut srefs = Vec::<SRefRecord>::new();
|
|
|
|
|
let mut arefs = Vec::<ARefRecord>::new();
|
|
|
|
|
let (_, mut header) = RecordHeader::read(input)?; // don't consume tag
|
|
|
|
|
while header.tag != records::RTAG_ENDSTR {
|
|
|
|
|
(input, _) = match header.tag {
|
|
|
|
|
records::RTAG_SREF | records::RTAG_AREF => {
|
|
|
|
|
let (next_input, ref_record) = read_ref(input, header.tag, names)?;
|
|
|
|
|
match ref_record {
|
|
|
|
|
RefRecord::SRef(sref) => srefs.push(sref),
|
|
|
|
|
RefRecord::ARef(aref) => arefs.push(aref),
|
|
|
|
|
}
|
|
|
|
|
(next_input, ())
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_BOUNDARY => {
|
|
|
|
|
let (next_input, boundary) = read_boundary(input, layers)?;
|
|
|
|
|
boundaries.push(boundary);
|
|
|
|
|
(next_input, ())
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_PATH => read_path(input, cell_builder, layers)?,
|
|
|
|
|
records::RTAG_NODE => read_boxnode(input, cell_builder, header.tag, layers)?,
|
|
|
|
|
records::RTAG_BOX => read_boxnode(input, cell_builder, header.tag, layers)?,
|
|
|
|
|
records::RTAG_TEXT => read_text(input, cell_builder, layers)?,
|
|
|
|
|
_ => {
|
|
|
|
|
// don't care, skip
|
|
|
|
|
let result = take_bytes(input, header.data_size + 4)?;
|
|
|
|
|
(result.0, ())
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(_, header) = RecordHeader::read(input)?; // don't consume tag
|
|
|
|
|
}
|
|
|
|
|
(input, _) = take_bytes(input, 4_usize)?; // consume endstr tag
|
|
|
|
|
|
|
|
|
|
let mut sref_plain = Vec::<SRefRecord>::with_capacity(srefs.len() + arefs.len() / 4);
|
|
|
|
|
let mut sref_props = Vec::<SRefRecord>::with_capacity(srefs.len() / 16 + arefs.len() / 64);
|
|
|
|
|
for sref in srefs {
|
|
|
|
|
if sref.properties.is_empty() {
|
|
|
|
|
sref_plain.push(sref);
|
|
|
|
|
} else {
|
|
|
|
|
sref_props.push(sref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut aref_plain = Vec::<ARefRecord>::with_capacity(arefs.len());
|
|
|
|
|
let mut aref_props = Vec::<ARefRecord>::with_capacity(arefs.len() / 16);
|
|
|
|
|
for aref in arefs {
|
|
|
|
|
if aref.counts == UNIT_COUNTS {
|
|
|
|
|
let sref = aref_to_sref(aref);
|
|
|
|
|
if sref.properties.is_empty() {
|
|
|
|
|
sref_plain.push(sref);
|
|
|
|
|
} else {
|
|
|
|
|
sref_props.push(sref);
|
|
|
|
|
}
|
|
|
|
|
} else if aref.properties.is_empty() {
|
|
|
|
|
aref_plain.push(aref);
|
|
|
|
|
} else {
|
|
|
|
|
aref_props.push(aref);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sref_plain.sort_by_key(|sref| sref.target_id);
|
|
|
|
|
aref_plain.sort_by_key(|aref| aref.target_id);
|
|
|
|
|
|
|
|
|
|
let mut boundary_plain = Vec::<BoundaryRecord>::with_capacity(boundaries.len());
|
|
|
|
|
let mut boundary_props = Vec::<BoundaryRecord>::with_capacity(boundaries.len() / 16);
|
|
|
|
|
for boundary in boundaries {
|
|
|
|
|
if boundary.properties.is_empty() {
|
|
|
|
|
boundary_plain.push(boundary);
|
|
|
|
|
} else {
|
|
|
|
|
boundary_props.push(boundary);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
boundary_plain.sort_by_key(|boundary| boundary.layer_id);
|
|
|
|
|
|
|
|
|
|
let mut rect_batches = Vec::<RectBatchRecord>::new();
|
|
|
|
|
let mut boundary_batches = Vec::<BoundaryBatchRecord>::new();
|
|
|
|
|
let mut ii = 0;
|
|
|
|
|
while ii < boundary_plain.len() {
|
|
|
|
|
let start = ii;
|
|
|
|
|
let layer_id = boundary_plain[ii].layer_id;
|
|
|
|
|
while ii < boundary_plain.len() && boundary_plain[ii].layer_id == layer_id {
|
|
|
|
|
ii += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let group = &boundary_plain[start..ii];
|
|
|
|
|
let rect_capacity = group.len() * 4;
|
|
|
|
|
let vertex_capacity = group.iter().map(|boundary| boundary.vertices.len()).sum();
|
|
|
|
|
let mut rect_batch = RectBatchRecord {
|
|
|
|
|
layer_id,
|
|
|
|
|
rects: Vec::with_capacity(rect_capacity),
|
|
|
|
|
};
|
|
|
|
|
let mut boundary_batch = BoundaryBatchRecord {
|
|
|
|
|
layer_id,
|
|
|
|
|
vertices: Vec::with_capacity(vertex_capacity),
|
|
|
|
|
vertex_offsets: Vec::with_capacity(group.len()),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut next_offset: u32 = 0;
|
|
|
|
|
for boundary in group {
|
|
|
|
|
if let Some(rect) = boundary_to_rect(&boundary.vertices) {
|
|
|
|
|
rect_batch.rects.extend_from_slice(&rect);
|
|
|
|
|
} else {
|
|
|
|
|
boundary_batch.vertex_offsets.push(next_offset);
|
|
|
|
|
boundary_batch.vertices.extend_from_slice(&boundary.vertices);
|
|
|
|
|
next_offset += (boundary.vertices.len() / 2) as u32;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !rect_batch.rects.is_empty() {
|
|
|
|
|
rect_batches.push(rect_batch);
|
|
|
|
|
}
|
|
|
|
|
if !boundary_batch.vertex_offsets.is_empty() {
|
|
|
|
|
boundary_batches.push(boundary_batch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let sref_builder = cell_builder.field_builder::<DListBuilder>(2).unwrap();
|
|
|
|
|
for sref in sref_plain {
|
|
|
|
|
append_sref(sref_builder, sref);
|
|
|
|
|
}
|
|
|
|
|
sref_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let aref_builder = cell_builder.field_builder::<DListBuilder>(3).unwrap();
|
|
|
|
|
for aref in aref_plain {
|
|
|
|
|
append_aref(aref_builder, aref);
|
|
|
|
|
}
|
|
|
|
|
aref_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let sref_props_builder = cell_builder.field_builder::<DListBuilder>(4).unwrap();
|
|
|
|
|
for sref in sref_props {
|
|
|
|
|
append_sref_prop(sref_props_builder, sref);
|
|
|
|
|
}
|
|
|
|
|
sref_props_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let aref_props_builder = cell_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
for aref in aref_props {
|
|
|
|
|
append_aref_prop(aref_props_builder, aref);
|
|
|
|
|
}
|
|
|
|
|
aref_props_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let rect_batches_builder = cell_builder.field_builder::<DListBuilder>(6).unwrap();
|
|
|
|
|
for rect_batch in rect_batches {
|
|
|
|
|
append_rect_batch(rect_batches_builder, rect_batch);
|
|
|
|
|
}
|
|
|
|
|
rect_batches_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let boundary_batches_builder = cell_builder.field_builder::<DListBuilder>(7).unwrap();
|
|
|
|
|
for boundary_batch in boundary_batches {
|
|
|
|
|
append_boundary_batch(boundary_batches_builder, boundary_batch);
|
|
|
|
|
}
|
|
|
|
|
boundary_batches_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let boundary_props_builder = cell_builder.field_builder::<DListBuilder>(8).unwrap();
|
|
|
|
|
for boundary in boundary_props {
|
|
|
|
|
append_boundary_prop(boundary_props_builder, boundary);
|
|
|
|
|
}
|
|
|
|
|
boundary_props_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let paths_builder = cell_builder.field_builder::<DListBuilder>(9).unwrap();
|
|
|
|
|
paths_builder.append(true);
|
|
|
|
|
let nodes_builder = cell_builder.field_builder::<DListBuilder>(10).unwrap();
|
|
|
|
|
nodes_builder.append(true);
|
|
|
|
|
let boxes_builder = cell_builder.field_builder::<DListBuilder>(11).unwrap();
|
|
|
|
|
boxes_builder.append(true);
|
|
|
|
|
let texts_builder = cell_builder.field_builder::<DListBuilder>(12).unwrap();
|
|
|
|
|
texts_builder.append(true);
|
|
|
|
|
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
pub(crate) fn scan_elements<'a>(
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
input: &'a [u8],
|
|
|
|
|
names: &mut HashMap<String, u32>,
|
|
|
|
|
) -> IResult<'a, Vec<ScanRefRecord>> {
|
|
|
|
|
let mut input = input;
|
|
|
|
|
let mut refs = Vec::<ScanRefRecord>::new();
|
|
|
|
|
let (_, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != records::RTAG_ENDSTR {
|
|
|
|
|
(input, _) = match header.tag {
|
|
|
|
|
records::RTAG_SREF | records::RTAG_AREF => {
|
|
|
|
|
let (next_input, ref_record) = read_ref(input, header.tag, names)?;
|
|
|
|
|
refs.push(scan_ref_from_record(ref_record));
|
|
|
|
|
(next_input, ())
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_BOUNDARY
|
|
|
|
|
| records::RTAG_PATH
|
|
|
|
|
| records::RTAG_NODE
|
|
|
|
|
| records::RTAG_BOX
|
|
|
|
|
| records::RTAG_TEXT => skip_element(input)?,
|
|
|
|
|
_ => {
|
|
|
|
|
let result = take_bytes(input, header.data_size + 4)?;
|
|
|
|
|
(result.0, ())
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(_, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
refs.sort_by_key(|scan_ref| scan_ref.target_id);
|
|
|
|
|
(input, _) = take_bytes(input, 4_usize)?;
|
|
|
|
|
Ok((input, refs))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_sref(
|
|
|
|
|
sref_builder: &mut DListBuilder,
|
|
|
|
|
sref: SRefRecord,
|
|
|
|
|
) {
|
|
|
|
|
let sref_struct_builder = sref_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let target_builder = sref_struct_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
target_builder.append_value(sref.target_id);
|
|
|
|
|
let invert_builder = sref_struct_builder.field_builder::<BooleanBuilder>(1).unwrap();
|
|
|
|
|
invert_builder.append_value(sref.invert_y);
|
|
|
|
|
let scale_builder = sref_struct_builder.field_builder::<Float64Builder>(2).unwrap();
|
|
|
|
|
scale_builder.append_value(sref.scale);
|
|
|
|
|
let angle_builder = sref_struct_builder.field_builder::<Float64Builder>(3).unwrap();
|
|
|
|
|
angle_builder.append_value(sref.angle_rad);
|
|
|
|
|
let xy_builder = sref_struct_builder.field_builder::<UInt64Builder>(4).unwrap();
|
|
|
|
|
xy_builder.append_value(sref.xy);
|
|
|
|
|
|
|
|
|
|
sref_struct_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn scan_ref_from_record(ref_record: RefRecord) -> ScanRefRecord {
|
|
|
|
|
match ref_record {
|
|
|
|
|
RefRecord::SRef(sref) => ScanRefRecord {
|
|
|
|
|
target_id: sref.target_id,
|
|
|
|
|
invert_y: sref.invert_y,
|
|
|
|
|
scale: sref.scale,
|
|
|
|
|
angle_rad: sref.angle_rad,
|
|
|
|
|
xy: sref.xy,
|
|
|
|
|
xy0: ZERO_XY,
|
|
|
|
|
xy1: ZERO_XY,
|
|
|
|
|
counts: UNIT_COUNTS,
|
|
|
|
|
},
|
|
|
|
|
RefRecord::ARef(aref) => ScanRefRecord {
|
|
|
|
|
target_id: aref.target_id,
|
|
|
|
|
invert_y: aref.invert_y,
|
|
|
|
|
scale: aref.scale,
|
|
|
|
|
angle_rad: aref.angle_rad,
|
|
|
|
|
xy: aref.xy,
|
|
|
|
|
xy0: aref.xy0,
|
|
|
|
|
xy1: aref.xy1,
|
|
|
|
|
counts: aref.counts,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn skip_element<'a>(input: &'a [u8]) -> IResult<'a, ()> {
|
|
|
|
|
let mut input = input;
|
|
|
|
|
loop {
|
|
|
|
|
let (next_input, header) = RecordHeader::read(input)?;
|
|
|
|
|
let (next_input, _) = take_bytes(next_input, header.data_size)?;
|
|
|
|
|
input = next_input;
|
|
|
|
|
if header.tag == ENDEL::tag() {
|
|
|
|
|
return Ok((input, ()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_aref(
|
|
|
|
|
aref_builder: &mut DListBuilder,
|
|
|
|
|
aref: ARefRecord,
|
|
|
|
|
) {
|
|
|
|
|
let aref_struct_builder = aref_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let target_builder = aref_struct_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
target_builder.append_value(aref.target_id);
|
|
|
|
|
let invert_builder = aref_struct_builder.field_builder::<BooleanBuilder>(1).unwrap();
|
|
|
|
|
invert_builder.append_value(aref.invert_y);
|
|
|
|
|
let scale_builder = aref_struct_builder.field_builder::<Float64Builder>(2).unwrap();
|
|
|
|
|
scale_builder.append_value(aref.scale);
|
|
|
|
|
let angle_builder = aref_struct_builder.field_builder::<Float64Builder>(3).unwrap();
|
|
|
|
|
angle_builder.append_value(aref.angle_rad);
|
|
|
|
|
let xy_builder = aref_struct_builder.field_builder::<UInt64Builder>(4).unwrap();
|
|
|
|
|
xy_builder.append_value(aref.xy);
|
|
|
|
|
let xy0_builder = aref_struct_builder.field_builder::<UInt64Builder>(5).unwrap();
|
|
|
|
|
xy0_builder.append_value(aref.xy0);
|
|
|
|
|
let xy1_builder = aref_struct_builder.field_builder::<UInt64Builder>(6).unwrap();
|
|
|
|
|
xy1_builder.append_value(aref.xy1);
|
|
|
|
|
let counts_builder = aref_struct_builder.field_builder::<UInt32Builder>(7).unwrap();
|
|
|
|
|
counts_builder.append_value(aref.counts);
|
|
|
|
|
|
|
|
|
|
aref_struct_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_property(props_builder: &mut DListBuilder, property: PropertyRecord) {
|
|
|
|
|
let prop_builder = props_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
let key_builder = prop_builder.field_builder::<Int16Builder>(0).unwrap();
|
|
|
|
|
key_builder.append_value(property.key);
|
|
|
|
|
|
|
|
|
|
let val_builder = prop_builder.field_builder::<StringBuilder>(1).unwrap();
|
|
|
|
|
val_builder.append_value(property.value);
|
|
|
|
|
|
|
|
|
|
prop_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_properties(
|
|
|
|
|
props_builder: &mut DListBuilder,
|
|
|
|
|
properties: Vec<PropertyRecord>,
|
|
|
|
|
) {
|
|
|
|
|
for prop in properties {
|
|
|
|
|
append_property(props_builder, prop);
|
|
|
|
|
}
|
|
|
|
|
props_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_sref_prop(
|
|
|
|
|
sref_props_builder: &mut DListBuilder,
|
|
|
|
|
sref: SRefRecord,
|
|
|
|
|
) {
|
|
|
|
|
let sref_prop_builder = sref_props_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let target_builder = sref_prop_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
target_builder.append_value(sref.target_id);
|
|
|
|
|
let invert_builder = sref_prop_builder.field_builder::<BooleanBuilder>(1).unwrap();
|
|
|
|
|
invert_builder.append_value(sref.invert_y);
|
|
|
|
|
let scale_builder = sref_prop_builder.field_builder::<Float64Builder>(2).unwrap();
|
|
|
|
|
scale_builder.append_value(sref.scale);
|
|
|
|
|
let angle_builder = sref_prop_builder.field_builder::<Float64Builder>(3).unwrap();
|
|
|
|
|
angle_builder.append_value(sref.angle_rad);
|
|
|
|
|
let xy_builder = sref_prop_builder.field_builder::<UInt64Builder>(4).unwrap();
|
|
|
|
|
xy_builder.append_value(sref.xy);
|
|
|
|
|
|
|
|
|
|
let props_builder = sref_prop_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
append_properties(props_builder, sref.properties);
|
|
|
|
|
|
|
|
|
|
sref_prop_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_aref_prop(
|
|
|
|
|
aref_props_builder: &mut DListBuilder,
|
|
|
|
|
aref: ARefRecord,
|
|
|
|
|
) {
|
|
|
|
|
let aref_prop_builder = aref_props_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let target_builder = aref_prop_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
target_builder.append_value(aref.target_id);
|
|
|
|
|
let invert_builder = aref_prop_builder.field_builder::<BooleanBuilder>(1).unwrap();
|
|
|
|
|
invert_builder.append_value(aref.invert_y);
|
|
|
|
|
let scale_builder = aref_prop_builder.field_builder::<Float64Builder>(2).unwrap();
|
|
|
|
|
scale_builder.append_value(aref.scale);
|
|
|
|
|
let angle_builder = aref_prop_builder.field_builder::<Float64Builder>(3).unwrap();
|
|
|
|
|
angle_builder.append_value(aref.angle_rad);
|
|
|
|
|
let xy_builder = aref_prop_builder.field_builder::<UInt64Builder>(4).unwrap();
|
|
|
|
|
xy_builder.append_value(aref.xy);
|
|
|
|
|
let xy0_builder = aref_prop_builder.field_builder::<UInt64Builder>(5).unwrap();
|
|
|
|
|
xy0_builder.append_value(aref.xy0);
|
|
|
|
|
let xy1_builder = aref_prop_builder.field_builder::<UInt64Builder>(6).unwrap();
|
|
|
|
|
xy1_builder.append_value(aref.xy1);
|
|
|
|
|
let counts_builder = aref_prop_builder.field_builder::<UInt32Builder>(7).unwrap();
|
|
|
|
|
counts_builder.append_value(aref.counts);
|
|
|
|
|
|
|
|
|
|
let props_builder = aref_prop_builder.field_builder::<DListBuilder>(8).unwrap();
|
|
|
|
|
append_properties(props_builder, aref.properties);
|
|
|
|
|
|
|
|
|
|
aref_prop_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn aref_to_sref(aref: ARefRecord) -> SRefRecord {
|
|
|
|
|
SRefRecord {
|
|
|
|
|
target_id: aref.target_id,
|
|
|
|
|
invert_y: aref.invert_y,
|
|
|
|
|
scale: aref.scale,
|
|
|
|
|
angle_rad: aref.angle_rad,
|
|
|
|
|
xy: aref.xy,
|
|
|
|
|
properties: aref.properties,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn read_boundary<'a>(
|
|
|
|
|
input: &'a [u8],
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> IResult<'a, BoundaryRecord> {
|
|
|
|
|
let (input, _) = records::BOUNDARY::read(input)?;
|
|
|
|
|
|
|
|
|
|
let (input, layer) = LAYER::skip_and_read(input)?;
|
|
|
|
|
let (input, dtype) = DATATYPE::read(input)?;
|
|
|
|
|
let layer_id = layer_id_for(layer, dtype, layers);
|
|
|
|
|
|
|
|
|
|
let (input, xy_iter) = XY::read(input)?;
|
|
|
|
|
let mut vertices: Vec<i32> = xy_iter.collect();
|
|
|
|
|
vertices.truncate(vertices.len().saturating_sub(2));
|
|
|
|
|
|
|
|
|
|
let (input, properties) = read_properties_vec(input)?;
|
|
|
|
|
|
|
|
|
|
Ok((input, BoundaryRecord { layer_id, vertices, properties }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_boundary_batch(
|
|
|
|
|
boundary_batches_builder: &mut DListBuilder,
|
|
|
|
|
boundary_batch: BoundaryBatchRecord,
|
|
|
|
|
) {
|
|
|
|
|
let boundary_batch_builder = boundary_batches_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let layer_builder = boundary_batch_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
layer_builder.append_value(boundary_batch.layer_id);
|
|
|
|
|
|
|
|
|
|
let vertices_builder = boundary_batch_builder.field_builder::<DListBuilder>(1).unwrap();
|
|
|
|
|
let vertex_builder = vertices_builder.values().as_any_mut().downcast_mut::<Int32Builder>().unwrap();
|
|
|
|
|
vertex_builder.append_slice(&boundary_batch.vertices);
|
|
|
|
|
vertices_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let offsets_builder = boundary_batch_builder.field_builder::<DListBuilder>(2).unwrap();
|
|
|
|
|
let offset_builder = offsets_builder.values().as_any_mut().downcast_mut::<UInt32Builder>().unwrap();
|
|
|
|
|
offset_builder.append_slice(&boundary_batch.vertex_offsets);
|
|
|
|
|
offsets_builder.append(true);
|
|
|
|
|
|
|
|
|
|
boundary_batch_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_rect_batch(
|
|
|
|
|
rect_batches_builder: &mut DListBuilder,
|
|
|
|
|
rect_batch: RectBatchRecord,
|
|
|
|
|
) {
|
|
|
|
|
let rect_batch_builder = rect_batches_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let layer_builder = rect_batch_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
layer_builder.append_value(rect_batch.layer_id);
|
|
|
|
|
|
|
|
|
|
let rects_builder = rect_batch_builder.field_builder::<DListBuilder>(1).unwrap();
|
|
|
|
|
let rect_builder = rects_builder.values().as_any_mut().downcast_mut::<Int32Builder>().unwrap();
|
|
|
|
|
rect_builder.append_slice(&rect_batch.rects);
|
|
|
|
|
rects_builder.append(true);
|
|
|
|
|
|
|
|
|
|
rect_batch_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_boundary_prop(
|
|
|
|
|
boundary_props_builder: &mut DListBuilder,
|
|
|
|
|
boundary: BoundaryRecord,
|
|
|
|
|
) {
|
|
|
|
|
let boundary_prop_builder = boundary_props_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let layer_builder = boundary_prop_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
layer_builder.append_value(boundary.layer_id);
|
|
|
|
|
|
|
|
|
|
let vertices_builder = boundary_prop_builder.field_builder::<DListBuilder>(1).unwrap();
|
|
|
|
|
let vertex_builder = vertices_builder.values().as_any_mut().downcast_mut::<Int32Builder>().unwrap();
|
|
|
|
|
vertex_builder.append_slice(&boundary.vertices);
|
|
|
|
|
vertices_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let props_builder = boundary_prop_builder.field_builder::<DListBuilder>(2).unwrap();
|
|
|
|
|
append_properties(props_builder, boundary.properties);
|
|
|
|
|
|
|
|
|
|
boundary_prop_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
fn read_path<'a>(
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
input: &'a [u8],
|
|
|
|
|
cell_builder: &mut StructBuilder,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let paths_builder = cell_builder.field_builder::<DListBuilder>(9).unwrap();
|
|
|
|
|
let path_builder = paths_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let (input, _) = records::PATH::read(input)?;
|
|
|
|
|
|
|
|
|
|
let (input, layer) = LAYER::skip_and_read(input)?;
|
|
|
|
|
let (input, dtype) = DATATYPE::read(input)?;
|
|
|
|
|
insert_layer(layer, dtype, layers, path_builder, 0);
|
|
|
|
|
|
|
|
|
|
let mut path_type = None;
|
|
|
|
|
let mut width = None;
|
|
|
|
|
let mut bgn_ext = None;
|
|
|
|
|
let mut end_ext = None;
|
|
|
|
|
|
|
|
|
|
let (mut input, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != records::RTAG_XY {
|
|
|
|
|
match header.tag {
|
|
|
|
|
records::RTAG_PATHTYPE => {
|
|
|
|
|
let _path_type;
|
|
|
|
|
(input, _path_type) = PATHTYPE::read_data(input, header.data_size)?;
|
|
|
|
|
path_type = Some(_path_type);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_WIDTH => {
|
|
|
|
|
let _width;
|
|
|
|
|
(input, _width) = WIDTH::read_data(input, header.data_size)?;
|
|
|
|
|
width = Some(_width);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_BGNEXTN => {
|
|
|
|
|
let _bgn_ext;
|
|
|
|
|
(input, _bgn_ext) = BGNEXTN::read_data(input, header.data_size)?;
|
|
|
|
|
bgn_ext = Some(_bgn_ext);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_ENDEXTN => {
|
|
|
|
|
let _end_ext;
|
|
|
|
|
(input, _end_ext) = ENDEXTN::read_data(input, header.data_size)?;
|
|
|
|
|
end_ext = Some(_end_ext);
|
|
|
|
|
},
|
|
|
|
|
_ =>
|
|
|
|
|
return fail(input, format!("Unexpected tag {:04x}", header.tag)),
|
|
|
|
|
};
|
|
|
|
|
(input, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
let path_type_builder = path_builder.field_builder::<Int16Builder>(1).unwrap();
|
|
|
|
|
path_type_builder.append_option(path_type);
|
|
|
|
|
let ext0_builder = path_builder.field_builder::<Int32Builder>(2).unwrap();
|
|
|
|
|
ext0_builder.append_option(bgn_ext);
|
|
|
|
|
let ext1_builder = path_builder.field_builder::<Int32Builder>(3).unwrap();
|
|
|
|
|
ext1_builder.append_option(end_ext);
|
|
|
|
|
let width_builder = path_builder.field_builder::<Int32Builder>(4).unwrap();
|
|
|
|
|
width_builder.append_option(width);
|
|
|
|
|
|
|
|
|
|
let xys_builder = path_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
let (input, xy_iter) = XY::read_data(input, header.data_size)?;
|
|
|
|
|
for xy in xy_iter {
|
|
|
|
|
let xy_builder = xys_builder.values().as_any_mut().downcast_mut::<Int32Builder>().unwrap();
|
|
|
|
|
xy_builder.append_value(xy);
|
|
|
|
|
}
|
|
|
|
|
xys_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let props_builder = path_builder.field_builder::<DListBuilder>(6).unwrap();
|
|
|
|
|
let (input, ()) = read_properties(input, props_builder)?;
|
|
|
|
|
|
|
|
|
|
path_builder.append(true);
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
fn read_boxnode<'a>(
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
input: &'a [u8],
|
|
|
|
|
cell_builder: &mut StructBuilder,
|
|
|
|
|
tag: u16,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let field_num = match tag {
|
|
|
|
|
records::RTAG_NODE => 10,
|
|
|
|
|
records::RTAG_BOX => 11,
|
|
|
|
|
_ => return fail(input, format!("Unexpected tag {:04x}", tag)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let boxnodes_builder = cell_builder.field_builder::<DListBuilder>(field_num).unwrap();
|
|
|
|
|
let boxnode_builder = boxnodes_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let (input, _) = match tag {
|
|
|
|
|
records::RTAG_NODE => records::NODE::read(input)?,
|
|
|
|
|
records::RTAG_BOX => records::BOX::read(input)?,
|
|
|
|
|
_ => return fail(input, format!("Unexpected tag {:04x}", tag)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let (input, layer) = LAYER::skip_and_read(input)?;
|
|
|
|
|
let (input, dtype) = match tag {
|
|
|
|
|
records::RTAG_NODE => NODETYPE::read(input)?,
|
|
|
|
|
records::RTAG_BOX => BOXTYPE::read(input)?,
|
|
|
|
|
_ => return fail(input, format!("Unexpected tag {:04x}", tag)),
|
|
|
|
|
};
|
|
|
|
|
insert_layer(layer, dtype, layers, boxnode_builder, 0);
|
|
|
|
|
|
|
|
|
|
let xys_builder = boxnode_builder.field_builder::<DListBuilder>(1).unwrap();
|
|
|
|
|
let xy_builder = xys_builder.values().as_any_mut().downcast_mut::<Int32Builder>().unwrap();
|
|
|
|
|
let (input, xy_iter) = XY::read(input)?;
|
|
|
|
|
for xy in xy_iter {
|
|
|
|
|
xy_builder.append_value(xy);
|
|
|
|
|
}
|
|
|
|
|
xys_builder.append(true);
|
|
|
|
|
|
|
|
|
|
let props_builder = boxnode_builder.field_builder::<DListBuilder>(2).unwrap();
|
|
|
|
|
let (input, ()) = read_properties(input, props_builder)?;
|
|
|
|
|
|
|
|
|
|
boxnode_builder.append(true);
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
fn read_text<'a>(
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
input: &'a [u8],
|
|
|
|
|
cell_builder: &mut StructBuilder,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let texts_builder = cell_builder.field_builder::<DListBuilder>(12).unwrap();
|
|
|
|
|
let text_builder = texts_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
|
|
|
|
|
let mut path_type = None;
|
|
|
|
|
let mut pres_hori = None;
|
|
|
|
|
let mut pres_vert = None;
|
|
|
|
|
let mut pres_font = None;
|
|
|
|
|
let mut invert_y = None;
|
|
|
|
|
let mut width = None;
|
|
|
|
|
let mut mag = None;
|
|
|
|
|
let mut angle_deg = None;
|
|
|
|
|
|
|
|
|
|
let (input, layer) = LAYER::skip_and_read(input)?;
|
|
|
|
|
let (input, dtype) = TEXTTYPE::read(input)?;
|
|
|
|
|
insert_layer(layer, dtype, layers, text_builder, 0);
|
|
|
|
|
|
|
|
|
|
let (mut input, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != records::RTAG_XY {
|
|
|
|
|
match header.tag {
|
|
|
|
|
// TODO warn if repeat tags?
|
|
|
|
|
records::RTAG_PRESENTATION => {
|
|
|
|
|
let _presentation;
|
|
|
|
|
(input, _presentation) = PRESENTATION::read_data(input, header.data_size)?;
|
|
|
|
|
pres_hori = Some(_presentation[14] as u8 * 2 + _presentation[15] as u8);
|
|
|
|
|
pres_vert = Some(_presentation[12] as u8 * 2 + _presentation[13] as u8);
|
|
|
|
|
pres_font = Some(_presentation[10] as u8 * 2 + _presentation[11] as u8);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_PATHTYPE => {
|
|
|
|
|
let _path_type;
|
|
|
|
|
(input, _path_type) = PATHTYPE::read_data(input, header.data_size)?;
|
|
|
|
|
path_type = Some(_path_type);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_WIDTH => {
|
|
|
|
|
let _width;
|
|
|
|
|
(input, _width) = WIDTH::read_data(input, header.data_size)?;
|
|
|
|
|
width = Some(_width);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_STRANS => {
|
|
|
|
|
let strans;
|
|
|
|
|
(input, strans) = STRANS::read_data(input, header.data_size)?;
|
|
|
|
|
invert_y = Some(strans[0]);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_MAG => {
|
|
|
|
|
let _mag;
|
|
|
|
|
(input, _mag) = MAG::read_data(input, header.data_size)?;
|
|
|
|
|
mag = Some(_mag);
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_ANGLE => {
|
|
|
|
|
let _angle_deg;
|
|
|
|
|
(input, _angle_deg) = ANGLE::read_data(input, header.data_size)?;
|
|
|
|
|
angle_deg = Some(_angle_deg);
|
|
|
|
|
},
|
|
|
|
|
_ =>
|
|
|
|
|
return fail(input, format!("Unexpected tag {:04x}", header.tag)),
|
|
|
|
|
}
|
|
|
|
|
(input, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let pres_hori_builder = text_builder.field_builder::<UInt8Builder>(1).unwrap();
|
|
|
|
|
pres_hori_builder.append_option(pres_hori);
|
|
|
|
|
let pres_vert_builder = text_builder.field_builder::<UInt8Builder>(2).unwrap();
|
|
|
|
|
pres_vert_builder.append_option(pres_vert);
|
|
|
|
|
let pres_font_builder = text_builder.field_builder::<UInt8Builder>(3).unwrap();
|
|
|
|
|
pres_font_builder.append_option(pres_font);
|
|
|
|
|
let path_type_builder = text_builder.field_builder::<Int16Builder>(4).unwrap();
|
|
|
|
|
path_type_builder.append_option(path_type);
|
|
|
|
|
let width_builder = text_builder.field_builder::<Int32Builder>(5).unwrap();
|
|
|
|
|
width_builder.append_option(width);
|
|
|
|
|
let inv_builder = text_builder.field_builder::<BooleanBuilder>(6).unwrap();
|
|
|
|
|
inv_builder.append_option(invert_y);
|
|
|
|
|
let mag_builder = text_builder.field_builder::<Float64Builder>(7).unwrap();
|
|
|
|
|
mag_builder.append_option(mag);
|
|
|
|
|
let angle_builder = text_builder.field_builder::<Float64Builder>(8).unwrap();
|
|
|
|
|
angle_builder.append_option(angle_deg);
|
|
|
|
|
|
|
|
|
|
let (input, mut xy_iter) = XY::read_data(input, header.data_size)?;
|
|
|
|
|
let xx = xy_iter.next().unwrap();
|
|
|
|
|
let yy = xy_iter.next().unwrap();
|
|
|
|
|
let xy = ((xx as u32 as u64) << 32) | (yy as u32 as u64);
|
|
|
|
|
let xy_builder = text_builder.field_builder::<UInt64Builder>(9).unwrap();
|
|
|
|
|
xy_builder.append_value(xy);
|
|
|
|
|
|
|
|
|
|
let (input, string_bytes) = STRING::read(input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
let string = decode_utf8(string_bytes).map_err(|error| (input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let string_builder = text_builder.field_builder::<StringBuilder>(10).unwrap();
|
|
|
|
|
string_builder.append_value(string);
|
|
|
|
|
|
|
|
|
|
let props_builder = text_builder.field_builder::<DListBuilder>(11).unwrap();
|
|
|
|
|
let (input, ()) = read_properties(input, props_builder)?;
|
|
|
|
|
|
|
|
|
|
text_builder.append(true);
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn boundary_to_rect(vertices: &[i32]) -> Option<[i32; 4]> {
|
|
|
|
|
if vertices.len() != 8 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let xs = [vertices[0], vertices[2], vertices[4], vertices[6]];
|
|
|
|
|
let ys = [vertices[1], vertices[3], vertices[5], vertices[7]];
|
|
|
|
|
|
|
|
|
|
let min_x = *xs.iter().min().unwrap();
|
|
|
|
|
let max_x = *xs.iter().max().unwrap();
|
|
|
|
|
let min_y = *ys.iter().min().unwrap();
|
|
|
|
|
let max_y = *ys.iter().max().unwrap();
|
|
|
|
|
if min_x >= max_x || min_y >= max_y {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut seen_corners: u8 = 0;
|
|
|
|
|
for ii in 0..4 {
|
|
|
|
|
let jj = (ii + 1) % 4;
|
|
|
|
|
let same_x = xs[jj] == xs[ii];
|
|
|
|
|
let same_y = ys[jj] == ys[ii];
|
|
|
|
|
if same_x == same_y {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let x = xs[ii];
|
|
|
|
|
let y = ys[ii];
|
|
|
|
|
if (x != min_x && x != max_x) || (y != min_y && y != max_y) {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let code = ((x == max_x) as u8) << 1 | ((y == max_y) as u8);
|
|
|
|
|
seen_corners |= 1 << code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if seen_corners != 0b1111 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
Some([min_x, min_y, max_x, max_y])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn read_ref<'a>(
|
|
|
|
|
input: &'a [u8],
|
|
|
|
|
tag: u16,
|
|
|
|
|
names: &mut HashMap<String, u32>,
|
|
|
|
|
) -> IResult<'a, RefRecord> {
|
|
|
|
|
let (input, _) = match tag {
|
|
|
|
|
records::RTAG_SREF => records::SREF::read(input)?,
|
|
|
|
|
records::RTAG_AREF => records::AREF::read(input)?,
|
|
|
|
|
_ => return fail(input, format!("Unexpected tag {:04x}", tag)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let is_aref = tag == records::RTAG_AREF;
|
|
|
|
|
let mut invert_y = false;
|
|
|
|
|
let mut scale = 1.0;
|
|
|
|
|
let mut angle_rad = 0.0;
|
|
|
|
|
let mut colrow = None;
|
|
|
|
|
|
|
|
|
|
let (input, struct_name_bytes) = SNAME::skip_and_read(input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
let struct_name = decode_utf8(struct_name_bytes).map_err(|error| (input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let next_id = names.len();
|
|
|
|
|
let id = names.entry(struct_name).or_insert(next_id.try_into().unwrap());
|
|
|
|
|
|
|
|
|
|
let (mut input, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != records::RTAG_XY {
|
|
|
|
|
match header.tag {
|
|
|
|
|
records::RTAG_STRANS => {
|
|
|
|
|
let strans;
|
|
|
|
|
(input, strans) = STRANS::read_data(input, header.data_size)?;
|
|
|
|
|
invert_y = strans[0];
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_MAG => {
|
|
|
|
|
let _mag;
|
|
|
|
|
(input, _mag) = MAG::read_data(input, header.data_size)?;
|
|
|
|
|
scale = _mag;
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_ANGLE => {
|
|
|
|
|
let _angle_deg;
|
|
|
|
|
(input, _angle_deg) = ANGLE::read_data(input, header.data_size)?;
|
|
|
|
|
angle_rad = _angle_deg.to_radians();
|
|
|
|
|
},
|
|
|
|
|
records::RTAG_COLROW => {
|
|
|
|
|
if header.data_size != 4 {
|
|
|
|
|
return fail(input, "COLROW must contain two counts".to_string());
|
|
|
|
|
}
|
|
|
|
|
let mut _colrow;
|
|
|
|
|
(input, _colrow) = COLROW::read_data(input, header.data_size)?;
|
|
|
|
|
colrow = Some((_colrow.next().unwrap(), _colrow.next().unwrap()));
|
|
|
|
|
if !is_aref {
|
|
|
|
|
return fail(input, "Got a COLROW record inside an SREF".to_string());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
_ =>
|
|
|
|
|
return fail(input, format!("Unexpected tag {:04x}", header.tag)),
|
|
|
|
|
};
|
|
|
|
|
(input, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let expected_xy_size = if is_aref { 24 } else { 8 };
|
|
|
|
|
if header.data_size != expected_xy_size {
|
|
|
|
|
return fail(input, format!("Expected {expected_xy_size} bytes of reference coordinates, got {}", header.data_size));
|
|
|
|
|
}
|
|
|
|
|
let (input, mut xy_iter) = XY::read_data(input, header.data_size)?;
|
|
|
|
|
let xx = xy_iter.next().unwrap();
|
|
|
|
|
let yy = xy_iter.next().unwrap();
|
|
|
|
|
let xy = ((xx as u32 as u64) << 32) | (yy as u32 as u64);
|
|
|
|
|
let (input, properties) = read_properties_vec(input)?;
|
|
|
|
|
|
|
|
|
|
if is_aref {
|
|
|
|
|
if colrow.is_none() {
|
|
|
|
|
return fail(input, "AREF without COLROW before XY".to_string())
|
|
|
|
|
}
|
|
|
|
|
let (count0, count1) = colrow.unwrap();
|
|
|
|
|
if count0 <= 0 || count1 <= 0 {
|
|
|
|
|
return fail(input, "AREF column and row counts must be positive".to_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let pitch = |end: i32, origin: i32, count: i16| {
|
|
|
|
|
let delta = i64::from(end) - i64::from(origin);
|
|
|
|
|
let divisor = i64::from(count);
|
|
|
|
|
if delta % divisor != 0 {
|
|
|
|
|
return Err((input, crate::basic::ErrType::Failed(
|
|
|
|
|
"AREF pitch is not an integer database-unit increment; the Arrow schema cannot represent it exactly".to_string()
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
let value = delta / divisor;
|
|
|
|
|
i32::try_from(value).map_err(|_| (input, crate::basic::ErrType::Failed(
|
|
|
|
|
"AREF pitch exceeds signed 32-bit coordinate range".to_string()
|
|
|
|
|
)))
|
|
|
|
|
};
|
|
|
|
|
let x0a = pitch(xy_iter.next().unwrap(), xx, count0)?;
|
|
|
|
|
let y0a = pitch(xy_iter.next().unwrap(), yy, count0)?;
|
|
|
|
|
let x1a = pitch(xy_iter.next().unwrap(), xx, count1)?;
|
|
|
|
|
let y1a = pitch(xy_iter.next().unwrap(), yy, count1)?;
|
|
|
|
|
|
|
|
|
|
let xy0a = ((x0a as u32 as u64) << 32) | (y0a as u32 as u64);
|
|
|
|
|
let xy1a = ((x1a as u32 as u64) << 32) | (y1a as u32 as u64);
|
|
|
|
|
let counts = ((count0 as u16 as u32) << 16) | (count1 as u16 as u32);
|
|
|
|
|
Ok((input, RefRecord::ARef(ARefRecord {
|
|
|
|
|
target_id: *id,
|
|
|
|
|
invert_y,
|
|
|
|
|
scale,
|
|
|
|
|
angle_rad,
|
|
|
|
|
xy,
|
|
|
|
|
xy0: xy0a,
|
|
|
|
|
xy1: xy1a,
|
|
|
|
|
counts,
|
|
|
|
|
properties,
|
|
|
|
|
})))
|
|
|
|
|
} else {
|
|
|
|
|
Ok((input, RefRecord::SRef(SRefRecord {
|
|
|
|
|
target_id: *id,
|
|
|
|
|
invert_y,
|
|
|
|
|
scale,
|
|
|
|
|
angle_rad,
|
|
|
|
|
xy,
|
|
|
|
|
properties,
|
|
|
|
|
})))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// Read element properties.
|
|
|
|
|
///
|
|
|
|
|
/// Preserves record order and duplicate property attributes.
|
|
|
|
|
/// Stops reading after consuming ENDEL record.
|
|
|
|
|
///
|
2026-11-16 20:44:48 -08:00
|
|
|
fn read_properties<'a>(input: &'a [u8], props_builder: &mut DListBuilder) -> IResult<'a, ()> {
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let (input, ()) = walk_properties(input, |property| append_property(props_builder, property))?;
|
|
|
|
|
props_builder.append(true);
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn walk_properties<'a>(
|
|
|
|
|
input: &'a [u8],
|
|
|
|
|
mut on_property: impl FnMut(PropertyRecord),
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let (mut input, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != ENDEL::tag() {
|
|
|
|
|
if header.tag == PROPATTR::tag() {
|
|
|
|
|
let key;
|
|
|
|
|
let value_bytes;
|
|
|
|
|
(input, key) = PROPATTR::read_data(input, header.data_size)?;
|
|
|
|
|
(input, value_bytes) = PROPVALUE::read(input)?;
|
|
|
|
|
|
|
|
|
|
on_property(PropertyRecord {
|
|
|
|
|
key,
|
2026-11-16 21:28:54 -08:00
|
|
|
value: decode_utf8(value_bytes).map_err(|error| (input, error))?,
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
(input, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn read_properties_vec<'a>(input: &'a [u8]) -> IResult<'a, Vec<PropertyRecord>> {
|
|
|
|
|
let mut properties = Vec::new();
|
|
|
|
|
let (input, ()) = walk_properties(input, |property| properties.push(property))?;
|
|
|
|
|
Ok((input, properties))
|
|
|
|
|
}
|