mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.builder: streamline -stats output between backends. add a 'compilation speed' stat too
This commit is contained in:
parent
9881ff8448
commit
7c79e9bce7
@ -21,6 +21,8 @@ mut:
|
|||||||
out_name_c string
|
out_name_c string
|
||||||
out_name_js string
|
out_name_js string
|
||||||
max_nr_errors int = 100
|
max_nr_errors int = 100
|
||||||
|
stats_lines int // size of backend generated source code in lines
|
||||||
|
stats_bytes int // size of backend generated source code in bytes
|
||||||
pub mut:
|
pub mut:
|
||||||
module_search_paths []string
|
module_search_paths []string
|
||||||
parsed_files []ast.File
|
parsed_files []ast.File
|
||||||
@ -283,6 +285,9 @@ pub fn (b &Builder) find_module_path(mod string, fpath string) ?string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (b &Builder) show_total_warns_and_errors_stats() {
|
fn (b &Builder) show_total_warns_and_errors_stats() {
|
||||||
|
if b.checker.nr_errors == 0 && b.checker.nr_warnings == 0 && b.checker.nr_notices == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
if b.pref.is_stats {
|
if b.pref.is_stats {
|
||||||
estring := util.bold(b.checker.nr_errors.str())
|
estring := util.bold(b.checker.nr_errors.str())
|
||||||
wstring := util.bold(b.checker.nr_warnings.str())
|
wstring := util.bold(b.checker.nr_warnings.str())
|
||||||
|
@ -46,23 +46,8 @@ pub fn (mut b Builder) build_c(v_files []string, out_file string) {
|
|||||||
f.writeln(output2) or { panic(err) }
|
f.writeln(output2) or { panic(err) }
|
||||||
f.close()
|
f.close()
|
||||||
if b.pref.is_stats {
|
if b.pref.is_stats {
|
||||||
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
|
b.stats_lines = output2.count('\n') + 1
|
||||||
for mut pf in b.parsed_files {
|
b.stats_bytes = output2.len
|
||||||
all_v_source_lines += pf.lines
|
|
||||||
all_v_source_bytes += pf.bytes
|
|
||||||
}
|
|
||||||
mut sall_v_source_lines := all_v_source_lines.str()
|
|
||||||
mut sall_v_source_bytes := all_v_source_bytes.str()
|
|
||||||
mut slines := (output2.count('\n') + 1).str()
|
|
||||||
mut sbytes := output2.len.str()
|
|
||||||
//
|
|
||||||
slines = util.bold('${slines:10s}')
|
|
||||||
sbytes = util.bold('${sbytes:10s}')
|
|
||||||
sall_v_source_lines = util.bold('${sall_v_source_lines:10s}')
|
|
||||||
sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}')
|
|
||||||
//
|
|
||||||
println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes')
|
|
||||||
println('generated C source code size: $slines lines, $sbytes bytes')
|
|
||||||
}
|
}
|
||||||
// os.write_file(out_file, b.gen_c(v_files))
|
// os.write_file(out_file, b.gen_c(v_files))
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,28 @@ pub fn compile(command string, pref &pref.Preferences) {
|
|||||||
.x64 { b.compile_x64() }
|
.x64 { b.compile_x64() }
|
||||||
}
|
}
|
||||||
if pref.is_stats {
|
if pref.is_stats {
|
||||||
compilation_time := util.bold(sw.elapsed().milliseconds().str())
|
compilation_time_micros := 1 + sw.elapsed().microseconds()
|
||||||
println('compilation took: $compilation_time ms')
|
scompilation_time_ms := util.bold('${f64(compilation_time_micros) / 1000.0:6.3f}')
|
||||||
|
mut all_v_source_lines, mut all_v_source_bytes := 0, 0
|
||||||
|
for mut pf in b.parsed_files {
|
||||||
|
all_v_source_lines += pf.lines
|
||||||
|
all_v_source_bytes += pf.bytes
|
||||||
|
}
|
||||||
|
mut sall_v_source_lines := all_v_source_lines.str()
|
||||||
|
mut sall_v_source_bytes := all_v_source_bytes.str()
|
||||||
|
sall_v_source_lines = util.bold('${sall_v_source_lines:10s}')
|
||||||
|
sall_v_source_bytes = util.bold('${sall_v_source_bytes:10s}')
|
||||||
|
println(' V source code size: $sall_v_source_lines lines, $sall_v_source_bytes bytes')
|
||||||
|
//
|
||||||
|
mut slines := b.stats_lines.str()
|
||||||
|
mut sbytes := b.stats_bytes.str()
|
||||||
|
slines = util.bold('${slines:10s}')
|
||||||
|
sbytes = util.bold('${sbytes:10s}')
|
||||||
|
println('generated target code size: $slines lines, $sbytes bytes')
|
||||||
|
//
|
||||||
|
vlines_per_second := int(1_000_000.0 * f64(all_v_source_lines) / f64(compilation_time_micros))
|
||||||
|
svlines_per_second := util.bold(vlines_per_second.str())
|
||||||
|
println('compilation took: $scompilation_time_ms ms, compilation speed: $svlines_per_second vlines/s')
|
||||||
}
|
}
|
||||||
b.exit_on_invalid_syntax()
|
b.exit_on_invalid_syntax()
|
||||||
// running does not require the parsers anymore
|
// running does not require the parsers anymore
|
||||||
|
@ -36,6 +36,10 @@ pub fn (mut b Builder) build_js(v_files []string, out_file string) {
|
|||||||
output := b.gen_js(v_files)
|
output := b.gen_js(v_files)
|
||||||
mut f := os.create(out_file) or { panic(err) }
|
mut f := os.create(out_file) or { panic(err) }
|
||||||
f.writeln(output) or { panic(err) }
|
f.writeln(output) or { panic(err) }
|
||||||
|
if b.pref.is_stats {
|
||||||
|
b.stats_lines = output.count('\n') + 1
|
||||||
|
b.stats_bytes = output.len
|
||||||
|
}
|
||||||
f.close()
|
f.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub fn (mut b Builder) build_x64(v_files []string, out_file string) {
|
|||||||
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
||||||
}
|
}
|
||||||
util.timing_start('x64 GEN')
|
util.timing_start('x64 GEN')
|
||||||
x64.gen(b.parsed_files, b.table, out_file, b.pref)
|
b.stats_lines, b.stats_bytes = x64.gen(b.parsed_files, b.table, out_file, b.pref)
|
||||||
util.timing_measure('x64 GEN')
|
util.timing_measure('x64 GEN')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,5 +103,7 @@ pub fn (mut g Gen) generate_elf_footer() {
|
|||||||
os.chmod(g.out_name, 0o775) // make it an executable
|
os.chmod(g.out_name, 0o775) // make it an executable
|
||||||
unsafe { f.write_ptr(g.buf.data, g.buf.len) }
|
unsafe { f.write_ptr(g.buf.data, g.buf.len) }
|
||||||
f.close()
|
f.close()
|
||||||
println('\nx64 elf binary has been successfully generated')
|
if g.pref.is_verbose {
|
||||||
|
println('\nx64 elf binary has been successfully generated')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ mut:
|
|||||||
warnings []errors.Warning
|
warnings []errors.Warning
|
||||||
syms []Symbol
|
syms []Symbol
|
||||||
relocs []Reloc
|
relocs []Reloc
|
||||||
|
nlines int
|
||||||
}
|
}
|
||||||
|
|
||||||
// string_addr map[string]i64
|
// string_addr map[string]i64
|
||||||
@ -81,7 +82,7 @@ enum Size {
|
|||||||
_64
|
_64
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) {
|
pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Preferences) (int, int) {
|
||||||
mut g := Gen{
|
mut g := Gen{
|
||||||
table: table
|
table: table
|
||||||
sect_header_name_pos: 0
|
sect_header_name_pos: 0
|
||||||
@ -96,6 +97,7 @@ pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Prefe
|
|||||||
g.stmts(file.stmts)
|
g.stmts(file.stmts)
|
||||||
}
|
}
|
||||||
g.generate_elf_footer()
|
g.generate_elf_footer()
|
||||||
|
return g.nlines, g.buf.len
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut g Gen) stmts(stmts []ast.Stmt) {
|
pub fn (mut g Gen) stmts(stmts []ast.Stmt) {
|
||||||
@ -272,6 +274,7 @@ fn (mut g Gen) jle(addr i64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) println(comment string) {
|
fn (mut g Gen) println(comment string) {
|
||||||
|
g.nlines++
|
||||||
if !g.pref.is_verbose {
|
if !g.pref.is_verbose {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user