public static LLVMValueRef BuildGetElementPtr(EmittingContext pContext, LLVMValueRef?pValue) { List <LLVMValueRef> indexes = new List <LLVMValueRef>(pContext.AccessStack.Count) { pContext.GetInt(0) }; for (int j = pContext.AccessStack.Count - 1; j > 0; j--) { indexes.Add(pContext.AccessStack.PeekAt(j).Value); } if (pValue.HasValue) { indexes.Add(pValue.Value); } var i = pContext.AccessStack.PeekAt(0).Value; return(LLVM.BuildInBoundsGEP(pContext.Builder, i, indexes.ToArray(), "memberaccess")); }
public static void StringFromChars(LLVMValueRef pVariable, SyntaxNode pChars, EmittingContext pContext) { var data = pChars.Emit(pContext); //Save length var arrayLength = pContext.GetArrayLength(data); var stringLength = pContext.GetArrayLength(pVariable); LLVM.BuildStore(pContext.Builder, LLVM.BuildLoad(pContext.Builder, arrayLength, ""), stringLength); var arrayData = LLVM.BuildInBoundsGEP(pContext.Builder, data, new LLVMValueRef[] { pContext.GetInt(0), pContext.GetInt(1) }, ""); arrayData = LLVM.BuildLoad(pContext.Builder, arrayData, ""); //Load the data var variableData = LLVM.BuildInBoundsGEP(pContext.Builder, pVariable, new LLVMValueRef[] { pContext.GetInt(0), pContext.GetInt(1) }, ""); LLVM.BuildStore(pContext.Builder, arrayData, variableData); }