Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
315b9da
v0.15.1: SV構文拡張 - 連接・複製・always_*・bit[N]・enum/struct/function
shadowlink0122 Mar 10, 2026
e9ee9a1
extern struct 実装: 外部ハードウェアモジュールのインスタンス化サポート
shadowlink0122 Mar 10, 2026
080e49f
修正: 非SVプラットフォームの暗黙的構造体リテラルパースを復元
shadowlink0122 Mar 10, 2026
551e768
修正: グローバル文字列初期化のCreateGlobalStringPtrハングを解消
shadowlink0122 Mar 10, 2026
1708f29
修正: MIR→LLVM変換に到達可能性分析を追加し到達不能ブロックをスキップ
shadowlink0122 Mar 10, 2026
ce7959e
修正: wasmtime CIセットアップをcurlインストールに切り替え
shadowlink0122 Mar 10, 2026
cae567b
ドキュメント: SV バックエンド チュートリアルを追加
shadowlink0122 Mar 11, 2026
6b2810a
ドキュメント: SVチュートリアルをdocs/tutorials/に日英両言語で配置
shadowlink0122 Mar 11, 2026
48aa574
修正: SV バックエンドの言語仕様整合
shadowlink0122 Mar 11, 2026
b587720
修正: #[sv::param]属性廃止、task出力廃止
shadowlink0122 Mar 11, 2026
e0a7572
修正: SV バックエンド品質改善6項目
shadowlink0122 Mar 11, 2026
15a3eb0
修正: switch/case構文ドキュメント修正とenum FSM例追加
shadowlink0122 Mar 11, 2026
5c2d417
Copilotの指摘事項に対応
shadowlink0122 Apr 29, 2026
e667c84
format
shadowlink0122 Apr 29, 2026
fe0a946
リファクタリング用ドキュメント
shadowlink0122 Apr 29, 2026
e7bd20d
リファクタ
shadowlink0122 Apr 29, 2026
94c33fe
リファクタ(新規機能)
shadowlink0122 Apr 29, 2026
d5c16fb
リファクタ(新規機能)
shadowlink0122 Apr 29, 2026
64fecf7
make修正
shadowlink0122 Apr 29, 2026
ff8ea30
verilogのテスト追加
shadowlink0122 Apr 29, 2026
a385759
fix
shadowlink0122 Apr 29, 2026
57b6604
x86用のビルドを追加
shadowlink0122 Apr 29, 2026
3cb4129
Copilotの指摘事項に対応
shadowlink0122 Apr 29, 2026
d231ccf
リリースノート作成
shadowlink0122 Apr 29, 2026
8513ddd
チュートリアル追記
shadowlink0122 Apr 29, 2026
6f26423
refactorを実装
shadowlink0122 May 3, 2026
d202d46
wasm用のexpect
shadowlink0122 May 3, 2026
78dede7
Copilotの指摘事項に対応
shadowlink0122 May 3, 2026
b5a63ca
Copilotの指摘事項に対応
shadowlink0122 May 3, 2026
ab7e008
なるべくasyncを使う
shadowlink0122 May 9, 2026
c6dc56a
SV バックエンド: 配列宣言サポートの修正
shadowlink0122 Jun 1, 2026
b3b6427
HDMI Phase 1: ビデオタイミング・TMDS エンコーダ単体テスト追加
shadowlink0122 Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ jobs:
- { id: wasm-o3, name: "WASMコンパイル+実行 O3", target: twp3, backend: llvm-wasm, needs_node: false }
- { id: js-o0, name: "JSコード生成+実行 O0", target: tjp0, backend: js, needs_node: true }
- { id: js-o3, name: "JSコード生成+実行 O3", target: tjp3, backend: js, needs_node: true }
- { id: sv-o0, name: "SV生成テスト O0", target: tsvp0, backend: sv, needs_node: false }
- { id: sv-o3, name: "SV生成テスト O3", target: tsvp3, backend: sv, needs_node: false }
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -289,9 +290,11 @@ jobs:

- name: Install wasmtime
if: matrix.config.backend == 'llvm-wasm'
uses: bytecodealliance/actions/wasmtime/setup@v1
with:
version: "latest"
run: |
# bytecodealliance/actions/wasmtime/setup@v1 はGitHub APIレート制限で
# HTMLエラーを返すことがあるため、直接インストールスクリプトを使用
curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH

