cgen: nofloat for kernel code

pull/11467/head
Alexander Medvednikov 2021-09-10 20:54:41 +03:00
parent 5010d18f27
commit 5c4385a472
2 changed files with 12 additions and 0 deletions

View File

@ -619,6 +619,14 @@ fn (mut g Gen) typ(t ast.Type) string {
} }
fn (mut g Gen) base_type(t ast.Type) string { fn (mut g Gen) base_type(t ast.Type) string {
if g.pref.nofloat {
// todo compile time if for perf?
if t == ast.f32_type {
return 'u32'
} else if t == ast.f64_type {
return 'u64'
}
}
share := t.share() share := t.share()
mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) } mut styp := if share == .atomic_t { t.atomic_typename() } else { g.cc_type(t, true) }
if t.has_flag(.shared_f) { if t.has_flag(.shared_f) {

View File

@ -192,6 +192,7 @@ pub mut:
is_cstrict bool // turn on more C warnings; slightly slower is_cstrict bool // turn on more C warnings; slightly slower
assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure
message_limit int = 100 // the maximum amount of warnings/errors/notices that will be accumulated message_limit int = 100 // the maximum amount of warnings/errors/notices that will be accumulated
nofloat bool // for low level code, like kernels: replaces f32 with u32 and f64 with u64
// checker settings: // checker settings:
checker_match_exhaustive_cutoff_limit int = 12 checker_match_exhaustive_cutoff_limit int = 12
} }
@ -277,6 +278,9 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
'-cstrict' { '-cstrict' {
res.is_cstrict = true res.is_cstrict = true
} }
'-nofloat' {
res.nofloat = true
}
'-gc' { '-gc' {
gc_mode := cmdline.option(current_args, '-gc', '') gc_mode := cmdline.option(current_args, '-gc', '')
match gc_mode { match gc_mode {