Ignore:
Timestamp:
Sep 9, 2024, 6:15:53 PM (36 hours ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
3d618a0
Parents:
478dade
Message:

Add separate compilation discussion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/conclusion.tex

    r478dade rd93b813  
    7171Label arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a considerable program overhead.
    7272It is helpful to provide a new syntax or annotation for a \CFA enumeration definition that tells the compiler the labels will not be used
    73 throughout the execution. Therefore, \CFA optimizes the label array away. The @value()@ function can still be used on an enumeration constant,
    74 and the function called is reduced to a @char *@ constant expression that holds the name of the enumerator. But if @value()@ is called on
     73throughout the execution. Therefore, \CFA optimizes the label array away. The @label()@ function can still be used on an enumeration constant,
     74and the function called is reduced to a @char *@ constant expression that holds the name of the enumerator. But if @label()@ is called on
    7575a variable with an enumerated type, it returns an empty string since the label information is lost for the runtime.
     76\item
     77\CFA enumeration has its limitation in separate compilation. Consider the followings example:
     78\begin{cfa}
     79// libvacodec.h: v1
     80enum(int) C_Codec ! {
     81    FIRST_VIDEO = 0,
     82    VP8 = 2,
     83    VP9 = 4,
     84    LAST_VIDEO = 8,
     85
     86    FIRST_AUDIO = 3,
     87    VORBIS = 9,
     88    OPUS = 27,
     89    LAST_AUDIO = 81
     90};
     91
     92enum(int) CFA_Codec ! {
     93    FIRST_VIDEO = 0,
     94    VP8 = 2,
     95    VP9 = 4,
     96    LAST_VIDEO = 8,
     97
     98    FIRST_AUDIO = 3,
     99    VORBIS = 9,
     100    OPUS = 27,
     101    LAST_AUDIO = 81
     102};
     103
     104// main.c
     105C_Codec c_code = C_Codec.VORBIS;
     106CFA_Codec cfa_code = CFA_Codec.VORBIS;
     107\end{cfa}
     108In the preceding example, the memory location of @c_code@ stores a value 9, the integral value of VORBIS.
     109The memory of @cfa_code@ stores 5, which is the position of @CFA_Codec.VORBIS@ and can be mapped to value 9.
     110
     111If to insert a new enumerator in both @C_Codec@ and @CFA_Codec@
     112before the relative position of VORBIS, without a re-compilation of @main.c@, variable @cfa_code@ would be mapped
     113to an unintented value.
     114// libvacodec.h: v2
     115enum(int) C_Codec ! {
     116    FIRST_VIDEO = 0,
     117    VP8 = 2,
     118    VP9 = 4,
     119    @AV1@,
     120    LAST_VIDEO = 8,
     121
     122    FIRST_AUDIO = 3,
     123    VORBIS = 9,
     124    OPUS = 27,
     125    LAST_AUDIO = 81
     126};
     127
     128enum(int) CFA_Codec ! {
     129    FIRST_VIDEO = 0,
     130    VP8 = 2,
     131    VP9 = 4,
     132    @AV1@,
     133    LAST_VIDEO = 8,
     134
     135    FIRST_AUDIO = 3,
     136    VORBIS = 9,
     137    OPUS = 27,
     138    LAST_AUDIO = 81
     139};
     140
     141\end{cfa}
     142While @c_code@ still has the correct value of 9, @cfa_code@ (5) is now mapped to @First_AUDIO@. In other words, it is
     143necessary to to recompile @main.c@ when to update @libvacodec.h@.
     144
     145To avoid a recompilation, enumeration positions can be represented as @extern const@. For example, \CFA-cc can generate the following code for @CFA_Codec@:
     146\begin{cfa}
     147// CFA-cc transpile: libvacodec.h
     148const int FIRST_VIDEO = 0;
     149const int VP8 = 1;
     150const int VP9 = 2;
     151const int LAST_VIDEO = 3;
     152const int FIRST_AUDIO = 4;
     153const int VORBIS = 5;
     154const int OPUS = 6;
     155const int LAST_AUDIO = 7;
     156
     157// CFA-cc transpile: main.c
     158extern const int FIRST_VIDEO;
     159extern const int VP8;
     160extern const int VP9;
     161extern const int LAST_VIDEO;
     162extern const int FIRST_AUDIO;
     163extern const int VORBIS;
     164extern const int OPUS;
     165extern const int LAST_AUDIO;
     166
     167int cfa_code = VORBIS;
     168\end{cfa}
     169If later a position of an enumerator is changed, the generated expression @int cfa_code = VORBIS;@ will still have the correct
     170value, because it is linked to a external constant @VORBIS@ from @libvacodec.h@. This implementation requires extra memory to store position, but
     171solve the separate compilation problem.
     172
    76173\end{enumerate}
Note: See TracChangeset for help on using the changeset viewer.