TYnptr in LLVM?

Jacob Carlborg doob at me.com
Mon Jul 16 13:40:35 UTC 2018


On Monday, 16 July 2018 at 09:29:59 UTC, kinke wrote:

> No idea about the DMD backend, but in LLVM you generally just 
> declare a global of some arbitrary IR type (e.g., from a D 
> type: `DtoType(dtype)`), and the resulting GlobalVariable will 
> always be a pointer to that type. You define the global by 
> setting an initializer. See the pretty new 
> `{declare,define}Global()` helpers.

Hmm. I don't have a D type. This is for when referencing an 
Objective-C class defined externally. The compiler generates a 
symbol like _OBJC_CLASS_$_<name>. I need a type for that symbol. 
The IR code generated by Clang looks like this

%struct._class_t = type { %struct._class_t*, %struct._class_t*, 
%struct._objc_cache*, i8* (i8*, i8*)**, %struct._class_ro_t* }
%struct._objc_cache = type opaque
%struct._class_ro_t = type { i32, i32, i32, i8*, i8*, 
%struct.__method_list_t*, %struct._objc_protocol_list*, 
%struct._ivar_list_t*, i8*, %struct._prop_list_t* }
%struct.__method_list_t = type { i32, i32, [0 x 
%struct._objc_method] }
%struct._objc_method = type { i8*, i8*, i8* }
%struct._objc_protocol_list = type { i64, [0 x 
%struct._protocol_t*] }
%struct._protocol_t = type { i8*, i8*, 
%struct._objc_protocol_list*, %struct.__method_list_t*, 
%struct.__method_list_t*, %struct.__method_list_t*, 
%struct.__method_list_t*, %struct._prop_list_t*, i32, i32, i8**, 
i8*, %struct._prop_list_t* }
%struct._ivar_list_t = type { i32, i32, [0 x %struct._ivar_t] }
%struct._ivar_t = type { i64*, i8*, i8*, i32, i32 }
%struct._prop_list_t = type { i32, i32, [0 x %struct._prop_t] }
%struct._prop_t = type { i8*, i8* }

@"OBJC_CLASS_$_NSObject" = external global %struct._class_t
@"OBJC_CLASSLIST_REFERENCES_$_" = private global 
%struct._class_t* @"OBJC_CLASS_$_NSObject", section 
"__DATA,__objc_classrefs,regular,no_dead_strip", align 8

--
/Jacob Carlborg


More information about the digitalmars-d-ldc mailing list