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 216

Go to most recent revision | 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
 
82
 
83
        }
84
        /*
85
                // - means stdin, not a file named '-'
86
                if (strcmp(argv[1], "-") == 0) {
87
 
88
                        Compiler = new TheiaCompiler(std::cin);
89
                } else {
90
                        PP.Execute(argv[1]);
91
 
92
                        Compiler = new TheiaCompiler( std::string(argv[1])+ ".preprocessed");
93
                }
94
                */
95
        } catch (std::string error) {
96
                std::cerr << "ERROR: " << error << std::endl;
97
                return 255;
98
        }
99
        Compiler->Print();
100
 
101
        std::ofstream ofs;
102
        ofs.open("code.list");
103
        if (!ofs.good())
104
        {
105
                std::cout << "Error could not open file for write 'code.mem'\n";
106
                return 0;
107
        }
108
 
109
        ofs << Compiler->GetHexCodeDump();
110
        ofs.close();
111
        ofs.open("code.mem");
112
        ofs << Compiler->PostProcess("code.list");
113
        ofs.close();
114
 
115
    delete Compiler;
116
        std::string Command = "rm " + std::string(inputFile)+ ".preprocessed";
117
        system(Command.c_str());
118
        std::cout << "Code successfully compiled!\n";
119
        return 0;
120
}
121
 

powered by: WebSVN 2.1.0

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