summaryrefslogtreecommitdiff
path: root/src/compilo.c
blob: 12a6f050926846094b5521393c4f725d75e3bc71 (plain)
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include "config.h"
#include "exceptions.h"
#include "meta.h"
#include "parser.h"
#include "hash.h"
#include "assembler.h"

typedef void (*sighandler_t) (int);

void invite(void)
{
	fprintf(stderr, _("Assembler v1.0\n\n"));
}

void usage(void)
{
	fprintf(stderr, _("Usage: compilo program.asm objet.out\n"));
	exit(0);
}

void init_all(void)
{
	fprintf(stderr, _(" o Initialising the meta engine...   "));

	if (meta_init()) {
		exception(1, _("Meta parser init failed."));
	}

	fprintf(stderr, _(" Done!\n o Meta language loading...          "));

	if (meta_load("instructions.txt")) {
		exception(1, _("Meta language loading failed."));
	}

	fprintf(stderr, _(" Done!\n o Initialising the assembler core..."));

	if (assembler_init()) {
		exception(1, _("Assembler core init failed."));
	}

	fprintf(stderr, _(" Done!\n"));
}

void flush_all(void)
{
	assembler_flush();
	meta_flush();
}

void segfaulthand(int i)
{
	exception(1, _("Signal received: segfault"));
}

int main(int argc, char **argv)
{
	invite();

#ifndef DEBUG
	signal(SIGSEGV, segfaulthand);
#endif
	if (argc != 3)
		usage();

	fprintf(stderr, _("\nPerforming initialisation...\n\n"));
	init_all();

	assemble_file(argv[1], argv[2]);

	fprintf(stderr, _("\nPerforming shutdown...\n\n"));
	flush_all();
	
	signal(SIGSEGV, NULL);

	fprintf(stderr, _("Exitting, bye!\n"));
	return 0;
}