cc/cgen: cached modules fixes
parent
761fb930ce
commit
1e4e882bc2
|
@ -47,6 +47,11 @@ pub fn (b mut Builder) go_back(n int) {
|
||||||
b.len -= n
|
b.len -= n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn (b mut Builder) go_back_to(pos int) {
|
||||||
|
b.buf.trim(pos)
|
||||||
|
b.len = pos
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (b mut Builder) writeln(s string) {
|
pub fn (b mut Builder) writeln(s string) {
|
||||||
// for c in s {
|
// for c in s {
|
||||||
// b.buf << c
|
// b.buf << c
|
||||||
|
|
|
@ -308,7 +308,7 @@ fn (mut v Builder) cc() {
|
||||||
if v.pref.use_cache {
|
if v.pref.use_cache {
|
||||||
//vexe := pref.vexe_path()
|
//vexe := pref.vexe_path()
|
||||||
|
|
||||||
cached_modules:= [ 'builtin', 'os' ]//, 'math']
|
cached_modules:= [ 'builtin', 'os', 'math', 'strconv', 'strings']
|
||||||
for cfile in cached_modules{
|
for cfile in cached_modules{
|
||||||
ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile + '.o')
|
ofile := os.join_path(pref.default_module_path, 'cache', 'vlib', cfile + '.o')
|
||||||
if !os.exists(ofile) {
|
if !os.exists(ofile) {
|
||||||
|
|
|
@ -58,6 +58,7 @@ struct Gen {
|
||||||
pcs_declarations strings.Builder // -prof profile counter declarations for each function
|
pcs_declarations strings.Builder // -prof profile counter declarations for each function
|
||||||
table &table.Table
|
table &table.Table
|
||||||
pref &pref.Preferences
|
pref &pref.Preferences
|
||||||
|
module_built string
|
||||||
mut:
|
mut:
|
||||||
file ast.File
|
file ast.File
|
||||||
fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0
|
fn_decl &ast.FnDecl // pointer to the FnDecl we are currently inside otherwise 0
|
||||||
|
@ -86,6 +87,8 @@ mut:
|
||||||
array_fn_definitions []string // array equality functions that have been defined
|
array_fn_definitions []string // array equality functions that have been defined
|
||||||
is_json_fn bool // inside json.encode()
|
is_json_fn bool // inside json.encode()
|
||||||
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
pcs []ProfileCounterMeta // -prof profile counter fn_names => fn counter name
|
||||||
|
attr string
|
||||||
|
is_builtin_mod bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -122,6 +125,7 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
||||||
fn_decl: 0
|
fn_decl: 0
|
||||||
autofree: true
|
autofree: true
|
||||||
indent: -1
|
indent: -1
|
||||||
|
module_built: pref.path.after('vlib/')
|
||||||
}
|
}
|
||||||
g.init()
|
g.init()
|
||||||
//
|
//
|
||||||
|
@ -159,7 +163,6 @@ pub fn cgen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
||||||
//
|
//
|
||||||
g.finish()
|
g.finish()
|
||||||
//
|
//
|
||||||
|
|
||||||
b := strings.new_builder(250000)
|
b := strings.new_builder(250000)
|
||||||
b.writeln(g.hashes())
|
b.writeln(g.hashes())
|
||||||
b.writeln(g.comptime_defines.str())
|
b.writeln(g.comptime_defines.str())
|
||||||
|
@ -238,7 +241,6 @@ pub fn (mut g Gen) finish() {
|
||||||
}
|
}
|
||||||
g.stringliterals.writeln('// << string literal consts')
|
g.stringliterals.writeln('// << string literal consts')
|
||||||
g.stringliterals.writeln('')
|
g.stringliterals.writeln('')
|
||||||
|
|
||||||
if g.pref.is_prof {
|
if g.pref.is_prof {
|
||||||
g.gen_vprint_profile_stats()
|
g.gen_vprint_profile_stats()
|
||||||
}
|
}
|
||||||
|
@ -446,8 +448,9 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
g.gen_assign_stmt(it)
|
g.gen_assign_stmt(it)
|
||||||
}
|
}
|
||||||
ast.Attr {
|
ast.Attr {
|
||||||
|
g.attr = it.name
|
||||||
if it.name == 'inline' {
|
if it.name == 'inline' {
|
||||||
g.writeln(it.name)
|
//g.writeln(it.name)
|
||||||
} else {
|
} else {
|
||||||
g.writeln('//[$it.name]')
|
g.writeln('//[$it.name]')
|
||||||
}
|
}
|
||||||
|
@ -512,12 +515,30 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.FnDecl {
|
ast.FnDecl {
|
||||||
|
mut skip := false
|
||||||
|
pos := g.out.buf.len
|
||||||
|
if g.pref.build_mode==.build_module {
|
||||||
|
if !it.name.starts_with(g.module_built + '.'){
|
||||||
|
// Skip functions that don't have to be generated
|
||||||
|
// for this module.
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
if g.is_builtin_mod && g.module_built == 'builtin' {
|
||||||
|
skip=false
|
||||||
|
}
|
||||||
|
if !skip {
|
||||||
|
println('build module `$g.module_built` fn `$it.name`')
|
||||||
|
}
|
||||||
|
}
|
||||||
fn_start_pos := g.out.len
|
fn_start_pos := g.out.len
|
||||||
g.fn_decl = it // &it
|
g.fn_decl = it // &it
|
||||||
g.gen_fn_decl(it)
|
g.gen_fn_decl(it)
|
||||||
if g.pref.printfn_list.len > 0 && g.last_fn_c_name in g.pref.printfn_list {
|
if g.pref.printfn_list.len > 0 && g.last_fn_c_name in g.pref.printfn_list {
|
||||||
println(g.out.after(fn_start_pos))
|
println(g.out.after(fn_start_pos))
|
||||||
}
|
}
|
||||||
|
if skip {
|
||||||
|
g.out.go_back_to(pos)
|
||||||
|
}
|
||||||
g.writeln('')
|
g.writeln('')
|
||||||
}
|
}
|
||||||
ast.ForCStmt {
|
ast.ForCStmt {
|
||||||
|
@ -584,7 +605,9 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
g.definitions.writeln('\tint _interface_idx;')
|
g.definitions.writeln('\tint _interface_idx;')
|
||||||
g.definitions.writeln('} $it.name;')
|
g.definitions.writeln('} $it.name;')
|
||||||
}
|
}
|
||||||
ast.Module {}
|
ast.Module {
|
||||||
|
g.is_builtin_mod = it.name=='builtin'
|
||||||
|
}
|
||||||
ast.Return {
|
ast.Return {
|
||||||
g.write_defer_stmts_when_needed()
|
g.write_defer_stmts_when_needed()
|
||||||
g.return_statement(it)
|
g.return_statement(it)
|
||||||
|
|
|
@ -12,6 +12,10 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||||
// || it.no_body {
|
// || it.no_body {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if g.attr == 'inline' {
|
||||||
|
g.write('inline ')
|
||||||
|
g.attr = ''
|
||||||
|
}
|
||||||
g.reset_tmp_count()
|
g.reset_tmp_count()
|
||||||
is_main := it.name == 'main'
|
is_main := it.name == 'main'
|
||||||
if is_main {
|
if is_main {
|
||||||
|
|
Loading…
Reference in New Issue