- name: Install SV tools (for SV backend tests)
if: matrix.config.backend == 'sv'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 実行ファイル
/cm
/cm.exe
/cm-x86

# Build artifacts
build/
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,15 @@ if(BUILD_TESTING)
target_link_libraries(mir_optimization_test gtest_main cm_frontend)
gtest_discover_tests(mir_optimization_test PROPERTIES LABELS "unit")

# Unit tests - Error handling
add_executable(error_test
tests/unit/error_test.cpp
)
set_target_properties(error_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TEST_RUNTIME_OUTPUT_DIRECTORY})
target_include_directories(error_test BEFORE PRIVATE ${GTEST_INCLUDE_DIR})
target_link_libraries(error_test gtest_main)
gtest_discover_tests(error_test PROPERTIES LABELS "unit")

# Unit tests - MIR Interpreter (disabled until MirBuilder is implemented)
# add_executable(mir_interpreter_test
# tests/unit/mir_interpreter_test.cpp
Expand Down
134 changes: 124 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ help:
@echo " 例: make build ARCH=x86_64"
@echo ""
@echo "Test Commands (Unit Tests):"
@echo " make test - すべてのC++ユニットテストを実行"
@echo " make test - 全テスト実行(unit + integration)"
@echo " make test-unit - C++ユニットテストのみ"
@echo " make test-lexer - Lexerテストのみ"
@echo " make test-hir - HIR Loweringテストのみ"
@echo " make test-mir - MIR Loweringテストのみ"
Expand Down Expand Up @@ -121,6 +122,11 @@ help:
@echo " make test-baremetal - ベアメタルコンパイルテスト"
@echo " make test-uefi - UEFIコンパイルテスト"
@echo ""
@echo "Test Commands (SystemVerilog/Hardware):"
@echo " make test-sv - SystemVerilogテスト (Cm→SV変換 + Verilator lint)"
@echo " make test-sv-parallel - SystemVerilogテスト(並列)"
@echo " make test-sv-o0/o1/o2/o3 - SystemVerilog最適化レベル別テスト"
@echo ""
@echo " make test-all - すべてのテストを実行"
@echo ""
@echo "Run Commands:"
Expand All @@ -132,9 +138,16 @@ help:
@echo " make format-check - フォーマットをチェック"
@echo " make lint - C++コードを静的解析(clang-tidy)"
@echo ""
@echo "x86_64 Debug Commands (macOS Rosetta):"
@echo " make build-x86 - x86_64用コンパイラをビルド"
@echo " make test-x86 - x86_64でテスト実行(Rosetta経由)"
@echo " make debug-x86 FILE=<file> - x86_64で特定テストをデバッグ"
@echo " make clean-x86 - x86_64ビルドをクリーン"
@echo ""
@echo "Quick Shortcuts:"
@echo " make b - build"
@echo " make t - test"
@echo " make t - test (unit + integration)"
@echo " make tu - test-unit (C++ unit tests only)"
@echo " make ta - test-all"
@echo " make tao - test-all-opts (全最適化レベルテスト)"
@echo " make tl - test-llvm"
Expand All @@ -149,6 +162,7 @@ help:
@echo " make tw0/tw1/tw2/tw3 - WASM O0-O3(シリアル)"
@echo " make tj0/tj1/tj2/tj3 - JS O0-O3(シリアル)"
@echo " make tjit0/tjit1/tjit2/tjit3 - JIT O0-O3(シリアル)"
@echo " make tsv/tsvp - SystemVerilog(シリアル/パラレル)"
@echo " make tip0/tip1/tip2/tip3 - インタプリタ O0-O3(パラレル)"
@echo " make tlp0/tlp1/tlp2/tlp3 - LLVM O0-O3(パラレル)"
@echo " make twp0/twp1/twp2/twp3 - WASM O0-O3(パラレル)"
Expand Down Expand Up @@ -319,17 +333,118 @@ clean:
rebuild: clean build-all


# ========================================
# x86_64 Debug Commands (macOS Rosetta)
# ========================================

# x86_64用ビルドディレクトリ
BUILD_DIR_X86 := build-x86_64

