1/*****************************************************************************
2 *                                McPAT
3 *                      SOFTWARE LICENSE AGREEMENT
4 *            Copyright 2012 Hewlett-Packard Development Company, L.P.
5 *            Copyright (c) 2010-2013 Advanced Micro Devices, Inc.
6 *                          All Rights Reserved
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer;
12 * redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution;
15 * neither the name of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 ***************************************************************************/
32#include <sys/stat.h>
33
34#include <cassert>
35#include <iostream>
36
37#include "basic_components.h"
38#include "io.h"
39#include "system.h"
40#include "version.h"
41#include "xmlParser.h"
42
43using namespace std;
44
45void print_usage(char * argv0);
46
47int main(int argc, char *argv[]) {
48    char* xml_file = NULL;
49    int plevel = 2;
50
51    for (int32_t i = 0; i < argc; i++) {
52        if (argv[i] == string("-infile")) {
53            xml_file = argv[++i];
54
55        } else if (argv[i] == string("-print_level")) {
56            plevel = atoi(argv[++i]);
57
58        } else if (argv[i] == string("-opt_for_clk")) {
59            McPATComponent::opt_for_clk = (bool)atoi(argv[++i]);
60        }
61    }
62
63    // Ensure that the XML file was specified
64    if (xml_file == NULL) {
65        cerr << "ERROR: Please specify infile\n\n";
66        print_usage(argv[0]);
67    }
68
69    // Ensure that the XML file exists
70    struct stat file_info;
71    if (stat(xml_file, &file_info)) {
72        cerr << "ERROR: File not found: " << xml_file << endl << endl;
73        print_usage(argv[0]);
74    }
75
76    cout << "McPAT (version " << VER_MAJOR << "." << VER_MINOR
77         << " of " << VER_UPDATE << ") is computing the target processor...\n "
78         << endl;
79
80    // Parse the XML input file
81    XMLNode xml_data = XMLNode::openFileHelper(xml_file, "component");
82    unsigned int num_children = xml_data.nChildNode("component");
83    assert(num_children == 1);
84    XMLNode system_xml = xml_data.getChildNode("component");
85    assert(strcmp(system_xml.getAttribute("type"), "System") == 0);
86
87    // Recursively instantiate the system hierarchy
88    System* system = new System(&system_xml);
89
90    // Recursively compute chip area
91    system->computeArea();
92
93    // Recursively compute the power consumed
94    system->computeEnergy();
95
96    // Recursively output the computed values
97    system->displayData(2, plevel);
98
99    // Clean up
100    delete system;
101    return 0;
102
103}
104
105void print_usage(char * argv0) {
106    cerr << "How to use McPAT:" << endl;
107    cerr << "  mcpat -infile <input file name>  -print_level < "
108         << "level of details 0~5 >  -opt_for_clk < 0 (optimize for ED^2P "
109         << "only)/1 (optimzed for target clock rate)>" << endl;
110    exit(1);
111}
112