cgen: use __attribute__((convention)) for normal functions too, when cc != msvc
parent
0fd43a2530
commit
778614bcc9
|
|
@ -96,6 +96,7 @@ mut:
|
||||||
is_json_fn bool // inside json.encode()
|
is_json_fn bool // inside json.encode()
|
||||||
is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)`
|
is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)`
|
||||||
is_fn_index_call bool
|
is_fn_index_call bool
|
||||||
|
is_cc_msvc bool // g.pref.ccompiler == 'msvc'
|
||||||
vlines_path string // set to the proper path for generating #line directives
|
vlines_path string // set to the proper path for generating #line directives
|
||||||
optionals map[string]string // to avoid duplicates
|
optionals map[string]string // to avoid duplicates
|
||||||
done_optionals shared []string // to avoid duplicates
|
done_optionals shared []string // to avoid duplicates
|
||||||
|
|
@ -258,6 +259,7 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string {
|
||||||
inner_loop: &ast.EmptyStmt{}
|
inner_loop: &ast.EmptyStmt{}
|
||||||
field_data_type: ast.Type(table.find_type_idx('FieldData'))
|
field_data_type: ast.Type(table.find_type_idx('FieldData'))
|
||||||
init: strings.new_builder(100)
|
init: strings.new_builder(100)
|
||||||
|
is_cc_msvc: pref.ccompiler == 'msvc'
|
||||||
}
|
}
|
||||||
// anon fn may include assert and thus this needs
|
// anon fn may include assert and thus this needs
|
||||||
// to be included before any test contents are written
|
// to be included before any test contents are written
|
||||||
|
|
@ -557,6 +559,7 @@ fn cgen_process_one_file_cb(p &pool.PoolProcessor, idx int, wid int) &Gen {
|
||||||
done_optionals: global_g.done_optionals
|
done_optionals: global_g.done_optionals
|
||||||
is_autofree: global_g.pref.autofree
|
is_autofree: global_g.pref.autofree
|
||||||
referenced_fns: global_g.referenced_fns
|
referenced_fns: global_g.referenced_fns
|
||||||
|
is_cc_msvc: global_g.is_cc_msvc
|
||||||
}
|
}
|
||||||
g.gen_file()
|
g.gen_file()
|
||||||
return g
|
return g
|
||||||
|
|
@ -1346,11 +1349,10 @@ pub fn (mut g Gen) write_fn_typesymbol_declaration(sym ast.TypeSymbol) {
|
||||||
|
|
||||||
mut call_conv := ''
|
mut call_conv := ''
|
||||||
mut msvc_call_conv := ''
|
mut msvc_call_conv := ''
|
||||||
is_cc_msvc := g.pref.ccompiler == 'msvc'
|
|
||||||
for attr in func.attrs {
|
for attr in func.attrs {
|
||||||
match attr.name {
|
match attr.name {
|
||||||
'callconv' {
|
'callconv' {
|
||||||
if is_cc_msvc {
|
if g.is_cc_msvc {
|
||||||
msvc_call_conv = '__$attr.arg '
|
msvc_call_conv = '__$attr.arg '
|
||||||
} else {
|
} else {
|
||||||
call_conv = '$attr.arg'
|
call_conv = '$attr.arg'
|
||||||
|
|
|
||||||
|
|
@ -2148,13 +2148,13 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string {
|
||||||
'windows_stdcall' {
|
'windows_stdcall' {
|
||||||
// windows attributes (msvc/mingw)
|
// windows attributes (msvc/mingw)
|
||||||
// prefixed by windows to indicate they're for advanced users only and not really supported by V.
|
// prefixed by windows to indicate they're for advanced users only and not really supported by V.
|
||||||
fn_attrs += '__stdcall '
|
fn_attrs += call_convention_attribute('stdcall', g.is_cc_msvc)
|
||||||
}
|
}
|
||||||
'_fastcall' {
|
'_fastcall' {
|
||||||
fn_attrs += '__fastcall '
|
fn_attrs += call_convention_attribute('fastcall', g.is_cc_msvc)
|
||||||
}
|
}
|
||||||
'callconv' {
|
'callconv' {
|
||||||
fn_attrs += '__$attr.arg '
|
fn_attrs += call_convention_attribute(attr.arg, g.is_cc_msvc)
|
||||||
}
|
}
|
||||||
'console' {
|
'console' {
|
||||||
g.force_main_console = true
|
g.force_main_console = true
|
||||||
|
|
@ -2166,3 +2166,7 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string {
|
||||||
}
|
}
|
||||||
return fn_attrs
|
return fn_attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn call_convention_attribute(cconvention string, is_cc_msvc bool) string {
|
||||||
|
return if is_cc_msvc { '__$cconvention ' } else { '__attribute__(($cconvention)) ' }
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue