static int _scf_op_while(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
- assert(2 == nb_nodes);
+ assert(2 == nb_nodes || 1 == nb_nodes);
scf_handler_data_t* d = data;
d->branch_ops = local_branch_ops;
// while body
- if (_scf_op_node(ast, nodes[1], d) < 0) {
- scf_loge("\n");
- return -1;
+ if (2 == nb_nodes) {
+ if (_scf_op_node(ast, nodes[1], d) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
}
if (_scf_op_end_loop(start_prev, NULL, jmp_end, up_branch_ops, d) < 0) {
if (ret < 0)
return ret;
+ if (dom == bb)
+ return 0;
+
ret = scf_vector_add(loop, dom);
if (ret < 0)
return ret;
- if (dom == bb)
- return 0;
-
for (l = scf_list_tail(bb_list_head); l != scf_list_sentinel(bb_list_head);
l = scf_list_prev(l)) {
jmp = scf_list_data(scf_list_next(&bbg->entry->list), scf_basic_block_t, list);
- assert(jmp->jmp_flag);
+ if (jmp->jmp_flag) {
- if (!jmp->jcc_flag) {
- scf_loge("\n");
- return -EINVAL;
- }
+ if (!jmp->jcc_flag)
+ return -EINVAL;
+ } else
+ jmp = bbg->entry;
pre = scf_basic_block_alloc();
if (!pre)
int i;
// int j;
+ if (0 == bbg->posts->size)
+ return 0;
+
pre = bbg->pre;
post = bbg->posts->data[0];
static int _scf_op_const_while(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
- assert(2 == nb_nodes);
+ assert(2 == nb_nodes || 1 == nb_nodes);
scf_handler_data_t* d = data;
+ scf_variable_t* r = NULL;
+ scf_expr_t* e = nodes[0];
- scf_expr_t* e = nodes[0];
assert(SCF_OP_EXPR == e->type);
- scf_variable_t* r = NULL;
if (_scf_expr_calculate_internal(ast, e, &r) < 0)
return -1;
- if (_scf_op_const_node(ast, nodes[1], d) < 0)
- return -1;
+ if (2 == nb_nodes) {
+ if (_scf_op_const_node(ast, nodes[1], d) < 0)
+ return -1;
+ }
return 0;
}
static int _scf_op_semantic_while(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
{
- assert(2 == nb_nodes);
+ assert(2 == nb_nodes || 1 == nb_nodes);
scf_handler_data_t* d = data;
r = NULL;
// while body
- scf_node_t* node = nodes[1];
- scf_operator_t* op = node->op;
+ if (2 == nb_nodes) {
+ scf_node_t* node = nodes[1];
+ scf_operator_t* op = node->op;
- if (!op) {
- op = scf_find_base_operator_by_type(node->type);
if (!op) {
+ op = scf_find_base_operator_by_type(node->type);
+ if (!op) {
+ scf_loge("\n");
+ return -1;
+ }
+ }
+
+ scf_operator_handler_t* h = scf_find_semantic_operator_handler(op->type, -1, -1, -1);
+ if (!h) {
scf_loge("\n");
return -1;
}
- }
-
- scf_operator_handler_t* h = scf_find_semantic_operator_handler(op->type, -1, -1, -1);
- if (!h) {
- scf_loge("\n");
- return -1;
- }
- scf_variable_t** pret = d->pret;
+ scf_variable_t** pret = d->pret;
- d->pret = &node->result;
- int ret = h->func(ast, node->nodes, node->nb_nodes, d);
- d->pret = pret;
+ d->pret = &node->result;
+ int ret = h->func(ast, node->nodes, node->nb_nodes, d);
+ d->pret = pret;
- if (ret < 0) {
- scf_loge("\n");
- return -1;
+ if (ret < 0) {
+ scf_loge("\n");
+ return -1;
+ }
}
return 0;