summaryrefslogtreecommitdiff
path: root/mips.ml
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2009-01-14 20:38:38 +0100
committerGuillaume Seguin <guillaume@segu.in>2009-01-14 20:38:38 +0100
commit0c80d91036efe66957039b6bf0c88aa73ff7dc14 (patch)
treebe29867afc30ae41fa74f8d3ecea6ed46f321d33 /mips.ml
parent9d878f3e39a2bd46e652d2b0cac4f82046728b52 (diff)
downloadpetitcaml-0c80d91036efe66957039b6bf0c88aa73ff7dc14.tar.gz
petitcaml-0c80d91036efe66957039b6bf0c88aa73ff7dc14.tar.bz2
[petitcaml] mips* : comment and fix strings support
Diffstat (limited to 'mips.ml')
-rw-r--r--mips.ml16
1 files changed, 15 insertions, 1 deletions
diff --git a/mips.ml b/mips.ml
index 2b4cee8..496009c 100644
--- a/mips.ml
+++ b/mips.ml
@@ -1,3 +1,7 @@
+(****************************************
+ mips.ml - opérations mips & formatage
+ ****************************************)
+
open Format
type register =
@@ -52,6 +56,7 @@ type instruction =
| Asciiz of label * string
| Word of label * int
+(* Formateurs divers et variés *)
let print_register fmt = function
| ZERO -> pp_print_string fmt "$zero"
| V0 -> pp_print_string fmt "$v0"
@@ -182,9 +187,16 @@ let print_instruction fmt = function
| Asciiz _
| Word _ -> failwith "Unreachable matching"
+let rec output_byte = function
+ | "" -> "0"
+ | s ->
+ let c = s.[0] and s2 = String.sub s 1 ((String.length s) - 1)
+ in
+ (Printf.sprintf "%d, " (int_of_char c)) ^ (output_byte s2)
+
let print_data fmt = function
| Asciiz (l, s) ->
- fprintf fmt "%s:\t.asciiz %S\n" l s
+ fprintf fmt "%s:\t.byte %s\n" l (output_byte s)
| Word (l, n) ->
fprintf fmt "%s:\t.word %d\n" l n
| _ -> failwith "Unreachable matching"
@@ -193,11 +205,13 @@ type program =
{ text : instruction list ;
data : instruction list }
+(* Supprime les commentaires du code assembleur *)
let rec filter_comments = function
| [] -> []
| (Comment c)::l -> filter_comments l
| x::l -> x::(filter_comments l)
+(* Sépare les data des instructions text *)
let rec filter_program = function
| [] -> { text = [] ; data = [] }
| (Asciiz (label, s))::l ->