mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
Preparing to generate code from the IR - code_write should return a bool, and take a filename rather than use program.dat hardcoded
This commit is contained in:
parent
ac890513e4
commit
8bfbe4d619
4 changed files with 44 additions and 12 deletions
2
asm.c
2
asm.c
|
@ -65,7 +65,7 @@ void asm_init(const char *file, FILE **fp) {
|
|||
}
|
||||
void asm_close(FILE *fp) {
|
||||
fclose(fp);
|
||||
code_write();
|
||||
code_write("program.dat");
|
||||
}
|
||||
void asm_clear() {
|
||||
size_t i = 0;
|
||||
|
|
28
code.c
28
code.c
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* 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
|
||||
|
@ -144,7 +144,7 @@ void code_test() {
|
|||
code_statements_add(s3);
|
||||
}
|
||||
|
||||
void code_write() {
|
||||
bool code_write(const char *filename) {
|
||||
prog_header code_header;
|
||||
FILE *fp = NULL;
|
||||
size_t it = 2;
|
||||
|
@ -184,14 +184,21 @@ void code_write() {
|
|||
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 );
|
||||
|
@ -254,4 +261,5 @@ void code_write() {
|
|||
mem_d(code_globals_data);
|
||||
mem_d(code_chars_data);
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
|
2
gmqcc.h
2
gmqcc.h
|
@ -533,7 +533,7 @@ VECTOR_PROT(char, code_chars );
|
|||
* code_write -- writes out the compiled file
|
||||
* code_init -- prepares the code file
|
||||
*/
|
||||
void code_write ();
|
||||
bool code_write (const char *filename);
|
||||
void code_init ();
|
||||
|
||||
/*===================================================================*/
|
||||
|
|
24
ir.c
24
ir.c
|
@ -1655,6 +1655,30 @@ on_error:
|
|||
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...
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue