1 /* `Deep Thought', a softcore CPU implemented on a FPGA
3 Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include <boost/tokenizer.hpp>
25 #include <boost/program_options.hpp>
26 #include <boost/lexical_cast.hpp>
32 #include "CInstrFactory.hpp"
34 using boost::lexical_cast;
35 using boost::bad_lexical_cast;
39 using namespace boost::program_options;
40 namespace po = boost::program_options;
46 disasm* Iinstr::m_disasm;
48 int main(int argc, char* argv[])
53 po::options_description desc("Allowed options");
55 ("help,h","produce help message")
56 ("file,f",value<string>(), "input file")
59 po::positional_options_description p;
63 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
66 if(vm.count("help")) {
71 if(vm.count("file")) {
73 cout << "going to open file " << vm["file"].as<string>() << endl;
75 inFile.open(vm["file"].as<string>(), ios::in);
77 cerr << "Error opening file " << vm["file"].as<string>() << endl;
82 cout << "not input file given!" << endl << endl;
87 catch(std::exception& ex) {
88 cout << ex.what() << endl;
92 string dir = "./instr/";
94 map<short, Iinstr*> instr;
96 CInstrFactory instrFab;
98 instrFab.loadLibsIntoMap(instr, dir);
100 catch(std::bad_alloc& e) {
101 cerr << progName << ": bad_alloc caught " << e.what() << endl;
108 std::string str = "";
109 boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
110 boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
111 disasm disasm(instr);
112 while(getline(inFile, str)) {
117 for(auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
118 if(tok_iter == tokens.begin()) {
120 type = lexical_cast<int>(*tok_iter);
124 catch(bad_lexical_cast &) {
137 if((*tok_iter).size() > 0) {
141 cout << *tok_iter << ":";
146 out << "[0x" << *tok_iter << "]: ";
148 else if(count == 2) {
149 out << disasm.decodeToString(*tok_iter);
151 else if(count == 3) {
152 //code saved in hex-file
153 //cout << *tok_iter ;
155 else if(count == 4) {
157 if((*tok_iter).size() > 0) {
158 cout << *tok_iter << ":" << endl;
162 else if(count == 5) {
163 if((*tok_iter).size() > 0) {
173 cerr << "i was to lazy to implement the other format types for now" << endl;
177 if(type == 1 && count <= 4) {