Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public override Value code(IRBuilder builder)
        {
            if (Parser.variables.stringLiterals.ContainsKey(value))
            {
                return(Parser.variables.stringLiterals[value]);
            }

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

            Value output = ConstantExpr.GEP(global, Parser.zero, Parser.zero);

            Parser.variables.stringLiterals[value] = output;
            return(output);
        }