TYnptr in LLVM?
kinke
noone at nowhere.com
Mon Jul 16 18:37:38 UTC 2018
On Monday, 16 July 2018 at 13:40:35 UTC, Jacob Carlborg wrote:
> 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
Assuming you only need an opaque pointer to that symbol (and you
don't mix LDC/clang bitcode, e.g., via LTO), any type should do
(see clang's opaque `%struct._objc_cache` - I think you create an
opaque type as IR struct without elements via
`llvm::StructType::create(gIR->context(), "name")`).
Otherwise, you'll have to define these types like clang does
(using another `StructType::create()` overload, one taking the
array of element types). LDC's `getVoidPtrType()` helpers returns
the common `i8*` IR type, `llvm::IntegerType::get(gIR->context(),
32)` returns `i32` etc.
More information about the digitalmars-d-ldc
mailing list