svlang-sdk 0.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- svlang_sdk-0.7.0/PKG-INFO +82 -0
- svlang_sdk-0.7.0/README.md +69 -0
- svlang_sdk-0.7.0/pyproject.toml +24 -0
- svlang_sdk-0.7.0/setup.cfg +4 -0
- svlang_sdk-0.7.0/svlang_sdk/__init__.py +38 -0
- svlang_sdk-0.7.0/svlang_sdk/_ffi.py +460 -0
- svlang_sdk-0.7.0/svlang_sdk/arrow.py +361 -0
- svlang_sdk-0.7.0/svlang_sdk/session.py +616 -0
- svlang_sdk-0.7.0/svlang_sdk.egg-info/PKG-INFO +82 -0
- svlang_sdk-0.7.0/svlang_sdk.egg-info/SOURCES.txt +12 -0
- svlang_sdk-0.7.0/svlang_sdk.egg-info/dependency_links.txt +1 -0
- svlang_sdk-0.7.0/svlang_sdk.egg-info/requires.txt +3 -0
- svlang_sdk-0.7.0/svlang_sdk.egg-info/top_level.txt +1 -0
- svlang_sdk-0.7.0/tests/test_python_sdk.py +426 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: svlang-sdk
|
|
3
|
+
Version: 0.7.0
|
|
4
|
+
Summary: Zero-build-dependency Python bindings for the svlang EDA Compiler SDK (ctypes + Apache Arrow PyCapsule Interface)
|
|
5
|
+
Author-email: Mayur Kubavat <mkubavat01@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/mayurkubavat/svlang
|
|
8
|
+
Project-URL: Repository, https://github.com/mayurkubavat/svlang
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Provides-Extra: arrow
|
|
12
|
+
Requires-Dist: pyarrow>=14.0; extra == "arrow"
|
|
13
|
+
|
|
14
|
+
# `svlang-sdk` — Zero-Build-Dependency Python SDK
|
|
15
|
+
|
|
16
|
+
Pure-Python (`ctypes`) bindings over the frozen svlang C11 ABI v1.1 (`libsvlang_sdk_c`), with zero required third-party dependencies and native **Apache Arrow PyCapsule Interface** zero-copy export (`__arrow_c_schema__` / `__arrow_c_array__`).
|
|
17
|
+
|
|
18
|
+
## Library Discovery
|
|
19
|
+
|
|
20
|
+
`svlang_sdk` locates `libsvlang_sdk_c.{dylib,so,dll}` automatically in priority order:
|
|
21
|
+
|
|
22
|
+
1. `SVLANG_SDK_LIB` — exact shared library file path
|
|
23
|
+
2. `SVLANG_SDK_LIB_DIR` — directory containing the shared library
|
|
24
|
+
3. Sibling repository build directories (`sdk/build/release/abi/c/`, `sdk/build/dev/abi/c/`)
|
|
25
|
+
4. Standard OS library search (`ctypes.util.find_library("svlang_sdk_c")` / dynamic linker paths)
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import pyarrow as pa
|
|
31
|
+
from svlang_sdk import AtomicChange, Durability, Graph, Host, Registry, abi_version
|
|
32
|
+
|
|
33
|
+
print("C ABI:", abi_version()) # (1, 1)
|
|
34
|
+
|
|
35
|
+
with Host() as host:
|
|
36
|
+
host.set_file(
|
|
37
|
+
"rtl/top.sv",
|
|
38
|
+
"module top(input logic [7:0] a, output logic [7:0] y); assign y = ~a; endmodule\n",
|
|
39
|
+
Durability.LOW,
|
|
40
|
+
)
|
|
41
|
+
host.set_file(
|
|
42
|
+
"pwr/top.upf",
|
|
43
|
+
"upf_version 3.1\ncreate_power_domain PD_TOP -include_scope\n",
|
|
44
|
+
Durability.HIGH,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
with host.take_snapshot() as snap, snap.build_graph("top") as graph:
|
|
48
|
+
# Zero-copy Apache Arrow PyCapsule export (no pyarrow.cffi boilerplate).
|
|
49
|
+
arr = pa.array(graph.entities_arrow())
|
|
50
|
+
batch = pa.RecordBatch.from_struct_array(arr)
|
|
51
|
+
print(batch.num_rows, batch.schema.names)
|
|
52
|
+
|
|
53
|
+
# Immutable .svdb snapshot persistence (ABI v1.1).
|
|
54
|
+
graph.save_svdb("top.svdb")
|
|
55
|
+
summary = Graph.inspect_svdb("top.svdb")
|
|
56
|
+
with Graph.load_svdb("top.svdb") as loaded:
|
|
57
|
+
assert loaded.entity_count == summary["entity_count"]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Without `pyarrow` installed, `ArrowEntityTable` still supports pure-Python inspection:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
with graph.entities_arrow() as table:
|
|
64
|
+
print(table.row_count, table.column_names)
|
|
65
|
+
rows = table.to_pylist()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Public API
|
|
69
|
+
|
|
70
|
+
- **Lifecycle & Errors:** `abi_version()`, `inspect_svdb(path)`, `Durability`, `StatusCode`, `SdkError` (`.code`, `.message`)
|
|
71
|
+
- **`Host`:** `revision`, `set_file(path, content, durability=Durability.LOW)`, `remove_file(path)`, `take_snapshot()`
|
|
72
|
+
- **`Snapshot`:** `revision`, `is_cancelled`, `build_graph(top_module=None)`, `lint_file(path)`
|
|
73
|
+
- **`Graph`:** `entity_count`, `find_entity(path)`, `export_entities(...)`, `fanin_cone(...)`, `explain_overlay(...)`, `apply_overlay_str(...)`, `power_crossings()`, `entities_arrow()`, `save_svdb(path)`, `Graph.load_svdb(path)`, `Graph.inspect_svdb(path)`
|
|
74
|
+
- **`ArrowEntityTable`:** `__arrow_c_schema__()`, `__arrow_c_array__(requested_schema=None)`, `row_count`, `column_count`, `column_names`, `column_formats`, `to_pylist()`, `close()`
|
|
75
|
+
- **`AtomicChange`:** `add_edit(...)`, `preview(snapshot, ...)`, `apply_to_host(host, ...)`
|
|
76
|
+
- **`Registry`:** `register_builtins()`, `list_plugins()`, `run_passes(graph)`
|
|
77
|
+
|
|
78
|
+
## Running Tests
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
PYTHONPATH=sdk/bindings/python python3 -m unittest discover -s sdk/bindings/python/tests -v
|
|
82
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# `svlang-sdk` — Zero-Build-Dependency Python SDK
|
|
2
|
+
|
|
3
|
+
Pure-Python (`ctypes`) bindings over the frozen svlang C11 ABI v1.1 (`libsvlang_sdk_c`), with zero required third-party dependencies and native **Apache Arrow PyCapsule Interface** zero-copy export (`__arrow_c_schema__` / `__arrow_c_array__`).
|
|
4
|
+
|
|
5
|
+
## Library Discovery
|
|
6
|
+
|
|
7
|
+
`svlang_sdk` locates `libsvlang_sdk_c.{dylib,so,dll}` automatically in priority order:
|
|
8
|
+
|
|
9
|
+
1. `SVLANG_SDK_LIB` — exact shared library file path
|
|
10
|
+
2. `SVLANG_SDK_LIB_DIR` — directory containing the shared library
|
|
11
|
+
3. Sibling repository build directories (`sdk/build/release/abi/c/`, `sdk/build/dev/abi/c/`)
|
|
12
|
+
4. Standard OS library search (`ctypes.util.find_library("svlang_sdk_c")` / dynamic linker paths)
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import pyarrow as pa
|
|
18
|
+
from svlang_sdk import AtomicChange, Durability, Graph, Host, Registry, abi_version
|
|
19
|
+
|
|
20
|
+
print("C ABI:", abi_version()) # (1, 1)
|
|
21
|
+
|
|
22
|
+
with Host() as host:
|
|
23
|
+
host.set_file(
|
|
24
|
+
"rtl/top.sv",
|
|
25
|
+
"module top(input logic [7:0] a, output logic [7:0] y); assign y = ~a; endmodule\n",
|
|
26
|
+
Durability.LOW,
|
|
27
|
+
)
|
|
28
|
+
host.set_file(
|
|
29
|
+
"pwr/top.upf",
|
|
30
|
+
"upf_version 3.1\ncreate_power_domain PD_TOP -include_scope\n",
|
|
31
|
+
Durability.HIGH,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
with host.take_snapshot() as snap, snap.build_graph("top") as graph:
|
|
35
|
+
# Zero-copy Apache Arrow PyCapsule export (no pyarrow.cffi boilerplate).
|
|
36
|
+
arr = pa.array(graph.entities_arrow())
|
|
37
|
+
batch = pa.RecordBatch.from_struct_array(arr)
|
|
38
|
+
print(batch.num_rows, batch.schema.names)
|
|
39
|
+
|
|
40
|
+
# Immutable .svdb snapshot persistence (ABI v1.1).
|
|
41
|
+
graph.save_svdb("top.svdb")
|
|
42
|
+
summary = Graph.inspect_svdb("top.svdb")
|
|
43
|
+
with Graph.load_svdb("top.svdb") as loaded:
|
|
44
|
+
assert loaded.entity_count == summary["entity_count"]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Without `pyarrow` installed, `ArrowEntityTable` still supports pure-Python inspection:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
with graph.entities_arrow() as table:
|
|
51
|
+
print(table.row_count, table.column_names)
|
|
52
|
+
rows = table.to_pylist()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Public API
|
|
56
|
+
|
|
57
|
+
- **Lifecycle & Errors:** `abi_version()`, `inspect_svdb(path)`, `Durability`, `StatusCode`, `SdkError` (`.code`, `.message`)
|
|
58
|
+
- **`Host`:** `revision`, `set_file(path, content, durability=Durability.LOW)`, `remove_file(path)`, `take_snapshot()`
|
|
59
|
+
- **`Snapshot`:** `revision`, `is_cancelled`, `build_graph(top_module=None)`, `lint_file(path)`
|
|
60
|
+
- **`Graph`:** `entity_count`, `find_entity(path)`, `export_entities(...)`, `fanin_cone(...)`, `explain_overlay(...)`, `apply_overlay_str(...)`, `power_crossings()`, `entities_arrow()`, `save_svdb(path)`, `Graph.load_svdb(path)`, `Graph.inspect_svdb(path)`
|
|
61
|
+
- **`ArrowEntityTable`:** `__arrow_c_schema__()`, `__arrow_c_array__(requested_schema=None)`, `row_count`, `column_count`, `column_names`, `column_formats`, `to_pylist()`, `close()`
|
|
62
|
+
- **`AtomicChange`:** `add_edit(...)`, `preview(snapshot, ...)`, `apply_to_host(host, ...)`
|
|
63
|
+
- **`Registry`:** `register_builtins()`, `list_plugins()`, `run_passes(graph)`
|
|
64
|
+
|
|
65
|
+
## Running Tests
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
PYTHONPATH=sdk/bindings/python python3 -m unittest discover -s sdk/bindings/python/tests -v
|
|
69
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "svlang-sdk"
|
|
7
|
+
version = "0.7.0"
|
|
8
|
+
description = "Zero-build-dependency Python bindings for the svlang EDA Compiler SDK (ctypes + Apache Arrow PyCapsule Interface)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Mayur Kubavat", email = "mkubavat01@gmail.com" }]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
license = { text = "Apache-2.0" }
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/mayurkubavat/svlang"
|
|
17
|
+
Repository = "https://github.com/mayurkubavat/svlang"
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
arrow = ["pyarrow>=14.0"]
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.packages.find]
|
|
23
|
+
where = ["."]
|
|
24
|
+
include = ["svlang_sdk*"]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""svlang_sdk — Zero-build-dependency Python SDK over the frozen C11 ABI v1.1.
|
|
2
|
+
|
|
3
|
+
Provides context-managed Python wrappers for the svlang incremental VFS host,
|
|
4
|
+
cancellable snapshots, multi-domain ``DesignGraph`` (SystemVerilog + UPF +
|
|
5
|
+
SystemC), transactional ``AtomicChange``, ``.svdb`` snapshot persistence,
|
|
6
|
+
plugin registry, and zero-copy Apache Arrow PyCapsule export.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .arrow import ArrowEntityTable
|
|
10
|
+
from .session import (
|
|
11
|
+
AtomicChange,
|
|
12
|
+
Durability,
|
|
13
|
+
Graph,
|
|
14
|
+
Host,
|
|
15
|
+
Registry,
|
|
16
|
+
SdkError,
|
|
17
|
+
Snapshot,
|
|
18
|
+
StatusCode,
|
|
19
|
+
abi_version,
|
|
20
|
+
inspect_svdb,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__version__ = "0.7.0"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"__version__",
|
|
27
|
+
"ArrowEntityTable",
|
|
28
|
+
"AtomicChange",
|
|
29
|
+
"Durability",
|
|
30
|
+
"Graph",
|
|
31
|
+
"Host",
|
|
32
|
+
"Registry",
|
|
33
|
+
"SdkError",
|
|
34
|
+
"Snapshot",
|
|
35
|
+
"StatusCode",
|
|
36
|
+
"abi_version",
|
|
37
|
+
"inspect_svdb",
|
|
38
|
+
]
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
"""Low-level ctypes bindings for the frozen svlang C11 ABI v1.1 (`libsvlang_sdk_c`).
|
|
2
|
+
|
|
3
|
+
This module discovers the compiled shared library with zero build dependencies
|
|
4
|
+
and binds exact ``argtypes`` / ``restype`` signatures for all 39 ``svsdk_*``
|
|
5
|
+
entry points declared in ``svsdk/c_api.h``, plus byte-exact ``ctypes.Structure``
|
|
6
|
+
definitions for ``ArrowSchema``, ``ArrowArray``, and ``svsdk_plugin_descriptor_v1``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import ctypes
|
|
12
|
+
import ctypes.util
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
# ABI Constants (svsdk/c_api.h & svsdk/plugin_abi.h)
|
|
20
|
+
# ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
SVSDK_ABI_VERSION_MAJOR = 1
|
|
23
|
+
SVSDK_ABI_VERSION_MINOR = 1
|
|
24
|
+
SVSDK_PLUGIN_ABI_VERSION = 1
|
|
25
|
+
|
|
26
|
+
SVSDK_OK = 0
|
|
27
|
+
SVSDK_ERR_INVALID_ARG = 1
|
|
28
|
+
SVSDK_ERR_CANCELLED = 2
|
|
29
|
+
SVSDK_ERR_PARSE = 3
|
|
30
|
+
SVSDK_ERR_ELAB = 4
|
|
31
|
+
SVSDK_ERR_NOT_FOUND = 5
|
|
32
|
+
SVSDK_ERR_CONFLICT = 6
|
|
33
|
+
SVSDK_ERR_INTERNAL = 7
|
|
34
|
+
|
|
35
|
+
SVSDK_DURABILITY_LOW = 0
|
|
36
|
+
SVSDK_DURABILITY_MEDIUM = 1
|
|
37
|
+
SVSDK_DURABILITY_HIGH = 2
|
|
38
|
+
|
|
39
|
+
SVSDK_CAP_NONE = 0x00
|
|
40
|
+
SVSDK_CAP_FRONTEND = 0x01
|
|
41
|
+
SVSDK_CAP_OVERLAY_SCHEMA = 0x02
|
|
42
|
+
SVSDK_CAP_PASS = 0x04
|
|
43
|
+
SVSDK_CAP_BACKEND = 0x08
|
|
44
|
+
SVSDK_CAP_SIDECAR = 0x10
|
|
45
|
+
SVSDK_CAP_PROJECTION = 0x20
|
|
46
|
+
|
|
47
|
+
# ---------------------------------------------------------------------------
|
|
48
|
+
# Apache Arrow C Data Interface Structures (svsdk/arrow_abi.h)
|
|
49
|
+
# ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ArrowSchema(ctypes.Structure):
|
|
53
|
+
"""Byte-exact match for ``struct ArrowSchema`` in ``svsdk/arrow_abi.h``."""
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
ARROW_SCHEMA_RELEASE_FN = ctypes.CFUNCTYPE(None, ctypes.POINTER(ArrowSchema))
|
|
57
|
+
|
|
58
|
+
ArrowSchema._fields_ = [
|
|
59
|
+
("format", ctypes.c_char_p),
|
|
60
|
+
("name", ctypes.c_char_p),
|
|
61
|
+
("metadata", ctypes.c_char_p),
|
|
62
|
+
("flags", ctypes.c_int64),
|
|
63
|
+
("n_children", ctypes.c_int64),
|
|
64
|
+
("children", ctypes.POINTER(ctypes.POINTER(ArrowSchema))),
|
|
65
|
+
("dictionary", ctypes.POINTER(ArrowSchema)),
|
|
66
|
+
# Store function pointer as c_void_p so NULL checks are exact and invoking
|
|
67
|
+
# release callbacks does not trigger ctypes callback-object lifetime issues.
|
|
68
|
+
("release", ctypes.c_void_p),
|
|
69
|
+
("private_data", ctypes.c_void_p),
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ArrowArray(ctypes.Structure):
|
|
74
|
+
"""Byte-exact match for ``struct ArrowArray`` in ``svsdk/arrow_abi.h``."""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
ARROW_ARRAY_RELEASE_FN = ctypes.CFUNCTYPE(None, ctypes.POINTER(ArrowArray))
|
|
78
|
+
|
|
79
|
+
ArrowArray._fields_ = [
|
|
80
|
+
("length", ctypes.c_int64),
|
|
81
|
+
("null_count", ctypes.c_int64),
|
|
82
|
+
("offset", ctypes.c_int64),
|
|
83
|
+
("n_buffers", ctypes.c_int64),
|
|
84
|
+
("n_children", ctypes.c_int64),
|
|
85
|
+
("buffers", ctypes.POINTER(ctypes.c_void_p)),
|
|
86
|
+
("children", ctypes.POINTER(ctypes.POINTER(ArrowArray))),
|
|
87
|
+
("dictionary", ctypes.POINTER(ArrowArray)),
|
|
88
|
+
("release", ctypes.c_void_p),
|
|
89
|
+
("private_data", ctypes.c_void_p),
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# ---------------------------------------------------------------------------
|
|
94
|
+
# C Plugin Vtable SPI Structure (svsdk/plugin_abi.h)
|
|
95
|
+
# ---------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
SVSDK_PLUGIN_PASS_FN = ctypes.CFUNCTYPE(
|
|
98
|
+
ctypes.c_int32, ctypes.c_void_p, ctypes.c_void_p
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class SvsdkPluginDescriptorV1(ctypes.Structure):
|
|
103
|
+
"""Byte-exact match for ``struct svsdk_plugin_descriptor_v1``."""
|
|
104
|
+
|
|
105
|
+
_fields_ = [
|
|
106
|
+
("abi_version", ctypes.c_uint32),
|
|
107
|
+
("struct_size", ctypes.c_uint32),
|
|
108
|
+
("id", ctypes.c_char_p),
|
|
109
|
+
("name", ctypes.c_char_p),
|
|
110
|
+
("version", ctypes.c_char_p),
|
|
111
|
+
("capabilities", ctypes.c_uint32),
|
|
112
|
+
("on_pass", ctypes.c_void_p),
|
|
113
|
+
("user_data", ctypes.c_void_p),
|
|
114
|
+
("reserved", ctypes.c_uint64 * 8),
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# ---------------------------------------------------------------------------
|
|
119
|
+
# All 39 Frozen C ABI v1.1 Symbols
|
|
120
|
+
# ---------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
BOUND_SYMBOLS: tuple[str, ...] = (
|
|
123
|
+
# Version, Error, and Heap String Lifecycle (5)
|
|
124
|
+
"svsdk_abi_version",
|
|
125
|
+
"svsdk_error_code",
|
|
126
|
+
"svsdk_error_message",
|
|
127
|
+
"svsdk_error_destroy",
|
|
128
|
+
"svsdk_string_destroy",
|
|
129
|
+
# Incremental Analysis Host & Immutable Snapshots (9)
|
|
130
|
+
"svsdk_host_create",
|
|
131
|
+
"svsdk_host_destroy",
|
|
132
|
+
"svsdk_host_set_file",
|
|
133
|
+
"svsdk_host_remove_file",
|
|
134
|
+
"svsdk_host_revision",
|
|
135
|
+
"svsdk_host_snapshot_take",
|
|
136
|
+
"svsdk_snapshot_destroy",
|
|
137
|
+
"svsdk_snapshot_revision",
|
|
138
|
+
"svsdk_snapshot_is_cancelled",
|
|
139
|
+
# Multi-Domain Design Graph, Overlays & Arrow Export (10)
|
|
140
|
+
"svsdk_snapshot_build_graph",
|
|
141
|
+
"svsdk_graph_destroy",
|
|
142
|
+
"svsdk_graph_entity_count",
|
|
143
|
+
"svsdk_graph_find_entity",
|
|
144
|
+
"svsdk_graph_export_entities_json",
|
|
145
|
+
"svsdk_graph_fanin_cone_json",
|
|
146
|
+
"svsdk_graph_explain_overlay_json",
|
|
147
|
+
"svsdk_graph_apply_overlay_str",
|
|
148
|
+
"svsdk_graph_power_crossings_json",
|
|
149
|
+
"svsdk_graph_export_entities_arrow",
|
|
150
|
+
# Opt-In Immutable .svdb Snapshot Persistence — ABI v1.1 Additive (3)
|
|
151
|
+
"svsdk_graph_save_svdb",
|
|
152
|
+
"svsdk_graph_load_svdb",
|
|
153
|
+
"svsdk_svdb_inspect_json",
|
|
154
|
+
# Static Linting & Macro-Aware Transactional AtomicChange (6)
|
|
155
|
+
"svsdk_snapshot_lint_file_json",
|
|
156
|
+
"svsdk_change_create",
|
|
157
|
+
"svsdk_change_destroy",
|
|
158
|
+
"svsdk_change_add_edit",
|
|
159
|
+
"svsdk_change_preview_json",
|
|
160
|
+
"svsdk_change_apply_to_host",
|
|
161
|
+
# Microkernel Plugin Registry & C Plugin SPI (6)
|
|
162
|
+
"svsdk_registry_create",
|
|
163
|
+
"svsdk_registry_destroy",
|
|
164
|
+
"svsdk_registry_register_builtins",
|
|
165
|
+
"svsdk_registry_register_c_plugin",
|
|
166
|
+
"svsdk_registry_list_json",
|
|
167
|
+
"svsdk_registry_run_passes",
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _platform_lib_names() -> tuple[str, ...]:
|
|
172
|
+
if sys.platform == "darwin":
|
|
173
|
+
return ("libsvlang_sdk_c.dylib",)
|
|
174
|
+
if sys.platform in ("win32", "cygwin"):
|
|
175
|
+
return ("svlang_sdk_c.dll", "libsvlang_sdk_c.dll")
|
|
176
|
+
return ("libsvlang_sdk_c.so",)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _candidate_library_paths() -> list[str]:
|
|
180
|
+
candidates: list[str] = []
|
|
181
|
+
lib_names = _platform_lib_names()
|
|
182
|
+
|
|
183
|
+
# 1) Exact file path override.
|
|
184
|
+
env_lib = os.environ.get("SVLANG_SDK_LIB")
|
|
185
|
+
if env_lib:
|
|
186
|
+
candidates.append(env_lib)
|
|
187
|
+
|
|
188
|
+
# 2) Directory override.
|
|
189
|
+
env_dir = os.environ.get("SVLANG_SDK_LIB_DIR")
|
|
190
|
+
if env_dir:
|
|
191
|
+
base = Path(env_dir)
|
|
192
|
+
for name in lib_names:
|
|
193
|
+
candidates.append(str(base / name))
|
|
194
|
+
|
|
195
|
+
# 3) Sibling repo build directories relative to this file:
|
|
196
|
+
# sdk/bindings/python/svlang_sdk/_ffi.py -> parents[3] == sdk/
|
|
197
|
+
here = Path(__file__).resolve()
|
|
198
|
+
if len(here.parents) >= 4:
|
|
199
|
+
sdk_root = here.parents[3]
|
|
200
|
+
for profile in ("release", "dev"):
|
|
201
|
+
build_dir = sdk_root / "build" / profile / "abi" / "c"
|
|
202
|
+
for name in lib_names:
|
|
203
|
+
candidates.append(str(build_dir / name))
|
|
204
|
+
|
|
205
|
+
# 4) Standard OS library search.
|
|
206
|
+
found = ctypes.util.find_library("svlang_sdk_c")
|
|
207
|
+
if found:
|
|
208
|
+
candidates.append(found)
|
|
209
|
+
candidates.extend(lib_names)
|
|
210
|
+
return candidates
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _configure_signatures(lib: ctypes.CDLL) -> None:
|
|
214
|
+
c_void_p = ctypes.c_void_p
|
|
215
|
+
c_char_p = ctypes.c_char_p
|
|
216
|
+
c_bool = ctypes.c_bool
|
|
217
|
+
c_uint8 = ctypes.c_uint8
|
|
218
|
+
c_int32 = ctypes.c_int32
|
|
219
|
+
c_uint32 = ctypes.c_uint32
|
|
220
|
+
c_uint64 = ctypes.c_uint64
|
|
221
|
+
c_size_t = ctypes.c_size_t
|
|
222
|
+
p_void = ctypes.POINTER(c_void_p)
|
|
223
|
+
p_u32 = ctypes.POINTER(c_uint32)
|
|
224
|
+
p_schema = ctypes.POINTER(ArrowSchema)
|
|
225
|
+
p_array = ctypes.POINTER(ArrowArray)
|
|
226
|
+
p_plugin = ctypes.POINTER(SvsdkPluginDescriptorV1)
|
|
227
|
+
|
|
228
|
+
# Version, Error, and Heap String Lifecycle
|
|
229
|
+
lib.svsdk_abi_version.argtypes = [p_u32, p_u32]
|
|
230
|
+
lib.svsdk_abi_version.restype = None
|
|
231
|
+
|
|
232
|
+
lib.svsdk_error_code.argtypes = [c_void_p]
|
|
233
|
+
lib.svsdk_error_code.restype = c_int32
|
|
234
|
+
|
|
235
|
+
lib.svsdk_error_message.argtypes = [c_void_p]
|
|
236
|
+
lib.svsdk_error_message.restype = c_char_p
|
|
237
|
+
|
|
238
|
+
lib.svsdk_error_destroy.argtypes = [c_void_p]
|
|
239
|
+
lib.svsdk_error_destroy.restype = None
|
|
240
|
+
|
|
241
|
+
lib.svsdk_string_destroy.argtypes = [c_void_p]
|
|
242
|
+
lib.svsdk_string_destroy.restype = None
|
|
243
|
+
|
|
244
|
+
# Incremental Analysis Host & Immutable Snapshots
|
|
245
|
+
lib.svsdk_host_create.argtypes = []
|
|
246
|
+
lib.svsdk_host_create.restype = c_void_p
|
|
247
|
+
|
|
248
|
+
lib.svsdk_host_destroy.argtypes = [c_void_p]
|
|
249
|
+
lib.svsdk_host_destroy.restype = None
|
|
250
|
+
|
|
251
|
+
lib.svsdk_host_set_file.argtypes = [
|
|
252
|
+
c_void_p,
|
|
253
|
+
c_char_p,
|
|
254
|
+
c_char_p,
|
|
255
|
+
c_size_t,
|
|
256
|
+
c_uint8,
|
|
257
|
+
p_void,
|
|
258
|
+
]
|
|
259
|
+
lib.svsdk_host_set_file.restype = c_int32
|
|
260
|
+
|
|
261
|
+
lib.svsdk_host_remove_file.argtypes = [c_void_p, c_char_p, p_void]
|
|
262
|
+
lib.svsdk_host_remove_file.restype = c_int32
|
|
263
|
+
|
|
264
|
+
lib.svsdk_host_revision.argtypes = [c_void_p]
|
|
265
|
+
lib.svsdk_host_revision.restype = c_uint64
|
|
266
|
+
|
|
267
|
+
lib.svsdk_host_snapshot_take.argtypes = [c_void_p, p_void, p_void]
|
|
268
|
+
lib.svsdk_host_snapshot_take.restype = c_int32
|
|
269
|
+
|
|
270
|
+
lib.svsdk_snapshot_destroy.argtypes = [c_void_p]
|
|
271
|
+
lib.svsdk_snapshot_destroy.restype = None
|
|
272
|
+
|
|
273
|
+
lib.svsdk_snapshot_revision.argtypes = [c_void_p]
|
|
274
|
+
lib.svsdk_snapshot_revision.restype = c_uint64
|
|
275
|
+
|
|
276
|
+
lib.svsdk_snapshot_is_cancelled.argtypes = [c_void_p]
|
|
277
|
+
lib.svsdk_snapshot_is_cancelled.restype = c_bool
|
|
278
|
+
|
|
279
|
+
# Multi-Domain Design Graph, Overlays & Arrow Export
|
|
280
|
+
lib.svsdk_snapshot_build_graph.argtypes = [c_void_p, c_char_p, p_void, p_void]
|
|
281
|
+
lib.svsdk_snapshot_build_graph.restype = c_int32
|
|
282
|
+
|
|
283
|
+
lib.svsdk_graph_destroy.argtypes = [c_void_p]
|
|
284
|
+
lib.svsdk_graph_destroy.restype = None
|
|
285
|
+
|
|
286
|
+
lib.svsdk_graph_entity_count.argtypes = [c_void_p]
|
|
287
|
+
lib.svsdk_graph_entity_count.restype = c_size_t
|
|
288
|
+
|
|
289
|
+
lib.svsdk_graph_find_entity.argtypes = [c_void_p, c_char_p, p_u32]
|
|
290
|
+
lib.svsdk_graph_find_entity.restype = c_int32
|
|
291
|
+
|
|
292
|
+
lib.svsdk_graph_export_entities_json.argtypes = [
|
|
293
|
+
c_void_p,
|
|
294
|
+
c_size_t,
|
|
295
|
+
c_size_t,
|
|
296
|
+
p_void,
|
|
297
|
+
p_void,
|
|
298
|
+
]
|
|
299
|
+
lib.svsdk_graph_export_entities_json.restype = c_int32
|
|
300
|
+
|
|
301
|
+
lib.svsdk_graph_fanin_cone_json.argtypes = [
|
|
302
|
+
c_void_p,
|
|
303
|
+
c_uint32,
|
|
304
|
+
c_uint32,
|
|
305
|
+
c_size_t,
|
|
306
|
+
c_size_t,
|
|
307
|
+
p_void,
|
|
308
|
+
p_void,
|
|
309
|
+
]
|
|
310
|
+
lib.svsdk_graph_fanin_cone_json.restype = c_int32
|
|
311
|
+
|
|
312
|
+
lib.svsdk_graph_explain_overlay_json.argtypes = [
|
|
313
|
+
c_void_p,
|
|
314
|
+
c_uint32,
|
|
315
|
+
c_char_p,
|
|
316
|
+
c_char_p,
|
|
317
|
+
p_void,
|
|
318
|
+
p_void,
|
|
319
|
+
]
|
|
320
|
+
lib.svsdk_graph_explain_overlay_json.restype = c_int32
|
|
321
|
+
|
|
322
|
+
lib.svsdk_graph_apply_overlay_str.argtypes = [
|
|
323
|
+
c_void_p,
|
|
324
|
+
c_uint32,
|
|
325
|
+
c_char_p,
|
|
326
|
+
c_char_p,
|
|
327
|
+
c_char_p,
|
|
328
|
+
c_char_p,
|
|
329
|
+
p_void,
|
|
330
|
+
]
|
|
331
|
+
lib.svsdk_graph_apply_overlay_str.restype = c_int32
|
|
332
|
+
|
|
333
|
+
lib.svsdk_graph_power_crossings_json.argtypes = [c_void_p, p_void, p_void]
|
|
334
|
+
lib.svsdk_graph_power_crossings_json.restype = c_int32
|
|
335
|
+
|
|
336
|
+
lib.svsdk_graph_export_entities_arrow.argtypes = [
|
|
337
|
+
c_void_p,
|
|
338
|
+
p_schema,
|
|
339
|
+
p_array,
|
|
340
|
+
p_void,
|
|
341
|
+
]
|
|
342
|
+
lib.svsdk_graph_export_entities_arrow.restype = c_int32
|
|
343
|
+
|
|
344
|
+
# Opt-In Immutable .svdb Snapshot Persistence (ABI v1.1 Additive)
|
|
345
|
+
lib.svsdk_graph_save_svdb.argtypes = [c_void_p, c_char_p, p_void]
|
|
346
|
+
lib.svsdk_graph_save_svdb.restype = c_int32
|
|
347
|
+
|
|
348
|
+
lib.svsdk_graph_load_svdb.argtypes = [c_char_p, p_void, p_void]
|
|
349
|
+
lib.svsdk_graph_load_svdb.restype = c_int32
|
|
350
|
+
|
|
351
|
+
lib.svsdk_svdb_inspect_json.argtypes = [c_char_p, p_void, p_void]
|
|
352
|
+
lib.svsdk_svdb_inspect_json.restype = c_int32
|
|
353
|
+
|
|
354
|
+
# Static Linting & Macro-Aware Transactional AtomicChange
|
|
355
|
+
lib.svsdk_snapshot_lint_file_json.argtypes = [c_void_p, c_char_p, p_void, p_void]
|
|
356
|
+
lib.svsdk_snapshot_lint_file_json.restype = c_int32
|
|
357
|
+
|
|
358
|
+
lib.svsdk_change_create.argtypes = [c_char_p]
|
|
359
|
+
lib.svsdk_change_create.restype = c_void_p
|
|
360
|
+
|
|
361
|
+
lib.svsdk_change_destroy.argtypes = [c_void_p]
|
|
362
|
+
lib.svsdk_change_destroy.restype = None
|
|
363
|
+
|
|
364
|
+
lib.svsdk_change_add_edit.argtypes = [
|
|
365
|
+
c_void_p,
|
|
366
|
+
c_char_p,
|
|
367
|
+
c_uint32,
|
|
368
|
+
c_uint32,
|
|
369
|
+
c_char_p,
|
|
370
|
+
c_bool,
|
|
371
|
+
c_char_p,
|
|
372
|
+
]
|
|
373
|
+
lib.svsdk_change_add_edit.restype = c_int32
|
|
374
|
+
|
|
375
|
+
lib.svsdk_change_preview_json.argtypes = [
|
|
376
|
+
c_void_p,
|
|
377
|
+
c_void_p,
|
|
378
|
+
c_bool,
|
|
379
|
+
c_bool,
|
|
380
|
+
p_void,
|
|
381
|
+
p_void,
|
|
382
|
+
]
|
|
383
|
+
lib.svsdk_change_preview_json.restype = c_int32
|
|
384
|
+
|
|
385
|
+
lib.svsdk_change_apply_to_host.argtypes = [
|
|
386
|
+
c_void_p,
|
|
387
|
+
c_void_p,
|
|
388
|
+
c_bool,
|
|
389
|
+
c_bool,
|
|
390
|
+
p_void,
|
|
391
|
+
p_void,
|
|
392
|
+
]
|
|
393
|
+
lib.svsdk_change_apply_to_host.restype = c_int32
|
|
394
|
+
|
|
395
|
+
# Microkernel Plugin Registry & C Plugin SPI
|
|
396
|
+
lib.svsdk_registry_create.argtypes = []
|
|
397
|
+
lib.svsdk_registry_create.restype = c_void_p
|
|
398
|
+
|
|
399
|
+
lib.svsdk_registry_destroy.argtypes = [c_void_p]
|
|
400
|
+
lib.svsdk_registry_destroy.restype = None
|
|
401
|
+
|
|
402
|
+
lib.svsdk_registry_register_builtins.argtypes = [c_void_p, p_void]
|
|
403
|
+
lib.svsdk_registry_register_builtins.restype = c_int32
|
|
404
|
+
|
|
405
|
+
lib.svsdk_registry_register_c_plugin.argtypes = [c_void_p, p_plugin, p_void]
|
|
406
|
+
lib.svsdk_registry_register_c_plugin.restype = c_int32
|
|
407
|
+
|
|
408
|
+
lib.svsdk_registry_list_json.argtypes = [c_void_p, p_void, p_void]
|
|
409
|
+
lib.svsdk_registry_list_json.restype = c_int32
|
|
410
|
+
|
|
411
|
+
lib.svsdk_registry_run_passes.argtypes = [c_void_p, c_void_p, p_void]
|
|
412
|
+
lib.svsdk_registry_run_passes.restype = c_int32
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
_CACHED_LIB: Optional[ctypes.CDLL] = None
|
|
416
|
+
_CACHED_LIB_PATH: Optional[str] = None
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def load_lib(path: Optional[str] = None) -> ctypes.CDLL:
|
|
420
|
+
"""Load ``libsvlang_sdk_c`` from an explicit path or standard discovery order."""
|
|
421
|
+
if path is not None:
|
|
422
|
+
lib = ctypes.CDLL(path)
|
|
423
|
+
_configure_signatures(lib)
|
|
424
|
+
return lib
|
|
425
|
+
|
|
426
|
+
errors: list[str] = []
|
|
427
|
+
for candidate in _candidate_library_paths():
|
|
428
|
+
# Skip non-existent filesystem paths eagerly so bare OS names still run.
|
|
429
|
+
if os.sep in candidate or (os.altsep and os.altsep in candidate):
|
|
430
|
+
if not os.path.isfile(candidate):
|
|
431
|
+
errors.append(f" - {candidate} (not found)")
|
|
432
|
+
continue
|
|
433
|
+
try:
|
|
434
|
+
lib = ctypes.CDLL(candidate)
|
|
435
|
+
_configure_signatures(lib)
|
|
436
|
+
global _CACHED_LIB_PATH
|
|
437
|
+
_CACHED_LIB_PATH = candidate
|
|
438
|
+
return lib
|
|
439
|
+
except OSError as exc:
|
|
440
|
+
errors.append(f" - {candidate} ({exc})")
|
|
441
|
+
|
|
442
|
+
detail = "\n".join(errors)
|
|
443
|
+
raise OSError(
|
|
444
|
+
"Failed to locate libsvlang_sdk_c shared library. Set SVLANG_SDK_LIB or "
|
|
445
|
+
"SVLANG_SDK_LIB_DIR, or build sdk/build/release.\nSearched:\n" + detail
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def get_lib() -> ctypes.CDLL:
|
|
450
|
+
"""Return the process-wide cached ``libsvlang_sdk_c`` handle."""
|
|
451
|
+
global _CACHED_LIB
|
|
452
|
+
if _CACHED_LIB is None:
|
|
453
|
+
_CACHED_LIB = load_lib()
|
|
454
|
+
return _CACHED_LIB
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def loaded_library_path() -> Optional[str]:
|
|
458
|
+
"""Return the resolved path/name of the currently loaded shared library."""
|
|
459
|
+
get_lib()
|
|
460
|
+
return _CACHED_LIB_PATH
|