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] - Diff between revs 216 and 230

Only display areas with differences | Details | Blame | View Log

Rev 216 Rev 230
/* This program is free software. It comes without any warranty, to
/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */
 * http://sam.zoy.org/wtfpl/COPYING for more details. */
 
 
#include "Compiler.h"
#include "Compiler.h"
#include "Preprocessor.h"
#include "Preprocessor.h"
#include <string>
#include <string>
#include <iostream>
#include <iostream>
#include <fstream>
#include <fstream>
#include <cstring>
#include <cstring>
 
 
Preprocessor PP;
Preprocessor PP;
 
 
int main(int argc, char * argv[]) {
int main(int argc, char * argv[]) {
        // make sure we received a filename
        // make sure we received a filename
        if (argc < 2) {
        if (argc < 2) {
                std::cerr << "Usage: ./theia_compile -i [FILENAME] [-f <hex32|hex64>]" << std::endl;
                std::cerr << "Usage: ./theia_compile -i [FILENAME] [-f <hex32|hex64>]" << std::endl;
                return 255;
                return 255;
        }
        }
 
 
 
 
std::cout << "---------------------------------------------------------------\n";
std::cout << "---------------------------------------------------------------\n";
std::cout << "  \n";
std::cout << "  \n";
std::cout << " _/_/_/_/_/  _/                  _/            \n";
std::cout << " _/_/_/_/_/  _/                  _/            \n";
std::cout << "   _/      _/_/_/      _/_/          _/_/_/   \n";
std::cout << "   _/      _/_/_/      _/_/          _/_/_/   \n";
std::cout << "  _/      _/    _/  _/_/_/_/  _/  _/    _/    \n";
std::cout << "  _/      _/    _/  _/_/_/_/  _/  _/    _/    \n";
std::cout << " _/      _/    _/  _/        _/  _/    _/     \n";
std::cout << " _/      _/    _/  _/        _/  _/    _/     \n";
std::cout << "_/      _/    _/    _/_/_/  _/    _/_/_/      \n";
std::cout << "_/      _/    _/    _/_/_/  _/    _/_/_/      \n";
std::cout << "\n";
std::cout << "\n";
std::cout << "\n";
std::cout << "\n";
std::cout << "---------------------------------------------------------------\n";
std::cout << "---------------------------------------------------------------\n";
 
 
        char * inputFile, * outputMode;
        char * inputFile, * outputMode;
        TheiaCompiler * Compiler;
        TheiaCompiler * Compiler;
        bool OutputMode32 = false;
        bool OutputMode32 = false;
        bool FilePathDefined = false;
        bool FilePathDefined = false;
        bool StdIn = false;
        bool StdIn = false;
        try {
        try {
 
 
        for (int i = 1; i < argc; i++)
        for (int i = 1; i < argc; i++)
        {
        {
 
 
                        if (!strcmp(argv[i],"-i"))
                        if (!strcmp(argv[i],"-i"))
                        {
                        {
                                inputFile = argv[i+1];
                                inputFile = argv[i+1];
                                FilePathDefined = true;
                                FilePathDefined = true;
                                i++;
                                i++;
                        }
                        }
                        else if (!strcmp(argv[i],"-stdin"))
                        else if (!strcmp(argv[i],"-stdin"))
                        {
                        {
                                StdIn = true;
                                StdIn = true;
                        }
                        }
                        else if (!strcmp(argv[i],"-hex32"))
                        else if (!strcmp(argv[i],"-hex32"))
                        {
                        {
                                        OutputMode32 = true;
                                        OutputMode32 = true;
 
 
                        }
                        }
                        else
                        else
                        {
                        {
                                std::cout << "Error: Invalid option " <<  argv[i] << "\n";
                                std::cout << "Error: Invalid option " <<  argv[i] << "\n";
                                return 255;
                                return 255;
                        }
                        }
 
 
 
 
 
 
        }
        }
        if (!FilePathDefined)
        if (!FilePathDefined)
        {
        {
                std::cout << "Error: Input file not defined\n ";
                std::cout << "Error: Input file not defined\n ";
                return 255;
                return 255;
        }
        }
 
 
        if (StdIn)
        if (StdIn)
        {
        {
                Compiler = new TheiaCompiler(std::cin);
                Compiler = new TheiaCompiler(std::cin);
        } else {
        } else {
                PP.Execute(inputFile);
                PP.Execute(inputFile);
                Compiler = new TheiaCompiler( std::string(inputFile)+ ".preprocessed",OutputMode32);
                Compiler = new TheiaCompiler( std::string(inputFile)+ ".preprocessed",OutputMode32);
 
                if (!OutputMode32)
 
                        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";
 
 
 
 
        }
        }
        /*
        /*
                // - means stdin, not a file named '-'
                // - means stdin, not a file named '-'
                if (strcmp(argv[1], "-") == 0) {
                if (strcmp(argv[1], "-") == 0) {
 
 
                        Compiler = new TheiaCompiler(std::cin);
                        Compiler = new TheiaCompiler(std::cin);
                } else {
                } else {
                        PP.Execute(argv[1]);
                        PP.Execute(argv[1]);
 
 
                        Compiler = new TheiaCompiler( std::string(argv[1])+ ".preprocessed");
                        Compiler = new TheiaCompiler( std::string(argv[1])+ ".preprocessed");
                }
                }
                */
                */
        } catch (std::string error) {
        } catch (std::string error) {
                std::cerr << "ERROR: " << error << std::endl;
                std::cerr << "ERROR: " << error << std::endl;
                return 255;
                return 255;
        }
        }
        Compiler->Print();
        Compiler->Print();
 
 
        std::ofstream ofs;
        std::ofstream ofs;
        ofs.open("code.list");
        ofs.open("code.list");
        if (!ofs.good())
        if (!ofs.good())
        {
        {
                std::cout << "Error could not open file for write 'code.mem'\n";
                std::cout << "Error could not open file for write 'code.mem'\n";
                return 0;
                return 0;
        }
        }
 
 
        ofs << Compiler->GetHexCodeDump();
        ofs << Compiler->GetHexCodeDump();
        ofs.close();
        ofs.close();
        ofs.open("code.mem");
        ofs.open("code.mem");
        ofs << Compiler->PostProcess("code.list");
        ofs << Compiler->PostProcess("code.list");
        ofs.close();
        ofs.close();
 
 
    delete Compiler;
    delete Compiler;
        std::string Command = "rm " + std::string(inputFile)+ ".preprocessed";
        std::string Command = "rm " + std::string(inputFile)+ ".preprocessed";
        system(Command.c_str());
        system(Command.c_str());
        std::cout << "Code successfully compiled!\n";
        std::cout << "Code successfully compiled!\n";
        return 0;
        return 0;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

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