Changeset 13967


Ignore:
Timestamp:
Nov 6, 2019 9:40:05 PM (8 days ago)
Author:
jwedin
Message:

Moved buildNodeCountMap from ASTNode to UtilInterface. #5865

Location:
branches/dev-jw-2590/Compiler
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-jw-2590/Compiler/ModelicaCompiler/src/jastadd/ModelicaCompiler.jrag

    r13960 r13967  
    530530     * @param count  it node counts should also be generated
    531531     */
    532     protected void dumpMemoryUseFile(ASTNode root, String type, boolean count) throws FileNotFoundException {
    533         dumpMemoryUseFile(root, type, type, count);
     532    protected void dumpMemoryUseFile(ASTNode root, UtilInterface util, String type, boolean count) throws FileNotFoundException {
     533        dumpMemoryUseFile(root, util, type, type, count);
    534534    }
    535535
     
    544544     * @param count  it node counts should also be generated
    545545     */
    546     protected void dumpMemoryUseFile(ASTNode root, String type, String name, boolean count)
     546    protected void dumpMemoryUseFile(ASTNode root, UtilInterface util, String type, String name, boolean count)
    547547            throws FileNotFoundException {
    548548        if (dumpMemoryUse) {
     
    553553            time = Math.round((System.currentTimeMillis() - time) / 1000.0);
    554554            if (count)
    555                 root.buildNodeCount();
     555                root.buildNodeCount(util.getBuildNodeCountMap());
    556556            log.debug(" Dumped tree in " + time + "s");
    557557        }
     
    568568            String file = "node_count.txt";
    569569            log.debug("Dumping node counts to '" + file + "'...");
    570             root.dumpNodeCount(file);
     570            root.dumpNodeCount(file, root.getUtilInterface());
    571571        }
    572572    }
     
    10861086        // build source tree
    10871087        SourceRoot sr = parseModelFromPaths(paths);
    1088         dumpMemoryUseFile(sr, "source", false);
     1088        dumpMemoryUseFile(sr, sr.getUtilInterface(), "source", false);
    10891089
    10901090        if (options.getBooleanOption("generate_html_diagnostics")) {
     
    10951095        InstClassDecl icl = instantiateModel(sr, cl, target);
    10961096       
    1097         dumpMemoryUseFile(sr, "source and instance", "instance", true);
     1097        dumpMemoryUseFile(sr, sr.getUtilInterface(), "source and instance", "instance", true);
    10981098       
    10991099        return icl;
     
    12221222        log.info("Flattening model...");
    12231223        icd.flattenInstClassDecl(fc);
    1224         dumpMemoryUseFile(fc, "flat", true);
     1224        dumpMemoryUseFile(fc, fc.root().getUtilInterface(), "flat", true);
    12251225        dumpNodeCountFile(icd.root());
    12261226        icd = null;
     
    12841284        ASTNode.endStep("prettyPrintFlat()");
    12851285       
    1286         dumpMemoryUseFile(fc, "transformed", false);
     1286        dumpMemoryUseFile(fc, fc.root().getUtilInterface(), "transformed", false);
    12871287       
    12881288        if (options.getBooleanOption("write_iteration_variables_to_file")) {
     
    20612061            if (target.getCodeGenFlag()) {
    20622062                generateCode(fc, target);
    2063                 dumpMemoryUseFile(fc, "generated", false);
     2063                dumpMemoryUseFile(fc, util, "generated", false);
    20642064            }
    20652065           
  • branches/dev-jw-2590/Compiler/ModelicaCompiler/src/jastadd/UtilInterface.jrag

    r13914 r13967  
     1import org.jmodelica.modelica.compiler.ASTNode.Counter;
     2
    13aspect UtilInterface {
    24   
     
    5860            public void tearDown() {}
    5961        }
    60        
     62
     63        private Map<Class, Counter> buildNodeCountMap;
     64        public Map<Class, Counter> getBuildNodeCountMap() {
     65            if (buildNodeCountMap == null) {
     66                buildNodeCountMap = new HashMap<>();
     67            }
     68            return buildNodeCountMap;
     69        }
     70
    6171        private static LinkedList<Registrant> registrants = new LinkedList<>();
    6272        private static Registrant addRegistrant(Registrant registrant) {
  • branches/dev-jw-2590/Compiler/ModelicaMiddleEnd/src/jastadd/Profiling.jrag

    r13900 r13967  
    401401    }
    402402
    403     private Map<Class,Counter> ASTNode.buildNodeCountMap = null;
    404 
    405403    private static NodeCountExtra[] ASTNode.nodeCountExtra = new NodeCountExtra[] { };
    406404
     
    413411     * Output a list of the number of instances of each node class.
    414412     */
    415     public void ASTNode.dumpNodeCount(String file)
     413    public void ASTNode.dumpNodeCount(String file, UtilInterface util)
    416414            throws IOException {
    417415        ArrayList<Counter> list = new ArrayList<Counter>();
    418         list.addAll(buildNodeCountMap.values());
     416        list.addAll(util.getBuildNodeCountMap().values());
    419417        Collections.sort(list);
    420418        CodeStream out = new CodeStream(file);
     
    426424    }
    427425
    428     public void ASTNode.buildNodeCount() {
    429         Profiler.clear();
    430         if (buildNodeCountMap == null)
    431             buildNodeCountMap = new HashMap<Class,Counter>();
    432         buildNodeCount(buildNodeCountMap);
    433         Profiler.clear();
    434     }
    435 
    436     private void ASTNode.buildNodeCount(Map<Class,Counter> map) {
     426    public void ASTNode.buildNodeCount(Map<Class,Counter> map) {
    437427        addToNodeCount(map, getClass(), Profiler.getNodeSize(this, false), Profiler.getNodeSize(this, true));
    438428        for (NodeCountExtra nce : nodeCountExtra)
Note: See TracChangeset for help on using the changeset viewer.