support bit member of struct, such as 'struct S { uint8_t flag:1; }; '
authoryu.dongliang <18588496441@163.com>
Thu, 6 Mar 2025 09:17:39 +0000 (17:17 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 6 Mar 2025 09:17:59 +0000 (17:17 +0800)
20 files changed:
core/scf_3ac.c
core/scf_core_types.h
core/scf_operator_dag.c
core/scf_operator_handler_3ac.c
core/scf_optimizer_pointer_alias.c
core/scf_variable.c
core/scf_variable.h
examples/bit_struct.c [new file with mode: 0644]
native/eda/scf_eda_inst.c
native/risc/scf_risc_inst.c
native/risc/scf_risc_rcg.c
native/x64/scf_x64.h
native/x64/scf_x64_inst.c
native/x64/scf_x64_inst_binary.c
native/x64/scf_x64_peephole.c
native/x64/scf_x64_rcg.c
native/x64/scf_x64_reg.c
native/x64/scf_x64_reg.h
parse/scf_dfa_class.c
parse/scf_dfa_var.c

index 3c59e1388348341babf225683902c428e234148e..f19f82b3efacb2acda152cd27559db2e736806ad 100644 (file)
@@ -117,38 +117,6 @@ static scf_3ac_operator_t _3ac_operators[] = {
        {SCF_OP_3AC_ASSIGN_ARRAY_INDEX,     "array_index="},
        {SCF_OP_3AC_ASSIGN_POINTER,             "pointer="},
 
-       {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE,     "dereference+="},
-       {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX,     "array_index+="},
-       {SCF_OP_3AC_ADD_ASSIGN_POINTER,     "pointer+="},
-
-       {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE,     "dereference-="},
-       {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX,     "array_index-="},
-       {SCF_OP_3AC_SUB_ASSIGN_POINTER,     "pointer-="},
-
-       {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE, "dereference&="},
-       {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, "array_index&="},
-       {SCF_OP_3AC_AND_ASSIGN_POINTER,     "pointer&="},
-
-       {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE,  "dereference|="},
-       {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX,  "array_index|="},
-       {SCF_OP_3AC_OR_ASSIGN_POINTER,      "pointer|="},
-
-       {SCF_OP_3AC_INC_DEREFERENCE,        "++dereference"},
-       {SCF_OP_3AC_INC_ARRAY_INDEX,        "++array_index"},
-       {SCF_OP_3AC_INC_POINTER,            "++pointer"},
-
-       {SCF_OP_3AC_DEC_DEREFERENCE,        "--dereference"},
-       {SCF_OP_3AC_DEC_ARRAY_INDEX,        "--array_index"},
-       {SCF_OP_3AC_DEC_POINTER,            "--pointer"},
-
-       {SCF_OP_3AC_INC_POST_DEREFERENCE,   "dereference++"},
-       {SCF_OP_3AC_INC_POST_ARRAY_INDEX,   "array_index++"},
-       {SCF_OP_3AC_INC_POST_POINTER,       "pointer++"},
-
-       {SCF_OP_3AC_DEC_POST_DEREFERENCE,   "dereference--"},
-       {SCF_OP_3AC_DEC_POST_ARRAY_INDEX,   "array_index--"},
-       {SCF_OP_3AC_DEC_POST_POINTER,       "pointer--"},
-
        {SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX, "&array_index"},
        {SCF_OP_3AC_ADDRESS_OF_POINTER,     "&pointer"},
 };
@@ -869,8 +837,6 @@ int scf_3ac_code_to_dag(scf_3ac_code_t* c, scf_list_t* dag)
                        switch (c->op->type) {
                                case SCF_OP_ARRAY_INDEX:
                                case SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX:
-                               case SCF_OP_3AC_INC_POST_ARRAY_INDEX:
-                               case SCF_OP_3AC_DEC_POST_ARRAY_INDEX:
                                case SCF_OP_VA_START:
                                case SCF_OP_VA_ARG:
                                        n_operands0 = 3;
index e67df03ce62d579a0982ca42120cc61c86543b91..339f380b09da6fcd64a2c2c65da7282b75817c4e 100644 (file)
@@ -149,36 +149,12 @@ enum scf_core_types
        SCF_OP_3AC_DEC,
 
        SCF_OP_3AC_ASSIGN_DEREFERENCE,     // left value, *p = expr
-       SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE,
-       SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE,
-       SCF_OP_3AC_AND_ASSIGN_DEREFERENCE,
-       SCF_OP_3AC_OR_ASSIGN_DEREFERENCE,
-       SCF_OP_3AC_INC_DEREFERENCE,
-       SCF_OP_3AC_DEC_DEREFERENCE,
-       SCF_OP_3AC_INC_POST_DEREFERENCE,
-       SCF_OP_3AC_DEC_POST_DEREFERENCE,
 
        SCF_OP_3AC_ASSIGN_ARRAY_INDEX,     // left value, a[0] = expr
-       SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX,
-       SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX,
-       SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX,
-       SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX,
-       SCF_OP_3AC_INC_ARRAY_INDEX,
-       SCF_OP_3AC_DEC_ARRAY_INDEX,
-       SCF_OP_3AC_INC_POST_ARRAY_INDEX,
-       SCF_OP_3AC_DEC_POST_ARRAY_INDEX,
        SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX,
 
        // 97
        SCF_OP_3AC_ASSIGN_POINTER,         // left value, p->a = expr
-       SCF_OP_3AC_ADD_ASSIGN_POINTER,
-       SCF_OP_3AC_SUB_ASSIGN_POINTER,
-       SCF_OP_3AC_AND_ASSIGN_POINTER,
-       SCF_OP_3AC_OR_ASSIGN_POINTER,
-       SCF_OP_3AC_INC_POINTER,
-       SCF_OP_3AC_DEC_POINTER,
-       SCF_OP_3AC_INC_POST_POINTER,
-       SCF_OP_3AC_DEC_POST_POINTER,
        SCF_OP_3AC_ADDRESS_OF_POINTER,
 
        SCF_OP_3AC_JZ,          // jz
@@ -257,17 +233,17 @@ static int scf_type_is_binary_assign(int type)
 
 static int scf_type_is_assign_dereference(int type)
 {
-       return type >= SCF_OP_3AC_ASSIGN_DEREFERENCE && type <= SCF_OP_3AC_DEC_POST_DEREFERENCE;
+       return SCF_OP_3AC_ASSIGN_DEREFERENCE == type;
 }
 
 static int scf_type_is_assign_array_index(int type)
 {
-       return type >= SCF_OP_3AC_ASSIGN_ARRAY_INDEX && type <= SCF_OP_3AC_DEC_POST_ARRAY_INDEX;
+       return SCF_OP_3AC_ASSIGN_ARRAY_INDEX == type;
 }
 
 static int scf_type_is_assign_pointer(int type)
 {
-       return type >= SCF_OP_3AC_ASSIGN_POINTER && type <= SCF_OP_3AC_DEC_POST_POINTER;
+       return SCF_OP_3AC_ASSIGN_POINTER == type;
 }
 
 static int scf_type_is_signed(int type)
index 462e0abfcaaa7976d8c8b4b1235ec0fdc1060494..cac9df1220fe7d3ccb8685e33302aa9f1f9fb35a 100644 (file)
@@ -313,12 +313,6 @@ static int _scf_dag_op_##name##_dereference(scf_list_t* h, scf_dag_node_t* paren
        return _scf_3ac_code_N(h, SCF_OP_3AC_##op##_DEREFERENCE, NULL, nodes, nb_nodes); \
 }
 SCF_DAG_ASSIGN_DEREFERENCE(assign,     ASSIGN);
-SCF_DAG_ASSIGN_DEREFERENCE(add_assign, ADD_ASSIGN);
-SCF_DAG_ASSIGN_DEREFERENCE(sub_assign, SUB_ASSIGN);
-SCF_DAG_ASSIGN_DEREFERENCE(and_assign, AND_ASSIGN);
-SCF_DAG_ASSIGN_DEREFERENCE(or_assign,  OR_ASSIGN);
-SCF_DAG_ASSIGN_DEREFERENCE(inc,        INC);
-SCF_DAG_ASSIGN_DEREFERENCE(dec,        DEC);
 
 #define SCF_DAG_ASSIGN_ARRAY_INDEX(name, op) \
 static int _scf_dag_op_##name##_array_index(scf_list_t* h, scf_dag_node_t* parent, scf_dag_node_t** nodes, int nb_nodes) \
@@ -327,12 +321,6 @@ static int _scf_dag_op_##name##_array_index(scf_list_t* h, scf_dag_node_t* paren
        return _scf_3ac_code_N(h, SCF_OP_3AC_##op##_ARRAY_INDEX, NULL, nodes, nb_nodes); \
 }
 SCF_DAG_ASSIGN_ARRAY_INDEX(assign,     ASSIGN);
-SCF_DAG_ASSIGN_ARRAY_INDEX(add_assign, ADD_ASSIGN);
-SCF_DAG_ASSIGN_ARRAY_INDEX(sub_assign, SUB_ASSIGN);
-SCF_DAG_ASSIGN_ARRAY_INDEX(and_assign, AND_ASSIGN);
-SCF_DAG_ASSIGN_ARRAY_INDEX(or_assign,  OR_ASSIGN);
-SCF_DAG_ASSIGN_ARRAY_INDEX(inc,        INC);
-SCF_DAG_ASSIGN_ARRAY_INDEX(dec,        DEC);
 
 #define SCF_DAG_ASSIGN_POINTER(name, op) \
 static int _scf_dag_op_##name##_pointer(scf_list_t* h, scf_dag_node_t* parent, scf_dag_node_t** nodes, int nb_nodes) \
@@ -340,12 +328,6 @@ static int _scf_dag_op_##name##_pointer(scf_list_t* h, scf_dag_node_t* parent, s
        return _scf_3ac_code_N(h, SCF_OP_3AC_##op##_POINTER, NULL, nodes, nb_nodes); \
 }
 SCF_DAG_ASSIGN_POINTER(assign,     ASSIGN);
-SCF_DAG_ASSIGN_POINTER(add_assign, ADD_ASSIGN);
-SCF_DAG_ASSIGN_POINTER(sub_assign, SUB_ASSIGN);
-SCF_DAG_ASSIGN_POINTER(and_assign, AND_ASSIGN);
-SCF_DAG_ASSIGN_POINTER(or_assign,  OR_ASSIGN);
-SCF_DAG_ASSIGN_POINTER(inc,        INC);
-SCF_DAG_ASSIGN_POINTER(dec,        DEC);
 
 static int _scf_dag_op_return(scf_list_t* h, scf_dag_node_t* parent, scf_dag_node_t** nodes, int nb_nodes)
 {
@@ -454,28 +436,8 @@ scf_dag_operator_t dag_operators[] =
        {SCF_OP_OR_ASSIGN,      SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_or_assign},
 
        {SCF_OP_3AC_ASSIGN_ARRAY_INDEX,        SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_assign_array_index},
-       {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_add_assign_array_index},
-       {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_sub_assign_array_index},
-       {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_and_assign_array_index},
-       {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX,     SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_or_assign_array_index},
-       {SCF_OP_3AC_INC_ARRAY_INDEX,           SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_inc_array_index},
-       {SCF_OP_3AC_DEC_ARRAY_INDEX,           SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_dec_array_index},
-
        {SCF_OP_3AC_ASSIGN_POINTER,            SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_assign_pointer},
-       {SCF_OP_3AC_ADD_ASSIGN_POINTER,        SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_add_assign_pointer},
-       {SCF_OP_3AC_SUB_ASSIGN_POINTER,        SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_sub_assign_pointer},
-       {SCF_OP_3AC_AND_ASSIGN_POINTER,        SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_and_assign_pointer},
-       {SCF_OP_3AC_OR_ASSIGN_POINTER,         SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_or_assign_pointer},
-       {SCF_OP_3AC_INC_POINTER,               SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_inc_pointer},
-       {SCF_OP_3AC_DEC_POINTER,               SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_dec_pointer},
-
        {SCF_OP_3AC_ASSIGN_DEREFERENCE,        SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_assign_dereference},
-       {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_add_assign_dereference},
-       {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_sub_assign_dereference},
-       {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE,    SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_and_assign_dereference},
-       {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE,     SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_or_assign_dereference},
-       {SCF_OP_3AC_INC_DEREFERENCE,           SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_inc_dereference},
-       {SCF_OP_3AC_DEC_DEREFERENCE,           SCF_OP_ASSOCIATIVITY_RIGHT, _scf_dag_op_dec_dereference},
 };
 
 scf_dag_operator_t* scf_dag_operator_find(int type)
@@ -518,7 +480,7 @@ int scf_dag_expr_calculate(scf_list_t* h, scf_dag_node_t* node)
 #endif
        scf_dag_operator_t* op = scf_dag_operator_find(node->type);
        if (!op) {
-               scf_loge("node->type: %d, %d\n", node->type, SCF_OP_3AC_DEC_POINTER);
+               scf_loge("node->type: %d\n", node->type);
                if (node->var && node->var->w)
                        scf_loge("node->var: %s\n", node->var->w->text->data);
                return -1;
index f627ada2b7f83c34a14624f924c41797f7ec0fd7..5f3d29f77ecb38d332c2e7d3956b833bc543493d 100644 (file)
@@ -406,7 +406,6 @@ static int _scf_op_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void*
                }
 
                if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
-                       scf_loge("\n");
                        ast->current_block = up;
                        return -1;
                }
@@ -1347,10 +1346,8 @@ static int __scf_op_call(scf_ast_t* ast, scf_function_t* f, void* data)
        ast->current_block = (scf_block_t*)f;
        d->branch_ops      = local_branch_ops; // use local_branch_ops, because branch code should NOT jmp over the function block
 
-       if (_scf_op_block(ast, f->node.nodes, f->node.nb_nodes, d) < 0) {
-               scf_loge("\n");
+       if (_scf_op_block(ast, f->node.nodes, f->node.nb_nodes, d) < 0)
                return -1;
-       }
 
        scf_list_t*        next;
        scf_3ac_operand_t* dst;
@@ -1683,10 +1680,8 @@ static int _scf_op_expr(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void*
        scf_handler_data_t* d = data;
 
        int ret = _scf_expr_calculate_internal(ast, nodes[0], d);
-       if (ret < 0) {
-               scf_loge("\n");
+       if (ret < 0)
                return -1;
-       }
 #endif
        return 0;
 }
@@ -1762,6 +1757,13 @@ static int _scf_op_address_of(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes,
                srcs[0] = child->nodes[0];
                srcs[1] = child->nodes[1];
 
+               scf_variable_t* v = _scf_operand_get(srcs[1]);
+               if (v->bit_size > 0) {
+                       scf_loge("can't pointer to the bit member '%s' of a struct, file: %s, line: %d\n",
+                                       v->w->text->data, parent->w->file->data, parent->w->line);
+                       return -EINVAL;
+               }
+
                return _scf_3ac_code_N(d->_3ac_list_head, SCF_OP_3AC_ADDRESS_OF_POINTER, parent, srcs, 2);
        }
 
@@ -1875,10 +1877,8 @@ static int _scf_op_right_value(scf_ast_t* ast, scf_node_t** pright, scf_handler_
 {
        scf_node_t* right = *pright;
 
-       if (_scf_expr_calculate_internal(ast, right, d) < 0) {
-               scf_loge("\n");
+       if (_scf_expr_calculate_internal(ast, right, d) < 0)
                return -1;
-       }
 
        if (scf_type_is_assign(right->type)) {
                right = right->nodes[0];
@@ -1890,10 +1890,8 @@ static int _scf_op_right_value(scf_ast_t* ast, scf_node_t** pright, scf_handler_
 
                right->_3ac_done = 0;
 
-               if (_scf_expr_calculate_internal(ast, right, d) < 0) {
-                       scf_loge("\n");
+               if (_scf_expr_calculate_internal(ast, right, d) < 0)
                        return -1;
-               }
 
        } else {
                while (SCF_OP_EXPR == right->type)
@@ -1965,50 +1963,31 @@ static int _scf_op_##name##_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_no
        while (SCF_OP_EXPR == node0->type) \
                node0 = node0->nodes[0]; \
        \
-       int is_float = scf_type_is_float(v1->type) && 0 == v1->nb_pointers; \
-       if (is_float) { \
-               if (_scf_expr_calculate_internal(ast, node0, d) < 0) { \
-                       scf_loge("\n"); \
-                       return -1; \
-               } \
-               \
-               if ( _scf_3ac_code_2(d->_3ac_list_head, parent->type, node0, node1) < 0) { \
-                       scf_loge("\n"); \
-                       return -1; \
-               } \
-               \
-               switch (node0->type) { \
-                       case SCF_OP_DEREFERENCE: \
-                               return _scf_op_left_value(ast, SCF_OP_3AC_ASSIGN_DEREFERENCE, node0, node0, d); \
-                               break; \
-                       case SCF_OP_ARRAY_INDEX: \
-                               return _scf_op_left_value_array_index(ast, SCF_OP_3AC_ASSIGN_ARRAY_INDEX, node0, node0, d); \
-                               break; \
-                       case SCF_OP_POINTER: \
-                               return _scf_op_left_value(ast, SCF_OP_3AC_ASSIGN_POINTER, node0, node0, d); \
-                               break; \
-                       default: \
-                               break; \
-               }; \
-               \
-               return 0; \
+       if (_scf_expr_calculate_internal(ast, node0, d) < 0) { \
+               scf_loge("\n"); \
+               return -1; \
+       } \
+       \
+       if ( _scf_3ac_code_2(d->_3ac_list_head, parent->type, node0, node1) < 0) { \
+               scf_loge("\n"); \
+               return -1; \
        } \
        \
        switch (node0->type) { \
                case SCF_OP_DEREFERENCE: \
-                       return _scf_op_left_value(ast, SCF_OP_3AC_##op##_ASSIGN_DEREFERENCE, node0, node1, d); \
+                       return _scf_op_left_value(ast, SCF_OP_3AC_ASSIGN_DEREFERENCE, node0, node0, d); \
                        break; \
                case SCF_OP_ARRAY_INDEX: \
-                       return _scf_op_left_value_array_index(ast, SCF_OP_3AC_##op##_ASSIGN_ARRAY_INDEX, node0, node1, d); \
+                       return _scf_op_left_value_array_index(ast, SCF_OP_3AC_ASSIGN_ARRAY_INDEX, node0, node0, d); \
                        break; \
                case SCF_OP_POINTER: \
-                       return _scf_op_left_value(ast, SCF_OP_3AC_##op##_ASSIGN_POINTER, node0, node1, d); \
+                       return _scf_op_left_value(ast, SCF_OP_3AC_ASSIGN_POINTER, node0, node0, d); \
                        break; \
                default: \
                        break; \
        }; \
        \
-       return _scf_3ac_code_2(d->_3ac_list_head, SCF_OP_##op##_ASSIGN, node0, node1); \
+       return 0; \
 }
 
 SCF_OP_BINARY_ASSIGN(add, ADD)
@@ -2016,19 +1995,19 @@ SCF_OP_BINARY_ASSIGN(sub, SUB)
 SCF_OP_BINARY_ASSIGN(and, AND)
 SCF_OP_BINARY_ASSIGN(or,  OR)
 
-#define SCF_OP_BINARY_ASSIGN2(name, op) \
-static int _scf_op_##name##_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) \
+SCF_OP_BINARY_ASSIGN(shl, SHL)
+SCF_OP_BINARY_ASSIGN(shr, SHR)
+SCF_OP_BINARY_ASSIGN(mul, MUL)
+SCF_OP_BINARY_ASSIGN(div, DIV)
+SCF_OP_BINARY_ASSIGN(mod, MOD)
+
+#define SCF_OP_UNARY_ASSIGN(name, op) \
+static int __scf_op_##name(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) \
 { \
-       assert(2 == nb_nodes); \
+       assert(1 == nb_nodes); \
        scf_handler_data_t* d = data; \
        \
-       scf_node_t*     parent = nodes[0]->parent; \
-       scf_node_t*     node0  = nodes[0]; \
-       scf_node_t*     node1  = nodes[1]; \
-       scf_variable_t* v1     = _scf_operand_get(nodes[1]); \
-       \
-       if ( _scf_op_right_value(ast, &node1, d) < 0) \
-               return -1; \
+       scf_node_t*     node0 = nodes[0]; \
        \
        while (SCF_OP_EXPR == node0->type) \
                node0 = node0->nodes[0]; \
@@ -2038,7 +2017,7 @@ static int _scf_op_##name##_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_no
                return -1; \
        } \
        \
-       if ( _scf_3ac_code_2(d->_3ac_list_head, parent->type, node0, node1) < 0) { \
+       if (_scf_3ac_code_1(d->_3ac_list_head, SCF_OP_3AC_##op, node0) < 0) { \
                scf_loge("\n"); \
                return -1; \
        } \
@@ -2059,39 +2038,6 @@ static int _scf_op_##name##_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_no
        \
        return 0; \
 }
-SCF_OP_BINARY_ASSIGN2(shl, SHL)
-SCF_OP_BINARY_ASSIGN2(shr, SHR)
-SCF_OP_BINARY_ASSIGN2(mul, MUL)
-SCF_OP_BINARY_ASSIGN2(div, DIV)
-SCF_OP_BINARY_ASSIGN2(mod, MOD)
-
-#define SCF_OP_UNARY_ASSIGN(name, op) \
-static int __scf_op_##name(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) \
-{ \
-       assert(1 == nb_nodes); \
-       scf_handler_data_t* d = data; \
-       \
-       scf_node_t*     node0 = nodes[0]; \
-       \
-       while (SCF_OP_EXPR == node0->type) \
-               node0 = node0->nodes[0]; \
-       \
-       switch (node0->type) { \
-               case SCF_OP_DEREFERENCE: \
-                       return _scf_op_left_value(ast, SCF_OP_3AC_##op##_DEREFERENCE, node0, NULL, d); \
-                       break; \
-               case SCF_OP_ARRAY_INDEX: \
-                       return _scf_op_left_value_array_index(ast, SCF_OP_3AC_##op##_ARRAY_INDEX, node0, NULL, d); \
-                       break; \
-               case SCF_OP_POINTER: \
-                       return _scf_op_left_value(ast, SCF_OP_3AC_##op##_POINTER, node0, NULL, d); \
-                       break; \
-               default: \
-                       break; \
-       }; \
-       \
-       return _scf_3ac_code_1(d->_3ac_list_head, SCF_OP_3AC_##op, node0); \
-}
 SCF_OP_UNARY_ASSIGN(inc, INC)
 SCF_OP_UNARY_ASSIGN(dec, DEC)
 
index 8c61410a84e52841d093f6a9e01143d27726b946..d974d303efd147e66097658743ea31625f4a543a 100644 (file)
@@ -134,34 +134,6 @@ static int _3ac_pointer_alias(scf_dag_node_t* alias, scf_3ac_code_t* c, scf_basi
                case SCF_OP_3AC_ASSIGN_DEREFERENCE:
                        c->op = scf_3ac_find_operator(SCF_OP_ASSIGN);
                        break;
-
-               case SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_ADD_ASSIGN);
-                       break;
-               case SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_SUB_ASSIGN);
-                       break;
-
-               case SCF_OP_3AC_AND_ASSIGN_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_AND_ASSIGN);
-                       break;
-               case SCF_OP_3AC_OR_ASSIGN_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_OR_ASSIGN);
-                       break;
-
-               case SCF_OP_3AC_INC_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_INC);
-                       break;
-               case SCF_OP_3AC_DEC_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_DEC);
-                       break;
-               case SCF_OP_3AC_INC_POST_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_INC_POST);
-                       break;
-               case SCF_OP_3AC_DEC_POST_DEREFERENCE:
-                       c->op = scf_3ac_find_operator(SCF_OP_DEC_POST);
-                       break;
-
                default:
                        scf_loge("\n");
                        return -1;
index bf260a73de1827b345e088d02814386a506e3350..96197d20ae567ef7952ae62fd43e235ade2f0902 100644 (file)
@@ -209,6 +209,9 @@ scf_variable_t*     scf_variable_clone(scf_variable_t* v)
        v2->data_size = v->data_size;
        v2->offset    = v->offset;
 
+       v2->bit_offset = v->bit_offset;
+       v2->bit_size   = v->bit_size;
+
        if (scf_variable_is_struct(v) || scf_variable_is_array(v)) {
 
                int size = scf_variable_size(v);
index 471fd562efe7500f1350d9171f3aba389950be7c..18169e0b4d1cf240284ec4ed75428c068a9fe578 100644 (file)
@@ -27,6 +27,9 @@ struct scf_variable_s {
        int                                     size;
        int                 data_size;
 
+       int                 bit_offset;
+       int                 bit_size;
+
        int                                     offset;
        int                                     bp_offset;  // offset based on RBP / EBP register
        int                                     sp_offset;  // offset based on RSP / ESP register
diff --git a/examples/bit_struct.c b/examples/bit_struct.c
new file mode 100644 (file)
index 0000000..1862734
--- /dev/null
@@ -0,0 +1,22 @@
+int printf(const char* fmt, ...);
+
+struct S
+{
+       uint32_t a:3;
+       uint16_t b:13;
+       uint8_t c:5;
+};
+
+int main()
+{
+       S s;
+
+       s.a = 1;
+       s.b = 2;
+       s.c = 3;
+
+//     uint32_t* p = &s.a;
+
+       printf("%d, %d, %d\n", s.a, s.b, s.c);
+       return 0;
+}
index c56cf6ad32476e61e1b77978595c80a6f35992b1..e6ee7c27b65382c102bb9d84e940347780041f7e 100644 (file)
@@ -1001,62 +1001,6 @@ static int _eda_inst_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_
        return -EINVAL;
 }
 
-static int _eda_inst_and_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)
-{
-       if (!c->srcs || c->srcs->size != 4)
-               return -EINVAL;
-
-       scf_eda_context_t*  eda    = ctx->priv;
-       scf_function_t*     f      = eda->f;
-
-       scf_3ac_operand_t*  base   = c->srcs->data[0];
-       scf_3ac_operand_t*  index  = c->srcs->data[1];
-       scf_3ac_operand_t*  scale  = c->srcs->data[2];
-       scf_3ac_operand_t*  src    = c->srcs->data[3];
-
-       if (!base || !base->dag_node)
-               return -EINVAL;
-
-       if (!index || !index->dag_node)
-               return -EINVAL;
-
-       if (!scale || !scale->dag_node)
-               return -EINVAL;
-
-       if (!src || !src->dag_node)
-               return -EINVAL;
-
-       return -EINVAL;
-}
-
-static int _eda_inst_or_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)
-{
-       if (!c->srcs || c->srcs->size != 4)
-               return -EINVAL;
-
-       scf_eda_context_t*  eda    = ctx->priv;
-       scf_function_t*     f      = eda->f;
-
-       scf_3ac_operand_t*  base   = c->srcs->data[0];
-       scf_3ac_operand_t*  index  = c->srcs->data[1];
-       scf_3ac_operand_t*  scale  = c->srcs->data[2];
-       scf_3ac_operand_t*  src    = c->srcs->data[3];
-
-       if (!base || !base->dag_node)
-               return -EINVAL;
-
-       if (!index || !index->dag_node)
-               return -EINVAL;
-
-       if (!scale || !scale->dag_node)
-               return -EINVAL;
-
-       if (!src || !src->dag_node)
-               return -EINVAL;
-
-       return -EINVAL;
-}
-
 static int _eda_inst_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)
 {
        if (!c->dsts || c->dsts->size != 1)
@@ -1361,9 +1305,7 @@ static eda_inst_handler_pt eda_inst_handlers[] =
        [SCF_OP_3AC_RESAVE]  =  _eda_inst_save_handler,
        [SCF_OP_3AC_RELOAD]  =  _eda_inst_reload_handler,
 
-       [SCF_OP_3AC_ASSIGN_ARRAY_INDEX]     = _eda_inst_assign_array_index_handler,
-       [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX] = _eda_inst_and_assign_array_index_handler,
-       [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX]  = _eda_inst_or_assign_array_index_handler,
+       [SCF_OP_3AC_ASSIGN_ARRAY_INDEX] = _eda_inst_assign_array_index_handler,
 };
 
 eda_inst_handler_pt scf_eda_find_inst_handler(const int op_type)
index 1bf5a695f4a5495f431dc6ac7a362fd336a606dd..221af0e4cd39b6c635d60ffa12d90e69c0db6ce1 100644 (file)
@@ -5738,38 +5738,6 @@ static risc_inst_handler_pt  risc_inst_handlers[SCF_N_3AC_OPS] =
        [SCF_OP_3AC_ASSIGN_ARRAY_INDEX    ]  =   _risc_inst_assign_array_index_handler,
        [SCF_OP_3AC_ASSIGN_POINTER        ]  =   _risc_inst_assign_pointer_handler,
 
-       [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE]  =   _risc_inst_add_assign_dereference_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX]  =   _risc_inst_add_assign_array_index_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_POINTER    ]  =   _risc_inst_add_assign_pointer_handler,
-
-       [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE]  =   _risc_inst_sub_assign_dereference_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX]  =   _risc_inst_sub_assign_array_index_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_POINTER    ]  =   _risc_inst_sub_assign_pointer_handler,
-
-       [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE]  =   _risc_inst_and_assign_dereference_handler,
-       [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX]  =   _risc_inst_and_assign_array_index_handler,
-       [SCF_OP_3AC_AND_ASSIGN_POINTER    ]  =   _risc_inst_and_assign_pointer_handler,
-
-       [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ]  =   _risc_inst_or_assign_dereference_handler,
-       [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ]  =   _risc_inst_or_assign_array_index_handler,
-       [SCF_OP_3AC_OR_ASSIGN_POINTER     ]  =   _risc_inst_or_assign_pointer_handler,
-
-       [SCF_OP_3AC_INC_DEREFERENCE       ]  =   _risc_inst_inc_dereference_handler,
-       [SCF_OP_3AC_INC_ARRAY_INDEX       ]  =   _risc_inst_inc_array_index_handler,
-       [SCF_OP_3AC_INC_POINTER           ]  =   _risc_inst_inc_pointer_handler,
-
-       [SCF_OP_3AC_INC_POST_DEREFERENCE  ]  =   _risc_inst_inc_post_dereference_handler,
-       [SCF_OP_3AC_INC_POST_ARRAY_INDEX  ]  =   _risc_inst_inc_post_array_index_handler,
-       [SCF_OP_3AC_INC_POST_POINTER      ]  =   _risc_inst_inc_post_pointer_handler,
-
-       [SCF_OP_3AC_DEC_DEREFERENCE       ]  =   _risc_inst_dec_dereference_handler,
-       [SCF_OP_3AC_DEC_ARRAY_INDEX       ]  =   _risc_inst_dec_array_index_handler,
-       [SCF_OP_3AC_DEC_POINTER           ]  =   _risc_inst_dec_pointer_handler,
-
-       [SCF_OP_3AC_DEC_POST_DEREFERENCE  ]  =   _risc_inst_dec_post_dereference_handler,
-       [SCF_OP_3AC_DEC_POST_ARRAY_INDEX  ]  =   _risc_inst_dec_post_array_index_handler,
-       [SCF_OP_3AC_DEC_POST_POINTER      ]  =   _risc_inst_dec_post_pointer_handler,
-
        [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX]  =   _risc_inst_address_of_array_index_handler,
        [SCF_OP_3AC_ADDRESS_OF_POINTER    ]  =   _risc_inst_address_of_pointer_handler,
 };
index 629ce91da086efd24ed5c77cb07d9e139b2a463d..072f9dbb02800d852f4824f352c6e501e3e32253 100644 (file)
@@ -1230,38 +1230,6 @@ static risc_rcg_handler_pt  risc_rcg_handlers[SCF_N_3AC_OPS] =
        [SCF_OP_3AC_ASSIGN_ARRAY_INDEX    ]  =  _risc_rcg_assign_array_index_handler,
        [SCF_OP_3AC_ASSIGN_POINTER        ]  =  _risc_rcg_assign_pointer_handler,
 
-       [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE]  =  _risc_rcg_add_assign_dereference_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX]  =  _risc_rcg_add_assign_array_index_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_POINTER    ]  =  _risc_rcg_add_assign_pointer_handler,
-
-       [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE]  =  _risc_rcg_sub_assign_dereference_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX]  =  _risc_rcg_sub_assign_array_index_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_POINTER    ]  =  _risc_rcg_sub_assign_pointer_handler,
-
-       [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE]  =  _risc_rcg_and_assign_dereference_handler,
-       [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX]  =  _risc_rcg_and_assign_array_index_handler,
-       [SCF_OP_3AC_AND_ASSIGN_POINTER    ]  =  _risc_rcg_and_assign_pointer_handler,
-
-       [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ]  =  _risc_rcg_or_assign_dereference_handler,
-       [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ]  =  _risc_rcg_or_assign_array_index_handler,
-       [SCF_OP_3AC_OR_ASSIGN_POINTER     ]  =  _risc_rcg_or_assign_pointer_handler,
-
-       [SCF_OP_3AC_INC_DEREFERENCE       ]  =  _risc_rcg_inc_dereference_handler,
-       [SCF_OP_3AC_INC_ARRAY_INDEX       ]  =  _risc_rcg_inc_array_index_handler,
-       [SCF_OP_3AC_INC_POINTER           ]  =  _risc_rcg_inc_pointer_handler,
-
-       [SCF_OP_3AC_INC_POST_DEREFERENCE  ]  =  _risc_rcg_inc_post_dereference_handler,
-       [SCF_OP_3AC_INC_POST_ARRAY_INDEX  ]  =  _risc_rcg_inc_post_array_index_handler,
-       [SCF_OP_3AC_INC_POST_POINTER      ]  =  _risc_rcg_inc_post_pointer_handler,
-
-       [SCF_OP_3AC_DEC_DEREFERENCE       ]  =  _risc_rcg_dec_dereference_handler,
-       [SCF_OP_3AC_DEC_ARRAY_INDEX       ]  =  _risc_rcg_dec_array_index_handler,
-       [SCF_OP_3AC_DEC_POINTER           ]  =  _risc_rcg_dec_pointer_handler,
-
-       [SCF_OP_3AC_DEC_POST_DEREFERENCE  ]  =  _risc_rcg_dec_post_dereference_handler,
-       [SCF_OP_3AC_DEC_POST_ARRAY_INDEX  ]  =  _risc_rcg_dec_post_array_index_handler,
-       [SCF_OP_3AC_DEC_POST_POINTER      ]  =  _risc_rcg_dec_post_pointer_handler,
-
        [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX]  =  _risc_rcg_address_of_array_index_handler,
        [SCF_OP_3AC_ADDRESS_OF_POINTER    ]  =  _risc_rcg_address_of_pointer_handler,
 };
