From dead771b3f6167d3a78b474548ea52fe16966430 Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@slava-pestovs-macbook-pro.local>
Date: Mon, 25 May 2009 19:16:58 -0500
Subject: [PATCH] compiler.cfg.checker: new vocabulary for checking CFG
 invariants

---
 basis/compiler/cfg/checker/authors.txt    |  1 +
 basis/compiler/cfg/checker/checker.factor | 24 +++++++++++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 basis/compiler/cfg/checker/authors.txt
 create mode 100644 basis/compiler/cfg/checker/checker.factor

diff --git a/basis/compiler/cfg/checker/authors.txt b/basis/compiler/cfg/checker/authors.txt
new file mode 100644
index 0000000000..d4f5d6b3ae
--- /dev/null
+++ b/basis/compiler/cfg/checker/authors.txt
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/compiler/cfg/checker/checker.factor b/basis/compiler/cfg/checker/checker.factor
new file mode 100644
index 0000000000..c14b7d0ae0
--- /dev/null
+++ b/basis/compiler/cfg/checker/checker.factor
@@ -0,0 +1,24 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel compiler.cfg.instructions compiler.cfg.rpo sequences
+combinators.short-circuit accessors ;
+IN: compiler.cfg.checker
+
+ERROR: last-insn-not-a-jump insn ;
+
+: check-basic-block ( bb -- )
+    peek dup {
+        [ ##branch? ]
+        [ ##conditional-branch? ]
+        [ ##compare-imm-branch? ]
+        [ ##return? ]
+        [ ##callback-return? ]
+        [ ##jump? ]
+        [ ##call? ]
+        [ ##dispatch-label? ]
+    } 1|| [ drop ] [ last-insn-not-a-jump ] if ;
+
+: check-cfg ( cfg -- )
+    entry>> reverse-post-order [
+        instructions>> check-basic-block
+    ] each ;
\ No newline at end of file