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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [wigen/] [main.cpp] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
/*
2
 * Copyright (c) 2016 by Alex I. Kuznetsov.
3
 *
4
 * Part of the LXP32 CPU IP core.
5
 *
6
 * Main translation unit for the WISHBONE interconnect generator.
7
 */
8
 
9
#include "generator.h"
10
 
11
#include <iostream>
12
#include <string>
13
#include <stdexcept>
14
#include <cstring>
15
#include <cstdlib>
16
 
17
static void displayUsage(std::ostream &os,const char *program) {
18
        os<<std::endl;
19
        os<<"Usage:"<<std::endl;
20
        os<<"    "<<program<<" [ option(s) ] <nm> <ns> <ma> <sa> <ps> [ <pg> ]"<<std::endl<<std::endl;
21
        os<<"    <nm>         Number of masters"<<std::endl;
22
        os<<"    <ns>         Number of slaves"<<std::endl;
23
        os<<"    <ma>         Master address width"<<std::endl;
24
        os<<"    <sa>         Slave address width"<<std::endl;
25
        os<<"    <ps>         Port size"<<std::endl;
26
        os<<"    <pg>         Port granularity, default: port size"<<std::endl;
27
        os<<std::endl;
28
 
29
        os<<"Options:"<<std::endl;
30
        os<<"    -e <entity>  Entity name, default: \"intercon\""<<std::endl;
31
        os<<"    -h, --help   Display a short help message"<<std::endl;
32
        os<<"    -o <file>    Output file name, default: \"<entity>.vhd\""<<std::endl;
33
        os<<"    -p           Generate pipelined arbiter"<<std::endl;
34
        os<<"    -r           Generate registered feedback signals"<<std::endl;
35
        os<<"    -u           Generate unsafe slave decoder"<<std::endl;
36
}
37
 
38
int main(int argc,char *argv[]) try {
39
        std::cout<<"WISHBONE interconnect generator"<<std::endl;
40
        std::cout<<"Copyright (c) 2016 by Alex I. Kuznetsov"<<std::endl;
41
 
42
        if(argc<=1) {
43
                displayUsage(std::cout,argv[0]);
44
                return 0;
45
        }
46
 
47
        Generator gen;
48
        std::string outputFileName;
49
        int mainArg=0;
50
 
51
        for(int i=1;i<argc;i++) {
52
                if(argv[i][0]=='-') {
53
                        if(!strcmp(argv[i],"-e")) {
54
                                if(++i==argc) {
55
                                        displayUsage(std::cerr,argv[0]);
56
                                        return EXIT_FAILURE;
57
                                }
58
                                gen.setEntityName(argv[i]);
59
                        }
60
                        else if(!strcmp(argv[i],"-h")||!strcmp(argv[i],"--help")) {
61
                                displayUsage(std::cout,argv[0]);
62
                                return 0;
63
                        }
64
                        else if(!strcmp(argv[i],"-o")) {
65
                                if(++i==argc) {
66
                                        displayUsage(std::cerr,argv[0]);
67
                                        return EXIT_FAILURE;
68
                                }
69
                                outputFileName=argv[i];
70
                        }
71
                        else if(!strcmp(argv[i],"-p")) {
72
                                gen.setPipelinedArbiter(true);
73
                        }
74
                        else if(!strcmp(argv[i],"-r")) {
75
                                gen.setRegisteredFeedback(true);
76
                        }
77
                        else if(!strcmp(argv[i],"-u")) {
78
                                gen.setUnsafeDecoder(true);
79
                        }
80
                        else throw std::runtime_error(std::string("Unrecognized option: \"")+argv[i]+"\"");
81
                }
82
                else {
83
                        if(mainArg>5) throw std::runtime_error("Too many arguments");
84
 
85
                        int value;
86
 
87
                        try {
88
                                value=std::stoi(argv[i],nullptr,0);
89
                        }
90
                        catch(std::exception &) {
91
                                throw std::runtime_error("Invalid value");
92
                        }
93
 
94
                        switch(mainArg) {
95
                        case 0:
96
                                gen.setMasters(value);
97
                                break;
98
                        case 1:
99
                                gen.setSlaves(value);
100
                                break;
101
                        case 2:
102
                                gen.setAddrWidth(value);
103
                                break;
104
                        case 3:
105
                                gen.setSlaveAddrWidth(value);
106
                                break;
107
                        case 4:
108
                                gen.setPortSize(value);
109
                                break;
110
                        case 5:
111
                                gen.setPortGranularity(value);
112
                                break;
113
                        }
114
                        mainArg++;
115
                }
116
        }
117
 
118
        if(mainArg<5) throw std::runtime_error("Too few arguments");
119
        if(mainArg==5) gen.setPortGranularity(gen.portSize());
120
 
121
        if(outputFileName.empty()) outputFileName=gen.entityName()+".vhd";
122
 
123
        gen.generate(outputFileName);
124
}
125
catch(std::exception &ex) {
126
        std::cerr<<"Error: "<<ex.what()<<std::endl;
127
        return EXIT_FAILURE;
128
}

powered by: WebSVN 2.1.0

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