void write_assembly(Syntax *syntax){ FILE *out = fopen("out.s", "wb"); write_header(out); write_syntax(out, syntax); write_footer(out); }
void write_asm(void) { entity *list = NULL; tree *current = NULL; write_header(); write_startup(); write_declarations(); write_externs(); /* write out all the source */ list = state.list; while (list != NULL) { current = list->node; switch(current->tag) { case node_decl: /* do nothing */ break; case node_func: write_procedure(current, 1); break; case node_proc: write_procedure(current, 0); break; default: assert(0); } list = list->next; } write_footer(); }
void t_log::write_report(const string &report, const string &func_name, t_log_class log_class, t_log_severity severity) { if (log_disabled) return; write_header(func_name, log_class, severity); write_raw(report); write_endl(); write_footer(); }
/* plot parsed expression and write it to postscript file */ void write_ps(FILE * out, parsed_expr parsed, char *expr, Limits * lim) { plot_init(parsed.length, lim); write_header(out, expr); plot(out, parsed); write_box(out); write_footer(out); free(stack); }
/* Coordination of matlab data capture. */ static bool capture_matlab_data(FILE *stream) { uint64_t frames_written; time_t local_offset = offset_matlab_times ? local_time_offset() : 0; return TEST_OK(READ_ITEM(stream, timestamp_header)) && TEST_OK_(timestamp_header.offset < timestamp_header.block_size, "Invalid response from server") && write_header((uint32_t) sample_count) && capture_data(stream, &frames_written) && write_footer((uint32_t) frames_written, local_offset) && IF_(frames_written != sample_count, /* For an incomplete capture, probably an interrupted continuous * capture, we need to rewrite the header with the correct * capture count. */ TEST_IO_(fseek(output_file, 0, SEEK_SET), "Cannot update matlab file, file not seekable") && write_header((uint32_t) frames_written)); }
static int dump_irep(mrb_state *mrb, mrb_irep *irep, int debug_info, uint8_t **bin, size_t *bin_size) { int result = MRB_DUMP_GENERAL_FAILURE; size_t section_irep_size; size_t section_lineno_size = 0; uint8_t *cur = NULL; mrb_bool const debug_info_defined = is_debug_info_defined(irep); if (mrb == NULL) { *bin = NULL; return MRB_DUMP_GENERAL_FAILURE; } section_irep_size = sizeof(struct rite_section_irep_header); section_irep_size += get_irep_record_size(mrb, irep); /* DEBUG section size */ if (debug_info) { if (debug_info_defined) { mrb_sym *filenames; section_lineno_size += sizeof(struct rite_section_debug_header); // filename table filenames = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym *) + 1); // filename table size section_lineno_size += sizeof(uint16_t); section_lineno_size += get_filename_table_size(mrb, irep, &filenames, NULL); mrb_free(mrb, filenames); section_lineno_size += get_debug_record_size(mrb, irep); } else { section_lineno_size += sizeof(struct rite_section_lineno_header); section_lineno_size += get_lineno_record_size(mrb, irep); } } *bin_size = sizeof(struct rite_binary_header) + section_irep_size + section_lineno_size + sizeof(struct rite_binary_footer); cur = *bin = (uint8_t*)mrb_malloc(mrb, *bin_size); if (cur == NULL) { goto error_exit; } cur += sizeof(struct rite_binary_header); result = write_section_irep(mrb, irep, cur); if (result != MRB_DUMP_OK) { goto error_exit; } cur += section_irep_size; /* write DEBUG section */ if (debug_info) { if (debug_info_defined) { result = write_section_debug(mrb, irep, cur); } else { result = write_section_lineno(mrb, irep, cur); } if (result != MRB_DUMP_OK) { goto error_exit; } cur += section_lineno_size; } write_footer(mrb, cur); write_rite_binary_header(mrb, *bin_size, *bin); error_exit: if (result != MRB_DUMP_OK) { mrb_free(mrb, *bin); *bin = NULL; } return result; }
int group_recorder::commit(TIMESTAMP t1){ // short-circuit if strict & error if((TS_ERROR == tape_status) && strict){ gl_error("group_recorder::commit(): the object has error'ed and is halting the simulation"); /* TROUBLESHOOT In strict mode, any group_recorder logic errors or input errors will halt the simulation. */ return 0; } // short-circuit if not open if(TS_OPEN != tape_status){ return 1; } // if periodic interval, check for write if(write_interval > 0){ if(interval_write){ if(0 == read_line()){ gl_error("group_recorder::commit(): error when reading the values"); return 0; } if(0 == write_line(t1)){ gl_error("group_recorder::commit(): error when writing the values to the file"); return 0; } last_write = t1; interval_write = false; } } // if every change, // * compare to last values // * if different, write if(-1 == write_interval){ if(0 == read_line()){ if(0 == read_line()){ gl_error("group_recorder::commit(): error when reading the values"); return 0; } if(0 != strcmp(line_buffer, prev_line_buffer) ){ if(0 == write_line(t1)){ gl_error("group_recorder::commit(): error when writing the values to the file"); return 0; } } } } // if periodic flush, check for flush if(flush_interval > 0){ if(last_flush + flush_interval <= t1){ last_flush = t1; } } else if(flush_interval < 0){ if( ((write_count + 1) % (-flush_interval)) == 0 ){ flush_line(); } } // if 0, no flush // check if write limit if(limit > 0 && write_count >= limit){ // write footer write_footer(); fclose(rec_file); rec_file = 0; free(line_buffer); line_buffer = 0; line_size = 0; tape_status = TS_DONE; } // check if strict & error ... a second time in case the periodic behavior failed. if((TS_ERROR == tape_status) && strict){ gl_error("group_recorder::commit(): the object has error'ed and is halting the simulation"); /* TROUBLESHOOT In strict mode, any group_recorder logic errors or input errors will halt the simulation. */ return 0; } return 1; }
decision_proceduret::resultt smt2_dect::dec_solve() { // we write the problem into a file smt2_temp_filet smt2_temp_file; // copy from string buffer into file smt2_temp_file.temp_out << stringstream.str(); // this finishes up and closes the SMT2 file write_footer(smt2_temp_file.temp_out); smt2_temp_file.temp_out.close(); smt2_temp_file.temp_result_filename= get_temporary_file("smt2_dec_result_", ""); std::string command; switch(solver) { case solvert::BOOLECTOR: command = "boolector --smt2 " + smt2_temp_file.temp_out_filename + " -m > " + smt2_temp_file.temp_result_filename; break; case solvert::CVC3: command = "cvc3 +model -lang smtlib -output-lang smtlib " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::CVC4: // The flags --bitblast=eager --bv-div-zero-const help but only // work for pure bit-vector formulas. command = "cvc4 -L smt2 " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::MATHSAT: // The options below were recommended by Alberto Griggio // on 10 July 2013 command = "mathsat -input=smt2" " -preprocessor.toplevel_propagation=true" " -preprocessor.simplification=7" " -dpll.branching_random_frequency=0.01" " -dpll.branching_random_invalidate_phase_cache=true" " -dpll.restart_strategy=3" " -dpll.glucose_var_activity=true" " -dpll.glucose_learnt_minimization=true" " -theory.bv.eager=true" " -theory.bv.bit_blast_mode=1" " -theory.bv.delay_propagated_eqs=true" " -theory.fp.mode=1" " -theory.fp.bit_blast_mode=2" " -theory.arr.mode=1" " < "+smt2_temp_file.temp_out_filename + " > "+smt2_temp_file.temp_result_filename; break; case solvert::OPENSMT: command = "opensmt " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::YICES: // command = "yices -smt -e " // Calling convention for older versions command = "yices-smt2 " // Calling for 2.2.1 + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; case solvert::Z3: command = "z3 -smt2 " + smt2_temp_file.temp_out_filename + " > " + smt2_temp_file.temp_result_filename; break; default: assert(false); } #if defined(__linux__) || defined(__APPLE__) command+=" 2>&1"; #endif int res=system(command.c_str()); if(res<0) { error() << "error running SMT2 solver" << eom; return decision_proceduret::resultt::D_ERROR; } std::ifstream in(smt2_temp_file.temp_result_filename.c_str()); return read_result(in); }
static int dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size) { int result = MRB_DUMP_GENERAL_FAILURE; size_t malloc_size; size_t section_irep_size; size_t section_lineno_size = 0, section_lv_size = 0; uint8_t *cur = NULL; mrb_bool const debug_info_defined = is_debug_info_defined(irep), lv_defined = is_lv_defined(irep); mrb_sym *lv_syms = NULL; uint32_t lv_syms_len = 0; mrb_sym *filenames = NULL; uint16_t filenames_len = 0; if (mrb == NULL) { *bin = NULL; return MRB_DUMP_GENERAL_FAILURE; } section_irep_size = sizeof(struct rite_section_irep_header); section_irep_size += get_irep_record_size(mrb, irep); /* DEBUG section size */ if (flags & DUMP_DEBUG_INFO) { if (debug_info_defined) { section_lineno_size += sizeof(struct rite_section_debug_header); /* filename table */ filenames = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) + 1); /* filename table size */ section_lineno_size += sizeof(uint16_t); section_lineno_size += get_filename_table_size(mrb, irep, &filenames, &filenames_len); section_lineno_size += get_debug_record_size(mrb, irep); } else { section_lineno_size += sizeof(struct rite_section_lineno_header); section_lineno_size += get_lineno_record_size(mrb, irep); } } if (lv_defined) { section_lv_size += sizeof(struct rite_section_lv_header); create_lv_sym_table(mrb, irep, &lv_syms, &lv_syms_len); section_lv_size += get_lv_section_size(mrb, irep, lv_syms, lv_syms_len); } malloc_size = sizeof(struct rite_binary_header) + section_irep_size + section_lineno_size + section_lv_size + sizeof(struct rite_binary_footer); cur = *bin = (uint8_t*)mrb_malloc(mrb, malloc_size); cur += sizeof(struct rite_binary_header); result = write_section_irep(mrb, irep, cur, §ion_irep_size, flags); if (result != MRB_DUMP_OK) { goto error_exit; } cur += section_irep_size; *bin_size = sizeof(struct rite_binary_header) + section_irep_size + section_lineno_size + section_lv_size + sizeof(struct rite_binary_footer); /* write DEBUG section */ if (flags & DUMP_DEBUG_INFO) { if (debug_info_defined) { result = write_section_debug(mrb, irep, cur, filenames, filenames_len); } else { result = write_section_lineno(mrb, irep, cur); } if (result != MRB_DUMP_OK) { goto error_exit; } cur += section_lineno_size; } if (lv_defined) { result = write_section_lv(mrb, irep, cur, lv_syms, lv_syms_len); if (result != MRB_DUMP_OK) { goto error_exit; } cur += section_lv_size; } write_footer(mrb, cur); write_rite_binary_header(mrb, *bin_size, *bin, flags); error_exit: if (result != MRB_DUMP_OK) { mrb_free(mrb, *bin); *bin = NULL; } if (lv_syms) { mrb_free(mrb, lv_syms); } if (filenames) { mrb_free(mrb, filenames); } return result; }
void VrmlExporter::end() { write_footer(); file_.close(); }
int main(int argc, char **argv) { int c; bzero(CONFIG_PATH, PATH_MAX); while ((c = getopt(argc,argv, "vf:")) != EOF) { switch (c) { case 'f': snprintf(CONFIG_PATH, PATH_MAX, "%s", optarg); break; case 'v': verbose = 1; break; case '?': fprintf(stderr,"Invalid argument\n"); exit(1); } } read_config(); #ifdef HAVE_LIBMAGIC load_magic(); #endif load_regexes(); pcre_callout = pcre_callout_spider; umask(077); compile_regexes(); if (Encrypt) { // do we have a password? if (!strlen(Password)) { fprintf(stderr, "No password supplied\n"); exit(1); } // prep the log array startlog = (struct logarray *)malloc(sizeof(struct logarray)); if (startlog == NULL) { fprintf(stderr, "Malloc: %s\n", strerror(errno)); exit(1); } bzero(startlog -> entry, LOG_MAX); currlog = startlog; // prep our keying material generate_iv(); generate_key(); } if (Log2File && !LogStdout) { // get our filehandle open if (AppendLog) { if (CustomLogPath[0]) { logfp = fopen(CustomLogPath, "a+"); } else { logfp = fopen(LogPath, "a+"); } } else { if (CustomLogPath[0]) { logfp = fopen(CustomLogPath, "w"); } else { logfp = fopen(LogPath, "w"); } } if (logfp == NULL) { fprintf(stderr, "unable to open %s:%s\n", LogPath, strerror(errno)); exit(1); } } if (LogSyslog) { (void)openlog("spider", LOG_PID|LOG_NDELAY, LOG_FAC); } // normally, this would run as a child process // we'd hold the child PID in pid_t worker // when the Stop Spider button is clicked, // we'll send a TERM signal to the child process // run_spider(START_PATH); if (LogFooter[0]) { write_footer(); } if (Encrypt) { // write out the encrypted log if (!spider_encrypt()) { fprintf(stderr, "failure to write encrypted log!\n"); exit(1); } } if (logfp) { fclose(logfp); } if (WhenDone == EXIT_WHEN_DONE) { if (verbose) { fprintf(stderr, "Normal exit.\n"); } exit(0); } if (WhenDone == RESTORE_WHEN_DONE) { // GTK fru-fru } if (WhenDone == VIEWLOG_WHEN_DONE) { // launch the log viewer } exit(0); }
~CalJob() { write_footer(file_); }
decision_proceduret::resultt smt1_dect::dec_solve() { // SMT1 is really not incremental assert(!dec_solve_was_called); dec_solve_was_called=true; // this closes the SMT benchmark write_footer(); temp_out.close(); temp_result_filename= get_temporary_file("smt1_dec_result_", ""); std::string command; switch(solver) { case BOOLECTOR: // -rwl0 disables rewriting, which makes things slower, // but in return values for arrays appear // command = "boolector -rwl0 --smt " // Removed as not necessarily needed on newer versions command = "boolector --smt " + temp_out_filename + " --model --output " + temp_result_filename; break; case CVC3: command = "cvc3 +model -lang smtlib -output-lang smtlib " + temp_out_filename + " > " + temp_result_filename; break; case CVC4: command = "cvc4 -L smt1 " + temp_out_filename + " > " + temp_result_filename; break; case MATHSAT: command = "mathsat -model -input=smt" " < "+temp_out_filename + " > "+temp_result_filename; break; case OPENSMT: command = "opensmt " + temp_out_filename + " > " + temp_result_filename; break; case YICES: // command = "yices -smt -e " // Calling convention for older versions command = "yices-smt --full-model " // Calling for 2.2.1 + temp_out_filename + " > " + temp_result_filename; break; case Z3: command = "z3 -smt " + temp_out_filename + " > " + temp_result_filename; break; default: assert(false); } #if defined(__linux__) || defined(__APPLE__) command+=" 2>&1"; #endif int res=system(command.c_str()); if(res<0) { error() << "error running SMT1 solver" << eom; return decision_proceduret::D_ERROR; } std::ifstream in(temp_result_filename.c_str()); switch(solver) { case BOOLECTOR: return read_result_boolector(in); case CVC3: return read_result_cvc3(in); case CVC4: error() << "no support for CVC4 with SMT1, use SMT2 instead" << eom; return decision_proceduret::D_ERROR; case MATHSAT: return read_result_mathsat(in); case OPENSMT: return read_result_opensmt(in); case YICES: return read_result_yices(in); case Z3: return read_result_z3(in); case GENERIC: default: error() << "Generic solver can't solve" << eom; return decision_proceduret::D_ERROR; } }