瀏覽代碼

Renamed ast.ml to types.ml

Taddeus Kroes 12 年之前
父節點
當前提交
45ccce6001
共有 20 個文件被更改,包括 56 次插入56 次删除
  1. 2 2
      Makefile
  2. 1 1
      main.ml
  3. 2 2
      parser.mly
  4. 2 2
      phases/assemble.ml
  5. 2 2
      phases/bool_op.ml
  6. 3 3
      phases/constant_propagation.ml
  7. 2 2
      phases/context_analysis.ml
  8. 3 3
      phases/desug.ml
  9. 2 2
      phases/dim_reduce.ml
  10. 2 2
      phases/expand_dims.ml
  11. 3 3
      phases/extern_vars.ml
  12. 1 1
      phases/load.ml
  13. 2 2
      phases/parse.ml
  14. 2 2
      phases/print.ml
  15. 2 2
      phases/typecheck.ml
  16. 1 1
      stringify.ml
  17. 4 4
      stringify.mli
  18. 1 1
      types.ml
  19. 1 1
      util.ml
  20. 18 18
      util.mli

+ 2 - 2
Makefile

@@ -1,9 +1,9 @@
 RESULT := civicc
 PHASES := load parse print desug context_analysis expand_dims typecheck \
 	dim_reduce bool_op extern_vars constant_propagation
-SOURCES := ast.ml stringify.mli stringify.ml util.mli util.ml lexer.mll \
+SOURCES := types.ml stringify.mli stringify.ml util.mli util.ml lexer.mll \
 	parser.mly $(patsubst %,phases/%.ml,$(PHASES)) main.ml
-PRE_TARGETS := ast.cmi ast.o stringify.cmi stringify.o util.cmi util.o
+PRE_TARGETS := types.cmi types.o stringify.cmi stringify.o util.cmi util.o
 LIBS := str unix
 
 OCAMLFLAGS := -g

+ 1 - 1
main.ml

@@ -1,6 +1,6 @@
 open Printf
 open Lexing
-open Ast
+open Types
 open Util
 
 (* Compile CVC file to assembly code

+ 2 - 2
parser.mly

@@ -7,7 +7,7 @@
      *)
 
     open Lexing
-    open Ast
+    open Types
 
     let loc start stop = [Loc (Util.loc_from_lexpos start stop)]
 
@@ -48,7 +48,7 @@
 %nonassoc ELSE
 
 (* Start symbol *)
-%type <Ast.node> program
+%type <Types.node> program
 %start program
 
 %%

+ 2 - 2
phases/assemble.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 
 let store ctype = function
@@ -69,5 +69,5 @@ let assemble program =
 let rec phase input =
     prerr_endline "- Assembly";
     match input with
-    | Ast node -> Assembly (assemble node)
+    | Types node -> Assembly (assemble node)
     | _ -> raise (InvalidInput "assembly")

+ 2 - 2
phases/bool_op.ml

@@ -16,7 +16,7 @@
  * > (int)b1    ==>   b1 ? 1 : 0
  * > (float)b1  ==>   b1 ? 1.0 : 0.0
  *)
-open Ast
+open Types
 open Util
 
 let cast ctype node = TypeCast (ctype, node, [Type ctype])
@@ -62,5 +62,5 @@ and bool_op = function
 let rec phase input =
     log_line 2 "- Convert bool operations";
     match input with
-    | Ast node -> Ast (bool_op node)
+    | Types node -> Types (bool_op node)
     | _ -> raise (InvalidInput "bool operations")

+ 3 - 3
phases/constant_propagation.ml

@@ -10,7 +10,7 @@
  * Static Single Assignment form). Expressions can only be propagated when they
  * have no side effects, i.e. when they do not contain function calls.
  *)
-open Ast
+open Types
 open Util
 
 let is_const_name name =
@@ -167,8 +167,8 @@ let rec prune_vardecs consts = function
 let rec phase input =
     log_line 2 "- Constant propagation";
     match input with
-    | Ast node ->
+    | Types node ->
         let consts = Hashtbl.create 32 in
         let node = propagate consts node in