index 377a9105034193da0513373874bf5bbb7b651293..6ce1a692793740cea1121cb6d08ed36105b676c9 100644 (file)
@@ -129,14 +129,9 @@ int x64_shift_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
 
 int x64_binary_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
 
-int x64_binary_assign_dereference(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-int x64_binary_assign_pointer    (scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-int x64_binary_assign_array_index(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-
-int x64_unary_assign_dereference (scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-int x64_unary_assign_pointer     (scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-int x64_unary_assign_array_index (scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type);
-
+int x64_assign_dereference(scf_native_t* ctx, scf_3ac_code_t* c);
+int x64_assign_pointer    (scf_native_t* ctx, scf_3ac_code_t* c);
+int x64_assign_array_index(scf_native_t* ctx, scf_3ac_code_t* c);
 
 int x64_inst_int_mul(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c, scf_function_t* f);
 int x64_inst_int_div(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c, scf_function_t* f, int mod_flag);
index 726f7601cb595396bef13857182dce4cb0f91d6c..ab0fc3b338b85f7d20fc277ddb5f4f95ded0c1dd 100644 (file)
@@ -1966,18 +1966,6 @@ static int _x64_inst_save_handler(scf_native_t* ctx, scf_3ac_code_t* c)
 static int _x64_inst_##name##_handler(scf_native_t* ctx, scf_3ac_code_t* c) \
 { \
        return x64_binary_assign(ctx, c, SCF_X64_##op); \
-} \
-static int _x64_inst_##name##_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c) \
-{ \
-       return x64_binary_assign_pointer(ctx, c, SCF_X64_##op); \
-} \
-static int _x64_inst_##name##_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       return _x64_inst_assign_array_index(ctx, c, SCF_X64_##op);\
-}\
-static int _x64_inst_##name##_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       return x64_binary_assign_dereference(ctx, c, SCF_X64_##op);\
 }
 
 X64_INST_BINARY_ASSIGN(assign,     MOV)
@@ -1986,6 +1974,19 @@ X64_INST_BINARY_ASSIGN(sub_assign, SUB)
 X64_INST_BINARY_ASSIGN(and_assign, AND)
 X64_INST_BINARY_ASSIGN(or_assign,  OR)
 
+static int _x64_inst_assign_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c)
+{
+       return x64_assign_pointer(ctx, c);
+}
+static int _x64_inst_assign_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)
+{
+       return _x64_inst_assign_array_index(ctx, c, SCF_X64_MOV);
+}
+static int _x64_inst_assign_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* c)
+{
+       return x64_assign_dereference(ctx, c);
+}
+
 #define X64_INST_SHIFT(name, op) \
 static int _x64_inst_##name##_handler(scf_native_t* ctx, scf_3ac_code_t* c) \
 { \
@@ -1998,47 +1999,6 @@ static int _x64_inst_##name##_assign_handler(scf_native_t* ctx, scf_3ac_code_t*
 X64_INST_SHIFT(shl, SHL)
 X64_INST_SHIFT(shr, SHR)
 
-#define X64_INST_UNARY_ASSIGN(name, op) \
-static int _x64_inst_##name##_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c) \
-{ \
-       return x64_unary_assign_pointer(ctx, c, SCF_X64_##op); \
-} \
-static int _x64_inst_##name##_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       return x64_unary_assign_array_index(ctx, c, SCF_X64_##op);\
-}\
-static int _x64_inst_##name##_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       return x64_unary_assign_dereference(ctx, c, SCF_X64_##op);\
-}
-X64_INST_UNARY_ASSIGN(inc, INC)
-X64_INST_UNARY_ASSIGN(dec, DEC)
-
-#define X64_INST_UNARY_POST_ASSIGN(name, op) \
-static int _x64_inst_##name##_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c) \
-{ \
-       int ret = x64_inst_pointer(ctx, c, 0); \
-       if (ret < 0) \
-               return ret; \
-       return x64_unary_assign_pointer(ctx, c, SCF_X64_##op); \
-} \
-static int _x64_inst_##name##_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       int ret = _x64_inst_array_index_handler(ctx, c); \
-       if (ret < 0) \
-               return ret; \
-       return x64_unary_assign_array_index(ctx, c, SCF_X64_##op);\
-}\
-static int _x64_inst_##name##_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* c)\
-{\
-       int ret = x64_inst_dereference(ctx, c); \
-       if (ret < 0) \
-               return ret; \
-       return x64_unary_assign_dereference(ctx, c, SCF_X64_##op);\
-}
-X64_INST_UNARY_POST_ASSIGN(inc_post, INC)
-X64_INST_UNARY_POST_ASSIGN(dec_post, DEC)
-
 static int _x64_inst_address_of_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* c)
 {
        return _x64_inst_array_index(ctx, c, 1);
@@ -2477,38 +2437,6 @@ static x64_inst_handler_pt  x64_inst_handlers[] =
        [SCF_OP_3AC_ASSIGN_ARRAY_INDEX    ]  =  _x64_inst_assign_array_index_handler,
        [SCF_OP_3AC_ASSIGN_POINTER        ]  =  _x64_inst_assign_pointer_handler,
 
-       [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE]  =  _x64_inst_add_assign_dereference_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX]  =  _x64_inst_add_assign_array_index_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_POINTER    ]  =  _x64_inst_add_assign_pointer_handler,
-
-       [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE]  =  _x64_inst_sub_assign_dereference_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX]  =  _x64_inst_sub_assign_array_index_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_POINTER    ]  =  _x64_inst_sub_assign_pointer_handler,
-
-       [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE]  =  _x64_inst_and_assign_dereference_handler,
-       [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX]  =  _x64_inst_and_assign_array_index_handler,
-       [SCF_OP_3AC_AND_ASSIGN_POINTER    ]  =  _x64_inst_and_assign_pointer_handler,
-
-       [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ]  =  _x64_inst_or_assign_dereference_handler,
-       [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ]  =  _x64_inst_or_assign_array_index_handler,
-       [SCF_OP_3AC_OR_ASSIGN_POINTER     ]  =  _x64_inst_or_assign_pointer_handler,
-
-       [SCF_OP_3AC_INC_DEREFERENCE       ]  =  _x64_inst_inc_dereference_handler,
-       [SCF_OP_3AC_INC_ARRAY_INDEX       ]  =  _x64_inst_inc_array_index_handler,
-       [SCF_OP_3AC_INC_POINTER           ]  =  _x64_inst_inc_pointer_handler,
-
-       [SCF_OP_3AC_INC_POST_DEREFERENCE  ]  =  _x64_inst_inc_post_dereference_handler,
-       [SCF_OP_3AC_INC_POST_ARRAY_INDEX  ]  =  _x64_inst_inc_post_array_index_handler,
-       [SCF_OP_3AC_INC_POST_POINTER      ]  =  _x64_inst_inc_post_pointer_handler,
-
-       [SCF_OP_3AC_DEC_DEREFERENCE       ]  =  _x64_inst_dec_dereference_handler,
-       [SCF_OP_3AC_DEC_ARRAY_INDEX       ]  =  _x64_inst_dec_array_index_handler,
-       [SCF_OP_3AC_DEC_POINTER           ]  =  _x64_inst_dec_pointer_handler,
-
-       [SCF_OP_3AC_DEC_POST_DEREFERENCE  ]  =  _x64_inst_dec_post_dereference_handler,
-       [SCF_OP_3AC_DEC_POST_ARRAY_INDEX  ]  =  _x64_inst_dec_post_array_index_handler,
-       [SCF_OP_3AC_DEC_POST_POINTER      ]  =  _x64_inst_dec_post_pointer_handler,
-
        [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX]  =  _x64_inst_address_of_array_index_handler,
        [SCF_OP_3AC_ADDRESS_OF_POINTER    ]  =  _x64_inst_address_of_pointer_handler,
 };
