diff options
| author | Alasdair | 2018-06-23 18:16:42 +0100 |
|---|---|---|
| committer | Alasdair | 2018-06-23 18:23:21 +0100 |
| commit | 5f729ff5afbe26423143006cf616f11d0790ac01 (patch) | |
| tree | 7dd09b5bef8b81d51470cf629d81daa6909dfdb3 /src/bytecode_util.ml | |
| parent | 74e459da59e8411de84bded89d010e62fd735d29 (diff) | |
Split Sail->ANF translation into its own file
Refactor the C compilation process by moving out the conversion to
A-normal form into its own file. Also make the A-normal form AST
parameterised by the type of the types annotating it. The idea being we
can have a typ aexp -> ctyp aexp translation, converting to low-level
types at a slightly higher level before mapping into our low-level IR.
This would fix some issues we have where the type of variables change
due to flow typing, because we could map the sail types to low-level
types in the ANF ast where we still have some knowledge about the
structure of the original Sail.
Diffstat (limited to 'src/bytecode_util.ml')
| -rw-r--r-- | src/bytecode_util.ml | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bytecode_util.ml b/src/bytecode_util.ml index da7d3c31..9f23412e 100644 --- a/src/bytecode_util.ml +++ b/src/bytecode_util.ml @@ -116,6 +116,20 @@ let iraw ?loc:(l=Parse_ast.Unknown) str = let ijump ?loc:(l=Parse_ast.Unknown) cval label = I_aux (I_jump (cval, label), (instr_number (), l)) +let rec frag_rename from_id to_id = function + | F_id id when Id.compare id from_id = 0 -> F_id to_id + | F_id id -> F_id id + | F_ref id when Id.compare id from_id = 0 -> F_ref to_id + | F_ref id -> F_ref id + | F_lit v -> F_lit v + | F_have_exception -> F_have_exception + | F_current_exception -> F_current_exception + | F_call (call, frags) -> F_call (call, List.map (frag_rename from_id to_id) frags) + | F_op (f1, op, f2) -> F_op (frag_rename from_id to_id f1, op, frag_rename from_id to_id f2) + | F_unary (op, f) -> F_unary (op, frag_rename from_id to_id f) + | F_field (f, field) -> F_field (frag_rename from_id to_id f, field) + | F_raw raw -> F_raw raw + (**************************************************************************) (* 1. Instruction pretty printer *) (**************************************************************************) |