# x86_64用コンパイラをビルド(Rosettaでテスト実行用)
# ツールチェーンファイル: cmake/toolchains/x86_64-apple-darwin.cmake
.PHONY: build-x86
build-x86:
@if [ "$$(uname -s)" != "Darwin" ]; then \
echo "❌ This target is only available on macOS"; \
exit 1; \
fi
@echo "Building x86_64 compiler (for Rosetta testing)..."
@rm -rf $(BUILD_DIR_X86)
@BREW_PREFIX=/usr/local && \
LLVM_PREFIX=$${BREW_PREFIX}/opt/llvm@17 && \
OPENSSL_PREFIX=$${BREW_PREFIX}/opt/openssl@3 && \
if [ ! -d "$${LLVM_PREFIX}" ]; then \
echo "❌ x86_64 LLVM not found. Install with:"; \
echo " arch -x86_64 /usr/local/bin/brew install llvm@17 openssl@3"; \
exit 1; \
fi && \
arch -x86_64 cmake -B $(BUILD_DIR_X86) \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/x86_64-apple-darwin.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-DCM_USE_LLVM=ON \
-DCM_TARGET_ARCH=x86_64 \
-DLLVM_DIR=$${LLVM_PREFIX}/lib/cmake/llvm \
-DCMAKE_PREFIX_PATH="$${LLVM_PREFIX};$${OPENSSL_PREFIX}" \
-DOPENSSL_ROOT_DIR=$${OPENSSL_PREFIX} \
-DOPENSSL_SSL_LIBRARY=$${OPENSSL_PREFIX}/lib/libssl.dylib \
-DOPENSSL_CRYPTO_LIBRARY=$${OPENSSL_PREFIX}/lib/libcrypto.dylib \
-DOPENSSL_INCLUDE_DIR=$${OPENSSL_PREFIX}/include \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_EXE_LINKER_FLAGS="-L$${LLVM_PREFIX}/lib" && \
arch -x86_64 cmake --build $(BUILD_DIR_X86) --target cm -j$$(sysctl -n hw.ncpu) && \
mv cm cm-x86 && \
install_name_tool -change /opt/homebrew/opt/llvm@17/lib/libLLVM.dylib /usr/local/opt/llvm@17/lib/libLLVM.dylib cm-x86 2>/dev/null || true && \
install_name_tool -change /opt/homebrew/opt/llvm@17/lib/libunwind.1.dylib /usr/local/opt/llvm@17/lib/libunwind.1.dylib cm-x86 2>/dev/null || true && \
install_name_tool -change /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib /usr/local/opt/openssl@3/lib/libssl.3.dylib cm-x86 2>/dev/null || true && \
install_name_tool -change /opt/homebrew/opt/openssl@3/lib/libcrypto.3.dylib /usr/local/opt/openssl@3/lib/libcrypto.3.dylib cm-x86 2>/dev/null || true && \
echo "✅ x86_64 build complete! Binary: cm-x86"

# x86_64用テスト実行(Rosettaで実行)
.PHONY: test-x86
test-x86: build-x86
@echo "Running x86_64 tests via Rosetta..."
@CM_EXECUTABLE=./cm-x86 OPT_LEVEL=3 tests/unified_test_runner.sh -b llvm -p
Comment thread
shadowlink0122 marked this conversation as resolved.
@echo "✅ x86_64 tests completed!"

# x86_64で特定のテストをデバッグ実行
# 使用例: make debug-x86 FILE=tests/common/functions/recursive_function.cm
.PHONY: debug-x86
debug-x86: build-x86
@if [ -z "$(FILE)" ]; then \
echo "Usage: make debug-x86 FILE=<test.cm>"; \
exit 1; \
fi
@echo "=== x86_64 Debug: $(FILE) ==="
@echo "--- Compiling ---"
@./cm-x86 compile -O3 -o /tmp/debug_x86_test $(FILE) 2>&1 || true
@echo ""
@echo "--- Running via Rosetta ---"
@if [ -f /tmp/debug_x86_test ]; then \
/tmp/debug_x86_test 2>&1; \
echo "Exit code: $$?"; \
else \
echo "Compilation failed"; \
fi

# x86_64用クリーン
.PHONY: clean-x86
clean-x86:
@rm -rf $(BUILD_DIR_X86) cm-x86
@echo "✅ x86_64 build cleaned!"

# ショートカット
.PHONY: bx tx dx
bx: build-x86
tx: test-x86
dx: debug-x86


# ========================================
# Unit Test Commands (C++ tests via ctest)
# ========================================

