int brainfuck_make_asm(FILE *_output, FILE *_input, output_t _type, size_t stacksize) { output = _output; input = _input; type = _type; assert(type != NONE); assert(stacksize > 0); /* Create header */ session_start(); define_put(); define_get(); define_start(stacksize); /* Transpile brainfuck to asm */ memset(stack, 0, TRANSPILER_STACK_SIZE); ptr = 0; int queued_op = 0; int num_queued = 0; int op; while ((op = fgetc(input)) != EOF) { if (strchr(".,+-><[]", op) == NULL) continue; if (queued_op != 0) { if (queued_op == op) { ++num_queued; continue; } handle_queued_ops(queued_op, num_queued); queued_op = 0; num_queued = 0; } switch (op) { case '.': op_put(); break; case ',': op_get(); break; case '+': /* FALLTHROUGH */ case '-': /* FALLTHROUGH */ case '>': /* FALLTHROUGH */ case '<': queued_op = op; num_queued = 1; break; case '[': op_tag(stack, ptr); break; case ']': op_jmp(stack, ptr); break; } } handle_queued_ops(queued_op, num_queued); /* Create clean exit */ define_exit(); return 0; }
void parsing(char *argv, t_map *map, t_param *param) { int fd; map->nb_line = 0; map->nb_col = 0; if ((fd = open(argv, O_RDONLY)) < 0) ft_exit(); map = count_line_col(fd, map); map->tab = (int **)malloc(sizeof(int *) * (map->nb_line)); map->tab[map->nb_line] = NULL; close(fd); fd = open(argv, O_RDONLY); map = split_tab(map, fd); define_start(param, map); check_border(map); close(fd); }