00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028
00029 #include <fstream>
00030 #include <unistd.h>
00031 #include <stdio.h>
00032 #include <string>
00033 #include <vector>
00034 #include "ucloc.h"
00035 #include "ucfun.h"
00036
00037 #ifndef ALPHA_LINUX_CXX
00038 # include <iosfwd>
00039 #endif
00040
00041 using std::strcpy;
00042 using std::strrchr;
00043 using std::strlen;
00044 using std::ios;
00045
00046
00047 extern std::vector<Uc_function *> functions;
00048
00049 std::vector<char *> include_dirs;
00050
00051
00052
00053
00054
00055 int main
00056 (
00057 int argc,
00058 char **argv
00059 )
00060 {
00061 extern int yyparse();
00062 extern FILE *yyin;
00063 char *src;
00064 char outbuf[256];
00065 char *outname = 0;
00066 static char *optstring = "o:I:s";
00067 extern int optind, opterr, optopt;
00068 extern char *optarg;
00069 Uc_function::Intrinsic_type ty = Uc_function::bg;
00070 opterr = 0;
00071 int optchr;
00072 while ((optchr = getopt(argc, argv, optstring)) != -1)
00073 switch (optchr)
00074 {
00075 case 'o':
00076 outname = optarg;
00077 break;
00078 case 'I':
00079 include_dirs.push_back(optarg);
00080 break;
00081 case 's':
00082 ty = Uc_function::si;
00083 break;
00084 }
00085 if (optind < argc)
00086 {
00087 src = argv[optind];
00088 yyin = fopen(argv[optind], "r");
00089 if (!outname)
00090 {
00091 outname = strncpy(outbuf, src, sizeof(outbuf) - 5);
00092 outbuf[sizeof(outbuf) - 5] = 0;
00093 char *dot = strrchr(outname, '.');
00094 if (!dot)
00095 dot = outname + strlen(outname);
00096 strcpy(dot, ".uco");
00097 }
00098 }
00099 else
00100 {
00101 src = "<stdin>";
00102 yyin = stdin;
00103 if (!outname)
00104 outname = strcpy(outbuf, "a.ucout");
00105 }
00106 Uc_location::set_cur(src, 0);
00107
00108 Uc_function::set_intrinsics(ty);
00109 #if 0
00110
00111 int tok;
00112 extern int yylex();
00113 while ((tok = yylex()) != EOF)
00114 printf("%d\n", tok);
00115 #endif
00116 yyparse();
00117 int errs = Uc_location::get_num_errors();
00118 if (errs > 0)
00119 return errs;
00120
00121 std::ofstream out(outname, ios::binary|ios::out);
00122 for (std::vector<Uc_function *>::iterator it = functions.begin();
00123 it != functions.end(); it++)
00124 {
00125 Uc_function *fun = *it;
00126 fun->gen(out);
00127 }
00128 return Uc_location::get_num_errors();
00129 }
00130
00131
00132
00133
00134 void yyerror
00135 (
00136 char *s
00137 )
00138 {
00139 Uc_location::yyerror(s);
00140 }