.PHONY: test
test:
.PHONY: test-unit
test-unit:
@echo "Running all C++ unit tests..."
@ctest --test-dir $(BUILD_DIR) --output-on-failure
@echo ""
@echo "✅ All unit tests passed!"

# 全テスト実行(unit + integration)- 並列実行
.PHONY: test
test: test-unit test-interpreter-parallel test-llvm-parallel test-llvm-wasm-parallel test-js-parallel test-sv-parallel
@echo ""
@echo "=========================================="
@echo "✅ All tests completed!"
@echo " - Unit tests (C++)"
@echo " - Interpreter tests (parallel)"
@echo " - LLVM Native tests (parallel)"
@echo " - LLVM WASM tests (parallel)"
@echo " - JavaScript tests (parallel)"
@echo " - SystemVerilog tests (parallel)"
@echo "=========================================="

.PHONY: test-lexer
test-lexer:
@echo "Running Lexer tests..."
Expand Down Expand Up @@ -513,13 +628,9 @@ test-all-parallel-nc: build ## 全バックエンド(パラレル、キャッ
@echo "✅ All parallel tests (no cache) completed!"
@echo "=========================================="

# すべてのテストを実行
# すべてのテストを実行(testのエイリアス)
.PHONY: test-all
test-all: test test-interpreter test-llvm-all
@echo ""
@echo "=========================================="
@echo "✅ All tests completed!"
@echo "=========================================="
test-all: test

# ========================================
# Run Commands
Expand Down Expand Up @@ -592,6 +703,9 @@ b: build
.PHONY: t
t: test

.PHONY: tu
tu: test-unit

.PHONY: ta
ta: test-all

Expand Down
21 changes: 21 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ impl Point for Printable {

---

## リファクタリング項目

### SystemVerilog バックエンドテスト

| 項目 | 状態 | 説明 |
|------|------|------|
| テストスイート | ✅ | `tests/sv/` に65+テストケース |
| Makeターゲット | ✅ | `make test-sv`, `make test-sv-parallel` |
| Verilator lint検証 | ✅ | `verilator --lint-only` |
| iverilog検証 | ✅ | `iverilog -g2012` フォールバック |
| シミュレーション実行 | ✅ | `vvp` によるシミュレーション |

**テスト実行方法**:
```bash
make test-sv # SystemVerilogテスト(シリアル)
make test-sv-parallel # SystemVerilogテスト(並列)
make tsv # ショートカット
```

---

## 廃止機能

- Rust/TypeScript/C++トランスパイラ(2025年12月廃止)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.15.0
0.15.1
22 changes: 22 additions & 0 deletions cmake/toolchains/x86_64-apple-darwin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# x86_64 Apple Darwin toolchain for cross-compiling on ARM64 Mac
# Usage: cmake -B build-x86_64 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/x86_64-apple-darwin.cmake

set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_OSX_ARCHITECTURES x86_64)

# x86_64 Homebrew prefix
set(BREW_PREFIX "/usr/local")

# Find x86_64 LLVM installation
set(CMAKE_PREFIX_PATH "${BREW_PREFIX}/opt/llvm@17;${BREW_PREFIX}/opt/openssl@3")

