1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/**
** Ucmain.cc - Usecode Compiler
**
** Written: 12/30/2000 - JSF
**/
/*
Copyright (C) 2000 The Exult Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <fstream>
#include <unistd.h>
#include <stdio.h>
#include <string>
#include <vector>
#include "ucloc.h"
#include "ucfun.h"
#ifndef ALPHA_LINUX_CXX
# include <iosfwd>
#endif
using std::strcpy;
using std::strrchr;
using std::strlen;
using std::ios;
// THIS is what the parser produces.
extern std::vector<Uc_function *> functions;
std::vector<char *> include_dirs; // -I directories.
/*
* MAIN.
*/
int main
(
int argc,
char **argv
)
{
extern int yyparse();
extern FILE *yyin;
char *src;
char outbuf[256];
char *outname = 0;
static char *optstring = "o:I:s";
extern int optind, opterr, optopt;
extern char *optarg;
Uc_function::Intrinsic_type ty = Uc_function::bg;
opterr = 0; // Don't let getopt() print errs.
int optchr;
while ((optchr = getopt(argc, argv, optstring)) != -1)
switch (optchr)
{
case 'o': // Output to write.
outname = optarg;
break;
case 'I': // Include dir.
include_dirs.push_back(optarg);
break;
case 's':
ty = Uc_function::si;
break;
}
if (optind < argc) // Filename?
{
src = argv[optind];
yyin = fopen(argv[optind], "r");
if (!outname) // No -o option?
{ // Set up output name.
outname = strncpy(outbuf, src, sizeof(outbuf) - 5);
outbuf[sizeof(outbuf) - 5] = 0;
char *dot = strrchr(outname, '.');
if (!dot)
dot = outname + strlen(outname);
strcpy(dot, ".uco");
}
}
else
{
src = "<stdin>";
yyin = stdin;
if (!outname)
outname = strcpy(outbuf, "a.ucout");
}
Uc_location::set_cur(src, 0);
// For now, use black gate.
Uc_function::set_intrinsics(ty);
#if 0
//++++TESTING
int tok;
extern int yylex();
while ((tok = yylex()) != EOF)
printf("%d\n", tok);
#endif
yyparse();
int errs = Uc_location::get_num_errors();
if (errs > 0) // Check for errors.
return errs;
// Open output.
std::ofstream out(outname, ios::binary|ios::out);
for (std::vector<Uc_function *>::iterator it = functions.begin();
it != functions.end(); it++)
{
Uc_function *fun = *it;
fun->gen(out); // Generate function.
}
return Uc_location::get_num_errors();
}
/*
* Report error.
*/
void yyerror
(
char *s
)
{
Uc_location::yyerror(s);
}
|