Changeset d93b813 for doc/theses/jiada_liang_MMath/conclusion.tex
- Timestamp:
- Sep 9, 2024, 6:15:53 PM (36 hours ago)
- Branches:
- master
- Children:
- 3d618a0
- Parents:
- 478dade
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/conclusion.tex
r478dade rd93b813 71 71 Label arrays are auxiliary data structures that are always generated for \CFA enumeration, which is a considerable program overhead. 72 72 It 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 on73 throughout the execution. Therefore, \CFA optimizes the label array away. The @label()@ 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 @label()@ is called on 75 75 a 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 80 enum(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 92 enum(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 105 C_Codec c_code = C_Codec.VORBIS; 106 CFA_Codec cfa_code = CFA_Codec.VORBIS; 107 \end{cfa} 108 In the preceding example, the memory location of @c_code@ stores a value 9, the integral value of VORBIS. 109 The memory of @cfa_code@ stores 5, which is the position of @CFA_Codec.VORBIS@ and can be mapped to value 9. 110 111 If to insert a new enumerator in both @C_Codec@ and @CFA_Codec@ 112 before the relative position of VORBIS, without a re-compilation of @main.c@, variable @cfa_code@ would be mapped 113 to an unintented value. 114 // libvacodec.h: v2 115 enum(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 128 enum(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} 142 While @c_code@ still has the correct value of 9, @cfa_code@ (5) is now mapped to @First_AUDIO@. In other words, it is 143 necessary to to recompile @main.c@ when to update @libvacodec.h@. 144 145 To 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 148 const int FIRST_VIDEO = 0; 149 const int VP8 = 1; 150 const int VP9 = 2; 151 const int LAST_VIDEO = 3; 152 const int FIRST_AUDIO = 4; 153 const int VORBIS = 5; 154 const int OPUS = 6; 155 const int LAST_AUDIO = 7; 156 157 // CFA-cc transpile: main.c 158 extern const int FIRST_VIDEO; 159 extern const int VP8; 160 extern const int VP9; 161 extern const int LAST_VIDEO; 162 extern const int FIRST_AUDIO; 163 extern const int VORBIS; 164 extern const int OPUS; 165 extern const int LAST_AUDIO; 166 167 int cfa_code = VORBIS; 168 \end{cfa} 169 If later a position of an enumerator is changed, the generated expression @int cfa_code = VORBIS;@ will still have the correct 170 value, because it is linked to a external constant @VORBIS@ from @libvacodec.h@. This implementation requires extra memory to store position, but 171 solve the separate compilation problem. 172 76 173 \end{enumerate}
Note: See TracChangeset
for help on using the changeset viewer.