index e7b66e5c7d65ee27052c509456da69377b5cc211..c2c5f5b07ab895afa8ab30c6b59d0dbf4be24576 100644 (file)
@@ -112,52 +112,6 @@ static int _binary_assign_sib_int(x64_sib_t* sib, scf_dag_node_t* src, scf_3ac_c
        return 0;
 }
 
-static int _binary_assign_sib(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type, int nb_srcs, x64_sib_fill_pt fill)
-{
-       if (!c->srcs || c->srcs->size != nb_srcs) {
-               scf_loge("\n");
-               return -EINVAL;
-       }
-
-       scf_x64_context_t*  x64   = ctx->priv;
-       scf_function_t*     f     = x64->f;
-
-       scf_3ac_operand_t*  base  = c->srcs->data[0];
-       scf_3ac_operand_t*  index = c->srcs->data[1];
-       scf_3ac_operand_t*  src   = c->srcs->data[c->srcs->size - 1];
-
-       if (!base || !base->dag_node)
-               return -EINVAL;
-
-       if (!index || !index->dag_node)
-               return -EINVAL;
-
-       if (!src || !src->dag_node)
-               return -EINVAL;
-
-       scf_variable_t* b = base->dag_node->var;
-       assert(b->nb_pointers > 0 || b->nb_dimentions > 0 || b->type >= SCF_STRUCT);
-
-       if (!c->instructions) {
-               c->instructions = scf_vector_alloc();
-               if (!c->instructions)
-                       return -ENOMEM;
-       }
-
-       scf_variable_t* v   = src->dag_node->var;
-       x64_sib_t       sib = {0};
-
-       int ret = fill(&sib, base->dag_node, index->dag_node, c, f);
-       if (ret < 0)
-               return ret;
-
-       int is_float = scf_variable_float(v);
-       if (is_float)
-               return _binary_assign_sib_float(sib.base, sib.index, sib.scale, sib.disp, src->dag_node, c, f, OpCode_type);
-
-       return _binary_assign_sib_int(&sib, src->dag_node, c, f, OpCode_type);
-}
-
 static int _binary_SIB2G(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type, int nb_srcs, x64_sib_fill_pt fill)
 {
        if (!c->dsts || c->dsts->size != 1)
@@ -261,19 +215,175 @@ int x64_binary_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type)
        return x64_inst_op2(OpCode_type, dst->dag_node, src->dag_node, c, f);
 }
 