# RPATH settings for proper library resolution
set(CMAKE_INSTALL_RPATH "${BREW_PREFIX}/opt/llvm@17/lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_MACOSX_RPATH TRUE)

# Ensure we use Rosetta-compatible libraries
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
6 changes: 3 additions & 3 deletions docs/PR.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cm compile --target=sv program.cm -o output.sv
| ポート宣言 | `#[input]`/`#[output]`アトリビュートでI/Oポート宣言 |
| 組み合わせ回路 | 通常関数 → `always_comb begin ... end` |
| 順序回路 | `posedge`/`negedge`型引数 → `always_ff @(posedge clk)` |
| SV固有型 | `posedge`, `negedge`, `wire`, `reg`(文脈キーワード) |
| SV固有キーワード | `posedge`, `negedge`, `wire`, `reg`, `always`, `assign`, `bit`等(文脈キーワード) |
| 非ブロッキング代入 | 順序回路で`<=`を自動使用 |
| BRAM推論 | 配列をBlock RAMとして推論 |
| テストベンチ自動生成 | iverilog互換の`_tb.sv`を自動生成 |
Expand Down Expand Up @@ -65,13 +65,13 @@ result = sel ? a : b;

```cm
//! platform: sv
// この行以降、posedge/negedge/wire/regがキーワードトークンとして認識される
// この行以降、SV固有キーワードがトークンとして認識される
```

| モード | キーワード追加 | 用途 |
|--------|-------------|------|
| `LexerPlatform::Default` | なし | 通常のCmコード |
| `LexerPlatform::SV` | `posedge`, `negedge`, `wire`, `reg` | SVターゲット |
| `LexerPlatform::SV` | `posedge`, `negedge`, `wire`, `reg`, `always`, `always_ff`, `always_comb`, `always_latch`, `assign`, `initial`, `bit` | SVターゲット |

> 非SVモードでは`posedge`等は通常のIdent(変数名として使用可能)

Expand Down
18 changes: 9 additions & 9 deletions docs/design/v0.15.0/systemverilog_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Cmコンパイラに**SystemVerilog (SV) バックエンド**を追加し、Cm
任意ビット幅のハードウェアレジスタ/ワイヤを表現するための新しい型を導入する。

```cm
// 任意ビット幅型
bit<24> addr = 24'h0; // 24ビットアドレス
bit<3> rgb = 3'b101; // 3ビットRGB
bit<128> data = 128'h0; // 128ビット幅データ
// 任意ビット幅型(配列サフィックス形式)
bit[24] addr = 24'h0; // 24ビットアドレス
bit[3] rgb = 3'b101; // 3ビットRGB
bit[128] data = 128'h0; // 128ビット幅データ
```

#### SV出力
Expand Down Expand Up @@ -400,7 +400,7 @@ impl SpiMaster {
#[sv::module]
struct VideoRAM {
#[input] clk: bool,
#[input] addr: bit<15>,
#[input] addr: bit[15],
#[input] write_data: utiny,
#[input] write_enable: bool,
#[output] read_data: utiny,
Expand Down Expand Up @@ -449,13 +449,13 @@ impl SoC {
// Phase 4: AXIバスインターフェース
#[sv::interface]
interface AXI4Lite {
awaddr: bit<32>,
awaddr: bit[32],
awvalid: bool,
awready: bool,
wdata: bit<32>,
wdata: bit[32],
wvalid: bool,
wready: bool,
bresp: bit<2>,
bresp: bit[2],
bvalid: bool,
bready: bool,
// ... Read channels
Expand Down Expand Up @@ -546,7 +546,7 @@ export Core; // 外部から参照可能にする
struct Core {
#[input] clk: bool,
#[input] rst: bool,
#[output] mem_addr: bit<16>,
#[output] mem_addr: bit[16],
#[output] mem_data: utiny,
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/releases/v0.15.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ cm compile --target=sv program.cm -o output.sv
| `posedge`型引数 | `always_ff @(posedge clk) begin ... end` |
| `negedge`型引数 | `always_ff @(negedge clk) begin ... end` |

### SV固有型(文脈キーワード)
### SV固有キーワード(文脈キーワード)

`posedge`、`negedge`、`wire`、`reg`型をCm言語レベルで直接サポート。SVプラットフォーム時のみキーワードとして認識され、非SVモードでは通常の識別子として使用可能。
`posedge`、`negedge`、`wire`、`reg`、`always`、`always_ff`、`always_comb`、`always_latch`、`assign`、`initial`、`bit`をCm言語レベルで直接サポート。SVプラットフォーム時のみキーワードとして認識され、非SVモードでは通常の識別子として使用可能。

### SV幅付きリテラル

Expand Down Expand Up @@ -78,13 +78,13 @@ if/elseが同一変数への単一代入のみの場合、`cond ? a : b` に自

```cm
//! platform: sv
// posedge/negedge/wire/reg がキーワードトークンとして認識される
// SV固有キーワードがトークンとして認識される
```

| モード | キーワード追加 | 用途 |
|--------|-------------|------|
| `LexerPlatform::Default` | なし | 通常のCmコード |
| `LexerPlatform::SV` | `posedge`, `negedge`, `wire`, `reg` | SVターゲット |
| `LexerPlatform::SV` | `posedge`, `negedge`, `wire`, `reg`, `always`, `always_ff`, `always_comb`, `always_latch`, `assign`, `initial`, `bit` | SVターゲット |

---

Expand Down
Loading
Loading