(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(* Correctness proof of a (very) simple compiler *)
Unset Standard Proposition Elimination Names.
(* source language *)
Parameter string : Set.
Inductive expr : Set :=
| Lit : nat -> expr
| Var : string -> expr
| Plus : expr -> expr -> expr.
(* semantics of source language *)
Definition state := string -> nat.
Fixpoint E (s : state) (e : expr) {struct e} : nat :=
match e with
| Lit n => n
| Var v => s v
| Plus e1 e2 => E s e1 + E s e2
end.
(* target language *)
Inductive instr : Set :=
| LI : nat -> instr
| LOAD : nat -> instr
| STO : nat -> instr
| ADD : nat -> instr.
(* memory *)
Inductive cell : Set :=
| Acc : cell
| Reg : nat -> cell.
Definition store := cell -> nat.

Lemma cell_eq_dec : forall c1 c2 : cell, {c1 = c2} + {c1 <> c2}.
simple destruct c1; simple destruct c2; intros; try (right; discriminate).