diff options
| author | Christopher Pulte | 2015-09-24 11:31:46 +0100 |
|---|---|---|
| committer | Christopher Pulte | 2015-09-24 11:31:46 +0100 |
| commit | ddd603c61644bdef9e5b98860a448348b90b614e (patch) | |
| tree | d87075c4a8efacd4a5b9018c7324b40a3ed0c326 | |
| parent | d3c159b424533ef5f2a0c6bf37cf710adf5e36cd (diff) | |
added 'remove_vector_string_patterns and .._expressions functions
| -rw-r--r-- | src/rewriter.ml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/rewriter.ml b/src/rewriter.ml index 1682710a..74eb4bb1 100644 --- a/src/rewriter.ml +++ b/src/rewriter.ml @@ -228,3 +228,49 @@ let rewrite_defs (Defs defs) = | [] -> [] | d::ds -> (rewrite_def d)::(rewrite ds) in Defs (rewrite defs) + + +let explode s = + let rec exp i l = if i < 0 then l else exp (i - 1) (s.[i] :: l) in + exp (String.length s - 1) [] + + +let vector_string_to_bit_list lit = + + let hexchar_to_binlist = function + | '0' -> ['0';'0';'0';'0'] + | '1' -> ['0';'0';'0';'1'] + | '2' -> ['0';'0';'1';'0'] + | '3' -> ['0';'0';'1';'1'] + | '4' -> ['0';'1';'0';'0'] + | '5' -> ['0';'1';'0';'1'] + | '6' -> ['0';'1';'1';'0'] + | '7' -> ['0';'1';'1';'1'] + | '8' -> ['1';'0';'0';'0'] + | '9' -> ['1';'0';'0';'1'] + | 'A' -> ['1';'0';'1';'0'] + | 'B' -> ['1';'0';'1';'1'] + | 'C' -> ['1';'1';'0';'0'] + | 'D' -> ['1';'1';'0';'1'] + | 'E' -> ['1';'1';'1';'0'] + | 'F' -> ['1';'1';'1';'1'] in + + let s_bin = match lit with + | L_hex s_hex -> List.flatten (List.map hexchar_to_binlist (explode s_hex)) + | L_bin s_bin -> explode s_bin in + + List.map (function '0' -> L_aux (L_zero, Unknown) | '1' -> L_aux (L_one,Unknown)) s_bin + +let remove_vector_string_patterns pat = match pat with + | P_lit (L_aux (lit,_)) -> + let ps = List.map (fun p -> P_aux (P_lit p,(Unknown,simple_annot {t = Tid "bit"}))) + (vector_string_to_bit_list lit) in + P_vector ps + | _ -> pat + +let remove_vector_string_expressions exp = match exp with + | E_lit (L_aux (lit,_)) -> + let es = List.map (fun p -> E_aux (E_lit p ,(Unknown,simple_annot {t = Tid "bit"}))) + (vector_string_to_bit_list lit) in + E_vector es + | _ -> exp |
