Пример #1
0
        public TypeSpecifier VisitIndexAccessExpression(Expr.IndexAccess exp)
        {
            var name     = exp.Identifier.Source;
            var variable = _namedValues[name];
            var vartype  = new TypeSpecifier {
                Dimensions = 0, Type = variable.KtsType.Type
            };

            if (variable.IsDecayed)
            {
                LLVMValueRef[] indices = new LLVMValueRef[exp.Expressions.Count];

                for (int i = 0; i < indices.Length; i++)
                {
                    var exprType = Visit(exp.Expressions[i]);
                    var exprVal  = _valueStack.Pop();

                    var casted = CheckedCast(exprVal, exprType, new TypeSpecifier {
                        Dimensions = 0, Type = TypeEnum.I64
                    });
                    indices[i] = casted;
                }

                var load    = LLVM.BuildLoad(_builder, variable.Value, "");
                var address = LLVM.BuildInBoundsGEP(_builder, load, indices, "");
                var loadsec = LLVM.BuildLoad(_builder, address, "");
                _valueStack.Push(loadsec);

                return(vartype);
            }
            else
            {
                LLVMValueRef[] indices = new LLVMValueRef[exp.Expressions.Count + 1];

                indices[0] = LLVM.ConstInt(LLVM.Int64Type(), 0, _lFalse);

                for (int i = 1; i < indices.Length; i++)
                {
                    var exprType = Visit(exp.Expressions[i - 1]);
                    var exprVal  = _valueStack.Pop();

                    var casted = CheckedCast(exprVal, exprType, new TypeSpecifier {
                        Dimensions = 0, Type = TypeEnum.I64
                    });
                    indices[i] = casted;
                }

                var address = LLVM.BuildInBoundsGEP(_builder, variable.Value, indices, "");
                var load    = LLVM.BuildLoad(_builder, address, "");
                _valueStack.Push(load);

                if (variable.Binding != null)
                {
                    HandleBinding(variable, true);
                }

                return(vartype);
            }

            /*LLVMValueRef[] indices = new LLVMValueRef[exp.Expressions.Count + 1];
             *
             * indices[0] = LLVM.ConstInt(LLVM.Int64Type(), 0, _lFalse);
             *
             * for (int i = 1; i < indices.Length; i++)
             * {
             *  var exprType = Visit(exp.Expressions[i - 1]);
             *  var exprVal = _valueStack.Pop();
             *
             *  var casted = CheckedCast(exprVal, exprType, new TypeSpecifier { Dimensions = 0, Type = TypeEnum.I64 });
             *  indices[i] = casted;
             * }
             *
             * var address = LLVM.BuildInBoundsGEP(_builder, variable.Value, indices, "");
             * var load = LLVM.BuildLoad(_builder, address, "");
             * _valueStack.Push(load);
             *
             * return vartype;*/
        }
Пример #2
0
 public T VisitIndexAccessExpression(Expr.IndexAccess exp);