Add copyright notices and new function String.chomp
[ocaml.git] / asmcomp / mach.ml
blob13c831fc1c647d582cd1e61b4774c83389ae97f3
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 (* Representation of machine code by sequences of pseudoinstructions *)
17 type integer_comparison =
18 Isigned of Cmm.comparison
19 | Iunsigned of Cmm.comparison
21 type integer_operation =
22 Iadd | Isub | Imul | Idiv | Imod
23 | Iand | Ior | Ixor | Ilsl | Ilsr | Iasr
24 | Icomp of integer_comparison
25 | Icheckbound
27 type test =
28 Itruetest
29 | Ifalsetest
30 | Iinttest of integer_comparison
31 | Iinttest_imm of integer_comparison * int
32 | Ifloattest of Cmm.comparison * bool
33 | Ioddtest
34 | Ieventest
36 type operation =
37 Imove
38 | Ispill
39 | Ireload
40 | Iconst_int of nativeint
41 | Iconst_float of string
42 | Iconst_symbol of string
43 | Icall_ind
44 | Icall_imm of string
45 | Itailcall_ind
46 | Itailcall_imm of string
47 | Iextcall of string * bool
48 | Istackoffset of int
49 | Iload of Cmm.memory_chunk * Arch.addressing_mode
50 | Istore of Cmm.memory_chunk * Arch.addressing_mode
51 | Ialloc of int
52 | Iintop of integer_operation
53 | Iintop_imm of integer_operation * int
54 | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf
55 | Ifloatofint | Iintoffloat
56 | Ispecific of Arch.specific_operation
58 type instruction =
59 { desc: instruction_desc;
60 next: instruction;
61 arg: Reg.t array;
62 res: Reg.t array;
63 dbg: Debuginfo.t;
64 mutable live: Reg.Set.t }
66 and instruction_desc =
67 Iend
68 | Iop of operation
69 | Ireturn
70 | Iifthenelse of test * instruction * instruction
71 | Iswitch of int array * instruction array
72 | Iloop of instruction
73 | Icatch of int * instruction * instruction
74 | Iexit of int
75 | Itrywith of instruction * instruction
76 | Iraise
78 type fundecl =
79 { fun_name: string;
80 fun_args: Reg.t array;
81 fun_body: instruction;
82 fun_fast: bool }
84 let rec dummy_instr =
85 { desc = Iend;
86 next = dummy_instr;
87 arg = [||];
88 res = [||];
89 dbg = Debuginfo.none;
90 live = Reg.Set.empty }
92 let end_instr () =
93 { desc = Iend;
94 next = dummy_instr;
95 arg = [||];
96 res = [||];
97 dbg = Debuginfo.none;
98 live = Reg.Set.empty }
100 let instr_cons d a r n =
101 { desc = d; next = n; arg = a; res = r;
102 dbg = Debuginfo.none; live = Reg.Set.empty }
104 let instr_cons_debug d a r dbg n =
105 { desc = d; next = n; arg = a; res = r; dbg = dbg; live = Reg.Set.empty }
107 let rec instr_iter f i =
108 match i.desc with
109 Iend -> ()
110 | _ ->
111 f i;
112 match i.desc with
113 Iend -> ()
114 | Ireturn | Iop(Itailcall_ind) | Iop(Itailcall_imm _) -> ()
115 | Iifthenelse(tst, ifso, ifnot) ->
116 instr_iter f ifso; instr_iter f ifnot; instr_iter f i.next
117 | Iswitch(index, cases) ->
118 for i = 0 to Array.length cases - 1 do
119 instr_iter f cases.(i)
120 done;
121 instr_iter f i.next
122 | Iloop(body) ->
123 instr_iter f body; instr_iter f i.next
124 | Icatch(_, body, handler) ->
125 instr_iter f body; instr_iter f handler; instr_iter f i.next
126 | Iexit _ -> ()
127 | Itrywith(body, handler) ->
128 instr_iter f body; instr_iter f handler; instr_iter f i.next
129 | Iraise -> ()
130 | _ ->
131 instr_iter f i.next