OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [utils/] [StringHelper.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright (c) 2014, Aleksander Osman
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
 
27
package ao486.utils;
28
 
29
import java.io.File;
30
import java.nio.file.Files;
31
import java.util.LinkedList;
32
 
33
public class StringHelper {
34
 
35
    static class Port {
36
        String direction;
37
        boolean is_reg;
38
        int size;
39
        String name;
40
    }
41
 
42
    public static void main(String args[]) throws Exception {
43
 
44
        File input_file = new File("convert.txt");
45
 
46
        byte input_bytes[] = Files.readAllBytes(input_file.toPath());
47
 
48
        String input = new String(input_bytes);
49
 
50
        String lines[] = input.split(",");
51
 
52
        LinkedList<Port> list = new LinkedList<>();
53
 
54
        for(String line : lines) {
55
            String tokens[] = line.split("\\s+");
56
 
57
            Port port = new Port();
58
            int index = 0;
59
 
60
            if(tokens[index].equals("")) index++;
61
 
62
            //direction
63
            if(tokens[index].equals("output"))      port.direction = "output";
64
            else if(tokens[index].equals("input"))  port.direction = "input";
65
            else throw new Exception("Unknown direction: " + tokens[index]);
66
            index++;
67
 
68
            //is_reg
69
            if(tokens[index].equals("reg")) {
70
                index++;
71
                port.is_reg = true;
72
            }
73
 
74
            //size
75
            if(tokens[index].startsWith("[")) {
76
                int end = tokens[index].indexOf(":");
77
                port.size = Integer.parseInt(tokens[index].substring(1, end));
78
                port.size++;
79
                index++;
80
            }
81
            else {
82
                port.size = 1;
83
            }
84
 
85
            //name
86
            port.name = tokens[index];
87
            index++;
88
 
89
            if(index != tokens.length) throw new Exception("Parse error: too long.");
90
 
91
            list.add(port);
92
        }
93
 
94
        StringBuilder build = new StringBuilder();
95
 
96
        int l1 = 30;
97
        int l2 = 30;
98
        for(Port port : list) {
99
 
100
            build.append("    .").append(port.name);
101
            for(int i=port.name.length(); i<l1; i++) build.append(" ");
102
 
103
            build.append("(").append(port.name).append("),");
104
            for(int i=port.name.length(); i<l2; i++) build.append(" ");
105
 
106
            build.append("//").append(port.direction);
107
            if(port.size > 1) build.append(" [").append(port.size-1).append(":0]");
108
 
109
            build.append("\n");
110
        }
111
        System.out.println(build);
112
        System.out.println("---------------");
113
 
114
 
115
        build = new StringBuilder();
116
 
117
        l1 = 12;
118
        for(Port port : list) {
119
            StringBuilder local = new StringBuilder();
120
 
121
            local.append("wire ");
122
            if(port.size > 1) local.append("[").append(port.size-1).append(":0]");
123
 
124
            for(int i=local.length(); i<l1; i++) local.append(" ");
125
 
126
            local.append(port.name).append(";\n");
127
            build.append(local);
128
        }
129
        System.out.println(build);
130
        System.out.println("---------------");
131
    }
132
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.