1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# An abstraction for a pointer to a non-void type.
#
# Example usage:
#
# TODO
#
attr_reader :type
# Create a new JIT pointer type.
#
# +type+:: The pointed-to type.
#
pointer_type = self.create_pointer(type)
pointer_type.instance_eval do
@type = type
end
return pointer_type
end
# Wrap an existing void pointer.
#
# +ptr+:: The pointer to wrap.
#
return Instance.wrap(self, ptr)
end
# Return the offset (in bytes) of the element at the given +index+.
#
# +index+:: The index of the desired element.
#
return index * @type.size
end
# Return the type of the element at the given +index+.
#
# +index+:: The index of the desired element.
#
return @type
end
# An abstraction for a pointer object.
#
# Wrap an existing void pointer.
#
# +array_type+:: The JIT::Array type to wrap.
# +ptr+:: A pointer to the first element in the array.
#
value = self.new_value(ptr.function, pointer_type)
value.store(ptr)
value.instance_eval do
@pointer_type = pointer_type
@pointed_type = pointer_type.type
@function = ptr.function
@ptr = ptr
end
return value
end
# Generate JIT code to retrieve the element at the given +index+.
#
# +index+:: The index of the desired element. The value of the
# index must be known at compile-time.
#
@function.insn_load_relative(
@ptr,
@pointer_type.offset_of(index),
@pointer_type.type_of(index))
end
# Generate JIT code to assign to the element at the given +index+.
#
# +index+:: The index of the desired element. The value of the
# index must be known at compile-time.
# +value+:: The JIT::Value to assign to the element.
#
@function.insn_store_relative(
@ptr,
@pointer_type.offset_of(index),
value)
end
end
end
end