示例#1
0
        public override void Visit(FunctionCallAST functionCall)
        {
            var functionIdent = _symTableManager.LookupFunctionInfo(_currentFileName, (functionCall.Name as VariableNameAST).Name, _currentScopeId, functionCall.argTypes);

            if (functionIdent.valueRef.Pointer == IntPtr.Zero)
            {
                var fnType = IRTypesConverter.GetFunctionType(functionIdent.typeAST as FunctionTypeAST);

                functionIdent.valueRef = LLVM.AddFunction(_module, functionIdent.name, fnType);
            }

            var expressions = new LLVMValueRef[Math.Max(functionCall.ExpressionList.Count, 1)];

            for (var i = 0; i < functionCall.ExpressionList.Count; i++)
            {
                functionCall.ExpressionList[i].Accept(this);

                expressions[i] = _currentValue;

                if (LLVM.IsConstant(_currentValue))
                {
                    expressions[i] = LLVM.BuildAlloca(_builder, _currentValue.TypeOf(), "val");
                    LLVM.BuildStore(_builder, _currentValue, expressions[i]);
                    expressions[i].Dump();
                }
            }
            LLVM.BuildCall(_builder, functionIdent.valueRef, out expressions[0], (uint)functionCall.ExpressionList.Count, (functionIdent.typeAST as FunctionTypeAST).ReturnType.ToString() == "void" ? "" : functionIdent.name);
        }
示例#2
0
        public override void Visit(FunctionProtoAST functionProto)
        {
            var functionIden = _symTableManager.LookupFunctionInfo(_currentFileName, functionProto.Name, _currentScopeId, functionProto.GetFunctionType().ArgumentTypes);

            if (functionIden.valueRef.Pointer == IntPtr.Zero)
            {
                var fnType = IRTypesConverter.GetFunctionType(functionProto.GetFunctionType());

                functionIden.valueRef = LLVM.AddFunction(_module, functionProto.Name, fnType);
            }

            _currentFunction = functionIden.valueRef;
        }
示例#3
0
        public override void Visit(DeclareAST declareAST)
        {
            var identifier = _symTableManager.LookupIdentifierInfo(_currentFileName, declareAST.VariableDec.Name, _currentScopeId, _currentNodePosition);

            if (identifier.valueRef.Pointer != IntPtr.Zero)
            {
                return;
            }

            var fnType = IRTypesConverter.GetFunctionType(declareAST.VariableDec.Type as FunctionTypeAST);

            identifier.valueRef = LLVM.AddFunction(_module, identifier.name, fnType);
            LLVM.SetFunctionCallConv(identifier.valueRef, 0);
            LLVM.SetLinkage(identifier.valueRef, LLVMLinkage.LLVMExternalLinkage);
        }
示例#4
0
        public override void Visit(VariableDecAST variableDec)
        {
            var variableDecIdentifier = _symTableManager.LookupIdentifierInfo(_currentFileName, variableDec.Name,
                                                                              _currentScopeId, _currentNodePosition);

            if (variableDecIdentifier.valueRef.Pointer != IntPtr.Zero)
            {
                return;
            }

            LLVMTypeRef type;

            if (variableDecIdentifier.isFunctionType)
            {
                type = LLVM.PointerType(IRTypesConverter.GetFunctionType(variableDecIdentifier.typeAST as FunctionTypeAST), 0);
            }
            else
            {
                type = IRTypesConverter.PrimitivesTypesDic[variableDecIdentifier.typeAST.ToString()];
            }

            variableDecIdentifier.valueRef = LLVM.BuildAlloca(_builder, type, variableDec.Name);
        }