Blang/src/code-gen/src/main.cpp

94 lines
2.2 KiB
C++
Raw Normal View History

2015-06-30 08:17:40 +02:00
#include <iostream>
2015-07-03 16:58:15 +02:00
#include <string>
2015-06-30 08:17:40 +02:00
#include <vector>
2015-07-03 16:58:15 +02:00
#include <map>
2015-06-30 08:17:40 +02:00
#include <fstream>
2016-04-22 21:46:31 +02:00
#include <getopt.h>
2015-07-03 16:58:15 +02:00
#include <cstdlib>
2015-06-30 08:17:40 +02:00
using namespace std;
2015-07-03 18:31:48 +02:00
string getHelpString(){
2016-04-22 21:46:31 +02:00
return "\nUsage : Blang input-file [OPTION]\n\n"
2015-07-03 18:31:48 +02:00
" -o output\t\tWrite output to file.\n"
" -l lib\t\tSearch the library named library.\n"
" -L dir\t\tadd all the libraries in the folder dir.\n"
" -v\t\t\tShow version then exit\n"
" -h\t\t\tShow help then exit\n";
}
2015-07-03 17:56:19 +02:00
string getVersionString(){
2016-04-22 21:46:31 +02:00
string str;
/*
str += "g1m-assembler-mkg1m version ";
str += BLANG_VERSION;
str += " release ";
str += BLANG_RELEASE;
*/
return str;
2015-06-30 08:17:40 +02:00
}
int main(int argc,char *argv[])
{
2015-06-30 17:09:08 +02:00
vector<string> outputFiles;
vector<string> inputFiles;
2015-07-03 16:58:15 +02:00
vector<string> CLibraries;
vector<string> CLibraryDir;
2015-06-30 17:09:08 +02:00
int c;
opterr = 0; // disable getopt error
2016-04-22 21:46:31 +02:00
int option_index = 0;
static struct option long_options[] = {
{"version", no_argument, 0, 'v' },
{"help", no_argument, 0, 'h' },
{"input", required_argument, 0, 'i' },
{"output", required_argument, 0, 'o' },
{0, 0, 0, 0 }
};
while ((c = getopt_long(argc, argv, "o:i:l:L:vh", long_options,&option_index)) != -1){
2015-06-30 17:09:08 +02:00
switch (c){
case 'o':
outputFiles.push_back(optarg); //get output files
break;
case 'i':
inputFiles.push_back(optarg); //get input files
break;
2015-07-03 16:58:15 +02:00
case 'l':
CLibraries.push_back(optarg); //get input files
break;
case 'L':
CLibraryDir.push_back(optarg); //get input files
break;
2015-07-03 17:56:19 +02:00
case 'v':
cout << getVersionString();
return 0;
2015-07-03 18:31:48 +02:00
case 'h':
cout << getHelpString();
return 0;
2015-06-30 17:09:08 +02:00
case '?':
if (optopt == 'o')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
return 1;
default:
2015-07-03 16:58:15 +02:00
return 1;
2015-06-30 17:09:08 +02:00
}
}
//get input files
for (int index = optind; index < argc; index++)
inputFiles.push_back(argv[index]);
2015-07-03 16:58:15 +02:00
if(inputFiles.empty()){
fprintf (stderr, "No input file\n");
return 1;
}
2015-06-30 08:17:40 +02:00
return 0;
}