mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.builder: refactor to make adding other post checker stages easier
This commit is contained in:
parent
2eafea6308
commit
adffae4453
@ -9,6 +9,7 @@ import v.vmod
|
||||
import v.checker
|
||||
import v.parser
|
||||
import v.depgraph
|
||||
import v.markused
|
||||
|
||||
pub struct Builder {
|
||||
pub:
|
||||
@ -65,6 +66,34 @@ pub fn new_builder(pref &pref.Preferences) Builder {
|
||||
// max_nr_errors: pref.error_limit ?? 100 TODO potential syntax?
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) front_stages(v_files []string) ? {
|
||||
util.timing_start('PARSE')
|
||||
b.parsed_files = parser.parse_files(v_files, b.table, b.pref, b.global_scope)
|
||||
b.parse_imports()
|
||||
util.get_timers().show('SCAN')
|
||||
util.get_timers().show('PARSE')
|
||||
util.get_timers().show_if_exists('PARSE stmt')
|
||||
if b.pref.only_check_syntax {
|
||||
return error('stop_after_parser')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) middle_stages() ? {
|
||||
util.timing_start('CHECK')
|
||||
b.table.generic_struct_insts_to_concrete()
|
||||
b.checker.check_files(b.parsed_files)
|
||||
util.timing_measure('CHECK')
|
||||
b.print_warnings_and_errors()
|
||||
if b.pref.skip_unused {
|
||||
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut b Builder) front_and_middle_stages(v_files []string) ? {
|
||||
b.front_stages(v_files) ?
|
||||
b.middle_stages() ?
|
||||
}
|
||||
|
||||
// parse all deps from already parsed files
|
||||
pub fn (mut b Builder) parse_imports() {
|
||||
mut done_imports := []string{}
|
||||
|
@ -1,33 +1,12 @@
|
||||
module builder
|
||||
|
||||
import os
|
||||
import v.parser
|
||||
import v.pref
|
||||
import v.util
|
||||
import v.gen.c
|
||||
import v.markused
|
||||
|
||||
pub fn (mut b Builder) gen_c(v_files []string) string {
|
||||
util.timing_start('PARSE')
|
||||
b.parsed_files = parser.parse_files(v_files, b.table, b.pref, b.global_scope)
|
||||
b.parse_imports()
|
||||
util.get_timers().show('SCAN')
|
||||
util.get_timers().show('PARSE')
|
||||
util.get_timers().show_if_exists('PARSE stmt')
|
||||
if b.pref.only_check_syntax {
|
||||
return ''
|
||||
}
|
||||
|
||||
util.timing_start('CHECK')
|
||||
b.table.generic_struct_insts_to_concrete()
|
||||
b.checker.check_files(b.parsed_files)
|
||||
util.timing_measure('CHECK')
|
||||
|
||||
if b.pref.skip_unused {
|
||||
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
||||
}
|
||||
|
||||
b.print_warnings_and_errors()
|
||||
b.front_and_middle_stages(v_files) or { return '' }
|
||||
// TODO: move gen.cgen() to c.gen()
|
||||
util.timing_start('C GEN')
|
||||
res := c.gen(b.parsed_files, b.table, b.pref)
|
||||
|
@ -1,29 +1,12 @@
|
||||
module builder
|
||||
|
||||
import os
|
||||
import v.parser
|
||||
import v.pref
|
||||
import v.util
|
||||
import v.gen.js
|
||||
import v.markused
|
||||
|
||||
pub fn (mut b Builder) gen_js(v_files []string) string {
|
||||
util.timing_start('PARSE')
|
||||
b.parsed_files = parser.parse_files(v_files, b.table, b.pref, b.global_scope)
|
||||
b.parse_imports()
|
||||
util.get_timers().show('SCAN')
|
||||
util.get_timers().show('PARSE')
|
||||
util.get_timers().show_if_exists('PARSE stmt')
|
||||
//
|
||||
util.timing_start('CHECK')
|
||||
b.checker.check_files(b.parsed_files)
|
||||
util.timing_measure('CHECK')
|
||||
//
|
||||
if b.pref.skip_unused {
|
||||
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
||||
}
|
||||
b.print_warnings_and_errors()
|
||||
//
|
||||
b.front_and_middle_stages(v_files) or { return '' }
|
||||
util.timing_start('JS GEN')
|
||||
res := js.gen(b.parsed_files, b.table, b.pref)
|
||||
util.timing_measure('JS GEN')
|
||||
|
@ -1,29 +1,14 @@
|
||||
module builder
|
||||
|
||||
import v.parser
|
||||
import v.pref
|
||||
import v.util
|
||||
import v.gen.native
|
||||
import v.markused
|
||||
|
||||
pub fn (mut b Builder) build_native(v_files []string, out_file string) {
|
||||
$if !linux && !macos {
|
||||
if b.pref.os != .linux || b.pref.os != .macos {
|
||||
eprintln('Warning: v -native can only generate macOS and Linux binaries for now')
|
||||
}
|
||||
util.timing_start('PARSE')
|
||||
b.parsed_files = parser.parse_files(v_files, b.table, b.pref, b.global_scope)
|
||||
b.parse_imports()
|
||||
util.get_timers().show('SCAN')
|
||||
util.get_timers().show('PARSE')
|
||||
util.get_timers().show_if_exists('PARSE stmt')
|
||||
//
|
||||
util.timing_start('CHECK')
|
||||
b.checker.check_files(b.parsed_files)
|
||||
util.timing_measure('CHECK')
|
||||
//
|
||||
if b.pref.skip_unused {
|
||||
markused.mark_used(mut b.table, b.pref, b.parsed_files)
|
||||
}
|
||||
b.front_and_middle_stages(v_files) or { return }
|
||||
util.timing_start('Native GEN')
|
||||
b.stats_lines, b.stats_bytes = native.gen(b.parsed_files, b.table, out_file, b.pref)
|
||||
util.timing_measure('Native GEN')
|
||||
|
@ -9,12 +9,10 @@ import v.pref
|
||||
// mark_used walks the AST, starting at main() and marks all used fns transitively
|
||||
pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.File) {
|
||||
mut all_fns, all_consts := all_fn_and_const(ast_files)
|
||||
|
||||
util.timing_start(@METHOD)
|
||||
defer {
|
||||
util.timing_measure(@METHOD)
|
||||
}
|
||||
|
||||
mut all_fn_root_names := [
|
||||
'main.main',
|
||||
'__new_array',
|
||||
|
Loading…
Reference in New Issue
Block a user