Package org.openquark.cal.machine

Examples of org.openquark.cal.machine.Module


                    } else {
                        // Get a record import stream.
                        RecordInputStream rs = new RecordInputStream(fis);

                        try {
                            Module m = Module.load(rs, allExistingModules, foreignClassLoader, compiledDefinitionInfo.getCodeInfo(), msgLogger);

                            if (m != null) {
                                // Succeeded in loading the module.
                                allExistingModules.put (m.getName(), m);
                                packager.addModule(m);
                            }

                            // Attempted load, continue with next module
                            return new CompiledModuleLoadStatus.LoadAttempted();
View Full Code Here


                        addDependentModulesToSet(moduleDependencyGraph, moduleName, dependentBrokenModulesSet);
                        continue;
                    }

                    // Add the module to the set of existing modules.
                    Module currentModule = packager.getCurrentModule();
                    allExistingModules.put (currentModule.getName(), currentModule);

                    // If we're here, the module shouldn't be loaded, which means that any previous CompiledDefinitionInfo for it will be out of date
                    // Note that because we compile modules in dependency order, modules which depend on this one will also be found to need regeneration.
                    validCompiledDefinitionInfoMap.remove(moduleName);
                   
View Full Code Here

     * @return ModuleTypeInfo
     * @param moduleName
     */
    public ModuleTypeInfo getModuleTypeInfo(ModuleName moduleName) {

        Module requestedModule = program.getModule(moduleName);
        if (requestedModule == null) {
            return null;
        }

        return requestedModule.getModuleTypeInfo();
    }
View Full Code Here

    private void doTransformOptimizations(CompilerMessageLogger logger) throws Packager.PackagerException, UnableToResolveForeignEntityException {
       
        // First build up a list of functions that haven't already been optimized.
        List<MachineFunction> functionsList = new ArrayList<MachineFunction>();
        Module m = getCurrentModule();
       
        for (final MachineFunction mf : m.getFunctions()) {
            if (!mf.isOptimized()) {
                functionsList.add (mf);
            }
        }

        // Run the CAL optimizer on the functions before other optimization are
        // performed.
        if (optimizer_executor != null) {           
            Iterator<MachineFunction> functions = functionsList.iterator();
            List<MachineFunction> moreFunctions = new LinkedList<MachineFunction>();
            // List of modules used by the module. Inlining expression can cause name from
            // non-imported module to be used. The type info has to be updated with these new
            // modules.
            Set<ModuleName> moreModules = new HashSet<ModuleName>();
            int skipped_otherCounter = 0;
            int skipped_tooManyHelperFunctionsCounter = 0;
            int skipped_unsupportedExpressionType = 0;
            int skipped_hasBadStructure = 0;
            int skipped_tooDeep = 0;
            int skipped_tooMuchTime = 0;
            int changedCounter = 0;
            while (functions.hasNext()) {
                MachineFunctionImpl cl = (MachineFunctionImpl) functions.next();
                CoreFunction coreFunction = cl.getCoreFunction();
               
                if (cl.getExpressionForm() instanceof Expression.PackCons) {
                    continue; // can't be optimized so skip these
                }
                if (cl.getName().startsWith("$")) {
                    continue; // skip compiler generated helper functions
                }

                try {
                    Expression newBody = applyCALOptimizer(cl.getTimeStamp(), coreFunction, moreFunctions);
                    if (!newBody.toString().equals(cl.getExpressionForm().toString())) {
                        ++changedCounter;
                    }
                    modules(newBody, moreModules);
                    cl.setExpression(newBody);
                } catch(TooManyHelperFunctionsException e){
                    skipped_tooManyHelperFunctionsCounter++;
                } catch (OptimizerHelper.UnsupportedExpressionTypeException e) {
                    skipped_unsupportedExpressionType++;
                } catch (HasBadStructureException e){
                    skipped_hasBadStructure++;
                } catch (TooDeepException e){
                    skipped_tooDeep++;
                } catch (TooMuchTimeException e){
                    skipped_tooMuchTime++;
                } catch (IllegalStateException e) {
                    // TODO fix this so all the types of expressions are
                    // handled.
                    skipped_otherCounter++;
                } catch (UnsupportedOperationException e){
                    skipped_unsupportedExpressionType++;
                } catch (IllegalArgumentException e) {
                    // TODO figure out why this is happening and fix it.
                    skipped_otherCounter++;
                } catch (Throwable e) {
                    // TODO figure out why this is happening and fix it.
                    skipped_otherCounter++;
                }
            }

            if (moreFunctions.size() > 0 ||
                    skipped_otherCounter > 0 ||
                    skipped_hasBadStructure > 0 ||
                    skipped_tooDeep > 0 ||
                    skipped_tooMuchTime > 0 ||
                    skipped_tooManyHelperFunctionsCounter > 0 ||
                    skipped_unsupportedExpressionType > 0 ||
                    changedCounter > 0) {
                System.out.print(m.getName());
                System.out.println(": ");
                if (moreFunctions.size() > 0) {
                    System.out.println("    Added " + moreFunctions.size()
                            + " more functions.");
                }
                if (changedCounter > 0) {
                    System.out.println("    Changed " + changedCounter + " of "
                            + functionsList.size() + " expressions.");
                }
                if (
                        skipped_unsupportedExpressionType > 0 ||
                        skipped_tooManyHelperFunctionsCounter > 0 ||
                        skipped_hasBadStructure > 0 ||
                        skipped_tooDeep > 0 ||
                        skipped_tooMuchTime > 0 ||
                        skipped_otherCounter > 0) {
                    System.out.println("    Skipped " + (skipped_hasBadStructure + skipped_otherCounter + skipped_tooManyHelperFunctionsCounter + skipped_unsupportedExpressionType) + " of " + functionsList.size() + " expressions.");
                    if (skipped_tooManyHelperFunctionsCounter > 0) {
                        System.out.println("        Too many helpers " + skipped_tooManyHelperFunctionsCounter + " of " + functionsList.size() + " expressions.");
                    }
                    if (skipped_unsupportedExpressionType > 0) {
                        System.out.println("        Unsupported expression types " + skipped_unsupportedExpressionType + " of " + functionsList.size() + " expressions.");
                    }
                    if (skipped_hasBadStructure > 0) {
                        System.out.println("        Incomplete optimization " + skipped_hasBadStructure + " of " + functionsList.size() + " expressions.");
                    }
                    if (skipped_tooDeep > 0) {
                        System.out.println("        Optimization too deep " + skipped_tooDeep + " of " + functionsList.size() + " expressions.");
                    }
                    if (skipped_tooMuchTime > 0) {
                        System.out.println("        Too much time " + skipped_tooMuchTime + " of " + functionsList.size() + " expressions.");
                    }                   
                    if (skipped_otherCounter > 0) {
                        System.out.println("        Other " + skipped_otherCounter + " of " + functionsList.size() + " expressions.");
                    }                   
                }
            }

            // add the helper functions to the list of functions for the module.
            {
                for (final MachineFunction mf : moreFunctions) {
                    m.addFunction(mf);
                    functionsList.add(mf);
                }
            }
           
        }
       
        Iterator<MachineFunction> functions = functionsList.iterator();
        Map<String, Expression> nameToExpressionMap = new HashMap<String, Expression>();
        while (functions.hasNext()) {
            MachineFunction cl = functions.next ();
            nameToExpressionMap.put (cl.getName(), cl.getExpressionForm());
        }
       
        // Determine the strongly connected components and put the information into the code labels.
        List<Set<String>> sets = ExpressionAnalyzer.determineStronglyConnectedComponents(m.getName(), nameToExpressionMap);
        for (int i = 0; i < sets.size(); ++i) {
            Set<String> set = sets.get(i);
            Iterator<String> items = set.iterator();
            while (items.hasNext()) {
                String name = items.next();
                MachineFunctionImpl mf = (MachineFunctionImpl)m.getFunction(name);
                if (mf != null) {
                    mf.setStronglyConnectedComponents(set);
                }
            }
        }

        // Now that we've determined the closely connected components we can use
        // an ExpressionAnalyzer to do optimizing transformations to the expression.
        functions = functionsList.iterator();
        while (functions.hasNext()) {
           
            MachineFunction cl = functions.next ();
            ExpressionAnalyzer ea = new ExpressionAnalyzer (m.getModuleTypeInfo(), cl);
           
            cl.setExpression(ea.transformExpression(cl.getExpressionForm()));
            if (ea.getHadUnsafeCoerce()){
                cl.setHadUnsafeCoerce();
            }
View Full Code Here

            // Imported modules.
            int nImports = s.readInt();
            for (int i = 0; i < nImports; ++i) {
                ModuleName importName = s.readModuleName();
                Module m = otherModules.get(importName);
                if (m == null) {
                    throw new IOException ("Unable to resolve imported module " + importName + " in " + getModuleName());
                }
                addImportedModule(m.getModuleTypeInfo());
            }
            finishAddingImportedModules();

            // All the using... map members are maps of String -> String.
            // usingFunctionOrClassMethodMap
View Full Code Here

        /**
         * Get the ModuleTypeInfo for the current module in this info object.
         * @return ModuleTypeInfo
         */
        public final ModuleTypeInfo getModuleTypeInfo() {
            Module module = program.getModule(moduleName);
            if (module == null) {
                return null;
            }
            return module.getModuleTypeInfo();
        }
View Full Code Here

    private List<QualifiedName> listCAFs (final ModuleName moduleName, final boolean includeDependees) {
        if (moduleName == null) {
            throw new NullPointerException ("Null module reference in ExecutionContext.listCAFs().");
        }      
                              
        Module module = workspaceManager.getModule(moduleName);
        if (module == null) {
            throw new IllegalArgumentException ("The module " + moduleName + " does not exist in the current workspace.");
        }
       
        Set<ModuleName> moduleNames;
        if (includeDependees) {
            moduleNames = module.getDependeeModuleNames();
        } else {
            moduleNames = new HashSet<ModuleName> ();
        }
        moduleNames.add(moduleName);
       

        List<QualifiedName> cafNames = new ArrayList<QualifiedName>();
       
        for (final ModuleName currentModuleName : moduleNames) {
           
            Module currentModule = workspaceManager.getModule(currentModuleName);
           
            for (final MachineFunction mf : currentModule.getFunctions()) {
               
                if (mf.isCAF() &&  // Only include CAFs
                    mf.getAliasOf() == null &&  // exclude CAFs which are an alias for another function
                    mf.getLiteralValue() == null &&  // exclude CAFs which are simply a literal value
                    mf.getName().indexOf('$') < 0){ // exclude CAFs which are automatically generated by a deriving clause
View Full Code Here

        // Create the TypeInfoStats object which will collect the stats.
        TypeInfoStats typeInfoStats = new TypeInfoStats(iceLogger);
       
        // Collect stats for all modules in the list.
        for (final ModuleName moduleName : moduleNames) {
            Module module = workspaceManager.getModule(moduleName);
            if (module == null) {
                iceLogger.log(Level.WARNING, "Module not in program: " + moduleName);
                continue;
            }
           
            ModuleTypeInfo moduleTypeInfo = module.getModuleTypeInfo();
            typeInfoStats.collectTypeInfoStats(moduleTypeInfo);
        }
       
        if (typeInfoStats.totalModules == 0) {
            // nothing to do.
View Full Code Here

            return;
        }

        ModuleName[] moduleNames = getWorkspaceManager().getModuleNamesInProgram();
        for (final ModuleName element : moduleNames) {
            Module module = getWorkspaceManager().getModuleTypeInfo(element).getModule();                        

            Collection<MachineFunction> functions = module.getFunctions();
            for (final MachineFunction function : functions) {               
                disassemble (function);
                logInfo("\n");
            }
        }
View Full Code Here

            CodeGenerator cg = makeCodeGenerator();

            forImmediateUse = bfor;

            Module module = program.getModule(adjunctModule);
            cg.generateSCCode(module, compilerLogger);

            cg.finishedGeneratingCode(compilerLogger);
       
        } catch (CompilerMessage.AbortCompilation e) {
View Full Code Here

TOP

Related Classes of org.openquark.cal.machine.Module

Copyright © 2018 www.massapicom. 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.