public
Rubygem
Description: LLVM bindings for Ruby
Homepage: http://llvmruby.org
Clone URL: git://github.com/tombagby/llvmruby.git
add inspector methods for allocation instructions
tombagby (author)
Sun Oct 19 14:05:01 -0700 2008
commit  e0eb33ec85b71d3761cb648e1fdc89a724b5bb9e
tree    0571bb0e88f74eed6f7b0459ca07ea2f44235d1e
parent  f26df3f0f9db776e33e04ee129d1a754b72e3bb1
...
135
136
137
138
 
139
140
141
...
155
156
157
158
 
159
160
161
...
135
136
137
 
138
139
140
141
...
155
156
157
 
158
159
160
161
0
@@ -135,7 +135,7 @@ llvm_builder_malloc(VALUE self, VALUE rtype, VALUE rsize) {
0
 
0
   Value *size = ConstantInt::get(Type::Int32Ty, FIX2INT(rsize));
0
   Value *v = builder->CreateMalloc(type, size);
0
-  return llvm_value_wrap(v);
0
+  return Data_Wrap_Struct(cLLVMAllocationInst, NULL, NULL, v);
0
 }
0
 
0
 VALUE
0
@@ -155,7 +155,7 @@ llvm_builder_alloca(VALUE self, VALUE rtype, VALUE rsize) {
0
 
0
   Value *size = ConstantInt::get(Type::Int32Ty, FIX2INT(rsize));
0
   Value *v = builder->CreateAlloca(type, size);
0
-  return llvm_value_wrap(v);
0
+  return Data_Wrap_Struct(cLLVMAllocationInst, NULL, NULL, v);
0
 }
0
 
0
 VALUE
...
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
116
117
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
0
@@ -112,6 +112,32 @@ llvm_switch_inst_add_case(VALUE self, VALUE rci, VALUE rbb) {
0
   return self;
0
 }
0
 
0
+#define DATA_GET_ALLOCATION_INST AllocationInst *ai; Data_Get_Struct(self, AllocationInst, ai);
0
+
0
+VALUE 
0
+llvm_allocation_inst_is_array_allocation(VALUE self) {
0
+  DATA_GET_ALLOCATION_INST
0
+  return ai->isArrayAllocation() ? true : false;
0
+}
0
+
0
+VALUE 
0
+llvm_allocation_inst_array_size(VALUE self) {
0
+  DATA_GET_ALLOCATION_INST
0
+  return llvm_value_wrap(ai->getArraySize());
0
+}
0
+
0
+VALUE 
0
+llvm_allocation_inst_allocated_type(VALUE self) {
0
+  DATA_GET_ALLOCATION_INST
0
+  Type *at = const_cast<Type*>(ai->getAllocatedType()); 
0
+  return Data_Wrap_Struct(cLLVMType, NULL, NULL, at);
0
+}
0
+
0
+VALUE 
0
+llvm_allocation_inst_alignment(VALUE self) {
0
+  DATA_GET_ALLOCATION_INST
0
+  return INT2FIX(ai->getAlignment());
0
+}
0
 
0
 #define DEFINE_INST(type, name) rb_define_const(cLLVMInstruction, #name, INT2FIX(Instruction::name));
0
 #define DEFINE_BINARY_INST(name) DEFINE_INST(cLLVMBinaryOps, name)
...
17
18
19
 
20
21
22
...
69
70
71
 
 
 
 
 
72
73
74
...
133
134
135
 
136
137
138
...
191
192
193
 
 
 
 
 
194
195
196
...
17
18
19
20
21
22
23
...
70
71
72
73
74
75
76
77
78
79
80
...
139
140
141
142
143
144
145
...
198
199
200
201
202
203
204
205
206
207
208
0
@@ -17,6 +17,7 @@ VALUE cLLVMTerminatorInst = Qnil;
0
 VALUE cLLVMReturnInst = Qnil;
0
 VALUE cLLVMBranchInst = Qnil;
0
 VALUE cLLVMSwitchInst = Qnil;
0
+VALUE cLLVMAllocationInst = Qnil;
0
 VALUE cLLVMPhi = Qnil;
0
 VALUE cLLVMBinaryOps = Qnil;
0
 VALUE cLLVMPassManager = Qnil;
