Problem with LLVM-C bindings

Daniel dtoffe at gmail.com
Thu Oct 26 20:01:56 UTC 2023


On Thursday, 26 October 2023 at 01:28:42 UTC, Daniel wrote:
> Hi all, I'm having a problem with llvm-c bindings, it is likely 
> a trivial thing, but this is my first D project, and I'm not an 
> expert in C either.
> 
> ---snipped
> 
> Any hint about what to try will be greatly appreciated.
>
> Daniel

EDIT: My bad, that is what happens when you do things in a hurry, 
sorry...

Hi all, I'm having a problem with llvm-c bindings, it is likely a 
trivial thing, but this is my first D project, and I'm not an 
expert in C either.

- symtable.d
```d
     struct Symbol {
         string name;
         SymbolKind kind;
         SymbolType type;
         LLVMValueRef valueRef;

         public LLVMValueRef getValueRef() {
             return valueRef;
         }

         public void setValueRef(LLVMValueRef valueRef) {
             this.valueRef = valueRef;
         }
     }
```

- ast.d
```d
     class ConstDeclNode : AstNode {
         string constName;
         int constValue;
         Symbol constSymbol;

         Symbol getConstSymbol() {
             return constSymbol;
         }

         void setConstSymbol(Symbol constSymbol) {
             this.constSymbol = constSymbol;
         }
     }
```
- codegen.d
```d
     valRef = LLVMBuildAlloca(llvmBuilder, int32Type, 
symbolName.toStringz());
     vars[symbolName] = valRef;                  // A
     node.getVarSymbol().setValueRef(valRef);    // B
     ---snip---
     variableRef = vars[symbolName];                   // A  => 
THIS WORKS
     variableRef = node.getVarSymbol().getValueRef();  // B => 
THIS DOES NOT WORK
```

Here, vars[] is declared in codegen.d, I set and get 
LLVMValueRefs using the lines commented with "A" and everything 
goes well, but I tried to store the LLVMValueRefs in the Symbol 
structure which is in another D module, in the lines commented 
with "B", and cannot get it to work, the program stops there when 
trying to access those values.

Any hint about what to try will be greatly appreciated.

Daniel


More information about the Digitalmars-d mailing list