v3.gen.fastc
fn fastc_add_prepared_link_input #
fn fastc_add_prepared_link_input(mut link FastcPreparedLink, input_path string) !
fastc_add_prepared_link_input loads one completed object into the macOS in-process linker. Callers preserve the original object order.
fn fastc_begin_feed_prestarted_c_units #
fn fastc_begin_feed_prestarted_c_units(mut prestarted FastcPrestartedCUnits, mut rendering FastcRenderingCUnits) !FastcFeedingCUnits
fastc_begin_feed_prestarted_c_units starts copying rendered source to TinyCC processes that were launched while FastC generation was still running.
fn fastc_begin_render_c_units #
fn fastc_begin_render_c_units(prefix string, pieces []string, units FastcUnitLayout, jobs int) FastcRenderingCUnits
fastc_begin_render_c_units starts rendering balanced split translation units and returns immediately, so their consumers can start concurrently.
fn fastc_begin_render_prestarted_c_units #
fn fastc_begin_render_prestarted_c_units(mut prestarted FastcPrestartedCUnits, prefix string, pieces []string, units FastcUnitLayout, jobs int) !FastcFeedingCUnits
fastc_begin_render_prestarted_c_units renders directly into prestarted TinyCC processes, avoiding a second set of threads just to hand strings off.
fn fastc_codesign_shim_dir #
fn fastc_codesign_shim_dir() FastcCodesignShim
fastc_codesign_shim_dir prepares a directory whose codesign is a link to /usr/bin/true and puts it first on PATH, so TinyCC's post-link codesign call (Apple's tool takes tens of milliseconds) does nothing; the driver then signs the executable itself with fastc_sign_macho_adhoc.
fn fastc_compile_c_unit_texts #
fn fastc_compile_c_unit_texts(tcc string, base_args []string, unit_paths []string, sources []string, prepared FastcPreparedUnits) ![]string
fastc_compile_c_unit_texts streams in-memory translation units to concurrent TinyCC processes. This avoids a temporary-file write/read round trip and overlaps feeding earlier processes with starting the remaining ones.
fn fastc_compile_c_units #
fn fastc_compile_c_units(tcc string, base_args []string, unit_paths []string, prepared FastcPreparedUnits) ![]string
fastc_compile_c_units compiles the translation units to objects with concurrent TinyCC processes (started with posix_spawn, which is cheaper than forking the compiler process), and returns the object paths, or the output of the first compile that failed.
fn fastc_compile_prestarted_rendering_c_units #
fn fastc_compile_prestarted_rendering_c_units(mut prestarted FastcPrestartedCUnits, mut rendering FastcRenderingCUnits, prepared FastcPreparedUnits, mut prepared_link FastcPreparedLink, preload_link bool) ![]string
fastc_compile_prestarted_rendering_c_units feeds and waits for translation units in one call. Callers with independent setup work can use the split begin/finish API to overlap that work with rendering and compilation.
fn fastc_compile_rendering_c_units #
fn fastc_compile_rendering_c_units(tcc string, base_args []string, mut rendering FastcRenderingCUnits, prepared FastcPreparedUnits, mut prepared_link FastcPreparedLink, preload_link bool) ![]string
fastc_compile_rendering_c_units starts concurrent TinyCC processes while their translation units are still being rendered, then streams each unit as soon as its render worker completes.
fn fastc_discard_link #
fn fastc_discard_link(mut link FastcPreparedLink)
fastc_discard_link releases a prepared linker after unit compilation fails.
fn fastc_discard_prestarted_c_units #
fn fastc_discard_prestarted_c_units(mut units FastcPrestartedCUnits)
fastc_discard_prestarted_c_units closes and reaps unused prestarted TinyCC processes, then removes their private build directory.
fn fastc_finish_link #
fn fastc_finish_link(mut link FastcPreparedLink, input_paths []string, final_args []string, output string) os.Result
fastc_finish_link adds the compiled inputs to a prepared linker and writes the executable. final_args contains libraries and other link-only flags.
fn fastc_finish_prestarted_c_units #
fn fastc_finish_prestarted_c_units(mut prestarted FastcPrestartedCUnits, mut feeding FastcFeedingCUnits, prepared FastcPreparedUnits, mut prepared_link FastcPreparedLink, preload_link bool) ![]string
fastc_finish_prestarted_c_units waits for TinyCC and optionally loads each completed object into the prepared linker in translation-unit order.
fn fastc_finish_render_c_units #
fn fastc_finish_render_c_units(mut rendering FastcRenderingCUnits) FastcRenderedCUnits
fastc_finish_render_c_units waits for an in-progress unit render.
fn fastc_generation_link_cache_key #
fn fastc_generation_link_cache_key(tcc string, compile_args []string, final_args []string, pieces []string, units FastcUnitLayout, jobs int, enabled bool) string
fastc_generation_link_cache_key identifies the final executable directly from the generated pieces and every input that affects unit compilation or linking. A warm build can therefore restore the executable before writing and re-reading the split C files.
fn fastc_link_cache_key #
fn fastc_link_cache_key(unit_key string, final_args []string) string
fastc_link_cache_key identifies a link of content-addressed unit objects.
fn fastc_macos_system_tbd #
fn fastc_macos_system_tbd(target_arch string) string
fastc_macos_system_tbd returns a compact libSystem text stub containing the complete macOS ABI table used by header-free FastC self-host builds. Passing this to TinyCC avoids parsing the SDK's much larger umbrella stub at link time while retaining the same libSystem install name.
fn fastc_prepare_c_units #
fn fastc_prepare_c_units(tcc string, base_args []string, unit_paths []string, cache_enabled bool) FastcPreparedUnits
fastc_prepare_c_units calculates the object cache keys and restores hits.
fn fastc_prepare_link #
fn fastc_prepare_link(program string, tcc_lib string, base_args []string, final_args []string) FastcPreparedLink
fastc_prepare_link initializes the in-process TinyCC linker on macOS. A compiler built by TinyCC or the V3 backend uses the executable-based linker instead. final_args are supplied here so state-affecting linker options are visible before TinyCC initializes its output state.
fn fastc_prepared_link_accepts_inputs #
fn fastc_prepared_link_accepts_inputs(link &FastcPreparedLink) bool
fastc_prepared_link_accepts_inputs reports whether object files can be loaded into this linker before the final output step.
fn fastc_prepared_link_skips_codesign #
fn fastc_prepared_link_skips_codesign(link &FastcPreparedLink) bool
fastc_prepared_link_skips_codesign reports whether the prepared linker suppresses TinyCC's codesign subprocess and needs in-process signing.
fn fastc_prestart_c_units #
fn fastc_prestart_c_units(tcc string, base_args []string, build_dir string, unit_count int) FastcPrestartedCUnits
fastc_prestart_c_units starts TinyCC processes that wait for their source on stdin. Starting this on a worker lets source generation hide process launch.
fn fastc_prestarted_c_units_match #
fn fastc_prestarted_c_units_match(units &FastcPrestartedCUnits, base_args []string, unit_count int) bool
fastc_prestarted_c_units_match reports whether units can consume a build with the final compile arguments and translation-unit count.
fn fastc_publish_link_cache #
fn fastc_publish_link_cache(key string, output string)
fastc_publish_link_cache atomically caches a linked and signed self-host.
fn fastc_remove_c_units #
fn fastc_remove_c_units(unit_paths []string)
FastcUnitCompile is one TinyCC process compiling a translation unit. fastc_remove_c_units deletes the translation unit sources and their objects.
fn fastc_remove_codesign_shim_dir #
fn fastc_remove_codesign_shim_dir(shim FastcCodesignShim)
fastc_remove_codesign_shim_dir restores PATH and removes the shim directory.
fn fastc_render_c_units #
fn fastc_render_c_units(prefix string, pieces []string, units FastcUnitLayout, jobs int) FastcRenderedCUnits
fastc_render_c_units renders balanced split translation units in parallel.
fn fastc_restore_link_cache #
fn fastc_restore_link_cache(key string, output string) bool
fastc_restore_link_cache copies a cached linked self-host to output.
fn fastc_run_command #
fn fastc_run_command(program string, args []string) os.Result
fastc_run_command runs the program with the argument vector and returns its exit code and merged output, like cmdexec.run, but through posix_spawn and a blocking wait rather than a fork of this (large) process and a polling loop.
fn fastc_sign_macho_adhoc #
fn fastc_sign_macho_adhoc(path string) !
fastc_sign_macho_adhoc gives the 64-bit Mach-O executable at path an ad-hoc code signature (a SHA-256 code directory over 4 KiB pages, an empty requirements blob and an empty CMS wrapper), replacing any signature it has. The identifier is the file name, as codesign -s - uses.
fn fastc_tcc_job_count #
fn fastc_tcc_job_count(prefs &pref.Preferences) int
fastc_tcc_job_count is the number of TinyCC processes a driver compiles a program's translation units with.
fn fastc_write_c_units #
fn fastc_write_c_units(prefix string, pieces []string, units FastcUnitLayout, jobs int) ![]string
fastc_write_c_units writes the translation units of a generation for jobs parallel TinyCC processes: prefix.unit<k>.c files, each with the shared head (the globals as extern declarations after the first), the first also with the startup, cleanup and main pieces, and consecutive body units grouped to balance their sizes. It returns the paths, or none when the program does not split.
fn generate #
fn generate(source string, path string, prefs &pref.Preferences) !string
generate scans V source and emits C as each declaration and statement is consumed. It does not construct an AST or invoke semantic type checking. Unsupported syntax is returned as an error; FastC never retries through an AST-based backend.
fn generate_files #
fn generate_files(paths []string, prefs &pref.Preferences) !string
generate_files discovers imports from the input files and emits one C translation unit for the complete source graph. Discovery and generation use scanner tokens only.
fn generate_files_with_source_paths #
fn generate_files_with_source_paths(paths []string, prefs &pref.Preferences) !GenerationResult
fn write_c_pieces #
fn write_c_pieces(path string, pieces []string) !
write_c_pieces writes generated C pieces to path without joining them.
fn FastcDeclaredTypeKind.from #
fn FastcDeclaredTypeKind.from[W](input W) !FastcDeclaredTypeKind
struct FastcCodesignShim #
struct FastcCodesignShim {
pub:
dir string
mut:
previous_path string
previous_path_set bool
}
FastcCodesignShim owns the temporary codesign shim and the PATH value that must be restored when its use ends.
struct FastcFeedingCUnits #
struct FastcFeedingCUnits {
pub:
paths []string
mut:
writers []thread
}
FastcFeedingCUnits holds the workers that copy rendered translation units into prestarted TinyCC processes.
struct FastcPreparedLink #
struct FastcPreparedLink {
mut:
state voidptr
diagnostics voidptr
program string
base_args []string
}
FastcPreparedLink holds a linker that can be initialized concurrently with the TinyCC processes compiling a program's translation units.
struct FastcPreparedUnits #
struct FastcPreparedUnits {
entries []FastcUnitCacheEntry
pub:
objects []string
cache_key string
}
FastcPreparedUnits holds the ordered TinyCC objects and their content cache entries. Preparing them restores object-cache hits before compilation starts.
struct FastcPrestartedCUnits #
struct FastcPrestartedCUnits {
pub:
build_dir string
base_args []string
unit_count int
mut:
paths []string
objects []string
pids []int
read_fds []int
write_fds []int
active bool
}
FastcPrestartedCUnits holds TinyCC processes started before FastC generation completes. They wait on stdin until the balanced translation units are ready.
struct FastcRenderedCUnits #
struct FastcRenderedCUnits {
pub:
paths []string
sources []string
}
FastcRenderedCUnits holds split translation units in memory so an uncached build can stream them to TinyCC without temporary C files.
struct FastcRenderingCUnits #
struct FastcRenderingCUnits {
pub:
paths []string
mut:
workers []thread string
order []int
}
FastcRenderingCUnits holds translation-unit render workers. Keeping the workers live lets an uncached build start TinyCC while the C text is still being assembled.
struct FastcUnitLayout #
struct FastcUnitLayout {
pub mut:
head_end int
solo_end int
unit_starts []int
extern_indexes []int
extern_texts []string
prototype_start int
prototype_end int
prototype_texts []string
unit_ref_starts []int
unit_ref_ids []int
solo_prototype_ids []int
tail_prototype_ids []int
// define_texts are the same pieces with `static` dropped, for the first
// unit: a static definition would not satisfy the other units' externs.
define_texts []string
}
FastcUnitLayout locates, in a generation's pieces, the shared head (types, constants, globals, prototypes, runtime), the pieces that belong to one unit only (the startup initializer, the cleanup hook and the synthesized main) and the per-file body units. extern_indexes name the head pieces whose definitions must become declarations in every unit but the first (the globals), with extern_texts holding those declarations.
struct GenerationResult #
struct GenerationResult {
pub:
c_pieces []string
source_paths []string
uses_threads bool
c_flags []string
// units describes how c_pieces split into translation units that the
// drivers can compile in parallel (see fastc_write_c_units).
units FastcUnitLayout
}
GenerationResult contains generated C and the complete resolved V source graph. c_pieces is the generated C in output order; every piece is an ordinary owned string, and writing them in sequence (write_c_pieces) or joining them (c_source) yields the program.
fn (GenerationResult) c_source #
fn (g &GenerationResult) c_source() string
c_source joins the generated C pieces into one string.
fn (GenerationResult) c_size #
fn (g &GenerationResult) c_size() int
c_size returns the size of the generated C in bytes.
- fn fastc_add_prepared_link_input
- fn fastc_begin_feed_prestarted_c_units
- fn fastc_begin_render_c_units
- fn fastc_begin_render_prestarted_c_units
- fn fastc_codesign_shim_dir
- fn fastc_compile_c_unit_texts
- fn fastc_compile_c_units
- fn fastc_compile_prestarted_rendering_c_units
- fn fastc_compile_rendering_c_units
- fn fastc_discard_link
- fn fastc_discard_prestarted_c_units
- fn fastc_finish_link
- fn fastc_finish_prestarted_c_units
- fn fastc_finish_render_c_units
- fn fastc_generation_link_cache_key
- fn fastc_link_cache_key
- fn fastc_macos_system_tbd
- fn fastc_prepare_c_units
- fn fastc_prepare_link
- fn fastc_prepared_link_accepts_inputs
- fn fastc_prepared_link_skips_codesign
- fn fastc_prestart_c_units
- fn fastc_prestarted_c_units_match
- fn fastc_publish_link_cache
- fn fastc_remove_c_units
- fn fastc_remove_codesign_shim_dir
- fn fastc_render_c_units
- fn fastc_restore_link_cache
- fn fastc_run_command
- fn fastc_sign_macho_adhoc
- fn fastc_tcc_job_count
- fn fastc_write_c_units
- fn generate
- fn generate_files
- fn generate_files_with_source_paths
- fn write_c_pieces
- fn FastcDeclaredTypeKind.from
- struct FastcCodesignShim
- struct FastcFeedingCUnits
- struct FastcPreparedLink
- struct FastcPreparedUnits
- struct FastcPrestartedCUnits
- struct FastcRenderedCUnits
- struct FastcRenderingCUnits
- struct FastcUnitLayout
- struct GenerationResult