#define intrin_ctx(I) parser_ctx((I)->parser)
static GMQCC_INLINE ast_function *intrin_value(intrin_t *intrin, ast_value **out, const char *name, qcint_t vtype) {
- ast_value *value = NULL;
- ast_function *func = NULL;
+ ast_value *value = nullptr;
+ ast_function *func = nullptr;
char buffer[1024];
char stype [1024];
/*
* since some intrinsics depend on each other there is the possibility
* that an intrinsic will fail to get a 'depended' function that a
- * builtin needs, causing some dependency in the chain to have a NULL
+ * builtin needs, causing some dependency in the chain to have a nullptr
* function. This will cause a segmentation fault at code generation,
* even though an error was raised. To contiue to allow it (instead
* of stopping compilation right away). We need to return from the
*/
static ast_expression *intrin_func_self(intrin_t *intrin, const char *name, const char *from);
static ast_expression *intrin_nullfunc(intrin_t *intrin) {
- ast_value *value = NULL;
- ast_function *func = intrin_value(intrin, &value, NULL, TYPE_VOID);
+ ast_value *value = nullptr;
+ ast_function *func = intrin_value(intrin, &value, nullptr, TYPE_VOID);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return !(isnan(x) || isinf(x));
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "isfinite", TYPE_FLOAT);
ast_call *callisnan = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "isnan", "isfinite"));
)
);
- vec_push(func->blocks, block);
+ func->blocks.push_back(block);
intrin_reg(intrin, value, func);
return (ast_expression*)value;;
* return (x != 0.0) && (x + x == x);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "isinf", TYPE_FLOAT);
);
value->expression.params.push_back(x);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
* return (x != local);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *local = ast_value_new(intrin_ctx(intrin), "local", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
);
value->expression.params.push_back(arg1);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
* return isfinite(x);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *callisfinite = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "isfinite", "isnormal"));
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return (x < 0);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "signbit", TYPE_FLOAT);
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return log(x + sqrt((x * x) - 1));
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "acosh"));
ast_call *callsqrt = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "sqrt", "acosh"));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return log(x + sqrt((x * x) + 1));
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "asinh"));
ast_call *callsqrt = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "sqrt", "asinh"));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return 0.5 * log((1 + x) / (1 - x))
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "atanh"));
ast_block *body = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return sum;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *sum = ast_value_new(intrin_ctx(intrin), "sum", TYPE_FLOAT);
ast_value *acc = ast_value_new(intrin_ctx(intrin), "acc", TYPE_FLOAT);
(ast_expression*)fold_constgen_float(intrin->fold, 200.0f, false)
),
false,
- NULL,
+ nullptr,
false,
/* ++i; */
(ast_expression*)ast_binstore_new(
)
);
- vec_push(func->blocks, body);
-
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return pow(2, x);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", "exp2"));
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, body);
-
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return exp(x) - 1;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *callexp = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "exp", "expm1"));
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return accumulate;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_function *func = intrin_value(intrin, &value, "pow", TYPE_FLOAT);
/* prepare some calls for later */
intrin_ctx(intrin),
(ast_expression*)intrin->fold->imm_float[1]
),
- NULL
+ nullptr
)
);
intrin_ctx(intrin),
(ast_expression*)base
),
- NULL
+ nullptr
)
);
(ast_expression*)callpow1
)
),
- NULL
+ nullptr
)
);
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)expgt1,
- NULL
+ nullptr
)
);
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
/* init */
- NULL,
+ nullptr,
/* pre condition */
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
/* pre not */
false,
/* post condition */
- NULL,
+ nullptr,
/* post not */
false,
/* increment expression */
- NULL,
+ nullptr,
/* code block */
(ast_expression*)whileblock
)
);
/* } */
- vec_push(func->blocks, body);
-
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* return a - b * sign * floor(sign * div);
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *call = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "floor", "mod"));
ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT);
ast_value *b = ast_value_new(intrin_ctx(intrin), "b", TYPE_FLOAT);
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
* return x < 0 ? -x : x;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "fabs", TYPE_FLOAT);
value->expression.params.push_back(arg1);
- vec_push(func->blocks, body);
-
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
* return eps;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *eps = ast_value_new(intrin_ctx(intrin), "eps", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "epsilon", TYPE_FLOAT);
body->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
- NULL,
+ nullptr,
+ nullptr,
false,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
(ast_expression*)intrin->fold->imm_float[1]
),
false,
- NULL,
+ nullptr,
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
* return x / x;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "nan", TYPE_FLOAT);
ast_block *block = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, block);
+ func->blocks.push_back(block);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
* return x / y;
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *y = ast_value_new(intrin_ctx(intrin), "y", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "inf", TYPE_FLOAT);
)
);
- vec_push(func->blocks, block);
+ func->blocks.push_back(block);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
* }
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_value *power = ast_value_new(intrin_ctx(intrin), "power", TYPE_FLOAT);
ast_value *base = ast_value_new(intrin_ctx(intrin), "base", TYPE_FLOAT);
ast_value *whole = ast_value_new(intrin_ctx(intrin), "whole", TYPE_FLOAT);
intrin_func_self(intrin, "__builtin_nan", "ln")
)
),
- NULL
+ nullptr
)
);
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)((i) ? blt1 : plt1),
- NULL
+ nullptr
)
);
}
whileloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
+ nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
(ast_expression*)newbase2
),
false,
- NULL,
+ nullptr,
false,
- NULL,
+ nullptr,
(ast_expression*)nestwhile
)
);
forloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
+ nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
(ast_expression*)base
),
false,
- NULL,
+ nullptr,
false,
- NULL,
+ nullptr,
(ast_expression*)whileloop
)
);
false,
0
),
- NULL
+ nullptr
)
);
block->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
- /* for(; 1; ) ?? (can this be NULL too?) */
+ nullptr,
+ /* for(; 1; ) ?? (can this be nullptr too?) */
(ast_expression*)intrin->fold->imm_float[1],
false,
- NULL,
+ nullptr,
false,
- NULL,
+ nullptr,
(ast_expression*)forloop
)
);
)
);
- vec_push(func->blocks, block);
+ func->blocks.push_back(block);
intrin_reg(intrin, value, func);
-
return (ast_expression*)value;
}
static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, float base) {
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *callln = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "__builtin_ln", name));
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
* float [shift] (float a, float b) {
* return floor(a [instr] pow(2, b));
*/
- ast_value *value = NULL;
+ ast_value *value = nullptr;
ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", name));
ast_call *callfloor = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "floor", name));
ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT);
)
);
- vec_push(func->blocks, body);
+ func->blocks.push_back(body);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
ast_expression *intrin_fold(intrin_t *intrin, ast_value *value, ast_expression **exprs) {
if (!value || !value->name)
- return NULL;
+ return nullptr;
for (auto &it : intrin->intrinsics) {
if (!strcmp(value->name, it.name))
return (vec_size(exprs) != it.args)
- ? NULL
+ ? nullptr
: fold_intrin(intrin->fold, value->name + 10, exprs);
}
- return NULL;
+ return nullptr;
}
static GMQCC_INLINE ast_expression *intrin_func_try(intrin_t *intrin, size_t offset, const char *compare) {
if (from) {
intrin_error(intrin, "need function `%s', compiler depends on it for `__builtin_%s'", name, from);
- return intrin_func_self(intrin, "#nullfunc", NULL);
+ return intrin_func_self(intrin, "#nullfunc", nullptr);
}
- return NULL;
+ return nullptr;
}
ast_expression *intrin_func(intrin_t *intrin, const char *name) {
- return intrin_func_self(intrin, name, NULL);
+ return intrin_func_self(intrin, name, nullptr);
}