Changes between Version 6 and Version 7 of Writing Rules/General


Ignore:
Timestamp:
Nov 29, 2012, 5:30:13 PM (11 years ago)
Author:
meunier
Comment:

Added a "Source Code Style" section (not finished)

Legend:

Unmodified
Added
Removed
Modified
  • Writing Rules/General

    v6 v7  
    4343 * LSBs of the VCI ADDRESS are ignored, and the VCI ADDRESS is only used to select a VCI cell (a word in memory).
    4444 * Bytes are selected by the VCI BE field, and the BE![0] bit is always associated to the Byte 0 of the VCI WDATA field (ie WDATA![7:0]).
     45
     46
     47= Source Code Style and Indentation (to be completed) =
     48
     49In so far as possible, people writing code are encouraged to follow some rules regarding indentation and coding style. These rules are described below:
     50
     51 * The coding style used is a variant of the BSD KNF style.
     52   * There must be one instruction per line : a line can be terminated by:
     53     * a semi-colon {{{;}}}
     54     * an opening bracket {{{ { }}}
     55     * a closing bracket {{{ } }}}
     56     * a colon after a {{{case}}} statement
     57   * A line following an opening bracket must be right-shifted
     58   * The opening bracket must always be the last character of its line
     59   * A left shift is done on a line containing a closing bracket
     60   * The opening bracket can be either on the same line as the instruction before or be the single instruction of its line
     61   * A line following a {{{case}}} statement must be right-shifted if no new block is created
     62   * A space is inserted at the following places:
     63     * after the statements {{{if}}}, {{{while}}}, {{{for}}} and {{{switch}}}
     64     * before and after a {{{=}}}
     65     * before and after all binary operators: {{{==}}}, {{{!=}}}, {{{&&}}}, {{{||}}}, {{{&}}} (bitwise and), {{{|}}}, {{{<<}}}, {{{>>}}}, {{{%}}}, {{{/}}}, {{{*}}} (multiplication), {{{+}}}, {{{-}}}, {{{<}}}, {{{>}}}
     66     * before and after a {{{*}}} in a pointer declaration
     67     * after a comma {{{,}}}
     68     * before the question mark {{{?}}} and the semi-colon {{{:}}} in a unary if construct {{{(x ? y : z)}}}
     69     * after the closing parenthesis in a cast statement
     70     * after the {{{//}}} sequence (commentary)
     71   * A space is '''not''' inserted at the following places :
     72     * before a semi-colon {{{;}}}
     73     * before and after the operators {{{->}}} and {{{.}}} (field selection)
     74     * before the opening bracket of a function declaration
     75     * before the opening bracket of a function call
     76     * before a comma {{{,}}}
     77     * before the operators {{{++}}} and {{{--}}}
     78     * after a {{{*}}} in a pointer dereferencement
     79     * before a colon {{{:}}} of a case statement
     80     * before an indexation operator {{{[]}}}
     81   * It is tolerated to add spaces to align some elements such as: affectations, indexation, conditions on several lines, parameters in function calls, variables declarations.
     82 * C-99 types must be used when possible: {{{int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t}}}
     83 * The indentation must use spaces and not tabs. The number of spaces used is 4.
     84 * Blocks (i.e. brackets) must be used even for a single instruction.
     85 * The keywords {{{public}}} and {{{private}}} can be either indented regularly or the same way as their parents (the class in which they are).
     86
     87Here is a code exemple :
     88{{{
     89#!cpp
     90
     91template <int32_t size> class MyClass : public Parent {
     92
     93public:
     94    sc_signal<uint32_t> my_signal;
     95};
     96
     97typedef struct _mystruct {
     98    uint32_t val;
     99} mystruct;
     100
     101
     102int32_t f(int32_t x, mystruct * y, uint32_t c) {
     103    int16_t a, b = 0;
     104    int32_t * ptr;
     105    mystruct st;
     106
     107    MyClass<1>  t1;
     108    MyClass<10> t10;
     109
     110    while (st.val == b && *ptr != 0) {
     111        if ((a & 0x10) != 0 || y->val) {
     112            *y--;
     113#ifdef SOME_FLAG
     114            my_counter++;
     115#endif
     116            return 1;
     117        }
     118
     119        switch (c) {
     120            case 0:
     121                printf("c is %d\n", c);
     122                break;
     123            case 1:
     124            {
     125                int local = 2;
     126                c = local + 1;
     127            }
     128            default:
     129                break;
     130        }
     131    }
     132    // f is a recursive function
     133    f(x, y, c + 1);
     134    int32_t exp = (a + (b * st.val) % d) >> 2;
     135    uint32_t b = (a * (b + c) == 1) ? c : c + 1;
     136    uint32_t var = *(uint32_t *) 0x10000000;
     137
     138    return exp;
     139}
     140}}}
     141
     142 * Every file must contain at its end an epilogue specifying some indentation parameters for vim and emacs. This epilogue must be:
     143{{{
     144# Local Variables:
     145# tab-width: 4;
     146# c-basic-offset: 4;
     147# c-file-offsets:((innamespace . 0)(inline-open . 0));
     148# indent-tabs-mode: nil;
     149# End:
     150#
     151# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     152}}}
     153
     154''Please note: some files do not respect yet all these conventions.''