Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
The wonders of a fresh perspective
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarWitch7 committed Mar 3, 2024
1 parent 55bf2b6 commit b9e8b14
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Moth/LLVM/Data/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ public Array(LLVMCompiler compiler, Type elementType, Value[] elements)
_compiler = compiler;
Type = new ArrType(compiler, elementType); //TODO: replace with lazy type creation?
LLVMValue = compiler.Builder.BuildAlloca(Type.LLVMType);


var arrLLVMType = LLVMTypeRef.CreateArray(elementType.LLVMType,
(uint)elements.Length);
var arr = compiler.Builder.BuildStructGEP2(Type.LLVMType, LLVMValue, 0);
var length = compiler.Builder.BuildStructGEP2(Type.LLVMType, LLVMValue, 1);
LLVMValueRef values = compiler.Builder.BuildAlloca(LLVMTypeRef.CreateArray(elementType.LLVMType,
(uint)elements.Length));
LLVMValueRef values = compiler.Builder.BuildAlloca(arrLLVMType);
compiler.Builder.BuildStore(LLVMValueRef.CreateConstArray(elementType.LLVMType,
elements.SafeLoadAll(compiler)
.AsLLVMValues()),
values);
compiler.Builder.BuildStore(values,
compiler.Builder.BuildStore(compiler.Builder.BuildLoad2(arrLLVMType, values),
arr);
compiler.Builder.BuildStore(LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32,
(ulong)elements.Length),
Expand Down

0 comments on commit b9e8b14

Please sign in to comment.