Skip to content

Commit

Permalink
Generic-arithmetic unparser
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-frigo committed Jun 4, 2003
1 parent d705a29 commit 10d5f54
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
39 changes: 31 additions & 8 deletions genfft/c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*)
(* $Id: c.ml,v 1.20 2003-06-01 11:01:17 athena Exp $ *)
(* $Id: c.ml,v 1.21 2003-06-04 19:11:29 athena Exp $ *)

(*
* This module contains the definition of a C-like abstract
Expand Down Expand Up @@ -75,7 +75,7 @@ let ctimes = function
*)
let foldr_string_concat l = fold_right (^) l ""

let rec unparse_expr =
let rec unparse_expr_c =
let yes x = x and no x = "" in

let rec unparse_plus maybe =
Expand Down Expand Up @@ -103,23 +103,46 @@ let rec unparse_expr =
| (a :: b) ->
maybep ^ (parenthesize a) ^ (unparse_plus yes b)
and parenthesize x = match x with
| (Load _) -> unparse_expr x
| (Num _) -> unparse_expr x
| _ -> "(" ^ (unparse_expr x) ^ ")"
| (Load _) -> unparse_expr_c x
| (Num _) -> unparse_expr_c x
| _ -> "(" ^ (unparse_expr_c x) ^ ")"
and op nam a b c =
nam ^ "(" ^ (unparse_expr a) ^ ", " ^ (unparse_expr b) ^ ", " ^
(unparse_expr c) ^ ")"
nam ^ "(" ^ (unparse_expr_c a) ^ ", " ^ (unparse_expr_c b) ^ ", " ^
(unparse_expr_c c) ^ ")"

in function
| Load v -> Variable.unparse v
| Num n -> Number.to_konst n
| Plus [] -> "0.0 /* bug */"
| Plus [a] -> " /* bug */ " ^ (unparse_expr a)
| Plus [a] -> " /* bug */ " ^ (unparse_expr_c a)
| Plus a -> (unparse_plus no a)
| Times (a, b) -> (parenthesize a) ^ " * " ^ (parenthesize b)
| Uminus a -> "- " ^ (parenthesize a)
| _ -> failwith "unparse_expr_c"

and unparse_expr_generic =
let rec binary op a b =
op ^ "(" ^ (unparse_expr_generic a) ^ ", " ^ (unparse_expr_generic b) ^ ")"
and unary op a =
op ^ "(" ^ (unparse_expr_generic a) ^ ")"
and unparse_plus = function
| [a; b] -> binary "ADD" a b
| a :: b :: c -> binary "ADD" a (Plus (b :: c))
| _ -> failwith "unparse_plus"
in function
| Load v -> Variable.unparse v
| Num n -> Number.to_konst n
| Plus a -> unparse_plus a
| Times (a, b) -> binary "MUL" a b
| Uminus a -> unary "NEG" a
| _ -> failwith "unparse_expr"

and unparse_expr x =
if !Magic.generic_arith then
unparse_expr_generic x
else
unparse_expr_c x

and unparse_assignment (Assign (v, x)) =
(Variable.unparse v) ^ " = " ^ (unparse_expr x) ^ ";\n"

Expand Down
6 changes: 5 additions & 1 deletion genfft/magic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*)
(* $Id: magic.ml,v 1.12 2003-03-15 20:29:42 stevenj Exp $ *)
(* $Id: magic.ml,v 1.13 2003-06-04 19:11:29 athena Exp $ *)

(* magic parameters *)
let verbose = ref false
Expand Down Expand Up @@ -51,6 +51,7 @@ let asched_dump_file = ref ""
let lisp_syntax = ref false
let network_transposition = ref true
let inklude = ref ""
let generic_arith = ref false

(* command-line parser for magic parameters *)
let undocumented = " Undocumented voodoo parameter"
Expand Down Expand Up @@ -90,6 +91,9 @@ let speclist = [
"-dif-split-radix", set_bool dif_split_radix, undocumented;
"-dit-split-radix", unset_bool dif_split_radix, undocumented;

"-generic-arith", set_bool generic_arith, undocumented;
"-no-generic-arith", unset_bool generic_arith, undocumented;

"-inline-single", set_bool inline_single, undocumented;
"-no-inline-single", unset_bool inline_single, undocumented;

Expand Down

0 comments on commit 10d5f54

Please sign in to comment.