|
@@ -132,23 +132,28 @@ let rec instr2str = function
|
|
|
let rec print_assembly oc instrs =
|
|
let rec print_assembly oc instrs =
|
|
|
let output_line line =
|
|
let output_line line =
|
|
|
output_string oc line;
|
|
output_string oc line;
|
|
|
- output_char oc '\n';
|
|
|
|
|
|
|
+ output_char oc '\n'
|
|
|
in
|
|
in
|
|
|
|
|
+
|
|
|
|
|
+ (* Print instructions to outfile and collect directives in endbuf list *)
|
|
|
let endbuf = ref [] in
|
|
let endbuf = ref [] in
|
|
|
let rec trav = function
|
|
let rec trav = function
|
|
|
| [] -> ()
|
|
| [] -> ()
|
|
|
| EmptyLine :: tl -> output_line ""; trav tl
|
|
| EmptyLine :: tl -> output_line ""; trav tl
|
|
|
| hd :: tl ->
|
|
| hd :: tl ->
|
|
|
- let line = instr2str hd in
|
|
|
|
|
begin
|
|
begin
|
|
|
- if String.length line > 0 && line.[0] = '.' then
|
|
|
|
|
- endbuf := line :: !endbuf
|
|
|
|
|
- else if String.length line > 0 then
|
|
|
|
|
- output_line line
|
|
|
|
|
|
|
+ match instr2str hd with
|
|
|
|
|
+ | "" -> ()
|
|
|
|
|
+ | line when line.[0] = '.' -> endbuf := line :: !endbuf
|
|
|
|
|
+ | line -> output_line line
|
|
|
end;
|
|
end;
|
|
|
trav tl
|
|
trav tl
|
|
|
in
|
|
in
|
|
|
trav instrs;
|
|
trav instrs;
|
|
|
|
|
+
|
|
|
|
|
+ (* Directives (lines beginning with a '.') are collected in endbuf and are
|
|
|
|
|
+ * printed at the end of the file here. The directives are sorted by the first
|
|
|
|
|
+ * 7 characters to group directive opcodes *)
|
|
|
if List.length !endbuf > 1 then begin
|
|
if List.length !endbuf > 1 then begin
|
|
|
output_line (instr2str (Comment ("globals:")));
|
|
output_line (instr2str (Comment ("globals:")));
|
|
|
let cmp a b = compare (String.sub b 0 7) (String.sub a 0 7) in
|
|
let cmp a b = compare (String.sub b 0 7) (String.sub a 0 7) in
|