-int x64_binary_assign_dereference(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type)
+int x64_assign_dereference(scf_native_t* ctx, scf_3ac_code_t* c)
 {
-       return _binary_assign_sib(ctx, c, OpCode_type, 2, x64_dereference_reg);
+       if (!c->srcs || c->srcs->size != 2) {
+               scf_loge("\n");
+               return -EINVAL;
+       }
+
+       scf_x64_context_t*  x64   = ctx->priv;
+       scf_function_t*     f     = x64->f;
+       scf_3ac_operand_t*  base  = c->srcs->data[0];
+       scf_3ac_operand_t*  src   = c->srcs->data[1];
+
+       if (!base || !base->dag_node)
+               return -EINVAL;
+
+       if (!src || !src->dag_node)
+               return -EINVAL;
+
+       scf_variable_t* b = base->dag_node->var;
+       assert(b->nb_pointers > 0 || b->nb_dimentions > 0 || b->type >= SCF_STRUCT);
+
+       if (!c->instructions) {
+               c->instructions = scf_vector_alloc();
+               if (!c->instructions)
+                       return -ENOMEM;
+       }
+
+       scf_variable_t* v   = src->dag_node->var;
+       x64_sib_t       sib = {0};
+
+       int ret = x64_dereference_reg(&sib, base->dag_node, NULL, c, f);
+       if (ret < 0)
+               return ret;
+
+       int is_float = scf_variable_float(v);
+       if (is_float)
+               return _binary_assign_sib_float(sib.base, sib.index, sib.scale, sib.disp, src->dag_node, c, f, SCF_X64_MOV);
+
+       return _binary_assign_sib_int(&sib, src->dag_node, c, f, SCF_X64_MOV);
 }
 
