-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
101 lines (89 loc) · 1.94 KB
/
Copy pathmain.c
File metadata and controls
101 lines (89 loc) · 1.94 KB
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
/**
* (C) Copyright 2010. All rights reserved. Sotiris Karavarsamis and Panagiotis Tigas.
* Computer Science Department
* University of Ioannina
*
* icode generation main code
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "lexer.h"
#include "syntax.h"
#include "st.h"
#include "ic.h"
#include "cg.h"
#include "cg_x86.h"
void help() {
char str[] = "Ciscal compiler.\n\
Usage: ciscal [options] ...\n\
Options:\n -f filename \t\t \
Compiles filename. \n -i \t\t\t \
Output icode to icode.txt \n \
-a [x86 or metasim] \t \
Output assembly to assembly.s. \
Default metasim.";
fprintf(stdout, "%s\n", str);
}
char *assembly = NULL;
int main(int argc, char *argv[]) {
int index;
int final = 0;
int icode = 0;
char *filename = NULL;
int c;
opterr = 0;
while ((c = getopt(argc, argv, "f:ia::h")) != -1) {
switch (c) {
case 'h':
help();
return 0;
case 'f':
filename = optarg;
in = fopen(filename, "r");
continue;
case 'i':
icode = 1;
continue;
case 'a':
final = 1;
assembly = optarg;
continue;
case '?':
if (optopt == 'a') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
fprintf (stderr, "Setting to default assembly [metasym].\n");
assembly = strdup("metasim");
final = 1;
continue;
}
return 1;
default:
abort();
}
}
/* drop the extra arguments */
for (index = optind; index < argc; index++){
printf ("Non-option argument %s\n", argv[index]);
return 0;
}
/* start parsing */
parse();
/* print the icode quads */
if (icode) {
printquads();
}
/* print the final code */
if (final) {
if (!strcmp(assembly, "x86")) {
generate_final_x86();
print_machine_code_x86();
} else {
generate_final();
print_machine_code();
}
}
return 0;
}