2016-09-17 22:02:16 +00:00
|
|
|
#include "mcg.h"
|
2016-09-17 20:21:47 +00:00
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
bool tracing(char k)
|
|
|
|
{
|
|
|
|
switch (k)
|
|
|
|
{
|
2016-09-24 20:46:08 +00:00
|
|
|
case 0: return true;
|
2016-09-22 21:19:29 +00:00
|
|
|
case 'E': return false;
|
|
|
|
case '0': return false;
|
2016-09-24 20:46:08 +00:00
|
|
|
case '1': return false;
|
2016-09-26 22:19:45 +00:00
|
|
|
case '2': return false;
|
|
|
|
case 'I': return true;
|
2016-09-21 22:15:48 +00:00
|
|
|
default: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tracef(char k, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (tracing(k))
|
|
|
|
{
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-23 23:04:00 +00:00
|
|
|
static bool find_procedures_cb(struct symbol* symbol, void* user)
|
|
|
|
{
|
|
|
|
if (symbol->proc)
|
|
|
|
procedure_compile(symbol->proc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-17 22:02:16 +00:00
|
|
|
int main(int argc, char* argv[])
|
2016-09-17 20:21:47 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
symbol_init();
|
|
|
|
|
2016-09-17 20:21:47 +00:00
|
|
|
if (!EM_open(argv[1]))
|
|
|
|
fatal("Couldn't open input file: %s", EM_error);
|
|
|
|
|
2016-09-23 23:04:00 +00:00
|
|
|
/* Reads in the EM, outputs the data sections, parses any code and
|
|
|
|
* generates IR trees. */
|
|
|
|
|
2016-09-17 22:02:16 +00:00
|
|
|
parse_em();
|
2016-09-17 20:21:47 +00:00
|
|
|
|
2016-09-23 23:04:00 +00:00
|
|
|
/* For every procedure, go ahead and do the compilation proper. We do this
|
|
|
|
* now so that we know that all the data has been read correctly and our
|
|
|
|
* symbol table is complete (we may need to refer to it). */
|
|
|
|
|
|
|
|
symbol_walk(find_procedures_cb, NULL);
|
|
|
|
|
2016-09-17 20:21:47 +00:00
|
|
|
EM_close();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|