-int x64_inst_dereference(scf_native_t* ctx, scf_3ac_code_t* c)
+int x64_assign_pointer(scf_native_t* ctx, scf_3ac_code_t* c)
 {
-       return _binary_SIB2G(ctx, c, SCF_X64_MOV, 1, x64_dereference_reg);
+       if (!c->srcs || c->srcs->size != 3) {
+               scf_loge("\n");
+               return -EINVAL;
+       }
+
+       scf_x64_context_t*  x64    = ctx->priv;
+       scf_function_t*     f      = x64->f;
+       scf_3ac_operand_t*  base   = c->srcs->data[0];
+       scf_3ac_operand_t*  member = c->srcs->data[1];
+       scf_3ac_operand_t*  src    = c->srcs->data[2];
+
+       if (!base || !base->dag_node)
+               return -EINVAL;
+
+       if (!member || !member->dag_node)
+               return -EINVAL;
+
+       if (!src || !src->dag_node)
+               return -EINVAL;
+
+       scf_variable_t* b   = base->dag_node->var;
+       scf_variable_t* vm  = member->dag_node->var;
+       scf_variable_t* vs  = src->dag_node->var;
+       scf_register_t* rs  = NULL;
+       scf_register_t* r   = NULL;
+       x64_sib_t       sib = {0};
+
+       assert(b->nb_pointers > 0 || b->nb_dimentions > 0 || b->type >= SCF_STRUCT);
+
+       if (!c->instructions) {
+               c->instructions = scf_vector_alloc();
+               if (!c->instructions)
+                       return -ENOMEM;
+       }
+
+       int ret = x64_pointer_reg(&sib, base->dag_node, member->dag_node, c, f);
+       if (ret < 0)
+               return ret;
+
+       int is_float = scf_variable_float(vs);
+       if (is_float)
+               return _binary_assign_sib_float(sib.base, sib.index, sib.scale, sib.disp, src->dag_node, c, f, SCF_X64_MOV);
+
+       int dsize = sib.size;
+       int vsize = x64_variable_size(vs);
+
+       assert(dsize <= vsize);
+
+       if (0 == src->dag_node->color)
+               src->dag_node->color = -1;
+
+       X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
+
+       rs = x64_find_register_color_bytes(rs->color, dsize);
+
+       scf_instruction_t*  inst;
+       scf_x64_OpCode_t*   mov;
+       scf_x64_OpCode_t*   shl;
+       scf_x64_OpCode_t*   shr;
+       scf_x64_OpCode_t*   and;
+       scf_x64_OpCode_t*   push;
+       scf_x64_OpCode_t*   pop;
+
+       mov = x64_find_OpCode(SCF_X64_MOV, dsize, dsize, SCF_X64_G2E);
+
+       if (vm->bit_size > 0) {
+               uint64_t mask = ((1ULL << vm->bit_size) - 1) << vm->bit_offset;
+               mask = ~mask;
+
+               push = x64_find_OpCode(SCF_X64_PUSH, 8,     8,     SCF_X64_G);
+               pop  = x64_find_OpCode(SCF_X64_POP,  8,     8,     SCF_X64_G);
+               mov  = x64_find_OpCode(SCF_X64_MOV,  dsize, dsize, SCF_X64_I2G);
+               and  = x64_find_OpCode(SCF_X64_AND,  dsize, dsize, SCF_X64_G2E);
+
+               r    = x64_find_register_color_bytes(rs->color, 8);
+               inst = x64_make_inst_G(push, r);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+
+               inst = x64_make_inst_I2G(mov, rs, (uint8_t*)&mask, dsize);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+
+               if (sib.index)
+                       inst = x64_make_inst_G2SIB(and, sib.base, sib.index, sib.scale, sib.disp, rs);
+               else
+                       inst = x64_make_inst_G2P(and, sib.base, sib.disp, rs);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+
+               inst = x64_make_inst_G(pop, r);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+
+               int imm = (rs->bytes << 3) - vm->bit_size;
+               assert(imm > 0);
+
+               shl  = x64_find_OpCode(SCF_X64_SHL, 1, rs->bytes, SCF_X64_I2E);
+               shr  = x64_find_OpCode(SCF_X64_SHR, 1, rs->bytes, SCF_X64_I2E);
+
+               inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&imm, 1);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+
+               imm -= vm->bit_offset;
+               assert(imm >= 0);
+
+               if (imm > 0) {
+                       inst = x64_make_inst_I2E(shr, rs, (uint8_t*)&imm, 1);
+                       X64_INST_ADD_CHECK(c->instructions, inst);
+               }
+
+               mov = x64_find_OpCode(SCF_X64_OR, dsize, dsize, SCF_X64_G2E);
+       }
+
+       if (!mov) {
+               scf_loge("\n");
+               return -EINVAL;
+       }
+
+       if (sib.index)
+               inst = x64_make_inst_G2SIB(mov, sib.base, sib.index, sib.scale, sib.disp, rs);
+       else
+               inst = x64_make_inst_G2P(mov, sib.base, sib.disp, rs);
+       X64_INST_ADD_CHECK(c->instructions, inst);
+       return 0;
 }
 
