/*
* Copyright (C) 2012
- * Dale Weiler
+ * Dale Weiler, Wolfgang Bumiller
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
code_statements_add(s3);
}
-void code_write() {
+bool code_write(const char *filename) {
prog_header code_header;
FILE *fp = NULL;
size_t it = 2;
util_endianswap(code_functions_data, code_functions_elements, sizeof(prog_section_function));
util_endianswap(code_globals_data, code_globals_elements, sizeof(int32_t));
- fp = fopen("program.dat", "wb");
- fwrite(&code_header, 1, sizeof(prog_header), fp);
- fwrite(code_statements_data, 1, sizeof(prog_section_statement)*code_statements_elements, fp);
- fwrite(code_defs_data, 1, sizeof(prog_section_def) *code_defs_elements, fp);
- fwrite(code_fields_data, 1, sizeof(prog_section_field) *code_fields_elements, fp);
- fwrite(code_functions_data, 1, sizeof(prog_section_function) *code_functions_elements, fp);
- fwrite(code_globals_data, 1, sizeof(int32_t) *code_globals_elements, fp);
- fwrite(code_chars_data, 1, 1 *code_chars_elements, fp);
+ fp = fopen(filename, "wb");
+ if (!fp)
+ return false;
+
+ if (1 != fwrite(&code_header, sizeof(prog_header), 1, fp) ||
+ 1 != fwrite(code_statements_data, sizeof(prog_section_statement)*code_statements_elements, 1, fp) ||
+ 1 != fwrite(code_defs_data, sizeof(prog_section_def) *code_defs_elements, 1, fp) ||
+ 1 != fwrite(code_fields_data, sizeof(prog_section_field) *code_fields_elements, 1, fp) ||
+ 1 != fwrite(code_functions_data, sizeof(prog_section_function) *code_functions_elements, 1, fp) ||
+ 1 != fwrite(code_globals_data, sizeof(int32_t) *code_globals_elements, 1, fp) ||
+ 1 != fwrite(code_chars_data, 1 *code_chars_elements, 1, fp))
+ {
+ fclose(fp);
+ return false;
+ }
util_debug("GEN","HEADER:\n");
util_debug("GEN"," version: = %d\n", code_header.version );
mem_d(code_globals_data);
mem_d(code_chars_data);
fclose(fp);
+ return true;
}
return false;
}
+/***********************************************************************
+ *IR Code-Generation
+ *
+ * Since the IR has the convention of putting 'write' operands
+ * at the beginning, we have to rotate the operands of instructions
+ * properly in order to generate valid QCVM code.
+ *
+ * Having destinations at a fixed position is more convenient. In QC
+ * this is *mostly* OPC, but FTE adds at least 2 instructions which
+ * read from from OPA, and store to OPB rather than OPC. Which is
+ * partially the reason why the implementation of these instructions
+ * in darkplaces has been delayed for so long.
+ *
+ * Breaking conventions is annoying...
+ */
+
+bool ir_builder_generate(ir_builder *self, const char *filename)
+{
+ code_init();
+
+ code_write(filename);
+ return false;
+}
+
/***********************************************************************
*IR DEBUG Dump functions...
*/