-        Ast (prune_vardecs consts node)
+        Types (prune_vardecs consts node)
     | _ -> raise (InvalidInput "constant propagation")

+ 2 - 2
phases/context_analysis.ml

@@ -1,5 +1,5 @@
 open Printf
-open Ast
+open Types
 open Util
 
 type nametype = Varname of string | Funcname of string
@@ -153,5 +153,5 @@ let analyse_context args program =
 let rec phase input =
     log_line 2 "- Context analysis";
     match input with
-    | Ast node -> Ast (analyse_context args node)
+    | Types node -> Types (analyse_context args node)
     | _ -> raise (InvalidInput "context analysis")

+ 3 - 3
phases/desug.ml

@@ -1,5 +1,5 @@
 open Printf
-open Ast
+open Types
 open Util
 
 let rec var_init = function
@@ -253,6 +253,6 @@ let rec array_dims = function
 let rec phase input =
     log_line 2 "- Desugaring";
     match input with
-    | Ast node ->
-            Ast (for_to_while (array_init (var_init (array_dims node))))
+    | Types node ->
+            Types (for_to_while (array_init (var_init (array_dims node))))
     | _ -> raise (InvalidInput "desugar")

+ 2 - 2
phases/dim_reduce.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 
 let rec multiply = function
@@ -50,5 +50,5 @@ let rec simplify_decs = function
 let rec phase input =
     log_line 2 "- Array dimension reduction";
     match input with
-    | Ast node -> Ast (simplify_decs (dim_reduce 0 node))
+    | Types node -> Types (simplify_decs (dim_reduce 0 node))
     | _ -> raise (InvalidInput "dimension reduction")

+ 2 - 2
phases/expand_dims.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 
 let rec expand_dims = function
@@ -38,5 +38,5 @@ let rec expand_dims = function
 let rec phase input =
     log_line 2 "- Expand array dimensions";
     match input with
-    | Ast node -> Ast (expand_dims node)
+    | Types node -> Types (expand_dims node)
     | _ -> raise (InvalidInput "expand dimensions")

+ 3 - 3
phases/extern_vars.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 
 let create_param ctype name =
@@ -126,8 +126,8 @@ let rec replace_vars scope depth = function
 let rec phase input =
     log_line 2 "- Create getters and setters for extern variables";
     match input with
-    | Ast node ->
+    | Types node ->
         let globals = Hashtbl.create 20 in
         let node = create_funcs globals node in
-        Ast (replace_vars globals 0 node)
+        Types (replace_vars globals 0 node)
     | _ -> raise (InvalidInput "extern vars")

+ 1 - 1
phases/load.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 
 (* Unix command to call for C preprocessor:

+ 2 - 2
phases/parse.ml

@@ -1,5 +1,5 @@
 open Lexing
-open Ast
+open Types
 
 let get_loc lexbuf =
     Util.loc_from_lexpos lexbuf.lex_curr_p lexbuf.lex_curr_p
@@ -25,5 +25,5 @@ let phase input =
         let ast = parse_with_error lexbuf in
         (match ast with
             | None -> raise (CompileError "no syntax tree was constructed")
-            | Some node -> Ast node)
+            | Some node -> Types node)
     | _ -> raise (InvalidInput "parse")

+ 2 - 2
phases/print.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 open Util
 open Stringify
 
@@ -77,7 +77,7 @@ let rec print_assembly oc instrs =
     *)
 
 let phase = function
