X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=intrin.cpp;h=b37b50f1fc3d38ffdf6192349012771dd9f1bd17;hp=cc6250be7cd1194986ba31d3001dca24204337ac;hb=3714a507c2395763a654d6a6fcec14fe387dd63d;hpb=90b5a6538a10f60d08ee3059b8f70e4e076dc30d diff --git a/intrin.cpp b/intrin.cpp index cc6250b..b37b50f 100644 --- a/intrin.cpp +++ b/intrin.cpp @@ -17,10 +17,10 @@ ast_function *intrin::value(ast_value **out, const char *name, qc_type vtype) { util_snprintf(buffer, sizeof(buffer), "__builtin_%s", name); util_snprintf(stype, sizeof(stype), "<%s>", type_name[vtype]); - value = ast_value_new(ctx(), buffer, TYPE_FUNCTION); + value = new ast_value(ctx(), buffer, TYPE_FUNCTION); value->m_intrinsic = true; - value->m_next = (ast_expression*)ast_value_new(ctx(), stype, vtype); - func = ast_function_new(ctx(), buffer, value); + value->m_next = new ast_value(ctx(), stype, vtype); + func = ast_function::make(ctx(), buffer, value); value->m_flags |= AST_FLAG_ERASEABLE; *out = value; @@ -29,7 +29,7 @@ ast_function *intrin::value(ast_value **out, const char *name, qc_type vtype) { void intrin::reg(ast_value *const value, ast_function *const func) { m_parser->functions.push_back(func); - m_parser->globals.push_back((ast_expression*)value); + m_parser->globals.push_back(value); } #define QC_POW_EPSILON 0.00001f @@ -38,7 +38,7 @@ ast_expression *intrin::nullfunc() { ast_value *val = nullptr; ast_function *func = value(&val, nullptr, TYPE_VOID); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::isfinite_() { @@ -48,33 +48,33 @@ ast_expression *intrin::isfinite_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); ast_function *func = value(&val, "isfinite", TYPE_FLOAT); - ast_call *callisnan = ast_call_new(ctx(), func_self("isnan", "isfinite")); - ast_call *callisinf = ast_call_new(ctx(), func_self("isinf", "isfinite")); - ast_block *block = ast_block_new(ctx()); + ast_call *callisnan = ast_call::make(ctx(), func_self("isnan", "isfinite")); + ast_call *callisinf = ast_call::make(ctx(), func_self("isinf", "isfinite")); + ast_block *block = new ast_block(ctx()); /* float x; */ - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* = isnan(x); */ - callisnan->m_params.push_back((ast_expression*)x); + callisnan->m_params.push_back(x); /* = isinf(x); */ - callisinf->m_params.push_back((ast_expression*)x); + callisinf->m_params.push_back(x); /* return (! || ); */ block->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_unary_new( + ast_unary::make( ctx(), INSTR_NOT_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_OR, - (ast_expression*)callisnan, - (ast_expression*)callisinf + callisnan, + callisinf ) ) ) @@ -83,7 +83,7 @@ ast_expression *intrin::isfinite_() { func->m_blocks.emplace_back(block); reg(val, func); - return (ast_expression*)val;; + return val;; } ast_expression *intrin::isinf_() { @@ -93,43 +93,43 @@ ast_expression *intrin::isinf_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "isinf", TYPE_FLOAT); body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_AND, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_NE_F, - (ast_expression*)x, - (ast_expression*)m_fold->m_imm_float[0] + x, + m_fold->m_imm_float[0] ), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_EQ_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)x, - (ast_expression*)x + x, + x ), - (ast_expression*)x + x ) ) ) ); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::isnan_() { @@ -142,39 +142,39 @@ ast_expression *intrin::isnan_() { * } */ ast_value *val = nullptr; - ast_value *arg1 = ast_value_new(ctx(), "x",TYPE_FLOAT); - ast_value *local = ast_value_new(ctx(), "local", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *arg1 = new ast_value(ctx(), "x",TYPE_FLOAT); + ast_value *local = new ast_value(ctx(), "local", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "isnan", TYPE_FLOAT); body->m_locals.push_back(local); body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)local, - (ast_expression*)arg1 + local, + arg1 ) ); body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_NE_F, - (ast_expression*)arg1, - (ast_expression*)local + arg1, + local ) ) ); - val->m_type_params.push_back(arg1); + val->m_type_params.emplace_back(arg1); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::isnormal_() { @@ -184,25 +184,25 @@ ast_expression *intrin::isnormal_() { * } */ ast_value *val = nullptr; - ast_call *callisfinite = ast_call_new(ctx(), func_self("isfinite", "isnormal")); - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *callisfinite = ast_call::make(ctx(), func_self("isfinite", "isnormal")); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "isnormal", TYPE_FLOAT); - val->m_type_params.push_back(x); - callisfinite->m_params.push_back((ast_expression*)x); + val->m_type_params.emplace_back(x); + callisfinite->m_params.push_back(x); /* return */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)callisfinite + callisfinite ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::signbit_() { @@ -212,33 +212,33 @@ ast_expression *intrin::signbit_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "signbit", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* return (x < 0); */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_ternary_new( + new ast_ternary( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)x, - (ast_expression*)m_fold->m_imm_float[0] + x, + m_fold->m_imm_float[0] ), - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)m_fold->m_imm_float[0] + m_fold->m_imm_float[1], + m_fold->m_imm_float[0] ) ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::acosh_() { @@ -248,50 +248,50 @@ ast_expression *intrin::acosh_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_call *calllog = ast_call_new(ctx(), func_self("log", "acosh")); - ast_call *callsqrt = ast_call_new(ctx(), func_self("sqrt", "acosh")); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_call *calllog = ast_call::make(ctx(), func_self("log", "acosh")); + ast_call *callsqrt = ast_call::make(ctx(), func_self("sqrt", "acosh")); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "acosh", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* = sqrt((x * x) - 1); */ callsqrt->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_SUB_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)x, - (ast_expression*)x + x, + x ), - (ast_expression*)m_fold->m_imm_float[1] + m_fold->m_imm_float[1] ) ); /* = log(x + ); */ calllog->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)x, - (ast_expression*)callsqrt + x, + callsqrt ) ); /* return ; */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)calllog + calllog ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::asinh_() { @@ -301,50 +301,50 @@ ast_expression *intrin::asinh_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_call *calllog = ast_call_new(ctx(), func_self("log", "asinh")); - ast_call *callsqrt = ast_call_new(ctx(), func_self("sqrt", "asinh")); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_call *calllog = ast_call::make(ctx(), func_self("log", "asinh")); + ast_call *callsqrt = ast_call::make(ctx(), func_self("sqrt", "asinh")); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "asinh", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* = sqrt((x * x) + 1); */ callsqrt->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)x, - (ast_expression*)x + x, + x ), - (ast_expression*)m_fold->m_imm_float[1] + m_fold->m_imm_float[1] ) ); /* = log(x + ); */ calllog->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)x, - (ast_expression*)callsqrt + x, + callsqrt ) ); /* return ; */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)calllog + calllog ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::atanh_() { @@ -354,46 +354,46 @@ ast_expression *intrin::atanh_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_call *calllog = ast_call_new(ctx(), func_self("log", "atanh")); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_call *calllog = ast_call::make(ctx(), func_self("log", "atanh")); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "atanh", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* = log((1 + x) / (1 - x)); */ calllog->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)x + m_fold->m_imm_float[1], + x ), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_SUB_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)x + m_fold->m_imm_float[1], + x ) ) ); /* return 0.5 * ; */ body->m_exprs.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)m_fold->constgen_float(0.5, false), - (ast_expression*)calllog + m_fold->constgen_float(0.5, false), + calllog ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::exp_() { @@ -409,14 +409,14 @@ ast_expression *intrin::exp_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_value *sum = ast_value_new(ctx(), "sum", TYPE_FLOAT); - ast_value *acc = ast_value_new(ctx(), "acc", TYPE_FLOAT); - ast_value *i = ast_value_new(ctx(), "i", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_value *sum = new ast_value(ctx(), "sum", TYPE_FLOAT); + ast_value *acc = new ast_value(ctx(), "acc", TYPE_FLOAT); + ast_value *i = new ast_value(ctx(), "i", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "exp", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); body->m_locals.push_back(sum); body->m_locals.push_back(acc); @@ -424,21 +424,21 @@ ast_expression *intrin::exp_() { /* sum = 1.0; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)sum, - (ast_expression*)m_fold->m_imm_float[1] + sum, + m_fold->m_imm_float[1] ) ); /* acc = 1.0; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)acc, - (ast_expression*)m_fold->m_imm_float[1] + acc, + m_fold->m_imm_float[1] ) ); @@ -447,49 +447,49 @@ ast_expression *intrin::exp_() { * sum += (acc *= x / i); */ body->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), /* i = 1; */ - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)i, - (ast_expression*)m_fold->m_imm_float[1] + i, + m_fold->m_imm_float[1] ), /* i < 200; */ - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)i, - (ast_expression*)m_fold->constgen_float(200.0f, false) + i, + m_fold->constgen_float(200.0f, false) ), false, nullptr, false, /* ++i; */ - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_ADD_F, - (ast_expression*)i, - (ast_expression*)m_fold->m_imm_float[1] + i, + m_fold->m_imm_float[1] ), /* sum += (acc *= (x / i)) */ - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_ADD_F, - (ast_expression*)sum, - (ast_expression*)ast_binstore_new( + sum, + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)acc, - (ast_expression*)ast_binary_new( + acc, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)x, - (ast_expression*)i + x, + i ) ) ) @@ -498,15 +498,15 @@ ast_expression *intrin::exp_() { /* return sum; */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)sum + sum ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::exp2_() { @@ -516,27 +516,27 @@ ast_expression *intrin::exp2_() { * } */ ast_value *val = nullptr; - ast_call *callpow = ast_call_new(ctx(), func_self("pow", "exp2")); - ast_value *arg1 = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *callpow = ast_call::make(ctx(), func_self("pow", "exp2")); + ast_value *arg1 = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "exp2", TYPE_FLOAT); - val->m_type_params.push_back(arg1); + val->m_type_params.emplace_back(arg1); - callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]); - callpow->m_params.push_back((ast_expression*)arg1); + callpow->m_params.push_back(m_fold->m_imm_float[3]); + callpow->m_params.push_back(arg1); /* return */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)callpow + callpow ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::expm1_() { @@ -546,32 +546,32 @@ ast_expression *intrin::expm1_() { * } */ ast_value *val = nullptr; - ast_call *callexp = ast_call_new(ctx(), func_self("exp", "expm1")); - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *callexp = ast_call::make(ctx(), func_self("exp", "expm1")); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "expm1", TYPE_FLOAT); - val->m_type_params.push_back(x); + val->m_type_params.emplace_back(x); /* = exp(x); */ - callexp->m_params.push_back((ast_expression*)x); + callexp->m_params.push_back(x); /* return - 1; */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_SUB_F, - (ast_expression*)callexp, - (ast_expression*)m_fold->m_imm_float[1] + callexp, + m_fold->m_imm_float[1] ) ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::pow_() { @@ -620,23 +620,23 @@ ast_expression *intrin::pow_() { ast_function *func = value(&val, "pow", TYPE_FLOAT); /* prepare some calls for later */ - ast_call *callpow1 = ast_call_new(ctx(), (ast_expression*)val); /* for pow(base, -exp) */ - ast_call *callpow2 = ast_call_new(ctx(), (ast_expression*)val); /* for pow(vase, exp / 2) */ - ast_call *callsqrt1 = ast_call_new(ctx(), func_self("sqrt", "pow")); /* for sqrt(base) */ - ast_call *callsqrt2 = ast_call_new(ctx(), func_self("sqrt", "pow")); /* for sqrt(square) */ - ast_call *callfabs = ast_call_new(ctx(), func_self("fabs", "pow")); /* for fabs(mid - exp) */ + ast_call *callpow1 = ast_call::make(ctx(), val); /* for pow(base, -exp) */ + ast_call *callpow2 = ast_call::make(ctx(), val); /* for pow(vase, exp / 2) */ + ast_call *callsqrt1 = ast_call::make(ctx(), func_self("sqrt", "pow")); /* for sqrt(base) */ + ast_call *callsqrt2 = ast_call::make(ctx(), func_self("sqrt", "pow")); /* for sqrt(square) */ + ast_call *callfabs = ast_call::make(ctx(), func_self("fabs", "pow")); /* for fabs(mid - exp) */ /* prepare some blocks for later */ - ast_block *expgt1 = ast_block_new(ctx()); - ast_block *midltexp = ast_block_new(ctx()); - ast_block *midltexpelse = ast_block_new(ctx()); - ast_block *whileblock = ast_block_new(ctx()); + ast_block *expgt1 = new ast_block(ctx()); + ast_block *midltexp = new ast_block(ctx()); + ast_block *midltexpelse = new ast_block(ctx()); + ast_block *whileblock = new ast_block(ctx()); /* float pow(float base, float exp) */ - ast_value *base = ast_value_new(ctx(), "base", TYPE_FLOAT); - ast_value *exp = ast_value_new(ctx(), "exp", TYPE_FLOAT); + ast_value *base = new ast_value(ctx(), "base", TYPE_FLOAT); + ast_value *exp = new ast_value(ctx(), "exp", TYPE_FLOAT); /* { */ - ast_block *body = ast_block_new(ctx()); + ast_block *body = new ast_block(ctx()); /* * float result; @@ -646,12 +646,12 @@ ast_expression *intrin::pow_() { * float accumulate; * float mid; */ - ast_value *result = ast_value_new(ctx(), "result", TYPE_FLOAT); - ast_value *low = ast_value_new(ctx(), "low", TYPE_FLOAT); - ast_value *high = ast_value_new(ctx(), "high", TYPE_FLOAT); - ast_value *square = ast_value_new(ctx(), "square", TYPE_FLOAT); - ast_value *accumulate = ast_value_new(ctx(), "accumulate", TYPE_FLOAT); - ast_value *mid = ast_value_new(ctx(), "mid", TYPE_FLOAT); + ast_value *result = new ast_value(ctx(), "result", TYPE_FLOAT); + ast_value *low = new ast_value(ctx(), "low", TYPE_FLOAT); + ast_value *high = new ast_value(ctx(), "high", TYPE_FLOAT); + ast_value *square = new ast_value(ctx(), "square", TYPE_FLOAT); + ast_value *accumulate = new ast_value(ctx(), "accumulate", TYPE_FLOAT); + ast_value *mid = new ast_value(ctx(), "mid", TYPE_FLOAT); body->m_locals.push_back(result); body->m_locals.push_back(low); body->m_locals.push_back(high); @@ -659,25 +659,25 @@ ast_expression *intrin::pow_() { body->m_locals.push_back(accumulate); body->m_locals.push_back(mid); - val->m_type_params.push_back(base); - val->m_type_params.push_back(exp); + val->m_type_params.emplace_back(base); + val->m_type_params.emplace_back(exp); /* * if (exp == 0.0) * return 1; */ body->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_EQ_F, - (ast_expression*)exp, - (ast_expression*)m_fold->m_imm_float[0] + exp, + m_fold->m_imm_float[0] ), - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)m_fold->m_imm_float[1] + m_fold->m_imm_float[1] ), nullptr ) @@ -688,29 +688,29 @@ ast_expression *intrin::pow_() { * return base; */ body->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_EQ_F, - (ast_expression*)exp, - (ast_expression*)m_fold->m_imm_float[1] + exp, + m_fold->m_imm_float[1] ), - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)base + base ), nullptr ) ); /* = pow(base, -exp) */ - callpow1->m_params.push_back((ast_expression*)base); + callpow1->m_params.push_back(base); callpow1->m_params.push_back( - (ast_expression*)ast_unary_new( + ast_unary::make( ctx(), VINSTR_NEG_F, - (ast_expression*)exp + exp ) ); @@ -719,21 +719,21 @@ ast_expression *intrin::pow_() { * return 1.0 / ; */ body->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)exp, - (ast_expression*)m_fold->m_imm_float[0] + exp, + m_fold->m_imm_float[0] ), - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)callpow1 + m_fold->m_imm_float[1], + callpow1 ) ), nullptr @@ -741,13 +741,13 @@ ast_expression *intrin::pow_() { ); /* = pow(base, exp / 2) */ - callpow2->m_params.push_back((ast_expression*)base); + callpow2->m_params.push_back(base); callpow2->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)exp, - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + exp, + m_fold->m_imm_float[3] /* 2.0f */ ) ); @@ -758,21 +758,21 @@ ast_expression *intrin::pow_() { * } */ expgt1->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)result, - (ast_expression*)callpow2 + result, + callpow2 ) ); expgt1->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)result, - (ast_expression*)result + result, + result ) ) ); @@ -783,15 +783,15 @@ ast_expression *intrin::pow_() { * } */ body->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_GE, - (ast_expression*)exp, - (ast_expression*)m_fold->m_imm_float[1] + exp, + m_fold->m_imm_float[1] ), - (ast_expression*)expgt1, + expgt1, nullptr ) ); @@ -799,7 +799,7 @@ ast_expression *intrin::pow_() { /* * = sqrt(base) */ - callsqrt1->m_params.push_back((ast_expression*)base); + callsqrt1->m_params.push_back(base); /* * low = 0.0f; @@ -809,48 +809,48 @@ ast_expression *intrin::pow_() { * mid = high / 2.0f; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new(ctx(), + new ast_store(ctx(), INSTR_STORE_F, - (ast_expression*)low, - (ast_expression*)m_fold->m_imm_float[0] + low, + m_fold->m_imm_float[0] ) ); body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)high, - (ast_expression*)m_fold->m_imm_float[1] + high, + m_fold->m_imm_float[1] ) ); body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)square, - (ast_expression*)callsqrt1 + square, + callsqrt1 ) ); body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)accumulate, - (ast_expression*)square + accumulate, + square ) ); body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)mid, - (ast_expression*)ast_binary_new( + mid, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)high, - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + high, + m_fold->m_imm_float[3] /* 2.0f */ ) ) ); @@ -862,20 +862,20 @@ ast_expression *intrin::pow_() { * } */ midltexp->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)low, - (ast_expression*)mid + low, + mid ) ); midltexp->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)accumulate, - (ast_expression*)square + accumulate, + square ) ); @@ -886,24 +886,24 @@ ast_expression *intrin::pow_() { * } */ midltexpelse->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)high, - (ast_expression*)mid + high, + mid ) ); midltexpelse->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)accumulate, - (ast_expression*)ast_binary_new( + accumulate, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)square + m_fold->m_imm_float[1], + square ) ) ); @@ -911,7 +911,7 @@ ast_expression *intrin::pow_() { /* * = sqrt(square) */ - callsqrt2->m_params.push_back((ast_expression*)square); + callsqrt2->m_params.push_back(square); /* * = { @@ -925,41 +925,41 @@ ast_expression *intrin::pow_() { * } */ whileblock->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)square, - (ast_expression*)callsqrt2 + square, + callsqrt2 ) ); whileblock->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)mid, - (ast_expression*)exp + mid, + exp ), - (ast_expression*)midltexp, - (ast_expression*)midltexpelse + midltexp, + midltexpelse ) ); whileblock->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)mid, - (ast_expression*)ast_binary_new( + mid, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)low, - (ast_expression*)high + low, + high ), - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + m_fold->m_imm_float[3] /* 2.0f */ ) ) ); @@ -968,11 +968,11 @@ ast_expression *intrin::pow_() { * = fabs(mid - exp) */ callfabs->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_SUB_F, - (ast_expression*)mid, - (ast_expression*)exp + mid, + exp ) ); @@ -981,16 +981,16 @@ ast_expression *intrin::pow_() { * */ body->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), /* init */ nullptr, /* pre condition */ - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_GT, - (ast_expression*)callfabs, - (ast_expression*)m_fold->constgen_float(QC_POW_EPSILON, false) + callfabs, + m_fold->constgen_float(QC_POW_EPSILON, false) ), /* pre not */ false, @@ -1001,22 +1001,22 @@ ast_expression *intrin::pow_() { /* increment expression */ nullptr, /* code block */ - (ast_expression*)whileblock + whileblock ) ); /* return accumulate */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)accumulate + accumulate ) ); /* } */ func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::mod_() { @@ -1028,82 +1028,82 @@ ast_expression *intrin::mod_() { * } */ ast_value *val = nullptr; - ast_call *call = ast_call_new(ctx(), func_self("floor", "mod")); - ast_value *a = ast_value_new(ctx(), "a", TYPE_FLOAT); - ast_value *b = ast_value_new(ctx(), "b", TYPE_FLOAT); - ast_value *div = ast_value_new(ctx(), "div", TYPE_FLOAT); - ast_value *sign = ast_value_new(ctx(), "sign", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *call = ast_call::make(ctx(), func_self("floor", "mod")); + ast_value *a = new ast_value(ctx(), "a", TYPE_FLOAT); + ast_value *b = new ast_value(ctx(), "b", TYPE_FLOAT); + ast_value *div = new ast_value(ctx(), "div", TYPE_FLOAT); + ast_value *sign = new ast_value(ctx(), "sign", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "mod", TYPE_FLOAT); - val->m_type_params.push_back(a); - val->m_type_params.push_back(b); + val->m_type_params.emplace_back(a); + val->m_type_params.emplace_back(b); body->m_locals.push_back(div); body->m_locals.push_back(sign); /* div = a / b; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)div, - (ast_expression*)ast_binary_new( + div, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)a, - (ast_expression*)b + a, + b ) ) ); /* sign = (div < 0.0f) ? -1 : 1; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)sign, - (ast_expression*)ast_ternary_new( + sign, + new ast_ternary( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)div, - (ast_expression*)m_fold->m_imm_float[0] + div, + m_fold->m_imm_float[0] ), - (ast_expression*)m_fold->m_imm_float[2], - (ast_expression*)m_fold->m_imm_float[1] + m_fold->m_imm_float[2], + m_fold->m_imm_float[1] ) ) ); /* floor(sign * div) */ call->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)sign, - (ast_expression*)div + sign, + div ) ); /* return a - b * sign * */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_SUB_F, - (ast_expression*)a, - (ast_expression*)ast_binary_new( + a, + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)b, - (ast_expression*)ast_binary_new( + b, + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)sign, - (ast_expression*)call + sign, + call ) ) ) @@ -1112,7 +1112,7 @@ ast_expression *intrin::mod_() { func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::fabs_() { @@ -1122,36 +1122,36 @@ ast_expression *intrin::fabs_() { * } */ ast_value *val = nullptr; - ast_value *arg1 = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *arg1 = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "fabs", TYPE_FLOAT); body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_ternary_new( + new ast_ternary( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LE, - (ast_expression*)arg1, - (ast_expression*)m_fold->m_imm_float[0] + arg1, + m_fold->m_imm_float[0] ), - (ast_expression*)ast_unary_new( + ast_unary::make( ctx(), VINSTR_NEG_F, - (ast_expression*)arg1 + arg1 ), - (ast_expression*)arg1 + arg1 ) ) ); - val->m_type_params.push_back(arg1); + val->m_type_params.emplace_back(arg1); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::epsilon_() { @@ -1163,67 +1163,67 @@ ast_expression *intrin::epsilon_() { * } */ ast_value *val = nullptr; - ast_value *eps = ast_value_new(ctx(), "eps", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_value *eps = new ast_value(ctx(), "eps", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, "epsilon", TYPE_FLOAT); body->m_locals.push_back(eps); /* eps = 1.0f; */ body->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)eps, - (ast_expression*)m_fold->m_imm_float[0] + eps, + m_fold->m_imm_float[0] ) ); body->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), nullptr, nullptr, false, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_NE_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)ast_binary_new( + m_fold->m_imm_float[1], + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)eps, - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + eps, + m_fold->m_imm_float[3] /* 2.0f */ ) ), - (ast_expression*)m_fold->m_imm_float[1] + m_fold->m_imm_float[1] ), false, nullptr, - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_DIV_F, - (ast_expression*)eps, - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + eps, + m_fold->m_imm_float[3] /* 2.0f */ ) ) ); /* return eps; */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)eps + eps ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::nan_() { @@ -1234,36 +1234,36 @@ ast_expression *intrin::nan_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); ast_function *func = value(&val, "nan", TYPE_FLOAT); - ast_block *block = ast_block_new(ctx()); + ast_block *block = new ast_block(ctx()); block->m_locals.push_back(x); block->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)x, - (ast_expression*)m_fold->m_imm_float[0] + x, + m_fold->m_imm_float[0] ) ); block->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)x, - (ast_expression*)x + x, + x ) ) ); func->m_blocks.emplace_back(block); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::inf_() { @@ -1275,10 +1275,10 @@ ast_expression *intrin::inf_() { * } */ ast_value *val = nullptr; - ast_value *x = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_value *y = ast_value_new(ctx(), "y", TYPE_FLOAT); + ast_value *x = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_value *y = new ast_value(ctx(), "y", TYPE_FLOAT); ast_function *func = value(&val, "inf", TYPE_FLOAT); - ast_block *block = ast_block_new(ctx()); + ast_block *block = new ast_block(ctx()); size_t i; block->m_locals.push_back(x); @@ -1287,30 +1287,30 @@ ast_expression *intrin::inf_() { /* to keep code size down */ for (i = 0; i <= 1; i++) { block->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i == 0) ? x : y), - (ast_expression*)m_fold->m_imm_float[i] + ((i == 0) ? x : y), + m_fold->m_imm_float[i] ) ); } block->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)x, - (ast_expression*)y + x, + y ) ) ); func->m_blocks.emplace_back(block); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::ln_() { @@ -1380,34 +1380,34 @@ ast_expression *intrin::ln_() { */ ast_value *val = nullptr; - ast_value *power = ast_value_new(ctx(), "power", TYPE_FLOAT); - ast_value *base = ast_value_new(ctx(), "base",TYPE_FLOAT); - ast_value *whole= ast_value_new(ctx(), "whole", TYPE_FLOAT); - ast_value *nth = ast_value_new(ctx(), "nth", TYPE_FLOAT); - ast_value *sign = ast_value_new(ctx(), "sign", TYPE_FLOAT); - ast_value *A_i = ast_value_new(ctx(), "A_i", TYPE_FLOAT); - ast_value *B_i = ast_value_new(ctx(), "B_i", TYPE_FLOAT); - ast_value *A_iminus1 = ast_value_new(ctx(), "A_iminus1", TYPE_FLOAT); - ast_value *B_iminus1 = ast_value_new(ctx(), "B_iminus1", TYPE_FLOAT); - ast_value *b_iplus1 = ast_value_new(ctx(), "b_iplus1", TYPE_FLOAT); - ast_value *A_iplus1 = ast_value_new(ctx(), "A_iplus1", TYPE_FLOAT); - ast_value *B_iplus1 = ast_value_new(ctx(), "B_iplus1", TYPE_FLOAT); - ast_value *eps = ast_value_new(ctx(), "eps", TYPE_FLOAT); - ast_value *base2 = ast_value_new(ctx(), "base2", TYPE_FLOAT); - ast_value *n2 = ast_value_new(ctx(), "n2",TYPE_FLOAT); - ast_value *newbase2 = ast_value_new(ctx(), "newbase2", TYPE_FLOAT); - ast_block *block = ast_block_new(ctx()); - ast_block *plt1orblt1 = ast_block_new(ctx()); // (power <= 1.0f || base <= 1.0f) - ast_block *plt1 = ast_block_new(ctx()); // (power < 1.0f) - ast_block *blt1 = ast_block_new(ctx()); // (base< 1.0f) - ast_block *forloop = ast_block_new(ctx()); // for(;;) - ast_block *whileloop = ast_block_new(ctx()); // while (whole >= base) - ast_block *nestwhile= ast_block_new(ctx()); // while (whole >= newbase2) + ast_value *power = new ast_value(ctx(), "power", TYPE_FLOAT); + ast_value *base = new ast_value(ctx(), "base",TYPE_FLOAT); + ast_value *whole= new ast_value(ctx(), "whole", TYPE_FLOAT); + ast_value *nth = new ast_value(ctx(), "nth", TYPE_FLOAT); + ast_value *sign = new ast_value(ctx(), "sign", TYPE_FLOAT); + ast_value *A_i = new ast_value(ctx(), "A_i", TYPE_FLOAT); + ast_value *B_i = new ast_value(ctx(), "B_i", TYPE_FLOAT); + ast_value *A_iminus1 = new ast_value(ctx(), "A_iminus1", TYPE_FLOAT); + ast_value *B_iminus1 = new ast_value(ctx(), "B_iminus1", TYPE_FLOAT); + ast_value *b_iplus1 = new ast_value(ctx(), "b_iplus1", TYPE_FLOAT); + ast_value *A_iplus1 = new ast_value(ctx(), "A_iplus1", TYPE_FLOAT); + ast_value *B_iplus1 = new ast_value(ctx(), "B_iplus1", TYPE_FLOAT); + ast_value *eps = new ast_value(ctx(), "eps", TYPE_FLOAT); + ast_value *base2 = new ast_value(ctx(), "base2", TYPE_FLOAT); + ast_value *n2 = new ast_value(ctx(), "n2",TYPE_FLOAT); + ast_value *newbase2 = new ast_value(ctx(), "newbase2", TYPE_FLOAT); + ast_block *block = new ast_block(ctx()); + ast_block *plt1orblt1 = new ast_block(ctx()); // (power <= 1.0f || base <= 1.0f) + ast_block *plt1 = new ast_block(ctx()); // (power < 1.0f) + ast_block *blt1 = new ast_block(ctx()); // (base< 1.0f) + ast_block *forloop = new ast_block(ctx()); // for(;;) + ast_block *whileloop = new ast_block(ctx()); // while (whole >= base) + ast_block *nestwhile= new ast_block(ctx()); // while (whole >= newbase2) ast_function *func = value(&val, "ln", TYPE_FLOAT); size_t i; - val->m_type_params.push_back(power); - val->m_type_params.push_back(base); + val->m_type_params.emplace_back(power); + val->m_type_params.emplace_back(base); block->m_locals.push_back(whole); block->m_locals.push_back(nth); @@ -1420,21 +1420,21 @@ ast_expression *intrin::ln_() { /* sign = 1.0f; */ block->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)sign, - (ast_expression*)m_fold->m_imm_float[1] + sign, + m_fold->m_imm_float[1] ) ); /* eps = __builtin_epsilon(); */ block->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)eps, - (ast_expression*)ast_call_new( + eps, + ast_call::make( ctx(), func_self("__builtin_epsilon", "ln") ) @@ -1451,12 +1451,12 @@ ast_expression *intrin::ln_() { int j; for (j = 1; j >= 0; j--) { block->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((j) ? ((i) ? B_iminus1 : A_i) + ((j) ? ((i) ? B_iminus1 : A_i) : ((i) ? A_iminus1 : B_i)), - (ast_expression*)m_fold->m_imm_float[j] + m_fold->m_imm_float[j] ) ); } @@ -1474,25 +1474,25 @@ ast_expression *intrin::ln_() { */ for (i = 0; i <= 1; i++) { ((i) ? blt1 : plt1)->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i) ? base : power), - (ast_expression*)ast_binary_new( + ((i) ? base : power), + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)((i) ? base : power) + m_fold->m_imm_float[1], + ((i) ? base : power) ) ) ); plt1->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)sign, - (ast_expression*)m_fold->m_imm_float[2] + sign, + m_fold->m_imm_float[2] ) ); } @@ -1508,27 +1508,27 @@ ast_expression *intrin::ln_() { * } */ plt1orblt1->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_OR, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LE, - (ast_expression*)power, - (ast_expression*)m_fold->m_imm_float[0] + power, + m_fold->m_imm_float[0] ), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LE, - (ast_expression*)base, - (ast_expression*)m_fold->m_imm_float[0] + base, + m_fold->m_imm_float[0] ) ), - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_call_new( + ast_call::make( ctx(), func_self("__builtin_nan", "ln") ) @@ -1539,74 +1539,74 @@ ast_expression *intrin::ln_() { for (i = 0; i <= 1; i++) { plt1orblt1->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LT, - (ast_expression*)((i) ? base : power), - (ast_expression*)m_fold->m_imm_float[1] + ((i) ? base : power), + m_fold->m_imm_float[1] ), - (ast_expression*)((i) ? blt1 : plt1), + ((i) ? blt1 : plt1), nullptr ) ); } - block->m_exprs.push_back((ast_expression*)plt1orblt1); + block->m_exprs.push_back(plt1orblt1); /* whole = power; */ forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)whole, - (ast_expression*)power + whole, + power ) ); /* nth = 0.0f; */ forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)nth, - (ast_expression*)m_fold->m_imm_float[0] + nth, + m_fold->m_imm_float[0] ) ); /* base2 = base; */ whileloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)base2, - (ast_expression*)base + base2, + base ) ); /* n2 = 1.0f; */ whileloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)n2, - (ast_expression*)m_fold->m_imm_float[1] + n2, + m_fold->m_imm_float[1] ) ); /* newbase2 = base2 * base2; */ whileloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)newbase2, - (ast_expression*)ast_binary_new( + newbase2, + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)base2, - (ast_expression*)base2 + base2, + base2 ) ) ); @@ -1618,93 +1618,93 @@ ast_expression *intrin::ln_() { /* base2 = newbase2; */ nestwhile->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)base2, - (ast_expression*)newbase2 + base2, + newbase2 ) ); /* n2 *= 2; */ nestwhile->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)n2, - (ast_expression*)m_fold->m_imm_float[3] /* 2.0f */ + n2, + m_fold->m_imm_float[3] /* 2.0f */ ) ); /* newbase2 *= newbase2; */ nestwhile->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_MUL_F, - (ast_expression*)newbase2, - (ast_expression*)newbase2 + newbase2, + newbase2 ) ); /* while (whole >= newbase2) */ whileloop->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), nullptr, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_GE, - (ast_expression*)whole, - (ast_expression*)newbase2 + whole, + newbase2 ), false, nullptr, false, nullptr, - (ast_expression*)nestwhile + nestwhile ) ); /* whole /= base2; */ whileloop->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_DIV_F, - (ast_expression*)whole, - (ast_expression*)base2 + whole, + base2 ) ); /* nth += n2; */ whileloop->m_exprs.push_back( - (ast_expression*)ast_binstore_new( + new ast_binstore( ctx(), INSTR_STORE_F, INSTR_ADD_F, - (ast_expression*)nth, - (ast_expression*)n2 + nth, + n2 ) ); /* while (whole >= base) */ forloop->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), nullptr, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_GE, - (ast_expression*)whole, - (ast_expression*)base + whole, + base ), false, nullptr, false, nullptr, - (ast_expression*)whileloop + whileloop ) ); @@ -1714,11 +1714,11 @@ ast_expression *intrin::ln_() { /* b_iplus1 = nth; */ forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)b_iplus1, - (ast_expression*)nth + b_iplus1, + nth ) ); @@ -1728,20 +1728,20 @@ ast_expression *intrin::ln_() { */ for (i = 0; i <= 1; i++) { forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i) ? B_iplus1 : A_iplus1), - (ast_expression*)ast_binary_new( + ((i) ? B_iplus1 : A_iplus1), + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)b_iplus1, - (ast_expression*) ((i) ? B_i : A_i) + b_iplus1, + ((i) ? B_i : A_i) ), - (ast_expression*)((i) ? B_iminus1 : A_iminus1) + ((i) ? B_iminus1 : A_iminus1) ) ) ); @@ -1753,11 +1753,11 @@ ast_expression *intrin::ln_() { */ for (i = 0; i <= 1; i++) { forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i) ? B_iminus1 : A_iminus1), - (ast_expression*)((i) ? B_i : A_i) + ((i) ? B_iminus1 : A_iminus1), + ((i) ? B_i : A_i) ) ); } @@ -1768,11 +1768,11 @@ ast_expression *intrin::ln_() { */ for (i = 0; i <= 1; i++) { forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i) ? B_i : A_i), - (ast_expression*)((i) ? B_iplus1 : A_iplus1) + ((i) ? B_i : A_i), + ((i) ? B_iplus1 : A_iplus1) ) ); } @@ -1782,20 +1782,20 @@ ast_expression *intrin::ln_() { * break; */ forloop->m_exprs.push_back( - (ast_expression*)ast_ifthen_new( + new ast_ifthen( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_LE, - (ast_expression*)whole, - (ast_expression*)ast_binary_new( + whole, + new ast_binary( ctx(), INSTR_ADD_F, - (ast_expression*)m_fold->m_imm_float[1], - (ast_expression*)eps + m_fold->m_imm_float[1], + eps ) ), - (ast_expression*)ast_breakcont_new( + new ast_breakcont( ctx(), false, 0 @@ -1810,43 +1810,43 @@ ast_expression *intrin::ln_() { */ for (i = 0; i <= 1; i++) { forloop->m_exprs.push_back( - (ast_expression*)ast_store_new( + new ast_store( ctx(), INSTR_STORE_F, - (ast_expression*)((i) ? base : power), - (ast_expression*)((i) ? whole : base) + ((i) ? base : power), + ((i) ? whole : base) ) ); } /* add the for loop block */ block->m_exprs.push_back( - (ast_expression*)ast_loop_new( + new ast_loop( ctx(), nullptr, /* for(; 1; ) ?? (can this be nullptr too?) */ - (ast_expression*)m_fold->m_imm_float[1], + m_fold->m_imm_float[1], false, nullptr, false, nullptr, - (ast_expression*)forloop + forloop ) ); /* return sign * A_i / B_il */ block->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), INSTR_MUL_F, - (ast_expression*)sign, - (ast_expression*)ast_binary_new( + sign, + new ast_binary( ctx(), INSTR_DIV_F, - (ast_expression*)A_i, - (ast_expression*)B_i + A_i, + B_i ) ) ) @@ -1854,31 +1854,31 @@ ast_expression *intrin::ln_() { func->m_blocks.emplace_back(block); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::log_variant(const char *name, float base) { ast_value *val = nullptr; - ast_call *callln = ast_call_new (ctx(), func_self("__builtin_ln", name)); - ast_value *arg1 = ast_value_new(ctx(), "x", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *callln = ast_call::make(ctx(), func_self("__builtin_ln", name)); + ast_value *arg1 = new ast_value(ctx(), "x", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, name, TYPE_FLOAT); - val->m_type_params.push_back(arg1); + val->m_type_params.emplace_back(arg1); - callln->m_params.push_back((ast_expression*)arg1); - callln->m_params.push_back((ast_expression*)m_fold->constgen_float(base, false)); + callln->m_params.push_back(arg1); + callln->m_params.push_back(m_fold->constgen_float(base, false)); body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)callln + callln ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::log_() { @@ -1901,41 +1901,41 @@ ast_expression *intrin::shift_variant(const char *name, size_t instr) { * return floor(a [instr] pow(2, b)); */ ast_value *val = nullptr; - ast_call *callpow = ast_call_new(ctx(), func_self("pow", name)); - ast_call *callfloor = ast_call_new(ctx(), func_self("floor", name)); - ast_value *a = ast_value_new(ctx(), "a", TYPE_FLOAT); - ast_value *b = ast_value_new(ctx(), "b", TYPE_FLOAT); - ast_block *body = ast_block_new(ctx()); + ast_call *callpow = ast_call::make(ctx(), func_self("pow", name)); + ast_call *callfloor = ast_call::make(ctx(), func_self("floor", name)); + ast_value *a = new ast_value(ctx(), "a", TYPE_FLOAT); + ast_value *b = new ast_value(ctx(), "b", TYPE_FLOAT); + ast_block *body = new ast_block(ctx()); ast_function *func = value(&val, name, TYPE_FLOAT); - val->m_type_params.push_back(a); - val->m_type_params.push_back(b); + val->m_type_params.emplace_back(a); + val->m_type_params.emplace_back(b); /* = pow(2, b) */ - callpow->m_params.push_back((ast_expression*)m_fold->m_imm_float[3]); - callpow->m_params.push_back((ast_expression*)b); + callpow->m_params.push_back(m_fold->m_imm_float[3]); + callpow->m_params.push_back(b); /* = floor(a [instr] ) */ callfloor->m_params.push_back( - (ast_expression*)ast_binary_new( + new ast_binary( ctx(), instr, - (ast_expression*)a, - (ast_expression*)callpow + a, + callpow ) ); /* return */ body->m_exprs.push_back( - (ast_expression*)ast_return_new( + new ast_return( ctx(), - (ast_expression*)callfloor + callfloor ) ); func->m_blocks.emplace_back(body); reg(val, func); - return (ast_expression*)val; + return val; } ast_expression *intrin::lshift() { @@ -1998,14 +1998,14 @@ intrin::intrin(parser_t *parser) } ast_expression *intrin::do_fold(ast_value *val, ast_expression **exprs) { - if (!val || !val->m_name) + if (!val || !val->m_name.length()) return nullptr; static constexpr size_t kPrefixLength = 10; // "__builtin_" for (auto &it : m_intrinsics) { - if (!strcmp(val->m_name, it.name)) + if (val->m_name == it.name) return (vec_size(exprs) != it.args) ? nullptr - : m_fold->intrinsic(val->m_name + kPrefixLength, exprs); + : m_fold->intrinsic(val->m_name.c_str() + kPrefixLength, exprs); } return nullptr; } @@ -2027,7 +2027,7 @@ ast_expression *intrin::func_self(const char *name, const char *from) { /* try current first */ if ((find = parser_find_global(m_parser, name)) && ((ast_value*)find)->m_vtype == TYPE_FUNCTION) for (auto &it : m_parser->functions) - if (((ast_value*)find)->m_name && !strcmp(it->m_name, ((ast_value*)find)->m_name) && it->m_builtin < 0) + if (reinterpret_cast(find)->m_name.length() && it->m_name == reinterpret_cast(find)->m_name && it->m_builtin < 0) return find; /* try name second */ if ((find = func_try(offsetof(intrin_func_t, name), name)))