cseq 0.0.1__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.
Files changed (106) hide show
  1. cseq-0.0.1/PKG-INFO +181 -0
  2. cseq-0.0.1/README.md +171 -0
  3. cseq-0.0.1/pyproject.toml +23 -0
  4. cseq-0.0.1/setup.cfg +4 -0
  5. cseq-0.0.1/src/cseq/__init__.py +9 -0
  6. cseq-0.0.1/src/cseq/acceptance.py +162 -0
  7. cseq-0.0.1/src/cseq/api.py +328 -0
  8. cseq-0.0.1/src/cseq/binary.py +122 -0
  9. cseq-0.0.1/src/cseq/cache.py +420 -0
  10. cseq-0.0.1/src/cseq/cli.py +895 -0
  11. cseq-0.0.1/src/cseq/compile_db.py +98 -0
  12. cseq-0.0.1/src/cseq/config.py +138 -0
  13. cseq-0.0.1/src/cseq/cpu_rules.py +48 -0
  14. cseq-0.0.1/src/cseq/dependencies.py +202 -0
  15. cseq-0.0.1/src/cseq/docs.py +21 -0
  16. cseq-0.0.1/src/cseq/dwarf.py +115 -0
  17. cseq-0.0.1/src/cseq/event_store.py +378 -0
  18. cseq-0.0.1/src/cseq/explain.py +113 -0
  19. cseq-0.0.1/src/cseq/fast_parser.py +286 -0
  20. cseq-0.0.1/src/cseq/html.py +485 -0
  21. cseq-0.0.1/src/cseq/html_bundle.py +464 -0
  22. cseq-0.0.1/src/cseq/hybrid_parser.py +120 -0
  23. cseq-0.0.1/src/cseq/linker.py +117 -0
  24. cseq-0.0.1/src/cseq/marker.py +294 -0
  25. cseq-0.0.1/src/cseq/model.py +367 -0
  26. cseq-0.0.1/src/cseq/parser.py +797 -0
  27. cseq-0.0.1/src/cseq/parser_contract_cases.json +69 -0
  28. cseq-0.0.1/src/cseq/parser_dependency_lock.json +59 -0
  29. cseq-0.0.1/src/cseq/parser_environment.py +186 -0
  30. cseq-0.0.1/src/cseq/parser_migration.py +126 -0
  31. cseq-0.0.1/src/cseq/plugin.py +216 -0
  32. cseq-0.0.1/src/cseq/project.py +305 -0
  33. cseq-0.0.1/src/cseq/query.py +62 -0
  34. cseq-0.0.1/src/cseq/resources/README.md +171 -0
  35. cseq-0.0.1/src/cseq/resources/design.md +6197 -0
  36. cseq-0.0.1/src/cseq/resources/verification_report.html +26 -0
  37. cseq-0.0.1/src/cseq/runtime.py +177 -0
  38. cseq-0.0.1/src/cseq/runtime_address.py +79 -0
  39. cseq-0.0.1/src/cseq/runtime_cpu.py +87 -0
  40. cseq-0.0.1/src/cseq/scanner.py +54 -0
  41. cseq-0.0.1/src/cseq/sequence.py +281 -0
  42. cseq-0.0.1/src/cseq/server.py +104 -0
  43. cseq-0.0.1/src/cseq/source_index.py +227 -0
  44. cseq-0.0.1/src/cseq/static_store.py +280 -0
  45. cseq-0.0.1/src/cseq/trace_analysis.py +336 -0
  46. cseq-0.0.1/src/cseq/trace_diff.py +56 -0
  47. cseq-0.0.1/src/cseq/tree_sitter_parser.py +468 -0
  48. cseq-0.0.1/src/cseq/valueflow.py +179 -0
  49. cseq-0.0.1/src/cseq.egg-info/PKG-INFO +181 -0
  50. cseq-0.0.1/src/cseq.egg-info/SOURCES.txt +104 -0
  51. cseq-0.0.1/src/cseq.egg-info/dependency_links.txt +1 -0
  52. cseq-0.0.1/src/cseq.egg-info/entry_points.txt +2 -0
  53. cseq-0.0.1/src/cseq.egg-info/requires.txt +4 -0
  54. cseq-0.0.1/src/cseq.egg-info/top_level.txt +1 -0
  55. cseq-0.0.1/tests/test_acceptance.py +24 -0
  56. cseq-0.0.1/tests/test_alias_tier3.py +73 -0
  57. cseq-0.0.1/tests/test_analysis_cache.py +46 -0
  58. cseq-0.0.1/tests/test_binary.py +51 -0
  59. cseq-0.0.1/tests/test_cache.py +70 -0
  60. cseq-0.0.1/tests/test_cli.py +267 -0
  61. cseq-0.0.1/tests/test_compile_db.py +74 -0
  62. cseq-0.0.1/tests/test_config_cli_api.py +82 -0
  63. cseq-0.0.1/tests/test_cpu_rules.py +37 -0
  64. cseq-0.0.1/tests/test_differential.py +30 -0
  65. cseq-0.0.1/tests/test_dwarf.py +48 -0
  66. cseq-0.0.1/tests/test_event_store.py +92 -0
  67. cseq-0.0.1/tests/test_explain.py +23 -0
  68. cseq-0.0.1/tests/test_fast_compact_table.py +40 -0
  69. cseq-0.0.1/tests/test_folding_semantic.py +25 -0
  70. cseq-0.0.1/tests/test_fuzz.py +172 -0
  71. cseq-0.0.1/tests/test_golden.py +89 -0
  72. cseq-0.0.1/tests/test_guarded_regions.py +67 -0
  73. cseq-0.0.1/tests/test_html.py +23 -0
  74. cseq-0.0.1/tests/test_html_advanced.py +74 -0
  75. cseq-0.0.1/tests/test_html_bundle.py +62 -0
  76. cseq-0.0.1/tests/test_html_folding.py +23 -0
  77. cseq-0.0.1/tests/test_html_range_bundle.py +90 -0
  78. cseq-0.0.1/tests/test_html_runtime.py +74 -0
  79. cseq-0.0.1/tests/test_hybrid_parser.py +94 -0
  80. cseq-0.0.1/tests/test_linker_map.py +55 -0
  81. cseq-0.0.1/tests/test_marker.py +83 -0
  82. cseq-0.0.1/tests/test_parallel_cli.py +11 -0
  83. cseq-0.0.1/tests/test_parallel_parse.py +40 -0
  84. cseq-0.0.1/tests/test_parser.py +73 -0
  85. cseq-0.0.1/tests/test_parser_environment.py +89 -0
  86. cseq-0.0.1/tests/test_parser_migration.py +53 -0
  87. cseq-0.0.1/tests/test_plugin.py +131 -0
  88. cseq-0.0.1/tests/test_preprocessor_guard.py +66 -0
  89. cseq-0.0.1/tests/test_project_cache.py +108 -0
  90. cseq-0.0.1/tests/test_property.py +119 -0
  91. cseq-0.0.1/tests/test_query.py +24 -0
  92. cseq-0.0.1/tests/test_runtime.py +57 -0
  93. cseq-0.0.1/tests/test_runtime_address.py +81 -0
  94. cseq-0.0.1/tests/test_runtime_cpu_evidence.py +80 -0
  95. cseq-0.0.1/tests/test_scanner.py +10 -0
  96. cseq-0.0.1/tests/test_sequence.py +49 -0
  97. cseq-0.0.1/tests/test_sequence_regions.py +52 -0
  98. cseq-0.0.1/tests/test_server.py +57 -0
  99. cseq-0.0.1/tests/test_source_index.py +87 -0
  100. cseq-0.0.1/tests/test_static_store.py +248 -0
  101. cseq-0.0.1/tests/test_switch_regions.py +48 -0
  102. cseq-0.0.1/tests/test_trace_analysis.py +149 -0
  103. cseq-0.0.1/tests/test_trace_diff.py +31 -0
  104. cseq-0.0.1/tests/test_tree_sitter_large_tu.py +35 -0
  105. cseq-0.0.1/tests/test_tree_sitter_parser_contract.py +50 -0
  106. cseq-0.0.1/tests/test_valueflow.py +63 -0
