mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-30 08:38:41 +08:00
stdatomic: c11 prefix; migrate to models macros
This commit is contained in:
parent
5053fd03a7
commit
65773a5300
88
tccgen.c
88
tccgen.c
@ -5727,20 +5727,24 @@ static void parse_builtin_params(int nc, const char *args)
|
|||||||
nocode_wanted--;
|
nocode_wanted--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_memory_model(int mtok)
|
static inline int is_memory_model(const SValue *sv)
|
||||||
{
|
{
|
||||||
next();
|
/*
|
||||||
|
* FIXME
|
||||||
switch (mtok) {
|
* The memory models should better be backed by an enumeration.
|
||||||
case TOK___ATOMIC_RELAXED: vpushs(0); break;
|
*
|
||||||
case TOK___ATOMIC_CONSUME: vpushs(1); break;
|
* const int t = sv->type.t;
|
||||||
case TOK___ATOMIC_ACQUIRE: vpushs(2); break;
|
*
|
||||||
case TOK___ATOMIC_RELEASE: vpushs(3); break;
|
* if (!IS_ENUM_VAL(t))
|
||||||
case TOK___ATOMIC_ACQ_REL: vpushs(4); break;
|
* return 0;
|
||||||
case TOK___ATOMIC_SEQ_CST: vpushs(5); break;
|
*
|
||||||
}
|
* if (!(t & VT_STATIC))
|
||||||
|
* return 0;
|
||||||
vtop->type.t |= (VT_UNSIGNED | VT_MEMMODEL);
|
*
|
||||||
|
* 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)
|
static void parse_atomic(int atok)
|
||||||
@ -5762,17 +5766,17 @@ static void parse_atomic(int atok)
|
|||||||
* v -- value
|
* v -- value
|
||||||
* m -- memory model
|
* m -- memory model
|
||||||
*/
|
*/
|
||||||
{TOK___atomic_init, "-a"},
|
{TOK___c11_atomic_init, "-a"},
|
||||||
{TOK___atomic_store, "-avm"},
|
{TOK___c11_atomic_store, "-avm"},
|
||||||
{TOK___atomic_load, "am"},
|
{TOK___c11_atomic_load, "am"},
|
||||||
{TOK___atomic_exchange, "avm"},
|
{TOK___c11_atomic_exchange, "avm"},
|
||||||
{TOK___atomic_compare_exchange_strong, "apvmm"},
|
{TOK___c11_atomic_compare_exchange_strong, "apvmm"},
|
||||||
{TOK___atomic_compare_exchange_weak, "apvmm"},
|
{TOK___c11_atomic_compare_exchange_weak, "apvmm"},
|
||||||
{TOK___atomic_fetch_add, "avm"},
|
{TOK___c11_atomic_fetch_add, "avm"},
|
||||||
{TOK___atomic_fetch_sub, "avm"},
|
{TOK___c11_atomic_fetch_sub, "avm"},
|
||||||
{TOK___atomic_fetch_or, "avm"},
|
{TOK___c11_atomic_fetch_or, "avm"},
|
||||||
{TOK___atomic_fetch_xor, "avm"},
|
{TOK___c11_atomic_fetch_xor, "avm"},
|
||||||
{TOK___atomic_fetch_and, "avm"},
|
{TOK___c11_atomic_fetch_and, "avm"},
|
||||||
};
|
};
|
||||||
|
|
||||||
next();
|
next();
|
||||||
@ -5837,8 +5841,8 @@ static void parse_atomic(int atok)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if ((vtop->type.t & VT_MEMMODEL) != VT_MEMMODEL)
|
if (!is_memory_model(vtop))
|
||||||
expect_arg("memory model constant", arg);
|
expect_arg("memory model", arg);
|
||||||
vtop->type.t &= ~VT_MEMMODEL;
|
vtop->type.t &= ~VT_MEMMODEL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -6234,28 +6238,18 @@ ST_FUNC void unary(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#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 */
|
/* atomic operations */
|
||||||
case TOK___atomic_init:
|
case TOK___c11_atomic_init:
|
||||||
case TOK___atomic_store:
|
case TOK___c11_atomic_store:
|
||||||
case TOK___atomic_load:
|
case TOK___c11_atomic_load:
|
||||||
case TOK___atomic_exchange:
|
case TOK___c11_atomic_exchange:
|
||||||
case TOK___atomic_compare_exchange_strong:
|
case TOK___c11_atomic_compare_exchange_strong:
|
||||||
case TOK___atomic_compare_exchange_weak:
|
case TOK___c11_atomic_compare_exchange_weak:
|
||||||
case TOK___atomic_fetch_add:
|
case TOK___c11_atomic_fetch_add:
|
||||||
case TOK___atomic_fetch_sub:
|
case TOK___c11_atomic_fetch_sub:
|
||||||
case TOK___atomic_fetch_or:
|
case TOK___c11_atomic_fetch_or:
|
||||||
case TOK___atomic_fetch_xor:
|
case TOK___c11_atomic_fetch_xor:
|
||||||
case TOK___atomic_fetch_and:
|
case TOK___c11_atomic_fetch_and:
|
||||||
parse_atomic(tok);
|
parse_atomic(tok);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
30
tcctok.h
30
tcctok.h
@ -174,14 +174,6 @@
|
|||||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||||
#endif
|
#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) \
|
#define DEF_ATOMIC(id, str) \
|
||||||
DEF(id, str) \
|
DEF(id, str) \
|
||||||
DEF(id##_8, str "_8") \
|
DEF(id##_8, str "_8") \
|
||||||
@ -190,17 +182,17 @@
|
|||||||
DEF(id##_64, str "_64")
|
DEF(id##_64, str "_64")
|
||||||
|
|
||||||
/* atomic operations */
|
/* atomic operations */
|
||||||
DEF_ATOMIC(TOK___atomic_init, "__atomic_init")
|
DEF_ATOMIC(TOK___c11_atomic_init, "__c11_atomic_init")
|
||||||
DEF_ATOMIC(TOK___atomic_store, "__atomic_store")
|
DEF_ATOMIC(TOK___c11_atomic_store, "__c11_atomic_store")
|
||||||
DEF_ATOMIC(TOK___atomic_load, "__atomic_load")
|
DEF_ATOMIC(TOK___c11_atomic_load, "__c11_atomic_load")
|
||||||
DEF_ATOMIC(TOK___atomic_exchange, "__atomic_exchange")
|
DEF_ATOMIC(TOK___c11_atomic_exchange, "__c11_atomic_exchange")
|
||||||
DEF_ATOMIC(TOK___atomic_compare_exchange_strong, "__atomic_compare_exchange_strong")
|
DEF_ATOMIC(TOK___c11_atomic_compare_exchange_strong, "__c11_atomic_compare_exchange_strong")
|
||||||
DEF_ATOMIC(TOK___atomic_compare_exchange_weak, "__atomic_compare_exchange_weak")
|
DEF_ATOMIC(TOK___c11_atomic_compare_exchange_weak, "__c11_atomic_compare_exchange_weak")
|
||||||
DEF_ATOMIC(TOK___atomic_fetch_add, "__atomic_fetch_add")
|
DEF_ATOMIC(TOK___c11_atomic_fetch_add, "__c11_atomic_fetch_add")
|
||||||
DEF_ATOMIC(TOK___atomic_fetch_sub, "__atomic_fetch_sub")
|
DEF_ATOMIC(TOK___c11_atomic_fetch_sub, "__c11_atomic_fetch_sub")
|
||||||
DEF_ATOMIC(TOK___atomic_fetch_or, "__atomic_fetch_or")
|
DEF_ATOMIC(TOK___c11_atomic_fetch_or, "__c11_atomic_fetch_or")
|
||||||
DEF_ATOMIC(TOK___atomic_fetch_xor, "__atomic_fetch_xor")
|
DEF_ATOMIC(TOK___c11_atomic_fetch_xor, "__c11_atomic_fetch_xor")
|
||||||
DEF_ATOMIC(TOK___atomic_fetch_and, "__atomic_fetch_and")
|
DEF_ATOMIC(TOK___c11_atomic_fetch_and, "__c11_atomic_fetch_and")
|
||||||
|
|
||||||
#undef DEF_ATOMIC
|
#undef DEF_ATOMIC
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user