Ignore:
Timestamp:
Sep 24, 2010, 1:36:41 PM (9 years ago)
Author:
mulligan
Message:

Some utility functions useful across modules moved into new file Util.
Started working on parser for Intel hex file format. Moved
physical.ml*' to Physical.ml*' for naming consistency across modules.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/IntelHex.ml

    r123 r128  
    11open BitVectors;;
    22open ASM;;
     3open Util;;
    34
    45type intel_hex_entry_type =
     
    1617};;
    1718
    18 let hex_string_of_vect x = "00"
     19let 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
     28
     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
     39let int_of_hex_string h =
     40  let digit_lookup =
     41    function
     42      '0' -> 0 | '1' -> 1 | '2' -> 2
     43    | '3' -> 3 | '4' -> 4 | '5' -> 5
     44    | '6' -> 6 | '7' -> 7 | '8' -> 8
     45    | '9' -> 9 | 'A' -> 10 | 'B' -> 11
     46    | 'C' -> 12 | 'D' -> 13 | 'E' -> 14
     47    | 'F' -> 15 | _ -> assert false in
     48
     49  let rec aux l p =
     50    match l with
     51      [] -> 0
     52    | hd::tl ->
     53        digit_lookup hd * p + aux tl (p * 16)
     54  in
     55    aux (List.rev $ char_list_of_string h) 1
     56
     57let hex_string_of_vect v =
     58  let vect_int = int_of_vect v in
     59    hex_string_of_int vect_int
    1960
    2061let string_of_intel_hex_entry entry =
Note: See TracChangeset for help on using the changeset viewer.