Changeset c21f5a9


Ignore:
Timestamp:
May 20, 2021, 10:53:21 AM (14 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr
Children:
090a7c5
Parents:
77f1265
Message:

Andrew MMath: Work on figures and linkonce.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/andrew_beach_MMath/cfalab.sty

    r77f1265 rc21f5a9  
    4040      \def\Cpp{C++}
    4141      \def\lstinline{}
     42      \def\code#1#2{#2}
    4243    }
    4344  }{}
  • doc/theses/andrew_beach_MMath/features.tex

    r77f1265 rc21f5a9  
    150150It is important to note that these are virtual members, not virtual methods
    151151of object-orientated programming, and can be of any type.
    152 However, since \CFA has function pointers and they are allowed, virtual
    153 members can be used to mimic virtual methods.
     152\CFA still supports virtual methods as a special case of virtual members.
     153Function pointers that take a pointer to the virtual type will be modified
     154with each level of inheritance so that refers to the new type.
     155This means an object can always be passed to a function in its virtual table
     156as if it were a method.
    154157
    155158Each virtual type has a unique id.
  • doc/theses/andrew_beach_MMath/implement.tex

    r77f1265 rc21f5a9  
    7171
    7272\begin{cfa}
    73 struct /* type name */ {
    74         /* parent type name */ const * parent;
     73struct TYPE_ID_TYPE {
     74        PARENT_ID_TYPE const * parent;
    7575};
    7676
    77 __attribute__((section(".gnu.linkonce./* instance name */")))
    78 /* type name */ const /* instance name */ = {
    79         &/* parent instance name */,
     77__attribute__((cfa_linkonce))
     78TYPE_ID_TYPE const TYPE_ID_NAME = {
     79        &PARENT_ID_NAME,
    8080};
    8181\end{cfa}
     82
     83\subsubsection{cfa\_linkonce Attribute}
     84Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}.
     85This attribute can be put on an object or function definition
     86(any global declaration with a name and a type).
     87This allows you to define that object or function multiple times.
     88All definitions should have the link-once attribute on them and all should
     89be identical.
     90
     91The simplist way to use it is to put a definition in a header where the
     92forward declaration would usually go.
     93This is how it is used for type-id instances. There was is no unique location
     94associated with a type except for the type definition which is in a header.
     95This allows the unique type-id object to be generated there.
     96
     97Internally @cfa_linkonce@ removes all @section@ attributes
     98from the declaration (as well as itself) and replaces them with
     99@section(".gnu.linkonce.NAME")@ where \texttt{NAME} is replaced by the
     100mangled name of the object.
     101The prefix \texttt{.gnu.linkonce} in section names is recognized by the
     102linker. If two of these sections with the same name, including everything
     103that comes after the special prefix, then only one will be used and the other
     104will be discarded.
    82105
    83106\subsection{Virtual Table}
     
    124147underlying object, access any of the virtual members and pass the object to
    125148any of the method-like virtual members.
    126 \todo{Introduce method-like virtual members.}
    127149
    128150When a virtual table is declared the user decides where to declare it and its
     
    144166the instance is created as well. The definition of the virtual table is created
    145167at the definition of the main function.
    146 \todo{Add an example with code snipits.}
     168
     169\begin{figure}
     170\begin{cfa}
     171coroutine Example {
     172        // fields
     173}
     174\end{cfa}
     175
     176\begin{cfa}
     177__attribute__((cfa_linkonce))
     178struct __cfatid_struct_CoroutineCancelled(Example)
     179                __cfatid_CoroutineCancelled = {
     180        &EXCEPTION_TYPE_ID,
     181};
     182extern CoroutineCancelled_vtable _default_vtable_object_declaration;
     183extern CoroutineCancelled_vtable & _default_vtable;
     184\end{cfa}
     185
     186\begin{cfa}
     187void main(Example & this) {
     188        // body
     189}
     190\end{cfa}
     191
     192\begin{cfa}
     193CoroutineCancelled_vtable _default_vtable_object_declaration = {
     194        __cfatid_CoroutineCancelled,
     195        // Virtual member initialization.
     196};
     197
     198CoroutineCancelled_vtable & _default_vtable =
     199        &_default_vtable_object_declaration;
     200\end{cfa}
     201\caption{Concurrency Transformations}
     202\label{f:ConcurrencyTransformations}
     203\end{figure}
     204\todo{Improve Concurrency Transformations figure.}
    147205
    148206\subsection{Virtual Cast}
     
    155213\begin{cfa}
    156214void * __cfa__virtual_cast(
    157         struct __cfa__parent_vtable const * parent,
    158         struct __cfa__parent_vtable const * const * child );
    159 \end{cfa}
    160 \todo{Get rid of \_\_cfa\_\_parent\_vtable in the standard library and then
    161 the document.}
     215        struct __cfavir_type_td parent,
     216        struct __cfavir_type_id const * child );
     217\end{cfa}
    162218The type id of target type of the virtual cast is passed in as @parent@ and
    163219the cast target is passed in as @child@.
     
    572628the LSDA.
    573629Using this pattern, \CFA implements destructors with the cleanup attribute.
    574 \todo{Add an example of the conversion from try statement to functions.}
     630
     631\begin{figure}
     632\begin{cfa}
     633try {
     634        // TRY BLOCK
     635} catch (Exception1 * name1 ; check(name1)) {
     636        // CATCH BLOCK 1
     637} catch (Exception2 * name2) {
     638        // CATCH BLOCK 2
     639}
     640\end{cfa}
     641
     642\begin{cfa}
     643void try(void) {
     644        // TRY BLOCK
     645}
     646int match(exception_t * __exception_inst) {
     647        {
     648                Exception1 * name1;
     649                if (name1 = (virtual Exception1 *)__exception_inst && check(name1)) {
     650                        return 1;
     651                }
     652        }
     653        {
     654                Exception2 * name2;
     655                if (name2 = (virtual Exception2 *)__exception_inst) {
     656                        return 2;
     657                }
     658        }
     659        return 0;
     660}
     661void catch(exception_t * __exception_inst, int __handler_index) {
     662        switch (__handler_index) {
     663        case 1:
     664        {
     665                Exception1 * name1 = (virtual Exception1 *)__exception_inst;
     666                // CATCH BLOCK 1
     667        }
     668        return;
     669        case 2:
     670        {
     671                Exception2 * name2 = (virtual Exception2 *)__exception_inst;
     672                // CATCH BLOCK 2
     673        }
     674        return;
     675        }
     676}
     677{
     678        __cfaehm_try_terminate(try, catch, match);
     679}
     680\end{cfa}
     681
     682\caption{Termination Transformation}
     683\label{f:TerminationTransformation}
     684\todo*{Improve (compress?) Termination Transformations.}
     685\end{figure}
    575686
    576687\section{Resumption}
     
    606717the next clause the function returns false as no handler could be found.
    607718
    608 \todo{Diagram showing a try statement being converted into resumption handlers.}
     719\begin{figure}
     720\begin{cfa}
     721try {
     722        // TRY BLOCK
     723} catchResume (Exception1 * name1 ; check(name1)) {
     724        // CATCH BLOCK 1
     725} catchResume (Exception2 * name2) {
     726        // CATCH BLOCK 2
     727}
     728\end{cfa}
     729
     730\begin{cfa}
     731bool handle(exception_t * __exception_inst) {
     732        {
     733                Exception1 * name1;
     734                if (name1 = (virtual Exception1 *)__exception_inst && check(name1)) {
     735                        // CATCH BLOCK 1
     736                        return 1;
     737                }
     738        }
     739        {
     740                Exception2 * name2;
     741                if (name2 = (virtual Exception2 *)__exception_inst) {
     742                        // CATCH BLOCK 2
     743                        return 2;
     744                }
     745        }
     746        return false;
     747}
     748struct __try_resume_node __resume_node
     749        __attribute__((cleanup( __cfaehm_try_resume_cleanup )));
     750__cfaehm_try_resume_setup( &__resume_node, handler );
     751\end{cfa}
     752
     753\caption{Resumption Transformation}
     754\label{f:ResumptionTransformation}
     755\todo*{Improve (compress?) Resumption Transformations.}
     756\end{figure}
    609757
    610758% Recursive Resumption Stuff:
     
    625773stack -- the first one points over all the checked handlers -- and the ordering
    626774is maintained.
    627 \todo{Add a diagram for resumption marking.}
     775
     776\begin{figure}
     777\begin{minipage}[l][][b]{0,2\textwidth}
     778\begin{verbatim}
     779
     780
     781  X <-
     782  |
     783  V
     784  X
     785  |
     786  V
     787  X
     788\end{verbatim}
     789Initial State
     790\end{minipage}
     791\begin{minipage}[l][][b]{0,2\textwidth}
     792\begin{verbatim}
     793
     794
     795  X
     796  |
     797  V
     798  X <-
     799  |
     800  V
     801  X
     802\end{verbatim}
     803Handler Found
     804\end{minipage}
     805\begin{minipage}[l][][b]{0,2\textwidth}
     806\begin{verbatim}
     807  X <-
     808 /
     809/ X
     810| |
     811\ V
     812  X
     813  |
     814  V
     815  X
     816\end{verbatim}
     817Try Block Added
     818\end{minipage}
     819\begin{minipage}[l][][b]{0,2\textwidth}
     820\begin{verbatim}
     821
     822
     823  X <-
     824  |
     825  V
     826  X
     827  |
     828  V
     829  X
     830\end{verbatim}
     831Handler Done
     832\end{minipage}
     833\caption{Resumption Marking}
     834\label{f:ResumptionMarking}
     835\todo*{Convert Resumption Marking into a line figure.}
     836\end{figure}
    628837
    629838\label{p:zero-cost}
  • tests/link-once/main.cfa

    r77f1265 rc21f5a9  
    44__attribute__(( cfa_linkonce )) unsigned int example = 12;
    55
     6__attribute__(( cfa_linkonce ))
     7void printformat(signed int signed_value, unsigned int unsigned_value) {
     8        printf("signed=%d unsigned=%d\n", signed_value, unsigned_value);
     9}
     10
    611int main(int argc, char * argv[]) {
    7         signed int si = example;
    8         unsigned int ui = example;
    9         printf("signed=%d unsigned=%d\n", si, ui);
     12        printformat(example, example);
    1013}
  • tests/link-once/partner.cfa

    r77f1265 rc21f5a9  
    33__attribute__(( cfa_linkonce )) signed int example = -7;
    44__attribute__(( cfa_linkonce )) unsigned int example = 12;
     5
     6__attribute__(( cfa_linkonce ))
     7void printformat(signed int signed_value, unsigned int unsigned_value) {
     8        printf("signed=%d unsigned=%d\n", signed_value, unsigned_value);
     9}
Note: See TracChangeset for help on using the changeset viewer.