Explorar el Código

Added more comments to assembly at -v 2

Taddeus Kroes hace 12 años
padre
commit
722c0bd9ab
Se han modificado 1 ficheros con 11 adiciones y 4 borrados
  1. 11 4
      phases/assemble.ml

+ 11 - 4
phases/assemble.ml

@@ -46,9 +46,11 @@ let assemble program =
           [Export (name, ret_type, param_types, label)]
         else []
       end @
-      [Comment (sprintf "fun \"%s\" with %d local vars" label (indexof node));
+      [Comment (sprintf "function \"%s\" with %d parameters and %d local vars"
+                        label (List.length params) (indexof node));
        Label label;
        RtnEnter (indexof node)] @
+      (trav_all params) @
       (trav body) @
       (match ret_type with Void -> [Ret Void] | _ -> []) @
       [EmptyLine] @
@@ -57,6 +59,9 @@ let assemble program =
     | VarDec (_, name, _, _) ->
       [comline (sprintf "local var \"%s\" at index %d" name (indexof node))]
 
+    | Param (_, name, _) ->
+      [comline (sprintf "parameter \"%s\" at index %d" name (indexof node))]
+
     | LocalFuns _ -> []
 
     | Block body | VarDecs body -> trav_all body
@@ -122,8 +127,8 @@ let assemble program =
      * stack, if any *)
     | Expr value ->
       let pop = match typeof value with
-      | Void -> [comline (node2str node)]
-      | ctype -> [InlineComment (Pop ctype, node2str node)]
+      | Void -> []
+      | ctype -> [InlineComment (Pop ctype, "disregard return value")]
       in
       trav value @ pop
 
@@ -183,7 +188,9 @@ let assemble program =
       | FunDef _ -> RtnJmp (LocalFun (List.length args, labelof dec))
       | _ -> raise InvalidNode
       in
-      init :: (trav_all args) @ [jmp]
+      InlineComment (init, nameof dec) ::
+      (trav_all args) @
+      [InlineComment (jmp, node2str node)]
 
     | Arg value -> trav value