-int x64_binary_assign_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type)
+int x64_inst_dereference(scf_native_t* ctx, scf_3ac_code_t* c)
 {
-       return _binary_assign_sib(ctx, c, OpCode_type, 3, x64_pointer_reg);
+       return _binary_SIB2G(ctx, c, SCF_X64_MOV, 1, x64_dereference_reg);
 }
 
 int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag)
@@ -312,6 +422,8 @@ int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag)
 
        scf_x64_OpCode_t*   lea;
        scf_x64_OpCode_t*   mov;
+       scf_x64_OpCode_t*   shl;
+       scf_x64_OpCode_t*   shr;
        scf_instruction_t*  inst;
 
        int ret = x64_select_reg(&rd, dst->dag_node, c, f, 0);
@@ -335,11 +447,11 @@ int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag)
                int is_float = scf_variable_float(vd);
                if (is_float) {
                        if (SCF_VAR_FLOAT == vd->type)
-                               mov  = x64_find_OpCode(SCF_X64_MOVSS, rd->bytes, rd->bytes, SCF_X64_E2G);
+                               mov = x64_find_OpCode(SCF_X64_MOVSS, rd->bytes, rd->bytes, SCF_X64_E2G);
                        else if (SCF_VAR_DOUBLE == vd->type)
-                               mov  = x64_find_OpCode(SCF_X64_MOVSD, rd->bytes, rd->bytes, SCF_X64_E2G);
+                               mov = x64_find_OpCode(SCF_X64_MOVSD, rd->bytes, rd->bytes, SCF_X64_E2G);
                } else
