stdatomic: c11 prefix; migrate to models macros

This commit is contained in:
Dmitry Selyutin 2021-01-27 13:32:48 +03:00
parent 5053fd03a7
commit 65773a5300
2 changed files with 52 additions and 66 deletions

View File

@ -5727,20 +5727,24 @@ static void parse_builtin_params(int nc, const char *args)
nocode_wanted--;
}
static void parse_memory_model(int mtok)
static inline int is_memory_model(const SValue *sv)
{
next();
switch (mtok) {
case TOK___ATOMIC_RELAXED: vpushs(0); break;
case TOK___ATOMIC_CONSUME: vpushs(1); break;
case TOK___ATOMIC_ACQUIRE: vpushs(2); break;
case TOK___ATOMIC_RELEASE: vpushs(3); break;
case TOK___ATOMIC_ACQ_REL: vpushs(4); break;
case TOK___ATOMIC_SEQ_CST: vpushs(5); break;
}
vtop->type.t |= (VT_UNSIGNED | VT_MEMMODEL);
/*
* FIXME
* The memory models should better be backed by an enumeration.
*
* const int t = sv->type.t;
*
* if (!IS_ENUM_VAL(t))
* return 0;
*
* if (!(t & VT_STATIC))
* return 0;
*
* Ideally we should check whether the model matches 1:1.
* If it is possible, we should check by the name of the value.
*/
return (((t & VT_BTYPE) == VT_INT) && (sv->c.i < 6));
}
static void parse_atomic(int atok)
@ -5762,17 +5766,17 @@ static void parse_atomic(int atok)
* v -- value
* m -- memory model
*/
{TOK___atomic_init, "-a"},
{TOK___atomic_store, "-avm"},
{TOK___atomic_load, "am"},
{TOK___atomic_exchange, "avm"},
{TOK___atomic_compare_exchange_strong, "apvmm"},
{TOK___atomic_compare_exchange_weak, "apvmm"},
{TOK___atomic_fetch_add, "avm"},
{TOK___atomic_fetch_sub, "avm"},
{TOK___atomic_fetch_or, "avm"},
{TOK___atomic_fetch_xor, "avm"},
{TOK___atomic_fetch_and, "avm"},
{TOK___c11_atomic_init, "-a"},
{TOK___c11_atomic_store, "-avm"},
{TOK___c11_atomic_load, "am"},
{TOK___c11_atomic_exchange, "avm"},
{TOK___c11_atomic_compare_exchange_strong, "apvmm"},
{TOK___c11_atomic_compare_exchange_weak, "apvmm"},
{TOK___c11_atomic_fetch_add, "avm"},
{TOK___c11_atomic_fetch_sub, "avm"},
{TOK___c11_atomic_fetch_or, "avm"},
{TOK___c11_atomic_fetch_xor, "avm"},
{TOK___c11_atomic_fetch_and, "avm"},
};
next();
@ -5837,8 +5841,8 @@ static void parse_atomic(int atok)
break;
case 'm':
if ((vtop->type.t & VT_MEMMODEL) != VT_MEMMODEL)
expect_arg("memory model constant", arg);
if (!is_memory_model(vtop))
expect_arg("memory model", arg);
vtop->type.t &= ~VT_MEMMODEL;
break;
@ -6234,28 +6238,18 @@ ST_FUNC void unary(void)
}
#endif
/* memory models */
case TOK___ATOMIC_RELAXED:
case TOK___ATOMIC_CONSUME:
case TOK___ATOMIC_ACQUIRE:
case TOK___ATOMIC_RELEASE:
case TOK___ATOMIC_ACQ_REL:
case TOK___ATOMIC_SEQ_CST:
parse_memory_model(tok);
break;
/* atomic operations */
case TOK___atomic_init:
case TOK___atomic_store:
case TOK___atomic_load:
case TOK___atomic_exchange:
case TOK___atomic_compare_exchange_strong:
case TOK___atomic_compare_exchange_weak:
case TOK___atomic_fetch_add:
case TOK___atomic_fetch_sub:
case TOK___atomic_fetch_or:
case TOK___atomic_fetch_xor:
case TOK___atomic_fetch_and:
case TOK___c11_atomic_init:
case TOK___c11_atomic_store:
case TOK___c11_atomic_load:
case TOK___c11_atomic_exchange:
case TOK___c11_atomic_compare_exchange_strong:
case TOK___c11_atomic_compare_exchange_weak:
case TOK___c11_atomic_fetch_add:
case TOK___c11_atomic_fetch_sub:
case TOK___c11_atomic_fetch_or:
case TOK___c11_atomic_fetch_xor:
case TOK___c11_atomic_fetch_and:
parse_atomic(tok);
break;

