23 char *basename = strdup(fn);
28 for (
int i = 0; basename[i] !=
'\0'; i++) {
29 if (basename[i] ==
'.')
33 basename[lastDot] =
'\0';
35 size_t nameLen = strlen(basename) + strlen(logType) + (size_t)8;
36 char *outfn = calloc(nameLen,
sizeof(
char));
40 snprintf(outfn, nameLen,
"%s_%s.log", basename, logType);
48 printf(
"ACSE %s compiler, (c) 2008-24 Politecnico di Milano\n",
TARGET_NAME);
53 puts(
"ACSE toolchain version 2.0.2");
60 printf(
"usage: %s [options] input\n\n", name);
62 puts(
" -o ASMFILE Name the output ASMFILE (default output.asm)");
63 puts(
" -v, --version Display version number");
64 puts(
" -h, --help Displays available options");
67int main(
int argc,
char *argv[])
75 static const struct option options[] = {
76 {
"help", no_argument, NULL,
'h'},
77 {
"version", no_argument, NULL,
'v'},
80 char *outputFn =
"output.asm";
82 while ((ch = getopt_long(argc, argv,
"ho:v", options, NULL)) != -1) {
104 }
else if (argc > 1) {
105 emitError(nullFileLocation,
"cannot assemble more than one file");
117 fprintf(stderr,
"Parsing the input program\n");
118 fprintf(stderr,
" -> Reading input from \"%s\"\n", argv[0]);
125 logFp = fopen(logFn,
"w");
127 fprintf(stderr,
" -> Writing the output of parsing to \"%s\"\n", logFn);
135 fprintf(stderr,
"Lowering of pseudo-instructions to machine instructions.\n");
140 fprintf(stderr,
"Performing register allocation.\n");
142 logFp = fopen(logFn,
"w");
144 fprintf(stderr,
" -> Writing the control flow graph to \"%s\"\n", logFn);
157 logFp = fopen(logFn,
"w");
159 fprintf(stderr,
" -> Writing the register bindings to \"%s\"\n", logFn);
168 fprintf(stderr,
"Writing the assembly file.\n");
169 fprintf(stderr,
" -> Output file name: \"%s\"\n", outputFn);
170 fprintf(stderr,
" -> Code segment size: %d instructions\n",
172 fprintf(stderr,
" -> Data segment size: %d elements\n",
178 emitError(nullFileLocation,
"could not write output file");
186 fprintf(stderr,
"Finished.\n");
int main(int argc, char *argv[])
void usage(const char *name)
char * getLogFileName(const char *logType, const char *fn)
Control Flow Graph generation and related analyses.
bool writeAssembly(t_program *program, const char *fn)
void cfgComputeLiveness(t_cfg *graph)
void deleteCFG(t_cfg *graph)
void cfgDump(t_cfg *graph, FILE *fout, bool verbose)
t_cfg * programToCFG(t_program *program)
void emitError(t_fileLocation loc, const char *fmt,...)
void fatalError(const char *format,...)
int listLength(t_listNode *list)
t_program * parseProgram(char *fn)
t_listNode * instructions
List of instructions.
t_listNode * labels
List of all labels.
t_listNode * symbols
Symbol table.
void programDump(t_program *program, FILE *fout)
void deleteProgram(t_program *program)
t_regAllocator * newRegAllocator(t_program *program)
void regallocDump(t_regAllocator *RA, FILE *fout)
void deleteRegAllocator(t_regAllocator *RA)
void regallocRun(t_regAllocator *regalloc)
void doTargetSpecificTransformations(t_program *program)
#define TARGET_NAME
Name of the target architecture.
Header file associated to parser.y.
Program object definition and management.
Structure encapsulating the state of the register allocator.
Register allocation pass.
Generation of the output assembly program.
Properties of the target machine.