summaryrefslogtreecommitdiffstats
path: root/zpu/sw/simulator/com/zylin/zpu/stats/CountSequences.java
blob: 0f06aec17de7bb0d3cde38949557e3bead1ac80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Created on Jan 18, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.zylin.zpu.stats;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.zylin.zpu.simulator.Machine;

public class CountSequences implements Machine
{

    private byte[] array;
    private StatKeeper statKeeper;

    public static void main(String[] args)
    {
        new CountSequences().run(args[0]);
    }

    private void run(String string)
    {
        try
        {
            File file=new File(string);
            if (file.exists())
                System.out.println("It exists!");
            FileInputStream in=new FileInputStream(file);
            
            try
            {
                array=new byte[(int) file.length()];
                
                if (in.read(array)!=array.length)
                    throw new IOException();
                
                countStats();
                
                statKeeper.printStats();
            } finally
            {
                in.close();
            }
            
        } catch (FileNotFoundException e)
        {
            e.printStackTrace();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
        
        
    }


    private void countStats()
    {
        statKeeper=new StatKeeper(this);
        for (int i=0; i<array.length; i++)
        {
            int j = array[i]&0xff;
//            
//            if ((j>=64)&&(j<96))
//            {
//                j=64;
//            } else if ((j>=96)&&(j<128))
//            {
//                j=96;
//            } else if ((j>=128)&&(j<256))
//            {
//                j=128;
//            }
            statKeeper.countInstruction(j);
        }
        
    }

    public long getPrevCycles()
    {
        return 0;
    }

    public long getCycles()
    {
        return 0;
    }
}
OpenPOWER on IntegriCloud