Fix the horror of the startup code; now uses getopt and stuff and the debug

flags can be set as an option.
This commit is contained in:
David Given 2016-10-04 22:36:01 +02:00
parent ac063a6f54
commit 249855ed23

View file

@ -1,22 +1,14 @@
#include "mcg.h" #include "mcg.h"
#include <unistd.h>
static const char* tracechars = NULL;
bool tracing(char k) bool tracing(char k)
{ {
switch (k) if (!tracechars)
{ return false;
case 0: return true;
case 'S': return true; return index(tracechars, k);
case 'E': return false;
case 'G': return true;
case '0': return false;
case '1': return false;
case '2': return false;
case '3': return false;
case '4': return false;
case '5': return false;
case 'I': return true;
default: return true;
}
} }
void tracef(char k, const char* fmt, ...) void tracef(char k, const char* fmt, ...)
@ -38,12 +30,32 @@ static bool find_procedures_cb(struct symbol* symbol, void* user)
return false; return false;
} }
int main(int argc, char* argv[]) int main(int argc, char* const argv[])
{ {
program_name = argv[0];
opterr = 1;
for (;;)
{
int c = getopt(argc, argv, "-d:");
if (c == -1)
break;
switch (c)
{
case 'd':
tracechars = optarg;
break;
case 1:
fatal("unexpected argument '%s'", optarg);
}
}
symbol_init(); symbol_init();
if (!EM_open(argv[1])) if (!EM_open(NULL))
fatal("Couldn't open input file: %s", EM_error); fatal("couldn't open stdin: %s", EM_error);
/* Reads in the EM, outputs the data sections, parses any code and /* Reads in the EM, outputs the data sections, parses any code and
* generates IR trees. */ * generates IR trees. */