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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [compiler/] [src/] [vp_compiler/] [Main.cpp] - Blame information for rev 230

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 216 diegovalve
/* This program is free software. It comes without any warranty, to
2
 * the extent permitted by applicable law. You can redistribute it
3
 * and/or modify it under the terms of the Do What The Fuck You Want
4
 * To Public License, Version 2, as published by Sam Hocevar. See
5
 * http://sam.zoy.org/wtfpl/COPYING for more details. */
6
 
7
#include "Compiler.h"
8
#include "Preprocessor.h"
9
#include <string>
10
#include <iostream>
11
#include <fstream>
12
#include <cstring>
13
 
14
Preprocessor PP;
15
 
16
int main(int argc, char * argv[]) {
17
        // make sure we received a filename
18
        if (argc < 2) {
19
                std::cerr << "Usage: ./theia_compile -i [FILENAME] [-f <hex32|hex64>]" << std::endl;
20
                return 255;
21
        }
22
 
23
 
24
std::cout << "---------------------------------------------------------------\n";
25
std::cout << "  \n";
26
std::cout << " _/_/_/_/_/  _/                  _/            \n";
27
std::cout << "   _/      _/_/_/      _/_/          _/_/_/   \n";
28
std::cout << "  _/      _/    _/  _/_/_/_/  _/  _/    _/    \n";
29
std::cout << " _/      _/    _/  _/        _/  _/    _/     \n";
30
std::cout << "_/      _/    _/    _/_/_/  _/    _/_/_/      \n";
31
std::cout << "\n";
32
std::cout << "\n";
33
std::cout << "---------------------------------------------------------------\n";
34
 
35
        char * inputFile, * outputMode;
36
        TheiaCompiler * Compiler;
37
        bool OutputMode32 = false;
38
        bool FilePathDefined = false;
39
        bool StdIn = false;
40
        try {
41
 
42
        for (int i = 1; i < argc; i++)
43
        {
44
 
45
                        if (!strcmp(argv[i],"-i"))
46
                        {
47
                                inputFile = argv[i+1];
48
                                FilePathDefined = true;
49
                                i++;
50
                        }
51
                        else if (!strcmp(argv[i],"-stdin"))
52
                        {
53
                                StdIn = true;
54
                        }
55
                        else if (!strcmp(argv[i],"-hex32"))
56
                        {
57
                                        OutputMode32 = true;
58
 
59
                        }
60
                        else
61
                        {
62
                                std::cout << "Error: Invalid option " <<  argv[i] << "\n";
63
                                return 255;
64
                        }
65
 
66
 
67
 
68
        }
69
        if (!FilePathDefined)
70
        {
71
                std::cout << "Error: Input file not defined\n ";
72
                return 255;
73
        }
74
 
75
        if (StdIn)
76
        {
77
                Compiler = new TheiaCompiler(std::cin);
78
        } else {
79
                PP.Execute(inputFile);
80
                Compiler = new TheiaCompiler( std::string(inputFile)+ ".preprocessed",OutputMode32);
81 230 diegovalve
                if (!OutputMode32)
82
                        std::cout << "-W- Warning not using 32 bit mode. You need to use 32 bit mode (-hex32) to load memory file into RTL simulation\n";
83 216 diegovalve
 
84
 
85
        }
86
        /*
87
                // - means stdin, not a file named '-'
88
                if (strcmp(argv[1], "-") == 0) {
89
 
90
                        Compiler = new TheiaCompiler(std::cin);
91
                } else {
92
                        PP.Execute(argv[1]);
93
 
94
                        Compiler = new TheiaCompiler( std::string(argv[1])+ ".preprocessed");
95
                }
96
                */
97
        } catch (std::string error) {
98
                std::cerr << "ERROR: " << error << std::endl;
99
                return 255;
100
        }
101
        Compiler->Print();
102
 
103
        std::ofstream ofs;
104
        ofs.open("code.list");
105
        if (!ofs.good())
106
        {
107
                std::cout << "Error could not open file for write 'code.mem'\n";
108
                return 0;
109
        }
110
 
111
        ofs << Compiler->GetHexCodeDump();
112
        ofs.close();
113
        ofs.open("code.mem");
114
        ofs << Compiler->PostProcess("code.list");
115
        ofs.close();
116
 
117
    delete Compiler;
118
        std::string Command = "rm " + std::string(inputFile)+ ".preprocessed";
119
        system(Command.c_str());
120
        std::cout << "Code successfully compiled!\n";
121
        return 0;
122
}
123
 

powered by: WebSVN 2.1.0

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