Changeset 130 for Deliverables
- Timestamp:
- Sep 25, 2010, 5:23:53 PM (10 years ago)
- Location:
- Deliverables/D4.1
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Deliverables/D4.1/ASMInterpret.ml
r129 r130 4 4 open Pretty;; 5 5 open IntelHex;; 6 open Parser;; 6 7 7 8 exception Fetch_exception of string;; -
Deliverables/D4.1/IntelHex.ml
r128 r130 2 2 open ASM;; 3 3 open Util;; 4 open Parser;; 4 5 5 6 type intel_hex_entry_type = … … 8 9 | ExtendedSeg 9 10 | ExtendedLinear 11 ;; 10 12 11 13 type intel_hex_entry = 12 14 { 13 15 record_length: byte * byte; 16 record_addr: byte * byte * byte * byte; 14 17 record_type: intel_hex_entry_type; 15 18 data_field: byte list; 16 19 data_checksum: byte * byte 17 };; 20 } 21 ;; 18 22 19 let hex_string_of_int i = 20 let digit_lookup = 21 function 22 0 -> "0" | 1 -> "1" | 2 -> "2" 23 | 3 -> "3" | 4 -> "4" | 5 -> "5" 24 | 6 -> "6" | 7 -> "7" | 8 -> "8" 25 | 9 -> "9" | 10 -> "A" | 11 -> "B" 26 | 12 -> "C" | 13 -> "D" | 14 -> "E" 27 | 15 -> "F" | _ -> assert false in 23 type intel_hex_format = intel_hex_entry list;; 28 24 29 let rec aux i = 30 if i < 16 then 31 digit_lookup i 32 else 33 let div = i / 16 in 34 let rem = i mod 16 in 35 aux div ^ digit_lookup rem 36 in 37 aux i 38 39 let int_of_hex_string h = 40 let digit_lookup = 25 let hex_digit_of_char = 41 26 function 42 27 '0' -> 0 | '1' -> 1 | '2' -> 2 … … 45 30 | '9' -> 9 | 'A' -> 10 | 'B' -> 11 46 31 | 'C' -> 12 | 'D' -> 13 | 'E' -> 14 47 | 'F' -> 15 | _ -> assert false in32 | 'F' -> 15 | _ -> assert false 48 33 49 let rec aux l p = 50 match l with 51 [] -> 0 52 | hd::tl -> 53 digit_lookup hd * p + aux tl (p * 16) 34 let vect_of_hex_string s size = 35 let int_of_hex_string h = 36 let rec aux l p = 37 match l with 38 [] -> 0 39 | hd::tl -> 40 hex_digit_of_char hd * p + aux tl (p * 16) 41 in 42 aux (List.rev $ char_list_of_string h) 1 54 43 in 55 aux (List.rev $ char_list_of_string h) 1 44 let i_str = int_of_hex_string s in 45 vect_of_int i_str size 46 ;; 56 47 57 48 let hex_string_of_vect v = 58 let vect_int = int_of_vect v in 59 hex_string_of_int vect_int 49 let hex_string_of_int i = 50 let digit_lookup = 51 function 52 0 -> "0" | 1 -> "1" | 2 -> "2" 53 | 3 -> "3" | 4 -> "4" | 5 -> "5" 54 | 6 -> "6" | 7 -> "7" | 8 -> "8" 55 | 9 -> "9" | 10 -> "A" | 11 -> "B" 56 | 12 -> "C" | 13 -> "D" | 14 -> "E" 57 | 15 -> "F" | _ -> assert false in 58 59 let rec aux i = 60 if i < 16 then 61 digit_lookup i 62 else 63 let div = i / 16 in 64 let rem = i mod 16 in 65 aux div ^ digit_lookup rem 66 in 67 aux i 68 in 69 let vect_int = int_of_vect v in 70 hex_string_of_int vect_int 71 ;; 72 73 let intel_hex_entry_type_of_int = 74 function 75 0 -> Data 76 | 1 -> End 77 | 2 -> ExtendedSeg 78 | 4 -> ExtendedLinear 79 | _ -> assert false 80 ;; 81 82 let prs_length = 83 prs_hex_digit >>= 84 fun a -> prs_hex_digit >>= 85 fun b -> return (vect_of_hex_string (String.make 1 a) `Eight, 86 vect_of_hex_string (String.make 1 b) `Eight) 87 ;; 88 89 let prs_addr = 90 prs_hex_digit >>= 91 fun a -> prs_hex_digit >>= 92 fun b -> prs_hex_digit >>= 93 fun c -> prs_hex_digit >>= 94 fun d -> return $ (vect_of_hex_string (String.make 1 a) `Eight, 95 vect_of_hex_string (String.make 1 b) `Eight, 96 vect_of_hex_string (String.make 1 c) `Eight, 97 vect_of_hex_string (String.make 1 d) `Eight) 98 ;; 99 100 let prs_type = 101 prs_hex_digit >>= 102 fun a -> prs_hex_digit >>= 103 fun b -> 104 let a_as_hex = hex_digit_of_char a in 105 let b_as_hex = hex_digit_of_char b in 106 let total = a_as_hex + b_as_hex in 107 return $ intel_hex_entry_type_of_int total 108 109 let prs_data len = 110 prs_exact len $ prs_hex_digit >>= 111 fun a -> 112 let a_as_strs = List.map (String.make 1) a in 113 let byte_data = List.map (fun x -> vect_of_hex_string x `Eight) a_as_strs in 114 return $ byte_data 115 ;; 116 117 let prs_checksum = 118 prs_hex_digit >>= 119 fun a -> prs_hex_digit >>= 120 fun b -> return (vect_of_hex_string (String.make 1 a) `Eight, 121 vect_of_hex_string (String.make 1 b) `Eight) 122 ;; 123 124 let prs_intel_hex_record = 125 prs_char ':' >>= 126 fun a -> prs_length >>= 127 fun b -> prs_addr >>= 128 fun c -> prs_type >>= 129 fun d -> 130 let (l_u_b, l_l_b) = b in 131 let len = int_of_vect (mk_word l_u_b l_l_b) in 132 prs_data len >>= 133 fun e -> prs_checksum >>= 134 fun f -> 135 return $ { 136 record_length = b; 137 record_addr = c; 138 record_type = d; 139 data_field = e; 140 data_checksum = f 141 } 142 ;; 143 144 let prs_intel_hex_format = 145 prs_sep_by prs_intel_hex_record (prs_char '\n') 146 ;; 147 148 let intel_hex_format_of_string s = 149 let chars = char_list_of_string s in 150 match prs_intel_hex_format chars with 151 [] -> None 152 | (prs,_)::_ -> Some prs 60 153 61 154 let string_of_intel_hex_entry entry = 62 155 let record_length_l, record_length_r = entry.record_length in 156 let record_addr_1, record_addr_2, record_addr_3, record_addr_4 = entry.record_addr in 63 157 let data_checksum_l, data_checksum_r = entry.data_checksum in 64 158 let length_string = hex_string_of_vect record_length_l ^ 65 159 hex_string_of_vect record_length_l in 160 let addr_string = hex_string_of_vect record_addr_1 ^ 161 hex_string_of_vect record_addr_2 ^ 162 hex_string_of_vect record_addr_3 ^ 163 hex_string_of_vect record_addr_4 in 66 164 let checksum_string = hex_string_of_vect data_checksum_l ^ 67 165 hex_string_of_vect data_checksum_r in … … 73 171 | ExtendedLinear -> "04" in 74 172 let data_string = String.concat "" (List.map hex_string_of_vect entry.data_field) in 75 ":" ^ length_string ^ type_string ^ data_string ^ checksum_string 173 ":" ^ length_string ^ addr_string ^ type_string ^ data_string ^ checksum_string 174 ;; 175 176 let string_of_intel_hex_format f = 177 let strs = List.map string_of_intel_hex_entry f in 178 let rec aux = 179 function 180 [] -> "" 181 | [e] -> e 182 | hd::tl -> hd ^ "\n" ^ aux tl 183 in 184 aux strs -
Deliverables/D4.1/IntelHex.mli
r123 r130 1 1 open BitVectors;; 2 2 open ASM;; 3 open Parser;; 3 4 4 5 type intel_hex_entry_type = … … 7 8 | ExtendedSeg 8 9 | ExtendedLinear 10 ;; 9 11 10 12 type intel_hex_entry = 11 13 { 12 14 record_length: byte * byte; 15 record_addr: byte * byte * byte * byte; 13 16 record_type: intel_hex_entry_type; 14 17 data_field: byte list; … … 16 19 };; 17 20 18 (* val intel_hex_of_instructions: instruction list -> intel_hex_entry list *) 19 val string_of_intel_hex_entry: intel_hex_entry -> string 21 type intel_hex_format = intel_hex_entry list;; 22 23 val string_of_intel_hex_format: intel_hex_format -> string;; 24 val prs_intel_hex_format: intel_hex_format parser;; 25 26 val vect_of_hex_string: string -> sizes -> sizes vect;; 27 val hex_string_of_vect: 'a vect -> string;; -
Deliverables/D4.1/Util.ml
r128 r130 1 1 let ($) f x = f x 2 ;; 3 4 let (<*>) f g x = f (g x) 5 ;; 2 6 3 7 let char_list_of_string s =
Note: See TracChangeset
for help on using the changeset viewer.