cseq-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: cseq
3
+ Version: 0.0.1
4
+ Summary: C source sequence analysis tool PoC
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Provides-Extra: parser-tree-sitter
8
+ Requires-Dist: tree-sitter==0.26.0; extra == "parser-tree-sitter"
9
+ Requires-Dist: tree-sitter-c==0.24.2; extra == "parser-tree-sitter"
10
+
11
+ # cseq
12
+
13
+ Cソースツリーから関数呼出し・分岐・コールバック・実行時markerを解析し、PlantUMLとインタラクティブHTMLを生成するシーケンス解析ツールです。
14
+
15
+ 初回リリースは **Windows + Python 3.11以上** を主対象とします。Tree-sitterを高速な構文フロントエンドとして使用し、型・macro・関数ポインタ等で意味解析が必要な翻訳単位だけClangへ送ります。
16
+
17
+ ## 主な機能
18
+
19
+ - ディレクトリ以下の `.c` / `.h` を再帰走査
20
+ - entry関数からのシーケンス生成
21
+ - 同名`static`関数を区別
22
+ - 外部未定義関数を内部calleeとして誤認しない
23
+ - `#if/#ifdef`、macro、compiler extensionのfail-soft解析
24
+ - 関数ポインタ、callback、dispatch tableの候補解決
25
+ - if/else、loop、無限loop、switch/case/defaultをSequence IRへ保持
26
+ - RTOS風の無限loopを有限表現
27
+ - CPU group / build configurationを外部設定可能
28
+ - runtime markerログの読込み、CPU/task evidence、静的経路との照合
29
+ - marker自動注入: source直接書換え / Overlay(原本非変更)の両方式
30
+ - PlantUML出力
31
+ - HTML UI: 検索、viewport、LOD、Canvas表示、path query、trace diff、marker suggestion
32
+ - 大きいruntime trace向けbundle/range出力
33
+ - optional linker map / binary symbol / DWARF evidence
34
+
35
+ ## Windowsでの導入
36
+
37
+ PowerShell例です。
38
+
39
+ ```powershell
40
+ py -3.12 -m venv .venv
41
+ .\.venv\Scripts\Activate.ps1
42
+ python -m pip install --upgrade pip
43
+ pip install "cseq[parser-tree-sitter]"
44
+ ```
45
+
46
+ ローカルwheelから導入する場合:
47
+
48
+ ```powershell
49
+ pip install .\cseq-0.0.1-py3-none-any.whl[parser-tree-sitter]
50
+ ```
51
+
52
+ ### Clang
53
+
54
+ 単純なC構文だけならTree-sitterで解析できますが、macro、関数ポインタ、型曖昧性、compiler extension等のselective semantic refinementにはClangを推奨します。
55
+
56
+ ```powershell
57
+ winget install --id LLVM.LLVM --exact
58
+ ```
59
+
60
+ 確認:
61
+
62
+ ```powershell
63
+ cseq doctor
64
+ ```
65
+
66
+ `current_execution_mode` が `tree-sitter+clang` なら両backendを利用できます。
67
+
68
+ ## 最短利用例
69
+
70
+ ```powershell
71
+ cseq analyze C:\path\to\project --entry main --json
72
+ cseq plantuml C:\path\to\project --entry main --output sequence.puml
73
+ cseq html C:\path\to\project --entry main --output sequence.html --mode auto
74
+ ```
75
+
76
+ HTMLは小規模時はportable単一HTML、中規模以上ではbundle/rangeへ切替できます。
77
+
78
+ ```powershell
79
+ cseq serve . --port 8000
80
+ ```
81
+
82
+ range/bundleをブラウザで確認する際はローカルHTTP配信を推奨します。
83
+
84
+ ## プロジェクト設定
85
+
86
+ ```powershell
87
+ cseq config init C:\path\to\project
88
+ cseq config validate C:\path\to\project\cseq.toml
89
+ ```
90
+
91
+ `cseq.toml`でentry、compile database、CPU group、build configuration等をプロジェクト固有名に合わせて設定します。cseq本体は特定企業・CPU名称を前提にしません。
92
+
93
+ `compile_commands.json` がある場合はClang semantic解析の精度向上に利用できます。
94
+
95
+ ## Runtime marker
96
+
97
+ ### 直接書換え
98
+
99
+ ```powershell
100
+ cseq marker apply .\src\worker.c --contains "rx=%d" --id RX01 --manifest .\rx01.json
101
+ ```
102
+
103
+ manifestにbefore/after hashを保存し、安全条件が成立するときだけundoできます。
104
+
105
+ ```powershell
106
+ cseq marker undo .\src\worker.c --manifest .\rx01.json
107
+ ```
108
+
109
+ ### Overlay(原本非変更)
110
+
111
+ ```powershell
112
+ cseq marker apply .\src\worker.c `
113
+ --contains "rx=%d" `
114
+ --id RX01 `
115
+ --manifest .\rx01-overlay.json `
116
+ --overlay-output .\cseq-overlay\worker.c
117
+ ```
118
+
119
+ 元sourceは変更されず、marker注入済みコピーだけを生成します。
120
+
121
+ ## Runtime log
122
+
123
+ marker形式:
124
+
125
+ ```text
126
+ [[CSEQ:RX01]] message...
127
+ ```
128
+
129
+ ログ形式は固定ではなくpatternで指定できます。
130
+
131
+ ```powershell
132
+ cseq trace import run.log `
133
+ --pattern "[{cpu}] {time} {message}" `
134
+ --time-format "%H:%M:%S.%f" `
135
+ --json
136
+ ```
137
+
138
+ CPU間で時刻が隣接しているだけでは因果関係とはみなしません。marker、payload、静的path等のevidenceを分離して扱います。
139
+
140
+ ## HTML UI
141
+
142
+ ```powershell
143
+ cseq html C:\path\to\project `
144
+ --entry main `
145
+ --runtime-log run.log `
146
+ --runtime-pattern "[{cpu}] {time} {message}" `
147
+ --runtime-time-format "%H:%M:%S.%f" `
148
+ --output sequence.html `
149
+ --mode auto
150
+ ```
151
+
152
+ UIは大量eventを全DOM化せず、viewport/LOD/Canvas/range bundleを使います。初回リリースでは深い性能チューニングより、汎用性・正しさ・必要UIを優先します。
153
+
154
+ ## 設計上の原則
155
+
156
+ - Silent Dropしない。解析不能領域はPARTIAL/OPAQUE等で明示する。
157
+ - static possible と runtime observed を混同しない。
158
+ - CPUのstatic/build/runtime evidenceを分離する。
159
+ - cross-CPU timestamp adjacencyだけで因果を断定しない。
160
+ - Tree-sitterとClangは代替関係ではなく、Fast Syntax + Selective Semantic Refinementとして併用する。
161
+
162
+ ## 開発時検証
163
+
164
+ ```powershell
165
+ python -m pytest -q
166
+ ```
167
+
168
+ Windows実機で全テスト、Tree-sitter/Clang統合acceptance、clean wheel installを確認してからrelease候補を作成します。
169
+
170
+ ## 同梱ドキュメントの出力
171
+
172
+ インストール済みwheelから、README・設計書(清書版)・実装/検証成績書を1コマンドで取り出せます。
173
+
174
+ ```powershell
175
+ cseq docs readme --output README.md
176
+ cseq docs design --output シーケンス解析_設計書.md
177
+ cseq docs report --output 実装・検証成績書.html
178
+ cseq docs all --output-dir .\cseq-docs
179
+ ```
180
+
181
+ `--output`を省略するとREADME/設計書/成績書の内容を標準出力します。`docs all` は3点を一括で出力します。
cseq-0.0.1/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # cseq
2
+
3
+ Cソースツリーから関数呼出し・分岐・コールバック・実行時markerを解析し、PlantUMLとインタラクティブHTMLを生成するシーケンス解析ツールです。
4
+
5
+ 初回リリースは **Windows + Python 3.11以上** を主対象とします。Tree-sitterを高速な構文フロントエンドとして使用し、型・macro・関数ポインタ等で意味解析が必要な翻訳単位だけClangへ送ります。
6
+
7
+ ## 主な機能
8
+
9
+ - ディレクトリ以下の `.c` / `.h` を再帰走査
10
+ - entry関数からのシーケンス生成
11
+ - 同名`static`関数を区別
12
+ - 外部未定義関数を内部calleeとして誤認しない
13
+ - `#if/#ifdef`、macro、compiler extensionのfail-soft解析
14
+ - 関数ポインタ、callback、dispatch tableの候補解決
15
+ - if/else、loop、無限loop、switch/case/defaultをSequence IRへ保持
16
+ - RTOS風の無限loopを有限表現
17
+ - CPU group / build configurationを外部設定可能
18
+ - runtime markerログの読込み、CPU/task evidence、静的経路との照合
19
+ - marker自動注入: source直接書換え / Overlay(原本非変更)の両方式
20
+ - PlantUML出力
21
+ - HTML UI: 検索、viewport、LOD、Canvas表示、path query、trace diff、marker suggestion
22
+ - 大きいruntime trace向けbundle/range出力
23
+ - optional linker map / binary symbol / DWARF evidence
24
+
25
+ ## Windowsでの導入
26
+
27
+ PowerShell例です。
28
+
29
+ ```powershell
30
+ py -3.12 -m venv .venv
31
+ .\.venv\Scripts\Activate.ps1
32
+ python -m pip install --upgrade pip
33
+ pip install "cseq[parser-tree-sitter]"
34
+ ```
35
+
36
+ ローカルwheelから導入する場合:
37
+
38
+ ```powershell
39
+ pip install .\cseq-0.0.1-py3-none-any.whl[parser-tree-sitter]
40
+ ```
41
+
42
+ ### Clang
43
+
44
+ 単純なC構文だけならTree-sitterで解析できますが、macro、関数ポインタ、型曖昧性、compiler extension等のselective semantic refinementにはClangを推奨します。
45
+
46
+ ```powershell
47
+ winget install --id LLVM.LLVM --exact
48
+ ```
49
+
50
+ 確認:
51
+
52
+ ```powershell
53
+ cseq doctor
54
+ ```
55
+
56
+ `current_execution_mode` が `tree-sitter+clang` なら両backendを利用できます。
57
+
58
+ ## 最短利用例
59
+
60
+ ```powershell
61
+ cseq analyze C:\path\to\project --entry main --json
62
+ cseq plantuml C:\path\to\project --entry main --output sequence.puml
63
+ cseq html C:\path\to\project --entry main --output sequence.html --mode auto
64
+ ```
65
+
66
+ HTMLは小規模時はportable単一HTML、中規模以上ではbundle/rangeへ切替できます。
67
+
68
+ ```powershell
69
+ cseq serve . --port 8000
70
+ ```
71
+
72
+ range/bundleをブラウザで確認する際はローカルHTTP配信を推奨します。
73
+
74
+ ## プロジェクト設定
75
+
76
+ ```powershell
77
+ cseq config init C:\path\to\project
78
+ cseq config validate C:\path\to\project\cseq.toml
79
+ ```
80
+
81
+ `cseq.toml`でentry、compile database、CPU group、build configuration等をプロジェクト固有名に合わせて設定します。cseq本体は特定企業・CPU名称を前提にしません。
82
+
83
+ `compile_commands.json` がある場合はClang semantic解析の精度向上に利用できます。
84
+
85
+ ## Runtime marker
86
+
87
+ ### 直接書換え
88
+
89
+ ```powershell
90
+ cseq marker apply .\src\worker.c --contains "rx=%d" --id RX01 --manifest .\rx01.json
91
+ ```
92
+
93
+ manifestにbefore/after hashを保存し、安全条件が成立するときだけundoできます。
94
+
95
+ ```powershell
96
+ cseq marker undo .\src\worker.c --manifest .\rx01.json
97
+ ```
98
+
99
+ ### Overlay(原本非変更)
100
+
101
+ ```powershell
102
+ cseq marker apply .\src\worker.c `
103
+ --contains "rx=%d" `
104
+ --id RX01 `
105
+ --manifest .\rx01-overlay.json `
106
+ --overlay-output .\cseq-overlay\worker.c
107
+ ```
108
+
109
+ 元sourceは変更されず、marker注入済みコピーだけを生成します。
110
+
111
+ ## Runtime log
112
+
113
+ marker形式:
114
+
115
+ ```text
116
+ [[CSEQ:RX01]] message...
117
+ ```
118
+
119
+ ログ形式は固定ではなくpatternで指定できます。
120
+
121
+ ```powershell
122
+ cseq trace import run.log `
123
+ --pattern "[{cpu}] {time} {message}" `
124
+ --time-format "%H:%M:%S.%f" `
125
+ --json
126
+ ```
127
+
128
+ CPU間で時刻が隣接しているだけでは因果関係とはみなしません。marker、payload、静的path等のevidenceを分離して扱います。
129
+
130
+ ## HTML UI
131
+
132
+ ```powershell
133
+ cseq html C:\path\to\project `
134
+ --entry main `
135
+ --runtime-log run.log `
136
+ --runtime-pattern "[{cpu}] {time} {message}" `
137
+ --runtime-time-format "%H:%M:%S.%f" `
138
+ --output sequence.html `
139
+ --mode auto
140
+ ```
141
+
142
+ UIは大量eventを全DOM化せず、viewport/LOD/Canvas/range bundleを使います。初回リリースでは深い性能チューニングより、汎用性・正しさ・必要UIを優先します。
143
+
144
+ ## 設計上の原則
145
+
146
+ - Silent Dropしない。解析不能領域はPARTIAL/OPAQUE等で明示する。
147
+ - static possible と runtime observed を混同しない。
148
+ - CPUのstatic/build/runtime evidenceを分離する。
149
+ - cross-CPU timestamp adjacencyだけで因果を断定しない。
150
+ - Tree-sitterとClangは代替関係ではなく、Fast Syntax + Selective Semantic Refinementとして併用する。
151
+
152
+ ## 開発時検証
153
+
154
+ ```powershell
155
+ python -m pytest -q
156
+ ```
157
+
158
+ Windows実機で全テスト、Tree-sitter/Clang統合acceptance、clean wheel installを確認してからrelease候補を作成します。
159
+
160
+ ## 同梱ドキュメントの出力
161
+
162
+ インストール済みwheelから、README・設計書(清書版)・実装/検証成績書を1コマンドで取り出せます。
163
+
164
+ ```powershell
165
+ cseq docs readme --output README.md
166
+ cseq docs design --output シーケンス解析_設計書.md
167
+ cseq docs report --output 実装・検証成績書.html
168
+ cseq docs all --output-dir .\cseq-docs
169
+ ```
170
+
171
+ `--output`を省略するとREADME/設計書/成績書の内容を標準出力します。`docs all` は3点を一括で出力します。
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cseq"
7
+ version = "0.0.1"
8
+ description = "C source sequence analysis tool PoC"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+
12
+ [project.optional-dependencies]
13
+ parser-tree-sitter = ["tree-sitter==0.26.0", "tree-sitter-c==0.24.2"]
14
+
15
+ [project.scripts]
16
+ cseq = "cseq.cli:main"
17
+
18
+ [tool.pytest.ini_options]
19
+ pythonpath = ["src"]
20
+ testpaths = ["tests"]
21
+
22
+ [tool.setuptools.package-data]
23
+ cseq = ["parser_dependency_lock.json", "parser_contract_cases.json", "resources/*.md", "resources/*.html"]
cseq-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ """cseq: C source sequence analysis tool."""
2
+
3
+ __version__ = "0.0.1"
4
+
5
+ from .api import Analysis, Explanation, MarkerSuggestion, QueryResult, RuntimeSession, analyze
6
+
7
+ __all__ = [
8
+ "Analysis", "Explanation", "MarkerSuggestion", "QueryResult", "RuntimeSession", "analyze", "__version__"
9
+ ]
@@ -0,0 +1,162 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict, dataclass
4
+ from pathlib import Path
5
+ import shutil
6
+
7
+ from .explain import explain_call
8
+ from .html import build_html_payload
9
+ from .marker import apply_marker, apply_marker_overlay, undo_marker
10
+ from .model import CallTargetKind
11
+ from .project import Project
12
+ from .runtime import RuntimePattern, build_trace_session
13
+ from .sequence import build_sequence, render_plantuml
14
+ from .trace_analysis import ReconstructionState, reconstruct_static_paths
15
+
16
+
17
+ @dataclass(frozen=True, slots=True)
18
+ class AcceptanceCriterion:
19
+ criterion_id: str
20
+ name: str
21
+ status: str
22
+ evidence: str
23
+ detail: str = ""
24
+
25
+
26
+ @dataclass(frozen=True, slots=True)
27
+ class AcceptanceReport:
28
+ criteria: tuple[AcceptanceCriterion, ...]
29
+
30
+ @property
31
+ def functional_pass(self) -> bool:
32
+ return all(c.status == "PASS" for c in self.criteria if c.status != "DEFERRED_TO_LATER_GATE")
33
+
34
+ def to_dict(self) -> dict:
35
+ return {
36
+ "functional_pass": self.functional_pass,
37
+ "criteria": [asdict(c) for c in self.criteria],
38
+ }
39
+
40
+
41
+ def run_poc_functional_acceptance(fixtures_root: str | Path, work_root: str | Path) -> AcceptanceReport:
42
+ fixtures = Path(fixtures_root)
43
+ work = Path(work_root)
44
+ work.mkdir(parents=True, exist_ok=True)
45
+ criteria: list[AcceptanceCriterion] = []
46
+
47
+ # A/B: direct call + external separation.
48
+ basic = Project(fixtures / "basic", use_cache=False).index()
49
+ calls = {(c.caller_name, c.callee_name): c for c in basic.callsites}
50
+ direct_ok = (
51
+ calls[("main", "helper")].target_kind == CallTargetKind.INTERNAL_EXACT
52
+ and calls[("main", "printf")].target_kind == CallTargetKind.EXTERNAL_DECLARED
53
+ )
54
+ criteria.append(AcceptanceCriterion(
55
+ "POC-01", "Direct Call基本精度とExternal分離",
56
+ "PASS" if direct_ok else "FAIL", "fixtures/basic",
57
+ ))
58
+
59
+ # C/D/E: indirect target explanation.
60
+ fptr = Project(fixtures / "fptr_local", use_cache=False).index()
61
+ explanation = explain_call(fptr, caller="run")
62
+ indirect_calls = [c for c in explanation.get("calls", []) if c.get("resolution", "").startswith("INDIRECT")]
63
+ indirect_ok = bool(indirect_calls) and all(c.get("targets") for c in indirect_calls) and any(c.get("value_flow") for c in indirect_calls)
64
+ criteria.append(AcceptanceCriterion(
65
+ "POC-02", "Indirect Callbackを理由付きで説明可能",
66
+ "PASS" if indirect_ok else "FAIL", "fixtures/fptr_local + explain_call",
67
+ ))
68
+
69
+ # L/M: unknown syntax does not drop surrounding functions.
70
+ unknown = Project(fixtures / "unknown_compiler", use_cache=False).index()
71
+ names = {f.name for f in unknown.functions()}
72
+ opaque_count = sum(len(a.opaque_regions) for a in unknown.parse_artifacts)
73
+ unknown_ok = {"helper", "main"} <= names and opaque_count >= 1
74
+ criteria.append(AcceptanceCriterion(
75
+ "POC-03", "未知構文でも解析可能部分を保持",
76
+ "PASS" if unknown_ok else "FAIL", "fixtures/unknown_compiler",
77
+ f"functions={sorted(names)}, opaque_regions={opaque_count}",
78
+ ))
79
+
80
+ # H: finite representation of infinite loop.
81
+ rtos = Project(fixtures / "rtos_infinite", use_cache=False).index()
82
+ rtos_model = build_sequence(rtos, "main")
83
+ puml = render_plantuml(rtos_model)
84
+ rtos_ok = "loop [infinite]" in puml and puml.count("dispatch()") == 1
85
+ criteria.append(AcceptanceCriterion(
86
+ "POC-04", "RTOS無限loopを有限表示",
87
+ "PASS" if rtos_ok else "FAIL", "fixtures/rtos_infinite + PlantUML",
88
+ ))
89
+
90
+ # I: runtime observation + static reconstruction.
91
+ pattern = RuntimePattern("[{cpu}] {time} {message}", "%H:%M:%S.%f")
92
+ session = build_trace_session("acceptance", [fixtures / "runtime" / "a.log", fixtures / "runtime" / "b.log"], pattern=pattern)
93
+ recon_index = Project(fixtures / "reconstruction" / "unique", use_cache=False).index()
94
+ reconstruction = reconstruct_static_paths(recon_index, "a", "f")
95
+ runtime_ok = len(session.events) == 3 and reconstruction.state == ReconstructionState.EXACT_PATH
96
+ criteria.append(AcceptanceCriterion(
97
+ "POC-05", "Runtime Marker観測と静的経路復元",
98
+ "PASS" if runtime_ok else "FAIL", "fixtures/runtime + reconstruction/unique",
99
+ ))
100
+
101
+ # G/J: generic CPU rule without company-specific core naming.
102
+ cpu_root = fixtures / "cpu_rules"
103
+ cpu = Project(cpu_root, config=cpu_root / "cseq.toml", configuration="GROUP_A_BUILD", use_cache=False).index()
104
+ cpu_values = {e.value for e in cpu.cpu_evidence}
105
+ cpu_ok = "CPU_GROUP_A" in cpu_values and "CPU_A2" in cpu_values
106
+ criteria.append(AcceptanceCriterion(
107
+ "POC-06", "一般化CPU Ruleで割当可能",
108
+ "PASS" if cpu_ok else "FAIL", "fixtures/cpu_rules",
109
+ ))
110
+
111
+ # K: marker rewrite minimal and reversible.
112
+ marker_src = fixtures / "marker" / "main.c"
113
+ marker_dst = work / "marker_acceptance.c"
114
+ shutil.copyfile(marker_src, marker_dst)
115
+ before = marker_dst.read_bytes()
116
+ manifest = apply_marker(marker_dst, literal_contains="rx=%d", marker_id="ACCEPT01")
117
+ after = marker_dst.read_bytes()
118
+ marker_token = b"[[CSEQ:ACCEPT01]] "
119
+ minimal_ok = after.replace(marker_token, b"", 1) == before and after.count(marker_token) == 1
120
+ undo_marker(marker_dst, manifest)
121
+ marker_ok = minimal_ok and marker_dst.read_bytes() == before
122
+ criteria.append(AcceptanceCriterion(
123
+ "POC-07", "Marker直接編集が最小差分・可逆",
124
+ "PASS" if marker_ok else "FAIL", "fixtures/marker + apply/undo",
125
+ ))
126
+
127
+ # PlantUML and HTML consume the exact same SequenceModel instance.
128
+ basic_model = build_sequence(basic, "main")
129
+ html_payload = build_html_payload(basic_model)
130
+ puml2 = render_plantuml(basic_model)
131
+ shared_ir_ok = len(html_payload["messages"]) == len(basic_model.messages) and "@startuml" in puml2
132
+ criteria.append(AcceptanceCriterion(
133
+ "POC-08", "PlantUML / HTMLを同一Sequence IRから生成",
134
+ "PASS" if shared_ir_ok else "FAIL", "SequenceModel -> render_plantuml/build_html_payload",
135
+ ))
136
+
137
+ # K2: overlay marker mode leaves the original source untouched.
138
+ overlay_src = fixtures / "marker" / "main.c"
139
+ overlay_dst = work / "overlay" / "marker_acceptance.c"
140
+ overlay_before = overlay_src.read_bytes()
141
+ overlay_manifest = apply_marker_overlay(
142
+ overlay_src, overlay_dst, literal_contains="rx=%d", marker_id="OVERLAY01"
143
+ )
144
+ overlay_ok = (
145
+ overlay_src.read_bytes() == overlay_before
146
+ and b"[[CSEQ:OVERLAY01]] " in overlay_dst.read_bytes()
147
+ )
148
+ undo_marker(overlay_dst, overlay_manifest)
149
+ overlay_ok = overlay_ok and overlay_dst.read_bytes() == overlay_before
150
+ criteria.append(AcceptanceCriterion(
151
+ "POC-09", "Marker overlay mode preserves the original source",
152
+ "PASS" if overlay_ok else "FAIL", "apply_marker_overlay + undo",
153
+ ))
154
+
155
+ # Performance-dependent criterion is intentionally delegated to G5.
156
+ criteria.append(AcceptanceCriterion(
157
+ "POC-10", "1M Event級UIが構造的に破綻しない",
158
+ "DEFERRED_TO_LATER_GATE", "G5 Runtime/UI受入",
159
+ "Functional E2Eでは判定せず、固定済み性能Gateで正式受入する",
160
+ ))
161
+
162
+ return AcceptanceReport(tuple(criteria))