Ejemplo n.º 1
0
        public Stmt VisitDeclarationStatement(Stmt.VariableDeclaration statement)
        {
            var function = LLVM.GetBasicBlockParent(LLVM.GetInsertBlock(_builder));
            var type     = statement.TypeSpecifier;
            var name     = statement.Identifier.Source;

            if (_namedValues.ContainsKey(name))
            {
                throw new Exception("Variable name already declared");
            }

            LLVMValueRef alloca;

            if (type.Dimensions == 0)
            {
                alloca = EntryAllocation(function, type, name);
            }
            else
            {
                Expr.ArrayInitializer init = (Expr.ArrayInitializer)statement.Initializer;

                alloca = AllocateArray(function, type, name, init.DimensionSizes);
            }

            _namedValues.Add(name, new LLVMSymbol {
                Binding = statement.Binding, IsDecayed = false, KtsType = type, Value = alloca
            });

            if (statement.Initializer == null)
            {
                if (type.Dimensions == 0)
                {
                    if (type.IsFloat())
                    {
                        LLVM.BuildStore(_builder, LLVM.ConstReal(LLVMPrimitiveType(type.Type), 0), alloca);
                    }
                    else
                    {
                        LLVM.BuildStore(_builder, LLVM.ConstInt(LLVMPrimitiveType(type.Type), 0, _lFalse), alloca);
                    }
                }
                else
                {
                    throw new Exception("Uninitialized array");
                }
            }
            else
            {
                if (type.Dimensions == 0)
                {
                    var initType  = Visit(statement.Initializer);
                    var initValue = _valueStack.Pop();

                    var casted = CheckedCast(initValue, initType, type);
                    LLVM.BuildStore(_builder, casted, alloca);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
 public TypeSpecifier VisitArrayInitializer(Expr.ArrayInitializer exp)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
 public T VisitArrayInitializer(Expr.ArrayInitializer exp);