Пример #1
0
        protected override ExprAST VisitVariableExprAST(VariableExprAST node)
        {
            // Look this variable up in the function.
            if (this.namedValues.TryGetValue(node.Name, out var value))
            {
                this.valueStack.Push(value);
            }
            else
            {
                throw new Exception($"Unknown variable name {node.Name}");
            }

            return(node);
        }
Пример #2
0
        public ExprAST VariableExprVisit(VariableExprAST node)
        {
            LLVMValueRef initValue;

            this.Visit(node.Value);
            initValue = valueStack.Pop();
            LLVMValueRef alloca = default(LLVMValueRef);

            switch (LLVM.GetTypeKind(LLVM.TypeOf(initValue)))
            {
            case LLVMTypeKind.LLVMIntegerTypeKind:
                alloca = CreateEntryBlockAlloca(mainFunction, LLVMTypeRef.Int64Type(), node.Name);
                break;

            case LLVMTypeKind.LLVMDoubleTypeKind:
                alloca = CreateEntryBlockAlloca(mainFunction, LLVMTypeRef.DoubleType(), node.Name);
                break;
            }
            LLVM.BuildStore(builder, initValue, alloca);
            return(node);
        }
Пример #3
0
 protected internal virtual ExprAST VisitVariableExprAST(VariableExprAST node)
 {
     return node;
 }
Пример #4
0
 protected internal virtual ExprAST VisitVariableExprAST(VariableExprAST node)
 {
     return(node);
 }
Пример #5
0
 protected internal override void VisitAST(VariableExprAST node)
 {
     var (_, addr) = GetId(node.Name);
     GenCode.Add(Ins.Lod(node.RetType, 0, addr));
 }