0
@@ -69,6 +70,11 @@ VALUE llvm_switch_inst_get_default_dest(VALUE);
0
 VALUE llvm_switch_inst_get_num_cases(VALUE);
0
 VALUE llvm_switch_inst_add_case(VALUE, VALUE, VALUE);
0
 
0
+VALUE llvm_allocation_inst_is_array_allocation(VALUE);
0
+VALUE llvm_allocation_inst_array_size(VALUE);
0
+VALUE llvm_allocation_inst_allocated_type(VALUE);
0
+VALUE llvm_allocation_inst_alignment(VALUE);
0
+
0
 VALUE llvm_builder_set_insert_point(VALUE, VALUE);
0
 VALUE llvm_builder_bin_op(VALUE, VALUE, VALUE, VALUE);
0
 VALUE llvm_builder_phi(VALUE, VALUE);
0
@@ -133,6 +139,7 @@ void Init_llvmruby() {
0
   cLLVMReturnInst = rb_define_class_under(cLLVMRuby, "ReturnInst", cLLVMTerminatorInst);
0
   cLLVMBranchInst = rb_define_class_under(cLLVMRuby, "BranchInst", cLLVMTerminatorInst);
0
   cLLVMSwitchInst = rb_define_class_under(cLLVMRuby, "SwitchInst", cLLVMTerminatorInst);
0
+  cLLVMAllocationInst = rb_define_class_under(cLLVMRuby, "AllocationInst", cLLVMInstruction);
0
   cLLVMBinaryOps = rb_define_class_under(cLLVMInstruction, "BinaryOps", rb_cObject);
0
   cLLVMPhi = rb_define_class_under(cLLVMRuby, "Phi", cLLVMValue);
0
 
0
@@ -191,6 +198,11 @@ void Init_llvmruby() {
0
   rb_define_method(cLLVMSwitchInst, "get_num_cases", llvm_switch_inst_get_num_cases, 0);
0
   rb_define_method(cLLVMSwitchInst, "add_case", llvm_switch_inst_add_case, 2);
0
 
0
+  rb_define_method(cLLVMAllocationInst, "array_allocation?", llvm_allocation_inst_is_array_allocation, 0);
0
+  rb_define_method(cLLVMAllocationInst, "array_size", llvm_allocation_inst_array_size, 0);
0
+  rb_define_method(cLLVMAllocationInst, "allocated_type", llvm_allocation_inst_allocated_type, 0);
0
+  rb_define_method(cLLVMAllocationInst, "alignment", llvm_allocation_inst_alignment, 0);
0
+
0
   rb_define_method(cLLVMBuilder, "set_insert_point", llvm_builder_set_insert_point, 1);
0
   rb_define_method(cLLVMBuilder, "bin_op", llvm_builder_bin_op, 3);
0
   rb_define_method(cLLVMBuilder, "phi", llvm_builder_phi, 1);
...
36
37
38
 
39
40
41
...
36
37
38
39
40
41
42
0
@@ -36,6 +36,7 @@ extern VALUE cLLVMTerminatorInst;
0
 extern VALUE cLLVMReturnInst;
0
 extern VALUE cLLVMBranchInst;
0
 extern VALUE cLLVMSwitchInst;
0
+extern VALUE cLLVMAllocationInst;
0
 extern VALUE cLLVMBinaryOps;
0
 extern VALUE cLLVMPhi;
0
 extern VALUE cLLVMPassManager;
...
272
273
274
 
 
 
 
 
 
275
276
277
...
272
273
274
275
276
277
278
279
280
281
282
283
0
@@ -272,6 +272,12 @@ class BasicTests < Test::Unit::TestCase
0
     function_tester(23) do |f|
0
       b = f.create_block.builder
0
       new_space = b.malloc(MACHINE_WORD, 1)
0
+      assert_kind_of(AllocationInst, new_space)
0
+      assert(!new_space.array_allocation?)
0
+      assert_kind_of(Value, new_space.array_size)
0
+      assert_kind_of(Type, new_space.allocated_type)
0
+      assert_equal(0, new_space.alignment)
0
+
0
       b.store(23.llvm(MACHINE_WORD), new_space)    
0
       v = b.load(new_space)
0
       b.free(new_space)

Comments