summaryrefslogtreecommitdiff
path: root/mips.ml
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-14 09:39:18 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-14 09:39:18 +0100
commiteae584152cd35e0ee489a7f2938878fb294faa9e (patch)
treefd5472f1d24f7e385d0cbdfe1a2a7c325272cce9 /mips.ml
parent44b8335645e10cc1065eea8c904a3b8bd11da378 (diff)
downloadpetitcaml-eae584152cd35e0ee489a7f2938878fb294faa9e.tar.gz
petitcaml-eae584152cd35e0ee489a7f2938878fb294faa9e.tar.bz2
[petitcaml] Make it actually work
Diffstat (limited to 'mips.ml')
-rw-r--r--mips.ml25
1 files changed, 18 insertions, 7 deletions
diff --git a/mips.ml b/mips.ml
index ee0d046..2b4cee8 100644
--- a/mips.ml
+++ b/mips.ml
@@ -11,7 +11,11 @@ type register =
type label = string
type regaddress = int * register
-type ident_address = Alab of label | Areg of regaddress
+type ident_address =
+ | Alab of label
+ | Areg of register
+ | Amem of regaddress
+ | Aclosure of int * regaddress
type instruction =
| Move of register * register
@@ -40,9 +44,10 @@ type instruction =
| Blez of register * label
| J of label
| Jal of label
- | Jalr of register * register
+ | Jalr of register
| Jr of register
| Syscall
+ | Comment of string
| Label of label
| Asciiz of label * string
| Word of label * int
@@ -164,20 +169,22 @@ let print_instruction fmt = function
fprintf fmt "\tj %s\n" s
| Jal s ->
fprintf fmt "\tjal %s\n" s
- | Jalr (radd, rsave) ->
- fprintf fmt "\tjalr %a, %a\n" print_register radd print_register rsave
+ | Jalr radd ->
+ fprintf fmt "\tjalr %a\n" print_register radd
| Jr r ->
fprintf fmt "\tjr %a\n" print_register r
| Syscall ->
fprintf fmt "\tsyscall\n"
| Label s ->
- fprintf fmt "%s:" s
+ fprintf fmt "%s:\n" s
+ | Comment s ->
+ fprintf fmt "\t# %s\n" s
| Asciiz _
| Word _ -> failwith "Unreachable matching"
let print_data fmt = function
| Asciiz (l, s) ->
- fprintf fmt "%s:\t.asciiz %s\n" l s
+ fprintf fmt "%s:\t.asciiz %S\n" l s
| Word (l, n) ->
fprintf fmt "%s:\t.word %d\n" l n
| _ -> failwith "Unreachable matching"
@@ -186,6 +193,11 @@ type program =
{ text : instruction list ;
data : instruction list }
+let rec filter_comments = function
+ | [] -> []
+ | (Comment c)::l -> filter_comments l
+ | x::l -> x::(filter_comments l)
+
let rec filter_program = function
| [] -> { text = [] ; data = [] }
| (Asciiz (label, s))::l ->
@@ -206,4 +218,3 @@ let format_program fmt p =
List.iter (print_instruction fmt) p.text;
fprintf fmt "\t.data\n";
List.iter (print_data fmt) p.data
-