Sfoglia il codice sorgente

Moved args to ast.ml to avoid circular dependency

Taddeus Kroes 12 anni fa
parent
commit
662cca4a28
5 ha cambiato i file con 28 aggiunte e 26 eliminazioni
  1. 15 1
      ast.ml
  2. 0 1
      phases/print.ml
  3. 13 7
      stringify.ml
  4. 0 14
      util.ml
  5. 0 3
      util.mli

+ 15 - 1
ast.ml

@@ -56,13 +56,27 @@ and node =
     | DummyNode
 
 (* container for command-line arguments *)
-type args = {
+type args_record = {
     mutable infile  : string option;
     mutable outfile : string option;
     mutable verbose : int;
     mutable cpp     : bool;
 }
 
+(* Default config *)
+let verbosity_default = 2  (* TODO: set to 1 when done with debugging *)
+let verbosity_debug   = 3
+
+(* Commandline args are stored in a global struct
+ * (yes, it IS dirty, but I'd rather have this than having to pass [args] around
+ * everywhere) *)
+let args = {
+    infile  = None;
+    outfile = None;
+    verbose = verbosity_default;
+    cpp     = true;
+}
+
 (* intermediate representations between phases *)
 type intermediate =
     | Empty

+ 0 - 1
phases/print.ml

@@ -1,6 +1,5 @@
 open Ast
 open Stringify
-open Util
 
 let phase = function
     | Ast node as input ->

+ 13 - 7
stringify.ml

@@ -99,7 +99,6 @@ and node2str node =
     | IntConst (i, _) -> string_of_int i
     | FloatConst (f, _) -> string_of_float f
     | ArrayConst (dims, _) -> "[" ^ concat ", " dims ^ "]"
-    | ArrayScalar value -> "<scalar>(" ^ str value ^ ")"
     | Var (v, _) -> v
     | Deref (name, dims, _) -> name ^ (str (ArrayConst (dims, noloc)))
     | Monop (op, opnd, _) -> op2str op ^ str opnd
@@ -109,13 +108,20 @@ and node2str node =
     | FunCall (name, args, _) -> name ^ "(" ^ (concat ", " args) ^ ")"
     | Cond (cond, t, f, _) -> (str cond) ^ " ? " ^ str t ^ " : " ^ str f
 
-    (* FIXME: these shoud be printen when verbose > 2
-    | Arg node -> "<arg>(" ^ str node ^ ")"
-    | Type (node, ctype) -> str node ^ ":" ^ type2str ctype
-    | VarUse (value, ctype, _) -> "<use:" ^ type2str ctype ^ ">(" ^ str value ^ ")"
-    | FunUse (value, _, _) -> "<use>(" ^ str value ^ ")"
-    *)
+    (* Some intermediate nodes print more information at higher verbosity, for
+     * debugging purposes *)
+    | ArrayScalar value         when args.verbose >= 3 ->
+        "<scalar>(" ^ str value ^ ")"
+    | Arg node                  when args.verbose >= 3 ->
+        "<arg>(" ^ str node ^ ")"
+    | Type (node, ctype)        when args.verbose >= 3 ->
+        str node ^ ":" ^ type2str ctype
+    | VarUse (value, ctype, _)  when args.verbose >= 3 ->
+        "<use:" ^ type2str ctype ^ ">(" ^ str value ^ ")"
+    | FunUse (value, _, _)      when args.verbose >= 3 ->
+        "<use>(" ^ str value ^ ")"
 
+    | ArrayScalar node
     | ArrayInit (node, _)
     | Arg node
     | Type (node, _)

+ 0 - 14
util.ml

@@ -2,20 +2,6 @@ open Printf
 open Lexing
 open Ast
 
-(* Default config *)
-let verbosity_default = 2  (* TODO: set to 1 when done with debugging *)
-let verbosity_debug   = 3
-
-(* Commandline args are stored in a global struct
- * (yes, it IS dirty, but I'd rather have this than having to pass [args] around
- * everywhere) *)
-let args = {
-    infile  = None;
-    outfile = None;
-    verbose = verbosity_default;
-    cpp     = true;
-}
-
 (* Logging functions *)
 
 let log_line verbosity line =

+ 0 - 3
util.mli

@@ -1,6 +1,3 @@
-(* Global record with command-line arguments *)
-val args : Ast.args
-
 (* Logging functions, they print to stderr and consider the verbosity flag *)
 val log_line : int -> string -> unit
 val log_node : int -> Ast.node -> unit