Thread overview
New expression in ToElemVisitor
Aug 20
kinke
Aug 20
kinke
Aug 20
kinke
August 20
I'm adding support for a new expression to `ToElemVisitor`. It seems like I need to create a `DValue`, which seems to require a `llvm::Global` and a D type. I have the `llvm::Global` but not the D type. The global is created by the compiler. Any ideas/hints?

--
/Jacob Carlborg
August 20
On Monday, 20 August 2018 at 07:52:31 UTC, Jacob Carlborg wrote:
> I'm adding support for a new expression to `ToElemVisitor`. It seems like I need to create a `DValue`, which seems to require a `llvm::Global` and a D type. I have the `llvm::Global` but not the D type. The global is created by the compiler. Any ideas/hints?

Yeah, results of expressions are DValues, an association of an arbitrary llvm::Value* (not just globals) with a D type. Not having a D type wasn't an issue until now, as all expressions have one (Expression::type); why is yours special? - As it's a global (presumably ObjC stuff), you could probably get away with a void ptr.
August 20
On Monday, 20 August 2018 at 09:35:04 UTC, kinke wrote:

> Yeah, results of expressions are DValues, an association of an arbitrary llvm::Value* (not just globals) with a D type. Not having a D type wasn't an issue until now, as all expressions have one (Expression::type); why is yours special? - As it's a global (presumably ObjC stuff)

Yes, it's for Objective-C, as we discussed earlier [1]. I've created the type for the Value like Clang does, using `StructType::create()`.

> global (presumably ObjC stuff), you could probably get away with a void ptr.

You mean an instance of `TypePointer`?

[1] https://forum.dlang.org/thread/slflfkzldrtzagqpihgb@forum.dlang.org

--
/Jacob Carlborg
August 20
On Monday, 20 August 2018 at 11:30:15 UTC, Jacob Carlborg wrote:
> You mean an instance of `TypePointer`?

Something like `DImValue(Type::tvoidptr, DtoBitCast(myLLGlobal, getVoidPtrType())` (a DLValue would be preferrable, but you'd probably need a proper D type then). But what's the type of your new Expression? Do you have some code to show?
August 20
On Monday, 20 August 2018 at 11:30:15 UTC, Jacob Carlborg wrote:
> Yes, it's for Objective-C, as we discussed earlier [1].

Glancing over the original thread again, you could probably tackle this differently. What about defining the `_class_t` struct and its helper structs in object.d and stashing away that type (just like `Type::dtypeinfo` etc.), so that you can use it later for defining the ObjC global (and presumably also for your <NewExpression>::type)?
August 22
On 2018-08-20 22:30, kinke wrote:

> Glancing over the original thread again, you could probably tackle this differently. What about defining the `_class_t` struct and its helper structs in object.d and stashing away that type (just like `Type::dtypeinfo` etc.), so that you can use it later for defining the ObjC global (and presumably also for your <NewExpression>::type)?

I guess I could. But DMD doesn't require these types, what it seems like.

-- 
/Jacob Carlborg
August 22
On 2018-08-20 14:03, kinke wrote:
> On Monday, 20 August 2018 at 11:30:15 UTC, Jacob Carlborg wrote:
>> You mean an instance of `TypePointer`?
> 
> Something like `DImValue(Type::tvoidptr, DtoBitCast(myLLGlobal, getVoidPtrType())` (a DLValue would be preferrable, but you'd probably need a proper D type then). But what's the type of your new Expression? Do you have some code to show?

Not in LDC, yet, but in DMD. The new expression is defined here [1], getRuntimeMetaclass here [2] and setMetaclass here [3]. This is the code returning the elem value of the expression [4]. getClassReference is defined here [5].

[1] https://github.com/dlang/dmd/blob/3d289d3ea100bda6a2b25c5e43779d7dd487281f/src/dmd/expression.d#L6500-L6515

[2] https://github.com/dlang/dmd/blob/3d289d3ea100bda6a2b25c5e43779d7dd487281f/src/dmd/objc.d#L427-L438

[3] https://github.com/dlang/dmd/blob/3d289d3ea100bda6a2b25c5e43779d7dd487281f/src/dmd/objc.d#L485-L528

[4] https://github.com/dlang/dmd/blob/3d289d3ea100bda6a2b25c5e43779d7dd487281f/src/dmd/objc_glue.d#L143-L146

[5] https://github.com/dlang/dmd/blob/3d289d3ea100bda6a2b25c5e43779d7dd487281f/src/dmd/objc_glue.d#L449-L479

-- 
/Jacob Carlborg