]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
More jump removal
authorWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 18 Dec 2012 12:40:59 +0000 (13:40 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Tue, 18 Dec 2012 13:03:20 +0000 (14:03 +0100)
code.c
gmqcc.h
ir.c

diff --git a/code.c b/code.c
index 964797f8793e57191122f905a6c994c484d18f4c..3c418b1653125786a47f44355a32ae23e4da79b5 100644 (file)
--- a/code.c
+++ b/code.c
@@ -39,6 +39,12 @@ void code_push_statement(prog_section_statement *stmt, int linenum)
     vec_push(code_linenums,   linenum);
 }
 
+void code_pop_statement()
+{
+    vec_pop(code_statements);
+    vec_pop(code_linenums);
+}
+
 void code_init() {
     prog_section_function  empty_function  = {0,0,0,0,0,0,0,{0}};
     prog_section_statement empty_statement = {0,{0},{0},{0}};
diff --git a/gmqcc.h b/gmqcc.h
index b95bac4fc2268b2ca3f9db035831b2c0f204702a..df123c6c42713c733446ee21c1eb8c1773cf4409 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -573,6 +573,7 @@ qcint    code_alloc_field (size_t qcsize);
 
 /* this function is used to keep statements and linenumbers together */
 void     code_push_statement(prog_section_statement *stmt, int linenum);
+void     code_pop_statement();
 
 /*
  * A shallow copy of a lex_file to remember where which ast node
diff --git a/ir.c b/ir.c
index 6bc766c7dd7a47e0af8f2525341e488b1be2fe18..2375d55368c40d0d52c5e194f70f39a1439622b2 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -2743,8 +2743,7 @@ tailcall:
                 ontrue = tmp;
             }
             stidx = vec_size(code_statements);
-            if (stmt.o2.s1 != 1)
-                code_push_statement(&stmt, instr->context.line);
+            code_push_statement(&stmt, instr->context.line);
             /* on false we jump, so add ontrue-path */
             if (!gen_blocks_recursive(func, ontrue))
                 return false;
@@ -2754,6 +2753,12 @@ tailcall:
             if (onfalse->generated) {
                 /* fixup the jump address */
                 code_statements[stidx].o2.s1 = (onfalse->code_start) - (stidx);
+                if (code_statements[stidx].o2.s1 == 1) {
+                    code_statements[stidx] = code_statements[stidx+1];
+                    if (code_statements[stidx].o1.s1 < 0)
+                        code_statements[stidx].o1.s1++;
+                    code_pop_statement();
+                }
                 stmt.opcode = vec_last(code_statements).opcode;
                 if (stmt.opcode == INSTR_GOTO ||
                     stmt.opcode == INSTR_IF ||
@@ -2773,6 +2778,12 @@ tailcall:
                     code_push_statement(&stmt, instr->context.line);
                 return true;
             }
+            else if (code_statements[stidx].o2.s1 == 1) {
+                code_statements[stidx] = code_statements[stidx+1];
+                if (code_statements[stidx].o1.s1 < 0)
+                    code_statements[stidx].o1.s1++;
+                code_pop_statement();
+            }
             /* if not, generate now */
             block = onfalse;
             goto tailcall;