Commit dc8f107e authored by John van Groningen's avatar John van Groningen

port to 64 bit windows

parent 311b4811
......@@ -91,6 +91,11 @@ where
= s % (0,n-1);
= remove_null_chars_from_string (n+1);
freadi8 :: !*File -> (!Bool,!Int,!*File);
freadi8 file
# (r1,i1,file) = freadi file;
# (r2,i2,file) = freadi file;
= (r1 && r2,(i1 bitand 0xffffffff) + (i2<<32),file);
read_heap_file file_name files
# (ok,file,files) = fopen file_name FReadData files;
......@@ -98,22 +103,22 @@ read_heap_file file_name files
# (_,files) = fclose file files;
= (False,empty_header,empty_descriptors,{},{},{},{},files)
#!(application_name,file) = read_application_name file;
(_,heap_begin,file) = freadi file;
(_,heap_end,file) = freadi file;
(_,heap2_begin,file) = freadi file;
(_,heap2_end,file) = freadi file;
(_,stack_begin,file) = freadi file;
(_,stack_end,file) = freadi file;
(_,text_begin,file) = freadi file;
(_,data_begin,file) = freadi file;
(_,small_integers,file) = freadi file;
(_,characters,file) = freadi file;
(_,int_descriptor,file) = freadi file;
(_,char_descriptor,file) = freadi file;
(_,real_descriptor,file) = freadi file;
(_,bool_descriptor,file) = freadi file;
(_,string_descriptor,file) = freadi file;
(_,array_descriptor,file) = freadi file;
(_,heap_begin,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,heap_end,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,heap2_begin,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,heap2_end,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,stack_begin,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,stack_end,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,text_begin,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,data_begin,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,small_integers,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,characters,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,int_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,char_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,real_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,bool_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,string_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
(_,array_descriptor,file) = IF_INT_64_OR_32 (freadi8 file) (freadi file);
# (error,file) = ferror file;
| error
......@@ -166,20 +171,37 @@ find_zero_char i s
= i;
= find_zero_char (inc i) s;
WORD_SIZE_IN_BYTES:==IF_INT_64_OR_32 8 4;
WORD_SIZE_IN_BYTES_M1:==IF_INT_64_OR_32 7 3;
WORD_SIZE_IN_BITS_M1:==IF_INT_64_OR_32 63 31;
TWO_WORDS_SIZE_IN_BYTES:==IF_INT_64_OR_32 16 8;
THREE_WORDS_SIZE_IN_BYTES:==IF_INT_64_OR_32 24 12;
LOG_WORD_SIZE_IN_BYTES:==IF_INT_64_OR_32 3 2;
LOG_WORD_SIZE_IN_BITS:==IF_INT_64_OR_32 6 5;
MAX_STATIC_INT_OFFSET:==IF_INT_64_OR_32 512 256;
MAX_STATIC_CHAR_OFFSET:==IF_INT_64_OR_32 4096 2048;
LOG_WORD_SIZE_IN_BITS_P1:==IF_INT_64_OR_32 7 6;
LOG_WORD_SIZE_IN_BYTES_M1:==IF_INT_64_OR_32 2 1;
allocate_bit_array :: !Int -> .{#Int};
allocate_bit_array size_heap
= createArray ((size_heap+((1<<LOG_WORD_SIZE_IN_BITS_P1)-1))>>LOG_WORD_SIZE_IN_BITS_P1) 0;
u_get_two_bits :: !*{#Int} !Int -> (!Int,!*{#Int});
u_get_two_bits bits i
| i bitand 3==0
# (v,bits)=uselect bits (i>>6);
= ((v >> ((i>>1) bitand 31)) bitand 3,bits);
| i bitand WORD_SIZE_IN_BYTES_M1==0
# (v,bits)=bits![i>>LOG_WORD_SIZE_IN_BITS_P1];
= ((v >> ((i>>LOG_WORD_SIZE_IN_BYTES_M1) bitand WORD_SIZE_IN_BITS_M1)) bitand 3,bits);
get_two_bits bits i
# v=bits.[i>>6];
= (v >> ((i>>1) bitand 31)) bitand 3;
# v=bits.[i>>LOG_WORD_SIZE_IN_BITS_P1];
= (v >> ((i>>LOG_WORD_SIZE_IN_BYTES_M1) bitand WORD_SIZE_IN_BITS_M1)) bitand 3;
set_two_bits bits i v
# index=i>>6;
shift=(i>>1) bitand 31;
(bi,bits)=uselect bits index;
# index=i>>LOG_WORD_SIZE_IN_BITS_P1;
shift=(i>>LOG_WORD_SIZE_IN_BYTES_M1) bitand WORD_SIZE_IN_BITS_M1;
(bi,bits)=bits![index];
= {bits & [index]= (bi bitand (bitnot (3<<shift))) bitor (v << shift)};
:: Name :== (!String,!String);
......@@ -242,14 +264,9 @@ BEGIN_ARRAY_NODE:==3;
compute_sizes_by_node_kind :: !.Header .Descriptors !*{#Char} !{#Char} {#Char} {#Char} !{#Char} -> (!SizeByNodeKind,!.{#Int},!.{#Int});
compute_sizes_by_node_kind header descriptors heap heap2 data text stack
#! size_heap=size heap;
= let
bits1:: .{#Int};
bits1=createArray ((size_heap+63)>>6) 0;
bits2:: .{#Int};
bits2=createArray ((size heap2+63)>>6) 0;
in
size_stack descriptors 0 NilSizeByNodeKind bits1 bits2 heap;
bits1=allocate_bit_array size_heap;
bits2=allocate_bit_array size_heap;
= size_stack descriptors 0 NilSizeByNodeKind bits1 bits2 heap;
where
stack_size=size stack;
......@@ -258,9 +275,7 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| i>=stack_size
= (s,bits1,bits2);
# (s,bits1,bits2,heap)=compute_size_graph_by_node_kind descriptors header heap2 data text (stack LONG i) s bits1 bits2 heap (-1);
= size_stack descriptors (i+4) s bits1 bits2 heap;
= size_stack descriptors (i+WORD_SIZE_IN_BYTES) s bits1 bits2 heap;
compute_size_next_graph_by_node_kind :: .Descriptors !Header {#Char} {#Char} {#Char} !Int !SizeByNodeKind !*{#Int} !*{#Int} !*{#Char} !Int -> (!SizeByNodeKind,!*{#Int},!*{#Int},!*{#Char});
compute_size_next_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap next
......@@ -270,14 +285,14 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
#! bits=get_two_bits bits1 next_offset;
| bits==0
#! parent=heap LONG next_offset;
#! next_argument=heap LONG (next_offset-4);
# heap=update_long heap (next_offset-4) parent;
#! next_argument=heap LONG (next_offset-WORD_SIZE_IN_BYTES);
# heap=update_long heap (next_offset-WORD_SIZE_IN_BYTES) parent;
# heap=update_long heap next_offset a;
= compute_size_graph_by_node_kind descriptors header heap2 data text next_argument s bits1 bits2 heap (next-4);
= compute_size_graph_by_node_kind descriptors header heap2 data text next_argument s bits1 bits2 heap (next-WORD_SIZE_IN_BYTES);
| bits==BEGIN_NORMAL_NODE
#! parent_argument_address=heap LONG next_offset;
# heap=update_long heap next_offset a;
= compute_size_next_graph_by_node_kind descriptors header heap2 data text (next-4) s bits1 bits2 heap parent_argument_address;
= compute_size_next_graph_by_node_kind descriptors header heap2 data text (next-WORD_SIZE_IN_BYTES) s bits1 bits2 heap parent_argument_address;
| bits==BEGIN_ARGUMENT_NODE
#! parent_argument_address=heap LONG next_offset;
# heap=update_long heap next_offset a;
......@@ -285,7 +300,7 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| bits==BEGIN_ARRAY_NODE
#! parent_argument_address=heap LONG next_offset;
# heap=update_long heap next_offset a;
= compute_size_next_graph_by_node_kind descriptors header heap2 data text (next-12) s bits1 bits2 heap parent_argument_address;
= compute_size_next_graph_by_node_kind descriptors header heap2 data text (next-THREE_WORDS_SIZE_IN_BYTES) s bits1 bits2 heap parent_argument_address;
add_size_of_node_kind_and_compute_size_next_graph_by_node_kind :: .Descriptors !Header {#Char} {#Char} {#Char} !Name !Int !SizeByNodeKind !Int !*{#Int} !*{#Int} !*{#Char} !Int -> (!SizeByNodeKind,!*{#Int},!*{#Int},!*{#Char});
add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text string n s a bits1 bits2 heap next
......@@ -301,14 +316,14 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
# heap_offset=a-header.heap2_begin;
| heap_offset<0 || a>=header.heap2_end
/* node outside heap2 and heap1 */
| a>=header.small_integers && a<=header.small_integers+256
| a>=header.small_integers && a<=header.small_integers+MAX_STATIC_INT_OFFSET
// node is small integer, because the node is a small integer, it is skipped because it doesn't count.
= compute_size_next_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap next;
| a>=header.characters && a<(header.characters+2048)
| a>=header.characters && a<(header.characters+MAX_STATIC_CHAR_OFFSET)
// node is a character
= compute_size_next_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap next;
# data_offset=address_to_data_offset a header.data_begin data;
| data_offset<0 || data_offset>=size data
| (data_offset<0 || data_offset>=size data)
// node outside .data (e.g. in .text)
# text_resource_n=get_text_resource_n a header text;
| text_resource_n<0
......@@ -370,19 +385,19 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| descriptor== descriptors.real_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text Real_name 3 s a bits1 bits2 heap next;
| descriptor==descriptors.string_descriptor
# string_length=heap2 LONG (heap_offset+4);
# string_length=heap2 LONG (heap_offset+WORD_SIZE_IN_BYTES);
| string_length<=256
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text String_name (2+((string_length+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text StringLarge_name (2+((string_length+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text String_name (2+((string_length+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text StringLarge_name (2+((string_length+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| descriptor==descriptors.array_descriptor
# element_descriptor =heap2 LONG (heap_offset+8);
array_size=heap2 LONG (heap_offset+4);
# element_descriptor =heap2 LONG (heap_offset+TWO_WORDS_SIZE_IN_BYTES);
array_size=heap2 LONG (heap_offset+WORD_SIZE_IN_BYTES);
| element_descriptor==descriptors.int_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayInt_name (3+array_size) s a bits1 bits2 heap next;
| element_descriptor==descriptors.char_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayChar_name (3+((array_size+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayChar_name (3+((array_size+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| element_descriptor==descriptors.bool_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayBool_name (3+((array_size+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayBool_name (3+((array_size+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| element_descriptor==descriptors.real_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayReal_name (3+(array_size+array_size)) s a bits1 bits2 heap next;
// dus arrays met bijv. record als elementen worden niet ondersteund?
......@@ -439,13 +454,13 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| descriptor==descriptors.real_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text Real_name 3 s a bits1 bits2 heap next;
| descriptor==descriptors.string_descriptor
#! string_length=heap LONG (heap_offset+4);
#! string_length=heap LONG (heap_offset+WORD_SIZE_IN_BYTES);
| string_length<=256
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text String_name (2+((string_length+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text StringLarge_name (2+((string_length+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text String_name (2+((string_length+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text StringLarge_name (2+((string_length+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| descriptor==descriptors.array_descriptor
#! element_descriptor=heap LONG (heap_offset+8);
#! array_size=heap LONG (heap_offset+4);
#! element_descriptor=heap LONG (heap_offset+TWO_WORDS_SIZE_IN_BYTES);
#! array_size=heap LONG (heap_offset+WORD_SIZE_IN_BYTES);
| element_descriptor==0
= compute_size_array_elements_by_node_kind descriptors header heap2 data text array_size a (add_size_of_node_kind Array_name (3+array_size) s) bits1 bits2 heap next;
| element_descriptor==descriptors.string_descriptor
......@@ -453,9 +468,9 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| element_descriptor==descriptors.int_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayInt_name (3+array_size) s a bits1 bits2 heap next;
| element_descriptor==descriptors.bool_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayBool_name (3+((array_size+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayBool_name (3+((array_size+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| element_descriptor==descriptors.char_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayChar_name (3+((array_size+3)>>2)) s a bits1 bits2 heap next;
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayChar_name (3+((array_size+WORD_SIZE_IN_BYTES_M1)>>LOG_WORD_SIZE_IN_BYTES)) s a bits1 bits2 heap next;
| element_descriptor==descriptors.real_descriptor
= add_size_of_node_kind_and_compute_size_next_graph_by_node_kind descriptors header heap2 data text ArrayReal_name (3+(array_size+array_size)) s a bits1 bits2 heap next;
| element_descriptor==descriptors.array_descriptor
......@@ -493,39 +508,39 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
| a_size==0
= compute_size_next_graph_by_node_kind descriptors header heap2 data text e s bits1 bits2 heap next;
# heap_offset=e-header.heap_begin;
# last_argument_offset=heap_offset+(a_size<<2);
# bits1=set_two_bits bits1 (heap_offset+4) BEGIN_NORMAL_NODE;
# last_argument_offset=heap_offset+(a_size<<LOG_WORD_SIZE_IN_BYTES);
# bits1=set_two_bits bits1 (heap_offset+WORD_SIZE_IN_BYTES) BEGIN_NORMAL_NODE;
// a=pointer to node (node to be counted), next=address van a in its parent
#! a=heap LONG last_argument_offset;
# heap = update_long heap last_argument_offset next;
= compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (e+(a_size<<2));
= compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (e+(a_size<<LOG_WORD_SIZE_IN_BYTES));
compute_size_arguments_by_node_kind_of_split_node :: .Descriptors !Header {#Char} {#Char} {#Char} !Int !Int !SizeByNodeKind !*{#Int} !*{#Int} !*{#Char} !Int -> (!SizeByNodeKind,!*{#Int},!*{#Int},!*{#Char});
compute_size_arguments_by_node_kind_of_split_node descriptors header heap2 data text a_size e s bits1 bits2 heap next
| a_size<2
= compute_size_arguments_by_node_kind descriptors header heap2 data text a_size e s bits1 bits2 heap next;
# heap_offset=e-header.heap_begin;
# argument2_offset=heap_offset+8;
# argument2_offset=heap_offset+TWO_WORDS_SIZE_IN_BYTES;
#! argument_part=heap LONG argument2_offset;
# argument_part_offset=argument_part-header.heap_begin;
# last_argument_offset=argument_part_offset+((a_size-2)<<2);
# last_argument_offset=argument_part_offset+((a_size-2)<<LOG_WORD_SIZE_IN_BYTES);
#! a=heap LONG last_argument_offset;
# bits1=set_two_bits bits1 (heap_offset+4) BEGIN_NORMAL_NODE;
# bits1=set_two_bits bits1 (heap_offset+WORD_SIZE_IN_BYTES) BEGIN_NORMAL_NODE;
# bits1=set_two_bits bits1 argument_part_offset BEGIN_ARGUMENT_NODE;
# heap=update_long heap argument2_offset next;
# heap= update_long heap last_argument_offset (e+8);
= compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (argument_part+((a_size-2)<<2));
# heap= update_long heap last_argument_offset (e+TWO_WORDS_SIZE_IN_BYTES);
= compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (argument_part+((a_size-2)<<LOG_WORD_SIZE_IN_BYTES));
compute_size_array_elements_by_node_kind :: .Descriptors !Header {#Char} {#Char} {#Char} !Int !Int !SizeByNodeKind !*{#Int} !*{#Int} !*{#Char} !Int -> (!SizeByNodeKind,!*{#Int},!*{#Int},!*{#Char});
compute_size_array_elements_by_node_kind descriptors header heap2 data text a_size e s bits1 bits2 heap next
| a_size==0
= compute_size_next_graph_by_node_kind descriptors header heap2 data text e s bits1 bits2 heap next;
# heap_offset=e-header.heap_begin;
# last_element_offset=heap_offset+8+(a_size<<2);
# bits1=set_two_bits bits1 (heap_offset+12) BEGIN_ARRAY_NODE;
# last_element_offset=heap_offset+TWO_WORDS_SIZE_IN_BYTES+(a_size<<LOG_WORD_SIZE_IN_BYTES);
# bits1=set_two_bits bits1 (heap_offset+THREE_WORDS_SIZE_IN_BYTES) BEGIN_ARRAY_NODE;
#! a=heap LONG last_element_offset; //get ptr to last unboxed array element
# heap=update_long heap last_element_offset next;
#! (s,bits1,bits2,heap)=compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (e+8+(a_size<<2));
#! (s,bits1,bits2,heap)=compute_size_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap (e+TWO_WORDS_SIZE_IN_BYTES+(a_size<<LOG_WORD_SIZE_IN_BYTES));
= (s,bits1,bits2,heap);
compute_size_array_arguments_by_node_kind :: .Descriptors !Header {#Char} {#Char} {#Char} !Int Int !Int Int Int !Int SizeByNodeKind !*{#Int} !*{#Int} !*{#Char} !Int -> (!SizeByNodeKind,!*{#Int},!*{#Int},!*{#Char});
......@@ -534,7 +549,7 @@ compute_sizes_by_node_kind header descriptors heap heap2 data text stack
= compute_size_next_graph_by_node_kind descriptors header heap2 data text a s bits1 bits2 heap next;
| element_i==a_size
= compute_size_array_arguments_by_node_kind descriptors header heap2 data text (i+b_size) 0 array_size a_size b_size a s bits1 bits2 heap next;
#! e=heap LONG (a-header.heap_begin+((i+3)<<2));
#! e=heap LONG (a-header.heap_begin+((i+WORD_SIZE_IN_BYTES_M1)<<LOG_WORD_SIZE_IN_BYTES));
# (s,bits1,bits2,heap)=compute_size_graph_by_node_kind descriptors header heap2 data text e s bits1 bits2 heap (-1);
= compute_size_array_arguments_by_node_kind descriptors header heap2 data text (inc i) (inc element_i) array_size a_size b_size a s bits1 bits2 heap next;
......@@ -662,7 +677,7 @@ where
//*/
= picture >: draw_clipped_string_at (positions!!0+5,y_pos) function_name (positions!!1 - positions!!0-10)
>: draw_clipped_string_at (positions!!1+5,y_pos) module_name (positions!!2 - positions!!1-10)
>: draw_string_at_left (positions!!3-5,y_pos) r1 (toString (heap_size<<2))
>: draw_string_at_left (positions!!3-5,y_pos) r1 (toString (heap_size<<LOG_WORD_SIZE_IN_BYTES))
>: draw_string_at_left (positions!!4-5,y_pos) r2 (format_real 2 2 3 1000.0 (percentage heap_size node_size_sum));
where
percentage i1 i2 = if (i2==0) 0.0 ((toReal (i1*100))/(toReal i2));
......
......@@ -14,7 +14,7 @@ import StdEnv;
text_addresses :: !{#Int} // for 68k
};
import code from "file_exists.obj";
import code from "file_exists.";
PCorMac pc mac :== pc;
......@@ -56,7 +56,7 @@ read_application file_name application_file_name header files
| not ok
= abort "invalid application file";
#! (n_sections, optional_header_size, app_file) = ReadCOFFHeader app_file;
#! (code_size,data_size,base_of_code,base_of_data,image_base,section_alignment,file_alignment,app_file) = ReadOptionalHeader app_file optional_header_size;
#! (code_size,data_size,base_of_code,image_base,section_alignment,file_alignment,app_file) = ReadOptionalHeader app_file optional_header_size;
#! ((rva_raw_text,text),(rva_raw_data,data),rva_bss,app_file) = ReadSections 0 n_sections (0,"") (0,"") 0 app_file;
#! (ok,files) = fclose app_file files;
| not ok
......@@ -78,8 +78,8 @@ read_application file_name application_file_name header files
ReadCOFFHeader app_file
#! (coff_header, app_file) = freads app_file 20
#! machine = coff_header WORD 0;
| machine <> 0x14c
= abort ("invalid application file for i386");
| machine <> IF_INT_64_OR_32 0x8664 0x14c
= abort ("invalid application file for i386: "+++toString machine);
#! n_sections = coff_header WORD 2;
#! optional_header_size = coff_header WORD 16;
#! characteristics = coff_header WORD 18;
......@@ -90,16 +90,17 @@ read_application file_name application_file_name header files
ReadOptionalHeader app_file optional_header_size
#! (optional_header, app_file) = freads app_file optional_header_size;
#! magic = optional_header WORD 0;
| magic <> 0x10b
| magic <> IF_INT_64_OR_32 0x20b 0x10b
= abort ("incorrect magic number");
#! code_size = optional_header LONG 4;
#! data_size = optional_header LONG 8;
#! base_of_code = optional_header LONG 20;
#! base_of_data = optional_header LONG 24;
#! image_base = optional_header LONG 28;
#! image_base = IF_INT_64_OR_32
(((optional_header LONG 24) bitand 0xffffffff) + (optional_header LONG 28<<32))
(optional_header LONG 28);
#! section_alignment = optional_header LONG 32;
#! file_alignment = optional_header LONG 36;
= (code_size,data_size,base_of_code,base_of_data,image_base,section_alignment,file_alignment,app_file);
= (code_size,data_size,base_of_code,image_base,section_alignment,file_alignment,app_file);
ReadSections section_n n_sections text=:(rva_raw_text,raw_text) data=:(rva_raw_data,raw_data) rva_bss app_file
| (section_n == n_sections)
......@@ -171,10 +172,15 @@ get_string_from_offset name_offset data
constructor_name :: !Int !Int !Int !{#Char} {#Char} -> (!{#Char},!{#Char});
constructor_name data_begin data_offset arity data text
# descriptor_max_arity_offset = data_offset + (data WORD (data_offset+2));
#! string_offset = descriptor_max_arity_offset+12;
# module_name_pointer = data LONG (descriptor_max_arity_offset + 8);
/*
# nameP = data_offset - (data WORD (data_offset+2));
# total_descriptor_arity = data WORD (nameP - 2);
#! string_offset = nameP+4 + (total_descriptor_arity << 3);
# module_name_pointer = data LONG (nameP - 12);
*/
= (get_string_from_offset string_offset data, get_string_from_pointer module_name_pointer data_begin data);
closure_text_offset descriptor _ /*text_resource_n*/ header
......@@ -189,9 +195,15 @@ get_closure_name :: !Int .a .b !Header !{#Char} !{#Char} -> .(!{#Char},!{#Char})
get_closure_name text_offset arity text_resource_n header text data
# descriptor_pointer = text LONG (text_offset - 4);
# descriptor_offset = address_to_data_offset descriptor_pointer header.data_begin data;
# descriptor_max_arity_offset = descriptor_offset + (data WORD (descriptor_offset+2));
#! function_name_offset = descriptor_max_arity_offset+12;
# module_name_pointer = data LONG (descriptor_max_arity_offset + 8);
/*
# descriptor_arity=data WORD (descriptor_offset-2);
#! function_name_offset = descriptor_offset+4+(descriptor_arity<<3);
#! module_name_pointer = data LONG (descriptor_offset - 12);
*/
= (get_string_from_offset function_name_offset data,get_string_from_pointer module_name_pointer header.data_begin data);
record_name :: !Header !Int !{#Char} .b -> .(!{#Char},!{#Char});
......@@ -208,6 +220,8 @@ record_name header data_offset data text
((string BYTE i) bitor (string BYTE (i+1) << 8));
(LONG) :: !{#Char} !Int -> Int;
(LONG) string i = IF_BIG_ENDIAN
(LONG) string i
# r = IF_BIG_ENDIAN
((string BYTE i<<24) bitor (string BYTE (i+1)<<16) bitor (string BYTE (i+2)<<8) bitor (string BYTE (i+3)))
(((string BYTE i) bitor (string BYTE (i+1) << 8) bitor (string BYTE (i+2) << 16) bitor (string BYTE (i+3) << 24)));
= IF_INT_64_OR_32 ((r<<32)>>32) r;
#include <windows.h>
typedef struct clean_string
{ int length;
{ size_t length;
char characters[1];
} *CLEAN_STRING;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment