void codegen_pic(FILE *file, ImdtCode *program) { printf("Starting code generation\n"); output = file; bytecode = program; printf("Generating preamble\n"); write_preamble(); printf("Generating global variables\n"); write_globals(); printf("Generating function variables and code\n"); write_functions(); printf("Code generation complete\n"); }
void execute_command(const char* msg) { printf("EXEC %s\n", msg); if(strcmp("refresh_sensors", msg) == 0) { write_preamble(); serial_write("r"); write_preamble(); serial_write("t"); } else if(strcmp("refresh_temp", msg) == 0) { write_preamble(); serial_write("t"); } else if(strcmp("refresh_light", msg) == 0) { write_preamble(); serial_write("r"); } else if(strcmp("lamp_off", msg) == 0) { write_preamble(); serial_write("l"); } else if(strcmp("lamp_on", msg) == 0) { write_preamble(); serial_write("L"); } else if(strcmp("enable_pir", msg) == 0) { write_preamble(); serial_write("P"); } else if(strcmp("disable_pir", msg) == 0) { write_preamble(); serial_write("p"); } }
/* Write all the code fragments to a newly-chosen temporary file and * store the name of the file in code->path. */ static void write_code_file(struct code_state *code) { /* mkstemp will fill this in with the actual unique path name. */ char path_template[] = "/tmp/code_XXXXXX"; int code_fd = mkstemp(path_template); if (code_fd < 0) die_perror("error making temp output file for code: mkstemp"); assert(code->path == NULL); code->path = strdup(path_template); code->file = fdopen(code_fd, "w"); if (code->file == NULL) die_perror("error opening temp output file for code: fdopen"); write_preamble(code); write_all_fragments(code); if (fclose(code->file) != 0) die_perror("error closing temp output file for code: fclose"); code->file = NULL; }