コード例 #1
0
        public override BasicBlock code()
        {
            block = bb();
            IRBuilder builder = new IRBuilder(block);
            Value     alloc;

            if (var is SimpleNumericVariable)
            {
                SimpleNumericVariable simpleVar = (SimpleNumericVariable)var;
                if (Parser.variables.numbers.ContainsKey(simpleVar.name))
                {
                    alloc = Parser.variables.numbers[simpleVar.name];
                }
                else
                {
                    Parser.variables.numbers[simpleVar.name] = builder.CreateAlloca(Parser.dbl, simpleVar.name);
                    alloc = Parser.variables.numbers[simpleVar.name];
                }
            }
            else
            {
                NumericArrayElement arrayElement = (NumericArrayElement)var;
                alloc = Parser.variables.arrayItem(builder, arrayElement.numericarrayname, arrayElement.index.code(builder));
            }

            Value exprVal = value.code(builder);

            builder.CreateStore(exprVal, alloc);

            return(block);
        }
コード例 #2
0
        public void printNumericExpression(NumericExpression expr)
        {
            Value    expressionValue = expr.code(builder);
            Constant stringFormat    = new Constant(Parser.context, "%g");

            GlobalVariable global = new GlobalVariable(
                Parser.module,
                stringFormat.GetType(),
                true,                       // constant
                LinkageType.PrivateLinkage, // only visible in this module
                stringFormat,
                ".str");                    // the name of the global constant

            Value[] args = new Value[] {
                ConstantExpr.GEP(global, Parser.zero, Parser.zero),
                expressionValue
            };
            // Call printf
            builder.CreateCall(doubleprintf, args);
        }