home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / vbcc / doc / interface.doc < prev    next >
Encoding:
Text File  |  1997-01-31  |  25.4 KB  |  717 lines

  1. (c) in 1995-97 by Volker Barthelmann
  2.  
  3. This document is under construction! Not for public distribution!
  4.  
  5. This document describes some of the internals of vbcc and tries to explain
  6. what must be done to write a code generator for vbcc.
  7. However if someone wants to write one, I suggest to contact me first,
  8. so that it can be integrated into the source tree.
  9.  
  10. You should only have to rewrite/change the files machine.c and machine.h.
  11. It is probably best to choose an appropriate one from the generic* ones
  12. and only change something or add something and leave the rest untouched.
  13.  
  14. From now on integer means any of {char, short, int, long} or their
  15. unsigned couterparts. Arithmetic means integer or float or double.
  16. Elementary type means arithmetic or pointer.
  17. If You intend to write a code generator for a machine with different
  18. kinds of pointers You might have some problems.
  19.  
  20.  
  21. THE INTERMEDIATE CODE
  22.  
  23. vbcc will generate intermediate code for every function and pass this code
  24. to the code generator which has to convert it into the desired output.
  25.  
  26. In the future there may be a code generator generator which reads a machine
  27. description file and generates a code generator from that, but it is not
  28. clear whether this could simplify much without taking penalties in the
  29. generated code.
  30. Anyway this would be a layer on top of the current interface to the code
  31. generator so that the interface described in this document would still be
  32. valid and accessable.
  33.  
  34. The intermediate code is represented as a doubly linked list of quadruples
  35. (I am calling them ICs from now on) consisting mainly of an operator, two
  36. source operands and a target. They are represented like this:
  37.  
  38. struct IC{
  39.     struct IC *prev;
  40.     struct IC *next;
  41.     int code;
  42.     int typf;
  43.     [...]
  44.     struct obj q1;
  45.     struct obj q2;
  46.     struct obj z;
  47.     [...]
  48. };
  49.  
  50. The only members relevant to the code generator are 'prev', 'next', 'code',
  51. 'typf', 'q1', 'q2' and 'z'.
  52.  
  53. 'prev' and 'next' are pointers to the previous and next IC.
  54. The first IC has 'prev'==0 and the last one has 'next'==0.
  55.  
  56. 'typf' is the type of the operands of this IC. This can be one of:
  57.  
  58.     #define CHAR 1
  59.     #define SHORT 2
  60.     #define INT 3
  61.     #define LONG 4
  62.     #define FLOAT 5
  63.     #define DOUBLE 6
  64.     #define VOID 7
  65.     #define POINTER 8
  66.     #define ARRAY 9
  67.     #define STRUCT 10
  68.     #define UNION 11
  69.     #define ENUM 12         /*  not relevant for code generator     */
  70.     #define FUNKT 13
  71.  
  72.     and can be additionally or'ed by
  73.  
  74.     #define UNSIGNED 16
  75.     #define CONST 64
  76.     #define VOLATILE 128
  77.     #define UNCOMPLETE 256
  78.  
  79.     However only UNSIGNED is of real importance for the code generator.
  80.     'typf'&15 yields the type without any qualifiers.
  81.  
  82. 'q1', 'q2' and 'z' are the source1 (quelle1 in German), source2 and target
  83. (ziel).
  84. If a result has to be computed, it always will be stored in the object 'z'
  85. and the objects 'q1' and 'q2' may not be destroyed during this operation.
  86.  
  87. The objects are described by this structure.
  88.  
  89. struct obj{
  90.     int flags;
  91.     int reg;
  92.     struct Var *v;
  93.     struct AddressingMode *am;
  94.     union atyps{
  95.         zchar vchar;
  96.         zchar vuchar;
  97.         zshort vshort;
  98.         zushort vushort;
  99.         zint vint;
  100.         zuint vuint;
  101.         zlong vlong;
  102.         zulong vulong;
  103.         zfloat vfloat;
  104.         zdouble vdouble;
  105.         zpointer vpointer;
  106.     }val;
  107. };
  108.  
  109. 'flags' describes what kind the object is. It can be a combination of
  110.  
  111. #define VAR 1
  112.  
  113.     The object is a variable. The pointer to its struct Var is in 'v'.
  114.     'val.vlong' vontains an offset that has to be added to it.
  115.     In certain cases (e.g. flags==VAR|REG) where an offset is
  116.     useless, it can always be taken as 0.
  117.  
  118.     A struct Var looks like:
  119.  
  120.     struct Var{
  121.         int storage_class;
  122.         [...]
  123.         char *identifier;
  124.         [...]
  125.         zlong offset;
  126.         [...]
  127.     };
  128.  
  129.     The relevant entries are:
  130.  
  131.     'identifier':
  132.  
  133.         The name of the variable. Usually only of interest for variables
  134.         with external-linkage.
  135.  
  136.     'storage_class':
  137.  
  138.         One of:
  139.             #define AUTO 1
  140.             #define REGISTER 2
  141.             #define STATIC 3
  142.             #define EXTERN  4
  143.             #define TYPEDEF 5       /*  not relevant    */
  144.  
  145.         If the variable is not assigned to a register (i.e. bit REG
  146.         is not set in the flags of the struct obj) then the variable can
  147.         be addressed in the following ways (with examples of 68k-code):
  148.  
  149.         'storage_class' == AUTO or 'storage_class' == REGISTER:
  150.  
  151.             'offset' contains the offset inside the local-variables section.
  152.             The code generator must decide how it's going to handle the
  153.             activation record.
  154.             If 'offset' < 0 then the variable is a function argument on the
  155.             stack. In this case the offset in the parameter-area is
  156.              - ('offset' + 'maxalign').
  157.  
  158.             The code generator may have to calculate the actual offset
  159.             to a stack- or frame-pointer from the value in 'offset'.
  160.  
  161.                 'offset'+'val.vlong'(sp)
  162.  
  163.             Note that 'storage_class' REGISTER is equivalent to AUTO - whether
  164.             the variable is actually assigned a register is specified by
  165.             the bit REG in the 'flags' of the 'struct obj'.
  166.  
  167.         'storage_class' == EXTERN
  168.  
  169.             The variable can be addressed through its name in 'identifier'.
  170.  
  171.                 'val.vlong'+_'identifier'
  172.  
  173.         'storage_class' == STATIC
  174.  
  175.             The variable can be addressed through a numbered label. The
  176.             label number is stored in 'offset'.
  177.  
  178.                 'val.vlong'+l'offset'
  179.  
  180. #define KONST 2
  181.  
  182.     The object is a constant. Its value is in the corresponding (to 'typf')
  183.     member of 'val'.
  184.  
  185. #define DREFOBJ 32
  186.  
  187.     The content of the location in memory the object points to is used.
  188.  
  189. #define REG 64
  190.  
  191.     The object is a register. 'reg' contains its number.
  192.  
  193. #define VARADR 128
  194.  
  195.     The address of the object is to be used. Only together with static
  196.     variables (i.e. 'storage_class' STATIC or EXTERN).
  197.  
  198. Certain combination of these flags are possible, e.g. VAR|REG, VAR|DREFOBJ,
  199. VAR|REG|DREFOBJ. 'flags' can be 0. Also some other bits which are not relevant
  200. to the code generator may be set.
  201. Constants will usually be in 'q2' if possible. One of the sources always is
  202. not constant and the target is always an lvalue.
  203. Unless otherwise specified all operands of an IC are of the type 'typf' (which
  204. may be further restricted by 'code'). However not all objects must be used.
  205. This depends on 'code' and is listed below. In most cases (i.e. when not
  206. explicitly stated) 'typf' is an elementary type (i.e. arithmetic or pointer).
  207.  
  208. 'am' can be used to store information on special addressing modes.
  209. This has to be handled by the by the code generator. However 'am' has to be 0
  210. or has to point to a struct AddressingMode that was allocated using malloc()
  211. when the code generator returns.
  212.  
  213. 'val' stores either the value of the object if it is a constant or an offset
  214. if it is a variable.
  215.  
  216. 'code' describes the operation and can be one of:
  217.  
  218. #define ASSIGN 2
  219.  
  220.     Copy 'q1' to 'z'. 'q2.val.vlong' contains the size of the objects (this is
  221.     necessary if it is an array or a struct). 'typf' does not have to be an
  222.     elementary type!
  223.  
  224.     The only case where 'typf' == ARRAY should be in automatic initializations.
  225.  
  226.     It is also possible that ('typf'&15) == CHAR but the size is != 1. This is
  227.     created for an inline memcpy/strcpy where the type is not known.
  228.  
  229. #define OR 16
  230. #define XOR 17
  231. #define AND 18
  232.  
  233.     Bitwise boolean operations. q1,q2->z.
  234.     All operands are integers.
  235.  
  236. #define LSHIFT 25
  237. #define RSHIFT 26
  238.  
  239.     Bit shifting. q1,q2->z. 'q2' is the number of shifts.
  240.     All operands are integers. AFAIK the behaviour is implementation defined
  241.     if 'q2' is negative.
  242.  
  243. #define ADD 27
  244. #define SUB 28
  245. #define MULT 29
  246. #define DIV 30
  247.  
  248.     Standard arithmetic operations. q1,q2->z.
  249.     All operands are of arithmetic types (integers or floating point).
  250.  
  251. #define MOD 31
  252.  
  253.     Modulo (%). q1,q2->z.
  254.     All operands are integers.
  255.  
  256. #define KOMPLEMENT 33
  257.  
  258.     Bitwise complement. q1->z.
  259.     All operands are integers.
  260.  
  261. #define MINUS 38
  262.  
  263.     Unary minus. q1->z.
  264.     All operands are of arithmetic types (integers or floating point).
  265.  
  266. #define ADDRESS 40
  267.  
  268.     Get the address of an object. q1->z.
  269.     'z' is always a pointer and 'q1' is always an automatic variable.
  270.  
  271. #define CALL 42
  272.  
  273.     Call the function 'q1'. Currently 'q1' is a function rather than a pointer
  274.     to a function. This may change in the future.
  275.  
  276.     'q2.val.vlong' contains the number of bytes pushed on the stack as
  277.     function arguments. Those may have to be popped from the stack after the
  278.     function returns depending on the calling mechanism.
  279.  
  280. #define CONVCHAR 50
  281. #define CONVSHORT 51
  282. #define CONVINT 52
  283. #define CONVLONG 53
  284. #define CONVFLOAT 54
  285. #define CONVDOUBLE 55
  286. #define CONVPOINTER 57
  287. #define CONVUCHAR 58
  288. #define CONVUSHORT 59
  289. #define CONVUINT 60
  290. #define CONVULONG 61
  291.  
  292.     Convert one type to another. q1->z.
  293.     'z' is always of the type 'typf'. 'q1' is a short in CONVSHORT and an
  294.     unsigned long in CONVULONG etc.
  295.     Conversions floating point<->pointers do not occur.
  296.  
  297. #define ALLOCREG 65
  298.  
  299.     From now on the register 'q1.reg' is in use. No code has to be generated
  300.     for this, but it is probably necessary to keep track of the registers
  301.     in use to know which registers are available for the code generator
  302.     at a time and which registers the function trashes.
  303.  
  304. #define FREEREG 66
  305.  
  306.     From now on the register 'q1.reg' is free.
  307.     Also it means that the value currently stored in 'q1.reg' is not used any
  308.     more and therefore provides a little bit of data flow information.
  309.     Note however that if a FREEREG follows a branch the value of the register
  310.     may be used at the target of the branch.
  311.  
  312. #define COMPARE 77
  313.  
  314.     Compare and set condition codes. q1,q2(->z).
  315.     Compare the operands and set the condition code, so that
  316.     BEQ, BNE, BLT, BGE, BLE or BGT works.
  317.     If 'z.flags' == 0 then the condition codes will be evaluated immediately
  318.     after the COMPARE, i.e. the next instruction (except possible FREEREGs)
  319.     will be a conditional branch.
  320.     However if a target supports several condition code registers and sets
  321.     the global variable 'multiple_ccs' to 1 vbcc might use those registers
  322.     and perform certain optimizations. Then 'z' may be non-empty and the
  323.     condition codes have to be stored in 'z' (this will usually be a condition
  324.     code register).
  325.  
  326. #define TEST 68
  327.  
  328.     Test 'q1' to 0 and set condition codes. q1.
  329.     This is equal to COMPARE 'q1',(corresponding constant 0)
  330.     but only the condition code for BEQ and BNE has to be set.
  331.  
  332. #define LABEL 69
  333.  
  334.     Generate a label. 'typf' specifies the number of the label.
  335.  
  336. #define BEQ 70
  337. #define BNE 71
  338. #define BLT 72
  339. #define BGE 73
  340. #define BLE 74
  341. #define BGT 75
  342.  
  343.     Branch on condition codes. (q1)
  344.     'typf' specifies the label where program execution shall continue, if the
  345.     condition code is true (otherwise continue with next statement).
  346.     The condition codes mean equal, not equal, less than, greater or equal,
  347.     less or equal and greater than.
  348.     If 'q1' is empty then the codes set by the last COMPARE or TEST must be
  349.     evaluated. Otherwise 'q1' contains the condition codes.
  350.  
  351.     On some machines the type of operands of a comparison (e.g unsigned or
  352.     signed) is encoded in the branch instructions rather than in the
  353.     comparison instructions. In this case the code generator has to keep
  354.     track of the type of the last comparison.
  355.  
  356. #define BRA 76
  357.  
  358.     Branch always. 'typf' specifies the label where program execution
  359.     continues.
  360.  
  361. #define PUSH 78
  362.  
  363.     Push q1 on the stack. q1.
  364.     'q2.val.vlong' contains the size of the object and 'q1' does not have to
  365.     be an elementary type (see ASSIGN).
  366.     This is only used for passing function arguments.
  367.  
  368. #define ADDI2P 81
  369.  
  370.     Add an integer to a pointer. q1,q2->z.
  371.     'q1' and 'z' are always pointers and 'q2' is an integer of type 'typf'.
  372.     'z' has to be 'q1' increased by 'q2' bytes.
  373.  
  374. #define SUBIFP 82
  375.  
  376.     Subtract an Integer from a pointer. q1,q2->z.
  377.     'q1' and 'z' are always pointers and 'q2' is an integer of type 'typf'.
  378.     'z' has to be 'q1' decreased by 'q2' bytes.
  379.  
  380. #define SUBPFP 83
  381.  
  382.     Subtract a pointer from a pointer. q1,q2->z.
  383.     'q1' and 'q2' is a pointer and 'z' is an integer of type 'typf'.
  384.     'z' has to be 'q1' - 'q2' in bytes.
  385.  
  386. #define GETRETURN 93
  387.  
  388.     Get the return value of the last function call. ->z.
  389.     If the return value is in a register this will be in 'q1.reg'. Otherwise
  390.     'q1.reg' will be 0.
  391.     This follows immediately after a CALL instruction (except possible
  392.     FREEREGs).
  393.  
  394. #define SETRETURN 94
  395.  
  396.     Set the return value of the current function. q1.
  397.     If the return value is in a register this will be in 'z.reg'. Otherwise
  398.     'z.reg' will be 0.
  399.     This is immediately followed by a function exit (i.e. it is the last
  400.     IC or followed by an unconditional branch to a label which is the last
  401.     IC - always ignoring FREEREGs).
  402.  
  403. #define MOVEFROMREG 95
  404.  
  405.     Move a register to memory. q1->z.
  406.     'q1' is always a register and 'z' an array of size 'regsize[q1.reg]'.
  407.  
  408. #define MOVETOREG 96
  409.  
  410.     Load a register from memory. q1->z.
  411.     'z' is always a register and 'q1' an array of size 'regsize[z.reg]'.
  412.  
  413. #define NOP 97
  414.  
  415.     Do nothing.
  416.  
  417.  
  418.  
  419. MACHINE.H
  420.  
  421. Only a few changes should be necessary to machine.h.
  422.  
  423. TARGET DATA TYPES
  424.  
  425. First you need a typedef every elementary type of the target machine.
  426. These are:
  427.  
  428.     zchar           type char on the target machine
  429.     zuchar          type unsigned char on the target machine
  430.     zshort          ...
  431.     zushort
  432.     zint
  433.     zuint
  434.     zlong
  435.     zulong
  436.     zfloat
  437.     zdouble
  438.     zpointer        a byte pointer on the target machine
  439.  
  440. If the host machine has an elementary type which can represent a type of
  441. the target machine you can use that. However if there is none (e.g. if
  442. you want to build a cross-compiler for a 64bit machine on a 32bit host)
  443. you have to define it as a struct (if you use an array it has to be embedded
  444. in a struct because vbcc assigns those types and passes them as function
  445. arguments etc.) and provide some arithmetic functions.
  446.  
  447. In the future there will perhaps be an automated installation procedure which
  448. checks if the host machine offers appropriate data types and installs
  449. emulation routines otherwise if possible. However at the moment this must
  450. be done manually for every host.
  451.  
  452. If you could typedef every type to a host type you can copy the bunch of
  453. cryptic #defines from the beginning of an example machine.h and skip the
  454. next part about target arithmetic.
  455.  
  456. TARGET ARITHMETIC
  457.  
  458. Now you have to provide a lot of functions performing operations using the
  459. target machine's arithmetic. You can look them up in any machine.h.
  460. E.g. zladd() takes two zlongs and returns their sum as zlong. zuladd() does
  461. the same with zulongs, zdadd() with doubles. No functions for smaller types
  462. are needed because vbcc will calculate with the wider types and convert the
  463. results down if needed.
  464.  
  465. If you could typedef any target type to an elementary type of the host
  466. machine you can simply provide a macro, e.g. #define zladd(x,y) ((x)+(y)).
  467.  
  468. Note that you _must_ provide prototypes for all functions which are not
  469. macros.
  470.  
  471. Now you must provide conversion functions which convert between types of the
  472. target machine. E.g. zl2zc takes a zlong and returns it converted to a zchar.
  473. Again look at an example machine.h to see which ones are needed.
  474.  
  475. A few functions for converting between target and host types are also
  476. necessary, e.g. l2zl takes a long and returns it converted to a zlong.
  477.  
  478. At last we need functions for comparing target data types. E.g. zlleq(a,b)
  479. must return true if zlong a <= zlong b and false otherwise. zleqto(a,b)
  480. must return true if zlong a == zlong b and false otherwise.
  481.  
  482. ADDRESSING-MODES
  483.  
  484. If the code generator supports extended addressing modes You have to think
  485. of a way to represent them and define the structure AddressingMode so that
  486. all Modes can be stored in it. The machine independant part of vbcc will
  487. not use these modes, so Your code generator has to find a way to combine
  488. several statements to make use of these modes.
  489.  
  490. BASIC PARAMETERS
  491.  
  492. #define MAXR to the number of available registers.
  493.  
  494. #define MAXGF to the number of command line flags that can be used to
  495. configure the behaviour of the code generator. This must be at least one
  496. even if you do not use any flags.
  497.  
  498. #define USEQ2ASZ as 0 or 1; if it is set to 0, no ICs where 'q2' == 'z'
  499. will be generated. This is because those ICs might be hard to implement
  500. efficiently on certain CPUs.
  501.  
  502. #define MINADDI2P to the smallest integer type (i.e. CHAR, SHORT or INT)
  503. that can be added to a pointer. Smaller types will be automatically converted
  504. to MINADDI2P when they are to be added to a pointer.
  505. This may be subsumed by shortcut() in the future.
  506.  
  507. #define BIGENDIAN as 1 if integers are represented in big endian, i.e. the
  508. most significant byte is at the lowest memory address, the least significant
  509. byte at the highest.
  510.  
  511. #define LITTLEENDIAN as 1 if integers are represented in little endian, i.e.
  512. the least significant byte is at the lowest memory address, the most
  513. significant byte at the highest.
  514.  
  515. #define SWITCHSUBS as 1 if switch-statements should be compiled into a
  516. series of SUB/TEST/BEQ instructions rather than COMPARE/BEQ. This may be
  517. useful if the target has a more efficient SUB-instruction (e.g. 68k).
  518.  
  519. #define INLINEMEMCPY to the largest size in bytes allowed for inline memcpy.
  520. Calls to memcpy/strcpy with a known size smaller than INLINEMEMCPY may be
  521. replaced by a single ASSIGN IC by vbcc.
  522. This may be replaced by a variable of type zlong in the future.
  523.  
  524.  
  525.  
  526. MACHINE.C
  527.  
  528. This is the main part of the code generator. The following changes have to
  529. be made:
  530.  
  531. COMMANDLINE OPTIONS
  532.  
  533.     You can use code generator specific commandline options.
  534.     The number of flags is specified as MAXGF in machine.h.
  535.     Insert the names for the flags as char *g_flags_name[MAXGF].
  536.     If an option was specified (g_flags[i]&USEDFLAG) is not zero.
  537.     In int g_flags[MAXGF] You can also choose how the options are to be
  538.     used:
  539.         0       The option can only be specified. E.g. if
  540.                 g_flags_name[2]=="myflag", the commandline may contain
  541.                 "-myflag" and (g_flags[2]&USEDFLAG)!=0.
  542.       VALFLAG   The option must be specified with an integer constant, e.g.
  543.                 "-myflag=1234". This value can be found in g_flags_val[2].l
  544.                 then.
  545.     STRINGFLAG  The option must be specified with a string, e.g.
  546.                 "-myflag=Hallo". The pointer to the string can be found in
  547.                 g_flags_val[2].p then.
  548.  
  549. DATA TYPES
  550.  
  551.     The array zlong align[16] must contain the necessary alignments for every
  552.     type in bytes. Some of the entries in this array are not actually
  553.     used, but align[type&15] must yield the correct alignment for every type.
  554.     align[CHAR] must be 1.
  555.  
  556.     zlong maxalign; must be set to an alignment in bytes that is ok for every
  557.     type.
  558.  
  559.     The array zlong sizetab[16] must contain the sizes of every type in bytes.
  560.  
  561.     The array zlong t_min[32] must contain the smallest number for every
  562.     integer type (including unsigned ones).
  563.     The array zulong t_max[32] must contain the greatest number for every
  564.     integer type (including unsigned ones).
  565.  
  566.     As zlong and zulong may be no elementary types on the host machine those
  567.     arrays have to be initialized dynamically.
  568.     Also note that if you want the code generator to be portable those values
  569.     may not be representable as constants by the host architecture and have to
  570.     be calculated using the functions for arithmetic on the target's data
  571.     types. E.g. the smallest representable value of a 32bit twos-complement
  572.     data type is not guaranteed to be valid on every ANSI C implementation.
  573.  
  574.     Also note that you may not use simple operators on the target data types
  575.     but you have to use the functions or convert them to an elementary
  576.     type of the host machine before (if you know that it is representable
  577.     as such).
  578.  
  579. REGISTER SET
  580.  
  581.     The valid registers are numbered from 1..MAXR.
  582.  
  583.     The array char *regnames[MAXR+1] must contain the names for every register.
  584.  
  585.     zlong regsize[MAXR+1] must contain the size of each register in bytes.
  586.     This is used to create storage if registers have to be saved.
  587.  
  588.     int regscratch[MAXR+1] must contain information whether a register is
  589.     a scratchregister i.e. may be destroyed during a function call (1 or 0).
  590.     vbcc will generate code to save/restore all scratch-registers which are
  591.     assigned a value when calling a function. However if the code generator
  592.     uses additional scratch-registers it has to take care to save/restore
  593.     them.
  594.     Also the code generator must save/restore used non-scratch-registers
  595.     on function entry/exit.
  596.  
  597.     int regsa[MAXR+1] must contain information whether a register is in use
  598.     or not at the beginning of a function (1 or 0).
  599.     The compiler will not use any of those registers for register variables
  600.     or temporaries.
  601.     You _must_ set regsratch[i] = 0 if regsa[i] == 1. If you want it to be
  602.     save across function calls the code generator has to take care of this.
  603.  
  604.     You should order the registers so that the ones that should be used first
  605.     have the smallest number and it is recommended that registers which
  606.     are used to pass return values be assigned the lowest numbers.
  607.  
  608.     Also You may reserve certain registers to the code generator. This may be
  609.     reasonable if many ICs cannot be converted without using additional
  610.     registers.
  611.  
  612. FUNCTIONS
  613.  
  614. The following functions have to be implemented by the code generator:
  615.  
  616. - int init_cg(void);
  617.  
  618.     This function is called after the commandline arguments are parsed.
  619.     It can set up certain internal data, etc. The arrays regarding the
  620.     data types and the register set, can be set up at this point rather
  621.     than with a static initialization, however the arrays regarding the
  622.     commandline options have to be static initialized.
  623.     The results of the commandline options are available at this point.
  624.  
  625.     If something goes wrong, 0 has to be returned, otherwise 1.
  626.  
  627. - void cleanup_cg(FILE *f)
  628.  
  629.     This function is called before the compiler exits. f is the output file
  630.     which _must_ be checked against 0 before using.
  631.  
  632. - int freturn(struct Typ *t);
  633.  
  634.     This function has to return the number of the register return
  635.     values of type t are passed in. If the type is not passed in a
  636.     register, 0 must be returned.
  637.  
  638. - int regok(int r, int t, int mode);
  639.  
  640.     Check, whether the type t can be stored in register r; return 0, if not.
  641.     If t==POINTER and mode==0 the register only has to be able to store the
  642.     pointer, but if mode!=0 it has to be able to dereference the pointer.
  643.  
  644.     If t==0 return whether the register can be used to store condition codes.
  645.     This is only relevant if multiple_ccs is set to 1.
  646.  
  647. - int dangerous_IC(struct IC *p)
  648.  
  649.     Check if this IC can raise exceptions or is otherwise dangerous.
  650.     Movement of ICs which are dangerous is restricted to preserve the
  651.     semantics of the program.
  652.     Typical dangerous ICs are divisions or pointer dereferencing. On certain
  653.     targets floating point or even signed integer arithmetic can raise
  654.     exceptions, too.
  655.  
  656. - int must_convert(np p, int t)
  657.  
  658.     Check if type in p does not have to be converted to type t. E.g. on
  659.     many machines certain types have identical representations (integers
  660.     of the same size or pointers and integers of the same size).
  661.  
  662. - int shortcut(int code, int t)
  663.  
  664.     In C no operations are done with chars and shorts because of integral
  665.     promotion. However sometimes vbcc might see that an operation could
  666.     be performed with the short types yielding the same result.
  667.  
  668.     Before generating such an instruction with short types vbcc will ask
  669.     the code generator by calling shortcut() to find out whether it should
  670.     do so. Return true iff it is a win to perform the operation code with
  671.     type t rather than promoting the operands and using int or so.
  672.  
  673. - void gen_code(FILE *f, struct IC *p, struct Var *v, zlong offset);
  674.  
  675.     This function has to generate the output for a function to stream f.
  676.     v is a pointer to the function which contains the name of the function.
  677.     p is a pointer to the first IC, that has to be converted.
  678.     offset is the space needed for local variables in bytes.
  679.  
  680.     This function has to take care that only scratchregisters are destroyed
  681.     by this function. The array regused contains information about the
  682.     registers that have been used by vbcc in this function. However if the
  683.     code generator uses additional registers it has to take care of them,
  684.     too.
  685.     The regs[] and regused[] arrays may be overwritten by gen_code() as well
  686.     as parts of the list of ICs. However the list of ICs must still be a
  687.     valid list of ICs after gen_code() returned.
  688.  
  689. - void gen_ds(FILE *f, zlong size, struct Typ *t);
  690.  
  691.     Has to print output that generates size bytes of type t initialized
  692.     with proper 0.
  693.     t is a pointer to a struct Typ which contains the precise type of
  694.     the variable. On machines where every type can be initialized to 0
  695.     by setting all bits to zero the type does not matter.
  696.  
  697. - void gen_align(FILE *f, zlong align);
  698.  
  699.     Has to print output that ensures the following data to be aligned to
  700.     align bytes.
  701.  
  702. - void gen_var_head(FILE *f, struct Var *v);
  703.  
  704.     Has to print the head of a static or external variable v. This includes
  705.     the label and necessary informations for external linkage etc.
  706.  
  707.     Typically variables will be generated by a call to gen_align followed
  708.     by gen_var_head and a series of calls to gen_dc and/or gen_ds.
  709.  
  710. - void gen_dc(FILE *f, int t, struct const_list *p);
  711.  
  712.     Well..I'm too lazy at the moment to describe that...
  713.  
  714.  
  715. Volker Barthelmann                                      volker@vb.franken.de
  716.  
  717.