当前位置: 首页>>代码示例>>C#>>正文


C# LLVMValueRef.TypeOf方法代码示例

本文整理汇总了C#中LLVMSharp.LLVMValueRef.TypeOf方法的典型用法代码示例。如果您正苦于以下问题:C# LLVMValueRef.TypeOf方法的具体用法?C# LLVMValueRef.TypeOf怎么用?C# LLVMValueRef.TypeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LLVMSharp.LLVMValueRef的用法示例。


在下文中一共展示了LLVMValueRef.TypeOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateFloatingPointMath

        private LLVMValueRef GenerateFloatingPointMath(string op, LLVMValueRef lhs, LLVMValueRef rhs,
            LLVMBuilderRef builder)
        {
            Debug.Assert(lhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind ||
                         lhs.TypeOf().TypeKind == LLVM.DoubleType().TypeKind);
            Debug.Assert(rhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind ||
                         rhs.TypeOf().TypeKind == LLVM.DoubleType().TypeKind);

            // Promotion for floats and ints to work together -- very fragile. Need to do better type checking.
            if (lhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind)
            {
                lhs = LLVM.BuildSIToFP(builder, lhs, LLVM.DoubleType(), "");
            }

            if (rhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind)
            {
                rhs = LLVM.BuildSIToFP(builder, rhs, LLVM.DoubleType(), "");
            }

            if (op == "+")
            {
                return LLVM.BuildFAdd(builder, lhs, rhs, "");
            }
            else if (op == "-")
            {
                return LLVM.BuildFSub(builder, lhs, rhs, "");
            }
            else if (op == "*")
            {
                return LLVM.BuildFMul(builder, lhs, rhs, "");
            }
            else if (op == "/")
            {
                return LLVM.BuildFDiv(builder, lhs, rhs, "");
            }
            else if (op == "%")
            {
                return LLVM.BuildFRem(builder, lhs, rhs, "");
            }
            else if (op == "<")
            {
                return LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealOLT, lhs, rhs, "");
            }
            else if (op == ">")

            {
                return LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealOGT, lhs, rhs, "");
            }
            else if (op == "==")
            {
                return LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealOEQ, lhs, rhs, "");
            }
            else if (op == ">=")
            {
                return LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealOGE, lhs, rhs, "");
            }
            else if (op == "<=")
            {
                return LLVM.BuildFCmp(builder, LLVMRealPredicate.LLVMRealOLE, lhs, rhs, "");
            }
            else
            {
                throw new Exception("unknown operator");
            }
        }
开发者ID:nerdcorerising,项目名称:Language-Managed,代码行数:65,代码来源:CodeGen.cs

示例2: GenerateIntegerMath

        private LLVMValueRef GenerateIntegerMath(string op, LLVMValueRef lhs, LLVMValueRef rhs, LLVMBuilderRef builder)
        {
            Debug.Assert(lhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind);
            Debug.Assert(rhs.TypeOf().TypeKind == LLVM.Int32Type().TypeKind);

            if (op == "+")
            {
                return LLVM.BuildAdd(builder, lhs, rhs, "");
            }
            else if (op == "-")
            {
                return LLVM.BuildSub(builder, lhs, rhs, "");
            }
            else if (op == "*")
            {
                return LLVM.BuildMul(builder, lhs, rhs, "");
            }
            else if (op == "/")
            {
                return LLVM.BuildSDiv(builder, lhs, rhs, "");
            }
            else if (op == "%")
            {
                return LLVM.BuildSRem(builder, lhs, rhs, "");
            }
            else if (op == "<")
            {
                return LLVM.BuildICmp(builder, LLVMIntPredicate.LLVMIntSLT, lhs, rhs, "");
            }
            else if (op == ">")
            {
                return LLVM.BuildICmp(builder, LLVMIntPredicate.LLVMIntSGT, lhs, rhs, "");
            }
            else if (op == "==")
            {
                return LLVM.BuildICmp(builder, LLVMIntPredicate.LLVMIntEQ, lhs, rhs, "");
            }
            else if (op == ">=")
            {
                return LLVM.BuildICmp(builder, LLVMIntPredicate.LLVMIntSGE, lhs, rhs, "");
            }
            else if (op == "<=")
            {
                return LLVM.BuildICmp(builder, LLVMIntPredicate.LLVMIntSLE, lhs, rhs, "");
            }
            else
            {
                throw new Exception("unknown operator");
            }
        }
开发者ID:nerdcorerising,项目名称:Language-Managed,代码行数:50,代码来源:CodeGen.cs


注:本文中的LLVMSharp.LLVMValueRef.TypeOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。