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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [ParseDecode.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;
28
 
29
import java.util.HashMap;
30
 
31
public class ParseDecode extends Parse {
32
 
33
    ParseDecode(StringBuilder build) {
34
        this.build = build;
35
    }
36
 
37
    private StringBuilder build;
38
 
39
    @Override
40
    void parse(String section) throws Exception {
41
 
42
        HashMap<String, String> map = new HashMap<>();
43
        map.put("#command",    "");
44
        map.put("#cmdex",      "");
45
        map.put("#is_8bit",    "");
46
        map.put("#consume",    "");
47
        map.put("#is_complex", "");
48
        map.put("#opcode",     "");
49
        map.put("#ud_extra",   "");
50
 
51
        String lines[] = section.split("\\n");
52
        for(String line : lines) {
53
 
54
            boolean dec_cmd         = false;
55
            boolean dec_cmdex       = false;
56
            boolean dec_is_8bit     = false;
57
            boolean consume         = false;
58
            boolean dec_is_complex  = false;
59
            boolean dec_ready       = false;
60
            boolean prefix_group    = false;
61
 
62
            if(line.indexOf("`CMD_") != -1)                 dec_cmd = true;
63
            if(line.indexOf("SET(dec_cmdex") != -1)        dec_cmdex = true;
64
            if(line.indexOf("SET(dec_is_8bit") != -1)       dec_is_8bit = true;
65
            if(line.indexOf("SET(consume_") != -1)          consume = true;
66
            if(line.indexOf("SET(dec_is_complex") != -1)    dec_is_complex = true;
67
            if(line.indexOf("dec_ready_") != -1)            dec_ready = true;
68
            if(line.indexOf("prefix_group_1_lock") != -1)   prefix_group = true;
69
 
70
            if(dec_cmd) {
71
                if(dec_cmdex || dec_is_8bit || consume || dec_is_complex || dec_ready || prefix_group) throw new Exception("Can not distinguish: dec_cmd: " + line);
72
 
73
                map.put("#command", line);
74
            }
75
            if(dec_cmdex) {
76
                if(dec_cmd || dec_is_8bit || consume || dec_is_complex || dec_ready || prefix_group) throw new Exception("Can not distinguish: dec_cmdex: " + line);
77
 
78
                map.put("#cmdex", line);
79
            }
80
            if(dec_is_8bit) {
81
                if(dec_cmd || dec_cmdex || consume || dec_is_complex || dec_ready || prefix_group) throw new Exception("Can not distinguish: is_8bit: " + line);
82
 
83
                map.put("#is_8bit", line);
84
            }
85
            if(consume) {
86
                if(dec_cmd || dec_cmdex || dec_is_8bit || dec_is_complex || dec_ready || prefix_group) throw new Exception("Can not distinguish: consume: " + line);
87
 
88
                map.put("#consume", line);
89
            }
90
            if(dec_is_complex) {
91
                if(dec_cmd || dec_cmdex || dec_is_8bit || consume || dec_ready || prefix_group) throw new Exception("Can not distinguish: dec_is_complex: " + line);
92
 
93
                map.put("#is_complex", line);
94
            }
95
            if(dec_ready) {
96
                if(dec_cmd || dec_cmdex || dec_is_8bit || consume || dec_is_complex || prefix_group) throw new Exception("Can not distinguish: dec_ready: " + line);
97
 
98
                map.put("#opcode", line);
99
            }
100
            if(prefix_group) {
101
                if(dec_cmd || dec_cmdex || dec_is_8bit || consume || dec_is_complex || dec_ready) throw new Exception("Can not distinguish: prefix_group: " + line);
102
 
103
                String prefix = "prefix_group_1_lock";
104
                if(line.startsWith(prefix) == false) throw new Exception("Invalid prefix_group_1_lock: " + line);
105
                line = line.substring(prefix.length());
106
 
107
                map.put("#ud_extra", line);
108
            }
109
        }
110
 
111
        String decode_macro =
112
            "IF(#opcode);" + "\n" +
113
                "IF(prefix_group_1_lock #ud_extra); SET(exception_ud);" + "\n" +
114
                "ELSE();" + "\n" +
115
                    "#is_complex" + "\n" +
116
                    "#is_8bit" + "\n" +
117
                    "SET(dec_cmd, #command);" + "\n" +
118
                    "#cmdex" + "\n" +
119
                    "#consume" + "\n" +
120
                "ENDIF();" + "\n" +
121
            "ENDIF();" + "\n\n\n";
122
 
123
        String expanded_macro = decode_macro;
124
        for(String key : map.keySet()) {
125
            //System.out.println(key + "->" + map.get(key));
126
            expanded_macro = expanded_macro.replaceAll(key, map.get(key));
127
        }
128
        build.append(expanded_macro);
129
    }
130
}

powered by: WebSVN 2.1.0

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