aboutsummaryrefslogtreecommitdiffstats
path: root/utils/Burg/main.c
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-17 23:03:30 +0000
committerChris Lattner <sabre@nondot.org>2002-09-17 23:03:30 +0000
commit633a5b1aacb135957b20e5f11e779ea23ccb9619 (patch)
tree3ddd35119d12cadf13e31f3cae9f67b057332440 /utils/Burg/main.c
parent24b70926d5750dacadc3252f8fbcc964b369e2af (diff)
downloadexternal_llvm-633a5b1aacb135957b20e5f11e779ea23ccb9619.zip
external_llvm-633a5b1aacb135957b20e5f11e779ea23ccb9619.tar.gz
external_llvm-633a5b1aacb135957b20e5f11e779ea23ccb9619.tar.bz2
Initial checkin of burg files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3785 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/Burg/main.c')
-rw-r--r--utils/Burg/main.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/utils/Burg/main.c b/utils/Burg/main.c
new file mode 100644
index 0000000..5c13698
--- /dev/null
+++ b/utils/Burg/main.c
@@ -0,0 +1,182 @@
+char rcsid_main[] = "$Id$";
+
+#include <math.h>
+#include <stdio.h>
+#include "b.h"
+#include "fe.h"
+
+int debugTables = 0;
+static int simpleTables = 0;
+static int internals = 0;
+static int diagnostics = 0;
+
+static char *inFileName;
+static char *outFileName;
+
+static char version[] = "BURG, Version 1.0";
+
+extern void main ARGS((int argc, char **argv));
+
+void
+main(argc, argv) int argc; char **argv;
+{
+ int i;
+ extern int atoi ARGS((char *));
+
+ for (i = 1; argv[i]; i++) {
+ char **needStr = 0;
+ int *needInt = 0;
+
+ if (argv[i][0] == '-') {
+ switch (argv[i][1]) {
+ case 'V':
+ fprintf(stderr, "%s\n", version);
+ break;
+ case 'p':
+ needStr = &prefix;
+ break;
+ case 'o':
+ needStr = &outFileName;
+ break;
+ case 'I':
+ internals = 1;
+ break;
+ case 'T':
+ simpleTables = 1;
+ break;
+ case '=':
+#ifdef NOLEX
+ fprintf(stderr, "'%s' was not compiled to support lexicographic ordering\n", argv[0]);
+#else
+ lexical = 1;
+#endif /* NOLEX */
+ break;
+ case 'O':
+ needInt = &principleCost;
+ break;
+ case 'c':
+ needInt = &prevent_divergence;
+ break;
+ case 'e':
+ needInt = &exceptionTolerance;
+ break;
+ case 'd':
+ diagnostics = 1;
+ break;
+ case 'S':
+ speedflag = 1;
+ break;
+ case 't':
+ trimflag = 1;
+ break;
+ case 'G':
+ grammarflag = 1;
+ break;
+ default:
+ fprintf(stderr, "Bad option (%s)\n", argv[i]);
+ exit(1);
+ }
+ } else {
+ if (inFileName) {
+ fprintf(stderr, "Unexpected Filename (%s) after (%s)\n", argv[i], inFileName);
+ exit(1);
+ }
+ inFileName = argv[i];
+ }
+ if (needInt || needStr) {
+ char *v;
+ char *opt = argv[i];
+
+ if (argv[i][2]) {
+ v = &argv[i][2];
+ } else {
+ v = argv[++i];
+ if (!v) {
+ fprintf(stderr, "Expection argument after %s\n", opt);
+ exit(1);
+ }
+ }
+ if (needInt) {
+ *needInt = atoi(v);
+ } else if (needStr) {
+ *needStr = v;
+ }
+ }
+ }
+
+ if (inFileName) {
+ if(freopen(inFileName, "r", stdin)==NULL) {
+ fprintf(stderr, "Failed opening (%s)", inFileName);
+ exit(1);
+ }
+ }
+
+ if (outFileName) {
+ if ((outfile = fopen(outFileName, "w")) == NULL) {
+ fprintf(stderr, "Failed opening (%s)", outFileName);
+ exit(1);
+ }
+ } else {
+ outfile = stdout;
+ }
+
+
+ yyparse();
+
+ if (!rules) {
+ fprintf(stderr, "ERROR: No rules present\n");
+ exit(1);
+ }
+
+ findChainRules();
+ findAllPairs();
+ doGrammarNts();
+ build();
+
+ debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
+ debug(debugTables, printf("---final set of states ---\n"));
+ debug(debugTables, dumpMapping(globalMap));
+
+
+ startBurm();
+ makeNts();
+ if (simpleTables) {
+ makeSimple();
+ } else {
+ makePlanks();
+ }
+
+ startOptional();
+ makeLabel();
+ makeKids();
+
+ if (internals) {
+ makeChild();
+ makeOpLabel();
+ makeStateLabel();
+ }
+ endOptional();
+
+ makeOperatorVector();
+ makeNonterminals();
+ if (internals) {
+ makeOperators();
+ makeStringArray();
+ makeRuleDescArray();
+ makeCostArray();
+ makeDeltaCostArray();
+ makeStateStringArray();
+ makeNonterminalArray();
+ /*
+ makeLHSmap();
+ */
+ }
+ makeClosureArray();
+
+ if (diagnostics) {
+ reportDiagnostics();
+ }
+
+ yypurge();
+ exit(0);
+}