1.TH SCC-CC 1 scc\-VERSION2.SH NAME3scc-cc \- C compiler driver4.SH SYNOPSIS5.B scc-cc6.RB [ \-c | \-S | \-E ]7.RB [ \-std= standard ]8.br9.RB " " [ \-g ]10.RB [ \-Olevel ]11.br12.RB " " [ \-Wwarn ...]13.br14.RB " " [ \-Idir ...]15.RB [ \-Ldir ...]16.br17.RB " " [ \-Dmacro [ =defn ]...]18.RB [ \-Umacro ]19.br20.RB " " [ \-foption ...]21.RB [ \-mmachine-option ...]22.br23.RB " " [ \-o24.IR outfile ]25.RB [ \-l lib ]...26.br27.RB " " [ \-Msdk ]28.RB [ \-q | \-Q ]29.br30.RB " " [ \-a31.IR arch ]32.RB [ \-t33.IR sys ]34.br35.RB " "36.IR infile ...37.SH DESCRIPTION38.B scc-cc39is the compiler driver of the scc toolchain.40It accepts C source files, intermediate representation files,41assembler source files, object files, and archive libraries,42and orchestrates the tools required to turn them into an43executable or object file.44.PP45For each C source file46.RB ( .c ),47.B scc-cc48runs a pipeline of sub-processes connected by pipes:49the frontend50.B cc151compiles the source to scc IR, the backend52.B cc253lowers the IR to assembly (or to QBE IR when QBE mode is active),54the optional55.B qbe56stage compiles QBE IR to native assembly,57and finally the assembler58.B as59produces an object file.60When linking is not suppressed, the resulting object files are61passed to the linker62.B ld63to produce the final executable.64.PP65Files with other extensions are handled as follows:66.TP67.B .ir68Passed directly to69.BR cc2 ,70skipping the71.B cc172stage.73.TP74.B .qbe75Passed directly to76.BR qbe ,77skipping78.B cc179and80.BR cc2 .81.TP82.B .s83Passed directly to the assembler, skipping all compiler stages.84.TP85.B .o ", " .a86Passed directly to the linker.87.SH OPTIONS88.SS Compilation Control89.TP90.B \-c91Compile and assemble, but do not link.92One object file is produced for each input source file.93If94.B \-o95is also specified, only a single input file is permitted.96.TP97.B \-E98Stop after preprocessing.99The preprocessed source is written to standard output,100or to101.I outfile102if103.B \-o104is given.105Cannot be combined with106.B \-M107or the stop flags108.BR \-S ,109.BR \-k .110.TP111.B \-M112Emit a113.BR make (1)114dependency rule describing the115.B #include116dependencies of each source file, then exit.117No compilation is performed.118Cannot be combined with119.BR \-E .120.TP121.B \-S122Stop after compilation; do not assemble.123Assembly source is written to a file with the same base name as124the input and the suffix125.BR .s .126.TP127.B \-R128Stop after generation of the intermediate QBE representation.129The QBE source is written to a file with the same base name as130the input and the suffix131.BR .qbe .132.SS Preprocessor133.TP134.BI \-D macro [ =value ]135Define the preprocessor macro136.I macro137with an optional replacement text138.IR value .139If140.I value141is omitted, the macro is defined with the value142.BR 1 .143This option may be repeated to define multiple macros.144.TP145.BI \-U macro146Undefine the preprocessor macro147.IR macro .148This option may be repeated.149.TP150.BI \-I dir151Prepend152.I dir153to the list of directories searched for header files.154User-specified directories are searched before system include155directories.156This option may be repeated.157.SS Optimisation158.TP159.BI \-O level160Specify the optimisation level.161This option is accepted for compatibility with other compiler162driver interfaces but is otherwise ignored;163.B scc-cc164does not perform its own optimisation passes.165.SS Linker166.TP167.BI \-L dir168Add169.I dir170to the list of directories searched for libraries.171.TP172.BI \-l lib173Link against the library174.IR lib .175.SS Output176.TP177.BI \-o " outfile"178Place the output into179.IR outfile .180When compiling and linking, the default output name is181.BR a.out .182When compiling to an object file183.RB ( \-c ),184the default output name is derived from the input file name.185.SS Debugging and Symbols186.TP187.B \-g188Generate debugging information.189This flag is forwarded to the assembler and linker.190.TP191.B \-s192Strip all symbol table and relocation information from the output193executable.194This flag is forwarded to the linker.195.SS Warnings196.TP197.B \-w198Enable warning messages for dubious constructs.199The flag is forwarded to200.BR cc1 .201.TP202.BI \-W param203Enable warnings.204The parameter205.I param206is ignored; the effect is the same as207.BR \-w .208Accepted for compatibility with other compiler driver interfaces.209.SS Target210.TP211.BI \-a " arch"212Select the target architecture.213Overrides the214.B ARCH215environment variable.216.TP217.BI \-t " sys"218Select the target operating system.219Overrides the220.B SYS221environment variable.222.SS Driver Behaviour223.TP224.B \-d225Enable verbose driver output.226The exact command line executed for each sub-process is printed227to standard error before that process is started.228.TP229.B \-k230Keep intermediate files.231When this flag is set,232.B scc-cc233saves the IR, QBE IR, and assembler output produced during234compilation alongside the object file,235using the base name of the input file with the suffixes236.BR .ir ,237.BR .qbe ,238and239.BR .s ,240respectively.241The final object file is also kept even when linking.242.TP243.B \-q244Disable QBE mode.245.B cc2246produces native assembly directly, without invoking247.BR qbe (1).248.TP249.B \-Q250Enable QBE mode (default).251.B cc2252produces QBE IR, which is then compiled to native assembly by253.BR qbe (1).254.SS Compatibility Options255The following options are accepted and silently ignored for256compatibility with other compiler driver interfaces:257.BR \-static ,258.BR \-dynamic ,259.BR \-pedantic ,260.BR \-pipe ,261.BR \-ansi ,262any option beginning with263.BR \-std= ,264any265.BI \-f option266and any267.BI \-m option.268.SH COMPILATION PIPELINE269For each C source file,270.B scc-cc271constructs and runs the following pipeline:272.PP273.EX274cc1 | cc2[\-qbe_arch\-abi] | [qbe] | as275.EE276.PP277Each stage is a separate process.278The stages are connected by anonymous pipes so that no large279intermediate files are created on disk unless280.B \-k281is used.282.TP283.B cc1284The C compiler frontend.285It reads the C source file, preprocesses it, parses it,286performs type checking and semantic analysis,287and emits the scc intermediate representation (IR) to standard288output.289It is installed as290.IR $SCCPREFIX/libexec/scc/cc1 .291.TP292.B cc2293The C compiler backend.294It reads the scc IR and emits either native assembly or QBE IR.295The exact binary invoked depends on the target architecture, ABI,296and whether QBE mode is active.297In QBE mode (the default), the binary name has the form298.BI cc2\-qbe_ arch \- abi ;299in native mode300.RB ( \-q )301the form is302.BI cc2\- arch \- abi .303These binaries are installed under304.IR $SCCPREFIX/libexec/scc/ .305.TP306.B qbe307The QBE compiler backend.308Only invoked in QBE mode.309It reads QBE IR and emits native assembly.310.B qbe311is looked up in the standard312.BR PATH .313.TP314.B as315The target assembler.316It assembles the native assembly into an object file.317The assembler command and its arguments are determined at318build time via the319.B ascmd320configuration variable in321.I sys.h322and may include323.B %a324(architecture),325.B %s326(system),327.B %b328(ABI),329.B %p330(library prefix),331and332.B %o333(output file) wildcards.334.PP335After all source files are compiled, the linker is invoked unless336.BR \-c ,337.BR \-S ,338.BR \-E ,339or340.B \-M341suppresses linking:342.TP343.B ld344The target linker.345The linker command and its arguments are determined at build time346via the347.B ldcmd348configuration variable in349.IR sys.h .350The same wildcards as for351.B as352are supported, and353.B %c354expands to the full list of input object files.355.SH ENVIRONMENT VARIABLES356.TP357.B ARCH358Target architecture name (e.g.359.BR amd64 ,360.BR arm64 ,361.BR i386 ).362Overridden by363.BR \-a .364.TP365.B SYS366Target operating system name (e.g.367.BR linux ,368.BR openbsd ).369Overridden by370.BR \-t .371.TP372.B ABI373Target ABI name (e.g.374.BR sysv ).375.TP376.B FORMAT377Target object file format (e.g.378.BR elf ,379.BR coff ).380.TP381.B SCCPREFIX382Path prefix under which the scc suite is installed.383Used to locate384.B cc1385and386.B cc2387under388.IR $SCCPREFIX/libexec/scc/ .389If not set, the compile-time390.B PREFIX391value is used.392.TP393.B SCCLIBPREFIX394Path prefix for scc libraries.395Expanded from the396.B %p397wildcard in linker and assembler command templates.398If not set, the compile-time399.B LIBPREFIX400value is used.401.TP402.B TMPDIR403Directory used for temporary files created during compilation.404If not set or empty, the current directory is used.405.SH EXAMPLES406.PP407Compile a C source file and link into an executable:408.IP409.EX410scc-cc \-o hello hello.c411.EE412.PP413Compile to an object file only:414.IP415.EX416scc-cc \-c hello.c417.EE418.PP419Compile multiple source files and link:420.IP421.EX422scc-cc \-o prog main.c util.c \-lm423.EE424.PP425Preprocess only and view the output:426.IP427.EX428scc-cc \-E hello.c429.EE430.PP431Generate make dependency rules:432.IP433.EX434scc-cc \-M hello.c435.EE436.PP437Stop after compilation, keeping intermediate files:438.IP439.EX440scc-cc \-k \-c hello.c441.EE442.PP443Compile for a specific target:444.IP445.EX446ARCH=arm64 ABI=sysv SYS=linux scc-cc \-o hello hello.c447.EE448.PP449Compile in native mode (no QBE):450.IP451.EX452scc-cc \-q \-o hello hello.c453.EE454.PP455Show all sub-process command lines:456.IP457.EX458scc-cc \-d \-c hello.c459.EE460.PP461The462.B \-d463flag prints the exact command line of each sub-process to standard error.464For example, compiling465.I hello.c466on an amd64 Linux system in QBE mode produces:467.IP468.EX469/usr/local/libexec/scc/cc1 \-I /usr/local/include/scc/bits/amd64/ \e470 \-I /usr/local/include/scc/bits/linux/ \e471 \-I /usr/local/include/scc/bits/linux/amd64/ \e472 \-I /usr/local/include/scc/ hello.c473/usr/local/libexec/scc/cc2\-qbe_amd64\-sysv474qbe \-t amd64_sysv475as \-o hello.o476.EE477.SH DIAGNOSTICS478When a sub-process in the compilation pipeline fails,479.B scc-cc480reports an error to standard error and exits with a non-zero status.481.PP482If483.B cc1484exits with a non-zero status, the error message comes from485.B cc1486itself (a compilation error such as a syntax or type error) and487.B scc-cc488exits silently.489Likewise, if the linker490.B ld491fails, its own error output is displayed and492.B scc-cc493exits without an additional message.494.PP495If any stage terminates by a signal496or any other stage in the pipeline497.RB ( cc2 ,498.BR qbe ,499or500.BR as )501terminates with non-zero exit then502these conditions are considered an internal error.503In this case504.B scc-cc505prints the following message to standard error:506.IP507.EX508scc-cc:tool: internal error509.EE510.PP511where512.I tool513is the name of the failing sub-process.514This message indicates a bug in the toolchain rather than an error in515the user's source code.516The same message is printed if517.B scc-cc518cannot519.BR execvp (2)520the sub-process binary (for example because521.B SCCPREFIX522is set incorrectly and523.B cc1524or525.B cc2526cannot be found).527In this case,528Using the option529.B \-d530combined with531.B \-k532is very useful because533it provides all the information to run the tool in isolation534and debug the issue.535.SH SEE ALSO536.BR scc (1),537.BR scc\-cc1 (1),538.BR scc\-cc2 (1),539.BR scc\-cpp (1),540.BR scc\-ld (1),541.BR scc\-as (1),542.BR scc\-ir (7),543.BR qbe (1)