From 952c5c128f9efaea89d41d882c4ea3ade7df4591 Mon Sep 17 00:00:00 2001 From: zakk Date: Fri, 26 Aug 2005 04:48:05 +0000 Subject: Itsa me, quake3io! git-svn-id: svn://svn.icculus.org/quake3/trunk@2 edf5b092-35ff-0310-97b2-ce42778d08ea --- lcc/doc/4.html | 754 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 754 insertions(+) create mode 100755 lcc/doc/4.html (limited to 'lcc/doc/4.html') diff --git a/lcc/doc/4.html b/lcc/doc/4.html new file mode 100755 index 0000000..0158d8b --- /dev/null +++ b/lcc/doc/4.html @@ -0,0 +1,754 @@ + + + + + +The lcc 4.1 Code-Generation Interface + + + + +

The lcc 4.1 Code-Generation Interface

+ +

Christopher +W. Fraser and David R. Hanson, Microsoft Research

+ +

Contents

+ + +
  • Introduction
  • +
  • 5.1 Type Metrics
  • +
  • 5.3 Symbols
  • +
  • 5.5 Dag Operators
  • +
  • 5.6 Interface Flags
  • +
  • 5.8 Definitions
  • +
  • 5.9 Constants
  • +
  • 5.12 Upcalls
  • +
    + +

    Introduction

    + +

    Version 4.1 is the latest release of lcc, the ANSI C compiler described in +our book A Retargetable C Compiler: Design and Implementation +(Addison-Wesley, 1995, ISBN 0-8053-1670-1). This document summarizes the differences +between the 4.1 code-generation interface and the 3.x interface described in Chap. 5 of A +Retargetable C Compiler.

    + +

    Previous versions of lcc supported only three sizes of integers, two sizes of floats, +and insisted that pointers fit in unsigned integers (see Sec. 5.1 of A Retargetable +C Compiler). These assumptions simplified the compiler, and were suitable for +32-bit architectures. But on 64-bit architectures, such as the DEC ALPHA, it's natural to +have four sizes of integers and perhaps three sizes of floats, and on 16-bit +architectures, 32-bit pointers don't fit in unsigned integers. Also, the 3.x constaints +limited the use of lcc's back ends for other languages, such as Java.

    + +

    Version 4.x removes all of these restrictions: It supports any number of sizes for +integers and floats, and the size of pointers need not be related to the size of any of +the integer types. The major changes in the code-generation interface are: + +

    + +

    In addition, version 4.x is written in ANSI C and uses the standard I/O library and +other standard C functions.

    + +

    The sections below parallel the subsections of Chap. 5 of A Retargetable C +Compiler and summarize the differences between the 3.x and 4.x code-generation +interface. Unaffected subsections are omitted. Page citations refer to pages in A +Retargetable C Compiler.

    + +

    5.1 Type Metrics

    + +

    There are now 10 metrics in an interface record:

    + +
    Metrics charmetric;
    +Metrics shortmetric;
    +Metrics intmetric;
    +Metrics longmetric;
    +Metrics longlongmetric;
    +Metrics floatmetric;
    +Metrics doublemetric;
    +Metrics longdoublemetric;
    +Metrics ptrmetric;
    +Metrics structmetric;
    + +

    Each of these specifies the size and alignment of the corresponding type. ptrmetric +describes all pointers.

    + +

    5.3 Symbols

    + +

    The actual value of a constant is stored in the u.c.v field of a symbol, +which holds a Value:

    + +
    typedef union value {
    +	long i;
    +	unsigned long u;
    +	long double d;
    +	void *p;
    +	void (*g)(void);
    +} Value;
    + +

    The value is stored in the appropriate field according to its type, which is given by +the symbol's type field.

    + +

    5.5 Dag Operators

    + +

    The op field a of node structure holds a dag operator, which +consists of a generic operator, a type suffix, and a size indicator. The type suffixes +are:

    + +
    enum {
    +	F=FLOAT,
    +	I=INT,
    +	U=UNSIGNED,
    +	P=POINTER,
    +	V=VOID,
    +	B=STRUCT
    +};
    +
    +#define sizeop(n) ((n)<<10)
    + +

    Given a generic operator o, a type suffix t, and a size s, +a type- and size-specific operator is formed by o+t+sizeop(s). For example, ADD+F+sizeop(4) +forms the operator ADDF4, which denotes the sum of two 4-byte floats. +Similarly, ADD+F+sizeop(8) forms ADDF8, which denotes 8-byte +floating addition. In the 3.x code-generation interface, ADDF and ADDD +denoted these operations. There was no size indicator in the 3.x operators because the +type suffix supplied both a type and a size.

    + +

    Table 5.1 lists each generic operator, its valid type suffixes, and the number of kids +and syms that it uses; multiple values for kids indicate +type-specific variants. The notations in the syms column give the number +of syms values and a one-letter code that suggests their uses: 1V indicates +that syms[0] points to a symbol for a variable, 1C indicates that syms[0] +is a constant, and 1L indicates that syms[0] is a label. For 1S, syms[0] +is a constant whose value is a size in bytes; 2S adds syms[1], which is a +constant whose value is an alignment. For most operators, the type suffix and size +indicator denote the type and size of operation to perform and the type and size of the +result.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Table 5.1|Node Operators.
    symskidsOperatorType SuffixesSizesOperation
    1V0ADDRF...P..paddress of a parameter
    1V0ADDRG...P..paddress of a global
    1V0ADDRL...P..paddress of a local
    1C0CNSTFIUP..fdx csilh pconstant
    |
    1BCOM.IU...ilhbitwise complement
    1S1CVFFI....fdx ilhconvert from float
    1S1CVIFIU...fdx csilh csilhpconvert from signed integer
    1S1CVP..U..pconvert from pointer
    1S1CVU.IUP..csilh pconvert from unsigned integer
    1INDIRFIUP.Bfdx csilh pfetch
    1NEGFI....fdx ilhnegation
    |
    2ADDFIUP..fdx ilh ilhp paddition
    2BAND.IU...ilhbitwise AND
    2BOR.IU...ilhbitwise inclusive OR
    2BXOR.IU...ilhbitwise exclusive OR
    2DIVFIU...fdx ilhdivision
    2LSH.IU...ilhleft shift
    2MOD.IU...ilhmodulus
    2MULFIU...fdx ilhmultiplication
    2RSH.IU...ilhright shift
    2SUBFIUP..fdx ilh ilhp psubtraction
    |
    2S2ASGNFIUP.Bfdx csilh passignment
    1L2EQFIU...fdx ilh ilhpjump if equal
    1L2GEFIU...fdx ilh ilhpjump if greater than or equal
    1L2GTFIU...fdx ilh ilhpjump if greater than
    1L2LEFIU...fdx ilh ilhpjump if less than or equal
    1L2LTFIU...fdx ilh ilhpjump if less than
    1L2NEFIU...fdx ilh ilhpjump if not equal
    2S1ARGFIUP.Bfdx ilh pargument
    11 or 2CALLFIUPVBfdx ilh pfunction call
    1RETFIUPV.fdx ilh preturn from function
    |
    1JUMP....V.unconditional jump
    1L0LABEL....V.label definition
    + +

    The entries in the Sizes column indicate sizes of the operators that +back ends must implement. Letters denote the size of float (f), double (d), long double +(x), character (c), short integer (s), integer (i), long integer (l), "long +long" integer (h) , and pointer (p). These sizes are separated into sets for each +type suffix, except that a single set is used for both I and U when the set for I is +identical to the set for U.

    + +

    The actual values for the size indicators, fdxcsilhp, depend on the target. A +specification like ADDFf denotes the operator ADD+F+sizeop(f), +where "f" is replaced by a target-dependent value, e.g., ADDF4 and ADDF8. +For example, back ends must implement the following CVI and MUL +operators.

    + +
    +

    CVIFf CVIFd CVIFx
    + CVIIc CVIIs CVIIi CVIIl CVIIh
    + CVIUc CVIUs CVIUi CVIUl CVIUh + CVIUp
    +
    + MULFf MULFd MULFx
    + MULIi MULIl MULIh
    + MULUi MULUl MULUh

    +
    + +

    On most platforms, there are fewer than three sizes of floats and six sizes of +integers, and pointers are usually the same size as one of the integers. And lcc doesn't +support the "long long" type, so h is not currently used. So the set of +platform-specific operators is usually smaller than the list above suggests. For example, +the X86, SPARC, and MIPS back ends implement the following CVI and MUL +operators.

    + +
    +

    CVIF4 CVIF8
    + CVII1 CVII2 CVII4
    + CVIU1 CVIU2 CVIU4
    +
    + MULF4 MULF8
    + MULI4
    + MULU4

    +
    + +

    The set of operators is thus target-dependent; for example, ADDI8 appears +only if the target supports an 8-byte integer type. ops.c is +a program that, given a set of sizes, prints the required operators and their values, +e.g.,

    + +
    +
    % ops c=1 s=2 i=4 l=4 h=4 f=4 d=8 x=8 p=4
    +...
    + CVIF4=4225 CVIF8=8321
    + CVII1=1157 CVII2=2181 CVII4=4229
    + CVIU1=1158 CVIU2=2182 CVIU4=4230
    +...
    + MULF4=4561 MULF8=8657
    + MULI4=4565
    + MULU4=4566
    +...
    +131 operators
    +
    + +

    The type suffix for a conversion operator denotes the type of the result and the size +indicator gives the size of the result. For example, CVUI4 converts an +unsigned (U) to a 4-byte signed integer (I4). The syms[0] +field points to a symbol-table entry for a integer constant that gives the size of the +source operand. For example, if syms[0] in a CVUI4 points to a +symbol-table entry for 2, the conversion widens a 2-byte unsigned integer to a 4-byte +signed integer. Conversions that widen unsigned integers zero-extend; those that widen +signed integers sign-extend.

    + +

    The front end composes conversions between types T1 and T2 +by widening T1 to it's "supertype", if necessary, converting +that result to T2's supertype, then narrowing the result to T2, +if necessary. The following table lists the supertypes; omitted entries are their own +supertypes.

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Type|Supertype
    signed charint
    signed shortint
    unsigned charint, if sizeof (char) < sizeof (int)
    + unsigned, otherwise
    unsigned shortint, if sizeof (short) < sizeof (int)
    + unsigned, otherwise
    void *an unsigned type as large as a pointer
    +
    + +

    Pointers are converted to an unsigned type of the same size, even when that type is not +one of the integer types.

    + +

    For example, the front end converts a signed short to a float by first converting it to +an int and then to a float. It converts an unsigned short to an int with a single CVUIi +conversion, when shorts are smaller than ints.

    + +

    There are now signed and unsigned variants of ASGN, INDIR, BCOM, +BOR, BXOR, BAND, ARG, CALL, +and RET to simplify code generation on platforms that use different +instructions or register set for signed and unsigned operations. Likewise there are now +pointer variants of ASGN, INDIR, ARG, CALL, +and RET.

    + +

    5.6 Interface Flags

    + +
    unsigned unsigned_char:1;
    + +

    tells the front end whether plain characters are signed or unsigned. If it's zero, char +is a signed type; otherwise, char is an unsigned type.

    + +

    All the interface flags can be set by command-line options, e.g., -Wf-unsigned_char=1 +causes plain characters to be unsigned.

    + +

    5.8 Definitions

    + +

    The front end announces local variables by calling

    + +
    void (*local)(Symbol);
    + +

    It announces temporaries likewise; these have the symbol's temporary flag +set, which indicates that the symbol will be used only in the next call to gen. +If a temporary's u.t.cse field is nonnull, it points to the node that +computes the value assigned to the temporary; see page 346.

    + +

    The front end calls

    + +
    void (*address)(Symbol p, Symbol q, long n);
    + +

    to initialize q to a symbol that represents an address of the form x+n, +where x is the address represented by p and the long integer n +is positive or negative.

    + +

    5.9 Constants

    + +

    The interface function

    + +
    void (*defconst)(int suffix, int size, Value v);
    + +

    initializes constants. defconst emits directives to define a cell and initialize it to +a constant value. v is the constant value, suffix identifies the type of the value, and +size is the size of the value in bytes. The value of suffix indicates which field of v +holds the value, as shown in the following table.

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    suffix|v Field|size
    Fv.dfloat, double, long double
    Iv.isigned char, signed short, signed int, signed long
    Uv.uunsigned char, unsigned short, unsigned int, unsigned long
    Pv.pvoid *
    +
    + +

    defconst must narrow v.x when size is less than sizeof +v.x; e.g., to emit an unsigned char, defconst should emit (unsigned +char)v.i.

    + +

    5.12 Upcalls

    + +

    lcc 4.x uses standard I/O and its I/O functions have been changed accordingly. lcc +reads input from the standard input, emits code to the standard output, and writes +diagnostics to the standard error output. It uses freopen to redirect these +streams to explicit files, when necessary.

    + +

    bp, outflush, and outs have been eliminated.

    + +
    extern void fprint(FILE *f, const char *fmt, ...);
    +extern void  print(const char *fmt, ...);
    + +

    print formatted data to file f (fprint) or the standard +output (print). These functions are like standard C's printf and +fprintf, but support only some of the standard conversion specifiers and do +not support flags, precision, and field-width specifications. They support the following +new conversion specifiers in addition to those described on page 99.

    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Specifiers|Corresponding printf Specifiers
    %c%c
    %d %D%d %ld
    %u %U%u %lu
    %x %X%x %lx
    %f %e %g%e %f %g
    %pConverts the corresponding void * argument to unsigned long and prints it with the printf + %#x specifier or just %x when the argument is null.
    %IPrints the number of spaces given by the corresponding argument.
    +
    + +
    #define generic(op)  ((op)&0x3F0)
    +#define specific(op) ((op)&0x3FF)
    + +

    generic(op) returns the generic variant of op; that is, +without its type suffix and size indicator. specific(op) returns the +type-specific variant of op; that is, without its size indicator.

    + +

    newconst has been replaced by

    + +
    extern Symbol intconst(int n);
    + +

    which installs the integer constant n in the symbol table, if necessary, +and returns a pointer to the symbol-table entry.

    + +
    + +
    + Chris Fraser / cwfraser@microsoft.com
    + David Hanson / drh@microsoft.com
    + $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $ +
    + + -- cgit v1.2.3