-                       mov  = x64_find_OpCode(SCF_X64_MOV,   rd->bytes, rd->bytes, SCF_X64_E2G);
+                       mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_E2G);
        }
 
        if (sib.index) {
@@ -349,6 +461,23 @@ int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag)
                inst = x64_make_inst_P2G(mov, rd, sib.base, sib.disp);
                X64_INST_ADD_CHECK(c->instructions, inst);
        }
+
+       if (vm->bit_size > 0) {
+               int imm = (rd->bytes << 3) - vm->bit_size - vm->bit_offset;
+               assert(imm >= 0);
+
+               shl = x64_find_OpCode(SCF_X64_SHL, 1, rd->bytes, SCF_X64_I2E);
+               shr = x64_find_OpCode(SCF_X64_SHR, 1, rd->bytes, SCF_X64_I2E);
+
+               if (imm > 0) {
+                       inst = x64_make_inst_I2E(shl, rd, (uint8_t*)&imm, 1);
+                       X64_INST_ADD_CHECK(c->instructions, inst);
+               }
+
+               imm += vm->bit_offset;
+               inst = x64_make_inst_I2E(shr, rd, (uint8_t*)&imm, 1);
+               X64_INST_ADD_CHECK(c->instructions, inst);
+       }
+
        return 0;
 }
-
index c454bac9b90af2c434a26f1cbe1951958f09fc3f..976e29fbc41fbbdc5ea15b173bc0c5ca50bf3c56 100644 (file)
@@ -117,9 +117,12 @@ static int _x64_peephole_mov(scf_vector_t* std_insts, scf_instruction_t* inst)
                                if (std->src.base)
                                        inst2  = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->src.base);
                                else {
-                                       OpCode = x64_find_OpCode(inst->OpCode->type, std->src.imm_size, inst->dst.base->bytes, SCF_X64_I2G);
+                                       OpCode = x64_find_OpCode(inst->OpCode->type, inst->dst.base->bytes, inst->dst.base->bytes, SCF_X64_I2G);
 
-                                       inst2  = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&std->src.imm, std->src.imm_size);
+                                       if (std->src.imm_size < inst->dst.base->bytes)
+                                               std->src.imm = scf_zero_extend(std->src.imm, std->src.imm_size);
+
+                                       inst2  = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&std->src.imm, inst->dst.base->bytes);
                                }
                                if (!inst2)
                                        return -ENOMEM;
index 2e356c81f329681091134bfd0835630913466362..bb0d7280fd42f42d4890e061e6df9a895174cf67 100644 (file)
@@ -1362,38 +1362,6 @@ static x64_rcg_handler_pt  x64_rcg_handlers[SCF_N_3AC_OPS] =
        [SCF_OP_3AC_ASSIGN_ARRAY_INDEX    ]  =  _x64_rcg_assign_array_index_handler,
        [SCF_OP_3AC_ASSIGN_POINTER        ]  =  _x64_rcg_assign_pointer_handler,
 
-       [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE]  =  _x64_rcg_add_assign_dereference_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX]  =  _x64_rcg_add_assign_array_index_handler,
-       [SCF_OP_3AC_ADD_ASSIGN_POINTER    ]  =  _x64_rcg_add_assign_pointer_handler,
-
-       [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE]  =  _x64_rcg_sub_assign_dereference_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX]  =  _x64_rcg_sub_assign_array_index_handler,
-       [SCF_OP_3AC_SUB_ASSIGN_POINTER    ]  =  _x64_rcg_sub_assign_pointer_handler,
-
-       [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE]  =  _x64_rcg_and_assign_dereference_handler,
-       [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX]  =  _x64_rcg_and_assign_array_index_handler,
-       [SCF_OP_3AC_AND_ASSIGN_POINTER    ]  =  _x64_rcg_and_assign_pointer_handler,
-
-       [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ]  =  _x64_rcg_or_assign_dereference_handler,
-       [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ]  =  _x64_rcg_or_assign_array_index_handler,
-       [SCF_OP_3AC_OR_ASSIGN_POINTER     ]  =  _x64_rcg_or_assign_pointer_handler,
-
-       [SCF_OP_3AC_INC_DEREFERENCE       ]  =  _x64_rcg_inc_dereference_handler,
-       [SCF_OP_3AC_INC_ARRAY_INDEX       ]  =  _x64_rcg_inc_array_index_handler,
-       [SCF_OP_3AC_INC_POINTER           ]  =  _x64_rcg_inc_pointer_handler,
-
-       [SCF_OP_3AC_INC_POST_DEREFERENCE  ]  =  _x64_rcg_inc_post_dereference_handler,
-       [SCF_OP_3AC_INC_POST_ARRAY_INDEX  ]  =  _x64_rcg_inc_post_array_index_handler,
-       [SCF_OP_3AC_INC_POST_POINTER      ]  =  _x64_rcg_inc_post_pointer_handler,
-
-       [SCF_OP_3AC_DEC_DEREFERENCE       ]  =  _x64_rcg_dec_dereference_handler,
-       [SCF_OP_3AC_DEC_ARRAY_INDEX       ]  =  _x64_rcg_dec_array_index_handler,
-       [SCF_OP_3AC_DEC_POINTER           ]  =  _x64_rcg_dec_pointer_handler,
-
-       [SCF_OP_3AC_DEC_POST_DEREFERENCE  ]  =  _x64_rcg_dec_post_dereference_handler,
-       [SCF_OP_3AC_DEC_POST_ARRAY_INDEX  ]  =  _x64_rcg_dec_post_array_index_handler,
-       [SCF_OP_3AC_DEC_POST_POINTER      ]  =  _x64_rcg_dec_post_pointer_handler,
-
        [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX]  =  _x64_rcg_address_of_array_index_handler,
        [SCF_OP_3AC_ADDRESS_OF_POINTER    ]  =  _x64_rcg_address_of_pointer_handler,
 };
index f15750877cee74a5e4484311273615915f047e05..331d25d99b885677cff09110932616930a7a61a8 100644 (file)
@@ -516,6 +516,8 @@ int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_
        scf_variable_t*     v    = dn->var;
        scf_rela_t*         rela = NULL;
        scf_x64_OpCode_t*   mov;
+       scf_x64_OpCode_t*   and;
+       scf_x64_OpCode_t*   shl;
        scf_instruction_t*  inst;
 
        int var_size = x64_variable_size(v);
@@ -563,12 +565,13 @@ int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_
 
        if (is_float) {
                if (SCF_VAR_FLOAT == dn->var->type)
-                       mov  = x64_find_OpCode(SCF_X64_MOVSS, r->bytes, r->bytes, SCF_X64_G2E);
+                       mov = x64_find_OpCode(SCF_X64_MOVSS, r->bytes, r->bytes, SCF_X64_G2E);
                else if (SCF_VAR_DOUBLE == dn->var->type)
-                       mov  = x64_find_OpCode(SCF_X64_MOVSD, r->bytes, r->bytes, SCF_X64_G2E);
+                       mov = x64_find_OpCode(SCF_X64_MOVSD, r->bytes, r->bytes, SCF_X64_G2E);
        } else {
-               mov  = x64_find_OpCode(SCF_X64_MOV, r->bytes, r->bytes, SCF_X64_G2E);
                scf_logd("v->size: %d\n", v->size);
+
+               mov = x64_find_OpCode(SCF_X64_MOV, r->bytes, r->bytes, SCF_X64_G2E);
        }
 
        inst = x64_make_inst_G2M(&rela, mov, v, NULL, r);
