Examples of MachineFunction


Examples of org.openquark.cal.machine.MachineFunction

                        parameterStrictness,
                        parameterTypes,
                        new TypeVar(),
                        1123191938810L
                );
                MachineFunction mf = new LECCMachineFunction(cf);
                ExpressionAnalyzer analyzer = new ExpressionAnalyzer(currentModuleTypeInfo, mf);
               
                Expression exprOptimized = analyzer.transformExpression(exprs[i]);
                switch(i){
                case 0:
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

    /** {@inheritDoc} */
    @Override
    public String[][] getArgNamesAndTypes(String qualifiedFunctionName) {
        try {          
            MachineFunction mf = program.getCodeLabel(QualifiedName.makeFromCompoundName(qualifiedFunctionName));
            if (mf != null && mf.getArity() > 0) {
                String argNames[] = mf.getParameterNames();
                TypeExpr argTypes[] = mf.getParameterTypes();
                String argTypeStrings[] = new String[argTypes.length];
                for (int i = 0; i < argTypeStrings.length; ++i) {
                    if (argTypes[i] == null) {
                        argTypeStrings[i] = "internal type";
                    } else {
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

     */
    Code setupStartPoint2 (QualifiedName entryPointSCName) throws CALExecutorException {
       
        try {
              GProgram.GModule startModule = (GProgram.GModule)program.getModule(entryPointSCName.getModuleName());
               MachineFunction mf = startModule.getFunction(entryPointSCName);
               // The specified target may be an alias of another function, or it may be defined as a literal value
               // (either directly or from following an alias chain).  In either case there is no source/class
               // generated.  So we need to either return the literal value or follow the alias to a
               // function for which there is a generated source/class file.
               if (mf.getLiteralValue() != null) {
                   Instruction[] enterInst = new Instruction [4];
                   enterInst [0] = new Instruction.I_Instrument (new ExecTimeInfo(true, getInstructionCount()));
                   enterInst [1] = Instruction.I_PushVVal.makePushVVal(mf.getLiteralValue());
                   enterInst [2] = Instruction.I_Eval;
                   enterInst [3] = new Instruction.I_Instrument (new ExecTimeInfo(false, getInstructionCount()));
                  
                   Code enterCode = new Code (enterInst);
                  
                   return (enterCode);
               }
              
               if (mf.getAliasOf() != null) {
                   entryPointSCName = mf.getAliasOf();
               }
           
            if (nPushedArguments != 0) {
                Instruction[] enterInst = new Instruction [nPushedArguments + 3];
                enterInst [0] = new Instruction.I_PushGlobal (entryPointSCName);
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                // No argument, ENTER LABEL instead - this has to be resolved at runtime
                gp.code(new Instruction.I_PushGlobal(var.getName()));

                // If the global is a non-zero arity SC we can skip the I_Eval instruction
                // since it won't do anything.
                MachineFunction mf = currentModule.getFunction(var.getName());
                if (mf == null || mf.getArity() == 0) {
                    gp.code (Instruction.I_Eval);
                }

                if (CODEGEN_DIAG) {
                    MACHINE_LOGGER.log(Level.FINE, "        Global:");
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                    } else {
                        // We can do a fixup of the instruction if the function being pushed is not a CAF.
                        // Non-CAF functions have a single instance of NGlobal associated with them.
                        // CAF functions have multiple instances of NGlobal associated with them, keyed by
                        // the execution context.
                        MachineFunction calledFunction = module.getFunction(globalName);
                        if (calledFunction != null) {
                            if (calledFunction.isForeignFunction() || calledFunction.getArity() > 0) {                   
                                NGlobal node = ((GMachineFunction)calledFunction).makeNGlobal(null);
                                instructions [i] = new Instruction.I_PushGlobalN (node, !calledFunction.isForeignFunction());
                            }
                        } else {
                            throw new CodeGenerationException ("Unable to find code label for " + globalName + " when fixing up I_PushGlobal instructions.");
                        }
                    }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

            if (ei != null) {
                // This is a function argument check if it is strict.

            } else {
                // This is an SC
                MachineFunction mf = currentModule.getFunction(var.getName());
                if (mf != null && mf.getArity() > 0) {
                    return true;
                }

            }
        }

        // Is e an application of a saturated constructor?
        ConstructorOpTuple constructorOpTuple = ConstructorOpTuple.isConstructorOp(e, false);
        if (constructorOpTuple != null) {
            DataConstructor dc = constructorOpTuple.getDataConstructor ();

            boolean[] fieldStrictness = new boolean [dc.getArity()];
            boolean dcHasStrictFields = false;
            for (int i = 0; i < dc.getArity(); ++i) {
                fieldStrictness[i] = dc.isArgStrict(i);
                if (fieldStrictness[i]) {
                    dcHasStrictFields = true;
                }
            }

            // If there are no strict arguments we can simply create an instance of the DC class.
            // The simplest way to do this is to treat this DC application as if it were in a strict context.
            if (!dcHasStrictFields) {
                return true;
            } else {
                // If all strict arguments are already evaluated, or we consider them safe to evaluate (i.e. cheap and
                // with no side effects) we can treat this as strict.
                boolean allOK = true;
                for (int i = 0; i < dc.getArity(); ++i) {
                    if (dc.getArgStrictness()[i] && !canIgnoreLaziness(constructorOpTuple.getArgument(i), env)) {
                        allOK = false;
                        break;
                    }
                }

                if (allOK) {
                    return true;
                }
            }       
        }

        // We can shortcut a basic op if it is marked as allowed to
        // be eagerly evaluated and all arguments can all be shortcut.
        // Also if the op is Prelude.eager we can shortcut.
        BasicOpTuple basicOpExpressions = BasicOpTuple.isBasicOp(e);
        if (basicOpExpressions != null) {
            if (basicOpExpressions.getPrimitiveOp() == PrimOps.PRIMOP_EAGER) {
                return true;
            }

            QualifiedName opName = basicOpExpressions.getName();
            MachineFunction mf = currentModule.getFunction(opName);
            if (mf == null) {
                return false;
            }

            if (mf.canFunctionBeEagerlyEvaluated()) {
                int nArgs = basicOpExpressions.getNArguments();
                int nWHNFArgs = 0;
                for (int i = 0; i < nArgs; ++i) {
                    Expression eArg = basicOpExpressions.getArgument(i);
                    if (canIgnoreLaziness(eArg, env)) {
                        nWHNFArgs++;
                    }
                }
                if (nArgs == nWHNFArgs) {
                    // All the args are in WHNF so ideally we can ignore laziness for
                    // this primitive operation.  However, there are some primitive
                    // ops where an additional condition, that the second argument is
                    // known to not be zero, is required.
                    String unqualifiedOpName = opName.getUnqualifiedName();
                    if (opName.getModuleName().equals(CAL_Prelude.MODULE_NAME) &&
                            (unqualifiedOpName.equals("divideLong") ||
                                    unqualifiedOpName.equals("remainderLong") ||
                                    unqualifiedOpName.equals("divideInt") ||
                                    unqualifiedOpName.equals("remainderInt") ||
                                    unqualifiedOpName.equals("divideShort") ||
                                    unqualifiedOpName.equals("remainderShort") ||
                                    unqualifiedOpName.equals("divideByte") ||
                                    unqualifiedOpName.equals("remainderByte"))) {

                        // Check that the second argument is a non zero literal.

                        Expression arg = basicOpExpressions.getArgument(1);
                        if (arg.asLiteral() != null) {

                            if (unqualifiedOpName.equals("divideLong") || unqualifiedOpName.equals("remainderLong")) {

                                Long l = (Long)arg.asLiteral().getLiteral();
                                return l.longValue() != 0;

                            } else if (unqualifiedOpName.equals("divideInt") || unqualifiedOpName.equals("remainderInt")) {

                                Integer i = (Integer)arg.asLiteral().getLiteral();
                                return i.intValue() != 0;

                            } else if (unqualifiedOpName.equals("divideShort") || unqualifiedOpName.equals("remainderShort")) {

                                Short shortValue = (Short)arg.asLiteral().getLiteral();
                                return shortValue.shortValue() != 0;

                            } else if (unqualifiedOpName.equals("divideByte") || unqualifiedOpName.equals("remainderByte")) {

                                Byte byteValue = (Byte)arg.asLiteral().getLiteral();
                                return byteValue.byteValue() != 0;

                            } else {
                                throw new IllegalStateException();
                            }
                        } else {
                            return false;
                        }
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            }
        }

        basicOpExpressions = BasicOpTuple.isAndOr (e);
        if (basicOpExpressions != null) {

            // Code a basic operation
            int nArgs = basicOpExpressions.getNArguments ();
            int nWHNFArgs = 0;
            for (int i = 0; i < nArgs; ++i) {
                Expression eArg = basicOpExpressions.getArgument(i);
                if (canIgnoreLaziness(eArg, env)) {
                    nWHNFArgs++;
                }
            }
            if (nArgs == nWHNFArgs) {
                return true;
            }
        }

        // If e is a fully saturated application of a function tagged for optimization and
        // all the arguments are in WHNF or can have laziness ignored we can
        // ignore laziness for the application.
        if (e.asAppl() != null) {
            Expression[] chain = appChain(e.asAppl());
            if (chain[0].asVar() != null) {
                // Get the supercombinator on the left end of the chain.
                Expression.Var scVar = chain[0].asVar();
                if (scVar != null) {
                    // Check if this supercombinator is one we should try to optimize.
                    MachineFunction mf = currentModule.getFunction(scVar.getName());
                    if (mf != null && mf.canFunctionBeEagerlyEvaluated()) {

                        // Now determine the arity of the SC.
                        int calledArity = mf.getArity();

                        // Check to see if we can ignore laziness for all the arguments.
                        if (chain.length - 1 == calledArity) {
                            int nWHNFArgs = 0;
                            for (int i = 0; i < calledArity; ++i) {
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

            TypeConstructor typeConstructor = module.getModuleTypeInfo().getTypeConstructor(typeName);
            return DataTypeDefinitionBuilder.getClassRep(typeConstructor, unqualifiedClassName, module, null);
        } else {
            // Get the class from the function definition builder.
            String functionName = CALToJavaNames.getUnqualifiedFunctionNameFromClassName(moduleName, outerClassName, module);
            MachineFunction mf = module.getFunction(functionName);
            LECCModule.FunctionGroupInfo mfs = module.getFunctionGroupInfo(mf);
            return SCDefinitionBuilder.getClassRep(mfs, module, unqualifiedClassName, null);
        }
    }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

            TypeConstructor typeConstructor = module.getModuleTypeInfo().getTypeConstructor(typeName);
            return DataTypeDefinitionBuilder.getDataTypeDefinition(typeConstructor, module, null);
        } else {
            // Get the class from the function definition builder.
            String functionName = CALToJavaNames.getUnqualifiedFunctionNameFromClassName(moduleName, outerClassName, module);
            MachineFunction mf = module.getFunction(functionName);
            LECCModule.FunctionGroupInfo mfs = module.getFunctionGroupInfo(mf);
            return SCDefinitionBuilder.getSCDefinition(mfs, module, null);
        }
    }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

    static GeneratedCodeInfo getNewCodeInfo (Module module) {
        long timeStamp = -1;
        if (module != null) {
            Iterator<MachineFunction> functions = module.getFunctions().iterator();
            if (functions.hasNext()) {
                MachineFunction machineFunction = functions.next();
                timeStamp = machineFunction.getTimeStamp();
            } else {
                // Empty module.  Fall through.
            }
        }
View Full Code Here

Examples of org.openquark.cal.machine.MachineFunction

                                         executionContext.getNDataTypeInstances()));

            try {
                LECCModule startModule =
                    (LECCModule) program.getModule(entryPointSCName.getModuleName());
                MachineFunction mf = startModule.getFunction(entryPointSCName);

                startPoint = makeStartPointInstance(mf);
            } catch (Exception e) {
                throw new CALExecutorException.InternalException ("Unable to create instance of " + entryPointSCName, e);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.