]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ast.cpp
Rewrite constant folder in C++
[xonotic/gmqcc.git] / ast.cpp
diff --git a/ast.cpp b/ast.cpp
index 366d2a9ecd750069a9aaa0ff9824cbdb69df3af9..4768e6e5bb9db83be59b9415cb73733d66d829b9 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -5,7 +5,8 @@
 
 #include "gmqcc.h"
 #include "ast.h"
 
 #include "gmqcc.h"
 #include "ast.h"
-#include "parser.h"
+#include "fold.h"
+//#include "parser.h"
 
 #define ast_instantiate(T, ctx, destroyfn)                          \
     T* self = (T*)mem_a(sizeof(T));                                 \
 
 #define ast_instantiate(T, ctx, destroyfn)                          \
     T* self = (T*)mem_a(sizeof(T));                                 \
@@ -2560,7 +2561,7 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     ir_block *ontrue_endblock = nullptr;
     ir_block *onfalse_endblock = nullptr;
     ir_block *merge = nullptr;
     ir_block *ontrue_endblock = nullptr;
     ir_block *onfalse_endblock = nullptr;
     ir_block *merge = nullptr;
-    int       fold  = 0;
+    int folded = 0;
 
     /* We don't output any value, thus also don't care about r/lvalue */
     (void)out;
 
     /* We don't output any value, thus also don't care about r/lvalue */
     (void)out;
@@ -2580,8 +2581,8 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
     cond = func->curblock;
 
     /* try constant folding away the condition */
     cond = func->curblock;
 
     /* try constant folding away the condition */
-    if ((fold = fold_cond_ifthen(condval, func, self)) != -1)
-        return fold;
+    if ((folded = fold::cond_ifthen(condval, func, self)) != -1)
+        return folded;
 
     if (self->on_true) {
         /* create on-true block */
 
     if (self->on_true) {
         /* create on-true block */
@@ -2663,7 +2664,7 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
     ir_block *ontrue, *ontrue_out = nullptr;
     ir_block *onfalse, *onfalse_out = nullptr;
     ir_block *merge;
     ir_block *ontrue, *ontrue_out = nullptr;
     ir_block *onfalse, *onfalse_out = nullptr;
     ir_block *merge;
-    int       fold  = 0;
+    int folded = 0;
 
     /* Ternary can never create an lvalue... */
     if (lvalue)
 
     /* Ternary can never create an lvalue... */
     if (lvalue)
@@ -2689,8 +2690,8 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
     cond_out = func->curblock;
 
     /* try constant folding away the condition */
     cond_out = func->curblock;
 
     /* try constant folding away the condition */
-    if ((fold = fold_cond_ternary(condval, func, self)) != -1)
-        return fold;
+    if ((folded = fold::cond_ternary(condval, func, self)) != -1)
+        return folded;
 
     /* create on-true block */
     ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_T"));
 
     /* create on-true block */
     ontrue = ir_function_create_block(ast_ctx(self), func->ir_func, ast_function_label(func, "tern_T"));