@@ -927,6 +930,8 @@ int x64_load_reg(scf_register_t* r, scf_dag_node_t* dn, scf_3ac_code_t* c, scf_f
                return 0;
 
        scf_x64_OpCode_t*   mov;
+       scf_x64_OpCode_t*   shr;
+       scf_x64_OpCode_t*   and;
        scf_instruction_t*  inst;
        scf_rela_t*         rela = NULL;
 
index cd4cdfdd633e0ecc2ef982d2fa7323f0ccb1db53..790ce54961d727bb4a82b9d6dda9af948f00ebee 100644 (file)
@@ -93,9 +93,9 @@ typedef struct {
        scf_register_t* base;
        scf_register_t* index;
 
-       int32_t             scale;
-       int32_t             disp;
-       int32_t             size;
+       int32_t         scale;
+       int32_t         disp;
+       int32_t         size;
 } x64_sib_t;
 
 static inline int x64_variable_size(scf_variable_t* v)
index db09080e864b558817437832f67d94b7ab1c6dbd..2e8794470281593f6ec2cde9a1d26dca39d99067 100644 (file)
@@ -93,6 +93,7 @@ static int _class_calculate_size(scf_dfa_t* dfa, scf_type_t* s)
 {
        scf_variable_t* v;
 
+       int bits = 0;
        int size = 0;
        int i;
        int j;
@@ -133,16 +134,55 @@ static int _class_calculate_size(scf_dfa_t* dfa, scf_type_t* s)
                        }
 
                        size = v->offset + v->size * v->capacity;
-               } else
-                       size = v->offset + v->size;
+                       bits = size << 3;
+               } else {
+                       if (v->bit_size > 0) {
+                               int align = v->size << 3;
+                               int used  = bits & (align - 1);
+                               int rest  = align - used;
+
+                               if (rest < v->bit_size) {
+                                       bits += rest;
+                                       used  = 0;
+                                       rest  = align;
+                               }
+
+                               v->offset     = (bits >> 3) & ~(v->size - 1);
+                               v->bit_offset =  used;
+
+                               scf_logd("bits: %d, align: %d, used: %d, rest: %d, v->offset: %d\n", bits, align, used, rest, v->offset);
+
+                               bits = (v->offset << 3) + v->bit_offset + v->bit_size;
+                       } else
+                               bits = (v->offset + v->size) << 3;
 
-               scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d\n",
-                               s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity);
+                       if (size < v->offset + v->size)
+                               size = v->offset + v->size;
+               }
+
+               scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n",
+                               s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size);
        }
-       s->size = size;
+
+       switch (size) {
+               case 1:
+                       s->size = size;
+                       break;
+               case 2:
+                       s->size = (size + 1) & ~0x1;
+                       break;
+               case 3:
+               case 4:
+                       s->size = (size + 3) & ~0x3;
+                       break;
+               default:
+                       s->size = (size + 7) & ~0x7;
+                       break;
+       };
+
        s->node.define_flag = 1;
 
-       scf_logi("class '%s', size: %d\n", s->name->data, s->size);
+       scf_logi("class '%s', s->size: %d, size: %d\n", s->name->data, s->size, size);
        return 0;
 }
 
index dd193de31c669706f8d6cd2715b0c8600473740c..b911d12492d4f0158804e1fdbaecec9be0d2dab3 100644 (file)
@@ -584,6 +584,45 @@ static int _var_action_assign(scf_dfa_t* dfa, scf_vector_t* words, void* data)
        return SCF_DFA_NEXT_WORD;
 }
 
+static int _var_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data)
+{
+       scf_parse_t*  parse = dfa->priv;
+       dfa_data_t*   d     = data;
+
+       if (_var_add_var(dfa, d) < 0) {
+               scf_loge("add var error\n");
+               return SCF_DFA_ERROR;
+       }
+
+       if (!d->current_var) {
+               scf_loge("\n");
+               return SCF_DFA_ERROR;
+       }
+
+       return SCF_DFA_NEXT_WORD;
+}
+
+static int _var_action_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data)
+{
+       scf_parse_t*    parse = dfa->priv;
+       dfa_data_t*     d     = data;
+       scf_lex_word_t* w     = words->data[words->size - 1];
+
+       if (!d->current_var) {
+               scf_loge("\n");
+               return SCF_DFA_ERROR;
+       }
+
+       if (!d->current_var->member_flag) {
+               scf_loge("bits var '%s' must be a member of struct, file: %s, line: %d\n",
+                               d->current_var->w->text->data, d->current_var->w->file->data, d->current_var->w->line);
+               return SCF_DFA_ERROR;
+       }
+
+       d->current_var->bit_size = w->data.u32;
+       return SCF_DFA_NEXT_WORD;
+}
+
 static int _var_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
        scf_parse_t*  parse = dfa->priv;
@@ -678,13 +717,16 @@ static int _var_action_rs(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _dfa_init_module_var(scf_dfa_t* dfa)
 {
-       SCF_DFA_MODULE_NODE(dfa, var, comma,     scf_dfa_is_comma,     _var_action_comma);
-       SCF_DFA_MODULE_NODE(dfa, var, semicolon, scf_dfa_is_semicolon, _var_action_semicolon);
+       SCF_DFA_MODULE_NODE(dfa, var, comma,     scf_dfa_is_comma,         _var_action_comma);
+       SCF_DFA_MODULE_NODE(dfa, var, semicolon, scf_dfa_is_semicolon,     _var_action_semicolon);
+
+       SCF_DFA_MODULE_NODE(dfa, var, ls,        scf_dfa_is_ls,            _var_action_ls);
+       SCF_DFA_MODULE_NODE(dfa, var, rs,        scf_dfa_is_rs,            _var_action_rs);
 
-       SCF_DFA_MODULE_NODE(dfa, var, ls,        scf_dfa_is_ls,        _var_action_ls);
-       SCF_DFA_MODULE_NODE(dfa, var, rs,        scf_dfa_is_rs,        _var_action_rs);
+       SCF_DFA_MODULE_NODE(dfa, var, assign,    scf_dfa_is_assign,        _var_action_assign);
 
-       SCF_DFA_MODULE_NODE(dfa, var, assign,    scf_dfa_is_assign,    _var_action_assign);
+       SCF_DFA_MODULE_NODE(dfa, var, colon,     scf_dfa_is_colon,         _var_action_colon);
+       SCF_DFA_MODULE_NODE(dfa, var, bits,      scf_dfa_is_const_integer, _var_action_bits);
 
        return SCF_DFA_OK;
 }
@@ -698,13 +740,16 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa)
        SCF_DFA_GET_MODULE_NODE(dfa, var,    rs,        rs);
        SCF_DFA_GET_MODULE_NODE(dfa, var,    assign,    assign);
 
+       SCF_DFA_GET_MODULE_NODE(dfa, var,    colon,     colon);
+       SCF_DFA_GET_MODULE_NODE(dfa, var,    bits,      bits);
+
        SCF_DFA_GET_MODULE_NODE(dfa, type,   star,      star);
        SCF_DFA_GET_MODULE_NODE(dfa, type,   identity,  identity);
 
        SCF_DFA_GET_MODULE_NODE(dfa, expr,   entry,     expr);
 
        SCF_DFA_GET_MODULE_NODE(dfa, init_data, entry,  init_data);
-       SCF_DFA_GET_MODULE_NODE(dfa, init_data, rb,     init_data_rb);
+       SCF_DFA_GET_MODULE_NODE(dfa, init_data, rb,     init_rb);
 
 
        scf_dfa_node_add_child(identity,  comma);
@@ -720,6 +765,11 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa)
        scf_dfa_node_add_child(rs,        comma);
        scf_dfa_node_add_child(rs,        semicolon);
 
+       // bits
+       scf_dfa_node_add_child(identity,  colon);
+       scf_dfa_node_add_child(colon,     bits);
+       scf_dfa_node_add_child(bits,      semicolon);
+
        // var init
        scf_dfa_node_add_child(rs,        assign);
        scf_dfa_node_add_child(identity,  assign);
@@ -730,9 +780,9 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa)
        scf_dfa_node_add_child(expr,      semicolon);
 
        // struct or array init
-       scf_dfa_node_add_child(assign,       init_data);
-       scf_dfa_node_add_child(init_data_rb, comma);
-       scf_dfa_node_add_child(init_data_rb, semicolon);
+       scf_dfa_node_add_child(assign,    init_data);
+       scf_dfa_node_add_child(init_rb,   comma);
+       scf_dfa_node_add_child(init_rb,   semicolon);
 
        scf_dfa_node_add_child(identity,  semicolon);
        return 0;