-    | Ast node as input ->
+    | Types node as input ->
         if args.verbose >= 2 then (
             prerr_endline "--------------------------------------------------";
             prerr_endline (node2str node);

+ 2 - 2
phases/typecheck.ml

@@ -1,5 +1,5 @@
 open Printf
-open Ast
+open Types
 open Util
 open Stringify
 
@@ -213,5 +213,5 @@ let rec typecheck node =
 let rec phase input =
     log_line 2 "- Type checking";
     match input with
-    | Ast node -> Ast (typecheck node)
+    | Types node -> Types (typecheck node)
     | _ -> raise (InvalidInput "typecheck")

+ 1 - 1
stringify.ml

@@ -1,4 +1,4 @@
-open Ast
+open Types
 
 let tab = "    "
 

+ 4 - 4
stringify.mli

@@ -1,7 +1,7 @@
-val op2str : Ast.operator -> string
+val op2str : Types.operator -> string
 
-val node2str : Ast.node -> string
+val node2str : Types.node -> string
 
-val type2str : Ast.ctype -> string
+val type2str : Types.ctype -> string
 
-val types2str : Ast.ctype list -> string
+val types2str : Types.ctype list -> string

+ 1 - 1
ast.ml → types.ml

@@ -125,7 +125,7 @@ let args = {
 type intermediate =
     | Empty
     | FileContent of string * string
-    | Ast of node
+    | Types of node
     | Assembly of instr list
 
 (* exceptions *)

+ 1 - 1
util.ml

@@ -1,6 +1,6 @@
 open Printf
 open Lexing
-open Ast
+open Types
 
 (* Logging functions *)
 

+ 18 - 18
util.mli

@@ -1,10 +1,10 @@
 (* Logging functions, they print to stderr and consider the verbosity flag *)
 val prt_line : string -> unit
-val prt_node : Ast.node -> unit
+val prt_node : Types.node -> unit
 val log_line : int -> string -> unit
-val log_node : int -> Ast.node -> unit
+val log_node : int -> Types.node -> unit
 val dbg_line : string -> unit
-val dbg_node : Ast.node -> unit
+val dbg_node : Types.node -> unit
 
 (* Generate a fresh variable from a given prefix, e.g. "foo" -> "foo$1"  *)
 val fresh_var : string -> string
@@ -12,43 +12,43 @@ val fresh_var : string -> string
 (* Generate a fresg constant from a given prefix, e.g. "foo" -> "foo$$1"  *)
 val fresh_const : string -> string
 
-(* Generate an Ast.location tuple from Lexing data structures *)
-val loc_from_lexpos : Lexing.position -> Lexing.position -> Ast.location
+(* Generate an Types.location tuple from Lexing data structures *)
+val loc_from_lexpos : Lexing.position -> Lexing.position -> Types.location
 
 (* Default transformation traversal for AST nodes *)
-val transform_children : (Ast.node -> Ast.node) -> Ast.node -> Ast.node
+val transform_children : (Types.node -> Types.node) -> Types.node -> Types.node
 
-(*val visit_children : (Ast.node -> unit) -> Ast.node -> unit*)
+(*val visit_children : (Types.node -> unit) -> Types.node -> unit*)
 
 (* Extract annotation from node *)
-val annof   : Ast.node -> Ast.annotation list
-val locof   : Ast.node -> Ast.location
-val depthof : Ast.node -> int
-val typeof  : Ast.node -> Ast.ctype
+val annof   : Types.node -> Types.annotation list
+val locof   : Types.node -> Types.location
+val depthof : Types.node -> int
+val typeof  : Types.node -> Types.ctype
 
 (* Print file location to stderr *)
-val prerr_loc : Ast.location -> unit
+val prerr_loc : Types.location -> unit
 
 (* Print file location to stderr *)
-val prerr_loc_msg : Ast.location -> string -> int -> unit
+val prerr_loc_msg : Types.location -> string -> int -> unit
 
 (* Flatten Block nodes into the given array of nodes *)
-val flatten_blocks : Ast.node list -> Ast.node list
+val flatten_blocks : Types.node list -> Types.node list
 
 (* Extract the node list from a Block node *)
-val block_body : Ast.node -> Ast.node list
+val block_body : Types.node -> Types.node list
 
 (* Get the size of a list by traversing it recurcively *)
 val list_size : 'a list -> int
 
 (* Get the basic type of a declaration, removing array dimensions *)
-val basetypeof : Ast.node -> Ast.ctype
+val basetypeof : Types.node -> Types.ctype
 
 (* Get the number of dimensions from an Array type *)
-val array_depth : Ast.ctype -> int
+val array_depth : Types.ctype -> int
 
 (* Get name from variable or function declaration *)
-val nameof : Ast.node -> string
+val nameof : Types.node -> string
 
 val optmap : ('a -> 'b) -> 'a list option -> 'b list option
 val optmapl : ('a -> 'b) -> 'a list option -> 'b list