cgen: use __attribute__((convention)) for normal functions too, when cc != msvc

pull/14027/head
Delyan Angelov 2022-04-14 08:25:29 +03:00
parent 0fd43a2530
commit 778614bcc9
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 11 additions and 5 deletions

View File

@ -96,6 +96,7 @@ mut:
is_json_fn bool // inside json.encode()
is_js_call bool // for handling a special type arg #1 `json.decode(User, ...)`
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
optionals map[string]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{}
field_data_type: ast.Type(table.find_type_idx('FieldData'))
init: strings.new_builder(100)
is_cc_msvc: pref.ccompiler == 'msvc'
}
// anon fn may include assert and thus this needs
// 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
is_autofree: global_g.pref.autofree
referenced_fns: global_g.referenced_fns
is_cc_msvc: global_g.is_cc_msvc
}
g.gen_file()
return g
@ -1346,11 +1349,10 @@ pub fn (mut g Gen) write_fn_typesymbol_declaration(sym ast.TypeSymbol) {
mut call_conv := ''
mut msvc_call_conv := ''
is_cc_msvc := g.pref.ccompiler == 'msvc'
for attr in func.attrs {
match attr.name {
'callconv' {
if is_cc_msvc {
if g.is_cc_msvc {
msvc_call_conv = '__$attr.arg '
} else {
call_conv = '$attr.arg'

View File

@ -2148,13 +2148,13 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string {
'windows_stdcall' {
// windows attributes (msvc/mingw)
// 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' {
fn_attrs += '__fastcall '
fn_attrs += call_convention_attribute('fastcall', g.is_cc_msvc)
}
'callconv' {
fn_attrs += '__$attr.arg '
fn_attrs += call_convention_attribute(attr.arg, g.is_cc_msvc)
}
'console' {
g.force_main_console = true
@ -2166,3 +2166,7 @@ fn (mut g Gen) write_fn_attrs(attrs []ast.Attr) string {
}
return fn_attrs
}
fn call_convention_attribute(cconvention string, is_cc_msvc bool) string {
return if is_cc_msvc { '__$cconvention ' } else { '__attribute__(($cconvention)) ' }
}