Пример #1
0
 def attribute_lookup(self, struct, name, builder):
     """
 Helper for getting the address of an attribute lookup, used both when
 setting and getting attributes
 """
     llvm_struct = self.compile_expr(struct, builder)
     struct_t = struct.type
     field_pos = struct_t.field_pos(name)
     field_type = struct_t.field_type(name)
     indices = [int32(0), int32(field_pos)]
     ptr_name = "%s_ptr" % name
     ptr = builder.gep(llvm_struct, indices, ptr_name)
     return ptr, field_type
Пример #2
0
 def attribute_lookup(self, struct, name, builder):
   """
   Helper for getting the address of an attribute lookup, used both when
   setting and getting attributes
   """
   llvm_struct = self.compile_expr(struct, builder)
   struct_t = struct.type
   field_pos = struct_t.field_pos(name)
   field_type = struct_t.field_type(name)
   indices = [int32(0), int32(field_pos)]
   ptr_name = "%s_ptr" % name
   ptr = builder.gep(llvm_struct, indices, ptr_name)
   return ptr, field_type
Пример #3
0
  def compile_Struct(self, expr, builder, local = False):
    struct_t = expr.type
    llvm_struct_t = llvm_value_type(struct_t)
    name = expr.type.node_type()
    if local:
      struct_ptr = builder.alloca(llvm_struct_t, name + "_local_ptr")
    else:
      struct_ptr = builder.malloc(llvm_struct_t, name + "_ptr")

    for (i, elt) in enumerate(expr.args):
      field_name, field_type = struct_t._fields_[i]
      assert elt.type == field_type, \
          "Mismatch between expected type %s and given %s for field '%s' " % \
          (field_type, elt.type, field_name)
      elt_ptr = builder.gep(struct_ptr, [int32(0), int32(i)], "field%d_ptr" % i)
      llvm_elt = self.compile_expr(elt, builder)
      builder.store(llvm_elt, elt_ptr)

    return struct_ptr
Пример #4
0
    def compile_Struct(self, expr, builder, local=False):
        struct_t = expr.type
        llvm_struct_t = llvm_value_type(struct_t)
        name = expr.type.node_type()
        if local:
            struct_ptr = builder.alloca(llvm_struct_t, name + "_local_ptr")
        else:
            struct_ptr = builder.malloc(llvm_struct_t, name + "_ptr")

        for (i, elt) in enumerate(expr.args):
            field_name, field_type = struct_t._fields_[i]
            assert elt.type == field_type, \
                "Mismatch between expected type %s and given %s for field '%s' " % \
                (field_type, elt.type, field_name)
            elt_ptr = builder.gep(struct_ptr, [int32(0), int32(i)],
                                  "field%d_ptr" % i)
            llvm_elt = self.compile_expr(elt, builder)
            builder.store(llvm_elt, elt_ptr)

        return struct_ptr