mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: generate a v.c that is compatible with latest tcc
This commit is contained in:
parent
72ae12877e
commit
9a0a8e89fb
@ -40,9 +40,17 @@ CommonCHeaders = '
|
||||
|
||||
#define EMPTY_STRUCT_DECLARATION
|
||||
#define EMPTY_STRUCT_INITIALIZATION 0
|
||||
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
|
||||
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[])
|
||||
#define TCCSKIP(x) x
|
||||
|
||||
#ifdef __TINYC__
|
||||
#undef EMPTY_STRUCT_INITIALIZATION
|
||||
#define EMPTY_STRUCT_INITIALIZATION
|
||||
#undef EMPTY_ARRAY_OF_ELEMS
|
||||
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
|
||||
#undef TCCSKIP
|
||||
#define TCCSKIP(x)
|
||||
#endif
|
||||
|
||||
#define OPTION_CAST(x) (x)
|
||||
|
@ -317,18 +317,15 @@ fn (p mut Parser) gen_array_init(typ string, no_alloc bool, new_arr_ph int, nr_e
|
||||
if no_alloc {
|
||||
new_arr += '_no_alloc'
|
||||
}
|
||||
if nr_elems == 0 && p.pref.ccompiler != 'tcc' {
|
||||
p.gen(' 0 })')
|
||||
if nr_elems == 0 {
|
||||
p.gen(' TCCSKIP(0) })')
|
||||
} else {
|
||||
p.gen(' })')
|
||||
}
|
||||
// Need to do this in the second pass, otherwise it goes to the very top of the out.c file
|
||||
if !p.first_pass() {
|
||||
// Due to a tcc bug, the length needs to be specified.
|
||||
// GCC crashes if it is.
|
||||
cast := if p.pref.ccompiler == 'tcc' { '($typ[$nr_elems])' } else { '($typ[])' }
|
||||
p.cgen.set_placeholder(new_arr_ph,
|
||||
'$new_arr($nr_elems, $nr_elems, sizeof($typ), $cast { ')
|
||||
if !p.first_pass() {
|
||||
p.cgen.set_placeholder(new_arr_ph,
|
||||
'$new_arr($nr_elems, $nr_elems, sizeof($typ), EMPTY_ARRAY_OF_ELEMS( $typ, $nr_elems ) { ')
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user