20 int main(
int argc,
char **argv)
22 int stack_size = 1000;
23 int array_size = 1000;
24 int mode =
COMPILE | ASSEMBLE | LINK;
25 char *output_file = NULL;
26 char *input_file = NULL;
29 int ret =
my_getopt(argc, argv, &stack_size, &array_size, &output_file, &input_file, &mode);
32 if (
get_in(mode, input_file, &in) < 0)
34 if (
get_as_file(mode, &out, output_file, input_file) < 0)
36 compile(in, out, stack_size, array_size);
37 if (in != stdin && in != NULL)
41 if (!(mode & ASSEMBLE))
44 if (
get_as(mode, output_file, input_file, &as_file) == NULL && !(mode & PIPE_OUT))
46 char *obj_file = NULL;
47 if (
get_obj(mode, output_file, input_file, &obj_file) == NULL)
49 if (!(mode & PIPE_OUT))
63 if (output_file == NULL)
64 snprintf(buf, 256,
"ld %s", obj_file);
66 snprintf(buf, 256,
"ld %s -o %s", obj_file, output_file);
69 ret =
remove(obj_file);
int assemble(int mode, const char *as_file, const char *obj_file)
Wrapper around assembling the assembly code.
char * get_as(int mode, const char *name, const char *original, char **ret)
Gets the name of the assembly code file.
#define COMPILE
Macros for determining state of the program.
int my_getopt(int argc, char **argv, int *stack_size, int *array_size, char **output_file, char **input_file, int *mode)
Custom getopt function.
char * get_obj(int mode, const char *name, const char *original, char **ret)
Gets the name of the assembled file.
int get_in(int mode, const char *input_file, FILE **in)
Gets the source code file pointer and deals with IO errors.
int get_as_file(int mode, FILE **out, const char *name, const char *input_name)
Gets the file pointer to the assembly code file.
Header for extern functions.
int close_as_file(int mode, FILE *f)
Closes the file pointer to the assembly source file.
int compile(FILE *in, FILE *out, int stack_size, int array_size)
compiler function
int main(int argc, char **argv)
main