View File

@ -174,14 +174,6 @@
DEF(TOK_builtin_va_start, "__builtin_va_start")
#endif
/* memory models */
DEF(TOK___ATOMIC_RELAXED, "__ATOMIC_RELAXED")
DEF(TOK___ATOMIC_CONSUME, "__ATOMIC_CONSUME")
DEF(TOK___ATOMIC_ACQUIRE, "__ATOMIC_ACQUIRE")
DEF(TOK___ATOMIC_RELEASE, "__ATOMIC_RELEASE")
DEF(TOK___ATOMIC_ACQ_REL, "__ATOMIC_ACQ_REL")
DEF(TOK___ATOMIC_SEQ_CST, "__ATOMIC_SEQ_CST")
#define DEF_ATOMIC(id, str) \
DEF(id, str) \
DEF(id##_8, str "_8") \
@ -190,17 +182,17 @@
DEF(id##_64, str "_64")
/* atomic operations */
DEF_ATOMIC(TOK___atomic_init, "__atomic_init")
DEF_ATOMIC(TOK___atomic_store, "__atomic_store")
DEF_ATOMIC(TOK___atomic_load, "__atomic_load")
DEF_ATOMIC(TOK___atomic_exchange, "__atomic_exchange")
DEF_ATOMIC(TOK___atomic_compare_exchange_strong, "__atomic_compare_exchange_strong")
DEF_ATOMIC(TOK___atomic_compare_exchange_weak, "__atomic_compare_exchange_weak")
DEF_ATOMIC(TOK___atomic_fetch_add, "__atomic_fetch_add")
DEF_ATOMIC(TOK___atomic_fetch_sub, "__atomic_fetch_sub")
DEF_ATOMIC(TOK___atomic_fetch_or, "__atomic_fetch_or")
DEF_ATOMIC(TOK___atomic_fetch_xor, "__atomic_fetch_xor")
DEF_ATOMIC(TOK___atomic_fetch_and, "__atomic_fetch_and")
DEF_ATOMIC(TOK___c11_atomic_init, "__c11_atomic_init")
DEF_ATOMIC(TOK___c11_atomic_store, "__c11_atomic_store")
DEF_ATOMIC(TOK___c11_atomic_load, "__c11_atomic_load")
DEF_ATOMIC(TOK___c11_atomic_exchange, "__c11_atomic_exchange")
DEF_ATOMIC(TOK___c11_atomic_compare_exchange_strong, "__c11_atomic_compare_exchange_strong")
DEF_ATOMIC(TOK___c11_atomic_compare_exchange_weak, "__c11_atomic_compare_exchange_weak")
DEF_ATOMIC(TOK___c11_atomic_fetch_add, "__c11_atomic_fetch_add")
DEF_ATOMIC(TOK___c11_atomic_fetch_sub, "__c11_atomic_fetch_sub")
DEF_ATOMIC(TOK___c11_atomic_fetch_or, "__c11_atomic_fetch_or")
DEF_ATOMIC(TOK___c11_atomic_fetch_xor, "__c11_atomic_fetch_xor")
DEF_ATOMIC(TOK___c11_atomic_fetch_and, "__c11_atomic_fetch_and")
#undef DEF_ATOMIC