⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcc-doc.html

📁 Tiny C&C++,看看吧,也许用的着
💻 HTML
📖 第 1 页 / 共 3 页
字号:
          printf("unexpected\n");          break;    }</PRE><LI>The keyword <CODE>__attribute__</CODE> is handled to specify variable orfunction attributes. The following attributes are supported:<UL><LI><CODE>aligned(n)</CODE>: align data to n bytes (must be a power of two).<LI><CODE>section(name)</CODE>: generate function or data in assembly  section name (name is a string containing the section name) instead  of the default section.<LI><CODE>unused</CODE>: specify that the variable or the function is unused.<LI><CODE>cdecl</CODE>: use standard C calling convention.<LI><CODE>stdcall</CODE>: use Pascal-like calling convention.</UL>Here are some examples:<PRE>    int a __attribute__ ((aligned(8), section(".mysection")));</PRE>align variable <CODE>a</CODE> to 8 bytes and put it in section <CODE>.mysection</CODE>.<PRE>    int my_add(int a, int b) __attribute__ ((section(".mycodesection")))     {        return a + b;    }</PRE>generate function <CODE>my_add</CODE> in section <CODE>.mycodesection</CODE>.<LI>GNU style variadic macros:<PRE>    #define dprintf(fmt, args...) printf(fmt, ## args)    dprintf("no arg\n");    dprintf("one arg %d\n", 1);</PRE><LI><CODE>__FUNCTION__</CODE> is interpreted as C99 <CODE>__func__</CODE>(so it has not exactly the same semantics as string literal GNUCwhere it is a string literal).<LI>The <CODE>__alignof__</CODE> keyword can be used as <CODE>sizeof</CODE>to get the alignment of a type or an expression.<LI>The <CODE>typeof(x)</CODE> returns the type of <CODE>x</CODE>.<CODE>x</CODE> is an expression or a type.<LI>Computed gotos: <CODE>&#38;&#38;label</CODE> returns a pointer of type<CODE>void *</CODE> on the goto label <CODE>label</CODE>. <CODE>goto *expr</CODE> can beused to jump on the pointer resulting from <CODE>expr</CODE>.<LI>Inline assembly with asm instruction:<A NAME="IDX1"></A><A NAME="IDX2"></A><A NAME="IDX3"></A><PRE>static inline void * my_memcpy(void * to, const void * from, size_t n){int d0, d1, d2;__asm__ __volatile__(        "rep ; movsl\n\t"        "testb $2,%b4\n\t"        "je 1f\n\t"        "movsw\n"        "1:\ttestb $1,%b4\n\t"        "je 2f\n\t"        "movsb\n"        "2:"        : "=&#38;c" (d0), "=&#38;D" (d1), "=&#38;S" (d2)        :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)        : "memory");return (to);}</PRE><A NAME="IDX4"></A>TCC includes its own x86 inline assembler with a <CODE>gas</CODE>-like (GNUassembler) syntax. No intermediate files are generated. GCC 3.x namedoperands are supported.<LI><CODE>__builtin_types_compatible_p()</CODE> and <CODE>__builtin_constant_p()</CODE>are supported.</UL><H2><A NAME="SEC9" HREF="tcc-doc.html#TOC9">3.4 TinyCC extensions</A></H2><UL><LI><CODE>__TINYC__</CODE> is a predefined macro to <CODE>1</CODE> toindicate that you use TCC.<LI><CODE>#!</CODE> at the start of a line is ignored to allow scripting.<LI>Binary digits can be entered (<CODE>0b101</CODE> instead of<CODE>5</CODE>).<LI><CODE>__BOUNDS_CHECKING_ON</CODE> is defined if bound checking is activated.</UL><H1><A NAME="SEC10" HREF="tcc-doc.html#TOC10">4. TinyCC Assembler</A></H1><P>Since version 0.9.16, TinyCC integrates its own assembler. TinyCCassembler supports a gas-like syntax (GNU assembler). You candesactivate assembler support if you want a smaller TinyCC executable(the C compiler does not rely on the assembler).<P>TinyCC Assembler is used to handle files with <TT>`.S'</TT> (Cpreprocessed assembler) and <TT>`.s'</TT> extensions. It is also used tohandle the GNU inline assembler with the <CODE>asm</CODE> keyword.<H2><A NAME="SEC11" HREF="tcc-doc.html#TOC11">4.1 Syntax</A></H2><P>TinyCC Assembler supports most of the gas syntax. The tokens are thesame as C.<UL><LI>C and C++ comments are supported.<LI>Identifiers are the same as C, so you cannot use '.' or '$'.<LI>Only 32 bit integer numbers are supported.</UL><H2><A NAME="SEC12" HREF="tcc-doc.html#TOC12">4.2 Expressions</A></H2><UL><LI>Integers in decimal, octal and hexa are supported.<LI>Unary operators: +, -, ~.<LI>Binary operators in decreasing priority order:<OL><LI>*, /, %<LI>&#38;, |, ^<LI>+, -</OL><LI>A value is either an absolute number or a label plus an offset.All operators accept absolute values except '+' and '-'. '+' or '-' can beused to add an offset to a label. '-' supports two labels only if theyare the same or if they are both defined and in the same section.</UL><H2><A NAME="SEC13" HREF="tcc-doc.html#TOC13">4.3 Labels</A></H2><UL><LI>All labels are considered as local, except undefined ones.<LI>Numeric labels can be used as local <CODE>gas</CODE>-like labels.They can be defined several times in the same source. Use 'b'(backward) or 'f' (forward) as suffix to reference them:<PRE> 1:      jmp 1b /* jump to '1' label before */      jmp 1f /* jump to '1' label after */ 1:</PRE></UL><H2><A NAME="SEC14" HREF="tcc-doc.html#TOC14">4.4 Directives</A></H2><P><A NAME="IDX5"></A><A NAME="IDX6"></A><A NAME="IDX7"></A><A NAME="IDX8"></A><A NAME="IDX9"></A><A NAME="IDX10"></A><A NAME="IDX11"></A><A NAME="IDX12"></A><A NAME="IDX13"></A><A NAME="IDX14"></A><A NAME="IDX15"></A><A NAME="IDX16"></A><A NAME="IDX17"></A><A NAME="IDX18"></A><A NAME="IDX19"></A><A NAME="IDX20"></A><A NAME="IDX21"></A><P>All directives are preceeded by a '.'. The following directives aresupported:<UL><LI>.align n[,value]<LI>.skip n[,value]<LI>.space n[,value]<LI>.byte value1[,value2...]<LI>.word value1[,value2...]<LI>.short value1[,value2...]<LI>.int value1[,value2...]<LI>.long value1[,value2...]<LI>.string string<LI>.globl symbol<LI>.global symbol<LI>.section section<LI>.text<LI>.data<LI>.bss<LI>.fill repeat[,size[,value]]<LI>.org n<LI>.previous<LI>.string string[,...]<LI>.asciz string[,...]<LI>.ascii string[,...]</UL><H2><A NAME="SEC15" HREF="tcc-doc.html#TOC15">4.5 X86 Assembler</A></H2><P><A NAME="IDX22"></A><P>All X86 opcodes are supported. Only ATT syntax is supported (sourcethen destination operand order). If no size suffix is given, TinyCCtries to guess it from the operand sizes.<P>Currently, MMX opcodes are supported but not SSE ones.<H1><A NAME="SEC16" HREF="tcc-doc.html#TOC16">5. TinyCC Linker</A></H1><P><A NAME="IDX23"></A><H2><A NAME="SEC17" HREF="tcc-doc.html#TOC17">5.1 ELF file generation</A></H2><P><A NAME="IDX24"></A><P>TCC can directly output relocatable ELF files (object files),executable ELF files and dynamic ELF libraries without relying on anexternal linker.<P>Dynamic ELF libraries can be output but the C compiler does not generateposition independent code (PIC). It means that the dynamic librarycode generated by TCC cannot be factorized among processes yet.<P>TCC linker eliminates unreferenced object code in libraries. A single pass isdone on the object and library list, so the order in which object files andlibraries are specified is important (same constraint as GNU ld). No groupingoptions (<SAMP>`--start-group'</SAMP> and <SAMP>`--end-group'</SAMP>) are supported.<H2><A NAME="SEC18" HREF="tcc-doc.html#TOC18">5.2 ELF file loader</A></H2><P>TCC can load ELF object files, archives (.a files) and dynamiclibraries (.so).<H2><A NAME="SEC19" HREF="tcc-doc.html#TOC19">5.3 GNU Linker Scripts</A></H2><P><A NAME="IDX25"></A><A NAME="IDX26"></A><A NAME="IDX27"></A><A NAME="IDX28"></A><A NAME="IDX29"></A><A NAME="IDX30"></A><P>Because on many Linux systems some dynamic libraries (such as<TT>`/usr/lib/libc.so'</TT>) are in fact GNU ld link scripts (horrible!),the TCC linker also supports a subset of GNU ld scripts.<P>The <CODE>GROUP</CODE> and <CODE>FILE</CODE> commands are supported. <CODE>OUTPUT_FORMAT</CODE>and <CODE>TARGET</CODE> are ignored.<P>Example from <TT>`/usr/lib/libc.so'</TT>:<PRE>/* GNU ld script   Use the shared library, but some functions are only in   the static library, so try that secondarily.  */GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a )</PRE><H1><A NAME="SEC20" HREF="tcc-doc.html#TOC20">6. TinyCC Memory and Bound checks</A></H1><P><A NAME="IDX31"></A><A NAME="IDX32"></A><P>This feature is activated with the <SAMP>`-b'</SAMP> (see section <A HREF="tcc-doc.html#SEC2">2. Command line invocation</A>).<P>Note that pointer size is <EM>unchanged</EM> and that code generatedwith bound checks is <EM>fully compatible</EM> with uncheckedcode. When a pointer comes from unchecked code, it is assumed to bevalid. Even very obscure C code with casts should work correctly.<P>For more information about the ideas behind this method, see<A HREF="http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html">http://www.doc.ic.ac.uk/~phjk/BoundsChecking.html</A>.<P>Here are some examples of caught errors:<DL COMPACT><DT>Invalid range with standard string function:<DD><PRE>{    char tab[10];    memset(tab, 0, 11);}</PRE><DT>Out of bounds-error in global or local arrays:<DD><PRE>{    int tab[10];    for(i=0;i&#60;11;i++) {        sum += tab[i];    }}</PRE><DT>Out of bounds-error in malloc'ed data:<DD><PRE>{    int *tab;    tab = malloc(20 * sizeof(int));    for(i=0;i&#60;21;i++) {        sum += tab4[i];    }    free(tab);}</PRE><DT>Access of freed memory:<DD><PRE>{    int *tab;    tab = malloc(20 * sizeof(int));    free(tab);    for(i=0;i&#60;20;i++) {        sum += tab4[i];    }}</PRE><DT>Double free:<DD><PRE>{    int *tab;    tab = malloc(20 * sizeof(int));    free(tab);    free(tab);}</PRE></DL><H1><A NAME="SEC21" HREF="tcc-doc.html#TOC21">7. The <CODE>libtcc</CODE> library</A></H1><P>The <CODE>libtcc</CODE> library enables you to use TCC as a backend fordynamic code generation. <P>Read the <TT>`libtcc.h'</TT> to have an overview of the API. Read<TT>`libtcc_test.c'</TT> to have a very simple example.<P>The idea consists in giving a C string containing the program you wantto compile directly to <CODE>libtcc</CODE>. Then you can access to any globalsymbol (function or variable) defined.<H1><A NAME="SEC22" HREF="tcc-doc.html#TOC22">8. Developer's guide</A></H1><P>This chapter gives some hints to understand how TCC works. You can skipit if you do not intend to modify the TCC code.<H2><A NAME="SEC23" HREF="tcc-doc.html#TOC23">8.1 File reading</A></H2><P>The <CODE>BufferedFile</CODE> structure contains the context needed to read afile, including the current line number. <CODE>tcc_open()</CODE> opens a newfile and <CODE>tcc_close()</CODE> closes it. <CODE>inp()</CODE> returns the nextcharacter.<H2><A NAME="SEC24" HREF="tcc-doc.html#TOC24">8.2 Lexer</A></H2><P><CODE>next()</CODE> reads the next token in the currentfile. <CODE>next_nomacro()</CODE> reads the next token without macroexpansion.<P><CODE>tok</CODE> contains the current token (see <CODE>TOK_xxx</CODE>)constants. Identifiers and keywords are also keywords. <CODE>tokc</CODE>contains additional infos about the token (for example a constant valueif number or string token).<H2><A NAME="SEC25" HREF="tcc-doc.html#TOC25">8.3 Parser</A></H2><P>The parser is hardcoded (yacc is not necessary). It does only one pass,except:<UL><LI>For initialized arrays with unknown size, a first passis done to count the number of elements.<LI>For architectures where arguments are evaluated inreverse order, a first pass is done to reverse the argument order.</UL><H2><A NAME="SEC26" HREF="tcc-doc.html#TOC26">8.4 Types</A></H2><P>The types are stored in a single 'int' variable. It was choosen in thefirst stages of development when tcc was much simpler. Now, it may notbe the best solution.<PRE>#define VT_INT        0  /* integer type */#define VT_BYTE       1  /* signed byte type */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -