2 * Once the label resolution has been performed,
3 * build the actual binary data.
5 * ----------------------------------------------------------------
8 * Copyright (C) 2001 Jason Hickey, Caltech
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Author: Jason Hickey
25 * @email{jyh@cs.caltech.edu}
44 let bfd_print_int8 data pos i
=
45 data
.[pos
] <- Char.chr
(i
land 0xff)
47 let bfd_print_int16 data pos i
=
48 data
.[pos
+ 0] <- Char.chr
((i
lsr 0) land 0xff);
49 data
.[pos
+ 1] <- Char.chr
((i
lsr 8) land 0xff)
51 let bfd_print_int24 data pos i
=
52 data
.[pos
+ 0] <- Char.chr
((i
lsr 0) land 0xff);
53 data
.[pos
+ 1] <- Char.chr
((i
lsr 8) land 0xff);
54 data
.[pos
+ 2] <- Char.chr
((i
lsr 16) land 0xff)
56 let bfd_print_int32 data pos i
=
57 data
.[pos
+ 0] <- Char.chr
((Int32.to_int
(Int32.shift_right i
0)) land 0xff);
58 data
.[pos
+ 1] <- Char.chr
((Int32.to_int
(Int32.shift_right i
8)) land 0xff);
59 data
.[pos
+ 2] <- Char.chr
((Int32.to_int
(Int32.shift_right i
16)) land 0xff);
60 data
.[pos
+ 3] <- Char.chr
((Int32.to_int
(Int32.shift_right i
24)) land 0xff)
62 let bfd_print_int64 data pos i
=
63 data
.[pos
+ 0] <- Char.chr
((Int64.to_int
(Int64.shift_right i
0)) land 0xff);
64 data
.[pos
+ 1] <- Char.chr
((Int64.to_int
(Int64.shift_right i
8)) land 0xff);
65 data
.[pos
+ 2] <- Char.chr
((Int64.to_int
(Int64.shift_right i
16)) land 0xff);
66 data
.[pos
+ 3] <- Char.chr
((Int64.to_int
(Int64.shift_right i
24)) land 0xff);
67 data
.[pos
+ 4] <- Char.chr
((Int64.to_int
(Int64.shift_right i
32)) land 0xff);
68 data
.[pos
+ 5] <- Char.chr
((Int64.to_int
(Int64.shift_right i
40)) land 0xff);
69 data
.[pos
+ 6] <- Char.chr
((Int64.to_int
(Int64.shift_right i
48)) land 0xff);
70 data
.[pos
+ 7] <- Char.chr
((Int64.to_int
(Int64.shift_right i
56)) land 0xff)
73 * Make the choice, and print the buffer.
75 let rec bfd_print_choice venv data pos e cases
=
76 let rec search = function
78 let { choice_enabled
= enabled
;
79 choice_interval
= interval
;
85 assert (interval_test
(eval_eager_exp venv e
) interval
);
86 bfd_print_buf venv data pos buf
90 if debug debug_bfd_choice
&& interval_test
(eval_eager_exp venv e
) interval
then
91 eprintf
"Bfd_flatten.bfd_print_choice: choice was mistaken@.";
95 raise
(Failure
"Bfd_flatten.bfd_print_item.search")
102 and bfd_print_item venv data pos item
=
106 | BufSkip
(bfd_skip
, fill
) ->
107 let fill = Char.chr
fill in
108 for i
= 0 to pred bfd_skip
do
109 data
.[pos
+ i
] <- fill
113 let len = String.length s
in
114 String.blit s
0 data pos
len;
117 let len = String.length s
in
118 String.blit s
0 data pos
len;
119 data
.[pos
+ len] <- '
\000'
;
122 bfd_print_int8 data pos i
;
125 bfd_print_int16 data pos i
;
128 bfd_print_int24 data pos i
;
131 bfd_print_int32 data pos i
;
134 bfd_print_int64 data pos i
;
137 Float80.blit_float32 x data pos
;
140 Float80.blit_float64 x data pos
;
143 Float80.blit_float80 x data pos
;
145 | BufCommon
(_
, _
, size
) ->
151 reloc
.reloc_pos
<- reloc
.reloc_offset
+ pos
;
153 | BufChoice
(e
, cases
) ->
154 bfd_print_choice venv data pos e cases
156 and bfd_print_items venv data pos items
=
157 List.fold_left
(bfd_print_item venv data
) pos items
159 and bfd_print_buf venv data pos buf
=
160 bfd_print_items venv data pos
(buffer_items buf
)
163 * Print the data for a section.
165 let bfd_print_raw_section venv sect
=
166 let { sect_name
= name
;
171 let data = String.make
len fill in
172 let len'
= bfd_print_buf venv
data 0 sect
.sect_data
in
173 let len'
= do_align
len'
64 in
175 sect
.sect_object
<- data
178 * Marshal a value section.
180 let bfd_print_value_section sect
=
181 let { val_data
= data } = sect
in
182 sect
.val_object
<- Marshal.to_string
data []
185 * Produce the object for the BFD.
187 let flatten_bfd bfd
=
188 List.iter
(bfd_print_raw_section bfd
.bfd_venv
) (raw_sections bfd
);
189 List.iter
bfd_print_value_section (val_sections bfd
)
196 * Caml-master: "compile"